Z3
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_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 __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (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 2365 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 2403 of file z3py.py.

2403  def __add__(self, other):
2404  """Create the Z3 expression `self + other`.
2405 
2406  >>> x = Int('x')
2407  >>> y = Int('y')
2408  >>> x + y
2409  x + y
2410  >>> (x + y).sort()
2411  Int
2412  """
2413  a, b = _coerce_exprs(self, other)
2414  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2415 

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

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

2636  def __ge__(self, other):
2637  """Create the Z3 expression `other >= self`.
2638 
2639  >>> x, y = Ints('x y')
2640  >>> x >= y
2641  x >= y
2642  >>> y = Real('y')
2643  >>> x >= y
2644  ToReal(x) >= y
2645  """
2646  a, b = _coerce_exprs(self, other)
2647  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2648 
2649 
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 2623 of file z3py.py.

2623  def __gt__(self, other):
2624  """Create the Z3 expression `other > self`.
2625 
2626  >>> x, y = Ints('x y')
2627  >>> x > y
2628  x > y
2629  >>> y = Real('y')
2630  >>> x > y
2631  ToReal(x) > y
2632  """
2633  a, b = _coerce_exprs(self, other)
2634  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2635 
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 2597 of file z3py.py.

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

2610  def __lt__(self, other):
2611  """Create the Z3 expression `other < self`.
2612 
2613  >>> x, y = Ints('x y')
2614  >>> x < y
2615  x < y
2616  >>> y = Real('y')
2617  >>> x < y
2618  ToReal(x) < y
2619  """
2620  a, b = _coerce_exprs(self, other)
2621  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2622 
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 2550 of file z3py.py.

2550  def __mod__(self, other):
2551  """Create the Z3 expression `other%self`.
2552 
2553  >>> x = Int('x')
2554  >>> y = Int('y')
2555  >>> x % y
2556  x%y
2557  >>> simplify(IntVal(10) % IntVal(3))
2558  1
2559  """
2560  a, b = _coerce_exprs(self, other)
2561  if z3_debug():
2562  _z3_assert(a.is_int(), "Z3 integer expression expected")
2563  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2564 
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
def z3_debug()
Definition: z3py.py:62

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

2426  def __mul__(self, other):
2427  """Create the Z3 expression `self * other`.
2428 
2429  >>> x = Real('x')
2430  >>> y = Real('y')
2431  >>> x * y
2432  x*y
2433  >>> (x * y).sort()
2434  Real
2435  """
2436  if isinstance(other, BoolRef):
2437  return If(other, self, 0)
2438  a, b = _coerce_exprs(self, other)
2439  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2440 
def If(a, b, c, ctx=None)
Definition: z3py.py:1370

◆ __neg__()

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

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

Definition at line 2577 of file z3py.py.

2577  def __neg__(self):
2578  """Return an expression representing `-self`.
2579 
2580  >>> x = Int('x')
2581  >>> -x
2582  -x
2583  >>> simplify(-(-x))
2584  x
2585  """
2586  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2587 
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 2588 of file z3py.py.

2588  def __pos__(self):
2589  """Return `self`.
2590 
2591  >>> x = Int('x')
2592  >>> +x
2593  x
2594  """
2595  return self
2596 

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

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

2416  def __radd__(self, other):
2417  """Create the Z3 expression `other + self`.
2418 
2419  >>> x = Int('x')
2420  >>> 10 + x
2421  10 + x
2422  """
2423  a, b = _coerce_exprs(self, other)
2424  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2425 

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

2529  def __rdiv__(self, other):
2530  """Create the Z3 expression `other/self`.
2531 
2532  >>> x = Int('x')
2533  >>> 10/x
2534  10/x
2535  >>> (10/x).sexpr()
2536  '(div 10 x)'
2537  >>> x = Real('x')
2538  >>> 10/x
2539  10/x
2540  >>> (10/x).sexpr()
2541  '(/ 10.0 x)'
2542  """
2543  a, b = _coerce_exprs(self, other)
2544  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2545 

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

2565  def __rmod__(self, other):
2566  """Create the Z3 expression `other%self`.
2567 
2568  >>> x = Int('x')
2569  >>> 10 % x
2570  10%x
2571  """
2572  a, b = _coerce_exprs(self, other)
2573  if z3_debug():
2574  _z3_assert(a.is_int(), "Z3 integer expression expected")
2575  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2576 

◆ __rmul__()

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

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

Definition at line 2441 of file z3py.py.

2441  def __rmul__(self, other):
2442  """Create the Z3 expression `other * self`.
2443 
2444  >>> x = Real('x')
2445  >>> 10 * x
2446  10*x
2447  """
2448  a, b = _coerce_exprs(self, other)
2449  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2450 

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

2488  def __rpow__(self, other):
2489  """Create the Z3 expression `other**self` (** is the power operator).
2490 
2491  >>> x = Real('x')
2492  >>> 2**x
2493  2**x
2494  >>> (2**x).sort()
2495  Real
2496  >>> simplify(2**IntVal(8))
2497  256
2498  """
2499  a, b = _coerce_exprs(self, other)
2500  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2501 

◆ __rsub__()

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

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

Definition at line 2464 of file z3py.py.

2464  def __rsub__(self, other):
2465  """Create the Z3 expression `other - self`.
2466 
2467  >>> x = Int('x')
2468  >>> 10 - x
2469  10 - x
2470  """
2471  a, b = _coerce_exprs(self, other)
2472  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2473 

◆ __rtruediv__()

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

Definition at line 2546 of file z3py.py.

2546  def __rtruediv__(self, other):
2547  """Create the Z3 expression `other/self`."""
2548  return self.__rdiv__(other)
2549 

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

2451  def __sub__(self, other):
2452  """Create the Z3 expression `self - other`.
2453 
2454  >>> x = Int('x')
2455  >>> y = Int('y')
2456  >>> x - y
2457  x - y
2458  >>> (x - y).sort()
2459  Int
2460  """
2461  a, b = _coerce_exprs(self, other)
2462  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2463 

◆ __truediv__()

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

Definition at line 2525 of file z3py.py.

2525  def __truediv__(self, other):
2526  """Create the Z3 expression `other/self`."""
2527  return self.__div__(other)
2528 

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

2378  def is_int(self):
2379  """Return `True` if `self` is an integer expression.
2380 
2381  >>> x = Int('x')
2382  >>> x.is_int()
2383  True
2384  >>> (x + 1).is_int()
2385  True
2386  >>> y = Real('y')
2387  >>> (x + y).is_int()
2388  False
2389  """
2390  return self.sort().is_int()
2391 
def is_int(a)
Definition: z3py.py:2671

Referenced by IntNumRef.as_long(), 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 2392 of file z3py.py.

2392  def is_real(self):
2393  """Return `True` if `self` is an real expression.
2394 
2395  >>> x = Real('x')
2396  >>> x.is_real()
2397  True
2398  >>> (x + 1).is_real()
2399  True
2400  """
2401  return self.sort().is_real()
2402 
def is_real(a)
Definition: z3py.py:2690

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

2368  def sort(self):
2369  """Return the sort (type) of the arithmetical expression `self`.
2370 
2371  >>> Int('x').sort()
2372  Int
2373  >>> (Real('x') + 1).sort()
2374  Real
2375  """
2376  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2377 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by FPNumRef.as_string(), ArrayRef.domain(), ArrayRef.domain_n(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), and ExprRef.sort_kind().