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
 

Detailed Description

Integer and Real expressions.

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

2409 def __add__(self, other):
2410 """Create the Z3 expression `self + other`.
2411
2412 >>> x = Int('x')
2413 >>> y = Int('y')
2414 >>> x + y
2415 x + y
2416 >>> (x + y).sort()
2417 Int
2418 """
2419 a, b = _coerce_exprs(self, other)
2420 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2421

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

2508 def __div__(self, other):
2509 """Create the Z3 expression `other/self`.
2510
2511 >>> x = Int('x')
2512 >>> y = Int('y')
2513 >>> x/y
2514 x/y
2515 >>> (x/y).sort()
2516 Int
2517 >>> (x/y).sexpr()
2518 '(div x y)'
2519 >>> x = Real('x')
2520 >>> y = Real('y')
2521 >>> x/y
2522 x/y
2523 >>> (x/y).sort()
2524 Real
2525 >>> (x/y).sexpr()
2526 '(/ x y)'
2527 """
2528 a, b = _coerce_exprs(self, other)
2529 return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2530
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 2642 of file z3py.py.

2642 def __ge__(self, other):
2643 """Create the Z3 expression `other >= self`.
2644
2645 >>> x, y = Ints('x y')
2646 >>> x >= y
2647 x >= y
2648 >>> y = Real('y')
2649 >>> x >= y
2650 ToReal(x) >= y
2651 """
2652 a, b = _coerce_exprs(self, other)
2653 return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2654
2655
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 2629 of file z3py.py.

2629 def __gt__(self, other):
2630 """Create the Z3 expression `other > self`.
2631
2632 >>> x, y = Ints('x y')
2633 >>> x > y
2634 x > y
2635 >>> y = Real('y')
2636 >>> x > y
2637 ToReal(x) > y
2638 """
2639 a, b = _coerce_exprs(self, other)
2640 return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2641
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 2603 of file z3py.py.

2603 def __le__(self, other):
2604 """Create the Z3 expression `other <= self`.
2605
2606 >>> x, y = Ints('x y')
2607 >>> x <= y
2608 x <= y
2609 >>> y = Real('y')
2610 >>> x <= y
2611 ToReal(x) <= y
2612 """
2613 a, b = _coerce_exprs(self, other)
2614 return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2615
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 2616 of file z3py.py.

2616 def __lt__(self, other):
2617 """Create the Z3 expression `other < self`.
2618
2619 >>> x, y = Ints('x y')
2620 >>> x < y
2621 x < y
2622 >>> y = Real('y')
2623 >>> x < y
2624 ToReal(x) < y
2625 """
2626 a, b = _coerce_exprs(self, other)
2627 return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2628
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 2556 of file z3py.py.

2556 def __mod__(self, other):
2557 """Create the Z3 expression `other%self`.
2558
2559 >>> x = Int('x')
2560 >>> y = Int('y')
2561 >>> x % y
2562 x%y
2563 >>> simplify(IntVal(10) % IntVal(3))
2564 1
2565 """
2566 a, b = _coerce_exprs(self, other)
2567 if z3_debug():
2568 _z3_assert(a.is_int(), "Z3 integer expression expected")
2569 return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2570
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 2432 of file z3py.py.

2432 def __mul__(self, other):
2433 """Create the Z3 expression `self * other`.
2434
2435 >>> x = Real('x')
2436 >>> y = Real('y')
2437 >>> x * y
2438 x*y
2439 >>> (x * y).sort()
2440 Real
2441 """
2442 if isinstance(other, BoolRef):
2443 return If(other, self, 0)
2444 a, b = _coerce_exprs(self, other)
2445 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2446

◆ __neg__()

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

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

Definition at line 2583 of file z3py.py.

2583 def __neg__(self):
2584 """Return an expression representing `-self`.
2585
2586 >>> x = Int('x')
2587 >>> -x
2588 -x
2589 >>> simplify(-(-x))
2590 x
2591 """
2592 return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2593
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 2594 of file z3py.py.

2594 def __pos__(self):
2595 """Return `self`.
2596
2597 >>> x = Int('x')
2598 >>> +x
2599 x
2600 """
2601 return self
2602

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

