示例#1
0
        public override Node GetDerivative() //O = original, D = derivative
        {
            Node nodeDiv     = new NodeDivision();
            Node nodeTimes1  = new NodeTimes();
            Node nodeTimes2  = new NodeTimes();
            Node nodeMin     = new NodeMinus();
            Node nodePow     = new NodePower();
            Node nodeNumber2 = new NodeNumber(false, false, 2);
            Node node1D      = node1.GetDerivative();
            Node node2D      = Node2.GetDerivative();
            Node node1O      = node1.Clone();
            Node node2O      = node2.Clone();
            Node node2O2     = node2.Clone();

            //divison (head node)
            nodeDiv.AddNode1(nodeMin);
            nodeDiv.AddNode2(nodePow);

            //creating upper part of division
            nodeMin.AddNode1(nodeTimes1);
            nodeMin.AddNode2(nodeTimes2);

            nodeTimes1.AddNode1(node1D);
            nodeTimes1.AddNode2(node2O);

            nodeTimes2.AddNode1(node1O);
            nodeTimes2.AddNode2(node2D);

            //creating lower part of division
            nodePow.AddNode1(node2O2);
            nodePow.AddNode2(nodeNumber2);

            return(nodeDiv);
        }
示例#2
0
        public override Node GetDerivative() //O = original, D = derivative
        {
            Node node1O1    = node1.Clone();
            Node node1D     = node1.GetDerivative();
            Node node2O1    = node2.Clone();
            Node nodeTimes1 = new NodeTimes();
            Node nodeTimes2 = new NodeTimes();

            if (node2.ContainsX())
            {
                Node thisNode   = this.Clone();
                Node node1O2    = node1.Clone();
                Node node2D     = node2.GetDerivative();
                Node nodePlus   = new NodePlus();
                Node nodeLN     = new NodeLN();
                Node nodeDiv    = new NodeDivision();
                Node nodeTimes3 = new NodeTimes();

                nodeTimes3.AddNode1(thisNode);
                nodeTimes3.AddNode2(nodePlus);

                nodePlus.AddNode1(nodeTimes1);
                nodePlus.AddNode2(nodeTimes2);

                nodeTimes1.AddNode1(node1D);
                nodeTimes1.AddNode2(nodeDiv);

                nodeDiv.AddNode1(node2O1);
                nodeDiv.AddNode2(node1O1);

                nodeTimes2.AddNode1(node2D);
                nodeTimes2.AddNode2(nodeLN);

                nodeLN.AddNode1(node1O2);

                return(nodeTimes3);
            }
            else
            {
                Node node2O2       = node2.Clone();
                Node nodeNumberOne = new NodeNumber(false, false, 1);
                Node nodeMin       = new NodeMinus();
                Node nodePow       = new NodePower();

                nodeTimes2.AddNode1(nodePow);
                nodeTimes2.AddNode2(nodeTimes1);

                nodeTimes1.AddNode1(node2O1);
                nodeTimes1.AddNode2(node1D);

                nodePow.AddNode1(node1O1);
                nodePow.AddNode2(nodeMin);

                nodeMin.AddNode1(node2O2);
                nodeMin.AddNode2(nodeNumberOne);

                return(nodeTimes2);
            }
        }
示例#3
0
        public override Node Clone()
        {
            Node newNode  = new NodeMinus();
            Node newNode1 = node1.Clone();
            Node newNode2 = node2.Clone();

            newNode.AddNode1(newNode1);
            newNode.AddNode2(newNode2);
            return(newNode);
        }
示例#4
0
        public override Node GetDerivative() //O = original, D = derivative
        {
            Node nodeMin = new NodeMinus();
            Node node1D  = node1.GetDerivative();
            Node node2D  = Node2.GetDerivative();

            nodeMin.AddNode1(node1D);
            nodeMin.AddNode2(node2D);

            return(nodeMin);
        }
