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)
 
 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)
 
- Public Member Functions inherited from Z3PPObject
 use_pp (self)
 

Data Fields

 ctx = _coerce_exprs(self, other)
 
- Data Fields inherited from ExprRef
 ctx
 
- Data Fields inherited from AstRef
 ast = ast
 
 ctx = _get_ctx(ctx)
 

Additional Inherited Members

- Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)
 

Detailed Description

Integer and Real expressions.

Definition at line 2430 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 2468 of file z3py.py.

2468 def __add__(self, other):
2469 """Create the Z3 expression `self + other`.
2470
2471 >>> x = Int('x')
2472 >>> y = Int('y')
2473 >>> x + y
2474 x + y
2475 >>> (x + y).sort()
2476 Int
2477 """
2478 a, b = _coerce_exprs(self, other)
2479 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2480

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

2567 def __div__(self, other):
2568 """Create the Z3 expression `other/self`.
2569
2570 >>> x = Int('x')
2571 >>> y = Int('y')
2572 >>> x/y
2573 x/y
2574 >>> (x/y).sort()
2575 Int
2576 >>> (x/y).sexpr()
2577 '(div x y)'
2578 >>> x = Real('x')
2579 >>> y = Real('y')
2580 >>> x/y
2581 x/y
2582 >>> (x/y).sort()
2583 Real
2584 >>> (x/y).sexpr()
2585 '(/ x y)'
2586 """
2587 a, b = _coerce_exprs(self, other)
2588 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2589
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 2701 of file z3py.py.

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

2688 def __gt__(self, other):
2689 """Create the Z3 expression `other > self`.
2690
2691 >>> x, y = Ints('x y')
2692 >>> x > y
2693 x > y
2694 >>> y = Real('y')
2695 >>> x > y
2696 ToReal(x) > y
2697 """
2698 a, b = _coerce_exprs(self, other)
2699 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2700
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 2662 of file z3py.py.

2662 def __le__(self, other):
2663 """Create the Z3 expression `other <= self`.
2664
2665 >>> x, y = Ints('x y')
2666 >>> x <= y
2667 x <= y
2668 >>> y = Real('y')
2669 >>> x <= y
2670 ToReal(x) <= y
2671 """
2672 a, b = _coerce_exprs(self, other)
2673 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2674
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 2675 of file z3py.py.

2675 def __lt__(self, other):
2676 """Create the Z3 expression `other < self`.
2677
2678 >>> x, y = Ints('x y')
2679 >>> x < y
2680 x < y
2681 >>> y = Real('y')
2682 >>> x < y
2683 ToReal(x) < y
2684 """
2685 a, b = _coerce_exprs(self, other)
2686 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2687
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 2615 of file z3py.py.

2615 def __mod__(self, other):
2616 """Create the Z3 expression `other%self`.
2617
2618 >>> x = Int('x')
2619 >>> y = Int('y')
2620 >>> x % y
2621 x%y
2622 >>> simplify(IntVal(10) % IntVal(3))
2623 1
2624 """
2625 a, b = _coerce_exprs(self, other)
2626 if z3_debug():
2627 _z3_assert(a.is_int(), "Z3 integer expression expected")
2628 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2629
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 2491 of file z3py.py.

2491 def __mul__(self, other):
2492 """Create the Z3 expression `self * other`.
2493
2494 >>> x = Real('x')
2495 >>> y = Real('y')
2496 >>> x * y
2497 x*y
2498 >>> (x * y).sort()
2499 Real
2500 """
2501 if isinstance(other, BoolRef):
2502 return If(other, self, 0)
2503 a, b = _coerce_exprs(self, other)
2504 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2505

◆ __neg__()

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

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

Definition at line 2642 of file z3py.py.

2642 def __neg__(self):
2643 """Return an expression representing `-self`.
2644
2645 >>> x = Int('x')
2646 >>> -x
2647 -x
2648 >>> simplify(-(-x))
2649 x
2650 """
2651 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2652
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 2653 of file z3py.py.

2653 def __pos__(self):
2654 """Return `self`.
2655
2656 >>> x = Int('x')
2657 >>> +x
2658 x
2659 """
2660 return self
2661

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

2539 def __pow__(self, other):
2540 """Create the Z3 expression `self**other` (** is the power operator).
2541
2542 >>> x = Real('x')
2543 >>> x**3
2544 x**3
2545 >>> (x**3).sort()
2546 Real
2547 >>> simplify(IntVal(2)**8)
2548 256
2549 """
2550 a, b = _coerce_exprs(self, other)
2551 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2552
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 2481 of file z3py.py.

2481 def __radd__(self, other):
2482 """Create the Z3 expression `other + self`.
2483
2484 >>> x = Int('x')
2485 >>> 10 + x
2486 10 + x
2487 """
2488 a, b = _coerce_exprs(self, other)
2489 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2490

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

2594 def __rdiv__(self, other):
2595 """Create the Z3 expression `other/self`.
2596
2597 >>> x = Int('x')
2598 >>> 10/x
2599 10/x
2600 >>> (10/x).sexpr()
2601 '(div 10 x)'
2602 >>> x = Real('x')
2603 >>> 10/x
2604 10/x
2605 >>> (10/x).sexpr()
2606 '(/ 10.0 x)'
2607 """
2608 a, b = _coerce_exprs(self, other)
2609 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2610

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

