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)
 
- 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 2214 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 2252 of file z3py.py.

2252  def __add__(self, other):
2253  """Create the Z3 expression `self + other`.
2254 
2255  >>> x = Int('x')
2256  >>> y = Int('y')
2257  >>> x + y
2258  x + y
2259  >>> (x + y).sort()
2260  Int
2261  """
2262  a, b = _coerce_exprs(self, other)
2263  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2264 

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

2351  def __div__(self, other):
2352  """Create the Z3 expression `other/self`.
2353 
2354  >>> x = Int('x')
2355  >>> y = Int('y')
2356  >>> x/y
2357  x/y
2358  >>> (x/y).sort()
2359  Int
2360  >>> (x/y).sexpr()
2361  '(div x y)'
2362  >>> x = Real('x')
2363  >>> y = Real('y')
2364  >>> x/y
2365  x/y
2366  >>> (x/y).sort()
2367  Real
2368  >>> (x/y).sexpr()
2369  '(/ x y)'
2370  """
2371  a, b = _coerce_exprs(self, other)
2372  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2373 

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

2485  def __ge__(self, other):
2486  """Create the Z3 expression `other >= self`.
2487 
2488  >>> x, y = Ints('x y')
2489  >>> x >= y
2490  x >= y
2491  >>> y = Real('y')
2492  >>> x >= y
2493  ToReal(x) >= y
2494  """
2495  a, b = _coerce_exprs(self, other)
2496  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2497 

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

2472  def __gt__(self, other):
2473  """Create the Z3 expression `other > self`.
2474 
2475  >>> x, y = Ints('x y')
2476  >>> x > y
2477  x > y
2478  >>> y = Real('y')
2479  >>> x > y
2480  ToReal(x) > y
2481  """
2482  a, b = _coerce_exprs(self, other)
2483  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2484 

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

2446  def __le__(self, other):
2447  """Create the Z3 expression `other <= self`.
2448 
2449  >>> x, y = Ints('x y')
2450  >>> x <= y
2451  x <= y
2452  >>> y = Real('y')
2453  >>> x <= y
2454  ToReal(x) <= y
2455  """
2456  a, b = _coerce_exprs(self, other)
2457  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2458 

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

2459  def __lt__(self, other):
2460  """Create the Z3 expression `other < self`.
2461 
2462  >>> x, y = Ints('x y')
2463  >>> x < y
2464  x < y
2465  >>> y = Real('y')
2466  >>> x < y
2467  ToReal(x) < y
2468  """
2469  a, b = _coerce_exprs(self, other)
2470  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2471 

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

2399  def __mod__(self, other):
2400  """Create the Z3 expression `other%self`.
2401 
2402  >>> x = Int('x')
2403  >>> y = Int('y')
2404  >>> x % y
2405  x%y
2406  >>> simplify(IntVal(10) % IntVal(3))
2407  1
2408  """
2409  a, b = _coerce_exprs(self, other)
2410  if z3_debug():
2411  _z3_assert(a.is_int(), "Z3 integer expression expected")
2412  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2413 

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

2275  def __mul__(self, other):
2276  """Create the Z3 expression `self * other`.
2277 
2278  >>> x = Real('x')
2279  >>> y = Real('y')
2280  >>> x * y
2281  x*y
2282  >>> (x * y).sort()
2283  Real
2284  """
2285  if isinstance(other, BoolRef):
2286  return If(other, self, 0)
2287  a, b = _coerce_exprs(self, other)
2288  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2289 

◆ __neg__()

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

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

Definition at line 2426 of file z3py.py.

2426  def __neg__(self):
2427  """Return an expression representing `-self`.
2428 
2429  >>> x = Int('x')
2430  >>> -x
2431  -x
2432  >>> simplify(-(-x))
2433  x
2434  """
2435  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2436 

◆ __pos__()

def __pos__ (   self)
Return `self`.

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

Definition at line 2437 of file z3py.py.

2437  def __pos__(self):
2438  """Return `self`.
2439 
2440  >>> x = Int('x')
2441  >>> +x
2442  x
2443  """
2444  return self
2445 

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

2323  def __pow__(self, other):
2324  """Create the Z3 expression `self**other` (** is the power operator).
2325 
2326  >>> x = Real('x')
2327  >>> x**3
2328  x**3
2329  >>> (x**3).sort()
2330  Real
2331  >>> simplify(IntVal(2)**8)
2332  256
2333  """
2334  a, b = _coerce_exprs(self, other)
2335  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2336 

◆ __radd__()

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

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

Definition at line 2265 of file z3py.py.