示例#5
0
        private Node combineNodes(Node cleanNode1, Node cleanNode2)
        {
            if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber)
            {
                int negOrPos = 0;
                if (((NodeNumber)cleanNode1).Number == ((NodeNumber)cleanNode2).Number)
                {
                    negOrPos = 1;
                }
                else if (((NodeNumber)cleanNode1).Number == -1 * ((NodeNumber)cleanNode2).Number)
                {
                    negOrPos = -1;
                }
                if (negOrPos != 0)
                {
                    if (cleanNode1.ContainsX() == cleanNode2.ContainsX() && cleanNode1.ContainsP() == cleanNode2.ContainsP())
                    {
                        Node newNumberNode;
                        newNumberNode = new NodeNumber(false, false, negOrPos);
                        return(newNumberNode);
                    }
                    else if (cleanNode1.ContainsX() == cleanNode2.ContainsX() && !cleanNode2.ContainsP())
                    {
                        Node newNumberNode;
                        newNumberNode = new NodeNumber(false, true, negOrPos);
                        return(newNumberNode);
                    }
                    else if (cleanNode1.ContainsP() == cleanNode2.ContainsP() && !cleanNode2.ContainsX())
                    {
                        Node newNumberNode;
                        newNumberNode = new NodeNumber(true, false, negOrPos);
                        return(newNumberNode);
                    }
                }
            }
            if (cleanNode1 is NodeNumber)
            {
                if (((NodeNumber)cleanNode1).Number == 0)
                {
                    Node newNumberNode;
                    newNumberNode = new NodeNumber(false, false, 0);
                    return(newNumberNode);
                }
                if (cleanNode2 is NodeFactorial)
                {
                    if (((NodeNumber)cleanNode1).Number == ((NodeFactorial)cleanNode2).GetValueForX(0))
                    {
                        return(new NodeNumber(cleanNode1.ContainsX(), cleanNode1.ContainsP(), 1));
                    }
                }
            }
            if (cleanNode2 is NodeNumber)
            {
                if (cleanNode1 is NodeFactorial)
                {
                    if (((NodeNumber)cleanNode2).Number == ((NodeFactorial)cleanNode1).GetValueForX(0))
                    {
                        Node nodeDiv = new NodeDivision();
                        nodeDiv.AddNode1(new NodeNumber(false, false, 1));
                        nodeDiv.AddNode2(new NodeNumber(cleanNode2.ContainsX(), cleanNode2.ContainsP(), 1));
                        return(nodeDiv);
                    }
                }
                if (((NodeNumber)cleanNode2).Number == 1 && !cleanNode2.ContainsP() && !cleanNode2.ContainsX())
                {
                    return(cleanNode1);
                }
            }

            //none of the nodes are numbers, so they need to be cleaned!
            Node trash;

            if (cleanNode2.SameAs(cleanNode1))
            {
                Node nodeNum = new NodeNumber(false, false, 1);
                return(nodeNum);
            }
            if ((cleanNode1 is NodePower && cleanNode2 is NodePower) || (cleanNode1 is NodeE && cleanNode2 is NodeE) || (cleanNode1 is NodeTimes && cleanNode2 is NodeTimes))
            {
                if (!(cleanNode1 is NodeE))
                {
                    if (cleanNode1.Node1.SameAs(cleanNode2.Node1))
                    {
                        if (cleanNode1 is NodePower)
                        {
                            NodePower nodePow = new NodePower();
                            NodeMinus nodeMin = new NodeMinus();
                            nodePow.AddNode1(cleanNode1.Node1);
                            nodePow.AddNode2(nodeMin);
                            nodeMin.AddNode1(cleanNode1.Node2);
                            nodeMin.AddNode2(cleanNode2.Node2);
                            nodePow.MakeNodeClean(null, out trash);
                            return(nodePow);
                        }
                        if (cleanNode1 is NodeTimes)
                        {
                            NodeDivision nodeDiv = new NodeDivision();
                            nodeDiv.AddNode1(cleanNode1.Node2);
                            nodeDiv.AddNode2(cleanNode2.Node2);
                            nodeDiv.MakeNodeClean(null, out trash);
                            return(nodeDiv);
                        }
                    }
                    else if (cleanNode1.Node1.SameAs(cleanNode2.Node2))
                    {
                        if (cleanNode1 is NodeTimes)
                        {
                            NodeDivision nodeDiv = new NodeDivision();
                            nodeDiv.AddNode1(cleanNode1.Node2);
                            nodeDiv.AddNode2(cleanNode2.Node1);
                            nodeDiv.MakeNodeClean(null, out trash);
                            return(nodeDiv);
                        }
                    }
                    else if (cleanNode1.Node2.SameAs(cleanNode2.Node1))
                    {
                        if (cleanNode1 is NodeTimes)
                        {
                            NodeDivision nodeDiv = new NodeDivision();
                            nodeDiv.AddNode1(cleanNode1.Node1);
                            nodeDiv.AddNode2(cleanNode2.Node2);
                            nodeDiv.MakeNodeClean(null, out trash);
                            return(nodeDiv);
                        }
                    }
                    else if (cleanNode1.Node2.SameAs(cleanNode2.Node2))
                    {
                        if (cleanNode1 is NodeTimes)
                        {
                            NodeDivision nodeDiv = new NodeDivision();
                            nodeDiv.AddNode1(cleanNode1.Node1);
                            nodeDiv.AddNode2(cleanNode2.Node1);
                            nodeDiv.MakeNodeClean(null, out trash);
                            return(nodeDiv);
                        }
                    }
                }
                else
                {
                    NodeE     nodeE   = new NodeE();
                    NodeMinus nodeMin = new NodeMinus();
                    nodeE.AddNode1(nodeMin);
                    nodeMin.AddNode1(cleanNode1.Node1);
                    nodeMin.AddNode2(cleanNode2.Node1);
                    nodeE.MakeNodeClean(null, out trash);
                    return(nodeE);
                }
            }

            return(null);
        }