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

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

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

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

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

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

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

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

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

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

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

◆ __neg__()

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

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

Definition at line 2409 of file z3py.py.

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

2420  def __pos__(self):
2421  """Return `self`.
2422 
2423  >>> x = Int('x')
2424  >>> +x
2425  x
2426  """
2427  return self
2428 

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

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

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

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

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

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

◆ __rmul__()

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

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

Definition at line 2273 of file z3py.py.

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

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

2320  def __rpow__(self, other):
2321  """Create the Z3 expression `other**self` (** is the power operator).
2322 
2323  >>> x = Real('x')
2324  >>> 2**x
2325  2**x
2326  >>> (2**x).sort()
2327  Real
2328  >>> simplify(2**IntVal(8))
2329  256
2330  """
2331  a, b = _coerce_exprs(self, other)
2332  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2333 
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 2296 of file z3py.py.

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

◆ __rtruediv__()

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

Definition at line 2378 of file z3py.py.

2378  def __rtruediv__(self, other):
2379  """Create the Z3 expression `other/self`."""
2380  return self.__rdiv__(other)
2381 

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

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

◆ __truediv__()

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

Definition at line 2357 of file z3py.py.

2357  def __truediv__(self, other):
2358  """Create the Z3 expression `other/self`."""
2359  return self.__div__(other)
2360 

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

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

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

2224  def is_real(self):
2225  """Return `True` if `self` is an real expression.
2226 
2227  >>> x = Real('x')
2228  >>> x.is_real()
2229  True
2230  >>> (x + 1).is_real()
2231  True
2232  """
2233  return self.sort().is_real()
2234 
def is_real(a)
Definition: z3py.py:2519

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

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