Esempio n. 1
0
        public static PowerExpression AsPower(this AlgebraExpression expression)
        {
            if (expression is PowerExpression power)
            {
                return(power);
            }

            return(ExpressionFactory.Exponentiate(expression, ExpressionFactory.One));
        }
        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);
        }
Esempio n. 3
0
 public PowerExpression WithExponent(AlgebraExpression newExponent)
 {
     return(ExpressionFactory.Exponentiate(this.Base, newExponent));
 }
Esempio n. 4
0
 public PowerExpression WithBase(AlgebraExpression newBase)
 {
     return(ExpressionFactory.Exponentiate(newBase, this.Exponent));
 }