public SumExpressionList Add(AlgebraExpression expression) { return(expression is SumExpressionList ? ExpressionFactory.Sum(this.Terms.Concat((expression as SumExpressionList).Terms).ToImmutableList()) : ExpressionFactory.Add(this, expression) ); }
public SumExpressionList Subtract(AlgebraExpression expression) { return(expression is SumExpressionList ? ExpressionFactory.Sum(this.Terms.Concat((expression as SumExpressionList).Terms.Select(ExpressionFactory.Negate)).ToImmutableList()) : ExpressionFactory.Subtract(this, expression) ); }
public AlgebraExpression Simplify(ProductExpressionList expression, CancellationToken cancellationToken) { var results = expression.Terms .Select(t => t.AsPower()) .GroupBy(p => p.Base) .ToList(); if (results.Count != expression.Terms.Count) { return(expression.WithTerms( results .Select(g => ExpressionFactory.Exponentiate(g.Key, ExpressionFactory.Sum(g.Select(p => p.Exponent).ToImmutableList())) ) .Select(p => exponentSimplifier.Simplify(p, cancellationToken)) .ToImmutableList() )); } return(expression); }
public SumExpressionList WithTerms(IImmutableList <AlgebraExpression> newTerms) { return(ExpressionFactory.Sum(newTerms)); }