Exemplo n.º 1
0
        public TermNumericalExpr SimplyGroupPow()
        {
            var exprs = new ExprCollection <NumericalExpr>(Exprs);
            var pDone = false;

            for (var i = 0; i < exprs.Count; i++)
            {
                for (var j = i + 1; j < exprs.Count;)
                {
                    var e1    = exprs[i];
                    var _base = e1.GetPowBase();

                    if (_base is NumericalExpr n1)
                    {
                        var e2 = exprs[j];
                        var n2 = e2.GetPowBase();

                        if (n1 == n2)
                        {
                            var exp1 = e1.GetPowExp();

                            if (exp1 != null)
                            {
                                var exp2 = e2.GetPowExp();

                                if (exp2 != null)
                                {
                                    var nexp = (exp1 + exp2).SimplySumNumericals();

                                    if (nexp != null)
                                    {
                                        exprs[i] = MakePow(n1, nexp);

                                        pDone = true;
                                        exprs.RemoveAt(j);

                                        continue;
                                    }
                                }
                            }
                        }

                        j++;
                    }
                }
            }

            if (!pDone)
            {
                return(null);
            }

            return(new TermNumericalExpr(Sign, exprs));
        }
Exemplo n.º 2
0
        public override NumericalExpr SimplySumNumericals()
        {
            var exprs = new ExprCollection <NumericalExpr>(Exprs);
            var pDone = false;

            for (var i = 0; i < exprs.Count; i++)
            {
                var e1   = SimplyOrExpr(e => e.SimplySumNumericals(), exprs[i]);
                var num1 = e1.SimplyToInteger();

                if (num1 != null)
                {
                    var pDone1 = false;

                    for (var j = i + 1; j < exprs.Count;)
                    {
                        var e2   = SimplyOrExpr(e => e.SimplySumNumericals(), exprs[j]);
                        var num2 = e2.SimplyToInteger();

                        if (num2 != null)
                        {
                            num1 += num2;

                            pDone = pDone1 = true;
                            exprs.RemoveAt(j);

                            continue;
                        }
                        j++;
                    }

                    if (pDone1)
                    {
                        exprs[i] = MakeNumber(num1);
                    }
                }
            }

            return
                ((!pDone)
                    ? null
                    : (exprs.Count == 1)
                        ? exprs.First()
                        : MakeSum(exprs));
        }