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); }
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); } }
private Node combineNodes(Node cleanNode1, Node cleanNode2) { if (cleanNode1 is NodeNumber && !(cleanNode2 is NodeNumber)) { if (((NodeNumber)cleanNode1).Number == 0) { return(cleanNode2); } } if (cleanNode2 is NodeNumber && !(cleanNode1 is NodeNumber)) { if (((NodeNumber)cleanNode2).Number == 0) { return(cleanNode1); } } if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber) { if (((NodeNumber)cleanNode1).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(cleanNode2.ContainsX(), cleanNode2.ContainsP(), ((NodeNumber)cleanNode2).Number); return(newNumberNode); } else if (((NodeNumber)cleanNode2).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(cleanNode1.ContainsX(), cleanNode1.ContainsP(), ((NodeNumber)cleanNode1).Number); return(newNumberNode); } else if (cleanNode1.ContainsX() == cleanNode2.ContainsX()) { if (cleanNode1.ContainsP() == cleanNode2.ContainsP()) { Node newNumberNode; newNumberNode = new NodeNumber(cleanNode1.ContainsX(), cleanNode1.ContainsP(), ((NodeNumber)cleanNode1).Number + ((NodeNumber)cleanNode2).Number); return(newNumberNode); } } } //none of the nodes are numbers, so they need to be cleaned! Node trash; if (cleanNode1 is NodeLN && cleanNode2 is NodeLN) { Node nodeln = new NodeLN(); Node nodeTim = new NodeTimes(); nodeTim.AddNode1(cleanNode1.Node1); nodeTim.AddNode2(cleanNode2.Node1); nodeln.AddNode1(nodeTim); nodeln.MakeNodeClean(null, out trash); return(nodeln); } return(null); }
public override Node GetDerivative() //O = original, D = derivative { Node negativenode = new NodeNumber(false, false, -1); Node node1O = node1.Clone(); Node node1D = node1.GetDerivative(); Node sinnode = new NodeSin(); Node timesnode = new NodeTimes(); Node timesnode2 = new NodeTimes(); timesnode2.AddNode1(negativenode); timesnode2.AddNode2(timesnode); timesnode.AddNode1(sinnode); timesnode.AddNode2(node1D); sinnode.AddNode1(node1O); return(timesnode2); }
public override Node MakeNodeClean(Node prevNodeNumber, out Node replacementNode) { Node garbage; if (node1 is NodeLN && node2 is NodeLN) //exception { Node nodeDiv = new NodeDivision(); Node nodeln = new NodeLN(); nodeln.AddNode1(nodeDiv); nodeDiv.AddNode1(Node1.Node1); nodeDiv.AddNode2(node2.Node1); nodeln.MakeNodeClean(null, out garbage); replacementNode = null; return(nodeln); } else { Node nodePlus = new NodePlus(); nodePlus.AddNode1(node1); if (node2 is NodeNumber) { ((NodeNumber)node2).SwapPositivity(); nodePlus.AddNode2(node2); } else if (node2 is NodeMinus) { Node newNode2 = node2.MakeNodeClean(null, out garbage); //node2 is now nodeplus ((NodePlus)newNode2).SwapPositivity(); nodePlus.AddNode2(newNode2); } else { Node nodeTimes = new NodeTimes(); Node nodeNumber = new NodeNumber(false, false, -1); nodeTimes.AddNode1(nodeNumber); nodeTimes.AddNode2(node2); nodePlus.AddNode2(nodeTimes); } replacementNode = null; nodePlus.MakeNodeClean(null, out garbage); return(nodePlus); } }
public void SwapPositivity() { if (node1 is NodeNumber) { ((NodeNumber)node1).SwapPositivity(); } else if (node1 is NodeMinus) { ((NodeMinus)node1).SwapPositivity(); } else if (node1 is NodePlus) { ((NodePlus)node1).SwapPositivity(); } else { Node nodeTimes = new NodeTimes(); Node nodeNumber = new NodeNumber(false, false, -1); nodeTimes.AddNode1(nodeNumber); nodeTimes.AddNode2(node1); this.AddNode1(nodeTimes); } if (node2 is NodeNumber) { ((NodeNumber)node2).SwapPositivity(); } else if (node2 is NodeMinus) { ((NodeMinus)node2).SwapPositivity(); } else if (node2 is NodePlus) { ((NodePlus)node2).SwapPositivity(); } else { Node nodeTimes = new NodeTimes(); Node nodeNumber = new NodeNumber(false, false, -1); nodeTimes.AddNode1(nodeNumber); nodeTimes.AddNode2(node2); this.AddNode2(nodeTimes); } }
private Node GetPolyNode(List <double> polyPoints) { //create polyfunction nodes List <NodePolyFunction> polyFunctions = new List <NodePolyFunction>(); int totalPoints = polyPoints.Count / 2; int nOrder = totalPoints - 1; for (int i = 0; i < polyPoints.Count; i += 2) //each point { double ans = polyPoints[i + 1]; List <double> xValues = new List <double>(); for (int j = nOrder; j >= 0; j--) //each x value { double x = polyPoints[i]; if (x == 0) { x = 0.000000001; } xValues.Add(Math.Pow(x, j)); } NodePolyFunction newNode = new NodePolyFunction(xValues, ans); polyFunctions.Add(newNode); } //transform polyfunctions into ideal functions (1a + 0 + 0 = ?, 0 + 1b + 0 = ? etc.) for (int i = 0; i < polyFunctions.Count; i++) //make current x value equal to 1 of this function { double divNumber; divNumber = polyFunctions[i].xValues[i]; polyFunctions[i].divideBy(divNumber); for (int j = 0; j < polyFunctions.Count; j++)//make current x value equal to 0 of other functions { if (j != i) { double timesNumber; timesNumber = polyFunctions[j].xValues[i]; polyFunctions[j].minusBy(timesNumber, polyFunctions[i]); } } } //make the return node out of the ideal (poly) functions Node headNode = new NodePlus(); Node tempNode = headNode; for (int i = 0; i < polyFunctions.Count(); i++) { Node nodePow = new NodePower(); Node nodeTim = new NodeTimes(); Node nodeNum = new NodeNumber(false, false, polyFunctions[i].answer); Node nodeNumLow = new NodeNumber(true, false, 1); Node nodeNumUp = new NodeNumber(false, false, nOrder - i); nodeTim.AddNode1(nodeNum); nodeTim.AddNode2(nodePow); nodePow.AddNode1(nodeNumLow); nodePow.AddNode2(nodeNumUp); if (i <= polyFunctions.Count - 3) //normal { tempNode.AddNode1(nodeTim); Node nodePlus = new NodePlus(); tempNode.AddNode2(nodePlus); tempNode = nodePlus; } else if (i <= polyFunctions.Count - 2) //one before last one { tempNode.AddNode1(nodeTim); } else if (i <= polyFunctions.Count - 1) //last one { tempNode.AddNode2(nodeTim); } } return(headNode); }
private Node setNodesLoop() { Node headNode = null; string tempNumber = null; //number in parameter (input) int parameter = 0; //parameter section bool negativeNumber = false; bool decimalNumber = false; bool tempNumberContainsX = false; bool tempNumberContainsP = false; while (enteredSum.Length != 0) { switch (enteredSum[0]) { case '(': //start of 1st parameter if (headNode == null) { throw new Exception("No action found for ("); } parameter = 1; remove1stChar(); break; case ')': //end of final parameter, CREATE FINAL NODE AND RETURN HEADNODE if (headNode == null) { throw new Exception("No action found for )"); } if (parameter == 1) //1st parameter input here--------------------- { if (!action2Parameter.Contains(headNode.GetLocalString().ToArray <char>()[0])) { if (headNode.Node1 == null) { if (tempNumber != null) //input was a number { Node node1 = new NodeNumber(tempNumberContainsX, tempNumberContainsP, stringToDouble(tempNumber)); headNode.AddNode1(node1); tempNumberContainsX = false; tempNumberContainsP = false; tempNumber = null; remove1stChar(); return(headNode); } else { throw new Exception("parameter 1 is missing for " + headNode.GetLocalString()); } } else //action already has input { remove1stChar(); return(headNode); } } else { throw new Exception(headNode.GetLocalString() + " requires 2 parameters"); } } //2nd parameter input here--------------------- if (!action1Parameter.Contains(headNode.GetLocalString().ToArray <char>()[0])) { if (tempNumber != null && headNode.Node2 == null) //2nd parameter was a number { Node node2 = new NodeNumber(tempNumberContainsX, tempNumberContainsP, stringToDouble(tempNumber)); headNode.AddNode2(node2); tempNumberContainsX = false; tempNumberContainsP = false; tempNumber = null; remove1stChar(); return(headNode); } else if (headNode.Node2 != null) //2nd parameter was a function { remove1stChar(); return(headNode); } else { throw new Exception("parameter 2 is missing for " + headNode.GetLocalString()); } } else { throw new Exception(headNode.GetLocalString() + " requires 1 parameter, not 2"); } case ',': //end of 1st parameter and start of 2nd parameter if (headNode == null) { throw new Exception("No action found for ,"); } if (parameter == 0) { throw new Exception("Parameter 1 for " + headNode.GetLocalString() + " has to be between ( and ,"); } if (parameter == 2) { throw new Exception(headNode.GetLocalString() + " can not have more than 2 parameters"); } if (tempNumber != null && headNode.Node1 == null) //1st parameter was a number { Node node1 = new NodeNumber(tempNumberContainsX, tempNumberContainsP, stringToDouble(tempNumber)); headNode.AddNode1(node1); tempNumberContainsX = false; tempNumberContainsP = false; tempNumber = null; remove1stChar(); } else if (headNode.Node1 != null) //1st parameter was a action { remove1stChar(); } else { throw new Exception("parameter 1 is missing for " + headNode.GetLocalString()); } parameter = 2; break; case '.': //point for decimal numbers if (decimalNumber) { throw new Exception("A number can not have more than 1 dot"); } decimalNumber = true; remove1stChar(); break; case 'x': if (tempNumberContainsX) { throw new Exception("A number can only have one x"); } if (tempNumber != null) { tempNumberContainsX = true; } else { if (negativeNumber) { tempNumber = "-1"; tempNumberContainsX = true; } else { tempNumber = "1"; tempNumberContainsX = true; } negativeNumber = false; } remove1stChar(); break; case 'p': //pi if (tempNumberContainsP) { throw new Exception("A number can only have one p"); } if (tempNumber != null) { tempNumberContainsP = true; } else { if (negativeNumber) { tempNumber = "-1"; tempNumberContainsP = true; } else { tempNumber = "1"; tempNumberContainsP = true; } negativeNumber = false; } remove1stChar(); break; default: //it's must be a number OR an action int number; if (int.TryParse(enteredSum[0].ToString(), out number)) //NUMBER { if (tempNumberContainsP || tempNumberContainsX) { throw new Exception("No numbers can be placed after PI or X"); } else //You can add the number { if (tempNumber != null) //tempnumber already has a value { if (decimalNumber) { if (tempNumber.Contains(".")) { throw new Exception("A number can not have more than 1 dot"); } tempNumber += "." + number.ToString(); decimalNumber = false; } else { tempNumber += number.ToString(); } } else //tempnumber is not set yet { if (decimalNumber) { if (negativeNumber) { tempNumber = "-0." + number.ToString(); } else { tempNumber = "0." + number.ToString(); } decimalNumber = false; } else { if (negativeNumber) { tempNumber = "-" + number.ToString(); } else { tempNumber = number.ToString(); } } negativeNumber = false; } remove1stChar(); } } else if (action1Parameter.Contains(enteredSum[0]) || action2Parameter.Contains(enteredSum[0])) //ACTION { if (enteredSum[0] == '-' && (int.TryParse(enteredSum[1].ToString(), out number) || enteredSum[1] == 'p' || enteredSum[1] == 'x')) //negative number check { negativeNumber = true; remove1stChar(); } else if (parameter == 0) { headNode = getNodeForChar(enteredSum[0]); remove1stChar(); } else if (parameter == 1) { Node node1 = setNodesLoop(); headNode.AddNode1(node1); } else if (parameter == 2) { Node node2 = setNodesLoop(); headNode.AddNode2(node2); } } else //SOMETHING UNKNOWN/USELESS { remove1stChar(); } break; } } if (parameter == 0 && tempNumber != null && headNode == null) //function was only a number { headNode = new NodeNumber(tempNumberContainsX, tempNumberContainsP, stringToDouble(tempNumber)); return(headNode); } if (headNode != null) //node hasn't been closed { throw new Exception("Node is incomplete for " + headNode.GetLocalString()); } return(null); }
public override Node GetDerivative() //O = original, D = derivative { NodeNumber nodeNumber = new NodeNumber(false, false, 0); return(nodeNumber); }
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, bool bothAreUpperNodes) { if (!bothAreUpperNodes) { if (!(cleanNode1 is NodeNumber) && cleanNode2 is NodeNumber) { if (((NodeNumber)cleanNode2).Number == 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 1); return(newNumberNode); } } if (cleanNode1 is NodeNumber && cleanNode2 is NodeNumber) { if (((NodeNumber)cleanNode2).Number == 0 && ((NodeNumber)cleanNode1).Number != 0) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, 1); return(newNumberNode); } else if (!cleanNode1.ContainsX() && !cleanNode2.ContainsX()) { if (!cleanNode1.ContainsP() && !cleanNode2.ContainsP()) { Node newNumberNode; newNumberNode = new NodeNumber(false, false, Math.Pow(((NodeNumber)cleanNode1).Number, ((NodeNumber)cleanNode2).Number)); return(newNumberNode); } } else if (((NodeNumber)cleanNode2).Number == 1) { return(cleanNode1); } } //none of the nodes are numbers, so they need to be cleaned! Node trash; if (cleanNode1 is NodeLN) { Node nodePow = new NodePower(); nodePow.AddNode1(cleanNode1.Node1); nodePow.AddNode2(cleanNode2); cleanNode1.AddNode1(nodePow); cleanNode1.MakeNodeClean(null, out trash); return(cleanNode1); } if (cleanNode1 is NodeE) { Node nodePlus = new NodePlus(); nodePlus.AddNode1(cleanNode1.Node1); nodePlus.AddNode2(cleanNode2); cleanNode1.AddNode1(nodePlus); cleanNode1.MakeNodeClean(null, out trash); return(cleanNode1); } } else //both are upper nodes, try to multiply time if possible (this is a copy of nodeTimes.combineNodes() method) { 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); } } } } return(null); }
public override Node Clone() { Node newNode = new NodeNumber(containsX, containsP, number); return(newNode); }
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); }