Exemplo n.º 1
0
        protected override Expression VisitUnknown(Expression E)
        {
            Expression LE = Call.L(E, t, s);

            // Try applying a rule to E.
            Expression TLE = rules.Transform(LE);

            if (!ReferenceEquals(TLE, LE))
            {
                return(TLE);
            }

            // Try expanding E.
            Expression Ex = E.Expand(s);

            if (!Equals(E, Ex))
            {
                return(Visit(Ex));
            }

            // Try -L(-E, s, t)
            // TODO: It would be nice to handle this case in LinearTransform somehow.
            Expression NE  = Unary.Negate(E);
            Expression NEx = NE.Evaluate();

            if (!Equals(NE, NEx))
            {
                return(Unary.Negate(Visit(NEx)));
            }

            // Give up.
            return(LE);
        }
Exemplo n.º 2
0
        public void Simplify_NegativeNegations_success()
        {
            SillyParser p       = new SillyParser(null);
            Unary       node    = (Unary)p.m("-", p.m("a"));
            Unary       neg     = (Unary)node.Negate();
            Leaf        negSimp = (Leaf)neg.Simplify();

            Assert.AreEqual("--a", neg.Unparse());
            Assert.AreEqual("a", negSimp.Unparse());
            p.SetVar("a", 2);
            Assert.AreEqual(-2, node.Eval());
            Assert.AreEqual(2, neg.Eval());
            Assert.AreEqual(2, negSimp.Eval());
        }
Exemplo n.º 3
0
 public static LazyExpression operator -(LazyExpression L, LazyExpression R)
 {
     return(new LazyExpression(Sum.New(L.value, Unary.Negate(R.value))));
 }