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__ (self, ast, ctx=None)
 
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 1856 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 1891 of file z3py.py.

1891  def cast(self, val):
1892  """Try to cast `val` as an Integer or Real.
1893 
1894  >>> IntSort().cast(10)
1895  10
1896  >>> is_int(IntSort().cast(10))
1897  True
1898  >>> is_int(10)
1899  False
1900  >>> RealSort().cast(10)
1901  10
1902  >>> is_real(RealSort().cast(10))
1903  True
1904  """
1905  if is_expr(val):
1906  if __debug__:
1907  _z3_assert(self.ctx == val.ctx, "Context mismatch")
1908  val_s = val.sort()
1909  if self.eq(val_s):
1910  return val
1911  if val_s.is_int() and self.is_real():
1912  return ToReal(val)
1913  if val_s.is_bool() and self.is_int():
1914  return If(val, 1, 0)
1915  if val_s.is_bool() and self.is_real():
1916  return ToReal(If(val, 1, 0))
1917  if __debug__:
1918  _z3_assert(False, "Z3 Integer/Real expression expected" )
1919  else:
1920  if self.is_int():
1921  return IntVal(val, self.ctx)
1922  if self.is_real():
1923  return RealVal(val, self.ctx)
1924  if __debug__:
1925  _z3_assert(False, "int, long, float, string (numeral), or Z3 Integer/Real expression expected")
1926 
def is_int(self)
Definition: z3py.py:1873
def IntVal(val, ctx=None)
Definition: z3py.py:2686
def If(a, b, c, ctx=None)
Definition: z3py.py:1092
def RealVal(val, ctx=None)
Definition: z3py.py:2697
def is_real(self)
Definition: z3py.py:1859
def eq(self, other)
Definition: z3py.py:308
def ToReal(a)
Definition: z3py.py:2842
def cast(self, val)
Definition: z3py.py:1891
def is_expr(a)
Definition: z3py.py:961
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 1873 of file z3py.py.

Referenced by ArithSortRef.cast().

1873  def is_int(self):
1874  """Return `True` if `self` is of the sort Integer.
1875 
1876  >>> x = Int('x')
1877  >>> x.is_int()
1878  True
1879  >>> (x + 1).is_int()
1880  True
1881  >>> x = Real('x')
1882  >>> x.is_int()
1883  False
1884  """
1885  return self.kind() == Z3_INT_SORT
1886 
def is_int(self)
Definition: z3py.py:1873
def kind(self)
Definition: z3py.py:457
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 1859 of file z3py.py.

Referenced by ArithSortRef.cast().

1859  def is_real(self):
1860  """Return `True` if `self` is of the sort Real.
1861 
1862  >>> x = Real('x')
1863  >>> x.is_real()
1864  True
1865  >>> (x + 1).is_real()
1866  True
1867  >>> x = Int('x')
1868  >>> x.is_real()
1869  False
1870  """
1871  return self.kind() == Z3_REAL_SORT
1872 
def is_real(self)
Definition: z3py.py:1859
def kind(self)
Definition: z3py.py:457
def subsort (   self,
  other 
)
Return `True` if `self` is a subsort of `other`.

Definition at line 1887 of file z3py.py.

1887  def subsort(self, other):
1888  """Return `True` if `self` is a subsort of `other`."""
1889  return self.is_int() and is_arith_sort(other) and other.is_real()
1890 
def is_arith_sort(s)
Definition: z3py.py:1927
def is_int(self)
Definition: z3py.py:1873
def subsort(self, other)
Definition: z3py.py:1887

Field Documentation

ctx