Exemplo n.º 1
0
        public static RPN.Node LogExponentExpansion(RPN.Node node)
        {
            RPN.Node exponent = node.Children[0];
            RPN.Node baseNode = exponent.Children[1];
            RPN.Node power    = exponent.Children[0];

            RPN.Node log = new RPN.Node(new[] { baseNode.Clone(), node.Children[1] }, new RPN.Token("log", 2, RPN.Type.Function));
            return(new Mul(power, log));
        }
Exemplo n.º 2
0
Arquivo: Sum.cs Projeto: 65001/AbMath
        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()));
        }
Exemplo n.º 3
0
        public static RPN.Node expressionTimesDivision(RPN.Node node)
        {
            RPN.Node division;
            RPN.Node expression;
            if (node.Children[0].IsDivision())
            {
                division   = node.Children[0];
                expression = node.Children[1];
            }
            else
            {
                division   = node.Children[1];
                expression = node.Children[0];
            }

            RPN.Node numerator = division.Children[1];
            RPN.Node multiply  = new Mul(expression.Clone(), numerator.Clone());
            numerator.Remove(multiply);
            expression.Remove(new RPN.Node(1));
            return(node);
        }
Exemplo n.º 4
0
Arquivo: Sum.cs Projeto: 65001/AbMath
 public static RPN.Node Propagation(RPN.Node node)
 {
     RPN.Node sum = new RPN.Node(new RPN.Node[] { node[0].Clone(), node[1].Clone(), node[2].Clone(), node[3, 1].Clone() }, _sum);
     node.Replace(node[3], node[3, 0]); //This saves a simplification step later
     return(new Add(node.Clone(), sum));
 }