/// <summary> /// (f + g)' = f' + g' /// Meaning we differentiate both the left and right sub tree first /// and return an addition operator with the differentiated sub trees /// as it's successors /// </summary> /// <returns> /// An addition operator object with both left /// and right successor differentiated. /// </returns> public override Operand Differentiate() { Addition derivative = new Addition(); derivative.LeftSuccessor = LeftSuccessor.Differentiate(); derivative.RightSuccessor = RightSuccessor.Differentiate(); return(derivative); }
/// <summary> /// (f - g)' = f'- g' /// Meaning we differentiate both the left and right sub tree first /// and return a subtraction operator with the differentiated sub trees /// as it's successors /// </summary> /// <returns> /// A subtraction operator object with both left /// and right successor differentiated. /// </returns> public override Operand Differentiate() { Operand leftDerivative = LeftSuccessor.Differentiate(); Operand rightDerivative = RightSuccessor.Differentiate(); Subtraction derivative = new Subtraction(); derivative.LeftSuccessor = leftDerivative; derivative.RightSuccessor = rightDerivative; return(derivative); }
/// <summary> /// Applies the product rule to the sub trees. /// (f * g)' = f * g' + f' * g /// /// The method differentiates the appropriate sub trees and /// eventually returns a single Operand object (in this case /// an addition operator object) holding both an original /// expression sub tree as well as a differentiated sub tree. /// </summary> /// <returns> /// An operator object, representing the applied product rule. /// </returns> public override Operand Differentiate() { // Create and assign fg' Multiplication newLeftExpression = new Multiplication(); newLeftExpression.LeftSuccessor = LeftSuccessor.Copy(); newLeftExpression.RightSuccessor = RightSuccessor.Differentiate(); // Create and assign f'g Multiplication newRightExpression = new Multiplication(); newRightExpression.LeftSuccessor = LeftSuccessor.Differentiate(); newRightExpression.RightSuccessor = RightSuccessor.Copy(); // Create and assign fg' + f'g Addition derivative = new Addition(); derivative.LeftSuccessor = newLeftExpression; derivative.RightSuccessor = newRightExpression; return(derivative); }