public override Node Clone() { Node newNode = new NodeE(); Node newNode1 = node1.Clone(); newNode.AddNode1(newNode1); return(newNode); }
public override Node GetDerivative() //O = original, D = derivative { Node node1O = node1.Clone(); Node node1D = node1.GetDerivative(); Node nodeE = new NodeE(); Node nodeTimes = new NodeTimes(); nodeTimes.AddNode1(nodeE); nodeTimes.AddNode2(node1D); nodeE.AddNode1(node1O); return(nodeTimes); }
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); }
private Node combineNodes(Node cleanNode1, Node cleanNode2) { if (cleanNode1 is NodeNumber && !(cleanNode2 is NodeNumber)) { if (((NodeNumber)cleanNode1).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 0); return(newNumberNode); } else if (((NodeNumber)cleanNode1).Number == 1 && !cleanNode1.ContainsX() && !cleanNode1.ContainsP()) { return(cleanNode2); } else if (cleanNode2 is NodePower) { if (cleanNode2.Node1 is NodeNumber) { if (((NodeNumber)cleanNode1).ContainsX() == ((NodeNumber)cleanNode2.Node1).ContainsX()) { //check if nodePower.Node1(lower) has only 1x and node has (somenumber)x } } } } if (cleanNode2 is NodeNumber && !(cleanNode1 is NodeNumber)) { if (((NodeNumber)cleanNode2).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 0); return(newNumberNode); } else if (((NodeNumber)cleanNode2).Number == 1 && !cleanNode2.ContainsX() && !cleanNode2.ContainsP()) { return(cleanNode1); } } if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber) { if (cleanNode1.ContainsX() != cleanNode2.ContainsX()) //one has X { if (cleanNode1.ContainsP() != cleanNode2.ContainsP()) //one has P { Node newNumberNode; newNumberNode = new NodeNumber(true, true, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (!cleanNode1.ContainsP()) //both have not P { Node newNumberNode; newNumberNode = new NodeNumber(true, false, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } else if (!cleanNode1.ContainsX()) //both have not X { if (cleanNode1.ContainsP() != cleanNode2.ContainsP()) //one has P { Node newNumberNode; newNumberNode = new NodeNumber(false, true, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (!cleanNode1.ContainsP()) //both have not P { Node newNumberNode; newNumberNode = new NodeNumber(false, false, ((NodeNumber)cleanNode1).Number * ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } } //none of the nodes are numbers, so they need to be cleaned! Node trash; if (cleanNode2.SameAs(cleanNode1)) { Node nodePow = new NodePower(); nodePow.AddNode1(cleanNode1); nodePow.AddNode2(new NodeNumber(false, false, 2)); nodePow.MakeNodeClean(null, out trash); return(nodePow); } if ((cleanNode1 is NodePower && cleanNode2 is NodePower) || (cleanNode1 is NodeE && cleanNode2 is NodeE) || (cleanNode1 is NodeLN && cleanNode2 is NodeLN)) { if (cleanNode1.Node1.SameAs(cleanNode2.Node1)) { if (cleanNode1 is NodePower) { Node nodePow = new NodePower(); Node nodePlus = new NodePlus(); nodePow.AddNode1(cleanNode1.Node1); nodePow.AddNode2(nodePlus); nodePlus.AddNode1(cleanNode1.Node2); nodePlus.AddNode2(cleanNode2.Node2); nodePow.MakeNodeClean(null, out trash); return(nodePow); } } if (cleanNode1 is NodeE) { Node nodeE = new NodeE(); Node nodePlus = new NodePlus(); nodeE.AddNode1(nodePlus); nodePlus.AddNode1(cleanNode1.Node1); nodePlus.AddNode2(cleanNode2.Node1); nodeE.MakeNodeClean(null, out trash); return(nodeE); } } return(null); }