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())
1105 def _to_expr_ref(a, ctx):
1106 if isinstance(a, Pattern):
1110 if k == Z3_QUANTIFIER_AST:
1113 if sk == Z3_BOOL_SORT:
1115 if sk == Z3_INT_SORT:
1116 if k == Z3_NUMERAL_AST:
1119 if sk == Z3_REAL_SORT:
1120 if k == Z3_NUMERAL_AST:
1122 if _is_algebraic(ctx, a):
1125 if sk == Z3_BV_SORT:
1126 if k == Z3_NUMERAL_AST:
1130 if sk == Z3_ARRAY_SORT:
1132 if sk == Z3_DATATYPE_SORT:
1134 if sk == Z3_FLOATING_POINT_SORT:
1135 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1138 return FPRef(a, ctx)
1139 if sk == Z3_FINITE_DOMAIN_SORT:
1140 if k == Z3_NUMERAL_AST:
1144 if sk == Z3_ROUNDING_MODE_SORT:
1146 if sk == Z3_SEQ_SORT:
1148 if sk == Z3_CHAR_SORT:
1150 if sk == Z3_RE_SORT:
1151 return ReRef(a, ctx)
1155 def _coerce_expr_merge(s, a):
1168 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1169 _z3_assert(
False,
"sort mismatch")
1174 def _coerce_exprs(a, b, ctx=None):
1176 a = _py2expr(a, ctx)
1177 b = _py2expr(b, ctx)
1178 if isinstance(a, str)
and isinstance(b, SeqRef):
1180 if isinstance(b, str)
and isinstance(a, SeqRef):
1183 s = _coerce_expr_merge(s, a)
1184 s = _coerce_expr_merge(s, b)
1190 def _reduce(func, sequence, initial):
1192 for element
in sequence:
1193 result = func(result, element)
1197 def _coerce_expr_list(alist, ctx=None):
1204 alist = [_py2expr(a, ctx)
for a
in alist]
1205 s = _reduce(_coerce_expr_merge, alist,
None)
1206 return [s.cast(a)
for a
in alist]
1210 """Return `True` if `a` is a Z3 expression.
1217 >>> is_expr(IntSort())
1221 >>> is_expr(IntVal(1))
1224 >>> is_expr(ForAll(x, x >= 0))
1226 >>> is_expr(FPVal(1.0))
1229 return isinstance(a, ExprRef)
1233 """Return `True` if `a` is a Z3 function application.
1235 Note that, constants are function applications with 0 arguments.
1242 >>> is_app(IntSort())
1246 >>> is_app(IntVal(1))
1249 >>> is_app(ForAll(x, x >= 0))
1252 if not isinstance(a, ExprRef):
1254 k = _ast_kind(a.ctx, a)
1255 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1259 """Return `True` if `a` is Z3 constant/variable expression.
1268 >>> is_const(IntVal(1))
1271 >>> is_const(ForAll(x, x >= 0))
1274 return is_app(a)
and a.num_args() == 0
1278 """Return `True` if `a` is variable.
1280 Z3 uses de-Bruijn indices for representing bound variables in
1288 >>> f = Function('f', IntSort(), IntSort())
1289 >>> # Z3 replaces x with bound variables when ForAll is executed.
1290 >>> q = ForAll(x, f(x) == x)
1296 >>> is_var(b.arg(1))
1299 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1303 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1311 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1312 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1313 >>> q = ForAll([x, y], f(x, y) == x + y)
1315 f(Var(1), Var(0)) == Var(1) + Var(0)
1319 >>> v1 = b.arg(0).arg(0)
1320 >>> v2 = b.arg(0).arg(1)
1325 >>> get_var_index(v1)
1327 >>> get_var_index(v2)
1331 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1336 """Return `True` if `a` is an application of the given kind `k`.
1340 >>> is_app_of(n, Z3_OP_ADD)
1342 >>> is_app_of(n, Z3_OP_MUL)
1345 return is_app(a)
and a.decl().kind() == k
1348 def If(a, b, c, ctx=None):
1349 """Create a Z3 if-then-else expression.
1353 >>> max = If(x > y, x, y)
1359 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1360 return Cond(a, b, c, ctx)
1362 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1365 b, c = _coerce_exprs(b, c, ctx)
1367 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1368 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1372 """Create a Z3 distinct expression.
1379 >>> Distinct(x, y, z)
1381 >>> simplify(Distinct(x, y, z))
1383 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1384 And(Not(x == y), Not(x == z), Not(y == z))
1386 args = _get_args(args)
1387 ctx = _ctx_from_ast_arg_list(args)
1389 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1390 args = _coerce_expr_list(args, ctx)
1391 _args, sz = _to_ast_array(args)
1395 def _mk_bin(f, a, b):
1398 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1399 args[0] = a.as_ast()
1400 args[1] = b.as_ast()
1401 return f(a.ctx.ref(), 2, args)
1405 """Create a constant of the given sort.
1407 >>> Const('x', IntSort())
1411 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1417 """Create several constants of the given sort.
1419 `names` is a string containing the names of all constants to be created.
1420 Blank spaces separate the names of different constants.
1422 >>> x, y, z = Consts('x y z', IntSort())
1426 if isinstance(names, str):
1427 names = names.split(
" ")
1428 return [
Const(name, sort)
for name
in names]
1432 """Create a fresh constant of a specified sort"""
1433 ctx = _get_ctx(sort.ctx)
1438 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1440 >>> Var(0, IntSort())
1442 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1446 _z3_assert(
is_sort(s),
"Z3 sort expected")
1447 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1452 Create a real free variable. Free variables are used to create quantified formulas.
1453 They are also used to create polynomials.
1463 Create a list of Real free variables.
1464 The variables have ids: 0, 1, ..., n-1
1466 >>> x0, x1, x2, x3 = RealVarVector(4)
1483 """Try to cast `val` as a Boolean.
1485 >>> x = BoolSort().cast(True)
1495 if isinstance(val, bool):
1499 msg =
"True, False or Z3 Boolean expression expected. Received %s of type %s"
1500 _z3_assert(
is_expr(val), msg % (val, type(val)))
1501 if not self.
eqeq(val.sort()):
1502 _z3_assert(self.
eqeq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1506 return isinstance(other, ArithSortRef)
1516 """All Boolean expressions are instances of this class."""
1525 """Create the Z3 expression `self * other`.
1531 return If(self, other, 0)
1535 """Return `True` if `a` is a Z3 Boolean expression.
1541 >>> is_bool(And(p, q))
1549 return isinstance(a, BoolRef)
1553 """Return `True` if `a` is the Z3 true expression.
1558 >>> is_true(simplify(p == p))
1563 >>> # True is a Python Boolean expression
1571 """Return `True` if `a` is the Z3 false expression.
1578 >>> is_false(BoolVal(False))
1585 """Return `True` if `a` is a Z3 and expression.
1587 >>> p, q = Bools('p q')
1588 >>> is_and(And(p, q))
1590 >>> is_and(Or(p, q))
1597 """Return `True` if `a` is a Z3 or expression.
1599 >>> p, q = Bools('p q')
1602 >>> is_or(And(p, q))
1609 """Return `True` if `a` is a Z3 implication expression.
1611 >>> p, q = Bools('p q')
1612 >>> is_implies(Implies(p, q))
1614 >>> is_implies(And(p, q))
1621 """Return `True` if `a` is a Z3 not expression.
1633 """Return `True` if `a` is a Z3 equality expression.
1635 >>> x, y = Ints('x y')
1643 """Return `True` if `a` is a Z3 distinct expression.
1645 >>> x, y, z = Ints('x y z')
1646 >>> is_distinct(x == y)
1648 >>> is_distinct(Distinct(x, y, z))
1655 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1659 >>> p = Const('p', BoolSort())
1662 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1665 >>> is_bool(r(0, 1))
1673 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1677 >>> is_true(BoolVal(True))
1681 >>> is_false(BoolVal(False))
1692 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1704 """Return a tuple of Boolean constants.
1706 `names` is a single string containing all names separated by blank spaces.
1707 If `ctx=None`, then the global context is used.
1709 >>> p, q, r = Bools('p q r')
1710 >>> And(p, Or(q, r))
1714 if isinstance(names, str):
1715 names = names.split(
" ")
1716 return [
Bool(name, ctx)
for name
in names]
1720 """Return a list of Boolean constants of size `sz`.
1722 The constants are named using the given prefix.
1723 If `ctx=None`, then the global context is used.
1725 >>> P = BoolVector('p', 3)
1729 And(p__0, p__1, p__2)
1731 return [
Bool(
"%s__%s" % (prefix, i))
for i
in range(sz)]
1735 """Return a fresh Boolean constant in the given context using the given prefix.
1737 If `ctx=None`, then the global context is used.
1739 >>> b1 = FreshBool()
1740 >>> b2 = FreshBool()
1749 """Create a Z3 implies expression.
1751 >>> p, q = Bools('p q')
1755 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1763 """Create a Z3 Xor expression.
1765 >>> p, q = Bools('p q')
1768 >>> simplify(Xor(p, q))
1771 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1779 """Create a Z3 not expression or probe.
1784 >>> simplify(Not(Not(p)))
1787 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1804 def _has_probe(args):
1805 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1813 """Create a Z3 and-expression or and-probe.
1815 >>> p, q, r = Bools('p q r')
1818 >>> P = BoolVector('p', 5)
1820 And(p__0, p__1, p__2, p__3, p__4)
1824 last_arg = args[len(args) - 1]
1825 if isinstance(last_arg, Context):
1826 ctx = args[len(args) - 1]
1827 args = args[:len(args) - 1]
1828 elif len(args) == 1
and isinstance(args[0], AstVector):
1830 args = [a
for a
in args[0]]
1833 args = _get_args(args)
1834 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1836 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1837 if _has_probe(args):
1838 return _probe_and(args, ctx)
1840 args = _coerce_expr_list(args, ctx)
1841 _args, sz = _to_ast_array(args)
1846 """Create a Z3 or-expression or or-probe.
1848 >>> p, q, r = Bools('p q r')
1851 >>> P = BoolVector('p', 5)
1853 Or(p__0, p__1, p__2, p__3, p__4)
1857 last_arg = args[len(args) - 1]
1858 if isinstance(last_arg, Context):
1859 ctx = args[len(args) - 1]
1860 args = args[:len(args) - 1]
1861 elif len(args) == 1
and isinstance(args[0], AstVector):
1863 args = [a
for a
in args[0]]
1866 args = _get_args(args)
1867 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1869 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1870 if _has_probe(args):
1871 return _probe_or(args, ctx)
1873 args = _coerce_expr_list(args, ctx)
1874 _args, sz = _to_ast_array(args)
1885 """Patterns are hints for quantifier instantiation.
1897 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1899 >>> f = Function('f', IntSort(), IntSort())
1901 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1903 ForAll(x, f(x) == 0)
1904 >>> q.num_patterns()
1906 >>> is_pattern(q.pattern(0))
1911 return isinstance(a, PatternRef)
1915 """Create a Z3 multi-pattern using the given expressions `*args`
1917 >>> f = Function('f', IntSort(), IntSort())
1918 >>> g = Function('g', IntSort(), IntSort())
1920 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1922 ForAll(x, f(x) != g(x))
1923 >>> q.num_patterns()
1925 >>> is_pattern(q.pattern(0))
1928 MultiPattern(f(Var(0)), g(Var(0)))
1931 _z3_assert(len(args) > 0,
"At least one argument expected")
1932 _z3_assert(all([
is_expr(a)
for a
in args]),
"Z3 expressions expected")
1934 args, sz = _to_ast_array(args)
1938 def _to_pattern(arg):
1952 """Universally and Existentially quantified formulas."""
1961 """Return the Boolean sort or sort of Lambda."""
1967 """Return `True` if `self` is a universal quantifier.
1969 >>> f = Function('f', IntSort(), IntSort())
1971 >>> q = ForAll(x, f(x) == 0)
1974 >>> q = Exists(x, f(x) != 0)
1981 """Return `True` if `self` is an existential quantifier.
1983 >>> f = Function('f', IntSort(), IntSort())
1985 >>> q = ForAll(x, f(x) == 0)
1988 >>> q = Exists(x, f(x) != 0)
1995 """Return `True` if `self` is a lambda expression.
1997 >>> f = Function('f', IntSort(), IntSort())
1999 >>> q = Lambda(x, f(x))
2002 >>> q = Exists(x, f(x) != 0)
2009 """Return the Z3 expression `self[arg]`.
2012 _z3_assert(self.
is_lambdais_lambda(),
"quantifier should be a lambda expression")
2013 return _array_select(self, arg)
2016 """Return the weight annotation of `self`.
2018 >>> f = Function('f', IntSort(), IntSort())
2020 >>> q = ForAll(x, f(x) == 0)
2023 >>> q = ForAll(x, f(x) == 0, weight=10)
2030 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2032 >>> f = Function('f', IntSort(), IntSort())
2033 >>> g = Function('g', IntSort(), IntSort())
2035 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2036 >>> q.num_patterns()
2042 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2044 >>> f = Function('f', IntSort(), IntSort())
2045 >>> g = Function('g', IntSort(), IntSort())
2047 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2048 >>> q.num_patterns()
2056 _z3_assert(idx < self.
num_patternsnum_patterns(),
"Invalid pattern idx")
2060 """Return the number of no-patterns."""
2064 """Return a no-pattern."""
2066 _z3_assert(idx < self.
num_no_patternsnum_no_patterns(),
"Invalid no-pattern idx")
2070 """Return the expression being quantified.
2072 >>> f = Function('f', IntSort(), IntSort())
2074 >>> q = ForAll(x, f(x) == 0)
2081 """Return the number of variables bounded by this quantifier.
2083 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2086 >>> q = ForAll([x, y], f(x, y) >= x)
2093 """Return a string representing a name used when displaying the quantifier.
2095 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2098 >>> q = ForAll([x, y], f(x, y) >= x)
2105 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2109 """Return the sort of a bound variable.
2111 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2114 >>> q = ForAll([x, y], f(x, y) >= x)
2121 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2125 """Return a list containing a single element self.body()
2127 >>> f = Function('f', IntSort(), IntSort())
2129 >>> q = ForAll(x, f(x) == 0)
2133 return [self.
bodybody()]
2137 """Return `True` if `a` is a Z3 quantifier.
2139 >>> f = Function('f', IntSort(), IntSort())
2141 >>> q = ForAll(x, f(x) == 0)
2142 >>> is_quantifier(q)
2144 >>> is_quantifier(f(x))
2147 return isinstance(a, QuantifierRef)
2150 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2152 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2153 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2154 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2155 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2166 _vs = (Ast * num_vars)()
2167 for i
in range(num_vars):
2169 _vs[i] = vs[i].as_ast()
2170 patterns = [_to_pattern(p)
for p
in patterns]
2171 num_pats = len(patterns)
2172 _pats = (Pattern * num_pats)()
2173 for i
in range(num_pats):
2174 _pats[i] = patterns[i].ast
2175 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2181 num_no_pats, _no_pats,
2182 body.as_ast()), ctx)
2185 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2186 """Create a Z3 forall formula.
2188 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2190 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2193 >>> ForAll([x, y], f(x, y) >= x)
2194 ForAll([x, y], f(x, y) >= x)
2195 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2196 ForAll([x, y], f(x, y) >= x)
2197 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2198 ForAll([x, y], f(x, y) >= x)
2200 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2203 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2204 """Create a Z3 exists formula.
2206 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2209 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2212 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2214 Exists([x, y], f(x, y) >= x)
2215 >>> is_quantifier(q)
2217 >>> r = Tactic('nnf')(q).as_expr()
2218 >>> is_quantifier(r)
2221 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2225 """Create a Z3 lambda expression.
2227 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2228 >>> mem0 = Array('mem0', IntSort(), IntSort())
2229 >>> lo, hi, e, i = Ints('lo hi e i')
2230 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2232 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2238 _vs = (Ast * num_vars)()
2239 for i
in range(num_vars):
2241 _vs[i] = vs[i].as_ast()
2252 """Real and Integer sorts."""
2255 """Return `True` if `self` is of the sort Real.
2260 >>> (x + 1).is_real()
2266 return self.
kindkind() == Z3_REAL_SORT
2269 """Return `True` if `self` is of the sort Integer.
2274 >>> (x + 1).is_int()
2280 return self.
kindkind() == Z3_INT_SORT
2283 """Return `True` if `self` is a subsort of `other`."""
2287 """Try to cast `val` as an Integer or Real.
2289 >>> IntSort().cast(10)
2291 >>> is_int(IntSort().cast(10))
2295 >>> RealSort().cast(10)
2297 >>> is_real(RealSort().cast(10))
2302 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
2304 if self.
eqeq(val_s):
2306 if val_s.is_int()
and self.
is_realis_real():
2308 if val_s.is_bool()
and self.
is_intis_int():
2309 return If(val, 1, 0)
2310 if val_s.is_bool()
and self.
is_realis_real():
2313 _z3_assert(
False,
"Z3 Integer/Real expression expected")
2320 msg =
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2321 _z3_assert(
False, msg % self)
2325 """Return `True` if s is an arithmetical sort (type).
2327 >>> is_arith_sort(IntSort())
2329 >>> is_arith_sort(RealSort())
2331 >>> is_arith_sort(BoolSort())
2333 >>> n = Int('x') + 1
2334 >>> is_arith_sort(n.sort())
2337 return isinstance(s, ArithSortRef)
2341 """Integer and Real expressions."""
2344 """Return the sort (type) of the arithmetical expression `self`.
2348 >>> (Real('x') + 1).sort()
2354 """Return `True` if `self` is an integer expression.
2359 >>> (x + 1).is_int()
2362 >>> (x + y).is_int()
2368 """Return `True` if `self` is an real expression.
2373 >>> (x + 1).is_real()
2379 """Create the Z3 expression `self + other`.
2388 a, b = _coerce_exprs(self, other)
2389 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctxctx)
2392 """Create the Z3 expression `other + self`.
2398 a, b = _coerce_exprs(self, other)
2399 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctxctx)
2402 """Create the Z3 expression `self * other`.
2411 if isinstance(other, BoolRef):
2412 return If(other, self, 0)
2413 a, b = _coerce_exprs(self, other)
2414 return ArithRef(_mk_bin(Z3_mk_mul, 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_mul, b, a), self.
ctxctx)
2427 """Create the Z3 expression `self - other`.
2436 a, b = _coerce_exprs(self, other)
2437 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctxctx)
2440 """Create the Z3 expression `other - self`.
2446 a, b = _coerce_exprs(self, other)
2447 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctxctx)
2450 """Create the Z3 expression `self**other` (** is the power operator).
2457 >>> simplify(IntVal(2)**8)
2460 a, b = _coerce_exprs(self, other)
2464 """Create the Z3 expression `other**self` (** is the power operator).
2471 >>> simplify(2**IntVal(8))
2474 a, b = _coerce_exprs(self, other)
2478 """Create the Z3 expression `other/self`.
2497 a, b = _coerce_exprs(self, other)
2501 """Create the Z3 expression `other/self`."""
2502 return self.
__div____div__(other)
2505 """Create the Z3 expression `other/self`.
2518 a, b = _coerce_exprs(self, other)
2522 """Create the Z3 expression `other/self`."""
2523 return self.
__rdiv____rdiv__(other)
2526 """Create the Z3 expression `other%self`.
2532 >>> simplify(IntVal(10) % IntVal(3))
2535 a, b = _coerce_exprs(self, other)
2537 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2541 """Create the Z3 expression `other%self`.
2547 a, b = _coerce_exprs(self, other)
2549 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2553 """Return an expression representing `-self`.
2573 """Create the Z3 expression `other <= self`.
2575 >>> x, y = Ints('x y')
2582 a, b = _coerce_exprs(self, other)
2586 """Create the Z3 expression `other < self`.
2588 >>> x, y = Ints('x y')
2595 a, b = _coerce_exprs(self, other)
2599 """Create the Z3 expression `other > self`.
2601 >>> x, y = Ints('x y')
2608 a, b = _coerce_exprs(self, other)
2612 """Create the Z3 expression `other >= self`.
2614 >>> x, y = Ints('x y')
2621 a, b = _coerce_exprs(self, other)
2626 """Return `True` if `a` is an arithmetical expression.
2635 >>> is_arith(IntVal(1))
2643 return isinstance(a, ArithRef)
2647 """Return `True` if `a` is an integer expression.
2654 >>> is_int(IntVal(1))
2666 """Return `True` if `a` is a real expression.
2678 >>> is_real(RealVal(1))
2684 def _is_numeral(ctx, a):
2688 def _is_algebraic(ctx, a):
2693 """Return `True` if `a` is an integer value of sort Int.
2695 >>> is_int_value(IntVal(1))
2699 >>> is_int_value(Int('x'))
2701 >>> n = Int('x') + 1
2706 >>> is_int_value(n.arg(1))
2708 >>> is_int_value(RealVal("1/3"))
2710 >>> is_int_value(RealVal(1))
2713 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2717 """Return `True` if `a` is rational value of sort Real.
2719 >>> is_rational_value(RealVal(1))
2721 >>> is_rational_value(RealVal("3/5"))
2723 >>> is_rational_value(IntVal(1))
2725 >>> is_rational_value(1)
2727 >>> n = Real('x') + 1
2730 >>> is_rational_value(n.arg(1))
2732 >>> is_rational_value(Real('x'))
2735 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2739 """Return `True` if `a` is an algebraic value of sort Real.
2741 >>> is_algebraic_value(RealVal("3/5"))
2743 >>> n = simplify(Sqrt(2))
2746 >>> is_algebraic_value(n)
2749 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2753 """Return `True` if `a` is an expression of the form b + c.
2755 >>> x, y = Ints('x y')
2765 """Return `True` if `a` is an expression of the form b * c.
2767 >>> x, y = Ints('x y')
2777 """Return `True` if `a` is an expression of the form b - c.
2779 >>> x, y = Ints('x y')
2789 """Return `True` if `a` is an expression of the form b / c.
2791 >>> x, y = Reals('x y')
2796 >>> x, y = Ints('x y')
2806 """Return `True` if `a` is an expression of the form b div c.
2808 >>> x, y = Ints('x y')
2818 """Return `True` if `a` is an expression of the form b % c.
2820 >>> x, y = Ints('x y')
2830 """Return `True` if `a` is an expression of the form b <= c.
2832 >>> x, y = Ints('x y')
2842 """Return `True` if `a` is an expression of the form b < c.
2844 >>> x, y = Ints('x y')
2854 """Return `True` if `a` is an expression of the form b >= c.
2856 >>> x, y = Ints('x y')
2866 """Return `True` if `a` is an expression of the form b > c.
2868 >>> x, y = Ints('x y')
2878 """Return `True` if `a` is an expression of the form IsInt(b).
2881 >>> is_is_int(IsInt(x))
2890 """Return `True` if `a` is an expression of the form ToReal(b).
2905 """Return `True` if `a` is an expression of the form ToInt(b).
2920 """Integer values."""
2923 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2932 _z3_assert(self.
is_intis_int(),
"Integer value expected")
2936 """Return a Z3 integer numeral as a Python string.
2944 """Return a Z3 integer numeral as a Python binary string.
2946 >>> v.as_binary_string()
2953 """Rational values."""
2956 """ Return the numerator of a Z3 rational numeral.
2958 >>> is_rational_value(RealVal("3/5"))
2960 >>> n = RealVal("3/5")
2963 >>> is_rational_value(Q(3,5))
2965 >>> Q(3,5).numerator()
2971 """ Return the denominator of a Z3 rational numeral.
2973 >>> is_rational_value(Q(3,5))
2982 """ Return the numerator as a Python long.
2984 >>> v = RealVal(10000000000)
2989 >>> v.numerator_as_long() + 1 == 10000000001
2995 """ Return the denominator as a Python long.
2997 >>> v = RealVal("1/3")
3000 >>> v.denominator_as_long()
3015 _z3_assert(self.
is_int_valueis_int_value(),
"Expected integer fraction")
3019 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3021 >>> v = RealVal("1/5")
3024 >>> v = RealVal("1/3")
3031 """Return a Z3 rational numeral as a Python string.
3040 """Return a Z3 rational as a Python Fraction object.
3042 >>> v = RealVal("1/5")
3050 """Algebraic irrational values."""
3053 """Return a Z3 rational number that approximates the algebraic number `self`.
3054 The result `r` is such that |r - self| <= 1/10^precision
3056 >>> x = simplify(Sqrt(2))
3058 6838717160008073720548335/4835703278458516698824704
3065 """Return a string representation of the algebraic number `self` in decimal notation
3066 using `prec` decimal places.
3068 >>> x = simplify(Sqrt(2))
3069 >>> x.as_decimal(10)
3071 >>> x.as_decimal(20)
3072 '1.41421356237309504880?'
3083 def _py2expr(a, ctx=None):
3084 if isinstance(a, bool):
3088 if isinstance(a, float):
3090 if isinstance(a, str):
3095 _z3_assert(
False,
"Python bool, int, long or float expected")
3099 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3103 >>> x = Const('x', IntSort())
3106 >>> x.sort() == IntSort()
3108 >>> x.sort() == BoolSort()
3116 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3120 >>> x = Const('x', RealSort())
3125 >>> x.sort() == RealSort()
3132 def _to_int_str(val):
3133 if isinstance(val, float):
3134 return str(int(val))
3135 elif isinstance(val, bool):
3142 elif isinstance(val, str):
3145 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
3149 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3161 """Return a Z3 real value.
3163 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3164 If `ctx=None`, then the global context is used.
3168 >>> RealVal(1).sort()
3180 """Return a Z3 rational a/b.
3182 If `ctx=None`, then the global context is used.
3186 >>> RatVal(3,5).sort()
3190 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3191 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3195 def Q(a, b, ctx=None):
3196 """Return a Z3 rational a/b.
3198 If `ctx=None`, then the global context is used.
3209 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3222 """Return a tuple of Integer constants.
3224 >>> x, y, z = Ints('x y z')
3229 if isinstance(names, str):
3230 names = names.split(
" ")
3231 return [
Int(name, ctx)
for name
in names]
3235 """Return a list of integer constants of size `sz`.
3237 >>> X = IntVector('x', 3)
3244 return [
Int(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3248 """Return a fresh integer constant in the given context using the given prefix.
3262 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3275 """Return a tuple of real constants.
3277 >>> x, y, z = Reals('x y z')
3280 >>> Sum(x, y, z).sort()
3284 if isinstance(names, str):
3285 names = names.split(
" ")
3286 return [
Real(name, ctx)
for name
in names]
3290 """Return a list of real constants of size `sz`.
3292 >>> X = RealVector('x', 3)
3301 return [
Real(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3305 """Return a fresh real constant in the given context using the given prefix.
3319 """ Return the Z3 expression ToReal(a).
3331 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3337 """ Return the Z3 expression ToInt(a).
3349 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3355 """ Return the Z3 predicate IsInt(a).
3358 >>> IsInt(x + "1/2")
3360 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3362 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3366 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3372 """ Return a Z3 expression which represents the square root of a.
3385 """ Return a Z3 expression which represents the cubic root of a.
3404 """Bit-vector sort."""
3407 """Return the size (number of bits) of the bit-vector sort `self`.
3409 >>> b = BitVecSort(32)
3419 """Try to cast `val` as a Bit-Vector.
3421 >>> b = BitVecSort(32)
3424 >>> b.cast(10).sexpr()
3429 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
3437 """Return True if `s` is a Z3 bit-vector sort.
3439 >>> is_bv_sort(BitVecSort(32))
3441 >>> is_bv_sort(IntSort())
3444 return isinstance(s, BitVecSortRef)
3448 """Bit-vector expressions."""
3451 """Return the sort of the bit-vector expression `self`.
3453 >>> x = BitVec('x', 32)
3456 >>> x.sort() == BitVecSort(32)
3462 """Return the number of bits of the bit-vector expression `self`.
3464 >>> x = BitVec('x', 32)
3467 >>> Concat(x, x).size()
3473 """Create the Z3 expression `self + other`.
3475 >>> x = BitVec('x', 32)
3476 >>> y = BitVec('y', 32)
3482 a, b = _coerce_exprs(self, other)
3486 """Create the Z3 expression `other + self`.
3488 >>> x = BitVec('x', 32)
3492 a, b = _coerce_exprs(self, other)
3496 """Create the Z3 expression `self * other`.
3498 >>> x = BitVec('x', 32)
3499 >>> y = BitVec('y', 32)
3505 a, b = _coerce_exprs(self, other)
3509 """Create the Z3 expression `other * self`.
3511 >>> x = BitVec('x', 32)
3515 a, b = _coerce_exprs(self, other)
3519 """Create the Z3 expression `self - other`.
3521 >>> x = BitVec('x', 32)
3522 >>> y = BitVec('y', 32)
3528 a, b = _coerce_exprs(self, other)
3532 """Create the Z3 expression `other - self`.
3534 >>> x = BitVec('x', 32)
3538 a, b = _coerce_exprs(self, other)
3542 """Create the Z3 expression bitwise-or `self | other`.
3544 >>> x = BitVec('x', 32)
3545 >>> y = BitVec('y', 32)
3551 a, b = _coerce_exprs(self, other)
3555 """Create the Z3 expression bitwise-or `other | self`.
3557 >>> x = BitVec('x', 32)
3561 a, b = _coerce_exprs(self, other)
3565 """Create the Z3 expression bitwise-and `self & other`.
3567 >>> x = BitVec('x', 32)
3568 >>> y = BitVec('y', 32)
3574 a, b = _coerce_exprs(self, other)
3578 """Create the Z3 expression bitwise-or `other & self`.
3580 >>> x = BitVec('x', 32)
3584 a, b = _coerce_exprs(self, other)
3588 """Create the Z3 expression bitwise-xor `self ^ other`.
3590 >>> x = BitVec('x', 32)
3591 >>> y = BitVec('y', 32)
3597 a, b = _coerce_exprs(self, other)
3601 """Create the Z3 expression bitwise-xor `other ^ self`.
3603 >>> x = BitVec('x', 32)
3607 a, b = _coerce_exprs(self, other)
3613 >>> x = BitVec('x', 32)
3620 """Return an expression representing `-self`.
3622 >>> x = BitVec('x', 32)
3631 """Create the Z3 expression bitwise-not `~self`.
3633 >>> x = BitVec('x', 32)
3642 """Create the Z3 expression (signed) division `self / other`.
3644 Use the function UDiv() for unsigned division.
3646 >>> x = BitVec('x', 32)
3647 >>> y = BitVec('y', 32)
3654 >>> UDiv(x, y).sexpr()
3657 a, b = _coerce_exprs(self, other)
3661 """Create the Z3 expression (signed) division `self / other`."""
3662 return self.
__div____div__(other)
3665 """Create the Z3 expression (signed) division `other / self`.
3667 Use the function UDiv() for unsigned division.
3669 >>> x = BitVec('x', 32)
3672 >>> (10 / x).sexpr()
3673 '(bvsdiv #x0000000a x)'
3674 >>> UDiv(10, x).sexpr()
3675 '(bvudiv #x0000000a x)'
3677 a, b = _coerce_exprs(self, other)
3681 """Create the Z3 expression (signed) division `other / self`."""
3682 return self.
__rdiv____rdiv__(other)
3685 """Create the Z3 expression (signed) mod `self % other`.
3687 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3689 >>> x = BitVec('x', 32)
3690 >>> y = BitVec('y', 32)
3697 >>> URem(x, y).sexpr()
3699 >>> SRem(x, y).sexpr()
3702 a, b = _coerce_exprs(self, other)
3706 """Create the Z3 expression (signed) mod `other % self`.
3708 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3710 >>> x = BitVec('x', 32)
3713 >>> (10 % x).sexpr()
3714 '(bvsmod #x0000000a x)'
3715 >>> URem(10, x).sexpr()
3716 '(bvurem #x0000000a x)'
3717 >>> SRem(10, x).sexpr()
3718 '(bvsrem #x0000000a x)'
3720 a, b = _coerce_exprs(self, other)
3724 """Create the Z3 expression (signed) `other <= self`.
3726 Use the function ULE() for unsigned less than or equal to.
3728 >>> x, y = BitVecs('x y', 32)
3731 >>> (x <= y).sexpr()
3733 >>> ULE(x, y).sexpr()
3736 a, b = _coerce_exprs(self, other)
3740 """Create the Z3 expression (signed) `other < self`.
3742 Use the function ULT() for unsigned less than.
3744 >>> x, y = BitVecs('x y', 32)
3749 >>> ULT(x, y).sexpr()
3752 a, b = _coerce_exprs(self, other)
3756 """Create the Z3 expression (signed) `other > self`.
3758 Use the function UGT() for unsigned greater than.
3760 >>> x, y = BitVecs('x y', 32)
3765 >>> UGT(x, y).sexpr()
3768 a, b = _coerce_exprs(self, other)
3772 """Create the Z3 expression (signed) `other >= self`.
3774 Use the function UGE() for unsigned greater than or equal to.
3776 >>> x, y = BitVecs('x y', 32)
3779 >>> (x >= y).sexpr()
3781 >>> UGE(x, y).sexpr()
3784 a, b = _coerce_exprs(self, other)
3788 """Create the Z3 expression (arithmetical) right shift `self >> other`
3790 Use the function LShR() for the right logical shift
3792 >>> x, y = BitVecs('x y', 32)
3795 >>> (x >> y).sexpr()
3797 >>> LShR(x, y).sexpr()
3801 >>> BitVecVal(4, 3).as_signed_long()
3803 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3805 >>> simplify(BitVecVal(4, 3) >> 1)
3807 >>> simplify(LShR(BitVecVal(4, 3), 1))
3809 >>> simplify(BitVecVal(2, 3) >> 1)
3811 >>> simplify(LShR(BitVecVal(2, 3), 1))
3814 a, b = _coerce_exprs(self, other)
3818 """Create the Z3 expression left shift `self << other`
3820 >>> x, y = BitVecs('x y', 32)
3823 >>> (x << y).sexpr()
3825 >>> simplify(BitVecVal(2, 3) << 1)
3828 a, b = _coerce_exprs(self, other)
3832 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3834 Use the function LShR() for the right logical shift
3836 >>> x = BitVec('x', 32)
3839 >>> (10 >> x).sexpr()
3840 '(bvashr #x0000000a x)'
3842 a, b = _coerce_exprs(self, other)
3846 """Create the Z3 expression left shift `other << self`.
3848 Use the function LShR() for the right logical shift
3850 >>> x = BitVec('x', 32)
3853 >>> (10 << x).sexpr()
3854 '(bvshl #x0000000a x)'
3856 a, b = _coerce_exprs(self, other)
3861 """Bit-vector values."""
3864 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3866 >>> v = BitVecVal(0xbadc0de, 32)
3869 >>> print("0x%.8x" % v.as_long())
3875 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3876 The most significant bit is assumed to be the sign.
3878 >>> BitVecVal(4, 3).as_signed_long()
3880 >>> BitVecVal(7, 3).as_signed_long()
3882 >>> BitVecVal(3, 3).as_signed_long()
3884 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3886 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3889 sz = self.
sizesize()
3891 if val >= 2**(sz - 1):
3893 if val < -2**(sz - 1):
3905 """Return `True` if `a` is a Z3 bit-vector expression.
3907 >>> b = BitVec('b', 32)
3915 return isinstance(a, BitVecRef)
3919 """Return `True` if `a` is a Z3 bit-vector numeral value.
3921 >>> b = BitVec('b', 32)
3924 >>> b = BitVecVal(10, 32)
3930 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3934 """Return the Z3 expression BV2Int(a).
3936 >>> b = BitVec('b', 3)
3937 >>> BV2Int(b).sort()
3942 >>> x > BV2Int(b, is_signed=False)
3944 >>> x > BV2Int(b, is_signed=True)
3945 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3946 >>> solve(x > BV2Int(b), b == 1, x < 3)
3950 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3957 """Return the z3 expression Int2BV(a, num_bits).
3958 It is a bit-vector of width num_bits and represents the
3959 modulo of a by 2^num_bits
3966 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3968 >>> Byte = BitVecSort(8)
3969 >>> Word = BitVecSort(16)
3972 >>> x = Const('x', Byte)
3973 >>> eq(x, BitVec('x', 8))
3981 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3983 >>> v = BitVecVal(10, 32)
3986 >>> print("0x%.8x" % v.as_long())
3998 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3999 If `ctx=None`, then the global context is used.
4001 >>> x = BitVec('x', 16)
4008 >>> word = BitVecSort(16)
4009 >>> x2 = BitVec('x', word)
4013 if isinstance(bv, BitVecSortRef):
4022 """Return a tuple of bit-vector constants of size bv.
4024 >>> x, y, z = BitVecs('x y z', 16)
4031 >>> Product(x, y, z)
4033 >>> simplify(Product(x, y, z))
4037 if isinstance(names, str):
4038 names = names.split(
" ")
4039 return [
BitVec(name, bv, ctx)
for name
in names]
4043 """Create a Z3 bit-vector concatenation expression.
4045 >>> v = BitVecVal(1, 4)
4046 >>> Concat(v, v+1, v)
4047 Concat(Concat(1, 1 + 1), 1)
4048 >>> simplify(Concat(v, v+1, v))
4050 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4053 args = _get_args(args)
4056 _z3_assert(sz >= 2,
"At least two arguments expected.")
4063 if is_seq(args[0])
or isinstance(args[0], str):
4064 args = [_coerce_seq(s, ctx)
for s
in args]
4066 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
4069 v[i] = args[i].as_ast()
4074 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
4077 v[i] = args[i].as_ast()
4081 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
4083 for i
in range(sz - 1):
4089 """Create a Z3 bit-vector extraction expression.
4090 Extract is overloaded to also work on sequence extraction.
4091 The functions SubString and SubSeq are redirected to Extract.
4092 For this case, the arguments are reinterpreted as:
4093 high - is a sequence (string)
4095 a - is the length to be extracted
4097 >>> x = BitVec('x', 8)
4098 >>> Extract(6, 2, x)
4100 >>> Extract(6, 2, x).sort()
4102 >>> simplify(Extract(StringVal("abcd"),2,1))
4105 if isinstance(high, str):
4109 offset, length = _coerce_exprs(low, a, s.ctx)
4112 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
4113 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
4114 "First and second arguments must be non negative integers")
4115 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
4119 def _check_bv_args(a, b):
4121 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
4125 """Create the Z3 expression (unsigned) `other <= self`.
4127 Use the operator <= for signed less than or equal to.
4129 >>> x, y = BitVecs('x y', 32)
4132 >>> (x <= y).sexpr()
4134 >>> ULE(x, y).sexpr()
4137 _check_bv_args(a, b)
4138 a, b = _coerce_exprs(a, b)
4143 """Create the Z3 expression (unsigned) `other < self`.
4145 Use the operator < for signed less than.
4147 >>> x, y = BitVecs('x y', 32)
4152 >>> ULT(x, y).sexpr()
4155 _check_bv_args(a, b)
4156 a, b = _coerce_exprs(a, b)
4161 """Create the Z3 expression (unsigned) `other >= self`.
4163 Use the operator >= for signed greater than or equal to.
4165 >>> x, y = BitVecs('x y', 32)
4168 >>> (x >= y).sexpr()
4170 >>> UGE(x, y).sexpr()
4173 _check_bv_args(a, b)
4174 a, b = _coerce_exprs(a, b)
4179 """Create the Z3 expression (unsigned) `other > self`.
4181 Use the operator > for signed greater than.
4183 >>> x, y = BitVecs('x y', 32)
4188 >>> UGT(x, y).sexpr()
4191 _check_bv_args(a, b)
4192 a, b = _coerce_exprs(a, b)
4197 """Create the Z3 expression (unsigned) division `self / other`.
4199 Use the operator / for signed division.
4201 >>> x = BitVec('x', 32)
4202 >>> y = BitVec('y', 32)
4205 >>> UDiv(x, y).sort()
4209 >>> UDiv(x, y).sexpr()
4212 _check_bv_args(a, b)
4213 a, b = _coerce_exprs(a, b)
4218 """Create the Z3 expression (unsigned) remainder `self % other`.
4220 Use the operator % for signed modulus, and SRem() for signed remainder.
4222 >>> x = BitVec('x', 32)
4223 >>> y = BitVec('y', 32)
4226 >>> URem(x, y).sort()
4230 >>> URem(x, y).sexpr()
4233 _check_bv_args(a, b)
4234 a, b = _coerce_exprs(a, b)
4239 """Create the Z3 expression signed remainder.
4241 Use the operator % for signed modulus, and URem() for unsigned remainder.
4243 >>> x = BitVec('x', 32)
4244 >>> y = BitVec('y', 32)
4247 >>> SRem(x, y).sort()
4251 >>> SRem(x, y).sexpr()
4254 _check_bv_args(a, b)
4255 a, b = _coerce_exprs(a, b)
4260 """Create the Z3 expression logical right shift.
4262 Use the operator >> for the arithmetical right shift.
4264 >>> x, y = BitVecs('x y', 32)
4267 >>> (x >> y).sexpr()
4269 >>> LShR(x, y).sexpr()
4273 >>> BitVecVal(4, 3).as_signed_long()
4275 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4277 >>> simplify(BitVecVal(4, 3) >> 1)
4279 >>> simplify(LShR(BitVecVal(4, 3), 1))
4281 >>> simplify(BitVecVal(2, 3) >> 1)
4283 >>> simplify(LShR(BitVecVal(2, 3), 1))
4286 _check_bv_args(a, b)
4287 a, b = _coerce_exprs(a, b)
4292 """Return an expression representing `a` rotated to the left `b` times.
4294 >>> a, b = BitVecs('a b', 16)
4295 >>> RotateLeft(a, b)
4297 >>> simplify(RotateLeft(a, 0))
4299 >>> simplify(RotateLeft(a, 16))
4302 _check_bv_args(a, b)
4303 a, b = _coerce_exprs(a, b)
4308 """Return an expression representing `a` rotated to the right `b` times.
4310 >>> a, b = BitVecs('a b', 16)
4311 >>> RotateRight(a, b)
4313 >>> simplify(RotateRight(a, 0))
4315 >>> simplify(RotateRight(a, 16))
4318 _check_bv_args(a, b)
4319 a, b = _coerce_exprs(a, b)
4324 """Return a bit-vector expression with `n` extra sign-bits.
4326 >>> x = BitVec('x', 16)
4327 >>> n = SignExt(8, x)
4334 >>> v0 = BitVecVal(2, 2)
4339 >>> v = simplify(SignExt(6, v0))
4344 >>> print("%.x" % v.as_long())
4348 _z3_assert(_is_int(n),
"First argument must be an integer")
4349 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4354 """Return a bit-vector expression with `n` extra zero-bits.
4356 >>> x = BitVec('x', 16)
4357 >>> n = ZeroExt(8, x)
4364 >>> v0 = BitVecVal(2, 2)
4369 >>> v = simplify(ZeroExt(6, v0))
4376 _z3_assert(_is_int(n),
"First argument must be an integer")
4377 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4382 """Return an expression representing `n` copies of `a`.
4384 >>> x = BitVec('x', 8)
4385 >>> n = RepeatBitVec(4, x)
4390 >>> v0 = BitVecVal(10, 4)
4391 >>> print("%.x" % v0.as_long())
4393 >>> v = simplify(RepeatBitVec(4, v0))
4396 >>> print("%.x" % v.as_long())
4400 _z3_assert(_is_int(n),
"First argument must be an integer")
4401 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4406 """Return the reduction-and expression of `a`."""
4408 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4413 """Return the reduction-or expression of `a`."""
4415 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4420 """A predicate the determines that bit-vector addition does not overflow"""
4421 _check_bv_args(a, b)
4422 a, b = _coerce_exprs(a, b)
4427 """A predicate the determines that signed bit-vector addition does not underflow"""
4428 _check_bv_args(a, b)
4429 a, b = _coerce_exprs(a, b)
4434 """A predicate the determines that bit-vector subtraction does not overflow"""
4435 _check_bv_args(a, b)
4436 a, b = _coerce_exprs(a, b)
4441 """A predicate the determines that bit-vector subtraction does not underflow"""
4442 _check_bv_args(a, b)
4443 a, b = _coerce_exprs(a, b)
4448 """A predicate the determines that bit-vector signed division does not overflow"""
4449 _check_bv_args(a, b)
4450 a, b = _coerce_exprs(a, b)
4455 """A predicate the determines that bit-vector unary negation does not overflow"""
4457 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4462 """A predicate the determines that bit-vector multiplication does not overflow"""
4463 _check_bv_args(a, b)
4464 a, b = _coerce_exprs(a, b)
4469 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4470 _check_bv_args(a, b)
4471 a, b = _coerce_exprs(a, b)
4485 """Return the domain of the array sort `self`.
4487 >>> A = ArraySort(IntSort(), BoolSort())
4494 """Return the domain of the array sort `self`.
4499 """Return the range of the array sort `self`.
4501 >>> A = ArraySort(IntSort(), BoolSort())
4509 """Array expressions. """
4512 """Return the array sort of the array expression `self`.
4514 >>> a = Array('a', IntSort(), BoolSort())
4521 """Shorthand for `self.sort().domain()`.
4523 >>> a = Array('a', IntSort(), BoolSort())
4530 """Shorthand for self.sort().domain_n(i)`."""
4534 """Shorthand for `self.sort().range()`.
4536 >>> a = Array('a', IntSort(), BoolSort())
4543 """Return the Z3 expression `self[arg]`.
4545 >>> a = Array('a', IntSort(), BoolSort())
4552 return _array_select(self, arg)
4558 def _array_select(ar, arg):
4559 if isinstance(arg, tuple):
4560 args = [ar.domain_n(i).cast(arg[i])
for i
in range(len(arg))]
4561 _args, sz = _to_ast_array(args)
4562 return _to_expr_ref(
Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4563 arg = ar.domain().cast(arg)
4564 return _to_expr_ref(
Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4572 """Return `True` if `a` is a Z3 array expression.
4574 >>> a = Array('a', IntSort(), IntSort())
4577 >>> is_array(Store(a, 0, 1))
4582 return isinstance(a, ArrayRef)
4586 """Return `True` if `a` is a Z3 constant array.
4588 >>> a = K(IntSort(), 10)
4589 >>> is_const_array(a)
4591 >>> a = Array('a', IntSort(), IntSort())
4592 >>> is_const_array(a)
4599 """Return `True` if `a` is a Z3 constant array.
4601 >>> a = K(IntSort(), 10)
4604 >>> a = Array('a', IntSort(), IntSort())
4612 """Return `True` if `a` is a Z3 map array expression.
4614 >>> f = Function('f', IntSort(), IntSort())
4615 >>> b = Array('b', IntSort(), IntSort())
4628 """Return `True` if `a` is a Z3 default array expression.
4629 >>> d = Default(K(IntSort(), 10))
4633 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4637 """Return the function declaration associated with a Z3 map array expression.
4639 >>> f = Function('f', IntSort(), IntSort())
4640 >>> b = Array('b', IntSort(), IntSort())
4642 >>> eq(f, get_map_func(a))
4646 >>> get_map_func(a)(0)
4650 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4661 """Return the Z3 array sort with the given domain and range sorts.
4663 >>> A = ArraySort(IntSort(), BoolSort())
4670 >>> AA = ArraySort(IntSort(), A)
4672 Array(Int, Array(Int, Bool))
4674 sig = _get_args(sig)
4676 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4677 arity = len(sig) - 1
4682 _z3_assert(
is_sort(s),
"Z3 sort expected")
4683 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4687 dom = (Sort * arity)()
4688 for i
in range(arity):
4694 """Return an array constant named `name` with the given domain and range sorts.
4696 >>> a = Array('a', IntSort(), IntSort())
4708 """Return a Z3 store array expression.
4710 >>> a = Array('a', IntSort(), IntSort())
4711 >>> i, v = Ints('i v')
4712 >>> s = Update(a, i, v)
4715 >>> prove(s[i] == v)
4718 >>> prove(Implies(i != j, s[j] == a[j]))
4722 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4723 args = _get_args(args)
4726 raise Z3Exception(
"array update requires index and value arguments")
4730 i = a.sort().domain().cast(i)
4731 v = a.sort().
range().cast(v)
4732 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4733 v = a.sort().
range().cast(args[-1])
4734 idxs = [a.sort().domain_n(i).cast(args[i])
for i
in range(len(args)-1)]
4735 _args, sz = _to_ast_array(idxs)
4736 return _to_expr_ref(
Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4740 """ Return a default value for array expression.
4741 >>> b = K(IntSort(), 1)
4742 >>> prove(Default(b) == 1)
4746 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4751 """Return a Z3 store array expression.
4753 >>> a = Array('a', IntSort(), IntSort())
4754 >>> i, v = Ints('i v')
4755 >>> s = Store(a, i, v)
4758 >>> prove(s[i] == v)
4761 >>> prove(Implies(i != j, s[j] == a[j]))
4768 """Return a Z3 select array expression.
4770 >>> a = Array('a', IntSort(), IntSort())
4774 >>> eq(Select(a, i), a[i])
4777 args = _get_args(args)
4779 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4784 """Return a Z3 map array expression.
4786 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4787 >>> a1 = Array('a1', IntSort(), IntSort())
4788 >>> a2 = Array('a2', IntSort(), IntSort())
4789 >>> b = Map(f, a1, a2)
4792 >>> prove(b[0] == f(a1[0], a2[0]))
4795 args = _get_args(args)
4797 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4798 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4799 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4800 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4801 _args, sz = _to_ast_array(args)
4807 """Return a Z3 constant array expression.
4809 >>> a = K(IntSort(), 10)
4821 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4824 v = _py2expr(v, ctx)
4829 """Return extensionality index for one-dimensional arrays.
4830 >> a, b = Consts('a b', SetSort(IntSort()))
4837 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4842 k = _py2expr(k, ctx)
4847 """Return `True` if `a` is a Z3 array select application.
4849 >>> a = Array('a', IntSort(), IntSort())
4860 """Return `True` if `a` is a Z3 array store application.
4862 >>> a = Array('a', IntSort(), IntSort())
4865 >>> is_store(Store(a, 0, 1))
4878 """ Create a set sort over element sort s"""
4883 """Create the empty set
4884 >>> EmptySet(IntSort())
4892 """Create the full set
4893 >>> FullSet(IntSort())
4901 """ Take the union of sets
4902 >>> a = Const('a', SetSort(IntSort()))
4903 >>> b = Const('b', SetSort(IntSort()))
4907 args = _get_args(args)
4908 ctx = _ctx_from_ast_arg_list(args)
4909 _args, sz = _to_ast_array(args)
4914 """ Take the union of sets
4915 >>> a = Const('a', SetSort(IntSort()))
4916 >>> b = Const('b', SetSort(IntSort()))
4917 >>> SetIntersect(a, b)
4920 args = _get_args(args)
4921 ctx = _ctx_from_ast_arg_list(args)
4922 _args, sz = _to_ast_array(args)
4927 """ Add element e to set s
4928 >>> a = Const('a', SetSort(IntSort()))
4932 ctx = _ctx_from_ast_arg_list([s, e])
4933 e = _py2expr(e, ctx)
4938 """ Remove element e to set s
4939 >>> a = Const('a', SetSort(IntSort()))
4943 ctx = _ctx_from_ast_arg_list([s, e])
4944 e = _py2expr(e, ctx)
4949 """ The complement of set s
4950 >>> a = Const('a', SetSort(IntSort()))
4951 >>> SetComplement(a)
4959 """ The set difference of a and b
4960 >>> a = Const('a', SetSort(IntSort()))
4961 >>> b = Const('b', SetSort(IntSort()))
4962 >>> SetDifference(a, b)
4965 ctx = _ctx_from_ast_arg_list([a, b])
4970 """ Check if e is a member of set s
4971 >>> a = Const('a', SetSort(IntSort()))
4975 ctx = _ctx_from_ast_arg_list([s, e])
4976 e = _py2expr(e, ctx)
4981 """ Check if a is a subset of b
4982 >>> a = Const('a', SetSort(IntSort()))
4983 >>> b = Const('b', SetSort(IntSort()))
4987 ctx = _ctx_from_ast_arg_list([a, b])
4997 def _valid_accessor(acc):
4998 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4999 if not isinstance(acc, tuple):
5003 return isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
5007 """Helper class for declaring Z3 datatypes.
5009 >>> List = Datatype('List')
5010 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5011 >>> List.declare('nil')
5012 >>> List = List.create()
5013 >>> # List is now a Z3 declaration
5016 >>> List.cons(10, List.nil)
5018 >>> List.cons(10, List.nil).sort()
5020 >>> cons = List.cons
5024 >>> n = cons(1, cons(0, nil))
5026 cons(1, cons(0, nil))
5027 >>> simplify(cdr(n))
5029 >>> simplify(car(n))
5040 r.constructors = copy.deepcopy(self.
constructorsconstructors)
5045 _z3_assert(isinstance(name, str),
"String expected")
5046 _z3_assert(isinstance(rec_name, str),
"String expected")
5048 all([_valid_accessor(a)
for a
in args]),
5049 "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)",
5051 self.
constructorsconstructors.append((name, rec_name, args))
5054 """Declare constructor named `name` with the given accessors `args`.
5055 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort
5056 or a reference to the datatypes being declared.
5058 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
5059 declares the constructor named `cons` that builds a new List using an integer and a List.
5060 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer
5061 of a `cons` cell, and `cdr` the list of a `cons` cell. After all constructors were declared,
5062 we use the method create() to create the actual datatype in Z3.
5064 >>> List = Datatype('List')
5065 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5066 >>> List.declare('nil')
5067 >>> List = List.create()
5070 _z3_assert(isinstance(name, str),
"String expected")
5071 _z3_assert(name !=
"",
"Constructor name cannot be empty")
5072 return self.
declare_coredeclare_core(name,
"is-" + name, *args)
5078 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
5080 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
5082 >>> List = Datatype('List')
5083 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5084 >>> List.declare('nil')
5085 >>> List = List.create()
5088 >>> List.cons(10, List.nil)
5095 """Auxiliary object used to create Z3 datatypes."""
5102 if self.
ctxctx.ref()
is not None:
5107 """Auxiliary object used to create Z3 datatypes."""
5114 if self.
ctxctx.ref()
is not None:
5119 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5121 In the following example we define a Tree-List using two mutually recursive datatypes.
5123 >>> TreeList = Datatype('TreeList')
5124 >>> Tree = Datatype('Tree')
5125 >>> # Tree has two constructors: leaf and node
5126 >>> Tree.declare('leaf', ('val', IntSort()))
5127 >>> # a node contains a list of trees
5128 >>> Tree.declare('node', ('children', TreeList))
5129 >>> TreeList.declare('nil')
5130 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5131 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5132 >>> Tree.val(Tree.leaf(10))
5134 >>> simplify(Tree.val(Tree.leaf(10)))
5136 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5138 node(cons(leaf(10), cons(leaf(20), nil)))
5139 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5140 >>> simplify(n2 == n1)
5142 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5147 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
5148 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
5149 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
5150 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
5153 names = (Symbol * num)()
5154 out = (Sort * num)()
5155 clists = (ConstructorList * num)()
5157 for i
in range(num):
5160 num_cs = len(d.constructors)
5161 cs = (Constructor * num_cs)()
5162 for j
in range(num_cs):
5163 c = d.constructors[j]
5168 fnames = (Symbol * num_fs)()
5169 sorts = (Sort * num_fs)()
5170 refs = (ctypes.c_uint * num_fs)()
5171 for k
in range(num_fs):
5175 if isinstance(ftype, Datatype):
5178 ds.count(ftype) == 1,
5179 "One and only one occurrence of each datatype is expected",
5182 refs[k] = ds.index(ftype)
5185 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
5186 sorts[k] = ftype.ast
5195 for i
in range(num):
5197 num_cs = dref.num_constructors()
5198 for j
in range(num_cs):
5199 cref = dref.constructor(j)
5200 cref_name = cref.name()
5201 cref_arity = cref.arity()
5202 if cref.arity() == 0:
5204 setattr(dref, cref_name, cref)
5205 rref = dref.recognizer(j)
5206 setattr(dref,
"is_" + cref_name, rref)
5207 for k
in range(cref_arity):
5208 aref = dref.accessor(j, k)
5209 setattr(dref, aref.name(), aref)
5211 return tuple(result)
5215 """Datatype sorts."""
5218 """Return the number of constructors in the given Z3 datatype.
5220 >>> List = Datatype('List')
5221 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5222 >>> List.declare('nil')
5223 >>> List = List.create()
5224 >>> # List is now a Z3 declaration
5225 >>> List.num_constructors()
5231 """Return a constructor of the datatype `self`.
5233 >>> List = Datatype('List')
5234 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5235 >>> List.declare('nil')
5236 >>> List = List.create()
5237 >>> # List is now a Z3 declaration
5238 >>> List.num_constructors()
5240 >>> List.constructor(0)
5242 >>> List.constructor(1)
5246 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5250 """In Z3, each constructor has an associated recognizer predicate.
5252 If the constructor is named `name`, then the recognizer `is_name`.
5254 >>> List = Datatype('List')
5255 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5256 >>> List.declare('nil')
5257 >>> List = List.create()
5258 >>> # List is now a Z3 declaration
5259 >>> List.num_constructors()
5261 >>> List.recognizer(0)
5263 >>> List.recognizer(1)
5265 >>> simplify(List.is_nil(List.cons(10, List.nil)))
5267 >>> simplify(List.is_cons(List.cons(10, List.nil)))
5269 >>> l = Const('l', List)
5270 >>> simplify(List.is_cons(l))
5274 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid recognizer index")
5278 """In Z3, each constructor has 0 or more accessor.
5279 The number of accessors is equal to the arity of the constructor.
5281 >>> List = Datatype('List')
5282 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5283 >>> List.declare('nil')
5284 >>> List = List.create()
5285 >>> List.num_constructors()
5287 >>> List.constructor(0)
5289 >>> num_accs = List.constructor(0).arity()
5292 >>> List.accessor(0, 0)
5294 >>> List.accessor(0, 1)
5296 >>> List.constructor(1)
5298 >>> num_accs = List.constructor(1).arity()
5303 _z3_assert(i < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5304 _z3_assert(j < self.
constructorconstructor(i).arity(),
"Invalid accessor index")
5312 """Datatype expressions."""
5315 """Return the datatype sort of the datatype expression `self`."""
5320 """Create a named tuple sort base on a set of underlying sorts
5322 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5325 projects = [(
"project%d" % i, sorts[i])
for i
in range(len(sorts))]
5326 tuple.declare(name, *projects)
5327 tuple = tuple.create()
5328 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5332 """Create a named tagged union sort base on a set of underlying sorts
5334 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5337 for i
in range(len(sorts)):
5338 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5340 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5344 """Return a new enumeration sort named `name` containing the given values.
5346 The result is a pair (sort, list of constants).
5348 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5351 _z3_assert(isinstance(name, str),
"Name must be a string")
5352 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5353 _z3_assert(len(values) > 0,
"At least one value expected")
5356 _val_names = (Symbol * num)()
5357 for i
in range(num):
5359 _values = (FuncDecl * num)()
5360 _testers = (FuncDecl * num)()
5364 for i
in range(num):
5366 V = [a()
for a
in V]
5377 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5379 Consider using the function `args2params` to create instances of this object.
5387 self.
paramsparams = params
5394 if self.
ctxctx.ref()
is not None:
5398 """Set parameter name with value val."""
5400 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5402 if isinstance(val, bool):
5406 elif isinstance(val, float):
5408 elif isinstance(val, str):
5412 _z3_assert(
False,
"invalid parameter value")
5418 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5423 """Convert python arguments into a Z3_params object.
5424 A ':' is added to the keywords, and '_' is replaced with '-'
5426 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5427 (params model true relevancy 2 elim_and true)
5430 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5446 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5450 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5456 return ParamsDescrsRef(self.
descrdescr, self.
ctxctx)
5459 if self.
ctxctx.ref()
is not None:
5463 """Return the size of in the parameter description `self`.
5468 """Return the size of in the parameter description `self`.
5470 return self.
sizesize()
5473 """Return the i-th parameter name in the parameter description `self`.
5478 """Return the kind of the parameter named `n`.
5483 """Return the documentation string of the parameter named `n`.
5504 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5506 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5507 A goal has a solution if one of its subgoals has a solution.
5508 A goal is unsatisfiable if all subgoals are unsatisfiable.
5511 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5513 _z3_assert(goal
is None or ctx
is not None,
5514 "If goal is different from None, then ctx must be also different from None")
5517 if self.
goalgoal
is None:
5522 if self.
goalgoal
is not None and self.
ctxctx.ref()
is not None:
5526 """Return the depth of the goal `self`.
5527 The depth corresponds to the number of tactics applied to `self`.
5529 >>> x, y = Ints('x y')
5531 >>> g.add(x == 0, y >= x + 1)
5534 >>> r = Then('simplify', 'solve-eqs')(g)
5535 >>> # r has 1 subgoal
5544 """Return `True` if `self` contains the `False` constraints.
5546 >>> x, y = Ints('x y')
5548 >>> g.inconsistent()
5550 >>> g.add(x == 0, x == 1)
5553 >>> g.inconsistent()
5555 >>> g2 = Tactic('propagate-values')(g)[0]
5556 >>> g2.inconsistent()
5562 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5565 >>> g.prec() == Z3_GOAL_PRECISE
5567 >>> x, y = Ints('x y')
5568 >>> g.add(x == y + 1)
5569 >>> g.prec() == Z3_GOAL_PRECISE
5571 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5574 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5575 >>> g2.prec() == Z3_GOAL_PRECISE
5577 >>> g2.prec() == Z3_GOAL_UNDER
5583 """Alias for `prec()`.
5586 >>> g.precision() == Z3_GOAL_PRECISE
5589 return self.
precprec()
5592 """Return the number of constraints in the goal `self`.
5597 >>> x, y = Ints('x y')
5598 >>> g.add(x == 0, y > x)
5605 """Return the number of constraints in the goal `self`.
5610 >>> x, y = Ints('x y')
5611 >>> g.add(x == 0, y > x)
5615 return self.
sizesize()
5618 """Return a constraint in the goal `self`.
5621 >>> x, y = Ints('x y')
5622 >>> g.add(x == 0, y > x)
5631 """Return a constraint in the goal `self`.
5634 >>> x, y = Ints('x y')
5635 >>> g.add(x == 0, y > x)
5641 if arg >= len(self):
5643 return self.
getget(arg)
5646 """Assert constraints into the goal.
5650 >>> g.assert_exprs(x > 0, x < 2)
5654 args = _get_args(args)
5665 >>> g.append(x > 0, x < 2)
5676 >>> g.insert(x > 0, x < 2)
5687 >>> g.add(x > 0, x < 2)
5694 """Retrieve model from a satisfiable goal
5695 >>> a, b = Ints('a b')
5697 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5698 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5701 [Or(b == 0, b == 1), Not(0 <= b)]
5703 [Or(b == 0, b == 1), Not(1 <= b)]
5704 >>> # Remark: the subgoal r[0] is unsatisfiable
5705 >>> # Creating a solver for solving the second subgoal
5712 >>> # Model s.model() does not assign a value to `a`
5713 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5714 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5715 >>> r[1].convert_model(s.model())
5719 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5723 return obj_to_string(self)
5726 """Return a textual representation of the s-expression representing the goal."""
5730 """Return a textual representation of the goal in DIMACS format."""
5734 """Copy goal `self` to context `target`.
5742 >>> g2 = g.translate(c2)
5745 >>> g.ctx == main_ctx()
5749 >>> g2.ctx == main_ctx()
5753 _z3_assert(isinstance(target, Context),
"target must be a context")
5763 """Return a new simplified goal.
5765 This method is essentially invoking the simplify tactic.
5769 >>> g.add(x + 1 >= 2)
5772 >>> g2 = g.simplify()
5775 >>> # g was not modified
5780 return t.apply(self, *arguments, **keywords)[0]
5783 """Return goal `self` as a single Z3 expression.
5800 return self.
getget(0)
5802 return And([self.
getget(i)
for i
in range(len(self))], self.
ctxctx)
5812 """A collection (vector) of ASTs."""
5821 assert ctx
is not None
5826 if self.
vectorvector
is not None and self.
ctxctx.ref()
is not None:
5830 """Return the size of the vector `self`.
5835 >>> A.push(Int('x'))
5836 >>> A.push(Int('x'))
5843 """Return the AST at position `i`.
5846 >>> A.push(Int('x') + 1)
5847 >>> A.push(Int('y'))
5854 if isinstance(i, int):
5858 if i >= self.
__len____len__():
5862 elif isinstance(i, slice):
5865 result.append(_to_ast_ref(
5872 """Update AST at position `i`.
5875 >>> A.push(Int('x') + 1)
5876 >>> A.push(Int('y'))
5883 if i >= self.
__len____len__():
5888 """Add `v` in the end of the vector.
5893 >>> A.push(Int('x'))
5900 """Resize the vector to `sz` elements.
5906 >>> for i in range(10): A[i] = Int('x')
5913 """Return `True` if the vector contains `item`.
5936 """Copy vector `self` to context `other_ctx`.
5942 >>> B = A.translate(c2)
5958 return obj_to_string(self)
5961 """Return a textual representation of the s-expression representing the vector."""
5972 """A mapping from ASTs to ASTs."""
5981 assert ctx
is not None
5989 if self.
mapmap
is not None and self.
ctxctx.ref()
is not None:
5993 """Return the size of the map.
5999 >>> M[x] = IntVal(1)
6006 """Return `True` if the map contains key `key`.
6019 """Retrieve the value associated with key `key`.
6030 """Add/Update key `k` with value `v`.
6039 >>> M[x] = IntVal(1)
6049 """Remove the entry associated with key `k`.
6063 """Remove all entries from the map.
6068 >>> M[x+x] = IntVal(1)
6078 """Return an AstVector containing all keys in the map.
6083 >>> M[x+x] = IntVal(1)
6097 """Store the value of the interpretation of a function in a particular point."""
6108 if self.
ctxctx.ref()
is not None:
6112 """Return the number of arguments in the given entry.
6114 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6116 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6121 >>> f_i.num_entries()
6123 >>> e = f_i.entry(0)
6130 """Return the value of argument `idx`.
6132 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6134 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6139 >>> f_i.num_entries()
6141 >>> e = f_i.entry(0)
6152 ... except IndexError:
6153 ... print("index error")
6161 """Return the value of the function at point `self`.
6163 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6165 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6170 >>> f_i.num_entries()
6172 >>> e = f_i.entry(0)
6183 """Return entry `self` as a Python list.
6184 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6186 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6191 >>> f_i.num_entries()
6193 >>> e = f_i.entry(0)
6198 args.append(self.
valuevalue())
6202 return repr(self.
as_listas_list())
6206 """Stores the interpretation of a function in a Z3 model."""
6211 if self.
ff
is not None:
6215 if self.
ff
is not None and self.
ctxctx.ref()
is not None:
6220 Return the `else` value for a function interpretation.
6221 Return None if Z3 did not specify the `else` value for
6224 >>> f = Function('f', IntSort(), IntSort())
6226 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6232 >>> m[f].else_value()
6237 return _to_expr_ref(r, self.
ctxctx)
6242 """Return the number of entries/points in the function interpretation `self`.
6244 >>> f = Function('f', IntSort(), IntSort())
6246 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6252 >>> m[f].num_entries()
6258 """Return the number of arguments for each entry in the function interpretation `self`.
6260 >>> f = Function('f', IntSort(), IntSort())
6262 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6272 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
6274 >>> f = Function('f', IntSort(), IntSort())
6276 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6282 >>> m[f].num_entries()
6292 """Copy model 'self' to context 'other_ctx'.
6303 """Return the function interpretation as a Python list.
6304 >>> f = Function('f', IntSort(), IntSort())
6306 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6320 return obj_to_string(self)
6324 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6327 assert ctx
is not None
6333 if self.
ctxctx.ref()
is not None:
6337 return obj_to_string(self)
6340 """Return a textual representation of the s-expression representing the model."""
6343 def eval(self, t, model_completion=False):
6344 """Evaluate the expression `t` in the model `self`.
6345 If `model_completion` is enabled, then a default interpretation is automatically added
6346 for symbols that do not have an interpretation in the model `self`.
6350 >>> s.add(x > 0, x < 2)
6363 >>> m.eval(y, model_completion=True)
6365 >>> # Now, m contains an interpretation for y
6371 return _to_expr_ref(r[0], self.
ctxctx)
6372 raise Z3Exception(
"failed to evaluate expression in the model")
6375 """Alias for `eval`.
6379 >>> s.add(x > 0, x < 2)
6383 >>> m.evaluate(x + 1)
6385 >>> m.evaluate(x == 1)
6388 >>> m.evaluate(y + x)
6392 >>> m.evaluate(y, model_completion=True)
6394 >>> # Now, m contains an interpretation for y
6395 >>> m.evaluate(y + x)
6398 return self.
evaleval(t, model_completion)
6401 """Return the number of constant and function declarations in the model `self`.
6403 >>> f = Function('f', IntSort(), IntSort())
6406 >>> s.add(x > 0, f(x) != x)
6415 return num_consts + num_funcs
6418 """Return the interpretation for a given declaration or constant.
6420 >>> f = Function('f', IntSort(), IntSort())
6423 >>> s.add(x > 0, x < 2, f(x) == 0)
6433 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6437 if decl.arity() == 0:
6439 if _r.value
is None:
6441 r = _to_expr_ref(_r, self.
ctxctx)
6452 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6454 >>> A = DeclareSort('A')
6455 >>> a, b = Consts('a b', A)
6467 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6469 >>> A = DeclareSort('A')
6470 >>> B = DeclareSort('B')
6471 >>> a1, a2 = Consts('a1 a2', A)
6472 >>> b1, b2 = Consts('b1 b2', B)
6474 >>> s.add(a1 != a2, b1 != b2)
6490 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6492 >>> A = DeclareSort('A')
6493 >>> B = DeclareSort('B')
6494 >>> a1, a2 = Consts('a1 a2', A)
6495 >>> b1, b2 = Consts('b1 b2', B)
6497 >>> s.add(a1 != a2, b1 != b2)
6507 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6509 >>> A = DeclareSort('A')
6510 >>> a, b = Consts('a b', A)
6516 >>> m.get_universe(A)
6520 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6527 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
6528 If `idx` is a declaration, then the actual interpretation is returned.
6530 The elements can be retrieved using position or the actual declaration.
6532 >>> f = Function('f', IntSort(), IntSort())
6535 >>> s.add(x > 0, x < 2, f(x) == 0)
6549 >>> for d in m: print("%s -> %s" % (d, m[d]))
6554 if idx >= len(self):
6557 if (idx < num_consts):
6561 if isinstance(idx, FuncDeclRef):
6565 if isinstance(idx, SortRef):
6568 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6572 """Return a list with all symbols that have an interpretation in the model `self`.
6573 >>> f = Function('f', IntSort(), IntSort())
6576 >>> s.add(x > 0, x < 2, f(x) == 0)
6591 """Update the interpretation of a constant"""
6595 raise Z3Exception(
"Expecting 0-ary function or constant expression")
6596 value = _py2expr(value)
6600 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6603 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6620 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6621 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6625 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6627 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6638 """Statistics for `Solver.check()`."""
6649 if self.
ctxctx.ref()
is not None:
6656 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6659 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6662 out.write(u(
"<tr>"))
6664 out.write(u(
"<td>%s</td><td>%s</td></tr>" % (k, v)))
6665 out.write(u(
"</table>"))
6666 return out.getvalue()
6671 """Return the number of statistical counters.
6674 >>> s = Then('simplify', 'nlsat').solver()
6678 >>> st = s.statistics()
6685 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6688 >>> s = Then('simplify', 'nlsat').solver()
6692 >>> st = s.statistics()
6696 ('nlsat propagations', 2)
6700 if idx >= len(self):
6709 """Return the list of statistical counters.
6712 >>> s = Then('simplify', 'nlsat').solver()
6716 >>> st = s.statistics()
6721 """Return the value of a particular statistical counter.
6724 >>> s = Then('simplify', 'nlsat').solver()
6728 >>> st = s.statistics()
6729 >>> st.get_key_value('nlsat propagations')
6732 for idx
in range(len(self)):
6738 raise Z3Exception(
"unknown key")
6741 """Access the value of statistical using attributes.
6743 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6744 we should use '_' (e.g., 'nlsat_propagations').
6747 >>> s = Then('simplify', 'nlsat').solver()
6751 >>> st = s.statistics()
6752 >>> st.nlsat_propagations
6757 key = name.replace(
"_",
" ")
6761 raise AttributeError
6771 """Represents the result of a satisfiability check: sat, unsat, unknown.
6777 >>> isinstance(r, CheckSatResult)
6788 return isinstance(other, CheckSatResult)
and self.
rr == other.r
6791 return not self.
__eq____eq__(other)
6795 if self.
rr == Z3_L_TRUE:
6797 elif self.
rr == Z3_L_FALSE:
6798 return "<b>unsat</b>"
6800 return "<b>unknown</b>"
6802 if self.
rr == Z3_L_TRUE:
6804 elif self.
rr == Z3_L_FALSE:
6809 def _repr_html_(self):
6810 in_html = in_html_mode()
6813 set_html_mode(in_html)
6824 Solver API provides methods for implementing the main SMT 2.0 commands:
6825 push, pop, check, get-model, etc.
6828 def __init__(self, solver=None, ctx=None, logFile=None):
6829 assert solver
is None or ctx
is not None
6836 self.
solversolver = solver
6838 if logFile
is not None:
6839 self.
setset(
"smtlib2_log", logFile)
6842 if self.
solversolver
is not None and self.
ctxctx.ref()
is not None:
6846 """Set a configuration option.
6847 The method `help()` return a string containing all available options.
6850 >>> # The option MBQI can be set using three different approaches.
6851 >>> s.set(mbqi=True)
6852 >>> s.set('MBQI', True)
6853 >>> s.set(':mbqi', True)
6859 """Create a backtracking point.
6881 """Backtrack \\c num backtracking points.
6903 """Return the current number of backtracking points.
6921 """Remove all asserted constraints and backtracking points created using `push()`.
6935 """Assert constraints into the solver.
6939 >>> s.assert_exprs(x > 0, x < 2)
6943 args = _get_args(args)
6946 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6954 """Assert constraints into the solver.
6958 >>> s.add(x > 0, x < 2)
6969 """Assert constraints into the solver.
6973 >>> s.append(x > 0, x < 2)
6980 """Assert constraints into the solver.
6984 >>> s.insert(x > 0, x < 2)
6991 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6993 If `p` is a string, it will be automatically converted into a Boolean constant.
6998 >>> s.set(unsat_core=True)
6999 >>> s.assert_and_track(x > 0, 'p1')
7000 >>> s.assert_and_track(x != 1, 'p2')
7001 >>> s.assert_and_track(x < 0, p3)
7002 >>> print(s.check())
7004 >>> c = s.unsat_core()
7014 if isinstance(p, str):
7016 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7017 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7021 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
7027 >>> s.add(x > 0, x < 2)
7030 >>> s.model().eval(x)
7036 >>> s.add(2**x == 4)
7041 assumptions = _get_args(assumptions)
7042 num = len(assumptions)
7043 _assumptions = (Ast * num)()
7044 for i
in range(num):
7045 _assumptions[i] = s.cast(assumptions[i]).as_ast()
7050 """Return a model for the last `check()`.
7052 This function raises an exception if
7053 a model is not available (e.g., last `check()` returned unsat).
7057 >>> s.add(a + 2 == 0)
7066 raise Z3Exception(
"model is not available")
7069 """Import model converter from other into the current solver"""
7073 """Return a subset (as an AST vector) of the assumptions provided to the last check().
7075 These are the assumptions Z3 used in the unsatisfiability proof.
7076 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
7077 They may be also used to "retract" assumptions. Note that, assumptions are not really
7078 "soft constraints", but they can be used to implement them.
7080 >>> p1, p2, p3 = Bools('p1 p2 p3')
7081 >>> x, y = Ints('x y')
7083 >>> s.add(Implies(p1, x > 0))
7084 >>> s.add(Implies(p2, y > x))
7085 >>> s.add(Implies(p2, y < 1))
7086 >>> s.add(Implies(p3, y > -3))
7087 >>> s.check(p1, p2, p3)
7089 >>> core = s.unsat_core()
7098 >>> # "Retracting" p2
7105 """Determine fixed values for the variables based on the solver state and assumptions.
7107 >>> a, b, c, d = Bools('a b c d')
7108 >>> s.add(Implies(a,b), Implies(b, c))
7109 >>> s.consequences([a],[b,c,d])
7110 (sat, [Implies(a, b), Implies(a, c)])
7111 >>> s.consequences([Not(c),d],[a,b,c,d])
7112 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
7114 if isinstance(assumptions, list):
7116 for a
in assumptions:
7119 if isinstance(variables, list):
7124 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
7125 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
7128 variables.vector, consequences.vector)
7129 sz = len(consequences)
7130 consequences = [consequences[i]
for i
in range(sz)]
7134 """Parse assertions from a file"""
7138 """Parse assertions from a string"""
7143 The method takes an optional set of variables that restrict which
7144 variables may be used as a starting point for cubing.
7145 If vars is not None, then the first case split is based on a variable in
7149 if vars
is not None:
7156 if (len(r) == 1
and is_false(r[0])):
7163 """Access the set of variables that were touched by the most recently generated cube.
7164 This set of variables can be used as a starting point for additional cubes.
7165 The idea is that variables that appear in clauses that are reduced by the most recent
7166 cube are likely more useful to cube on."""
7170 """Return a proof for the last `check()`. Proof construction must be enabled."""
7174 """Return an AST vector containing all added constraints.
7188 """Return an AST vector containing all currently inferred units.
7193 """Return an AST vector containing all atomic formulas in solver state that are not units.
7198 """Return trail and decision levels of the solver state after a check() call.
7200 trail = self.
trailtrail()
7201 levels = (ctypes.c_uint * len(trail))()
7203 return trail, levels
7206 """Return trail of the solver state after a check() call.
7211 """Return statistics for the last `check()`.
7213 >>> s = SimpleSolver()
7218 >>> st = s.statistics()
7219 >>> st.get_key_value('final checks')
7229 """Return a string describing why the last `check()` returned `unknown`.
7232 >>> s = SimpleSolver()
7233 >>> s.add(2**x == 4)
7236 >>> s.reason_unknown()
7237 '(incomplete (theory arithmetic))'
7242 """Display a string describing all available options."""
7246 """Return the parameter description set."""
7250 """Return a formatted string with all added constraints."""
7251 return obj_to_string(self)
7254 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
7258 >>> s1 = Solver(ctx=c1)
7259 >>> s2 = s1.translate(c2)
7262 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
7264 return Solver(solver, target)
7273 """Return a formatted string (in Lisp-like format) with all added constraints.
7274 We say the string is in s-expression format.
7285 """Return a textual representation of the solver in DIMACS format."""
7289 """return SMTLIB2 formatted benchmark for solver's assertions"""
7296 for i
in range(sz1):
7297 v[i] = es[i].as_ast()
7299 e = es[sz1].as_ast()
7303 self.
ctxctx.ref(),
"benchmark generated from python API",
"",
"unknown",
"", sz1, v, e,
7308 """Create a solver customized for the given logic.
7310 The parameter `logic` is a string. It should be contains
7311 the name of a SMT-LIB logic.
7312 See http://www.smtlib.org/ for the name of all available logics.
7314 >>> s = SolverFor("QF_LIA")
7329 """Return a simple general purpose solver with limited amount of preprocessing.
7331 >>> s = SimpleSolver()
7348 """Fixedpoint API provides methods for solving with recursive predicates"""
7351 assert fixedpoint
is None or ctx
is not None
7354 if fixedpoint
is None:
7365 if self.
fixedpointfixedpoint
is not None and self.
ctxctx.ref()
is not None:
7369 """Set a configuration option. The method `help()` return a string containing all available options.
7375 """Display a string describing all available options."""
7379 """Return the parameter description set."""
7383 """Assert constraints as background axioms for the fixedpoint solver."""
7384 args = _get_args(args)
7387 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7397 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7405 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7409 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7413 """Assert rules defining recursive predicates to the fixedpoint solver.
7416 >>> s = Fixedpoint()
7417 >>> s.register_relation(a.decl())
7418 >>> s.register_relation(b.decl())
7431 body = _get_args(body)
7435 def rule(self, head, body=None, name=None):
7436 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7437 self.
add_ruleadd_rule(head, body, name)
7440 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7441 self.
add_ruleadd_rule(head,
None, name)
7444 """Query the fixedpoint engine whether formula is derivable.
7445 You can also pass an tuple or list of recursive predicates.
7447 query = _get_args(query)
7449 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7450 _decls = (FuncDecl * sz)()
7460 query =
And(query, self.
ctxctx)
7461 query = self.
abstractabstract(query,
False)
7466 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7468 query = _get_args(query)
7470 if sz >= 1
and isinstance(query[0], FuncDecl):
7471 _z3_assert(
False,
"unsupported")
7477 query = self.
abstractabstract(query,
False)
7478 r = Z3_fixedpoint_query_from_lvl(self.
ctxctx.ref(), self.
fixedpointfixedpoint, query.as_ast(), lvl)
7486 body = _get_args(body)
7491 """Retrieve answer from last query call."""
7493 return _to_expr_ref(r, self.
ctxctx)
7496 """Retrieve a ground cex from last query call."""
7497 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctxctx.ref(), self.
fixedpointfixedpoint)
7498 return _to_expr_ref(r, self.
ctxctx)
7501 """retrieve rules along the counterexample trace"""
7505 """retrieve rule names along the counterexample trace"""
7508 names = _symbol2py(self.
ctxctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctxctx.ref(), self.
fixedpointfixedpoint))
7510 return names.split(
";")
7513 """Retrieve number of levels used for predicate in PDR engine"""
7517 """Retrieve properties known about predicate for the level'th unfolding.
7518 -1 is treated as the limit (infinity)
7521 return _to_expr_ref(r, self.
ctxctx)
7524 """Add property to predicate for the level'th unfolding.
7525 -1 is treated as infinity (infinity)
7530 """Register relation as recursive"""
7531 relations = _get_args(relations)
7536 """Control how relation is represented"""
7537 representations = _get_args(representations)
7538 representations = [
to_symbol(s)
for s
in representations]
7539 sz = len(representations)
7540 args = (Symbol * sz)()
7542 args[i] = representations[i]
7546 """Parse rules and queries from a string"""
7550 """Parse rules and queries from a file"""
7554 """retrieve rules that have been added to fixedpoint context"""
7558 """retrieve assertions that have been added to fixedpoint context"""
7562 """Return a formatted string with all added rules and constraints."""
7563 return self.
sexprsexpr()
7566 """Return a formatted string (in Lisp-like format) with all added constraints.
7567 We say the string is in s-expression format.
7572 """Return a formatted string (in Lisp-like format) with all added constraints.
7573 We say the string is in s-expression format.
7574 Include also queries.
7576 args, len = _to_ast_array(queries)
7580 """Return statistics for the last `query()`.
7585 """Return a string describing why the last `query()` returned `unknown`.
7590 """Add variable or several variables.
7591 The added variable or variables will be bound in the rules
7594 vars = _get_args(vars)
7596 self.
varsvars += [v]
7599 if self.
varsvars == []:
7614 """Finite domain sort."""
7617 """Return the size of the finite domain sort"""
7618 r = (ctypes.c_ulonglong * 1)()
7622 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7626 """Create a named finite domain sort of a given size sz"""
7627 if not isinstance(name, Symbol):
7634 """Return True if `s` is a Z3 finite-domain sort.
7636 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7638 >>> is_finite_domain_sort(IntSort())
7641 return isinstance(s, FiniteDomainSortRef)
7645 """Finite-domain expressions."""
7648 """Return the sort of the finite-domain expression `self`."""
7652 """Return a Z3 floating point expression as a Python string."""
7657 """Return `True` if `a` is a Z3 finite-domain expression.
7659 >>> s = FiniteDomainSort('S', 100)
7660 >>> b = Const('b', s)
7661 >>> is_finite_domain(b)
7663 >>> is_finite_domain(Int('x'))
7666 return isinstance(a, FiniteDomainRef)
7670 """Integer values."""
7673 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7675 >>> s = FiniteDomainSort('S', 100)
7676 >>> v = FiniteDomainVal(3, s)
7685 """Return a Z3 finite-domain numeral as a Python string.
7687 >>> s = FiniteDomainSort('S', 100)
7688 >>> v = FiniteDomainVal(42, s)
7696 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7698 >>> s = FiniteDomainSort('S', 256)
7699 >>> FiniteDomainVal(255, s)
7701 >>> FiniteDomainVal('100', s)
7711 """Return `True` if `a` is a Z3 finite-domain value.
7713 >>> s = FiniteDomainSort('S', 100)
7714 >>> b = Const('b', s)
7715 >>> is_finite_domain_value(b)
7717 >>> b = FiniteDomainVal(10, s)
7720 >>> is_finite_domain_value(b)
7735 self.
_value_value = value
7756 return self.
upperupper()
7758 return self.
lowerlower()
7767 def _global_on_model(ctx):
7768 (fn, mdl) = _on_models[ctx]
7772 _on_model_eh = on_model_eh_type(_global_on_model)
7776 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7788 if self.
optimizeoptimize
is not None and self.
ctxctx.ref()
is not None:
7794 """Set a configuration option.
7795 The method `help()` return a string containing all available options.
7801 """Display a string describing all available options."""
7805 """Return the parameter description set."""
7809 """Assert constraints as background axioms for the optimize solver."""
7810 args = _get_args(args)
7813 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7821 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7829 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7831 If `p` is a string, it will be automatically converted into a Boolean constant.
7836 >>> s.assert_and_track(x > 0, 'p1')
7837 >>> s.assert_and_track(x != 1, 'p2')
7838 >>> s.assert_and_track(x < 0, p3)
7839 >>> print(s.check())
7841 >>> c = s.unsat_core()
7851 if isinstance(p, str):
7853 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7854 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7858 """Add soft constraint with optional weight and optional identifier.
7859 If no weight is supplied, then the penalty for violating the soft constraint
7861 Soft constraints are grouped by identifiers. Soft constraints that are
7862 added without identifiers are grouped by default.
7865 weight =
"%d" % weight
7866 elif isinstance(weight, float):
7867 weight =
"%f" % weight
7868 if not isinstance(weight, str):
7869 raise Z3Exception(
"weight should be a string or an integer")
7877 if sys.version_info.major >= 3
and isinstance(arg, Iterable):
7878 return [asoft(a)
for a
in arg]
7882 """Add objective function to maximize."""
7890 """Add objective function to minimize."""
7898 """create a backtracking point for added rules, facts and assertions"""
7902 """restore to previously created backtracking point"""
7906 """Check satisfiability while optimizing objective functions."""
7907 assumptions = _get_args(assumptions)
7908 num = len(assumptions)
7909 _assumptions = (Ast * num)()
7910 for i
in range(num):
7911 _assumptions[i] = assumptions[i].as_ast()
7915 """Return a string that describes why the last `check()` returned `unknown`."""
7919 """Return a model for the last check()."""
7923 raise Z3Exception(
"model is not available")
7929 if not isinstance(obj, OptimizeObjective):
7930 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7934 if not isinstance(obj, OptimizeObjective):
7935 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7939 if not isinstance(obj, OptimizeObjective):
7940 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7941 return obj.lower_values()
7944 if not isinstance(obj, OptimizeObjective):
7945 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7946 return obj.upper_values()
7949 """Parse assertions and objectives from a file"""
7953 """Parse assertions and objectives from a string"""
7957 """Return an AST vector containing all added constraints."""
7961 """returns set of objective functions"""
7965 """Return a formatted string with all added rules and constraints."""
7966 return self.
sexprsexpr()
7969 """Return a formatted string (in Lisp-like format) with all added constraints.
7970 We say the string is in s-expression format.
7975 """Return statistics for the last check`.
7980 """Register a callback that is invoked with every incremental improvement to
7981 objective values. The callback takes a model as argument.
7982 The life-time of the model is limited to the callback so the
7983 model has to be (deep) copied if it is to be used after the callback
7985 id = len(_on_models) + 41
7987 _on_models[id] = (on_model, mdl)
7990 self.
ctxctx.ref(), self.
optimizeoptimize, mdl.model, ctypes.c_void_p(id), _on_model_eh,
8000 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal.
8001 It also contains model and proof converters.
8013 if self.
ctxctx.ref()
is not None:
8017 """Return the number of subgoals in `self`.
8019 >>> a, b = Ints('a b')
8021 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
8022 >>> t = Tactic('split-clause')
8026 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
8029 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
8036 """Return one of the subgoals stored in ApplyResult object `self`.
8038 >>> a, b = Ints('a b')
8040 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
8041 >>> t = Tactic('split-clause')
8044 [a == 0, Or(b == 0, b == 1), a > b]
8046 [a == 1, Or(b == 0, b == 1), a > b]
8048 if idx >= len(self):
8053 return obj_to_string(self)
8056 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
8060 """Return a Z3 expression consisting of all subgoals.
8065 >>> g.add(Or(x == 2, x == 3))
8066 >>> r = Tactic('simplify')(g)
8068 [[Not(x <= 1), Or(x == 2, x == 3)]]
8070 And(Not(x <= 1), Or(x == 2, x == 3))
8071 >>> r = Tactic('split-clause')(g)
8073 [[x > 1, x == 2], [x > 1, x == 3]]
8075 Or(And(x > 1, x == 2), And(x > 1, x == 3))
8093 """Tactics transform, solver and/or simplify sets of constraints (Goal).
8094 A Tactic can be converted into a Solver using the method solver().
8096 Several combinators are available for creating new tactics using the built-in ones:
8097 Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
8103 if isinstance(tactic, TacticObj):
8104 self.
tactictactic = tactic
8107 _z3_assert(isinstance(tactic, str),
"tactic name expected")
8111 raise Z3Exception(
"unknown tactic '%s'" % tactic)
8118 if self.
tactictactic
is not None and self.
ctxctx.ref()
is not None:
8122 """Create a solver using the tactic `self`.
8124 The solver supports the methods `push()` and `pop()`, but it
8125 will always solve each `check()` from scratch.
8127 >>> t = Then('simplify', 'nlsat')
8130 >>> s.add(x**2 == 2, x > 0)
8138 def apply(self, goal, *arguments, **keywords):
8139 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8141 >>> x, y = Ints('x y')
8142 >>> t = Tactic('solve-eqs')
8143 >>> t.apply(And(x == 0, y >= x + 1))
8147 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expressions expected")
8148 goal = _to_goal(goal)
8149 if len(arguments) > 0
or len(keywords) > 0:
8156 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8158 >>> x, y = Ints('x y')
8159 >>> t = Tactic('solve-eqs')
8160 >>> t(And(x == 0, y >= x + 1))
8163 return self.
applyapply(goal, *arguments, **keywords)
8166 """Display a string containing a description of the available options for the `self` tactic."""
8170 """Return the parameter description set."""
8175 if isinstance(a, BoolRef):
8176 goal =
Goal(ctx=a.ctx)
8183 def _to_tactic(t, ctx=None):
8184 if isinstance(t, Tactic):
8190 def _and_then(t1, t2, ctx=None):
8191 t1 = _to_tactic(t1, ctx)
8192 t2 = _to_tactic(t2, ctx)
8194 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8198 def _or_else(t1, t2, ctx=None):
8199 t1 = _to_tactic(t1, ctx)
8200 t2 = _to_tactic(t2, ctx)
8202 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8207 """Return a tactic that applies the tactics in `*ts` in sequence.
8209 >>> x, y = Ints('x y')
8210 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8211 >>> t(And(x == 0, y > x + 1))
8213 >>> t(And(x == 0, y > x + 1)).as_expr()
8217 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8218 ctx = ks.get(
"ctx",
None)
8221 for i
in range(num - 1):
8222 r = _and_then(r, ts[i + 1], ctx)
8227 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8229 >>> x, y = Ints('x y')
8230 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8231 >>> t(And(x == 0, y > x + 1))
8233 >>> t(And(x == 0, y > x + 1)).as_expr()
8240 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8243 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8244 >>> # Tactic split-clause fails if there is no clause in the given goal.
8247 >>> t(Or(x == 0, x == 1))
8248 [[x == 0], [x == 1]]
8251 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8252 ctx = ks.get(
"ctx",
None)
8255 for i
in range(num - 1):
8256 r = _or_else(r, ts[i + 1], ctx)
8261 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8264 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8269 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8270 ctx = _get_ctx(ks.get(
"ctx",
None))
8271 ts = [_to_tactic(t, ctx)
for t
in ts]
8273 _args = (TacticObj * sz)()
8275 _args[i] = ts[i].tactic
8280 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8281 The subgoals are processed in parallel.
8283 >>> x, y = Ints('x y')
8284 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8285 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8286 [[x == 1, y == 2], [x == 2, y == 3]]
8288 t1 = _to_tactic(t1, ctx)
8289 t2 = _to_tactic(t2, ctx)
8291 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8296 """Alias for ParThen(t1, t2, ctx)."""
8301 """Return a tactic that applies tactic `t` using the given configuration options.
8303 >>> x, y = Ints('x y')
8304 >>> t = With(Tactic('simplify'), som=True)
8305 >>> t((x + 1)*(y + 2) == 0)
8306 [[2*x + y + x*y == -2]]
8308 ctx = keys.pop(
"ctx",
None)
8309 t = _to_tactic(t, ctx)
8315 """Return a tactic that applies tactic `t` using the given configuration options.
8317 >>> x, y = Ints('x y')
8319 >>> p.set("som", True)
8320 >>> t = WithParams(Tactic('simplify'), p)
8321 >>> t((x + 1)*(y + 2) == 0)
8322 [[2*x + y + x*y == -2]]
8324 t = _to_tactic(t,
None)
8329 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8330 or the maximum number of iterations `max` is reached.
8332 >>> x, y = Ints('x y')
8333 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8334 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8336 >>> for subgoal in r: print(subgoal)
8337 [x == 0, y == 0, x > y]
8338 [x == 0, y == 1, x > y]
8339 [x == 1, y == 0, x > y]
8340 [x == 1, y == 1, x > y]
8341 >>> t = Then(t, Tactic('propagate-values'))
8345 t = _to_tactic(t, ctx)
8350 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8352 If `t` does not terminate in `ms` milliseconds, then it fails.
8354 t = _to_tactic(t, ctx)
8359 """Return a list of all available tactics in Z3.
8362 >>> l.count('simplify') == 1
8370 """Return a short description for the tactic named `name`.
8372 >>> d = tactic_description('simplify')
8379 """Display a (tabular) description of all available tactics in Z3."""
8382 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8385 print(
'<tr style="background-color:#CFCFCF">')
8390 print(
"<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(
tactic_description(t), 40)))
8398 """Probes are used to inspect a goal (aka problem) and collect information that may be used
8399 to decide which solver and/or preprocessing step will be used.
8405 if isinstance(probe, ProbeObj):
8406 self.
probeprobe = probe
8407 elif isinstance(probe, float):
8409 elif _is_int(probe):
8411 elif isinstance(probe, bool):
8418 _z3_assert(isinstance(probe, str),
"probe name expected")
8422 raise Z3Exception(
"unknown probe '%s'" % probe)
8429 if self.
probeprobe
is not None and self.
ctxctx.ref()
is not None:
8433 """Return a probe that evaluates to "true" when the value returned by `self`
8434 is less than the value returned by `other`.
8436 >>> p = Probe('size') < 10
8447 """Return a probe that evaluates to "true" when the value returned by `self`
8448 is greater than the value returned by `other`.
8450 >>> p = Probe('size') > 10
8461 """Return a probe that evaluates to "true" when the value returned by `self`
8462 is less than or equal to the value returned by `other`.
8464 >>> p = Probe('size') <= 2
8475 """Return a probe that evaluates to "true" when the value returned by `self`
8476 is greater than or equal to the value returned by `other`.
8478 >>> p = Probe('size') >= 2
8489 """Return a probe that evaluates to "true" when the value returned by `self`
8490 is equal to the value returned by `other`.
8492 >>> p = Probe('size') == 2
8503 """Return a probe that evaluates to "true" when the value returned by `self`
8504 is not equal to the value returned by `other`.
8506 >>> p = Probe('size') != 2
8514 p = self.
__eq____eq__(other)
8518 """Evaluate the probe `self` in the given goal.
8520 >>> p = Probe('size')
8530 >>> p = Probe('num-consts')
8533 >>> p = Probe('is-propositional')
8536 >>> p = Probe('is-qflia')
8541 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expression expected")
8542 goal = _to_goal(goal)
8547 """Return `True` if `p` is a Z3 probe.
8549 >>> is_probe(Int('x'))
8551 >>> is_probe(Probe('memory'))
8554 return isinstance(p, Probe)
8557 def _to_probe(p, ctx=None):
8561 return Probe(p, ctx)
8565 """Return a list of all available probes in Z3.
8568 >>> l.count('memory') == 1
8576 """Return a short description for the probe named `name`.
8578 >>> d = probe_description('memory')
8585 """Display a (tabular) description of all available probes in Z3."""
8588 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8591 print(
'<tr style="background-color:#CFCFCF">')
8596 print(
"<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(
probe_description(p), 40)))
8603 def _probe_nary(f, args, ctx):
8605 _z3_assert(len(args) > 0,
"At least one argument expected")
8607 r = _to_probe(args[0], ctx)
8608 for i
in range(num - 1):
8609 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8613 def _probe_and(args, ctx):
8614 return _probe_nary(Z3_probe_and, args, ctx)
8617 def _probe_or(args, ctx):
8618 return _probe_nary(Z3_probe_or, args, ctx)
8622 """Return a tactic that fails if the probe `p` evaluates to true.
8623 Otherwise, it returns the input goal unmodified.
8625 In the following example, the tactic applies 'simplify' if and only if there are
8626 more than 2 constraints in the goal.
8628 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8629 >>> x, y = Ints('x y')
8635 >>> g.add(x == y + 1)
8637 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8639 p = _to_probe(p, ctx)
8644 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8645 Otherwise, it returns the input goal unmodified.
8647 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8648 >>> x, y = Ints('x y')
8654 >>> g.add(x == y + 1)
8656 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8658 p = _to_probe(p, ctx)
8659 t = _to_tactic(t, ctx)
8664 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8666 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8668 p = _to_probe(p, ctx)
8669 t1 = _to_tactic(t1, ctx)
8670 t2 = _to_tactic(t2, ctx)
8681 """Simplify the expression `a` using the given options.
8683 This function has many options. Use `help_simplify` to obtain the complete list.
8687 >>> simplify(x + 1 + y + x + 1)
8689 >>> simplify((x + 1)*(y + 1), som=True)
8691 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8692 And(Not(x == y), Not(x == 1), Not(y == 1))
8693 >>> simplify(And(x == 0, y == 1), elim_and=True)
8694 Not(Or(Not(x == 0), Not(y == 1)))
8697 _z3_assert(
is_expr(a),
"Z3 expression expected")
8698 if len(arguments) > 0
or len(keywords) > 0:
8700 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8702 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8706 """Return a string describing all options available for Z3 `simplify` procedure."""
8711 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8716 """Apply substitution m on t, m is a list of pairs of the form (from, to).
8717 Every occurrence in t of from is replaced with to.
8721 >>> substitute(x + 1, (x, y + 1))
8723 >>> f = Function('f', IntSort(), IntSort())
8724 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8727 if isinstance(m, tuple):
8729 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8732 _z3_assert(
is_expr(t),
"Z3 expression expected")
8733 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(
8734 p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8736 _from = (Ast * num)()
8738 for i
in range(num):
8739 _from[i] = m[i][0].as_ast()
8740 _to[i] = m[i][1].as_ast()
8741 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8745 """Substitute the free variables in t with the expression in m.
8747 >>> v0 = Var(0, IntSort())
8748 >>> v1 = Var(1, IntSort())
8750 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8751 >>> # replace v0 with x+1 and v1 with x
8752 >>> substitute_vars(f(v0, v1), x + 1, x)
8756 _z3_assert(
is_expr(t),
"Z3 expression expected")
8757 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8760 for i
in range(num):
8761 _to[i] = m[i].as_ast()
8766 """Create the sum of the Z3 expressions.
8768 >>> a, b, c = Ints('a b c')
8773 >>> A = IntVector('a', 5)
8775 a__0 + a__1 + a__2 + a__3 + a__4
8777 args = _get_args(args)
8780 ctx = _ctx_from_ast_arg_list(args)
8782 return _reduce(
lambda a, b: a + b, args, 0)
8783 args = _coerce_expr_list(args, ctx)
8785 return _reduce(
lambda a, b: a + b, args, 0)
8787 _args, sz = _to_ast_array(args)
8792 """Create the product of the Z3 expressions.
8794 >>> a, b, c = Ints('a b c')
8795 >>> Product(a, b, c)
8797 >>> Product([a, b, c])
8799 >>> A = IntVector('a', 5)
8801 a__0*a__1*a__2*a__3*a__4
8803 args = _get_args(args)
8806 ctx = _ctx_from_ast_arg_list(args)
8808 return _reduce(
lambda a, b: a * b, args, 1)
8809 args = _coerce_expr_list(args, ctx)
8811 return _reduce(
lambda a, b: a * b, args, 1)
8813 _args, sz = _to_ast_array(args)
8817 """Create the absolute value of an arithmetic expression"""
8818 return If(arg > 0, arg, -arg)
8822 """Create an at-most Pseudo-Boolean k constraint.
8824 >>> a, b, c = Bools('a b c')
8825 >>> f = AtMost(a, b, c, 2)
8827 args = _get_args(args)
8829 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8830 ctx = _ctx_from_ast_arg_list(args)
8832 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8833 args1 = _coerce_expr_list(args[:-1], ctx)
8835 _args, sz = _to_ast_array(args1)
8840 """Create an at-most Pseudo-Boolean k constraint.
8842 >>> a, b, c = Bools('a b c')
8843 >>> f = AtLeast(a, b, c, 2)
8845 args = _get_args(args)
8847 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8848 ctx = _ctx_from_ast_arg_list(args)
8850 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8851 args1 = _coerce_expr_list(args[:-1], ctx)
8853 _args, sz = _to_ast_array(args1)
8857 def _reorder_pb_arg(arg):
8859 if not _is_int(b)
and _is_int(a):
8864 def _pb_args_coeffs(args, default_ctx=None):
8865 args = _get_args_ast_list(args)
8867 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8868 args = [_reorder_pb_arg(arg)
for arg
in args]
8869 args, coeffs = zip(*args)
8871 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8872 ctx = _ctx_from_ast_arg_list(args)
8874 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8875 args = _coerce_expr_list(args, ctx)
8876 _args, sz = _to_ast_array(args)
8877 _coeffs = (ctypes.c_int * len(coeffs))()
8878 for i
in range(len(coeffs)):
8879 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8880 _coeffs[i] = coeffs[i]
8881 return ctx, sz, _args, _coeffs, args
8885 """Create a Pseudo-Boolean inequality k constraint.
8887 >>> a, b, c = Bools('a b c')
8888 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8890 _z3_check_cint_overflow(k,
"k")
8891 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8896 """Create a Pseudo-Boolean inequality k constraint.
8898 >>> a, b, c = Bools('a b c')
8899 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8901 _z3_check_cint_overflow(k,
"k")
8902 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8907 """Create a Pseudo-Boolean inequality k constraint.
8909 >>> a, b, c = Bools('a b c')
8910 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8912 _z3_check_cint_overflow(k,
"k")
8913 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8918 """Solve the constraints `*args`.
8920 This is a simple function for creating demonstrations. It creates a solver,
8921 configure it using the options in `keywords`, adds the constraints
8922 in `args`, and invokes check.
8925 >>> solve(a > 0, a < 2)
8928 show = keywords.pop(
"show",
False)
8936 print(
"no solution")
8938 print(
"failed to solve")
8948 """Solve the constraints `*args` using solver `s`.
8950 This is a simple function for creating demonstrations. It is similar to `solve`,
8951 but it uses the given solver `s`.
8952 It configures solver `s` using the options in `keywords`, adds the constraints
8953 in `args`, and invokes check.
8955 show = keywords.pop(
"show",
False)
8957 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8965 print(
"no solution")
8967 print(
"failed to solve")
8978 def prove(claim, show=False, **keywords):
8979 """Try to prove the given claim.
8981 This is a simple function for creating demonstrations. It tries to prove
8982 `claim` by showing the negation is unsatisfiable.
8984 >>> p, q = Bools('p q')
8985 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8989 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8999 print(
"failed to prove")
9002 print(
"counterexample")
9006 def _solve_html(*args, **keywords):
9007 """Version of function `solve` that renders HTML output."""
9008 show = keywords.pop(
"show",
False)
9013 print(
"<b>Problem:</b>")
9017 print(
"<b>no solution</b>")
9019 print(
"<b>failed to solve</b>")
9026 print(
"<b>Solution:</b>")
9030 def _solve_using_html(s, *args, **keywords):
9031 """Version of function `solve_using` that renders HTML."""
9032 show = keywords.pop(
"show",
False)
9034 _z3_assert(isinstance(s, Solver),
"Solver object expected")
9038 print(
"<b>Problem:</b>")
9042 print(
"<b>no solution</b>")
9044 print(
"<b>failed to solve</b>")
9051 print(
"<b>Solution:</b>")
9055 def _prove_html(claim, show=False, **keywords):
9056 """Version of function `prove` that renders HTML."""
9058 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9066 print(
"<b>proved</b>")
9068 print(
"<b>failed to prove</b>")
9071 print(
"<b>counterexample</b>")
9075 def _dict2sarray(sorts, ctx):
9077 _names = (Symbol * sz)()
9078 _sorts = (Sort * sz)()
9083 _z3_assert(isinstance(k, str),
"String expected")
9084 _z3_assert(
is_sort(v),
"Z3 sort expected")
9088 return sz, _names, _sorts
9091 def _dict2darray(decls, ctx):
9093 _names = (Symbol * sz)()
9094 _decls = (FuncDecl * sz)()
9099 _z3_assert(isinstance(k, str),
"String expected")
9103 _decls[i] = v.decl().ast
9107 return sz, _names, _decls
9111 """Parse a string in SMT 2.0 format using the given sorts and decls.
9113 The arguments sorts and decls are Python dictionaries used to initialize
9114 the symbol table used for the SMT 2.0 parser.
9116 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9118 >>> x, y = Ints('x y')
9119 >>> f = Function('f', IntSort(), IntSort())
9120 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9122 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9126 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9127 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9132 """Parse a file in SMT 2.0 format using the given sorts and decls.
9134 This function is similar to parse_smt2_string().
9137 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9138 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9150 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
9151 _dflt_fpsort_ebits = 11
9152 _dflt_fpsort_sbits = 53
9156 """Retrieves the global default rounding mode."""
9157 global _dflt_rounding_mode
9158 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9160 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9162 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9164 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9166 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9170 _ROUNDING_MODES = frozenset({
9171 Z3_OP_FPA_RM_TOWARD_ZERO,
9172 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
9173 Z3_OP_FPA_RM_TOWARD_POSITIVE,
9174 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
9175 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
9180 global _dflt_rounding_mode
9182 _dflt_rounding_mode = rm.decl().kind()
9184 _z3_assert(_dflt_rounding_mode
in _ROUNDING_MODES,
"illegal rounding mode")
9185 _dflt_rounding_mode = rm
9189 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9193 global _dflt_fpsort_ebits
9194 global _dflt_fpsort_sbits
9195 _dflt_fpsort_ebits = ebits
9196 _dflt_fpsort_sbits = sbits
9199 def _dflt_rm(ctx=None):
9203 def _dflt_fps(ctx=None):
9207 def _coerce_fp_expr_list(alist, ctx):
9208 first_fp_sort =
None
9211 if first_fp_sort
is None:
9212 first_fp_sort = a.sort()
9213 elif first_fp_sort == a.sort():
9218 first_fp_sort =
None
9222 for i
in range(len(alist)):
9224 is_repr = isinstance(a, str)
and a.contains(
"2**(")
and a.endswith(
")")
9225 if is_repr
or _is_int(a)
or isinstance(a, (float, bool)):
9226 r.append(
FPVal(a,
None, first_fp_sort, ctx))
9229 return _coerce_expr_list(r, ctx)
9235 """Floating-point sort."""
9238 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
9239 >>> b = FPSort(8, 24)
9246 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
9247 >>> b = FPSort(8, 24)
9254 """Try to cast `val` as a floating-point expression.
9255 >>> b = FPSort(8, 24)
9258 >>> b.cast(1.0).sexpr()
9259 '(fp #b0 #x7f #b00000000000000000000000)'
9263 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
9270 """Floating-point 16-bit (half) sort."""
9276 """Floating-point 16-bit (half) sort."""
9282 """Floating-point 32-bit (single) sort."""
9288 """Floating-point 32-bit (single) sort."""
9294 """Floating-point 64-bit (double) sort."""
9300 """Floating-point 64-bit (double) sort."""
9306 """Floating-point 128-bit (quadruple) sort."""
9312 """Floating-point 128-bit (quadruple) sort."""
9318 """"Floating-point rounding mode sort."""
9322 """Return True if `s` is a Z3 floating-point sort.
9324 >>> is_fp_sort(FPSort(8, 24))
9326 >>> is_fp_sort(IntSort())
9329 return isinstance(s, FPSortRef)
9333 """Return True if `s` is a Z3 floating-point rounding mode sort.
9335 >>> is_fprm_sort(FPSort(8, 24))
9337 >>> is_fprm_sort(RNE().sort())
9340 return isinstance(s, FPRMSortRef)
9346 """Floating-point expressions."""
9349 """Return the sort of the floating-point expression `self`.
9351 >>> x = FP('1.0', FPSort(8, 24))
9354 >>> x.sort() == FPSort(8, 24)
9360 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9361 >>> b = FPSort(8, 24)
9368 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9369 >>> b = FPSort(8, 24)
9376 """Return a Z3 floating point expression as a Python string."""
9380 return fpLEQ(self, other, self.
ctxctx)
9383 return fpLT(self, other, self.
ctxctx)
9386 return fpGEQ(self, other, self.
ctxctx)
9389 return fpGT(self, other, self.
ctxctx)
9392 """Create the Z3 expression `self + other`.
9394 >>> x = FP('x', FPSort(8, 24))
9395 >>> y = FP('y', FPSort(8, 24))
9401 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9402 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
9405 """Create the Z3 expression `other + self`.
9407 >>> x = FP('x', FPSort(8, 24))
9411 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9412 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
9415 """Create the Z3 expression `self - other`.
9417 >>> x = FP('x', FPSort(8, 24))
9418 >>> y = FP('y', FPSort(8, 24))
9424 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9425 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
9428 """Create the Z3 expression `other - self`.
9430 >>> x = FP('x', FPSort(8, 24))
9434 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9435 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
9438 """Create the Z3 expression `self * other`.
9440 >>> x = FP('x', FPSort(8, 24))
9441 >>> y = FP('y', FPSort(8, 24))
9449 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9450 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
9453 """Create the Z3 expression `other * self`.
9455 >>> x = FP('x', FPSort(8, 24))
9456 >>> y = FP('y', FPSort(8, 24))
9462 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9463 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
9466 """Create the Z3 expression `+self`."""
9470 """Create the Z3 expression `-self`.
9472 >>> x = FP('x', Float32())
9479 """Create the Z3 expression `self / other`.
9481 >>> x = FP('x', FPSort(8, 24))
9482 >>> y = FP('y', FPSort(8, 24))
9490 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9491 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
9494 """Create the Z3 expression `other / self`.
9496 >>> x = FP('x', FPSort(8, 24))
9497 >>> y = FP('y', FPSort(8, 24))
9503 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9504 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
9507 """Create the Z3 expression division `self / other`."""
9508 return self.
__div____div__(other)
9511 """Create the Z3 expression division `other / self`."""
9512 return self.
__rdiv____rdiv__(other)
9515 """Create the Z3 expression mod `self % other`."""
9516 return fpRem(self, other)
9519 """Create the Z3 expression mod `other % self`."""
9520 return fpRem(other, self)
9524 """Floating-point rounding mode expressions"""
9527 """Return a Z3 floating point expression as a Python string."""
9582 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9591 return isinstance(a, FPRMRef)
9595 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9596 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9602 """The sign of the numeral.
9604 >>> x = FPVal(+1.0, FPSort(8, 24))
9607 >>> x = FPVal(-1.0, FPSort(8, 24))
9613 num = (ctypes.c_int)()
9616 raise Z3Exception(
"error retrieving the sign of a numeral.")
9617 return num.value != 0
9619 """The sign of a floating-point numeral as a bit-vector expression.
9621 Remark: NaN's are invalid arguments.
9627 """The significand of the numeral.
9629 >>> x = FPVal(2.5, FPSort(8, 24))
9637 """The significand of the numeral as a long.
9639 >>> x = FPVal(2.5, FPSort(8, 24))
9640 >>> x.significand_as_long()
9645 ptr = (ctypes.c_ulonglong * 1)()
9647 raise Z3Exception(
"error retrieving the significand of a numeral.")
9650 """The significand of the numeral as a bit-vector expression.
9652 Remark: NaN are invalid arguments.
9658 """The exponent of the numeral.
9660 >>> x = FPVal(2.5, FPSort(8, 24))
9668 """The exponent of the numeral as a long.
9670 >>> x = FPVal(2.5, FPSort(8, 24))
9671 >>> x.exponent_as_long()
9676 ptr = (ctypes.c_longlong * 1)()
9678 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9681 """The exponent of the numeral as a bit-vector expression.
9683 Remark: NaNs are invalid arguments.
9689 """Indicates whether the numeral is a NaN."""
9694 """Indicates whether the numeral is +oo or -oo."""
9699 """Indicates whether the numeral is +zero or -zero."""
9704 """Indicates whether the numeral is normal."""
9709 """Indicates whether the numeral is subnormal."""
9714 """Indicates whether the numeral is positive."""
9719 """Indicates whether the numeral is negative."""
9725 The string representation of the numeral.
9727 >>> x = FPVal(20, FPSort(8, 24))
9734 return (
"FPVal(%s, %s)" % (s, self.
sortsortsort()))
9738 """Return `True` if `a` is a Z3 floating-point expression.
9740 >>> b = FP('b', FPSort(8, 24))
9748 return isinstance(a, FPRef)
9752 """Return `True` if `a` is a Z3 floating-point numeral value.
9754 >>> b = FP('b', FPSort(8, 24))
9757 >>> b = FPVal(1.0, FPSort(8, 24))
9763 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9767 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9769 >>> Single = FPSort(8, 24)
9770 >>> Double = FPSort(11, 53)
9773 >>> x = Const('x', Single)
9774 >>> eq(x, FP('x', FPSort(8, 24)))
9781 def _to_float_str(val, exp=0):
9782 if isinstance(val, float):
9786 sone = math.copysign(1.0, val)
9791 elif val == float(
"+inf"):
9793 elif val == float(
"-inf"):
9796 v = val.as_integer_ratio()
9799 rvs = str(num) +
"/" + str(den)
9800 res = rvs +
"p" + _to_int_str(exp)
9801 elif isinstance(val, bool):
9808 elif isinstance(val, str):
9809 inx = val.find(
"*(2**")
9812 elif val[-1] ==
")":
9814 exp = str(int(val[inx + 5:-1]) + int(exp))
9816 _z3_assert(
False,
"String does not have floating-point numeral form.")
9818 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9822 return res +
"p" + exp
9826 """Create a Z3 floating-point NaN term.
9828 >>> s = FPSort(8, 24)
9829 >>> set_fpa_pretty(True)
9832 >>> pb = get_fpa_pretty()
9833 >>> set_fpa_pretty(False)
9835 fpNaN(FPSort(8, 24))
9836 >>> set_fpa_pretty(pb)
9838 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9843 """Create a Z3 floating-point +oo term.
9845 >>> s = FPSort(8, 24)
9846 >>> pb = get_fpa_pretty()
9847 >>> set_fpa_pretty(True)
9848 >>> fpPlusInfinity(s)
9850 >>> set_fpa_pretty(False)
9851 >>> fpPlusInfinity(s)
9852 fpPlusInfinity(FPSort(8, 24))
9853 >>> set_fpa_pretty(pb)
9855 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9860 """Create a Z3 floating-point -oo term."""
9861 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9866 """Create a Z3 floating-point +oo or -oo term."""
9867 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9868 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9873 """Create a Z3 floating-point +0.0 term."""
9874 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9879 """Create a Z3 floating-point -0.0 term."""
9880 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9885 """Create a Z3 floating-point +0.0 or -0.0 term."""
9886 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9887 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9891 def FPVal(sig, exp=None, fps=None, ctx=None):
9892 """Return a floating-point value of value `val` and sort `fps`.
9893 If `ctx=None`, then the global context is used.
9895 >>> v = FPVal(20.0, FPSort(8, 24))
9898 >>> print("0x%.8x" % v.exponent_as_long(False))
9900 >>> v = FPVal(2.25, FPSort(8, 24))
9903 >>> v = FPVal(-2.25, FPSort(8, 24))
9906 >>> FPVal(-0.0, FPSort(8, 24))
9908 >>> FPVal(0.0, FPSort(8, 24))
9910 >>> FPVal(+0.0, FPSort(8, 24))
9918 fps = _dflt_fps(ctx)
9922 val = _to_float_str(sig)
9923 if val ==
"NaN" or val ==
"nan":
9927 elif val ==
"0.0" or val ==
"+0.0":
9929 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9931 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9937 def FP(name, fpsort, ctx=None):
9938 """Return a floating-point constant named `name`.
9939 `fpsort` is the floating-point sort.
9940 If `ctx=None`, then the global context is used.
9942 >>> x = FP('x', FPSort(8, 24))
9949 >>> word = FPSort(8, 24)
9950 >>> x2 = FP('x', word)
9954 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9961 def FPs(names, fpsort, ctx=None):
9962 """Return an array of floating-point constants.
9964 >>> x, y, z = FPs('x y z', FPSort(8, 24))
9971 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9972 fpMul(RNE(), fpAdd(RNE(), x, y), z)
9975 if isinstance(names, str):
9976 names = names.split(
" ")
9977 return [
FP(name, fpsort, ctx)
for name
in names]
9981 """Create a Z3 floating-point absolute value expression.
9983 >>> s = FPSort(8, 24)
9985 >>> x = FPVal(1.0, s)
9988 >>> y = FPVal(-20.0, s)
9993 >>> fpAbs(-1.25*(2**4))
9999 [a] = _coerce_fp_expr_list([a], ctx)
10004 """Create a Z3 floating-point addition expression.
10006 >>> s = FPSort(8, 24)
10011 >>> fpNeg(x).sort()
10014 ctx = _get_ctx(ctx)
10015 [a] = _coerce_fp_expr_list([a], ctx)
10019 def _mk_fp_unary(f, rm, a, ctx):
10020 ctx = _get_ctx(ctx)
10021 [a] = _coerce_fp_expr_list([a], ctx)
10023 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10024 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
10025 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10028 def _mk_fp_unary_pred(f, a, ctx):
10029 ctx = _get_ctx(ctx)
10030 [a] = _coerce_fp_expr_list([a], ctx)
10032 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
10033 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10036 def _mk_fp_bin(f, rm, a, b, ctx):
10037 ctx = _get_ctx(ctx)
10038 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10040 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10041 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
10042 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10045 def _mk_fp_bin_norm(f, a, b, ctx):
10046 ctx = _get_ctx(ctx)
10047 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10049 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10050 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10053 def _mk_fp_bin_pred(f, a, b, ctx):
10054 ctx = _get_ctx(ctx)
10055 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10057 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10058 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10061 def _mk_fp_tern(f, rm, a, b, c, ctx):
10062 ctx = _get_ctx(ctx)
10063 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10065 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10067 c),
"Second, third or fourth argument must be a Z3 floating-point expression")
10068 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10072 """Create a Z3 floating-point addition expression.
10074 >>> s = FPSort(8, 24)
10078 >>> fpAdd(rm, x, y)
10080 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10082 >>> fpAdd(rm, x, y).sort()
10085 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10089 """Create a Z3 floating-point subtraction expression.
10091 >>> s = FPSort(8, 24)
10095 >>> fpSub(rm, x, y)
10097 >>> fpSub(rm, x, y).sort()
10100 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10104 """Create a Z3 floating-point multiplication expression.
10106 >>> s = FPSort(8, 24)
10110 >>> fpMul(rm, x, y)
10112 >>> fpMul(rm, x, y).sort()
10115 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10119 """Create a Z3 floating-point division expression.
10121 >>> s = FPSort(8, 24)
10125 >>> fpDiv(rm, x, y)
10127 >>> fpDiv(rm, x, y).sort()
10130 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10134 """Create a Z3 floating-point remainder expression.
10136 >>> s = FPSort(8, 24)
10141 >>> fpRem(x, y).sort()
10144 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10148 """Create a Z3 floating-point minimum expression.
10150 >>> s = FPSort(8, 24)
10156 >>> fpMin(x, y).sort()
10159 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10163 """Create a Z3 floating-point maximum expression.
10165 >>> s = FPSort(8, 24)
10171 >>> fpMax(x, y).sort()
10174 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10178 """Create a Z3 floating-point fused multiply-add expression.
10180 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10184 """Create a Z3 floating-point square root expression.
10186 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10190 """Create a Z3 floating-point roundToIntegral expression.
10192 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10196 """Create a Z3 floating-point isNaN expression.
10198 >>> s = FPSort(8, 24)
10204 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10208 """Create a Z3 floating-point isInfinite expression.
10210 >>> s = FPSort(8, 24)
10215 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10219 """Create a Z3 floating-point isZero expression.
10221 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10225 """Create a Z3 floating-point isNormal expression.
10227 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10231 """Create a Z3 floating-point isSubnormal expression.
10233 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10237 """Create a Z3 floating-point isNegative expression.
10239 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10243 """Create a Z3 floating-point isPositive expression.
10245 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10248 def _check_fp_args(a, b):
10250 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10254 """Create the Z3 floating-point expression `other < self`.
10256 >>> x, y = FPs('x y', FPSort(8, 24))
10259 >>> (x < y).sexpr()
10262 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10266 """Create the Z3 floating-point expression `other <= self`.
10268 >>> x, y = FPs('x y', FPSort(8, 24))
10271 >>> (x <= y).sexpr()
10274 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10278 """Create the Z3 floating-point expression `other > self`.
10280 >>> x, y = FPs('x y', FPSort(8, 24))
10283 >>> (x > y).sexpr()
10286 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10290 """Create the Z3 floating-point expression `other >= self`.
10292 >>> x, y = FPs('x y', FPSort(8, 24))
10295 >>> (x >= y).sexpr()
10298 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10302 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10304 >>> x, y = FPs('x y', FPSort(8, 24))
10307 >>> fpEQ(x, y).sexpr()
10310 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10314 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10316 >>> x, y = FPs('x y', FPSort(8, 24))
10319 >>> (x != y).sexpr()
10326 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10328 >>> s = FPSort(8, 24)
10329 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10331 fpFP(1, 127, 4194304)
10332 >>> xv = FPVal(-1.5, s)
10335 >>> slvr = Solver()
10336 >>> slvr.add(fpEQ(x, xv))
10339 >>> xv = FPVal(+1.5, s)
10342 >>> slvr = Solver()
10343 >>> slvr.add(fpEQ(x, xv))
10347 _z3_assert(
is_bv(sgn)
and is_bv(exp)
and is_bv(sig),
"sort mismatch")
10348 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
10349 ctx = _get_ctx(ctx)
10350 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
10355 """Create a Z3 floating-point conversion expression from other term sorts
10358 From a bit-vector term in IEEE 754-2008 format:
10359 >>> x = FPVal(1.0, Float32())
10360 >>> x_bv = fpToIEEEBV(x)
10361 >>> simplify(fpToFP(x_bv, Float32()))
10364 From a floating-point term with different precision:
10365 >>> x = FPVal(1.0, Float32())
10366 >>> x_db = fpToFP(RNE(), x, Float64())
10371 >>> x_r = RealVal(1.5)
10372 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10375 From a signed bit-vector term:
10376 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10377 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10380 ctx = _get_ctx(ctx)
10390 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
10394 """Create a Z3 floating-point conversion expression that represents the
10395 conversion from a bit-vector term to a floating-point term.
10397 >>> x_bv = BitVecVal(0x3F800000, 32)
10398 >>> x_fp = fpBVToFP(x_bv, Float32())
10404 _z3_assert(
is_bv(v),
"First argument must be a Z3 bit-vector expression")
10405 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
10406 ctx = _get_ctx(ctx)
10411 """Create a Z3 floating-point conversion expression that represents the
10412 conversion from a floating-point term to a floating-point term of different precision.
10414 >>> x_sgl = FPVal(1.0, Float32())
10415 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10418 >>> simplify(x_dbl)
10423 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10424 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
10425 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10426 ctx = _get_ctx(ctx)
10431 """Create a Z3 floating-point conversion expression that represents the
10432 conversion from a real term to a floating-point term.
10434 >>> x_r = RealVal(1.5)
10435 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10441 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10442 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
10443 _z3_assert(
is_fp_sort(sort),
"Third 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 signed bit-vector term (encoding an integer) to a floating-point term.
10452 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10453 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10455 fpToFP(RNE(), 4294967291)
10459 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10460 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10461 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10462 ctx = _get_ctx(ctx)
10467 """Create a Z3 floating-point conversion expression that represents the
10468 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10470 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10471 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10473 fpToFPUnsigned(RNE(), 4294967291)
10477 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10478 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10479 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10480 ctx = _get_ctx(ctx)
10485 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10487 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10488 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
10489 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
10490 ctx = _get_ctx(ctx)
10495 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10497 >>> x = FP('x', FPSort(8, 24))
10498 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10499 >>> print(is_fp(x))
10501 >>> print(is_bv(y))
10503 >>> print(is_fp(y))
10505 >>> print(is_bv(x))
10509 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10510 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10511 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10512 ctx = _get_ctx(ctx)
10517 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10519 >>> x = FP('x', FPSort(8, 24))
10520 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10521 >>> print(is_fp(x))
10523 >>> print(is_bv(y))
10525 >>> print(is_fp(y))
10527 >>> print(is_bv(x))
10531 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10532 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10533 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10534 ctx = _get_ctx(ctx)
10539 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10541 >>> x = FP('x', FPSort(8, 24))
10542 >>> y = fpToReal(x)
10543 >>> print(is_fp(x))
10545 >>> print(is_real(y))
10547 >>> print(is_fp(y))
10549 >>> print(is_real(x))
10553 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10554 ctx = _get_ctx(ctx)
10559 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10561 The size of the resulting bit-vector is automatically determined.
10563 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10564 knows only one NaN and it will always produce the same bit-vector representation of
10567 >>> x = FP('x', FPSort(8, 24))
10568 >>> y = fpToIEEEBV(x)
10569 >>> print(is_fp(x))
10571 >>> print(is_bv(y))
10573 >>> print(is_fp(y))
10575 >>> print(is_bv(x))
10579 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10580 ctx = _get_ctx(ctx)
10591 """Sequence sort."""
10594 """Determine if sort is a string
10595 >>> s = StringSort()
10598 >>> s = SeqSort(IntSort())
10608 """Character sort."""
10612 """Create a string sort
10613 >>> s = StringSort()
10617 ctx = _get_ctx(ctx)
10621 """Create a character sort
10622 >>> ch = CharSort()
10626 ctx = _get_ctx(ctx)
10631 """Create a sequence sort over elements provided in the argument
10632 >>> s = SeqSort(IntSort())
10633 >>> s == Unit(IntVal(1)).sort()
10640 """Sequence expression."""
10646 return Concat(self, other)
10649 return Concat(other, self)
10668 """Return a string representation of sequence expression."""
10670 string_length = ctypes.c_uint()
10672 return string_at(chars, size=string_length.value).decode(
"latin-1")
10688 def _coerce_char(ch, ctx=None):
10689 if isinstance(ch, str):
10690 ctx = _get_ctx(ctx)
10693 raise Z3Exception(
"Character expression expected")
10697 """Character expression."""
10700 other = _coerce_char(other, self.
ctxctx)
10714 ctx = _get_ctx(ctx)
10715 if isinstance(ch, str):
10717 if not isinstance(ch, int):
10718 raise Z3Exception(
"character value should be an ordinal")
10719 return _to_expr_ref(
Z3_mk_char(ctx.ref(), ch), ctx)
10723 raise Z3Expression(
"Bit-vector expression needed")
10727 ch = _coerce_char(ch, ctx)
10731 ch = _coerce_char(ch, ctx)
10735 ch = _coerce_char(ch, ctx)
10736 return ch.is_digit()
10738 def _coerce_seq(s, ctx=None):
10739 if isinstance(s, str):
10740 ctx = _get_ctx(ctx)
10743 raise Z3Exception(
"Non-expression passed as a sequence")
10745 raise Z3Exception(
"Non-sequence passed as a sequence")
10749 def _get_ctx2(a, b, ctx=None):
10760 """Return `True` if `a` is a Z3 sequence expression.
10761 >>> print (is_seq(Unit(IntVal(0))))
10763 >>> print (is_seq(StringVal("abc")))
10766 return isinstance(a, SeqRef)
10770 """Return `True` if `a` is a Z3 string expression.
10771 >>> print (is_string(StringVal("ab")))
10774 return isinstance(a, SeqRef)
and a.is_string()
10778 """return 'True' if 'a' is a Z3 string constant expression.
10779 >>> print (is_string_value(StringVal("a")))
10781 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10784 return isinstance(a, SeqRef)
and a.is_string_value()
10787 """create a string expression"""
10788 s =
"".join(str(ch)
if 32 <= ord(ch)
and ord(ch) < 127
else "\\u{%x}" % (ord(ch))
for ch
in s)
10789 ctx = _get_ctx(ctx)
10794 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10796 >>> x = String('x')
10798 ctx = _get_ctx(ctx)
10803 """Return a tuple of String constants. """
10804 ctx = _get_ctx(ctx)
10805 if isinstance(names, str):
10806 names = names.split(
" ")
10807 return [
String(name, ctx)
for name
in names]
10811 """Extract substring or subsequence starting at offset"""
10812 return Extract(s, offset, length)
10816 """Extract substring or subsequence starting at offset"""
10817 return Extract(s, offset, length)
10821 """Create the empty sequence of the given sort
10822 >>> e = Empty(StringSort())
10823 >>> e2 = StringVal("")
10824 >>> print(e.eq(e2))
10826 >>> e3 = Empty(SeqSort(IntSort()))
10829 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10831 Empty(ReSort(Seq(Int)))
10833 if isinstance(s, SeqSortRef):
10835 if isinstance(s, ReSortRef):
10837 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10841 """Create the regular expression that accepts the universal language
10842 >>> e = Full(ReSort(SeqSort(IntSort())))
10844 Full(ReSort(Seq(Int)))
10845 >>> e1 = Full(ReSort(StringSort()))
10847 Full(ReSort(String))
10849 if isinstance(s, ReSortRef):
10851 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10856 """Create a singleton sequence"""
10861 """Check if 'a' is a prefix of 'b'
10862 >>> s1 = PrefixOf("ab", "abc")
10865 >>> s2 = PrefixOf("bc", "abc")
10869 ctx = _get_ctx2(a, b)
10870 a = _coerce_seq(a, ctx)
10871 b = _coerce_seq(b, ctx)
10876 """Check if 'a' is a suffix of 'b'
10877 >>> s1 = SuffixOf("ab", "abc")
10880 >>> s2 = SuffixOf("bc", "abc")
10884 ctx = _get_ctx2(a, b)
10885 a = _coerce_seq(a, ctx)
10886 b = _coerce_seq(b, ctx)
10891 """Check if 'a' contains 'b'
10892 >>> s1 = Contains("abc", "ab")
10895 >>> s2 = Contains("abc", "bc")
10898 >>> x, y, z = Strings('x y z')
10899 >>> s3 = Contains(Concat(x,y,z), y)
10903 ctx = _get_ctx2(a, b)
10904 a = _coerce_seq(a, ctx)
10905 b = _coerce_seq(b, ctx)
10910 """Replace the first occurrence of 'src' by 'dst' in 's'
10911 >>> r = Replace("aaa", "a", "b")
10915 ctx = _get_ctx2(dst, s)
10916 if ctx
is None and is_expr(src):
10918 src = _coerce_seq(src, ctx)
10919 dst = _coerce_seq(dst, ctx)
10920 s = _coerce_seq(s, ctx)
10925 """Retrieve the index of substring within a string starting at a specified offset.
10926 >>> simplify(IndexOf("abcabc", "bc", 0))
10928 >>> simplify(IndexOf("abcabc", "bc", 2))
10936 ctx = _get_ctx2(s, substr, ctx)
10937 s = _coerce_seq(s, ctx)
10938 substr = _coerce_seq(substr, ctx)
10939 if _is_int(offset):
10940 offset =
IntVal(offset, ctx)
10945 """Retrieve the last index of substring within a string"""
10947 ctx = _get_ctx2(s, substr, ctx)
10948 s = _coerce_seq(s, ctx)
10949 substr = _coerce_seq(substr, ctx)
10954 """Obtain the length of a sequence 's'
10955 >>> l = Length(StringVal("abc"))
10964 """Convert string expression to integer
10965 >>> a = StrToInt("1")
10966 >>> simplify(1 == a)
10968 >>> b = StrToInt("2")
10969 >>> simplify(1 == b)
10971 >>> c = StrToInt(IntToStr(2))
10972 >>> simplify(1 == c)
10980 """Convert integer expression to string"""
10987 """Convert a unit length string to integer code"""
10993 """Convert code to a string"""
10999 """The regular expression that accepts sequence 's'
11001 >>> s2 = Re(StringVal("ab"))
11002 >>> s3 = Re(Unit(BoolVal(True)))
11004 s = _coerce_seq(s, ctx)
11011 """Regular expression sort."""
11020 if s
is None or isinstance(s, Context):
11023 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
11027 """Regular expressions."""
11030 return Union(self, other)
11034 return isinstance(s, ReRef)
11038 """Create regular expression membership test
11039 >>> re = Union(Re("a"),Re("b"))
11040 >>> print (simplify(InRe("a", re)))
11042 >>> print (simplify(InRe("b", re)))
11044 >>> print (simplify(InRe("c", re)))
11047 s = _coerce_seq(s, re.ctx)
11052 """Create union of regular expressions.
11053 >>> re = Union(Re("a"), Re("b"), Re("c"))
11054 >>> print (simplify(InRe("d", re)))
11057 args = _get_args(args)
11060 _z3_assert(sz > 0,
"At least one argument expected.")
11061 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
11066 for i
in range(sz):
11067 v[i] = args[i].as_ast()
11072 """Create intersection of regular expressions.
11073 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
11075 args = _get_args(args)
11078 _z3_assert(sz > 0,
"At least one argument expected.")
11079 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
11084 for i
in range(sz):
11085 v[i] = args[i].as_ast()
11090 """Create the regular expression accepting one or more repetitions of argument.
11091 >>> re = Plus(Re("a"))
11092 >>> print(simplify(InRe("aa", re)))
11094 >>> print(simplify(InRe("ab", re)))
11096 >>> print(simplify(InRe("", re)))
11103 """Create the regular expression that optionally accepts the argument.
11104 >>> re = Option(Re("a"))
11105 >>> print(simplify(InRe("a", re)))
11107 >>> print(simplify(InRe("", re)))
11109 >>> print(simplify(InRe("aa", re)))
11116 """Create the complement regular expression."""
11121 """Create the regular expression accepting zero or more repetitions of argument.
11122 >>> re = Star(Re("a"))
11123 >>> print(simplify(InRe("aa", re)))
11125 >>> print(simplify(InRe("ab", re)))
11127 >>> print(simplify(InRe("", re)))
11134 """Create the regular expression accepting between a lower and upper bound repetitions
11135 >>> re = Loop(Re("a"), 1, 3)
11136 >>> print(simplify(InRe("aa", re)))
11138 >>> print(simplify(InRe("aaaa", re)))
11140 >>> print(simplify(InRe("", re)))
11147 """Create the range regular expression over two sequences of length 1
11148 >>> range = Range("a","z")
11149 >>> print(simplify(InRe("b", range)))
11151 >>> print(simplify(InRe("bb", range)))
11154 lo = _coerce_seq(lo, ctx)
11155 hi = _coerce_seq(hi, ctx)
11159 """Create the difference regular epression
11164 """Create a regular expression that accepts all single character strings
11188 """Given a binary relation R, such that the two arguments have the same sort
11189 create the transitive closure relation R+.
11190 The transitive closure R+ is a new relation.
11201 if self.
locklock
is None:
11203 self.
locklock = threading.Lock()
11207 with self.
locklock:
11208 r = self.
basesbases[ctx]
11210 r = self.
basesbases[ctx]
11215 with self.
locklock:
11216 self.
basesbases[ctx] = r
11218 self.
basesbases[ctx] = r
11222 with self.
locklock:
11223 id = len(self.
basesbases) + 3
11224 self.
basesbases[id] = r
11226 id = len(self.
basesbases) + 3
11227 self.
basesbases[id] = r
11231 _prop_closures =
None
11235 global _prop_closures
11236 if _prop_closures
is None:
11241 _prop_closures.get(ctx).push()
11245 _prop_closures.get(ctx).pop(num_scopes)
11249 _prop_closures.set_threaded()
11250 prop = _prop_closures.get(id)
11251 new_prop = prop.fresh()
11252 _prop_closures.set(new_prop.id, new_prop)
11253 return ctypes.c_void_p(new_prop.id)
11257 super(ctypes.c_void_p, ast).__init__(ptr)
11261 prop = _prop_closures.get(ctx)
11263 id = _to_expr_ref(
to_Ast(id), prop.ctx())
11264 value = _to_expr_ref(
to_Ast(value), prop.ctx())
11265 prop.fixed(id, value)
11269 prop = _prop_closures.get(ctx)
11275 prop = _prop_closures.get(ctx)
11277 x = _to_expr_ref(
to_Ast(x), prop.ctx())
11278 y = _to_expr_ref(
to_Ast(y), prop.ctx())
11283 prop = _prop_closures.get(ctx)
11285 x = _to_expr_ref(
to_Ast(x), prop.ctx())
11286 y = _to_expr_ref(
to_Ast(y), prop.ctx())
11291 _user_prop_push = push_eh_type(user_prop_push)
11292 _user_prop_pop = pop_eh_type(user_prop_pop)
11293 _user_prop_fresh = fresh_eh_type(user_prop_fresh)
11294 _user_prop_fixed = fixed_eh_type(user_prop_fixed)
11295 _user_prop_final = final_eh_type(user_prop_final)
11296 _user_prop_eq = eq_eh_type(user_prop_eq)
11297 _user_prop_diseq = eq_eh_type(user_prop_diseq)
11310 assert s
is None or ctx
is None
11313 self.
_ctx_ctx =
None
11315 self.
idid = _prop_closures.insert(self)
11330 ctypes.c_void_p(self.
idid),
11337 self.
_ctx_ctx.ctx =
None
11341 return self.
_ctx_ctx
11343 return self.
solversolver.ctx
11346 return self.
ctxctx().ref()
11349 assert not self.
fixedfixed
11350 assert not self.
_ctx_ctx
11352 self.
fixedfixed = fixed
11355 assert not self.
finalfinal
11356 assert not self.
_ctx_ctx
11358 self.
finalfinal = final
11361 assert not self.
eqeq
11362 assert not self.
_ctx_ctx
11367 assert not self.
diseqdiseq
11368 assert not self.
_ctx_ctx
11370 self.
diseqdiseq = diseq
11373 raise Z3Exception(
"push needs to be overwritten")
11376 raise Z3Exception(
"pop needs to be overwritten")
11379 raise Z3Exception(
"fresh needs to be overwritten")
11382 assert self.
solversolver
11383 assert not self.
_ctx_ctx
11390 _ids, num_fixed = _to_ast_array(ids)
11392 _lhs, _num_lhs = _to_ast_array([x
for x, y
in eqs])
11393 _rhs, _num_rhs = _to_ast_array([y
for x, y
in eqs])
11395 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_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 first occurrence of substr in s starting from offset offset. If s does not contain su...
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 the last occurrence of substr in s. If s does not contain substr, then the value is -1,...
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...
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 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 solve(*args, **keywords)
def CharFromBv(ch, ctx=None)
def FloatSingle(ctx=None)
def user_prop_pop(ctx, num_scopes)
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)