예제 #1
0
 public static void Add(IEnumerable <int> values)
 {
     foreach (var value in values)
     {
         rational.Add(Rational.For(value));
     }
 }
예제 #2
0
            public override bool VisitMultiply(TExpr left, TExpr right, TExpr original, Dummy data)
            {
                Polynomial <TVar, TExpr> l, r;
                var lBuilt = Build(left, out l);
                var rBuilt = Build(right, out r);

                if (lBuilt && rBuilt)
                {
                    long   kLeft, kRight;
                    object mult;
                    if (l.IsIntConstant(out kLeft) && r.IsIntConstant(out kRight) &&
                        EvaluateArithmeticWithOverflow.TryBinary(
                            Decoder.TypeOf(original), ExpressionOperator.Mult, kLeft, kRight, out mult))
                    {
                        var longValue = mult.ConvertToLong();
                        if (longValue.HasValue)
                        {
                            var monomial = Monomial <TVar> .From(Rational.For(longValue.Value));

                            return(true.With(new Polynomial <TVar, TExpr> (monomial), out poly));
                        }
                    }
                    return(TryToPolynomialHelperForMultiplication(l, r, out poly));
                }
                return(false);
            }
예제 #3
0
            public override bool VisitSizeOf(TExpr expr, Dummy data)
            {
                int sizeOf;

                if (!Decoder.TrySizeOf(expr, out sizeOf))
                {
                    return(false);
                }

                return(true.With(new Polynomial <TVar, TExpr> (Monomial <TVar> .From(Rational.For(sizeOf))), out poly));
            }
예제 #4
0
            public override bool VisitSubtraction(TExpr left, TExpr right, TExpr original, Dummy data)
            {
                Polynomial <TVar, TExpr> polyLeft, polyRight;

                if (!Build(left, out polyLeft) || !Build(right, out polyRight))
                {
                    return(false);
                }

                long   kLeft, kRight;
                object subtraction;

                if (polyLeft.IsIntConstant(out kLeft) && polyRight.IsIntConstant(out kRight) &&
                    EvaluateArithmeticWithOverflow.TryBinary(Decoder.TypeOf(original), ExpressionOperator.Sub, kLeft, kRight, out subtraction))
                {
                    var longValue = subtraction.ConvertToLong();
                    if (longValue.HasValue)
                    {
                        return(true.With(new Polynomial <TVar, TExpr> (Monomial <TVar> .From(Rational.For(longValue.Value))), out poly));
                    }
                }
                return(TryToPolynomialHelperForSubtraction(polyLeft, polyRight, out poly));
            }