Go to the documentation of this file.
9 """Z3 is a high performance theorem prover developed at Microsoft Research. Z3 is used in many applications such as: software/hardware verification and testing, constraint solving, analysis of hybrid systems, security, biology (in silico analysis), and geometrical problems.
11 Several online tutorials for Z3Py are available at:
12 http://rise4fun.com/Z3Py/tutorial/guide
14 Please send feedback, comments and/or corrections on the Issue tracker for https://github.com/Z3prover/z3.git. Your comments are very valuable.
35 ... x = BitVec('x', 32)
37 ... # the expression x + y is type incorrect
39 ... except Z3Exception as ex:
40 ... print("failed: %s" % ex)
45 from .z3types
import *
46 from .z3consts
import *
47 from .z3printer
import *
48 from fractions
import Fraction
62 return isinstance(v, (int, long))
65 return isinstance(v, int)
74 major = ctypes.c_uint(0)
75 minor = ctypes.c_uint(0)
76 build = ctypes.c_uint(0)
77 rev = ctypes.c_uint(0)
79 return "%s.%s.%s" % (major.value, minor.value, build.value)
82 major = ctypes.c_uint(0)
83 minor = ctypes.c_uint(0)
84 build = ctypes.c_uint(0)
85 rev = ctypes.c_uint(0)
87 return (major.value, minor.value, build.value, rev.value)
94 def _z3_assert(cond, msg):
96 raise Z3Exception(msg)
98 def _z3_check_cint_overflow(n, name):
99 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
102 """Log interaction to a file. This function must be invoked immediately after init(). """
106 """Append user-defined string to interaction log. """
110 """Convert an integer or string into a Z3 symbol."""
116 def _symbol2py(ctx, s):
117 """Convert a Z3 symbol back into a Python object. """
128 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
130 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
131 return [arg
for arg
in args[0]]
138 def _get_args_ast_list(args):
140 if isinstance(args, set)
or isinstance(args, AstVector)
or isinstance(args, tuple):
141 return [arg
for arg
in args]
147 def _to_param_value(val):
148 if isinstance(val, bool):
162 """A Context manages all other Z3 objects, global configuration options, etc.
164 Z3Py uses a default global context. For most applications this is sufficient.
165 An application may use multiple Z3 contexts. Objects created in one context
166 cannot be used in another one. However, several objects may be "translated" from
167 one context to another. It is not safe to access Z3 objects from multiple threads.
168 The only exception is the method `interrupt()` that can be used to interrupt() a long
170 The initialization method receives global configuration options for the new context.
174 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
197 """Return a reference to the actual C pointer to the Z3 context."""
201 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
203 This method can be invoked from a thread different from the one executing the
204 interruptible procedure.
212 """Return a reference to the global Z3 context.
215 >>> x.ctx == main_ctx()
220 >>> x2 = Real('x', c)
227 if _main_ctx
is None:
241 """Set Z3 global (or module) parameters.
243 >>> set_param(precision=10)
246 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
250 if not set_pp_option(k, v):
264 """Reset all global (or module) parameters.
269 """Alias for 'set_param' for backward compatibility.
274 """Return the value of a Z3 global (or module) parameter
276 >>> get_param('nlsat.reorder')
279 ptr = (ctypes.c_char_p * 1)()
281 r = z3core._to_pystr(ptr[0])
283 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
293 """Superclass for all Z3 objects that have support for pretty printing."""
297 def _repr_html_(self):
298 in_html = in_html_mode()
301 set_html_mode(in_html)
306 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
313 if self.
ctx.ref()
is not None and self.
ast is not None:
318 return _to_ast_ref(self.
ast, self.
ctx)
321 return obj_to_string(self)
324 return obj_to_string(self)
327 return self.
eq(other)
340 elif is_eq(self)
and self.num_args() == 2:
341 return self.arg(0).
eq(self.arg(1))
343 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
346 """Return a string representing the AST node in s-expression notation.
349 >>> ((x + 1)*x).sexpr()
355 """Return a pointer to the corresponding C Z3_ast object."""
359 """Return unique identifier for object. It can be used for hash-tables and maps."""
363 """Return a reference to the C context where this AST node is stored."""
364 return self.
ctx.ref()
367 """Return `True` if `self` and `other` are structurally identical.
374 >>> n1 = simplify(n1)
375 >>> n2 = simplify(n2)
380 _z3_assert(
is_ast(other),
"Z3 AST expected")
384 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
390 >>> # Nodes in different contexts can't be mixed.
391 >>> # However, we can translate nodes from one context to another.
392 >>> x.translate(c2) + y
396 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
403 """Return a hashcode for the `self`.
405 >>> n1 = simplify(Int('x') + 1)
406 >>> n2 = simplify(2 + Int('x') - 1)
407 >>> n1.hash() == n2.hash()
413 """Return `True` if `a` is an AST node.
417 >>> is_ast(IntVal(10))
421 >>> is_ast(BoolSort())
423 >>> is_ast(Function('f', IntSort(), IntSort()))
430 return isinstance(a, AstRef)
433 """Return `True` if `a` and `b` are structurally identical AST nodes.
443 >>> eq(simplify(x + 1), simplify(1 + x))
450 def _ast_kind(ctx, a):
455 def _ctx_from_ast_arg_list(args, default_ctx=None):
463 _z3_assert(ctx == a.ctx,
"Context mismatch")
468 def _ctx_from_ast_args(*args):
469 return _ctx_from_ast_arg_list(args)
471 def _to_func_decl_array(args):
473 _args = (FuncDecl * sz)()
475 _args[i] = args[i].as_func_decl()
478 def _to_ast_array(args):
482 _args[i] = args[i].as_ast()
485 def _to_ref_array(ref, args):
489 _args[i] = args[i].as_ast()
492 def _to_ast_ref(a, ctx):
493 k = _ast_kind(ctx, a)
495 return _to_sort_ref(a, ctx)
496 elif k == Z3_FUNC_DECL_AST:
497 return _to_func_decl_ref(a, ctx)
499 return _to_expr_ref(a, ctx)
508 def _sort_kind(ctx, s):
512 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
520 """Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts.
523 >>> b.kind() == Z3_BOOL_SORT
525 >>> b.kind() == Z3_INT_SORT
527 >>> A = ArraySort(IntSort(), IntSort())
528 >>> A.kind() == Z3_ARRAY_SORT
530 >>> A.kind() == Z3_INT_SORT
533 return _sort_kind(self.
ctx, self.
ast)
536 """Return `True` if `self` is a subsort of `other`.
538 >>> IntSort().subsort(RealSort())
544 """Try to cast `val` as an element of sort `self`.
546 This method is used in Z3Py to convert Python objects such as integers,
547 floats, longs and strings into Z3 expressions.
550 >>> RealSort().cast(x)
554 _z3_assert(
is_expr(val),
"Z3 expression expected")
555 _z3_assert(self.
eq(val.sort()),
"Sort mismatch")
559 """Return the name (string) of sort `self`.
561 >>> BoolSort().name()
563 >>> ArraySort(IntSort(), IntSort()).name()
569 """Return `True` if `self` and `other` are the same Z3 sort.
572 >>> p.sort() == BoolSort()
574 >>> p.sort() == IntSort()
582 """Return `True` if `self` and `other` are not the same Z3 sort.
585 >>> p.sort() != BoolSort()
587 >>> p.sort() != IntSort()
594 return AstRef.__hash__(self)
597 """Return `True` if `s` is a Z3 sort.
599 >>> is_sort(IntSort())
601 >>> is_sort(Int('x'))
603 >>> is_expr(Int('x'))
606 return isinstance(s, SortRef)
608 def _to_sort_ref(s, ctx):
610 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
611 k = _sort_kind(ctx, s)
612 if k == Z3_BOOL_SORT:
614 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
616 elif k == Z3_BV_SORT:
618 elif k == Z3_ARRAY_SORT:
620 elif k == Z3_DATATYPE_SORT:
622 elif k == Z3_FINITE_DOMAIN_SORT:
624 elif k == Z3_FLOATING_POINT_SORT:
626 elif k == Z3_ROUNDING_MODE_SORT:
628 elif k == Z3_RE_SORT:
630 elif k == Z3_SEQ_SORT:
635 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
638 """Create a new uninterpreted sort named `name`.
640 If `ctx=None`, then the new sort is declared in the global Z3Py context.
642 >>> A = DeclareSort('A')
643 >>> a = Const('a', A)
644 >>> b = Const('b', A)
662 """Function declaration. Every constant and function have an associated declaration.
664 The declaration assigns a name, a sort (i.e., type), and for function
665 the sort (i.e., type) of each of its arguments. Note that, in Z3,
666 a constant is a function with 0 arguments.
678 """Return the name of the function declaration `self`.
680 >>> f = Function('f', IntSort(), IntSort())
683 >>> isinstance(f.name(), str)
689 """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
691 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
698 """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
700 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
707 _z3_assert(i < self.
arity(),
"Index out of bounds")
711 """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
713 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
720 """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
723 >>> d = (x + 1).decl()
724 >>> d.kind() == Z3_OP_ADD
726 >>> d.kind() == Z3_OP_MUL
734 result = [
None for i
in range(n) ]
737 if k == Z3_PARAMETER_INT:
739 elif k == Z3_PARAMETER_DOUBLE:
741 elif k == Z3_PARAMETER_RATIONAL:
743 elif k == Z3_PARAMETER_SYMBOL:
745 elif k == Z3_PARAMETER_SORT:
747 elif k == Z3_PARAMETER_AST:
749 elif k == Z3_PARAMETER_FUNC_DECL:
756 """Create a Z3 application expression using the function `self`, and the given arguments.
758 The arguments must be Z3 expressions. This method assumes that
759 the sorts of the elements in `args` match the sorts of the
760 domain. Limited coercion is supported. For example, if
761 args[0] is a Python integer, and the function expects a Z3
762 integer, then the argument is automatically converted into a
765 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
773 args = _get_args(args)
776 _z3_assert(num == self.
arity(),
"Incorrect number of arguments to %s" % self)
777 _args = (Ast * num)()
782 tmp = self.
domain(i).cast(args[i])
784 _args[i] = tmp.as_ast()
788 """Return `True` if `a` is a Z3 function declaration.
790 >>> f = Function('f', IntSort(), IntSort())
797 return isinstance(a, FuncDeclRef)
800 """Create a new Z3 uninterpreted function with the given sorts.
802 >>> f = Function('f', IntSort(), IntSort())
808 _z3_assert(len(sig) > 0,
"At least two arguments expected")
812 _z3_assert(
is_sort(rng),
"Z3 sort expected")
813 dom = (Sort * arity)()
814 for i
in range(arity):
816 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
821 def _to_func_decl_ref(a, ctx):
825 """Create a new Z3 recursive with the given sorts."""
828 _z3_assert(len(sig) > 0,
"At least two arguments expected")
832 _z3_assert(
is_sort(rng),
"Z3 sort expected")
833 dom = (Sort * arity)()
834 for i
in range(arity):
836 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
842 """Set the body of a recursive function.
843 Recursive definitions are only unfolded during search.
845 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
846 >>> n = Int('n', ctx)
847 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
850 >>> s = Solver(ctx=ctx)
851 >>> s.add(fac(n) < 3)
854 >>> s.model().eval(fac(5))
860 args = _get_args(args)
864 _args[i] = args[i].ast
874 """Constraints, formulas and terms are expressions in Z3.
876 Expressions are ASTs. Every expression has a sort.
877 There are three main kinds of expressions:
878 function applications, quantifiers and bounded variables.
879 A constant is a function application with 0 arguments.
880 For quantifier free problems, all expressions are
881 function applications.
890 """Return the sort of expression `self`.
902 """Shorthand for `self.sort().kind()`.
904 >>> a = Array('a', IntSort(), IntSort())
905 >>> a.sort_kind() == Z3_ARRAY_SORT
907 >>> a.sort_kind() == Z3_INT_SORT
910 return self.
sort().kind()
913 """Return a Z3 expression that represents the constraint `self == other`.
915 If `other` is `None`, then this method simply returns `False`.
926 a, b = _coerce_exprs(self, other)
931 return AstRef.__hash__(self)
934 """Return a Z3 expression that represents the constraint `self != other`.
936 If `other` is `None`, then this method simply returns `True`.
947 a, b = _coerce_exprs(self, other)
948 _args, sz = _to_ast_array((a, b))
955 """Return the Z3 function declaration associated with a Z3 application.
957 >>> f = Function('f', IntSort(), IntSort())
966 _z3_assert(
is_app(self),
"Z3 application expected")
970 """Return the number of arguments of a Z3 application.
974 >>> (a + b).num_args()
976 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
982 _z3_assert(
is_app(self),
"Z3 application expected")
986 """Return argument `idx` of the application `self`.
988 This method assumes that `self` is a function application with at least `idx+1` arguments.
992 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1002 _z3_assert(
is_app(self),
"Z3 application expected")
1003 _z3_assert(idx < self.
num_args(),
"Invalid argument index")
1007 """Return a list containing the children of the given expression
1011 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1021 def _to_expr_ref(a, ctx):
1022 if isinstance(a, Pattern):
1026 if k == Z3_QUANTIFIER_AST:
1029 if sk == Z3_BOOL_SORT:
1031 if sk == Z3_INT_SORT:
1032 if k == Z3_NUMERAL_AST:
1035 if sk == Z3_REAL_SORT:
1036 if k == Z3_NUMERAL_AST:
1038 if _is_algebraic(ctx, a):
1041 if sk == Z3_BV_SORT:
1042 if k == Z3_NUMERAL_AST:
1046 if sk == Z3_ARRAY_SORT:
1048 if sk == Z3_DATATYPE_SORT:
1050 if sk == Z3_FLOATING_POINT_SORT:
1051 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1054 return FPRef(a, ctx)
1055 if sk == Z3_FINITE_DOMAIN_SORT:
1056 if k == Z3_NUMERAL_AST:
1060 if sk == Z3_ROUNDING_MODE_SORT:
1062 if sk == Z3_SEQ_SORT:
1064 if sk == Z3_RE_SORT:
1065 return ReRef(a, ctx)
1068 def _coerce_expr_merge(s, a):
1081 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1082 _z3_assert(
False,
"sort mismatch")
1086 def _coerce_exprs(a, b, ctx=None):
1088 a = _py2expr(a, ctx)
1089 b = _py2expr(b, ctx)
1091 s = _coerce_expr_merge(s, a)
1092 s = _coerce_expr_merge(s, b)
1098 def _reduce(f, l, a):
1104 def _coerce_expr_list(alist, ctx=None):
1111 alist = [ _py2expr(a, ctx)
for a
in alist ]
1112 s = _reduce(_coerce_expr_merge, alist,
None)
1113 return [ s.cast(a)
for a
in alist ]
1116 """Return `True` if `a` is a Z3 expression.
1123 >>> is_expr(IntSort())
1127 >>> is_expr(IntVal(1))
1130 >>> is_expr(ForAll(x, x >= 0))
1132 >>> is_expr(FPVal(1.0))
1135 return isinstance(a, ExprRef)
1138 """Return `True` if `a` is a Z3 function application.
1140 Note that, constants are function applications with 0 arguments.
1147 >>> is_app(IntSort())
1151 >>> is_app(IntVal(1))
1154 >>> is_app(ForAll(x, x >= 0))
1157 if not isinstance(a, ExprRef):
1159 k = _ast_kind(a.ctx, a)
1160 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1163 """Return `True` if `a` is Z3 constant/variable expression.
1172 >>> is_const(IntVal(1))
1175 >>> is_const(ForAll(x, x >= 0))
1178 return is_app(a)
and a.num_args() == 0
1181 """Return `True` if `a` is variable.
1183 Z3 uses de-Bruijn indices for representing bound variables in
1191 >>> f = Function('f', IntSort(), IntSort())
1192 >>> # Z3 replaces x with bound variables when ForAll is executed.
1193 >>> q = ForAll(x, f(x) == x)
1199 >>> is_var(b.arg(1))
1202 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1205 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1213 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1214 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1215 >>> q = ForAll([x, y], f(x, y) == x + y)
1217 f(Var(1), Var(0)) == Var(1) + Var(0)
1221 >>> v1 = b.arg(0).arg(0)
1222 >>> v2 = b.arg(0).arg(1)
1227 >>> get_var_index(v1)
1229 >>> get_var_index(v2)
1233 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1237 """Return `True` if `a` is an application of the given kind `k`.
1241 >>> is_app_of(n, Z3_OP_ADD)
1243 >>> is_app_of(n, Z3_OP_MUL)
1246 return is_app(a)
and a.decl().kind() == k
1248 def If(a, b, c, ctx=None):
1249 """Create a Z3 if-then-else expression.
1253 >>> max = If(x > y, x, y)
1259 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1260 return Cond(a, b, c, ctx)
1262 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1265 b, c = _coerce_exprs(b, c, ctx)
1267 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1268 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1271 """Create a Z3 distinct expression.
1278 >>> Distinct(x, y, z)
1280 >>> simplify(Distinct(x, y, z))
1282 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1283 And(Not(x == y), Not(x == z), Not(y == z))
1285 args = _get_args(args)
1286 ctx = _ctx_from_ast_arg_list(args)
1288 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1289 args = _coerce_expr_list(args, ctx)
1290 _args, sz = _to_ast_array(args)
1293 def _mk_bin(f, a, b):
1296 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1297 args[0] = a.as_ast()
1298 args[1] = b.as_ast()
1299 return f(a.ctx.ref(), 2, args)
1302 """Create a constant of the given sort.
1304 >>> Const('x', IntSort())
1308 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1313 """Create several constants of the given sort.
1315 `names` is a string containing the names of all constants to be created.
1316 Blank spaces separate the names of different constants.
1318 >>> x, y, z = Consts('x y z', IntSort())
1322 if isinstance(names, str):
1323 names = names.split(
" ")
1324 return [
Const(name, sort)
for name
in names]
1327 """Create a fresh constant of a specified sort"""
1328 ctx = _get_ctx(sort.ctx)
1332 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1334 >>> Var(0, IntSort())
1336 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1340 _z3_assert(
is_sort(s),
"Z3 sort expected")
1341 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1345 Create a real free variable. Free variables are used to create quantified formulas.
1346 They are also used to create polynomials.
1355 Create a list of Real free variables.
1356 The variables have ids: 0, 1, ..., n-1
1358 >>> x0, x1, x2, x3 = RealVarVector(4)
1373 """Try to cast `val` as a Boolean.
1375 >>> x = BoolSort().cast(True)
1385 if isinstance(val, bool):
1389 _z3_assert(
is_expr(val),
"True, False or Z3 Boolean expression expected. Received %s" % val)
1390 if not self.
eq(val.sort()):
1391 _z3_assert(self.
eq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1395 return isinstance(other, ArithSortRef)
1405 """All Boolean expressions are instances of this class."""
1413 """Create the Z3 expression `self * other`.
1419 return If(self, other, 0)
1423 """Return `True` if `a` is a Z3 Boolean expression.
1429 >>> is_bool(And(p, q))
1437 return isinstance(a, BoolRef)
1440 """Return `True` if `a` is the Z3 true expression.
1445 >>> is_true(simplify(p == p))
1450 >>> # True is a Python Boolean expression
1457 """Return `True` if `a` is the Z3 false expression.
1464 >>> is_false(BoolVal(False))
1470 """Return `True` if `a` is a Z3 and expression.
1472 >>> p, q = Bools('p q')
1473 >>> is_and(And(p, q))
1475 >>> is_and(Or(p, q))
1481 """Return `True` if `a` is a Z3 or expression.
1483 >>> p, q = Bools('p q')
1486 >>> is_or(And(p, q))
1492 """Return `True` if `a` is a Z3 implication expression.
1494 >>> p, q = Bools('p q')
1495 >>> is_implies(Implies(p, q))
1497 >>> is_implies(And(p, q))
1503 """Return `True` if `a` is a Z3 not expression.
1514 """Return `True` if `a` is a Z3 equality expression.
1516 >>> x, y = Ints('x y')
1523 """Return `True` if `a` is a Z3 distinct expression.
1525 >>> x, y, z = Ints('x y z')
1526 >>> is_distinct(x == y)
1528 >>> is_distinct(Distinct(x, y, z))
1534 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1538 >>> p = Const('p', BoolSort())
1541 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1544 >>> is_bool(r(0, 1))
1551 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1555 >>> is_true(BoolVal(True))
1559 >>> is_false(BoolVal(False))
1569 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1580 """Return a tuple of Boolean constants.
1582 `names` is a single string containing all names separated by blank spaces.
1583 If `ctx=None`, then the global context is used.
1585 >>> p, q, r = Bools('p q r')
1586 >>> And(p, Or(q, r))
1590 if isinstance(names, str):
1591 names = names.split(
" ")
1592 return [
Bool(name, ctx)
for name
in names]
1595 """Return a list of Boolean constants of size `sz`.
1597 The constants are named using the given prefix.
1598 If `ctx=None`, then the global context is used.
1600 >>> P = BoolVector('p', 3)
1604 And(p__0, p__1, p__2)
1606 return [
Bool(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
1609 """Return a fresh Boolean constant in the given context using the given prefix.
1611 If `ctx=None`, then the global context is used.
1613 >>> b1 = FreshBool()
1614 >>> b2 = FreshBool()
1622 """Create a Z3 implies expression.
1624 >>> p, q = Bools('p q')
1628 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1635 """Create a Z3 Xor expression.
1637 >>> p, q = Bools('p q')
1640 >>> simplify(Xor(p, q))
1643 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1650 """Create a Z3 not expression or probe.
1655 >>> simplify(Not(Not(p)))
1658 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1673 def _has_probe(args):
1674 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1681 """Create a Z3 and-expression or and-probe.
1683 >>> p, q, r = Bools('p q r')
1686 >>> P = BoolVector('p', 5)
1688 And(p__0, p__1, p__2, p__3, p__4)
1692 last_arg = args[len(args)-1]
1693 if isinstance(last_arg, Context):
1694 ctx = args[len(args)-1]
1695 args = args[:len(args)-1]
1696 elif len(args) == 1
and isinstance(args[0], AstVector):
1698 args = [a
for a
in args[0]]
1701 args = _get_args(args)
1702 ctx_args = _ctx_from_ast_arg_list(args, ctx)
1704 _z3_assert(ctx_args
is None or ctx_args == ctx,
"context mismatch")
1705 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1706 if _has_probe(args):
1707 return _probe_and(args, ctx)
1709 args = _coerce_expr_list(args, ctx)
1710 _args, sz = _to_ast_array(args)
1714 """Create a Z3 or-expression or or-probe.
1716 >>> p, q, r = Bools('p q r')
1719 >>> P = BoolVector('p', 5)
1721 Or(p__0, p__1, p__2, p__3, p__4)
1725 last_arg = args[len(args)-1]
1726 if isinstance(last_arg, Context):
1727 ctx = args[len(args)-1]
1728 args = args[:len(args)-1]
1731 args = _get_args(args)
1732 ctx_args = _ctx_from_ast_arg_list(args, ctx)
1734 _z3_assert(ctx_args
is None or ctx_args == ctx,
"context mismatch")
1735 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1736 if _has_probe(args):
1737 return _probe_or(args, ctx)
1739 args = _coerce_expr_list(args, ctx)
1740 _args, sz = _to_ast_array(args)
1750 """Patterns are hints for quantifier instantiation.
1760 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1762 >>> f = Function('f', IntSort(), IntSort())
1764 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1766 ForAll(x, f(x) == 0)
1767 >>> q.num_patterns()
1769 >>> is_pattern(q.pattern(0))
1774 return isinstance(a, PatternRef)
1777 """Create a Z3 multi-pattern using the given expressions `*args`
1779 >>> f = Function('f', IntSort(), IntSort())
1780 >>> g = Function('g', IntSort(), IntSort())
1782 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1784 ForAll(x, f(x) != g(x))
1785 >>> q.num_patterns()
1787 >>> is_pattern(q.pattern(0))
1790 MultiPattern(f(Var(0)), g(Var(0)))
1793 _z3_assert(len(args) > 0,
"At least one argument expected")
1794 _z3_assert(all([
is_expr(a)
for a
in args ]),
"Z3 expressions expected")
1796 args, sz = _to_ast_array(args)
1799 def _to_pattern(arg):
1812 """Universally and Existentially quantified formulas."""
1821 """Return the Boolean sort or sort of Lambda."""
1827 """Return `True` if `self` is a universal quantifier.
1829 >>> f = Function('f', IntSort(), IntSort())
1831 >>> q = ForAll(x, f(x) == 0)
1834 >>> q = Exists(x, f(x) != 0)
1841 """Return `True` if `self` is an existential quantifier.
1843 >>> f = Function('f', IntSort(), IntSort())
1845 >>> q = ForAll(x, f(x) == 0)
1848 >>> q = Exists(x, f(x) != 0)
1855 """Return `True` if `self` is a lambda expression.
1857 >>> f = Function('f', IntSort(), IntSort())
1859 >>> q = Lambda(x, f(x))
1862 >>> q = Exists(x, f(x) != 0)
1869 """Return the Z3 expression `self[arg]`.
1872 _z3_assert(self.
is_lambda(),
"quantifier should be a lambda expression")
1873 arg = self.
sort().domain().cast(arg)
1878 """Return the weight annotation of `self`.
1880 >>> f = Function('f', IntSort(), IntSort())
1882 >>> q = ForAll(x, f(x) == 0)
1885 >>> q = ForAll(x, f(x) == 0, weight=10)
1892 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
1894 >>> f = Function('f', IntSort(), IntSort())
1895 >>> g = Function('g', IntSort(), IntSort())
1897 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
1898 >>> q.num_patterns()
1904 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
1906 >>> f = Function('f', IntSort(), IntSort())
1907 >>> g = Function('g', IntSort(), IntSort())
1909 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
1910 >>> q.num_patterns()
1918 _z3_assert(idx < self.
num_patterns(),
"Invalid pattern idx")
1922 """Return the number of no-patterns."""
1926 """Return a no-pattern."""
1932 """Return the expression being quantified.
1934 >>> f = Function('f', IntSort(), IntSort())
1936 >>> q = ForAll(x, f(x) == 0)
1943 """Return the number of variables bounded by this quantifier.
1945 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1948 >>> q = ForAll([x, y], f(x, y) >= x)
1955 """Return a string representing a name used when displaying the quantifier.
1957 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1960 >>> q = ForAll([x, y], f(x, y) >= x)
1967 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
1971 """Return the sort of a bound variable.
1973 >>> f = Function('f', IntSort(), RealSort(), IntSort())
1976 >>> q = ForAll([x, y], f(x, y) >= x)
1983 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
1987 """Return a list containing a single element self.body()
1989 >>> f = Function('f', IntSort(), IntSort())
1991 >>> q = ForAll(x, f(x) == 0)
1995 return [ self.
body() ]
1998 """Return `True` if `a` is a Z3 quantifier.
2000 >>> f = Function('f', IntSort(), IntSort())
2002 >>> q = ForAll(x, f(x) == 0)
2003 >>> is_quantifier(q)
2005 >>> is_quantifier(f(x))
2008 return isinstance(a, QuantifierRef)
2010 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2012 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2013 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2014 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2015 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2026 _vs = (Ast * num_vars)()
2027 for i
in range(num_vars):
2029 _vs[i] = vs[i].as_ast()
2030 patterns = [ _to_pattern(p)
for p
in patterns ]
2031 num_pats = len(patterns)
2032 _pats = (Pattern * num_pats)()
2033 for i
in range(num_pats):
2034 _pats[i] = patterns[i].ast
2035 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2041 num_no_pats, _no_pats,
2042 body.as_ast()), ctx)
2044 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2045 """Create a Z3 forall formula.
2047 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2049 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2052 >>> ForAll([x, y], f(x, y) >= x)
2053 ForAll([x, y], f(x, y) >= x)
2054 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2055 ForAll([x, y], f(x, y) >= x)
2056 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2057 ForAll([x, y], f(x, y) >= x)
2059 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2061 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2062 """Create a Z3 exists formula.
2064 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2067 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2070 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2072 Exists([x, y], f(x, y) >= x)
2073 >>> is_quantifier(q)
2075 >>> r = Tactic('nnf')(q).as_expr()
2076 >>> is_quantifier(r)
2079 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2082 """Create a Z3 lambda expression.
2084 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2085 >>> mem0 = Array('mem0', IntSort(), IntSort())
2086 >>> lo, hi, e, i = Ints('lo hi e i')
2087 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2089 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2095 _vs = (Ast * num_vars)()
2096 for i
in range(num_vars):
2098 _vs[i] = vs[i].as_ast()
2108 """Real and Integer sorts."""
2111 """Return `True` if `self` is of the sort Real.
2116 >>> (x + 1).is_real()
2122 return self.
kind() == Z3_REAL_SORT
2125 """Return `True` if `self` is of the sort Integer.
2130 >>> (x + 1).is_int()
2136 return self.
kind() == Z3_INT_SORT
2139 """Return `True` if `self` is a subsort of `other`."""
2143 """Try to cast `val` as an Integer or Real.
2145 >>> IntSort().cast(10)
2147 >>> is_int(IntSort().cast(10))
2151 >>> RealSort().cast(10)
2153 >>> is_real(RealSort().cast(10))
2158 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
2162 if val_s.is_int()
and self.
is_real():
2164 if val_s.is_bool()
and self.
is_int():
2165 return If(val, 1, 0)
2166 if val_s.is_bool()
and self.
is_real():
2169 _z3_assert(
False,
"Z3 Integer/Real expression expected" )
2176 _z3_assert(
False,
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s" % self)
2179 """Return `True` if s is an arithmetical sort (type).
2181 >>> is_arith_sort(IntSort())
2183 >>> is_arith_sort(RealSort())
2185 >>> is_arith_sort(BoolSort())
2187 >>> n = Int('x') + 1
2188 >>> is_arith_sort(n.sort())
2191 return isinstance(s, ArithSortRef)
2194 """Integer and Real expressions."""
2197 """Return the sort (type) of the arithmetical expression `self`.
2201 >>> (Real('x') + 1).sort()
2207 """Return `True` if `self` is an integer expression.
2212 >>> (x + 1).is_int()
2215 >>> (x + y).is_int()
2221 """Return `True` if `self` is an real expression.
2226 >>> (x + 1).is_real()
2232 """Create the Z3 expression `self + other`.
2241 a, b = _coerce_exprs(self, other)
2242 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctx)
2245 """Create the Z3 expression `other + self`.
2251 a, b = _coerce_exprs(self, other)
2252 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctx)
2255 """Create the Z3 expression `self * other`.
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)
2270 """Create the Z3 expression `other * self`.
2276 a, b = _coerce_exprs(self, other)
2277 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctx)
2280 """Create the Z3 expression `self - other`.
2289 a, b = _coerce_exprs(self, other)
2290 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctx)
2293 """Create the Z3 expression `other - self`.
2299 a, b = _coerce_exprs(self, other)
2300 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctx)
2303 """Create the Z3 expression `self**other` (** is the power operator).
2310 >>> simplify(IntVal(2)**8)
2313 a, b = _coerce_exprs(self, other)
2317 """Create the Z3 expression `other**self` (** is the power operator).
2324 >>> simplify(2**IntVal(8))
2327 a, b = _coerce_exprs(self, other)
2331 """Create the Z3 expression `other/self`.
2350 a, b = _coerce_exprs(self, other)
2354 """Create the Z3 expression `other/self`."""
2358 """Create the Z3 expression `other/self`.
2371 a, b = _coerce_exprs(self, other)
2375 """Create the Z3 expression `other/self`."""
2379 """Create the Z3 expression `other%self`.
2385 >>> simplify(IntVal(10) % IntVal(3))
2388 a, b = _coerce_exprs(self, other)
2390 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2394 """Create the Z3 expression `other%self`.
2400 a, b = _coerce_exprs(self, other)
2402 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2406 """Return an expression representing `-self`.
2426 """Create the Z3 expression `other <= self`.
2428 >>> x, y = Ints('x y')
2435 a, b = _coerce_exprs(self, other)
2439 """Create the Z3 expression `other < self`.
2441 >>> x, y = Ints('x y')
2448 a, b = _coerce_exprs(self, other)
2452 """Create the Z3 expression `other > self`.
2454 >>> x, y = Ints('x y')
2461 a, b = _coerce_exprs(self, other)
2465 """Create the Z3 expression `other >= self`.
2467 >>> x, y = Ints('x y')
2474 a, b = _coerce_exprs(self, other)
2478 """Return `True` if `a` is an arithmetical expression.
2487 >>> is_arith(IntVal(1))
2495 return isinstance(a, ArithRef)
2498 """Return `True` if `a` is an integer expression.
2505 >>> is_int(IntVal(1))
2516 """Return `True` if `a` is a real expression.
2528 >>> is_real(RealVal(1))
2533 def _is_numeral(ctx, a):
2536 def _is_algebraic(ctx, a):
2540 """Return `True` if `a` is an integer value of sort Int.
2542 >>> is_int_value(IntVal(1))
2546 >>> is_int_value(Int('x'))
2548 >>> n = Int('x') + 1
2553 >>> is_int_value(n.arg(1))
2555 >>> is_int_value(RealVal("1/3"))
2557 >>> is_int_value(RealVal(1))
2560 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2563 """Return `True` if `a` is rational value of sort Real.
2565 >>> is_rational_value(RealVal(1))
2567 >>> is_rational_value(RealVal("3/5"))
2569 >>> is_rational_value(IntVal(1))
2571 >>> is_rational_value(1)
2573 >>> n = Real('x') + 1
2576 >>> is_rational_value(n.arg(1))
2578 >>> is_rational_value(Real('x'))
2581 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2584 """Return `True` if `a` is an algebraic value of sort Real.
2586 >>> is_algebraic_value(RealVal("3/5"))
2588 >>> n = simplify(Sqrt(2))
2591 >>> is_algebraic_value(n)
2594 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2597 """Return `True` if `a` is an expression of the form b + c.
2599 >>> x, y = Ints('x y')
2608 """Return `True` if `a` is an expression of the form b * c.
2610 >>> x, y = Ints('x y')
2619 """Return `True` if `a` is an expression of the form b - c.
2621 >>> x, y = Ints('x y')
2630 """Return `True` if `a` is an expression of the form b / c.
2632 >>> x, y = Reals('x y')
2637 >>> x, y = Ints('x y')
2646 """Return `True` if `a` is an expression of the form b div c.
2648 >>> x, y = Ints('x y')
2657 """Return `True` if `a` is an expression of the form b % c.
2659 >>> x, y = Ints('x y')
2668 """Return `True` if `a` is an expression of the form b <= c.
2670 >>> x, y = Ints('x y')
2679 """Return `True` if `a` is an expression of the form b < c.
2681 >>> x, y = Ints('x y')
2690 """Return `True` if `a` is an expression of the form b >= c.
2692 >>> x, y = Ints('x y')
2701 """Return `True` if `a` is an expression of the form b > c.
2703 >>> x, y = Ints('x y')
2712 """Return `True` if `a` is an expression of the form IsInt(b).
2715 >>> is_is_int(IsInt(x))
2723 """Return `True` if `a` is an expression of the form ToReal(b).
2737 """Return `True` if `a` is an expression of the form ToInt(b).
2751 """Integer values."""
2754 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2763 _z3_assert(self.
is_int(),
"Integer value expected")
2767 """Return a Z3 integer numeral as a Python string.
2775 """Rational values."""
2778 """ Return the numerator of a Z3 rational numeral.
2780 >>> is_rational_value(RealVal("3/5"))
2782 >>> n = RealVal("3/5")
2785 >>> is_rational_value(Q(3,5))
2787 >>> Q(3,5).numerator()
2793 """ Return the denominator of a Z3 rational numeral.
2795 >>> is_rational_value(Q(3,5))
2804 """ Return the numerator as a Python long.
2806 >>> v = RealVal(10000000000)
2811 >>> v.numerator_as_long() + 1 == 10000000001
2817 """ Return the denominator as a Python long.
2819 >>> v = RealVal("1/3")
2822 >>> v.denominator_as_long()
2837 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
2841 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2843 >>> v = RealVal("1/5")
2846 >>> v = RealVal("1/3")
2853 """Return a Z3 rational numeral as a Python string.
2862 """Return a Z3 rational as a Python Fraction object.
2864 >>> v = RealVal("1/5")
2871 """Algebraic irrational values."""
2874 """Return a Z3 rational number that approximates the algebraic number `self`.
2875 The result `r` is such that |r - self| <= 1/10^precision
2877 >>> x = simplify(Sqrt(2))
2879 6838717160008073720548335/4835703278458516698824704
2885 """Return a string representation of the algebraic number `self` in decimal notation using `prec` decimal places
2887 >>> x = simplify(Sqrt(2))
2888 >>> x.as_decimal(10)
2890 >>> x.as_decimal(20)
2891 '1.41421356237309504880?'
2895 def _py2expr(a, ctx=None):
2896 if isinstance(a, bool):
2900 if isinstance(a, float):
2905 _z3_assert(
False,
"Python bool, int, long or float expected")
2908 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2912 >>> x = Const('x', IntSort())
2915 >>> x.sort() == IntSort()
2917 >>> x.sort() == BoolSort()
2924 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2928 >>> x = Const('x', RealSort())
2933 >>> x.sort() == RealSort()
2939 def _to_int_str(val):
2940 if isinstance(val, float):
2941 return str(int(val))
2942 elif isinstance(val, bool):
2949 elif isinstance(val, str):
2952 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
2955 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
2966 """Return a Z3 real value.
2968 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
2969 If `ctx=None`, then the global context is used.
2973 >>> RealVal(1).sort()
2984 """Return a Z3 rational a/b.
2986 If `ctx=None`, then the global context is used.
2990 >>> RatVal(3,5).sort()
2994 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
2995 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
2998 def Q(a, b, ctx=None):
2999 """Return a Z3 rational a/b.
3001 If `ctx=None`, then the global context is used.
3011 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3023 """Return a tuple of Integer constants.
3025 >>> x, y, z = Ints('x y z')
3030 if isinstance(names, str):
3031 names = names.split(
" ")
3032 return [
Int(name, ctx)
for name
in names]
3035 """Return a list of integer constants of size `sz`.
3037 >>> X = IntVector('x', 3)
3043 return [
Int(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
3046 """Return a fresh integer constant in the given context using the given prefix.
3059 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3071 """Return a tuple of real constants.
3073 >>> x, y, z = Reals('x y z')
3076 >>> Sum(x, y, z).sort()
3080 if isinstance(names, str):
3081 names = names.split(
" ")
3082 return [
Real(name, ctx)
for name
in names]
3085 """Return a list of real constants of size `sz`.
3087 >>> X = RealVector('x', 3)
3095 return [
Real(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
3098 """Return a fresh real constant in the given context using the given prefix.
3111 """ Return the Z3 expression ToReal(a).
3123 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3128 """ Return the Z3 expression ToInt(a).
3140 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3145 """ Return the Z3 predicate IsInt(a).
3148 >>> IsInt(x + "1/2")
3150 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3152 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3156 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3161 """ Return a Z3 expression which represents the square root of a.
3173 """ Return a Z3 expression which represents the cubic root of a.
3191 """Bit-vector sort."""
3194 """Return the size (number of bits) of the bit-vector sort `self`.
3196 >>> b = BitVecSort(32)
3206 """Try to cast `val` as a Bit-Vector.
3208 >>> b = BitVecSort(32)
3211 >>> b.cast(10).sexpr()
3216 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
3223 """Return True if `s` is a Z3 bit-vector sort.
3225 >>> is_bv_sort(BitVecSort(32))
3227 >>> is_bv_sort(IntSort())
3230 return isinstance(s, BitVecSortRef)
3233 """Bit-vector expressions."""
3236 """Return the sort of the bit-vector expression `self`.
3238 >>> x = BitVec('x', 32)
3241 >>> x.sort() == BitVecSort(32)
3247 """Return the number of bits of the bit-vector expression `self`.
3249 >>> x = BitVec('x', 32)
3252 >>> Concat(x, x).size()
3258 """Create the Z3 expression `self + other`.
3260 >>> x = BitVec('x', 32)
3261 >>> y = BitVec('y', 32)
3267 a, b = _coerce_exprs(self, other)
3271 """Create the Z3 expression `other + self`.
3273 >>> x = BitVec('x', 32)
3277 a, b = _coerce_exprs(self, other)
3281 """Create the Z3 expression `self * other`.
3283 >>> x = BitVec('x', 32)
3284 >>> y = BitVec('y', 32)
3290 a, b = _coerce_exprs(self, other)
3294 """Create the Z3 expression `other * self`.
3296 >>> x = BitVec('x', 32)
3300 a, b = _coerce_exprs(self, other)
3304 """Create the Z3 expression `self - other`.
3306 >>> x = BitVec('x', 32)
3307 >>> y = BitVec('y', 32)
3313 a, b = _coerce_exprs(self, other)
3317 """Create the Z3 expression `other - self`.
3319 >>> x = BitVec('x', 32)
3323 a, b = _coerce_exprs(self, other)
3327 """Create the Z3 expression bitwise-or `self | other`.
3329 >>> x = BitVec('x', 32)
3330 >>> y = BitVec('y', 32)
3336 a, b = _coerce_exprs(self, other)
3340 """Create the Z3 expression bitwise-or `other | self`.
3342 >>> x = BitVec('x', 32)
3346 a, b = _coerce_exprs(self, other)
3350 """Create the Z3 expression bitwise-and `self & other`.
3352 >>> x = BitVec('x', 32)
3353 >>> y = BitVec('y', 32)
3359 a, b = _coerce_exprs(self, other)
3363 """Create the Z3 expression bitwise-or `other & self`.
3365 >>> x = BitVec('x', 32)
3369 a, b = _coerce_exprs(self, other)
3373 """Create the Z3 expression bitwise-xor `self ^ other`.
3375 >>> x = BitVec('x', 32)
3376 >>> y = BitVec('y', 32)
3382 a, b = _coerce_exprs(self, other)
3386 """Create the Z3 expression bitwise-xor `other ^ self`.
3388 >>> x = BitVec('x', 32)
3392 a, b = _coerce_exprs(self, other)
3398 >>> x = BitVec('x', 32)
3405 """Return an expression representing `-self`.
3407 >>> x = BitVec('x', 32)
3416 """Create the Z3 expression bitwise-not `~self`.
3418 >>> x = BitVec('x', 32)
3427 """Create the Z3 expression (signed) division `self / other`.
3429 Use the function UDiv() for unsigned division.
3431 >>> x = BitVec('x', 32)
3432 >>> y = BitVec('y', 32)
3439 >>> UDiv(x, y).sexpr()
3442 a, b = _coerce_exprs(self, other)
3446 """Create the Z3 expression (signed) division `self / other`."""
3450 """Create the Z3 expression (signed) division `other / self`.
3452 Use the function UDiv() for unsigned division.
3454 >>> x = BitVec('x', 32)
3457 >>> (10 / x).sexpr()
3458 '(bvsdiv #x0000000a x)'
3459 >>> UDiv(10, x).sexpr()
3460 '(bvudiv #x0000000a x)'
3462 a, b = _coerce_exprs(self, other)
3466 """Create the Z3 expression (signed) division `other / self`."""
3470 """Create the Z3 expression (signed) mod `self % other`.
3472 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3474 >>> x = BitVec('x', 32)
3475 >>> y = BitVec('y', 32)
3482 >>> URem(x, y).sexpr()
3484 >>> SRem(x, y).sexpr()
3487 a, b = _coerce_exprs(self, other)
3491 """Create the Z3 expression (signed) mod `other % self`.
3493 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3495 >>> x = BitVec('x', 32)
3498 >>> (10 % x).sexpr()
3499 '(bvsmod #x0000000a x)'
3500 >>> URem(10, x).sexpr()
3501 '(bvurem #x0000000a x)'
3502 >>> SRem(10, x).sexpr()
3503 '(bvsrem #x0000000a x)'
3505 a, b = _coerce_exprs(self, other)
3509 """Create the Z3 expression (signed) `other <= self`.
3511 Use the function ULE() for unsigned less than or equal to.
3513 >>> x, y = BitVecs('x y', 32)
3516 >>> (x <= y).sexpr()
3518 >>> ULE(x, y).sexpr()
3521 a, b = _coerce_exprs(self, other)
3525 """Create the Z3 expression (signed) `other < self`.
3527 Use the function ULT() for unsigned less than.
3529 >>> x, y = BitVecs('x y', 32)
3534 >>> ULT(x, y).sexpr()
3537 a, b = _coerce_exprs(self, other)
3541 """Create the Z3 expression (signed) `other > self`.
3543 Use the function UGT() for unsigned greater than.
3545 >>> x, y = BitVecs('x y', 32)
3550 >>> UGT(x, y).sexpr()
3553 a, b = _coerce_exprs(self, other)
3557 """Create the Z3 expression (signed) `other >= self`.
3559 Use the function UGE() for unsigned greater than or equal to.
3561 >>> x, y = BitVecs('x y', 32)
3564 >>> (x >= y).sexpr()
3566 >>> UGE(x, y).sexpr()
3569 a, b = _coerce_exprs(self, other)
3573 """Create the Z3 expression (arithmetical) right shift `self >> other`
3575 Use the function LShR() for the right logical shift
3577 >>> x, y = BitVecs('x y', 32)
3580 >>> (x >> y).sexpr()
3582 >>> LShR(x, y).sexpr()
3586 >>> BitVecVal(4, 3).as_signed_long()
3588 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3590 >>> simplify(BitVecVal(4, 3) >> 1)
3592 >>> simplify(LShR(BitVecVal(4, 3), 1))
3594 >>> simplify(BitVecVal(2, 3) >> 1)
3596 >>> simplify(LShR(BitVecVal(2, 3), 1))
3599 a, b = _coerce_exprs(self, other)
3603 """Create the Z3 expression left shift `self << other`
3605 >>> x, y = BitVecs('x y', 32)
3608 >>> (x << y).sexpr()
3610 >>> simplify(BitVecVal(2, 3) << 1)
3613 a, b = _coerce_exprs(self, other)
3617 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3619 Use the function LShR() for the right logical shift
3621 >>> x = BitVec('x', 32)
3624 >>> (10 >> x).sexpr()
3625 '(bvashr #x0000000a x)'
3627 a, b = _coerce_exprs(self, other)
3631 """Create the Z3 expression left shift `other << self`.
3633 Use the function LShR() for the right logical shift
3635 >>> x = BitVec('x', 32)
3638 >>> (10 << x).sexpr()
3639 '(bvshl #x0000000a x)'
3641 a, b = _coerce_exprs(self, other)
3645 """Bit-vector values."""
3648 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3650 >>> v = BitVecVal(0xbadc0de, 32)
3653 >>> print("0x%.8x" % v.as_long())
3659 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign.
3661 >>> BitVecVal(4, 3).as_signed_long()
3663 >>> BitVecVal(7, 3).as_signed_long()
3665 >>> BitVecVal(3, 3).as_signed_long()
3667 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3669 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3674 if val >= 2**(sz - 1):
3676 if val < -2**(sz - 1):
3684 """Return `True` if `a` is a Z3 bit-vector expression.
3686 >>> b = BitVec('b', 32)
3694 return isinstance(a, BitVecRef)
3697 """Return `True` if `a` is a Z3 bit-vector numeral value.
3699 >>> b = BitVec('b', 32)
3702 >>> b = BitVecVal(10, 32)
3708 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3711 """Return the Z3 expression BV2Int(a).
3713 >>> b = BitVec('b', 3)
3714 >>> BV2Int(b).sort()
3719 >>> x > BV2Int(b, is_signed=False)
3721 >>> x > BV2Int(b, is_signed=True)
3722 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3723 >>> solve(x > BV2Int(b), b == 1, x < 3)
3727 _z3_assert(
is_bv(a),
"Z3 bit-vector expression expected")
3733 """Return the z3 expression Int2BV(a, num_bits).
3734 It is a bit-vector of width num_bits and represents the
3735 modulo of a by 2^num_bits
3741 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3743 >>> Byte = BitVecSort(8)
3744 >>> Word = BitVecSort(16)
3747 >>> x = Const('x', Byte)
3748 >>> eq(x, BitVec('x', 8))
3755 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3757 >>> v = BitVecVal(10, 32)
3760 >>> print("0x%.8x" % v.as_long())
3771 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3772 If `ctx=None`, then the global context is used.
3774 >>> x = BitVec('x', 16)
3781 >>> word = BitVecSort(16)
3782 >>> x2 = BitVec('x', word)
3786 if isinstance(bv, BitVecSortRef):
3794 """Return a tuple of bit-vector constants of size bv.
3796 >>> x, y, z = BitVecs('x y z', 16)
3803 >>> Product(x, y, z)
3805 >>> simplify(Product(x, y, z))
3809 if isinstance(names, str):
3810 names = names.split(
" ")
3811 return [
BitVec(name, bv, ctx)
for name
in names]
3814 """Create a Z3 bit-vector concatenation expression.
3816 >>> v = BitVecVal(1, 4)
3817 >>> Concat(v, v+1, v)
3818 Concat(Concat(1, 1 + 1), 1)
3819 >>> simplify(Concat(v, v+1, v))
3821 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3824 args = _get_args(args)
3827 _z3_assert(sz >= 2,
"At least two arguments expected.")
3834 if is_seq(args[0])
or isinstance(args[0], str):
3835 args = [_coerce_seq(s, ctx)
for s
in args]
3837 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
3840 v[i] = args[i].as_ast()
3845 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
3848 v[i] = args[i].as_ast()
3852 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
3854 for i
in range(sz - 1):
3859 """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3861 >>> x = BitVec('x', 8)
3862 >>> Extract(6, 2, x)
3864 >>> Extract(6, 2, x).sort()
3866 >>> simplify(Extract(StringVal("abcd"),2,1))
3869 if isinstance(high, str):
3873 offset, length = _coerce_exprs(low, a, s.ctx)
3876 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
3877 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
"First and second arguments must be non negative integers")
3878 _z3_assert(
is_bv(a),
"Third argument must be a Z3 Bitvector expression")
3881 def _check_bv_args(a, b):
3883 _z3_assert(
is_bv(a)
or is_bv(b),
"At least one of the arguments must be a Z3 bit-vector expression")
3886 """Create the Z3 expression (unsigned) `other <= self`.
3888 Use the operator <= for signed less than or equal to.
3890 >>> x, y = BitVecs('x y', 32)
3893 >>> (x <= y).sexpr()
3895 >>> ULE(x, y).sexpr()
3898 _check_bv_args(a, b)
3899 a, b = _coerce_exprs(a, b)
3903 """Create the Z3 expression (unsigned) `other < self`.
3905 Use the operator < for signed less than.
3907 >>> x, y = BitVecs('x y', 32)
3912 >>> ULT(x, y).sexpr()
3915 _check_bv_args(a, b)
3916 a, b = _coerce_exprs(a, b)
3920 """Create the Z3 expression (unsigned) `other >= self`.
3922 Use the operator >= for signed greater than or equal to.
3924 >>> x, y = BitVecs('x y', 32)
3927 >>> (x >= y).sexpr()
3929 >>> UGE(x, y).sexpr()
3932 _check_bv_args(a, b)
3933 a, b = _coerce_exprs(a, b)
3937 """Create the Z3 expression (unsigned) `other > self`.
3939 Use the operator > for signed greater than.
3941 >>> x, y = BitVecs('x y', 32)
3946 >>> UGT(x, y).sexpr()
3949 _check_bv_args(a, b)
3950 a, b = _coerce_exprs(a, b)
3954 """Create the Z3 expression (unsigned) division `self / other`.
3956 Use the operator / for signed division.
3958 >>> x = BitVec('x', 32)
3959 >>> y = BitVec('y', 32)
3962 >>> UDiv(x, y).sort()
3966 >>> UDiv(x, y).sexpr()
3969 _check_bv_args(a, b)
3970 a, b = _coerce_exprs(a, b)
3974 """Create the Z3 expression (unsigned) remainder `self % other`.
3976 Use the operator % for signed modulus, and SRem() for signed remainder.
3978 >>> x = BitVec('x', 32)
3979 >>> y = BitVec('y', 32)
3982 >>> URem(x, y).sort()
3986 >>> URem(x, y).sexpr()
3989 _check_bv_args(a, b)
3990 a, b = _coerce_exprs(a, b)
3994 """Create the Z3 expression signed remainder.
3996 Use the operator % for signed modulus, and URem() for unsigned remainder.
3998 >>> x = BitVec('x', 32)
3999 >>> y = BitVec('y', 32)
4002 >>> SRem(x, y).sort()
4006 >>> SRem(x, y).sexpr()
4009 _check_bv_args(a, b)
4010 a, b = _coerce_exprs(a, b)
4014 """Create the Z3 expression logical right shift.
4016 Use the operator >> for the arithmetical right shift.
4018 >>> x, y = BitVecs('x y', 32)
4021 >>> (x >> y).sexpr()
4023 >>> LShR(x, y).sexpr()
4027 >>> BitVecVal(4, 3).as_signed_long()
4029 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4031 >>> simplify(BitVecVal(4, 3) >> 1)
4033 >>> simplify(LShR(BitVecVal(4, 3), 1))
4035 >>> simplify(BitVecVal(2, 3) >> 1)
4037 >>> simplify(LShR(BitVecVal(2, 3), 1))
4040 _check_bv_args(a, b)
4041 a, b = _coerce_exprs(a, b)
4045 """Return an expression representing `a` rotated to the left `b` times.
4047 >>> a, b = BitVecs('a b', 16)
4048 >>> RotateLeft(a, b)
4050 >>> simplify(RotateLeft(a, 0))
4052 >>> simplify(RotateLeft(a, 16))
4055 _check_bv_args(a, b)
4056 a, b = _coerce_exprs(a, b)
4060 """Return an expression representing `a` rotated to the right `b` times.
4062 >>> a, b = BitVecs('a b', 16)
4063 >>> RotateRight(a, b)
4065 >>> simplify(RotateRight(a, 0))
4067 >>> simplify(RotateRight(a, 16))
4070 _check_bv_args(a, b)
4071 a, b = _coerce_exprs(a, b)
4075 """Return a bit-vector expression with `n` extra sign-bits.
4077 >>> x = BitVec('x', 16)
4078 >>> n = SignExt(8, x)
4085 >>> v0 = BitVecVal(2, 2)
4090 >>> v = simplify(SignExt(6, v0))
4095 >>> print("%.x" % v.as_long())
4099 _z3_assert(_is_int(n),
"First argument must be an integer")
4100 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4104 """Return a bit-vector expression with `n` extra zero-bits.
4106 >>> x = BitVec('x', 16)
4107 >>> n = ZeroExt(8, x)
4114 >>> v0 = BitVecVal(2, 2)
4119 >>> v = simplify(ZeroExt(6, v0))
4126 _z3_assert(_is_int(n),
"First argument must be an integer")
4127 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4131 """Return an expression representing `n` copies of `a`.
4133 >>> x = BitVec('x', 8)
4134 >>> n = RepeatBitVec(4, x)
4139 >>> v0 = BitVecVal(10, 4)
4140 >>> print("%.x" % v0.as_long())
4142 >>> v = simplify(RepeatBitVec(4, v0))
4145 >>> print("%.x" % v.as_long())
4149 _z3_assert(_is_int(n),
"First argument must be an integer")
4150 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4154 """Return the reduction-and expression of `a`."""
4156 _z3_assert(
is_bv(a),
"First argument must be a Z3 Bitvector expression")
4160 """Return the reduction-or expression of `a`."""
4162 _z3_assert(
is_bv(a),
"First argument must be a Z3 Bitvector expression")
4166 """A predicate the determines that bit-vector addition does not overflow"""
4167 _check_bv_args(a, b)
4168 a, b = _coerce_exprs(a, b)
4172 """A predicate the determines that signed bit-vector addition does not underflow"""
4173 _check_bv_args(a, b)
4174 a, b = _coerce_exprs(a, b)
4178 """A predicate the determines that bit-vector subtraction does not overflow"""
4179 _check_bv_args(a, b)
4180 a, b = _coerce_exprs(a, b)
4185 """A predicate the determines that bit-vector subtraction does not underflow"""
4186 _check_bv_args(a, b)
4187 a, b = _coerce_exprs(a, b)
4191 """A predicate the determines that bit-vector signed division does not overflow"""
4192 _check_bv_args(a, b)
4193 a, b = _coerce_exprs(a, b)
4197 """A predicate the determines that bit-vector unary negation does not overflow"""
4199 _z3_assert(
is_bv(a),
"Argument should be a bit-vector")
4203 """A predicate the determines that bit-vector multiplication does not overflow"""
4204 _check_bv_args(a, b)
4205 a, b = _coerce_exprs(a, b)
4210 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4211 _check_bv_args(a, b)
4212 a, b = _coerce_exprs(a, b)
4227 """Return the domain of the array sort `self`.
4229 >>> A = ArraySort(IntSort(), BoolSort())
4236 """Return the range of the array sort `self`.
4238 >>> A = ArraySort(IntSort(), BoolSort())
4245 """Array expressions. """
4248 """Return the array sort of the array expression `self`.
4250 >>> a = Array('a', IntSort(), BoolSort())
4257 """Shorthand for `self.sort().domain()`.
4259 >>> a = Array('a', IntSort(), BoolSort())
4266 """Shorthand for `self.sort().range()`.
4268 >>> a = Array('a', IntSort(), BoolSort())
4275 """Return the Z3 expression `self[arg]`.
4277 >>> a = Array('a', IntSort(), BoolSort())
4284 arg = self.
domain().cast(arg)
4295 """Return `True` if `a` is a Z3 array expression.
4297 >>> a = Array('a', IntSort(), IntSort())
4300 >>> is_array(Store(a, 0, 1))
4305 return isinstance(a, ArrayRef)
4308 """Return `True` if `a` is a Z3 constant array.
4310 >>> a = K(IntSort(), 10)
4311 >>> is_const_array(a)
4313 >>> a = Array('a', IntSort(), IntSort())
4314 >>> is_const_array(a)
4320 """Return `True` if `a` is a Z3 constant array.
4322 >>> a = K(IntSort(), 10)
4325 >>> a = Array('a', IntSort(), IntSort())
4332 """Return `True` if `a` is a Z3 map array expression.
4334 >>> f = Function('f', IntSort(), IntSort())
4335 >>> b = Array('b', IntSort(), IntSort())
4347 """Return `True` if `a` is a Z3 default array expression.
4348 >>> d = Default(K(IntSort(), 10))
4352 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4355 """Return the function declaration associated with a Z3 map array expression.
4357 >>> f = Function('f', IntSort(), IntSort())
4358 >>> b = Array('b', IntSort(), IntSort())
4360 >>> eq(f, get_map_func(a))
4364 >>> get_map_func(a)(0)
4368 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4372 """Return the Z3 array sort with the given domain and range sorts.
4374 >>> A = ArraySort(IntSort(), BoolSort())
4381 >>> AA = ArraySort(IntSort(), A)
4383 Array(Int, Array(Int, Bool))
4385 sig = _get_args(sig)
4387 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4388 arity = len(sig) - 1
4393 _z3_assert(
is_sort(s),
"Z3 sort expected")
4394 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4398 dom = (Sort * arity)()
4399 for i
in range(arity):
4404 """Return an array constant named `name` with the given domain and range sorts.
4406 >>> a = Array('a', IntSort(), IntSort())
4417 """Return a Z3 store array expression.
4419 >>> a = Array('a', IntSort(), IntSort())
4420 >>> i, v = Ints('i v')
4421 >>> s = Update(a, i, v)
4424 >>> prove(s[i] == v)
4427 >>> prove(Implies(i != j, s[j] == a[j]))
4431 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4432 i = a.domain().cast(i)
4433 v = a.range().cast(v)
4435 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4438 """ Return a default value for array expression.
4439 >>> b = K(IntSort(), 1)
4440 >>> prove(Default(b) == 1)
4444 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4449 """Return a Z3 store array expression.
4451 >>> a = Array('a', IntSort(), IntSort())
4452 >>> i, v = Ints('i v')
4453 >>> s = Store(a, i, v)
4456 >>> prove(s[i] == v)
4459 >>> prove(Implies(i != j, s[j] == a[j]))
4465 """Return a Z3 select array expression.
4467 >>> a = Array('a', IntSort(), IntSort())
4471 >>> eq(Select(a, i), a[i])
4475 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4480 """Return a Z3 map array expression.
4482 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4483 >>> a1 = Array('a1', IntSort(), IntSort())
4484 >>> a2 = Array('a2', IntSort(), IntSort())
4485 >>> b = Map(f, a1, a2)
4488 >>> prove(b[0] == f(a1[0], a2[0]))
4491 args = _get_args(args)
4493 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4494 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4495 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4496 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4497 _args, sz = _to_ast_array(args)
4502 """Return a Z3 constant array expression.
4504 >>> a = K(IntSort(), 10)
4516 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4519 v = _py2expr(v, ctx)
4523 """Return extensionality index for one-dimensional arrays.
4524 >> a, b = Consts('a b', SetSort(IntSort()))
4531 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4535 k = _py2expr(k, ctx)
4539 """Return `True` if `a` is a Z3 array select application.
4541 >>> a = Array('a', IntSort(), IntSort())
4551 """Return `True` if `a` is a Z3 array store application.
4553 >>> a = Array('a', IntSort(), IntSort())
4556 >>> is_store(Store(a, 0, 1))
4569 """ Create a set sort over element sort s"""
4573 """Create the empty set
4574 >>> EmptySet(IntSort())
4581 """Create the full set
4582 >>> FullSet(IntSort())
4589 """ Take the union of sets
4590 >>> a = Const('a', SetSort(IntSort()))
4591 >>> b = Const('b', SetSort(IntSort()))
4595 args = _get_args(args)
4596 ctx = _ctx_from_ast_arg_list(args)
4597 _args, sz = _to_ast_array(args)
4601 """ Take the union of sets
4602 >>> a = Const('a', SetSort(IntSort()))
4603 >>> b = Const('b', SetSort(IntSort()))
4604 >>> SetIntersect(a, b)
4607 args = _get_args(args)
4608 ctx = _ctx_from_ast_arg_list(args)
4609 _args, sz = _to_ast_array(args)
4613 """ Add element e to set s
4614 >>> a = Const('a', SetSort(IntSort()))
4618 ctx = _ctx_from_ast_arg_list([s,e])
4619 e = _py2expr(e, ctx)
4623 """ Remove element e to set s
4624 >>> a = Const('a', SetSort(IntSort()))
4628 ctx = _ctx_from_ast_arg_list([s,e])
4629 e = _py2expr(e, ctx)
4633 """ The complement of set s
4634 >>> a = Const('a', SetSort(IntSort()))
4635 >>> SetComplement(a)
4642 """ The set difference of a and b
4643 >>> a = Const('a', SetSort(IntSort()))
4644 >>> b = Const('b', SetSort(IntSort()))
4645 >>> SetDifference(a, b)
4648 ctx = _ctx_from_ast_arg_list([a, b])
4652 """ Check if e is a member of set s
4653 >>> a = Const('a', SetSort(IntSort()))
4657 ctx = _ctx_from_ast_arg_list([s,e])
4658 e = _py2expr(e, ctx)
4662 """ Check if a is a subset of b
4663 >>> a = Const('a', SetSort(IntSort()))
4664 >>> b = Const('b', SetSort(IntSort()))
4668 ctx = _ctx_from_ast_arg_list([a, b])
4678 def _valid_accessor(acc):
4679 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4680 return isinstance(acc, tuple)
and len(acc) == 2
and isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4683 """Helper class for declaring Z3 datatypes.
4685 >>> List = Datatype('List')
4686 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4687 >>> List.declare('nil')
4688 >>> List = List.create()
4689 >>> # List is now a Z3 declaration
4692 >>> List.cons(10, List.nil)
4694 >>> List.cons(10, List.nil).sort()
4696 >>> cons = List.cons
4700 >>> n = cons(1, cons(0, nil))
4702 cons(1, cons(0, nil))
4703 >>> simplify(cdr(n))
4705 >>> simplify(car(n))
4720 _z3_assert(isinstance(name, str),
"String expected")
4721 _z3_assert(isinstance(rec_name, str),
"String expected")
4722 _z3_assert(all([_valid_accessor(a)
for a
in args]),
"Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
4726 """Declare constructor named `name` with the given accessors `args`.
4727 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared.
4729 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4730 declares the constructor named `cons` that builds a new List using an integer and a List.
4731 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4732 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4733 the actual datatype in Z3.
4735 >>> List = Datatype('List')
4736 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4737 >>> List.declare('nil')
4738 >>> List = List.create()
4741 _z3_assert(isinstance(name, str),
"String expected")
4742 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4749 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
4751 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4753 >>> List = Datatype('List')
4754 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4755 >>> List.declare('nil')
4756 >>> List = List.create()
4759 >>> List.cons(10, List.nil)
4765 """Auxiliary object used to create Z3 datatypes."""
4770 if self.
ctx.ref()
is not None:
4774 """Auxiliary object used to create Z3 datatypes."""
4779 if self.
ctx.ref()
is not None:
4783 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4785 In the following example we define a Tree-List using two mutually recursive datatypes.
4787 >>> TreeList = Datatype('TreeList')
4788 >>> Tree = Datatype('Tree')
4789 >>> # Tree has two constructors: leaf and node
4790 >>> Tree.declare('leaf', ('val', IntSort()))
4791 >>> # a node contains a list of trees
4792 >>> Tree.declare('node', ('children', TreeList))
4793 >>> TreeList.declare('nil')
4794 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4795 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4796 >>> Tree.val(Tree.leaf(10))
4798 >>> simplify(Tree.val(Tree.leaf(10)))
4800 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4802 node(cons(leaf(10), cons(leaf(20), nil)))
4803 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4804 >>> simplify(n2 == n1)
4806 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4811 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
4812 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
4813 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
4814 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
4817 names = (Symbol * num)()
4818 out = (Sort * num)()
4819 clists = (ConstructorList * num)()
4821 for i
in range(num):
4824 num_cs = len(d.constructors)
4825 cs = (Constructor * num_cs)()
4826 for j
in range(num_cs):
4827 c = d.constructors[j]
4832 fnames = (Symbol * num_fs)()
4833 sorts = (Sort * num_fs)()
4834 refs = (ctypes.c_uint * num_fs)()
4835 for k
in range(num_fs):
4839 if isinstance(ftype, Datatype):
4841 _z3_assert(ds.count(ftype) == 1,
"One and only one occurrence of each datatype is expected")
4843 refs[k] = ds.index(ftype)
4846 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
4847 sorts[k] = ftype.ast
4856 for i
in range(num):
4858 num_cs = dref.num_constructors()
4859 for j
in range(num_cs):
4860 cref = dref.constructor(j)
4861 cref_name = cref.name()
4862 cref_arity = cref.arity()
4863 if cref.arity() == 0:
4865 setattr(dref, cref_name, cref)
4866 rref = dref.recognizer(j)
4867 setattr(dref,
"is_" + cref_name, rref)
4868 for k
in range(cref_arity):
4869 aref = dref.accessor(j, k)
4870 setattr(dref, aref.name(), aref)
4872 return tuple(result)
4875 """Datatype sorts."""
4877 """Return the number of constructors in the given Z3 datatype.
4879 >>> List = Datatype('List')
4880 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4881 >>> List.declare('nil')
4882 >>> List = List.create()
4883 >>> # List is now a Z3 declaration
4884 >>> List.num_constructors()
4890 """Return a constructor of the datatype `self`.
4892 >>> List = Datatype('List')
4893 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4894 >>> List.declare('nil')
4895 >>> List = List.create()
4896 >>> # List is now a Z3 declaration
4897 >>> List.num_constructors()
4899 >>> List.constructor(0)
4901 >>> List.constructor(1)
4909 """In Z3, each constructor has an associated recognizer predicate.
4911 If the constructor is named `name`, then the recognizer `is_name`.
4913 >>> List = Datatype('List')
4914 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4915 >>> List.declare('nil')
4916 >>> List = List.create()
4917 >>> # List is now a Z3 declaration
4918 >>> List.num_constructors()
4920 >>> List.recognizer(0)
4922 >>> List.recognizer(1)
4924 >>> simplify(List.is_nil(List.cons(10, List.nil)))
4926 >>> simplify(List.is_cons(List.cons(10, List.nil)))
4928 >>> l = Const('l', List)
4929 >>> simplify(List.is_cons(l))
4937 """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4939 >>> List = Datatype('List')
4940 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4941 >>> List.declare('nil')
4942 >>> List = List.create()
4943 >>> List.num_constructors()
4945 >>> List.constructor(0)
4947 >>> num_accs = List.constructor(0).arity()
4950 >>> List.accessor(0, 0)
4952 >>> List.accessor(0, 1)
4954 >>> List.constructor(1)
4956 >>> num_accs = List.constructor(1).arity()
4962 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
4966 """Datatype expressions."""
4968 """Return the datatype sort of the datatype expression `self`."""
4972 """Create a named tuple sort base on a set of underlying sorts
4974 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
4977 projects = [ (
'project%d' % i, sorts[i])
for i
in range(len(sorts)) ]
4978 tuple.declare(name, *projects)
4979 tuple = tuple.create()
4980 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
4983 """Create a named tagged union sort base on a set of underlying sorts
4985 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
4988 for i
in range(len(sorts)):
4989 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
4991 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
4995 """Return a new enumeration sort named `name` containing the given values.
4997 The result is a pair (sort, list of constants).
4999 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5002 _z3_assert(isinstance(name, str),
"Name must be a string")
5003 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5004 _z3_assert(len(values) > 0,
"At least one value expected")
5007 _val_names = (Symbol * num)()
5008 for i
in range(num):
5010 _values = (FuncDecl * num)()
5011 _testers = (FuncDecl * num)()
5015 for i
in range(num):
5017 V = [a()
for a
in V]
5027 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5029 Consider using the function `args2params` to create instances of this object.
5043 if self.
ctx.ref()
is not None:
5047 """Set parameter name with value val."""
5049 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5051 if isinstance(val, bool):
5055 elif isinstance(val, float):
5057 elif isinstance(val, str):
5061 _z3_assert(
False,
"invalid parameter value")
5067 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5071 """Convert python arguments into a Z3_params object.
5072 A ':' is added to the keywords, and '_' is replaced with '-'
5074 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5075 (params model true relevancy 2 elim_and true)
5078 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5093 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5096 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5102 return ParamsDescrsRef(self.
descr, self.
ctx)
5105 if self.
ctx.ref()
is not None:
5109 """Return the size of in the parameter description `self`.
5114 """Return the size of in the parameter description `self`.
5119 """Return the i-th parameter name in the parameter description `self`.
5124 """Return the kind of the parameter named `n`.
5129 """Return the documentation string of the parameter named `n`.
5149 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5151 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5152 A goal has a solution if one of its subgoals has a solution.
5153 A goal is unsatisfiable if all subgoals are unsatisfiable.
5156 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5158 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5161 if self.
goal is None:
5166 return Goal(
False,
False,
False, self.
ctx, self.
goal)
5169 if self.
goal is not None and self.
ctx.ref()
is not None:
5173 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
5175 >>> x, y = Ints('x y')
5177 >>> g.add(x == 0, y >= x + 1)
5180 >>> r = Then('simplify', 'solve-eqs')(g)
5181 >>> # r has 1 subgoal
5190 """Return `True` if `self` contains the `False` constraints.
5192 >>> x, y = Ints('x y')
5194 >>> g.inconsistent()
5196 >>> g.add(x == 0, x == 1)
5199 >>> g.inconsistent()
5201 >>> g2 = Tactic('propagate-values')(g)[0]
5202 >>> g2.inconsistent()
5208 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5211 >>> g.prec() == Z3_GOAL_PRECISE
5213 >>> x, y = Ints('x y')
5214 >>> g.add(x == y + 1)
5215 >>> g.prec() == Z3_GOAL_PRECISE
5217 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5220 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5221 >>> g2.prec() == Z3_GOAL_PRECISE
5223 >>> g2.prec() == Z3_GOAL_UNDER
5229 """Alias for `prec()`.
5232 >>> g.precision() == Z3_GOAL_PRECISE
5238 """Return the number of constraints in the goal `self`.
5243 >>> x, y = Ints('x y')
5244 >>> g.add(x == 0, y > x)
5251 """Return the number of constraints in the goal `self`.
5256 >>> x, y = Ints('x y')
5257 >>> g.add(x == 0, y > x)
5264 """Return a constraint in the goal `self`.
5267 >>> x, y = Ints('x y')
5268 >>> g.add(x == 0, y > x)
5277 """Return a constraint in the goal `self`.
5280 >>> x, y = Ints('x y')
5281 >>> g.add(x == 0, y > x)
5287 if arg >= len(self):
5289 return self.
get(arg)
5292 """Assert constraints into the goal.
5296 >>> g.assert_exprs(x > 0, x < 2)
5300 args = _get_args(args)
5311 >>> g.append(x > 0, x < 2)
5322 >>> g.insert(x > 0, x < 2)
5333 >>> g.add(x > 0, x < 2)
5340 """Retrieve model from a satisfiable goal
5341 >>> a, b = Ints('a b')
5343 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5344 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5347 [Or(b == 0, b == 1), Not(0 <= b)]
5349 [Or(b == 0, b == 1), Not(1 <= b)]
5350 >>> # Remark: the subgoal r[0] is unsatisfiable
5351 >>> # Creating a solver for solving the second subgoal
5358 >>> # Model s.model() does not assign a value to `a`
5359 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5360 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5361 >>> r[1].convert_model(s.model())
5365 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5369 return obj_to_string(self)
5372 """Return a textual representation of the s-expression representing the goal."""
5376 """Return a textual representation of the goal in DIMACS format."""
5380 """Copy goal `self` to context `target`.
5388 >>> g2 = g.translate(c2)
5391 >>> g.ctx == main_ctx()
5395 >>> g2.ctx == main_ctx()
5399 _z3_assert(isinstance(target, Context),
"target must be a context")
5409 """Return a new simplified goal.
5411 This method is essentially invoking the simplify tactic.
5415 >>> g.add(x + 1 >= 2)
5418 >>> g2 = g.simplify()
5421 >>> # g was not modified
5426 return t.apply(self, *arguments, **keywords)[0]
5429 """Return goal `self` as a single Z3 expression.
5456 """A collection (vector) of ASTs."""
5465 assert ctx
is not None
5473 if self.
vector is not None and self.
ctx.ref()
is not None:
5477 """Return the size of the vector `self`.
5482 >>> A.push(Int('x'))
5483 >>> A.push(Int('x'))
5490 """Return the AST at position `i`.
5493 >>> A.push(Int('x') + 1)
5494 >>> A.push(Int('y'))
5501 if isinstance(i, int):
5509 elif isinstance(i, slice):
5514 """Update AST at position `i`.
5517 >>> A.push(Int('x') + 1)
5518 >>> A.push(Int('y'))
5530 """Add `v` in the end of the vector.
5535 >>> A.push(Int('x'))
5542 """Resize the vector to `sz` elements.
5548 >>> for i in range(10): A[i] = Int('x')
5555 """Return `True` if the vector contains `item`.
5578 """Copy vector `self` to context `other_ctx`.
5584 >>> B = A.translate(c2)
5597 return obj_to_string(self)
5600 """Return a textual representation of the s-expression representing the vector."""
5609 """A mapping from ASTs to ASTs."""
5618 assert ctx
is not None
5626 if self.
map is not None and self.
ctx.ref()
is not None:
5630 """Return the size of the map.
5636 >>> M[x] = IntVal(1)
5643 """Return `True` if the map contains key `key`.
5656 """Retrieve the value associated with key `key`.
5667 """Add/Update key `k` with value `v`.
5676 >>> M[x] = IntVal(1)
5686 """Remove the entry associated with key `k`.
5700 """Remove all entries from the map.
5705 >>> M[x+x] = IntVal(1)
5715 """Return an AstVector containing all keys in the map.
5720 >>> M[x+x] = IntVal(1)
5733 """Store the value of the interpretation of a function in a particular point."""
5744 if self.
ctx.ref()
is not None:
5748 """Return the number of arguments in the given entry.
5750 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5752 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5757 >>> f_i.num_entries()
5759 >>> e = f_i.entry(0)
5766 """Return the value of argument `idx`.
5768 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5770 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5775 >>> f_i.num_entries()
5777 >>> e = f_i.entry(0)
5788 ... except IndexError:
5789 ... print("index error")
5797 """Return the value of the function at point `self`.
5799 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5801 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5806 >>> f_i.num_entries()
5808 >>> e = f_i.entry(0)
5819 """Return entry `self` as a Python list.
5820 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5822 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5827 >>> f_i.num_entries()
5829 >>> e = f_i.entry(0)
5834 args.append(self.
value())
5841 """Stores the interpretation of a function in a Z3 model."""
5846 if self.
f is not None:
5853 if self.
f is not None and self.
ctx.ref()
is not None:
5858 Return the `else` value for a function interpretation.
5859 Return None if Z3 did not specify the `else` value for
5862 >>> f = Function('f', IntSort(), IntSort())
5864 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5870 >>> m[f].else_value()
5875 return _to_expr_ref(r, self.
ctx)
5880 """Return the number of entries/points in the function interpretation `self`.
5882 >>> f = Function('f', IntSort(), IntSort())
5884 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5890 >>> m[f].num_entries()
5896 """Return the number of arguments for each entry in the function interpretation `self`.
5898 >>> f = Function('f', IntSort(), IntSort())
5900 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5910 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5912 >>> f = Function('f', IntSort(), IntSort())
5914 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5920 >>> m[f].num_entries()
5930 """Copy model 'self' to context 'other_ctx'.
5941 """Return the function interpretation as a Python list.
5942 >>> f = Function('f', IntSort(), IntSort())
5944 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5958 return obj_to_string(self)
5961 """Model/Solution of a satisfiability problem (aka system of constraints)."""
5964 assert ctx
is not None
5970 if self.
ctx.ref()
is not None:
5974 return obj_to_string(self)
5977 """Return a textual representation of the s-expression representing the model."""
5980 def eval(self, t, model_completion=False):
5981 """Evaluate the expression `t` in the model `self`. If `model_completion` is enabled, then a default interpretation is automatically added for symbols that do not have an interpretation in the model `self`.
5985 >>> s.add(x > 0, x < 2)
5998 >>> m.eval(y, model_completion=True)
6000 >>> # Now, m contains an interpretation for y
6006 return _to_expr_ref(r[0], self.
ctx)
6007 raise Z3Exception(
"failed to evaluate expression in the model")
6010 """Alias for `eval`.
6014 >>> s.add(x > 0, x < 2)
6018 >>> m.evaluate(x + 1)
6020 >>> m.evaluate(x == 1)
6023 >>> m.evaluate(y + x)
6027 >>> m.evaluate(y, model_completion=True)
6029 >>> # Now, m contains an interpretation for y
6030 >>> m.evaluate(y + x)
6033 return self.
eval(t, model_completion)
6036 """Return the number of constant and function declarations in the model `self`.
6038 >>> f = Function('f', IntSort(), IntSort())
6041 >>> s.add(x > 0, f(x) != x)
6051 """Return the interpretation for a given declaration or constant.
6053 >>> f = Function('f', IntSort(), IntSort())
6056 >>> s.add(x > 0, x < 2, f(x) == 0)
6066 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6070 if decl.arity() == 0:
6072 if _r.value
is None:
6074 r = _to_expr_ref(_r, self.
ctx)
6085 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6087 >>> A = DeclareSort('A')
6088 >>> a, b = Consts('a b', A)
6100 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6102 >>> A = DeclareSort('A')
6103 >>> B = DeclareSort('B')
6104 >>> a1, a2 = Consts('a1 a2', A)
6105 >>> b1, b2 = Consts('b1 b2', B)
6107 >>> s.add(a1 != a2, b1 != b2)
6123 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6125 >>> A = DeclareSort('A')
6126 >>> B = DeclareSort('B')
6127 >>> a1, a2 = Consts('a1 a2', A)
6128 >>> b1, b2 = Consts('b1 b2', B)
6130 >>> s.add(a1 != a2, b1 != b2)
6140 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6142 >>> A = DeclareSort('A')
6143 >>> a, b = Consts('a b', A)
6149 >>> m.get_universe(A)
6153 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6160 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpretation is returned.
6162 The elements can be retrieved using position or the actual declaration.
6164 >>> f = Function('f', IntSort(), IntSort())
6167 >>> s.add(x > 0, x < 2, f(x) == 0)
6181 >>> for d in m: print("%s -> %s" % (d, m[d]))
6186 if idx >= len(self):
6189 if (idx < num_consts):
6193 if isinstance(idx, FuncDeclRef):
6197 if isinstance(idx, SortRef):
6200 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6204 """Return a list with all symbols that have an interpretation in the model `self`.
6205 >>> f = Function('f', IntSort(), IntSort())
6208 >>> s.add(x > 0, x < 2, f(x) == 0)
6223 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6226 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6228 return Model(model, target)
6241 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6242 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6245 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6247 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6256 """Statistics for `Solver.check()`."""
6267 if self.
ctx.ref()
is not None:
6274 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6277 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6280 out.write(u(
'<tr>'))
6282 out.write(u(
'<td>%s</td><td>%s</td></tr>' % (k, v)))
6283 out.write(u(
'</table>'))
6284 return out.getvalue()
6289 """Return the number of statistical counters.
6292 >>> s = Then('simplify', 'nlsat').solver()
6296 >>> st = s.statistics()
6303 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6306 >>> s = Then('simplify', 'nlsat').solver()
6310 >>> st = s.statistics()
6314 ('nlsat propagations', 2)
6318 if idx >= len(self):
6327 """Return the list of statistical counters.
6330 >>> s = Then('simplify', 'nlsat').solver()
6334 >>> st = s.statistics()
6339 """Return the value of a particular statistical counter.
6342 >>> s = Then('simplify', 'nlsat').solver()
6346 >>> st = s.statistics()
6347 >>> st.get_key_value('nlsat propagations')
6350 for idx
in range(len(self)):
6356 raise Z3Exception(
"unknown key")
6359 """Access the value of statistical using attributes.
6361 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6362 we should use '_' (e.g., 'nlsat_propagations').
6365 >>> s = Then('simplify', 'nlsat').solver()
6369 >>> st = s.statistics()
6370 >>> st.nlsat_propagations
6375 key = name.replace(
'_',
' ')
6379 raise AttributeError
6387 """Represents the result of a satisfiability check: sat, unsat, unknown.
6393 >>> isinstance(r, CheckSatResult)
6404 return isinstance(other, CheckSatResult)
and self.
r == other.r
6407 return not self.
__eq__(other)
6411 if self.
r == Z3_L_TRUE:
6413 elif self.
r == Z3_L_FALSE:
6414 return "<b>unsat</b>"
6416 return "<b>unknown</b>"
6418 if self.
r == Z3_L_TRUE:
6420 elif self.
r == Z3_L_FALSE:
6425 def _repr_html_(self):
6426 in_html = in_html_mode()
6429 set_html_mode(in_html)
6437 """Solver API provides methods for implementing the main SMT 2.0 commands: push, pop, check, get-model, etc."""
6439 def __init__(self, solver=None, ctx=None, logFile=None):
6440 assert solver
is None or ctx
is not None
6449 if logFile
is not None:
6450 self.
set(
"solver.smtlib2_log", logFile)
6453 if self.
solver is not None and self.
ctx.ref()
is not None:
6457 """Set a configuration option. The method `help()` return a string containing all available options.
6460 >>> # The option MBQI can be set using three different approaches.
6461 >>> s.set(mbqi=True)
6462 >>> s.set('MBQI', True)
6463 >>> s.set(':mbqi', True)
6469 """Create a backtracking point.
6491 """Backtrack \c num backtracking points.
6513 """Return the current number of backtracking points.
6531 """Remove all asserted constraints and backtracking points created using `push()`.
6545 """Assert constraints into the solver.
6549 >>> s.assert_exprs(x > 0, x < 2)
6553 args = _get_args(args)
6556 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6564 """Assert constraints into the solver.
6568 >>> s.add(x > 0, x < 2)
6579 """Assert constraints into the solver.
6583 >>> s.append(x > 0, x < 2)
6590 """Assert constraints into the solver.
6594 >>> s.insert(x > 0, x < 2)
6601 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6603 If `p` is a string, it will be automatically converted into a Boolean constant.
6608 >>> s.set(unsat_core=True)
6609 >>> s.assert_and_track(x > 0, 'p1')
6610 >>> s.assert_and_track(x != 1, 'p2')
6611 >>> s.assert_and_track(x < 0, p3)
6612 >>> print(s.check())
6614 >>> c = s.unsat_core()
6624 if isinstance(p, str):
6626 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6627 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6631 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
6637 >>> s.add(x > 0, x < 2)
6640 >>> s.model().eval(x)
6646 >>> s.add(2**x == 4)
6650 assumptions = _get_args(assumptions)
6651 num = len(assumptions)
6652 _assumptions = (Ast * num)()
6653 for i
in range(num):
6654 _assumptions[i] = assumptions[i].as_ast()
6659 """Return a model for the last `check()`.
6661 This function raises an exception if
6662 a model is not available (e.g., last `check()` returned unsat).
6666 >>> s.add(a + 2 == 0)
6675 raise Z3Exception(
"model is not available")
6678 """Import model converter from other into the current solver"""
6682 """Return a subset (as an AST vector) of the assumptions provided to the last check().
6684 These are the assumptions Z3 used in the unsatisfiability proof.
6685 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
6686 They may be also used to "retract" assumptions. Note that, assumptions are not really
6687 "soft constraints", but they can be used to implement them.
6689 >>> p1, p2, p3 = Bools('p1 p2 p3')
6690 >>> x, y = Ints('x y')
6692 >>> s.add(Implies(p1, x > 0))
6693 >>> s.add(Implies(p2, y > x))
6694 >>> s.add(Implies(p2, y < 1))
6695 >>> s.add(Implies(p3, y > -3))
6696 >>> s.check(p1, p2, p3)
6698 >>> core = s.unsat_core()
6707 >>> # "Retracting" p2
6714 """Determine fixed values for the variables based on the solver state and assumptions.
6716 >>> a, b, c, d = Bools('a b c d')
6717 >>> s.add(Implies(a,b), Implies(b, c))
6718 >>> s.consequences([a],[b,c,d])
6719 (sat, [Implies(a, b), Implies(a, c)])
6720 >>> s.consequences([Not(c),d],[a,b,c,d])
6721 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
6723 if isinstance(assumptions, list):
6725 for a
in assumptions:
6728 if isinstance(variables, list):
6733 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
6734 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
6737 sz = len(consequences)
6738 consequences = [ consequences[i]
for i
in range(sz) ]
6742 """Parse assertions from a file"""
6746 """Parse assertions from a string"""
6751 The method takes an optional set of variables that restrict which
6752 variables may be used as a starting point for cubing.
6753 If vars is not None, then the first case split is based on a variable in
6757 if vars
is not None:
6764 if (len(r) == 1
and is_false(r[0])):
6771 """Access the set of variables that were touched by the most recently generated cube.
6772 This set of variables can be used as a starting point for additional cubes.
6773 The idea is that variables that appear in clauses that are reduced by the most recent
6774 cube are likely more useful to cube on."""
6778 """Return a proof for the last `check()`. Proof construction must be enabled."""
6782 """Return an AST vector containing all added constraints.
6796 """Return an AST vector containing all currently inferred units.
6801 """Return an AST vector containing all atomic formulas in solver state that are not units.
6806 """Return trail and decision levels of the solver state after a check() call.
6808 trail = self.
trail()
6809 levels = (ctypes.c_uint * len(trail))()
6811 return trail, levels
6814 """Return trail of the solver state after a check() call.
6819 """Return statistics for the last `check()`.
6821 >>> s = SimpleSolver()
6826 >>> st = s.statistics()
6827 >>> st.get_key_value('final checks')
6837 """Return a string describing why the last `check()` returned `unknown`.
6840 >>> s = SimpleSolver()
6841 >>> s.add(2**x == 4)
6844 >>> s.reason_unknown()
6845 '(incomplete (theory arithmetic))'
6850 """Display a string describing all available options."""
6854 """Return the parameter description set."""
6858 """Return a formatted string with all added constraints."""
6859 return obj_to_string(self)
6862 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6866 >>> s1 = Solver(ctx=c1)
6867 >>> s2 = s1.translate(c2)
6870 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6872 return Solver(solver, target)
6881 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
6892 """Return a textual representation of the solver in DIMACS format."""
6896 """return SMTLIB2 formatted benchmark for solver's assertions"""
6903 for i
in range(sz1):
6904 v[i] = es[i].as_ast()
6906 e = es[sz1].as_ast()
6912 """Create a solver customized for the given logic.
6914 The parameter `logic` is a string. It should be contains
6915 the name of a SMT-LIB logic.
6916 See http://www.smtlib.org/ for the name of all available logics.
6918 >>> s = SolverFor("QF_LIA")
6932 """Return a simple general purpose solver with limited amount of preprocessing.
6934 >>> s = SimpleSolver()
6950 """Fixedpoint API provides methods for solving with recursive predicates"""
6953 assert fixedpoint
is None or ctx
is not None
6956 if fixedpoint
is None:
6967 if self.
fixedpoint is not None and self.
ctx.ref()
is not None:
6971 """Set a configuration option. The method `help()` return a string containing all available options.
6977 """Display a string describing all available options."""
6981 """Return the parameter description set."""
6985 """Assert constraints as background axioms for the fixedpoint solver."""
6986 args = _get_args(args)
6989 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6999 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7007 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7011 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7015 """Assert rules defining recursive predicates to the fixedpoint solver.
7018 >>> s = Fixedpoint()
7019 >>> s.register_relation(a.decl())
7020 >>> s.register_relation(b.decl())
7033 body = _get_args(body)
7037 def rule(self, head, body = None, name = None):
7038 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7042 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7046 """Query the fixedpoint engine whether formula is derivable.
7047 You can also pass an tuple or list of recursive predicates.
7049 query = _get_args(query)
7051 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7052 _decls = (FuncDecl * sz)()
7062 query =
And(query, self.
ctx)
7063 query = self.
abstract(query,
False)
7068 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7070 query = _get_args(query)
7072 if sz >= 1
and isinstance(query[0], FuncDecl):
7073 _z3_assert (
False,
"unsupported")
7079 query = self.
abstract(query,
False)
7080 r = Z3_fixedpoint_query_from_lvl (self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
7088 body = _get_args(body)
7093 """Retrieve answer from last query call."""
7095 return _to_expr_ref(r, self.
ctx)
7098 """Retrieve a ground cex from last query call."""
7099 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7100 return _to_expr_ref(r, self.
ctx)
7103 """retrieve rules along the counterexample trace"""
7107 """retrieve rule names along the counterexample trace"""
7110 names = _symbol2py (self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7112 return names.split (
';')
7115 """Retrieve number of levels used for predicate in PDR engine"""
7119 """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)"""
7121 return _to_expr_ref(r, self.
ctx)
7124 """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)"""
7128 """Register relation as recursive"""
7129 relations = _get_args(relations)
7134 """Control how relation is represented"""
7135 representations = _get_args(representations)
7136 representations = [
to_symbol(s)
for s
in representations]
7137 sz = len(representations)
7138 args = (Symbol * sz)()
7140 args[i] = representations[i]
7144 """Parse rules and queries from a string"""
7148 """Parse rules and queries from a file"""
7152 """retrieve rules that have been added to fixedpoint context"""
7156 """retrieve assertions that have been added to fixedpoint context"""
7160 """Return a formatted string with all added rules and constraints."""
7164 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7169 """Return a formatted string (in Lisp-like format) with all added constraints.
7170 We say the string is in s-expression format.
7171 Include also queries.
7173 args, len = _to_ast_array(queries)
7177 """Return statistics for the last `query()`.
7182 """Return a string describing why the last `query()` returned `unknown`.
7187 """Add variable or several variables.
7188 The added variable or variables will be bound in the rules
7191 vars = _get_args(vars)
7211 """Finite domain sort."""
7214 """Return the size of the finite domain sort"""
7215 r = (ctypes.c_ulonglong * 1)()
7219 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7222 """Create a named finite domain sort of a given size sz"""
7223 if not isinstance(name, Symbol):
7229 """Return True if `s` is a Z3 finite-domain sort.
7231 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7233 >>> is_finite_domain_sort(IntSort())
7236 return isinstance(s, FiniteDomainSortRef)
7240 """Finite-domain expressions."""
7243 """Return the sort of the finite-domain expression `self`."""
7247 """Return a Z3 floating point expression as a Python string."""
7251 """Return `True` if `a` is a Z3 finite-domain expression.
7253 >>> s = FiniteDomainSort('S', 100)
7254 >>> b = Const('b', s)
7255 >>> is_finite_domain(b)
7257 >>> is_finite_domain(Int('x'))
7260 return isinstance(a, FiniteDomainRef)
7264 """Integer values."""
7267 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7269 >>> s = FiniteDomainSort('S', 100)
7270 >>> v = FiniteDomainVal(3, s)
7279 """Return a Z3 finite-domain numeral as a Python string.
7281 >>> s = FiniteDomainSort('S', 100)
7282 >>> v = FiniteDomainVal(42, s)
7290 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7292 >>> s = FiniteDomainSort('S', 256)
7293 >>> FiniteDomainVal(255, s)
7295 >>> FiniteDomainVal('100', s)
7304 """Return `True` if `a` is a Z3 finite-domain value.
7306 >>> s = FiniteDomainSort('S', 100)
7307 >>> b = Const('b', s)
7308 >>> is_finite_domain_value(b)
7310 >>> b = FiniteDomainVal(10, s)
7313 >>> is_finite_domain_value(b)
7358 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7369 if self.
optimize is not None and self.
ctx.ref()
is not None:
7373 """Set a configuration option. The method `help()` return a string containing all available options.
7379 """Display a string describing all available options."""
7383 """Return the parameter description set."""
7387 """Assert constraints as background axioms for the optimize solver."""
7388 args = _get_args(args)
7391 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7399 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7407 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7409 If `p` is a string, it will be automatically converted into a Boolean constant.
7414 >>> s.assert_and_track(x > 0, 'p1')
7415 >>> s.assert_and_track(x != 1, 'p2')
7416 >>> s.assert_and_track(x < 0, p3)
7417 >>> print(s.check())
7419 >>> c = s.unsat_core()
7429 if isinstance(p, str):
7431 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7432 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7436 """Add soft constraint with optional weight and optional identifier.
7437 If no weight is supplied, then the penalty for violating the soft constraint
7439 Soft constraints are grouped by identifiers. Soft constraints that are
7440 added without identifiers are grouped by default.
7443 weight =
"%d" % weight
7444 elif isinstance(weight, float):
7445 weight =
"%f" % weight
7446 if not isinstance(weight, str):
7447 raise Z3Exception(
"weight should be a string or an integer")
7455 """Add objective function to maximize."""
7459 """Add objective function to minimize."""
7463 """create a backtracking point for added rules, facts and assertions"""
7467 """restore to previously created backtracking point"""
7471 """Check satisfiability while optimizing objective functions."""
7472 assumptions = _get_args(assumptions)
7473 num = len(assumptions)
7474 _assumptions = (Ast * num)()
7475 for i
in range(num):
7476 _assumptions[i] = assumptions[i].as_ast()
7480 """Return a string that describes why the last `check()` returned `unknown`."""
7484 """Return a model for the last check()."""
7488 raise Z3Exception(
"model is not available")
7494 if not isinstance(obj, OptimizeObjective):
7495 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7499 if not isinstance(obj, OptimizeObjective):
7500 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7504 if not isinstance(obj, OptimizeObjective):
7505 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7506 return obj.lower_values()
7509 if not isinstance(obj, OptimizeObjective):
7510 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7511 return obj.upper_values()
7514 """Parse assertions and objectives from a file"""
7518 """Parse assertions and objectives from a string"""
7522 """Return an AST vector containing all added constraints."""
7526 """returns set of objective functions"""
7530 """Return a formatted string with all added rules and constraints."""
7534 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7539 """Return statistics for the last check`.
7552 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters."""
7563 if self.
ctx.ref()
is not None:
7567 """Return the number of subgoals in `self`.
7569 >>> a, b = Ints('a b')
7571 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7572 >>> t = Tactic('split-clause')
7576 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
7579 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
7586 """Return one of the subgoals stored in ApplyResult object `self`.
7588 >>> a, b = Ints('a b')
7590 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7591 >>> t = Tactic('split-clause')
7594 [a == 0, Or(b == 0, b == 1), a > b]
7596 [a == 1, Or(b == 0, b == 1), a > b]
7598 if idx >= len(self):
7603 return obj_to_string(self)
7606 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
7611 """Return a Z3 expression consisting of all subgoals.
7616 >>> g.add(Or(x == 2, x == 3))
7617 >>> r = Tactic('simplify')(g)
7619 [[Not(x <= 1), Or(x == 2, x == 3)]]
7621 And(Not(x <= 1), Or(x == 2, x == 3))
7622 >>> r = Tactic('split-clause')(g)
7624 [[x > 1, x == 2], [x > 1, x == 3]]
7626 Or(And(x > 1, x == 2), And(x > 1, x == 3))
7642 """Tactics transform, solver and/or simplify sets of constraints (Goal). A Tactic can be converted into a Solver using the method solver().
7644 Several combinators are available for creating new tactics using the built-in ones: Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
7649 if isinstance(tactic, TacticObj):
7653 _z3_assert(isinstance(tactic, str),
"tactic name expected")
7657 raise Z3Exception(
"unknown tactic '%s'" % tactic)
7664 if self.
tactic is not None and self.
ctx.ref()
is not None:
7668 """Create a solver using the tactic `self`.
7670 The solver supports the methods `push()` and `pop()`, but it
7671 will always solve each `check()` from scratch.
7673 >>> t = Then('simplify', 'nlsat')
7676 >>> s.add(x**2 == 2, x > 0)
7684 def apply(self, goal, *arguments, **keywords):
7685 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7687 >>> x, y = Ints('x y')
7688 >>> t = Tactic('solve-eqs')
7689 >>> t.apply(And(x == 0, y >= x + 1))
7693 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expressions expected")
7694 goal = _to_goal(goal)
7695 if len(arguments) > 0
or len(keywords) > 0:
7702 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7704 >>> x, y = Ints('x y')
7705 >>> t = Tactic('solve-eqs')
7706 >>> t(And(x == 0, y >= x + 1))
7709 return self.
apply(goal, *arguments, **keywords)
7712 """Display a string containing a description of the available options for the `self` tactic."""
7716 """Return the parameter description set."""
7720 if isinstance(a, BoolRef):
7721 goal =
Goal(ctx = a.ctx)
7727 def _to_tactic(t, ctx=None):
7728 if isinstance(t, Tactic):
7733 def _and_then(t1, t2, ctx=None):
7734 t1 = _to_tactic(t1, ctx)
7735 t2 = _to_tactic(t2, ctx)
7737 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7740 def _or_else(t1, t2, ctx=None):
7741 t1 = _to_tactic(t1, ctx)
7742 t2 = _to_tactic(t2, ctx)
7744 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7748 """Return a tactic that applies the tactics in `*ts` in sequence.
7750 >>> x, y = Ints('x y')
7751 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7752 >>> t(And(x == 0, y > x + 1))
7754 >>> t(And(x == 0, y > x + 1)).as_expr()
7758 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7759 ctx = ks.get(
'ctx',
None)
7762 for i
in range(num - 1):
7763 r = _and_then(r, ts[i+1], ctx)
7767 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7769 >>> x, y = Ints('x y')
7770 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7771 >>> t(And(x == 0, y > x + 1))
7773 >>> t(And(x == 0, y > x + 1)).as_expr()
7779 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7782 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7783 >>> # Tactic split-clause fails if there is no clause in the given goal.
7786 >>> t(Or(x == 0, x == 1))
7787 [[x == 0], [x == 1]]
7790 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7791 ctx = ks.get(
'ctx',
None)
7794 for i
in range(num - 1):
7795 r = _or_else(r, ts[i+1], ctx)
7799 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7802 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7807 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7808 ctx = _get_ctx(ks.get(
'ctx',
None))
7809 ts = [ _to_tactic(t, ctx)
for t
in ts ]
7811 _args = (TacticObj * sz)()
7813 _args[i] = ts[i].tactic
7817 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7819 >>> x, y = Ints('x y')
7820 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7821 >>> t(And(Or(x == 1, x == 2), y == x + 1))
7822 [[x == 1, y == 2], [x == 2, y == 3]]
7824 t1 = _to_tactic(t1, ctx)
7825 t2 = _to_tactic(t2, ctx)
7827 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7831 """Alias for ParThen(t1, t2, ctx)."""
7835 """Return a tactic that applies tactic `t` using the given configuration options.
7837 >>> x, y = Ints('x y')
7838 >>> t = With(Tactic('simplify'), som=True)
7839 >>> t((x + 1)*(y + 2) == 0)
7840 [[2*x + y + x*y == -2]]
7842 ctx = keys.pop(
'ctx',
None)
7843 t = _to_tactic(t, ctx)
7848 """Return a tactic that applies tactic `t` using the given configuration options.
7850 >>> x, y = Ints('x y')
7852 >>> p.set("som", True)
7853 >>> t = WithParams(Tactic('simplify'), p)
7854 >>> t((x + 1)*(y + 2) == 0)
7855 [[2*x + y + x*y == -2]]
7857 t = _to_tactic(t,
None)
7861 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7863 >>> x, y = Ints('x y')
7864 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7865 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7867 >>> for subgoal in r: print(subgoal)
7868 [x == 0, y == 0, x > y]
7869 [x == 0, y == 1, x > y]
7870 [x == 1, y == 0, x > y]
7871 [x == 1, y == 1, x > y]
7872 >>> t = Then(t, Tactic('propagate-values'))
7876 t = _to_tactic(t, ctx)
7880 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7882 If `t` does not terminate in `ms` milliseconds, then it fails.
7884 t = _to_tactic(t, ctx)
7888 """Return a list of all available tactics in Z3.
7891 >>> l.count('simplify') == 1
7898 """Return a short description for the tactic named `name`.
7900 >>> d = tactic_description('simplify')
7906 """Display a (tabular) description of all available tactics in Z3."""
7909 print(
'<table border="1" cellpadding="2" cellspacing="0">')
7912 print(
'<tr style="background-color:#CFCFCF">')
7917 print(
'<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(
tactic_description(t), 40)))
7924 """Probes are used to inspect a goal (aka problem) and collect information that may be used to decide which solver and/or preprocessing step will be used."""
7928 if isinstance(probe, ProbeObj):
7930 elif isinstance(probe, float):
7932 elif _is_int(probe):
7934 elif isinstance(probe, bool):
7941 _z3_assert(isinstance(probe, str),
"probe name expected")
7945 raise Z3Exception(
"unknown probe '%s'" % probe)
7952 if self.
probe is not None and self.
ctx.ref()
is not None:
7956 """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7958 >>> p = Probe('size') < 10
7969 """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
7971 >>> p = Probe('size') > 10
7982 """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
7984 >>> p = Probe('size') <= 2
7995 """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
7997 >>> p = Probe('size') >= 2
8008 """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
8010 >>> p = Probe('size') == 2
8021 """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
8023 >>> p = Probe('size') != 2
8035 """Evaluate the probe `self` in the given goal.
8037 >>> p = Probe('size')
8047 >>> p = Probe('num-consts')
8050 >>> p = Probe('is-propositional')
8053 >>> p = Probe('is-qflia')
8058 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expression expected")
8059 goal = _to_goal(goal)
8063 """Return `True` if `p` is a Z3 probe.
8065 >>> is_probe(Int('x'))
8067 >>> is_probe(Probe('memory'))
8070 return isinstance(p, Probe)
8072 def _to_probe(p, ctx=None):
8076 return Probe(p, ctx)
8079 """Return a list of all available probes in Z3.
8082 >>> l.count('memory') == 1
8089 """Return a short description for the probe named `name`.
8091 >>> d = probe_description('memory')
8097 """Display a (tabular) description of all available probes in Z3."""
8100 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8103 print(
'<tr style="background-color:#CFCFCF">')
8108 print(
'<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(
probe_description(p), 40)))
8114 def _probe_nary(f, args, ctx):
8116 _z3_assert(len(args) > 0,
"At least one argument expected")
8118 r = _to_probe(args[0], ctx)
8119 for i
in range(num - 1):
8120 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i+1], ctx).probe), ctx)
8123 def _probe_and(args, ctx):
8124 return _probe_nary(Z3_probe_and, args, ctx)
8126 def _probe_or(args, ctx):
8127 return _probe_nary(Z3_probe_or, args, ctx)
8130 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8132 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
8134 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8135 >>> x, y = Ints('x y')
8141 >>> g.add(x == y + 1)
8143 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8145 p = _to_probe(p, ctx)
8149 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8151 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8152 >>> x, y = Ints('x y')
8158 >>> g.add(x == y + 1)
8160 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8162 p = _to_probe(p, ctx)
8163 t = _to_tactic(t, ctx)
8167 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8169 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8171 p = _to_probe(p, ctx)
8172 t1 = _to_tactic(t1, ctx)
8173 t2 = _to_tactic(t2, ctx)
8183 """Simplify the expression `a` using the given options.
8185 This function has many options. Use `help_simplify` to obtain the complete list.
8189 >>> simplify(x + 1 + y + x + 1)
8191 >>> simplify((x + 1)*(y + 1), som=True)
8193 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8194 And(Not(x == y), Not(x == 1), Not(y == 1))
8195 >>> simplify(And(x == 0, y == 1), elim_and=True)
8196 Not(Or(Not(x == 0), Not(y == 1)))
8199 _z3_assert(
is_expr(a),
"Z3 expression expected")
8200 if len(arguments) > 0
or len(keywords) > 0:
8202 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8204 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8207 """Return a string describing all options available for Z3 `simplify` procedure."""
8211 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8215 """Apply substitution m on t, m is a list of pairs of the form (from, to). Every occurrence in t of from is replaced with to.
8219 >>> substitute(x + 1, (x, y + 1))
8221 >>> f = Function('f', IntSort(), IntSort())
8222 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8225 if isinstance(m, tuple):
8227 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8230 _z3_assert(
is_expr(t),
"Z3 expression expected")
8231 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8233 _from = (Ast * num)()
8235 for i
in range(num):
8236 _from[i] = m[i][0].as_ast()
8237 _to[i] = m[i][1].as_ast()
8238 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8241 """Substitute the free variables in t with the expression in m.
8243 >>> v0 = Var(0, IntSort())
8244 >>> v1 = Var(1, IntSort())
8246 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8247 >>> # replace v0 with x+1 and v1 with x
8248 >>> substitute_vars(f(v0, v1), x + 1, x)
8252 _z3_assert(
is_expr(t),
"Z3 expression expected")
8253 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8256 for i
in range(num):
8257 _to[i] = m[i].as_ast()
8261 """Create the sum of the Z3 expressions.
8263 >>> a, b, c = Ints('a b c')
8268 >>> A = IntVector('a', 5)
8270 a__0 + a__1 + a__2 + a__3 + a__4
8272 args = _get_args(args)
8275 ctx = _ctx_from_ast_arg_list(args)
8277 return _reduce(
lambda a, b: a + b, args, 0)
8278 args = _coerce_expr_list(args, ctx)
8280 return _reduce(
lambda a, b: a + b, args, 0)
8282 _args, sz = _to_ast_array(args)
8287 """Create the product of the Z3 expressions.
8289 >>> a, b, c = Ints('a b c')
8290 >>> Product(a, b, c)
8292 >>> Product([a, b, c])
8294 >>> A = IntVector('a', 5)
8296 a__0*a__1*a__2*a__3*a__4
8298 args = _get_args(args)
8301 ctx = _ctx_from_ast_arg_list(args)
8303 return _reduce(
lambda a, b: a * b, args, 1)
8304 args = _coerce_expr_list(args, ctx)
8306 return _reduce(
lambda a, b: a * b, args, 1)
8308 _args, sz = _to_ast_array(args)
8312 """Create an at-most Pseudo-Boolean k constraint.
8314 >>> a, b, c = Bools('a b c')
8315 >>> f = AtMost(a, b, c, 2)
8317 args = _get_args(args)
8319 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8320 ctx = _ctx_from_ast_arg_list(args)
8322 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8323 args1 = _coerce_expr_list(args[:-1], ctx)
8325 _args, sz = _to_ast_array(args1)
8329 """Create an at-most Pseudo-Boolean k constraint.
8331 >>> a, b, c = Bools('a b c')
8332 >>> f = AtLeast(a, b, c, 2)
8334 args = _get_args(args)
8336 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8337 ctx = _ctx_from_ast_arg_list(args)
8339 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8340 args1 = _coerce_expr_list(args[:-1], ctx)
8342 _args, sz = _to_ast_array(args1)
8345 def _reorder_pb_arg(arg):
8347 if not _is_int(b)
and _is_int(a):
8351 def _pb_args_coeffs(args, default_ctx = None):
8352 args = _get_args_ast_list(args)
8354 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8355 args = [_reorder_pb_arg(arg)
for arg
in args]
8356 args, coeffs = zip(*args)
8358 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8359 ctx = _ctx_from_ast_arg_list(args)
8361 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8362 args = _coerce_expr_list(args, ctx)
8363 _args, sz = _to_ast_array(args)
8364 _coeffs = (ctypes.c_int * len(coeffs))()
8365 for i
in range(len(coeffs)):
8366 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8367 _coeffs[i] = coeffs[i]
8368 return ctx, sz, _args, _coeffs
8371 """Create a Pseudo-Boolean inequality k constraint.
8373 >>> a, b, c = Bools('a b c')
8374 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8376 _z3_check_cint_overflow(k,
"k")
8377 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8381 """Create a Pseudo-Boolean inequality k constraint.
8383 >>> a, b, c = Bools('a b c')
8384 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8386 _z3_check_cint_overflow(k,
"k")
8387 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8391 """Create a Pseudo-Boolean inequality k constraint.
8393 >>> a, b, c = Bools('a b c')
8394 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8396 _z3_check_cint_overflow(k,
"k")
8397 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8402 """Solve the constraints `*args`.
8404 This is a simple function for creating demonstrations. It creates a solver,
8405 configure it using the options in `keywords`, adds the constraints
8406 in `args`, and invokes check.
8409 >>> solve(a > 0, a < 2)
8415 if keywords.get(
'show',
False):
8419 print(
"no solution")
8421 print(
"failed to solve")
8430 """Solve the constraints `*args` using solver `s`.
8432 This is a simple function for creating demonstrations. It is similar to `solve`,
8433 but it uses the given solver `s`.
8434 It configures solver `s` using the options in `keywords`, adds the constraints
8435 in `args`, and invokes check.
8438 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8441 if keywords.get(
'show',
False):
8446 print(
"no solution")
8448 print(
"failed to solve")
8454 if keywords.get(
'show',
False):
8459 """Try to prove the given claim.
8461 This is a simple function for creating demonstrations. It tries to prove
8462 `claim` by showing the negation is unsatisfiable.
8464 >>> p, q = Bools('p q')
8465 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8469 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8473 if keywords.get(
'show',
False):
8479 print(
"failed to prove")
8482 print(
"counterexample")
8485 def _solve_html(*args, **keywords):
8486 """Version of function `solve` used in RiSE4Fun."""
8490 if keywords.get(
'show',
False):
8491 print(
"<b>Problem:</b>")
8495 print(
"<b>no solution</b>")
8497 print(
"<b>failed to solve</b>")
8503 if keywords.get(
'show',
False):
8504 print(
"<b>Solution:</b>")
8507 def _solve_using_html(s, *args, **keywords):
8508 """Version of function `solve_using` used in RiSE4Fun."""
8510 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8513 if keywords.get(
'show',
False):
8514 print(
"<b>Problem:</b>")
8518 print(
"<b>no solution</b>")
8520 print(
"<b>failed to solve</b>")
8526 if keywords.get(
'show',
False):
8527 print(
"<b>Solution:</b>")
8530 def _prove_html(claim, **keywords):
8531 """Version of function `prove` used in RiSE4Fun."""
8533 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8537 if keywords.get(
'show',
False):
8541 print(
"<b>proved</b>")
8543 print(
"<b>failed to prove</b>")
8546 print(
"<b>counterexample</b>")
8549 def _dict2sarray(sorts, ctx):
8551 _names = (Symbol * sz)()
8552 _sorts = (Sort * sz) ()
8557 _z3_assert(isinstance(k, str),
"String expected")
8558 _z3_assert(
is_sort(v),
"Z3 sort expected")
8562 return sz, _names, _sorts
8564 def _dict2darray(decls, ctx):
8566 _names = (Symbol * sz)()
8567 _decls = (FuncDecl * sz) ()
8572 _z3_assert(isinstance(k, str),
"String expected")
8576 _decls[i] = v.decl().ast
8580 return sz, _names, _decls
8584 """Parse a string in SMT 2.0 format using the given sorts and decls.
8586 The arguments sorts and decls are Python dictionaries used to initialize
8587 the symbol table used for the SMT 2.0 parser.
8589 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8591 >>> x, y = Ints('x y')
8592 >>> f = Function('f', IntSort(), IntSort())
8593 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8595 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
8599 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8600 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8604 """Parse a file in SMT 2.0 format using the given sorts and decls.
8606 This function is similar to parse_smt2_string().
8609 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8610 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8622 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
8623 _dflt_fpsort_ebits = 11
8624 _dflt_fpsort_sbits = 53
8627 """Retrieves the global default rounding mode."""
8628 global _dflt_rounding_mode
8629 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8631 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8633 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8635 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8637 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8641 global _dflt_rounding_mode
8643 _dflt_rounding_mode = rm.decl().kind()
8645 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO
or
8646 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE
or
8647 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE
or
8648 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
or
8649 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8650 "illegal rounding mode")
8651 _dflt_rounding_mode = rm
8654 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8657 global _dflt_fpsort_ebits
8658 global _dflt_fpsort_sbits
8659 _dflt_fpsort_ebits = ebits
8660 _dflt_fpsort_sbits = sbits
8662 def _dflt_rm(ctx=None):
8665 def _dflt_fps(ctx=None):
8668 def _coerce_fp_expr_list(alist, ctx):
8669 first_fp_sort =
None
8672 if first_fp_sort
is None:
8673 first_fp_sort = a.sort()
8674 elif first_fp_sort == a.sort():
8679 first_fp_sort =
None
8683 for i
in range(len(alist)):
8685 if (isinstance(a, str)
and a.contains(
'2**(')
and a.endswith(
')'))
or _is_int(a)
or isinstance(a, float)
or isinstance(a, bool):
8686 r.append(
FPVal(a,
None, first_fp_sort, ctx))
8689 return _coerce_expr_list(r, ctx)
8695 """Floating-point sort."""
8698 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
8699 >>> b = FPSort(8, 24)
8706 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
8707 >>> b = FPSort(8, 24)
8714 """Try to cast `val` as a floating-point expression.
8715 >>> b = FPSort(8, 24)
8718 >>> b.cast(1.0).sexpr()
8719 '(fp #b0 #x7f #b00000000000000000000000)'
8723 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
8726 return FPVal(val,
None, self, self.
ctx)
8730 """Floating-point 16-bit (half) sort."""
8735 """Floating-point 16-bit (half) sort."""
8740 """Floating-point 32-bit (single) sort."""
8745 """Floating-point 32-bit (single) sort."""
8750 """Floating-point 64-bit (double) sort."""
8755 """Floating-point 64-bit (double) sort."""
8760 """Floating-point 128-bit (quadruple) sort."""
8765 """Floating-point 128-bit (quadruple) sort."""
8770 """"Floating-point rounding mode sort."""
8774 """Return True if `s` is a Z3 floating-point sort.
8776 >>> is_fp_sort(FPSort(8, 24))
8778 >>> is_fp_sort(IntSort())
8781 return isinstance(s, FPSortRef)
8784 """Return True if `s` is a Z3 floating-point rounding mode sort.
8786 >>> is_fprm_sort(FPSort(8, 24))
8788 >>> is_fprm_sort(RNE().sort())
8791 return isinstance(s, FPRMSortRef)
8796 """Floating-point expressions."""
8799 """Return the sort of the floating-point expression `self`.
8801 >>> x = FP('1.0', FPSort(8, 24))
8804 >>> x.sort() == FPSort(8, 24)
8810 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8811 >>> b = FPSort(8, 24)
8818 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8819 >>> b = FPSort(8, 24)
8826 """Return a Z3 floating point expression as a Python string."""
8830 return fpLEQ(self, other, self.
ctx)
8833 return fpLT(self, other, self.
ctx)
8836 return fpGEQ(self, other, self.
ctx)
8839 return fpGT(self, other, self.
ctx)
8842 """Create the Z3 expression `self + other`.
8844 >>> x = FP('x', FPSort(8, 24))
8845 >>> y = FP('y', FPSort(8, 24))
8851 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8852 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8855 """Create the Z3 expression `other + self`.
8857 >>> x = FP('x', FPSort(8, 24))
8861 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8862 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8865 """Create the Z3 expression `self - other`.
8867 >>> x = FP('x', FPSort(8, 24))
8868 >>> y = FP('y', FPSort(8, 24))
8874 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8875 return fpSub(_dflt_rm(), a, b, self.
ctx)
8878 """Create the Z3 expression `other - self`.
8880 >>> x = FP('x', FPSort(8, 24))
8884 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8885 return fpSub(_dflt_rm(), a, b, self.
ctx)
8888 """Create the Z3 expression `self * other`.
8890 >>> x = FP('x', FPSort(8, 24))
8891 >>> y = FP('y', FPSort(8, 24))
8899 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8900 return fpMul(_dflt_rm(), a, b, self.
ctx)
8903 """Create the Z3 expression `other * self`.
8905 >>> x = FP('x', FPSort(8, 24))
8906 >>> y = FP('y', FPSort(8, 24))
8912 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8913 return fpMul(_dflt_rm(), a, b, self.
ctx)
8916 """Create the Z3 expression `+self`."""
8920 """Create the Z3 expression `-self`.
8922 >>> x = FP('x', Float32())
8929 """Create the Z3 expression `self / other`.
8931 >>> x = FP('x', FPSort(8, 24))
8932 >>> y = FP('y', FPSort(8, 24))
8940 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8941 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8944 """Create the Z3 expression `other / self`.
8946 >>> x = FP('x', FPSort(8, 24))
8947 >>> y = FP('y', FPSort(8, 24))
8953 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8954 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8957 """Create the Z3 expression division `self / other`."""
8961 """Create the Z3 expression division `other / self`."""
8965 """Create the Z3 expression mod `self % other`."""
8966 return fpRem(self, other)
8969 """Create the Z3 expression mod `other % self`."""
8970 return fpRem(other, self)
8973 """Floating-point rounding mode expressions"""
8976 """Return a Z3 floating point expression as a Python string."""
9021 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9030 return isinstance(a, FPRMRef)
9033 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9034 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9039 """The sign of the numeral.
9041 >>> x = FPVal(+1.0, FPSort(8, 24))
9044 >>> x = FPVal(-1.0, FPSort(8, 24))
9049 l = (ctypes.c_int)()
9051 raise Z3Exception(
"error retrieving the sign of a numeral.")
9054 """The sign of a floating-point numeral as a bit-vector expression.
9056 Remark: NaN's are invalid arguments.
9061 """The significand of the numeral.
9063 >>> x = FPVal(2.5, FPSort(8, 24))
9070 """The significand of the numeral as a long.
9072 >>> x = FPVal(2.5, FPSort(8, 24))
9073 >>> x.significand_as_long()
9077 ptr = (ctypes.c_ulonglong * 1)()
9079 raise Z3Exception(
"error retrieving the significand of a numeral.")
9082 """The significand of the numeral as a bit-vector expression.
9084 Remark: NaN are invalid arguments.
9089 """The exponent of the numeral.
9091 >>> x = FPVal(2.5, FPSort(8, 24))
9098 """The exponent of the numeral as a long.
9100 >>> x = FPVal(2.5, FPSort(8, 24))
9101 >>> x.exponent_as_long()
9105 ptr = (ctypes.c_longlong * 1)()
9107 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9110 """The exponent of the numeral as a bit-vector expression.
9112 Remark: NaNs are invalid arguments.
9117 """Indicates whether the numeral is a NaN."""
9121 """Indicates whether the numeral is +oo or -oo."""
9125 """Indicates whether the numeral is +zero or -zero."""
9129 """Indicates whether the numeral is normal."""
9133 """Indicates whether the numeral is subnormal."""
9137 """Indicates whether the numeral is positive."""
9141 """Indicates whether the numeral is negative."""
9146 The string representation of the numeral.
9148 >>> x = FPVal(20, FPSort(8, 24))
9154 return (
"FPVal(%s, %s)" % (s, self.
sort()))
9157 """Return `True` if `a` is a Z3 floating-point expression.
9159 >>> b = FP('b', FPSort(8, 24))
9167 return isinstance(a, FPRef)
9170 """Return `True` if `a` is a Z3 floating-point numeral value.
9172 >>> b = FP('b', FPSort(8, 24))
9175 >>> b = FPVal(1.0, FPSort(8, 24))
9181 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9184 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9186 >>> Single = FPSort(8, 24)
9187 >>> Double = FPSort(11, 53)
9190 >>> x = Const('x', Single)
9191 >>> eq(x, FP('x', FPSort(8, 24)))
9197 def _to_float_str(val, exp=0):
9198 if isinstance(val, float):
9202 sone = math.copysign(1.0, val)
9207 elif val == float(
"+inf"):
9209 elif val == float(
"-inf"):
9212 v = val.as_integer_ratio()
9215 rvs = str(num) +
'/' + str(den)
9216 res = rvs +
'p' + _to_int_str(exp)
9217 elif isinstance(val, bool):
9224 elif isinstance(val, str):
9225 inx = val.find(
'*(2**')
9228 elif val[-1] ==
')':
9230 exp = str(int(val[inx+5:-1]) + int(exp))
9232 _z3_assert(
False,
"String does not have floating-point numeral form.")
9234 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9238 return res +
'p' + exp
9242 """Create a Z3 floating-point NaN term.
9244 >>> s = FPSort(8, 24)
9245 >>> set_fpa_pretty(True)
9248 >>> pb = get_fpa_pretty()
9249 >>> set_fpa_pretty(False)
9251 fpNaN(FPSort(8, 24))
9252 >>> set_fpa_pretty(pb)
9254 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9258 """Create a Z3 floating-point +oo term.
9260 >>> s = FPSort(8, 24)
9261 >>> pb = get_fpa_pretty()
9262 >>> set_fpa_pretty(True)
9263 >>> fpPlusInfinity(s)
9265 >>> set_fpa_pretty(False)
9266 >>> fpPlusInfinity(s)
9267 fpPlusInfinity(FPSort(8, 24))
9268 >>> set_fpa_pretty(pb)
9270 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9274 """Create a Z3 floating-point -oo term."""
9275 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9279 """Create a Z3 floating-point +oo or -oo term."""
9280 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9281 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9285 """Create a Z3 floating-point +0.0 term."""
9286 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9290 """Create a Z3 floating-point -0.0 term."""
9291 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9295 """Create a Z3 floating-point +0.0 or -0.0 term."""
9296 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9297 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9300 def FPVal(sig, exp=None, fps=None, ctx=None):
9301 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9303 >>> v = FPVal(20.0, FPSort(8, 24))
9306 >>> print("0x%.8x" % v.exponent_as_long(False))
9308 >>> v = FPVal(2.25, FPSort(8, 24))
9311 >>> v = FPVal(-2.25, FPSort(8, 24))
9314 >>> FPVal(-0.0, FPSort(8, 24))
9316 >>> FPVal(0.0, FPSort(8, 24))
9318 >>> FPVal(+0.0, FPSort(8, 24))
9326 fps = _dflt_fps(ctx)
9330 val = _to_float_str(sig)
9331 if val ==
"NaN" or val ==
"nan":
9335 elif val ==
"0.0" or val ==
"+0.0":
9337 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9339 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9344 def FP(name, fpsort, ctx=None):
9345 """Return a floating-point constant named `name`.
9346 `fpsort` is the floating-point sort.
9347 If `ctx=None`, then the global context is used.
9349 >>> x = FP('x', FPSort(8, 24))
9356 >>> word = FPSort(8, 24)
9357 >>> x2 = FP('x', word)
9361 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9367 def FPs(names, fpsort, ctx=None):
9368 """Return an array of floating-point constants.
9370 >>> x, y, z = FPs('x y z', FPSort(8, 24))
9377 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9378 fpMul(RNE(), fpAdd(RNE(), x, y), z)
9381 if isinstance(names, str):
9382 names = names.split(
" ")
9383 return [
FP(name, fpsort, ctx)
for name
in names]
9386 """Create a Z3 floating-point absolute value expression.
9388 >>> s = FPSort(8, 24)
9390 >>> x = FPVal(1.0, s)
9393 >>> y = FPVal(-20.0, s)
9398 >>> fpAbs(-1.25*(2**4))
9404 [a] = _coerce_fp_expr_list([a], ctx)
9408 """Create a Z3 floating-point addition expression.
9410 >>> s = FPSort(8, 24)
9419 [a] = _coerce_fp_expr_list([a], ctx)
9422 def _mk_fp_unary(f, rm, a, ctx):
9424 [a] = _coerce_fp_expr_list([a], ctx)
9426 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9427 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9428 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9430 def _mk_fp_unary_pred(f, a, ctx):
9432 [a] = _coerce_fp_expr_list([a], ctx)
9434 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9435 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9437 def _mk_fp_bin(f, rm, a, b, ctx):
9439 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9441 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9442 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9443 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
9445 def _mk_fp_bin_norm(f, a, b, ctx):
9447 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9449 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9450 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9452 def _mk_fp_bin_pred(f, a, b, ctx):
9454 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9456 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9457 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9459 def _mk_fp_tern(f, rm, a, b, c, ctx):
9461 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
9463 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9464 _z3_assert(
is_fp(a)
or is_fp(b)
or is_fp(c),
"At least one of the arguments must be a Z3 floating-point expression")
9465 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
9468 """Create a Z3 floating-point addition expression.
9470 >>> s = FPSort(8, 24)
9476 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9478 >>> fpAdd(rm, x, y).sort()
9481 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9484 """Create a Z3 floating-point subtraction expression.
9486 >>> s = FPSort(8, 24)
9492 >>> fpSub(rm, x, y).sort()
9495 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9498 """Create a Z3 floating-point multiplication expression.
9500 >>> s = FPSort(8, 24)
9506 >>> fpMul(rm, x, y).sort()
9509 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9512 """Create a Z3 floating-point division expression.
9514 >>> s = FPSort(8, 24)
9520 >>> fpDiv(rm, x, y).sort()
9523 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9526 """Create a Z3 floating-point remainder expression.
9528 >>> s = FPSort(8, 24)
9533 >>> fpRem(x, y).sort()
9536 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9539 """Create a Z3 floating-point minimum expression.
9541 >>> s = FPSort(8, 24)
9547 >>> fpMin(x, y).sort()
9550 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9553 """Create a Z3 floating-point maximum expression.
9555 >>> s = FPSort(8, 24)
9561 >>> fpMax(x, y).sort()
9564 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9567 """Create a Z3 floating-point fused multiply-add expression.
9569 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9572 """Create a Z3 floating-point square root expression.
9574 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9577 """Create a Z3 floating-point roundToIntegral expression.
9579 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9582 """Create a Z3 floating-point isNaN expression.
9584 >>> s = FPSort(8, 24)
9590 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
9593 """Create a Z3 floating-point isInfinite expression.
9595 >>> s = FPSort(8, 24)
9600 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
9603 """Create a Z3 floating-point isZero expression.
9605 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
9608 """Create a Z3 floating-point isNormal expression.
9610 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
9613 """Create a Z3 floating-point isSubnormal expression.
9615 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
9618 """Create a Z3 floating-point isNegative expression.
9620 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
9623 """Create a Z3 floating-point isPositive expression.
9625 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
9627 def _check_fp_args(a, b):
9629 _z3_assert(
is_fp(a)
or is_fp(b),
"At least one of the arguments must be a Z3 floating-point expression")
9632 """Create the Z3 floating-point expression `other < self`.
9634 >>> x, y = FPs('x y', FPSort(8, 24))
9640 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9643 """Create the Z3 floating-point expression `other <= self`.
9645 >>> x, y = FPs('x y', FPSort(8, 24))
9648 >>> (x <= y).sexpr()
9651 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9654 """Create the Z3 floating-point expression `other > self`.
9656 >>> x, y = FPs('x y', FPSort(8, 24))
9662 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9665 """Create the Z3 floating-point expression `other >= self`.
9667 >>> x, y = FPs('x y', FPSort(8, 24))
9670 >>> (x >= y).sexpr()
9673 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9676 """Create the Z3 floating-point expression `fpEQ(other, self)`.
9678 >>> x, y = FPs('x y', FPSort(8, 24))
9681 >>> fpEQ(x, y).sexpr()
9684 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9687 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9689 >>> x, y = FPs('x y', FPSort(8, 24))
9692 >>> (x != y).sexpr()
9698 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9700 >>> s = FPSort(8, 24)
9701 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9703 fpFP(1, 127, 4194304)
9704 >>> xv = FPVal(-1.5, s)
9708 >>> slvr.add(fpEQ(x, xv))
9711 >>> xv = FPVal(+1.5, s)
9715 >>> slvr.add(fpEQ(x, xv))
9720 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
9722 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
9726 """Create a Z3 floating-point conversion expression from other term sorts
9729 From a bit-vector term in IEEE 754-2008 format:
9730 >>> x = FPVal(1.0, Float32())
9731 >>> x_bv = fpToIEEEBV(x)
9732 >>> simplify(fpToFP(x_bv, Float32()))
9735 From a floating-point term with different precision:
9736 >>> x = FPVal(1.0, Float32())
9737 >>> x_db = fpToFP(RNE(), x, Float64())
9742 >>> x_r = RealVal(1.5)
9743 >>> simplify(fpToFP(RNE(), x_r, Float32()))
9746 From a signed bit-vector term:
9747 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9748 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9761 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
9764 """Create a Z3 floating-point conversion expression that represents the
9765 conversion from a bit-vector term to a floating-point term.
9767 >>> x_bv = BitVecVal(0x3F800000, 32)
9768 >>> x_fp = fpBVToFP(x_bv, Float32())
9774 _z3_assert(
is_bv(v),
"First argument must be a Z3 floating-point rounding mode expression.")
9775 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
9780 """Create a Z3 floating-point conversion expression that represents the
9781 conversion from a floating-point term to a floating-point term of different precision.
9783 >>> x_sgl = FPVal(1.0, Float32())
9784 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9792 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9793 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
9794 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9799 """Create a Z3 floating-point conversion expression that represents the
9800 conversion from a real term to a floating-point term.
9802 >>> x_r = RealVal(1.5)
9803 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9809 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9810 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
9811 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9816 """Create a Z3 floating-point conversion expression that represents the
9817 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9819 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9820 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9822 fpToFP(RNE(), 4294967291)
9826 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9827 _z3_assert(
is_bv(v),
"Second argument must be a Z3 expression or real sort.")
9828 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9833 """Create a Z3 floating-point conversion expression that represents the
9834 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9836 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9837 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9839 fpToFPUnsigned(RNE(), 4294967291)
9843 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9844 _z3_assert(
is_bv(v),
"Second argument must be a Z3 expression or real sort.")
9845 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9850 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9852 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9853 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
9854 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
9859 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9861 >>> x = FP('x', FPSort(8, 24))
9862 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9873 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9874 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9875 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9880 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9882 >>> x = FP('x', FPSort(8, 24))
9883 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9894 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9895 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9896 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9901 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9903 >>> x = FP('x', FPSort(8, 24))
9907 >>> print(is_real(y))
9911 >>> print(is_real(x))
9915 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9920 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9922 The size of the resulting bit-vector is automatically determined.
9924 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9925 knows only one NaN and it will always produce the same bit-vector representation of
9928 >>> x = FP('x', FPSort(8, 24))
9929 >>> y = fpToIEEEBV(x)
9940 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9953 """Sequence sort."""
9956 """Determine if sort is a string
9957 >>> s = StringSort()
9960 >>> s = SeqSort(IntSort())
9971 """Create a string sort
9972 >>> s = StringSort()
9981 """Create a sequence sort over elements provided in the argument
9982 >>> s = SeqSort(IntSort())
9983 >>> s == Unit(IntVal(1)).sort()
9989 """Sequence expression."""
9995 return Concat(self, other)
9998 return Concat(other, self)
10017 """Return a string representation of sequence expression."""
10035 def _coerce_seq(s, ctx=None):
10036 if isinstance(s, str):
10037 ctx = _get_ctx(ctx)
10040 raise Z3Exception(
"Non-expression passed as a sequence")
10042 raise Z3Exception(
"Non-sequence passed as a sequence")
10045 def _get_ctx2(a, b, ctx=None):
10055 """Return `True` if `a` is a Z3 sequence expression.
10056 >>> print (is_seq(Unit(IntVal(0))))
10058 >>> print (is_seq(StringVal("abc")))
10061 return isinstance(a, SeqRef)
10064 """Return `True` if `a` is a Z3 string expression.
10065 >>> print (is_string(StringVal("ab")))
10068 return isinstance(a, SeqRef)
and a.is_string()
10071 """return 'True' if 'a' is a Z3 string constant expression.
10072 >>> print (is_string_value(StringVal("a")))
10074 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10077 return isinstance(a, SeqRef)
and a.is_string_value()
10081 """create a string expression"""
10082 ctx = _get_ctx(ctx)
10086 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10088 >>> x = String('x')
10090 ctx = _get_ctx(ctx)
10094 """Return string constants"""
10095 ctx = _get_ctx(ctx)
10096 if isinstance(names, str):
10097 names = names.split(
" ")
10098 return [
String(name, ctx)
for name
in names]
10101 """Extract substring or subsequence starting at offset"""
10102 return Extract(s, offset, length)
10105 """Extract substring or subsequence starting at offset"""
10106 return Extract(s, offset, length)
10108 def Strings(names, ctx=None):
10109 """Return a tuple of String constants. """
10110 ctx = _get_ctx(ctx)
10111 if isinstance(names, str):
10112 names = names.split(
" ")
10113 return [
String(name, ctx)
for name
in names]
10116 """Create the empty sequence of the given sort
10117 >>> e = Empty(StringSort())
10118 >>> e2 = StringVal("")
10119 >>> print(e.eq(e2))
10121 >>> e3 = Empty(SeqSort(IntSort()))
10124 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10126 Empty(ReSort(Seq(Int)))
10128 if isinstance(s, SeqSortRef):
10130 if isinstance(s, ReSortRef):
10132 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10135 """Create the regular expression that accepts the universal language
10136 >>> e = Full(ReSort(SeqSort(IntSort())))
10138 Full(ReSort(Seq(Int)))
10139 >>> e1 = Full(ReSort(StringSort()))
10141 Full(ReSort(String))
10143 if isinstance(s, ReSortRef):
10145 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10149 """Create a singleton sequence"""
10153 """Check if 'a' is a prefix of 'b'
10154 >>> s1 = PrefixOf("ab", "abc")
10157 >>> s2 = PrefixOf("bc", "abc")
10161 ctx = _get_ctx2(a, b)
10162 a = _coerce_seq(a, ctx)
10163 b = _coerce_seq(b, ctx)
10167 """Check if 'a' is a suffix of 'b'
10168 >>> s1 = SuffixOf("ab", "abc")
10171 >>> s2 = SuffixOf("bc", "abc")
10175 ctx = _get_ctx2(a, b)
10176 a = _coerce_seq(a, ctx)
10177 b = _coerce_seq(b, ctx)
10181 """Check if 'a' contains 'b'
10182 >>> s1 = Contains("abc", "ab")
10185 >>> s2 = Contains("abc", "bc")
10188 >>> x, y, z = Strings('x y z')
10189 >>> s3 = Contains(Concat(x,y,z), y)
10193 ctx = _get_ctx2(a, b)
10194 a = _coerce_seq(a, ctx)
10195 b = _coerce_seq(b, ctx)
10200 """Replace the first occurrence of 'src' by 'dst' in 's'
10201 >>> r = Replace("aaa", "a", "b")
10205 ctx = _get_ctx2(dst, s)
10206 if ctx
is None and is_expr(src):
10208 src = _coerce_seq(src, ctx)
10209 dst = _coerce_seq(dst, ctx)
10210 s = _coerce_seq(s, ctx)
10217 """Retrieve the index of substring within a string starting at a specified offset.
10218 >>> simplify(IndexOf("abcabc", "bc", 0))
10220 >>> simplify(IndexOf("abcabc", "bc", 2))
10226 ctx = _get_ctx2(s, substr, ctx)
10227 s = _coerce_seq(s, ctx)
10228 substr = _coerce_seq(substr, ctx)
10229 if _is_int(offset):
10230 offset =
IntVal(offset, ctx)
10234 """Retrieve the last index of substring within a string"""
10236 ctx = _get_ctx2(s, substr, ctx)
10237 s = _coerce_seq(s, ctx)
10238 substr = _coerce_seq(substr, ctx)
10243 """Obtain the length of a sequence 's'
10244 >>> l = Length(StringVal("abc"))
10252 """Convert string expression to integer
10253 >>> a = StrToInt("1")
10254 >>> simplify(1 == a)
10256 >>> b = StrToInt("2")
10257 >>> simplify(1 == b)
10259 >>> c = StrToInt(IntToStr(2))
10260 >>> simplify(1 == c)
10268 """Convert integer expression to string"""
10275 """The regular expression that accepts sequence 's'
10277 >>> s2 = Re(StringVal("ab"))
10278 >>> s3 = Re(Unit(BoolVal(True)))
10280 s = _coerce_seq(s, ctx)
10289 """Regular expression sort."""
10297 if s
is None or isinstance(s, Context):
10300 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10304 """Regular expressions."""
10307 return Union(self, other)
10310 return isinstance(s, ReRef)
10314 """Create regular expression membership test
10315 >>> re = Union(Re("a"),Re("b"))
10316 >>> print (simplify(InRe("a", re)))
10318 >>> print (simplify(InRe("b", re)))
10320 >>> print (simplify(InRe("c", re)))
10323 s = _coerce_seq(s, re.ctx)
10327 """Create union of regular expressions.
10328 >>> re = Union(Re("a"), Re("b"), Re("c"))
10329 >>> print (simplify(InRe("d", re)))
10332 args = _get_args(args)
10335 _z3_assert(sz > 0,
"At least one argument expected.")
10336 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10341 for i
in range(sz):
10342 v[i] = args[i].as_ast()
10346 """Create intersection of regular expressions.
10347 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
10349 args = _get_args(args)
10352 _z3_assert(sz > 0,
"At least one argument expected.")
10353 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10358 for i
in range(sz):
10359 v[i] = args[i].as_ast()
10363 """Create the regular expression accepting one or more repetitions of argument.
10364 >>> re = Plus(Re("a"))
10365 >>> print(simplify(InRe("aa", re)))
10367 >>> print(simplify(InRe("ab", re)))
10369 >>> print(simplify(InRe("", re)))
10375 """Create the regular expression that optionally accepts the argument.
10376 >>> re = Option(Re("a"))
10377 >>> print(simplify(InRe("a", re)))
10379 >>> print(simplify(InRe("", re)))
10381 >>> print(simplify(InRe("aa", re)))
10387 """Create the complement regular expression."""
10391 """Create the regular expression accepting zero or more repetitions of argument.
10392 >>> re = Star(Re("a"))
10393 >>> print(simplify(InRe("aa", re)))
10395 >>> print(simplify(InRe("ab", re)))
10397 >>> print(simplify(InRe("", re)))
10403 """Create the regular expression accepting between a lower and upper bound repetitions
10404 >>> re = Loop(Re("a"), 1, 3)
10405 >>> print(simplify(InRe("aa", re)))
10407 >>> print(simplify(InRe("aaaa", re)))
10409 >>> print(simplify(InRe("", re)))
10415 """Create the range regular expression over two sequences of length 1
10416 >>> range = Range("a","z")
10417 >>> print(simplify(InRe("b", range)))
10419 >>> print(simplify(InRe("bb", range)))
10422 lo = _coerce_seq(lo, ctx)
10423 hi = _coerce_seq(hi, ctx)
10441 """Given a binary relation R, such that the two arguments have the same sort
10442 create the transitive closure relation R+.
10443 The transitive closure R+ is a new relation.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
def Reals(names, ctx=None)
Z3_bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...
def __rand__(self, other)
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
def fpInfinity(s, negative)
bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a +oo or -oo.
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p)
Convert a Z3_pattern into Z3_ast. This is just type casting.
Z3_ast_vector Z3_API Z3_optimize_get_lower_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector ...
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
def fpRoundToIntegral(rm, a, ctx=None)
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
def __rsub__(self, other)
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
def __init__(self, stats, ctx)
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
void Z3_API Z3_solver_import_model_converter(Z3_context ctx, Z3_solver src, Z3_solver dst)
Ad-hoc method for importing model conversion from solver.
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
def __init__(self, descr, ctx=None)
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1....
def RoundTowardPositive(ctx=None)
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
def is_string_value(self)
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
def FreshReal(prefix='b', ctx=None)
def fact(self, head, name=None)
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, bool biased)
Retrieves the exponent of a floating-point literal as a bit-vector expression.
void Z3_API Z3_params_set_uint(Z3_context c, Z3_params p, Z3_symbol k, unsigned v)
Add a unsigned parameter k with value v to the parameter set p.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
void Z3_API Z3_params_set_double(Z3_context c, Z3_params p, Z3_symbol k, double v)
Add a double parameter k with value v to the parameter set p.
def exponent(self, biased=True)
def parse_string(self, s)
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
def __deepcopy__(self, memo={})
def __rxor__(self, other)
void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz, unsigned levels[])
retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat c...
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t *n, bool biased)
Return the exponent value of a floating-point numeral as a signed 64-bit integer.
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
def TupleSort(name, sorts, ctx=None)
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
def evaluate(self, t, model_completion=False)
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
def fpBVToFP(v, sort, ctx=None)
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
def __truediv__(self, other)
void Z3_API Z3_dec_ref(Z3_context c, Z3_ast a)
Decrement the reference counter of the given AST. The context c should have been created using Z3_mk_...
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i)
Return the name of the parameter at given index i.
def FPs(names, fpsort, ctx=None)
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.
def __contains__(self, item)
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.
def DisjointSum(name, sorts, ctx=None)
def Strings(names, ctx=None)
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
def __deepcopy__(self, memo={})
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
Z3_string Z3_API Z3_optimize_get_reason_unknown(Z3_context c, Z3_optimize d)
Retrieve a string that describes the last status returned by Z3_optimize_check.
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
def __init__(self, ctx=None, params=None)
def cube(self, vars=None)
def __rlshift__(self, other)
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
def FPVal(sig, exp=None, fps=None, ctx=None)
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_translate(Z3_context source, Z3_ast a, Z3_context target)
Translate/Copy the AST a from context source to context target. AST a must have been created using co...
def RealVarVector(n, ctx=None)
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
def fpToUBV(rm, x, s, ctx=None)
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms)
Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms mil...
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s)
Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if th...
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p)
Convert a parameter description set into a string. This function is mainly used for printing the cont...
def set(self, *args, **keys)
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.
expr range(expr const &lo, expr const &hi)
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
def BVSubNoOverflow(a, b)
unsigned Z3_API Z3_get_app_num_args(Z3_context c, Z3_app a)
Return the number of argument of an application. If t is an constant, then the number of arguments is...
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural. You can use Z3_get_ast_id intercha...
def __init__(self, *args, **kws)
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
def declare_core(self, name, rec_name, *args)
def RoundTowardNegative(ctx=None)
def __init__(self, result, ctx)
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
unsigned Z3_API Z3_apply_result_get_num_subgoals(Z3_context c, Z3_apply_result r)
Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
def set_param(*args, **kws)
def __deepcopy__(self, memo={})
def RatVal(a, b, ctx=None)
def IntVal(val, ctx=None)
def translate(self, target)
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s)
Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_ch...
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.
def fpToFP(a1, a2=None, a3=None, ctx=None)
def eval(self, t, model_completion=False)
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p)
Convert a parameter set into a string. This function is mainly used for printing the contents of a pa...
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
def __init__(self, tactic, ctx=None)
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
def to_string(self, queries)
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
Z3_ast Z3_API Z3_mk_set_has_size(Z3_context c, Z3_ast set, Z3_ast k)
Create predicate that holds if Boolean array set has k elements set to true.
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
def fpUnsignedToFP(rm, v, sort, ctx=None)
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
def register_relation(self, *relations)
Z3_ast Z3_API Z3_func_decl_to_ast(Z3_context c, Z3_func_decl f)
Convert a Z3_func_decl into Z3_ast. This is just type casting.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
def add_rule(self, head, body=None, name=None)
def numerator_as_long(self)
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
def add_cover(self, level, predicate, property)
def BoolVector(prefix, sz, ctx=None)
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
def __init__(self, ast, ctx=None)
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
def SubSeq(s, offset, length)
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
unsigned Z3_API Z3_param_descrs_size(Z3_context c, Z3_param_descrs p)
Return the number of parameters in the given parameter description set.
def SimpleSolver(ctx=None, logFile=None)
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not.
def With(t, *args, **keys)
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
def simplify(a, *arguments, **keywords)
Utils.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
def __deepcopy__(self, memo={})
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_param_descrs Z3_API Z3_optimize_get_param_descrs(Z3_context c, Z3_optimize o)
Return the parameter description set for the given optimize object.
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
def num_no_patterns(self)
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size)
Create a named finite domain sort.
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
def __init__(self, ctx=None)
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
def __call__(self, goal, *arguments, **keywords)
def __rdiv__(self, other)
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
def to_symbol(s, ctx=None)
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
def fpMul(rm, a, b, ctx=None)
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
def fpGEQ(a, b, ctx=None)
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
def translate(self, target)
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
def __init__(self, v=None, ctx=None)
def consequences(self, assumptions, variables)
def fpRem(a, b, ctx=None)
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)
def set(self, *args, **keys)
def FiniteDomainSort(name, sz, ctx=None)
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a string of a numeric constant term.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a)
The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3....
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
def abstract(self, fml, is_forall=True)
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
def z3_error_handler(c, e)
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
def __init__(self, entry, ctx)
def BitVecVal(val, bv, ctx=None)
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode)
Select mode for the format used for pretty-printing AST nodes.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
void Z3_API Z3_param_descrs_dec_ref(Z3_context c, Z3_param_descrs p)
Decrement the reference counter of the given parameter description set.
def __radd__(self, other)
def __setitem__(self, k, v)
def Range(lo, hi, ctx=None)
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
Z3_ast Z3_API Z3_get_algebraic_number_upper(Z3_context c, Z3_ast a, unsigned precision)
Return a upper bound for the given real algebraic number. The interval isolating the number is smalle...
def exponent_as_long(self, biased=True)
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.
def Cond(p, t1, t2, ctx=None)
def __truediv__(self, other)
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const args[])
Create a constant or function application.
def is_finite_domain_sort(s)
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
def fpMax(a, b, ctx=None)
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
def from_file(self, filename)
def RealVal(val, ctx=None)
def translate(self, target)
def solve(*args, **keywords)
def __rdiv__(self, other)
def RoundNearestTiesToEven(ctx=None)
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def __getitem__(self, arg)
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t *n)
Return the significand value of a floating-point numeral as a uint64.
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v)
Add a Boolean parameter k with value v to the parameter set p.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
def fpToFPUnsigned(rm, x, s, ctx=None)
def set_predicate_representation(self, f, *representations)
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
def FloatQuadruple(ctx=None)
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
def __deepcopy__(self, memo={})
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
def If(a, b, c, ctx=None)
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
unsigned Z3_API Z3_fpa_get_sbits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the significand in a FloatingPoint sort.
def denominator_as_long(self)
Z3_ast Z3_API Z3_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t)
Retrieves the sign of a floating-point literal as a bit-vector expression.
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
def set_default_rounding_mode(rm, ctx=None)
def get_documentation(self, n)
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
def __rpow__(self, other)
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k)
Return true if the map m contains the AST key k.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
def lower_values(self, obj)
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
Z3_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
Z3_ast Z3_API Z3_sort_to_ast(Z3_context c, Z3_sort s)
Convert a Z3_sort into Z3_ast. This is just type casting.
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.
def __getitem__(self, idx)
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, bool is_forall, unsigned weight, Z3_symbol quantifier_id, Z3_symbol skolem_id, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], unsigned num_no_patterns, Z3_ast const no_patterns[], Z3_ast body)
Create a universal or existential quantifier using a list of constants that will form the set of boun...
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function interpretation. It represents the value of f in a particular p...
def fpFMA(rm, a, b, c, ctx=None)
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
def __deepcopy__(self, memo={})
def __rmul__(self, other)
def simplify_param_descrs()
def exponent_as_bv(self, biased=True)
Z3_string Z3_API Z3_get_string(Z3_context c, Z3_ast s)
Retrieve the string constant stored in s.
def fpSignedToFP(rm, v, sort, ctx=None)
def get_default_rounding_mode(ctx=None)
def __getitem__(self, idx)
Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s)
Return the parameter description set for the given solver object.
def PbEq(args, k, ctx=None)
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k)
Return the value associated with the key k.
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
def __getitem__(self, key)
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return the last occurrence of substr in s. If s does not contain substr, then the value is -1,...
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
def BVAddNoOverflow(a, b, signed)
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
def __rmod__(self, other)
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
def get_cover_delta(self, level, predicate)
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
def __rtruediv__(self, other)
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
def Ints(names, ctx=None)
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
def Extract(high, low, a)
Z3_sort Z3_API Z3_get_domain(Z3_context c, Z3_func_decl d, unsigned i)
Return the sort of the i-th parameter of the given function declaration.
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
def FreshBool(prefix='b', ctx=None)
def approx(self, precision=10)
def Array(name, dom, rng)
def __rdiv__(self, other)
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
unsigned Z3_API Z3_solver_get_num_scopes(Z3_context c, Z3_solver s)
Return the number of backtracking points.
def assert_exprs(self, *args)
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.
def ParAndThen(t1, t2, ctx=None)
def BVAddNoUnderflow(a, b)
def FloatDouble(ctx=None)
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality....
def Bools(names, ctx=None)
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
def __rmul__(self, other)
def RoundNearestTiesToAway(ctx=None)
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i)
Return sort of the i'th bound variable.
Z3_ast_vector Z3_API Z3_solver_get_trail(Z3_context c, Z3_solver s)
Return the trail modulo model conversion, in order of decision level The decision level can be retrie...
def __deepcopy__(self, memo={})
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p)
Increment the reference counter of the given parameter description set.
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
def recognizer(self, idx)
def substitute_vars(t, *m)
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n,...
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
def Implies(a, b, ctx=None)
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
def constructor(self, idx)
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.
def get_rules_along_trace(self)
def BVSDivNoOverflow(a, b)
def BitVec(name, bv, ctx=None)
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL,...
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
def __deepcopy__(self, memo={})
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
def __rtruediv__(self, other)
def __radd__(self, other)
def BitVecs(names, bv, ctx=None)
Z3_goal Z3_API Z3_goal_translate(Z3_context source, Z3_goal g, Z3_context target)
Copy a goal g from the context source to the context target.
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...
def LastIndexOf(s, substr)
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
def __deepcopy__(self, memo={})
Z3_bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
def fpIsNormal(a, ctx=None)
def __init__(self, fixedpoint=None, ctx=None)
def get_universe(self, s)
def FreshConst(sort, prefix='c')
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
Z3_ast Z3_API Z3_mk_ext_rotate_right(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the right t2 times.
def __deepcopy__(self, memo={})
Z3_sort Z3_API Z3_get_re_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for regex sort.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
def add_soft(self, arg, weight="1", id=None)
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
def __deepcopy__(self, memo={})
def probe_description(name, ctx=None)
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Strings, Sequences and Regular expressions.
def solver(self, logFile=None)
def assert_and_track(self, a, p)
def tactic_description(name, ctx=None)
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
def StringVal(s, ctx=None)
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
def update_rule(self, head, body, name)
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
def fpFP(sgn, exp, sig, ctx=None)
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
Z3_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...
def significand_as_long(self)
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s)
Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the as...
def FPSort(ebits, sbits, ctx=None)
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a NaN.
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
void Z3_API Z3_fixedpoint_set_predicate_representation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f, unsigned num_relations, Z3_symbol const relation_kinds[])
Configure the predicate representation.
def DeclareSort(name, ctx=None)
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
def __rmod__(self, other)
def fpSqrt(rm, a, ctx=None)
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.
def __deepcopy__(self, memo={})
def apply(self, goal, *arguments, **keywords)
def RealVar(idx, ctx=None)
def FP(name, fpsort, ctx=None)
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context....
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
def fpDiv(rm, a, b, ctx=None)
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
def __getitem__(self, arg)
def set_default_fp_sort(ebits, sbits, ctx=None)
def __init__(self, c, ctx)
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.
void Z3_API Z3_params_validate(Z3_context c, Z3_params p, Z3_param_descrs d)
Validate the parameter set p against the parameter description set d.
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
def __init__(self, m, ctx)
def PiecewiseLinearOrder(a, index)
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
def __radd__(self, other)
Z3_params Z3_API Z3_mk_params(Z3_context c)
Create a Z3 (empty) parameter set. Starting at Z3 4.0, parameter sets are used to configure many comp...
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
def get_ground_sat_answer(self)
def RecAddDefinition(f, args, body)
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
def fpToSBV(rm, x, s, ctx=None)
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.
def __contains__(self, key)
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
def assert_and_track(self, a, p)
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
def rule(self, head, body=None, name=None)
Z3_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than or equal to.
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
def __getattr__(self, name)
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
def FreshInt(prefix='x', ctx=None)
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
def solve_using(s, *args, **keywords)
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
def FiniteDomainVal(val, sort, ctx=None)
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
def __init__(self, m=None, ctx=None)
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s)
Return the set of non units in the solver state.
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
Z3_apply_result Z3_API Z3_tactic_apply_ex(Z3_context c, Z3_tactic t, Z3_goal g, Z3_params p)
Apply tactic t to the goal g using the parameter set p.
def num_constructors(self)
def LinearOrder(a, index)
def BitVecSort(sz, ctx=None)
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vars, unsigned backtrack_level)
extract a next cube for a solver. The last cube is the constant true or false. The number of (non-con...
void Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
Z3_ast Z3_API Z3_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.
def translate(self, target)
def __rmul__(self, other)
Z3_string Z3_API Z3_solver_to_dimacs_string(Z3_context c, Z3_solver s)
Convert a solver into a DIMACS formatted string.
def fpAdd(rm, a, b, ctx=None)
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
def is_finite_domain_value(a)
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
def __deepcopy__(self, memo={})
Z3_ast_vector Z3_API Z3_optimize_get_upper_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the tactic with the given name.
def fpSub(rm, a, b, ctx=None)
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
def __init__(self, c, ctx)
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
def no_pattern(self, idx)
def TryFor(t, ms, ctx=None)
def __init__(self, probe, ctx=None)
def get_interp(self, decl)
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t)
Return the significand value of a floating-point numeral as a string.
Z3_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
def fpLEQ(a, b, ctx=None)
def EnumSort(name, values, ctx=None)
def BoolVal(val, ctx=None)
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
def significand_as_bv(self)
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
def get_default_fp_sort(ctx=None)
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None)
def __call__(self, *args)
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
def check(self, *assumptions)
def convert_model(self, model)
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i,...
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
def __init__(self, f, ctx)
unsigned Z3_API Z3_func_interp_get_arity(Z3_context c, Z3_func_interp f)
Return the arity (number of arguments) of the given function interpretation.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
def SolverFor(logic, ctx=None, logFile=None)
Z3_symbol Z3_API Z3_get_quantifier_bound_name(Z3_context c, Z3_ast a, unsigned i)
Return symbol of the i'th bound variable.
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def __rrshift__(self, other)
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_solver Z3_API Z3_mk_solver(Z3_context c)
Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally ...
unsigned Z3_API Z3_fpa_get_ebits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the exponent in a FloatingPoint sort.
Z3_param_kind Z3_API Z3_param_descrs_get_kind(Z3_context c, Z3_param_descrs p, Z3_symbol n)
Return the kind associated with the given parameter name n.
def simplify(self, *arguments, **keywords)
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, bool biased)
Return the exponent value of a floating-point numeral as a string.
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs....
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
def __rmul__(self, other)
def __init__(self, name, ctx=None)
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t *r)
Store the size of the sort in r. Return false if the call failed. That is, Z3_get_sort_kind(s) == Z3_...
Z3_sort Z3_API Z3_get_array_sort_domain(Z3_context c, Z3_sort t)
Return the domain of the given array sort. In the case of a multi-dimensional array,...
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
def from_file(self, filename)
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
def IntVector(prefix, sz, ctx=None)
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
def translate(self, other_ctx)
def query_from_lvl(self, lvl, *query)
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
def as_decimal(self, prec)
def get_key_value(self, key)
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
def __rsub__(self, other)
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
def __radd__(self, other)
def __init__(self, opt, value, is_max)
def fpIsZero(a, ctx=None)
def assert_exprs(self, *args)
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
def PartialOrder(a, index)
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
def __setitem__(self, i, v)
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
def assert_exprs(self, *args)
def __rtruediv__(self, other)
def set(self, *args, **keys)
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of first occurrence of substr in s starting from offset offset. If s does not contain su...
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_ast Z3_API Z3_mk_str_lt(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is lexicographically strictly less than s2.
void Z3_API Z3_params_set_symbol(Z3_context c, Z3_params p, Z3_symbol k, Z3_symbol v)
Add a symbol parameter k with value v to the parameter set p.
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the free variables in a with the expressions in to. For every i smaller than num_exprs,...
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
def BV2Int(a, is_signed=False)
def __init__(self, solver=None, ctx=None, logFile=None)
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
def RoundTowardZero(ctx=None)
def __rshift__(self, other)
def get_rule_names_along_trace(self)
def RecFunction(name, *sig)
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is subnormal.
def assert_exprs(self, *args)
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
def is_algebraic_value(a)
def BVMulNoUnderflow(a, b)
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s)
Return a string describing all solver available parameters.
def translate(self, other_ctx)
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
def __rsub__(self, other)
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
def prove(claim, **keywords)
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s)
Check if s is a string sort.
def fpMin(a, b, ctx=None)
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
def declare(self, name, *args)
def __getitem__(self, idx)
def BVMulNoOverflow(a, b, signed)
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
def Repeat(t, max=4294967295, ctx=None)
def fpToReal(x, ctx=None)
def check(self, *assumptions)
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
Z3_ast Z3_API Z3_mk_seq_at(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the unit sequence positioned at position index. The sequence is empty if the index is...
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
def __lshift__(self, other)
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 as_decimal(self, prec)
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
void Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property)
Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forw...
def upper_values(self, obj)
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
def get_num_levels(self, predicate)
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_str_le(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is equal or lexicographically strictly less than s2.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
def __rmod__(self, other)
def fpIsSubnormal(a, ctx=None)
def __getitem__(self, arg)
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
def fpIsNegative(a, ctx=None)
def declare_var(self, *vars)
def fpFPToFP(rm, v, sort, ctx=None)
def fpNEQ(a, b, ctx=None)
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.
bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int *sgn)
Retrieves the sign of a floating-point literal.
def __truediv__(self, other)
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...
def BVSubNoUnderflow(a, b, signed)
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
def ParThen(t1, t2, ctx=None)
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
def args2params(arguments, keywords, ctx=None)
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def FloatSingle(ctx=None)
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
Z3_string Z3_API Z3_benchmark_to_smtlib_string(Z3_context c, Z3_string name, Z3_string logic, Z3_string status, Z3_string attributes, unsigned num_assumptions, Z3_ast const assumptions[], Z3_ast formula)
Convert the given benchmark into SMT-LIB formatted string.
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is +zero or -zero.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
def fpRealToFP(rm, v, sort, ctx=None)
Z3_ast Z3_API Z3_mk_seq_nth(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the element positioned at position index. The function is under-specified if the inde...
def RealVector(prefix, sz, ctx=None)
def __getitem__(self, arg)
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
def fpIsPositive(a, ctx=None)
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_string Z3_API Z3_optimize_get_help(Z3_context c, Z3_optimize t)
Return a string containing a description of parameters accepted by optimize.
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_ast Z3_API Z3_fpa_get_numeral_significand_bv(Z3_context c, Z3_ast t)
Retrieves the significand of a floating-point literal as a bit-vector expression.
Z3_ast Z3_API Z3_mk_seq_extract(Z3_context c, Z3_ast s, Z3_ast offset, Z3_ast length)
Extract subsequence starting at offset of length.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
def set_option(*args, **kws)
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
def import_model_converter(self, other)
def SubString(s, offset, length)
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
def fpToIEEEBV(x, ctx=None)
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s)
Retrieve documentation string corresponding to parameter name s.
def String(name, ctx=None)
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.