예제 #1
0
 private Rational(BigNum num, BigNum den)
 {
   Contract.Assert(den.Signum > 0);
   Contract.Assert(num == BigNum.ZERO || num.Gcd(den) == BigNum.ONE);
   numerator = num;
   denominator = den;
 }
예제 #2
0
 public static bool TryParse(string v, out BigNum res) {
   try {
     res = BigNum.FromString(v);
     return true;
   } catch (FormatException) {
     res = ZERO;
     return false;
   }
 }
예제 #3
0
파일: BigNum.cs 프로젝트: omaragb/tlp182
 public static bool TryParse(string v, out BigNum res)
 {
     try {
         res = BigNum.FromString(v);
         return(true);
     } catch (FormatException) {
         res = ZERO;
         return(false);
     }
 }
예제 #4
0
파일: BigNum.cs 프로젝트: CrystalMei/boogie
 public int CompareTo(BigNum that)
 {
     if (this.val == that.val)
     {
         return(0);
     }
     if (this.val < that.val)
     {
         return(-1);
     }
     return(1);
 }
예제 #5
0
 public static Rational FromBignums(BigNum num, BigNum den) {
   Contract.Assert(!den.IsZero);
   if (num == BigNum.ZERO)
     return ZERO;
   if (den.Signum < 0) {
     den = -den;
     num = -num;
   }
   if (den == BigNum.ONE)
     return new Rational(num, den);
   var gcd = num.Gcd(den);
   if (gcd == BigNum.ONE)
     return new Rational(num, den);
   return new Rational(num / gcd, den / gcd);
 }
예제 #6
0
파일: BigNum.cs 프로젝트: CrystalMei/boogie
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is BigNum))
            {
                return(false);
            }

            BigNum other = (BigNum)obj;

            return(this.val == other.val);
        }
예제 #7
0
        public static Rational FromBignums(BigNum num, BigNum den)
        {
            Contract.Assert(!den.IsZero);
            if (num == BigNum.ZERO)
            {
                return(ZERO);
            }
            if (den.Signum < 0)
            {
                den = -den;
                num = -num;
            }
            if (den == BigNum.ONE)
            {
                return(new Rational(num, den));
            }
            var gcd = num.Gcd(den);

            if (gcd == BigNum.ONE)
            {
                return(new Rational(num, den));
            }
            return(new Rational(num / gcd, den / gcd));
        }
예제 #8
0
 public PureInteger(BigNum i) {
   this.val = i;
 }
예제 #9
0
      public static IntervalElement/*!*/ Factory(BigNum inf, BigNum sup) {
        Contract.Ensures(Contract.Result<IntervalElement>() != null);
        ExtendedInt/*!*/ i = ExtendedInt.Factory(inf);
        ExtendedInt/*!*/ s = ExtendedInt.Factory(sup);

        return Factory(i, s);
      }
예제 #10
0
 // Construct the interval [inf, sup]
 protected IntervalElement(BigNum infInt, BigNum supInt) {
   this.inf = ExtendedInt.Factory(infInt);
   this.sup = ExtendedInt.Factory(supInt);
   // base();   // to please the compiler...
 }
예제 #11
0
파일: Parser.cs 프로젝트: qunyanm/boogie
	void BvLit(out BigNum n, out int m) {
		Expect(2);
		int pos = t.val.IndexOf("bv");
		string a = t.val.Substring(0, pos);
		string b = t.val.Substring(pos + 2);
		try {
		 n = BigNum.FromString(a);
		 m = Convert.ToInt32(b);
		} catch (FormatException) {
		 this.SemErr("incorrectly formatted bitvector");
		 n = BigNum.ZERO;
		 m = 0;
		}
		
	}
예제 #12
0
파일: Parser.cs 프로젝트: qunyanm/boogie
 public BvBounds(IToken/*!*/ tok, BigNum lower, BigNum upper)
   : base(tok, /*immutable=*/ false) {
   Contract.Requires(tok != null);
   this.Lower = lower;
   this.Upper = upper;
 }
예제 #13
0
        //    int numerator;
        //    int denominator;


        // invariant: 0 < denominator || (numerator == 0 && denominator == 0);
        // invariant: numerator != 0 ==> gcd(abs(numerator),denominator) == 1;
        // invariant: numerator == 0 ==> denominator == 1 || denominator == 0;

        public static Rational FromInt(int x)
        {
            return(FromBignum(BigNum.FromInt(x)));
        }
