Z3
 
Loading...
Searching...
No Matches
Public Member Functions
ArithRef Class Reference
+ Inheritance diagram for ArithRef:

Public Member Functions

def sort (self)
 
def is_int (self)
 
def is_real (self)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def __mul__ (self, other)
 
def __rmul__ (self, other)
 
def __sub__ (self, other)
 
def __rsub__ (self, other)
 
def __pow__ (self, other)
 
def __rpow__ (self, other)
 
def __div__ (self, other)
 
def __truediv__ (self, other)
 
def __rdiv__ (self, other)
 
def __rtruediv__ (self, other)
 
def __mod__ (self, other)
 
def __rmod__ (self, other)
 
def __neg__ (self)
 
def __pos__ (self)
 
def __le__ (self, other)
 
def __lt__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
- Public Member Functions inherited from ExprRef
def as_ast (self)
 
def get_id (self)
 
def sort (self)
 
def sort_kind (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 
def params (self)
 
def decl (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
def from_string (self, s)
 
def serialize (self)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
def __deepcopy__ (self, memo={})
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def __copy__ (self)
 
def hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 
- Protected Member Functions inherited from Z3PPObject
def _repr_html_ (self)
 

Detailed Description

Integer and Real expressions.

Definition at line 2380 of file z3py.py.

Member Function Documentation

◆ __add__()

def __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 2418 of file z3py.py.

2418 def __add__(self, other):
2419 """Create the Z3 expression `self + other`.
2420
2421 >>> x = Int('x')
2422 >>> y = Int('y')
2423 >>> x + y
2424 x + y
2425 >>> (x + y).sort()
2426 Int
2427 """
2428 a, b = _coerce_exprs(self, other)
2429 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2430

◆ __div__()

def __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 2517 of file z3py.py.

2517 def __div__(self, other):
2518 """Create the Z3 expression `other/self`.
2519
2520 >>> x = Int('x')
2521 >>> y = Int('y')
2522 >>> x/y
2523 x/y
2524 >>> (x/y).sort()
2525 Int
2526 >>> (x/y).sexpr()
2527 '(div x y)'
2528 >>> x = Real('x')
2529 >>> y = Real('y')
2530 >>> x/y
2531 x/y
2532 >>> (x/y).sort()
2533 Real
2534 >>> (x/y).sexpr()
2535 '(/ x y)'
2536 """
2537 a, b = _coerce_exprs(self, other)
2538 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2539
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__(), BitVecRef.__truediv__(), and FPRef.__truediv__().

◆ __ge__()

def __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 2651 of file z3py.py.

2651 def __ge__(self, other):
2652 """Create the Z3 expression `other >= self`.
2653
2654 >>> x, y = Ints('x y')
2655 >>> x >= y
2656 x >= y
2657 >>> y = Real('y')
2658 >>> x >= y
2659 ToReal(x) >= y
2660 """
2661 a, b = _coerce_exprs(self, other)
2662 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2663
2664
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.

◆ __gt__()

def __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 2638 of file z3py.py.

2638 def __gt__(self, other):
2639 """Create the Z3 expression `other > self`.
2640
2641 >>> x, y = Ints('x y')
2642 >>> x > y
2643 x > y
2644 >>> y = Real('y')
2645 >>> x > y
2646 ToReal(x) > y
2647 """
2648 a, b = _coerce_exprs(self, other)
2649 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2650
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.

◆ __le__()

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

2612 def __le__(self, other):
2613 """Create the Z3 expression `other <= self`.
2614
2615 >>> x, y = Ints('x y')
2616 >>> x <= y
2617 x <= y
2618 >>> y = Real('y')
2619 >>> x <= y
2620 ToReal(x) <= y
2621 """
2622 a, b = _coerce_exprs(self, other)
2623 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2624
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.

◆ __lt__()

def __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 2625 of file z3py.py.

2625 def __lt__(self, other):
2626 """Create the Z3 expression `other < self`.
2627
2628 >>> x, y = Ints('x y')
2629 >>> x < y
2630 x < y
2631 >>> y = Real('y')
2632 >>> x < y
2633 ToReal(x) < y
2634 """
2635 a, b = _coerce_exprs(self, other)
2636 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2637
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.

◆ __mod__()

def __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 2565 of file z3py.py.

2565 def __mod__(self, other):
2566 """Create the Z3 expression `other%self`.
2567
2568 >>> x = Int('x')
2569 >>> y = Int('y')
2570 >>> x % y
2571 x%y
2572 >>> simplify(IntVal(10) % IntVal(3))
2573 1
2574 """
2575 a, b = _coerce_exprs(self, other)
2576 if z3_debug():
2577 _z3_assert(a.is_int(), "Z3 integer expression expected")
2578 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2579
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__()

def __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 2441 of file z3py.py.

2441 def __mul__(self, other):
2442 """Create the Z3 expression `self * other`.
2443
2444 >>> x = Real('x')
2445 >>> y = Real('y')
2446 >>> x * y
2447 x*y
2448 >>> (x * y).sort()
2449 Real
2450 """
2451 if isinstance(other, BoolRef):
2452 return If(other, self, 0)
2453 a, b = _coerce_exprs(self, other)
2454 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2455

◆ __neg__()

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

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

Definition at line 2592 of file z3py.py.

2592 def __neg__(self):
2593 """Return an expression representing `-self`.
2594
2595 >>> x = Int('x')
2596 >>> -x
2597 -x
2598 >>> simplify(-(-x))
2599 x
2600 """
2601 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2602
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.

◆ __pos__()

def __pos__ (   self)
Return `self`.

>>> x = Int('x')
>>> +x
x

Definition at line 2603 of file z3py.py.

2603 def __pos__(self):
2604 """Return `self`.
2605
2606 >>> x = Int('x')
2607 >>> +x
2608 x
2609 """
2610 return self
2611

◆ __pow__()

def __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 2489 of file z3py.py.

2489 def __pow__(self, other):
2490 """Create the Z3 expression `self**other` (** is the power operator).
2491
2492 >>> x = Real('x')
2493 >>> x**3
2494 x**3
2495 >>> (x**3).sort()
2496 Real
2497 >>> simplify(IntVal(2)**8)
2498 256
2499 """
2500 a, b = _coerce_exprs(self, other)
2501 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2502
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.

◆ __radd__()

def __radd__ (   self,
  other 
)
Create the Z3 expression `other + self`.

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

Definition at line 2431 of file z3py.py.

2431 def __radd__(self, other):
2432 """Create the Z3 expression `other + self`.
2433
2434 >>> x = Int('x')
2435 >>> 10 + x
2436 10 + x
2437 """
2438 a, b = _coerce_exprs(self, other)
2439 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2440

◆ __rdiv__()

def __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 2544 of file z3py.py.

2544 def __rdiv__(self, other):
2545 """Create the Z3 expression `other/self`.
2546
2547 >>> x = Int('x')
2548 >>> 10/x
2549 10/x
2550 >>> (10/x).sexpr()
2551 '(div 10 x)'
2552 >>> x = Real('x')
2553 >>> 10/x
2554 10/x
2555 >>> (10/x).sexpr()
2556 '(/ 10.0 x)'
2557 """
2558 a, b = _coerce_exprs(self, other)
2559 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2560

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

◆ __rmod__()

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

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

Definition at line 2580 of file z3py.py.

2580 def __rmod__(self, other):
2581 """Create the Z3 expression `other%self`.
2582
2583 >>> x = Int('x')
2584 >>> 10 % x
2585 10%x
2586 """
2587 a, b = _coerce_exprs(self, other)
2588 if z3_debug():
2589 _z3_assert(a.is_int(), "Z3 integer expression expected")
2590 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2591

◆ __rmul__()

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

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

Definition at line 2456 of file z3py.py.

2456 def __rmul__(self, other):
2457 """Create the Z3 expression `other * self`.
2458
2459 >>> x = Real('x')
2460 >>> 10 * x
2461 10*x
2462 """
2463 a, b = _coerce_exprs(self, other)
2464 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2465

◆ __rpow__()

def __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 2503 of file z3py.py.

2503 def __rpow__(self, other):
2504 """Create the Z3 expression `other**self` (** is the power operator).
2505
2506 >>> x = Real('x')
2507 >>> 2**x
2508 2**x
2509 >>> (2**x).sort()
2510 Real
2511 >>> simplify(2**IntVal(8))
2512 256
2513 """
2514 a, b = _coerce_exprs(self, other)
2515 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2516

◆ __rsub__()

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

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

Definition at line 2479 of file z3py.py.

2479 def __rsub__(self, other):
2480 """Create the Z3 expression `other - self`.
2481
2482 >>> x = Int('x')
2483 >>> 10 - x
2484 10 - x
2485 """
2486 a, b = _coerce_exprs(self, other)
2487 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2488

◆ __rtruediv__()

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

Definition at line 2561 of file z3py.py.

2561 def __rtruediv__(self, other):
2562 """Create the Z3 expression `other/self`."""
2563 return self.__rdiv__(other)
2564

◆ __sub__()

def __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 2466 of file z3py.py.

2466 def __sub__(self, other):
2467 """Create the Z3 expression `self - other`.
2468
2469 >>> x = Int('x')
2470 >>> y = Int('y')
2471 >>> x - y
2472 x - y
2473 >>> (x - y).sort()
2474 Int
2475 """
2476 a, b = _coerce_exprs(self, other)
2477 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2478

◆ __truediv__()

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

Definition at line 2540 of file z3py.py.

2540 def __truediv__(self, other):
2541 """Create the Z3 expression `other/self`."""
2542 return self.__div__(other)
2543

◆ is_int()

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

2393 def is_int(self):
2394 """Return `True` if `self` is an integer expression.
2395
2396 >>> x = Int('x')
2397 >>> x.is_int()
2398 True
2399 >>> (x + 1).is_int()
2400 True
2401 >>> y = Real('y')
2402 >>> (x + y).is_int()
2403 False
2404 """
2405 return self.sort().is_int()
2406

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

◆ is_real()

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

2407 def is_real(self):
2408 """Return `True` if `self` is an real expression.
2409
2410 >>> x = Real('x')
2411 >>> x.is_real()
2412 True
2413 >>> (x + 1).is_real()
2414 True
2415 """
2416 return self.sort().is_real()
2417

Referenced by ArithRef.is_real().

◆ sort()

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

2383 def sort(self):
2384 """Return the sort (type) of the arithmetical expression `self`.
2385
2386 >>> Int('x').sort()
2387 Int
2388 >>> (Real('x') + 1).sort()
2389 Real
2390 """
2391 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2392
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by ArithRef.__add__(), ArithRef.__div__(), ArithRef.__mul__(), ArithRef.__pow__(), ArithRef.__rpow__(), ArithRef.__sub__(), FPNumRef.as_string(), ArrayRef.domain(), ArrayRef.domain_n(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), ArithRef.sort(), and ExprRef.sort_kind().