Z3
Loading...
Searching...
No Matches
ArithRef Class Reference
Inheritance diagram for ArithRef:

Public Member Functions

 sort (self)
 is_int (self)
 is_real (self)
 __add__ (self, other)
 __radd__ (self, other)
 __mul__ (self, other)
 __rmul__ (self, other)
 __sub__ (self, other)
 __rsub__ (self, other)
 __pow__ (self, other)
 __rpow__ (self, other)
 __div__ (self, other)
 __truediv__ (self, other)
 __rdiv__ (self, other)
 __rtruediv__ (self, other)
 __mod__ (self, other)
 __rmod__ (self, other)
 __neg__ (self)
 __pos__ (self)
 __le__ (self, other)
 __lt__ (self, other)
 __gt__ (self, other)
 __ge__ (self, other)
 __abs__ (self)
Public Member Functions inherited from ExprRef
 as_ast (self)
 get_id (self)
 sort_kind (self)
 __eq__ (self, other)
 __hash__ (self)
 __ne__ (self, other)
 params (self)
 decl (self)
 kind (self)
 num_args (self)
 arg (self, idx)
 children (self)
 update (self, *args)
 from_string (self, s)
 serialize (self)
Public Member Functions inherited from AstRef
 __init__ (self, ast, ctx=None)
 __del__ (self)
 __deepcopy__ (self, memo={})
 __str__ (self)
 __repr__ (self)
 __eq__ (self, other)
 __hash__ (self)
 __nonzero__ (self)
 __bool__ (self)
 sexpr (self)
 ctx_ref (self)
 eq (self, other)
 translate (self, target)
 __copy__ (self)
 hash (self)
 py_value (self)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Additional Inherited Members

Data Fields inherited from AstRef
 ast = ast
 ctx = _get_ctx(ctx)
Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

Integer, Real, and Complex expressions.

Definition at line 2551 of file z3py.py.

Member Function Documentation

◆ __abs__()

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

2835 def __abs__(self):
2836 """Return an expression representing `abs(self)`.
2837
2838 >>> x = Int('x')
2839 >>> abs(x)
2840 If(x > 0, x, -x)
2841 >>> eq(abs(x), Abs(x))
2842 True
2843 """
2844 return Abs(self)
2845
2846

◆ __add__()

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

2589 def __add__(self, other):
2590 """Create the Z3 expression `self + other`.
2591
2592 >>> x = Int('x')
2593 >>> y = Int('y')
2594 >>> x + y
2595 x + y
2596 >>> (x + y).sort()
2597 Int
2598 """
2599 a, b = _coerce_exprs(self, other)
2600 return _to_expr_ref(_mk_bin(Z3_mk_add, a, b), self.ctx)
2601

◆ __div__()

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

