// V(x + y) = V(x) + V(y)
 protected override Expression VisitSum(Sum A)
 {
     return Sum.New(A.Terms.Select(i => Visit(i)));
 }
 protected override Expression VisitSum(Sum A)
 {
     return Sum.New(A.Terms.Select(i => Visit(i)).Where(i => !i.EqualsZero()));
 }
 protected override Expression VisitSum(Sum A)
 {
     return EvaluateSum(A.Terms.SelectMany(i => Sum.TermsOf(Visit(i))));
 }
        protected override string VisitSum(Sum A)
        {
            int pr = Parser.Precedence(Operator.Add);

            StringBuilder s = new StringBuilder();
            s.Append(Visit(A.Terms.First(), pr));
            foreach (Expression i in A.Terms.Skip(1))
            {
                string si = Visit(i, pr);

                if (si[0] != '-')
                    s.Append("+");
                s.Append(si);
            }
            return s.ToString();
        }
Exemple #5
0
 public Expression Solve(Expression x)
 {
     return(Unary.Negate(Sum.New(this.Where(i => !i.Key.Equals(x)).Select(i => Product.New(i.Key, i.Value)))) / this[x]);
 }
 // Expression operators.
 public static LazyExpression operator +(LazyExpression L, LazyExpression R)
 {
     return(new LazyExpression(Sum.New(L.value, R.value)));
 }
 public static LazyExpression operator -(LazyExpression L, LazyExpression R)
 {
     return(new LazyExpression(Sum.New(L.value, Unary.Negate(R.value))));
 }