Exemplo n.º 1
0
 public static Expression Build(Expression expr)
 {
     if (expr is NegatedExpression negated)
     {
         return(negated.Expression);
     }
     else if (expr is ConstantExpression constant)
     {
         return(-constant.Value);
     }
     else if (expr is AdditionExpression addition)
     {
         return(AdditionExpression.Build(-addition.Constant, addition.VariableParts.Select(x => NegatedExpression.Build(x))));
     }
     else if (expr is MultiplicationExpression multiplication)
     {
         return(MultiplicationExpression.Build(-multiplication.Coefficient, multiplication.VariableParts));
     }
     else
     {
         return(new NegatedExpression(expr));
     }
 }
Exemplo n.º 2
0
 public override Expression FindDerivative() =>
 AdditionExpression.Build(VariableParts.Select(x => x.FindDerivative() * MultiplicationExpression.Build(VariableParts.Where(y => y != x)))) * Coefficient;
Exemplo n.º 3
0
 /// <summary>
 /// Binary multiplication of expressions.
 /// </summary>
 /// <param name="first">Left-side expression.</param>
 /// <param name="second">Right-side expression.</param>
 /// <returns>Returns the result of multiplying the operand expressions.</returns>
 public static Expression operator *(Expression first, Expression second) =>
 MultiplicationExpression.Build(first, second);