2480 def __pow__(self, other):
2481 """Create the Z3 expression `self**other` (** is the power operator).
2482
2483 >>> x = Real('x')
2484 >>> x**3
2485 x**3
2486 >>> (x**3).sort()
2487 Real
2488 >>> simplify(IntVal(2)**8)
2489 256
2490 """
2491 a, b = _coerce_exprs(self, other)
2492 return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2493
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 2422 of file z3py.py.

2422 def __radd__(self, other):
2423 """Create the Z3 expression `other + self`.
2424
2425 >>> x = Int('x')
2426 >>> 10 + x
2427 10 + x
2428 """
2429 a, b = _coerce_exprs(self, other)
2430 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2431

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

2535 def __rdiv__(self, other):
2536 """Create the Z3 expression `other/self`.
2537
2538 >>> x = Int('x')
2539 >>> 10/x
2540 10/x
2541 >>> (10/x).sexpr()
2542 '(div 10 x)'
2543 >>> x = Real('x')
2544 >>> 10/x
2545 10/x
2546 >>> (10/x).sexpr()
2547 '(/ 10.0 x)'
2548 """
2549 a, b = _coerce_exprs(self, other)
2550 return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2551

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

2571 def __rmod__(self, other):
2572 """Create the Z3 expression `other%self`.
2573
2574 >>> x = Int('x')
2575 >>> 10 % x
2576 10%x
2577 """
2578 a, b = _coerce_exprs(self, other)
2579 if z3_debug():
2580 _z3_assert(a.is_int(), "Z3 integer expression expected")
2581 return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2582

◆ __rmul__()

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

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

Definition at line 2447 of file z3py.py.

2447 def __rmul__(self, other):
2448 """Create the Z3 expression `other * self`.
2449
2450 >>> x = Real('x')
2451 >>> 10 * x
2452 10*x
2453 """
2454 a, b = _coerce_exprs(self, other)
2455 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2456

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

2494 def __rpow__(self, other):
2495 """Create the Z3 expression `other**self` (** is the power operator).
2496
2497 >>> x = Real('x')
2498 >>> 2**x
2499 2**x
2500 >>> (2**x).sort()
2501 Real
2502 >>> simplify(2**IntVal(8))
2503 256
2504 """
2505 a, b = _coerce_exprs(self, other)
2506 return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2507

◆ __rsub__()

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

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

Definition at line 2470 of file z3py.py.

2470 def __rsub__(self, other):
2471 """Create the Z3 expression `other - self`.
2472
2473 >>> x = Int('x')
2474 >>> 10 - x
2475 10 - x
2476 """
2477 a, b = _coerce_exprs(self, other)
2478 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2479

◆ __rtruediv__()

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

Definition at line 2552 of file z3py.py.

2552 def __rtruediv__(self, other):
2553 """Create the Z3 expression `other/self`."""
2554 return self.__rdiv__(other)
2555

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

2457 def __sub__(self, other):
2458 """Create the Z3 expression `self - other`.
2459
2460 >>> x = Int('x')
2461 >>> y = Int('y')
2462 >>> x - y
2463 x - y
2464 >>> (x - y).sort()
2465 Int
2466 """
2467 a, b = _coerce_exprs(self, other)
2468 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2469

◆ __truediv__()

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

Definition at line 2531 of file z3py.py.

2531 def __truediv__(self, other):
2532 """Create the Z3 expression `other/self`."""
2533 return self.__div__(other)
2534

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

2384 def is_int(self):
2385 """Return `True` if `self` is an integer expression.
2386
2387 >>> x = Int('x')
2388 >>> x.is_int()
2389 True
2390 >>> (x + 1).is_int()
2391 True
2392 >>> y = Real('y')
2393 >>> (x + y).is_int()
2394 False
2395 """
2396 return self.sort().is_int()
2397

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

2398 def is_real(self):
2399 """Return `True` if `self` is an real expression.
2400
2401 >>> x = Real('x')
2402 >>> x.is_real()
2403 True
2404 >>> (x + 1).is_real()
2405 True
2406 """
2407 return self.sort().is_real()
2408

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

2374 def sort(self):
2375 """Return the sort (type) of the arithmetical expression `self`.
2376
2377 >>> Int('x').sort()
2378 Int
2379 >>> (Real('x') + 1).sort()
2380 Real
2381 """
2382 return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2383
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().