Z3
 
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
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)
 
- 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)
 
 __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)
 

Data Fields

 ctx
 
- Data Fields inherited from ExprRef
 ctx
 
 ast
 
- Data Fields inherited from AstRef
 ast
 
 ctx
 

Additional Inherited Members

- Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)
 

Detailed Description

Integer and Real expressions.

Definition at line 2526 of file z3py.py.

Member Function Documentation

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

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

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

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

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

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

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

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

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

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

◆ __neg__()

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

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

Definition at line 2738 of file z3py.py.

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

2749 def __pos__(self):
2750 """Return `self`.
2751
2752 >>> x = Int('x')
2753 >>> +x
2754 x
2755 """
2756 return self
2757

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

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

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

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

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

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

◆ __rmod__()

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

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

Definition at line 2726 of file z3py.py.

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

◆ __rmul__()

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

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

Definition at line 2602 of file z3py.py.

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

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

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

◆ __rsub__()

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

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

Definition at line 2625 of file z3py.py.

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

◆ __rtruediv__()

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

Definition at line 2707 of file z3py.py.

2707 def __rtruediv__(self, other):
2708 """Create the Z3 expression `other/self`."""
2709 return self.__rdiv__(other)
2710

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

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

◆ __truediv__()

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

Definition at line 2686 of file z3py.py.

2686 def __truediv__(self, other):
2687 """Create the Z3 expression `other/self`."""
2688 return self.__div__(other)
2689

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

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

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

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

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

Referenced by ArithRef.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 2529 of file z3py.py.

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

Referenced by ArrayRef.domain(), ArrayRef.domain_n(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), BitVecRef.size(), and ExprRef.sort_kind().

Field Documentation

◆ ctx

ctx

Definition at line 2537 of file z3py.py.

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), FuncDeclRef.__call__(), AstMap.__contains__(), AstRef.__copy__(), Goal.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), AstRef.__deepcopy__(), Datatype.__deepcopy__(), ParamsRef.__deepcopy__(), ParamDescrsRef.__deepcopy__(), Goal.__deepcopy__(), AstVector.__deepcopy__(), AstMap.__deepcopy__(), FuncEntry.__deepcopy__(), FuncInterp.__deepcopy__(), ModelRef.__deepcopy__(), Statistics.__deepcopy__(), Context.__del__(), AstRef.__del__(), ScopedConstructor.__del__(), ScopedConstructorList.__del__(), ParamsRef.__del__(), ParamDescrsRef.__del__(), Goal.__del__(), AstVector.__del__(), AstMap.__del__(), FuncEntry.__del__(), FuncInterp.__del__(), ModelRef.__del__(), Statistics.__del__(), Solver.__del__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), AstVector.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), AstMap.__getitem__(), ArithRef.__gt__(), BitVecRef.__gt__(), BitVecRef.__invert__(), ArithRef.__le__(), BitVecRef.__le__(), AstVector.__len__(), AstMap.__len__(), ModelRef.__len__(), Statistics.__len__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), BoolRef.__mul__(), ArithRef.__mul__(), BitVecRef.__mul__(), ExprRef.__ne__(), ArithRef.__neg__(), BitVecRef.__neg__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), ParamsRef.__repr__(), ParamDescrsRef.__repr__(), AstMap.__repr__(), Statistics.__repr__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), AstVector.__setitem__(), AstMap.__setitem__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), DatatypeSortRef.accessor(), ExprRef.arg(), FuncEntry.arg_value(), FuncInterp.arity(), Goal.as_expr(), Solver.assert_and_track(), Goal.assert_exprs(), Solver.assert_exprs(), QuantifierRef.body(), Solver.check(), Goal.convert_model(), AstRef.ctx_ref(), ExprRef.decl(), ModelRef.decls(), ArrayRef.default(), RatNumRef.denominator(), Goal.depth(), Goal.dimacs(), FuncDeclRef.domain(), ArraySortRef.domain_n(), FuncInterp.else_value(), FuncInterp.entry(), AstMap.erase(), ModelRef.eval(), Goal.get(), ParamDescrsRef.get_documentation(), ModelRef.get_interp(), Statistics.get_key_value(), ParamDescrsRef.get_kind(), ParamDescrsRef.get_name(), ModelRef.get_sort(), ModelRef.get_universe(), Goal.inconsistent(), AstMap.keys(), Statistics.keys(), Solver.model(), SortRef.name(), QuantifierRef.no_pattern(), FuncEntry.num_args(), FuncInterp.num_entries(), Solver.num_scopes(), ModelRef.num_sorts(), FuncDeclRef.params(), QuantifierRef.pattern(), AlgebraicNumRef.poly(), Solver.pop(), Goal.prec(), ModelRef.project(), ModelRef.project_with_witness(), Solver.push(), AstVector.push(), QuantifierRef.qid(), FuncDeclRef.range(), ArraySortRef.range(), DatatypeSortRef.recognizer(), Context.ref(), AstMap.reset(), Solver.reset(), AstVector.resize(), Solver.set(), ParamsRef.set(), Goal.sexpr(), AstVector.sexpr(), ModelRef.sexpr(), ParamDescrsRef.size(), Goal.size(), QuantifierRef.skolem_id(), AstVector.translate(), AstRef.translate(), Goal.translate(), ModelRef.translate(), ExprRef.update(), ParamsRef.validate(), FuncEntry.value(), QuantifierRef.var_name(), and QuantifierRef.var_sort().