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 (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 __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 2176 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 2214 of file z3py.py.

2214  def __add__(self, other):
2215  """Create the Z3 expression `self + other`.
2216 
2217  >>> x = Int('x')
2218  >>> y = Int('y')
2219  >>> x + y
2220  x + y
2221  >>> (x + y).sort()
2222  Int
2223  """
2224  a, b = _coerce_exprs(self, other)
2225  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2226 

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

2313  def __div__(self, other):
2314  """Create the Z3 expression `other/self`.
2315 
2316  >>> x = Int('x')
2317  >>> y = Int('y')
2318  >>> x/y
2319  x/y
2320  >>> (x/y).sort()
2321  Int
2322  >>> (x/y).sexpr()
2323  '(div x y)'
2324  >>> x = Real('x')
2325  >>> y = Real('y')
2326  >>> x/y
2327  x/y
2328  >>> (x/y).sort()
2329  Real
2330  >>> (x/y).sexpr()
2331  '(/ x y)'
2332  """
2333  a, b = _coerce_exprs(self, other)
2334  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2335 
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.

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

2447  def __ge__(self, other):
2448  """Create the Z3 expression `other >= self`.
2449 
2450  >>> x, y = Ints('x y')
2451  >>> x >= y
2452  x >= y
2453  >>> y = Real('y')
2454  >>> x >= y
2455  ToReal(x) >= y
2456  """
2457  a, b = _coerce_exprs(self, other)
2458  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2459 
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 2434 of file z3py.py.

2434  def __gt__(self, other):
2435  """Create the Z3 expression `other > self`.
2436 
2437  >>> x, y = Ints('x y')
2438  >>> x > y
2439  x > y
2440  >>> y = Real('y')
2441  >>> x > y
2442  ToReal(x) > y
2443  """
2444  a, b = _coerce_exprs(self, other)
2445  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2446 
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 2408 of file z3py.py.

2408  def __le__(self, other):
2409  """Create the Z3 expression `other <= self`.
2410 
2411  >>> x, y = Ints('x y')
2412  >>> x <= y
2413  x <= y
2414  >>> y = Real('y')
2415  >>> x <= y
2416  ToReal(x) <= y
2417  """
2418  a, b = _coerce_exprs(self, other)
2419  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2420 
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 2421 of file z3py.py.

2421  def __lt__(self, other):
2422  """Create the Z3 expression `other < self`.
2423 
2424  >>> x, y = Ints('x y')
2425  >>> x < y
2426  x < y
2427  >>> y = Real('y')
2428  >>> x < y
2429  ToReal(x) < y
2430  """
2431  a, b = _coerce_exprs(self, other)
2432  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2433 
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 2361 of file z3py.py.

2361  def __mod__(self, other):
2362  """Create the Z3 expression `other%self`.
2363 
2364  >>> x = Int('x')
2365  >>> y = Int('y')
2366  >>> x % y
2367  x%y
2368  >>> simplify(IntVal(10) % IntVal(3))
2369  1
2370  """
2371  a, b = _coerce_exprs(self, other)
2372  if z3_debug():
2373  _z3_assert(a.is_int(), "Z3 integer expression expected")
2374  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2375 
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 2237 of file z3py.py.

2237  def __mul__(self, other):
2238  """Create the Z3 expression `self * other`.
2239 
2240  >>> x = Real('x')
2241  >>> y = Real('y')
2242  >>> x * y
2243  x*y
2244  >>> (x * y).sort()
2245  Real
2246  """
2247  if isinstance(other, BoolRef):
2248  return If(other, self, 0)
2249  a, b = _coerce_exprs(self, other)
2250  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2251 
def If(a, b, c, ctx=None)
Definition: z3py.py:1238

◆ __neg__()

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

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

Definition at line 2388 of file z3py.py.

2388  def __neg__(self):
2389  """Return an expression representing `-self`.
2390 
2391  >>> x = Int('x')
2392  >>> -x
2393  -x
2394  >>> simplify(-(-x))
2395  x
2396  """
2397  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2398 
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 2399 of file z3py.py.

2399  def __pos__(self):
2400  """Return `self`.
2401 
2402  >>> x = Int('x')
2403  >>> +x
2404  x
2405  """
2406  return self
2407 

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

2285  def __pow__(self, other):
2286  """Create the Z3 expression `self**other` (** is the power operator).
2287 
2288  >>> x = Real('x')
2289  >>> x**3
2290  x**3
2291  >>> (x**3).sort()
2292  Real
2293  >>> simplify(IntVal(2)**8)
2294  256
2295  """
2296  a, b = _coerce_exprs(self, other)
2297  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2298 
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 2227 of file z3py.py.

2227  def __radd__(self, other):
2228  """Create the Z3 expression `other + self`.
2229 
2230  >>> x = Int('x')
2231  >>> 10 + x
2232  10 + x
2233  """
2234  a, b = _coerce_exprs(self, other)
2235  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2236 

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

2340  def __rdiv__(self, other):
2341  """Create the Z3 expression `other/self`.
2342 
2343  >>> x = Int('x')
2344  >>> 10/x
2345  10/x
2346  >>> (10/x).sexpr()
2347  '(div 10 x)'
2348  >>> x = Real('x')
2349  >>> 10/x
2350  10/x
2351  >>> (10/x).sexpr()
2352  '(/ 10.0 x)'
2353  """
2354  a, b = _coerce_exprs(self, other)
2355  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.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.

◆ __rmod__()

def __rmod__ (   self,
  other 
)
Create the Z3 expression `other%self`.

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

Definition at line 2376 of file z3py.py.

2376  def __rmod__(self, other):
2377  """Create the Z3 expression `other%self`.
2378 
2379  >>> x = Int('x')
2380  >>> 10 % x
2381  10%x
2382  """
2383  a, b = _coerce_exprs(self, other)
2384  if z3_debug():
2385  _z3_assert(a.is_int(), "Z3 integer expression expected")
2386  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2387 
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 2252 of file z3py.py.

2252  def __rmul__(self, other):
2253  """Create the Z3 expression `other * self`.
2254 
2255  >>> x = Real('x')
2256  >>> 10 * x
2257  10*x
2258  """
2259  a, b = _coerce_exprs(self, other)
2260  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2261 

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

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

2275  def __rsub__(self, other):
2276  """Create the Z3 expression `other - self`.
2277 
2278  >>> x = Int('x')
2279  >>> 10 - x
2280  10 - x
2281  """
2282  a, b = _coerce_exprs(self, other)
2283  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2284 

◆ __rtruediv__()

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

Definition at line 2357 of file z3py.py.

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

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

2262  def __sub__(self, other):
2263  """Create the Z3 expression `self - other`.
2264 
2265  >>> x = Int('x')
2266  >>> y = Int('y')
2267  >>> x - y
2268  x - y
2269  >>> (x - y).sort()
2270  Int
2271  """
2272  a, b = _coerce_exprs(self, other)
2273  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2274 

◆ __truediv__()

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

Definition at line 2336 of file z3py.py.

2336  def __truediv__(self, other):
2337  """Create the Z3 expression `other/self`."""
2338  return self.__div__(other)
2339 

◆ 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

Definition at line 2189 of file z3py.py.

2189  def is_int(self):
2190  """Return `True` if `self` is an integer expression.
2191 
2192  >>> x = Int('x')
2193  >>> x.is_int()
2194  True
2195  >>> (x + 1).is_int()
2196  True
2197  >>> y = Real('y')
2198  >>> (x + y).is_int()
2199  False
2200  """
2201  return self.sort().is_int()
2202 
def is_int(a)
Definition: z3py.py:2480

◆ 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

Definition at line 2203 of file z3py.py.

2203  def is_real(self):
2204  """Return `True` if `self` is an real expression.
2205 
2206  >>> x = Real('x')
2207  >>> x.is_real()
2208  True
2209  >>> (x + 1).is_real()
2210  True
2211  """
2212  return self.sort().is_real()
2213 
def is_real(a)
Definition: z3py.py:2498

◆ sort()

def sort (   self)
Return the sort (type) of the arithmetical expression `self`.

>>> Int('x').sort()
Int
>>> (Real('x') + 1).sort()
Real

Definition at line 2179 of file z3py.py.

Referenced by ArithRef.__add__(), ArithRef.__div__(), ArithRef.__mul__(), ArithRef.__pow__(), ArithRef.__rpow__(), and ArithRef.__sub__().

2179  def sort(self):
2180  """Return the sort (type) of the arithmetical expression `self`.
2181 
2182  >>> Int('x').sort()
2183  Int
2184  >>> (Real('x') + 1).sort()
2185  Real
2186  """
2187  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2188 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.