Example #1
0
        public override Expression FindDerivative()
        {
            if (Arguments.Count == 1)
            {
                Expression topLevelDerivative =
                    FunctionName == "sin" ? Build("cos", Arguments) :
                    FunctionName == "cos" ? -Build("sin", Arguments) :
                    FunctionName == "ln" ? FractionExpression.Build(ConstantExpression.One, Arguments[0]) :
                    FunctionName == "sqrt" ? FractionExpression.Build(ConstantExpression.One, (Fraction)2 * this) :
                    null;

                if (topLevelDerivative != null)
                {
                    return(Arguments[0] is VariableExpression ?
                           topLevelDerivative :
                           topLevelDerivative *Arguments[0].FindDerivative());
                }
            }

            throw new NotImplementedException($"Function \"{FunctionName}\" with {Arguments.Count} arguments has no defined derivation");
        }
Example #2
0
 /// <summary>
 /// Binary division of expressions.
 /// </summary>
 /// <param name="first">Left-side expression.</param>
 /// <param name="second">Right-side expression.</param>
 /// <returns>Returns the result of dividing the first expression by the second expression.
 /// If immediate division is not possible, a fraction expression will be returned instead.</returns>
 public static Expression operator /(Expression first, Expression second) =>
 FractionExpression.Build(first, second);