public IExpressionNode Simplify() { LeftOperand = LeftOperand.Simplify(); RightOperand = RightOperand.Simplify(); if (!LeftOperand.ContainsVariable() && !RightOperand.ContainsVariable()) { return(new Constant(this.Evaluate(null))); } else if (!LeftOperand.ContainsVariable() && RightOperand.ContainsVariable()) { if (LeftOperand.Evaluate(null) == 0) { return(new Constant(0)); } } else if (LeftOperand.ContainsVariable() && !RightOperand.ContainsVariable()) { if (RightOperand.Evaluate(null) == 0) { throw new DivideByZeroException(); } if (RightOperand.Evaluate(null) == 1) { return(LeftOperand.DeepCopy()); } } return(this); }
public IExpressionNode Derivate() { var leftDerivative = LeftOperand.Derivate(); var rightDerivative = RightOperand.Derivate(); return(new OperationDivision( new OperationSubtraction( new OperationMultiplication(LeftOperand.DeepCopy(), rightDerivative), new OperationMultiplication(leftDerivative, RightOperand.DeepCopy()) ), new OperationPower(RightOperand.DeepCopy(), new Constant(2)))); }
public IExpressionNode Derivate() { var leftDerivative = LeftOperand.Derivate(); var rightDerivative = RightOperand.Derivate(); return(new OperationAdd( new OperationMultiplication( leftDerivative, RightOperand.DeepCopy()), new OperationMultiplication( LeftOperand.DeepCopy(), rightDerivative))); }
public IExpressionNode Derivate() { if (LeftOperand.ContainsVariable() && RightOperand.ContainsVariable()) { return(new OperationMultiplication( this.DeepCopy(), new OperationMultiplication( new FunctionLn(LeftOperand.DeepCopy()), RightOperand.DeepCopy()).Derivate())); } else if (LeftOperand.ContainsVariable()) { return(new OperationMultiplication( new OperationMultiplication( RightOperand.DeepCopy(), new OperationPower( LeftOperand.DeepCopy(), new OperationSubtraction(RightOperand.DeepCopy(), new Constant(1)) ) ), LeftOperand.Derivate() )); } else if (RightOperand.ContainsVariable()) { return(new OperationMultiplication( new OperationMultiplication( this.DeepCopy(), new FunctionLn(LeftOperand.DeepCopy()) ), RightOperand.Derivate() )); } else { return(new Constant(0)); } }
public IExpressionNode DeepCopy() => new OperationDivision(LeftOperand.DeepCopy(), RightOperand.DeepCopy());
public IExpressionNode DeepCopy() => new OperationMultiplication(LeftOperand.DeepCopy(), RightOperand.DeepCopy());