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)
 
- 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 2437 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 2475 of file z3py.py.

2475 def __add__(self, other):
2476 """Create the Z3 expression `self + other`.
2477
2478 >>> x = Int('x')
2479 >>> y = Int('y')
2480 >>> x + y
2481 x + y
2482 >>> (x + y).sort()
2483 Int
2484 """
2485 a, b = _coerce_exprs(self, other)
2486 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2487

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

2574 def __div__(self, other):
2575 """Create the Z3 expression `other/self`.
2576
2577 >>> x = Int('x')
2578 >>> y = Int('y')
2579 >>> x/y
2580 x/y
2581 >>> (x/y).sort()
2582 Int
2583 >>> (x/y).sexpr()
2584 '(div x y)'
2585 >>> x = Real('x')
2586 >>> y = Real('y')
2587 >>> x/y
2588 x/y
2589 >>> (x/y).sort()
2590 Real
2591 >>> (x/y).sexpr()
2592 '(/ x y)'
2593 """
2594 a, b = _coerce_exprs(self, other)
2595 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2596
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 2708 of file z3py.py.

2708 def __ge__(self, other):
2709 """Create the Z3 expression `other >= self`.
2710
2711 >>> x, y = Ints('x y')
2712 >>> x >= y
2713 x >= y
2714 >>> y = Real('y')
2715 >>> x >= y
2716 ToReal(x) >= y
2717 """
2718 a, b = _coerce_exprs(self, other)
2719 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2720
2721
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 2695 of file z3py.py.

2695 def __gt__(self, other):
2696 """Create the Z3 expression `other > self`.
2697
2698 >>> x, y = Ints('x y')
2699 >>> x > y
2700 x > y
2701 >>> y = Real('y')
2702 >>> x > y
2703 ToReal(x) > y
2704 """
2705 a, b = _coerce_exprs(self, other)
2706 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2707
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 2669 of file z3py.py.

2669 def __le__(self, other):
2670 """Create the Z3 expression `other <= self`.
2671
2672 >>> x, y = Ints('x y')
2673 >>> x <= y
2674 x <= y
2675 >>> y = Real('y')
2676 >>> x <= y
2677 ToReal(x) <= y
2678 """
2679 a, b = _coerce_exprs(self, other)
2680 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2681
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 2682 of file z3py.py.

2682 def __lt__(self, other):
2683 """Create the Z3 expression `other < self`.
2684
2685 >>> x, y = Ints('x y')
2686 >>> x < y
2687 x < y
2688 >>> y = Real('y')
2689 >>> x < y
2690 ToReal(x) < y
2691 """
2692 a, b = _coerce_exprs(self, other)
2693 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2694
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 2622 of file z3py.py.

2622 def __mod__(self, other):
2623 """Create the Z3 expression `other%self`.
2624
2625 >>> x = Int('x')
2626 >>> y = Int('y')
2627 >>> x % y
2628 x%y
2629 >>> simplify(IntVal(10) % IntVal(3))
2630 1
2631 """
2632 a, b = _coerce_exprs(self, other)
2633 if z3_debug():
2634 _z3_assert(a.is_int(), "Z3 integer expression expected")
2635 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2636
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 2498 of file z3py.py.

2498 def __mul__(self, other):
2499 """Create the Z3 expression `self * other`.
2500
2501 >>> x = Real('x')
2502 >>> y = Real('y')
2503 >>> x * y
2504 x*y
2505 >>> (x * y).sort()
2506 Real
2507 """
2508 if isinstance(other, BoolRef):
2509 return If(other, self, 0)
2510 a, b = _coerce_exprs(self, other)
2511 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2512

◆ __neg__()

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

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

Definition at line 2649 of file z3py.py.

2649 def __neg__(self):
2650 """Return an expression representing `-self`.
2651
2652 >>> x = Int('x')
2653 >>> -x
2654 -x
2655 >>> simplify(-(-x))
2656 x
2657 """
2658 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2659
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 2660 of file z3py.py.

2660 def __pos__(self):
2661 """Return `self`.
2662
2663 >>> x = Int('x')
2664 >>> +x
2665 x
2666 """
2667 return self
2668

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

