protected override Expression VisitSum(Sum A) { List <Expression> terms = new List <Expression>(); foreach (Expression i in A.Terms) { terms.Add(Visit(i)); } return(EvaluateVisitor.EvaluateSum(terms)); }
// Evaluate x*A, distributing x if A is Add. public static Expression Distribute(Expression x, Expression A) { if (A is Sum || x is Sum) { return(EvaluateVisitor.EvaluateSum(Sum.TermsOf(A).SelectMany(i => Sum.TermsOf(Distribute(i, x))))); } else { return(Product.New(A, x).Evaluate()); } }
public static IEnumerable <Expression> Evaluate(this IEnumerable <Expression> f, IDictionary <Expression, Expression> x0) { EvaluateVisitor V = new EvaluateVisitor(); return(f.Select(i => V.Visit(i.Substitute(x0)))); }
public static IEnumerable<Expression> Evaluate(this IEnumerable<Expression> f, IDictionary<Expression, Expression> x0) { EvaluateVisitor V = new EvaluateVisitor(); return f.Select(i => V.Visit(i.Substitute(x0))); }