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)
 
 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 2482 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 2520 of file z3py.py.

2520 def __add__(self, other):
2521 """Create the Z3 expression `self + other`.
2522
2523 >>> x = Int('x')
2524 >>> y = Int('y')
2525 >>> x + y
2526 x + y
2527 >>> (x + y).sort()
2528 Int
2529 """
2530 a, b = _coerce_exprs(self, other)
2531 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2532

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

2619 def __div__(self, other):
2620 """Create the Z3 expression `other/self`.
2621
2622 >>> x = Int('x')
2623 >>> y = Int('y')
2624 >>> x/y
2625 x/y
2626 >>> (x/y).sort()
2627 Int
2628 >>> (x/y).sexpr()
2629 '(div x y)'
2630 >>> x = Real('x')
2631 >>> y = Real('y')
2632 >>> x/y
2633 x/y
2634 >>> (x/y).sort()
2635 Real
2636 >>> (x/y).sexpr()
2637 '(/ x y)'
2638 """
2639 a, b = _coerce_exprs(self, other)
2640 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2641
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 2753 of file z3py.py.

2753 def __ge__(self, other):
2754 """Create the Z3 expression `other >= self`.
2755
2756 >>> x, y = Ints('x y')
2757 >>> x >= y
2758 x >= y
2759 >>> y = Real('y')
2760 >>> x >= y
2761 ToReal(x) >= y
2762 """
2763 a, b = _coerce_exprs(self, other)
2764 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2765
2766
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 2740 of file z3py.py.

2740 def __gt__(self, other):
2741 """Create the Z3 expression `other > self`.
2742
2743 >>> x, y = Ints('x y')
2744 >>> x > y
2745 x > y
2746 >>> y = Real('y')
2747 >>> x > y
2748 ToReal(x) > y
2749 """
2750 a, b = _coerce_exprs(self, other)
2751 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2752
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 2714 of file z3py.py.

2714 def __le__(self, other):
2715 """Create the Z3 expression `other <= self`.
2716
2717 >>> x, y = Ints('x y')
2718 >>> x <= y
2719 x <= y
2720 >>> y = Real('y')
2721 >>> x <= y
2722 ToReal(x) <= y
2723 """
2724 a, b = _coerce_exprs(self, other)
2725 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2726
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 2727 of file z3py.py.

2727 def __lt__(self, other):
2728 """Create the Z3 expression `other < self`.
2729
2730 >>> x, y = Ints('x y')
2731 >>> x < y
2732 x < y
2733 >>> y = Real('y')
2734 >>> x < y
2735 ToReal(x) < y
2736 """
2737 a, b = _coerce_exprs(self, other)
2738 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2739
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 2667 of file z3py.py.

2667 def __mod__(self, other):
2668 """Create the Z3 expression `other%self`.
2669
2670 >>> x = Int('x')
2671 >>> y = Int('y')
2672 >>> x % y
2673 x%y
2674 >>> simplify(IntVal(10) % IntVal(3))
2675 1
2676 """
2677 a, b = _coerce_exprs(self, other)
2678 if z3_debug():
2679 _z3_assert(a.is_int(), "Z3 integer expression expected")
2680 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2681
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 2543 of file z3py.py.

2543 def __mul__(self, other):
2544 """Create the Z3 expression `self * other`.
2545
2546 >>> x = Real('x')
2547 >>> y = Real('y')
2548 >>> x * y
2549 x*y
2550 >>> (x * y).sort()
2551 Real
2552 """
2553 if isinstance(other, BoolRef):
2554 return If(other, self, 0)
2555 a, b = _coerce_exprs(self, other)
2556 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2557

◆ __neg__()

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

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

Definition at line 2694 of file z3py.py.

2694 def __neg__(self):
2695 """Return an expression representing `-self`.
2696
2697 >>> x = Int('x')
2698 >>> -x
2699 -x
2700 >>> simplify(-(-x))
2701 x
2702 """
2703 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2704
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 2705 of file z3py.py.