2546 def __pow__(self, other):
2547 """Create the Z3 expression `self**other` (** is the power operator).
2548
2549 >>> x = Real('x')
2550 >>> x**3
2551 x**3
2552 >>> (x**3).sort()
2553 Real
2554 >>> simplify(IntVal(2)**8)
2555 256
2556 """
2557 a, b = _coerce_exprs(self, other)
2558 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2559
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 2488 of file z3py.py.

2488 def __radd__(self, other):
2489 """Create the Z3 expression `other + self`.
2490
2491 >>> x = Int('x')
2492 >>> 10 + x
2493 10 + x
2494 """
2495 a, b = _coerce_exprs(self, other)
2496 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2497

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

2601 def __rdiv__(self, other):
2602 """Create the Z3 expression `other/self`.
2603
2604 >>> x = Int('x')
2605 >>> 10/x
2606 10/x
2607 >>> (10/x).sexpr()
2608 '(div 10 x)'
2609 >>> x = Real('x')
2610 >>> 10/x
2611 10/x
2612 >>> (10/x).sexpr()
2613 '(/ 10.0 x)'
2614 """
2615 a, b = _coerce_exprs(self, other)
2616 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2617

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

2637 def __rmod__(self, other):
2638 """Create the Z3 expression `other%self`.
2639
2640 >>> x = Int('x')
2641 >>> 10 % x
2642 10%x
2643 """
2644 a, b = _coerce_exprs(self, other)
2645 if z3_debug():
2646 _z3_assert(a.is_int(), "Z3 integer expression expected")
2647 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2648

◆ __rmul__()

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

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

Definition at line 2513 of file z3py.py.

2513 def __rmul__(self, other):
2514 """Create the Z3 expression `other * self`.
2515
2516 >>> x = Real('x')
2517 >>> 10 * x
2518 10*x
2519 """
2520 a, b = _coerce_exprs(self, other)
2521 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2522

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

2560 def __rpow__(self, other):
2561 """Create the Z3 expression `other**self` (** is the power operator).
2562
2563 >>> x = Real('x')
2564 >>> 2**x
2565 2**x
2566 >>> (2**x).sort()
2567 Real
2568 >>> simplify(2**IntVal(8))
2569 256
2570 """
2571 a, b = _coerce_exprs(self, other)
2572 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2573

◆ __rsub__()

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

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

Definition at line 2536 of file z3py.py.

2536 def __rsub__(self, other):
2537 """Create the Z3 expression `other - self`.
2538
2539 >>> x = Int('x')
2540 >>> 10 - x
2541 10 - x
2542 """
2543 a, b = _coerce_exprs(self, other)
2544 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2545

◆ __rtruediv__()

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

Definition at line 2618 of file z3py.py.

2618 def __rtruediv__(self, other):
2619 """Create the Z3 expression `other/self`."""
2620 return self.__rdiv__(other)
2621

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

2523 def __sub__(self, other):
2524 """Create the Z3 expression `self - other`.
2525
2526 >>> x = Int('x')
2527 >>> y = Int('y')
2528 >>> x - y
2529 x - y
2530 >>> (x - y).sort()
2531 Int
2532 """
2533 a, b = _coerce_exprs(self, other)
2534 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2535

◆ __truediv__()

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

Definition at line 2597 of file z3py.py.

2597 def __truediv__(self, other):
2598 """Create the Z3 expression `other/self`."""
2599 return self.__div__(other)
2600

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

2450 def is_int(self):
2451 """Return `True` if `self` is an integer expression.
2452
2453 >>> x = Int('x')
2454 >>> x.is_int()
2455 True
2456 >>> (x + 1).is_int()
2457 True
2458 >>> y = Real('y')
2459 >>> (x + y).is_int()
2460 False
2461 """
2462 return self.sort().is_int()
2463

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

2464 def is_real(self):
2465 """Return `True` if `self` is an real expression.
2466
2467 >>> x = Real('x')
2468 >>> x.is_real()
2469 True
2470 >>> (x + 1).is_real()
2471 True
2472 """
2473 return self.sort().is_real()
2474

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

2440 def sort(self):
2441 """Return the sort (type) of the arithmetical expression `self`.
2442
2443 >>> Int('x').sort()
2444 Int
2445 >>> (Real('x') + 1).sort()
2446 Real
2447 """
2448 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2449
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.