def test_is_methods(self): from fractions import Fraction as pyFraction self.assertFalse(is_pysmt_fraction(4)) self.assertTrue(is_pysmt_fraction(Fraction(4))) self.assertFalse(is_pysmt_integer(4.0)) self.assertTrue(is_pysmt_integer(Integer(4))) self.assertTrue(is_python_integer(int(2))) if PY2: self.assertTrue(is_python_integer(long(2))) if HAS_GMPY: from gmpy2 import mpz self.assertTrue(is_python_integer(mpz(1))) if HAS_GMPY: from gmpy2 import mpz, mpq self.assertTrue(is_python_rational(mpz(1))) self.assertTrue(is_python_rational(mpq(1))) if PY2: self.assertTrue(is_python_rational(long(1))) self.assertTrue(is_python_rational(pyFraction(5))) self.assertTrue(is_python_rational(3)) self.assertTrue(is_python_boolean(True)) self.assertTrue(is_python_boolean(False))
def test_is_methods(self): self.assertFalse(is_pysmt_fraction(4)) self.assertTrue(is_pysmt_fraction(Fraction(4))) self.assertFalse(is_pysmt_integer(4.0)) self.assertTrue(is_pysmt_integer(Integer(4))) self.assertTrue(is_python_integer(int(2))) if PY2: self.assertTrue(is_python_integer(long(2))) if HAS_GMPY: from gmpy2 import mpz self.assertTrue(is_python_integer(mpz(1))) if HAS_GMPY: from gmpy2 import mpz, mpq self.assertTrue(is_python_rational(mpz(1))) self.assertTrue(is_python_rational(mpq(1))) if PY2: self.assertTrue(is_python_rational(long(1))) self.assertTrue(is_python_rational(pyFraction(5))) self.assertTrue(is_python_rational(3)) self.assertTrue(is_python_boolean(True)) self.assertTrue(is_python_boolean(False))
def Real(self, value): """ Returns a Real-type constant of the given value. value can be: - A Fraction(n,d) - A tuple (n,d) - A long or int n - A float - (Optionally) a mpq or mpz object """ if value in self.real_constants: return self.real_constants[value] if is_pysmt_fraction(value): val = value elif type(value) == tuple: val = Fraction(value[0], value[1]) elif is_python_rational(value): val = pysmt_fraction_from_rational(value) else: raise PysmtTypeError("Invalid type in constant. The type was:" + \ str(type(value))) n = self.create_node(node_type=op.REAL_CONSTANT, args=tuple(), payload=val) self.real_constants[value] = n return n
def _apply_infix(self, right, function, bv_function=None): if _env().enable_infix_notation: mgr = _mgr() # BVs # Default bv_function to function if bv_function is None: bv_function = function if _is_bv(self): if is_python_integer(right): right = mgr.BV(right, width=self.bv_width()) return bv_function(self, right) # Boolean, Integer and Arithmetic if is_python_boolean(right): right = mgr.Bool(right) elif is_python_integer(right): ty = self.get_type() if ty.is_real_type(): right = mgr.Real(right) else: right = mgr.Int(right) elif is_python_rational(right): right = mgr.Real(right) return function(self, right) else: raise Exception("Cannot use infix notation")
def _apply_infix(self, right, function, bv_function=None): if _env().enable_infix_notation: mgr = _mgr() # BVs # Default bv_function to function if bv_function is None: bv_function = function if _is_bv(self): if is_python_integer(right): right = mgr.BV(right, width=self.bv_width()) return bv_function(self, right) # Boolean, Integer and Arithmetic if is_python_boolean(right): right = mgr.Bool(right) elif is_python_integer(right): ty = self.get_type() if ty.is_real_type(): right = mgr.Real(right) else: right = mgr.Int(right) elif is_python_rational(right): right = mgr.Real(right) return function(self, right) else: raise PysmtModeError("Cannot use infix notation")