2265  def __radd__(self, other):
2266  """Create the Z3 expression `other + self`.
2267 
2268  >>> x = Int('x')
2269  >>> 10 + x
2270  10 + x
2271  """
2272  a, b = _coerce_exprs(self, other)
2273  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2274 

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

2378  def __rdiv__(self, other):
2379  """Create the Z3 expression `other/self`.
2380 
2381  >>> x = Int('x')
2382  >>> 10/x
2383  10/x
2384  >>> (10/x).sexpr()
2385  '(div 10 x)'
2386  >>> x = Real('x')
2387  >>> 10/x
2388  10/x
2389  >>> (10/x).sexpr()
2390  '(/ 10.0 x)'
2391  """
2392  a, b = _coerce_exprs(self, other)
2393  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2394 

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

2414  def __rmod__(self, other):
2415  """Create the Z3 expression `other%self`.
2416 
2417  >>> x = Int('x')
2418  >>> 10 % x
2419  10%x
2420  """
2421  a, b = _coerce_exprs(self, other)
2422  if z3_debug():
2423  _z3_assert(a.is_int(), "Z3 integer expression expected")
2424  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2425 

◆ __rmul__()

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

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

Definition at line 2290 of file z3py.py.

2290  def __rmul__(self, other):
2291  """Create the Z3 expression `other * self`.
2292 
2293  >>> x = Real('x')
2294  >>> 10 * x
2295  10*x
2296  """
2297  a, b = _coerce_exprs(self, other)
2298  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2299 

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

2337  def __rpow__(self, other):
2338  """Create the Z3 expression `other**self` (** is the power operator).
2339 
2340  >>> x = Real('x')
2341  >>> 2**x
2342  2**x
2343  >>> (2**x).sort()
2344  Real
2345  >>> simplify(2**IntVal(8))
2346  256
2347  """
2348  a, b = _coerce_exprs(self, other)
2349  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2350 

◆ __rsub__()

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

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

Definition at line 2313 of file z3py.py.

2313  def __rsub__(self, other):
2314  """Create the Z3 expression `other - self`.
2315 
2316  >>> x = Int('x')
2317  >>> 10 - x
2318  10 - x
2319  """
2320  a, b = _coerce_exprs(self, other)
2321  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2322 

◆ __rtruediv__()

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

Definition at line 2395 of file z3py.py.

2395  def __rtruediv__(self, other):
2396  """Create the Z3 expression `other/self`."""
2397  return self.__rdiv__(other)
2398 

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

2300  def __sub__(self, other):
2301  """Create the Z3 expression `self - other`.
2302 
2303  >>> x = Int('x')
2304  >>> y = Int('y')
2305  >>> x - y
2306  x - y
2307  >>> (x - y).sort()
2308  Int
2309  """
2310  a, b = _coerce_exprs(self, other)
2311  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2312 

◆ __truediv__()

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

Definition at line 2374 of file z3py.py.

2374  def __truediv__(self, other):
2375  """Create the Z3 expression `other/self`."""
2376  return self.__div__(other)
2377 

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

2227  def is_int(self):
2228  """Return `True` if `self` is an integer expression.
2229 
2230  >>> x = Int('x')
2231  >>> x.is_int()
2232  True
2233  >>> (x + 1).is_int()
2234  True
2235  >>> y = Real('y')
2236  >>> (x + y).is_int()
2237  False
2238  """
2239  return self.sort().is_int()
2240 

Referenced by IntNumRef.as_long().

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

2241  def is_real(self):
2242  """Return `True` if `self` is an real expression.
2243 
2244  >>> x = Real('x')
2245  >>> x.is_real()
2246  True
2247  >>> (x + 1).is_real()
2248  True
2249  """
2250  return self.sort().is_real()
2251 

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

2217  def sort(self):
2218  """Return the sort (type) of the arithmetical expression `self`.
2219 
2220  >>> Int('x').sort()
2221  Int
2222  >>> (Real('x') + 1).sort()
2223  Real
2224  """
2225  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2226 
Z3_mk_unary_minus
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
Z3_mk_ge
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
Z3_mk_gt
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
z3py.If
def If(a, b, c, ctx=None)
Definition: z3py.py:1268
z3py.is_real
def is_real(a)
Definition: z3py.py:2536
z3py.is_int
def is_int(a)
Definition: z3py.py:2518
Z3_mk_power
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_mk_div
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
Z3_mk_lt
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
z3py.z3_debug
def z3_debug()
Definition: z3py.py:56
Z3_get_sort
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
Z3_mk_mod
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
Z3_mk_le
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.