Z3
Public Member Functions | Data Fields
ArithSortRef Class Reference

Arithmetic. More...

+ Inheritance diagram for ArithSortRef:

Public Member Functions

def is_real (self)
 
def is_int (self)
 
def is_bool (self)
 
def subsort (self, other)
 
def cast (self, val)
 
- Public Member Functions inherited from SortRef
def as_ast (self)
 
def get_id (self)
 
def kind (self)
 
def subsort (self, other)
 
def cast (self, val)
 
def name (self)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__ (self)
 
def __deepcopy__
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def __copy__ (self)
 
def hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Data Fields

 ctx
 
- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Arithmetic.

Real and Integer sorts.

Definition at line 2284 of file z3py.py.

Member Function Documentation

def cast (   self,
  val 
)
Try to cast `val` as an Integer or Real.

>>> IntSort().cast(10)
10
>>> is_int(IntSort().cast(10))
True
>>> is_int(10)
False
>>> RealSort().cast(10)
10
>>> is_real(RealSort().cast(10))
True

Definition at line 2322 of file z3py.py.

2322  def cast(self, val):
2323  """Try to cast `val` as an Integer or Real.
2324 
2325  >>> IntSort().cast(10)
2326  10
2327  >>> is_int(IntSort().cast(10))
2328  True
2329  >>> is_int(10)
2330  False
2331  >>> RealSort().cast(10)
2332  10
2333  >>> is_real(RealSort().cast(10))
2334  True
2335  """
2336  if is_expr(val):
2337  if z3_debug():
2338  _z3_assert(self.ctx == val.ctx, "Context mismatch")
2339  val_s = val.sort()
2340  if self.eq(val_s):
2341  return val
2342  if val_s.is_int() and self.is_real():
2343  return ToReal(val)
2344  if val_s.is_bool() and self.is_int():
2345  return If(val, 1, 0)
2346  if val_s.is_bool() and self.is_real():
2347  return ToReal(If(val, 1, 0))
2348  if z3_debug():
2349  _z3_assert(False, "Z3 Integer/Real expression expected")
2350  else:
2351  if self.is_int():
2352  return IntVal(val, self.ctx)
2353  if self.is_real():
2354  return RealVal(val, self.ctx)
2355  if z3_debug():
2356  msg = "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2357  _z3_assert(False, msg % self)
2358 
2359 
def is_int(self)
Definition: z3py.py:2301
def If
Definition: z3py.py:1377
def is_real(self)
Definition: z3py.py:2287
def eq(self, other)
Definition: z3py.py:404
def ToReal(a)
Definition: z3py.py:3350
def z3_debug()
Definition: z3py.py:62
def cast(self, val)
Definition: z3py.py:2322
def RealVal
Definition: z3py.py:3192
def is_expr(a)
Definition: z3py.py:1238
def IntVal
Definition: z3py.py:3180
def is_bool (   self)

Definition at line 2315 of file z3py.py.

2315  def is_bool(self):
2316  return False
2317 
def is_bool(self)
Definition: z3py.py:2315
def is_int (   self)
Return `True` if `self` is of the sort Integer.

>>> x = Int('x')
>>> x.is_int()
True
>>> (x + 1).is_int()
True
>>> x = Real('x')
>>> x.is_int()
False

Definition at line 2301 of file z3py.py.

Referenced by ArithSortRef.cast().

2301  def is_int(self):
2302  """Return `True` if `self` is of the sort Integer.
2303 
2304  >>> x = Int('x')
2305  >>> x.is_int()
2306  True
2307  >>> (x + 1).is_int()
2308  True
2309  >>> x = Real('x')
2310  >>> x.is_int()
2311  False
2312  """
2313  return self.kind() == Z3_INT_SORT
2314 
def is_int(self)
Definition: z3py.py:2301
def kind(self)
Definition: z3py.py:568
def is_real (   self)
Return `True` if `self` is of the sort Real.

>>> x = Real('x')
>>> x.is_real()
True
>>> (x + 1).is_real()
True
>>> x = Int('x')
>>> x.is_real()
False

Definition at line 2287 of file z3py.py.

Referenced by ArithSortRef.cast().

2287  def is_real(self):
2288  """Return `True` if `self` is of the sort Real.
2289 
2290  >>> x = Real('x')
2291  >>> x.is_real()
2292  True
2293  >>> (x + 1).is_real()
2294  True
2295  >>> x = Int('x')
2296  >>> x.is_real()
2297  False
2298  """
2299  return self.kind() == Z3_REAL_SORT
2300 
def is_real(self)
Definition: z3py.py:2287
def kind(self)
Definition: z3py.py:568
def subsort (   self,
  other 
)
Return `True` if `self` is a subsort of `other`.

Definition at line 2318 of file z3py.py.

2318  def subsort(self, other):
2319  """Return `True` if `self` is a subsort of `other`."""
2320  return self.is_int() and is_arith_sort(other) and other.is_real()
2321 
def is_arith_sort(s)
Definition: z3py.py:2360
def is_int(self)
Definition: z3py.py:2301
def subsort(self, other)
Definition: z3py.py:2318

Field Documentation

ctx