Exemplo n.º 1
0
        /// <inheritdoc/>
        public override ExpNode Execute(MultiplicationOperNode node)
        {
            // TODO: Sinusoidal u substitutions
            // TODO: Constants recognitions for v
            Differentiator differentiator = new(_variable);

            // \int{u'vwx} = uvwx - \int{uv'wx} - \int{uvw'x} - \int{uvwx'}
            int partCount = node.ChildCount - 1;

            // Get u and du
            ExpNode du = node.GetChild(partCount);
            ExpNode u  = du.Clone().Execute(this);

            // Get dvs and vs
            ExpNode[] dvs = new ExpNode[partCount];
            ExpNode[] vs  = new ExpNode[partCount];
            for (int i = 0; i < partCount; i++)
            {
                vs[i]  = node.GetChild(i);
                dvs[i] = vs[i].Clone().Execute(differentiator);
            }

            AdditionOperNode aNode = new();

            // u*vs
            MultiplicationOperNode mNode = new();

            mNode.AddChild(u.Clone());
            for (int i = 0; i < partCount; i++)
            {
                mNode.AddChild(vs[i].Clone());
            }
            aNode.AddChild(mNode);

            // Combinatoric integrals
            for (int i = 0; i < partCount; i++)
            {
                IntegralOperNode intNode = new();
                mNode            = new MultiplicationOperNode();
                intNode.Variable = new VarValueNode(_variable);
                mNode.AddChild(u.Clone());
                for (int j = 0; j < partCount; j++)
                {
                    if (i == j)
                    {
                        mNode.AddChild(dvs[j].Clone());
                    }
                    else
                    {
                        mNode.AddChild(vs[j].Clone());
                    }
                }
                intNode.AddChild(mNode);
                aNode.AddChild(QuickOpers.Negative(intNode));
            }

            return(aNode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Splits an <see cref="MultiplicationOperNode"/> into terms and simplifies by common terms.
        /// </summary>
        /// <param name="node">The <see cref="MultiplicationOperNode"/> to simplify.</param>
        /// <param name="simplifier">The <see cref="Simplifier"/> calling.</param>
        /// <returns>The resulting <see cref="ExpNode"/>.</returns>
        public static MultiplicationOperNode SimplfiyMTerms(MultiplicationOperNode node, Simplifier simplifier)
        {
            SortedSet <MultiplicativeTerm> mTerms = new();

            for (int i = 0; i < node.ChildCount; i++)
            {
                MultiplicativeTerm mTerm = new(node.GetChild(i));

                if (mTerms.TryGetValue(mTerm, out MultiplicativeTerm existingMTerm))
                {
                    existingMTerm.AddToExponent(mTerm, simplifier);
                }
                else
                {
                    mTerms.Add(mTerm);
                }
            }

            node.ClearChildren();
            foreach (var term in mTerms)
            {
                node.AddChild(term.AsExpNode());
            }

            return(node);
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override ExpNode Execute(MultiplicationOperNode node)
        {
            double valueProg = 1;

            for (int i = 0; i < node.ChildCount; i++)
            {
                ExpNode simpleChild = node.GetChild(i).Execute(this);

                if (simpleChild is NumericalValueNode nvNode)
                {
                    valueProg *= nvNode.DoubleValue;
                    node.RemoveChild(i);
                    i--;
                }
                else if (simpleChild is MultiplicationOperNode mNode)
                {
                    mNode.TransferChildren(node);
                    node.RemoveChild(i);
                    i--;
                }
                else
                {
                    node.ReplaceChild(simpleChild, i);
                }
            }

            // Anything multiplied by 0, is zero
            if (valueProg == 0)
            {
                return(QuickOpers.MakeNumericalNode(0));
            }

            if (node.ChildCount == 0 || valueProg != 1)
            {
                node.AddChild(QuickOpers.MakeNumericalNode(valueProg));
            }

            MultiplicationHelpers.SimplfiyMTerms(node, this);

            if (node.ChildCount == 0)
            {
                return(QuickOpers.MakeNumericalNode(0));
            }
            else if (node.ChildCount == 1)
            {
                return(node.GetChild(0));
            }

            node = MultiplicationHelpers.MultiplyScalarTensor(node, this);

            if (node == null)
            {
                return(node);
            }

            return(MultiplicationHelpers.Distribute(node, this));
        }