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

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

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

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

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

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

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

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

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

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

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

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

◆ __neg__()

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

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

Definition at line 2741 of file z3py.py.

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

2752 def __pos__(self):
2753 """Return `self`.
2754
2755 >>> x = Int('x')
2756 >>> +x
2757 x
2758 """
2759 return self
2760

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

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

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

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

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

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

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

◆ __rmul__()

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

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

Definition at line 2605 of file z3py.py.

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

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

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

◆ __rsub__()

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

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

Definition at line 2628 of file z3py.py.

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

◆ __rtruediv__()

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

Definition at line 2710 of file z3py.py.

2710 def __rtruediv__(self, other):
2711 """Create the Z3 expression `other/self`."""
2712 return self.__rdiv__(other)
2713

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

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

◆ __truediv__()

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

Definition at line 2689 of file z3py.py.

2689 def __truediv__(self, other):
2690 """Create the Z3 expression `other/self`."""
2691 return self.__div__(other)
2692

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

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

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

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

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

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