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

2231  def __add__(self, other):
2232  """Create the Z3 expression `self + other`.
2233 
2234  >>> x = Int('x')
2235  >>> y = Int('y')
2236  >>> x + y
2237  x + y
2238  >>> (x + y).sort()
2239  Int
2240  """
2241  a, b = _coerce_exprs(self, other)
2242  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2243 

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

2330  def __div__(self, other):
2331  """Create the Z3 expression `other/self`.
2332 
2333  >>> x = Int('x')
2334  >>> y = Int('y')
2335  >>> x/y
2336  x/y
2337  >>> (x/y).sort()
2338  Int
2339  >>> (x/y).sexpr()
2340  '(div x y)'
2341  >>> x = Real('x')
2342  >>> y = Real('y')
2343  >>> x/y
2344  x/y
2345  >>> (x/y).sort()
2346  Real
2347  >>> (x/y).sexpr()
2348  '(/ x y)'
2349  """
2350  a, b = _coerce_exprs(self, other)
2351  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2352 
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 2464 of file z3py.py.

2464  def __ge__(self, other):
2465  """Create the Z3 expression `other >= self`.
2466 
2467  >>> x, y = Ints('x y')
2468  >>> x >= y
2469  x >= y
2470  >>> y = Real('y')
2471  >>> x >= y
2472  ToReal(x) >= y
2473  """
2474  a, b = _coerce_exprs(self, other)
2475  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2476 
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 2451 of file z3py.py.

2451  def __gt__(self, other):
2452  """Create the Z3 expression `other > self`.
2453 
2454  >>> x, y = Ints('x y')
2455  >>> x > y
2456  x > y
2457  >>> y = Real('y')
2458  >>> x > y
2459  ToReal(x) > y
2460  """
2461  a, b = _coerce_exprs(self, other)
2462  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2463 
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 2425 of file z3py.py.

2425  def __le__(self, other):
2426  """Create the Z3 expression `other <= self`.
2427 
2428  >>> x, y = Ints('x y')
2429  >>> x <= y
2430  x <= y
2431  >>> y = Real('y')
2432  >>> x <= y
2433  ToReal(x) <= y
2434  """
2435  a, b = _coerce_exprs(self, other)
2436  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2437 
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 2438 of file z3py.py.

2438  def __lt__(self, other):
2439  """Create the Z3 expression `other < self`.
2440 
2441  >>> x, y = Ints('x y')
2442  >>> x < y
2443  x < y
2444  >>> y = Real('y')
2445  >>> x < y
2446  ToReal(x) < y
2447  """
2448  a, b = _coerce_exprs(self, other)
2449  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2450 
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 2378 of file z3py.py.

2378  def __mod__(self, other):
2379  """Create the Z3 expression `other%self`.
2380 
2381  >>> x = Int('x')
2382  >>> y = Int('y')
2383  >>> x % y
2384  x%y
2385  >>> simplify(IntVal(10) % IntVal(3))
2386  1
2387  """
2388  a, b = _coerce_exprs(self, other)
2389  if z3_debug():
2390  _z3_assert(a.is_int(), "Z3 integer expression expected")
2391  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2392 
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:56

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

2254  def __mul__(self, other):
2255  """Create the Z3 expression `self * other`.
2256 
2257  >>> x = Real('x')
2258  >>> y = Real('y')
2259  >>> x * y
2260  x*y
2261  >>> (x * y).sort()
2262  Real
2263  """
2264  if isinstance(other, BoolRef):
2265  return If(other, self, 0)
2266  a, b = _coerce_exprs(self, other)
2267  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2268 
def If(a, b, c, ctx=None)
Definition: z3py.py:1248

◆ __neg__()

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

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

Definition at line 2405 of file z3py.py.

2405  def __neg__(self):
2406  """Return an expression representing `-self`.
2407 
2408  >>> x = Int('x')
2409  >>> -x
2410  -x
2411  >>> simplify(-(-x))
2412  x
2413  """
2414  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2415 
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 2416 of file z3py.py.

2416  def __pos__(self):
2417  """Return `self`.
2418 
2419  >>> x = Int('x')
2420  >>> +x
2421  x
2422  """
2423  return self
2424 

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

