Z3
Public Member Functions
ArithRef Class Reference
+ Inheritance diagram for ArithRef:

Public Member Functions

def sort (self)
 
def is_int (self)
 
def is_real (self)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def __mul__ (self, other)
 
def __rmul__ (self, other)
 
def __sub__ (self, other)
 
def __rsub__ (self, other)
 
def __pow__ (self, other)
 
def __rpow__ (self, other)
 
def __div__ (self, other)
 
def __truediv__ (self, other)
 
def __rdiv__ (self, other)
 
def __rtruediv__ (self, other)
 
def __mod__ (self, other)
 
def __rmod__ (self, other)
 
def __neg__ (self)
 
def __pos__ (self)
 
def __le__ (self, other)
 
def __lt__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
- Public Member Functions inherited from ExprRef
def as_ast (self)
 
def get_id (self)
 
def sort (self)
 
def sort_kind (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 
def params (self)
 
def decl (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
def __deepcopy__ (self, memo={})
 
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 hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Integer and Real expressions.

Definition at line 2036 of file z3py.py.

Member Function Documentation

§ __add__()

def __add__ (   self,
  other 
)
Create the Z3 expression `self + other`.

>>> x = Int('x')
>>> y = Int('y')
>>> x + y
x + y
>>> (x + y).sort()
Int

Definition at line 2074 of file z3py.py.

2074  def __add__(self, other):
2075  """Create the Z3 expression `self + other`.
2076 
2077  >>> x = Int('x')
2078  >>> y = Int('y')
2079  >>> x + y
2080  x + y
2081  >>> (x + y).sort()
2082  Int
2083  """
2084  a, b = _coerce_exprs(self, other)
2085  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2086 

§ __div__()

def __div__ (   self,
  other 
)
Create the Z3 expression `other/self`.

>>> x = Int('x')
>>> y = Int('y')
>>> x/y
x/y
>>> (x/y).sort()
Int
>>> (x/y).sexpr()
'(div x y)'
>>> x = Real('x')
>>> y = Real('y')
>>> x/y
x/y
>>> (x/y).sort()
Real
>>> (x/y).sexpr()
'(/ x y)'

Definition at line 2171 of file z3py.py.

2171  def __div__(self, other):
2172  """Create the Z3 expression `other/self`.
2173 
2174  >>> x = Int('x')
2175  >>> y = Int('y')
2176  >>> x/y
2177  x/y
2178  >>> (x/y).sort()
2179  Int
2180  >>> (x/y).sexpr()
2181  '(div x y)'
2182  >>> x = Real('x')
2183  >>> y = Real('y')
2184  >>> x/y
2185  x/y
2186  >>> (x/y).sort()
2187  Real
2188  >>> (x/y).sexpr()
2189  '(/ x y)'
2190  """
2191  a, b = _coerce_exprs(self, other)
2192  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2193 
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.

§ __ge__()

def __ge__ (   self,
  other 
)
Create the Z3 expression `other >= self`.

>>> x, y = Ints('x y')
>>> x >= y
x >= y
>>> y = Real('y')
>>> x >= y
ToReal(x) >= y

Definition at line 2305 of file z3py.py.

2305  def __ge__(self, other):
2306  """Create the Z3 expression `other >= self`.
2307 
2308  >>> x, y = Ints('x y')
2309  >>> x >= y
2310  x >= y
2311  >>> y = Real('y')
2312  >>> x >= y
2313  ToReal(x) >= y
2314  """
2315  a, b = _coerce_exprs(self, other)
2316  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2317 
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.

§ __gt__()

def __gt__ (   self,
  other 
)
Create the Z3 expression `other > self`.

>>> x, y = Ints('x y')
>>> x > y
x > y
>>> y = Real('y')
>>> x > y
ToReal(x) > y

Definition at line 2292 of file z3py.py.

2292  def __gt__(self, other):
2293  """Create the Z3 expression `other > self`.
2294 
2295  >>> x, y = Ints('x y')
2296  >>> x > y
2297  x > y
2298  >>> y = Real('y')
2299  >>> x > y
2300  ToReal(x) > y
2301  """
2302  a, b = _coerce_exprs(self, other)
2303  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2304 
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.

§ __le__()

def __le__ (   self,
  other 
)
Create the Z3 expression `other <= self`.

>>> x, y = Ints('x y')
>>> x <= y
x <= y
>>> y = Real('y')
>>> x <= y
ToReal(x) <= y

Definition at line 2266 of file z3py.py.

2266  def __le__(self, other):
2267  """Create the Z3 expression `other <= self`.
2268 
2269  >>> x, y = Ints('x y')
2270  >>> x <= y
2271  x <= y
2272  >>> y = Real('y')
2273  >>> x <= y
2274  ToReal(x) <= y
2275  """
2276  a, b = _coerce_exprs(self, other)
2277  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2278 
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.

§ __lt__()

def __lt__ (   self,
  other 
)
Create the Z3 expression `other < self`.

>>> x, y = Ints('x y')
>>> x < y
x < y
>>> y = Real('y')
>>> x < y
ToReal(x) < y

Definition at line 2279 of file z3py.py.

2279  def __lt__(self, other):
2280  """Create the Z3 expression `other < self`.
2281 
2282  >>> x, y = Ints('x y')
2283  >>> x < y
2284  x < y
2285  >>> y = Real('y')
2286  >>> x < y
2287  ToReal(x) < y
2288  """
2289  a, b = _coerce_exprs(self, other)
2290  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2291 
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.

§ __mod__()

def __mod__ (   self,
  other 
)
Create the Z3 expression `other%self`.

>>> x = Int('x')
>>> y = Int('y')
>>> x % y
x%y
>>> simplify(IntVal(10) % IntVal(3))
1

Definition at line 2219 of file z3py.py.

2219  def __mod__(self, other):
2220  """Create the Z3 expression `other%self`.
2221 
2222  >>> x = Int('x')
2223  >>> y = Int('y')
2224  >>> x % y
2225  x%y
2226  >>> simplify(IntVal(10) % IntVal(3))
2227  1
2228  """
2229  a, b = _coerce_exprs(self, other)
2230  if __debug__:
2231  _z3_assert(a.is_int(), "Z3 integer expression expected")
2232  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2233 
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.

§ __mul__()

def __mul__ (   self,
  other 
)
Create the Z3 expression `self * other`.

>>> x = Real('x')
>>> y = Real('y')
>>> x * y
x*y
>>> (x * y).sort()
Real

Definition at line 2097 of file z3py.py.

2097  def __mul__(self, other):
2098  """Create the Z3 expression `self * other`.
2099 
2100  >>> x = Real('x')
2101  >>> y = Real('y')
2102  >>> x * y
2103  x*y
2104  >>> (x * y).sort()
2105  Real
2106  """
2107  a, b = _coerce_exprs(self, other)
2108  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2109 

§ __neg__()

def __neg__ (   self)
Return an expression representing `-self`.

>>> x = Int('x')
>>> -x
-x
>>> simplify(-(-x))
x

Definition at line 2246 of file z3py.py.

2246  def __neg__(self):
2247  """Return an expression representing `-self`.
2248 
2249  >>> x = Int('x')
2250  >>> -x
2251  -x
2252  >>> simplify(-(-x))
2253  x
2254  """
2255  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2256 
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.

§ __pos__()

def __pos__ (   self)
Return `self`.

>>> x = Int('x')
>>> +x
x

Definition at line 2257 of file z3py.py.

2257  def __pos__(self):
2258  """Return `self`.
2259 
2260  >>> x = Int('x')
2261  >>> +x
2262  x
2263  """
2264  return self
2265 

§ __pow__()

def __pow__ (   self,
  other 
)
Create the Z3 expression `self**other` (** is the power operator).

>>> x = Real('x')
>>> x**3
x**3
>>> (x**3).sort()
Real
>>> simplify(IntVal(2)**8)
256

Definition at line 2143 of file z3py.py.

2143  def __pow__(self, other):
2144  """Create the Z3 expression `self**other` (** is the power operator).
2145 
2146  >>> x = Real('x')
2147  >>> x**3
2148  x**3
2149  >>> (x**3).sort()
2150  Real
2151  >>> simplify(IntVal(2)**8)
2152  256
2153  """
2154  a, b = _coerce_exprs(self, other)
2155  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2156 
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.

§ __radd__()

def __radd__ (   self,
  other 
)
Create the Z3 expression `other + self`.

>>> x = Int('x')
>>> 10 + x
10 + x

Definition at line 2087 of file z3py.py.

2087  def __radd__(self, other):
2088  """Create the Z3 expression `other + self`.
2089 
2090  >>> x = Int('x')
2091  >>> 10 + x
2092  10 + x
2093  """
2094  a, b = _coerce_exprs(self, other)
2095  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2096 

§ __rdiv__()

def __rdiv__ (   self,
  other 
)
Create the Z3 expression `other/self`.

>>> x = Int('x')
>>> 10/x
10/x
>>> (10/x).sexpr()
'(div 10 x)'
>>> x = Real('x')
>>> 10/x
10/x
>>> (10/x).sexpr()
'(/ 10.0 x)'

Definition at line 2198 of file z3py.py.

2198  def __rdiv__(self, other):
2199  """Create the Z3 expression `other/self`.
2200 
2201  >>> x = Int('x')
2202  >>> 10/x
2203  10/x
2204  >>> (10/x).sexpr()
2205  '(div 10 x)'
2206  >>> x = Real('x')
2207  >>> 10/x
2208  10/x
2209  >>> (10/x).sexpr()
2210  '(/ 10.0 x)'
2211  """
2212  a, b = _coerce_exprs(self, other)
2213  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2214 
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.

§ __rmod__()

def __rmod__ (   self,
  other 
)
Create the Z3 expression `other%self`.

>>> x = Int('x')
>>> 10 % x
10%x

Definition at line 2234 of file z3py.py.

2234  def __rmod__(self, other):
2235  """Create the Z3 expression `other%self`.
2236 
2237  >>> x = Int('x')
2238  >>> 10 % x
2239  10%x
2240  """
2241  a, b = _coerce_exprs(self, other)
2242  if __debug__:
2243  _z3_assert(a.is_int(), "Z3 integer expression expected")
2244  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2245 
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.

§ __rmul__()

def __rmul__ (   self,
  other 
)
Create the Z3 expression `other * self`.

>>> x = Real('x')
>>> 10 * x
10*x

Definition at line 2110 of file z3py.py.

2110  def __rmul__(self, other):
2111  """Create the Z3 expression `other * self`.
2112 
2113  >>> x = Real('x')
2114  >>> 10 * x
2115  10*x
2116  """
2117  a, b = _coerce_exprs(self, other)
2118  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2119 

§ __rpow__()

def __rpow__ (   self,
  other 
)
Create the Z3 expression `other**self` (** is the power operator).

>>> x = Real('x')
>>> 2**x
2**x
>>> (2**x).sort()
Real
>>> simplify(2**IntVal(8))
256

Definition at line 2157 of file z3py.py.

2157  def __rpow__(self, other):
2158  """Create the Z3 expression `other**self` (** is the power operator).
2159 
2160  >>> x = Real('x')
2161  >>> 2**x
2162  2**x
2163  >>> (2**x).sort()
2164  Real
2165  >>> simplify(2**IntVal(8))
2166  256
2167  """
2168  a, b = _coerce_exprs(self, other)
2169  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2170 
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.

§ __rsub__()

def __rsub__ (   self,
  other 
)
Create the Z3 expression `other - self`.

>>> x = Int('x')
>>> 10 - x
10 - x

Definition at line 2133 of file z3py.py.

2133  def __rsub__(self, other):
2134  """Create the Z3 expression `other - self`.
2135 
2136  >>> x = Int('x')
2137  >>> 10 - x
2138  10 - x
2139  """
2140  a, b = _coerce_exprs(self, other)
2141  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2142 

§ __rtruediv__()

def __rtruediv__ (   self,
  other 
)
Create the Z3 expression `other/self`.

Definition at line 2215 of file z3py.py.

2215  def __rtruediv__(self, other):
2216  """Create the Z3 expression `other/self`."""
2217  return self.__rdiv__(other)
2218 

§ __sub__()

def __sub__ (   self,
  other 
)
Create the Z3 expression `self - other`.

>>> x = Int('x')
>>> y = Int('y')
>>> x - y
x - y
>>> (x - y).sort()
Int

Definition at line 2120 of file z3py.py.

2120  def __sub__(self, other):
2121  """Create the Z3 expression `self - other`.
2122 
2123  >>> x = Int('x')
2124  >>> y = Int('y')
2125  >>> x - y
2126  x - y
2127  >>> (x - y).sort()
2128  Int
2129  """
2130  a, b = _coerce_exprs(self, other)
2131  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2132 

§ __truediv__()

def __truediv__ (   self,
  other 
)
Create the Z3 expression `other/self`.

Definition at line 2194 of file z3py.py.

2194  def __truediv__(self, other):
2195  """Create the Z3 expression `other/self`."""
2196  return self.__div__(other)
2197 

§ is_int()

def is_int (   self)
Return `True` if `self` is an integer expression.

>>> x = Int('x')
>>> x.is_int()
True
>>> (x + 1).is_int()
True
>>> y = Real('y')
>>> (x + y).is_int()
False

Definition at line 2049 of file z3py.py.

2049  def is_int(self):
2050  """Return `True` if `self` is an integer expression.
2051 
2052  >>> x = Int('x')
2053  >>> x.is_int()
2054  True
2055  >>> (x + 1).is_int()
2056  True
2057  >>> y = Real('y')
2058  >>> (x + y).is_int()
2059  False
2060  """
2061  return self.sort().is_int()
2062 
def is_int(a)
Definition: z3py.py:2338

§ is_real()

def is_real (   self)
Return `True` if `self` is an real expression.

>>> x = Real('x')
>>> x.is_real()
True
>>> (x + 1).is_real()
True

Definition at line 2063 of file z3py.py.

2063  def is_real(self):
2064  """Return `True` if `self` is an real expression.
2065 
2066  >>> x = Real('x')
2067  >>> x.is_real()
2068  True
2069  >>> (x + 1).is_real()
2070  True
2071  """
2072  return self.sort().is_real()
2073 
def is_real(a)
Definition: z3py.py:2356

§ sort()

def sort (   self)
Return the sort (type) of the arithmetical expression `self`.

>>> Int('x').sort()
Int
>>> (Real('x') + 1).sort()
Real

Definition at line 2039 of file z3py.py.

Referenced by ArithRef.__add__(), ArithRef.__div__(), ArithRef.__mul__(), ArithRef.__pow__(), ArithRef.__rpow__(), and ArithRef.__sub__().

2039  def sort(self):
2040  """Return the sort (type) of the arithmetical expression `self`.
2041 
2042  >>> Int('x').sort()
2043  Int
2044  >>> (Real('x') + 1).sort()
2045  Real
2046  """
2047  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2048 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.