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)
 
def __abs__ (self)
 
- 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 kind (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
def update (self, args)
 
def from_string (self, s)
 
def serialize (self)
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__ (self)
 
def __deepcopy__
 
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)
 
def py_value (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 2523 of file z3py.py.

Member Function Documentation

def __abs__ (   self)
Return an expression representing `abs(self)`.

>>> x = Int('x')
>>> abs(x)
If(x > 0, x, -x)
>>> eq(abs(x), Abs(x))
True

Definition at line 2807 of file z3py.py.

2807  def __abs__(self):
2808  """Return an expression representing `abs(self)`.
2809 
2810  >>> x = Int('x')
2811  >>> abs(x)
2812  If(x > 0, x, -x)
2813  >>> eq(abs(x), Abs(x))
2814  True
2815  """
2816  return Abs(self)
2817 
2818 
def Abs(arg)
Definition: z3py.py:9335
def __abs__(self)
Definition: z3py.py:2807
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 2561 of file z3py.py.

2561  def __add__(self, other):
2562  """Create the Z3 expression `self + other`.
2563 
2564  >>> x = Int('x')
2565  >>> y = Int('y')
2566  >>> x + y
2567  x + y
2568  >>> (x + y).sort()
2569  Int
2570  """
2571  a, b = _coerce_exprs(self, other)
2572  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2573 
def __add__(self, other)
Definition: z3py.py:2561
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 2660 of file z3py.py.

2660  def __div__(self, other):
2661  """Create the Z3 expression `other/self`.
2662 
2663  >>> x = Int('x')
2664  >>> y = Int('y')
2665  >>> x/y
2666  x/y
2667  >>> (x/y).sort()
2668  Int
2669  >>> (x/y).sexpr()
2670  '(div x y)'
2671  >>> x = Real('x')
2672  >>> y = Real('y')
2673  >>> x/y
2674  x/y
2675  >>> (x/y).sort()
2676  Real
2677  >>> (x/y).sexpr()
2678  '(/ x y)'
2679  """
2680  a, b = _coerce_exprs(self, other)
2681  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2682 
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
def ctx_ref(self)
Definition: z3py.py:427
def __div__(self, other)
Definition: z3py.py:2660
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 2794 of file z3py.py.

2794  def __ge__(self, other):
2795  """Create the Z3 expression `other >= self`.
2796 
2797  >>> x, y = Ints('x y')
2798  >>> x >= y
2799  x >= y
2800  >>> y = Real('y')
2801  >>> x >= y
2802  ToReal(x) >= y
2803  """
2804  a, b = _coerce_exprs(self, other)
2805  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2806 
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
def __ge__(self, other)
Definition: z3py.py:2794
def ctx_ref(self)
Definition: z3py.py:427
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 2781 of file z3py.py.

2781  def __gt__(self, other):
2782  """Create the Z3 expression `other > self`.
2783 
2784  >>> x, y = Ints('x y')
2785  >>> x > y
2786  x > y
2787  >>> y = Real('y')
2788  >>> x > y
2789  ToReal(x) > y
2790  """
2791  a, b = _coerce_exprs(self, other)
2792  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2793 
def __gt__(self, other)
Definition: z3py.py:2781
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
def ctx_ref(self)
Definition: z3py.py:427
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 2755 of file z3py.py.

2755  def __le__(self, other):
2756  """Create the Z3 expression `other <= self`.
2757 
2758  >>> x, y = Ints('x y')
2759  >>> x <= y
2760  x <= y
2761  >>> y = Real('y')
2762  >>> x <= y
2763  ToReal(x) <= y
2764  """
2765  a, b = _coerce_exprs(self, other)
2766  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2767 
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
def __le__(self, other)
Definition: z3py.py:2755
def ctx_ref(self)
Definition: z3py.py:427
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 2768 of file z3py.py.

2768  def __lt__(self, other):
2769  """Create the Z3 expression `other < self`.
2770 
2771  >>> x, y = Ints('x y')
2772  >>> x < y
2773  x < y
2774  >>> y = Real('y')
2775  >>> x < y
2776  ToReal(x) < y
2777  """
2778  a, b = _coerce_exprs(self, other)
2779  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2780 
def __lt__(self, other)
Definition: z3py.py:2768
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
def ctx_ref(self)
Definition: z3py.py:427
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 2708 of file z3py.py.

2708  def __mod__(self, other):
2709  """Create the Z3 expression `other%self`.
2710 
2711  >>> x = Int('x')
2712  >>> y = Int('y')
2713  >>> x % y
2714  x%y
2715  >>> simplify(IntVal(10) % IntVal(3))
2716  1
2717  """
2718  a, b = _coerce_exprs(self, other)
2719  if z3_debug():
2720  _z3_assert(a.is_int(), "Z3 integer expression expected")
2721  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2722 
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 __mod__(self, other)
Definition: z3py.py:2708
def z3_debug()
Definition: z3py.py:70
def ctx_ref(self)
Definition: z3py.py:427
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 2584 of file z3py.py.

2584  def __mul__(self, other):
2585  """Create the Z3 expression `self * other`.
2586 
2587  >>> x = Real('x')
2588  >>> y = Real('y')
2589  >>> x * y
2590  x*y
2591  >>> (x * y).sort()
2592  Real
2593  """
2594  if isinstance(other, BoolRef):
2595  return If(other, self, 0)
2596  a, b = _coerce_exprs(self, other)
2597  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2598 
def If
Definition: z3py.py:1484
def __mul__(self, other)
Definition: z3py.py:2584
def __neg__ (   self)
Return an expression representing `-self`.

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

Definition at line 2735 of file z3py.py.

2735  def __neg__(self):
2736  """Return an expression representing `-self`.
2737 
2738  >>> x = Int('x')
2739  >>> -x
2740  -x
2741  >>> simplify(-(-x))
2742  x
2743  """
2744  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2745 
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
def as_ast(self)
Definition: z3py.py:419
def __neg__(self)
Definition: z3py.py:2735
def ctx_ref(self)
Definition: z3py.py:427
def __pos__ (   self)
Return `self`.

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

Definition at line 2746 of file z3py.py.

2746  def __pos__(self):
2747  """Return `self`.
2748 
2749  >>> x = Int('x')
2750  >>> +x
2751  x
2752  """
2753  return self
2754 
def __pos__(self)
Definition: z3py.py:2746
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 2632 of file z3py.py.

2632  def __pow__(self, other):
2633  """Create the Z3 expression `self**other` (** is the power operator).
2634 
2635  >>> x = Real('x')
2636  >>> x**3
2637  x**3
2638  >>> (x**3).sort()
2639  Real
2640  >>> simplify(IntVal(2)**8)
2641  256
2642  """
2643  a, b = _coerce_exprs(self, other)
2644  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2645 
def __pow__(self, other)
Definition: z3py.py:2632
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
def ctx_ref(self)
Definition: z3py.py:427
def __radd__ (   self,
  other 
)
Create the Z3 expression `other + self`.

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

Definition at line 2574 of file z3py.py.

2574  def __radd__(self, other):
2575  """Create the Z3 expression `other + self`.
2576 
2577  >>> x = Int('x')
2578  >>> 10 + x
2579  10 + x
2580  """
2581  a, b = _coerce_exprs(self, other)
2582  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2583 
def __radd__(self, other)
Definition: z3py.py:2574
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 2687 of file z3py.py.

2687  def __rdiv__(self, other):
2688  """Create the Z3 expression `other/self`.
2689 
2690  >>> x = Int('x')
2691  >>> 10/x
2692  10/x
2693  >>> (10/x).sexpr()
2694  '(div 10 x)'
2695  >>> x = Real('x')
2696  >>> 10/x
2697  10/x
2698  >>> (10/x).sexpr()
2699  '(/ 10.0 x)'
2700  """
2701  a, b = _coerce_exprs(self, other)
2702  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2703 
def __rdiv__(self, other)
Definition: z3py.py:2687
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
def ctx_ref(self)
Definition: z3py.py:427
def __rmod__ (   self,
  other 
)
Create the Z3 expression `other%self`.

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

Definition at line 2723 of file z3py.py.

2723  def __rmod__(self, other):
2724  """Create the Z3 expression `other%self`.
2725 
2726  >>> x = Int('x')
2727  >>> 10 % x
2728  10%x
2729  """
2730  a, b = _coerce_exprs(self, other)
2731  if z3_debug():
2732  _z3_assert(a.is_int(), "Z3 integer expression expected")
2733  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2734 
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 __rmod__(self, other)
Definition: z3py.py:2723
def z3_debug()
Definition: z3py.py:70
def ctx_ref(self)
Definition: z3py.py:427
def __rmul__ (   self,
  other 
)
Create the Z3 expression `other * self`.

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

Definition at line 2599 of file z3py.py.

2599  def __rmul__(self, other):
2600  """Create the Z3 expression `other * self`.
2601 
2602  >>> x = Real('x')
2603  >>> 10 * x
2604  10*x
2605  """
2606  a, b = _coerce_exprs(self, other)
2607  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2608 
def __rmul__(self, other)
Definition: z3py.py:2599
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 2646 of file z3py.py.

2646  def __rpow__(self, other):
2647  """Create the Z3 expression `other**self` (** is the power operator).
2648 
2649  >>> x = Real('x')
2650  >>> 2**x
2651  2**x
2652  >>> (2**x).sort()
2653  Real
2654  >>> simplify(2**IntVal(8))
2655  256
2656  """
2657  a, b = _coerce_exprs(self, other)
2658  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2659 
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
def ctx_ref(self)
Definition: z3py.py:427
def __rpow__(self, other)
Definition: z3py.py:2646
def __rsub__ (   self,
  other 
)
Create the Z3 expression `other - self`.

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

Definition at line 2622 of file z3py.py.

2622  def __rsub__(self, other):
2623  """Create the Z3 expression `other - self`.
2624 
2625  >>> x = Int('x')
2626  >>> 10 - x
2627  10 - x
2628  """
2629  a, b = _coerce_exprs(self, other)
2630  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2631 
def __rsub__(self, other)
Definition: z3py.py:2622
def __rtruediv__ (   self,
  other 
)
Create the Z3 expression `other/self`.

Definition at line 2704 of file z3py.py.

2704  def __rtruediv__(self, other):
2705  """Create the Z3 expression `other/self`."""
2706  return self.__rdiv__(other)
2707 
def __rdiv__(self, other)
Definition: z3py.py:2687
def __rtruediv__(self, other)
Definition: z3py.py:2704
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 2609 of file z3py.py.

2609  def __sub__(self, other):
2610  """Create the Z3 expression `self - other`.
2611 
2612  >>> x = Int('x')
2613  >>> y = Int('y')
2614  >>> x - y
2615  x - y
2616  >>> (x - y).sort()
2617  Int
2618  """
2619  a, b = _coerce_exprs(self, other)
2620  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2621 
def __sub__(self, other)
Definition: z3py.py:2609
def __truediv__ (   self,
  other 
)
Create the Z3 expression `other/self`.

Definition at line 2683 of file z3py.py.

2683  def __truediv__(self, other):
2684  """Create the Z3 expression `other/self`."""
2685  return self.__div__(other)
2686 
def __truediv__(self, other)
Definition: z3py.py:2683
def __div__(self, other)
Definition: z3py.py:2660
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 2536 of file z3py.py.

2536  def is_int(self):
2537  """Return `True` if `self` is an integer expression.
2538 
2539  >>> x = Int('x')
2540  >>> x.is_int()
2541  True
2542  >>> (x + 1).is_int()
2543  True
2544  >>> y = Real('y')
2545  >>> (x + y).is_int()
2546  False
2547  """
2548  return self.sort().is_int()
2549 
def is_int(self)
Definition: z3py.py:2536
def sort(self)
Definition: z3py.py:1035
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 2550 of file z3py.py.

2550  def is_real(self):
2551  """Return `True` if `self` is an real expression.
2552 
2553  >>> x = Real('x')
2554  >>> x.is_real()
2555  True
2556  >>> (x + 1).is_real()
2557  True
2558  """
2559  return self.sort().is_real()
2560 
def is_real(self)
Definition: z3py.py:2550
def sort(self)
Definition: z3py.py:1035
def sort (   self)
Return the sort (type) of the arithmetical expression `self`.

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

Definition at line 2526 of file z3py.py.

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

2526  def sort(self):
2527  """Return the sort (type) of the arithmetical expression `self`.
2528 
2529  >>> Int('x').sort()
2530  Int
2531  >>> (Real('x') + 1).sort()
2532  Real
2533  """
2534  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2535 
def as_ast(self)
Definition: z3py.py:419
Arithmetic.
Definition: z3py.py:2431
def sort(self)
Definition: z3py.py:2526
def ctx_ref(self)
Definition: z3py.py:427
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.