2688 def __div__(self, other):
2689 """Create the Z3 expression `other/self`.
2690
2691 >>> x = Int('x')
2692 >>> y = Int('y')
2693 >>> x/y
2694 x/y
2695 >>> (x/y).sort()
2696 Int
2697 >>> (x/y).sexpr()
2698 '(div x y)'
2699 >>> x = Real('x')
2700 >>> y = Real('y')
2701 >>> x/y
2702 x/y
2703 >>> (x/y).sort()
2704 Real
2705 >>> (x/y).sexpr()
2706 '(/ x y)'
2707 """
2708 a, b = _coerce_exprs(self, other)
2709 return _to_expr_ref(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2710
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 __truediv__(), and BitVecRef.__truediv__().

◆ __ge__()

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

2822 def __ge__(self, other):
2823 """Create the Z3 expression `other >= self`.
2824
2825 >>> x, y = Ints('x y')
2826 >>> x >= y
2827 x >= y
2828 >>> y = Real('y')
2829 >>> x >= y
2830 ToReal(x) >= y
2831 """
2832 a, b = _coerce_exprs(self, other)
2833 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2834
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.

◆ __gt__()

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

2809 def __gt__(self, other):
2810 """Create the Z3 expression `other > self`.
2811
2812 >>> x, y = Ints('x y')
2813 >>> x > y
2814 x > y
2815 >>> y = Real('y')
2816 >>> x > y
2817 ToReal(x) > y
2818 """
2819 a, b = _coerce_exprs(self, other)
2820 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2821
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.

◆ __le__()

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

2783 def __le__(self, other):
2784 """Create the Z3 expression `other <= self`.
2785
2786 >>> x, y = Ints('x y')
2787 >>> x <= y
2788 x <= y
2789 >>> y = Real('y')
2790 >>> x <= y
2791 ToReal(x) <= y
2792 """
2793 a, b = _coerce_exprs(self, other)
2794 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2795
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.

◆ __lt__()

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

2796 def __lt__(self, other):
2797 """Create the Z3 expression `other < self`.
2798
2799 >>> x, y = Ints('x y')
2800 >>> x < y
2801 x < y
2802 >>> y = Real('y')
2803 >>> x < y
2804 ToReal(x) < y
2805 """
2806 a, b = _coerce_exprs(self, other)
2807 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2808
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.

◆ __mod__()

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

2736 def __mod__(self, other):
2737 """Create the Z3 expression `other%self`.
2738
2739 >>> x = Int('x')
2740 >>> y = Int('y')
2741 >>> x % y
2742 x%y
2743 >>> simplify(IntVal(10) % IntVal(3))
2744 1
2745 """
2746 a, b = _coerce_exprs(self, other)
2747 if z3_debug():
2748 _z3_assert(a.is_int(), "Z3 integer expression expected")
2749 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2750
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__()

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

2612 def __mul__(self, other):
2613 """Create the Z3 expression `self * other`.
2614
2615 >>> x = Real('x')
2616 >>> y = Real('y')
2617 >>> x * y
2618 x*y
2619 >>> (x * y).sort()
2620 Real
2621 """
2622 if isinstance(other, BoolRef):
2623 return If(other, self, 0)
2624 a, b = _coerce_exprs(self, other)
2625 return _to_expr_ref(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2626

◆ __neg__()

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

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

Definition at line 2763 of file z3py.py.

2763 def __neg__(self):
2764 """Return an expression representing `-self`.
2765
2766 >>> x = Int('x')
2767 >>> -x
2768 -x
2769 >>> simplify(-(-x))
2770 x
2771 """
2772 return _to_expr_ref(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2773
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.

◆ __pos__()

__pos__ ( self)
Return `self`.

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

Definition at line 2774 of file z3py.py.

2774 def __pos__(self):
2775 """Return `self`.
2776
2777 >>> x = Int('x')
2778 >>> +x
2779 x
2780 """
2781 return self
2782

◆ __pow__()

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

2660 def __pow__(self, other):
2661 """Create the Z3 expression `self**other` (** is the power operator).
2662
2663 >>> x = Real('x')
2664 >>> x**3
2665 x**3
2666 >>> (x**3).sort()
2667 Real
2668 >>> simplify(IntVal(2)**8)
2669 256
2670 """
2671 a, b = _coerce_exprs(self, other)
2672 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2673
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.

◆ __radd__()

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

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

Definition at line 2602 of file z3py.py.

2602 def __radd__(self, other):
2603 """Create the Z3 expression `other + self`.
2604
2605 >>> x = Int('x')
2606 >>> 10 + x
2607 10 + x
2608 """
2609 a, b = _coerce_exprs(self, other)
2610 return _to_expr_ref(_mk_bin(Z3_mk_add, b, a), self.ctx)
2611

◆ __rdiv__()

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

2715 def __rdiv__(self, other):
2716 """Create the Z3 expression `other/self`.
2717
2718 >>> x = Int('x')
2719 >>> 10/x
2720 10/x
2721 >>> (10/x).sexpr()
2722 '(div 10 x)'
2723 >>> x = Real('x')
2724 >>> 10/x
2725 10/x
2726 >>> (10/x).sexpr()
2727 '(/ 10.0 x)'
2728 """
2729 a, b = _coerce_exprs(self, other)
2730 return _to_expr_ref(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2731

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

◆ __rmod__()

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

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

Definition at line 2751 of file z3py.py.

2751 def __rmod__(self, other):
2752 """Create the Z3 expression `other%self`.
2753
2754 >>> x = Int('x')
2755 >>> 10 % x
2756 10%x
2757 """
2758 a, b = _coerce_exprs(self, other)
2759 if z3_debug():
2760 _z3_assert(a.is_int(), "Z3 integer expression expected")
2761 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2762

◆ __rmul__()

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

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

Definition at line 2627 of file z3py.py.

2627 def __rmul__(self, other):
2628 """Create the Z3 expression `other * self`.
2629
2630 >>> x = Real('x')
2631 >>> 10 * x
2632 10*x
2633 """
2634 a, b = _coerce_exprs(self, other)
2635 return _to_expr_ref(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2636

◆ __rpow__()

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

2674 def __rpow__(self, other):
2675 """Create the Z3 expression `other**self` (** is the power operator).
2676
2677 >>> x = Real('x')
2678 >>> 2**x
2679 2**x
2680 >>> (2**x).sort()
2681 Real
2682 >>> simplify(2**IntVal(8))
2683 256
2684 """
2685 a, b = _coerce_exprs(self, other)
2686 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2687

◆ __rsub__()

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

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

Definition at line 2650 of file z3py.py.

2650 def __rsub__(self, other):
2651 """Create the Z3 expression `other - self`.
2652
2653 >>> x = Int('x')
2654 >>> 10 - x
2655 10 - x
2656 """
2657 a, b = _coerce_exprs(self, other)
2658 return _to_expr_ref(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2659

◆ __rtruediv__()

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

Definition at line 2732 of file z3py.py.

2732 def __rtruediv__(self, other):
2733 """Create the Z3 expression `other/self`."""
2734 return self.__rdiv__(other)
2735

◆ __sub__()

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

2637 def __sub__(self, other):
2638 """Create the Z3 expression `self - other`.
2639
2640 >>> x = Int('x')
2641 >>> y = Int('y')
2642 >>> x - y
2643 x - y
2644 >>> (x - y).sort()
2645 Int
2646 """
2647 a, b = _coerce_exprs(self, other)
2648 return _to_expr_ref(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2649

◆ __truediv__()

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

Definition at line 2711 of file z3py.py.

2711 def __truediv__(self, other):
2712 """Create the Z3 expression `other/self`."""
2713 return self.__div__(other)
2714

◆ is_int()

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

2564 def is_int(self):
2565 """Return `True` if `self` is an integer expression.
2566
2567 >>> x = Int('x')
2568 >>> x.is_int()
2569 True
2570 >>> (x + 1).is_int()
2571 True
2572 >>> y = Real('y')
2573 >>> (x + y).is_int()
2574 False
2575 """
2576 return self.sort().is_int()
2577

Referenced by IntNumRef.as_long(), and is_int().

◆ is_real()

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

2578 def is_real(self):
2579 """Return `True` if `self` is an real expression.
2580
2581 >>> x = Real('x')
2582 >>> x.is_real()
2583 True
2584 >>> (x + 1).is_real()
2585 True
2586 """
2587 return self.sort().is_real()
2588

Referenced by is_real().

◆ sort()

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

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

Reimplemented from ExprRef.

Reimplemented in ComplexRef.

Definition at line 2554 of file z3py.py.

2554 def sort(self):
2555 """Return the sort (type) of the arithmetical expression `self`.
2556
2557 >>> Int('x').sort()
2558 Int
2559 >>> (Real('x') + 1).sort()
2560 Real
2561 """
2562 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2563
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.