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 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 2255 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 2290 of file z3py.py.

2290  def cast(self, val):
2291  """Try to cast `val` as an Integer or Real.
2292 
2293  >>> IntSort().cast(10)
2294  10
2295  >>> is_int(IntSort().cast(10))
2296  True
2297  >>> is_int(10)
2298  False
2299  >>> RealSort().cast(10)
2300  10
2301  >>> is_real(RealSort().cast(10))
2302  True
2303  """
2304  if is_expr(val):
2305  if z3_debug():
2306  _z3_assert(self.ctx == val.ctx, "Context mismatch")
2307  val_s = val.sort()
2308  if self.eq(val_s):
2309  return val
2310  if val_s.is_int() and self.is_real():
2311  return ToReal(val)
2312  if val_s.is_bool() and self.is_int():
2313  return If(val, 1, 0)
2314  if val_s.is_bool() and self.is_real():
2315  return ToReal(If(val, 1, 0))
2316  if z3_debug():
2317  _z3_assert(False, "Z3 Integer/Real expression expected")
2318  else:
2319  if self.is_int():
2320  return IntVal(val, self.ctx)
2321  if self.is_real():
2322  return RealVal(val, self.ctx)
2323  if z3_debug():
2324  msg = "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2325  _z3_assert(False, msg % self)
2326 
2327 
def is_int(self)
Definition: z3py.py:2272
def If
Definition: z3py.py:1351
def is_real(self)
Definition: z3py.py:2258
def eq(self, other)
Definition: z3py.py:403
def ToReal(a)
Definition: z3py.py:3322
def z3_debug()
Definition: z3py.py:64
def cast(self, val)
Definition: z3py.py:2290
def RealVal
Definition: z3py.py:3164
def is_expr(a)
Definition: z3py.py:1212
def IntVal
Definition: z3py.py:3152
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 2272 of file z3py.py.

Referenced by ArithSortRef.cast().

2272  def is_int(self):
2273  """Return `True` if `self` is of the sort Integer.
2274 
2275  >>> x = Int('x')
2276  >>> x.is_int()
2277  True
2278  >>> (x + 1).is_int()
2279  True
2280  >>> x = Real('x')
2281  >>> x.is_int()
2282  False
2283  """
2284  return self.kind() == Z3_INT_SORT
2285 
def is_int(self)
Definition: z3py.py:2272
def kind(self)
Definition: z3py.py:567
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 2258 of file z3py.py.

Referenced by ArithSortRef.cast().

2258  def is_real(self):
2259  """Return `True` if `self` is of the sort Real.
2260 
2261  >>> x = Real('x')
2262  >>> x.is_real()
2263  True
2264  >>> (x + 1).is_real()
2265  True
2266  >>> x = Int('x')
2267  >>> x.is_real()
2268  False
2269  """
2270  return self.kind() == Z3_REAL_SORT
2271 
def is_real(self)
Definition: z3py.py:2258
def kind(self)
Definition: z3py.py:567
def subsort (   self,
  other 
)
Return `True` if `self` is a subsort of `other`.

Definition at line 2286 of file z3py.py.

2286  def subsort(self, other):
2287  """Return `True` if `self` is a subsort of `other`."""
2288  return self.is_int() and is_arith_sort(other) and other.is_real()
2289 
def is_arith_sort(s)
Definition: z3py.py:2328
def is_int(self)
Definition: z3py.py:2272
def subsort(self, other)
Definition: z3py.py:2286

Field Documentation

ctx