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 __copy__ (self)
 
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 2165 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 2203 of file z3py.py.

2203  def __add__(self, other):
2204  """Create the Z3 expression `self + other`.
2205 
2206  >>> x = Int('x')
2207  >>> y = Int('y')
2208  >>> x + y
2209  x + y
2210  >>> (x + y).sort()
2211  Int
2212  """
2213  a, b = _coerce_exprs(self, other)
2214  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2215 

◆ __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 2302 of file z3py.py.

2302  def __div__(self, other):
2303  """Create the Z3 expression `other/self`.
2304 
2305  >>> x = Int('x')
2306  >>> y = Int('y')
2307  >>> x/y
2308  x/y
2309  >>> (x/y).sort()
2310  Int
2311  >>> (x/y).sexpr()
2312  '(div x y)'
2313  >>> x = Real('x')
2314  >>> y = Real('y')
2315  >>> x/y
2316  x/y
2317  >>> (x/y).sort()
2318  Real
2319  >>> (x/y).sexpr()
2320  '(/ x y)'
2321  """
2322  a, b = _coerce_exprs(self, other)
2323  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2324 
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 2436 of file z3py.py.

2436  def __ge__(self, other):
2437  """Create the Z3 expression `other >= self`.
2438 
2439  >>> x, y = Ints('x y')
2440  >>> x >= y
2441  x >= y
2442  >>> y = Real('y')
2443  >>> x >= y
2444  ToReal(x) >= y
2445  """
2446  a, b = _coerce_exprs(self, other)
2447  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2448 
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 2423 of file z3py.py.

2423  def __gt__(self, other):
2424  """Create the Z3 expression `other > self`.
2425 
2426  >>> x, y = Ints('x y')
2427  >>> x > y
2428  x > y
2429  >>> y = Real('y')
2430  >>> x > y
2431  ToReal(x) > y
2432  """
2433  a, b = _coerce_exprs(self, other)
2434  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2435 
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 2397 of file z3py.py.

2397  def __le__(self, other):
2398  """Create the Z3 expression `other <= self`.
2399 
2400  >>> x, y = Ints('x y')
2401  >>> x <= y
2402  x <= y
2403  >>> y = Real('y')
2404  >>> x <= y
2405  ToReal(x) <= y
2406  """
2407  a, b = _coerce_exprs(self, other)
2408  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2409 
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 2410 of file z3py.py.

2410  def __lt__(self, other):
2411  """Create the Z3 expression `other < self`.
2412 
2413  >>> x, y = Ints('x y')
2414  >>> x < y
2415  x < y
2416  >>> y = Real('y')
2417  >>> x < y
2418  ToReal(x) < y
2419  """
2420  a, b = _coerce_exprs(self, other)
2421  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2422 
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 2350 of file z3py.py.

2350  def __mod__(self, other):
2351  """Create the Z3 expression `other%self`.
2352 
2353  >>> x = Int('x')
2354  >>> y = Int('y')
2355  >>> x % y
2356  x%y
2357  >>> simplify(IntVal(10) % IntVal(3))
2358  1
2359  """
2360  a, b = _coerce_exprs(self, other)
2361  if __debug__:
2362  _z3_assert(a.is_int(), "Z3 integer expression expected")
2363  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2364 
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 2226 of file z3py.py.

2226  def __mul__(self, other):
2227  """Create the Z3 expression `self * other`.
2228 
2229  >>> x = Real('x')
2230  >>> y = Real('y')
2231  >>> x * y
2232  x*y
2233  >>> (x * y).sort()
2234  Real
2235  """
2236  if isinstance(other, BoolRef):
2237  return If(other, self, 0)
2238  a, b = _coerce_exprs(self, other)
2239  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2240 
def If(a, b, c, ctx=None)
Definition: z3py.py:1227

◆ __neg__()

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

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

Definition at line 2377 of file z3py.py.

2377  def __neg__(self):
2378  """Return an expression representing `-self`.
2379 
2380  >>> x = Int('x')
2381  >>> -x
2382  -x
2383  >>> simplify(-(-x))
2384  x
2385  """
2386  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2387 
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 2388 of file z3py.py.

2388  def __pos__(self):
2389  """Return `self`.
2390 
2391  >>> x = Int('x')
2392  >>> +x
2393  x
2394  """
2395  return self
2396 

◆ __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 2274 of file z3py.py.

