9 """Z3 is a high performance theorem prover developed at Microsoft Research.
11 Z3 is used in many applications such as: software/hardware verification and testing,
12 constraint solving, analysis of hybrid systems, security, biology (in silico analysis),
13 and geometrical problems.
16 Please send feedback, comments and/or corrections on the Issue tracker for
17 https://github.com/Z3prover/z3.git. Your comments are very valuable.
38 ... x = BitVec('x', 32)
40 ... # the expression x + y is type incorrect
42 ... except Z3Exception as ex:
43 ... print("failed: %s" % ex)
48 from .z3types
import *
49 from .z3consts
import *
50 from .z3printer
import *
51 from fractions
import Fraction
56 if sys.version_info.major >= 3:
57 from typing
import Iterable
67 if sys.version_info.major < 3:
69 return isinstance(v, (int, long))
72 return isinstance(v, int)
84 major = ctypes.c_uint(0)
85 minor = ctypes.c_uint(0)
86 build = ctypes.c_uint(0)
87 rev = ctypes.c_uint(0)
89 return "%s.%s.%s" % (major.value, minor.value, build.value)
93 major = ctypes.c_uint(0)
94 minor = ctypes.c_uint(0)
95 build = ctypes.c_uint(0)
96 rev = ctypes.c_uint(0)
98 return (major.value, minor.value, build.value, rev.value)
105 def _z3_assert(cond, msg):
107 raise Z3Exception(msg)
110 def _z3_check_cint_overflow(n, name):
111 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
115 """Log interaction to a file. This function must be invoked immediately after init(). """
120 """Append user-defined string to interaction log. """
125 """Convert an integer or string into a Z3 symbol."""
132 def _symbol2py(ctx, s):
133 """Convert a Z3 symbol back into a Python object. """
146 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
148 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
149 return [arg
for arg
in args[0]]
158 def _get_args_ast_list(args):
160 if isinstance(args, (set, AstVector, tuple)):
161 return [arg
for arg
in args]
168 def _to_param_value(val):
169 if isinstance(val, bool):
170 return "true" if val
else "false"
181 """A Context manages all other Z3 objects, global configuration options, etc.
183 Z3Py uses a default global context. For most applications this is sufficient.
184 An application may use multiple Z3 contexts. Objects created in one context
185 cannot be used in another one. However, several objects may be "translated" from
186 one context to another. It is not safe to access Z3 objects from multiple threads.
187 The only exception is the method `interrupt()` that can be used to interrupt() a long
189 The initialization method receives global configuration options for the new context.
194 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
217 """Return a reference to the actual C pointer to the Z3 context."""
221 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
223 This method can be invoked from a thread different from the one executing the
224 interruptible procedure.
234 """Return a reference to the global Z3 context.
237 >>> x.ctx == main_ctx()
242 >>> x2 = Real('x', c)
249 if _main_ctx
is None:
266 """Set Z3 global (or module) parameters.
268 >>> set_param(precision=10)
271 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
275 if not set_pp_option(k, v):
290 """Reset all global (or module) parameters.
296 """Alias for 'set_param' for backward compatibility.
302 """Return the value of a Z3 global (or module) parameter
304 >>> get_param('nlsat.reorder')
307 ptr = (ctypes.c_char_p * 1)()
309 r = z3core._to_pystr(ptr[0])
311 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
323 """Superclass for all Z3 objects that have support for pretty printing."""
328 def _repr_html_(self):
329 in_html = in_html_mode()
332 set_html_mode(in_html)
337 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
341 self.
ctxctx = _get_ctx(ctx)
345 if self.
ctxctx.ref()
is not None and self.
astast
is not None:
350 return _to_ast_ref(self.
astast, self.
ctxctx)
353 return obj_to_string(self)
356 return obj_to_string(self)
359 return self.
eqeq(other)
362 return self.
hashhash()
372 elif is_eq(self)
and self.num_args() == 2:
373 return self.arg(0).
eq(self.arg(1))
375 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
378 """Return a string representing the AST node in s-expression notation.
381 >>> ((x + 1)*x).sexpr()
387 """Return a pointer to the corresponding C Z3_ast object."""
391 """Return unique identifier for object. It can be used for hash-tables and maps."""
395 """Return a reference to the C context where this AST node is stored."""
396 return self.
ctxctx.ref()
399 """Return `True` if `self` and `other` are structurally identical.
406 >>> n1 = simplify(n1)
407 >>> n2 = simplify(n2)
412 _z3_assert(
is_ast(other),
"Z3 AST expected")
416 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
422 >>> # Nodes in different contexts can't be mixed.
423 >>> # However, we can translate nodes from one context to another.
424 >>> x.translate(c2) + y
428 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
435 """Return a hashcode for the `self`.
437 >>> n1 = simplify(Int('x') + 1)
438 >>> n2 = simplify(2 + Int('x') - 1)
439 >>> n1.hash() == n2.hash()
446 """Return `True` if `a` is an AST node.
450 >>> is_ast(IntVal(10))
454 >>> is_ast(BoolSort())
456 >>> is_ast(Function('f', IntSort(), IntSort()))
463 return isinstance(a, AstRef)
467 """Return `True` if `a` and `b` are structurally identical AST nodes.
477 >>> eq(simplify(x + 1), simplify(1 + x))
485 def _ast_kind(ctx, a):
491 def _ctx_from_ast_arg_list(args, default_ctx=None):
499 _z3_assert(ctx == a.ctx,
"Context mismatch")
505 def _ctx_from_ast_args(*args):
506 return _ctx_from_ast_arg_list(args)
509 def _to_func_decl_array(args):
511 _args = (FuncDecl * sz)()
513 _args[i] = args[i].as_func_decl()
517 def _to_ast_array(args):
521 _args[i] = args[i].as_ast()
525 def _to_ref_array(ref, args):
529 _args[i] = args[i].as_ast()
533 def _to_ast_ref(a, ctx):
534 k = _ast_kind(ctx, a)
536 return _to_sort_ref(a, ctx)
537 elif k == Z3_FUNC_DECL_AST:
538 return _to_func_decl_ref(a, ctx)
540 return _to_expr_ref(a, ctx)
549 def _sort_kind(ctx, s):
554 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
563 """Return the Z3 internal kind of a sort.
564 This method can be used to test if `self` is one of the Z3 builtin sorts.
567 >>> b.kind() == Z3_BOOL_SORT
569 >>> b.kind() == Z3_INT_SORT
571 >>> A = ArraySort(IntSort(), IntSort())
572 >>> A.kind() == Z3_ARRAY_SORT
574 >>> A.kind() == Z3_INT_SORT
577 return _sort_kind(self.
ctxctx, self.
astast)
580 """Return `True` if `self` is a subsort of `other`.
582 >>> IntSort().subsort(RealSort())
588 """Try to cast `val` as an element of sort `self`.
590 This method is used in Z3Py to convert Python objects such as integers,
591 floats, longs and strings into Z3 expressions.
594 >>> RealSort().cast(x)
598 _z3_assert(
is_expr(val),
"Z3 expression expected")
599 _z3_assert(self.
eqeq(val.sort()),
"Sort mismatch")
603 """Return the name (string) of sort `self`.
605 >>> BoolSort().name()
607 >>> ArraySort(IntSort(), IntSort()).name()
613 """Return `True` if `self` and `other` are the same Z3 sort.
616 >>> p.sort() == BoolSort()
618 >>> p.sort() == IntSort()
626 """Return `True` if `self` and `other` are not the same Z3 sort.
629 >>> p.sort() != BoolSort()
631 >>> p.sort() != IntSort()
638 return AstRef.__hash__(self)
642 """Return `True` if `s` is a Z3 sort.
644 >>> is_sort(IntSort())
646 >>> is_sort(Int('x'))
648 >>> is_expr(Int('x'))
651 return isinstance(s, SortRef)
654 def _to_sort_ref(s, ctx):
656 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
657 k = _sort_kind(ctx, s)
658 if k == Z3_BOOL_SORT:
660 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
662 elif k == Z3_BV_SORT:
664 elif k == Z3_ARRAY_SORT:
666 elif k == Z3_DATATYPE_SORT:
668 elif k == Z3_FINITE_DOMAIN_SORT:
670 elif k == Z3_FLOATING_POINT_SORT:
672 elif k == Z3_ROUNDING_MODE_SORT:
674 elif k == Z3_RE_SORT:
676 elif k == Z3_SEQ_SORT:
678 elif k == Z3_CHAR_SORT:
684 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
688 """Create a new uninterpreted sort named `name`.
690 If `ctx=None`, then the new sort is declared in the global Z3Py context.
692 >>> A = DeclareSort('A')
693 >>> a = Const('a', A)
694 >>> b = Const('b', A)
713 """Function declaration. Every constant and function have an associated declaration.
715 The declaration assigns a name, a sort (i.e., type), and for function
716 the sort (i.e., type) of each of its arguments. Note that, in Z3,
717 a constant is a function with 0 arguments.
730 """Return the name of the function declaration `self`.
732 >>> f = Function('f', IntSort(), IntSort())
735 >>> isinstance(f.name(), str)
741 """Return the number of arguments of a function declaration.
742 If `self` is a constant, then `self.arity()` is 0.
744 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
751 """Return the sort of the argument `i` of a function declaration.
752 This method assumes that `0 <= i < self.arity()`.
754 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
761 _z3_assert(i < self.
arityarity(),
"Index out of bounds")
765 """Return the sort of the range of a function declaration.
766 For constants, this is the sort of the constant.
768 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
775 """Return the internal kind of a function declaration.
776 It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
779 >>> d = (x + 1).decl()
780 >>> d.kind() == Z3_OP_ADD
782 >>> d.kind() == Z3_OP_MUL
790 result = [
None for i
in range(n)]
793 if k == Z3_PARAMETER_INT:
795 elif k == Z3_PARAMETER_DOUBLE:
797 elif k == Z3_PARAMETER_RATIONAL:
799 elif k == Z3_PARAMETER_SYMBOL:
801 elif k == Z3_PARAMETER_SORT:
803 elif k == Z3_PARAMETER_AST:
805 elif k == Z3_PARAMETER_FUNC_DECL:
812 """Create a Z3 application expression using the function `self`, and the given arguments.
814 The arguments must be Z3 expressions. This method assumes that
815 the sorts of the elements in `args` match the sorts of the
816 domain. Limited coercion is supported. For example, if
817 args[0] is a Python integer, and the function expects a Z3
818 integer, then the argument is automatically converted into a
821 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
829 args = _get_args(args)
832 _z3_assert(num == self.
arityarity(),
"Incorrect number of arguments to %s" % self)
833 _args = (Ast * num)()
838 tmp = self.
domaindomain(i).cast(args[i])
840 _args[i] = tmp.as_ast()
845 """Return `True` if `a` is a Z3 function declaration.
847 >>> f = Function('f', IntSort(), IntSort())
854 return isinstance(a, FuncDeclRef)
858 """Create a new Z3 uninterpreted function with the given sorts.
860 >>> f = Function('f', IntSort(), IntSort())
866 _z3_assert(len(sig) > 0,
"At least two arguments expected")
870 _z3_assert(
is_sort(rng),
"Z3 sort expected")
871 dom = (Sort * arity)()
872 for i
in range(arity):
874 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
881 """Create a new fresh Z3 uninterpreted function with the given sorts.
885 _z3_assert(len(sig) > 0,
"At least two arguments expected")
889 _z3_assert(
is_sort(rng),
"Z3 sort expected")
890 dom = (z3.Sort * arity)()
891 for i
in range(arity):
893 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
899 def _to_func_decl_ref(a, ctx):
904 """Create a new Z3 recursive with the given sorts."""
907 _z3_assert(len(sig) > 0,
"At least two arguments expected")
911 _z3_assert(
is_sort(rng),
"Z3 sort expected")
912 dom = (Sort * arity)()
913 for i
in range(arity):
915 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
922 """Set the body of a recursive function.
923 Recursive definitions can be simplified if they are applied to ground
926 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
927 >>> n = Int('n', ctx)
928 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
931 >>> s = Solver(ctx=ctx)
932 >>> s.add(fac(n) < 3)
935 >>> s.model().eval(fac(5))
941 args = _get_args(args)
945 _args[i] = args[i].ast
956 """Constraints, formulas and terms are expressions in Z3.
958 Expressions are ASTs. Every expression has a sort.
959 There are three main kinds of expressions:
960 function applications, quantifiers and bounded variables.
961 A constant is a function application with 0 arguments.
962 For quantifier free problems, all expressions are
963 function applications.
973 """Return the sort of expression `self`.
985 """Shorthand for `self.sort().kind()`.
987 >>> a = Array('a', IntSort(), IntSort())
988 >>> a.sort_kind() == Z3_ARRAY_SORT
990 >>> a.sort_kind() == Z3_INT_SORT
993 return self.
sortsort().kind()
996 """Return a Z3 expression that represents the constraint `self == other`.
998 If `other` is `None`, then this method simply returns `False`.
1009 a, b = _coerce_exprs(self, other)
1014 return AstRef.__hash__(self)
1017 """Return a Z3 expression that represents the constraint `self != other`.
1019 If `other` is `None`, then this method simply returns `True`.
1030 a, b = _coerce_exprs(self, other)
1031 _args, sz = _to_ast_array((a, b))
1038 """Return the Z3 function declaration associated with a Z3 application.
1040 >>> f = Function('f', IntSort(), IntSort())
1049 _z3_assert(
is_app(self),
"Z3 application expected")
1053 """Return the number of arguments of a Z3 application.
1057 >>> (a + b).num_args()
1059 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1065 _z3_assert(
is_app(self),
"Z3 application expected")
1069 """Return argument `idx` of the application `self`.
1071 This method assumes that `self` is a function application with at least `idx+1` arguments.
1075 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1085 _z3_assert(
is_app(self),
"Z3 application expected")
1086 _z3_assert(idx < self.
num_argsnum_args(),
"Invalid argument index")
1090 """Return a list containing the children of the given expression
1094 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1114 """inverse function to the serialize method on ExprRef.
1115 It is made available to make it easier for users to serialize expressions back and forth between
1116 strings. Solvers can be serialized using the 'sexpr()' method.
1120 if len(s.assertions()) != 1:
1121 raise Z3Exception(
"single assertion expected")
1122 fml = s.assertions()[0]
1123 if fml.num_args() != 1:
1124 raise Z3Exception(
"dummy function 'F' expected")
1127 def _to_expr_ref(a, ctx):
1128 if isinstance(a, Pattern):
1132 if k == Z3_QUANTIFIER_AST:
1135 if sk == Z3_BOOL_SORT:
1137 if sk == Z3_INT_SORT:
1138 if k == Z3_NUMERAL_AST:
1141 if sk == Z3_REAL_SORT:
1142 if k == Z3_NUMERAL_AST:
1144 if _is_algebraic(ctx, a):
1147 if sk == Z3_BV_SORT:
1148 if k == Z3_NUMERAL_AST:
1152 if sk == Z3_ARRAY_SORT:
1154 if sk == Z3_DATATYPE_SORT:
1156 if sk == Z3_FLOATING_POINT_SORT:
1157 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1160 return FPRef(a, ctx)
1161 if sk == Z3_FINITE_DOMAIN_SORT:
1162 if k == Z3_NUMERAL_AST:
1166 if sk == Z3_ROUNDING_MODE_SORT:
1168 if sk == Z3_SEQ_SORT:
1170 if sk == Z3_CHAR_SORT:
1172 if sk == Z3_RE_SORT:
1173 return ReRef(a, ctx)
1177 def _coerce_expr_merge(s, a):
1190 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1191 _z3_assert(
False,
"sort mismatch")
1196 def _coerce_exprs(a, b, ctx=None):
1198 a = _py2expr(a, ctx)
1199 b = _py2expr(b, ctx)
1200 if isinstance(a, str)
and isinstance(b, SeqRef):
1202 if isinstance(b, str)
and isinstance(a, SeqRef):
1205 s = _coerce_expr_merge(s, a)
1206 s = _coerce_expr_merge(s, b)
1212 def _reduce(func, sequence, initial):
1214 for element
in sequence:
1215 result = func(result, element)
1219 def _coerce_expr_list(alist, ctx=None):
1226 alist = [_py2expr(a, ctx)
for a
in alist]
1227 s = _reduce(_coerce_expr_merge, alist,
None)
1228 return [s.cast(a)
for a
in alist]
1232 """Return `True` if `a` is a Z3 expression.
1239 >>> is_expr(IntSort())
1243 >>> is_expr(IntVal(1))
1246 >>> is_expr(ForAll(x, x >= 0))
1248 >>> is_expr(FPVal(1.0))
1251 return isinstance(a, ExprRef)
1255 """Return `True` if `a` is a Z3 function application.
1257 Note that, constants are function applications with 0 arguments.
1264 >>> is_app(IntSort())
1268 >>> is_app(IntVal(1))
1271 >>> is_app(ForAll(x, x >= 0))
1274 if not isinstance(a, ExprRef):
1276 k = _ast_kind(a.ctx, a)
1277 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1281 """Return `True` if `a` is Z3 constant/variable expression.
1290 >>> is_const(IntVal(1))
1293 >>> is_const(ForAll(x, x >= 0))
1296 return is_app(a)
and a.num_args() == 0
1300 """Return `True` if `a` is variable.
1302 Z3 uses de-Bruijn indices for representing bound variables in
1310 >>> f = Function('f', IntSort(), IntSort())
1311 >>> # Z3 replaces x with bound variables when ForAll is executed.
1312 >>> q = ForAll(x, f(x) == x)
1318 >>> is_var(b.arg(1))
1321 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1325 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1333 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1334 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1335 >>> q = ForAll([x, y], f(x, y) == x + y)
1337 f(Var(1), Var(0)) == Var(1) + Var(0)
1341 >>> v1 = b.arg(0).arg(0)
1342 >>> v2 = b.arg(0).arg(1)
1347 >>> get_var_index(v1)
1349 >>> get_var_index(v2)
1353 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1358 """Return `True` if `a` is an application of the given kind `k`.
1362 >>> is_app_of(n, Z3_OP_ADD)
1364 >>> is_app_of(n, Z3_OP_MUL)
1367 return is_app(a)
and a.decl().kind() == k
1370 def If(a, b, c, ctx=None):
1371 """Create a Z3 if-then-else expression.
1375 >>> max = If(x > y, x, y)
1381 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1382 return Cond(a, b, c, ctx)
1384 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1387 b, c = _coerce_exprs(b, c, ctx)
1389 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1390 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1394 """Create a Z3 distinct expression.
1401 >>> Distinct(x, y, z)
1403 >>> simplify(Distinct(x, y, z))
1405 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1406 And(Not(x == y), Not(x == z), Not(y == z))
1408 args = _get_args(args)
1409 ctx = _ctx_from_ast_arg_list(args)
1411 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1412 args = _coerce_expr_list(args, ctx)
1413 _args, sz = _to_ast_array(args)
1417 def _mk_bin(f, a, b):
1420 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1421 args[0] = a.as_ast()
1422 args[1] = b.as_ast()
1423 return f(a.ctx.ref(), 2, args)
1427 """Create a constant of the given sort.
1429 >>> Const('x', IntSort())
1433 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1439 """Create several constants of the given sort.
1441 `names` is a string containing the names of all constants to be created.
1442 Blank spaces separate the names of different constants.
1444 >>> x, y, z = Consts('x y z', IntSort())
1448 if isinstance(names, str):
1449 names = names.split(
" ")
1450 return [
Const(name, sort)
for name
in names]
1454 """Create a fresh constant of a specified sort"""
1455 ctx = _get_ctx(sort.ctx)
1460 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1462 >>> Var(0, IntSort())
1464 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1468 _z3_assert(
is_sort(s),
"Z3 sort expected")
1469 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1474 Create a real free variable. Free variables are used to create quantified formulas.
1475 They are also used to create polynomials.
1485 Create a list of Real free variables.
1486 The variables have ids: 0, 1, ..., n-1
1488 >>> x0, x1, x2, x3 = RealVarVector(4)
1505 """Try to cast `val` as a Boolean.
1507 >>> x = BoolSort().cast(True)
1517 if isinstance(val, bool):
1521 msg =
"True, False or Z3 Boolean expression expected. Received %s of type %s"
1522 _z3_assert(
is_expr(val), msg % (val, type(val)))
1523 if not self.
eqeq(val.sort()):
1524 _z3_assert(self.
eqeq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1528 return isinstance(other, ArithSortRef)
1538 """All Boolean expressions are instances of this class."""
1547 """Create the Z3 expression `self * other`.
1553 return If(self, other, 0)
1557 """Return `True` if `a` is a Z3 Boolean expression.
1563 >>> is_bool(And(p, q))
1571 return isinstance(a, BoolRef)
1575 """Return `True` if `a` is the Z3 true expression.
1580 >>> is_true(simplify(p == p))
1585 >>> # True is a Python Boolean expression
1593 """Return `True` if `a` is the Z3 false expression.
1600 >>> is_false(BoolVal(False))
1607 """Return `True` if `a` is a Z3 and expression.
1609 >>> p, q = Bools('p q')
1610 >>> is_and(And(p, q))
1612 >>> is_and(Or(p, q))
1619 """Return `True` if `a` is a Z3 or expression.
1621 >>> p, q = Bools('p q')
1624 >>> is_or(And(p, q))
1631 """Return `True` if `a` is a Z3 implication expression.
1633 >>> p, q = Bools('p q')
1634 >>> is_implies(Implies(p, q))
1636 >>> is_implies(And(p, q))
1643 """Return `True` if `a` is a Z3 not expression.
1655 """Return `True` if `a` is a Z3 equality expression.
1657 >>> x, y = Ints('x y')
1665 """Return `True` if `a` is a Z3 distinct expression.
1667 >>> x, y, z = Ints('x y z')
1668 >>> is_distinct(x == y)
1670 >>> is_distinct(Distinct(x, y, z))
1677 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1681 >>> p = Const('p', BoolSort())
1684 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1687 >>> is_bool(r(0, 1))
1695 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1699 >>> is_true(BoolVal(True))
1703 >>> is_false(BoolVal(False))
1714 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1726 """Return a tuple of Boolean constants.
1728 `names` is a single string containing all names separated by blank spaces.
1729 If `ctx=None`, then the global context is used.
1731 >>> p, q, r = Bools('p q r')
1732 >>> And(p, Or(q, r))
1736 if isinstance(names, str):
1737 names = names.split(
" ")
1738 return [
Bool(name, ctx)
for name
in names]
1742 """Return a list of Boolean constants of size `sz`.
1744 The constants are named using the given prefix.
1745 If `ctx=None`, then the global context is used.
1747 >>> P = BoolVector('p', 3)
1751 And(p__0, p__1, p__2)
1753 return [
Bool(
"%s__%s" % (prefix, i))
for i
in range(sz)]
1757 """Return a fresh Boolean constant in the given context using the given prefix.
1759 If `ctx=None`, then the global context is used.
1761 >>> b1 = FreshBool()
1762 >>> b2 = FreshBool()
1771 """Create a Z3 implies expression.
1773 >>> p, q = Bools('p q')
1777 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1785 """Create a Z3 Xor expression.
1787 >>> p, q = Bools('p q')
1790 >>> simplify(Xor(p, q))
1793 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1801 """Create a Z3 not expression or probe.
1806 >>> simplify(Not(Not(p)))
1809 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1826 def _has_probe(args):
1827 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1835 """Create a Z3 and-expression or and-probe.
1837 >>> p, q, r = Bools('p q r')
1840 >>> P = BoolVector('p', 5)
1842 And(p__0, p__1, p__2, p__3, p__4)
1846 last_arg = args[len(args) - 1]
1847 if isinstance(last_arg, Context):
1848 ctx = args[len(args) - 1]
1849 args = args[:len(args) - 1]
1850 elif len(args) == 1
and isinstance(args[0], AstVector):
1852 args = [a
for a
in args[0]]
1855 args = _get_args(args)
1856 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1858 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1859 if _has_probe(args):
1860 return _probe_and(args, ctx)
1862 args = _coerce_expr_list(args, ctx)
1863 _args, sz = _to_ast_array(args)
1868 """Create a Z3 or-expression or or-probe.
1870 >>> p, q, r = Bools('p q r')
1873 >>> P = BoolVector('p', 5)
1875 Or(p__0, p__1, p__2, p__3, p__4)
1879 last_arg = args[len(args) - 1]
1880 if isinstance(last_arg, Context):
1881 ctx = args[len(args) - 1]
1882 args = args[:len(args) - 1]
1883 elif len(args) == 1
and isinstance(args[0], AstVector):
1885 args = [a
for a
in args[0]]
1888 args = _get_args(args)
1889 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1891 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1892 if _has_probe(args):
1893 return _probe_or(args, ctx)
1895 args = _coerce_expr_list(args, ctx)
1896 _args, sz = _to_ast_array(args)
1907 """Patterns are hints for quantifier instantiation.
1919 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1921 >>> f = Function('f', IntSort(), IntSort())
1923 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1925 ForAll(x, f(x) == 0)
1926 >>> q.num_patterns()
1928 >>> is_pattern(q.pattern(0))
1933 return isinstance(a, PatternRef)
1937 """Create a Z3 multi-pattern using the given expressions `*args`
1939 >>> f = Function('f', IntSort(), IntSort())
1940 >>> g = Function('g', IntSort(), IntSort())
1942 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1944 ForAll(x, f(x) != g(x))
1945 >>> q.num_patterns()
1947 >>> is_pattern(q.pattern(0))
1950 MultiPattern(f(Var(0)), g(Var(0)))
1953 _z3_assert(len(args) > 0,
"At least one argument expected")
1954 _z3_assert(all([
is_expr(a)
for a
in args]),
"Z3 expressions expected")
1956 args, sz = _to_ast_array(args)
1960 def _to_pattern(arg):
1974 """Universally and Existentially quantified formulas."""
1983 """Return the Boolean sort or sort of Lambda."""
1989 """Return `True` if `self` is a universal quantifier.
1991 >>> f = Function('f', IntSort(), IntSort())
1993 >>> q = ForAll(x, f(x) == 0)
1996 >>> q = Exists(x, f(x) != 0)
2003 """Return `True` if `self` is an existential quantifier.
2005 >>> f = Function('f', IntSort(), IntSort())
2007 >>> q = ForAll(x, f(x) == 0)
2010 >>> q = Exists(x, f(x) != 0)
2017 """Return `True` if `self` is a lambda expression.
2019 >>> f = Function('f', IntSort(), IntSort())
2021 >>> q = Lambda(x, f(x))
2024 >>> q = Exists(x, f(x) != 0)
2031 """Return the Z3 expression `self[arg]`.
2034 _z3_assert(self.
is_lambdais_lambda(),
"quantifier should be a lambda expression")
2035 return _array_select(self, arg)
2038 """Return the weight annotation of `self`.
2040 >>> f = Function('f', IntSort(), IntSort())
2042 >>> q = ForAll(x, f(x) == 0)
2045 >>> q = ForAll(x, f(x) == 0, weight=10)
2052 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2054 >>> f = Function('f', IntSort(), IntSort())
2055 >>> g = Function('g', IntSort(), IntSort())
2057 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2058 >>> q.num_patterns()
2064 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2066 >>> f = Function('f', IntSort(), IntSort())
2067 >>> g = Function('g', IntSort(), IntSort())
2069 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2070 >>> q.num_patterns()
2078 _z3_assert(idx < self.
num_patternsnum_patterns(),
"Invalid pattern idx")
2082 """Return the number of no-patterns."""
2086 """Return a no-pattern."""
2088 _z3_assert(idx < self.
num_no_patternsnum_no_patterns(),
"Invalid no-pattern idx")
2092 """Return the expression being quantified.
2094 >>> f = Function('f', IntSort(), IntSort())
2096 >>> q = ForAll(x, f(x) == 0)
2103 """Return the number of variables bounded by this quantifier.
2105 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2108 >>> q = ForAll([x, y], f(x, y) >= x)
2115 """Return a string representing a name used when displaying the quantifier.
2117 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2120 >>> q = ForAll([x, y], f(x, y) >= x)
2127 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2131 """Return the sort of a bound variable.
2133 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2136 >>> q = ForAll([x, y], f(x, y) >= x)
2143 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2147 """Return a list containing a single element self.body()
2149 >>> f = Function('f', IntSort(), IntSort())
2151 >>> q = ForAll(x, f(x) == 0)
2155 return [self.
bodybody()]
2159 """Return `True` if `a` is a Z3 quantifier.
2161 >>> f = Function('f', IntSort(), IntSort())
2163 >>> q = ForAll(x, f(x) == 0)
2164 >>> is_quantifier(q)
2166 >>> is_quantifier(f(x))
2169 return isinstance(a, QuantifierRef)
2172 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2174 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2175 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2176 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2177 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2188 _vs = (Ast * num_vars)()
2189 for i
in range(num_vars):
2191 _vs[i] = vs[i].as_ast()
2192 patterns = [_to_pattern(p)
for p
in patterns]
2193 num_pats = len(patterns)
2194 _pats = (Pattern * num_pats)()
2195 for i
in range(num_pats):
2196 _pats[i] = patterns[i].ast
2197 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2203 num_no_pats, _no_pats,
2204 body.as_ast()), ctx)
2207 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2208 """Create a Z3 forall formula.
2210 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2212 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2215 >>> ForAll([x, y], f(x, y) >= x)
2216 ForAll([x, y], f(x, y) >= x)
2217 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2218 ForAll([x, y], f(x, y) >= x)
2219 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2220 ForAll([x, y], f(x, y) >= x)
2222 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2225 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2226 """Create a Z3 exists formula.
2228 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2231 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2234 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2236 Exists([x, y], f(x, y) >= x)
2237 >>> is_quantifier(q)
2239 >>> r = Tactic('nnf')(q).as_expr()
2240 >>> is_quantifier(r)
2243 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2247 """Create a Z3 lambda expression.
2249 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2250 >>> mem0 = Array('mem0', IntSort(), IntSort())
2251 >>> lo, hi, e, i = Ints('lo hi e i')
2252 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2254 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2260 _vs = (Ast * num_vars)()
2261 for i
in range(num_vars):
2263 _vs[i] = vs[i].as_ast()
2274 """Real and Integer sorts."""
2277 """Return `True` if `self` is of the sort Real.
2282 >>> (x + 1).is_real()
2288 return self.
kindkind() == Z3_REAL_SORT
2291 """Return `True` if `self` is of the sort Integer.
2296 >>> (x + 1).is_int()
2302 return self.
kindkind() == Z3_INT_SORT
2308 """Return `True` if `self` is a subsort of `other`."""
2312 """Try to cast `val` as an Integer or Real.
2314 >>> IntSort().cast(10)
2316 >>> is_int(IntSort().cast(10))
2320 >>> RealSort().cast(10)
2322 >>> is_real(RealSort().cast(10))
2327 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
2329 if self.
eqeq(val_s):
2331 if val_s.is_int()
and self.
is_realis_real():
2333 if val_s.is_bool()
and self.
is_intis_int():
2334 return If(val, 1, 0)
2335 if val_s.is_bool()
and self.
is_realis_real():
2338 _z3_assert(
False,
"Z3 Integer/Real expression expected")
2345 msg =
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2346 _z3_assert(
False, msg % self)
2350 """Return `True` if s is an arithmetical sort (type).
2352 >>> is_arith_sort(IntSort())
2354 >>> is_arith_sort(RealSort())
2356 >>> is_arith_sort(BoolSort())
2358 >>> n = Int('x') + 1
2359 >>> is_arith_sort(n.sort())
2362 return isinstance(s, ArithSortRef)
2366 """Integer and Real expressions."""
2369 """Return the sort (type) of the arithmetical expression `self`.
2373 >>> (Real('x') + 1).sort()
2379 """Return `True` if `self` is an integer expression.
2384 >>> (x + 1).is_int()
2387 >>> (x + y).is_int()
2393 """Return `True` if `self` is an real expression.
2398 >>> (x + 1).is_real()
2404 """Create the Z3 expression `self + other`.
2413 a, b = _coerce_exprs(self, other)
2414 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctxctx)
2417 """Create the Z3 expression `other + self`.
2423 a, b = _coerce_exprs(self, other)
2424 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctxctx)
2427 """Create the Z3 expression `self * other`.
2436 if isinstance(other, BoolRef):
2437 return If(other, self, 0)
2438 a, b = _coerce_exprs(self, other)
2439 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctxctx)
2442 """Create the Z3 expression `other * self`.
2448 a, b = _coerce_exprs(self, other)
2449 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctxctx)
2452 """Create the Z3 expression `self - other`.
2461 a, b = _coerce_exprs(self, other)
2462 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctxctx)
2465 """Create the Z3 expression `other - self`.
2471 a, b = _coerce_exprs(self, other)
2472 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctxctx)
2475 """Create the Z3 expression `self**other` (** is the power operator).
2482 >>> simplify(IntVal(2)**8)
2485 a, b = _coerce_exprs(self, other)
2489 """Create the Z3 expression `other**self` (** is the power operator).
2496 >>> simplify(2**IntVal(8))
2499 a, b = _coerce_exprs(self, other)
2503 """Create the Z3 expression `other/self`.
2522 a, b = _coerce_exprs(self, other)
2526 """Create the Z3 expression `other/self`."""
2527 return self.
__div____div__(other)
2530 """Create the Z3 expression `other/self`.
2543 a, b = _coerce_exprs(self, other)
2547 """Create the Z3 expression `other/self`."""
2548 return self.
__rdiv____rdiv__(other)
2551 """Create the Z3 expression `other%self`.
2557 >>> simplify(IntVal(10) % IntVal(3))
2560 a, b = _coerce_exprs(self, other)
2562 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2566 """Create the Z3 expression `other%self`.
2572 a, b = _coerce_exprs(self, other)
2574 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2578 """Return an expression representing `-self`.
2598 """Create the Z3 expression `other <= self`.
2600 >>> x, y = Ints('x y')
2607 a, b = _coerce_exprs(self, other)
2611 """Create the Z3 expression `other < self`.
2613 >>> x, y = Ints('x y')
2620 a, b = _coerce_exprs(self, other)
2624 """Create the Z3 expression `other > self`.
2626 >>> x, y = Ints('x y')
2633 a, b = _coerce_exprs(self, other)
2637 """Create the Z3 expression `other >= self`.
2639 >>> x, y = Ints('x y')
2646 a, b = _coerce_exprs(self, other)
2651 """Return `True` if `a` is an arithmetical expression.
2660 >>> is_arith(IntVal(1))
2668 return isinstance(a, ArithRef)
2672 """Return `True` if `a` is an integer expression.
2679 >>> is_int(IntVal(1))
2691 """Return `True` if `a` is a real expression.
2703 >>> is_real(RealVal(1))
2709 def _is_numeral(ctx, a):
2713 def _is_algebraic(ctx, a):
2718 """Return `True` if `a` is an integer value of sort Int.
2720 >>> is_int_value(IntVal(1))
2724 >>> is_int_value(Int('x'))
2726 >>> n = Int('x') + 1
2731 >>> is_int_value(n.arg(1))
2733 >>> is_int_value(RealVal("1/3"))
2735 >>> is_int_value(RealVal(1))
2738 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2742 """Return `True` if `a` is rational value of sort Real.
2744 >>> is_rational_value(RealVal(1))
2746 >>> is_rational_value(RealVal("3/5"))
2748 >>> is_rational_value(IntVal(1))
2750 >>> is_rational_value(1)
2752 >>> n = Real('x') + 1
2755 >>> is_rational_value(n.arg(1))
2757 >>> is_rational_value(Real('x'))
2760 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2764 """Return `True` if `a` is an algebraic value of sort Real.
2766 >>> is_algebraic_value(RealVal("3/5"))
2768 >>> n = simplify(Sqrt(2))
2771 >>> is_algebraic_value(n)
2774 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2778 """Return `True` if `a` is an expression of the form b + c.
2780 >>> x, y = Ints('x y')
2790 """Return `True` if `a` is an expression of the form b * c.
2792 >>> x, y = Ints('x y')
2802 """Return `True` if `a` is an expression of the form b - c.
2804 >>> x, y = Ints('x y')
2814 """Return `True` if `a` is an expression of the form b / c.
2816 >>> x, y = Reals('x y')
2821 >>> x, y = Ints('x y')
2831 """Return `True` if `a` is an expression of the form b div c.
2833 >>> x, y = Ints('x y')
2843 """Return `True` if `a` is an expression of the form b % c.
2845 >>> x, y = Ints('x y')
2855 """Return `True` if `a` is an expression of the form b <= c.
2857 >>> x, y = Ints('x y')
2867 """Return `True` if `a` is an expression of the form b < c.
2869 >>> x, y = Ints('x y')
2879 """Return `True` if `a` is an expression of the form b >= c.
2881 >>> x, y = Ints('x y')
2891 """Return `True` if `a` is an expression of the form b > c.
2893 >>> x, y = Ints('x y')
2903 """Return `True` if `a` is an expression of the form IsInt(b).
2906 >>> is_is_int(IsInt(x))
2915 """Return `True` if `a` is an expression of the form ToReal(b).
2930 """Return `True` if `a` is an expression of the form ToInt(b).
2945 """Integer values."""
2948 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2957 _z3_assert(self.
is_intis_int(),
"Integer value expected")
2961 """Return a Z3 integer numeral as a Python string.
2969 """Return a Z3 integer numeral as a Python binary string.
2971 >>> v.as_binary_string()
2978 """Rational values."""
2981 """ Return the numerator of a Z3 rational numeral.
2983 >>> is_rational_value(RealVal("3/5"))
2985 >>> n = RealVal("3/5")
2988 >>> is_rational_value(Q(3,5))
2990 >>> Q(3,5).numerator()
2996 """ Return the denominator of a Z3 rational numeral.
2998 >>> is_rational_value(Q(3,5))
3007 """ Return the numerator as a Python long.
3009 >>> v = RealVal(10000000000)
3014 >>> v.numerator_as_long() + 1 == 10000000001
3020 """ Return the denominator as a Python long.
3022 >>> v = RealVal("1/3")
3025 >>> v.denominator_as_long()
3040 _z3_assert(self.
is_int_valueis_int_value(),
"Expected integer fraction")
3044 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3046 >>> v = RealVal("1/5")
3049 >>> v = RealVal("1/3")
3056 """Return a Z3 rational numeral as a Python string.
3065 """Return a Z3 rational as a Python Fraction object.
3067 >>> v = RealVal("1/5")
3075 """Algebraic irrational values."""
3078 """Return a Z3 rational number that approximates the algebraic number `self`.
3079 The result `r` is such that |r - self| <= 1/10^precision
3081 >>> x = simplify(Sqrt(2))
3083 6838717160008073720548335/4835703278458516698824704
3090 """Return a string representation of the algebraic number `self` in decimal notation
3091 using `prec` decimal places.
3093 >>> x = simplify(Sqrt(2))
3094 >>> x.as_decimal(10)
3096 >>> x.as_decimal(20)
3097 '1.41421356237309504880?'
3108 def _py2expr(a, ctx=None):
3109 if isinstance(a, bool):
3113 if isinstance(a, float):
3115 if isinstance(a, str):
3120 _z3_assert(
False,
"Python bool, int, long or float expected")
3124 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3128 >>> x = Const('x', IntSort())
3131 >>> x.sort() == IntSort()
3133 >>> x.sort() == BoolSort()
3141 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3145 >>> x = Const('x', RealSort())
3150 >>> x.sort() == RealSort()
3157 def _to_int_str(val):
3158 if isinstance(val, float):
3159 return str(int(val))
3160 elif isinstance(val, bool):
3167 elif isinstance(val, str):
3170 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
3174 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3186 """Return a Z3 real value.
3188 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3189 If `ctx=None`, then the global context is used.
3193 >>> RealVal(1).sort()
3205 """Return a Z3 rational a/b.
3207 If `ctx=None`, then the global context is used.
3211 >>> RatVal(3,5).sort()
3215 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3216 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3220 def Q(a, b, ctx=None):
3221 """Return a Z3 rational a/b.
3223 If `ctx=None`, then the global context is used.
3234 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3247 """Return a tuple of Integer constants.
3249 >>> x, y, z = Ints('x y z')
3254 if isinstance(names, str):
3255 names = names.split(
" ")
3256 return [
Int(name, ctx)
for name
in names]
3260 """Return a list of integer constants of size `sz`.
3262 >>> X = IntVector('x', 3)
3269 return [
Int(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3273 """Return a fresh integer constant in the given context using the given prefix.
3287 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3300 """Return a tuple of real constants.
3302 >>> x, y, z = Reals('x y z')
3305 >>> Sum(x, y, z).sort()
3309 if isinstance(names, str):
3310 names = names.split(
" ")
3311 return [
Real(name, ctx)
for name
in names]
3315 """Return a list of real constants of size `sz`.
3317 >>> X = RealVector('x', 3)
3326 return [
Real(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3330 """Return a fresh real constant in the given context using the given prefix.
3344 """ Return the Z3 expression ToReal(a).
3356 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3362 """ Return the Z3 expression ToInt(a).
3374 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3380 """ Return the Z3 predicate IsInt(a).
3383 >>> IsInt(x + "1/2")
3385 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3387 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3391 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3397 """ Return a Z3 expression which represents the square root of a.
3410 """ Return a Z3 expression which represents the cubic root of a.
3429 """Bit-vector sort."""
3432 """Return the size (number of bits) of the bit-vector sort `self`.
3434 >>> b = BitVecSort(32)
3444 """Try to cast `val` as a Bit-Vector.
3446 >>> b = BitVecSort(32)
3449 >>> b.cast(10).sexpr()
3454 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
3462 """Return True if `s` is a Z3 bit-vector sort.
3464 >>> is_bv_sort(BitVecSort(32))
3466 >>> is_bv_sort(IntSort())
3469 return isinstance(s, BitVecSortRef)
3473 """Bit-vector expressions."""
3476 """Return the sort of the bit-vector expression `self`.
3478 >>> x = BitVec('x', 32)
3481 >>> x.sort() == BitVecSort(32)
3487 """Return the number of bits of the bit-vector expression `self`.
3489 >>> x = BitVec('x', 32)
3492 >>> Concat(x, x).size()
3498 """Create the Z3 expression `self + other`.
3500 >>> x = BitVec('x', 32)
3501 >>> y = BitVec('y', 32)
3507 a, b = _coerce_exprs(self, other)
3511 """Create the Z3 expression `other + self`.
3513 >>> x = BitVec('x', 32)
3517 a, b = _coerce_exprs(self, other)
3521 """Create the Z3 expression `self * other`.
3523 >>> x = BitVec('x', 32)
3524 >>> y = BitVec('y', 32)
3530 a, b = _coerce_exprs(self, other)
3534 """Create the Z3 expression `other * self`.
3536 >>> x = BitVec('x', 32)
3540 a, b = _coerce_exprs(self, other)
3544 """Create the Z3 expression `self - other`.
3546 >>> x = BitVec('x', 32)
3547 >>> y = BitVec('y', 32)
3553 a, b = _coerce_exprs(self, other)
3557 """Create the Z3 expression `other - self`.
3559 >>> x = BitVec('x', 32)
3563 a, b = _coerce_exprs(self, other)
3567 """Create the Z3 expression bitwise-or `self | other`.
3569 >>> x = BitVec('x', 32)
3570 >>> y = BitVec('y', 32)
3576 a, b = _coerce_exprs(self, other)
3580 """Create the Z3 expression bitwise-or `other | self`.
3582 >>> x = BitVec('x', 32)
3586 a, b = _coerce_exprs(self, other)
3590 """Create the Z3 expression bitwise-and `self & other`.
3592 >>> x = BitVec('x', 32)
3593 >>> y = BitVec('y', 32)
3599 a, b = _coerce_exprs(self, other)
3603 """Create the Z3 expression bitwise-or `other & self`.
3605 >>> x = BitVec('x', 32)
3609 a, b = _coerce_exprs(self, other)
3613 """Create the Z3 expression bitwise-xor `self ^ other`.
3615 >>> x = BitVec('x', 32)
3616 >>> y = BitVec('y', 32)
3622 a, b = _coerce_exprs(self, other)
3626 """Create the Z3 expression bitwise-xor `other ^ self`.
3628 >>> x = BitVec('x', 32)
3632 a, b = _coerce_exprs(self, other)
3638 >>> x = BitVec('x', 32)
3645 """Return an expression representing `-self`.
3647 >>> x = BitVec('x', 32)
3656 """Create the Z3 expression bitwise-not `~self`.
3658 >>> x = BitVec('x', 32)
3667 """Create the Z3 expression (signed) division `self / other`.
3669 Use the function UDiv() for unsigned division.
3671 >>> x = BitVec('x', 32)
3672 >>> y = BitVec('y', 32)
3679 >>> UDiv(x, y).sexpr()
3682 a, b = _coerce_exprs(self, other)
3686 """Create the Z3 expression (signed) division `self / other`."""
3687 return self.
__div____div__(other)
3690 """Create the Z3 expression (signed) division `other / self`.
3692 Use the function UDiv() for unsigned division.
3694 >>> x = BitVec('x', 32)
3697 >>> (10 / x).sexpr()
3698 '(bvsdiv #x0000000a x)'
3699 >>> UDiv(10, x).sexpr()
3700 '(bvudiv #x0000000a x)'
3702 a, b = _coerce_exprs(self, other)
3706 """Create the Z3 expression (signed) division `other / self`."""
3707 return self.
__rdiv____rdiv__(other)
3710 """Create the Z3 expression (signed) mod `self % other`.
3712 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3714 >>> x = BitVec('x', 32)
3715 >>> y = BitVec('y', 32)
3722 >>> URem(x, y).sexpr()
3724 >>> SRem(x, y).sexpr()
3727 a, b = _coerce_exprs(self, other)
3731 """Create the Z3 expression (signed) mod `other % self`.
3733 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3735 >>> x = BitVec('x', 32)
3738 >>> (10 % x).sexpr()
3739 '(bvsmod #x0000000a x)'
3740 >>> URem(10, x).sexpr()
3741 '(bvurem #x0000000a x)'
3742 >>> SRem(10, x).sexpr()
3743 '(bvsrem #x0000000a x)'
3745 a, b = _coerce_exprs(self, other)
3749 """Create the Z3 expression (signed) `other <= self`.
3751 Use the function ULE() for unsigned less than or equal to.
3753 >>> x, y = BitVecs('x y', 32)
3756 >>> (x <= y).sexpr()
3758 >>> ULE(x, y).sexpr()
3761 a, b = _coerce_exprs(self, other)
3765 """Create the Z3 expression (signed) `other < self`.
3767 Use the function ULT() for unsigned less than.
3769 >>> x, y = BitVecs('x y', 32)
3774 >>> ULT(x, y).sexpr()
3777 a, b = _coerce_exprs(self, other)
3781 """Create the Z3 expression (signed) `other > self`.
3783 Use the function UGT() for unsigned greater than.
3785 >>> x, y = BitVecs('x y', 32)
3790 >>> UGT(x, y).sexpr()
3793 a, b = _coerce_exprs(self, other)
3797 """Create the Z3 expression (signed) `other >= self`.
3799 Use the function UGE() for unsigned greater than or equal to.
3801 >>> x, y = BitVecs('x y', 32)
3804 >>> (x >= y).sexpr()
3806 >>> UGE(x, y).sexpr()
3809 a, b = _coerce_exprs(self, other)
3813 """Create the Z3 expression (arithmetical) right shift `self >> other`
3815 Use the function LShR() for the right logical shift
3817 >>> x, y = BitVecs('x y', 32)
3820 >>> (x >> y).sexpr()
3822 >>> LShR(x, y).sexpr()
3826 >>> BitVecVal(4, 3).as_signed_long()
3828 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3830 >>> simplify(BitVecVal(4, 3) >> 1)
3832 >>> simplify(LShR(BitVecVal(4, 3), 1))
3834 >>> simplify(BitVecVal(2, 3) >> 1)
3836 >>> simplify(LShR(BitVecVal(2, 3), 1))
3839 a, b = _coerce_exprs(self, other)
3843 """Create the Z3 expression left shift `self << other`
3845 >>> x, y = BitVecs('x y', 32)
3848 >>> (x << y).sexpr()
3850 >>> simplify(BitVecVal(2, 3) << 1)
3853 a, b = _coerce_exprs(self, other)
3857 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3859 Use the function LShR() for the right logical shift
3861 >>> x = BitVec('x', 32)
3864 >>> (10 >> x).sexpr()
3865 '(bvashr #x0000000a x)'
3867 a, b = _coerce_exprs(self, other)
3871 """Create the Z3 expression left shift `other << self`.
3873 Use the function LShR() for the right logical shift
3875 >>> x = BitVec('x', 32)
3878 >>> (10 << x).sexpr()
3879 '(bvshl #x0000000a x)'
3881 a, b = _coerce_exprs(self, other)
3886 """Bit-vector values."""
3889 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3891 >>> v = BitVecVal(0xbadc0de, 32)
3894 >>> print("0x%.8x" % v.as_long())
3900 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3901 The most significant bit is assumed to be the sign.
3903 >>> BitVecVal(4, 3).as_signed_long()
3905 >>> BitVecVal(7, 3).as_signed_long()
3907 >>> BitVecVal(3, 3).as_signed_long()
3909 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3911 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3914 sz = self.
sizesize()
3916 if val >= 2**(sz - 1):
3918 if val < -2**(sz - 1):
3930 """Return `True` if `a` is a Z3 bit-vector expression.
3932 >>> b = BitVec('b', 32)
3940 return isinstance(a, BitVecRef)
3944 """Return `True` if `a` is a Z3 bit-vector numeral value.
3946 >>> b = BitVec('b', 32)
3949 >>> b = BitVecVal(10, 32)
3955 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3959 """Return the Z3 expression BV2Int(a).
3961 >>> b = BitVec('b', 3)
3962 >>> BV2Int(b).sort()
3967 >>> x > BV2Int(b, is_signed=False)
3969 >>> x > BV2Int(b, is_signed=True)
3970 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3971 >>> solve(x > BV2Int(b), b == 1, x < 3)
3975 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3982 """Return the z3 expression Int2BV(a, num_bits).
3983 It is a bit-vector of width num_bits and represents the
3984 modulo of a by 2^num_bits
3991 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3993 >>> Byte = BitVecSort(8)
3994 >>> Word = BitVecSort(16)
3997 >>> x = Const('x', Byte)
3998 >>> eq(x, BitVec('x', 8))
4006 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4008 >>> v = BitVecVal(10, 32)
4011 >>> print("0x%.8x" % v.as_long())
4023 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4024 If `ctx=None`, then the global context is used.
4026 >>> x = BitVec('x', 16)
4033 >>> word = BitVecSort(16)
4034 >>> x2 = BitVec('x', word)
4038 if isinstance(bv, BitVecSortRef):
4047 """Return a tuple of bit-vector constants of size bv.
4049 >>> x, y, z = BitVecs('x y z', 16)
4056 >>> Product(x, y, z)
4058 >>> simplify(Product(x, y, z))
4062 if isinstance(names, str):
4063 names = names.split(
" ")
4064 return [
BitVec(name, bv, ctx)
for name
in names]
4068 """Create a Z3 bit-vector concatenation expression.
4070 >>> v = BitVecVal(1, 4)
4071 >>> Concat(v, v+1, v)
4072 Concat(Concat(1, 1 + 1), 1)
4073 >>> simplify(Concat(v, v+1, v))
4075 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4078 args = _get_args(args)
4081 _z3_assert(sz >= 2,
"At least two arguments expected.")
4088 if is_seq(args[0])
or isinstance(args[0], str):
4089 args = [_coerce_seq(s, ctx)
for s
in args]
4091 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
4094 v[i] = args[i].as_ast()
4099 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
4102 v[i] = args[i].as_ast()
4106 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
4108 for i
in range(sz - 1):
4114 """Create a Z3 bit-vector extraction expression.
4115 Extract is overloaded to also work on sequence extraction.
4116 The functions SubString and SubSeq are redirected to Extract.
4117 For this case, the arguments are reinterpreted as:
4118 high - is a sequence (string)
4120 a - is the length to be extracted
4122 >>> x = BitVec('x', 8)
4123 >>> Extract(6, 2, x)
4125 >>> Extract(6, 2, x).sort()
4127 >>> simplify(Extract(StringVal("abcd"),2,1))
4130 if isinstance(high, str):
4134 offset, length = _coerce_exprs(low, a, s.ctx)
4137 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
4138 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
4139 "First and second arguments must be non negative integers")
4140 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
4144 def _check_bv_args(a, b):
4146 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
4150 """Create the Z3 expression (unsigned) `other <= self`.
4152 Use the operator <= for signed less than or equal to.
4154 >>> x, y = BitVecs('x y', 32)
4157 >>> (x <= y).sexpr()
4159 >>> ULE(x, y).sexpr()
4162 _check_bv_args(a, b)
4163 a, b = _coerce_exprs(a, b)
4168 """Create the Z3 expression (unsigned) `other < self`.
4170 Use the operator < for signed less than.
4172 >>> x, y = BitVecs('x y', 32)
4177 >>> ULT(x, y).sexpr()
4180 _check_bv_args(a, b)
4181 a, b = _coerce_exprs(a, b)
4186 """Create the Z3 expression (unsigned) `other >= self`.
4188 Use the operator >= for signed greater than or equal to.
4190 >>> x, y = BitVecs('x y', 32)
4193 >>> (x >= y).sexpr()
4195 >>> UGE(x, y).sexpr()
4198 _check_bv_args(a, b)
4199 a, b = _coerce_exprs(a, b)
4204 """Create the Z3 expression (unsigned) `other > self`.
4206 Use the operator > for signed greater than.
4208 >>> x, y = BitVecs('x y', 32)
4213 >>> UGT(x, y).sexpr()
4216 _check_bv_args(a, b)
4217 a, b = _coerce_exprs(a, b)
4222 """Create the Z3 expression (unsigned) division `self / other`.
4224 Use the operator / for signed division.
4226 >>> x = BitVec('x', 32)
4227 >>> y = BitVec('y', 32)
4230 >>> UDiv(x, y).sort()
4234 >>> UDiv(x, y).sexpr()
4237 _check_bv_args(a, b)
4238 a, b = _coerce_exprs(a, b)
4243 """Create the Z3 expression (unsigned) remainder `self % other`.
4245 Use the operator % for signed modulus, and SRem() for signed remainder.
4247 >>> x = BitVec('x', 32)
4248 >>> y = BitVec('y', 32)
4251 >>> URem(x, y).sort()
4255 >>> URem(x, y).sexpr()
4258 _check_bv_args(a, b)
4259 a, b = _coerce_exprs(a, b)
4264 """Create the Z3 expression signed remainder.
4266 Use the operator % for signed modulus, and URem() for unsigned remainder.
4268 >>> x = BitVec('x', 32)
4269 >>> y = BitVec('y', 32)
4272 >>> SRem(x, y).sort()
4276 >>> SRem(x, y).sexpr()
4279 _check_bv_args(a, b)
4280 a, b = _coerce_exprs(a, b)
4285 """Create the Z3 expression logical right shift.
4287 Use the operator >> for the arithmetical right shift.
4289 >>> x, y = BitVecs('x y', 32)
4292 >>> (x >> y).sexpr()
4294 >>> LShR(x, y).sexpr()
4298 >>> BitVecVal(4, 3).as_signed_long()
4300 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4302 >>> simplify(BitVecVal(4, 3) >> 1)
4304 >>> simplify(LShR(BitVecVal(4, 3), 1))
4306 >>> simplify(BitVecVal(2, 3) >> 1)
4308 >>> simplify(LShR(BitVecVal(2, 3), 1))
4311 _check_bv_args(a, b)
4312 a, b = _coerce_exprs(a, b)
4317 """Return an expression representing `a` rotated to the left `b` times.
4319 >>> a, b = BitVecs('a b', 16)
4320 >>> RotateLeft(a, b)
4322 >>> simplify(RotateLeft(a, 0))
4324 >>> simplify(RotateLeft(a, 16))
4327 _check_bv_args(a, b)
4328 a, b = _coerce_exprs(a, b)
4333 """Return an expression representing `a` rotated to the right `b` times.
4335 >>> a, b = BitVecs('a b', 16)
4336 >>> RotateRight(a, b)
4338 >>> simplify(RotateRight(a, 0))
4340 >>> simplify(RotateRight(a, 16))
4343 _check_bv_args(a, b)
4344 a, b = _coerce_exprs(a, b)
4349 """Return a bit-vector expression with `n` extra sign-bits.
4351 >>> x = BitVec('x', 16)
4352 >>> n = SignExt(8, x)
4359 >>> v0 = BitVecVal(2, 2)
4364 >>> v = simplify(SignExt(6, v0))
4369 >>> print("%.x" % v.as_long())
4373 _z3_assert(_is_int(n),
"First argument must be an integer")
4374 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4379 """Return a bit-vector expression with `n` extra zero-bits.
4381 >>> x = BitVec('x', 16)
4382 >>> n = ZeroExt(8, x)
4389 >>> v0 = BitVecVal(2, 2)
4394 >>> v = simplify(ZeroExt(6, v0))
4401 _z3_assert(_is_int(n),
"First argument must be an integer")
4402 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4407 """Return an expression representing `n` copies of `a`.
4409 >>> x = BitVec('x', 8)
4410 >>> n = RepeatBitVec(4, x)
4415 >>> v0 = BitVecVal(10, 4)
4416 >>> print("%.x" % v0.as_long())
4418 >>> v = simplify(RepeatBitVec(4, v0))
4421 >>> print("%.x" % v.as_long())
4425 _z3_assert(_is_int(n),
"First argument must be an integer")
4426 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4431 """Return the reduction-and expression of `a`."""
4433 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4438 """Return the reduction-or expression of `a`."""
4440 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4445 """A predicate the determines that bit-vector addition does not overflow"""
4446 _check_bv_args(a, b)
4447 a, b = _coerce_exprs(a, b)
4452 """A predicate the determines that signed bit-vector addition does not underflow"""
4453 _check_bv_args(a, b)
4454 a, b = _coerce_exprs(a, b)
4459 """A predicate the determines that bit-vector subtraction does not overflow"""
4460 _check_bv_args(a, b)
4461 a, b = _coerce_exprs(a, b)
4466 """A predicate the determines that bit-vector subtraction does not underflow"""
4467 _check_bv_args(a, b)
4468 a, b = _coerce_exprs(a, b)
4473 """A predicate the determines that bit-vector signed division does not overflow"""
4474 _check_bv_args(a, b)
4475 a, b = _coerce_exprs(a, b)
4480 """A predicate the determines that bit-vector unary negation does not overflow"""
4482 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4487 """A predicate the determines that bit-vector multiplication does not overflow"""
4488 _check_bv_args(a, b)
4489 a, b = _coerce_exprs(a, b)
4494 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4495 _check_bv_args(a, b)
4496 a, b = _coerce_exprs(a, b)
4510 """Return the domain of the array sort `self`.
4512 >>> A = ArraySort(IntSort(), BoolSort())
4519 """Return the domain of the array sort `self`.
4524 """Return the range of the array sort `self`.
4526 >>> A = ArraySort(IntSort(), BoolSort())
4534 """Array expressions. """
4537 """Return the array sort of the array expression `self`.
4539 >>> a = Array('a', IntSort(), BoolSort())
4546 """Shorthand for `self.sort().domain()`.
4548 >>> a = Array('a', IntSort(), BoolSort())
4555 """Shorthand for self.sort().domain_n(i)`."""
4559 """Shorthand for `self.sort().range()`.
4561 >>> a = Array('a', IntSort(), BoolSort())
4568 """Return the Z3 expression `self[arg]`.
4570 >>> a = Array('a', IntSort(), BoolSort())
4577 return _array_select(self, arg)
4583 def _array_select(ar, arg):
4584 if isinstance(arg, tuple):
4585 args = [ar.domain_n(i).cast(arg[i])
for i
in range(len(arg))]
4586 _args, sz = _to_ast_array(args)
4587 return _to_expr_ref(
Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4588 arg = ar.domain().cast(arg)
4589 return _to_expr_ref(
Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4597 """Return `True` if `a` is a Z3 array expression.
4599 >>> a = Array('a', IntSort(), IntSort())
4602 >>> is_array(Store(a, 0, 1))
4607 return isinstance(a, ArrayRef)
4611 """Return `True` if `a` is a Z3 constant array.
4613 >>> a = K(IntSort(), 10)
4614 >>> is_const_array(a)
4616 >>> a = Array('a', IntSort(), IntSort())
4617 >>> is_const_array(a)
4624 """Return `True` if `a` is a Z3 constant array.
4626 >>> a = K(IntSort(), 10)
4629 >>> a = Array('a', IntSort(), IntSort())
4637 """Return `True` if `a` is a Z3 map array expression.
4639 >>> f = Function('f', IntSort(), IntSort())
4640 >>> b = Array('b', IntSort(), IntSort())
4653 """Return `True` if `a` is a Z3 default array expression.
4654 >>> d = Default(K(IntSort(), 10))
4658 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4662 """Return the function declaration associated with a Z3 map array expression.
4664 >>> f = Function('f', IntSort(), IntSort())
4665 >>> b = Array('b', IntSort(), IntSort())
4667 >>> eq(f, get_map_func(a))
4671 >>> get_map_func(a)(0)
4675 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4686 """Return the Z3 array sort with the given domain and range sorts.
4688 >>> A = ArraySort(IntSort(), BoolSort())
4695 >>> AA = ArraySort(IntSort(), A)
4697 Array(Int, Array(Int, Bool))
4699 sig = _get_args(sig)
4701 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4702 arity = len(sig) - 1
4707 _z3_assert(
is_sort(s),
"Z3 sort expected")
4708 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4712 dom = (Sort * arity)()
4713 for i
in range(arity):
4719 """Return an array constant named `name` with the given domain and range sorts.
4721 >>> a = Array('a', IntSort(), IntSort())
4733 """Return a Z3 store array expression.
4735 >>> a = Array('a', IntSort(), IntSort())
4736 >>> i, v = Ints('i v')
4737 >>> s = Update(a, i, v)
4740 >>> prove(s[i] == v)
4743 >>> prove(Implies(i != j, s[j] == a[j]))
4747 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4748 args = _get_args(args)
4751 raise Z3Exception(
"array update requires index and value arguments")
4755 i = a.sort().domain().cast(i)
4756 v = a.sort().
range().cast(v)
4757 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4758 v = a.sort().
range().cast(args[-1])
4759 idxs = [a.sort().domain_n(i).cast(args[i])
for i
in range(len(args)-1)]
4760 _args, sz = _to_ast_array(idxs)
4761 return _to_expr_ref(
Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4765 """ Return a default value for array expression.
4766 >>> b = K(IntSort(), 1)
4767 >>> prove(Default(b) == 1)
4771 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4776 """Return a Z3 store array expression.
4778 >>> a = Array('a', IntSort(), IntSort())
4779 >>> i, v = Ints('i v')
4780 >>> s = Store(a, i, v)
4783 >>> prove(s[i] == v)
4786 >>> prove(Implies(i != j, s[j] == a[j]))
4793 """Return a Z3 select array expression.
4795 >>> a = Array('a', IntSort(), IntSort())
4799 >>> eq(Select(a, i), a[i])
4802 args = _get_args(args)
4804 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4809 """Return a Z3 map array expression.
4811 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4812 >>> a1 = Array('a1', IntSort(), IntSort())
4813 >>> a2 = Array('a2', IntSort(), IntSort())
4814 >>> b = Map(f, a1, a2)
4817 >>> prove(b[0] == f(a1[0], a2[0]))
4820 args = _get_args(args)
4822 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4823 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4824 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4825 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4826 _args, sz = _to_ast_array(args)
4832 """Return a Z3 constant array expression.
4834 >>> a = K(IntSort(), 10)
4846 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4849 v = _py2expr(v, ctx)
4854 """Return extensionality index for one-dimensional arrays.
4855 >> a, b = Consts('a b', SetSort(IntSort()))
4862 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4867 k = _py2expr(k, ctx)
4872 """Return `True` if `a` is a Z3 array select application.
4874 >>> a = Array('a', IntSort(), IntSort())
4885 """Return `True` if `a` is a Z3 array store application.
4887 >>> a = Array('a', IntSort(), IntSort())
4890 >>> is_store(Store(a, 0, 1))
4903 """ Create a set sort over element sort s"""
4908 """Create the empty set
4909 >>> EmptySet(IntSort())
4917 """Create the full set
4918 >>> FullSet(IntSort())
4926 """ Take the union of sets
4927 >>> a = Const('a', SetSort(IntSort()))
4928 >>> b = Const('b', SetSort(IntSort()))
4932 args = _get_args(args)
4933 ctx = _ctx_from_ast_arg_list(args)
4934 _args, sz = _to_ast_array(args)
4939 """ Take the union of sets
4940 >>> a = Const('a', SetSort(IntSort()))
4941 >>> b = Const('b', SetSort(IntSort()))
4942 >>> SetIntersect(a, b)
4945 args = _get_args(args)
4946 ctx = _ctx_from_ast_arg_list(args)
4947 _args, sz = _to_ast_array(args)
4952 """ Add element e to set s
4953 >>> a = Const('a', SetSort(IntSort()))
4957 ctx = _ctx_from_ast_arg_list([s, e])
4958 e = _py2expr(e, ctx)
4963 """ Remove element e to set s
4964 >>> a = Const('a', SetSort(IntSort()))
4968 ctx = _ctx_from_ast_arg_list([s, e])
4969 e = _py2expr(e, ctx)
4974 """ The complement of set s
4975 >>> a = Const('a', SetSort(IntSort()))
4976 >>> SetComplement(a)
4984 """ The set difference of a and b
4985 >>> a = Const('a', SetSort(IntSort()))
4986 >>> b = Const('b', SetSort(IntSort()))
4987 >>> SetDifference(a, b)
4990 ctx = _ctx_from_ast_arg_list([a, b])
4995 """ Check if e is a member of set s
4996 >>> a = Const('a', SetSort(IntSort()))
5000 ctx = _ctx_from_ast_arg_list([s, e])
5001 e = _py2expr(e, ctx)
5006 """ Check if a is a subset of b
5007 >>> a = Const('a', SetSort(IntSort()))
5008 >>> b = Const('b', SetSort(IntSort()))
5012 ctx = _ctx_from_ast_arg_list([a, b])
5022 def _valid_accessor(acc):
5023 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5024 if not isinstance(acc, tuple):
5028 return isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
5032 """Helper class for declaring Z3 datatypes.
5034 >>> List = Datatype('List')
5035 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5036 >>> List.declare('nil')
5037 >>> List = List.create()
5038 >>> # List is now a Z3 declaration
5041 >>> List.cons(10, List.nil)
5043 >>> List.cons(10, List.nil).sort()
5045 >>> cons = List.cons
5049 >>> n = cons(1, cons(0, nil))
5051 cons(1, cons(0, nil))
5052 >>> simplify(cdr(n))
5054 >>> simplify(car(n))
5065 r.constructors = copy.deepcopy(self.
constructorsconstructors)
5070 _z3_assert(isinstance(name, str),
"String expected")
5071 _z3_assert(isinstance(rec_name, str),
"String expected")
5073 all([_valid_accessor(a)
for a
in args]),
5074 "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)",
5076 self.
constructorsconstructors.append((name, rec_name, args))
5079 """Declare constructor named `name` with the given accessors `args`.
5080 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort
5081 or a reference to the datatypes being declared.
5083 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
5084 declares the constructor named `cons` that builds a new List using an integer and a List.
5085 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer
5086 of a `cons` cell, and `cdr` the list of a `cons` cell. After all constructors were declared,
5087 we use the method create() to create the actual datatype in Z3.
5089 >>> List = Datatype('List')
5090 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5091 >>> List.declare('nil')
5092 >>> List = List.create()
5095 _z3_assert(isinstance(name, str),
"String expected")
5096 _z3_assert(name !=
"",
"Constructor name cannot be empty")
5097 return self.
declare_coredeclare_core(name,
"is-" + name, *args)
5103 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
5105 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
5107 >>> List = Datatype('List')
5108 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5109 >>> List.declare('nil')
5110 >>> List = List.create()
5113 >>> List.cons(10, List.nil)
5120 """Auxiliary object used to create Z3 datatypes."""
5127 if self.
ctxctx.ref()
is not None:
5132 """Auxiliary object used to create Z3 datatypes."""
5139 if self.
ctxctx.ref()
is not None:
5144 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5146 In the following example we define a Tree-List using two mutually recursive datatypes.
5148 >>> TreeList = Datatype('TreeList')
5149 >>> Tree = Datatype('Tree')
5150 >>> # Tree has two constructors: leaf and node
5151 >>> Tree.declare('leaf', ('val', IntSort()))
5152 >>> # a node contains a list of trees
5153 >>> Tree.declare('node', ('children', TreeList))
5154 >>> TreeList.declare('nil')
5155 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5156 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5157 >>> Tree.val(Tree.leaf(10))
5159 >>> simplify(Tree.val(Tree.leaf(10)))
5161 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5163 node(cons(leaf(10), cons(leaf(20), nil)))
5164 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5165 >>> simplify(n2 == n1)
5167 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5172 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
5173 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
5174 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
5175 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
5178 names = (Symbol * num)()
5179 out = (Sort * num)()
5180 clists = (ConstructorList * num)()
5182 for i
in range(num):
5185 num_cs = len(d.constructors)
5186 cs = (Constructor * num_cs)()
5187 for j
in range(num_cs):
5188 c = d.constructors[j]
5193 fnames = (Symbol * num_fs)()
5194 sorts = (Sort * num_fs)()
5195 refs = (ctypes.c_uint * num_fs)()
5196 for k
in range(num_fs):
5200 if isinstance(ftype, Datatype):
5203 ds.count(ftype) == 1,
5204 "One and only one occurrence of each datatype is expected",
5207 refs[k] = ds.index(ftype)
5210 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
5211 sorts[k] = ftype.ast
5220 for i
in range(num):
5222 num_cs = dref.num_constructors()
5223 for j
in range(num_cs):
5224 cref = dref.constructor(j)
5225 cref_name = cref.name()
5226 cref_arity = cref.arity()
5227 if cref.arity() == 0:
5229 setattr(dref, cref_name, cref)
5230 rref = dref.recognizer(j)
5231 setattr(dref,
"is_" + cref_name, rref)
5232 for k
in range(cref_arity):
5233 aref = dref.accessor(j, k)
5234 setattr(dref, aref.name(), aref)
5236 return tuple(result)
5240 """Datatype sorts."""
5243 """Return the number of constructors in the given Z3 datatype.
5245 >>> List = Datatype('List')
5246 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5247 >>> List.declare('nil')
5248 >>> List = List.create()
5249 >>> # List is now a Z3 declaration
5250 >>> List.num_constructors()
5256 """Return a constructor of the datatype `self`.
5258 >>> List = Datatype('List')
5259 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5260 >>> List.declare('nil')
5261 >>> List = List.create()
5262 >>> # List is now a Z3 declaration
5263 >>> List.num_constructors()
5265 >>> List.constructor(0)
5267 >>> List.constructor(1)
5271 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5275 """In Z3, each constructor has an associated recognizer predicate.
5277 If the constructor is named `name`, then the recognizer `is_name`.
5279 >>> List = Datatype('List')
5280 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5281 >>> List.declare('nil')
5282 >>> List = List.create()
5283 >>> # List is now a Z3 declaration
5284 >>> List.num_constructors()
5286 >>> List.recognizer(0)
5288 >>> List.recognizer(1)
5290 >>> simplify(List.is_nil(List.cons(10, List.nil)))
5292 >>> simplify(List.is_cons(List.cons(10, List.nil)))
5294 >>> l = Const('l', List)
5295 >>> simplify(List.is_cons(l))
5299 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid recognizer index")
5303 """In Z3, each constructor has 0 or more accessor.
5304 The number of accessors is equal to the arity of the constructor.
5306 >>> List = Datatype('List')
5307 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5308 >>> List.declare('nil')
5309 >>> List = List.create()
5310 >>> List.num_constructors()
5312 >>> List.constructor(0)
5314 >>> num_accs = List.constructor(0).arity()
5317 >>> List.accessor(0, 0)
5319 >>> List.accessor(0, 1)
5321 >>> List.constructor(1)
5323 >>> num_accs = List.constructor(1).arity()
5328 _z3_assert(i < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5329 _z3_assert(j < self.
constructorconstructor(i).arity(),
"Invalid accessor index")
5337 """Datatype expressions."""
5340 """Return the datatype sort of the datatype expression `self`."""
5345 """Create a named tuple sort base on a set of underlying sorts
5347 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5350 projects = [(
"project%d" % i, sorts[i])
for i
in range(len(sorts))]
5351 tuple.declare(name, *projects)
5352 tuple = tuple.create()
5353 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5357 """Create a named tagged union sort base on a set of underlying sorts
5359 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5362 for i
in range(len(sorts)):
5363 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5365 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5369 """Return a new enumeration sort named `name` containing the given values.
5371 The result is a pair (sort, list of constants).
5373 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5376 _z3_assert(isinstance(name, str),
"Name must be a string")
5377 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5378 _z3_assert(len(values) > 0,
"At least one value expected")
5381 _val_names = (Symbol * num)()
5382 for i
in range(num):
5384 _values = (FuncDecl * num)()
5385 _testers = (FuncDecl * num)()
5389 for i
in range(num):
5391 V = [a()
for a
in V]
5402 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5404 Consider using the function `args2params` to create instances of this object.
5412 self.
paramsparams = params
5419 if self.
ctxctx.ref()
is not None:
5423 """Set parameter name with value val."""
5425 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5427 if isinstance(val, bool):
5431 elif isinstance(val, float):
5433 elif isinstance(val, str):
5437 _z3_assert(
False,
"invalid parameter value")
5443 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5448 """Convert python arguments into a Z3_params object.
5449 A ':' is added to the keywords, and '_' is replaced with '-'
5451 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5452 (params model true relevancy 2 elim_and true)
5455 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5471 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5475 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5481 return ParamsDescrsRef(self.
descrdescr, self.
ctxctx)
5484 if self.
ctxctx.ref()
is not None:
5488 """Return the size of in the parameter description `self`.
5493 """Return the size of in the parameter description `self`.
5495 return self.
sizesize()
5498 """Return the i-th parameter name in the parameter description `self`.
5503 """Return the kind of the parameter named `n`.
5508 """Return the documentation string of the parameter named `n`.
5529 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5531 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5532 A goal has a solution if one of its subgoals has a solution.
5533 A goal is unsatisfiable if all subgoals are unsatisfiable.
5536 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5538 _z3_assert(goal
is None or ctx
is not None,
5539 "If goal is different from None, then ctx must be also different from None")
5542 if self.
goalgoal
is None:
5547 if self.
goalgoal
is not None and self.
ctxctx.ref()
is not None:
5551 """Return the depth of the goal `self`.
5552 The depth corresponds to the number of tactics applied to `self`.
5554 >>> x, y = Ints('x y')
5556 >>> g.add(x == 0, y >= x + 1)
5559 >>> r = Then('simplify', 'solve-eqs')(g)
5560 >>> # r has 1 subgoal
5569 """Return `True` if `self` contains the `False` constraints.
5571 >>> x, y = Ints('x y')
5573 >>> g.inconsistent()
5575 >>> g.add(x == 0, x == 1)
5578 >>> g.inconsistent()
5580 >>> g2 = Tactic('propagate-values')(g)[0]
5581 >>> g2.inconsistent()
5587 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5590 >>> g.prec() == Z3_GOAL_PRECISE
5592 >>> x, y = Ints('x y')
5593 >>> g.add(x == y + 1)
5594 >>> g.prec() == Z3_GOAL_PRECISE
5596 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5599 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5600 >>> g2.prec() == Z3_GOAL_PRECISE
5602 >>> g2.prec() == Z3_GOAL_UNDER
5608 """Alias for `prec()`.
5611 >>> g.precision() == Z3_GOAL_PRECISE
5614 return self.
precprec()
5617 """Return the number of constraints in the goal `self`.
5622 >>> x, y = Ints('x y')
5623 >>> g.add(x == 0, y > x)
5630 """Return the number of constraints in the goal `self`.
5635 >>> x, y = Ints('x y')
5636 >>> g.add(x == 0, y > x)
5640 return self.
sizesize()
5643 """Return a constraint in the goal `self`.
5646 >>> x, y = Ints('x y')
5647 >>> g.add(x == 0, y > x)
5656 """Return a constraint in the goal `self`.
5659 >>> x, y = Ints('x y')
5660 >>> g.add(x == 0, y > x)
5666 if arg >= len(self):
5668 return self.
getget(arg)
5671 """Assert constraints into the goal.
5675 >>> g.assert_exprs(x > 0, x < 2)
5679 args = _get_args(args)
5690 >>> g.append(x > 0, x < 2)
5701 >>> g.insert(x > 0, x < 2)
5712 >>> g.add(x > 0, x < 2)
5719 """Retrieve model from a satisfiable goal
5720 >>> a, b = Ints('a b')
5722 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5723 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5726 [Or(b == 0, b == 1), Not(0 <= b)]
5728 [Or(b == 0, b == 1), Not(1 <= b)]
5729 >>> # Remark: the subgoal r[0] is unsatisfiable
5730 >>> # Creating a solver for solving the second subgoal
5737 >>> # Model s.model() does not assign a value to `a`
5738 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5739 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5740 >>> r[1].convert_model(s.model())
5744 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5748 return obj_to_string(self)
5751 """Return a textual representation of the s-expression representing the goal."""
5755 """Return a textual representation of the goal in DIMACS format."""
5759 """Copy goal `self` to context `target`.
5767 >>> g2 = g.translate(c2)
5770 >>> g.ctx == main_ctx()
5774 >>> g2.ctx == main_ctx()
5778 _z3_assert(isinstance(target, Context),
"target must be a context")
5788 """Return a new simplified goal.
5790 This method is essentially invoking the simplify tactic.
5794 >>> g.add(x + 1 >= 2)
5797 >>> g2 = g.simplify()
5800 >>> # g was not modified
5805 return t.apply(self, *arguments, **keywords)[0]
5808 """Return goal `self` as a single Z3 expression.
5825 return self.
getget(0)
5827 return And([self.
getget(i)
for i
in range(len(self))], self.
ctxctx)
5837 """A collection (vector) of ASTs."""
5846 assert ctx
is not None
5851 if self.
vectorvector
is not None and self.
ctxctx.ref()
is not None:
5855 """Return the size of the vector `self`.
5860 >>> A.push(Int('x'))
5861 >>> A.push(Int('x'))
5868 """Return the AST at position `i`.
5871 >>> A.push(Int('x') + 1)
5872 >>> A.push(Int('y'))
5879 if isinstance(i, int):
5883 if i >= self.
__len____len__():
5887 elif isinstance(i, slice):
5890 result.append(_to_ast_ref(
5897 """Update AST at position `i`.
5900 >>> A.push(Int('x') + 1)
5901 >>> A.push(Int('y'))
5908 if i >= self.
__len____len__():
5913 """Add `v` in the end of the vector.
5918 >>> A.push(Int('x'))
5925 """Resize the vector to `sz` elements.
5931 >>> for i in range(10): A[i] = Int('x')
5938 """Return `True` if the vector contains `item`.
5961 """Copy vector `self` to context `other_ctx`.
5967 >>> B = A.translate(c2)
5983 return obj_to_string(self)
5986 """Return a textual representation of the s-expression representing the vector."""
5997 """A mapping from ASTs to ASTs."""
6006 assert ctx
is not None
6014 if self.
mapmap
is not None and self.
ctxctx.ref()
is not None:
6018 """Return the size of the map.
6024 >>> M[x] = IntVal(1)
6031 """Return `True` if the map contains key `key`.
6044 """Retrieve the value associated with key `key`.
6055 """Add/Update key `k` with value `v`.
6064 >>> M[x] = IntVal(1)
6074 """Remove the entry associated with key `k`.
6088 """Remove all entries from the map.
6093 >>> M[x+x] = IntVal(1)
6103 """Return an AstVector containing all keys in the map.
6108 >>> M[x+x] = IntVal(1)
6122 """Store the value of the interpretation of a function in a particular point."""
6133 if self.
ctxctx.ref()
is not None:
6137 """Return the number of arguments in the given entry.
6139 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6141 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6146 >>> f_i.num_entries()
6148 >>> e = f_i.entry(0)
6155 """Return the value of argument `idx`.
6157 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6159 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6164 >>> f_i.num_entries()
6166 >>> e = f_i.entry(0)
6177 ... except IndexError:
6178 ... print("index error")
6186 """Return the value of the function at point `self`.
6188 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6190 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6195 >>> f_i.num_entries()
6197 >>> e = f_i.entry(0)
6208 """Return entry `self` as a Python list.
6209 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6211 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6216 >>> f_i.num_entries()
6218 >>> e = f_i.entry(0)
6223 args.append(self.
valuevalue())
6227 return repr(self.
as_listas_list())
6231 """Stores the interpretation of a function in a Z3 model."""
6236 if self.
ff
is not None:
6240 if self.
ff
is not None and self.
ctxctx.ref()
is not None:
6245 Return the `else` value for a function interpretation.
6246 Return None if Z3 did not specify the `else` value for
6249 >>> f = Function('f', IntSort(), IntSort())
6251 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6257 >>> m[f].else_value()
6262 return _to_expr_ref(r, self.
ctxctx)
6267 """Return the number of entries/points in the function interpretation `self`.
6269 >>> f = Function('f', IntSort(), IntSort())
6271 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6277 >>> m[f].num_entries()
6283 """Return the number of arguments for each entry in the function interpretation `self`.
6285 >>> f = Function('f', IntSort(), IntSort())
6287 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6297 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
6299 >>> f = Function('f', IntSort(), IntSort())
6301 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6307 >>> m[f].num_entries()
6317 """Copy model 'self' to context 'other_ctx'.
6328 """Return the function interpretation as a Python list.
6329 >>> f = Function('f', IntSort(), IntSort())
6331 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6345 return obj_to_string(self)
6349 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6352 assert ctx
is not None
6358 if self.
ctxctx.ref()
is not None:
6362 return obj_to_string(self)
6365 """Return a textual representation of the s-expression representing the model."""
6368 def eval(self, t, model_completion=False):
6369 """Evaluate the expression `t` in the model `self`.
6370 If `model_completion` is enabled, then a default interpretation is automatically added
6371 for symbols that do not have an interpretation in the model `self`.
6375 >>> s.add(x > 0, x < 2)
6388 >>> m.eval(y, model_completion=True)
6390 >>> # Now, m contains an interpretation for y
6396 return _to_expr_ref(r[0], self.
ctxctx)
6397 raise Z3Exception(
"failed to evaluate expression in the model")
6400 """Alias for `eval`.
6404 >>> s.add(x > 0, x < 2)
6408 >>> m.evaluate(x + 1)
6410 >>> m.evaluate(x == 1)
6413 >>> m.evaluate(y + x)
6417 >>> m.evaluate(y, model_completion=True)
6419 >>> # Now, m contains an interpretation for y
6420 >>> m.evaluate(y + x)
6423 return self.
evaleval(t, model_completion)
6426 """Return the number of constant and function declarations in the model `self`.
6428 >>> f = Function('f', IntSort(), IntSort())
6431 >>> s.add(x > 0, f(x) != x)
6440 return num_consts + num_funcs
6443 """Return the interpretation for a given declaration or constant.
6445 >>> f = Function('f', IntSort(), IntSort())
6448 >>> s.add(x > 0, x < 2, f(x) == 0)
6458 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6462 if decl.arity() == 0:
6464 if _r.value
is None:
6466 r = _to_expr_ref(_r, self.
ctxctx)
6477 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6479 >>> A = DeclareSort('A')
6480 >>> a, b = Consts('a b', A)
6492 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6494 >>> A = DeclareSort('A')
6495 >>> B = DeclareSort('B')
6496 >>> a1, a2 = Consts('a1 a2', A)
6497 >>> b1, b2 = Consts('b1 b2', B)
6499 >>> s.add(a1 != a2, b1 != b2)
6515 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6517 >>> A = DeclareSort('A')
6518 >>> B = DeclareSort('B')
6519 >>> a1, a2 = Consts('a1 a2', A)
6520 >>> b1, b2 = Consts('b1 b2', B)
6522 >>> s.add(a1 != a2, b1 != b2)
6532 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6534 >>> A = DeclareSort('A')
6535 >>> a, b = Consts('a b', A)
6541 >>> m.get_universe(A)
6545 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6552 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
6553 If `idx` is a declaration, then the actual interpretation is returned.
6555 The elements can be retrieved using position or the actual declaration.
6557 >>> f = Function('f', IntSort(), IntSort())
6560 >>> s.add(x > 0, x < 2, f(x) == 0)
6574 >>> for d in m: print("%s -> %s" % (d, m[d]))
6579 if idx >= len(self):
6582 if (idx < num_consts):
6586 if isinstance(idx, FuncDeclRef):
6590 if isinstance(idx, SortRef):
6593 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6597 """Return a list with all symbols that have an interpretation in the model `self`.
6598 >>> f = Function('f', IntSort(), IntSort())
6601 >>> s.add(x > 0, x < 2, f(x) == 0)
6616 """Update the interpretation of a constant"""
6619 if is_func_decl(x)
and x.arity() != 0
and isinstance(value, FuncInterp):
6623 for i
in range(value.num_entries()):
6628 v.push(entry.arg_value(j))
6633 raise Z3Exception(
"Expecting 0-ary function or constant expression")
6634 value = _py2expr(value)
6638 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6641 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6658 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6659 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6663 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6665 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6676 """Statistics for `Solver.check()`."""
6687 if self.
ctxctx.ref()
is not None:
6694 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6697 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6700 out.write(u(
"<tr>"))
6702 out.write(u(
"<td>%s</td><td>%s</td></tr>" % (k, v)))
6703 out.write(u(
"</table>"))
6704 return out.getvalue()
6709 """Return the number of statistical counters.
6712 >>> s = Then('simplify', 'nlsat').solver()
6716 >>> st = s.statistics()
6723 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6726 >>> s = Then('simplify', 'nlsat').solver()
6730 >>> st = s.statistics()
6734 ('nlsat propagations', 2)
6738 if idx >= len(self):
6747 """Return the list of statistical counters.
6750 >>> s = Then('simplify', 'nlsat').solver()
6754 >>> st = s.statistics()
6759 """Return the value of a particular statistical counter.
6762 >>> s = Then('simplify', 'nlsat').solver()
6766 >>> st = s.statistics()
6767 >>> st.get_key_value('nlsat propagations')
6770 for idx
in range(len(self)):
6776 raise Z3Exception(
"unknown key")
6779 """Access the value of statistical using attributes.
6781 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6782 we should use '_' (e.g., 'nlsat_propagations').
6785 >>> s = Then('simplify', 'nlsat').solver()
6789 >>> st = s.statistics()
6790 >>> st.nlsat_propagations
6795 key = name.replace(
"_",
" ")
6799 raise AttributeError
6809 """Represents the result of a satisfiability check: sat, unsat, unknown.
6815 >>> isinstance(r, CheckSatResult)
6826 return isinstance(other, CheckSatResult)
and self.
rr == other.r
6829 return not self.
__eq____eq__(other)
6833 if self.
rr == Z3_L_TRUE:
6835 elif self.
rr == Z3_L_FALSE:
6836 return "<b>unsat</b>"
6838 return "<b>unknown</b>"
6840 if self.
rr == Z3_L_TRUE:
6842 elif self.
rr == Z3_L_FALSE:
6847 def _repr_html_(self):
6848 in_html = in_html_mode()
6851 set_html_mode(in_html)
6862 Solver API provides methods for implementing the main SMT 2.0 commands:
6863 push, pop, check, get-model, etc.
6866 def __init__(self, solver=None, ctx=None, logFile=None):
6867 assert solver
is None or ctx
is not None
6874 self.
solversolver = solver
6876 if logFile
is not None:
6877 self.
setset(
"smtlib2_log", logFile)
6880 if self.
solversolver
is not None and self.
ctxctx.ref()
is not None:
6884 """Set a configuration option.
6885 The method `help()` return a string containing all available options.
6888 >>> # The option MBQI can be set using three different approaches.
6889 >>> s.set(mbqi=True)
6890 >>> s.set('MBQI', True)
6891 >>> s.set(':mbqi', True)
6897 """Create a backtracking point.
6919 """Backtrack \\c num backtracking points.
6941 """Return the current number of backtracking points.
6959 """Remove all asserted constraints and backtracking points created using `push()`.
6973 """Assert constraints into the solver.
6977 >>> s.assert_exprs(x > 0, x < 2)
6981 args = _get_args(args)
6984 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6992 """Assert constraints into the solver.
6996 >>> s.add(x > 0, x < 2)
7007 """Assert constraints into the solver.
7011 >>> s.append(x > 0, x < 2)
7018 """Assert constraints into the solver.
7022 >>> s.insert(x > 0, x < 2)
7029 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7031 If `p` is a string, it will be automatically converted into a Boolean constant.
7036 >>> s.set(unsat_core=True)
7037 >>> s.assert_and_track(x > 0, 'p1')
7038 >>> s.assert_and_track(x != 1, 'p2')
7039 >>> s.assert_and_track(x < 0, p3)
7040 >>> print(s.check())
7042 >>> c = s.unsat_core()
7052 if isinstance(p, str):
7054 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7055 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7059 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
7065 >>> s.add(x > 0, x < 2)
7068 >>> s.model().eval(x)
7074 >>> s.add(2**x == 4)
7079 assumptions = _get_args(assumptions)
7080 num = len(assumptions)
7081 _assumptions = (Ast * num)()
7082 for i
in range(num):
7083 _assumptions[i] = s.cast(assumptions[i]).as_ast()
7088 """Return a model for the last `check()`.
7090 This function raises an exception if
7091 a model is not available (e.g., last `check()` returned unsat).
7095 >>> s.add(a + 2 == 0)
7104 raise Z3Exception(
"model is not available")
7107 """Import model converter from other into the current solver"""
7111 """Return a subset (as an AST vector) of the assumptions provided to the last check().
7113 These are the assumptions Z3 used in the unsatisfiability proof.
7114 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
7115 They may be also used to "retract" assumptions. Note that, assumptions are not really
7116 "soft constraints", but they can be used to implement them.
7118 >>> p1, p2, p3 = Bools('p1 p2 p3')
7119 >>> x, y = Ints('x y')
7121 >>> s.add(Implies(p1, x > 0))
7122 >>> s.add(Implies(p2, y > x))
7123 >>> s.add(Implies(p2, y < 1))
7124 >>> s.add(Implies(p3, y > -3))
7125 >>> s.check(p1, p2, p3)
7127 >>> core = s.unsat_core()
7136 >>> # "Retracting" p2
7143 """Determine fixed values for the variables based on the solver state and assumptions.
7145 >>> a, b, c, d = Bools('a b c d')
7146 >>> s.add(Implies(a,b), Implies(b, c))
7147 >>> s.consequences([a],[b,c,d])
7148 (sat, [Implies(a, b), Implies(a, c)])
7149 >>> s.consequences([Not(c),d],[a,b,c,d])
7150 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
7152 if isinstance(assumptions, list):
7154 for a
in assumptions:
7157 if isinstance(variables, list):
7162 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
7163 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
7166 variables.vector, consequences.vector)
7167 sz = len(consequences)
7168 consequences = [consequences[i]
for i
in range(sz)]
7172 """Parse assertions from a file"""
7176 """Parse assertions from a string"""
7181 The method takes an optional set of variables that restrict which
7182 variables may be used as a starting point for cubing.
7183 If vars is not None, then the first case split is based on a variable in
7187 if vars
is not None:
7194 if (len(r) == 1
and is_false(r[0])):
7201 """Access the set of variables that were touched by the most recently generated cube.
7202 This set of variables can be used as a starting point for additional cubes.
7203 The idea is that variables that appear in clauses that are reduced by the most recent
7204 cube are likely more useful to cube on."""
7208 """Return a proof for the last `check()`. Proof construction must be enabled."""
7212 """Return an AST vector containing all added constraints.
7226 """Return an AST vector containing all currently inferred units.
7231 """Return an AST vector containing all atomic formulas in solver state that are not units.
7236 """Return trail and decision levels of the solver state after a check() call.
7238 trail = self.
trailtrail()
7239 levels = (ctypes.c_uint * len(trail))()
7241 return trail, levels
7244 """Return trail of the solver state after a check() call.
7249 """Return statistics for the last `check()`.
7251 >>> s = SimpleSolver()
7256 >>> st = s.statistics()
7257 >>> st.get_key_value('final checks')
7267 """Return a string describing why the last `check()` returned `unknown`.
7270 >>> s = SimpleSolver()
7271 >>> s.add(2**x == 4)
7274 >>> s.reason_unknown()
7275 '(incomplete (theory arithmetic))'
7280 """Display a string describing all available options."""
7284 """Return the parameter description set."""
7288 """Return a formatted string with all added constraints."""
7289 return obj_to_string(self)
7292 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
7296 >>> s1 = Solver(ctx=c1)
7297 >>> s2 = s1.translate(c2)
7300 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
7302 return Solver(solver, target)
7311 """Return a formatted string (in Lisp-like format) with all added constraints.
7312 We say the string is in s-expression format.
7323 """Return a textual representation of the solver in DIMACS format."""
7327 """return SMTLIB2 formatted benchmark for solver's assertions"""
7334 for i
in range(sz1):
7335 v[i] = es[i].as_ast()
7337 e = es[sz1].as_ast()
7341 self.
ctxctx.ref(),
"benchmark generated from python API",
"",
"unknown",
"", sz1, v, e,
7346 """Create a solver customized for the given logic.
7348 The parameter `logic` is a string. It should be contains
7349 the name of a SMT-LIB logic.
7350 See http://www.smtlib.org/ for the name of all available logics.
7352 >>> s = SolverFor("QF_LIA")
7367 """Return a simple general purpose solver with limited amount of preprocessing.
7369 >>> s = SimpleSolver()
7386 """Fixedpoint API provides methods for solving with recursive predicates"""
7389 assert fixedpoint
is None or ctx
is not None
7392 if fixedpoint
is None:
7403 if self.
fixedpointfixedpoint
is not None and self.
ctxctx.ref()
is not None:
7407 """Set a configuration option. The method `help()` return a string containing all available options.
7413 """Display a string describing all available options."""
7417 """Return the parameter description set."""
7421 """Assert constraints as background axioms for the fixedpoint solver."""
7422 args = _get_args(args)
7425 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7435 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7443 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7447 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7451 """Assert rules defining recursive predicates to the fixedpoint solver.
7454 >>> s = Fixedpoint()
7455 >>> s.register_relation(a.decl())
7456 >>> s.register_relation(b.decl())
7469 body = _get_args(body)
7473 def rule(self, head, body=None, name=None):
7474 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7475 self.
add_ruleadd_rule(head, body, name)
7478 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7479 self.
add_ruleadd_rule(head,
None, name)
7482 """Query the fixedpoint engine whether formula is derivable.
7483 You can also pass an tuple or list of recursive predicates.
7485 query = _get_args(query)
7487 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7488 _decls = (FuncDecl * sz)()
7498 query =
And(query, self.
ctxctx)
7499 query = self.
abstractabstract(query,
False)
7504 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7506 query = _get_args(query)
7508 if sz >= 1
and isinstance(query[0], FuncDecl):
7509 _z3_assert(
False,
"unsupported")
7515 query = self.
abstractabstract(query,
False)
7516 r = Z3_fixedpoint_query_from_lvl(self.
ctxctx.ref(), self.
fixedpointfixedpoint, query.as_ast(), lvl)
7524 body = _get_args(body)
7529 """Retrieve answer from last query call."""
7531 return _to_expr_ref(r, self.
ctxctx)
7534 """Retrieve a ground cex from last query call."""
7535 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctxctx.ref(), self.
fixedpointfixedpoint)
7536 return _to_expr_ref(r, self.
ctxctx)
7539 """retrieve rules along the counterexample trace"""
7543 """retrieve rule names along the counterexample trace"""
7546 names = _symbol2py(self.
ctxctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctxctx.ref(), self.
fixedpointfixedpoint))
7548 return names.split(
";")
7551 """Retrieve number of levels used for predicate in PDR engine"""
7555 """Retrieve properties known about predicate for the level'th unfolding.
7556 -1 is treated as the limit (infinity)
7559 return _to_expr_ref(r, self.
ctxctx)
7562 """Add property to predicate for the level'th unfolding.
7563 -1 is treated as infinity (infinity)
7568 """Register relation as recursive"""
7569 relations = _get_args(relations)
7574 """Control how relation is represented"""
7575 representations = _get_args(representations)
7576 representations = [
to_symbol(s)
for s
in representations]
7577 sz = len(representations)
7578 args = (Symbol * sz)()
7580 args[i] = representations[i]
7584 """Parse rules and queries from a string"""
7588 """Parse rules and queries from a file"""
7592 """retrieve rules that have been added to fixedpoint context"""
7596 """retrieve assertions that have been added to fixedpoint context"""
7600 """Return a formatted string with all added rules and constraints."""
7601 return self.
sexprsexpr()
7604 """Return a formatted string (in Lisp-like format) with all added constraints.
7605 We say the string is in s-expression format.
7610 """Return a formatted string (in Lisp-like format) with all added constraints.
7611 We say the string is in s-expression format.
7612 Include also queries.
7614 args, len = _to_ast_array(queries)
7618 """Return statistics for the last `query()`.
7623 """Return a string describing why the last `query()` returned `unknown`.
7628 """Add variable or several variables.
7629 The added variable or variables will be bound in the rules
7632 vars = _get_args(vars)
7634 self.
varsvars += [v]
7637 if self.
varsvars == []:
7652 """Finite domain sort."""
7655 """Return the size of the finite domain sort"""
7656 r = (ctypes.c_ulonglong * 1)()
7660 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7664 """Create a named finite domain sort of a given size sz"""
7665 if not isinstance(name, Symbol):
7672 """Return True if `s` is a Z3 finite-domain sort.
7674 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7676 >>> is_finite_domain_sort(IntSort())
7679 return isinstance(s, FiniteDomainSortRef)
7683 """Finite-domain expressions."""
7686 """Return the sort of the finite-domain expression `self`."""
7690 """Return a Z3 floating point expression as a Python string."""
7695 """Return `True` if `a` is a Z3 finite-domain expression.
7697 >>> s = FiniteDomainSort('S', 100)
7698 >>> b = Const('b', s)
7699 >>> is_finite_domain(b)
7701 >>> is_finite_domain(Int('x'))
7704 return isinstance(a, FiniteDomainRef)
7708 """Integer values."""
7711 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7713 >>> s = FiniteDomainSort('S', 100)
7714 >>> v = FiniteDomainVal(3, s)
7723 """Return a Z3 finite-domain numeral as a Python string.
7725 >>> s = FiniteDomainSort('S', 100)
7726 >>> v = FiniteDomainVal(42, s)
7734 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7736 >>> s = FiniteDomainSort('S', 256)
7737 >>> FiniteDomainVal(255, s)
7739 >>> FiniteDomainVal('100', s)
7749 """Return `True` if `a` is a Z3 finite-domain value.
7751 >>> s = FiniteDomainSort('S', 100)
7752 >>> b = Const('b', s)
7753 >>> is_finite_domain_value(b)
7755 >>> b = FiniteDomainVal(10, s)
7758 >>> is_finite_domain_value(b)
7773 self.
_value_value = value
7794 return self.
upperupper()
7796 return self.
lowerlower()
7805 def _global_on_model(ctx):
7806 (fn, mdl) = _on_models[ctx]
7810 _on_model_eh = on_model_eh_type(_global_on_model)
7814 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7826 if self.
optimizeoptimize
is not None and self.
ctxctx.ref()
is not None:
7832 """Set a configuration option.
7833 The method `help()` return a string containing all available options.
7839 """Display a string describing all available options."""
7843 """Return the parameter description set."""
7847 """Assert constraints as background axioms for the optimize solver."""
7848 args = _get_args(args)
7851 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7859 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7867 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7869 If `p` is a string, it will be automatically converted into a Boolean constant.
7874 >>> s.assert_and_track(x > 0, 'p1')
7875 >>> s.assert_and_track(x != 1, 'p2')
7876 >>> s.assert_and_track(x < 0, p3)
7877 >>> print(s.check())
7879 >>> c = s.unsat_core()
7889 if isinstance(p, str):
7891 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7892 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7896 """Add soft constraint with optional weight and optional identifier.
7897 If no weight is supplied, then the penalty for violating the soft constraint
7899 Soft constraints are grouped by identifiers. Soft constraints that are
7900 added without identifiers are grouped by default.
7903 weight =
"%d" % weight
7904 elif isinstance(weight, float):
7905 weight =
"%f" % weight
7906 if not isinstance(weight, str):
7907 raise Z3Exception(
"weight should be a string or an integer")
7915 if sys.version_info.major >= 3
and isinstance(arg, Iterable):
7916 return [asoft(a)
for a
in arg]
7920 """Add objective function to maximize."""
7928 """Add objective function to minimize."""
7936 """create a backtracking point for added rules, facts and assertions"""
7940 """restore to previously created backtracking point"""
7944 """Check satisfiability while optimizing objective functions."""
7945 assumptions = _get_args(assumptions)
7946 num = len(assumptions)
7947 _assumptions = (Ast * num)()
7948 for i
in range(num):
7949 _assumptions[i] = assumptions[i].as_ast()
7953 """Return a string that describes why the last `check()` returned `unknown`."""
7957 """Return a model for the last check()."""
7961 raise Z3Exception(
"model is not available")
7967 if not isinstance(obj, OptimizeObjective):
7968 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7972 if not isinstance(obj, OptimizeObjective):
7973 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7977 if not isinstance(obj, OptimizeObjective):
7978 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7979 return obj.lower_values()
7982 if not isinstance(obj, OptimizeObjective):
7983 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7984 return obj.upper_values()
7987 """Parse assertions and objectives from a file"""
7991 """Parse assertions and objectives from a string"""
7995 """Return an AST vector containing all added constraints."""
7999 """returns set of objective functions"""
8003 """Return a formatted string with all added rules and constraints."""
8004 return self.
sexprsexpr()
8007 """Return a formatted string (in Lisp-like format) with all added constraints.
8008 We say the string is in s-expression format.
8013 """Return statistics for the last check`.
8018 """Register a callback that is invoked with every incremental improvement to
8019 objective values. The callback takes a model as argument.
8020 The life-time of the model is limited to the callback so the
8021 model has to be (deep) copied if it is to be used after the callback
8023 id = len(_on_models) + 41
8025 _on_models[id] = (on_model, mdl)
8028 self.
ctxctx.ref(), self.
optimizeoptimize, mdl.model, ctypes.c_void_p(id), _on_model_eh,
8038 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal.
8039 It also contains model and proof converters.
8051 if self.
ctxctx.ref()
is not None:
8055 """Return the number of subgoals in `self`.
8057 >>> a, b = Ints('a b')
8059 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
8060 >>> t = Tactic('split-clause')
8064 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
8067 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
8074 """Return one of the subgoals stored in ApplyResult object `self`.
8076 >>> a, b = Ints('a b')
8078 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
8079 >>> t = Tactic('split-clause')
8082 [a == 0, Or(b == 0, b == 1), a > b]
8084 [a == 1, Or(b == 0, b == 1), a > b]
8086 if idx >= len(self):
8091 return obj_to_string(self)
8094 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
8098 """Return a Z3 expression consisting of all subgoals.
8103 >>> g.add(Or(x == 2, x == 3))
8104 >>> r = Tactic('simplify')(g)
8106 [[Not(x <= 1), Or(x == 2, x == 3)]]
8108 And(Not(x <= 1), Or(x == 2, x == 3))
8109 >>> r = Tactic('split-clause')(g)
8111 [[x > 1, x == 2], [x > 1, x == 3]]
8113 Or(And(x > 1, x == 2), And(x > 1, x == 3))
8131 """Tactics transform, solver and/or simplify sets of constraints (Goal).
8132 A Tactic can be converted into a Solver using the method solver().
8134 Several combinators are available for creating new tactics using the built-in ones:
8135 Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
8141 if isinstance(tactic, TacticObj):
8142 self.
tactictactic = tactic
8145 _z3_assert(isinstance(tactic, str),
"tactic name expected")
8149 raise Z3Exception(
"unknown tactic '%s'" % tactic)
8156 if self.
tactictactic
is not None and self.
ctxctx.ref()
is not None:
8160 """Create a solver using the tactic `self`.
8162 The solver supports the methods `push()` and `pop()`, but it
8163 will always solve each `check()` from scratch.
8165 >>> t = Then('simplify', 'nlsat')
8168 >>> s.add(x**2 == 2, x > 0)
8176 def apply(self, goal, *arguments, **keywords):
8177 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8179 >>> x, y = Ints('x y')
8180 >>> t = Tactic('solve-eqs')
8181 >>> t.apply(And(x == 0, y >= x + 1))
8185 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expressions expected")
8186 goal = _to_goal(goal)
8187 if len(arguments) > 0
or len(keywords) > 0:
8194 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8196 >>> x, y = Ints('x y')
8197 >>> t = Tactic('solve-eqs')
8198 >>> t(And(x == 0, y >= x + 1))
8201 return self.
applyapply(goal, *arguments, **keywords)
8204 """Display a string containing a description of the available options for the `self` tactic."""
8208 """Return the parameter description set."""
8213 if isinstance(a, BoolRef):
8214 goal =
Goal(ctx=a.ctx)
8221 def _to_tactic(t, ctx=None):
8222 if isinstance(t, Tactic):
8228 def _and_then(t1, t2, ctx=None):
8229 t1 = _to_tactic(t1, ctx)
8230 t2 = _to_tactic(t2, ctx)
8232 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8236 def _or_else(t1, t2, ctx=None):
8237 t1 = _to_tactic(t1, ctx)
8238 t2 = _to_tactic(t2, ctx)
8240 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8245 """Return a tactic that applies the tactics in `*ts` in sequence.
8247 >>> x, y = Ints('x y')
8248 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8249 >>> t(And(x == 0, y > x + 1))
8251 >>> t(And(x == 0, y > x + 1)).as_expr()
8255 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8256 ctx = ks.get(
"ctx",
None)
8259 for i
in range(num - 1):
8260 r = _and_then(r, ts[i + 1], ctx)
8265 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8267 >>> x, y = Ints('x y')
8268 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8269 >>> t(And(x == 0, y > x + 1))
8271 >>> t(And(x == 0, y > x + 1)).as_expr()
8278 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8281 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8282 >>> # Tactic split-clause fails if there is no clause in the given goal.
8285 >>> t(Or(x == 0, x == 1))
8286 [[x == 0], [x == 1]]
8289 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8290 ctx = ks.get(
"ctx",
None)
8293 for i
in range(num - 1):
8294 r = _or_else(r, ts[i + 1], ctx)
8299 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8302 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8307 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8308 ctx = _get_ctx(ks.get(
"ctx",
None))
8309 ts = [_to_tactic(t, ctx)
for t
in ts]
8311 _args = (TacticObj * sz)()
8313 _args[i] = ts[i].tactic
8318 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8319 The subgoals are processed in parallel.
8321 >>> x, y = Ints('x y')
8322 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8323 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8324 [[x == 1, y == 2], [x == 2, y == 3]]
8326 t1 = _to_tactic(t1, ctx)
8327 t2 = _to_tactic(t2, ctx)
8329 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8334 """Alias for ParThen(t1, t2, ctx)."""
8339 """Return a tactic that applies tactic `t` using the given configuration options.
8341 >>> x, y = Ints('x y')
8342 >>> t = With(Tactic('simplify'), som=True)
8343 >>> t((x + 1)*(y + 2) == 0)
8344 [[2*x + y + x*y == -2]]
8346 ctx = keys.pop(
"ctx",
None)
8347 t = _to_tactic(t, ctx)
8353 """Return a tactic that applies tactic `t` using the given configuration options.
8355 >>> x, y = Ints('x y')
8357 >>> p.set("som", True)
8358 >>> t = WithParams(Tactic('simplify'), p)
8359 >>> t((x + 1)*(y + 2) == 0)
8360 [[2*x + y + x*y == -2]]
8362 t = _to_tactic(t,
None)
8367 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8368 or the maximum number of iterations `max` is reached.
8370 >>> x, y = Ints('x y')
8371 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8372 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8374 >>> for subgoal in r: print(subgoal)
8375 [x == 0, y == 0, x > y]
8376 [x == 0, y == 1, x > y]
8377 [x == 1, y == 0, x > y]
8378 [x == 1, y == 1, x > y]
8379 >>> t = Then(t, Tactic('propagate-values'))
8383 t = _to_tactic(t, ctx)
8388 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8390 If `t` does not terminate in `ms` milliseconds, then it fails.
8392 t = _to_tactic(t, ctx)
8397 """Return a list of all available tactics in Z3.
8400 >>> l.count('simplify') == 1
8408 """Return a short description for the tactic named `name`.
8410 >>> d = tactic_description('simplify')
8417 """Display a (tabular) description of all available tactics in Z3."""
8420 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8423 print(
'<tr style="background-color:#CFCFCF">')
8428 print(
"<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(
tactic_description(t), 40)))
8436 """Probes are used to inspect a goal (aka problem) and collect information that may be used
8437 to decide which solver and/or preprocessing step will be used.
8443 if isinstance(probe, ProbeObj):
8444 self.
probeprobe = probe
8445 elif isinstance(probe, float):
8447 elif _is_int(probe):
8449 elif isinstance(probe, bool):
8456 _z3_assert(isinstance(probe, str),
"probe name expected")
8460 raise Z3Exception(
"unknown probe '%s'" % probe)
8467 if self.
probeprobe
is not None and self.
ctxctx.ref()
is not None:
8471 """Return a probe that evaluates to "true" when the value returned by `self`
8472 is less than the value returned by `other`.
8474 >>> p = Probe('size') < 10
8485 """Return a probe that evaluates to "true" when the value returned by `self`
8486 is greater than the value returned by `other`.
8488 >>> p = Probe('size') > 10
8499 """Return a probe that evaluates to "true" when the value returned by `self`
8500 is less than or equal to the value returned by `other`.
8502 >>> p = Probe('size') <= 2
8513 """Return a probe that evaluates to "true" when the value returned by `self`
8514 is greater than or equal to the value returned by `other`.
8516 >>> p = Probe('size') >= 2
8527 """Return a probe that evaluates to "true" when the value returned by `self`
8528 is equal to the value returned by `other`.
8530 >>> p = Probe('size') == 2
8541 """Return a probe that evaluates to "true" when the value returned by `self`
8542 is not equal to the value returned by `other`.
8544 >>> p = Probe('size') != 2
8552 p = self.
__eq____eq__(other)
8556 """Evaluate the probe `self` in the given goal.
8558 >>> p = Probe('size')
8568 >>> p = Probe('num-consts')
8571 >>> p = Probe('is-propositional')
8574 >>> p = Probe('is-qflia')
8579 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expression expected")
8580 goal = _to_goal(goal)
8585 """Return `True` if `p` is a Z3 probe.
8587 >>> is_probe(Int('x'))
8589 >>> is_probe(Probe('memory'))
8592 return isinstance(p, Probe)
8595 def _to_probe(p, ctx=None):
8599 return Probe(p, ctx)
8603 """Return a list of all available probes in Z3.
8606 >>> l.count('memory') == 1
8614 """Return a short description for the probe named `name`.
8616 >>> d = probe_description('memory')
8623 """Display a (tabular) description of all available probes in Z3."""
8626 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8629 print(
'<tr style="background-color:#CFCFCF">')
8634 print(
"<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(
probe_description(p), 40)))
8641 def _probe_nary(f, args, ctx):
8643 _z3_assert(len(args) > 0,
"At least one argument expected")
8645 r = _to_probe(args[0], ctx)
8646 for i
in range(num - 1):
8647 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8651 def _probe_and(args, ctx):
8652 return _probe_nary(Z3_probe_and, args, ctx)
8655 def _probe_or(args, ctx):
8656 return _probe_nary(Z3_probe_or, args, ctx)
8660 """Return a tactic that fails if the probe `p` evaluates to true.
8661 Otherwise, it returns the input goal unmodified.
8663 In the following example, the tactic applies 'simplify' if and only if there are
8664 more than 2 constraints in the goal.
8666 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8667 >>> x, y = Ints('x y')
8673 >>> g.add(x == y + 1)
8675 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8677 p = _to_probe(p, ctx)
8682 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8683 Otherwise, it returns the input goal unmodified.
8685 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8686 >>> x, y = Ints('x y')
8692 >>> g.add(x == y + 1)
8694 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8696 p = _to_probe(p, ctx)
8697 t = _to_tactic(t, ctx)
8702 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8704 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8706 p = _to_probe(p, ctx)
8707 t1 = _to_tactic(t1, ctx)
8708 t2 = _to_tactic(t2, ctx)
8719 """Simplify the expression `a` using the given options.
8721 This function has many options. Use `help_simplify` to obtain the complete list.
8725 >>> simplify(x + 1 + y + x + 1)
8727 >>> simplify((x + 1)*(y + 1), som=True)
8729 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8730 And(Not(x == y), Not(x == 1), Not(y == 1))
8731 >>> simplify(And(x == 0, y == 1), elim_and=True)
8732 Not(Or(Not(x == 0), Not(y == 1)))
8735 _z3_assert(
is_expr(a),
"Z3 expression expected")
8736 if len(arguments) > 0
or len(keywords) > 0:
8738 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8740 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8744 """Return a string describing all options available for Z3 `simplify` procedure."""
8749 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8754 """Apply substitution m on t, m is a list of pairs of the form (from, to).
8755 Every occurrence in t of from is replaced with to.
8759 >>> substitute(x + 1, (x, y + 1))
8761 >>> f = Function('f', IntSort(), IntSort())
8762 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8765 if isinstance(m, tuple):
8767 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8770 _z3_assert(
is_expr(t),
"Z3 expression expected")
8771 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(
8772 p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8774 _from = (Ast * num)()
8776 for i
in range(num):
8777 _from[i] = m[i][0].as_ast()
8778 _to[i] = m[i][1].as_ast()
8779 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8783 """Substitute the free variables in t with the expression in m.
8785 >>> v0 = Var(0, IntSort())
8786 >>> v1 = Var(1, IntSort())
8788 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8789 >>> # replace v0 with x+1 and v1 with x
8790 >>> substitute_vars(f(v0, v1), x + 1, x)
8794 _z3_assert(
is_expr(t),
"Z3 expression expected")
8795 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8798 for i
in range(num):
8799 _to[i] = m[i].as_ast()
8804 """Create the sum of the Z3 expressions.
8806 >>> a, b, c = Ints('a b c')
8811 >>> A = IntVector('a', 5)
8813 a__0 + a__1 + a__2 + a__3 + a__4
8815 args = _get_args(args)
8818 ctx = _ctx_from_ast_arg_list(args)
8820 return _reduce(
lambda a, b: a + b, args, 0)
8821 args = _coerce_expr_list(args, ctx)
8823 return _reduce(
lambda a, b: a + b, args, 0)
8825 _args, sz = _to_ast_array(args)
8830 """Create the product of the Z3 expressions.
8832 >>> a, b, c = Ints('a b c')
8833 >>> Product(a, b, c)
8835 >>> Product([a, b, c])
8837 >>> A = IntVector('a', 5)
8839 a__0*a__1*a__2*a__3*a__4
8841 args = _get_args(args)
8844 ctx = _ctx_from_ast_arg_list(args)
8846 return _reduce(
lambda a, b: a * b, args, 1)
8847 args = _coerce_expr_list(args, ctx)
8849 return _reduce(
lambda a, b: a * b, args, 1)
8851 _args, sz = _to_ast_array(args)
8855 """Create the absolute value of an arithmetic expression"""
8856 return If(arg > 0, arg, -arg)
8860 """Create an at-most Pseudo-Boolean k constraint.
8862 >>> a, b, c = Bools('a b c')
8863 >>> f = AtMost(a, b, c, 2)
8865 args = _get_args(args)
8867 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8868 ctx = _ctx_from_ast_arg_list(args)
8870 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8871 args1 = _coerce_expr_list(args[:-1], ctx)
8873 _args, sz = _to_ast_array(args1)
8878 """Create an at-most Pseudo-Boolean k constraint.
8880 >>> a, b, c = Bools('a b c')
8881 >>> f = AtLeast(a, b, c, 2)
8883 args = _get_args(args)
8885 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8886 ctx = _ctx_from_ast_arg_list(args)
8888 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8889 args1 = _coerce_expr_list(args[:-1], ctx)
8891 _args, sz = _to_ast_array(args1)
8895 def _reorder_pb_arg(arg):
8897 if not _is_int(b)
and _is_int(a):
8902 def _pb_args_coeffs(args, default_ctx=None):
8903 args = _get_args_ast_list(args)
8905 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8906 args = [_reorder_pb_arg(arg)
for arg
in args]
8907 args, coeffs = zip(*args)
8909 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8910 ctx = _ctx_from_ast_arg_list(args)
8912 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8913 args = _coerce_expr_list(args, ctx)
8914 _args, sz = _to_ast_array(args)
8915 _coeffs = (ctypes.c_int * len(coeffs))()
8916 for i
in range(len(coeffs)):
8917 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8918 _coeffs[i] = coeffs[i]
8919 return ctx, sz, _args, _coeffs, args
8923 """Create a Pseudo-Boolean inequality k constraint.
8925 >>> a, b, c = Bools('a b c')
8926 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8928 _z3_check_cint_overflow(k,
"k")
8929 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8934 """Create a Pseudo-Boolean inequality k constraint.
8936 >>> a, b, c = Bools('a b c')
8937 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8939 _z3_check_cint_overflow(k,
"k")
8940 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8945 """Create a Pseudo-Boolean inequality k constraint.
8947 >>> a, b, c = Bools('a b c')
8948 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8950 _z3_check_cint_overflow(k,
"k")
8951 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8956 """Solve the constraints `*args`.
8958 This is a simple function for creating demonstrations. It creates a solver,
8959 configure it using the options in `keywords`, adds the constraints
8960 in `args`, and invokes check.
8963 >>> solve(a > 0, a < 2)
8966 show = keywords.pop(
"show",
False)
8974 print(
"no solution")
8976 print(
"failed to solve")
8986 """Solve the constraints `*args` using solver `s`.
8988 This is a simple function for creating demonstrations. It is similar to `solve`,
8989 but it uses the given solver `s`.
8990 It configures solver `s` using the options in `keywords`, adds the constraints
8991 in `args`, and invokes check.
8993 show = keywords.pop(
"show",
False)
8995 _z3_assert(isinstance(s, Solver),
"Solver object expected")
9003 print(
"no solution")
9005 print(
"failed to solve")
9016 def prove(claim, show=False, **keywords):
9017 """Try to prove the given claim.
9019 This is a simple function for creating demonstrations. It tries to prove
9020 `claim` by showing the negation is unsatisfiable.
9022 >>> p, q = Bools('p q')
9023 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
9027 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9037 print(
"failed to prove")
9040 print(
"counterexample")
9044 def _solve_html(*args, **keywords):
9045 """Version of function `solve` that renders HTML output."""
9046 show = keywords.pop(
"show",
False)
9051 print(
"<b>Problem:</b>")
9055 print(
"<b>no solution</b>")
9057 print(
"<b>failed to solve</b>")
9064 print(
"<b>Solution:</b>")
9068 def _solve_using_html(s, *args, **keywords):
9069 """Version of function `solve_using` that renders HTML."""
9070 show = keywords.pop(
"show",
False)
9072 _z3_assert(isinstance(s, Solver),
"Solver object expected")
9076 print(
"<b>Problem:</b>")
9080 print(
"<b>no solution</b>")
9082 print(
"<b>failed to solve</b>")
9089 print(
"<b>Solution:</b>")
9093 def _prove_html(claim, show=False, **keywords):
9094 """Version of function `prove` that renders HTML."""
9096 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9104 print(
"<b>proved</b>")
9106 print(
"<b>failed to prove</b>")
9109 print(
"<b>counterexample</b>")
9113 def _dict2sarray(sorts, ctx):
9115 _names = (Symbol * sz)()
9116 _sorts = (Sort * sz)()
9121 _z3_assert(isinstance(k, str),
"String expected")
9122 _z3_assert(
is_sort(v),
"Z3 sort expected")
9126 return sz, _names, _sorts
9129 def _dict2darray(decls, ctx):
9131 _names = (Symbol * sz)()
9132 _decls = (FuncDecl * sz)()
9137 _z3_assert(isinstance(k, str),
"String expected")
9141 _decls[i] = v.decl().ast
9145 return sz, _names, _decls
9149 """Parse a string in SMT 2.0 format using the given sorts and decls.
9151 The arguments sorts and decls are Python dictionaries used to initialize
9152 the symbol table used for the SMT 2.0 parser.
9154 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9156 >>> x, y = Ints('x y')
9157 >>> f = Function('f', IntSort(), IntSort())
9158 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9160 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9164 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9165 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9170 """Parse a file in SMT 2.0 format using the given sorts and decls.
9172 This function is similar to parse_smt2_string().
9175 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9176 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9188 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
9189 _dflt_fpsort_ebits = 11
9190 _dflt_fpsort_sbits = 53
9194 """Retrieves the global default rounding mode."""
9195 global _dflt_rounding_mode
9196 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9198 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9200 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9202 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9204 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9208 _ROUNDING_MODES = frozenset({
9209 Z3_OP_FPA_RM_TOWARD_ZERO,
9210 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
9211 Z3_OP_FPA_RM_TOWARD_POSITIVE,
9212 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
9213 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
9218 global _dflt_rounding_mode
9220 _dflt_rounding_mode = rm.decl().kind()
9222 _z3_assert(_dflt_rounding_mode
in _ROUNDING_MODES,
"illegal rounding mode")
9223 _dflt_rounding_mode = rm
9227 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9231 global _dflt_fpsort_ebits
9232 global _dflt_fpsort_sbits
9233 _dflt_fpsort_ebits = ebits
9234 _dflt_fpsort_sbits = sbits
9237 def _dflt_rm(ctx=None):
9241 def _dflt_fps(ctx=None):
9245 def _coerce_fp_expr_list(alist, ctx):
9246 first_fp_sort =
None
9249 if first_fp_sort
is None:
9250 first_fp_sort = a.sort()
9251 elif first_fp_sort == a.sort():
9256 first_fp_sort =
None
9260 for i
in range(len(alist)):
9262 is_repr = isinstance(a, str)
and a.contains(
"2**(")
and a.endswith(
")")
9263 if is_repr
or _is_int(a)
or isinstance(a, (float, bool)):
9264 r.append(
FPVal(a,
None, first_fp_sort, ctx))
9267 return _coerce_expr_list(r, ctx)
9273 """Floating-point sort."""
9276 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
9277 >>> b = FPSort(8, 24)
9284 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
9285 >>> b = FPSort(8, 24)
9292 """Try to cast `val` as a floating-point expression.
9293 >>> b = FPSort(8, 24)
9296 >>> b.cast(1.0).sexpr()
9297 '(fp #b0 #x7f #b00000000000000000000000)'
9301 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
9308 """Floating-point 16-bit (half) sort."""
9314 """Floating-point 16-bit (half) sort."""
9320 """Floating-point 32-bit (single) sort."""
9326 """Floating-point 32-bit (single) sort."""
9332 """Floating-point 64-bit (double) sort."""
9338 """Floating-point 64-bit (double) sort."""
9344 """Floating-point 128-bit (quadruple) sort."""
9350 """Floating-point 128-bit (quadruple) sort."""
9356 """"Floating-point rounding mode sort."""
9360 """Return True if `s` is a Z3 floating-point sort.
9362 >>> is_fp_sort(FPSort(8, 24))
9364 >>> is_fp_sort(IntSort())
9367 return isinstance(s, FPSortRef)
9371 """Return True if `s` is a Z3 floating-point rounding mode sort.
9373 >>> is_fprm_sort(FPSort(8, 24))
9375 >>> is_fprm_sort(RNE().sort())
9378 return isinstance(s, FPRMSortRef)
9384 """Floating-point expressions."""
9387 """Return the sort of the floating-point expression `self`.
9389 >>> x = FP('1.0', FPSort(8, 24))
9392 >>> x.sort() == FPSort(8, 24)
9398 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9399 >>> b = FPSort(8, 24)
9406 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9407 >>> b = FPSort(8, 24)
9414 """Return a Z3 floating point expression as a Python string."""
9418 return fpLEQ(self, other, self.
ctxctx)
9421 return fpLT(self, other, self.
ctxctx)
9424 return fpGEQ(self, other, self.
ctxctx)
9427 return fpGT(self, other, self.
ctxctx)
9430 """Create the Z3 expression `self + other`.
9432 >>> x = FP('x', FPSort(8, 24))
9433 >>> y = FP('y', FPSort(8, 24))
9439 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9440 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
9443 """Create the Z3 expression `other + self`.
9445 >>> x = FP('x', FPSort(8, 24))
9449 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9450 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
9453 """Create the Z3 expression `self - other`.
9455 >>> x = FP('x', FPSort(8, 24))
9456 >>> y = FP('y', FPSort(8, 24))
9462 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9463 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
9466 """Create the Z3 expression `other - self`.
9468 >>> x = FP('x', FPSort(8, 24))
9472 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9473 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
9476 """Create the Z3 expression `self * other`.
9478 >>> x = FP('x', FPSort(8, 24))
9479 >>> y = FP('y', FPSort(8, 24))
9487 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9488 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
9491 """Create the Z3 expression `other * self`.
9493 >>> x = FP('x', FPSort(8, 24))
9494 >>> y = FP('y', FPSort(8, 24))
9500 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9501 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
9504 """Create the Z3 expression `+self`."""
9508 """Create the Z3 expression `-self`.
9510 >>> x = FP('x', Float32())
9517 """Create the Z3 expression `self / other`.
9519 >>> x = FP('x', FPSort(8, 24))
9520 >>> y = FP('y', FPSort(8, 24))
9528 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9529 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
9532 """Create the Z3 expression `other / self`.
9534 >>> x = FP('x', FPSort(8, 24))
9535 >>> y = FP('y', FPSort(8, 24))
9541 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9542 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
9545 """Create the Z3 expression division `self / other`."""
9546 return self.
__div____div__(other)
9549 """Create the Z3 expression division `other / self`."""
9550 return self.
__rdiv____rdiv__(other)
9553 """Create the Z3 expression mod `self % other`."""
9554 return fpRem(self, other)
9557 """Create the Z3 expression mod `other % self`."""
9558 return fpRem(other, self)
9562 """Floating-point rounding mode expressions"""
9565 """Return a Z3 floating point expression as a Python string."""
9620 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9629 return isinstance(a, FPRMRef)
9633 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9634 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9640 """The sign of the numeral.
9642 >>> x = FPVal(+1.0, FPSort(8, 24))
9645 >>> x = FPVal(-1.0, FPSort(8, 24))
9651 num = (ctypes.c_int)()
9654 raise Z3Exception(
"error retrieving the sign of a numeral.")
9655 return num.value != 0
9657 """The sign of a floating-point numeral as a bit-vector expression.
9659 Remark: NaN's are invalid arguments.
9665 """The significand of the numeral.
9667 >>> x = FPVal(2.5, FPSort(8, 24))
9675 """The significand of the numeral as a long.
9677 >>> x = FPVal(2.5, FPSort(8, 24))
9678 >>> x.significand_as_long()
9683 ptr = (ctypes.c_ulonglong * 1)()
9685 raise Z3Exception(
"error retrieving the significand of a numeral.")
9688 """The significand of the numeral as a bit-vector expression.
9690 Remark: NaN are invalid arguments.
9696 """The exponent of the numeral.
9698 >>> x = FPVal(2.5, FPSort(8, 24))
9706 """The exponent of the numeral as a long.
9708 >>> x = FPVal(2.5, FPSort(8, 24))
9709 >>> x.exponent_as_long()
9714 ptr = (ctypes.c_longlong * 1)()
9716 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9719 """The exponent of the numeral as a bit-vector expression.
9721 Remark: NaNs are invalid arguments.
9727 """Indicates whether the numeral is a NaN."""
9732 """Indicates whether the numeral is +oo or -oo."""
9737 """Indicates whether the numeral is +zero or -zero."""
9742 """Indicates whether the numeral is normal."""
9747 """Indicates whether the numeral is subnormal."""
9752 """Indicates whether the numeral is positive."""
9757 """Indicates whether the numeral is negative."""
9763 The string representation of the numeral.
9765 >>> x = FPVal(20, FPSort(8, 24))
9772 return (
"FPVal(%s, %s)" % (s, self.
sortsortsort()))
9776 """Return `True` if `a` is a Z3 floating-point expression.
9778 >>> b = FP('b', FPSort(8, 24))
9786 return isinstance(a, FPRef)
9790 """Return `True` if `a` is a Z3 floating-point numeral value.
9792 >>> b = FP('b', FPSort(8, 24))
9795 >>> b = FPVal(1.0, FPSort(8, 24))
9801 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9805 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9807 >>> Single = FPSort(8, 24)
9808 >>> Double = FPSort(11, 53)
9811 >>> x = Const('x', Single)
9812 >>> eq(x, FP('x', FPSort(8, 24)))
9819 def _to_float_str(val, exp=0):
9820 if isinstance(val, float):
9824 sone = math.copysign(1.0, val)
9829 elif val == float(
"+inf"):
9831 elif val == float(
"-inf"):
9834 v = val.as_integer_ratio()
9837 rvs = str(num) +
"/" + str(den)
9838 res = rvs +
"p" + _to_int_str(exp)
9839 elif isinstance(val, bool):
9846 elif isinstance(val, str):
9847 inx = val.find(
"*(2**")
9850 elif val[-1] ==
")":
9852 exp = str(int(val[inx + 5:-1]) + int(exp))
9854 _z3_assert(
False,
"String does not have floating-point numeral form.")
9856 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9860 return res +
"p" + exp
9864 """Create a Z3 floating-point NaN term.
9866 >>> s = FPSort(8, 24)
9867 >>> set_fpa_pretty(True)
9870 >>> pb = get_fpa_pretty()
9871 >>> set_fpa_pretty(False)
9873 fpNaN(FPSort(8, 24))
9874 >>> set_fpa_pretty(pb)
9876 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9881 """Create a Z3 floating-point +oo term.
9883 >>> s = FPSort(8, 24)
9884 >>> pb = get_fpa_pretty()
9885 >>> set_fpa_pretty(True)
9886 >>> fpPlusInfinity(s)
9888 >>> set_fpa_pretty(False)
9889 >>> fpPlusInfinity(s)
9890 fpPlusInfinity(FPSort(8, 24))
9891 >>> set_fpa_pretty(pb)
9893 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9898 """Create a Z3 floating-point -oo term."""
9899 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9904 """Create a Z3 floating-point +oo or -oo term."""
9905 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9906 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9911 """Create a Z3 floating-point +0.0 term."""
9912 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9917 """Create a Z3 floating-point -0.0 term."""
9918 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9923 """Create a Z3 floating-point +0.0 or -0.0 term."""
9924 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9925 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9929 def FPVal(sig, exp=None, fps=None, ctx=None):
9930 """Return a floating-point value of value `val` and sort `fps`.
9931 If `ctx=None`, then the global context is used.
9933 >>> v = FPVal(20.0, FPSort(8, 24))
9936 >>> print("0x%.8x" % v.exponent_as_long(False))
9938 >>> v = FPVal(2.25, FPSort(8, 24))
9941 >>> v = FPVal(-2.25, FPSort(8, 24))
9944 >>> FPVal(-0.0, FPSort(8, 24))
9946 >>> FPVal(0.0, FPSort(8, 24))
9948 >>> FPVal(+0.0, FPSort(8, 24))
9956 fps = _dflt_fps(ctx)
9960 val = _to_float_str(sig)
9961 if val ==
"NaN" or val ==
"nan":
9965 elif val ==
"0.0" or val ==
"+0.0":
9967 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9969 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9975 def FP(name, fpsort, ctx=None):
9976 """Return a floating-point constant named `name`.
9977 `fpsort` is the floating-point sort.
9978 If `ctx=None`, then the global context is used.
9980 >>> x = FP('x', FPSort(8, 24))
9987 >>> word = FPSort(8, 24)
9988 >>> x2 = FP('x', word)
9992 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9999 def FPs(names, fpsort, ctx=None):
10000 """Return an array of floating-point constants.
10002 >>> x, y, z = FPs('x y z', FPSort(8, 24))
10009 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
10010 fpMul(RNE(), fpAdd(RNE(), x, y), z)
10012 ctx = _get_ctx(ctx)
10013 if isinstance(names, str):
10014 names = names.split(
" ")
10015 return [
FP(name, fpsort, ctx)
for name
in names]
10019 """Create a Z3 floating-point absolute value expression.
10021 >>> s = FPSort(8, 24)
10023 >>> x = FPVal(1.0, s)
10026 >>> y = FPVal(-20.0, s)
10030 fpAbs(-1.25*(2**4))
10031 >>> fpAbs(-1.25*(2**4))
10032 fpAbs(-1.25*(2**4))
10033 >>> fpAbs(x).sort()
10036 ctx = _get_ctx(ctx)
10037 [a] = _coerce_fp_expr_list([a], ctx)
10042 """Create a Z3 floating-point addition expression.
10044 >>> s = FPSort(8, 24)
10049 >>> fpNeg(x).sort()
10052 ctx = _get_ctx(ctx)
10053 [a] = _coerce_fp_expr_list([a], ctx)
10057 def _mk_fp_unary(f, rm, a, ctx):
10058 ctx = _get_ctx(ctx)
10059 [a] = _coerce_fp_expr_list([a], ctx)
10061 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10062 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
10063 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10066 def _mk_fp_unary_pred(f, a, ctx):
10067 ctx = _get_ctx(ctx)
10068 [a] = _coerce_fp_expr_list([a], ctx)
10070 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
10071 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10074 def _mk_fp_bin(f, rm, a, b, ctx):
10075 ctx = _get_ctx(ctx)
10076 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10078 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10079 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
10080 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10083 def _mk_fp_bin_norm(f, a, b, ctx):
10084 ctx = _get_ctx(ctx)
10085 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10087 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10088 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10091 def _mk_fp_bin_pred(f, a, b, ctx):
10092 ctx = _get_ctx(ctx)
10093 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10095 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10096 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10099 def _mk_fp_tern(f, rm, a, b, c, ctx):
10100 ctx = _get_ctx(ctx)
10101 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10103 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10105 c),
"Second, third or fourth argument must be a Z3 floating-point expression")
10106 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10110 """Create a Z3 floating-point addition expression.
10112 >>> s = FPSort(8, 24)
10116 >>> fpAdd(rm, x, y)
10118 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10120 >>> fpAdd(rm, x, y).sort()
10123 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10127 """Create a Z3 floating-point subtraction expression.
10129 >>> s = FPSort(8, 24)
10133 >>> fpSub(rm, x, y)
10135 >>> fpSub(rm, x, y).sort()
10138 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10142 """Create a Z3 floating-point multiplication expression.
10144 >>> s = FPSort(8, 24)
10148 >>> fpMul(rm, x, y)
10150 >>> fpMul(rm, x, y).sort()
10153 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10157 """Create a Z3 floating-point division expression.
10159 >>> s = FPSort(8, 24)
10163 >>> fpDiv(rm, x, y)
10165 >>> fpDiv(rm, x, y).sort()
10168 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10172 """Create a Z3 floating-point remainder expression.
10174 >>> s = FPSort(8, 24)
10179 >>> fpRem(x, y).sort()
10182 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10186 """Create a Z3 floating-point minimum expression.
10188 >>> s = FPSort(8, 24)
10194 >>> fpMin(x, y).sort()
10197 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10201 """Create a Z3 floating-point maximum expression.
10203 >>> s = FPSort(8, 24)
10209 >>> fpMax(x, y).sort()
10212 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10216 """Create a Z3 floating-point fused multiply-add expression.
10218 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10222 """Create a Z3 floating-point square root expression.
10224 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10228 """Create a Z3 floating-point roundToIntegral expression.
10230 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10234 """Create a Z3 floating-point isNaN expression.
10236 >>> s = FPSort(8, 24)
10242 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10246 """Create a Z3 floating-point isInfinite expression.
10248 >>> s = FPSort(8, 24)
10253 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10257 """Create a Z3 floating-point isZero expression.
10259 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10263 """Create a Z3 floating-point isNormal expression.
10265 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10269 """Create a Z3 floating-point isSubnormal expression.
10271 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10275 """Create a Z3 floating-point isNegative expression.
10277 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10281 """Create a Z3 floating-point isPositive expression.
10283 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10286 def _check_fp_args(a, b):
10288 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10292 """Create the Z3 floating-point expression `other < self`.
10294 >>> x, y = FPs('x y', FPSort(8, 24))
10297 >>> (x < y).sexpr()
10300 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10304 """Create the Z3 floating-point expression `other <= self`.
10306 >>> x, y = FPs('x y', FPSort(8, 24))
10309 >>> (x <= y).sexpr()
10312 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10316 """Create the Z3 floating-point expression `other > self`.
10318 >>> x, y = FPs('x y', FPSort(8, 24))
10321 >>> (x > y).sexpr()
10324 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10328 """Create the Z3 floating-point expression `other >= self`.
10330 >>> x, y = FPs('x y', FPSort(8, 24))
10333 >>> (x >= y).sexpr()
10336 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10340 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10342 >>> x, y = FPs('x y', FPSort(8, 24))
10345 >>> fpEQ(x, y).sexpr()
10348 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10352 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10354 >>> x, y = FPs('x y', FPSort(8, 24))
10357 >>> (x != y).sexpr()
10364 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10366 >>> s = FPSort(8, 24)
10367 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10369 fpFP(1, 127, 4194304)
10370 >>> xv = FPVal(-1.5, s)
10373 >>> slvr = Solver()
10374 >>> slvr.add(fpEQ(x, xv))
10377 >>> xv = FPVal(+1.5, s)
10380 >>> slvr = Solver()
10381 >>> slvr.add(fpEQ(x, xv))
10385 _z3_assert(
is_bv(sgn)
and is_bv(exp)
and is_bv(sig),
"sort mismatch")
10386 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
10387 ctx = _get_ctx(ctx)
10388 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
10393 """Create a Z3 floating-point conversion expression from other term sorts
10396 From a bit-vector term in IEEE 754-2008 format:
10397 >>> x = FPVal(1.0, Float32())
10398 >>> x_bv = fpToIEEEBV(x)
10399 >>> simplify(fpToFP(x_bv, Float32()))
10402 From a floating-point term with different precision:
10403 >>> x = FPVal(1.0, Float32())
10404 >>> x_db = fpToFP(RNE(), x, Float64())
10409 >>> x_r = RealVal(1.5)
10410 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10413 From a signed bit-vector term:
10414 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10415 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10418 ctx = _get_ctx(ctx)
10428 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
10432 """Create a Z3 floating-point conversion expression that represents the
10433 conversion from a bit-vector term to a floating-point term.
10435 >>> x_bv = BitVecVal(0x3F800000, 32)
10436 >>> x_fp = fpBVToFP(x_bv, Float32())
10442 _z3_assert(
is_bv(v),
"First argument must be a Z3 bit-vector expression")
10443 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
10444 ctx = _get_ctx(ctx)
10449 """Create a Z3 floating-point conversion expression that represents the
10450 conversion from a floating-point term to a floating-point term of different precision.
10452 >>> x_sgl = FPVal(1.0, Float32())
10453 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10456 >>> simplify(x_dbl)
10461 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10462 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
10463 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10464 ctx = _get_ctx(ctx)
10469 """Create a Z3 floating-point conversion expression that represents the
10470 conversion from a real term to a floating-point term.
10472 >>> x_r = RealVal(1.5)
10473 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10479 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10480 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
10481 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10482 ctx = _get_ctx(ctx)
10487 """Create a Z3 floating-point conversion expression that represents the
10488 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10490 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10491 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10493 fpToFP(RNE(), 4294967291)
10497 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10498 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10499 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10500 ctx = _get_ctx(ctx)
10505 """Create a Z3 floating-point conversion expression that represents the
10506 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10508 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10509 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10511 fpToFPUnsigned(RNE(), 4294967291)
10515 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10516 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10517 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10518 ctx = _get_ctx(ctx)
10523 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10525 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10526 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
10527 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
10528 ctx = _get_ctx(ctx)
10533 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10535 >>> x = FP('x', FPSort(8, 24))
10536 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10537 >>> print(is_fp(x))
10539 >>> print(is_bv(y))
10541 >>> print(is_fp(y))
10543 >>> print(is_bv(x))
10547 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10548 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10549 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10550 ctx = _get_ctx(ctx)
10555 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10557 >>> x = FP('x', FPSort(8, 24))
10558 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10559 >>> print(is_fp(x))
10561 >>> print(is_bv(y))
10563 >>> print(is_fp(y))
10565 >>> print(is_bv(x))
10569 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10570 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10571 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10572 ctx = _get_ctx(ctx)
10577 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10579 >>> x = FP('x', FPSort(8, 24))
10580 >>> y = fpToReal(x)
10581 >>> print(is_fp(x))
10583 >>> print(is_real(y))
10585 >>> print(is_fp(y))
10587 >>> print(is_real(x))
10591 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10592 ctx = _get_ctx(ctx)
10597 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10599 The size of the resulting bit-vector is automatically determined.
10601 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10602 knows only one NaN and it will always produce the same bit-vector representation of
10605 >>> x = FP('x', FPSort(8, 24))
10606 >>> y = fpToIEEEBV(x)
10607 >>> print(is_fp(x))
10609 >>> print(is_bv(y))
10611 >>> print(is_fp(y))
10613 >>> print(is_bv(x))
10617 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10618 ctx = _get_ctx(ctx)
10629 """Sequence sort."""
10632 """Determine if sort is a string
10633 >>> s = StringSort()
10636 >>> s = SeqSort(IntSort())
10646 """Character sort."""
10650 """Create a string sort
10651 >>> s = StringSort()
10655 ctx = _get_ctx(ctx)
10659 """Create a character sort
10660 >>> ch = CharSort()
10664 ctx = _get_ctx(ctx)
10669 """Create a sequence sort over elements provided in the argument
10670 >>> s = SeqSort(IntSort())
10671 >>> s == Unit(IntVal(1)).sort()
10678 """Sequence expression."""
10684 return Concat(self, other)
10687 return Concat(other, self)
10706 """Return a string representation of sequence expression."""
10708 string_length = ctypes.c_uint()
10710 return string_at(chars, size=string_length.value).decode(
"latin-1")
10726 def _coerce_char(ch, ctx=None):
10727 if isinstance(ch, str):
10728 ctx = _get_ctx(ctx)
10731 raise Z3Exception(
"Character expression expected")
10735 """Character expression."""
10738 other = _coerce_char(other, self.
ctxctx)
10752 ctx = _get_ctx(ctx)
10753 if isinstance(ch, str):
10755 if not isinstance(ch, int):
10756 raise Z3Exception(
"character value should be an ordinal")
10757 return _to_expr_ref(
Z3_mk_char(ctx.ref(), ch), ctx)
10761 raise Z3Expression(
"Bit-vector expression needed")
10765 ch = _coerce_char(ch, ctx)
10769 ch = _coerce_char(ch, ctx)
10773 ch = _coerce_char(ch, ctx)
10774 return ch.is_digit()
10776 def _coerce_seq(s, ctx=None):
10777 if isinstance(s, str):
10778 ctx = _get_ctx(ctx)
10781 raise Z3Exception(
"Non-expression passed as a sequence")
10783 raise Z3Exception(
"Non-sequence passed as a sequence")
10787 def _get_ctx2(a, b, ctx=None):
10798 """Return `True` if `a` is a Z3 sequence expression.
10799 >>> print (is_seq(Unit(IntVal(0))))
10801 >>> print (is_seq(StringVal("abc")))
10804 return isinstance(a, SeqRef)
10808 """Return `True` if `a` is a Z3 string expression.
10809 >>> print (is_string(StringVal("ab")))
10812 return isinstance(a, SeqRef)
and a.is_string()
10816 """return 'True' if 'a' is a Z3 string constant expression.
10817 >>> print (is_string_value(StringVal("a")))
10819 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10822 return isinstance(a, SeqRef)
and a.is_string_value()
10825 """create a string expression"""
10826 s =
"".join(str(ch)
if 32 <= ord(ch)
and ord(ch) < 127
else "\\u{%x}" % (ord(ch))
for ch
in s)
10827 ctx = _get_ctx(ctx)
10832 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10834 >>> x = String('x')
10836 ctx = _get_ctx(ctx)
10841 """Return a tuple of String constants. """
10842 ctx = _get_ctx(ctx)
10843 if isinstance(names, str):
10844 names = names.split(
" ")
10845 return [
String(name, ctx)
for name
in names]
10849 """Extract substring or subsequence starting at offset"""
10850 return Extract(s, offset, length)
10854 """Extract substring or subsequence starting at offset"""
10855 return Extract(s, offset, length)
10859 """Create the empty sequence of the given sort
10860 >>> e = Empty(StringSort())
10861 >>> e2 = StringVal("")
10862 >>> print(e.eq(e2))
10864 >>> e3 = Empty(SeqSort(IntSort()))
10867 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10869 Empty(ReSort(Seq(Int)))
10871 if isinstance(s, SeqSortRef):
10873 if isinstance(s, ReSortRef):
10875 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10879 """Create the regular expression that accepts the universal language
10880 >>> e = Full(ReSort(SeqSort(IntSort())))
10882 Full(ReSort(Seq(Int)))
10883 >>> e1 = Full(ReSort(StringSort()))
10885 Full(ReSort(String))
10887 if isinstance(s, ReSortRef):
10889 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10894 """Create a singleton sequence"""
10899 """Check if 'a' is a prefix of 'b'
10900 >>> s1 = PrefixOf("ab", "abc")
10903 >>> s2 = PrefixOf("bc", "abc")
10907 ctx = _get_ctx2(a, b)
10908 a = _coerce_seq(a, ctx)
10909 b = _coerce_seq(b, ctx)
10914 """Check if 'a' is a suffix of 'b'
10915 >>> s1 = SuffixOf("ab", "abc")
10918 >>> s2 = SuffixOf("bc", "abc")
10922 ctx = _get_ctx2(a, b)
10923 a = _coerce_seq(a, ctx)
10924 b = _coerce_seq(b, ctx)
10929 """Check if 'a' contains 'b'
10930 >>> s1 = Contains("abc", "ab")
10933 >>> s2 = Contains("abc", "bc")
10936 >>> x, y, z = Strings('x y z')
10937 >>> s3 = Contains(Concat(x,y,z), y)
10941 ctx = _get_ctx2(a, b)
10942 a = _coerce_seq(a, ctx)
10943 b = _coerce_seq(b, ctx)
10948 """Replace the first occurrence of 'src' by 'dst' in 's'
10949 >>> r = Replace("aaa", "a", "b")
10953 ctx = _get_ctx2(dst, s)
10954 if ctx
is None and is_expr(src):
10956 src = _coerce_seq(src, ctx)
10957 dst = _coerce_seq(dst, ctx)
10958 s = _coerce_seq(s, ctx)
10963 """Retrieve the index of substring within a string starting at a specified offset.
10964 >>> simplify(IndexOf("abcabc", "bc", 0))
10966 >>> simplify(IndexOf("abcabc", "bc", 2))
10974 ctx = _get_ctx2(s, substr, ctx)
10975 s = _coerce_seq(s, ctx)
10976 substr = _coerce_seq(substr, ctx)
10977 if _is_int(offset):
10978 offset =
IntVal(offset, ctx)
10983 """Retrieve the last index of substring within a string"""
10985 ctx = _get_ctx2(s, substr, ctx)
10986 s = _coerce_seq(s, ctx)
10987 substr = _coerce_seq(substr, ctx)
10992 """Obtain the length of a sequence 's'
10993 >>> l = Length(StringVal("abc"))
11002 """Convert string expression to integer
11003 >>> a = StrToInt("1")
11004 >>> simplify(1 == a)
11006 >>> b = StrToInt("2")
11007 >>> simplify(1 == b)
11009 >>> c = StrToInt(IntToStr(2))
11010 >>> simplify(1 == c)
11018 """Convert integer expression to string"""
11025 """Convert a unit length string to integer code"""
11031 """Convert code to a string"""
11037 """The regular expression that accepts sequence 's'
11039 >>> s2 = Re(StringVal("ab"))
11040 >>> s3 = Re(Unit(BoolVal(True)))
11042 s = _coerce_seq(s, ctx)
11049 """Regular expression sort."""
11058 if s
is None or isinstance(s, Context):
11061 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
11065 """Regular expressions."""
11068 return Union(self, other)
11072 return isinstance(s, ReRef)
11076 """Create regular expression membership test
11077 >>> re = Union(Re("a"),Re("b"))
11078 >>> print (simplify(InRe("a", re)))
11080 >>> print (simplify(InRe("b", re)))
11082 >>> print (simplify(InRe("c", re)))
11085 s = _coerce_seq(s, re.ctx)
11090 """Create union of regular expressions.
11091 >>> re = Union(Re("a"), Re("b"), Re("c"))
11092 >>> print (simplify(InRe("d", re)))
11095 args = _get_args(args)
11098 _z3_assert(sz > 0,
"At least one argument expected.")
11099 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
11104 for i
in range(sz):
11105 v[i] = args[i].as_ast()
11110 """Create intersection of regular expressions.
11111 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11113 args = _get_args(args)
11116 _z3_assert(sz > 0,
"At least one argument expected.")
11117 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
11122 for i
in range(sz):
11123 v[i] = args[i].as_ast()
11128 """Create the regular expression accepting one or more repetitions of argument.
11129 >>> re = Plus(Re("a"))
11130 >>> print(simplify(InRe("aa", re)))
11132 >>> print(simplify(InRe("ab", re)))
11134 >>> print(simplify(InRe("", re)))
11141 """Create the regular expression that optionally accepts the argument.
11142 >>> re = Option(Re("a"))
11143 >>> print(simplify(InRe("a", re)))
11145 >>> print(simplify(InRe("", re)))
11147 >>> print(simplify(InRe("aa", re)))
11154 """Create the complement regular expression."""
11159 """Create the regular expression accepting zero or more repetitions of argument.
11160 >>> re = Star(Re("a"))
11161 >>> print(simplify(InRe("aa", re)))
11163 >>> print(simplify(InRe("ab", re)))
11165 >>> print(simplify(InRe("", re)))
11172 """Create the regular expression accepting between a lower and upper bound repetitions
11173 >>> re = Loop(Re("a"), 1, 3)
11174 >>> print(simplify(InRe("aa", re)))
11176 >>> print(simplify(InRe("aaaa", re)))
11178 >>> print(simplify(InRe("", re)))
11185 """Create the range regular expression over two sequences of length 1
11186 >>> range = Range("a","z")
11187 >>> print(simplify(InRe("b", range)))
11189 >>> print(simplify(InRe("bb", range)))
11192 lo = _coerce_seq(lo, ctx)
11193 hi = _coerce_seq(hi, ctx)
11197 """Create the difference regular epression
11202 """Create a regular expression that accepts all single character strings
11226 """Given a binary relation R, such that the two arguments have the same sort
11227 create the transitive closure relation R+.
11228 The transitive closure R+ is a new relation.
11239 if self.
locklock
is None:
11241 self.
locklock = threading.Lock()
11245 with self.
locklock:
11246 r = self.
basesbases[ctx]
11248 r = self.
basesbases[ctx]
11253 with self.
locklock:
11254 self.
basesbases[ctx] = r
11256 self.
basesbases[ctx] = r
11260 with self.
locklock:
11261 id = len(self.
basesbases) + 3
11262 self.
basesbases[id] = r
11264 id = len(self.
basesbases) + 3
11265 self.
basesbases[id] = r
11269 _prop_closures =
None
11273 global _prop_closures
11274 if _prop_closures
is None:
11279 prop = _prop_closures.get(ctx)
11285 prop = _prop_closures.get(ctx)
11287 prop.pop(num_scopes)
11291 _prop_closures.set_threaded()
11292 prop = _prop_closures.get(id)
11293 new_prop = prop.fresh()
11294 _prop_closures.set(new_prop.id, new_prop)
11295 return ctypes.c_void_p(new_prop.id)
11299 super(ctypes.c_void_p, ast).__init__(ptr)
11303 prop = _prop_closures.get(ctx)
11305 id = _to_expr_ref(
to_Ast(id), prop.ctx())
11306 value = _to_expr_ref(
to_Ast(value), prop.ctx())
11307 prop.fixed(id, value)
11311 prop = _prop_closures.get(ctx)
11317 prop = _prop_closures.get(ctx)
11319 x = _to_expr_ref(
to_Ast(x), prop.ctx())
11320 y = _to_expr_ref(
to_Ast(y), prop.ctx())
11325 prop = _prop_closures.get(ctx)
11327 x = _to_expr_ref(
to_Ast(x), prop.ctx())
11328 y = _to_expr_ref(
to_Ast(y), prop.ctx())
11333 _user_prop_push = push_eh_type(user_prop_push)
11334 _user_prop_pop = pop_eh_type(user_prop_pop)
11335 _user_prop_fresh = fresh_eh_type(user_prop_fresh)
11336 _user_prop_fixed = fixed_eh_type(user_prop_fixed)
11337 _user_prop_final = final_eh_type(user_prop_final)
11338 _user_prop_eq = eq_eh_type(user_prop_eq)
11339 _user_prop_diseq = eq_eh_type(user_prop_diseq)
11352 assert s
is None or ctx
is None
11355 self.
_ctx_ctx =
None
11357 self.
idid = _prop_closures.insert(self)
11372 ctypes.c_void_p(self.
idid),
11379 self.
_ctx_ctx.ctx =
None
11383 return self.
_ctx_ctx
11385 return self.
solversolver.ctx
11388 return self.
ctxctx().ref()
11391 assert not self.
fixedfixed
11392 assert not self.
_ctx_ctx
11394 self.
fixedfixed = fixed
11397 assert not self.
finalfinal
11398 assert not self.
_ctx_ctx
11400 self.
finalfinal = final
11403 assert not self.
eqeq
11404 assert not self.
_ctx_ctx
11409 assert not self.
diseqdiseq
11410 assert not self.
_ctx_ctx
11412 self.
diseqdiseq = diseq
11415 raise Z3Exception(
"push needs to be overwritten")
11418 raise Z3Exception(
"pop needs to be overwritten")
11421 raise Z3Exception(
"fresh needs to be overwritten")
11424 assert self.
solversolver
11425 assert not self.
_ctx_ctx
11432 _ids, num_fixed = _to_ast_array(ids)
11434 _lhs, _num_lhs = _to_ast_array([x
for x, y
in eqs])
11435 _rhs, _num_rhs = _to_ast_array([y
for x, y
in eqs])
11437 self.
cbcb), num_fixed, _ids, num_eqs, _lhs, _rhs, e.ast)
def as_decimal(self, prec)
def approx(self, precision=10)
def __getitem__(self, idx)
def __init__(self, result, ctx)
def __deepcopy__(self, memo={})
def __radd__(self, other)
def __rmul__(self, other)
def __rsub__(self, other)
def __rtruediv__(self, other)
def __rdiv__(self, other)
def __truediv__(self, other)
def __rpow__(self, other)
def __rmod__(self, other)
def __getitem__(self, arg)
def __init__(self, m=None, ctx=None)
def __getitem__(self, key)
def __deepcopy__(self, memo={})
def __setitem__(self, k, v)
def __contains__(self, key)
def __init__(self, ast, ctx=None)
def translate(self, target)
def __deepcopy__(self, memo={})
def __contains__(self, item)
def __init__(self, v=None, ctx=None)
def __setitem__(self, i, v)
def translate(self, other_ctx)
def __deepcopy__(self, memo={})
def as_binary_string(self)
def __rlshift__(self, other)
def __radd__(self, other)
def __rxor__(self, other)
def __rshift__(self, other)
def __rand__(self, other)
def __rmul__(self, other)
def __rsub__(self, other)
def __rtruediv__(self, other)
def __rdiv__(self, other)
def __lshift__(self, other)
def __rrshift__(self, other)
def __truediv__(self, other)
def __rmod__(self, other)
def __rmul__(self, other)
def __deepcopy__(self, memo={})
def __init__(self, *args, **kws)
def __init__(self, name, ctx=None)
def declare(self, name, *args)
def declare_core(self, name, rec_name, *args)
def __deepcopy__(self, memo={})
def recognizer(self, idx)
def num_constructors(self)
def constructor(self, idx)
def exponent(self, biased=True)
def significand_as_bv(self)
def exponent_as_long(self, biased=True)
def significand_as_long(self)
def exponent_as_bv(self, biased=True)
def __radd__(self, other)
def __rmul__(self, other)
def __rsub__(self, other)
def __rtruediv__(self, other)
def __rdiv__(self, other)
def __truediv__(self, other)
def __rmod__(self, other)
def abstract(self, fml, is_forall=True)
def fact(self, head, name=None)
def rule(self, head, body=None, name=None)
def to_string(self, queries)
def add_cover(self, level, predicate, property)
def add_rule(self, head, body=None, name=None)
def assert_exprs(self, *args)
def update_rule(self, head, body, name)
def query_from_lvl(self, lvl, *query)
def parse_string(self, s)
def get_rules_along_trace(self)
def get_ground_sat_answer(self)
def set_predicate_representation(self, f, *representations)
def get_cover_delta(self, level, predicate)
def __deepcopy__(self, memo={})
def get_num_levels(self, predicate)
def declare_var(self, *vars)
def set(self, *args, **keys)
def __init__(self, fixedpoint=None, ctx=None)
def register_relation(self, *relations)
def get_rule_names_along_trace(self)
def __call__(self, *args)
def __init__(self, entry, ctx)
def __deepcopy__(self, memo={})
def __init__(self, f, ctx)
def translate(self, other_ctx)
def __deepcopy__(self, memo={})
def dimacs(self, include_names=True)
def convert_model(self, model)
def assert_exprs(self, *args)
def __getitem__(self, arg)
def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None)
def translate(self, target)
def __deepcopy__(self, memo={})
def simplify(self, *arguments, **keywords)
def as_binary_string(self)
def get_universe(self, s)
def eval(self, t, model_completion=False)
def __init__(self, m, ctx)
def __getitem__(self, idx)
def update_value(self, x, value)
def translate(self, target)
def evaluate(self, t, model_completion=False)
def __deepcopy__(self, memo={})
def get_interp(self, decl)
def add_soft(self, arg, weight="1", id=None)
def assert_exprs(self, *args)
def upper_values(self, obj)
def from_file(self, filename)
def set_on_model(self, on_model)
def check(self, *assumptions)
def __deepcopy__(self, memo={})
def assert_and_track(self, a, p)
def set(self, *args, **keys)
def lower_values(self, obj)
def __init__(self, ctx=None)
def __init__(self, opt, value, is_max)
def __getitem__(self, arg)
def __init__(self, descr, ctx=None)
def get_documentation(self, n)
def __deepcopy__(self, memo={})
def __init__(self, ctx=None, params=None)
def __deepcopy__(self, memo={})
def __init__(self, probe, ctx=None)
def __deepcopy__(self, memo={})
def no_pattern(self, idx)
def num_no_patterns(self)
def __getitem__(self, arg)
def as_decimal(self, prec)
def numerator_as_long(self)
def denominator_as_long(self)
def __init__(self, c, ctx)
def __init__(self, c, ctx)
def __radd__(self, other)
def is_string_value(self)
Strings, Sequences and Regular expressions.
def dimacs(self, include_names=True)
def import_model_converter(self, other)
def __init__(self, solver=None, ctx=None, logFile=None)
def assert_exprs(self, *args)
def cube(self, vars=None)
def from_file(self, filename)
def check(self, *assumptions)
def translate(self, target)
def __deepcopy__(self, memo={})
def consequences(self, assumptions, variables)
def assert_and_track(self, a, p)
def set(self, *args, **keys)
def __getattr__(self, name)
def __getitem__(self, idx)
def __init__(self, stats, ctx)
def get_key_value(self, key)
def __deepcopy__(self, memo={})
def __call__(self, goal, *arguments, **keywords)
def solver(self, logFile=None)
def __init__(self, tactic, ctx=None)
def __deepcopy__(self, memo={})
def apply(self, goal, *arguments, **keywords)
def add_fixed(self, fixed)
def add_diseq(self, diseq)
def pop(self, num_scopes)
def __init__(self, s, ctx=None)
def propagate(self, e, ids, eqs=[])
def add_final(self, final)
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.
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.
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_int_sort(Z3_context c)
Create the integer type.
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_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.
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
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_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_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_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
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.
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_ast Z3_API Z3_mk_char_to_bv(Z3_context c, Z3_ast ch)
Create a bit-vector (code point) from character.
void Z3_API Z3_solver_propagate_diseq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression dis-equalities.
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.
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
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.
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
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:
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_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 ...
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.
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
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_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
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_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_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_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.
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_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.
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
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...
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,...
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 Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
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_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...
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
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.
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_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....
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
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.
Z3_ast Z3_API Z3_mk_char_le(Z3_context c, Z3_ast ch1, Z3_ast ch2)
Create less than or equal to between two characters.
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.
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_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.
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.
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_mk_true(Z3_context c)
Create an AST node representing true.
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.
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.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
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_func_interp Z3_API Z3_add_func_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast default_value)
Create a fresh func_interp object, add it to a model for a specified function. It has reference count...
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.
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
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_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
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.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
Z3_ast Z3_API Z3_mk_string_from_code(Z3_context c, Z3_ast a)
Code to string conversion.
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_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
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.
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....
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.
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_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed 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.
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_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
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_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
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.
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
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.
bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int *sgn)
Retrieves the sign of a floating-point literal.
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
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...
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].
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
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_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.
Z3_ast Z3_API Z3_mk_re_allchar(Z3_context c, Z3_sort regex_sort)
Create a regular expression that accepts all singleton sequences of the regular expression sort.
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
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_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
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.
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
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_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,...
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
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....
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_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
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.
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_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
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_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
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.
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
Z3_char_ptr Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned *length)
Retrieve the string constant stored in s. The string can contain escape sequences....
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,...
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
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_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
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.
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.
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.
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a NaN.
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.
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 ...
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 ...
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_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.
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_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.
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.
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_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 Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
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_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.
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.
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.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
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.
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...
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_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
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.
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
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_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.
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_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
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.
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.
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_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.
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_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
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_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...
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
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_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs)
n-ary Array read. The argument a is the array and idxs are the indices of the array that gets read.
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s)
Check if s is a string sort.
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_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
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.
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_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_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
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.
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.
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.
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.
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 ...
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.
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
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.
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.
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_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is subnormal.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
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.
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_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.
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.
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_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...
Z3_sort Z3_API Z3_get_array_sort_domain_n(Z3_context c, Z3_sort t, unsigned idx)
Return the i'th domain sort of an n-dimensional array.
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_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
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.
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
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.
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
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.
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_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
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_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_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...
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.
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
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_sort Z3_API Z3_get_re_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for regex sort.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
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.
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s)
Return a string describing all solver available parameters.
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.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
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,...
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_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
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.
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
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.
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.
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_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
Z3_func_decl Z3_API Z3_mk_fresh_func_decl(Z3_context c, Z3_string prefix, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a fresh constant or function.
void Z3_API Z3_solver_propagate_final(Z3_context c, Z3_solver s, Z3_final_eh final_eh)
register a callback on final check. This provides freedom to the propagator to delay actions or imple...
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_param_descrs_size(Z3_context c, Z3_param_descrs p)
Return the number of parameters in the given parameter description set.
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.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
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_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
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_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
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.
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
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 Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
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.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
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_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_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
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_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of the first occurrence of substr in s starting from offset offset. If s does not contai...
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...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
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 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.
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
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_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.
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_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
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_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_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
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_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
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...
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.
void Z3_API Z3_solver_propagate_init(Z3_context c, Z3_solver s, void *user_context, Z3_push_eh push_eh, Z3_pop_eh pop_eh, Z3_fresh_eh fresh_eh)
register a user-properator with the solver.
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.
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
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...
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
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.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
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_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_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
Z3_ast Z3_API Z3_mk_char(Z3_context c, unsigned ch)
Create a character literal.
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.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
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.
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
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.
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.
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.
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_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
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_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
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_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
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_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
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...
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
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.
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_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
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.
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.
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.
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
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...
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.
unsigned Z3_API Z3_solver_get_num_scopes(Z3_context c, Z3_solver s)
Return the number of backtracking points.
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
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_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.
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_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
void Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback, unsigned num_fixed, Z3_ast const *fixed, unsigned num_eqs, Z3_ast const *eq_lhs, Z3_ast const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values. This is a callback a client may invoke during the fixe...
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
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_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
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_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...
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
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_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.
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_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.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
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_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.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
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...
Z3_ast Z3_API Z3_mk_char_to_int(Z3_context c, Z3_ast ch)
Create an integer (code point) from character.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
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.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
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...
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
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...
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.
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 but two different AST objects can m...
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_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
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_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
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...
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
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_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
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_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
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_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.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
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.
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.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in The string may contain escape encoding f...
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
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...
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.
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.
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.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
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_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return index of the last occurrence of substr in s. If s does not contain substr, then the value is -...
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.
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_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.
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...
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
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_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
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_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...
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.
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....
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
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.
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
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.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
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.
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_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.
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_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
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_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs, Z3_ast v)
n-ary Array update.
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_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.
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
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_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.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
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_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
Z3_string Z3_API Z3_solver_to_dimacs_string(Z3_context c, Z3_solver s, bool include_names)
Convert a solver into a DIMACS formatted string.
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.
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_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
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_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
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.
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
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....
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
void Z3_API Z3_solver_propagate_register(Z3_context c, Z3_solver s, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
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_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_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
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...
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
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.
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.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
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_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
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_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a decimal string of a numeric constant term.
void Z3_API Z3_solver_propagate_fixed(Z3_context c, Z3_solver s, Z3_fixed_eh fixed_eh)
register a callback for when an expression is bound to a fixed value. The supported expression types ...
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.
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...
Z3_ast Z3_API Z3_mk_char_is_digit(Z3_context c, Z3_ast ch)
Create a check if the character is a digit.
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...
void Z3_API Z3_func_interp_add_entry(Z3_context c, Z3_func_interp fi, Z3_ast_vector args, Z3_ast value)
add a function entry to a function interpretation.
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
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.
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_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
void Z3_API Z3_optimize_register_model_eh(Z3_context c, Z3_optimize o, Z3_model m, void *ctx, Z3_model_eh model_eh)
register a model event handler for new models.
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
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...
Z3_string Z3_API Z3_get_numeral_binary_string(Z3_context c, Z3_ast a)
Return numeral value, as a binary string of a numeric constant term.
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.
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.
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_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
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.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
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.
Z3_ast Z3_API Z3_mk_char_from_bv(Z3_context c, Z3_ast bv)
Create a character from a bit-vector (code point).
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.
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.
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_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
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_...
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.
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
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...
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_string_to_code(Z3_context c, Z3_ast a)
String to code conversion.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.
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.
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_bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
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.
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
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...
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_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
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.
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
expr range(expr const &lo, expr const &hi)
def fpIsNegative(a, ctx=None)
def fpFP(sgn, exp, sig, ctx=None)
def fpToFP(a1, a2=None, a3=None, ctx=None)
def PiecewiseLinearOrder(a, index)
def fpRealToFP(rm, v, sort, ctx=None)
def fpUnsignedToFP(rm, v, sort, ctx=None)
def fpAdd(rm, a, b, ctx=None)
def RealVarVector(n, ctx=None)
def RoundNearestTiesToEven(ctx=None)
def fpRoundToIntegral(rm, a, ctx=None)
def BVMulNoOverflow(a, b, signed)
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
def BVSDivNoOverflow(a, b)
def get_default_rounding_mode(ctx=None)
def fpFPToFP(rm, v, sort, ctx=None)
def simplify(a, *arguments, **keywords)
Utils.
def ParThen(t1, t2, ctx=None)
def substitute_vars(t, *m)
def user_prop_push(ctx, cb)
def fpToReal(x, ctx=None)
def BoolVector(prefix, sz, ctx=None)
def BitVec(name, bv, ctx=None)
def Repeat(t, max=4294967295, ctx=None)
def BitVecs(names, bv, ctx=None)
def DeclareSort(name, ctx=None)
def With(t, *args, **keys)
def args2params(arguments, keywords, ctx=None)
def PbEq(args, k, ctx=None)
def fpSqrt(rm, a, ctx=None)
def Reals(names, ctx=None)
def fpGEQ(a, b, ctx=None)
def FiniteDomainVal(val, sort, ctx=None)
def set_default_rounding_mode(rm, ctx=None)
def z3_error_handler(c, e)
def TryFor(t, ms, ctx=None)
def simplify_param_descrs()
def ensure_prop_closures()
def fpIsPositive(a, ctx=None)
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
def set_option(*args, **kws)
def CharVal(ch, ctx=None)
def Extract(high, low, a)
def BVAddNoUnderflow(a, b)
def get_default_fp_sort(ctx=None)
def fpIsZero(a, ctx=None)
def Range(lo, hi, ctx=None)
def set_param(*args, **kws)
def Bools(names, ctx=None)
def fpToFPUnsigned(rm, x, s, ctx=None)
def CharToInt(ch, ctx=None)
def FloatQuadruple(ctx=None)
def fpToUBV(rm, x, s, ctx=None)
def fpMax(a, b, ctx=None)
def AllChar(regex_sort, ctx=None)
def FPVal(sig, exp=None, fps=None, ctx=None)
def solve_using(s, *args, **keywords)
def FloatDouble(ctx=None)
def LinearOrder(a, index)
def probe_description(name, ctx=None)
def IndexOf(s, substr, offset=None)
def user_prop_fixed(ctx, cb, id, value)
def SimpleSolver(ctx=None, logFile=None)
def FreshInt(prefix="x", ctx=None)
def SolverFor(logic, ctx=None, logFile=None)
def FreshBool(prefix="b", ctx=None)
def BVAddNoOverflow(a, b, signed)
def SubString(s, offset, length)
def RecAddDefinition(f, args, body)
def fpRem(a, b, ctx=None)
def BitVecVal(val, bv, ctx=None)
def If(a, b, c, ctx=None)
def fpSignedToFP(rm, v, sort, ctx=None)
def BV2Int(a, is_signed=False)
def Cond(p, t1, t2, ctx=None)
def PartialOrder(a, index)
def RoundNearestTiesToAway(ctx=None)
def IntVector(prefix, sz, ctx=None)
def FPs(names, fpsort, ctx=None)
def BVSubNoOverflow(a, b)
def user_prop_pop(ctx, cb, num_scopes)
def solve(*args, **keywords)
def CharFromBv(ch, ctx=None)
def FloatSingle(ctx=None)
def user_prop_fresh(id, ctx)
def RealVar(idx, ctx=None)
def SubSeq(s, offset, length)
def fpNEQ(a, b, ctx=None)
def Ints(names, ctx=None)
def fpIsNormal(a, ctx=None)
def RatVal(a, b, ctx=None)
def fpMin(a, b, ctx=None)
def EnumSort(name, values, ctx=None)
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
def fpSub(rm, a, b, ctx=None)
def CharIsDigit(ch, ctx=None)
def is_finite_domain_sort(s)
def LastIndexOf(s, substr)
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
def RealVector(prefix, sz, ctx=None)
def is_finite_domain_value(a)
def fpToIEEEBV(x, ctx=None)
def FreshConst(sort, prefix="c")
def Implies(a, b, ctx=None)
def RoundTowardZero(ctx=None)
def RealVal(val, ctx=None)
def is_algebraic_value(a)
def String(name, ctx=None)
def user_prop_final(ctx, cb)
def fpLEQ(a, b, ctx=None)
def FiniteDomainSort(name, sz, ctx=None)
def fpDiv(rm, a, b, ctx=None)
def user_prop_eq(ctx, cb, x, y)
def FP(name, fpsort, ctx=None)
def BVSubNoUnderflow(a, b, signed)
def RecFunction(name, *sig)
def user_prop_diseq(ctx, cb, x, y)
def fpBVToFP(v, sort, ctx=None)
def RoundTowardNegative(ctx=None)
def CharToBv(ch, ctx=None)
def FPSort(ebits, sbits, ctx=None)
def tactic_description(name, ctx=None)
def Strings(names, ctx=None)
def BVMulNoUnderflow(a, b)
def TupleSort(name, sorts, ctx=None)
def fpMul(rm, a, b, ctx=None)
def StringVal(s, ctx=None)
def to_symbol(s, ctx=None)
def ParAndThen(t1, t2, ctx=None)
def RoundTowardPositive(ctx=None)
def BoolVal(val, ctx=None)
def FreshReal(prefix="b", ctx=None)
def fpFMA(rm, a, b, c, ctx=None)
def set_default_fp_sort(ebits, sbits, ctx=None)
def fpIsSubnormal(a, ctx=None)
def DisjointSum(name, sorts, ctx=None)
def fpToSBV(rm, x, s, ctx=None)
def BitVecSort(sz, ctx=None)
def fpInfinity(s, negative)
def IntVal(val, ctx=None)
def prove(claim, show=False, **keywords)