Exemplo n.º 1
0
        public override Operand Differentiate()
        {
            // (f(x))^b where b is a natural number even.
            // The general power rule but combined with the
            // chain rule. b * (f(x))^(b - 1) * f'(x)

            // b
            Operand power = RightSuccessor.Copy();

            // b - 1
            Integer newPower = new Integer(Convert.ToDouble(power.Data) - 1);

            // f(x)^(b - 1)
            Power onePowerLess = new Power();

            onePowerLess.LeftSuccessor  = LeftSuccessor.Copy();
            onePowerLess.RightSuccessor = newPower;

            // f'
            Operand derivativeOfF = LeftSuccessor.Differentiate();

            // b * f(x)^(b - 1)
            Multiplication intermediaryResult = new Multiplication();

            intermediaryResult.LeftSuccessor  = power;
            intermediaryResult.RightSuccessor = onePowerLess;

            // (b * f(x)^(b - 1)) * f'
            Multiplication derivative = new Multiplication();

            derivative.LeftSuccessor  = intermediaryResult;
            derivative.RightSuccessor = derivativeOfF;

            return(derivative);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The quotient rule
        ///
        /// (f / g)' = (gf' - g'f) / g^2
        ///
        /// </summary>
        /// <returns>A division operator object holding respective expressions.</returns>
        public override Operand Differentiate()
        {
            // Create gf'
            Multiplication leftNumerator = new Multiplication();

            leftNumerator.LeftSuccessor  = RightSuccessor.Copy();
            leftNumerator.RightSuccessor = LeftSuccessor.Differentiate();

            // Create g'f
            Multiplication rightNumerator = new Multiplication();

            rightNumerator.LeftSuccessor  = RightSuccessor.Differentiate();
            rightNumerator.RightSuccessor = LeftSuccessor.Copy();

            // Create the numrator of previous terms gf' - g'f
            Subtraction derivativeNumerator = new Subtraction();

            derivativeNumerator.LeftSuccessor  = leftNumerator;
            derivativeNumerator.RightSuccessor = rightNumerator;

            // Create g^2 of a new copy of g.
            Power derivativeDenominator = new Power();

            derivativeDenominator.LeftSuccessor  = RightSuccessor.Copy();
            derivativeDenominator.RightSuccessor = new Integer(2);

            // Create the final result and assign. (f / g)' = (gf' - g'f) / g^2
            Division derivative = new Division();

            derivative.LeftSuccessor  = derivativeNumerator;
            derivative.RightSuccessor = derivativeDenominator;

            return(derivative);
        }
Exemplo n.º 3
0
        public override Operand Copy()
        {
            Cosine copy = new Cosine();

            copy.LeftSuccessor = LeftSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 4
0
        public override Operand Copy()
        {
            Exp copy = new Exp();

            copy.LeftSuccessor = LeftSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 5
0
        public override Operand Copy()
        {
            NaturalLog copy = new NaturalLog();

            copy.LeftSuccessor = LeftSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 6
0
        public override Operand Copy()
        {
            Multiplication copy = new Multiplication();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 7
0
        public override Operand Copy()
        {
            Division copy = new Division();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 8
0
        public override Proposition Copy()
        {
            Negation copy = new Negation();

            copy.LeftSuccessor = LeftSuccessor.Copy();

            return(copy);
        }
Exemplo n.º 9
0
        public override Operand Copy()
        {
            Subtraction copy = new Subtraction();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 10
0
        public override Operand Copy()
        {
            Power copy = new Power();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();
            return(copy);
        }
Exemplo n.º 11
0
        public override Proposition Copy()
        {
            BiImplication copy = new BiImplication();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();

            return(copy);
        }
Exemplo n.º 12
0
        public override Proposition Copy()
        {
            Nand copy = new Nand();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();

            return(copy);
        }
Exemplo n.º 13
0
        public override Proposition Copy()
        {
            Conjunction copy = new Conjunction();

            copy.LeftSuccessor  = LeftSuccessor.Copy();
            copy.RightSuccessor = RightSuccessor.Copy();

            return(copy);
        }
Exemplo n.º 14
0
        public override Operand Differentiate()
        {
            // (ln(u))' = 1 / u * u'
            Division leftExpression = new Division();

            leftExpression.LeftSuccessor = new Integer(1);
            // 1 / u
            leftExpression.RightSuccessor = LeftSuccessor.Copy();
            // u'
            Operand rightExpression = LeftSuccessor.Differentiate();

            // 1 / u * u'
            Multiplication derivative = new Multiplication();

            derivative.LeftSuccessor  = leftExpression;
            derivative.RightSuccessor = rightExpression;

            return(derivative);
        }
Exemplo n.º 15
0
        public override Operand Differentiate()
        {
            // Derivative of sin(u) = cos(u) * u'
            // c(u)
            Cosine outerDerivative = new Cosine();

            outerDerivative.LeftSuccessor = LeftSuccessor.Copy();

            // Now for u' we call it's differentiate method.
            Operand innerDerivative = LeftSuccessor.Differentiate();

            // c(u) * u'
            Multiplication derivative = new Multiplication();

            derivative.LeftSuccessor  = outerDerivative;
            derivative.RightSuccessor = innerDerivative;

            return(derivative);
        }
Exemplo n.º 16
0
        public override Proposition Copy()
        {
            Quantifier quantifier = null;

            if (Data == UniversalQuantifier.SYMBOL)
            {
                quantifier = new UniversalQuantifier(boundVariable);
            }
            else
            {
                quantifier = new ExistentialQuantifier(boundVariable);
            }

            foreach (char appliedVariable in alreadyAppliedReplacementCharacters)
            {
                quantifier.AddAppliedReplacementVariable(appliedVariable);
            }

            quantifier.LeftSuccessor = LeftSuccessor.Copy();
            return(quantifier);
        }
Exemplo n.º 17
0
        /// <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);
        }
Exemplo n.º 18
0
        public override Operand Differentiate()
        {
            // Apply the chain rule.
            // Derivative of cos(u) = -sin(u) * u'
            Sine rightOuterDerivativeExpression = new Sine();

            // s(u)
            rightOuterDerivativeExpression.LeftSuccessor = LeftSuccessor.Copy();
            // -1 * sin(u)
            Multiplication outerDerivative = new Multiplication();

            outerDerivative.LeftSuccessor  = new Integer(-1);
            outerDerivative.RightSuccessor = rightOuterDerivativeExpression;

            // Now for u' we call it's differentiate method.
            Operand innerDerivative = LeftSuccessor.Differentiate();

            Multiplication derivative = new Multiplication();

            derivative.LeftSuccessor  = outerDerivative;
            derivative.RightSuccessor = innerDerivative;
            return(derivative);
        }