Пример #1
0
        //This is what we want our end result to look like

        /**
         * AST Simplified Infix : {a-f,b-f,c-f,d-f}
         * list [13 | 4 | Function | True | 7c563ab9893e876c49fcc316a78e6b6d]
         * ├─- [12 | 2 | Operator | False | 281861c9d3dfdecb3ddffdc8930cb63e]
         * │  ├─f [11 | 0 | Variable | False | 8fa14cdd754f91cc6554c9e71929cce7]
         * │  └─d [10 | 0 | Variable | False | 8277e0910d750195b448797616e091ad]
         * ├─- [9 | 2 | Operator | False | 4ad3c11a7d979f70332d8dbc8ab33f43]
         * │  ├─f [8 | 0 | Variable | False | 8fa14cdd754f91cc6554c9e71929cce7]
         * │  └─c [7 | 0 | Variable | False | 4a8a08f09d37b73795649038408b5f33]
         * ├─- [6 | 2 | Operator | False | df41b29ce151a927ae80c6df545518c1]
         * │  ├─f [5 | 0 | Variable | False | 8fa14cdd754f91cc6554c9e71929cce7]
         * │  └─b [4 | 0 | Variable | False | 92eb5ffee6ae2fec3ad71c777531578f]
         * └─- [3 | 2 | Operator | False | d5c11d5ccf6dc77d16eaf012db8813fa]
         *    ├─f [2 | 0 | Variable | False | 8fa14cdd754f91cc6554c9e71929cce7]
         *    └─a [1 | 0 | Variable | False | 0cc175b9c0f1b6a831c399e269772661]
         */
        public static RPN.Node VectorFrontScalarBack(RPN.Node node)
        {
            RPN.Token operatorToken = node.Token;



            return(node);
        }
Пример #2
0
        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()));
        }