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 and Real expressions.

Definition at line 2533 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 2817 of file z3py.py.

2817 def __abs__(self):
2818 """Return an expression representing `abs(self)`.
2819
2820 >>> x = Int('x')
2821 >>> abs(x)
2822 If(x > 0, x, -x)
2823 >>> eq(abs(x), Abs(x))
2824 True
2825 """
2826 return Abs(self)
2827
2828

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

2571 def __add__(self, other):
2572 """Create the Z3 expression `self + other`.
2573
2574 >>> x = Int('x')
2575 >>> y = Int('y')
2576 >>> x + y
2577 x + y
2578 >>> (x + y).sort()
2579 Int
2580 """
2581 a, b = _coerce_exprs(self, other)
2582 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2583

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

2670 def __div__(self, other):
2671 """Create the Z3 expression `other/self`.
2672
2673 >>> x = Int('x')
2674 >>> y = Int('y')
2675 >>> x/y
2676 x/y
2677 >>> (x/y).sort()
2678 Int
2679 >>> (x/y).sexpr()
2680 '(div x y)'
2681 >>> x = Real('x')
2682 >>> y = Real('y')
2683 >>> x/y
2684 x/y
2685 >>> (x/y).sort()
2686 Real
2687 >>> (x/y).sexpr()
2688 '(/ x y)'
2689 """
2690 a, b = _coerce_exprs(self, other)
2691 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2692
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 2804 of file z3py.py.

2804 def __ge__(self, other):
2805 """Create the Z3 expression `other >= self`.
2806
2807 >>> x, y = Ints('x y')
2808 >>> x >= y
2809 x >= y
2810 >>> y = Real('y')
2811 >>> x >= y
2812 ToReal(x) >= y
2813 """
2814 a, b = _coerce_exprs(self, other)
2815 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2816
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 2791 of file z3py.py.

2791 def __gt__(self, other):
2792 """Create the Z3 expression `other > self`.
2793
2794 >>> x, y = Ints('x y')
2795 >>> x > y
2796 x > y
2797 >>> y = Real('y')
2798 >>> x > y
2799 ToReal(x) > y
2800 """
2801 a, b = _coerce_exprs(self, other)
2802 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2803
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 2765 of file z3py.py.

2765 def __le__(self, other):
2766 """Create the Z3 expression `other <= self`.
2767
2768 >>> x, y = Ints('x y')
2769 >>> x <= y
2770 x <= y
2771 >>> y = Real('y')
2772 >>> x <= y
2773 ToReal(x) <= y
2774 """
2775 a, b = _coerce_exprs(self, other)
2776 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2777
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 2778 of file z3py.py.

2778 def __lt__(self, other):
2779 """Create the Z3 expression `other < self`.
2780
2781 >>> x, y = Ints('x y')
2782 >>> x < y
2783 x < y
2784 >>> y = Real('y')
2785 >>> x < y
2786 ToReal(x) < y
2787 """
2788 a, b = _coerce_exprs(self, other)
2789 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2790
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 2718 of file z3py.py.

2718 def __mod__(self, other):
2719 """Create the Z3 expression `other%self`.
2720
2721 >>> x = Int('x')
2722 >>> y = Int('y')
2723 >>> x % y
2724 x%y
2725 >>> simplify(IntVal(10) % IntVal(3))
2726 1
2727 """
2728 a, b = _coerce_exprs(self, other)
2729 if z3_debug():
2730 _z3_assert(a.is_int(), "Z3 integer expression expected")
2731 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2732
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 2594 of file z3py.py.

2594 def __mul__(self, other):
2595 """Create the Z3 expression `self * other`.
2596
2597 >>> x = Real('x')
2598 >>> y = Real('y')
2599 >>> x * y
2600 x*y
2601 >>> (x * y).sort()
2602 Real
2603 """
2604 if isinstance(other, BoolRef):
2605 return If(other, self, 0)
2606 a, b = _coerce_exprs(self, other)
2607 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2608

◆ __neg__()

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

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

Definition at line 2745 of file z3py.py.

2745 def __neg__(self):
2746 """Return an expression representing `-self`.
2747
2748 >>> x = Int('x')
2749 >>> -x
2750 -x
2751 >>> simplify(-(-x))
2752 x
2753 """
2754 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2755
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 2756 of file z3py.py.

2756 def __pos__(self):
2757 """Return `self`.
2758
2759 >>> x = Int('x')
2760 >>> +x
2761 x
2762 """
2763 return self
2764

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

