Beispiel #1
0
 /// <inheritdoc/>
 public override ExpNode Execute(VarValueNode node)
 {
     if (node.Character != _variable.Character)
     {
         return(ConstantRule(node));
     }
     return(QuickOpers.Multiply(.5, QuickOpers.Pow(node, 2)));
 }
Beispiel #2
0
        /// <inheritdoc/>
        public override ExpNode Execute(RecipricalOperNode node)
        {
            node.Child = node.Child.Execute(this);

            if (node.Child is NumericalValueNode nvNode)
            {
                return(QuickOpers.MakeNumericalNode(1 / nvNode.DoubleValue));
            }

            return(QuickOpers.Pow(node.Child, -1).Execute(this));
        }
Beispiel #3
0
        /// <inheritdoc/>
        public override ExpNode Execute(PowOperNode node)
        {
            // TODO: Handle variable in exponent
            if (node.IsConstantBy(_variable))
            {
                return(QuickOpers.MakeNumericalNode(0));
            }

            var coefficient = node.RightChild;
            var @base       = node.LeftChild;
            var exponent    = QuickOpers.Add(-1, coefficient);

            return(QuickOpers.Multiply(coefficient, QuickOpers.Pow(@base, exponent)));
        }
Beispiel #4
0
        /// <inheritdoc/>
        public override ExpNode Execute(PowOperNode node)
        {
            // TODO: Handle variable in exponent
            if (node.IsConstantBy(_variable))
            {
                return(ConstantRule(node));
            }

            // Increment exponent, divide by exponent
            AdditionOperNode   exponent    = QuickOpers.Add(1, node.RightChild);
            RecipricalOperNode coefficient = QuickOpers.Reciprical(exponent.Clone());
            PowOperNode        @base       = QuickOpers.Pow(node.LeftChild, exponent);

            return(QuickOpers.Multiply(coefficient, @base));
        }
Beispiel #5
0
        /// <summary>
        /// Converts the <see cref="NumericalValueNode"/> back to an <see cref="ExpNode"/>.
        /// </summary>
        /// <returns>The <see cref="NumericalValueNode"/> as an <see cref="ExpNode"/>.</returns>
        public ExpNode AsExpNode()
        {
            if (_exponent is NumericalValueNode nvNode)
            {
                if (nvNode.DoubleValue == 0)
                {
                    return(QuickOpers.MakeNumericalNode(1));
                }
                else if (nvNode.DoubleValue == 1)
                {
                    return(_base);
                }
            }

            return(QuickOpers.Pow(_base, _exponent));
        }
Beispiel #6
0
 /// <summary>
 /// Applies the power distributive property.
 /// </summary>
 /// <param name="node">The <see cref="PowOperNode"/> to simplify.</param>
 /// <returns>The resuling <see cref="ExpNode"/>.</returns>
 public static ExpNode Distribute(PowOperNode node)
 {
     if (node.LeftChild is ParenthesisOperNode parNode)
     {
         // Child is parenthesis
         // Check for multiplication
         if (parNode.Child is MultiplicationOperNode mNode)
         {
             // Grand child is multiplication
             // Distribute
             for (int i = 0; i < mNode.ChildCount; i++)
             {
                 PowOperNode pow = QuickOpers.Pow(mNode.GetChild(i), node.RightChild.Clone());
                 mNode.ReplaceChild(pow, i);
             }
             return(mNode);
         }
     }
     return(node);
 }