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.
15 Several online tutorials for Z3Py are available at:
16 http://rise4fun.com/Z3Py/tutorial/guide
18 Please send feedback, comments and/or corrections on the Issue tracker for
19 https://github.com/Z3prover/z3.git. Your comments are very valuable.
40 ... x = BitVec('x', 32)
42 ... # the expression x + y is type incorrect
44 ... except Z3Exception as ex:
45 ... print("failed: %s" % ex)
50 from .z3types
import *
51 from .z3consts
import *
52 from .z3printer
import *
53 from fractions
import Fraction
58 if sys.version_info.major >= 3:
59 from typing
import Iterable
69 if sys.version_info.major < 3:
71 return isinstance(v, (int, long))
74 return isinstance(v, int)
86 major = ctypes.c_uint(0)
87 minor = ctypes.c_uint(0)
88 build = ctypes.c_uint(0)
89 rev = ctypes.c_uint(0)
91 return "%s.%s.%s" % (major.value, minor.value, build.value)
95 major = ctypes.c_uint(0)
96 minor = ctypes.c_uint(0)
97 build = ctypes.c_uint(0)
98 rev = ctypes.c_uint(0)
100 return (major.value, minor.value, build.value, rev.value)
110 def _z3_assert(cond, msg):
112 raise Z3Exception(msg)
115 def _z3_check_cint_overflow(n, name):
116 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
120 """Log interaction to a file. This function must be invoked immediately after init(). """
125 """Append user-defined string to interaction log. """
130 """Convert an integer or string into a Z3 symbol."""
137 def _symbol2py(ctx, s):
138 """Convert a Z3 symbol back into a Python object. """
151 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
153 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
154 return [arg
for arg
in args[0]]
163 def _get_args_ast_list(args):
165 if isinstance(args, (set, AstVector, tuple)):
166 return [arg
for arg
in args]
173 def _to_param_value(val):
174 if isinstance(val, bool):
175 return "true" if val
else "false"
186 """A Context manages all other Z3 objects, global configuration options, etc.
188 Z3Py uses a default global context. For most applications this is sufficient.
189 An application may use multiple Z3 contexts. Objects created in one context
190 cannot be used in another one. However, several objects may be "translated" from
191 one context to another. It is not safe to access Z3 objects from multiple threads.
192 The only exception is the method `interrupt()` that can be used to interrupt() a long
194 The initialization method receives global configuration options for the new context.
199 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
222 """Return a reference to the actual C pointer to the Z3 context."""
226 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
228 This method can be invoked from a thread different from the one executing the
229 interruptible procedure.
239 """Return a reference to the global Z3 context.
242 >>> x.ctx == main_ctx()
247 >>> x2 = Real('x', c)
254 if _main_ctx
is None:
271 """Set Z3 global (or module) parameters.
273 >>> set_param(precision=10)
276 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
280 if not set_pp_option(k, v):
295 """Reset all global (or module) parameters.
301 """Alias for 'set_param' for backward compatibility.
307 """Return the value of a Z3 global (or module) parameter
309 >>> get_param('nlsat.reorder')
312 ptr = (ctypes.c_char_p * 1)()
314 r = z3core._to_pystr(ptr[0])
316 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
328 """Superclass for all Z3 objects that have support for pretty printing."""
333 def _repr_html_(self):
334 in_html = in_html_mode()
337 set_html_mode(in_html)
342 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
346 self.
ctxctx = _get_ctx(ctx)
350 if self.
ctxctx.ref()
is not None and self.
astast
is not None:
355 return _to_ast_ref(self.
astast, self.
ctxctx)
358 return obj_to_string(self)
361 return obj_to_string(self)
364 return self.
eqeq(other)
367 return self.
hashhash()
377 elif is_eq(self)
and self.num_args() == 2:
378 return self.arg(0).
eq(self.arg(1))
380 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
383 """Return a string representing the AST node in s-expression notation.
386 >>> ((x + 1)*x).sexpr()
392 """Return a pointer to the corresponding C Z3_ast object."""
396 """Return unique identifier for object. It can be used for hash-tables and maps."""
400 """Return a reference to the C context where this AST node is stored."""
401 return self.
ctxctx.ref()
404 """Return `True` if `self` and `other` are structurally identical.
411 >>> n1 = simplify(n1)
412 >>> n2 = simplify(n2)
417 _z3_assert(
is_ast(other),
"Z3 AST expected")
421 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
427 >>> # Nodes in different contexts can't be mixed.
428 >>> # However, we can translate nodes from one context to another.
429 >>> x.translate(c2) + y
433 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
440 """Return a hashcode for the `self`.
442 >>> n1 = simplify(Int('x') + 1)
443 >>> n2 = simplify(2 + Int('x') - 1)
444 >>> n1.hash() == n2.hash()
451 """Return `True` if `a` is an AST node.
455 >>> is_ast(IntVal(10))
459 >>> is_ast(BoolSort())
461 >>> is_ast(Function('f', IntSort(), IntSort()))
468 return isinstance(a, AstRef)
472 """Return `True` if `a` and `b` are structurally identical AST nodes.
482 >>> eq(simplify(x + 1), simplify(1 + x))
490 def _ast_kind(ctx, a):
496 def _ctx_from_ast_arg_list(args, default_ctx=None):
504 _z3_assert(ctx == a.ctx,
"Context mismatch")
510 def _ctx_from_ast_args(*args):
511 return _ctx_from_ast_arg_list(args)
514 def _to_func_decl_array(args):
516 _args = (FuncDecl * sz)()
518 _args[i] = args[i].as_func_decl()
522 def _to_ast_array(args):
526 _args[i] = args[i].as_ast()
530 def _to_ref_array(ref, args):
534 _args[i] = args[i].as_ast()
538 def _to_ast_ref(a, ctx):
539 k = _ast_kind(ctx, a)
541 return _to_sort_ref(a, ctx)
542 elif k == Z3_FUNC_DECL_AST:
543 return _to_func_decl_ref(a, ctx)
545 return _to_expr_ref(a, ctx)
554 def _sort_kind(ctx, s):
559 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
568 """Return the Z3 internal kind of a sort.
569 This method can be used to test if `self` is one of the Z3 builtin sorts.
572 >>> b.kind() == Z3_BOOL_SORT
574 >>> b.kind() == Z3_INT_SORT
576 >>> A = ArraySort(IntSort(), IntSort())
577 >>> A.kind() == Z3_ARRAY_SORT
579 >>> A.kind() == Z3_INT_SORT
582 return _sort_kind(self.
ctxctx, self.
astast)
585 """Return `True` if `self` is a subsort of `other`.
587 >>> IntSort().subsort(RealSort())
593 """Try to cast `val` as an element of sort `self`.
595 This method is used in Z3Py to convert Python objects such as integers,
596 floats, longs and strings into Z3 expressions.
599 >>> RealSort().cast(x)
603 _z3_assert(
is_expr(val),
"Z3 expression expected")
604 _z3_assert(self.
eqeq(val.sort()),
"Sort mismatch")
608 """Return the name (string) of sort `self`.
610 >>> BoolSort().name()
612 >>> ArraySort(IntSort(), IntSort()).name()
618 """Return `True` if `self` and `other` are the same Z3 sort.
621 >>> p.sort() == BoolSort()
623 >>> p.sort() == IntSort()
631 """Return `True` if `self` and `other` are not the same Z3 sort.
634 >>> p.sort() != BoolSort()
636 >>> p.sort() != IntSort()
643 return AstRef.__hash__(self)
647 """Return `True` if `s` is a Z3 sort.
649 >>> is_sort(IntSort())
651 >>> is_sort(Int('x'))
653 >>> is_expr(Int('x'))
656 return isinstance(s, SortRef)
659 def _to_sort_ref(s, ctx):
661 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
662 k = _sort_kind(ctx, s)
663 if k == Z3_BOOL_SORT:
665 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
667 elif k == Z3_BV_SORT:
669 elif k == Z3_ARRAY_SORT:
671 elif k == Z3_DATATYPE_SORT:
673 elif k == Z3_FINITE_DOMAIN_SORT:
675 elif k == Z3_FLOATING_POINT_SORT:
677 elif k == Z3_ROUNDING_MODE_SORT:
679 elif k == Z3_RE_SORT:
681 elif k == Z3_SEQ_SORT:
683 elif k == Z3_CHAR_SORT:
689 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
693 """Create a new uninterpreted sort named `name`.
695 If `ctx=None`, then the new sort is declared in the global Z3Py context.
697 >>> A = DeclareSort('A')
698 >>> a = Const('a', A)
699 >>> b = Const('b', A)
718 """Function declaration. Every constant and function have an associated declaration.
720 The declaration assigns a name, a sort (i.e., type), and for function
721 the sort (i.e., type) of each of its arguments. Note that, in Z3,
722 a constant is a function with 0 arguments.
735 """Return the name of the function declaration `self`.
737 >>> f = Function('f', IntSort(), IntSort())
740 >>> isinstance(f.name(), str)
746 """Return the number of arguments of a function declaration.
747 If `self` is a constant, then `self.arity()` is 0.
749 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
756 """Return the sort of the argument `i` of a function declaration.
757 This method assumes that `0 <= i < self.arity()`.
759 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
766 _z3_assert(i < self.
arityarity(),
"Index out of bounds")
770 """Return the sort of the range of a function declaration.
771 For constants, this is the sort of the constant.
773 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
780 """Return the internal kind of a function declaration.
781 It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
784 >>> d = (x + 1).decl()
785 >>> d.kind() == Z3_OP_ADD
787 >>> d.kind() == Z3_OP_MUL
795 result = [
None for i
in range(n)]
798 if k == Z3_PARAMETER_INT:
800 elif k == Z3_PARAMETER_DOUBLE:
802 elif k == Z3_PARAMETER_RATIONAL:
804 elif k == Z3_PARAMETER_SYMBOL:
806 elif k == Z3_PARAMETER_SORT:
808 elif k == Z3_PARAMETER_AST:
810 elif k == Z3_PARAMETER_FUNC_DECL:
817 """Create a Z3 application expression using the function `self`, and the given arguments.
819 The arguments must be Z3 expressions. This method assumes that
820 the sorts of the elements in `args` match the sorts of the
821 domain. Limited coercion is supported. For example, if
822 args[0] is a Python integer, and the function expects a Z3
823 integer, then the argument is automatically converted into a
826 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
834 args = _get_args(args)
837 _z3_assert(num == self.
arityarity(),
"Incorrect number of arguments to %s" % self)
838 _args = (Ast * num)()
843 tmp = self.
domaindomain(i).cast(args[i])
845 _args[i] = tmp.as_ast()
850 """Return `True` if `a` is a Z3 function declaration.
852 >>> f = Function('f', IntSort(), IntSort())
859 return isinstance(a, FuncDeclRef)
863 """Create a new Z3 uninterpreted function with the given sorts.
865 >>> f = Function('f', IntSort(), IntSort())
871 _z3_assert(len(sig) > 0,
"At least two arguments expected")
875 _z3_assert(
is_sort(rng),
"Z3 sort expected")
876 dom = (Sort * arity)()
877 for i
in range(arity):
879 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
886 """Create a new fresh Z3 uninterpreted function with the given sorts.
890 _z3_assert(len(sig) > 0,
"At least two arguments expected")
894 _z3_assert(
is_sort(rng),
"Z3 sort expected")
895 dom = (z3.Sort * arity)()
896 for i
in range(arity):
898 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
904 def _to_func_decl_ref(a, ctx):
909 """Create a new Z3 recursive with the given sorts."""
912 _z3_assert(len(sig) > 0,
"At least two arguments expected")
916 _z3_assert(
is_sort(rng),
"Z3 sort expected")
917 dom = (Sort * arity)()
918 for i
in range(arity):
920 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
927 """Set the body of a recursive function.
928 Recursive definitions can be simplified if they are applied to ground
931 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
932 >>> n = Int('n', ctx)
933 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
936 >>> s = Solver(ctx=ctx)
937 >>> s.add(fac(n) < 3)
940 >>> s.model().eval(fac(5))
946 args = _get_args(args)
950 _args[i] = args[i].ast
961 """Constraints, formulas and terms are expressions in Z3.
963 Expressions are ASTs. Every expression has a sort.
964 There are three main kinds of expressions:
965 function applications, quantifiers and bounded variables.
966 A constant is a function application with 0 arguments.
967 For quantifier free problems, all expressions are
968 function applications.
978 """Return the sort of expression `self`.
990 """Shorthand for `self.sort().kind()`.
992 >>> a = Array('a', IntSort(), IntSort())
993 >>> a.sort_kind() == Z3_ARRAY_SORT
995 >>> a.sort_kind() == Z3_INT_SORT
998 return self.
sortsort().kind()
1001 """Return a Z3 expression that represents the constraint `self == other`.
1003 If `other` is `None`, then this method simply returns `False`.
1014 a, b = _coerce_exprs(self, other)
1019 return AstRef.__hash__(self)
1022 """Return a Z3 expression that represents the constraint `self != other`.
1024 If `other` is `None`, then this method simply returns `True`.
1035 a, b = _coerce_exprs(self, other)
1036 _args, sz = _to_ast_array((a, b))
1043 """Return the Z3 function declaration associated with a Z3 application.
1045 >>> f = Function('f', IntSort(), IntSort())
1054 _z3_assert(
is_app(self),
"Z3 application expected")
1058 """Return the number of arguments of a Z3 application.
1062 >>> (a + b).num_args()
1064 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1070 _z3_assert(
is_app(self),
"Z3 application expected")
1074 """Return argument `idx` of the application `self`.
1076 This method assumes that `self` is a function application with at least `idx+1` arguments.
1080 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1090 _z3_assert(
is_app(self),
"Z3 application expected")
1091 _z3_assert(idx < self.
num_argsnum_args(),
"Invalid argument index")
1095 """Return a list containing the children of the given expression
1099 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1110 def _to_expr_ref(a, ctx):
1111 if isinstance(a, Pattern):
1115 if k == Z3_QUANTIFIER_AST:
1118 if sk == Z3_BOOL_SORT:
1120 if sk == Z3_INT_SORT:
1121 if k == Z3_NUMERAL_AST:
1124 if sk == Z3_REAL_SORT:
1125 if k == Z3_NUMERAL_AST:
1127 if _is_algebraic(ctx, a):
1130 if sk == Z3_BV_SORT:
1131 if k == Z3_NUMERAL_AST:
1135 if sk == Z3_ARRAY_SORT:
1137 if sk == Z3_DATATYPE_SORT:
1139 if sk == Z3_FLOATING_POINT_SORT:
1140 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1143 return FPRef(a, ctx)
1144 if sk == Z3_FINITE_DOMAIN_SORT:
1145 if k == Z3_NUMERAL_AST:
1149 if sk == Z3_ROUNDING_MODE_SORT:
1151 if sk == Z3_SEQ_SORT:
1153 if sk == Z3_RE_SORT:
1154 return ReRef(a, ctx)
1158 def _coerce_expr_merge(s, a):
1171 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1172 _z3_assert(
False,
"sort mismatch")
1177 def _coerce_exprs(a, b, ctx=None):
1179 a = _py2expr(a, ctx)
1180 b = _py2expr(b, ctx)
1181 if isinstance(a, str)
and isinstance(b, SeqRef):
1183 if isinstance(b, str)
and isinstance(a, SeqRef):
1186 s = _coerce_expr_merge(s, a)
1187 s = _coerce_expr_merge(s, b)
1193 def _reduce(func, sequence, initial):
1195 for element
in sequence:
1196 result = func(result, element)
1200 def _coerce_expr_list(alist, ctx=None):
1207 alist = [_py2expr(a, ctx)
for a
in alist]
1208 s = _reduce(_coerce_expr_merge, alist,
None)
1209 return [s.cast(a)
for a
in alist]
1213 """Return `True` if `a` is a Z3 expression.
1220 >>> is_expr(IntSort())
1224 >>> is_expr(IntVal(1))
1227 >>> is_expr(ForAll(x, x >= 0))
1229 >>> is_expr(FPVal(1.0))
1232 return isinstance(a, ExprRef)
1236 """Return `True` if `a` is a Z3 function application.
1238 Note that, constants are function applications with 0 arguments.
1245 >>> is_app(IntSort())
1249 >>> is_app(IntVal(1))
1252 >>> is_app(ForAll(x, x >= 0))
1255 if not isinstance(a, ExprRef):
1257 k = _ast_kind(a.ctx, a)
1258 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1262 """Return `True` if `a` is Z3 constant/variable expression.
1271 >>> is_const(IntVal(1))
1274 >>> is_const(ForAll(x, x >= 0))
1277 return is_app(a)
and a.num_args() == 0
1281 """Return `True` if `a` is variable.
1283 Z3 uses de-Bruijn indices for representing bound variables in
1291 >>> f = Function('f', IntSort(), IntSort())
1292 >>> # Z3 replaces x with bound variables when ForAll is executed.
1293 >>> q = ForAll(x, f(x) == x)
1299 >>> is_var(b.arg(1))
1302 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1306 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1314 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1315 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1316 >>> q = ForAll([x, y], f(x, y) == x + y)
1318 f(Var(1), Var(0)) == Var(1) + Var(0)
1322 >>> v1 = b.arg(0).arg(0)
1323 >>> v2 = b.arg(0).arg(1)
1328 >>> get_var_index(v1)
1330 >>> get_var_index(v2)
1334 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1339 """Return `True` if `a` is an application of the given kind `k`.
1343 >>> is_app_of(n, Z3_OP_ADD)
1345 >>> is_app_of(n, Z3_OP_MUL)
1348 return is_app(a)
and a.decl().kind() == k
1351 def If(a, b, c, ctx=None):
1352 """Create a Z3 if-then-else expression.
1356 >>> max = If(x > y, x, y)
1362 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1363 return Cond(a, b, c, ctx)
1365 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1368 b, c = _coerce_exprs(b, c, ctx)
1370 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1371 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1375 """Create a Z3 distinct expression.
1382 >>> Distinct(x, y, z)
1384 >>> simplify(Distinct(x, y, z))
1386 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1387 And(Not(x == y), Not(x == z), Not(y == z))
1389 args = _get_args(args)
1390 ctx = _ctx_from_ast_arg_list(args)
1392 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1393 args = _coerce_expr_list(args, ctx)
1394 _args, sz = _to_ast_array(args)
1398 def _mk_bin(f, a, b):
1401 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1402 args[0] = a.as_ast()
1403 args[1] = b.as_ast()
1404 return f(a.ctx.ref(), 2, args)
1408 """Create a constant of the given sort.
1410 >>> Const('x', IntSort())
1414 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1420 """Create several constants of the given sort.
1422 `names` is a string containing the names of all constants to be created.
1423 Blank spaces separate the names of different constants.
1425 >>> x, y, z = Consts('x y z', IntSort())
1429 if isinstance(names, str):
1430 names = names.split(
" ")
1431 return [
Const(name, sort)
for name
in names]
1435 """Create a fresh constant of a specified sort"""
1436 ctx = _get_ctx(sort.ctx)
1441 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1443 >>> Var(0, IntSort())
1445 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1449 _z3_assert(
is_sort(s),
"Z3 sort expected")
1450 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1455 Create a real free variable. Free variables are used to create quantified formulas.
1456 They are also used to create polynomials.
1466 Create a list of Real free variables.
1467 The variables have ids: 0, 1, ..., n-1
1469 >>> x0, x1, x2, x3 = RealVarVector(4)
1486 """Try to cast `val` as a Boolean.
1488 >>> x = BoolSort().cast(True)
1498 if isinstance(val, bool):
1502 msg =
"True, False or Z3 Boolean expression expected. Received %s of type %s"
1503 _z3_assert(
is_expr(val), msg % (val, type(val)))
1504 if not self.
eqeq(val.sort()):
1505 _z3_assert(self.
eqeq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1509 return isinstance(other, ArithSortRef)
1519 """All Boolean expressions are instances of this class."""
1528 """Create the Z3 expression `self * other`.
1534 return If(self, other, 0)
1538 """Return `True` if `a` is a Z3 Boolean expression.
1544 >>> is_bool(And(p, q))
1552 return isinstance(a, BoolRef)
1556 """Return `True` if `a` is the Z3 true expression.
1561 >>> is_true(simplify(p == p))
1566 >>> # True is a Python Boolean expression
1574 """Return `True` if `a` is the Z3 false expression.
1581 >>> is_false(BoolVal(False))
1588 """Return `True` if `a` is a Z3 and expression.
1590 >>> p, q = Bools('p q')
1591 >>> is_and(And(p, q))
1593 >>> is_and(Or(p, q))
1600 """Return `True` if `a` is a Z3 or expression.
1602 >>> p, q = Bools('p q')
1605 >>> is_or(And(p, q))
1612 """Return `True` if `a` is a Z3 implication expression.
1614 >>> p, q = Bools('p q')
1615 >>> is_implies(Implies(p, q))
1617 >>> is_implies(And(p, q))
1624 """Return `True` if `a` is a Z3 not expression.
1636 """Return `True` if `a` is a Z3 equality expression.
1638 >>> x, y = Ints('x y')
1646 """Return `True` if `a` is a Z3 distinct expression.
1648 >>> x, y, z = Ints('x y z')
1649 >>> is_distinct(x == y)
1651 >>> is_distinct(Distinct(x, y, z))
1658 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1662 >>> p = Const('p', BoolSort())
1665 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1668 >>> is_bool(r(0, 1))
1676 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1680 >>> is_true(BoolVal(True))
1684 >>> is_false(BoolVal(False))
1695 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1707 """Return a tuple of Boolean constants.
1709 `names` is a single string containing all names separated by blank spaces.
1710 If `ctx=None`, then the global context is used.
1712 >>> p, q, r = Bools('p q r')
1713 >>> And(p, Or(q, r))
1717 if isinstance(names, str):
1718 names = names.split(
" ")
1719 return [
Bool(name, ctx)
for name
in names]
1723 """Return a list of Boolean constants of size `sz`.
1725 The constants are named using the given prefix.
1726 If `ctx=None`, then the global context is used.
1728 >>> P = BoolVector('p', 3)
1732 And(p__0, p__1, p__2)
1734 return [
Bool(
"%s__%s" % (prefix, i))
for i
in range(sz)]
1738 """Return a fresh Boolean constant in the given context using the given prefix.
1740 If `ctx=None`, then the global context is used.
1742 >>> b1 = FreshBool()
1743 >>> b2 = FreshBool()
1752 """Create a Z3 implies expression.
1754 >>> p, q = Bools('p q')
1758 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1766 """Create a Z3 Xor expression.
1768 >>> p, q = Bools('p q')
1771 >>> simplify(Xor(p, q))
1774 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1782 """Create a Z3 not expression or probe.
1787 >>> simplify(Not(Not(p)))
1790 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1807 def _has_probe(args):
1808 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1816 """Create a Z3 and-expression or and-probe.
1818 >>> p, q, r = Bools('p q r')
1821 >>> P = BoolVector('p', 5)
1823 And(p__0, p__1, p__2, p__3, p__4)
1827 last_arg = args[len(args) - 1]
1828 if isinstance(last_arg, Context):
1829 ctx = args[len(args) - 1]
1830 args = args[:len(args) - 1]
1831 elif len(args) == 1
and isinstance(args[0], AstVector):
1833 args = [a
for a
in args[0]]
1836 args = _get_args(args)
1837 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1839 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1840 if _has_probe(args):
1841 return _probe_and(args, ctx)
1843 args = _coerce_expr_list(args, ctx)
1844 _args, sz = _to_ast_array(args)
1849 """Create a Z3 or-expression or or-probe.
1851 >>> p, q, r = Bools('p q r')
1854 >>> P = BoolVector('p', 5)
1856 Or(p__0, p__1, p__2, p__3, p__4)
1860 last_arg = args[len(args) - 1]
1861 if isinstance(last_arg, Context):
1862 ctx = args[len(args) - 1]
1863 args = args[:len(args) - 1]
1864 elif len(args) == 1
and isinstance(args[0], AstVector):
1866 args = [a
for a
in args[0]]
1869 args = _get_args(args)
1870 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1872 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1873 if _has_probe(args):
1874 return _probe_or(args, ctx)
1876 args = _coerce_expr_list(args, ctx)
1877 _args, sz = _to_ast_array(args)
1888 """Patterns are hints for quantifier instantiation.
1900 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1902 >>> f = Function('f', IntSort(), IntSort())
1904 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1906 ForAll(x, f(x) == 0)
1907 >>> q.num_patterns()
1909 >>> is_pattern(q.pattern(0))
1914 return isinstance(a, PatternRef)
1918 """Create a Z3 multi-pattern using the given expressions `*args`
1920 >>> f = Function('f', IntSort(), IntSort())
1921 >>> g = Function('g', IntSort(), IntSort())
1923 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1925 ForAll(x, f(x) != g(x))
1926 >>> q.num_patterns()
1928 >>> is_pattern(q.pattern(0))
1931 MultiPattern(f(Var(0)), g(Var(0)))
1934 _z3_assert(len(args) > 0,
"At least one argument expected")
1935 _z3_assert(all([
is_expr(a)
for a
in args]),
"Z3 expressions expected")
1937 args, sz = _to_ast_array(args)
1941 def _to_pattern(arg):
1955 """Universally and Existentially quantified formulas."""
1964 """Return the Boolean sort or sort of Lambda."""
1970 """Return `True` if `self` is a universal quantifier.
1972 >>> f = Function('f', IntSort(), IntSort())
1974 >>> q = ForAll(x, f(x) == 0)
1977 >>> q = Exists(x, f(x) != 0)
1984 """Return `True` if `self` is an existential quantifier.
1986 >>> f = Function('f', IntSort(), IntSort())
1988 >>> q = ForAll(x, f(x) == 0)
1991 >>> q = Exists(x, f(x) != 0)
1998 """Return `True` if `self` is a lambda expression.
2000 >>> f = Function('f', IntSort(), IntSort())
2002 >>> q = Lambda(x, f(x))
2005 >>> q = Exists(x, f(x) != 0)
2012 """Return the Z3 expression `self[arg]`.
2015 _z3_assert(self.
is_lambdais_lambda(),
"quantifier should be a lambda expression")
2020 """Return the weight annotation of `self`.
2022 >>> f = Function('f', IntSort(), IntSort())
2024 >>> q = ForAll(x, f(x) == 0)
2027 >>> q = ForAll(x, f(x) == 0, weight=10)
2034 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2036 >>> f = Function('f', IntSort(), IntSort())
2037 >>> g = Function('g', IntSort(), IntSort())
2039 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2040 >>> q.num_patterns()
2046 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2048 >>> f = Function('f', IntSort(), IntSort())
2049 >>> g = Function('g', IntSort(), IntSort())
2051 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2052 >>> q.num_patterns()
2060 _z3_assert(idx < self.
num_patternsnum_patterns(),
"Invalid pattern idx")
2064 """Return the number of no-patterns."""
2068 """Return a no-pattern."""
2070 _z3_assert(idx < self.
num_no_patternsnum_no_patterns(),
"Invalid no-pattern idx")
2074 """Return the expression being quantified.
2076 >>> f = Function('f', IntSort(), IntSort())
2078 >>> q = ForAll(x, f(x) == 0)
2085 """Return the number of variables bounded by this quantifier.
2087 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2090 >>> q = ForAll([x, y], f(x, y) >= x)
2097 """Return a string representing a name used when displaying the quantifier.
2099 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2102 >>> q = ForAll([x, y], f(x, y) >= x)
2109 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2113 """Return the sort of a bound variable.
2115 >>> f = Function('f', IntSort(), RealSort(), IntSort())
2118 >>> q = ForAll([x, y], f(x, y) >= x)
2125 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2129 """Return a list containing a single element self.body()
2131 >>> f = Function('f', IntSort(), IntSort())
2133 >>> q = ForAll(x, f(x) == 0)
2137 return [self.
bodybody()]
2141 """Return `True` if `a` is a Z3 quantifier.
2143 >>> f = Function('f', IntSort(), IntSort())
2145 >>> q = ForAll(x, f(x) == 0)
2146 >>> is_quantifier(q)
2148 >>> is_quantifier(f(x))
2151 return isinstance(a, QuantifierRef)
2154 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2156 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2157 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2158 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2159 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2170 _vs = (Ast * num_vars)()
2171 for i
in range(num_vars):
2173 _vs[i] = vs[i].as_ast()
2174 patterns = [_to_pattern(p)
for p
in patterns]
2175 num_pats = len(patterns)
2176 _pats = (Pattern * num_pats)()
2177 for i
in range(num_pats):
2178 _pats[i] = patterns[i].ast
2179 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2185 num_no_pats, _no_pats,
2186 body.as_ast()), ctx)
2189 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2190 """Create a Z3 forall formula.
2192 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2194 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2197 >>> ForAll([x, y], f(x, y) >= x)
2198 ForAll([x, y], f(x, y) >= x)
2199 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2200 ForAll([x, y], f(x, y) >= x)
2201 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2202 ForAll([x, y], f(x, y) >= x)
2204 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2207 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2208 """Create a Z3 exists formula.
2210 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2213 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2216 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2218 Exists([x, y], f(x, y) >= x)
2219 >>> is_quantifier(q)
2221 >>> r = Tactic('nnf')(q).as_expr()
2222 >>> is_quantifier(r)
2225 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2229 """Create a Z3 lambda expression.
2231 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2232 >>> mem0 = Array('mem0', IntSort(), IntSort())
2233 >>> lo, hi, e, i = Ints('lo hi e i')
2234 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2236 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2242 _vs = (Ast * num_vars)()
2243 for i
in range(num_vars):
2245 _vs[i] = vs[i].as_ast()
2256 """Real and Integer sorts."""
2259 """Return `True` if `self` is of the sort Real.
2264 >>> (x + 1).is_real()
2270 return self.
kindkind() == Z3_REAL_SORT
2273 """Return `True` if `self` is of the sort Integer.
2278 >>> (x + 1).is_int()
2284 return self.
kindkind() == Z3_INT_SORT
2287 """Return `True` if `self` is a subsort of `other`."""
2291 """Try to cast `val` as an Integer or Real.
2293 >>> IntSort().cast(10)
2295 >>> is_int(IntSort().cast(10))
2299 >>> RealSort().cast(10)
2301 >>> is_real(RealSort().cast(10))
2306 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
2308 if self.
eqeq(val_s):
2310 if val_s.is_int()
and self.
is_realis_real():
2312 if val_s.is_bool()
and self.
is_intis_int():
2313 return If(val, 1, 0)
2314 if val_s.is_bool()
and self.
is_realis_real():
2317 _z3_assert(
False,
"Z3 Integer/Real expression expected")
2324 msg =
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2325 _z3_assert(
False, msg % self)
2329 """Return `True` if s is an arithmetical sort (type).
2331 >>> is_arith_sort(IntSort())
2333 >>> is_arith_sort(RealSort())
2335 >>> is_arith_sort(BoolSort())
2337 >>> n = Int('x') + 1
2338 >>> is_arith_sort(n.sort())
2341 return isinstance(s, ArithSortRef)
2345 """Integer and Real expressions."""
2348 """Return the sort (type) of the arithmetical expression `self`.
2352 >>> (Real('x') + 1).sort()
2358 """Return `True` if `self` is an integer expression.
2363 >>> (x + 1).is_int()
2366 >>> (x + y).is_int()
2372 """Return `True` if `self` is an real expression.
2377 >>> (x + 1).is_real()
2383 """Create the Z3 expression `self + other`.
2392 a, b = _coerce_exprs(self, other)
2393 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctxctx)
2396 """Create the Z3 expression `other + self`.
2402 a, b = _coerce_exprs(self, other)
2403 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctxctx)
2406 """Create the Z3 expression `self * other`.
2415 if isinstance(other, BoolRef):
2416 return If(other, self, 0)
2417 a, b = _coerce_exprs(self, other)
2418 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctxctx)
2421 """Create the Z3 expression `other * self`.
2427 a, b = _coerce_exprs(self, other)
2428 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctxctx)
2431 """Create the Z3 expression `self - other`.
2440 a, b = _coerce_exprs(self, other)
2441 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctxctx)
2444 """Create the Z3 expression `other - self`.
2450 a, b = _coerce_exprs(self, other)
2451 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctxctx)
2454 """Create the Z3 expression `self**other` (** is the power operator).
2461 >>> simplify(IntVal(2)**8)
2464 a, b = _coerce_exprs(self, other)
2468 """Create the Z3 expression `other**self` (** is the power operator).
2475 >>> simplify(2**IntVal(8))
2478 a, b = _coerce_exprs(self, other)
2482 """Create the Z3 expression `other/self`.
2501 a, b = _coerce_exprs(self, other)
2505 """Create the Z3 expression `other/self`."""
2506 return self.
__div____div__(other)
2509 """Create the Z3 expression `other/self`.
2522 a, b = _coerce_exprs(self, other)
2526 """Create the Z3 expression `other/self`."""
2527 return self.
__rdiv____rdiv__(other)
2530 """Create the Z3 expression `other%self`.
2536 >>> simplify(IntVal(10) % IntVal(3))
2539 a, b = _coerce_exprs(self, other)
2541 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2545 """Create the Z3 expression `other%self`.
2551 a, b = _coerce_exprs(self, other)
2553 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2557 """Return an expression representing `-self`.
2577 """Create the Z3 expression `other <= self`.
2579 >>> x, y = Ints('x y')
2586 a, b = _coerce_exprs(self, other)
2590 """Create the Z3 expression `other < self`.
2592 >>> x, y = Ints('x y')
2599 a, b = _coerce_exprs(self, other)
2603 """Create the Z3 expression `other > self`.
2605 >>> x, y = Ints('x y')
2612 a, b = _coerce_exprs(self, other)
2616 """Create the Z3 expression `other >= self`.
2618 >>> x, y = Ints('x y')
2625 a, b = _coerce_exprs(self, other)
2630 """Return `True` if `a` is an arithmetical expression.
2639 >>> is_arith(IntVal(1))
2647 return isinstance(a, ArithRef)
2651 """Return `True` if `a` is an integer expression.
2658 >>> is_int(IntVal(1))
2670 """Return `True` if `a` is a real expression.
2682 >>> is_real(RealVal(1))
2688 def _is_numeral(ctx, a):
2692 def _is_algebraic(ctx, a):
2697 """Return `True` if `a` is an integer value of sort Int.
2699 >>> is_int_value(IntVal(1))
2703 >>> is_int_value(Int('x'))
2705 >>> n = Int('x') + 1
2710 >>> is_int_value(n.arg(1))
2712 >>> is_int_value(RealVal("1/3"))
2714 >>> is_int_value(RealVal(1))
2717 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2721 """Return `True` if `a` is rational value of sort Real.
2723 >>> is_rational_value(RealVal(1))
2725 >>> is_rational_value(RealVal("3/5"))
2727 >>> is_rational_value(IntVal(1))
2729 >>> is_rational_value(1)
2731 >>> n = Real('x') + 1
2734 >>> is_rational_value(n.arg(1))
2736 >>> is_rational_value(Real('x'))
2739 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2743 """Return `True` if `a` is an algebraic value of sort Real.
2745 >>> is_algebraic_value(RealVal("3/5"))
2747 >>> n = simplify(Sqrt(2))
2750 >>> is_algebraic_value(n)
2753 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2757 """Return `True` if `a` is an expression of the form b + c.
2759 >>> x, y = Ints('x y')
2769 """Return `True` if `a` is an expression of the form b * c.
2771 >>> x, y = Ints('x y')
2781 """Return `True` if `a` is an expression of the form b - c.
2783 >>> x, y = Ints('x y')
2793 """Return `True` if `a` is an expression of the form b / c.
2795 >>> x, y = Reals('x y')
2800 >>> x, y = Ints('x y')
2810 """Return `True` if `a` is an expression of the form b div c.
2812 >>> x, y = Ints('x y')
2822 """Return `True` if `a` is an expression of the form b % c.
2824 >>> x, y = Ints('x y')
2834 """Return `True` if `a` is an expression of the form b <= c.
2836 >>> x, y = Ints('x y')
2846 """Return `True` if `a` is an expression of the form b < c.
2848 >>> x, y = Ints('x y')
2858 """Return `True` if `a` is an expression of the form b >= c.
2860 >>> x, y = Ints('x y')
2870 """Return `True` if `a` is an expression of the form b > c.
2872 >>> x, y = Ints('x y')
2882 """Return `True` if `a` is an expression of the form IsInt(b).
2885 >>> is_is_int(IsInt(x))
2894 """Return `True` if `a` is an expression of the form ToReal(b).
2909 """Return `True` if `a` is an expression of the form ToInt(b).
2924 """Integer values."""
2927 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2936 _z3_assert(self.
is_intis_int(),
"Integer value expected")
2940 """Return a Z3 integer numeral as a Python string.
2948 """Return a Z3 integer numeral as a Python binary string.
2950 >>> v.as_binary_string()
2957 """Rational values."""
2960 """ Return the numerator of a Z3 rational numeral.
2962 >>> is_rational_value(RealVal("3/5"))
2964 >>> n = RealVal("3/5")
2967 >>> is_rational_value(Q(3,5))
2969 >>> Q(3,5).numerator()
2975 """ Return the denominator of a Z3 rational numeral.
2977 >>> is_rational_value(Q(3,5))
2986 """ Return the numerator as a Python long.
2988 >>> v = RealVal(10000000000)
2993 >>> v.numerator_as_long() + 1 == 10000000001
2999 """ Return the denominator as a Python long.
3001 >>> v = RealVal("1/3")
3004 >>> v.denominator_as_long()
3019 _z3_assert(self.
is_int_valueis_int_value(),
"Expected integer fraction")
3023 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3025 >>> v = RealVal("1/5")
3028 >>> v = RealVal("1/3")
3035 """Return a Z3 rational numeral as a Python string.
3044 """Return a Z3 rational as a Python Fraction object.
3046 >>> v = RealVal("1/5")
3054 """Algebraic irrational values."""
3057 """Return a Z3 rational number that approximates the algebraic number `self`.
3058 The result `r` is such that |r - self| <= 1/10^precision
3060 >>> x = simplify(Sqrt(2))
3062 6838717160008073720548335/4835703278458516698824704
3069 """Return a string representation of the algebraic number `self` in decimal notation
3070 using `prec` decimal places.
3072 >>> x = simplify(Sqrt(2))
3073 >>> x.as_decimal(10)
3075 >>> x.as_decimal(20)
3076 '1.41421356237309504880?'
3087 def _py2expr(a, ctx=None):
3088 if isinstance(a, bool):
3092 if isinstance(a, float):
3094 if isinstance(a, str):
3099 _z3_assert(
False,
"Python bool, int, long or float expected")
3103 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3107 >>> x = Const('x', IntSort())
3110 >>> x.sort() == IntSort()
3112 >>> x.sort() == BoolSort()
3120 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3124 >>> x = Const('x', RealSort())
3129 >>> x.sort() == RealSort()
3136 def _to_int_str(val):
3137 if isinstance(val, float):
3138 return str(int(val))
3139 elif isinstance(val, bool):
3146 elif isinstance(val, str):
3149 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
3153 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3165 """Return a Z3 real value.
3167 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3168 If `ctx=None`, then the global context is used.
3172 >>> RealVal(1).sort()
3184 """Return a Z3 rational a/b.
3186 If `ctx=None`, then the global context is used.
3190 >>> RatVal(3,5).sort()
3194 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3195 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3199 def Q(a, b, ctx=None):
3200 """Return a Z3 rational a/b.
3202 If `ctx=None`, then the global context is used.
3213 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3226 """Return a tuple of Integer constants.
3228 >>> x, y, z = Ints('x y z')
3233 if isinstance(names, str):
3234 names = names.split(
" ")
3235 return [
Int(name, ctx)
for name
in names]
3239 """Return a list of integer constants of size `sz`.
3241 >>> X = IntVector('x', 3)
3248 return [
Int(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3252 """Return a fresh integer constant in the given context using the given prefix.
3266 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3279 """Return a tuple of real constants.
3281 >>> x, y, z = Reals('x y z')
3284 >>> Sum(x, y, z).sort()
3288 if isinstance(names, str):
3289 names = names.split(
" ")
3290 return [
Real(name, ctx)
for name
in names]
3294 """Return a list of real constants of size `sz`.
3296 >>> X = RealVector('x', 3)
3305 return [
Real(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3309 """Return a fresh real constant in the given context using the given prefix.
3323 """ Return the Z3 expression ToReal(a).
3335 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3341 """ Return the Z3 expression ToInt(a).
3353 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3359 """ Return the Z3 predicate IsInt(a).
3362 >>> IsInt(x + "1/2")
3364 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3366 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3370 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3376 """ Return a Z3 expression which represents the square root of a.
3389 """ Return a Z3 expression which represents the cubic root of a.
3408 """Bit-vector sort."""
3411 """Return the size (number of bits) of the bit-vector sort `self`.
3413 >>> b = BitVecSort(32)
3423 """Try to cast `val` as a Bit-Vector.
3425 >>> b = BitVecSort(32)
3428 >>> b.cast(10).sexpr()
3433 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
3441 """Return True if `s` is a Z3 bit-vector sort.
3443 >>> is_bv_sort(BitVecSort(32))
3445 >>> is_bv_sort(IntSort())
3448 return isinstance(s, BitVecSortRef)
3452 """Bit-vector expressions."""
3455 """Return the sort of the bit-vector expression `self`.
3457 >>> x = BitVec('x', 32)
3460 >>> x.sort() == BitVecSort(32)
3466 """Return the number of bits of the bit-vector expression `self`.
3468 >>> x = BitVec('x', 32)
3471 >>> Concat(x, x).size()
3477 """Create the Z3 expression `self + other`.
3479 >>> x = BitVec('x', 32)
3480 >>> y = BitVec('y', 32)
3486 a, b = _coerce_exprs(self, other)
3490 """Create the Z3 expression `other + self`.
3492 >>> x = BitVec('x', 32)
3496 a, b = _coerce_exprs(self, other)
3500 """Create the Z3 expression `self * other`.
3502 >>> x = BitVec('x', 32)
3503 >>> y = BitVec('y', 32)
3509 a, b = _coerce_exprs(self, other)
3513 """Create the Z3 expression `other * self`.
3515 >>> x = BitVec('x', 32)
3519 a, b = _coerce_exprs(self, other)
3523 """Create the Z3 expression `self - other`.
3525 >>> x = BitVec('x', 32)
3526 >>> y = BitVec('y', 32)
3532 a, b = _coerce_exprs(self, other)
3536 """Create the Z3 expression `other - self`.
3538 >>> x = BitVec('x', 32)
3542 a, b = _coerce_exprs(self, other)
3546 """Create the Z3 expression bitwise-or `self | other`.
3548 >>> x = BitVec('x', 32)
3549 >>> y = BitVec('y', 32)
3555 a, b = _coerce_exprs(self, other)
3559 """Create the Z3 expression bitwise-or `other | self`.
3561 >>> x = BitVec('x', 32)
3565 a, b = _coerce_exprs(self, other)
3569 """Create the Z3 expression bitwise-and `self & other`.
3571 >>> x = BitVec('x', 32)
3572 >>> y = BitVec('y', 32)
3578 a, b = _coerce_exprs(self, other)
3582 """Create the Z3 expression bitwise-or `other & self`.
3584 >>> x = BitVec('x', 32)
3588 a, b = _coerce_exprs(self, other)
3592 """Create the Z3 expression bitwise-xor `self ^ other`.
3594 >>> x = BitVec('x', 32)
3595 >>> y = BitVec('y', 32)
3601 a, b = _coerce_exprs(self, other)
3605 """Create the Z3 expression bitwise-xor `other ^ self`.
3607 >>> x = BitVec('x', 32)
3611 a, b = _coerce_exprs(self, other)
3617 >>> x = BitVec('x', 32)
3624 """Return an expression representing `-self`.
3626 >>> x = BitVec('x', 32)
3635 """Create the Z3 expression bitwise-not `~self`.
3637 >>> x = BitVec('x', 32)
3646 """Create the Z3 expression (signed) division `self / other`.
3648 Use the function UDiv() for unsigned division.
3650 >>> x = BitVec('x', 32)
3651 >>> y = BitVec('y', 32)
3658 >>> UDiv(x, y).sexpr()
3661 a, b = _coerce_exprs(self, other)
3665 """Create the Z3 expression (signed) division `self / other`."""
3666 return self.
__div____div__(other)
3669 """Create the Z3 expression (signed) division `other / self`.
3671 Use the function UDiv() for unsigned division.
3673 >>> x = BitVec('x', 32)
3676 >>> (10 / x).sexpr()
3677 '(bvsdiv #x0000000a x)'
3678 >>> UDiv(10, x).sexpr()
3679 '(bvudiv #x0000000a x)'
3681 a, b = _coerce_exprs(self, other)
3685 """Create the Z3 expression (signed) division `other / self`."""
3686 return self.
__rdiv____rdiv__(other)
3689 """Create the Z3 expression (signed) mod `self % other`.
3691 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3693 >>> x = BitVec('x', 32)
3694 >>> y = BitVec('y', 32)
3701 >>> URem(x, y).sexpr()
3703 >>> SRem(x, y).sexpr()
3706 a, b = _coerce_exprs(self, other)
3710 """Create the Z3 expression (signed) mod `other % self`.
3712 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3714 >>> x = BitVec('x', 32)
3717 >>> (10 % x).sexpr()
3718 '(bvsmod #x0000000a x)'
3719 >>> URem(10, x).sexpr()
3720 '(bvurem #x0000000a x)'
3721 >>> SRem(10, x).sexpr()
3722 '(bvsrem #x0000000a x)'
3724 a, b = _coerce_exprs(self, other)
3728 """Create the Z3 expression (signed) `other <= self`.
3730 Use the function ULE() for unsigned less than or equal to.
3732 >>> x, y = BitVecs('x y', 32)
3735 >>> (x <= y).sexpr()
3737 >>> ULE(x, y).sexpr()
3740 a, b = _coerce_exprs(self, other)
3744 """Create the Z3 expression (signed) `other < self`.
3746 Use the function ULT() for unsigned less than.
3748 >>> x, y = BitVecs('x y', 32)
3753 >>> ULT(x, y).sexpr()
3756 a, b = _coerce_exprs(self, other)
3760 """Create the Z3 expression (signed) `other > self`.
3762 Use the function UGT() for unsigned greater than.
3764 >>> x, y = BitVecs('x y', 32)
3769 >>> UGT(x, y).sexpr()
3772 a, b = _coerce_exprs(self, other)
3776 """Create the Z3 expression (signed) `other >= self`.
3778 Use the function UGE() for unsigned greater than or equal to.
3780 >>> x, y = BitVecs('x y', 32)
3783 >>> (x >= y).sexpr()
3785 >>> UGE(x, y).sexpr()
3788 a, b = _coerce_exprs(self, other)
3792 """Create the Z3 expression (arithmetical) right shift `self >> other`
3794 Use the function LShR() for the right logical shift
3796 >>> x, y = BitVecs('x y', 32)
3799 >>> (x >> y).sexpr()
3801 >>> LShR(x, y).sexpr()
3805 >>> BitVecVal(4, 3).as_signed_long()
3807 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3809 >>> simplify(BitVecVal(4, 3) >> 1)
3811 >>> simplify(LShR(BitVecVal(4, 3), 1))
3813 >>> simplify(BitVecVal(2, 3) >> 1)
3815 >>> simplify(LShR(BitVecVal(2, 3), 1))
3818 a, b = _coerce_exprs(self, other)
3822 """Create the Z3 expression left shift `self << other`
3824 >>> x, y = BitVecs('x y', 32)
3827 >>> (x << y).sexpr()
3829 >>> simplify(BitVecVal(2, 3) << 1)
3832 a, b = _coerce_exprs(self, other)
3836 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3838 Use the function LShR() for the right logical shift
3840 >>> x = BitVec('x', 32)
3843 >>> (10 >> x).sexpr()
3844 '(bvashr #x0000000a x)'
3846 a, b = _coerce_exprs(self, other)
3850 """Create the Z3 expression left shift `other << self`.
3852 Use the function LShR() for the right logical shift
3854 >>> x = BitVec('x', 32)
3857 >>> (10 << x).sexpr()
3858 '(bvshl #x0000000a x)'
3860 a, b = _coerce_exprs(self, other)
3865 """Bit-vector values."""
3868 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3870 >>> v = BitVecVal(0xbadc0de, 32)
3873 >>> print("0x%.8x" % v.as_long())
3879 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3880 The most significant bit is assumed to be the sign.
3882 >>> BitVecVal(4, 3).as_signed_long()
3884 >>> BitVecVal(7, 3).as_signed_long()
3886 >>> BitVecVal(3, 3).as_signed_long()
3888 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3890 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3893 sz = self.
sizesize()
3895 if val >= 2**(sz - 1):
3897 if val < -2**(sz - 1):
3909 """Return `True` if `a` is a Z3 bit-vector expression.
3911 >>> b = BitVec('b', 32)
3919 return isinstance(a, BitVecRef)
3923 """Return `True` if `a` is a Z3 bit-vector numeral value.
3925 >>> b = BitVec('b', 32)
3928 >>> b = BitVecVal(10, 32)
3934 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3938 """Return the Z3 expression BV2Int(a).
3940 >>> b = BitVec('b', 3)
3941 >>> BV2Int(b).sort()
3946 >>> x > BV2Int(b, is_signed=False)
3948 >>> x > BV2Int(b, is_signed=True)
3949 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3950 >>> solve(x > BV2Int(b), b == 1, x < 3)
3954 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3961 """Return the z3 expression Int2BV(a, num_bits).
3962 It is a bit-vector of width num_bits and represents the
3963 modulo of a by 2^num_bits
3970 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3972 >>> Byte = BitVecSort(8)
3973 >>> Word = BitVecSort(16)
3976 >>> x = Const('x', Byte)
3977 >>> eq(x, BitVec('x', 8))
3985 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3987 >>> v = BitVecVal(10, 32)
3990 >>> print("0x%.8x" % v.as_long())
4002 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4003 If `ctx=None`, then the global context is used.
4005 >>> x = BitVec('x', 16)
4012 >>> word = BitVecSort(16)
4013 >>> x2 = BitVec('x', word)
4017 if isinstance(bv, BitVecSortRef):
4026 """Return a tuple of bit-vector constants of size bv.
4028 >>> x, y, z = BitVecs('x y z', 16)
4035 >>> Product(x, y, z)
4037 >>> simplify(Product(x, y, z))
4041 if isinstance(names, str):
4042 names = names.split(
" ")
4043 return [
BitVec(name, bv, ctx)
for name
in names]
4047 """Create a Z3 bit-vector concatenation expression.
4049 >>> v = BitVecVal(1, 4)
4050 >>> Concat(v, v+1, v)
4051 Concat(Concat(1, 1 + 1), 1)
4052 >>> simplify(Concat(v, v+1, v))
4054 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
4057 args = _get_args(args)
4060 _z3_assert(sz >= 2,
"At least two arguments expected.")
4067 if is_seq(args[0])
or isinstance(args[0], str):
4068 args = [_coerce_seq(s, ctx)
for s
in args]
4070 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
4073 v[i] = args[i].as_ast()
4078 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
4081 v[i] = args[i].as_ast()
4085 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
4087 for i
in range(sz - 1):
4093 """Create a Z3 bit-vector extraction expression.
4094 Extract is overloaded to also work on sequence extraction.
4095 The functions SubString and SubSeq are redirected to Extract.
4096 For this case, the arguments are reinterpreted as:
4097 high - is a sequence (string)
4099 a - is the length to be extracted
4101 >>> x = BitVec('x', 8)
4102 >>> Extract(6, 2, x)
4104 >>> Extract(6, 2, x).sort()
4106 >>> simplify(Extract(StringVal("abcd"),2,1))
4109 if isinstance(high, str):
4113 offset, length = _coerce_exprs(low, a, s.ctx)
4116 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
4117 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
4118 "First and second arguments must be non negative integers")
4119 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
4123 def _check_bv_args(a, b):
4125 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
4129 """Create the Z3 expression (unsigned) `other <= self`.
4131 Use the operator <= for signed less than or equal to.
4133 >>> x, y = BitVecs('x y', 32)
4136 >>> (x <= y).sexpr()
4138 >>> ULE(x, y).sexpr()
4141 _check_bv_args(a, b)
4142 a, b = _coerce_exprs(a, b)
4147 """Create the Z3 expression (unsigned) `other < self`.
4149 Use the operator < for signed less than.
4151 >>> x, y = BitVecs('x y', 32)
4156 >>> ULT(x, y).sexpr()
4159 _check_bv_args(a, b)
4160 a, b = _coerce_exprs(a, b)
4165 """Create the Z3 expression (unsigned) `other >= self`.
4167 Use the operator >= for signed greater than or equal to.
4169 >>> x, y = BitVecs('x y', 32)
4172 >>> (x >= y).sexpr()
4174 >>> UGE(x, y).sexpr()
4177 _check_bv_args(a, b)
4178 a, b = _coerce_exprs(a, b)
4183 """Create the Z3 expression (unsigned) `other > self`.
4185 Use the operator > for signed greater than.
4187 >>> x, y = BitVecs('x y', 32)
4192 >>> UGT(x, y).sexpr()
4195 _check_bv_args(a, b)
4196 a, b = _coerce_exprs(a, b)
4201 """Create the Z3 expression (unsigned) division `self / other`.
4203 Use the operator / for signed division.
4205 >>> x = BitVec('x', 32)
4206 >>> y = BitVec('y', 32)
4209 >>> UDiv(x, y).sort()
4213 >>> UDiv(x, y).sexpr()
4216 _check_bv_args(a, b)
4217 a, b = _coerce_exprs(a, b)
4222 """Create the Z3 expression (unsigned) remainder `self % other`.
4224 Use the operator % for signed modulus, and SRem() for signed remainder.
4226 >>> x = BitVec('x', 32)
4227 >>> y = BitVec('y', 32)
4230 >>> URem(x, y).sort()
4234 >>> URem(x, y).sexpr()
4237 _check_bv_args(a, b)
4238 a, b = _coerce_exprs(a, b)
4243 """Create the Z3 expression signed remainder.
4245 Use the operator % for signed modulus, and URem() for unsigned remainder.
4247 >>> x = BitVec('x', 32)
4248 >>> y = BitVec('y', 32)
4251 >>> SRem(x, y).sort()
4255 >>> SRem(x, y).sexpr()
4258 _check_bv_args(a, b)
4259 a, b = _coerce_exprs(a, b)
4264 """Create the Z3 expression logical right shift.
4266 Use the operator >> for the arithmetical right shift.
4268 >>> x, y = BitVecs('x y', 32)
4271 >>> (x >> y).sexpr()
4273 >>> LShR(x, y).sexpr()
4277 >>> BitVecVal(4, 3).as_signed_long()
4279 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4281 >>> simplify(BitVecVal(4, 3) >> 1)
4283 >>> simplify(LShR(BitVecVal(4, 3), 1))
4285 >>> simplify(BitVecVal(2, 3) >> 1)
4287 >>> simplify(LShR(BitVecVal(2, 3), 1))
4290 _check_bv_args(a, b)
4291 a, b = _coerce_exprs(a, b)
4296 """Return an expression representing `a` rotated to the left `b` times.
4298 >>> a, b = BitVecs('a b', 16)
4299 >>> RotateLeft(a, b)
4301 >>> simplify(RotateLeft(a, 0))
4303 >>> simplify(RotateLeft(a, 16))
4306 _check_bv_args(a, b)
4307 a, b = _coerce_exprs(a, b)
4312 """Return an expression representing `a` rotated to the right `b` times.
4314 >>> a, b = BitVecs('a b', 16)
4315 >>> RotateRight(a, b)
4317 >>> simplify(RotateRight(a, 0))
4319 >>> simplify(RotateRight(a, 16))
4322 _check_bv_args(a, b)
4323 a, b = _coerce_exprs(a, b)
4328 """Return a bit-vector expression with `n` extra sign-bits.
4330 >>> x = BitVec('x', 16)
4331 >>> n = SignExt(8, x)
4338 >>> v0 = BitVecVal(2, 2)
4343 >>> v = simplify(SignExt(6, v0))
4348 >>> print("%.x" % v.as_long())
4352 _z3_assert(_is_int(n),
"First argument must be an integer")
4353 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4358 """Return a bit-vector expression with `n` extra zero-bits.
4360 >>> x = BitVec('x', 16)
4361 >>> n = ZeroExt(8, x)
4368 >>> v0 = BitVecVal(2, 2)
4373 >>> v = simplify(ZeroExt(6, v0))
4380 _z3_assert(_is_int(n),
"First argument must be an integer")
4381 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4386 """Return an expression representing `n` copies of `a`.
4388 >>> x = BitVec('x', 8)
4389 >>> n = RepeatBitVec(4, x)
4394 >>> v0 = BitVecVal(10, 4)
4395 >>> print("%.x" % v0.as_long())
4397 >>> v = simplify(RepeatBitVec(4, v0))
4400 >>> print("%.x" % v.as_long())
4404 _z3_assert(_is_int(n),
"First argument must be an integer")
4405 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4410 """Return the reduction-and expression of `a`."""
4412 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4417 """Return the reduction-or expression of `a`."""
4419 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4424 """A predicate the determines that bit-vector addition does not overflow"""
4425 _check_bv_args(a, b)
4426 a, b = _coerce_exprs(a, b)
4431 """A predicate the determines that signed bit-vector addition does not underflow"""
4432 _check_bv_args(a, b)
4433 a, b = _coerce_exprs(a, b)
4438 """A predicate the determines that bit-vector subtraction does not overflow"""
4439 _check_bv_args(a, b)
4440 a, b = _coerce_exprs(a, b)
4445 """A predicate the determines that bit-vector subtraction does not underflow"""
4446 _check_bv_args(a, b)
4447 a, b = _coerce_exprs(a, b)
4452 """A predicate the determines that bit-vector signed division does not overflow"""
4453 _check_bv_args(a, b)
4454 a, b = _coerce_exprs(a, b)
4459 """A predicate the determines that bit-vector unary negation does not overflow"""
4461 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4466 """A predicate the determines that bit-vector multiplication does not overflow"""
4467 _check_bv_args(a, b)
4468 a, b = _coerce_exprs(a, b)
4473 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4474 _check_bv_args(a, b)
4475 a, b = _coerce_exprs(a, b)
4489 """Return the domain of the array sort `self`.
4491 >>> A = ArraySort(IntSort(), BoolSort())
4498 """Return the range of the array sort `self`.
4500 >>> A = ArraySort(IntSort(), BoolSort())
4508 """Array expressions. """
4511 """Return the array sort of the array expression `self`.
4513 >>> a = Array('a', IntSort(), BoolSort())
4520 """Shorthand for `self.sort().domain()`.
4522 >>> a = Array('a', IntSort(), BoolSort())
4529 """Shorthand for `self.sort().range()`.
4531 >>> a = Array('a', IntSort(), BoolSort())
4538 """Return the Z3 expression `self[arg]`.
4540 >>> a = Array('a', IntSort(), BoolSort())
4547 arg = self.
domaindomain().cast(arg)
4559 """Return `True` if `a` is a Z3 array expression.
4561 >>> a = Array('a', IntSort(), IntSort())
4564 >>> is_array(Store(a, 0, 1))
4569 return isinstance(a, ArrayRef)
4573 """Return `True` if `a` is a Z3 constant array.
4575 >>> a = K(IntSort(), 10)
4576 >>> is_const_array(a)
4578 >>> a = Array('a', IntSort(), IntSort())
4579 >>> is_const_array(a)
4586 """Return `True` if `a` is a Z3 constant array.
4588 >>> a = K(IntSort(), 10)
4591 >>> a = Array('a', IntSort(), IntSort())
4599 """Return `True` if `a` is a Z3 map array expression.
4601 >>> f = Function('f', IntSort(), IntSort())
4602 >>> b = Array('b', IntSort(), IntSort())
4615 """Return `True` if `a` is a Z3 default array expression.
4616 >>> d = Default(K(IntSort(), 10))
4620 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4624 """Return the function declaration associated with a Z3 map array expression.
4626 >>> f = Function('f', IntSort(), IntSort())
4627 >>> b = Array('b', IntSort(), IntSort())
4629 >>> eq(f, get_map_func(a))
4633 >>> get_map_func(a)(0)
4637 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4648 """Return the Z3 array sort with the given domain and range sorts.
4650 >>> A = ArraySort(IntSort(), BoolSort())
4657 >>> AA = ArraySort(IntSort(), A)
4659 Array(Int, Array(Int, Bool))
4661 sig = _get_args(sig)
4663 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4664 arity = len(sig) - 1
4669 _z3_assert(
is_sort(s),
"Z3 sort expected")
4670 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4674 dom = (Sort * arity)()
4675 for i
in range(arity):
4681 """Return an array constant named `name` with the given domain and range sorts.
4683 >>> a = Array('a', IntSort(), IntSort())
4695 """Return a Z3 store array expression.
4697 >>> a = Array('a', IntSort(), IntSort())
4698 >>> i, v = Ints('i v')
4699 >>> s = Update(a, i, v)
4702 >>> prove(s[i] == v)
4705 >>> prove(Implies(i != j, s[j] == a[j]))
4709 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4710 i = a.sort().domain().cast(i)
4711 v = a.sort().
range().cast(v)
4713 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4717 """ Return a default value for array expression.
4718 >>> b = K(IntSort(), 1)
4719 >>> prove(Default(b) == 1)
4723 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4728 """Return a Z3 store array expression.
4730 >>> a = Array('a', IntSort(), IntSort())
4731 >>> i, v = Ints('i v')
4732 >>> s = Store(a, i, v)
4735 >>> prove(s[i] == v)
4738 >>> prove(Implies(i != j, s[j] == a[j]))
4745 """Return a Z3 select array expression.
4747 >>> a = Array('a', IntSort(), IntSort())
4751 >>> eq(Select(a, i), a[i])
4755 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4760 """Return a Z3 map array expression.
4762 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4763 >>> a1 = Array('a1', IntSort(), IntSort())
4764 >>> a2 = Array('a2', IntSort(), IntSort())
4765 >>> b = Map(f, a1, a2)
4768 >>> prove(b[0] == f(a1[0], a2[0]))
4771 args = _get_args(args)
4773 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4774 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4775 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4776 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4777 _args, sz = _to_ast_array(args)
4783 """Return a Z3 constant array expression.
4785 >>> a = K(IntSort(), 10)
4797 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4800 v = _py2expr(v, ctx)
4805 """Return extensionality index for one-dimensional arrays.
4806 >> a, b = Consts('a b', SetSort(IntSort()))
4813 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4818 k = _py2expr(k, ctx)
4823 """Return `True` if `a` is a Z3 array select application.
4825 >>> a = Array('a', IntSort(), IntSort())
4836 """Return `True` if `a` is a Z3 array store application.
4838 >>> a = Array('a', IntSort(), IntSort())
4841 >>> is_store(Store(a, 0, 1))
4854 """ Create a set sort over element sort s"""
4859 """Create the empty set
4860 >>> EmptySet(IntSort())
4868 """Create the full set
4869 >>> FullSet(IntSort())
4877 """ Take the union of sets
4878 >>> a = Const('a', SetSort(IntSort()))
4879 >>> b = Const('b', SetSort(IntSort()))
4883 args = _get_args(args)
4884 ctx = _ctx_from_ast_arg_list(args)
4885 _args, sz = _to_ast_array(args)
4890 """ Take the union of sets
4891 >>> a = Const('a', SetSort(IntSort()))
4892 >>> b = Const('b', SetSort(IntSort()))
4893 >>> SetIntersect(a, b)
4896 args = _get_args(args)
4897 ctx = _ctx_from_ast_arg_list(args)
4898 _args, sz = _to_ast_array(args)
4903 """ Add element e to set s
4904 >>> a = Const('a', SetSort(IntSort()))
4908 ctx = _ctx_from_ast_arg_list([s, e])
4909 e = _py2expr(e, ctx)
4914 """ Remove element e to set s
4915 >>> a = Const('a', SetSort(IntSort()))
4919 ctx = _ctx_from_ast_arg_list([s, e])
4920 e = _py2expr(e, ctx)
4925 """ The complement of set s
4926 >>> a = Const('a', SetSort(IntSort()))
4927 >>> SetComplement(a)
4935 """ The set difference of a and b
4936 >>> a = Const('a', SetSort(IntSort()))
4937 >>> b = Const('b', SetSort(IntSort()))
4938 >>> SetDifference(a, b)
4941 ctx = _ctx_from_ast_arg_list([a, b])
4946 """ Check if e is a member of set s
4947 >>> a = Const('a', SetSort(IntSort()))
4951 ctx = _ctx_from_ast_arg_list([s, e])
4952 e = _py2expr(e, ctx)
4957 """ Check if a is a subset of b
4958 >>> a = Const('a', SetSort(IntSort()))
4959 >>> b = Const('b', SetSort(IntSort()))
4963 ctx = _ctx_from_ast_arg_list([a, b])
4973 def _valid_accessor(acc):
4974 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4975 if not isinstance(acc, tuple):
4979 return isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4983 """Helper class for declaring Z3 datatypes.
4985 >>> List = Datatype('List')
4986 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4987 >>> List.declare('nil')
4988 >>> List = List.create()
4989 >>> # List is now a Z3 declaration
4992 >>> List.cons(10, List.nil)
4994 >>> List.cons(10, List.nil).sort()
4996 >>> cons = List.cons
5000 >>> n = cons(1, cons(0, nil))
5002 cons(1, cons(0, nil))
5003 >>> simplify(cdr(n))
5005 >>> simplify(car(n))
5016 r.constructors = copy.deepcopy(self.
constructorsconstructors)
5021 _z3_assert(isinstance(name, str),
"String expected")
5022 _z3_assert(isinstance(rec_name, str),
"String expected")
5024 all([_valid_accessor(a)
for a
in args]),
5025 "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)",
5027 self.
constructorsconstructors.append((name, rec_name, args))
5030 """Declare constructor named `name` with the given accessors `args`.
5031 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort
5032 or a reference to the datatypes being declared.
5034 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
5035 declares the constructor named `cons` that builds a new List using an integer and a List.
5036 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer
5037 of a `cons` cell, and `cdr` the list of a `cons` cell. After all constructors were declared,
5038 we use the method create() to create the actual datatype in Z3.
5040 >>> List = Datatype('List')
5041 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5042 >>> List.declare('nil')
5043 >>> List = List.create()
5046 _z3_assert(isinstance(name, str),
"String expected")
5047 _z3_assert(name !=
"",
"Constructor name cannot be empty")
5048 return self.
declare_coredeclare_core(name,
"is-" + name, *args)
5054 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
5056 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
5058 >>> List = Datatype('List')
5059 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5060 >>> List.declare('nil')
5061 >>> List = List.create()
5064 >>> List.cons(10, List.nil)
5071 """Auxiliary object used to create Z3 datatypes."""
5078 if self.
ctxctx.ref()
is not None:
5083 """Auxiliary object used to create Z3 datatypes."""
5090 if self.
ctxctx.ref()
is not None:
5095 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5097 In the following example we define a Tree-List using two mutually recursive datatypes.
5099 >>> TreeList = Datatype('TreeList')
5100 >>> Tree = Datatype('Tree')
5101 >>> # Tree has two constructors: leaf and node
5102 >>> Tree.declare('leaf', ('val', IntSort()))
5103 >>> # a node contains a list of trees
5104 >>> Tree.declare('node', ('children', TreeList))
5105 >>> TreeList.declare('nil')
5106 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
5107 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
5108 >>> Tree.val(Tree.leaf(10))
5110 >>> simplify(Tree.val(Tree.leaf(10)))
5112 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5114 node(cons(leaf(10), cons(leaf(20), nil)))
5115 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5116 >>> simplify(n2 == n1)
5118 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
5123 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
5124 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
5125 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
5126 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
5129 names = (Symbol * num)()
5130 out = (Sort * num)()
5131 clists = (ConstructorList * num)()
5133 for i
in range(num):
5136 num_cs = len(d.constructors)
5137 cs = (Constructor * num_cs)()
5138 for j
in range(num_cs):
5139 c = d.constructors[j]
5144 fnames = (Symbol * num_fs)()
5145 sorts = (Sort * num_fs)()
5146 refs = (ctypes.c_uint * num_fs)()
5147 for k
in range(num_fs):
5151 if isinstance(ftype, Datatype):
5154 ds.count(ftype) == 1,
5155 "One and only one occurrence of each datatype is expected",
5158 refs[k] = ds.index(ftype)
5161 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
5162 sorts[k] = ftype.ast
5171 for i
in range(num):
5173 num_cs = dref.num_constructors()
5174 for j
in range(num_cs):
5175 cref = dref.constructor(j)
5176 cref_name = cref.name()
5177 cref_arity = cref.arity()
5178 if cref.arity() == 0:
5180 setattr(dref, cref_name, cref)
5181 rref = dref.recognizer(j)
5182 setattr(dref,
"is_" + cref_name, rref)
5183 for k
in range(cref_arity):
5184 aref = dref.accessor(j, k)
5185 setattr(dref, aref.name(), aref)
5187 return tuple(result)
5191 """Datatype sorts."""
5194 """Return the number of constructors in the given Z3 datatype.
5196 >>> List = Datatype('List')
5197 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5198 >>> List.declare('nil')
5199 >>> List = List.create()
5200 >>> # List is now a Z3 declaration
5201 >>> List.num_constructors()
5207 """Return a constructor of the datatype `self`.
5209 >>> List = Datatype('List')
5210 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5211 >>> List.declare('nil')
5212 >>> List = List.create()
5213 >>> # List is now a Z3 declaration
5214 >>> List.num_constructors()
5216 >>> List.constructor(0)
5218 >>> List.constructor(1)
5222 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5226 """In Z3, each constructor has an associated recognizer predicate.
5228 If the constructor is named `name`, then the recognizer `is_name`.
5230 >>> List = Datatype('List')
5231 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5232 >>> List.declare('nil')
5233 >>> List = List.create()
5234 >>> # List is now a Z3 declaration
5235 >>> List.num_constructors()
5237 >>> List.recognizer(0)
5239 >>> List.recognizer(1)
5241 >>> simplify(List.is_nil(List.cons(10, List.nil)))
5243 >>> simplify(List.is_cons(List.cons(10, List.nil)))
5245 >>> l = Const('l', List)
5246 >>> simplify(List.is_cons(l))
5250 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid recognizer index")
5254 """In Z3, each constructor has 0 or more accessor.
5255 The number of accessors is equal to the arity of the constructor.
5257 >>> List = Datatype('List')
5258 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
5259 >>> List.declare('nil')
5260 >>> List = List.create()
5261 >>> List.num_constructors()
5263 >>> List.constructor(0)
5265 >>> num_accs = List.constructor(0).arity()
5268 >>> List.accessor(0, 0)
5270 >>> List.accessor(0, 1)
5272 >>> List.constructor(1)
5274 >>> num_accs = List.constructor(1).arity()
5279 _z3_assert(i < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5280 _z3_assert(j < self.
constructorconstructor(i).arity(),
"Invalid accessor index")
5288 """Datatype expressions."""
5291 """Return the datatype sort of the datatype expression `self`."""
5296 """Create a named tuple sort base on a set of underlying sorts
5298 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5301 projects = [(
"project%d" % i, sorts[i])
for i
in range(len(sorts))]
5302 tuple.declare(name, *projects)
5303 tuple = tuple.create()
5304 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5308 """Create a named tagged union sort base on a set of underlying sorts
5310 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5313 for i
in range(len(sorts)):
5314 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5316 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5320 """Return a new enumeration sort named `name` containing the given values.
5322 The result is a pair (sort, list of constants).
5324 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5327 _z3_assert(isinstance(name, str),
"Name must be a string")
5328 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5329 _z3_assert(len(values) > 0,
"At least one value expected")
5332 _val_names = (Symbol * num)()
5333 for i
in range(num):
5335 _values = (FuncDecl * num)()
5336 _testers = (FuncDecl * num)()
5340 for i
in range(num):
5342 V = [a()
for a
in V]
5353 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5355 Consider using the function `args2params` to create instances of this object.
5363 self.
paramsparams = params
5370 if self.
ctxctx.ref()
is not None:
5374 """Set parameter name with value val."""
5376 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5378 if isinstance(val, bool):
5382 elif isinstance(val, float):
5384 elif isinstance(val, str):
5388 _z3_assert(
False,
"invalid parameter value")
5394 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5399 """Convert python arguments into a Z3_params object.
5400 A ':' is added to the keywords, and '_' is replaced with '-'
5402 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5403 (params model true relevancy 2 elim_and true)
5406 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5422 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5426 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5432 return ParamsDescrsRef(self.
descrdescr, self.
ctxctx)
5435 if self.
ctxctx.ref()
is not None:
5439 """Return the size of in the parameter description `self`.
5444 """Return the size of in the parameter description `self`.
5446 return self.
sizesize()
5449 """Return the i-th parameter name in the parameter description `self`.
5454 """Return the kind of the parameter named `n`.
5459 """Return the documentation string of the parameter named `n`.
5480 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5482 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5483 A goal has a solution if one of its subgoals has a solution.
5484 A goal is unsatisfiable if all subgoals are unsatisfiable.
5487 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5489 _z3_assert(goal
is None or ctx
is not None,
5490 "If goal is different from None, then ctx must be also different from None")
5493 if self.
goalgoal
is None:
5498 if self.
goalgoal
is not None and self.
ctxctx.ref()
is not None:
5502 """Return the depth of the goal `self`.
5503 The depth corresponds to the number of tactics applied to `self`.
5505 >>> x, y = Ints('x y')
5507 >>> g.add(x == 0, y >= x + 1)
5510 >>> r = Then('simplify', 'solve-eqs')(g)
5511 >>> # r has 1 subgoal
5520 """Return `True` if `self` contains the `False` constraints.
5522 >>> x, y = Ints('x y')
5524 >>> g.inconsistent()
5526 >>> g.add(x == 0, x == 1)
5529 >>> g.inconsistent()
5531 >>> g2 = Tactic('propagate-values')(g)[0]
5532 >>> g2.inconsistent()
5538 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5541 >>> g.prec() == Z3_GOAL_PRECISE
5543 >>> x, y = Ints('x y')
5544 >>> g.add(x == y + 1)
5545 >>> g.prec() == Z3_GOAL_PRECISE
5547 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5550 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5551 >>> g2.prec() == Z3_GOAL_PRECISE
5553 >>> g2.prec() == Z3_GOAL_UNDER
5559 """Alias for `prec()`.
5562 >>> g.precision() == Z3_GOAL_PRECISE
5565 return self.
precprec()
5568 """Return the number of constraints in the goal `self`.
5573 >>> x, y = Ints('x y')
5574 >>> g.add(x == 0, y > x)
5581 """Return the number of constraints in the goal `self`.
5586 >>> x, y = Ints('x y')
5587 >>> g.add(x == 0, y > x)
5591 return self.
sizesize()
5594 """Return a constraint in the goal `self`.
5597 >>> x, y = Ints('x y')
5598 >>> g.add(x == 0, y > x)
5607 """Return a constraint in the goal `self`.
5610 >>> x, y = Ints('x y')
5611 >>> g.add(x == 0, y > x)
5617 if arg >= len(self):
5619 return self.
getget(arg)
5622 """Assert constraints into the goal.
5626 >>> g.assert_exprs(x > 0, x < 2)
5630 args = _get_args(args)
5641 >>> g.append(x > 0, x < 2)
5652 >>> g.insert(x > 0, x < 2)
5663 >>> g.add(x > 0, x < 2)
5670 """Retrieve model from a satisfiable goal
5671 >>> a, b = Ints('a b')
5673 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5674 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5677 [Or(b == 0, b == 1), Not(0 <= b)]
5679 [Or(b == 0, b == 1), Not(1 <= b)]
5680 >>> # Remark: the subgoal r[0] is unsatisfiable
5681 >>> # Creating a solver for solving the second subgoal
5688 >>> # Model s.model() does not assign a value to `a`
5689 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5690 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5691 >>> r[1].convert_model(s.model())
5695 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5699 return obj_to_string(self)
5702 """Return a textual representation of the s-expression representing the goal."""
5706 """Return a textual representation of the goal in DIMACS format."""
5710 """Copy goal `self` to context `target`.
5718 >>> g2 = g.translate(c2)
5721 >>> g.ctx == main_ctx()
5725 >>> g2.ctx == main_ctx()
5729 _z3_assert(isinstance(target, Context),
"target must be a context")
5739 """Return a new simplified goal.
5741 This method is essentially invoking the simplify tactic.
5745 >>> g.add(x + 1 >= 2)
5748 >>> g2 = g.simplify()
5751 >>> # g was not modified
5756 return t.apply(self, *arguments, **keywords)[0]
5759 """Return goal `self` as a single Z3 expression.
5776 return self.
getget(0)
5778 return And([self.
getget(i)
for i
in range(len(self))], self.
ctxctx)
5788 """A collection (vector) of ASTs."""
5797 assert ctx
is not None
5802 if self.
vectorvector
is not None and self.
ctxctx.ref()
is not None:
5806 """Return the size of the vector `self`.
5811 >>> A.push(Int('x'))
5812 >>> A.push(Int('x'))
5819 """Return the AST at position `i`.
5822 >>> A.push(Int('x') + 1)
5823 >>> A.push(Int('y'))
5830 if isinstance(i, int):
5834 if i >= self.
__len____len__():
5838 elif isinstance(i, slice):
5841 result.append(_to_ast_ref(
5848 """Update AST at position `i`.
5851 >>> A.push(Int('x') + 1)
5852 >>> A.push(Int('y'))
5859 if i >= self.
__len____len__():
5864 """Add `v` in the end of the vector.
5869 >>> A.push(Int('x'))
5876 """Resize the vector to `sz` elements.
5882 >>> for i in range(10): A[i] = Int('x')
5889 """Return `True` if the vector contains `item`.
5912 """Copy vector `self` to context `other_ctx`.
5918 >>> B = A.translate(c2)
5934 return obj_to_string(self)
5937 """Return a textual representation of the s-expression representing the vector."""
5948 """A mapping from ASTs to ASTs."""
5957 assert ctx
is not None
5965 if self.
mapmap
is not None and self.
ctxctx.ref()
is not None:
5969 """Return the size of the map.
5975 >>> M[x] = IntVal(1)
5982 """Return `True` if the map contains key `key`.
5995 """Retrieve the value associated with key `key`.
6006 """Add/Update key `k` with value `v`.
6015 >>> M[x] = IntVal(1)
6025 """Remove the entry associated with key `k`.
6039 """Remove all entries from the map.
6044 >>> M[x+x] = IntVal(1)
6054 """Return an AstVector containing all keys in the map.
6059 >>> M[x+x] = IntVal(1)
6073 """Store the value of the interpretation of a function in a particular point."""
6084 if self.
ctxctx.ref()
is not None:
6088 """Return the number of arguments in the given entry.
6090 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6092 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6097 >>> f_i.num_entries()
6099 >>> e = f_i.entry(0)
6106 """Return the value of argument `idx`.
6108 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6110 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6115 >>> f_i.num_entries()
6117 >>> e = f_i.entry(0)
6128 ... except IndexError:
6129 ... print("index error")
6137 """Return the value of the function at point `self`.
6139 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6141 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6146 >>> f_i.num_entries()
6148 >>> e = f_i.entry(0)
6159 """Return entry `self` as a Python list.
6160 >>> f = Function('f', IntSort(), IntSort(), IntSort())
6162 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6167 >>> f_i.num_entries()
6169 >>> e = f_i.entry(0)
6174 args.append(self.
valuevalue())
6178 return repr(self.
as_listas_list())
6182 """Stores the interpretation of a function in a Z3 model."""
6187 if self.
ff
is not None:
6191 if self.
ff
is not None and self.
ctxctx.ref()
is not None:
6196 Return the `else` value for a function interpretation.
6197 Return None if Z3 did not specify the `else` value for
6200 >>> f = Function('f', IntSort(), IntSort())
6202 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6208 >>> m[f].else_value()
6213 return _to_expr_ref(r, self.
ctxctx)
6218 """Return the number of entries/points in the function interpretation `self`.
6220 >>> f = Function('f', IntSort(), IntSort())
6222 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6228 >>> m[f].num_entries()
6234 """Return the number of arguments for each entry in the function interpretation `self`.
6236 >>> f = Function('f', IntSort(), IntSort())
6238 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6248 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
6250 >>> f = Function('f', IntSort(), IntSort())
6252 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6258 >>> m[f].num_entries()
6268 """Copy model 'self' to context 'other_ctx'.
6279 """Return the function interpretation as a Python list.
6280 >>> f = Function('f', IntSort(), IntSort())
6282 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
6296 return obj_to_string(self)
6300 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6303 assert ctx
is not None
6309 if self.
ctxctx.ref()
is not None:
6313 return obj_to_string(self)
6316 """Return a textual representation of the s-expression representing the model."""
6319 def eval(self, t, model_completion=False):
6320 """Evaluate the expression `t` in the model `self`.
6321 If `model_completion` is enabled, then a default interpretation is automatically added
6322 for symbols that do not have an interpretation in the model `self`.
6326 >>> s.add(x > 0, x < 2)
6339 >>> m.eval(y, model_completion=True)
6341 >>> # Now, m contains an interpretation for y
6347 return _to_expr_ref(r[0], self.
ctxctx)
6348 raise Z3Exception(
"failed to evaluate expression in the model")
6351 """Alias for `eval`.
6355 >>> s.add(x > 0, x < 2)
6359 >>> m.evaluate(x + 1)
6361 >>> m.evaluate(x == 1)
6364 >>> m.evaluate(y + x)
6368 >>> m.evaluate(y, model_completion=True)
6370 >>> # Now, m contains an interpretation for y
6371 >>> m.evaluate(y + x)
6374 return self.
evaleval(t, model_completion)
6377 """Return the number of constant and function declarations in the model `self`.
6379 >>> f = Function('f', IntSort(), IntSort())
6382 >>> s.add(x > 0, f(x) != x)
6391 return num_consts + num_funcs
6394 """Return the interpretation for a given declaration or constant.
6396 >>> f = Function('f', IntSort(), IntSort())
6399 >>> s.add(x > 0, x < 2, f(x) == 0)
6409 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6413 if decl.arity() == 0:
6415 if _r.value
is None:
6417 r = _to_expr_ref(_r, self.
ctxctx)
6428 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6430 >>> A = DeclareSort('A')
6431 >>> a, b = Consts('a b', A)
6443 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6445 >>> A = DeclareSort('A')
6446 >>> B = DeclareSort('B')
6447 >>> a1, a2 = Consts('a1 a2', A)
6448 >>> b1, b2 = Consts('b1 b2', B)
6450 >>> s.add(a1 != a2, b1 != b2)
6466 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6468 >>> A = DeclareSort('A')
6469 >>> B = DeclareSort('B')
6470 >>> a1, a2 = Consts('a1 a2', A)
6471 >>> b1, b2 = Consts('b1 b2', B)
6473 >>> s.add(a1 != a2, b1 != b2)
6483 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6485 >>> A = DeclareSort('A')
6486 >>> a, b = Consts('a b', A)
6492 >>> m.get_universe(A)
6496 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6503 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
6504 If `idx` is a declaration, then the actual interpretation is returned.
6506 The elements can be retrieved using position or the actual declaration.
6508 >>> f = Function('f', IntSort(), IntSort())
6511 >>> s.add(x > 0, x < 2, f(x) == 0)
6525 >>> for d in m: print("%s -> %s" % (d, m[d]))
6530 if idx >= len(self):
6533 if (idx < num_consts):
6537 if isinstance(idx, FuncDeclRef):
6541 if isinstance(idx, SortRef):
6544 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6548 """Return a list with all symbols that have an interpretation in the model `self`.
6549 >>> f = Function('f', IntSort(), IntSort())
6552 >>> s.add(x > 0, x < 2, f(x) == 0)
6567 """Update the interpretation of a constant"""
6571 raise Z3Exception(
"Expecting 0-ary function or constant expression")
6572 value = _py2expr(value)
6576 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6579 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6596 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6597 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6601 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6603 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6614 """Statistics for `Solver.check()`."""
6625 if self.
ctxctx.ref()
is not None:
6632 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6635 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6638 out.write(u(
"<tr>"))
6640 out.write(u(
"<td>%s</td><td>%s</td></tr>" % (k, v)))
6641 out.write(u(
"</table>"))
6642 return out.getvalue()
6647 """Return the number of statistical counters.
6650 >>> s = Then('simplify', 'nlsat').solver()
6654 >>> st = s.statistics()
6661 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6664 >>> s = Then('simplify', 'nlsat').solver()
6668 >>> st = s.statistics()
6672 ('nlsat propagations', 2)
6676 if idx >= len(self):
6685 """Return the list of statistical counters.
6688 >>> s = Then('simplify', 'nlsat').solver()
6692 >>> st = s.statistics()
6697 """Return the value of a particular statistical counter.
6700 >>> s = Then('simplify', 'nlsat').solver()
6704 >>> st = s.statistics()
6705 >>> st.get_key_value('nlsat propagations')
6708 for idx
in range(len(self)):
6714 raise Z3Exception(
"unknown key")
6717 """Access the value of statistical using attributes.
6719 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6720 we should use '_' (e.g., 'nlsat_propagations').
6723 >>> s = Then('simplify', 'nlsat').solver()
6727 >>> st = s.statistics()
6728 >>> st.nlsat_propagations
6733 key = name.replace(
"_",
" ")
6737 raise AttributeError
6747 """Represents the result of a satisfiability check: sat, unsat, unknown.
6753 >>> isinstance(r, CheckSatResult)
6764 return isinstance(other, CheckSatResult)
and self.
rr == other.r
6767 return not self.
__eq____eq__(other)
6771 if self.
rr == Z3_L_TRUE:
6773 elif self.
rr == Z3_L_FALSE:
6774 return "<b>unsat</b>"
6776 return "<b>unknown</b>"
6778 if self.
rr == Z3_L_TRUE:
6780 elif self.
rr == Z3_L_FALSE:
6785 def _repr_html_(self):
6786 in_html = in_html_mode()
6789 set_html_mode(in_html)
6800 Solver API provides methods for implementing the main SMT 2.0 commands:
6801 push, pop, check, get-model, etc.
6804 def __init__(self, solver=None, ctx=None, logFile=None):
6805 assert solver
is None or ctx
is not None
6812 self.
solversolver = solver
6814 if logFile
is not None:
6815 self.
setset(
"smtlib2_log", logFile)
6818 if self.
solversolver
is not None and self.
ctxctx.ref()
is not None:
6822 """Set a configuration option.
6823 The method `help()` return a string containing all available options.
6826 >>> # The option MBQI can be set using three different approaches.
6827 >>> s.set(mbqi=True)
6828 >>> s.set('MBQI', True)
6829 >>> s.set(':mbqi', True)
6835 """Create a backtracking point.
6857 """Backtrack \\c num backtracking points.
6879 """Return the current number of backtracking points.
6897 """Remove all asserted constraints and backtracking points created using `push()`.
6911 """Assert constraints into the solver.
6915 >>> s.assert_exprs(x > 0, x < 2)
6919 args = _get_args(args)
6922 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6930 """Assert constraints into the solver.
6934 >>> s.add(x > 0, x < 2)
6945 """Assert constraints into the solver.
6949 >>> s.append(x > 0, x < 2)
6956 """Assert constraints into the solver.
6960 >>> s.insert(x > 0, x < 2)
6967 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6969 If `p` is a string, it will be automatically converted into a Boolean constant.
6974 >>> s.set(unsat_core=True)
6975 >>> s.assert_and_track(x > 0, 'p1')
6976 >>> s.assert_and_track(x != 1, 'p2')
6977 >>> s.assert_and_track(x < 0, p3)
6978 >>> print(s.check())
6980 >>> c = s.unsat_core()
6990 if isinstance(p, str):
6992 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6993 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6997 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
7003 >>> s.add(x > 0, x < 2)
7006 >>> s.model().eval(x)
7012 >>> s.add(2**x == 4)
7017 assumptions = _get_args(assumptions)
7018 num = len(assumptions)
7019 _assumptions = (Ast * num)()
7020 for i
in range(num):
7021 _assumptions[i] = s.cast(assumptions[i]).as_ast()
7026 """Return a model for the last `check()`.
7028 This function raises an exception if
7029 a model is not available (e.g., last `check()` returned unsat).
7033 >>> s.add(a + 2 == 0)
7042 raise Z3Exception(
"model is not available")
7045 """Import model converter from other into the current solver"""
7049 """Return a subset (as an AST vector) of the assumptions provided to the last check().
7051 These are the assumptions Z3 used in the unsatisfiability proof.
7052 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
7053 They may be also used to "retract" assumptions. Note that, assumptions are not really
7054 "soft constraints", but they can be used to implement them.
7056 >>> p1, p2, p3 = Bools('p1 p2 p3')
7057 >>> x, y = Ints('x y')
7059 >>> s.add(Implies(p1, x > 0))
7060 >>> s.add(Implies(p2, y > x))
7061 >>> s.add(Implies(p2, y < 1))
7062 >>> s.add(Implies(p3, y > -3))
7063 >>> s.check(p1, p2, p3)
7065 >>> core = s.unsat_core()
7074 >>> # "Retracting" p2
7081 """Determine fixed values for the variables based on the solver state and assumptions.
7083 >>> a, b, c, d = Bools('a b c d')
7084 >>> s.add(Implies(a,b), Implies(b, c))
7085 >>> s.consequences([a],[b,c,d])
7086 (sat, [Implies(a, b), Implies(a, c)])
7087 >>> s.consequences([Not(c),d],[a,b,c,d])
7088 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
7090 if isinstance(assumptions, list):
7092 for a
in assumptions:
7095 if isinstance(variables, list):
7100 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
7101 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
7104 variables.vector, consequences.vector)
7105 sz = len(consequences)
7106 consequences = [consequences[i]
for i
in range(sz)]
7110 """Parse assertions from a file"""
7114 """Parse assertions from a string"""
7119 The method takes an optional set of variables that restrict which
7120 variables may be used as a starting point for cubing.
7121 If vars is not None, then the first case split is based on a variable in
7125 if vars
is not None:
7132 if (len(r) == 1
and is_false(r[0])):
7139 """Access the set of variables that were touched by the most recently generated cube.
7140 This set of variables can be used as a starting point for additional cubes.
7141 The idea is that variables that appear in clauses that are reduced by the most recent
7142 cube are likely more useful to cube on."""
7146 """Return a proof for the last `check()`. Proof construction must be enabled."""
7150 """Return an AST vector containing all added constraints.
7164 """Return an AST vector containing all currently inferred units.
7169 """Return an AST vector containing all atomic formulas in solver state that are not units.
7174 """Return trail and decision levels of the solver state after a check() call.
7176 trail = self.
trailtrail()
7177 levels = (ctypes.c_uint * len(trail))()
7179 return trail, levels
7182 """Return trail of the solver state after a check() call.
7187 """Return statistics for the last `check()`.
7189 >>> s = SimpleSolver()
7194 >>> st = s.statistics()
7195 >>> st.get_key_value('final checks')
7205 """Return a string describing why the last `check()` returned `unknown`.
7208 >>> s = SimpleSolver()
7209 >>> s.add(2**x == 4)
7212 >>> s.reason_unknown()
7213 '(incomplete (theory arithmetic))'
7218 """Display a string describing all available options."""
7222 """Return the parameter description set."""
7226 """Return a formatted string with all added constraints."""
7227 return obj_to_string(self)
7230 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
7234 >>> s1 = Solver(ctx=c1)
7235 >>> s2 = s1.translate(c2)
7238 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
7240 return Solver(solver, target)
7249 """Return a formatted string (in Lisp-like format) with all added constraints.
7250 We say the string is in s-expression format.
7261 """Return a textual representation of the solver in DIMACS format."""
7265 """return SMTLIB2 formatted benchmark for solver's assertions"""
7272 for i
in range(sz1):
7273 v[i] = es[i].as_ast()
7275 e = es[sz1].as_ast()
7279 self.
ctxctx.ref(),
"benchmark generated from python API",
"",
"unknown",
"", sz1, v, e,
7284 """Create a solver customized for the given logic.
7286 The parameter `logic` is a string. It should be contains
7287 the name of a SMT-LIB logic.
7288 See http://www.smtlib.org/ for the name of all available logics.
7290 >>> s = SolverFor("QF_LIA")
7305 """Return a simple general purpose solver with limited amount of preprocessing.
7307 >>> s = SimpleSolver()
7324 """Fixedpoint API provides methods for solving with recursive predicates"""
7327 assert fixedpoint
is None or ctx
is not None
7330 if fixedpoint
is None:
7341 if self.
fixedpointfixedpoint
is not None and self.
ctxctx.ref()
is not None:
7345 """Set a configuration option. The method `help()` return a string containing all available options.
7351 """Display a string describing all available options."""
7355 """Return the parameter description set."""
7359 """Assert constraints as background axioms for the fixedpoint solver."""
7360 args = _get_args(args)
7363 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7373 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7381 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7385 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7389 """Assert rules defining recursive predicates to the fixedpoint solver.
7392 >>> s = Fixedpoint()
7393 >>> s.register_relation(a.decl())
7394 >>> s.register_relation(b.decl())
7407 body = _get_args(body)
7411 def rule(self, head, body=None, name=None):
7412 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7413 self.
add_ruleadd_rule(head, body, name)
7416 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7417 self.
add_ruleadd_rule(head,
None, name)
7420 """Query the fixedpoint engine whether formula is derivable.
7421 You can also pass an tuple or list of recursive predicates.
7423 query = _get_args(query)
7425 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7426 _decls = (FuncDecl * sz)()
7436 query =
And(query, self.
ctxctx)
7437 query = self.
abstractabstract(query,
False)
7442 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7444 query = _get_args(query)
7446 if sz >= 1
and isinstance(query[0], FuncDecl):
7447 _z3_assert(
False,
"unsupported")
7453 query = self.
abstractabstract(query,
False)
7454 r = Z3_fixedpoint_query_from_lvl(self.
ctxctx.ref(), self.
fixedpointfixedpoint, query.as_ast(), lvl)
7462 body = _get_args(body)
7467 """Retrieve answer from last query call."""
7469 return _to_expr_ref(r, self.
ctxctx)
7472 """Retrieve a ground cex from last query call."""
7473 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctxctx.ref(), self.
fixedpointfixedpoint)
7474 return _to_expr_ref(r, self.
ctxctx)
7477 """retrieve rules along the counterexample trace"""
7481 """retrieve rule names along the counterexample trace"""
7484 names = _symbol2py(self.
ctxctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctxctx.ref(), self.
fixedpointfixedpoint))
7486 return names.split(
";")
7489 """Retrieve number of levels used for predicate in PDR engine"""
7493 """Retrieve properties known about predicate for the level'th unfolding.
7494 -1 is treated as the limit (infinity)
7497 return _to_expr_ref(r, self.
ctxctx)
7500 """Add property to predicate for the level'th unfolding.
7501 -1 is treated as infinity (infinity)
7506 """Register relation as recursive"""
7507 relations = _get_args(relations)
7512 """Control how relation is represented"""
7513 representations = _get_args(representations)
7514 representations = [
to_symbol(s)
for s
in representations]
7515 sz = len(representations)
7516 args = (Symbol * sz)()
7518 args[i] = representations[i]
7522 """Parse rules and queries from a string"""
7526 """Parse rules and queries from a file"""
7530 """retrieve rules that have been added to fixedpoint context"""
7534 """retrieve assertions that have been added to fixedpoint context"""
7538 """Return a formatted string with all added rules and constraints."""
7539 return self.
sexprsexpr()
7542 """Return a formatted string (in Lisp-like format) with all added constraints.
7543 We say the string is in s-expression format.
7548 """Return a formatted string (in Lisp-like format) with all added constraints.
7549 We say the string is in s-expression format.
7550 Include also queries.
7552 args, len = _to_ast_array(queries)
7556 """Return statistics for the last `query()`.
7561 """Return a string describing why the last `query()` returned `unknown`.
7566 """Add variable or several variables.
7567 The added variable or variables will be bound in the rules
7570 vars = _get_args(vars)
7572 self.
varsvars += [v]
7575 if self.
varsvars == []:
7590 """Finite domain sort."""
7593 """Return the size of the finite domain sort"""
7594 r = (ctypes.c_ulonglong * 1)()
7598 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7602 """Create a named finite domain sort of a given size sz"""
7603 if not isinstance(name, Symbol):
7610 """Return True if `s` is a Z3 finite-domain sort.
7612 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7614 >>> is_finite_domain_sort(IntSort())
7617 return isinstance(s, FiniteDomainSortRef)
7621 """Finite-domain expressions."""
7624 """Return the sort of the finite-domain expression `self`."""
7628 """Return a Z3 floating point expression as a Python string."""
7633 """Return `True` if `a` is a Z3 finite-domain expression.
7635 >>> s = FiniteDomainSort('S', 100)
7636 >>> b = Const('b', s)
7637 >>> is_finite_domain(b)
7639 >>> is_finite_domain(Int('x'))
7642 return isinstance(a, FiniteDomainRef)
7646 """Integer values."""
7649 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7651 >>> s = FiniteDomainSort('S', 100)
7652 >>> v = FiniteDomainVal(3, s)
7661 """Return a Z3 finite-domain numeral as a Python string.
7663 >>> s = FiniteDomainSort('S', 100)
7664 >>> v = FiniteDomainVal(42, s)
7672 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7674 >>> s = FiniteDomainSort('S', 256)
7675 >>> FiniteDomainVal(255, s)
7677 >>> FiniteDomainVal('100', s)
7687 """Return `True` if `a` is a Z3 finite-domain value.
7689 >>> s = FiniteDomainSort('S', 100)
7690 >>> b = Const('b', s)
7691 >>> is_finite_domain_value(b)
7693 >>> b = FiniteDomainVal(10, s)
7696 >>> is_finite_domain_value(b)
7711 self.
_value_value = value
7732 return self.
upperupper()
7734 return self.
lowerlower()
7743 def _global_on_model(ctx):
7744 (fn, mdl) = _on_models[ctx]
7748 _on_model_eh = on_model_eh_type(_global_on_model)
7752 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7764 if self.
optimizeoptimize
is not None and self.
ctxctx.ref()
is not None:
7770 """Set a configuration option.
7771 The method `help()` return a string containing all available options.
7777 """Display a string describing all available options."""
7781 """Return the parameter description set."""
7785 """Assert constraints as background axioms for the optimize solver."""
7786 args = _get_args(args)
7789 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7797 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7805 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7807 If `p` is a string, it will be automatically converted into a Boolean constant.
7812 >>> s.assert_and_track(x > 0, 'p1')
7813 >>> s.assert_and_track(x != 1, 'p2')
7814 >>> s.assert_and_track(x < 0, p3)
7815 >>> print(s.check())
7817 >>> c = s.unsat_core()
7827 if isinstance(p, str):
7829 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7830 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7834 """Add soft constraint with optional weight and optional identifier.
7835 If no weight is supplied, then the penalty for violating the soft constraint
7837 Soft constraints are grouped by identifiers. Soft constraints that are
7838 added without identifiers are grouped by default.
7841 weight =
"%d" % weight
7842 elif isinstance(weight, float):
7843 weight =
"%f" % weight
7844 if not isinstance(weight, str):
7845 raise Z3Exception(
"weight should be a string or an integer")
7853 if sys.version_info.major >= 3
and isinstance(arg, Iterable):
7854 return [asoft(a)
for a
in arg]
7858 """Add objective function to maximize."""
7866 """Add objective function to minimize."""
7874 """create a backtracking point for added rules, facts and assertions"""
7878 """restore to previously created backtracking point"""
7882 """Check satisfiability while optimizing objective functions."""
7883 assumptions = _get_args(assumptions)
7884 num = len(assumptions)
7885 _assumptions = (Ast * num)()
7886 for i
in range(num):
7887 _assumptions[i] = assumptions[i].as_ast()
7891 """Return a string that describes why the last `check()` returned `unknown`."""
7895 """Return a model for the last check()."""
7899 raise Z3Exception(
"model is not available")
7905 if not isinstance(obj, OptimizeObjective):
7906 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7910 if not isinstance(obj, OptimizeObjective):
7911 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7915 if not isinstance(obj, OptimizeObjective):
7916 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7917 return obj.lower_values()
7920 if not isinstance(obj, OptimizeObjective):
7921 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7922 return obj.upper_values()
7925 """Parse assertions and objectives from a file"""
7929 """Parse assertions and objectives from a string"""
7933 """Return an AST vector containing all added constraints."""
7937 """returns set of objective functions"""
7941 """Return a formatted string with all added rules and constraints."""
7942 return self.
sexprsexpr()
7945 """Return a formatted string (in Lisp-like format) with all added constraints.
7946 We say the string is in s-expression format.
7951 """Return statistics for the last check`.
7956 """Register a callback that is invoked with every incremental improvement to
7957 objective values. The callback takes a model as argument.
7958 The life-time of the model is limited to the callback so the
7959 model has to be (deep) copied if it is to be used after the callback
7961 id = len(_on_models) + 41
7963 _on_models[id] = (on_model, mdl)
7966 self.
ctxctx.ref(), self.
optimizeoptimize, mdl.model, ctypes.c_void_p(id), _on_model_eh,
7976 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal.
7977 It also contains model and proof converters.
7989 if self.
ctxctx.ref()
is not None:
7993 """Return the number of subgoals in `self`.
7995 >>> a, b = Ints('a b')
7997 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7998 >>> t = Tactic('split-clause')
8002 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
8005 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
8012 """Return one of the subgoals stored in ApplyResult object `self`.
8014 >>> a, b = Ints('a b')
8016 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
8017 >>> t = Tactic('split-clause')
8020 [a == 0, Or(b == 0, b == 1), a > b]
8022 [a == 1, Or(b == 0, b == 1), a > b]
8024 if idx >= len(self):
8029 return obj_to_string(self)
8032 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
8036 """Return a Z3 expression consisting of all subgoals.
8041 >>> g.add(Or(x == 2, x == 3))
8042 >>> r = Tactic('simplify')(g)
8044 [[Not(x <= 1), Or(x == 2, x == 3)]]
8046 And(Not(x <= 1), Or(x == 2, x == 3))
8047 >>> r = Tactic('split-clause')(g)
8049 [[x > 1, x == 2], [x > 1, x == 3]]
8051 Or(And(x > 1, x == 2), And(x > 1, x == 3))
8069 """Tactics transform, solver and/or simplify sets of constraints (Goal).
8070 A Tactic can be converted into a Solver using the method solver().
8072 Several combinators are available for creating new tactics using the built-in ones:
8073 Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
8079 if isinstance(tactic, TacticObj):
8080 self.
tactictactic = tactic
8083 _z3_assert(isinstance(tactic, str),
"tactic name expected")
8087 raise Z3Exception(
"unknown tactic '%s'" % tactic)
8094 if self.
tactictactic
is not None and self.
ctxctx.ref()
is not None:
8098 """Create a solver using the tactic `self`.
8100 The solver supports the methods `push()` and `pop()`, but it
8101 will always solve each `check()` from scratch.
8103 >>> t = Then('simplify', 'nlsat')
8106 >>> s.add(x**2 == 2, x > 0)
8114 def apply(self, goal, *arguments, **keywords):
8115 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8117 >>> x, y = Ints('x y')
8118 >>> t = Tactic('solve-eqs')
8119 >>> t.apply(And(x == 0, y >= x + 1))
8123 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expressions expected")
8124 goal = _to_goal(goal)
8125 if len(arguments) > 0
or len(keywords) > 0:
8132 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8134 >>> x, y = Ints('x y')
8135 >>> t = Tactic('solve-eqs')
8136 >>> t(And(x == 0, y >= x + 1))
8139 return self.
applyapply(goal, *arguments, **keywords)
8142 """Display a string containing a description of the available options for the `self` tactic."""
8146 """Return the parameter description set."""
8151 if isinstance(a, BoolRef):
8152 goal =
Goal(ctx=a.ctx)
8159 def _to_tactic(t, ctx=None):
8160 if isinstance(t, Tactic):
8166 def _and_then(t1, t2, ctx=None):
8167 t1 = _to_tactic(t1, ctx)
8168 t2 = _to_tactic(t2, ctx)
8170 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8174 def _or_else(t1, t2, ctx=None):
8175 t1 = _to_tactic(t1, ctx)
8176 t2 = _to_tactic(t2, ctx)
8178 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8183 """Return a tactic that applies the tactics in `*ts` in sequence.
8185 >>> x, y = Ints('x y')
8186 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
8187 >>> t(And(x == 0, y > x + 1))
8189 >>> t(And(x == 0, y > x + 1)).as_expr()
8193 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8194 ctx = ks.get(
"ctx",
None)
8197 for i
in range(num - 1):
8198 r = _and_then(r, ts[i + 1], ctx)
8203 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8205 >>> x, y = Ints('x y')
8206 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
8207 >>> t(And(x == 0, y > x + 1))
8209 >>> t(And(x == 0, y > x + 1)).as_expr()
8216 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8219 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
8220 >>> # Tactic split-clause fails if there is no clause in the given goal.
8223 >>> t(Or(x == 0, x == 1))
8224 [[x == 0], [x == 1]]
8227 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8228 ctx = ks.get(
"ctx",
None)
8231 for i
in range(num - 1):
8232 r = _or_else(r, ts[i + 1], ctx)
8237 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8240 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
8245 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8246 ctx = _get_ctx(ks.get(
"ctx",
None))
8247 ts = [_to_tactic(t, ctx)
for t
in ts]
8249 _args = (TacticObj * sz)()
8251 _args[i] = ts[i].tactic
8256 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8257 The subgoals are processed in parallel.
8259 >>> x, y = Ints('x y')
8260 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
8261 >>> t(And(Or(x == 1, x == 2), y == x + 1))
8262 [[x == 1, y == 2], [x == 2, y == 3]]
8264 t1 = _to_tactic(t1, ctx)
8265 t2 = _to_tactic(t2, ctx)
8267 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8272 """Alias for ParThen(t1, t2, ctx)."""
8277 """Return a tactic that applies tactic `t` using the given configuration options.
8279 >>> x, y = Ints('x y')
8280 >>> t = With(Tactic('simplify'), som=True)
8281 >>> t((x + 1)*(y + 2) == 0)
8282 [[2*x + y + x*y == -2]]
8284 ctx = keys.pop(
"ctx",
None)
8285 t = _to_tactic(t, ctx)
8291 """Return a tactic that applies tactic `t` using the given configuration options.
8293 >>> x, y = Ints('x y')
8295 >>> p.set("som", True)
8296 >>> t = WithParams(Tactic('simplify'), p)
8297 >>> t((x + 1)*(y + 2) == 0)
8298 [[2*x + y + x*y == -2]]
8300 t = _to_tactic(t,
None)
8305 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8306 or the maximum number of iterations `max` is reached.
8308 >>> x, y = Ints('x y')
8309 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
8310 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
8312 >>> for subgoal in r: print(subgoal)
8313 [x == 0, y == 0, x > y]
8314 [x == 0, y == 1, x > y]
8315 [x == 1, y == 0, x > y]
8316 [x == 1, y == 1, x > y]
8317 >>> t = Then(t, Tactic('propagate-values'))
8321 t = _to_tactic(t, ctx)
8326 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8328 If `t` does not terminate in `ms` milliseconds, then it fails.
8330 t = _to_tactic(t, ctx)
8335 """Return a list of all available tactics in Z3.
8338 >>> l.count('simplify') == 1
8346 """Return a short description for the tactic named `name`.
8348 >>> d = tactic_description('simplify')
8355 """Display a (tabular) description of all available tactics in Z3."""
8358 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8361 print(
'<tr style="background-color:#CFCFCF">')
8366 print(
"<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(
tactic_description(t), 40)))
8374 """Probes are used to inspect a goal (aka problem) and collect information that may be used
8375 to decide which solver and/or preprocessing step will be used.
8381 if isinstance(probe, ProbeObj):
8382 self.
probeprobe = probe
8383 elif isinstance(probe, float):
8385 elif _is_int(probe):
8387 elif isinstance(probe, bool):
8394 _z3_assert(isinstance(probe, str),
"probe name expected")
8398 raise Z3Exception(
"unknown probe '%s'" % probe)
8405 if self.
probeprobe
is not None and self.
ctxctx.ref()
is not None:
8409 """Return a probe that evaluates to "true" when the value returned by `self`
8410 is less than the value returned by `other`.
8412 >>> p = Probe('size') < 10
8423 """Return a probe that evaluates to "true" when the value returned by `self`
8424 is greater than the value returned by `other`.
8426 >>> p = Probe('size') > 10
8437 """Return a probe that evaluates to "true" when the value returned by `self`
8438 is less than or equal to the value returned by `other`.
8440 >>> p = Probe('size') <= 2
8451 """Return a probe that evaluates to "true" when the value returned by `self`
8452 is greater than or equal to the value returned by `other`.
8454 >>> p = Probe('size') >= 2
8465 """Return a probe that evaluates to "true" when the value returned by `self`
8466 is equal to the value returned by `other`.
8468 >>> p = Probe('size') == 2
8479 """Return a probe that evaluates to "true" when the value returned by `self`
8480 is not equal to the value returned by `other`.
8482 >>> p = Probe('size') != 2
8490 p = self.
__eq____eq__(other)
8494 """Evaluate the probe `self` in the given goal.
8496 >>> p = Probe('size')
8506 >>> p = Probe('num-consts')
8509 >>> p = Probe('is-propositional')
8512 >>> p = Probe('is-qflia')
8517 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expression expected")
8518 goal = _to_goal(goal)
8523 """Return `True` if `p` is a Z3 probe.
8525 >>> is_probe(Int('x'))
8527 >>> is_probe(Probe('memory'))
8530 return isinstance(p, Probe)
8533 def _to_probe(p, ctx=None):
8537 return Probe(p, ctx)
8541 """Return a list of all available probes in Z3.
8544 >>> l.count('memory') == 1
8552 """Return a short description for the probe named `name`.
8554 >>> d = probe_description('memory')
8561 """Display a (tabular) description of all available probes in Z3."""
8564 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8567 print(
'<tr style="background-color:#CFCFCF">')
8572 print(
"<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(
probe_description(p), 40)))
8579 def _probe_nary(f, args, ctx):
8581 _z3_assert(len(args) > 0,
"At least one argument expected")
8583 r = _to_probe(args[0], ctx)
8584 for i
in range(num - 1):
8585 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8589 def _probe_and(args, ctx):
8590 return _probe_nary(Z3_probe_and, args, ctx)
8593 def _probe_or(args, ctx):
8594 return _probe_nary(Z3_probe_or, args, ctx)
8598 """Return a tactic that fails if the probe `p` evaluates to true.
8599 Otherwise, it returns the input goal unmodified.
8601 In the following example, the tactic applies 'simplify' if and only if there are
8602 more than 2 constraints in the goal.
8604 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8605 >>> x, y = Ints('x y')
8611 >>> g.add(x == y + 1)
8613 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8615 p = _to_probe(p, ctx)
8620 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8621 Otherwise, it returns the input goal unmodified.
8623 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8624 >>> x, y = Ints('x y')
8630 >>> g.add(x == y + 1)
8632 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8634 p = _to_probe(p, ctx)
8635 t = _to_tactic(t, ctx)
8640 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8642 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8644 p = _to_probe(p, ctx)
8645 t1 = _to_tactic(t1, ctx)
8646 t2 = _to_tactic(t2, ctx)
8657 """Simplify the expression `a` using the given options.
8659 This function has many options. Use `help_simplify` to obtain the complete list.
8663 >>> simplify(x + 1 + y + x + 1)
8665 >>> simplify((x + 1)*(y + 1), som=True)
8667 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8668 And(Not(x == y), Not(x == 1), Not(y == 1))
8669 >>> simplify(And(x == 0, y == 1), elim_and=True)
8670 Not(Or(Not(x == 0), Not(y == 1)))
8673 _z3_assert(
is_expr(a),
"Z3 expression expected")
8674 if len(arguments) > 0
or len(keywords) > 0:
8676 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8678 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8682 """Return a string describing all options available for Z3 `simplify` procedure."""
8687 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8692 """Apply substitution m on t, m is a list of pairs of the form (from, to).
8693 Every occurrence in t of from is replaced with to.
8697 >>> substitute(x + 1, (x, y + 1))
8699 >>> f = Function('f', IntSort(), IntSort())
8700 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8703 if isinstance(m, tuple):
8705 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8708 _z3_assert(
is_expr(t),
"Z3 expression expected")
8709 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(
8710 p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8712 _from = (Ast * num)()
8714 for i
in range(num):
8715 _from[i] = m[i][0].as_ast()
8716 _to[i] = m[i][1].as_ast()
8717 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8721 """Substitute the free variables in t with the expression in m.
8723 >>> v0 = Var(0, IntSort())
8724 >>> v1 = Var(1, IntSort())
8726 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8727 >>> # replace v0 with x+1 and v1 with x
8728 >>> substitute_vars(f(v0, v1), x + 1, x)
8732 _z3_assert(
is_expr(t),
"Z3 expression expected")
8733 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8736 for i
in range(num):
8737 _to[i] = m[i].as_ast()
8742 """Create the sum of the Z3 expressions.
8744 >>> a, b, c = Ints('a b c')
8749 >>> A = IntVector('a', 5)
8751 a__0 + a__1 + a__2 + a__3 + a__4
8753 args = _get_args(args)
8756 ctx = _ctx_from_ast_arg_list(args)
8758 return _reduce(
lambda a, b: a + b, args, 0)
8759 args = _coerce_expr_list(args, ctx)
8761 return _reduce(
lambda a, b: a + b, args, 0)
8763 _args, sz = _to_ast_array(args)
8768 """Create the product of the Z3 expressions.
8770 >>> a, b, c = Ints('a b c')
8771 >>> Product(a, b, c)
8773 >>> Product([a, b, c])
8775 >>> A = IntVector('a', 5)
8777 a__0*a__1*a__2*a__3*a__4
8779 args = _get_args(args)
8782 ctx = _ctx_from_ast_arg_list(args)
8784 return _reduce(
lambda a, b: a * b, args, 1)
8785 args = _coerce_expr_list(args, ctx)
8787 return _reduce(
lambda a, b: a * b, args, 1)
8789 _args, sz = _to_ast_array(args)
8794 """Create an at-most Pseudo-Boolean k constraint.
8796 >>> a, b, c = Bools('a b c')
8797 >>> f = AtMost(a, b, c, 2)
8799 args = _get_args(args)
8801 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8802 ctx = _ctx_from_ast_arg_list(args)
8804 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8805 args1 = _coerce_expr_list(args[:-1], ctx)
8807 _args, sz = _to_ast_array(args1)
8812 """Create an at-most Pseudo-Boolean k constraint.
8814 >>> a, b, c = Bools('a b c')
8815 >>> f = AtLeast(a, b, c, 2)
8817 args = _get_args(args)
8819 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8820 ctx = _ctx_from_ast_arg_list(args)
8822 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8823 args1 = _coerce_expr_list(args[:-1], ctx)
8825 _args, sz = _to_ast_array(args1)
8829 def _reorder_pb_arg(arg):
8831 if not _is_int(b)
and _is_int(a):
8836 def _pb_args_coeffs(args, default_ctx=None):
8837 args = _get_args_ast_list(args)
8839 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8840 args = [_reorder_pb_arg(arg)
for arg
in args]
8841 args, coeffs = zip(*args)
8843 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8844 ctx = _ctx_from_ast_arg_list(args)
8846 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8847 args = _coerce_expr_list(args, ctx)
8848 _args, sz = _to_ast_array(args)
8849 _coeffs = (ctypes.c_int * len(coeffs))()
8850 for i
in range(len(coeffs)):
8851 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8852 _coeffs[i] = coeffs[i]
8853 return ctx, sz, _args, _coeffs
8857 """Create a Pseudo-Boolean inequality k constraint.
8859 >>> a, b, c = Bools('a b c')
8860 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8862 _z3_check_cint_overflow(k,
"k")
8863 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8868 """Create a Pseudo-Boolean inequality k constraint.
8870 >>> a, b, c = Bools('a b c')
8871 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8873 _z3_check_cint_overflow(k,
"k")
8874 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8879 """Create a Pseudo-Boolean inequality k constraint.
8881 >>> a, b, c = Bools('a b c')
8882 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8884 _z3_check_cint_overflow(k,
"k")
8885 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8890 """Solve the constraints `*args`.
8892 This is a simple function for creating demonstrations. It creates a solver,
8893 configure it using the options in `keywords`, adds the constraints
8894 in `args`, and invokes check.
8897 >>> solve(a > 0, a < 2)
8900 show = keywords.pop(
"show",
False)
8908 print(
"no solution")
8910 print(
"failed to solve")
8920 """Solve the constraints `*args` using solver `s`.
8922 This is a simple function for creating demonstrations. It is similar to `solve`,
8923 but it uses the given solver `s`.
8924 It configures solver `s` using the options in `keywords`, adds the constraints
8925 in `args`, and invokes check.
8927 show = keywords.pop(
"show",
False)
8929 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8937 print(
"no solution")
8939 print(
"failed to solve")
8950 def prove(claim, show=False, **keywords):
8951 """Try to prove the given claim.
8953 This is a simple function for creating demonstrations. It tries to prove
8954 `claim` by showing the negation is unsatisfiable.
8956 >>> p, q = Bools('p q')
8957 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8961 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8971 print(
"failed to prove")
8974 print(
"counterexample")
8978 def _solve_html(*args, **keywords):
8979 """Version of function `solve` used in RiSE4Fun."""
8980 show = keywords.pop(
"show",
False)
8985 print(
"<b>Problem:</b>")
8989 print(
"<b>no solution</b>")
8991 print(
"<b>failed to solve</b>")
8998 print(
"<b>Solution:</b>")
9002 def _solve_using_html(s, *args, **keywords):
9003 """Version of function `solve_using` used in RiSE4Fun."""
9004 show = keywords.pop(
"show",
False)
9006 _z3_assert(isinstance(s, Solver),
"Solver object expected")
9010 print(
"<b>Problem:</b>")
9014 print(
"<b>no solution</b>")
9016 print(
"<b>failed to solve</b>")
9023 print(
"<b>Solution:</b>")
9027 def _prove_html(claim, show=False, **keywords):
9028 """Version of function `prove` used in RiSE4Fun."""
9030 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9038 print(
"<b>proved</b>")
9040 print(
"<b>failed to prove</b>")
9043 print(
"<b>counterexample</b>")
9047 def _dict2sarray(sorts, ctx):
9049 _names = (Symbol * sz)()
9050 _sorts = (Sort * sz)()
9055 _z3_assert(isinstance(k, str),
"String expected")
9056 _z3_assert(
is_sort(v),
"Z3 sort expected")
9060 return sz, _names, _sorts
9063 def _dict2darray(decls, ctx):
9065 _names = (Symbol * sz)()
9066 _decls = (FuncDecl * sz)()
9071 _z3_assert(isinstance(k, str),
"String expected")
9075 _decls[i] = v.decl().ast
9079 return sz, _names, _decls
9083 """Parse a string in SMT 2.0 format using the given sorts and decls.
9085 The arguments sorts and decls are Python dictionaries used to initialize
9086 the symbol table used for the SMT 2.0 parser.
9088 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9090 >>> x, y = Ints('x y')
9091 >>> f = Function('f', IntSort(), IntSort())
9092 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
9094 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
9098 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9099 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9104 """Parse a file in SMT 2.0 format using the given sorts and decls.
9106 This function is similar to parse_smt2_string().
9109 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9110 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9122 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
9123 _dflt_fpsort_ebits = 11
9124 _dflt_fpsort_sbits = 53
9128 """Retrieves the global default rounding mode."""
9129 global _dflt_rounding_mode
9130 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9132 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9134 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9136 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9138 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9142 _ROUNDING_MODES = frozenset({
9143 Z3_OP_FPA_RM_TOWARD_ZERO,
9144 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
9145 Z3_OP_FPA_RM_TOWARD_POSITIVE,
9146 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
9147 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
9152 global _dflt_rounding_mode
9154 _dflt_rounding_mode = rm.decl().kind()
9156 _z3_assert(_dflt_rounding_mode
in _ROUNDING_MODES,
"illegal rounding mode")
9157 _dflt_rounding_mode = rm
9161 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9165 global _dflt_fpsort_ebits
9166 global _dflt_fpsort_sbits
9167 _dflt_fpsort_ebits = ebits
9168 _dflt_fpsort_sbits = sbits
9171 def _dflt_rm(ctx=None):
9175 def _dflt_fps(ctx=None):
9179 def _coerce_fp_expr_list(alist, ctx):
9180 first_fp_sort =
None
9183 if first_fp_sort
is None:
9184 first_fp_sort = a.sort()
9185 elif first_fp_sort == a.sort():
9190 first_fp_sort =
None
9194 for i
in range(len(alist)):
9196 is_repr = isinstance(a, str)
and a.contains(
"2**(")
and a.endswith(
")")
9197 if is_repr
or _is_int(a)
or isinstance(a, (float, bool)):
9198 r.append(
FPVal(a,
None, first_fp_sort, ctx))
9201 return _coerce_expr_list(r, ctx)
9207 """Floating-point sort."""
9210 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
9211 >>> b = FPSort(8, 24)
9218 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
9219 >>> b = FPSort(8, 24)
9226 """Try to cast `val` as a floating-point expression.
9227 >>> b = FPSort(8, 24)
9230 >>> b.cast(1.0).sexpr()
9231 '(fp #b0 #x7f #b00000000000000000000000)'
9235 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
9242 """Floating-point 16-bit (half) sort."""
9248 """Floating-point 16-bit (half) sort."""
9254 """Floating-point 32-bit (single) sort."""
9260 """Floating-point 32-bit (single) sort."""
9266 """Floating-point 64-bit (double) sort."""
9272 """Floating-point 64-bit (double) sort."""
9278 """Floating-point 128-bit (quadruple) sort."""
9284 """Floating-point 128-bit (quadruple) sort."""
9290 """"Floating-point rounding mode sort."""
9294 """Return True if `s` is a Z3 floating-point sort.
9296 >>> is_fp_sort(FPSort(8, 24))
9298 >>> is_fp_sort(IntSort())
9301 return isinstance(s, FPSortRef)
9305 """Return True if `s` is a Z3 floating-point rounding mode sort.
9307 >>> is_fprm_sort(FPSort(8, 24))
9309 >>> is_fprm_sort(RNE().sort())
9312 return isinstance(s, FPRMSortRef)
9318 """Floating-point expressions."""
9321 """Return the sort of the floating-point expression `self`.
9323 >>> x = FP('1.0', FPSort(8, 24))
9326 >>> x.sort() == FPSort(8, 24)
9332 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9333 >>> b = FPSort(8, 24)
9340 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9341 >>> b = FPSort(8, 24)
9348 """Return a Z3 floating point expression as a Python string."""
9352 return fpLEQ(self, other, self.
ctxctx)
9355 return fpLT(self, other, self.
ctxctx)
9358 return fpGEQ(self, other, self.
ctxctx)
9361 return fpGT(self, other, self.
ctxctx)
9364 """Create the Z3 expression `self + other`.
9366 >>> x = FP('x', FPSort(8, 24))
9367 >>> y = FP('y', FPSort(8, 24))
9373 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9374 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
9377 """Create the Z3 expression `other + self`.
9379 >>> x = FP('x', FPSort(8, 24))
9383 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9384 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
9387 """Create the Z3 expression `self - other`.
9389 >>> x = FP('x', FPSort(8, 24))
9390 >>> y = FP('y', FPSort(8, 24))
9396 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9397 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
9400 """Create the Z3 expression `other - self`.
9402 >>> x = FP('x', FPSort(8, 24))
9406 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9407 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
9410 """Create the Z3 expression `self * other`.
9412 >>> x = FP('x', FPSort(8, 24))
9413 >>> y = FP('y', FPSort(8, 24))
9421 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9422 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
9425 """Create the Z3 expression `other * self`.
9427 >>> x = FP('x', FPSort(8, 24))
9428 >>> y = FP('y', FPSort(8, 24))
9434 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9435 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
9438 """Create the Z3 expression `+self`."""
9442 """Create the Z3 expression `-self`.
9444 >>> x = FP('x', Float32())
9451 """Create the Z3 expression `self / other`.
9453 >>> x = FP('x', FPSort(8, 24))
9454 >>> y = FP('y', FPSort(8, 24))
9462 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
9463 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
9466 """Create the Z3 expression `other / self`.
9468 >>> x = FP('x', FPSort(8, 24))
9469 >>> y = FP('y', FPSort(8, 24))
9475 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
9476 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
9479 """Create the Z3 expression division `self / other`."""
9480 return self.
__div____div__(other)
9483 """Create the Z3 expression division `other / self`."""
9484 return self.
__rdiv____rdiv__(other)
9487 """Create the Z3 expression mod `self % other`."""
9488 return fpRem(self, other)
9491 """Create the Z3 expression mod `other % self`."""
9492 return fpRem(other, self)
9496 """Floating-point rounding mode expressions"""
9499 """Return a Z3 floating point expression as a Python string."""
9554 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9563 return isinstance(a, FPRMRef)
9567 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9568 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9574 """The sign of the numeral.
9576 >>> x = FPVal(+1.0, FPSort(8, 24))
9579 >>> x = FPVal(-1.0, FPSort(8, 24))
9585 num = (ctypes.c_int)()
9588 raise Z3Exception(
"error retrieving the sign of a numeral.")
9589 return num.value != 0
9591 """The sign of a floating-point numeral as a bit-vector expression.
9593 Remark: NaN's are invalid arguments.
9599 """The significand of the numeral.
9601 >>> x = FPVal(2.5, FPSort(8, 24))
9609 """The significand of the numeral as a long.
9611 >>> x = FPVal(2.5, FPSort(8, 24))
9612 >>> x.significand_as_long()
9617 ptr = (ctypes.c_ulonglong * 1)()
9619 raise Z3Exception(
"error retrieving the significand of a numeral.")
9622 """The significand of the numeral as a bit-vector expression.
9624 Remark: NaN are invalid arguments.
9630 """The exponent of the numeral.
9632 >>> x = FPVal(2.5, FPSort(8, 24))
9640 """The exponent of the numeral as a long.
9642 >>> x = FPVal(2.5, FPSort(8, 24))
9643 >>> x.exponent_as_long()
9648 ptr = (ctypes.c_longlong * 1)()
9650 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9653 """The exponent of the numeral as a bit-vector expression.
9655 Remark: NaNs are invalid arguments.
9661 """Indicates whether the numeral is a NaN."""
9666 """Indicates whether the numeral is +oo or -oo."""
9671 """Indicates whether the numeral is +zero or -zero."""
9676 """Indicates whether the numeral is normal."""
9681 """Indicates whether the numeral is subnormal."""
9686 """Indicates whether the numeral is positive."""
9691 """Indicates whether the numeral is negative."""
9697 The string representation of the numeral.
9699 >>> x = FPVal(20, FPSort(8, 24))
9706 return (
"FPVal(%s, %s)" % (s, self.
sortsortsort()))
9710 """Return `True` if `a` is a Z3 floating-point expression.
9712 >>> b = FP('b', FPSort(8, 24))
9720 return isinstance(a, FPRef)
9724 """Return `True` if `a` is a Z3 floating-point numeral value.
9726 >>> b = FP('b', FPSort(8, 24))
9729 >>> b = FPVal(1.0, FPSort(8, 24))
9735 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9739 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9741 >>> Single = FPSort(8, 24)
9742 >>> Double = FPSort(11, 53)
9745 >>> x = Const('x', Single)
9746 >>> eq(x, FP('x', FPSort(8, 24)))
9753 def _to_float_str(val, exp=0):
9754 if isinstance(val, float):
9758 sone = math.copysign(1.0, val)
9763 elif val == float(
"+inf"):
9765 elif val == float(
"-inf"):
9768 v = val.as_integer_ratio()
9771 rvs = str(num) +
"/" + str(den)
9772 res = rvs +
"p" + _to_int_str(exp)
9773 elif isinstance(val, bool):
9780 elif isinstance(val, str):
9781 inx = val.find(
"*(2**")
9784 elif val[-1] ==
")":
9786 exp = str(int(val[inx + 5:-1]) + int(exp))
9788 _z3_assert(
False,
"String does not have floating-point numeral form.")
9790 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9794 return res +
"p" + exp
9798 """Create a Z3 floating-point NaN term.
9800 >>> s = FPSort(8, 24)
9801 >>> set_fpa_pretty(True)
9804 >>> pb = get_fpa_pretty()
9805 >>> set_fpa_pretty(False)
9807 fpNaN(FPSort(8, 24))
9808 >>> set_fpa_pretty(pb)
9810 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9815 """Create a Z3 floating-point +oo term.
9817 >>> s = FPSort(8, 24)
9818 >>> pb = get_fpa_pretty()
9819 >>> set_fpa_pretty(True)
9820 >>> fpPlusInfinity(s)
9822 >>> set_fpa_pretty(False)
9823 >>> fpPlusInfinity(s)
9824 fpPlusInfinity(FPSort(8, 24))
9825 >>> set_fpa_pretty(pb)
9827 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9832 """Create a Z3 floating-point -oo term."""
9833 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9838 """Create a Z3 floating-point +oo or -oo term."""
9839 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9840 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9845 """Create a Z3 floating-point +0.0 term."""
9846 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9851 """Create a Z3 floating-point -0.0 term."""
9852 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9857 """Create a Z3 floating-point +0.0 or -0.0 term."""
9858 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9859 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9863 def FPVal(sig, exp=None, fps=None, ctx=None):
9864 """Return a floating-point value of value `val` and sort `fps`.
9865 If `ctx=None`, then the global context is used.
9867 >>> v = FPVal(20.0, FPSort(8, 24))
9870 >>> print("0x%.8x" % v.exponent_as_long(False))
9872 >>> v = FPVal(2.25, FPSort(8, 24))
9875 >>> v = FPVal(-2.25, FPSort(8, 24))
9878 >>> FPVal(-0.0, FPSort(8, 24))
9880 >>> FPVal(0.0, FPSort(8, 24))
9882 >>> FPVal(+0.0, FPSort(8, 24))
9890 fps = _dflt_fps(ctx)
9894 val = _to_float_str(sig)
9895 if val ==
"NaN" or val ==
"nan":
9899 elif val ==
"0.0" or val ==
"+0.0":
9901 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9903 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9909 def FP(name, fpsort, ctx=None):
9910 """Return a floating-point constant named `name`.
9911 `fpsort` is the floating-point sort.
9912 If `ctx=None`, then the global context is used.
9914 >>> x = FP('x', FPSort(8, 24))
9921 >>> word = FPSort(8, 24)
9922 >>> x2 = FP('x', word)
9926 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9933 def FPs(names, fpsort, ctx=None):
9934 """Return an array of floating-point constants.
9936 >>> x, y, z = FPs('x y z', FPSort(8, 24))
9943 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9944 fpMul(RNE(), fpAdd(RNE(), x, y), z)
9947 if isinstance(names, str):
9948 names = names.split(
" ")
9949 return [
FP(name, fpsort, ctx)
for name
in names]
9953 """Create a Z3 floating-point absolute value expression.
9955 >>> s = FPSort(8, 24)
9957 >>> x = FPVal(1.0, s)
9960 >>> y = FPVal(-20.0, s)
9965 >>> fpAbs(-1.25*(2**4))
9971 [a] = _coerce_fp_expr_list([a], ctx)
9976 """Create a Z3 floating-point addition expression.
9978 >>> s = FPSort(8, 24)
9987 [a] = _coerce_fp_expr_list([a], ctx)
9991 def _mk_fp_unary(f, rm, a, ctx):
9993 [a] = _coerce_fp_expr_list([a], ctx)
9995 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9996 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9997 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10000 def _mk_fp_unary_pred(f, a, ctx):
10001 ctx = _get_ctx(ctx)
10002 [a] = _coerce_fp_expr_list([a], ctx)
10004 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
10005 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10008 def _mk_fp_bin(f, rm, a, b, ctx):
10009 ctx = _get_ctx(ctx)
10010 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10012 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10013 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
10014 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10017 def _mk_fp_bin_norm(f, a, b, ctx):
10018 ctx = _get_ctx(ctx)
10019 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10021 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10022 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10025 def _mk_fp_bin_pred(f, a, b, ctx):
10026 ctx = _get_ctx(ctx)
10027 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10029 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10030 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10033 def _mk_fp_tern(f, rm, a, b, c, ctx):
10034 ctx = _get_ctx(ctx)
10035 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10037 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10039 c),
"Second, third or fourth argument must be a Z3 floating-point expression")
10040 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10044 """Create a Z3 floating-point addition expression.
10046 >>> s = FPSort(8, 24)
10050 >>> fpAdd(rm, x, y)
10052 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
10054 >>> fpAdd(rm, x, y).sort()
10057 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10061 """Create a Z3 floating-point subtraction expression.
10063 >>> s = FPSort(8, 24)
10067 >>> fpSub(rm, x, y)
10069 >>> fpSub(rm, x, y).sort()
10072 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10076 """Create a Z3 floating-point multiplication expression.
10078 >>> s = FPSort(8, 24)
10082 >>> fpMul(rm, x, y)
10084 >>> fpMul(rm, x, y).sort()
10087 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10091 """Create a Z3 floating-point division expression.
10093 >>> s = FPSort(8, 24)
10097 >>> fpDiv(rm, x, y)
10099 >>> fpDiv(rm, x, y).sort()
10102 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10106 """Create a Z3 floating-point remainder expression.
10108 >>> s = FPSort(8, 24)
10113 >>> fpRem(x, y).sort()
10116 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10120 """Create a Z3 floating-point minimum expression.
10122 >>> s = FPSort(8, 24)
10128 >>> fpMin(x, y).sort()
10131 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10135 """Create a Z3 floating-point maximum expression.
10137 >>> s = FPSort(8, 24)
10143 >>> fpMax(x, y).sort()
10146 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10150 """Create a Z3 floating-point fused multiply-add expression.
10152 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10156 """Create a Z3 floating-point square root expression.
10158 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10162 """Create a Z3 floating-point roundToIntegral expression.
10164 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10168 """Create a Z3 floating-point isNaN expression.
10170 >>> s = FPSort(8, 24)
10176 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10180 """Create a Z3 floating-point isInfinite expression.
10182 >>> s = FPSort(8, 24)
10187 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10191 """Create a Z3 floating-point isZero expression.
10193 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10197 """Create a Z3 floating-point isNormal expression.
10199 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10203 """Create a Z3 floating-point isSubnormal expression.
10205 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10209 """Create a Z3 floating-point isNegative expression.
10211 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10215 """Create a Z3 floating-point isPositive expression.
10217 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10220 def _check_fp_args(a, b):
10222 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10226 """Create the Z3 floating-point expression `other < self`.
10228 >>> x, y = FPs('x y', FPSort(8, 24))
10231 >>> (x < y).sexpr()
10234 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10238 """Create the Z3 floating-point expression `other <= self`.
10240 >>> x, y = FPs('x y', FPSort(8, 24))
10243 >>> (x <= y).sexpr()
10246 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10250 """Create the Z3 floating-point expression `other > self`.
10252 >>> x, y = FPs('x y', FPSort(8, 24))
10255 >>> (x > y).sexpr()
10258 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10262 """Create the Z3 floating-point expression `other >= self`.
10264 >>> x, y = FPs('x y', FPSort(8, 24))
10267 >>> (x >= y).sexpr()
10270 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10274 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10276 >>> x, y = FPs('x y', FPSort(8, 24))
10279 >>> fpEQ(x, y).sexpr()
10282 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10286 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10288 >>> x, y = FPs('x y', FPSort(8, 24))
10291 >>> (x != y).sexpr()
10298 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10300 >>> s = FPSort(8, 24)
10301 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
10303 fpFP(1, 127, 4194304)
10304 >>> xv = FPVal(-1.5, s)
10307 >>> slvr = Solver()
10308 >>> slvr.add(fpEQ(x, xv))
10311 >>> xv = FPVal(+1.5, s)
10314 >>> slvr = Solver()
10315 >>> slvr.add(fpEQ(x, xv))
10319 _z3_assert(
is_bv(sgn)
and is_bv(exp)
and is_bv(sig),
"sort mismatch")
10320 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
10321 ctx = _get_ctx(ctx)
10322 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
10327 """Create a Z3 floating-point conversion expression from other term sorts
10330 From a bit-vector term in IEEE 754-2008 format:
10331 >>> x = FPVal(1.0, Float32())
10332 >>> x_bv = fpToIEEEBV(x)
10333 >>> simplify(fpToFP(x_bv, Float32()))
10336 From a floating-point term with different precision:
10337 >>> x = FPVal(1.0, Float32())
10338 >>> x_db = fpToFP(RNE(), x, Float64())
10343 >>> x_r = RealVal(1.5)
10344 >>> simplify(fpToFP(RNE(), x_r, Float32()))
10347 From a signed bit-vector term:
10348 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10349 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
10352 ctx = _get_ctx(ctx)
10362 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
10366 """Create a Z3 floating-point conversion expression that represents the
10367 conversion from a bit-vector term to a floating-point term.
10369 >>> x_bv = BitVecVal(0x3F800000, 32)
10370 >>> x_fp = fpBVToFP(x_bv, Float32())
10376 _z3_assert(
is_bv(v),
"First argument must be a Z3 bit-vector expression")
10377 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
10378 ctx = _get_ctx(ctx)
10383 """Create a Z3 floating-point conversion expression that represents the
10384 conversion from a floating-point term to a floating-point term of different precision.
10386 >>> x_sgl = FPVal(1.0, Float32())
10387 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
10390 >>> simplify(x_dbl)
10395 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10396 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
10397 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10398 ctx = _get_ctx(ctx)
10403 """Create a Z3 floating-point conversion expression that represents the
10404 conversion from a real term to a floating-point term.
10406 >>> x_r = RealVal(1.5)
10407 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
10413 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10414 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
10415 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10416 ctx = _get_ctx(ctx)
10421 """Create a Z3 floating-point conversion expression that represents the
10422 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10424 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10425 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
10427 fpToFP(RNE(), 4294967291)
10431 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10432 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10433 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10434 ctx = _get_ctx(ctx)
10439 """Create a Z3 floating-point conversion expression that represents the
10440 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10442 >>> x_signed = BitVecVal(-5, BitVecSort(32))
10443 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
10445 fpToFPUnsigned(RNE(), 4294967291)
10449 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
10450 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10451 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10452 ctx = _get_ctx(ctx)
10457 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10459 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10460 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
10461 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
10462 ctx = _get_ctx(ctx)
10467 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10469 >>> x = FP('x', FPSort(8, 24))
10470 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
10471 >>> print(is_fp(x))
10473 >>> print(is_bv(y))
10475 >>> print(is_fp(y))
10477 >>> print(is_bv(x))
10481 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10482 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10483 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10484 ctx = _get_ctx(ctx)
10489 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10491 >>> x = FP('x', FPSort(8, 24))
10492 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
10493 >>> print(is_fp(x))
10495 >>> print(is_bv(y))
10497 >>> print(is_fp(y))
10499 >>> print(is_bv(x))
10503 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10504 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10505 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10506 ctx = _get_ctx(ctx)
10511 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10513 >>> x = FP('x', FPSort(8, 24))
10514 >>> y = fpToReal(x)
10515 >>> print(is_fp(x))
10517 >>> print(is_real(y))
10519 >>> print(is_fp(y))
10521 >>> print(is_real(x))
10525 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10526 ctx = _get_ctx(ctx)
10531 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10533 The size of the resulting bit-vector is automatically determined.
10535 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10536 knows only one NaN and it will always produce the same bit-vector representation of
10539 >>> x = FP('x', FPSort(8, 24))
10540 >>> y = fpToIEEEBV(x)
10541 >>> print(is_fp(x))
10543 >>> print(is_bv(y))
10545 >>> print(is_fp(y))
10547 >>> print(is_bv(x))
10551 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10552 ctx = _get_ctx(ctx)
10563 """Sequence sort."""
10566 """Determine if sort is a string
10567 >>> s = StringSort()
10570 >>> s = SeqSort(IntSort())
10580 """Character sort."""
10585 """Create a string sort
10586 >>> s = StringSort()
10590 ctx = _get_ctx(ctx)
10594 """Create a character sort
10595 >>> ch = CharSort()
10599 ctx = _get_ctx(ctx)
10604 """Create a sequence sort over elements provided in the argument
10605 >>> s = SeqSort(IntSort())
10606 >>> s == Unit(IntVal(1)).sort()
10613 """Sequence expression."""
10619 return Concat(self, other)
10622 return Concat(other, self)
10641 """Return a string representation of sequence expression."""
10643 string_length = ctypes.c_uint()
10645 return string_at(chars, size=string_length.value).decode(
"latin-1")
10661 def _coerce_seq(s, ctx=None):
10662 if isinstance(s, str):
10663 ctx = _get_ctx(ctx)
10666 raise Z3Exception(
"Non-expression passed as a sequence")
10668 raise Z3Exception(
"Non-sequence passed as a sequence")
10672 def _get_ctx2(a, b, ctx=None):
10683 """Return `True` if `a` is a Z3 sequence expression.
10684 >>> print (is_seq(Unit(IntVal(0))))
10686 >>> print (is_seq(StringVal("abc")))
10689 return isinstance(a, SeqRef)
10693 """Return `True` if `a` is a Z3 string expression.
10694 >>> print (is_string(StringVal("ab")))
10697 return isinstance(a, SeqRef)
and a.is_string()
10701 """return 'True' if 'a' is a Z3 string constant expression.
10702 >>> print (is_string_value(StringVal("a")))
10704 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10707 return isinstance(a, SeqRef)
and a.is_string_value()
10710 """create a string expression"""
10711 s =
"".join(str(ch)
if 32 <= ord(ch)
and ord(ch) < 127
else "\\u{%x}" % (ord(ch))
for ch
in s)
10712 ctx = _get_ctx(ctx)
10717 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10719 >>> x = String('x')
10721 ctx = _get_ctx(ctx)
10726 """Return a tuple of String constants. """
10727 ctx = _get_ctx(ctx)
10728 if isinstance(names, str):
10729 names = names.split(
" ")
10730 return [
String(name, ctx)
for name
in names]
10734 """Extract substring or subsequence starting at offset"""
10735 return Extract(s, offset, length)
10739 """Extract substring or subsequence starting at offset"""
10740 return Extract(s, offset, length)
10744 """Create the empty sequence of the given sort
10745 >>> e = Empty(StringSort())
10746 >>> e2 = StringVal("")
10747 >>> print(e.eq(e2))
10749 >>> e3 = Empty(SeqSort(IntSort()))
10752 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10754 Empty(ReSort(Seq(Int)))
10756 if isinstance(s, SeqSortRef):
10758 if isinstance(s, ReSortRef):
10760 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10764 """Create the regular expression that accepts the universal language
10765 >>> e = Full(ReSort(SeqSort(IntSort())))
10767 Full(ReSort(Seq(Int)))
10768 >>> e1 = Full(ReSort(StringSort()))
10770 Full(ReSort(String))
10772 if isinstance(s, ReSortRef):
10774 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10778 """Create a singleton sequence"""
10783 """Check if 'a' is a prefix of 'b'
10784 >>> s1 = PrefixOf("ab", "abc")
10787 >>> s2 = PrefixOf("bc", "abc")
10791 ctx = _get_ctx2(a, b)
10792 a = _coerce_seq(a, ctx)
10793 b = _coerce_seq(b, ctx)
10798 """Check if 'a' is a suffix of 'b'
10799 >>> s1 = SuffixOf("ab", "abc")
10802 >>> s2 = SuffixOf("bc", "abc")
10806 ctx = _get_ctx2(a, b)
10807 a = _coerce_seq(a, ctx)
10808 b = _coerce_seq(b, ctx)
10813 """Check if 'a' contains 'b'
10814 >>> s1 = Contains("abc", "ab")
10817 >>> s2 = Contains("abc", "bc")
10820 >>> x, y, z = Strings('x y z')
10821 >>> s3 = Contains(Concat(x,y,z), y)
10825 ctx = _get_ctx2(a, b)
10826 a = _coerce_seq(a, ctx)
10827 b = _coerce_seq(b, ctx)
10832 """Replace the first occurrence of 'src' by 'dst' in 's'
10833 >>> r = Replace("aaa", "a", "b")
10837 ctx = _get_ctx2(dst, s)
10838 if ctx
is None and is_expr(src):
10840 src = _coerce_seq(src, ctx)
10841 dst = _coerce_seq(dst, ctx)
10842 s = _coerce_seq(s, ctx)
10847 """Retrieve the index of substring within a string starting at a specified offset.
10848 >>> simplify(IndexOf("abcabc", "bc", 0))
10850 >>> simplify(IndexOf("abcabc", "bc", 2))
10858 ctx = _get_ctx2(s, substr, ctx)
10859 s = _coerce_seq(s, ctx)
10860 substr = _coerce_seq(substr, ctx)
10861 if _is_int(offset):
10862 offset =
IntVal(offset, ctx)
10867 """Retrieve the last index of substring within a string"""
10869 ctx = _get_ctx2(s, substr, ctx)
10870 s = _coerce_seq(s, ctx)
10871 substr = _coerce_seq(substr, ctx)
10876 """Obtain the length of a sequence 's'
10877 >>> l = Length(StringVal("abc"))
10886 """Convert string expression to integer
10887 >>> a = StrToInt("1")
10888 >>> simplify(1 == a)
10890 >>> b = StrToInt("2")
10891 >>> simplify(1 == b)
10893 >>> c = StrToInt(IntToStr(2))
10894 >>> simplify(1 == c)
10902 """Convert integer expression to string"""
10909 """The regular expression that accepts sequence 's'
10911 >>> s2 = Re(StringVal("ab"))
10912 >>> s3 = Re(Unit(BoolVal(True)))
10914 s = _coerce_seq(s, ctx)
10921 """Regular expression sort."""
10930 if s
is None or isinstance(s, Context):
10933 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10937 """Regular expressions."""
10940 return Union(self, other)
10944 return isinstance(s, ReRef)
10948 """Create regular expression membership test
10949 >>> re = Union(Re("a"),Re("b"))
10950 >>> print (simplify(InRe("a", re)))
10952 >>> print (simplify(InRe("b", re)))
10954 >>> print (simplify(InRe("c", re)))
10957 s = _coerce_seq(s, re.ctx)
10962 """Create union of regular expressions.
10963 >>> re = Union(Re("a"), Re("b"), Re("c"))
10964 >>> print (simplify(InRe("d", re)))
10967 args = _get_args(args)
10970 _z3_assert(sz > 0,
"At least one argument expected.")
10971 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10976 for i
in range(sz):
10977 v[i] = args[i].as_ast()
10982 """Create intersection of regular expressions.
10983 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
10985 args = _get_args(args)
10988 _z3_assert(sz > 0,
"At least one argument expected.")
10989 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10994 for i
in range(sz):
10995 v[i] = args[i].as_ast()
11000 """Create the regular expression accepting one or more repetitions of argument.
11001 >>> re = Plus(Re("a"))
11002 >>> print(simplify(InRe("aa", re)))
11004 >>> print(simplify(InRe("ab", re)))
11006 >>> print(simplify(InRe("", re)))
11013 """Create the regular expression that optionally accepts the argument.
11014 >>> re = Option(Re("a"))
11015 >>> print(simplify(InRe("a", re)))
11017 >>> print(simplify(InRe("", re)))
11019 >>> print(simplify(InRe("aa", re)))
11026 """Create the complement regular expression."""
11031 """Create the regular expression accepting zero or more repetitions of argument.
11032 >>> re = Star(Re("a"))
11033 >>> print(simplify(InRe("aa", re)))
11035 >>> print(simplify(InRe("ab", re)))
11037 >>> print(simplify(InRe("", re)))
11044 """Create the regular expression accepting between a lower and upper bound repetitions
11045 >>> re = Loop(Re("a"), 1, 3)
11046 >>> print(simplify(InRe("aa", re)))
11048 >>> print(simplify(InRe("aaaa", re)))
11050 >>> print(simplify(InRe("", re)))
11057 """Create the range regular expression over two sequences of length 1
11058 >>> range = Range("a","z")
11059 >>> print(simplify(InRe("b", range)))
11061 >>> print(simplify(InRe("bb", range)))
11064 lo = _coerce_seq(lo, ctx)
11065 hi = _coerce_seq(hi, ctx)
11069 """Create the difference regular epression
11074 """Create a regular expression that accepts all single character strings
11098 """Given a binary relation R, such that the two arguments have the same sort
11099 create the transitive closure relation R+.
11100 The transitive closure R+ is a new relation.
11111 if self.
locklock
is None:
11113 self.
locklock = threading.Lock()
11117 with self.
locklock:
11118 r = self.
basesbases[ctx]
11120 r = self.
basesbases[ctx]
11125 with self.
locklock:
11126 self.
basesbases[ctx] = r
11128 self.
basesbases[ctx] = r
11132 with self.
locklock:
11133 id = len(self.
basesbases) + 3
11134 self.
basesbases[id] = r
11136 id = len(self.
basesbases) + 3
11137 self.
basesbases[id] = r
11141 _prop_closures =
None
11145 global _prop_closures
11146 if _prop_closures
is None:
11151 _prop_closures.get(ctx).push()
11155 _prop_closures.get(ctx).pop(num_scopes)
11159 _prop_closures.set_threaded()
11160 prop = _prop_closures.get(id)
11161 new_prop = prop.fresh()
11162 _prop_closures.set(new_prop.id, new_prop)
11163 return ctypes.c_void_p(new_prop.id)
11167 prop = _prop_closures.get(ctx)
11169 prop.fixed(id, _to_expr_ref(ctypes.c_void_p(value), prop.ctx()))
11174 prop = _prop_closures.get(ctx)
11181 prop = _prop_closures.get(ctx)
11188 prop = _prop_closures.get(ctx)
11194 _user_prop_push = push_eh_type(user_prop_push)
11195 _user_prop_pop = pop_eh_type(user_prop_pop)
11196 _user_prop_fresh = fresh_eh_type(user_prop_fresh)
11197 _user_prop_fixed = fixed_eh_type(user_prop_fixed)
11198 _user_prop_final = final_eh_type(user_prop_final)
11199 _user_prop_eq = eq_eh_type(user_prop_eq)
11200 _user_prop_diseq = eq_eh_type(user_prop_diseq)
11213 assert s
is None or ctx
is None
11216 self.
_ctx_ctx =
None
11218 self.
idid = _prop_closures.insert(self)
11233 ctypes.c_void_p(self.
idid),
11240 self.
_ctx_ctx.ctx =
None
11244 return self.
_ctx_ctx
11246 return self.
solversolver.ctx
11249 return self.
ctxctx().ref()
11252 assert not self.
fixedfixed
11253 assert not self.
_ctx_ctx
11255 self.
fixedfixed = fixed
11258 assert not self.
finalfinal
11259 assert not self.
_ctx_ctx
11261 self.
finalfinal = final
11264 assert not self.
eqeq
11265 assert not self.
_ctx_ctx
11270 assert not self.
diseqdiseq
11271 assert not self.
_ctx_ctx
11273 self.
diseqdiseq = diseq
11276 raise Z3Exception(
"push needs to be overwritten")
11279 raise Z3Exception(
"pop needs to be overwritten")
11282 raise Z3Exception(
"fresh needs to be overwritten")
11285 assert self.
solversolver
11286 assert not self.
_ctx_ctx
11293 num_fixed = len(ids)
11294 _ids = (ctypes.c_uint * num_fixed)()
11295 for i
in range(num_fixed):
11298 _lhs = (ctypes.c_uint * num_eqs)()
11299 _rhs = (ctypes.c_uint * num_eqs)()
11300 for i
in range(num_eqs):
11301 _lhs[i] = eqs[i][0]
11302 _rhs[i] = eqs[i][1]
11304 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.
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_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.
unsigned 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_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.
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.
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...
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*.
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.
void Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback, unsigned num_fixed, unsigned const *fixed_ids, unsigned num_eqs, unsigned const *eq_lhs, unsigned const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values. This is a callback a client may invoke during the fixe...
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.
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_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_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).
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...
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.
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_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 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 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 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 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 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 Array(name, dom, rng)
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)