예제 #14
0
 IFunApp IIntExprFactory.Const(BigNum i) {
   throw new System.NotImplementedException();
 }
예제 #15
0
 IFunApp IIntExprFactory.Const(BigNum i) {
   Contract.Ensures(Contract.Result<IFunApp>() != null);
   throw new System.NotImplementedException();
 }
예제 #16
0
 public Elt(BigNum i) {
   this.domainValue = Value.Constant;
   this.constantValue = i;
 }
예제 #17
0
    /// <summary>
    /// Returns true if "expr" represents a constant integer expressions, in which case
    /// "z" returns as that integer.  Otherwise, returns false, in which case "z" should
    /// not be used by the caller.
    ///
    /// This method throws an System.ArithmeticException in the event that folding the
    /// constant expression results in an arithmetic overflow or division by zero.
    /// </summary>
    private bool Fold(IExpr/*!*/ expr, out BigNum z) {
      Contract.Requires(expr != null);
      IFunApp e = expr as IFunApp;
      if (e == null) {
        z = BigNum.ZERO;
        return false;
      }

      if (e.FunctionSymbol is IntSymbol) {
        z = ((IntSymbol)e.FunctionSymbol).Value;
        return true;

      } else if (e.FunctionSymbol.Equals(Int.Negate)) {
        IList/*<IExpr!>*//*!*/ args = e.Arguments;
        Contract.Assert(args != null);
        Contract.Assert(args.Count == 1);
        IExpr/*!*/ arg0 = (IExpr/*!*/)cce.NonNull(args[0]);

        if (Fold(arg0, out z)) {
          z = z.Neg;
          return true;
        }

      } else if (e.Arguments.Count == 2) {
        IExpr/*!*/ arg0 = (IExpr/*!*/)cce.NonNull(e.Arguments[0]);
        IExpr/*!*/ arg1 = (IExpr/*!*/)cce.NonNull(e.Arguments[1]);
        BigNum z0, z1;
        if (Fold(arg0, out z0) && Fold(arg1, out z1)) {
          if (e.FunctionSymbol.Equals(Int.Add)) {
            z = z0 + z1;
          } else if (e.FunctionSymbol.Equals(Int.Sub)) {
            z = z0 - z1;
          } else if (e.FunctionSymbol.Equals(Int.Mul)) {
            z = z0 * z1;
          } else if (e.FunctionSymbol.Equals(Int.Div)) {
            z = z0 / z1;
          } else if (e.FunctionSymbol.Equals(Int.Mod)) {
            z = z0 % z1;
          } else {
            z = BigNum.ZERO;
            return false;
          }
          return true;
        }
      }

      z = BigNum.ZERO;
      return false;
    }
예제 #18
0
 public bool AsConstant(out BigNum x) {
   if (terms == null) {
     x = constant;
     return true;
   } else {
     x = BigNum.FromInt(-70022);  // to please complier
     return false;
   }
 }
예제 #19
0
 public void Multiply(BigNum x) /* throws ArithmeticException */
 {
   if (x.IsZero) {
     constant = BigNum.ZERO;
     terms = null;
   } else {
     for (Term t = terms; t != null; t = t.next) {
       checked {
         t.coeff *= x;
       }
     }
     checked {
       constant *= x;
     }
   }
 }
예제 #20
0
    /// <summary>
    /// Adds "le" to "this".  Afterwards, "le" should not be used, because it will have been destroyed.
    /// </summary>
    /// <param name="le"></param>
    public void Add(LinearExpr/*!*/ le) /* throws ArithmeticException */
        {
      Contract.Requires(le != null);
      Contract.Requires(le != this);
      checked {
        constant += le.constant;
      }
      le.constant = BigNum.FromInt(-70029);  // "le" should no longer be used; assign it a strange value so that misuse is perhaps more easily detected

      // optimization:
      if (le.terms == null) {
        return;
      } else if (terms == null) {
        terms = le.terms;
        le.terms = null;
        return;
      }

      // merge the two term lists
      // Use a nested loop, which is quadratic in time complexity, but we hope the lists will be small
      Term newTerms = null;
      while (le.terms != null) {
        // take off next term from "le"
        Term t = le.terms;
        le.terms = t.next;
        t.next = null;

        for (Term u = terms; u != null; u = u.next) {
          if (u.var == t.var) {
            checked {
              u.coeff += t.coeff;
            }
            goto NextOuter;
          }
        }
        t.next = newTerms;
        newTerms = t;

      NextOuter:
        ;
      }

      // finally, include all non-0 terms
      while (terms != null) {
        // take off next term from "this"
        Term t = terms;
        terms = t.next;

        if (!t.coeff.IsZero) {
          t.next = newTerms;
          newTerms = t;
        }
      }
      terms = newTerms;
    }
