Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Data Fields
ArithSortRef Class Reference

Arithmetic. More...

+ Inheritance diagram for ArithSortRef:

Public Member Functions

def is_real
 
def is_int
 
def subsort
 
def cast
 
- Public Member Functions inherited from SortRef
def as_ast
 
def get_id
 
def kind
 
def subsort
 
def cast
 
def name
 
def __eq__
 
def __ne__
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__
 
def __str__
 
def __repr__
 
def sexpr
 
def as_ast
 
def get_id
 
def ctx_ref
 
def eq
 
def translate
 
def hash
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

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.

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

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

1860  def is_real(self):
1861  """Return `True` if `self` is of the sort Real.
1862 
1863  >>> x = Real('x')
1864  >>> x.is_real()
1865  True
1866  >>> (x + 1).is_real()
1867  True
1868  >>> x = Int('x')
1869  >>> x.is_real()
1870  False
1871  """
1872  return self.kind() == Z3_REAL_SORT
def kind
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.

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

Field Documentation

ctx

Definition at line 1907 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ApplyResult.as_expr(), Fixedpoint.assert_exprs(), ApplyResult.convert_model(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), Optimize.model(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.query(), Fixedpoint.set(), Optimize.set(), Tactic.solver(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), and Fixedpoint.update_rule().