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)
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)
 __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 2467 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 2505 of file z3py.py.

2505 def __add__(self, other):
2506 """Create the Z3 expression `self + other`.
2507
2508 >>> x = Int('x')
2509 >>> y = Int('y')
2510 >>> x + y
2511 x + y
2512 >>> (x + y).sort()
2513 Int
2514 """
2515 a, b = _coerce_exprs(self, other)
2516 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2517

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

2604 def __div__(self, other):
2605 """Create the Z3 expression `other/self`.
2606
2607 >>> x = Int('x')
2608 >>> y = Int('y')
2609 >>> x/y
2610 x/y
2611 >>> (x/y).sort()
2612 Int
2613 >>> (x/y).sexpr()
2614 '(div x y)'
2615 >>> x = Real('x')
2616 >>> y = Real('y')
2617 >>> x/y
2618 x/y
2619 >>> (x/y).sort()
2620 Real
2621 >>> (x/y).sexpr()
2622 '(/ x y)'
2623 """
2624 a, b = _coerce_exprs(self, other)
2625 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2626
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 2738 of file z3py.py.

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

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

2699 def __le__(self, other):
2700 """Create the Z3 expression `other <= self`.
2701
2702 >>> x, y = Ints('x y')
2703 >>> x <= y
2704 x <= y
2705 >>> y = Real('y')
2706 >>> x <= y
2707 ToReal(x) <= y
2708 """
2709 a, b = _coerce_exprs(self, other)
2710 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2711
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 2712 of file z3py.py.

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

2652 def __mod__(self, other):
2653 """Create the Z3 expression `other%self`.
2654
2655 >>> x = Int('x')
2656 >>> y = Int('y')
2657 >>> x % y
2658 x%y
2659 >>> simplify(IntVal(10) % IntVal(3))
2660 1
2661 """
2662 a, b = _coerce_exprs(self, other)
2663 if z3_debug():
2664 _z3_assert(a.is_int(), "Z3 integer expression expected")
2665 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2666
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 2528 of file z3py.py.

2528 def __mul__(self, other):
2529 """Create the Z3 expression `self * other`.
2530
2531 >>> x = Real('x')
2532 >>> y = Real('y')
2533 >>> x * y
2534 x*y
2535 >>> (x * y).sort()
2536 Real
2537 """
2538 if isinstance(other, BoolRef):
2539 return If(other, self, 0)
2540 a, b = _coerce_exprs(self, other)
2541 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2542

◆ __neg__()

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

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

Definition at line 2679 of file z3py.py.

2679 def __neg__(self):
2680 """Return an expression representing `-self`.
2681
2682 >>> x = Int('x')
2683 >>> -x
2684 -x
2685 >>> simplify(-(-x))
2686 x
2687 """
2688 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2689
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 2690 of file z3py.py.

2690 def __pos__(self):
2691 """Return `self`.
2692
2693 >>> x = Int('x')
2694 >>> +x
2695 x
2696 """
2697 return self
2698

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

2576 def __pow__(self, other):
2577 """Create the Z3 expression `self**other` (** is the power operator).
2578
2579 >>> x = Real('x')
2580 >>> x**3
2581 x**3
2582 >>> (x**3).sort()
2583 Real
2584 >>> simplify(IntVal(2)**8)
2585 256
2586 """
2587 a, b = _coerce_exprs(self, other)
2588 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2589
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 2518 of file z3py.py.

2518 def __radd__(self, other):
2519 """Create the Z3 expression `other + self`.
2520
2521 >>> x = Int('x')
2522 >>> 10 + x
2523 10 + x
2524 """
2525 a, b = _coerce_exprs(self, other)
2526 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2527

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

2631 def __rdiv__(self, other):
2632 """Create the Z3 expression `other/self`.
2633
2634 >>> x = Int('x')
2635 >>> 10/x
2636 10/x
2637 >>> (10/x).sexpr()
2638 '(div 10 x)'
2639 >>> x = Real('x')
2640 >>> 10/x
2641 10/x
2642 >>> (10/x).sexpr()
2643 '(/ 10.0 x)'
2644 """
2645 a, b = _coerce_exprs(self, other)
2646 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2647

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

2667 def __rmod__(self, other):
2668 """Create the Z3 expression `other%self`.
2669
2670 >>> x = Int('x')
2671 >>> 10 % x
2672 10%x
2673 """
2674 a, b = _coerce_exprs(self, other)
2675 if z3_debug():
2676 _z3_assert(a.is_int(), "Z3 integer expression expected")
2677 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2678

◆ __rmul__()

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

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

Definition at line 2543 of file z3py.py.

2543 def __rmul__(self, other):
2544 """Create the Z3 expression `other * self`.
2545
2546 >>> x = Real('x')
2547 >>> 10 * x
2548 10*x
2549 """
2550 a, b = _coerce_exprs(self, other)
2551 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2552

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

2590 def __rpow__(self, other):
2591 """Create the Z3 expression `other**self` (** is the power operator).
2592
2593 >>> x = Real('x')
2594 >>> 2**x
2595 2**x
2596 >>> (2**x).sort()
2597 Real
2598 >>> simplify(2**IntVal(8))
2599 256
2600 """
2601 a, b = _coerce_exprs(self, other)
2602 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2603

◆ __rsub__()

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

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

Definition at line 2566 of file z3py.py.

2566 def __rsub__(self, other):
2567 """Create the Z3 expression `other - self`.
2568
2569 >>> x = Int('x')
2570 >>> 10 - x
2571 10 - x
2572 """
2573 a, b = _coerce_exprs(self, other)
2574 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2575

◆ __rtruediv__()

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

Definition at line 2648 of file z3py.py.

2648 def __rtruediv__(self, other):
2649 """Create the Z3 expression `other/self`."""
2650 return self.__rdiv__(other)
2651

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

2553 def __sub__(self, other):
2554 """Create the Z3 expression `self - other`.
2555
2556 >>> x = Int('x')
2557 >>> y = Int('y')
2558 >>> x - y
2559 x - y
2560 >>> (x - y).sort()
2561 Int
2562 """
2563 a, b = _coerce_exprs(self, other)
2564 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2565

◆ __truediv__()

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

Definition at line 2627 of file z3py.py.

2627 def __truediv__(self, other):
2628 """Create the Z3 expression `other/self`."""
2629 return self.__div__(other)
2630

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

2480 def is_int(self):
2481 """Return `True` if `self` is an integer expression.
2482
2483 >>> x = Int('x')
2484 >>> x.is_int()
2485 True
2486 >>> (x + 1).is_int()
2487 True
2488 >>> y = Real('y')
2489 >>> (x + y).is_int()
2490 False
2491 """
2492 return self.sort().is_int()
2493

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

2494 def is_real(self):
2495 """Return `True` if `self` is an real expression.
2496
2497 >>> x = Real('x')
2498 >>> x.is_real()
2499 True
2500 >>> (x + 1).is_real()
2501 True
2502 """
2503 return self.sort().is_real()
2504

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

2470 def sort(self):
2471 """Return the sort (type) of the arithmetical expression `self`.
2472
2473 >>> Int('x').sort()
2474 Int
2475 >>> (Real('x') + 1).sort()
2476 Real
2477 """
2478 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2479
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.