2642 def __pow__(self, other):
2643 """Create the Z3 expression `self**other` (** is the power operator).
2644
2645 >>> x = Real('x')
2646 >>> x**3
2647 x**3
2648 >>> (x**3).sort()
2649 Real
2650 >>> simplify(IntVal(2)**8)
2651 256
2652 """
2653 a, b = _coerce_exprs(self, other)
2654 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2655
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 2584 of file z3py.py.

2584 def __radd__(self, other):
2585 """Create the Z3 expression `other + self`.
2586
2587 >>> x = Int('x')
2588 >>> 10 + x
2589 10 + x
2590 """
2591 a, b = _coerce_exprs(self, other)
2592 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2593

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

2697 def __rdiv__(self, other):
2698 """Create the Z3 expression `other/self`.
2699
2700 >>> x = Int('x')
2701 >>> 10/x
2702 10/x
2703 >>> (10/x).sexpr()
2704 '(div 10 x)'
2705 >>> x = Real('x')
2706 >>> 10/x
2707 10/x
2708 >>> (10/x).sexpr()
2709 '(/ 10.0 x)'
2710 """
2711 a, b = _coerce_exprs(self, other)
2712 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2713

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

2733 def __rmod__(self, other):
2734 """Create the Z3 expression `other%self`.
2735
2736 >>> x = Int('x')
2737 >>> 10 % x
2738 10%x
2739 """
2740 a, b = _coerce_exprs(self, other)
2741 if z3_debug():
2742 _z3_assert(a.is_int(), "Z3 integer expression expected")
2743 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2744

◆ __rmul__()

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

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

Definition at line 2609 of file z3py.py.

2609 def __rmul__(self, other):
2610 """Create the Z3 expression `other * self`.
2611
2612 >>> x = Real('x')
2613 >>> 10 * x
2614 10*x
2615 """
2616 a, b = _coerce_exprs(self, other)
2617 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2618

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

2656 def __rpow__(self, other):
2657 """Create the Z3 expression `other**self` (** is the power operator).
2658
2659 >>> x = Real('x')
2660 >>> 2**x
2661 2**x
2662 >>> (2**x).sort()
2663 Real
2664 >>> simplify(2**IntVal(8))
2665 256
2666 """
2667 a, b = _coerce_exprs(self, other)
2668 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2669

◆ __rsub__()

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

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

Definition at line 2632 of file z3py.py.

2632 def __rsub__(self, other):
2633 """Create the Z3 expression `other - self`.
2634
2635 >>> x = Int('x')
2636 >>> 10 - x
2637 10 - x
2638 """
2639 a, b = _coerce_exprs(self, other)
2640 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2641

◆ __rtruediv__()

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

Definition at line 2714 of file z3py.py.

2714 def __rtruediv__(self, other):
2715 """Create the Z3 expression `other/self`."""
2716 return self.__rdiv__(other)
2717

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

2619 def __sub__(self, other):
2620 """Create the Z3 expression `self - other`.
2621
2622 >>> x = Int('x')
2623 >>> y = Int('y')
2624 >>> x - y
2625 x - y
2626 >>> (x - y).sort()
2627 Int
2628 """
2629 a, b = _coerce_exprs(self, other)
2630 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2631

◆ __truediv__()

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

Definition at line 2693 of file z3py.py.

2693 def __truediv__(self, other):
2694 """Create the Z3 expression `other/self`."""
2695 return self.__div__(other)
2696

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

2546 def is_int(self):
2547 """Return `True` if `self` is an integer expression.
2548
2549 >>> x = Int('x')
2550 >>> x.is_int()
2551 True
2552 >>> (x + 1).is_int()
2553 True
2554 >>> y = Real('y')
2555 >>> (x + y).is_int()
2556 False
2557 """
2558 return self.sort().is_int()
2559

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

2560 def is_real(self):
2561 """Return `True` if `self` is an real expression.
2562
2563 >>> x = Real('x')
2564 >>> x.is_real()
2565 True
2566 >>> (x + 1).is_real()
2567 True
2568 """
2569 return self.sort().is_real()
2570

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.

Definition at line 2536 of file z3py.py.

2536 def sort(self):
2537 """Return the sort (type) of the arithmetical expression `self`.
2538
2539 >>> Int('x').sort()
2540 Int
2541 >>> (Real('x') + 1).sort()
2542 Real
2543 """
2544 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2545
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.