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

2088  def __add__(self, other):
2089  """Create the Z3 expression `self + other`.
2090 
2091  >>> x = Int('x')
2092  >>> y = Int('y')
2093  >>> x + y
2094  x + y
2095  >>> (x + y).sort()
2096  Int
2097  """
2098  a, b = _coerce_exprs(self, other)
2099  return ArithRef(_mk_bin(Z3_mk_add, a, b), self.ctx)
2100 

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

2185  def __div__(self, other):
2186  """Create the Z3 expression `other/self`.
2187 
2188  >>> x = Int('x')
2189  >>> y = Int('y')
2190  >>> x/y
2191  x/y
2192  >>> (x/y).sort()
2193  Int
2194  >>> (x/y).sexpr()
2195  '(div x y)'
2196  >>> x = Real('x')
2197  >>> y = Real('y')
2198  >>> x/y
2199  x/y
2200  >>> (x/y).sort()
2201  Real
2202  >>> (x/y).sexpr()
2203  '(/ x y)'
2204  """
2205  a, b = _coerce_exprs(self, other)
2206  return ArithRef(Z3_mk_div(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2207 
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 2319 of file z3py.py.

2319  def __ge__(self, other):
2320  """Create the Z3 expression `other >= self`.
2321 
2322  >>> x, y = Ints('x y')
2323  >>> x >= y
2324  x >= y
2325  >>> y = Real('y')
2326  >>> x >= y
2327  ToReal(x) >= y
2328  """
2329  a, b = _coerce_exprs(self, other)
2330  return BoolRef(Z3_mk_ge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2331 
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 2306 of file z3py.py.

2306  def __gt__(self, other):
2307  """Create the Z3 expression `other > self`.
2308 
2309  >>> x, y = Ints('x y')
2310  >>> x > y
2311  x > y
2312  >>> y = Real('y')
2313  >>> x > y
2314  ToReal(x) > y
2315  """
2316  a, b = _coerce_exprs(self, other)
2317  return BoolRef(Z3_mk_gt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2318 
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 2280 of file z3py.py.

2280  def __le__(self, other):
2281  """Create the Z3 expression `other <= self`.
2282 
2283  >>> x, y = Ints('x y')
2284  >>> x <= y
2285  x <= y
2286  >>> y = Real('y')
2287  >>> x <= y
2288  ToReal(x) <= y
2289  """
2290  a, b = _coerce_exprs(self, other)
2291  return BoolRef(Z3_mk_le(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2292 
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 2293 of file z3py.py.

2293  def __lt__(self, other):
2294  """Create the Z3 expression `other < self`.
2295 
2296  >>> x, y = Ints('x y')
2297  >>> x < y
2298  x < y
2299  >>> y = Real('y')
2300  >>> x < y
2301  ToReal(x) < y
2302  """
2303  a, b = _coerce_exprs(self, other)
2304  return BoolRef(Z3_mk_lt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2305 
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 2233 of file z3py.py.

2233  def __mod__(self, other):
2234  """Create the Z3 expression `other%self`.
2235 
2236  >>> x = Int('x')
2237  >>> y = Int('y')
2238  >>> x % y
2239  x%y
2240  >>> simplify(IntVal(10) % IntVal(3))
2241  1
2242  """
2243  a, b = _coerce_exprs(self, other)
2244  if __debug__:
2245  _z3_assert(a.is_int(), "Z3 integer expression expected")
2246  return ArithRef(Z3_mk_mod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2247 
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.

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

2111  def __mul__(self, other):
2112  """Create the Z3 expression `self * other`.
2113 
2114  >>> x = Real('x')
2115  >>> y = Real('y')
2116  >>> x * y
2117  x*y
2118  >>> (x * y).sort()
2119  Real
2120  """
2121  a, b = _coerce_exprs(self, other)
2122  return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.ctx)
2123 

◆ __neg__()

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

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

Definition at line 2260 of file z3py.py.

2260  def __neg__(self):
2261  """Return an expression representing `-self`.
2262 
2263  >>> x = Int('x')
2264  >>> -x
2265  -x
2266  >>> simplify(-(-x))
2267  x
2268  """
2269  return ArithRef(Z3_mk_unary_minus(self.ctx_ref(), self.as_ast()), self.ctx)
2270 
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 2271 of file z3py.py.

2271  def __pos__(self):
2272  """Return `self`.
2273 
2274  >>> x = Int('x')
2275  >>> +x
2276  x
2277  """
2278  return self
2279 

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

2157  def __pow__(self, other):
2158  """Create the Z3 expression `self**other` (** is the power operator).
2159 
2160  >>> x = Real('x')
2161  >>> x**3
2162  x**3
2163  >>> (x**3).sort()
2164  Real
2165  >>> simplify(IntVal(2)**8)
2166  256
2167  """
2168  a, b = _coerce_exprs(self, other)
2169  return ArithRef(Z3_mk_power(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
2170 
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 2101 of file z3py.py.

2101  def __radd__(self, other):
2102  """Create the Z3 expression `other + self`.
2103 
2104  >>> x = Int('x')
2105  >>> 10 + x
2106  10 + x
2107  """
2108  a, b = _coerce_exprs(self, other)
2109  return ArithRef(_mk_bin(Z3_mk_add, b, a), self.ctx)
2110 

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

2212  def __rdiv__(self, other):
2213  """Create the Z3 expression `other/self`.
2214 
2215  >>> x = Int('x')
2216  >>> 10/x
2217  10/x
2218  >>> (10/x).sexpr()
2219  '(div 10 x)'
2220  >>> x = Real('x')
2221  >>> 10/x
2222  10/x
2223  >>> (10/x).sexpr()
2224  '(/ 10.0 x)'
2225  """
2226  a, b = _coerce_exprs(self, other)
2227  return ArithRef(Z3_mk_div(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2228 
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 2248 of file z3py.py.

2248  def __rmod__(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  if __debug__:
2257  _z3_assert(a.is_int(), "Z3 integer expression expected")
2258  return ArithRef(Z3_mk_mod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2259 
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.

◆ __rmul__()

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

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

Definition at line 2124 of file z3py.py.

2124  def __rmul__(self, other):
2125  """Create the Z3 expression `other * self`.
2126 
2127  >>> x = Real('x')
2128  >>> 10 * x
2129  10*x
2130  """
2131  a, b = _coerce_exprs(self, other)
2132  return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.ctx)
2133 

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

2171  def __rpow__(self, other):
2172  """Create the Z3 expression `other**self` (** is the power operator).
2173 
2174  >>> x = Real('x')
2175  >>> 2**x
2176  2**x
2177  >>> (2**x).sort()
2178  Real
2179  >>> simplify(2**IntVal(8))
2180  256
2181  """
2182  a, b = _coerce_exprs(self, other)
2183  return ArithRef(Z3_mk_power(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
2184 
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 2147 of file z3py.py.

2147  def __rsub__(self, other):
2148  """Create the Z3 expression `other - self`.
2149 
2150  >>> x = Int('x')
2151  >>> 10 - x
2152  10 - x
2153  """
2154  a, b = _coerce_exprs(self, other)
2155  return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.ctx)
2156 

◆ __rtruediv__()

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

Definition at line 2229 of file z3py.py.

2229  def __rtruediv__(self, other):
2230  """Create the Z3 expression `other/self`."""
2231  return self.__rdiv__(other)
2232 

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

2134  def __sub__(self, other):
2135  """Create the Z3 expression `self - other`.
2136 
2137  >>> x = Int('x')
2138  >>> y = Int('y')
2139  >>> x - y
2140  x - y
2141  >>> (x - y).sort()
2142  Int
2143  """
2144  a, b = _coerce_exprs(self, other)
2145  return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.ctx)
2146 

◆ __truediv__()

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

Definition at line 2208 of file z3py.py.

2208  def __truediv__(self, other):
2209  """Create the Z3 expression `other/self`."""
2210  return self.__div__(other)
2211 

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

2063  def is_int(self):
2064  """Return `True` if `self` is an integer expression.
2065 
2066  >>> x = Int('x')
2067  >>> x.is_int()
2068  True
2069  >>> (x + 1).is_int()
2070  True
2071  >>> y = Real('y')
2072  >>> (x + y).is_int()
2073  False
2074  """
2075  return self.sort().is_int()
2076 
def is_int(a)
Definition: z3py.py:2352

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

2077  def is_real(self):
2078  """Return `True` if `self` is an real expression.
2079 
2080  >>> x = Real('x')
2081  >>> x.is_real()
2082  True
2083  >>> (x + 1).is_real()
2084  True
2085  """
2086  return self.sort().is_real()
2087 
def is_real(a)
Definition: z3py.py:2370

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

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

2053  def sort(self):
2054  """Return the sort (type) of the arithmetical expression `self`.
2055 
2056  >>> Int('x').sort()
2057  Int
2058  >>> (Real('x') + 1).sort()
2059  Real
2060  """
2061  return ArithSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
2062 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.