2705 def __pos__(self):
2706 """Return `self`.
2707
2708 >>> x = Int('x')
2709 >>> +x
2710 x
2711 """
2712 return self
2713

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

2591 def __pow__(self, other):
2592 """Create the Z3 expression `self**other` (** is the power operator).
2593
2594 >>> x = Real('x')
2595 >>> x**3
2596 x**3
2597 >>> (x**3).sort()
2598 Real
2599 >>> simplify(IntVal(2)**8)
2600 256
2601 """
2602 a, b = _coerce_exprs(self, other)
2603 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2604
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 2533 of file z3py.py.

2533 def __radd__(self, other):
2534 """Create the Z3 expression `other + self`.
2535
2536 >>> x = Int('x')
2537 >>> 10 + x
2538 10 + x
2539 """
2540 a, b = _coerce_exprs(self, other)
2541 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2542

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

2646 def __rdiv__(self, other):
2647 """Create the Z3 expression `other/self`.
2648
2649 >>> x = Int('x')
2650 >>> 10/x
2651 10/x
2652 >>> (10/x).sexpr()
2653 '(div 10 x)'
2654 >>> x = Real('x')
2655 >>> 10/x
2656 10/x
2657 >>> (10/x).sexpr()
2658 '(/ 10.0 x)'
2659 """
2660 a, b = _coerce_exprs(self, other)
2661 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2662

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

2682 def __rmod__(self, other):
2683 """Create the Z3 expression `other%self`.
2684
2685 >>> x = Int('x')
2686 >>> 10 % x
2687 10%x
2688 """
2689 a, b = _coerce_exprs(self, other)
2690 if z3_debug():
2691 _z3_assert(a.is_int(), "Z3 integer expression expected")
2692 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2693

◆ __rmul__()

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

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

Definition at line 2558 of file z3py.py.

2558 def __rmul__(self, other):
2559 """Create the Z3 expression `other * self`.
2560
2561 >>> x = Real('x')
2562 >>> 10 * x
2563 10*x
2564 """
2565 a, b = _coerce_exprs(self, other)
2566 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2567

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

2605 def __rpow__(self, other):
2606 """Create the Z3 expression `other**self` (** is the power operator).
2607
2608 >>> x = Real('x')
2609 >>> 2**x
2610 2**x
2611 >>> (2**x).sort()
2612 Real
2613 >>> simplify(2**IntVal(8))
2614 256
2615 """
2616 a, b = _coerce_exprs(self, other)
2617 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2618

◆ __rsub__()

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

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

Definition at line 2581 of file z3py.py.

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

◆ __rtruediv__()

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

Definition at line 2663 of file z3py.py.

2663 def __rtruediv__(self, other):
2664 """Create the Z3 expression `other/self`."""
2665 return self.__rdiv__(other)
2666

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

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

◆ __truediv__()

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

Definition at line 2642 of file z3py.py.

2642 def __truediv__(self, other):
2643 """Create the Z3 expression `other/self`."""
2644 return self.__div__(other)
2645

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

2495 def is_int(self):
2496 """Return `True` if `self` is an integer expression.
2497
2498 >>> x = Int('x')
2499 >>> x.is_int()
2500 True
2501 >>> (x + 1).is_int()
2502 True
2503 >>> y = Real('y')
2504 >>> (x + y).is_int()
2505 False
2506 """
2507 return self.sort().is_int()
2508

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

2509 def is_real(self):
2510 """Return `True` if `self` is an real expression.
2511
2512 >>> x = Real('x')
2513 >>> x.is_real()
2514 True
2515 >>> (x + 1).is_real()
2516 True
2517 """
2518 return self.sort().is_real()
2519

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

2485 def sort(self):
2486 """Return the sort (type) of the arithmetical expression `self`.
2487
2488 >>> Int('x').sort()
2489 Int
2490 >>> (Real('x') + 1).sort()
2491 Real
2492 """
2493 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2494
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 2493 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(), ParamsRef.validate(), FuncEntry.value(), QuantifierRef.var_name(), and QuantifierRef.var_sort().