2274  def __pow__(self, other):
2275  """Create the Z3 expression `self**other` (** is the power operator).
2276 
2277  >>> x = Real('x')
2278  >>> x**3
2279  x**3
2280  >>> (x**3).sort()
2281  Real
2282  >>> simplify(IntVal(2)**8)
2283  256
2284  """
2285  a, b = _coerce_exprs(self, other)
2286  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2287 
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 2216 of file z3py.py.

2216  def __radd__(self, other):
2217  """Create the Z3 expression `other + self`.
2218 
2219  >>> x = Int('x')
2220  >>> 10 + x
2221  10 + x
2222  """
2223  a, b = _coerce_exprs(self, other)
2224  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2225 

◆ __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 2329 of file z3py.py.

2329  def __rdiv__(self, other):
2330  """Create the Z3 expression `other/self`.
2331 
2332  >>> x = Int('x')
2333  >>> 10/x
2334  10/x
2335  >>> (10/x).sexpr()
2336  '(div 10 x)'
2337  >>> x = Real('x')
2338  >>> 10/x
2339  10/x
2340  >>> (10/x).sexpr()
2341  '(/ 10.0 x)'
2342  """
2343  a, b = _coerce_exprs(self, other)
2344  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2345 
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 2365 of file z3py.py.

2365  def __rmod__(self, other):
2366  """Create the Z3 expression `other%self`.
2367 
2368  >>> x = Int('x')
2369  >>> 10 % x
2370  10%x
2371  """
2372  a, b = _coerce_exprs(self, other)
2373  if __debug__:
2374  _z3_assert(a.is_int(), "Z3 integer expression expected")
2375  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2376 
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 2241 of file z3py.py.

2241  def __rmul__(self, other):
2242  """Create the Z3 expression `other * self`.
2243 
2244  >>> x = Real('x')
2245  >>> 10 * x
2246  10*x
2247  """
2248  a, b = _coerce_exprs(self, other)
2249  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2250 

◆ __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 2288 of file z3py.py.

2288  def __rpow__(self, other):
2289  """Create the Z3 expression `other**self` (** is the power operator).
2290 
2291  >>> x = Real('x')
2292  >>> 2**x
2293  2**x
2294  >>> (2**x).sort()
2295  Real
2296  >>> simplify(2**IntVal(8))
2297  256
2298  """
2299  a, b = _coerce_exprs(self, other)
2300  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2301 
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 2264 of file z3py.py.

2264  def __rsub__(self, other):
2265  """Create the Z3 expression `other - self`.
2266 
2267  >>> x = Int('x')
2268  >>> 10 - x
2269  10 - x
2270  """
2271  a, b = _coerce_exprs(self, other)
2272  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2273 

◆ __rtruediv__()

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

Definition at line 2346 of file z3py.py.

2346  def __rtruediv__(self, other):
2347  """Create the Z3 expression `other/self`."""
2348  return self.__rdiv__(other)
2349 

◆ __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 2251 of file z3py.py.

2251  def __sub__(self, other):
2252  """Create the Z3 expression `self - other`.
2253 
2254  >>> x = Int('x')
2255  >>> y = Int('y')
2256  >>> x - y
2257  x - y
2258  >>> (x - y).sort()
2259  Int
2260  """
2261  a, b = _coerce_exprs(self, other)
2262  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2263 

◆ __truediv__()

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

Definition at line 2325 of file z3py.py.

2325  def __truediv__(self, other):
2326  """Create the Z3 expression `other/self`."""
2327  return self.__div__(other)
2328 

◆ 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 2178 of file z3py.py.

2178  def is_int(self):
2179  """Return `True` if `self` is an integer expression.
2180 
2181  >>> x = Int('x')
2182  >>> x.is_int()
2183  True
2184  >>> (x + 1).is_int()
2185  True
2186  >>> y = Real('y')
2187  >>> (x + y).is_int()
2188  False
2189  """
2190  return self.sort().is_int()
2191 
def is_int(a)
Definition: z3py.py:2469

◆ 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 2192 of file z3py.py.

2192  def is_real(self):
2193  """Return `True` if `self` is an real expression.
2194 
2195  >>> x = Real('x')
2196  >>> x.is_real()
2197  True
2198  >>> (x + 1).is_real()
2199  True
2200  """
2201  return self.sort().is_real()
2202 
def is_real(a)
Definition: z3py.py:2487

◆ 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 2168 of file z3py.py.

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

2168  def sort(self):
2169  """Return the sort (type) of the arithmetical expression `self`.
2170 
2171  >>> Int('x').sort()
2172  Int
2173  >>> (Real('x') + 1).sort()
2174  Real
2175  """
2176  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2177 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.