Пример #1
0
        public static void RegisterTheorems(ILibrary library)
        {
            Analysis.DerivativeTransformation.Provider.Add(
                new Analysis.DerivativeTransformation(_entityId,
                                                      delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs)
            {
                int cnt                  = manipulatedInputs.Count;
                Signal[] addSignals      = new Signal[cnt];
                Signal[] multiplySignals = new Signal[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    for (int j = 0; j < cnt; j++)
                    {
                        multiplySignals[j] = i == j ? manipulatedInputs[j] : port.InputSignals[j];
                    }
                    addSignals[i] = Std.Multiply(multiplySignals);
                }
                return(new SignalSet(Std.Add(addSignals)));
            }));

            Algebra.AutoSimplifyTransformation.Provider.Add(
                new Algebra.AutoSimplifyTransformation(_entityId,
                                                       delegate(Port port)
            {
                // TODO
                return(ManipulationPlan.DoAlter);
            },
                                                       delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs)
            {
                if (SimplifyFactors(manipulatedInputs) || hasManipulatedInputs)
                {
                    if (manipulatedInputs.Count == 0)
                    {
                        return(new SignalSet(IntegerValue.ConstantMultiplicativeIdentity));
                    }
                    if (manipulatedInputs.Count == 1)
                    {
                        return(manipulatedInputs);
                    }
                    return(new SignalSet(StdBuilder.Multiply(manipulatedInputs)));
                }
                else
                {
                    return(port.OutputSignals);
                }
            }));
        }
Пример #2
0
        public void Basic_Traversing()
        {
            Signal a = Binder.CreateSignal(); a.Label = "A";
            Signal b = Binder.CreateSignal(); b.Label = "B";
            Signal c = StdBuilder.Add(a, b); c.Label = "C";      //a + b;
            Signal d = StdBuilder.Multiply(a, c); d.Label = "D"; //a * c;

            Assert.IsTrue(c.DependsOn(a), "1: a->c");
            Assert.IsTrue(c.DependsOn(b), "1: b->c");
            Assert.IsTrue(d.DependsOn(a), "1: a->d");
            Assert.IsTrue(d.DependsOn(b), "1: b->d");
            Assert.IsTrue(d.DependsOn(c), "1: c->d");
            Assert.IsFalse(a.DependsOn(b), "1: b!->a");
            Assert.IsFalse(b.DependsOn(a), "1: a!->b");
            Assert.IsFalse(a.DependsOn(d), "1: d!->a");
            Assert.IsFalse(b.DependsOn(d), "1: d!->b");
            Assert.IsFalse(c.DependsOn(d), "1: d!->c");
            Assert.IsFalse(a.DependsOn(c), "1: c!->a");
            Assert.IsFalse(b.DependsOn(c), "1: c!->b");

            Service <IBuilder> .Instance.MapSignals(c, b);

            Assert.IsTrue(c.DependsOn(a), "2: a->c");
            Assert.IsTrue(c.DependsOn(b), "2: b->c");
            Assert.IsTrue(d.DependsOn(a), "2: a->d");
            Assert.IsTrue(d.DependsOn(b), "2: b->d");
            Assert.IsTrue(d.DependsOn(c), "2: c->d");
            Assert.IsFalse(a.DependsOn(b), "2: b!->a");
            Assert.IsTrue(b.DependsOn(a), "2: a->b"); // NEW
            Assert.IsFalse(a.DependsOn(d), "2: d!->a");
            Assert.IsFalse(b.DependsOn(d), "2: d!->b");
            Assert.IsFalse(c.DependsOn(d), "2: d!->c");
            Assert.IsFalse(a.DependsOn(c), "2: c!->a");
            Assert.IsTrue(b.DependsOn(c), "2: c->b");  // NEW

            Assert.IsTrue(Service <IScanner> .Instance.ExistsSignal(d, delegate(Signal s) { return(s.Label == "A"); }, false));
            Assert.IsFalse(Service <IScanner> .Instance.ExistsSignal(d, delegate(Signal s) { return(s.Label == "Z"); }, false));
            Assert.AreEqual("B", Service <IScanner> .Instance.FindSignal(d, delegate(Signal s) { return(s.Label == "B"); }, false).Label);
        }