2630 def __rmod__(self, other):
2631 """Create the Z3 expression `other%self`.
2632
2633 >>> x = Int('x')
2634 >>> 10 % x
2635 10%x
2636 """
2637 a, b = _coerce_exprs(self, other)
2638 if z3_debug():
2639 _z3_assert(a.is_int(), "Z3 integer expression expected")
2640 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2641

◆ __rmul__()

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

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

Definition at line 2506 of file z3py.py.

2506 def __rmul__(self, other):
2507 """Create the Z3 expression `other * self`.
2508
2509 >>> x = Real('x')
2510 >>> 10 * x
2511 10*x
2512 """
2513 a, b = _coerce_exprs(self, other)
2514 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2515

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

2553 def __rpow__(self, other):
2554 """Create the Z3 expression `other**self` (** is the power operator).
2555
2556 >>> x = Real('x')
2557 >>> 2**x
2558 2**x
2559 >>> (2**x).sort()
2560 Real
2561 >>> simplify(2**IntVal(8))
2562 256
2563 """
2564 a, b = _coerce_exprs(self, other)
2565 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2566

◆ __rsub__()

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

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

Definition at line 2529 of file z3py.py.

2529 def __rsub__(self, other):
2530 """Create the Z3 expression `other - self`.
2531
2532 >>> x = Int('x')
2533 >>> 10 - x
2534 10 - x
2535 """
2536 a, b = _coerce_exprs(self, other)
2537 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2538

◆ __rtruediv__()

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

Definition at line 2611 of file z3py.py.

2611 def __rtruediv__(self, other):
2612 """Create the Z3 expression `other/self`."""
2613 return self.__rdiv__(other)
2614

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

2516 def __sub__(self, other):
2517 """Create the Z3 expression `self - other`.
2518
2519 >>> x = Int('x')
2520 >>> y = Int('y')
2521 >>> x - y
2522 x - y
2523 >>> (x - y).sort()
2524 Int
2525 """
2526 a, b = _coerce_exprs(self, other)
2527 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2528

◆ __truediv__()

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

Definition at line 2590 of file z3py.py.

2590 def __truediv__(self, other):
2591 """Create the Z3 expression `other/self`."""
2592 return self.__div__(other)
2593

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

2443 def is_int(self):
2444 """Return `True` if `self` is an integer expression.
2445
2446 >>> x = Int('x')
2447 >>> x.is_int()
2448 True
2449 >>> (x + 1).is_int()
2450 True
2451 >>> y = Real('y')
2452 >>> (x + y).is_int()
2453 False
2454 """
2455 return self.sort().is_int()
2456

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

2457 def is_real(self):
2458 """Return `True` if `self` is an real expression.
2459
2460 >>> x = Real('x')
2461 >>> x.is_real()
2462 True
2463 >>> (x + 1).is_real()
2464 True
2465 """
2466 return self.sort().is_real()
2467

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

2433 def sort(self):
2434 """Return the sort (type) of the arithmetical expression `self`.
2435
2436 >>> Int('x').sort()
2437 Int
2438 >>> (Real('x') + 1).sort()
2439 Real
2440 """
2441 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2442
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 = _coerce_exprs(self, other)

Definition at line 2441 of file z3py.py.

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), FuncDeclRef.__call__(), AstMap.__contains__(), AstRef.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), Goal.__copy__(), ModelRef.__copy__(), AstMap.__deepcopy__(), AstRef.__deepcopy__(), AstVector.__deepcopy__(), Datatype.__deepcopy__(), FuncEntry.__deepcopy__(), FuncInterp.__deepcopy__(), Goal.__deepcopy__(), ModelRef.__deepcopy__(), ParamDescrsRef.__deepcopy__(), ParamsRef.__deepcopy__(), Statistics.__deepcopy__(), AstMap.__del__(), AstRef.__del__(), AstVector.__del__(), Context.__del__(), FuncEntry.__del__(), FuncInterp.__del__(), Goal.__del__(), ModelRef.__del__(), ParamDescrsRef.__del__(), ParamsRef.__del__(), ScopedConstructor.__del__(), ScopedConstructorList.__del__(), Solver.__del__(), Statistics.__del__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), AstMap.__getitem__(), AstVector.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), ArithRef.__gt__(), BitVecRef.__gt__(), BitVecRef.__invert__(), ArithRef.__le__(), BitVecRef.__le__(), AstMap.__len__(), AstVector.__len__(), ModelRef.__len__(), Statistics.__len__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), BoolRef.__mul__(), ExprRef.__ne__(), ArithRef.__neg__(), BitVecRef.__neg__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), AstMap.__repr__(), ParamDescrsRef.__repr__(), ParamsRef.__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__(), AstMap.__setitem__(), AstVector.__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(), AstVector.push(), Solver.push(), QuantifierRef.qid(), ArraySortRef.range(), FuncDeclRef.range(), DatatypeSortRef.recognizer(), Context.ref(), AstMap.reset(), Solver.reset(), AstVector.resize(), ParamsRef.set(), Solver.set(), AstVector.sexpr(), Goal.sexpr(), ModelRef.sexpr(), Goal.size(), ParamDescrsRef.size(), QuantifierRef.skolem_id(), AstRef.translate(), AstVector.translate(), Goal.translate(), ModelRef.translate(), ParamsRef.validate(), FuncEntry.value(), QuantifierRef.var_name(), and QuantifierRef.var_sort().