예제 #21
0
 public LinearExpr(BigNum x) {
   constant = x;
 }
예제 #22
0
 /// <summary>
 /// Adds "x" to "this".
 /// </summary>
 /// <param name="x"></param>
 public void AddConstant(BigNum x) /* throws ArithmeticException */
 {
   checked {
     constant += x;
   }
 }
예제 #23
0
 public static IntSymbol/*!*/ Const(BigNum x) {
   Contract.Ensures(Contract.Result<IntSymbol>() != null);
   // We could cache things here, but for now we don't.
   return new IntSymbol(x);
 }
예제 #24
0
 public static Rational FromBignum(BigNum n)
 {
     return(new Rational(n, BigNum.ONE));
 }
예제 #25
0
 public static BvSymbol/*!*/ Const(BigNum x, int y) {
   Contract.Ensures(Contract.Result<BvSymbol>() != null);
   // We could cache things here, but for now we don't.
   return new BvSymbol(x, y);
 }
예제 #26
0
 public static Rational FromInts(int num, int den)
 {
     return(FromBignums(BigNum.FromInt(num), BigNum.FromInt(den)));
 }
예제 #27
0
 /// <summary>
 /// The intention is that this constructor be called only from the Int.Const method.
 /// </summary>
 internal IntSymbol(BigNum x)
   : base(cce.NonNull(x.ToString()), Int.Type) {
   this.Value = x;
 }
예제 #28
0
파일: Parser.cs 프로젝트: qunyanm/boogie
	void Nat(out BigNum n) {
		Expect(3);
		try {
		 n = BigNum.FromString(t.val);
		} catch (FormatException) {
		 this.SemErr("incorrectly formatted number");
		 n = BigNum.ZERO;
		}
		
	}
예제 #29
0
 /// <summary>
 /// The intention is that this constructor be called only from the Int.Const method.
 /// </summary>
 internal BvSymbol(BigNum x, int y)
   : base(x + "bv" + y, Bv.Type) {
   this.Value = x;
   this.Bits = y;
 }
예제 #30
0
 // Construct the inteval [val, val]
 protected IntervalElement(BigNum val) {
   this.inf = this.sup = ExtendedInt.Factory(val);
   // base();
 }
예제 #31
0
파일: Parser.cs 프로젝트: hesam/SketchSharp
 public BvBounds(IToken! tok, BigNum lower, BigNum upper) {
   base(tok);
   this.Lower = lower;
   this.Upper = upper;
 }
예제 #32
0
 public static IntervalElement/*!*/ Factory(BigNum i) {
   Contract.Ensures(Contract.Result<IntervalElement>() != null);
   return new IntervalElement(i);
 }
예제 #33
0
 public Term(BigNum coeff, IVariable/*!*/ var) {
   Contract.Requires(var != null);
   this.coeff = coeff;
   this.var = var;
   // base();
 }
예제 #34
0
 // Return the ExtendedInt corresponding to the value
 public static ExtendedInt/*!*/ Factory(BigNum val) {
   Contract.Ensures(Contract.Result<ExtendedInt>() != null);
   return new PureInteger(val);
 }
예제 #35
0
파일: BigNum.cs 프로젝트: CrystalMei/boogie
 public BigNum Min(BigNum that)
 {
     return(new BigNum(this.val <= that.val ? this.val : that.val));
 }
예제 #36
0
 public static Rational FromBignum(BigNum n)       
 {
   return new Rational(n, BigNum.ONE);
 }
예제 #37
0
파일: BigNum.cs 프로젝트: CrystalMei/boogie
 public BigNum Max(BigNum that)
 {
     return(new BigNum(this.val >= that.val ? this.val : that.val));
 }
예제 #38
0
 public LinearExpr(IVariable/*!*/ var) {
   Contract.Requires(var != null);
   constant = BigNum.ZERO;
   terms = new Term(BigNum.ONE, var);
 }
예제 #39
0
    public void Negate() /* throws ArithmeticException */
    {
      checked {
        constant = -constant;
      }

      for (Term t = terms; t != null; t = t.next) {
        checked {
          t.coeff = -t.coeff;
        }
      }
    }