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)
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__ (self)
 
def __str__ (self)
 
def __repr__ (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 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 1835 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 1870 of file z3py.py.

1870  def cast(self, val):
1871  """Try to cast `val` as an Integer or Real.
1872 
1873  >>> IntSort().cast(10)
1874  10
1875  >>> is_int(IntSort().cast(10))
1876  True
1877  >>> is_int(10)
1878  False
1879  >>> RealSort().cast(10)
1880  10
1881  >>> is_real(RealSort().cast(10))
1882  True
1883  """
1884  if is_expr(val):
1885  if __debug__:
1886  _z3_assert(self.ctx == val.ctx, "Context mismatch")
1887  val_s = val.sort()
1888  if self.eq(val_s):
1889  return val
1890  if val_s.is_int() and self.is_real():
1891  return ToReal(val)
1892  if __debug__:
1893  _z3_assert(False, "Z3 Integer/Real expression expected" )
1894  else:
1895  if self.is_int():
1896  return IntVal(val, self.ctx)
1897  if self.is_real():
1898  return RealVal(val, self.ctx)
1899  if __debug__:
1900  _z3_assert(False, "int, long, float, string (numeral), or Z3 Integer/Real expression expected")
1901 
def is_int(self)
Definition: z3py.py:1852
def is_real(self)
Definition: z3py.py:1838
def eq(self, other)
Definition: z3py.py:309
def ToReal(a)
Definition: z3py.py:2817
def cast(self, val)
Definition: z3py.py:1870
def RealVal
Definition: z3py.py:2672
def is_expr(a)
Definition: z3py.py:950
def IntVal
Definition: z3py.py:2661
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 1852 of file z3py.py.

Referenced by ArithSortRef.cast().

1852  def is_int(self):
1853  """Return `True` if `self` is of the sort Integer.
1854 
1855  >>> x = Int('x')
1856  >>> x.is_int()
1857  True
1858  >>> (x + 1).is_int()
1859  True
1860  >>> x = Real('x')
1861  >>> x.is_int()
1862  False
1863  """
1864  return self.kind() == Z3_INT_SORT
1865 
def is_int(self)
Definition: z3py.py:1852
def kind(self)
Definition: z3py.py:459
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 1838 of file z3py.py.

Referenced by ArithSortRef.cast().

1838  def is_real(self):
1839  """Return `True` if `self` is of the sort Real.
1840 
1841  >>> x = Real('x')
1842  >>> x.is_real()
1843  True
1844  >>> (x + 1).is_real()
1845  True
1846  >>> x = Int('x')
1847  >>> x.is_real()
1848  False
1849  """
1850  return self.kind() == Z3_REAL_SORT
1851 
def is_real(self)
Definition: z3py.py:1838
def kind(self)
Definition: z3py.py:459
def subsort (   self,
  other 
)
Return `True` if `self` is a subsort of `other`.

Definition at line 1866 of file z3py.py.

1866  def subsort(self, other):
1867  """Return `True` if `self` is a subsort of `other`."""
1868  return self.is_int() and is_arith_sort(other) and other.is_real()
1869 
def is_arith_sort(s)
Definition: z3py.py:1902
def is_int(self)
Definition: z3py.py:1852
def subsort(self, other)
Definition: z3py.py:1866

Field Documentation

ctx