2302  def __pow__(self, other):
2303  """Create the Z3 expression `self**other` (** is the power operator).
2304 
2305  >>> x = Real('x')
2306  >>> x**3
2307  x**3
2308  >>> (x**3).sort()
2309  Real
2310  >>> simplify(IntVal(2)**8)
2311  256
2312  """
2313  a, b = _coerce_exprs(self, other)
2314  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2315 
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 2244 of file z3py.py.

2244  def __radd__(self, other):
2245  """Create the Z3 expression `other + self`.
2246 
2247  >>> x = Int('x')
2248  >>> 10 + x
2249  10 + x
2250  """
2251  a, b = _coerce_exprs(self, other)
2252  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2253 

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

2357  def __rdiv__(self, other):
2358  """Create the Z3 expression `other/self`.
2359 
2360  >>> x = Int('x')
2361  >>> 10/x
2362  10/x
2363  >>> (10/x).sexpr()
2364  '(div 10 x)'
2365  >>> x = Real('x')
2366  >>> 10/x
2367  10/x
2368  >>> (10/x).sexpr()
2369  '(/ 10.0 x)'
2370  """
2371  a, b = _coerce_exprs(self, other)
2372  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2373 
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.__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 2393 of file z3py.py.

2393  def __rmod__(self, other):
2394  """Create the Z3 expression `other%self`.
2395 
2396  >>> x = Int('x')
2397  >>> 10 % x
2398  10%x
2399  """
2400  a, b = _coerce_exprs(self, other)
2401  if z3_debug():
2402  _z3_assert(a.is_int(), "Z3 integer expression expected")
2403  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2404 
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:56

◆ __rmul__()

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

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

Definition at line 2269 of file z3py.py.

2269  def __rmul__(self, other):
2270  """Create the Z3 expression `other * self`.
2271 
2272  >>> x = Real('x')
2273  >>> 10 * x
2274  10*x
2275  """
2276  a, b = _coerce_exprs(self, other)
2277  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2278 

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

2316  def __rpow__(self, other):
2317  """Create the Z3 expression `other**self` (** is the power operator).
2318 
2319  >>> x = Real('x')
2320  >>> 2**x
2321  2**x
2322  >>> (2**x).sort()
2323  Real
2324  >>> simplify(2**IntVal(8))
2325  256
2326  """
2327  a, b = _coerce_exprs(self, other)
2328  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2329 
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.

◆ __rsub__()

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

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

Definition at line 2292 of file z3py.py.

2292  def __rsub__(self, other):
2293  """Create the Z3 expression `other - self`.
2294 
2295  >>> x = Int('x')
2296  >>> 10 - x
2297  10 - x
2298  """
2299  a, b = _coerce_exprs(self, other)
2300  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2301 

◆ __rtruediv__()

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

Definition at line 2374 of file z3py.py.

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

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

2279  def __sub__(self, other):
2280  """Create the Z3 expression `self - other`.
2281 
2282  >>> x = Int('x')
2283  >>> y = Int('y')
2284  >>> x - y
2285  x - y
2286  >>> (x - y).sort()
2287  Int
2288  """
2289  a, b = _coerce_exprs(self, other)
2290  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2291 

◆ __truediv__()

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

Definition at line 2353 of file z3py.py.

2353  def __truediv__(self, other):
2354  """Create the Z3 expression `other/self`."""
2355  return self.__div__(other)
2356 

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

2206  def is_int(self):
2207  """Return `True` if `self` is an integer expression.
2208 
2209  >>> x = Int('x')
2210  >>> x.is_int()
2211  True
2212  >>> (x + 1).is_int()
2213  True
2214  >>> y = Real('y')
2215  >>> (x + y).is_int()
2216  False
2217  """
2218  return self.sort().is_int()
2219 
def is_int(a)
Definition: z3py.py:2497

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

2220  def is_real(self):
2221  """Return `True` if `self` is an real expression.
2222 
2223  >>> x = Real('x')
2224  >>> x.is_real()
2225  True
2226  >>> (x + 1).is_real()
2227  True
2228  """
2229  return self.sort().is_real()
2230 
def is_real(a)
Definition: z3py.py:2515

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

2196  def sort(self):
2197  """Return the sort (type) of the arithmetical expression `self`.
2198 
2199  >>> Int('x').sort()
2200  Int
2201  >>> (Real('x') + 1).sort()
2202  Real
2203  """
2204  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2205 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.