public static RPN.Node increaseExponentTwo(RPN.Node node) { RPN.Node temp = node.Children[0].Children[0]; temp.Replace(temp.GetNumber() + 1); node.Children[1].Children[0].Remove(new RPN.Node(1)); return(node); }
public static RPN.Node Power(RPN.Node node) { RPN.Node power = node[3, 0].Clone(); RPN.Node end = node[0].Clone(); RPN.Token _fac = new RPN.Token("!", 1, RPN.Type.Operator); RPN.Token _total = new RPN.Token("total", (int)power.GetNumber(), RPN.Type.Function); RPN.Node total = new RPN.Node(_total); double max = power.GetNumber(); RPN.Node numeratorAddition = new RPN.Node(power.GetNumber() + 1); //(p + 1) for (int i = 0; i <= max; i++) { RPN.Node j = new RPN.Node(i); RPN.Node subtraction = new RPN.Node(power.GetNumber() - j.GetNumber()); //(p - j) RPN.Node addition = new RPN.Node(subtraction.GetNumber() + 1); //(p - j + 1) RPN.Node exponent = new Pow(end.Clone(), addition.Clone()); //n^(p - j + 1) RPN.Node bernoulli = Sum.getBernoulliNumber(i); //B(j) RPN.Node numerator = new RPN.Node(new RPN.Node[] { numeratorAddition.Clone() }, _fac); //(p + 1)! RPN.Node denominatorFactorial = new RPN.Node(new RPN.Node[] { addition.Clone() }, _fac); //(p - j + 1)! RPN.Node jFactorial = new RPN.Node(new RPN.Node[] { j.Clone() }, _fac); //j! RPN.Node denominator = new Mul(jFactorial, denominatorFactorial); // j! * (p - j + 1)! RPN.Node fraction = new Div(numerator, denominator); RPN.Node negativeOneExponent = new Pow(new RPN.Node(-1), j.Clone()); //(-1)^j RPN.Node multiplication = new Mul(new Mul(negativeOneExponent, fraction), new Mul(bernoulli, exponent)); total.AddChild(multiplication); } return(new Div(total, numeratorAddition.Clone())); }