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 __gt__ (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)
 
def py_value (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 2431 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 2469 of file z3py.py.

2469  def cast(self, val):
2470  """Try to cast `val` as an Integer or Real.
2471 
2472  >>> IntSort().cast(10)
2473  10
2474  >>> is_int(IntSort().cast(10))
2475  True
2476  >>> is_int(10)
2477  False
2478  >>> RealSort().cast(10)
2479  10
2480  >>> is_real(RealSort().cast(10))
2481  True
2482  """
2483  if is_expr(val):
2484  if z3_debug():
2485  _z3_assert(self.ctx == val.ctx, "Context mismatch")
2486  val_s = val.sort()
2487  if self.eq(val_s):
2488  return val
2489  if val_s.is_int() and self.is_real():
2490  return ToReal(val)
2491  if val_s.is_bool() and self.is_int():
2492  return If(val, 1, 0)
2493  if val_s.is_bool() and self.is_real():
2494  return ToReal(If(val, 1, 0))
2495  if z3_debug():
2496  _z3_assert(False, "Z3 Integer/Real expression expected")
2497  else:
2498  if self.is_int():
2499  return IntVal(val, self.ctx)
2500  if self.is_real():
2501  return RealVal(val, self.ctx)
2502  if z3_debug():
2503  msg = "int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2504  _z3_assert(False, msg % self)
2505 
2506 
def is_int(self)
Definition: z3py.py:2448
def If
Definition: z3py.py:1484
def is_real(self)
Definition: z3py.py:2434
def eq(self, other)
Definition: z3py.py:431
def ToReal(a)
Definition: z3py.py:3518
def z3_debug()
Definition: z3py.py:70
def cast(self, val)
Definition: z3py.py:2469
def RealVal
Definition: z3py.py:3356
def is_expr(a)
Definition: z3py.py:1345
def IntVal
Definition: z3py.py:3344
def is_bool (   self)

Definition at line 2462 of file z3py.py.

2462  def is_bool(self):
2463  return False
2464 
def is_bool(self)
Definition: z3py.py:2462
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 2448 of file z3py.py.

Referenced by ArithSortRef.cast().

2448  def is_int(self):
2449  """Return `True` if `self` is of the sort Integer.
2450 
2451  >>> x = Int('x')
2452  >>> x.is_int()
2453  True
2454  >>> (x + 1).is_int()
2455  True
2456  >>> x = Real('x')
2457  >>> x.is_int()
2458  False
2459  """
2460  return self.kind() == Z3_INT_SORT
2461 
def is_int(self)
Definition: z3py.py:2448
def kind(self)
Definition: z3py.py:599
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 2434 of file z3py.py.

Referenced by ArithSortRef.cast().

2434  def is_real(self):
2435  """Return `True` if `self` is of the sort Real.
2436 
2437  >>> x = Real('x')
2438  >>> x.is_real()
2439  True
2440  >>> (x + 1).is_real()
2441  True
2442  >>> x = Int('x')
2443  >>> x.is_real()
2444  False
2445  """
2446  return self.kind() == Z3_REAL_SORT
2447 
def is_real(self)
Definition: z3py.py:2434
def kind(self)
Definition: z3py.py:599
def subsort (   self,
  other 
)
Return `True` if `self` is a subsort of `other`.

Definition at line 2465 of file z3py.py.

2465  def subsort(self, other):
2466  """Return `True` if `self` is a subsort of `other`."""
2467  return self.is_int() and is_arith_sort(other) and other.is_real()
2468 
def is_int(self)
Definition: z3py.py:2448
def is_arith_sort
Definition: z3py.py:2507
def subsort(self, other)
Definition: z3py.py:2465

Field Documentation

ctx