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_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 __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (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 2340 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 2378 of file z3py.py.

2378  def __add__(self, other):
2379  """Create the Z3 expression `self + other`.
2380 
2381  >>> x = Int('x')
2382  >>> y = Int('y')
2383  >>> x + y
2384  x + y
2385  >>> (x + y).sort()
2386  Int
2387  """
2388  a, b = _coerce_exprs(self, other)
2389  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2390 

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

2477  def __div__(self, other):
2478  """Create the Z3 expression `other/self`.
2479 
2480  >>> x = Int('x')
2481  >>> y = Int('y')
2482  >>> x/y
2483  x/y
2484  >>> (x/y).sort()
2485  Int
2486  >>> (x/y).sexpr()
2487  '(div x y)'
2488  >>> x = Real('x')
2489  >>> y = Real('y')
2490  >>> x/y
2491  x/y
2492  >>> (x/y).sort()
2493  Real
2494  >>> (x/y).sexpr()
2495  '(/ x y)'
2496  """
2497  a, b = _coerce_exprs(self, other)
2498  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2499 
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.

Referenced by ArithRef.__truediv__(), BitVecRef.__truediv__(), and FPRef.__truediv__().

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

2611  def __ge__(self, other):
2612  """Create the Z3 expression `other >= self`.
2613 
2614  >>> x, y = Ints('x y')
2615  >>> x >= y
2616  x >= y
2617  >>> y = Real('y')
2618  >>> x >= y
2619  ToReal(x) >= y
2620  """
2621  a, b = _coerce_exprs(self, other)
2622  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2623 
2624 
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 2598 of file z3py.py.

2598  def __gt__(self, other):
2599  """Create the Z3 expression `other > self`.
2600 
2601  >>> x, y = Ints('x y')
2602  >>> x > y
2603  x > y
2604  >>> y = Real('y')
2605  >>> x > y
2606  ToReal(x) > y
2607  """
2608  a, b = _coerce_exprs(self, other)
2609  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2610 
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 2572 of file z3py.py.

2572  def __le__(self, other):
2573  """Create the Z3 expression `other <= self`.
2574 
2575  >>> x, y = Ints('x y')
2576  >>> x <= y
2577  x <= y
2578  >>> y = Real('y')
2579  >>> x <= y
2580  ToReal(x) <= y
2581  """
2582  a, b = _coerce_exprs(self, other)
2583  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2584 
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 2585 of file z3py.py.

2585  def __lt__(self, other):
2586  """Create the Z3 expression `other < self`.
2587 
2588  >>> x, y = Ints('x y')
2589  >>> x < y
2590  x < y
2591  >>> y = Real('y')
2592  >>> x < y
2593  ToReal(x) < y
2594  """
2595  a, b = _coerce_exprs(self, other)
2596  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2597 
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 2525 of file z3py.py.

2525  def __mod__(self, other):
2526  """Create the Z3 expression `other%self`.
2527 
2528  >>> x = Int('x')
2529  >>> y = Int('y')
2530  >>> x % y
2531  x%y
2532  >>> simplify(IntVal(10) % IntVal(3))
2533  1
2534  """
2535  a, b = _coerce_exprs(self, other)
2536  if z3_debug():
2537  _z3_assert(a.is_int(), "Z3 integer expression expected")
2538  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2539 
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
def z3_debug()
Definition: z3py.py:62

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

2401  def __mul__(self, other):
2402  """Create the Z3 expression `self * other`.
2403 
2404  >>> x = Real('x')
2405  >>> y = Real('y')
2406  >>> x * y
2407  x*y
2408  >>> (x * y).sort()
2409  Real
2410  """
2411  if isinstance(other, BoolRef):
2412  return If(other, self, 0)
2413  a, b = _coerce_exprs(self, other)
2414  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2415 
def If(a, b, c, ctx=None)
Definition: z3py.py:1348

◆ __neg__()

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

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

Definition at line 2552 of file z3py.py.

2552  def __neg__(self):
2553  """Return an expression representing `-self`.
2554 
2555  >>> x = Int('x')
2556  >>> -x
2557  -x
2558  >>> simplify(-(-x))
2559  x
2560  """
2561  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2562 
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 2563 of file z3py.py.

2563  def __pos__(self):
2564  """Return `self`.
2565 
2566  >>> x = Int('x')
2567  >>> +x
2568  x
2569  """
2570  return self
2571 

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

2449  def __pow__(self, other):
2450  """Create the Z3 expression `self**other` (** is the power operator).
2451 
2452  >>> x = Real('x')
2453  >>> x**3
2454  x**3
2455  >>> (x**3).sort()
2456  Real
2457  >>> simplify(IntVal(2)**8)
2458  256
2459  """
2460  a, b = _coerce_exprs(self, other)
2461  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2462 
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 2391 of file z3py.py.

2391  def __radd__(self, other):
2392  """Create the Z3 expression `other + self`.
2393 
2394  >>> x = Int('x')
2395  >>> 10 + x
2396  10 + x
2397  """
2398  a, b = _coerce_exprs(self, other)
2399  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2400 

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

2504  def __rdiv__(self, other):
2505  """Create the Z3 expression `other/self`.
2506 
2507  >>> x = Int('x')
2508  >>> 10/x
2509  10/x
2510  >>> (10/x).sexpr()
2511  '(div 10 x)'
2512  >>> x = Real('x')
2513  >>> 10/x
2514  10/x
2515  >>> (10/x).sexpr()
2516  '(/ 10.0 x)'
2517  """
2518  a, b = _coerce_exprs(self, other)
2519  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2520 

Referenced by ArithRef.__rtruediv__(), BitVecRef.__rtruediv__(), and FPRef.__rtruediv__().

◆ __rmod__()

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

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

Definition at line 2540 of file z3py.py.

2540  def __rmod__(self, other):
2541  """Create the Z3 expression `other%self`.
2542 
2543  >>> x = Int('x')
2544  >>> 10 % x
2545  10%x
2546  """
2547  a, b = _coerce_exprs(self, other)
2548  if z3_debug():
2549  _z3_assert(a.is_int(), "Z3 integer expression expected")
2550  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2551 

◆ __rmul__()

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

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

Definition at line 2416 of file z3py.py.

2416  def __rmul__(self, other):
2417  """Create the Z3 expression `other * self`.
2418 
2419  >>> x = Real('x')
2420  >>> 10 * x
2421  10*x
2422  """
2423  a, b = _coerce_exprs(self, other)
2424  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2425 

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

2463  def __rpow__(self, other):
2464  """Create the Z3 expression `other**self` (** is the power operator).
2465 
2466  >>> x = Real('x')
2467  >>> 2**x
2468  2**x
2469  >>> (2**x).sort()
2470  Real
2471  >>> simplify(2**IntVal(8))
2472  256
2473  """
2474  a, b = _coerce_exprs(self, other)
2475  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2476 

◆ __rsub__()

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

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

Definition at line 2439 of file z3py.py.

2439  def __rsub__(self, other):
2440  """Create the Z3 expression `other - self`.
2441 
2442  >>> x = Int('x')
2443  >>> 10 - x
2444  10 - x
2445  """
2446  a, b = _coerce_exprs(self, other)
2447  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2448 

◆ __rtruediv__()

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

Definition at line 2521 of file z3py.py.

2521  def __rtruediv__(self, other):
2522  """Create the Z3 expression `other/self`."""
2523  return self.__rdiv__(other)
2524 

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

2426  def __sub__(self, other):
2427  """Create the Z3 expression `self - other`.
2428 
2429  >>> x = Int('x')
2430  >>> y = Int('y')
2431  >>> x - y
2432  x - y
2433  >>> (x - y).sort()
2434  Int
2435  """
2436  a, b = _coerce_exprs(self, other)
2437  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2438 

◆ __truediv__()

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

Definition at line 2500 of file z3py.py.

2500  def __truediv__(self, other):
2501  """Create the Z3 expression `other/self`."""
2502  return self.__div__(other)
2503 

◆ 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

Reimplemented in RatNumRef.

Definition at line 2353 of file z3py.py.

2353  def is_int(self):
2354  """Return `True` if `self` is an integer expression.
2355 
2356  >>> x = Int('x')
2357  >>> x.is_int()
2358  True
2359  >>> (x + 1).is_int()
2360  True
2361  >>> y = Real('y')
2362  >>> (x + y).is_int()
2363  False
2364  """
2365  return self.sort().is_int()
2366 
def is_int(a)
Definition: z3py.py:2646

Referenced by IntNumRef.as_long(), and ArithSortRef.subsort().

◆ 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

Reimplemented in RatNumRef.

Definition at line 2367 of file z3py.py.

2367  def is_real(self):
2368  """Return `True` if `self` is an real expression.
2369 
2370  >>> x = Real('x')
2371  >>> x.is_real()
2372  True
2373  >>> (x + 1).is_real()
2374  True
2375  """
2376  return self.sort().is_real()
2377 
def is_real(a)
Definition: z3py.py:2665

◆ sort()

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

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

Reimplemented from ExprRef.

Definition at line 2343 of file z3py.py.

2343  def sort(self):
2344  """Return the sort (type) of the arithmetical expression `self`.
2345 
2346  >>> Int('x').sort()
2347  Int
2348  >>> (Real('x') + 1).sort()
2349  Real
2350  """
2351  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2352 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by FPNumRef.as_string(), ArrayRef.domain(), ArrayRef.domain_n(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), and ExprRef.sort_kind().