9 """Z3 is a high performance theorem prover developed at Microsoft Research. Z3 is used in many applications such as: software/hardware verification and testing, constraint solving, analysis of hybrid systems, security, biology (in silico analysis), and geometrical problems.
11 Several online tutorials for Z3Py are available at:
12 http://rise4fun.com/Z3Py/tutorial/guide
14 Please send feedback, comments and/or corrections on the Issue tracker for https://github.com/Z3prover/z3.git. Your comments are very valuable.
35 ... x = BitVec('x', 32)
37 ... # the expression x + y is type incorrect
39 ... except Z3Exception as ex:
40 ... print("failed: %s" % ex)
45 from .z3types
import *
46 from .z3consts
import *
47 from .z3printer
import *
48 from fractions
import Fraction
62 return isinstance(v, (int, long))
65 return isinstance(v, int)
74 major = ctypes.c_uint(0)
75 minor = ctypes.c_uint(0)
76 build = ctypes.c_uint(0)
77 rev = ctypes.c_uint(0)
79 return "%s.%s.%s" % (major.value, minor.value, build.value)
82 major = ctypes.c_uint(0)
83 minor = ctypes.c_uint(0)
84 build = ctypes.c_uint(0)
85 rev = ctypes.c_uint(0)
87 return (major.value, minor.value, build.value, rev.value)
94 def _z3_assert(cond, msg):
96 raise Z3Exception(msg)
98 def _z3_check_cint_overflow(n, name):
99 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
102 """Log interaction to a file. This function must be invoked immediately after init(). """
106 """Append user-defined string to interaction log. """
110 """Convert an integer or string into a Z3 symbol."""
116 def _symbol2py(ctx, s):
117 """Convert a Z3 symbol back into a Python object. """
128 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
130 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
131 return [arg
for arg
in args[0]]
138 def _get_args_ast_list(args):
140 if isinstance(args, set)
or isinstance(args, AstVector)
or isinstance(args, tuple):
141 return [arg
for arg
in args]
147 def _to_param_value(val):
148 if isinstance(val, bool):
162 """A Context manages all other Z3 objects, global configuration options, etc.
164 Z3Py uses a default global context. For most applications this is sufficient.
165 An application may use multiple Z3 contexts. Objects created in one context
166 cannot be used in another one. However, several objects may be "translated" from
167 one context to another. It is not safe to access Z3 objects from multiple threads.
168 The only exception is the method `interrupt()` that can be used to interrupt() a long
170 The initialization method receives global configuration options for the new context.
174 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
197 """Return a reference to the actual C pointer to the Z3 context."""
201 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
203 This method can be invoked from a thread different from the one executing the
204 interruptible procedure.
212 """Return a reference to the global Z3 context.
215 >>> x.ctx == main_ctx()
220 >>> x2 = Real('x', c)
227 if _main_ctx
is None:
241 """Set Z3 global (or module) parameters.
243 >>> set_param(precision=10)
246 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
250 if not set_pp_option(k, v):
264 """Reset all global (or module) parameters.
269 """Alias for 'set_param' for backward compatibility.
274 """Return the value of a Z3 global (or module) parameter
276 >>> get_param('nlsat.reorder')
279 ptr = (ctypes.c_char_p * 1)()
281 r = z3core._to_pystr(ptr[0])
283 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
293 """Superclass for all Z3 objects that have support for pretty printing."""
297 def _repr_html_(self):
298 in_html = in_html_mode()
301 set_html_mode(in_html)
306 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
309 self.
ctxctx = _get_ctx(ctx)
313 if self.
ctxctx.ref()
is not None and self.
astast
is not None:
318 return _to_ast_ref(self.
astast, self.
ctxctx)
321 return obj_to_string(self)
324 return obj_to_string(self)
327 return self.
eqeq(other)
330 return self.
hashhash()
340 elif is_eq(self)
and self.num_args() == 2:
341 return self.arg(0).
eq(self.arg(1))
343 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
346 """Return a string representing the AST node in s-expression notation.
349 >>> ((x + 1)*x).sexpr()
355 """Return a pointer to the corresponding C Z3_ast object."""
359 """Return unique identifier for object. It can be used for hash-tables and maps."""
363 """Return a reference to the C context where this AST node is stored."""
364 return self.
ctxctx.ref()
367 """Return `True` if `self` and `other` are structurally identical.
374 >>> n1 = simplify(n1)
375 >>> n2 = simplify(n2)
380 _z3_assert(
is_ast(other),
"Z3 AST expected")
384 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
390 >>> # Nodes in different contexts can't be mixed.
391 >>> # However, we can translate nodes from one context to another.
392 >>> x.translate(c2) + y
396 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
403 """Return a hashcode for the `self`.
405 >>> n1 = simplify(Int('x') + 1)
406 >>> n2 = simplify(2 + Int('x') - 1)
407 >>> n1.hash() == n2.hash()
413 """Return `True` if `a` is an AST node.
417 >>> is_ast(IntVal(10))
421 >>> is_ast(BoolSort())
423 >>> is_ast(Function('f', IntSort(), IntSort()))
430 return isinstance(a, AstRef)
433 """Return `True` if `a` and `b` are structurally identical AST nodes.
443 >>> eq(simplify(x + 1), simplify(1 + x))
450 def _ast_kind(ctx, a):
455 def _ctx_from_ast_arg_list(args, default_ctx=None):
463 _z3_assert(ctx == a.ctx,
"Context mismatch")
468 def _ctx_from_ast_args(*args):
469 return _ctx_from_ast_arg_list(args)
471 def _to_func_decl_array(args):
473 _args = (FuncDecl * sz)()
475 _args[i] = args[i].as_func_decl()
478 def _to_ast_array(args):
482 _args[i] = args[i].as_ast()
485 def _to_ref_array(ref, args):
489 _args[i] = args[i].as_ast()
492 def _to_ast_ref(a, ctx):
493 k = _ast_kind(ctx, a)
495 return _to_sort_ref(a, ctx)
496 elif k == Z3_FUNC_DECL_AST:
497 return _to_func_decl_ref(a, ctx)
499 return _to_expr_ref(a, ctx)
508 def _sort_kind(ctx, s):
512 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
520 """Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts.
523 >>> b.kind() == Z3_BOOL_SORT
525 >>> b.kind() == Z3_INT_SORT
527 >>> A = ArraySort(IntSort(), IntSort())
528 >>> A.kind() == Z3_ARRAY_SORT
530 >>> A.kind() == Z3_INT_SORT
533 return _sort_kind(self.
ctxctx, self.
astast)
536 """Return `True` if `self` is a subsort of `other`.
538 >>> IntSort().subsort(RealSort())
544 """Try to cast `val` as an element of sort `self`.
546 This method is used in Z3Py to convert Python objects such as integers,
547 floats, longs and strings into Z3 expressions.
550 >>> RealSort().cast(x)
554 _z3_assert(
is_expr(val),
"Z3 expression expected")
555 _z3_assert(self.
eqeq(val.sort()),
"Sort mismatch")
559 """Return the name (string) of sort `self`.
561 >>> BoolSort().name()
563 >>> ArraySort(IntSort(), IntSort()).name()
569 """Return `True` if `self` and `other` are the same Z3 sort.
572 >>> p.sort() == BoolSort()
574 >>> p.sort() == IntSort()
582 """Return `True` if `self` and `other` are not the same Z3 sort.
585 >>> p.sort() != BoolSort()
587 >>> p.sort() != IntSort()
594 return AstRef.__hash__(self)
597 """Return `True` if `s` is a Z3 sort.
599 >>> is_sort(IntSort())
601 >>> is_sort(Int('x'))
603 >>> is_expr(Int('x'))
606 return isinstance(s, SortRef)
608 def _to_sort_ref(s, ctx):
610 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
611 k = _sort_kind(ctx, s)
612 if k == Z3_BOOL_SORT:
614 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
616 elif k == Z3_BV_SORT:
618 elif k == Z3_ARRAY_SORT:
620 elif k == Z3_DATATYPE_SORT:
622 elif k == Z3_FINITE_DOMAIN_SORT:
624 elif k == Z3_FLOATING_POINT_SORT:
626 elif k == Z3_ROUNDING_MODE_SORT:
628 elif k == Z3_RE_SORT:
630 elif k == Z3_SEQ_SORT:
635 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
638 """Create a new uninterpreted sort named `name`.
640 If `ctx=None`, then the new sort is declared in the global Z3Py context.
642 >>> A = DeclareSort('A')
643 >>> a = Const('a', A)
644 >>> b = Const('b', A)
662 """Function declaration. Every constant and function have an associated declaration.
664 The declaration assigns a name, a sort (i.e., type), and for function
665 the sort (i.e., type) of each of its arguments. Note that, in Z3,
666 a constant is a function with 0 arguments.
678 """Return the name of the function declaration `self`.
680 >>> f = Function('f', IntSort(), IntSort())
683 >>> isinstance(f.name(), str)
689 """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
691 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
698 """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
700 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
707 _z3_assert(i < self.
arityarity(),
"Index out of bounds")
711 """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
713 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
720 """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
723 >>> d = (x + 1).decl()
724 >>> d.kind() == Z3_OP_ADD
726 >>> d.kind() == Z3_OP_MUL
734 result = [
None for i
in range(n) ]
737 if k == Z3_PARAMETER_INT:
739 elif k == Z3_PARAMETER_DOUBLE:
741 elif k == Z3_PARAMETER_RATIONAL:
743 elif k == Z3_PARAMETER_SYMBOL:
745 elif k == Z3_PARAMETER_SORT:
747 elif k == Z3_PARAMETER_AST:
749 elif k == Z3_PARAMETER_FUNC_DECL:
756 """Create a Z3 application expression using the function `self`, and the given arguments.
758 The arguments must be Z3 expressions. This method assumes that
759 the sorts of the elements in `args` match the sorts of the
760 domain. Limited coercion is supported. For example, if
761 args[0] is a Python integer, and the function expects a Z3
762 integer, then the argument is automatically converted into a
765 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
773 args = _get_args(args)
776 _z3_assert(num == self.
arityarity(),
"Incorrect number of arguments to %s" % self)
777 _args = (Ast * num)()
782 tmp = self.
domaindomain(i).cast(args[i])
784 _args[i] = tmp.as_ast()
788 """Return `True` if `a` is a Z3 function declaration.
790 >>> f = Function('f', IntSort(), IntSort())
797 return isinstance(a, FuncDeclRef)
800 """Create a new Z3 uninterpreted function with the given sorts.
802 >>> f = Function('f', IntSort(), IntSort())
808 _z3_assert(len(sig) > 0,
"At least two arguments expected")
812 _z3_assert(
is_sort(rng),
"Z3 sort expected")
813 dom = (Sort * arity)()
814 for i
in range(arity):
816 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
822 """Create a new fresh Z3 uninterpreted function with the given sorts.
826 _z3_assert(len(sig) > 0,
"At least two arguments expected")
830 _z3_assert(
is_sort(rng),
"Z3 sort expected")
831 dom = (z3.Sort * arity)()
832 for i
in range(arity):
834 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
840 def _to_func_decl_ref(a, ctx):
844 """Create a new Z3 recursive with the given sorts."""
847 _z3_assert(len(sig) > 0,
"At least two arguments expected")
851 _z3_assert(
is_sort(rng),
"Z3 sort expected")
852 dom = (Sort * arity)()
853 for i
in range(arity):
855 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
861 """Set the body of a recursive function.
862 Recursive definitions can be simplified if they are applied to ground
865 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx))
866 >>> n = Int('n', ctx)
867 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1)))
870 >>> s = Solver(ctx=ctx)
871 >>> s.add(fac(n) < 3)
874 >>> s.model().eval(fac(5))
880 args = _get_args(args)
884 _args[i] = args[i].ast
894 """Constraints, formulas and terms are expressions in Z3.
896 Expressions are ASTs. Every expression has a sort.
897 There are three main kinds of expressions:
898 function applications, quantifiers and bounded variables.
899 A constant is a function application with 0 arguments.
900 For quantifier free problems, all expressions are
901 function applications.
910 """Return the sort of expression `self`.
922 """Shorthand for `self.sort().kind()`.
924 >>> a = Array('a', IntSort(), IntSort())
925 >>> a.sort_kind() == Z3_ARRAY_SORT
927 >>> a.sort_kind() == Z3_INT_SORT
930 return self.
sortsort().kind()
933 """Return a Z3 expression that represents the constraint `self == other`.
935 If `other` is `None`, then this method simply returns `False`.
946 a, b = _coerce_exprs(self, other)
951 return AstRef.__hash__(self)
954 """Return a Z3 expression that represents the constraint `self != other`.
956 If `other` is `None`, then this method simply returns `True`.
967 a, b = _coerce_exprs(self, other)
968 _args, sz = _to_ast_array((a, b))
975 """Return the Z3 function declaration associated with a Z3 application.
977 >>> f = Function('f', IntSort(), IntSort())
986 _z3_assert(
is_app(self),
"Z3 application expected")
990 """Return the number of arguments of a Z3 application.
994 >>> (a + b).num_args()
996 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1002 _z3_assert(
is_app(self),
"Z3 application expected")
1006 """Return argument `idx` of the application `self`.
1008 This method assumes that `self` is a function application with at least `idx+1` arguments.
1012 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1022 _z3_assert(
is_app(self),
"Z3 application expected")
1023 _z3_assert(idx < self.
num_argsnum_args(),
"Invalid argument index")
1027 """Return a list containing the children of the given expression
1031 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort())
1041 def _to_expr_ref(a, ctx):
1042 if isinstance(a, Pattern):
1046 if k == Z3_QUANTIFIER_AST:
1049 if sk == Z3_BOOL_SORT:
1051 if sk == Z3_INT_SORT:
1052 if k == Z3_NUMERAL_AST:
1055 if sk == Z3_REAL_SORT:
1056 if k == Z3_NUMERAL_AST:
1058 if _is_algebraic(ctx, a):
1061 if sk == Z3_BV_SORT:
1062 if k == Z3_NUMERAL_AST:
1066 if sk == Z3_ARRAY_SORT:
1068 if sk == Z3_DATATYPE_SORT:
1070 if sk == Z3_FLOATING_POINT_SORT:
1071 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1074 return FPRef(a, ctx)
1075 if sk == Z3_FINITE_DOMAIN_SORT:
1076 if k == Z3_NUMERAL_AST:
1080 if sk == Z3_ROUNDING_MODE_SORT:
1082 if sk == Z3_SEQ_SORT:
1084 if sk == Z3_RE_SORT:
1085 return ReRef(a, ctx)
1088 def _coerce_expr_merge(s, a):
1101 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1102 _z3_assert(
False,
"sort mismatch")
1106 def _coerce_exprs(a, b, ctx=None):
1108 a = _py2expr(a, ctx)
1109 b = _py2expr(b, ctx)
1111 s = _coerce_expr_merge(s, a)
1112 s = _coerce_expr_merge(s, b)
1118 def _reduce(f, l, a):
1124 def _coerce_expr_list(alist, ctx=None):
1131 alist = [ _py2expr(a, ctx)
for a
in alist ]
1132 s = _reduce(_coerce_expr_merge, alist,
None)
1133 return [ s.cast(a)
for a
in alist ]
1136 """Return `True` if `a` is a Z3 expression.
1143 >>> is_expr(IntSort())
1147 >>> is_expr(IntVal(1))
1150 >>> is_expr(ForAll(x, x >= 0))
1152 >>> is_expr(FPVal(1.0))
1155 return isinstance(a, ExprRef)
1158 """Return `True` if `a` is a Z3 function application.
1160 Note that, constants are function applications with 0 arguments.
1167 >>> is_app(IntSort())
1171 >>> is_app(IntVal(1))
1174 >>> is_app(ForAll(x, x >= 0))
1177 if not isinstance(a, ExprRef):
1179 k = _ast_kind(a.ctx, a)
1180 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1183 """Return `True` if `a` is Z3 constant/variable expression.
1192 >>> is_const(IntVal(1))
1195 >>> is_const(ForAll(x, x >= 0))
1198 return is_app(a)
and a.num_args() == 0
1201 """Return `True` if `a` is variable.
1203 Z3 uses de-Bruijn indices for representing bound variables in
1211 >>> f = Function('f', IntSort(), IntSort())
1212 >>> # Z3 replaces x with bound variables when ForAll is executed.
1213 >>> q = ForAll(x, f(x) == x)
1219 >>> is_var(b.arg(1))
1222 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1225 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1233 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1234 >>> # Z3 replaces x and y with bound variables when ForAll is executed.
1235 >>> q = ForAll([x, y], f(x, y) == x + y)
1237 f(Var(1), Var(0)) == Var(1) + Var(0)
1241 >>> v1 = b.arg(0).arg(0)
1242 >>> v2 = b.arg(0).arg(1)
1247 >>> get_var_index(v1)
1249 >>> get_var_index(v2)
1253 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1257 """Return `True` if `a` is an application of the given kind `k`.
1261 >>> is_app_of(n, Z3_OP_ADD)
1263 >>> is_app_of(n, Z3_OP_MUL)
1266 return is_app(a)
and a.decl().kind() == k
1268 def If(a, b, c, ctx=None):
1269 """Create a Z3 if-then-else expression.
1273 >>> max = If(x > y, x, y)
1279 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1280 return Cond(a, b, c, ctx)
1282 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1285 b, c = _coerce_exprs(b, c, ctx)
1287 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1288 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1291 """Create a Z3 distinct expression.
1298 >>> Distinct(x, y, z)
1300 >>> simplify(Distinct(x, y, z))
1302 >>> simplify(Distinct(x, y, z), blast_distinct=True)
1303 And(Not(x == y), Not(x == z), Not(y == z))
1305 args = _get_args(args)
1306 ctx = _ctx_from_ast_arg_list(args)
1308 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1309 args = _coerce_expr_list(args, ctx)
1310 _args, sz = _to_ast_array(args)
1313 def _mk_bin(f, a, b):
1316 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1317 args[0] = a.as_ast()
1318 args[1] = b.as_ast()
1319 return f(a.ctx.ref(), 2, args)
1322 """Create a constant of the given sort.
1324 >>> Const('x', IntSort())
1328 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1333 """Create several constants of the given sort.
1335 `names` is a string containing the names of all constants to be created.
1336 Blank spaces separate the names of different constants.
1338 >>> x, y, z = Consts('x y z', IntSort())
1342 if isinstance(names, str):
1343 names = names.split(
" ")
1344 return [
Const(name, sort)
for name
in names]
1347 """Create a fresh constant of a specified sort"""
1348 ctx = _get_ctx(sort.ctx)
1352 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1354 >>> Var(0, IntSort())
1356 >>> eq(Var(0, IntSort()), Var(0, BoolSort()))
1360 _z3_assert(
is_sort(s),
"Z3 sort expected")
1361 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1365 Create a real free variable. Free variables are used to create quantified formulas.
1366 They are also used to create polynomials.
1375 Create a list of Real free variables.
1376 The variables have ids: 0, 1, ..., n-1
1378 >>> x0, x1, x2, x3 = RealVarVector(4)
1393 """Try to cast `val` as a Boolean.
1395 >>> x = BoolSort().cast(True)
1405 if isinstance(val, bool):
1409 _z3_assert(
is_expr(val),
"True, False or Z3 Boolean expression expected. Received %s of type %s" % (val, type(val)))
1410 if not self.
eqeq(val.sort()):
1411 _z3_assert(self.
eqeq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1415 return isinstance(other, ArithSortRef)
1425 """All Boolean expressions are instances of this class."""
1433 """Create the Z3 expression `self * other`.
1439 return If(self, other, 0)
1443 """Return `True` if `a` is a Z3 Boolean expression.
1449 >>> is_bool(And(p, q))
1457 return isinstance(a, BoolRef)
1460 """Return `True` if `a` is the Z3 true expression.
1465 >>> is_true(simplify(p == p))
1470 >>> # True is a Python Boolean expression
1477 """Return `True` if `a` is the Z3 false expression.
1484 >>> is_false(BoolVal(False))
1490 """Return `True` if `a` is a Z3 and expression.
1492 >>> p, q = Bools('p q')
1493 >>> is_and(And(p, q))
1495 >>> is_and(Or(p, q))
1501 """Return `True` if `a` is a Z3 or expression.
1503 >>> p, q = Bools('p q')
1506 >>> is_or(And(p, q))
1512 """Return `True` if `a` is a Z3 implication expression.
1514 >>> p, q = Bools('p q')
1515 >>> is_implies(Implies(p, q))
1517 >>> is_implies(And(p, q))
1523 """Return `True` if `a` is a Z3 not expression.
1534 """Return `True` if `a` is a Z3 equality expression.
1536 >>> x, y = Ints('x y')
1543 """Return `True` if `a` is a Z3 distinct expression.
1545 >>> x, y, z = Ints('x y z')
1546 >>> is_distinct(x == y)
1548 >>> is_distinct(Distinct(x, y, z))
1554 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1558 >>> p = Const('p', BoolSort())
1561 >>> r = Function('r', IntSort(), IntSort(), BoolSort())
1564 >>> is_bool(r(0, 1))
1571 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1575 >>> is_true(BoolVal(True))
1579 >>> is_false(BoolVal(False))
1589 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1600 """Return a tuple of Boolean constants.
1602 `names` is a single string containing all names separated by blank spaces.
1603 If `ctx=None`, then the global context is used.
1605 >>> p, q, r = Bools('p q r')
1606 >>> And(p, Or(q, r))
1610 if isinstance(names, str):
1611 names = names.split(
" ")
1612 return [
Bool(name, ctx)
for name
in names]
1615 """Return a list of Boolean constants of size `sz`.
1617 The constants are named using the given prefix.
1618 If `ctx=None`, then the global context is used.
1620 >>> P = BoolVector('p', 3)
1624 And(p__0, p__1, p__2)
1626 return [
Bool(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
1629 """Return a fresh Boolean constant in the given context using the given prefix.
1631 If `ctx=None`, then the global context is used.
1633 >>> b1 = FreshBool()
1634 >>> b2 = FreshBool()
1642 """Create a Z3 implies expression.
1644 >>> p, q = Bools('p q')
1648 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1655 """Create a Z3 Xor expression.
1657 >>> p, q = Bools('p q')
1660 >>> simplify(Xor(p, q))
1663 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1670 """Create a Z3 not expression or probe.
1675 >>> simplify(Not(Not(p)))
1678 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1693 def _has_probe(args):
1694 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1701 """Create a Z3 and-expression or and-probe.
1703 >>> p, q, r = Bools('p q r')
1706 >>> P = BoolVector('p', 5)
1708 And(p__0, p__1, p__2, p__3, p__4)
1712 last_arg = args[len(args)-1]
1713 if isinstance(last_arg, Context):
1714 ctx = args[len(args)-1]
1715 args = args[:len(args)-1]
1716 elif len(args) == 1
and isinstance(args[0], AstVector):
1718 args = [a
for a
in args[0]]
1721 args = _get_args(args)
1722 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1724 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1725 if _has_probe(args):
1726 return _probe_and(args, ctx)
1728 args = _coerce_expr_list(args, ctx)
1729 _args, sz = _to_ast_array(args)
1733 """Create a Z3 or-expression or or-probe.
1735 >>> p, q, r = Bools('p q r')
1738 >>> P = BoolVector('p', 5)
1740 Or(p__0, p__1, p__2, p__3, p__4)
1744 last_arg = args[len(args)-1]
1745 if isinstance(last_arg, Context):
1746 ctx = args[len(args)-1]
1747 args = args[:len(args)-1]
1748 elif len(args) == 1
and isinstance(args[0], AstVector):
1750 args = [a
for a
in args[0]]
1753 args = _get_args(args)
1754 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1756 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1757 if _has_probe(args):
1758 return _probe_or(args, ctx)
1760 args = _coerce_expr_list(args, ctx)
1761 _args, sz = _to_ast_array(args)
1771 """Patterns are hints for quantifier instantiation.
1781 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1783 >>> f = Function('f', IntSort(), IntSort())
1785 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
1787 ForAll(x, f(x) == 0)
1788 >>> q.num_patterns()
1790 >>> is_pattern(q.pattern(0))
1795 return isinstance(a, PatternRef)
1798 """Create a Z3 multi-pattern using the given expressions `*args`
1800 >>> f = Function('f', IntSort(), IntSort())
1801 >>> g = Function('g', IntSort(), IntSort())
1803 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
1805 ForAll(x, f(x) != g(x))
1806 >>> q.num_patterns()
1808 >>> is_pattern(q.pattern(0))
1811 MultiPattern(f(Var(0)), g(Var(0)))
1814 _z3_assert(len(args) > 0,
"At least one argument expected")
1815 _z3_assert(all([
is_expr(a)
for a
in args ]),
"Z3 expressions expected")
1817 args, sz = _to_ast_array(args)
1820 def _to_pattern(arg):
1833 """Universally and Existentially quantified formulas."""
1842 """Return the Boolean sort or sort of Lambda."""
1848 """Return `True` if `self` is a universal quantifier.
1850 >>> f = Function('f', IntSort(), IntSort())
1852 >>> q = ForAll(x, f(x) == 0)
1855 >>> q = Exists(x, f(x) != 0)
1862 """Return `True` if `self` is an existential quantifier.
1864 >>> f = Function('f', IntSort(), IntSort())
1866 >>> q = ForAll(x, f(x) == 0)
1869 >>> q = Exists(x, f(x) != 0)
1876 """Return `True` if `self` is a lambda expression.
1878 >>> f = Function('f', IntSort(), IntSort())
1880 >>> q = Lambda(x, f(x))
1883 >>> q = Exists(x, f(x) != 0)
1890 """Return the Z3 expression `self[arg]`.
1893 _z3_assert(self.
is_lambdais_lambda(),
"quantifier should be a lambda expression")
1899 """Return the weight annotation of `self`.
1901 >>> f = Function('f', IntSort(), IntSort())
1903 >>> q = ForAll(x, f(x) == 0)
1906 >>> q = ForAll(x, f(x) == 0, weight=10)
1913 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
1915 >>> f = Function('f', IntSort(), IntSort())
1916 >>> g = Function('g', IntSort(), IntSort())
1918 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
1919 >>> q.num_patterns()
1925 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
1927 >>> f = Function('f', IntSort(), IntSort())
1928 >>> g = Function('g', IntSort(), IntSort())
1930 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
1931 >>> q.num_patterns()
1939 _z3_assert(idx < self.
num_patternsnum_patterns(),
"Invalid pattern idx")
1943 """Return the number of no-patterns."""
1947 """Return a no-pattern."""
1949 _z3_assert(idx < self.
num_no_patternsnum_no_patterns(),
"Invalid no-pattern idx")
1953 """Return the expression being quantified.
1955 >>> f = Function('f', IntSort(), IntSort())
1957 >>> q = ForAll(x, f(x) == 0)
1964 """Return the number of variables bounded by this quantifier.
1966 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1969 >>> q = ForAll([x, y], f(x, y) >= x)
1976 """Return a string representing a name used when displaying the quantifier.
1978 >>> f = Function('f', IntSort(), IntSort(), IntSort())
1981 >>> q = ForAll([x, y], f(x, y) >= x)
1988 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
1992 """Return the sort of a bound variable.
1994 >>> f = Function('f', IntSort(), RealSort(), IntSort())
1997 >>> q = ForAll([x, y], f(x, y) >= x)
2004 _z3_assert(idx < self.
num_varsnum_vars(),
"Invalid variable idx")
2008 """Return a list containing a single element self.body()
2010 >>> f = Function('f', IntSort(), IntSort())
2012 >>> q = ForAll(x, f(x) == 0)
2016 return [ self.
bodybody() ]
2019 """Return `True` if `a` is a Z3 quantifier.
2021 >>> f = Function('f', IntSort(), IntSort())
2023 >>> q = ForAll(x, f(x) == 0)
2024 >>> is_quantifier(q)
2026 >>> is_quantifier(f(x))
2029 return isinstance(a, QuantifierRef)
2031 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2033 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2034 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2035 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2036 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2047 _vs = (Ast * num_vars)()
2048 for i
in range(num_vars):
2050 _vs[i] = vs[i].as_ast()
2051 patterns = [ _to_pattern(p)
for p
in patterns ]
2052 num_pats = len(patterns)
2053 _pats = (Pattern * num_pats)()
2054 for i
in range(num_pats):
2055 _pats[i] = patterns[i].ast
2056 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2062 num_no_pats, _no_pats,
2063 body.as_ast()), ctx)
2065 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2066 """Create a Z3 forall formula.
2068 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2070 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2073 >>> ForAll([x, y], f(x, y) >= x)
2074 ForAll([x, y], f(x, y) >= x)
2075 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2076 ForAll([x, y], f(x, y) >= x)
2077 >>> ForAll([x, y], f(x, y) >= x, weight=10)
2078 ForAll([x, y], f(x, y) >= x)
2080 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2082 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2083 """Create a Z3 exists formula.
2085 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2088 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2091 >>> q = Exists([x, y], f(x, y) >= x, skid="foo")
2093 Exists([x, y], f(x, y) >= x)
2094 >>> is_quantifier(q)
2096 >>> r = Tactic('nnf')(q).as_expr()
2097 >>> is_quantifier(r)
2100 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2103 """Create a Z3 lambda expression.
2105 >>> f = Function('f', IntSort(), IntSort(), IntSort())
2106 >>> mem0 = Array('mem0', IntSort(), IntSort())
2107 >>> lo, hi, e, i = Ints('lo hi e i')
2108 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i]))
2110 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i]))
2116 _vs = (Ast * num_vars)()
2117 for i
in range(num_vars):
2119 _vs[i] = vs[i].as_ast()
2129 """Real and Integer sorts."""
2132 """Return `True` if `self` is of the sort Real.
2137 >>> (x + 1).is_real()
2143 return self.
kindkind() == Z3_REAL_SORT
2146 """Return `True` if `self` is of the sort Integer.
2151 >>> (x + 1).is_int()
2157 return self.
kindkind() == Z3_INT_SORT
2160 """Return `True` if `self` is a subsort of `other`."""
2164 """Try to cast `val` as an Integer or Real.
2166 >>> IntSort().cast(10)
2168 >>> is_int(IntSort().cast(10))
2172 >>> RealSort().cast(10)
2174 >>> is_real(RealSort().cast(10))
2179 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
2181 if self.
eqeq(val_s):
2183 if val_s.is_int()
and self.
is_realis_real():
2185 if val_s.is_bool()
and self.
is_intis_int():
2186 return If(val, 1, 0)
2187 if val_s.is_bool()
and self.
is_realis_real():
2190 _z3_assert(
False,
"Z3 Integer/Real expression expected" )
2197 _z3_assert(
False,
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s" % self)
2200 """Return `True` if s is an arithmetical sort (type).
2202 >>> is_arith_sort(IntSort())
2204 >>> is_arith_sort(RealSort())
2206 >>> is_arith_sort(BoolSort())
2208 >>> n = Int('x') + 1
2209 >>> is_arith_sort(n.sort())
2212 return isinstance(s, ArithSortRef)
2215 """Integer and Real expressions."""
2218 """Return the sort (type) of the arithmetical expression `self`.
2222 >>> (Real('x') + 1).sort()
2228 """Return `True` if `self` is an integer expression.
2233 >>> (x + 1).is_int()
2236 >>> (x + y).is_int()
2242 """Return `True` if `self` is an real expression.
2247 >>> (x + 1).is_real()
2253 """Create the Z3 expression `self + other`.
2262 a, b = _coerce_exprs(self, other)
2263 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctxctx)
2266 """Create the Z3 expression `other + self`.
2272 a, b = _coerce_exprs(self, other)
2273 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctxctx)
2276 """Create the Z3 expression `self * other`.
2285 if isinstance(other, BoolRef):
2286 return If(other, self, 0)
2287 a, b = _coerce_exprs(self, other)
2288 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctxctx)
2291 """Create the Z3 expression `other * self`.
2297 a, b = _coerce_exprs(self, other)
2298 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctxctx)
2301 """Create the Z3 expression `self - other`.
2310 a, b = _coerce_exprs(self, other)
2311 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctxctx)
2314 """Create the Z3 expression `other - self`.
2320 a, b = _coerce_exprs(self, other)
2321 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctxctx)
2324 """Create the Z3 expression `self**other` (** is the power operator).
2331 >>> simplify(IntVal(2)**8)
2334 a, b = _coerce_exprs(self, other)
2338 """Create the Z3 expression `other**self` (** is the power operator).
2345 >>> simplify(2**IntVal(8))
2348 a, b = _coerce_exprs(self, other)
2352 """Create the Z3 expression `other/self`.
2371 a, b = _coerce_exprs(self, other)
2375 """Create the Z3 expression `other/self`."""
2376 return self.
__div____div__(other)
2379 """Create the Z3 expression `other/self`.
2392 a, b = _coerce_exprs(self, other)
2396 """Create the Z3 expression `other/self`."""
2397 return self.
__rdiv____rdiv__(other)
2400 """Create the Z3 expression `other%self`.
2406 >>> simplify(IntVal(10) % IntVal(3))
2409 a, b = _coerce_exprs(self, other)
2411 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2415 """Create the Z3 expression `other%self`.
2421 a, b = _coerce_exprs(self, other)
2423 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2427 """Return an expression representing `-self`.
2447 """Create the Z3 expression `other <= self`.
2449 >>> x, y = Ints('x y')
2456 a, b = _coerce_exprs(self, other)
2460 """Create the Z3 expression `other < self`.
2462 >>> x, y = Ints('x y')
2469 a, b = _coerce_exprs(self, other)
2473 """Create the Z3 expression `other > self`.
2475 >>> x, y = Ints('x y')
2482 a, b = _coerce_exprs(self, other)
2486 """Create the Z3 expression `other >= self`.
2488 >>> x, y = Ints('x y')
2495 a, b = _coerce_exprs(self, other)
2499 """Return `True` if `a` is an arithmetical expression.
2508 >>> is_arith(IntVal(1))
2516 return isinstance(a, ArithRef)
2519 """Return `True` if `a` is an integer expression.
2526 >>> is_int(IntVal(1))
2537 """Return `True` if `a` is a real expression.
2549 >>> is_real(RealVal(1))
2554 def _is_numeral(ctx, a):
2557 def _is_algebraic(ctx, a):
2561 """Return `True` if `a` is an integer value of sort Int.
2563 >>> is_int_value(IntVal(1))
2567 >>> is_int_value(Int('x'))
2569 >>> n = Int('x') + 1
2574 >>> is_int_value(n.arg(1))
2576 >>> is_int_value(RealVal("1/3"))
2578 >>> is_int_value(RealVal(1))
2581 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2584 """Return `True` if `a` is rational value of sort Real.
2586 >>> is_rational_value(RealVal(1))
2588 >>> is_rational_value(RealVal("3/5"))
2590 >>> is_rational_value(IntVal(1))
2592 >>> is_rational_value(1)
2594 >>> n = Real('x') + 1
2597 >>> is_rational_value(n.arg(1))
2599 >>> is_rational_value(Real('x'))
2602 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2605 """Return `True` if `a` is an algebraic value of sort Real.
2607 >>> is_algebraic_value(RealVal("3/5"))
2609 >>> n = simplify(Sqrt(2))
2612 >>> is_algebraic_value(n)
2615 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2618 """Return `True` if `a` is an expression of the form b + c.
2620 >>> x, y = Ints('x y')
2629 """Return `True` if `a` is an expression of the form b * c.
2631 >>> x, y = Ints('x y')
2640 """Return `True` if `a` is an expression of the form b - c.
2642 >>> x, y = Ints('x y')
2651 """Return `True` if `a` is an expression of the form b / c.
2653 >>> x, y = Reals('x y')
2658 >>> x, y = Ints('x y')
2667 """Return `True` if `a` is an expression of the form b div c.
2669 >>> x, y = Ints('x y')
2678 """Return `True` if `a` is an expression of the form b % c.
2680 >>> x, y = Ints('x y')
2689 """Return `True` if `a` is an expression of the form b <= c.
2691 >>> x, y = Ints('x y')
2700 """Return `True` if `a` is an expression of the form b < c.
2702 >>> x, y = Ints('x y')
2711 """Return `True` if `a` is an expression of the form b >= c.
2713 >>> x, y = Ints('x y')
2722 """Return `True` if `a` is an expression of the form b > c.
2724 >>> x, y = Ints('x y')
2733 """Return `True` if `a` is an expression of the form IsInt(b).
2736 >>> is_is_int(IsInt(x))
2744 """Return `True` if `a` is an expression of the form ToReal(b).
2758 """Return `True` if `a` is an expression of the form ToInt(b).
2772 """Integer values."""
2775 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2784 _z3_assert(self.
is_intis_int(),
"Integer value expected")
2788 """Return a Z3 integer numeral as a Python string.
2796 """Return a Z3 integer numeral as a Python binary string.
2798 >>> v.as_binary_string()
2804 """Rational values."""
2807 """ Return the numerator of a Z3 rational numeral.
2809 >>> is_rational_value(RealVal("3/5"))
2811 >>> n = RealVal("3/5")
2814 >>> is_rational_value(Q(3,5))
2816 >>> Q(3,5).numerator()
2822 """ Return the denominator of a Z3 rational numeral.
2824 >>> is_rational_value(Q(3,5))
2833 """ Return the numerator as a Python long.
2835 >>> v = RealVal(10000000000)
2840 >>> v.numerator_as_long() + 1 == 10000000001
2846 """ Return the denominator as a Python long.
2848 >>> v = RealVal("1/3")
2851 >>> v.denominator_as_long()
2866 _z3_assert(self.
is_int_valueis_int_value(),
"Expected integer fraction")
2870 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2872 >>> v = RealVal("1/5")
2875 >>> v = RealVal("1/3")
2882 """Return a Z3 rational numeral as a Python string.
2891 """Return a Z3 rational as a Python Fraction object.
2893 >>> v = RealVal("1/5")
2900 """Algebraic irrational values."""
2903 """Return a Z3 rational number that approximates the algebraic number `self`.
2904 The result `r` is such that |r - self| <= 1/10^precision
2906 >>> x = simplify(Sqrt(2))
2908 6838717160008073720548335/4835703278458516698824704
2914 """Return a string representation of the algebraic number `self` in decimal notation using `prec` decimal places
2916 >>> x = simplify(Sqrt(2))
2917 >>> x.as_decimal(10)
2919 >>> x.as_decimal(20)
2920 '1.41421356237309504880?'
2930 def _py2expr(a, ctx=None):
2931 if isinstance(a, bool):
2935 if isinstance(a, float):
2940 _z3_assert(
False,
"Python bool, int, long or float expected")
2943 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2947 >>> x = Const('x', IntSort())
2950 >>> x.sort() == IntSort()
2952 >>> x.sort() == BoolSort()
2959 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2963 >>> x = Const('x', RealSort())
2968 >>> x.sort() == RealSort()
2974 def _to_int_str(val):
2975 if isinstance(val, float):
2976 return str(int(val))
2977 elif isinstance(val, bool):
2984 elif isinstance(val, str):
2987 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
2990 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3001 """Return a Z3 real value.
3003 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3004 If `ctx=None`, then the global context is used.
3008 >>> RealVal(1).sort()
3019 """Return a Z3 rational a/b.
3021 If `ctx=None`, then the global context is used.
3025 >>> RatVal(3,5).sort()
3029 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3030 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3033 def Q(a, b, ctx=None):
3034 """Return a Z3 rational a/b.
3036 If `ctx=None`, then the global context is used.
3046 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3058 """Return a tuple of Integer constants.
3060 >>> x, y, z = Ints('x y z')
3065 if isinstance(names, str):
3066 names = names.split(
" ")
3067 return [
Int(name, ctx)
for name
in names]
3070 """Return a list of integer constants of size `sz`.
3072 >>> X = IntVector('x', 3)
3079 return [
Int(
'%s__%s' % (prefix, i), ctx)
for i
in range(sz) ]
3082 """Return a fresh integer constant in the given context using the given prefix.
3095 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3107 """Return a tuple of real constants.
3109 >>> x, y, z = Reals('x y z')
3112 >>> Sum(x, y, z).sort()
3116 if isinstance(names, str):
3117 names = names.split(
" ")
3118 return [
Real(name, ctx)
for name
in names]
3121 """Return a list of real constants of size `sz`.
3123 >>> X = RealVector('x', 3)
3132 return [
Real(
'%s__%s' % (prefix, i), ctx)
for i
in range(sz) ]
3135 """Return a fresh real constant in the given context using the given prefix.
3148 """ Return the Z3 expression ToReal(a).
3160 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3165 """ Return the Z3 expression ToInt(a).
3177 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3182 """ Return the Z3 predicate IsInt(a).
3185 >>> IsInt(x + "1/2")
3187 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3189 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3193 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3198 """ Return a Z3 expression which represents the square root of a.
3210 """ Return a Z3 expression which represents the cubic root of a.
3228 """Bit-vector sort."""
3231 """Return the size (number of bits) of the bit-vector sort `self`.
3233 >>> b = BitVecSort(32)
3243 """Try to cast `val` as a Bit-Vector.
3245 >>> b = BitVecSort(32)
3248 >>> b.cast(10).sexpr()
3253 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
3260 """Return True if `s` is a Z3 bit-vector sort.
3262 >>> is_bv_sort(BitVecSort(32))
3264 >>> is_bv_sort(IntSort())
3267 return isinstance(s, BitVecSortRef)
3270 """Bit-vector expressions."""
3273 """Return the sort of the bit-vector expression `self`.
3275 >>> x = BitVec('x', 32)
3278 >>> x.sort() == BitVecSort(32)
3284 """Return the number of bits of the bit-vector expression `self`.
3286 >>> x = BitVec('x', 32)
3289 >>> Concat(x, x).size()
3295 """Create the Z3 expression `self + other`.
3297 >>> x = BitVec('x', 32)
3298 >>> y = BitVec('y', 32)
3304 a, b = _coerce_exprs(self, other)
3308 """Create the Z3 expression `other + self`.
3310 >>> x = BitVec('x', 32)
3314 a, b = _coerce_exprs(self, other)
3318 """Create the Z3 expression `self * other`.
3320 >>> x = BitVec('x', 32)
3321 >>> y = BitVec('y', 32)
3327 a, b = _coerce_exprs(self, other)
3331 """Create the Z3 expression `other * self`.
3333 >>> x = BitVec('x', 32)
3337 a, b = _coerce_exprs(self, other)
3341 """Create the Z3 expression `self - other`.
3343 >>> x = BitVec('x', 32)
3344 >>> y = BitVec('y', 32)
3350 a, b = _coerce_exprs(self, other)
3354 """Create the Z3 expression `other - self`.
3356 >>> x = BitVec('x', 32)
3360 a, b = _coerce_exprs(self, other)
3364 """Create the Z3 expression bitwise-or `self | other`.
3366 >>> x = BitVec('x', 32)
3367 >>> y = BitVec('y', 32)
3373 a, b = _coerce_exprs(self, other)
3377 """Create the Z3 expression bitwise-or `other | self`.
3379 >>> x = BitVec('x', 32)
3383 a, b = _coerce_exprs(self, other)
3387 """Create the Z3 expression bitwise-and `self & other`.
3389 >>> x = BitVec('x', 32)
3390 >>> y = BitVec('y', 32)
3396 a, b = _coerce_exprs(self, other)
3400 """Create the Z3 expression bitwise-or `other & self`.
3402 >>> x = BitVec('x', 32)
3406 a, b = _coerce_exprs(self, other)
3410 """Create the Z3 expression bitwise-xor `self ^ other`.
3412 >>> x = BitVec('x', 32)
3413 >>> y = BitVec('y', 32)
3419 a, b = _coerce_exprs(self, other)
3423 """Create the Z3 expression bitwise-xor `other ^ self`.
3425 >>> x = BitVec('x', 32)
3429 a, b = _coerce_exprs(self, other)
3435 >>> x = BitVec('x', 32)
3442 """Return an expression representing `-self`.
3444 >>> x = BitVec('x', 32)
3453 """Create the Z3 expression bitwise-not `~self`.
3455 >>> x = BitVec('x', 32)
3464 """Create the Z3 expression (signed) division `self / other`.
3466 Use the function UDiv() for unsigned division.
3468 >>> x = BitVec('x', 32)
3469 >>> y = BitVec('y', 32)
3476 >>> UDiv(x, y).sexpr()
3479 a, b = _coerce_exprs(self, other)
3483 """Create the Z3 expression (signed) division `self / other`."""
3484 return self.
__div____div__(other)
3487 """Create the Z3 expression (signed) division `other / self`.
3489 Use the function UDiv() for unsigned division.
3491 >>> x = BitVec('x', 32)
3494 >>> (10 / x).sexpr()
3495 '(bvsdiv #x0000000a x)'
3496 >>> UDiv(10, x).sexpr()
3497 '(bvudiv #x0000000a x)'
3499 a, b = _coerce_exprs(self, other)
3503 """Create the Z3 expression (signed) division `other / self`."""
3504 return self.
__rdiv____rdiv__(other)
3507 """Create the Z3 expression (signed) mod `self % other`.
3509 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3511 >>> x = BitVec('x', 32)
3512 >>> y = BitVec('y', 32)
3519 >>> URem(x, y).sexpr()
3521 >>> SRem(x, y).sexpr()
3524 a, b = _coerce_exprs(self, other)
3528 """Create the Z3 expression (signed) mod `other % self`.
3530 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3532 >>> x = BitVec('x', 32)
3535 >>> (10 % x).sexpr()
3536 '(bvsmod #x0000000a x)'
3537 >>> URem(10, x).sexpr()
3538 '(bvurem #x0000000a x)'
3539 >>> SRem(10, x).sexpr()
3540 '(bvsrem #x0000000a x)'
3542 a, b = _coerce_exprs(self, other)
3546 """Create the Z3 expression (signed) `other <= self`.
3548 Use the function ULE() for unsigned less than or equal to.
3550 >>> x, y = BitVecs('x y', 32)
3553 >>> (x <= y).sexpr()
3555 >>> ULE(x, y).sexpr()
3558 a, b = _coerce_exprs(self, other)
3562 """Create the Z3 expression (signed) `other < self`.
3564 Use the function ULT() for unsigned less than.
3566 >>> x, y = BitVecs('x y', 32)
3571 >>> ULT(x, y).sexpr()
3574 a, b = _coerce_exprs(self, other)
3578 """Create the Z3 expression (signed) `other > self`.
3580 Use the function UGT() for unsigned greater than.
3582 >>> x, y = BitVecs('x y', 32)
3587 >>> UGT(x, y).sexpr()
3590 a, b = _coerce_exprs(self, other)
3594 """Create the Z3 expression (signed) `other >= self`.
3596 Use the function UGE() for unsigned greater than or equal to.
3598 >>> x, y = BitVecs('x y', 32)
3601 >>> (x >= y).sexpr()
3603 >>> UGE(x, y).sexpr()
3606 a, b = _coerce_exprs(self, other)
3610 """Create the Z3 expression (arithmetical) right shift `self >> other`
3612 Use the function LShR() for the right logical shift
3614 >>> x, y = BitVecs('x y', 32)
3617 >>> (x >> y).sexpr()
3619 >>> LShR(x, y).sexpr()
3623 >>> BitVecVal(4, 3).as_signed_long()
3625 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3627 >>> simplify(BitVecVal(4, 3) >> 1)
3629 >>> simplify(LShR(BitVecVal(4, 3), 1))
3631 >>> simplify(BitVecVal(2, 3) >> 1)
3633 >>> simplify(LShR(BitVecVal(2, 3), 1))
3636 a, b = _coerce_exprs(self, other)
3640 """Create the Z3 expression left shift `self << other`
3642 >>> x, y = BitVecs('x y', 32)
3645 >>> (x << y).sexpr()
3647 >>> simplify(BitVecVal(2, 3) << 1)
3650 a, b = _coerce_exprs(self, other)
3654 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3656 Use the function LShR() for the right logical shift
3658 >>> x = BitVec('x', 32)
3661 >>> (10 >> x).sexpr()
3662 '(bvashr #x0000000a x)'
3664 a, b = _coerce_exprs(self, other)
3668 """Create the Z3 expression left shift `other << self`.
3670 Use the function LShR() for the right logical shift
3672 >>> x = BitVec('x', 32)
3675 >>> (10 << x).sexpr()
3676 '(bvshl #x0000000a x)'
3678 a, b = _coerce_exprs(self, other)
3682 """Bit-vector values."""
3685 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3687 >>> v = BitVecVal(0xbadc0de, 32)
3690 >>> print("0x%.8x" % v.as_long())
3696 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign.
3698 >>> BitVecVal(4, 3).as_signed_long()
3700 >>> BitVecVal(7, 3).as_signed_long()
3702 >>> BitVecVal(3, 3).as_signed_long()
3704 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3706 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3709 sz = self.
sizesize()
3711 if val >= 2**(sz - 1):
3713 if val < -2**(sz - 1):
3725 """Return `True` if `a` is a Z3 bit-vector expression.
3727 >>> b = BitVec('b', 32)
3735 return isinstance(a, BitVecRef)
3738 """Return `True` if `a` is a Z3 bit-vector numeral value.
3740 >>> b = BitVec('b', 32)
3743 >>> b = BitVecVal(10, 32)
3749 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3752 """Return the Z3 expression BV2Int(a).
3754 >>> b = BitVec('b', 3)
3755 >>> BV2Int(b).sort()
3760 >>> x > BV2Int(b, is_signed=False)
3762 >>> x > BV2Int(b, is_signed=True)
3763 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3764 >>> solve(x > BV2Int(b), b == 1, x < 3)
3768 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3774 """Return the z3 expression Int2BV(a, num_bits).
3775 It is a bit-vector of width num_bits and represents the
3776 modulo of a by 2^num_bits
3782 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3784 >>> Byte = BitVecSort(8)
3785 >>> Word = BitVecSort(16)
3788 >>> x = Const('x', Byte)
3789 >>> eq(x, BitVec('x', 8))
3796 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3798 >>> v = BitVecVal(10, 32)
3801 >>> print("0x%.8x" % v.as_long())
3812 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3813 If `ctx=None`, then the global context is used.
3815 >>> x = BitVec('x', 16)
3822 >>> word = BitVecSort(16)
3823 >>> x2 = BitVec('x', word)
3827 if isinstance(bv, BitVecSortRef):
3835 """Return a tuple of bit-vector constants of size bv.
3837 >>> x, y, z = BitVecs('x y z', 16)
3844 >>> Product(x, y, z)
3846 >>> simplify(Product(x, y, z))
3850 if isinstance(names, str):
3851 names = names.split(
" ")
3852 return [
BitVec(name, bv, ctx)
for name
in names]
3855 """Create a Z3 bit-vector concatenation expression.
3857 >>> v = BitVecVal(1, 4)
3858 >>> Concat(v, v+1, v)
3859 Concat(Concat(1, 1 + 1), 1)
3860 >>> simplify(Concat(v, v+1, v))
3862 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3865 args = _get_args(args)
3868 _z3_assert(sz >= 2,
"At least two arguments expected.")
3875 if is_seq(args[0])
or isinstance(args[0], str):
3876 args = [_coerce_seq(s, ctx)
for s
in args]
3878 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
3881 v[i] = args[i].as_ast()
3886 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
3889 v[i] = args[i].as_ast()
3893 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
3895 for i
in range(sz - 1):
3900 """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3902 >>> x = BitVec('x', 8)
3903 >>> Extract(6, 2, x)
3905 >>> Extract(6, 2, x).sort()
3907 >>> simplify(Extract(StringVal("abcd"),2,1))
3910 if isinstance(high, str):
3914 offset, length = _coerce_exprs(low, a, s.ctx)
3917 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
3918 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
"First and second arguments must be non negative integers")
3919 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
3922 def _check_bv_args(a, b):
3924 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
3927 """Create the Z3 expression (unsigned) `other <= self`.
3929 Use the operator <= for signed less than or equal to.
3931 >>> x, y = BitVecs('x y', 32)
3934 >>> (x <= y).sexpr()
3936 >>> ULE(x, y).sexpr()
3939 _check_bv_args(a, b)
3940 a, b = _coerce_exprs(a, b)
3944 """Create the Z3 expression (unsigned) `other < self`.
3946 Use the operator < for signed less than.
3948 >>> x, y = BitVecs('x y', 32)
3953 >>> ULT(x, y).sexpr()
3956 _check_bv_args(a, b)
3957 a, b = _coerce_exprs(a, b)
3961 """Create the Z3 expression (unsigned) `other >= self`.
3963 Use the operator >= for signed greater than or equal to.
3965 >>> x, y = BitVecs('x y', 32)
3968 >>> (x >= y).sexpr()
3970 >>> UGE(x, y).sexpr()
3973 _check_bv_args(a, b)
3974 a, b = _coerce_exprs(a, b)
3978 """Create the Z3 expression (unsigned) `other > self`.
3980 Use the operator > for signed greater than.
3982 >>> x, y = BitVecs('x y', 32)
3987 >>> UGT(x, y).sexpr()
3990 _check_bv_args(a, b)
3991 a, b = _coerce_exprs(a, b)
3995 """Create the Z3 expression (unsigned) division `self / other`.
3997 Use the operator / for signed division.
3999 >>> x = BitVec('x', 32)
4000 >>> y = BitVec('y', 32)
4003 >>> UDiv(x, y).sort()
4007 >>> UDiv(x, y).sexpr()
4010 _check_bv_args(a, b)
4011 a, b = _coerce_exprs(a, b)
4015 """Create the Z3 expression (unsigned) remainder `self % other`.
4017 Use the operator % for signed modulus, and SRem() for signed remainder.
4019 >>> x = BitVec('x', 32)
4020 >>> y = BitVec('y', 32)
4023 >>> URem(x, y).sort()
4027 >>> URem(x, y).sexpr()
4030 _check_bv_args(a, b)
4031 a, b = _coerce_exprs(a, b)
4035 """Create the Z3 expression signed remainder.
4037 Use the operator % for signed modulus, and URem() for unsigned remainder.
4039 >>> x = BitVec('x', 32)
4040 >>> y = BitVec('y', 32)
4043 >>> SRem(x, y).sort()
4047 >>> SRem(x, y).sexpr()
4050 _check_bv_args(a, b)
4051 a, b = _coerce_exprs(a, b)
4055 """Create the Z3 expression logical right shift.
4057 Use the operator >> for the arithmetical right shift.
4059 >>> x, y = BitVecs('x y', 32)
4062 >>> (x >> y).sexpr()
4064 >>> LShR(x, y).sexpr()
4068 >>> BitVecVal(4, 3).as_signed_long()
4070 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4072 >>> simplify(BitVecVal(4, 3) >> 1)
4074 >>> simplify(LShR(BitVecVal(4, 3), 1))
4076 >>> simplify(BitVecVal(2, 3) >> 1)
4078 >>> simplify(LShR(BitVecVal(2, 3), 1))
4081 _check_bv_args(a, b)
4082 a, b = _coerce_exprs(a, b)
4086 """Return an expression representing `a` rotated to the left `b` times.
4088 >>> a, b = BitVecs('a b', 16)
4089 >>> RotateLeft(a, b)
4091 >>> simplify(RotateLeft(a, 0))
4093 >>> simplify(RotateLeft(a, 16))
4096 _check_bv_args(a, b)
4097 a, b = _coerce_exprs(a, b)
4101 """Return an expression representing `a` rotated to the right `b` times.
4103 >>> a, b = BitVecs('a b', 16)
4104 >>> RotateRight(a, b)
4106 >>> simplify(RotateRight(a, 0))
4108 >>> simplify(RotateRight(a, 16))
4111 _check_bv_args(a, b)
4112 a, b = _coerce_exprs(a, b)
4116 """Return a bit-vector expression with `n` extra sign-bits.
4118 >>> x = BitVec('x', 16)
4119 >>> n = SignExt(8, x)
4126 >>> v0 = BitVecVal(2, 2)
4131 >>> v = simplify(SignExt(6, v0))
4136 >>> print("%.x" % v.as_long())
4140 _z3_assert(_is_int(n),
"First argument must be an integer")
4141 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4145 """Return a bit-vector expression with `n` extra zero-bits.
4147 >>> x = BitVec('x', 16)
4148 >>> n = ZeroExt(8, x)
4155 >>> v0 = BitVecVal(2, 2)
4160 >>> v = simplify(ZeroExt(6, v0))
4167 _z3_assert(_is_int(n),
"First argument must be an integer")
4168 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4172 """Return an expression representing `n` copies of `a`.
4174 >>> x = BitVec('x', 8)
4175 >>> n = RepeatBitVec(4, x)
4180 >>> v0 = BitVecVal(10, 4)
4181 >>> print("%.x" % v0.as_long())
4183 >>> v = simplify(RepeatBitVec(4, v0))
4186 >>> print("%.x" % v.as_long())
4190 _z3_assert(_is_int(n),
"First argument must be an integer")
4191 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4195 """Return the reduction-and expression of `a`."""
4197 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4201 """Return the reduction-or expression of `a`."""
4203 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4207 """A predicate the determines that bit-vector addition does not overflow"""
4208 _check_bv_args(a, b)
4209 a, b = _coerce_exprs(a, b)
4213 """A predicate the determines that signed bit-vector addition does not underflow"""
4214 _check_bv_args(a, b)
4215 a, b = _coerce_exprs(a, b)
4219 """A predicate the determines that bit-vector subtraction does not overflow"""
4220 _check_bv_args(a, b)
4221 a, b = _coerce_exprs(a, b)
4226 """A predicate the determines that bit-vector subtraction does not underflow"""
4227 _check_bv_args(a, b)
4228 a, b = _coerce_exprs(a, b)
4232 """A predicate the determines that bit-vector signed division does not overflow"""
4233 _check_bv_args(a, b)
4234 a, b = _coerce_exprs(a, b)
4238 """A predicate the determines that bit-vector unary negation does not overflow"""
4240 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4244 """A predicate the determines that bit-vector multiplication does not overflow"""
4245 _check_bv_args(a, b)
4246 a, b = _coerce_exprs(a, b)
4251 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4252 _check_bv_args(a, b)
4253 a, b = _coerce_exprs(a, b)
4268 """Return the domain of the array sort `self`.
4270 >>> A = ArraySort(IntSort(), BoolSort())
4277 """Return the range of the array sort `self`.
4279 >>> A = ArraySort(IntSort(), BoolSort())
4286 """Array expressions. """
4289 """Return the array sort of the array expression `self`.
4291 >>> a = Array('a', IntSort(), BoolSort())
4298 """Shorthand for `self.sort().domain()`.
4300 >>> a = Array('a', IntSort(), BoolSort())
4307 """Shorthand for `self.sort().range()`.
4309 >>> a = Array('a', IntSort(), BoolSort())
4316 """Return the Z3 expression `self[arg]`.
4318 >>> a = Array('a', IntSort(), BoolSort())
4325 arg = self.
domaindomain().cast(arg)
4336 """Return `True` if `a` is a Z3 array expression.
4338 >>> a = Array('a', IntSort(), IntSort())
4341 >>> is_array(Store(a, 0, 1))
4346 return isinstance(a, ArrayRef)
4349 """Return `True` if `a` is a Z3 constant array.
4351 >>> a = K(IntSort(), 10)
4352 >>> is_const_array(a)
4354 >>> a = Array('a', IntSort(), IntSort())
4355 >>> is_const_array(a)
4361 """Return `True` if `a` is a Z3 constant array.
4363 >>> a = K(IntSort(), 10)
4366 >>> a = Array('a', IntSort(), IntSort())
4373 """Return `True` if `a` is a Z3 map array expression.
4375 >>> f = Function('f', IntSort(), IntSort())
4376 >>> b = Array('b', IntSort(), IntSort())
4388 """Return `True` if `a` is a Z3 default array expression.
4389 >>> d = Default(K(IntSort(), 10))
4393 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4396 """Return the function declaration associated with a Z3 map array expression.
4398 >>> f = Function('f', IntSort(), IntSort())
4399 >>> b = Array('b', IntSort(), IntSort())
4401 >>> eq(f, get_map_func(a))
4405 >>> get_map_func(a)(0)
4409 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4413 """Return the Z3 array sort with the given domain and range sorts.
4415 >>> A = ArraySort(IntSort(), BoolSort())
4422 >>> AA = ArraySort(IntSort(), A)
4424 Array(Int, Array(Int, Bool))
4426 sig = _get_args(sig)
4428 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4429 arity = len(sig) - 1
4434 _z3_assert(
is_sort(s),
"Z3 sort expected")
4435 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4439 dom = (Sort * arity)()
4440 for i
in range(arity):
4445 """Return an array constant named `name` with the given domain and range sorts.
4447 >>> a = Array('a', IntSort(), IntSort())
4458 """Return a Z3 store array expression.
4460 >>> a = Array('a', IntSort(), IntSort())
4461 >>> i, v = Ints('i v')
4462 >>> s = Update(a, i, v)
4465 >>> prove(s[i] == v)
4468 >>> prove(Implies(i != j, s[j] == a[j]))
4472 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4473 i = a.sort().domain().cast(i)
4474 v = a.sort().
range().cast(v)
4476 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4479 """ Return a default value for array expression.
4480 >>> b = K(IntSort(), 1)
4481 >>> prove(Default(b) == 1)
4485 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4490 """Return a Z3 store array expression.
4492 >>> a = Array('a', IntSort(), IntSort())
4493 >>> i, v = Ints('i v')
4494 >>> s = Store(a, i, v)
4497 >>> prove(s[i] == v)
4500 >>> prove(Implies(i != j, s[j] == a[j]))
4506 """Return a Z3 select array expression.
4508 >>> a = Array('a', IntSort(), IntSort())
4512 >>> eq(Select(a, i), a[i])
4516 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4521 """Return a Z3 map array expression.
4523 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4524 >>> a1 = Array('a1', IntSort(), IntSort())
4525 >>> a2 = Array('a2', IntSort(), IntSort())
4526 >>> b = Map(f, a1, a2)
4529 >>> prove(b[0] == f(a1[0], a2[0]))
4532 args = _get_args(args)
4534 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4535 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4536 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4537 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4538 _args, sz = _to_ast_array(args)
4543 """Return a Z3 constant array expression.
4545 >>> a = K(IntSort(), 10)
4557 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4560 v = _py2expr(v, ctx)
4564 """Return extensionality index for one-dimensional arrays.
4565 >> a, b = Consts('a b', SetSort(IntSort()))
4572 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4576 k = _py2expr(k, ctx)
4580 """Return `True` if `a` is a Z3 array select application.
4582 >>> a = Array('a', IntSort(), IntSort())
4592 """Return `True` if `a` is a Z3 array store application.
4594 >>> a = Array('a', IntSort(), IntSort())
4597 >>> is_store(Store(a, 0, 1))
4610 """ Create a set sort over element sort s"""
4614 """Create the empty set
4615 >>> EmptySet(IntSort())
4622 """Create the full set
4623 >>> FullSet(IntSort())
4630 """ Take the union of sets
4631 >>> a = Const('a', SetSort(IntSort()))
4632 >>> b = Const('b', SetSort(IntSort()))
4636 args = _get_args(args)
4637 ctx = _ctx_from_ast_arg_list(args)
4638 _args, sz = _to_ast_array(args)
4642 """ Take the union of sets
4643 >>> a = Const('a', SetSort(IntSort()))
4644 >>> b = Const('b', SetSort(IntSort()))
4645 >>> SetIntersect(a, b)
4648 args = _get_args(args)
4649 ctx = _ctx_from_ast_arg_list(args)
4650 _args, sz = _to_ast_array(args)
4654 """ Add element e to set s
4655 >>> a = Const('a', SetSort(IntSort()))
4659 ctx = _ctx_from_ast_arg_list([s,e])
4660 e = _py2expr(e, ctx)
4664 """ Remove element e to set s
4665 >>> a = Const('a', SetSort(IntSort()))
4669 ctx = _ctx_from_ast_arg_list([s,e])
4670 e = _py2expr(e, ctx)
4674 """ The complement of set s
4675 >>> a = Const('a', SetSort(IntSort()))
4676 >>> SetComplement(a)
4683 """ The set difference of a and b
4684 >>> a = Const('a', SetSort(IntSort()))
4685 >>> b = Const('b', SetSort(IntSort()))
4686 >>> SetDifference(a, b)
4689 ctx = _ctx_from_ast_arg_list([a, b])
4693 """ Check if e is a member of set s
4694 >>> a = Const('a', SetSort(IntSort()))
4698 ctx = _ctx_from_ast_arg_list([s,e])
4699 e = _py2expr(e, ctx)
4703 """ Check if a is a subset of b
4704 >>> a = Const('a', SetSort(IntSort()))
4705 >>> b = Const('b', SetSort(IntSort()))
4709 ctx = _ctx_from_ast_arg_list([a, b])
4719 def _valid_accessor(acc):
4720 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4721 return isinstance(acc, tuple)
and len(acc) == 2
and isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4724 """Helper class for declaring Z3 datatypes.
4726 >>> List = Datatype('List')
4727 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4728 >>> List.declare('nil')
4729 >>> List = List.create()
4730 >>> # List is now a Z3 declaration
4733 >>> List.cons(10, List.nil)
4735 >>> List.cons(10, List.nil).sort()
4737 >>> cons = List.cons
4741 >>> n = cons(1, cons(0, nil))
4743 cons(1, cons(0, nil))
4744 >>> simplify(cdr(n))
4746 >>> simplify(car(n))
4756 r.constructors = copy.deepcopy(self.
constructorsconstructors)
4761 _z3_assert(isinstance(name, str),
"String expected")
4762 _z3_assert(isinstance(rec_name, str),
"String expected")
4763 _z3_assert(all([_valid_accessor(a)
for a
in args]),
"Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
4764 self.
constructorsconstructors.append((name, rec_name, args))
4767 """Declare constructor named `name` with the given accessors `args`.
4768 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared.
4770 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4771 declares the constructor named `cons` that builds a new List using an integer and a List.
4772 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4773 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4774 the actual datatype in Z3.
4776 >>> List = Datatype('List')
4777 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4778 >>> List.declare('nil')
4779 >>> List = List.create()
4782 _z3_assert(isinstance(name, str),
"String expected")
4783 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4784 return self.
declare_coredeclare_core(name,
"is-" + name, *args)
4790 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
4792 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4794 >>> List = Datatype('List')
4795 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4796 >>> List.declare('nil')
4797 >>> List = List.create()
4800 >>> List.cons(10, List.nil)
4806 """Auxiliary object used to create Z3 datatypes."""
4811 if self.
ctxctx.ref()
is not None:
4815 """Auxiliary object used to create Z3 datatypes."""
4820 if self.
ctxctx.ref()
is not None:
4824 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4826 In the following example we define a Tree-List using two mutually recursive datatypes.
4828 >>> TreeList = Datatype('TreeList')
4829 >>> Tree = Datatype('Tree')
4830 >>> # Tree has two constructors: leaf and node
4831 >>> Tree.declare('leaf', ('val', IntSort()))
4832 >>> # a node contains a list of trees
4833 >>> Tree.declare('node', ('children', TreeList))
4834 >>> TreeList.declare('nil')
4835 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4836 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4837 >>> Tree.val(Tree.leaf(10))
4839 >>> simplify(Tree.val(Tree.leaf(10)))
4841 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4843 node(cons(leaf(10), cons(leaf(20), nil)))
4844 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4845 >>> simplify(n2 == n1)
4847 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4852 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
4853 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
4854 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
4855 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
4858 names = (Symbol * num)()
4859 out = (Sort * num)()
4860 clists = (ConstructorList * num)()
4862 for i
in range(num):
4865 num_cs = len(d.constructors)
4866 cs = (Constructor * num_cs)()
4867 for j
in range(num_cs):
4868 c = d.constructors[j]
4873 fnames = (Symbol * num_fs)()
4874 sorts = (Sort * num_fs)()
4875 refs = (ctypes.c_uint * num_fs)()
4876 for k
in range(num_fs):
4880 if isinstance(ftype, Datatype):
4882 _z3_assert(ds.count(ftype) == 1,
"One and only one occurrence of each datatype is expected")
4884 refs[k] = ds.index(ftype)
4887 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
4888 sorts[k] = ftype.ast
4897 for i
in range(num):
4899 num_cs = dref.num_constructors()
4900 for j
in range(num_cs):
4901 cref = dref.constructor(j)
4902 cref_name = cref.name()
4903 cref_arity = cref.arity()
4904 if cref.arity() == 0:
4906 setattr(dref, cref_name, cref)
4907 rref = dref.recognizer(j)
4908 setattr(dref,
"is_" + cref_name, rref)
4909 for k
in range(cref_arity):
4910 aref = dref.accessor(j, k)
4911 setattr(dref, aref.name(), aref)
4913 return tuple(result)
4916 """Datatype sorts."""
4918 """Return the number of constructors in the given Z3 datatype.
4920 >>> List = Datatype('List')
4921 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4922 >>> List.declare('nil')
4923 >>> List = List.create()
4924 >>> # List is now a Z3 declaration
4925 >>> List.num_constructors()
4931 """Return a constructor of the datatype `self`.
4933 >>> List = Datatype('List')
4934 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4935 >>> List.declare('nil')
4936 >>> List = List.create()
4937 >>> # List is now a Z3 declaration
4938 >>> List.num_constructors()
4940 >>> List.constructor(0)
4942 >>> List.constructor(1)
4946 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
4950 """In Z3, each constructor has an associated recognizer predicate.
4952 If the constructor is named `name`, then the recognizer `is_name`.
4954 >>> List = Datatype('List')
4955 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4956 >>> List.declare('nil')
4957 >>> List = List.create()
4958 >>> # List is now a Z3 declaration
4959 >>> List.num_constructors()
4961 >>> List.recognizer(0)
4963 >>> List.recognizer(1)
4965 >>> simplify(List.is_nil(List.cons(10, List.nil)))
4967 >>> simplify(List.is_cons(List.cons(10, List.nil)))
4969 >>> l = Const('l', List)
4970 >>> simplify(List.is_cons(l))
4974 _z3_assert(idx < self.
num_constructorsnum_constructors(),
"Invalid recognizer index")
4978 """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4980 >>> List = Datatype('List')
4981 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4982 >>> List.declare('nil')
4983 >>> List = List.create()
4984 >>> List.num_constructors()
4986 >>> List.constructor(0)
4988 >>> num_accs = List.constructor(0).arity()
4991 >>> List.accessor(0, 0)
4993 >>> List.accessor(0, 1)
4995 >>> List.constructor(1)
4997 >>> num_accs = List.constructor(1).arity()
5002 _z3_assert(i < self.
num_constructorsnum_constructors(),
"Invalid constructor index")
5003 _z3_assert(j < self.
constructorconstructor(i).arity(),
"Invalid accessor index")
5007 """Datatype expressions."""
5009 """Return the datatype sort of the datatype expression `self`."""
5013 """Create a named tuple sort base on a set of underlying sorts
5015 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5018 projects = [ (
'project%d' % i, sorts[i])
for i
in range(len(sorts)) ]
5019 tuple.declare(name, *projects)
5020 tuple = tuple.create()
5021 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5024 """Create a named tagged union sort base on a set of underlying sorts
5026 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5029 for i
in range(len(sorts)):
5030 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5032 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5036 """Return a new enumeration sort named `name` containing the given values.
5038 The result is a pair (sort, list of constants).
5040 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5043 _z3_assert(isinstance(name, str),
"Name must be a string")
5044 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5045 _z3_assert(len(values) > 0,
"At least one value expected")
5048 _val_names = (Symbol * num)()
5049 for i
in range(num):
5051 _values = (FuncDecl * num)()
5052 _testers = (FuncDecl * num)()
5056 for i
in range(num):
5058 V = [a()
for a
in V]
5068 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5070 Consider using the function `args2params` to create instances of this object.
5077 self.
paramsparams = params
5084 if self.
ctxctx.ref()
is not None:
5088 """Set parameter name with value val."""
5090 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5092 if isinstance(val, bool):
5096 elif isinstance(val, float):
5098 elif isinstance(val, str):
5102 _z3_assert(
False,
"invalid parameter value")
5108 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5112 """Convert python arguments into a Z3_params object.
5113 A ':' is added to the keywords, and '_' is replaced with '-'
5115 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5116 (params model true relevancy 2 elim_and true)
5119 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5134 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5137 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5143 return ParamsDescrsRef(self.
descrdescr, self.
ctxctx)
5146 if self.
ctxctx.ref()
is not None:
5150 """Return the size of in the parameter description `self`.
5155 """Return the size of in the parameter description `self`.
5157 return self.
sizesize()
5160 """Return the i-th parameter name in the parameter description `self`.
5165 """Return the kind of the parameter named `n`.
5170 """Return the documentation string of the parameter named `n`.
5190 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5192 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5193 A goal has a solution if one of its subgoals has a solution.
5194 A goal is unsatisfiable if all subgoals are unsatisfiable.
5197 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5199 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5202 if self.
goalgoal
is None:
5207 return Goal(
False,
False,
False, self.
ctxctx, self.
goalgoal)
5210 if self.
goalgoal
is not None and self.
ctxctx.ref()
is not None:
5214 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
5216 >>> x, y = Ints('x y')
5218 >>> g.add(x == 0, y >= x + 1)
5221 >>> r = Then('simplify', 'solve-eqs')(g)
5222 >>> # r has 1 subgoal
5231 """Return `True` if `self` contains the `False` constraints.
5233 >>> x, y = Ints('x y')
5235 >>> g.inconsistent()
5237 >>> g.add(x == 0, x == 1)
5240 >>> g.inconsistent()
5242 >>> g2 = Tactic('propagate-values')(g)[0]
5243 >>> g2.inconsistent()
5249 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5252 >>> g.prec() == Z3_GOAL_PRECISE
5254 >>> x, y = Ints('x y')
5255 >>> g.add(x == y + 1)
5256 >>> g.prec() == Z3_GOAL_PRECISE
5258 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5261 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5262 >>> g2.prec() == Z3_GOAL_PRECISE
5264 >>> g2.prec() == Z3_GOAL_UNDER
5270 """Alias for `prec()`.
5273 >>> g.precision() == Z3_GOAL_PRECISE
5276 return self.
precprec()
5279 """Return the number of constraints in the goal `self`.
5284 >>> x, y = Ints('x y')
5285 >>> g.add(x == 0, y > x)
5292 """Return the number of constraints in the goal `self`.
5297 >>> x, y = Ints('x y')
5298 >>> g.add(x == 0, y > x)
5302 return self.
sizesize()
5305 """Return a constraint in the goal `self`.
5308 >>> x, y = Ints('x y')
5309 >>> g.add(x == 0, y > x)
5318 """Return a constraint in the goal `self`.
5321 >>> x, y = Ints('x y')
5322 >>> g.add(x == 0, y > x)
5328 if arg >= len(self):
5330 return self.
getget(arg)
5333 """Assert constraints into the goal.
5337 >>> g.assert_exprs(x > 0, x < 2)
5341 args = _get_args(args)
5352 >>> g.append(x > 0, x < 2)
5363 >>> g.insert(x > 0, x < 2)
5374 >>> g.add(x > 0, x < 2)
5381 """Retrieve model from a satisfiable goal
5382 >>> a, b = Ints('a b')
5384 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5385 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5388 [Or(b == 0, b == 1), Not(0 <= b)]
5390 [Or(b == 0, b == 1), Not(1 <= b)]
5391 >>> # Remark: the subgoal r[0] is unsatisfiable
5392 >>> # Creating a solver for solving the second subgoal
5399 >>> # Model s.model() does not assign a value to `a`
5400 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5401 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5402 >>> r[1].convert_model(s.model())
5406 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5410 return obj_to_string(self)
5413 """Return a textual representation of the s-expression representing the goal."""
5417 """Return a textual representation of the goal in DIMACS format."""
5421 """Copy goal `self` to context `target`.
5429 >>> g2 = g.translate(c2)
5432 >>> g.ctx == main_ctx()
5436 >>> g2.ctx == main_ctx()
5440 _z3_assert(isinstance(target, Context),
"target must be a context")
5450 """Return a new simplified goal.
5452 This method is essentially invoking the simplify tactic.
5456 >>> g.add(x + 1 >= 2)
5459 >>> g2 = g.simplify()
5462 >>> # g was not modified
5467 return t.apply(self, *arguments, **keywords)[0]
5470 """Return goal `self` as a single Z3 expression.
5487 return self.
getget(0)
5489 return And([ self.
getget(i)
for i
in range(len(self)) ], self.
ctxctx)
5497 """A collection (vector) of ASTs."""
5506 assert ctx
is not None
5514 if self.
vectorvector
is not None and self.
ctxctx.ref()
is not None:
5518 """Return the size of the vector `self`.
5523 >>> A.push(Int('x'))
5524 >>> A.push(Int('x'))
5531 """Return the AST at position `i`.
5534 >>> A.push(Int('x') + 1)
5535 >>> A.push(Int('y'))
5542 if isinstance(i, int):
5546 if i >= self.
__len____len__():
5550 elif isinstance(i, slice):
5555 """Update AST at position `i`.
5558 >>> A.push(Int('x') + 1)
5559 >>> A.push(Int('y'))
5566 if i >= self.
__len____len__():
5571 """Add `v` in the end of the vector.
5576 >>> A.push(Int('x'))
5583 """Resize the vector to `sz` elements.
5589 >>> for i in range(10): A[i] = Int('x')
5596 """Return `True` if the vector contains `item`.
5619 """Copy vector `self` to context `other_ctx`.
5625 >>> B = A.translate(c2)
5638 return obj_to_string(self)
5641 """Return a textual representation of the s-expression representing the vector."""
5650 """A mapping from ASTs to ASTs."""
5659 assert ctx
is not None
5667 if self.
mapmap
is not None and self.
ctxctx.ref()
is not None:
5671 """Return the size of the map.
5677 >>> M[x] = IntVal(1)
5684 """Return `True` if the map contains key `key`.
5697 """Retrieve the value associated with key `key`.
5708 """Add/Update key `k` with value `v`.
5717 >>> M[x] = IntVal(1)
5727 """Remove the entry associated with key `k`.
5741 """Remove all entries from the map.
5746 >>> M[x+x] = IntVal(1)
5756 """Return an AstVector containing all keys in the map.
5761 >>> M[x+x] = IntVal(1)
5774 """Store the value of the interpretation of a function in a particular point."""
5785 if self.
ctxctx.ref()
is not None:
5789 """Return the number of arguments in the given entry.
5791 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5793 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5798 >>> f_i.num_entries()
5800 >>> e = f_i.entry(0)
5807 """Return the value of argument `idx`.
5809 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5811 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5816 >>> f_i.num_entries()
5818 >>> e = f_i.entry(0)
5829 ... except IndexError:
5830 ... print("index error")
5838 """Return the value of the function at point `self`.
5840 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5842 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5847 >>> f_i.num_entries()
5849 >>> e = f_i.entry(0)
5860 """Return entry `self` as a Python list.
5861 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5863 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5868 >>> f_i.num_entries()
5870 >>> e = f_i.entry(0)
5875 args.append(self.
valuevalue())
5879 return repr(self.
as_listas_list())
5882 """Stores the interpretation of a function in a Z3 model."""
5887 if self.
ff
is not None:
5894 if self.
ff
is not None and self.
ctxctx.ref()
is not None:
5899 Return the `else` value for a function interpretation.
5900 Return None if Z3 did not specify the `else` value for
5903 >>> f = Function('f', IntSort(), IntSort())
5905 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5911 >>> m[f].else_value()
5916 return _to_expr_ref(r, self.
ctxctx)
5921 """Return the number of entries/points in the function interpretation `self`.
5923 >>> f = Function('f', IntSort(), IntSort())
5925 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5931 >>> m[f].num_entries()
5937 """Return the number of arguments for each entry in the function interpretation `self`.
5939 >>> f = Function('f', IntSort(), IntSort())
5941 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5951 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5953 >>> f = Function('f', IntSort(), IntSort())
5955 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5961 >>> m[f].num_entries()
5971 """Copy model 'self' to context 'other_ctx'.
5982 """Return the function interpretation as a Python list.
5983 >>> f = Function('f', IntSort(), IntSort())
5985 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5999 return obj_to_string(self)
6002 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6005 assert ctx
is not None
6011 if self.
ctxctx.ref()
is not None:
6015 return obj_to_string(self)
6018 """Return a textual representation of the s-expression representing the model."""
6021 def eval(self, t, model_completion=False):
6022 """Evaluate the expression `t` in the model `self`. If `model_completion` is enabled, then a default interpretation is automatically added for symbols that do not have an interpretation in the model `self`.
6026 >>> s.add(x > 0, x < 2)
6039 >>> m.eval(y, model_completion=True)
6041 >>> # Now, m contains an interpretation for y
6047 return _to_expr_ref(r[0], self.
ctxctx)
6048 raise Z3Exception(
"failed to evaluate expression in the model")
6051 """Alias for `eval`.
6055 >>> s.add(x > 0, x < 2)
6059 >>> m.evaluate(x + 1)
6061 >>> m.evaluate(x == 1)
6064 >>> m.evaluate(y + x)
6068 >>> m.evaluate(y, model_completion=True)
6070 >>> # Now, m contains an interpretation for y
6071 >>> m.evaluate(y + x)
6074 return self.
evaleval(t, model_completion)
6077 """Return the number of constant and function declarations in the model `self`.
6079 >>> f = Function('f', IntSort(), IntSort())
6082 >>> s.add(x > 0, f(x) != x)
6092 """Return the interpretation for a given declaration or constant.
6094 >>> f = Function('f', IntSort(), IntSort())
6097 >>> s.add(x > 0, x < 2, f(x) == 0)
6107 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6111 if decl.arity() == 0:
6113 if _r.value
is None:
6115 r = _to_expr_ref(_r, self.
ctxctx)
6126 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6128 >>> A = DeclareSort('A')
6129 >>> a, b = Consts('a b', A)
6141 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6143 >>> A = DeclareSort('A')
6144 >>> B = DeclareSort('B')
6145 >>> a1, a2 = Consts('a1 a2', A)
6146 >>> b1, b2 = Consts('b1 b2', B)
6148 >>> s.add(a1 != a2, b1 != b2)
6164 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6166 >>> A = DeclareSort('A')
6167 >>> B = DeclareSort('B')
6168 >>> a1, a2 = Consts('a1 a2', A)
6169 >>> b1, b2 = Consts('b1 b2', B)
6171 >>> s.add(a1 != a2, b1 != b2)
6181 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6183 >>> A = DeclareSort('A')
6184 >>> a, b = Consts('a b', A)
6190 >>> m.get_universe(A)
6194 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6201 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpretation is returned.
6203 The elements can be retrieved using position or the actual declaration.
6205 >>> f = Function('f', IntSort(), IntSort())
6208 >>> s.add(x > 0, x < 2, f(x) == 0)
6222 >>> for d in m: print("%s -> %s" % (d, m[d]))
6227 if idx >= len(self):
6230 if (idx < num_consts):
6234 if isinstance(idx, FuncDeclRef):
6238 if isinstance(idx, SortRef):
6241 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6245 """Return a list with all symbols that have an interpretation in the model `self`.
6246 >>> f = Function('f', IntSort(), IntSort())
6249 >>> s.add(x > 0, x < 2, f(x) == 0)
6264 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6267 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6282 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6283 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6286 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6288 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6297 """Statistics for `Solver.check()`."""
6308 if self.
ctxctx.ref()
is not None:
6315 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6318 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6321 out.write(u(
'<tr>'))
6323 out.write(u(
'<td>%s</td><td>%s</td></tr>' % (k, v)))
6324 out.write(u(
'</table>'))
6325 return out.getvalue()
6330 """Return the number of statistical counters.
6333 >>> s = Then('simplify', 'nlsat').solver()
6337 >>> st = s.statistics()
6344 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6347 >>> s = Then('simplify', 'nlsat').solver()
6351 >>> st = s.statistics()
6355 ('nlsat propagations', 2)
6359 if idx >= len(self):
6368 """Return the list of statistical counters.
6371 >>> s = Then('simplify', 'nlsat').solver()
6375 >>> st = s.statistics()
6380 """Return the value of a particular statistical counter.
6383 >>> s = Then('simplify', 'nlsat').solver()
6387 >>> st = s.statistics()
6388 >>> st.get_key_value('nlsat propagations')
6391 for idx
in range(len(self)):
6397 raise Z3Exception(
"unknown key")
6400 """Access the value of statistical using attributes.
6402 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6403 we should use '_' (e.g., 'nlsat_propagations').
6406 >>> s = Then('simplify', 'nlsat').solver()
6410 >>> st = s.statistics()
6411 >>> st.nlsat_propagations
6416 key = name.replace(
'_',
' ')
6420 raise AttributeError
6428 """Represents the result of a satisfiability check: sat, unsat, unknown.
6434 >>> isinstance(r, CheckSatResult)
6445 return isinstance(other, CheckSatResult)
and self.
rr == other.r
6448 return not self.
__eq____eq__(other)
6452 if self.
rr == Z3_L_TRUE:
6454 elif self.
rr == Z3_L_FALSE:
6455 return "<b>unsat</b>"
6457 return "<b>unknown</b>"
6459 if self.
rr == Z3_L_TRUE:
6461 elif self.
rr == Z3_L_FALSE:
6466 def _repr_html_(self):
6467 in_html = in_html_mode()
6470 set_html_mode(in_html)
6478 """Solver API provides methods for implementing the main SMT 2.0 commands: push, pop, check, get-model, etc."""
6480 def __init__(self, solver=None, ctx=None, logFile=None):
6481 assert solver
is None or ctx
is not None
6488 self.
solversolver = solver
6490 if logFile
is not None:
6491 self.
setset(
"smtlib2_log", logFile)
6494 if self.
solversolver
is not None and self.
ctxctx.ref()
is not None:
6498 """Set a configuration option. The method `help()` return a string containing all available options.
6501 >>> # The option MBQI can be set using three different approaches.
6502 >>> s.set(mbqi=True)
6503 >>> s.set('MBQI', True)
6504 >>> s.set(':mbqi', True)
6510 """Create a backtracking point.
6532 """Backtrack \c num backtracking points.
6554 """Return the current number of backtracking points.
6572 """Remove all asserted constraints and backtracking points created using `push()`.
6586 """Assert constraints into the solver.
6590 >>> s.assert_exprs(x > 0, x < 2)
6594 args = _get_args(args)
6597 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6605 """Assert constraints into the solver.
6609 >>> s.add(x > 0, x < 2)
6620 """Assert constraints into the solver.
6624 >>> s.append(x > 0, x < 2)
6631 """Assert constraints into the solver.
6635 >>> s.insert(x > 0, x < 2)
6642 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6644 If `p` is a string, it will be automatically converted into a Boolean constant.
6649 >>> s.set(unsat_core=True)
6650 >>> s.assert_and_track(x > 0, 'p1')
6651 >>> s.assert_and_track(x != 1, 'p2')
6652 >>> s.assert_and_track(x < 0, p3)
6653 >>> print(s.check())
6655 >>> c = s.unsat_core()
6665 if isinstance(p, str):
6667 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6668 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6672 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
6678 >>> s.add(x > 0, x < 2)
6681 >>> s.model().eval(x)
6687 >>> s.add(2**x == 4)
6692 assumptions = _get_args(assumptions)
6693 num = len(assumptions)
6694 _assumptions = (Ast * num)()
6695 for i
in range(num):
6696 _assumptions[i] = s.cast(assumptions[i]).as_ast()
6701 """Return a model for the last `check()`.
6703 This function raises an exception if
6704 a model is not available (e.g., last `check()` returned unsat).
6708 >>> s.add(a + 2 == 0)
6717 raise Z3Exception(
"model is not available")
6720 """Import model converter from other into the current solver"""
6724 """Return a subset (as an AST vector) of the assumptions provided to the last check().
6726 These are the assumptions Z3 used in the unsatisfiability proof.
6727 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
6728 They may be also used to "retract" assumptions. Note that, assumptions are not really
6729 "soft constraints", but they can be used to implement them.
6731 >>> p1, p2, p3 = Bools('p1 p2 p3')
6732 >>> x, y = Ints('x y')
6734 >>> s.add(Implies(p1, x > 0))
6735 >>> s.add(Implies(p2, y > x))
6736 >>> s.add(Implies(p2, y < 1))
6737 >>> s.add(Implies(p3, y > -3))
6738 >>> s.check(p1, p2, p3)
6740 >>> core = s.unsat_core()
6749 >>> # "Retracting" p2
6756 """Determine fixed values for the variables based on the solver state and assumptions.
6758 >>> a, b, c, d = Bools('a b c d')
6759 >>> s.add(Implies(a,b), Implies(b, c))
6760 >>> s.consequences([a],[b,c,d])
6761 (sat, [Implies(a, b), Implies(a, c)])
6762 >>> s.consequences([Not(c),d],[a,b,c,d])
6763 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
6765 if isinstance(assumptions, list):
6767 for a
in assumptions:
6770 if isinstance(variables, list):
6775 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
6776 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
6779 sz = len(consequences)
6780 consequences = [ consequences[i]
for i
in range(sz) ]
6784 """Parse assertions from a file"""
6788 """Parse assertions from a string"""
6793 The method takes an optional set of variables that restrict which
6794 variables may be used as a starting point for cubing.
6795 If vars is not None, then the first case split is based on a variable in
6799 if vars
is not None:
6806 if (len(r) == 1
and is_false(r[0])):
6813 """Access the set of variables that were touched by the most recently generated cube.
6814 This set of variables can be used as a starting point for additional cubes.
6815 The idea is that variables that appear in clauses that are reduced by the most recent
6816 cube are likely more useful to cube on."""
6820 """Return a proof for the last `check()`. Proof construction must be enabled."""
6824 """Return an AST vector containing all added constraints.
6838 """Return an AST vector containing all currently inferred units.
6843 """Return an AST vector containing all atomic formulas in solver state that are not units.
6848 """Return trail and decision levels of the solver state after a check() call.
6850 trail = self.
trailtrail()
6851 levels = (ctypes.c_uint * len(trail))()
6853 return trail, levels
6856 """Return trail of the solver state after a check() call.
6861 """Return statistics for the last `check()`.
6863 >>> s = SimpleSolver()
6868 >>> st = s.statistics()
6869 >>> st.get_key_value('final checks')
6879 """Return a string describing why the last `check()` returned `unknown`.
6882 >>> s = SimpleSolver()
6883 >>> s.add(2**x == 4)
6886 >>> s.reason_unknown()
6887 '(incomplete (theory arithmetic))'
6892 """Display a string describing all available options."""
6896 """Return the parameter description set."""
6900 """Return a formatted string with all added constraints."""
6901 return obj_to_string(self)
6904 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6908 >>> s1 = Solver(ctx=c1)
6909 >>> s2 = s1.translate(c2)
6912 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6914 return Solver(solver, target)
6923 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
6934 """Return a textual representation of the solver in DIMACS format."""
6938 """return SMTLIB2 formatted benchmark for solver's assertions"""
6945 for i
in range(sz1):
6946 v[i] = es[i].as_ast()
6948 e = es[sz1].as_ast()
6954 """Create a solver customized for the given logic.
6956 The parameter `logic` is a string. It should be contains
6957 the name of a SMT-LIB logic.
6958 See http://www.smtlib.org/ for the name of all available logics.
6960 >>> s = SolverFor("QF_LIA")
6974 """Return a simple general purpose solver with limited amount of preprocessing.
6976 >>> s = SimpleSolver()
6992 """Fixedpoint API provides methods for solving with recursive predicates"""
6995 assert fixedpoint
is None or ctx
is not None
6998 if fixedpoint
is None:
7009 if self.
fixedpointfixedpoint
is not None and self.
ctxctx.ref()
is not None:
7013 """Set a configuration option. The method `help()` return a string containing all available options.
7019 """Display a string describing all available options."""
7023 """Return the parameter description set."""
7027 """Assert constraints as background axioms for the fixedpoint solver."""
7028 args = _get_args(args)
7031 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7041 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7049 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7053 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7057 """Assert rules defining recursive predicates to the fixedpoint solver.
7060 >>> s = Fixedpoint()
7061 >>> s.register_relation(a.decl())
7062 >>> s.register_relation(b.decl())
7075 body = _get_args(body)
7079 def rule(self, head, body = None, name = None):
7080 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7081 self.
add_ruleadd_rule(head, body, name)
7084 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7085 self.
add_ruleadd_rule(head,
None, name)
7088 """Query the fixedpoint engine whether formula is derivable.
7089 You can also pass an tuple or list of recursive predicates.
7091 query = _get_args(query)
7093 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7094 _decls = (FuncDecl * sz)()
7104 query =
And(query, self.
ctxctx)
7105 query = self.
abstractabstract(query,
False)
7110 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7112 query = _get_args(query)
7114 if sz >= 1
and isinstance(query[0], FuncDecl):
7115 _z3_assert (
False,
"unsupported")
7121 query = self.
abstractabstract(query,
False)
7122 r = Z3_fixedpoint_query_from_lvl (self.
ctxctx.ref(), self.
fixedpointfixedpoint, query.as_ast(), lvl)
7130 body = _get_args(body)
7135 """Retrieve answer from last query call."""
7137 return _to_expr_ref(r, self.
ctxctx)
7140 """Retrieve a ground cex from last query call."""
7141 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctxctx.ref(), self.
fixedpointfixedpoint)
7142 return _to_expr_ref(r, self.
ctxctx)
7145 """retrieve rules along the counterexample trace"""
7149 """retrieve rule names along the counterexample trace"""
7152 names = _symbol2py (self.
ctxctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctxctx.ref(), self.
fixedpointfixedpoint))
7154 return names.split (
';')
7157 """Retrieve number of levels used for predicate in PDR engine"""
7161 """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)"""
7163 return _to_expr_ref(r, self.
ctxctx)
7166 """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)"""
7170 """Register relation as recursive"""
7171 relations = _get_args(relations)
7176 """Control how relation is represented"""
7177 representations = _get_args(representations)
7178 representations = [
to_symbol(s)
for s
in representations]
7179 sz = len(representations)
7180 args = (Symbol * sz)()
7182 args[i] = representations[i]
7186 """Parse rules and queries from a string"""
7190 """Parse rules and queries from a file"""
7194 """retrieve rules that have been added to fixedpoint context"""
7198 """retrieve assertions that have been added to fixedpoint context"""
7202 """Return a formatted string with all added rules and constraints."""
7203 return self.
sexprsexpr()
7206 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7211 """Return a formatted string (in Lisp-like format) with all added constraints.
7212 We say the string is in s-expression format.
7213 Include also queries.
7215 args, len = _to_ast_array(queries)
7219 """Return statistics for the last `query()`.
7224 """Return a string describing why the last `query()` returned `unknown`.
7229 """Add variable or several variables.
7230 The added variable or variables will be bound in the rules
7233 vars = _get_args(vars)
7235 self.
varsvars += [v]
7238 if self.
varsvars == []:
7253 """Finite domain sort."""
7256 """Return the size of the finite domain sort"""
7257 r = (ctypes.c_ulonglong * 1)()
7261 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7264 """Create a named finite domain sort of a given size sz"""
7265 if not isinstance(name, Symbol):
7271 """Return True if `s` is a Z3 finite-domain sort.
7273 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7275 >>> is_finite_domain_sort(IntSort())
7278 return isinstance(s, FiniteDomainSortRef)
7282 """Finite-domain expressions."""
7285 """Return the sort of the finite-domain expression `self`."""
7289 """Return a Z3 floating point expression as a Python string."""
7293 """Return `True` if `a` is a Z3 finite-domain expression.
7295 >>> s = FiniteDomainSort('S', 100)
7296 >>> b = Const('b', s)
7297 >>> is_finite_domain(b)
7299 >>> is_finite_domain(Int('x'))
7302 return isinstance(a, FiniteDomainRef)
7306 """Integer values."""
7309 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7311 >>> s = FiniteDomainSort('S', 100)
7312 >>> v = FiniteDomainVal(3, s)
7321 """Return a Z3 finite-domain numeral as a Python string.
7323 >>> s = FiniteDomainSort('S', 100)
7324 >>> v = FiniteDomainVal(42, s)
7332 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7334 >>> s = FiniteDomainSort('S', 256)
7335 >>> FiniteDomainVal(255, s)
7337 >>> FiniteDomainVal('100', s)
7346 """Return `True` if `a` is a Z3 finite-domain value.
7348 >>> s = FiniteDomainSort('S', 100)
7349 >>> b = Const('b', s)
7350 >>> is_finite_domain_value(b)
7352 >>> b = FiniteDomainVal(10, s)
7355 >>> is_finite_domain_value(b)
7370 self.
_value_value = value
7391 return self.
upperupper()
7393 return self.
lowerlower()
7400 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7411 if self.
optimizeoptimize
is not None and self.
ctxctx.ref()
is not None:
7415 """Set a configuration option. The method `help()` return a string containing all available options.
7421 """Display a string describing all available options."""
7425 """Return the parameter description set."""
7429 """Assert constraints as background axioms for the optimize solver."""
7430 args = _get_args(args)
7433 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7441 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7449 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7451 If `p` is a string, it will be automatically converted into a Boolean constant.
7456 >>> s.assert_and_track(x > 0, 'p1')
7457 >>> s.assert_and_track(x != 1, 'p2')
7458 >>> s.assert_and_track(x < 0, p3)
7459 >>> print(s.check())
7461 >>> c = s.unsat_core()
7471 if isinstance(p, str):
7473 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7474 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7478 """Add soft constraint with optional weight and optional identifier.
7479 If no weight is supplied, then the penalty for violating the soft constraint
7481 Soft constraints are grouped by identifiers. Soft constraints that are
7482 added without identifiers are grouped by default.
7485 weight =
"%d" % weight
7486 elif isinstance(weight, float):
7487 weight =
"%f" % weight
7488 if not isinstance(weight, str):
7489 raise Z3Exception(
"weight should be a string or an integer")
7497 """Add objective function to maximize."""
7501 """Add objective function to minimize."""
7505 """create a backtracking point for added rules, facts and assertions"""
7509 """restore to previously created backtracking point"""
7513 """Check satisfiability while optimizing objective functions."""
7514 assumptions = _get_args(assumptions)
7515 num = len(assumptions)
7516 _assumptions = (Ast * num)()
7517 for i
in range(num):
7518 _assumptions[i] = assumptions[i].as_ast()
7522 """Return a string that describes why the last `check()` returned `unknown`."""
7526 """Return a model for the last check()."""
7530 raise Z3Exception(
"model is not available")
7536 if not isinstance(obj, OptimizeObjective):
7537 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7541 if not isinstance(obj, OptimizeObjective):
7542 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7546 if not isinstance(obj, OptimizeObjective):
7547 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7548 return obj.lower_values()
7551 if not isinstance(obj, OptimizeObjective):
7552 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7553 return obj.upper_values()
7556 """Parse assertions and objectives from a file"""
7560 """Parse assertions and objectives from a string"""
7564 """Return an AST vector containing all added constraints."""
7568 """returns set of objective functions"""
7572 """Return a formatted string with all added rules and constraints."""
7573 return self.
sexprsexpr()
7576 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7581 """Return statistics for the last check`.
7594 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters."""
7605 if self.
ctxctx.ref()
is not None:
7609 """Return the number of subgoals in `self`.
7611 >>> a, b = Ints('a b')
7613 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7614 >>> t = Tactic('split-clause')
7618 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
7621 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
7628 """Return one of the subgoals stored in ApplyResult object `self`.
7630 >>> a, b = Ints('a b')
7632 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7633 >>> t = Tactic('split-clause')
7636 [a == 0, Or(b == 0, b == 1), a > b]
7638 [a == 1, Or(b == 0, b == 1), a > b]
7640 if idx >= len(self):
7645 return obj_to_string(self)
7648 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
7653 """Return a Z3 expression consisting of all subgoals.
7658 >>> g.add(Or(x == 2, x == 3))
7659 >>> r = Tactic('simplify')(g)
7661 [[Not(x <= 1), Or(x == 2, x == 3)]]
7663 And(Not(x <= 1), Or(x == 2, x == 3))
7664 >>> r = Tactic('split-clause')(g)
7666 [[x > 1, x == 2], [x > 1, x == 3]]
7668 Or(And(x > 1, x == 2), And(x > 1, x == 3))
7684 """Tactics transform, solver and/or simplify sets of constraints (Goal). A Tactic can be converted into a Solver using the method solver().
7686 Several combinators are available for creating new tactics using the built-in ones: Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
7691 if isinstance(tactic, TacticObj):
7692 self.
tactictactic = tactic
7695 _z3_assert(isinstance(tactic, str),
"tactic name expected")
7699 raise Z3Exception(
"unknown tactic '%s'" % tactic)
7706 if self.
tactictactic
is not None and self.
ctxctx.ref()
is not None:
7710 """Create a solver using the tactic `self`.
7712 The solver supports the methods `push()` and `pop()`, but it
7713 will always solve each `check()` from scratch.
7715 >>> t = Then('simplify', 'nlsat')
7718 >>> s.add(x**2 == 2, x > 0)
7726 def apply(self, goal, *arguments, **keywords):
7727 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7729 >>> x, y = Ints('x y')
7730 >>> t = Tactic('solve-eqs')
7731 >>> t.apply(And(x == 0, y >= x + 1))
7735 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expressions expected")
7736 goal = _to_goal(goal)
7737 if len(arguments) > 0
or len(keywords) > 0:
7744 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7746 >>> x, y = Ints('x y')
7747 >>> t = Tactic('solve-eqs')
7748 >>> t(And(x == 0, y >= x + 1))
7751 return self.
applyapply(goal, *arguments, **keywords)
7754 """Display a string containing a description of the available options for the `self` tactic."""
7758 """Return the parameter description set."""
7762 if isinstance(a, BoolRef):
7763 goal =
Goal(ctx = a.ctx)
7769 def _to_tactic(t, ctx=None):
7770 if isinstance(t, Tactic):
7775 def _and_then(t1, t2, ctx=None):
7776 t1 = _to_tactic(t1, ctx)
7777 t2 = _to_tactic(t2, ctx)
7779 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7782 def _or_else(t1, t2, ctx=None):
7783 t1 = _to_tactic(t1, ctx)
7784 t2 = _to_tactic(t2, ctx)
7786 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7790 """Return a tactic that applies the tactics in `*ts` in sequence.
7792 >>> x, y = Ints('x y')
7793 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7794 >>> t(And(x == 0, y > x + 1))
7796 >>> t(And(x == 0, y > x + 1)).as_expr()
7800 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7801 ctx = ks.get(
'ctx',
None)
7804 for i
in range(num - 1):
7805 r = _and_then(r, ts[i+1], ctx)
7809 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7811 >>> x, y = Ints('x y')
7812 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7813 >>> t(And(x == 0, y > x + 1))
7815 >>> t(And(x == 0, y > x + 1)).as_expr()
7821 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7824 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7825 >>> # Tactic split-clause fails if there is no clause in the given goal.
7828 >>> t(Or(x == 0, x == 1))
7829 [[x == 0], [x == 1]]
7832 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7833 ctx = ks.get(
'ctx',
None)
7836 for i
in range(num - 1):
7837 r = _or_else(r, ts[i+1], ctx)
7841 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7844 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7849 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7850 ctx = _get_ctx(ks.get(
'ctx',
None))
7851 ts = [ _to_tactic(t, ctx)
for t
in ts ]
7853 _args = (TacticObj * sz)()
7855 _args[i] = ts[i].tactic
7859 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7861 >>> x, y = Ints('x y')
7862 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7863 >>> t(And(Or(x == 1, x == 2), y == x + 1))
7864 [[x == 1, y == 2], [x == 2, y == 3]]
7866 t1 = _to_tactic(t1, ctx)
7867 t2 = _to_tactic(t2, ctx)
7869 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7873 """Alias for ParThen(t1, t2, ctx)."""
7877 """Return a tactic that applies tactic `t` using the given configuration options.
7879 >>> x, y = Ints('x y')
7880 >>> t = With(Tactic('simplify'), som=True)
7881 >>> t((x + 1)*(y + 2) == 0)
7882 [[2*x + y + x*y == -2]]
7884 ctx = keys.pop(
'ctx',
None)
7885 t = _to_tactic(t, ctx)
7890 """Return a tactic that applies tactic `t` using the given configuration options.
7892 >>> x, y = Ints('x y')
7894 >>> p.set("som", True)
7895 >>> t = WithParams(Tactic('simplify'), p)
7896 >>> t((x + 1)*(y + 2) == 0)
7897 [[2*x + y + x*y == -2]]
7899 t = _to_tactic(t,
None)
7903 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7905 >>> x, y = Ints('x y')
7906 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7907 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7909 >>> for subgoal in r: print(subgoal)
7910 [x == 0, y == 0, x > y]
7911 [x == 0, y == 1, x > y]
7912 [x == 1, y == 0, x > y]
7913 [x == 1, y == 1, x > y]
7914 >>> t = Then(t, Tactic('propagate-values'))
7918 t = _to_tactic(t, ctx)
7922 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7924 If `t` does not terminate in `ms` milliseconds, then it fails.
7926 t = _to_tactic(t, ctx)
7930 """Return a list of all available tactics in Z3.
7933 >>> l.count('simplify') == 1
7940 """Return a short description for the tactic named `name`.
7942 >>> d = tactic_description('simplify')
7948 """Display a (tabular) description of all available tactics in Z3."""
7951 print(
'<table border="1" cellpadding="2" cellspacing="0">')
7954 print(
'<tr style="background-color:#CFCFCF">')
7959 print(
'<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(
tactic_description(t), 40)))
7966 """Probes are used to inspect a goal (aka problem) and collect information that may be used to decide which solver and/or preprocessing step will be used."""
7970 if isinstance(probe, ProbeObj):
7971 self.
probeprobe = probe
7972 elif isinstance(probe, float):
7974 elif _is_int(probe):
7976 elif isinstance(probe, bool):
7983 _z3_assert(isinstance(probe, str),
"probe name expected")
7987 raise Z3Exception(
"unknown probe '%s'" % probe)
7994 if self.
probeprobe
is not None and self.
ctxctx.ref()
is not None:
7998 """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
8000 >>> p = Probe('size') < 10
8011 """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
8013 >>> p = Probe('size') > 10
8024 """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
8026 >>> p = Probe('size') <= 2
8037 """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
8039 >>> p = Probe('size') >= 2
8050 """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
8052 >>> p = Probe('size') == 2
8063 """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
8065 >>> p = Probe('size') != 2
8073 p = self.
__eq____eq__(other)
8077 """Evaluate the probe `self` in the given goal.
8079 >>> p = Probe('size')
8089 >>> p = Probe('num-consts')
8092 >>> p = Probe('is-propositional')
8095 >>> p = Probe('is-qflia')
8100 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expression expected")
8101 goal = _to_goal(goal)
8105 """Return `True` if `p` is a Z3 probe.
8107 >>> is_probe(Int('x'))
8109 >>> is_probe(Probe('memory'))
8112 return isinstance(p, Probe)
8114 def _to_probe(p, ctx=None):
8118 return Probe(p, ctx)
8121 """Return a list of all available probes in Z3.
8124 >>> l.count('memory') == 1
8131 """Return a short description for the probe named `name`.
8133 >>> d = probe_description('memory')
8139 """Display a (tabular) description of all available probes in Z3."""
8142 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8145 print(
'<tr style="background-color:#CFCFCF">')
8150 print(
'<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(
probe_description(p), 40)))
8156 def _probe_nary(f, args, ctx):
8158 _z3_assert(len(args) > 0,
"At least one argument expected")
8160 r = _to_probe(args[0], ctx)
8161 for i
in range(num - 1):
8162 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i+1], ctx).probe), ctx)
8165 def _probe_and(args, ctx):
8166 return _probe_nary(Z3_probe_and, args, ctx)
8168 def _probe_or(args, ctx):
8169 return _probe_nary(Z3_probe_or, args, ctx)
8172 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8174 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
8176 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8177 >>> x, y = Ints('x y')
8183 >>> g.add(x == y + 1)
8185 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8187 p = _to_probe(p, ctx)
8191 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8193 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8194 >>> x, y = Ints('x y')
8200 >>> g.add(x == y + 1)
8202 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8204 p = _to_probe(p, ctx)
8205 t = _to_tactic(t, ctx)
8209 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8211 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8213 p = _to_probe(p, ctx)
8214 t1 = _to_tactic(t1, ctx)
8215 t2 = _to_tactic(t2, ctx)
8225 """Simplify the expression `a` using the given options.
8227 This function has many options. Use `help_simplify` to obtain the complete list.
8231 >>> simplify(x + 1 + y + x + 1)
8233 >>> simplify((x + 1)*(y + 1), som=True)
8235 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8236 And(Not(x == y), Not(x == 1), Not(y == 1))
8237 >>> simplify(And(x == 0, y == 1), elim_and=True)
8238 Not(Or(Not(x == 0), Not(y == 1)))
8241 _z3_assert(
is_expr(a),
"Z3 expression expected")
8242 if len(arguments) > 0
or len(keywords) > 0:
8244 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8246 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8249 """Return a string describing all options available for Z3 `simplify` procedure."""
8253 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8257 """Apply substitution m on t, m is a list of pairs of the form (from, to). Every occurrence in t of from is replaced with to.
8261 >>> substitute(x + 1, (x, y + 1))
8263 >>> f = Function('f', IntSort(), IntSort())
8264 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8267 if isinstance(m, tuple):
8269 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8272 _z3_assert(
is_expr(t),
"Z3 expression expected")
8273 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8275 _from = (Ast * num)()
8277 for i
in range(num):
8278 _from[i] = m[i][0].as_ast()
8279 _to[i] = m[i][1].as_ast()
8280 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8283 """Substitute the free variables in t with the expression in m.
8285 >>> v0 = Var(0, IntSort())
8286 >>> v1 = Var(1, IntSort())
8288 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8289 >>> # replace v0 with x+1 and v1 with x
8290 >>> substitute_vars(f(v0, v1), x + 1, x)
8294 _z3_assert(
is_expr(t),
"Z3 expression expected")
8295 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8298 for i
in range(num):
8299 _to[i] = m[i].as_ast()
8303 """Create the sum of the Z3 expressions.
8305 >>> a, b, c = Ints('a b c')
8310 >>> A = IntVector('a', 5)
8312 a__0 + a__1 + a__2 + a__3 + a__4
8314 args = _get_args(args)
8317 ctx = _ctx_from_ast_arg_list(args)
8319 return _reduce(
lambda a, b: a + b, args, 0)
8320 args = _coerce_expr_list(args, ctx)
8322 return _reduce(
lambda a, b: a + b, args, 0)
8324 _args, sz = _to_ast_array(args)
8329 """Create the product of the Z3 expressions.
8331 >>> a, b, c = Ints('a b c')
8332 >>> Product(a, b, c)
8334 >>> Product([a, b, c])
8336 >>> A = IntVector('a', 5)
8338 a__0*a__1*a__2*a__3*a__4
8340 args = _get_args(args)
8343 ctx = _ctx_from_ast_arg_list(args)
8345 return _reduce(
lambda a, b: a * b, args, 1)
8346 args = _coerce_expr_list(args, ctx)
8348 return _reduce(
lambda a, b: a * b, args, 1)
8350 _args, sz = _to_ast_array(args)
8354 """Create an at-most Pseudo-Boolean k constraint.
8356 >>> a, b, c = Bools('a b c')
8357 >>> f = AtMost(a, b, c, 2)
8359 args = _get_args(args)
8361 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8362 ctx = _ctx_from_ast_arg_list(args)
8364 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8365 args1 = _coerce_expr_list(args[:-1], ctx)
8367 _args, sz = _to_ast_array(args1)
8371 """Create an at-most Pseudo-Boolean k constraint.
8373 >>> a, b, c = Bools('a b c')
8374 >>> f = AtLeast(a, b, c, 2)
8376 args = _get_args(args)
8378 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8379 ctx = _ctx_from_ast_arg_list(args)
8381 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8382 args1 = _coerce_expr_list(args[:-1], ctx)
8384 _args, sz = _to_ast_array(args1)
8387 def _reorder_pb_arg(arg):
8389 if not _is_int(b)
and _is_int(a):
8393 def _pb_args_coeffs(args, default_ctx = None):
8394 args = _get_args_ast_list(args)
8396 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8397 args = [_reorder_pb_arg(arg)
for arg
in args]
8398 args, coeffs = zip(*args)
8400 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8401 ctx = _ctx_from_ast_arg_list(args)
8403 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8404 args = _coerce_expr_list(args, ctx)
8405 _args, sz = _to_ast_array(args)
8406 _coeffs = (ctypes.c_int * len(coeffs))()
8407 for i
in range(len(coeffs)):
8408 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8409 _coeffs[i] = coeffs[i]
8410 return ctx, sz, _args, _coeffs
8413 """Create a Pseudo-Boolean inequality k constraint.
8415 >>> a, b, c = Bools('a b c')
8416 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8418 _z3_check_cint_overflow(k,
"k")
8419 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8423 """Create a Pseudo-Boolean inequality k constraint.
8425 >>> a, b, c = Bools('a b c')
8426 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8428 _z3_check_cint_overflow(k,
"k")
8429 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8433 """Create a Pseudo-Boolean inequality k constraint.
8435 >>> a, b, c = Bools('a b c')
8436 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8438 _z3_check_cint_overflow(k,
"k")
8439 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8444 """Solve the constraints `*args`.
8446 This is a simple function for creating demonstrations. It creates a solver,
8447 configure it using the options in `keywords`, adds the constraints
8448 in `args`, and invokes check.
8451 >>> solve(a > 0, a < 2)
8457 if keywords.get(
'show',
False):
8461 print(
"no solution")
8463 print(
"failed to solve")
8472 """Solve the constraints `*args` using solver `s`.
8474 This is a simple function for creating demonstrations. It is similar to `solve`,
8475 but it uses the given solver `s`.
8476 It configures solver `s` using the options in `keywords`, adds the constraints
8477 in `args`, and invokes check.
8480 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8483 if keywords.get(
'show',
False):
8488 print(
"no solution")
8490 print(
"failed to solve")
8496 if keywords.get(
'show',
False):
8501 """Try to prove the given claim.
8503 This is a simple function for creating demonstrations. It tries to prove
8504 `claim` by showing the negation is unsatisfiable.
8506 >>> p, q = Bools('p q')
8507 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8511 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8515 if keywords.get(
'show',
False):
8521 print(
"failed to prove")
8524 print(
"counterexample")
8527 def _solve_html(*args, **keywords):
8528 """Version of function `solve` used in RiSE4Fun."""
8532 if keywords.get(
'show',
False):
8533 print(
"<b>Problem:</b>")
8537 print(
"<b>no solution</b>")
8539 print(
"<b>failed to solve</b>")
8545 if keywords.get(
'show',
False):
8546 print(
"<b>Solution:</b>")
8549 def _solve_using_html(s, *args, **keywords):
8550 """Version of function `solve_using` used in RiSE4Fun."""
8552 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8555 if keywords.get(
'show',
False):
8556 print(
"<b>Problem:</b>")
8560 print(
"<b>no solution</b>")
8562 print(
"<b>failed to solve</b>")
8568 if keywords.get(
'show',
False):
8569 print(
"<b>Solution:</b>")
8572 def _prove_html(claim, **keywords):
8573 """Version of function `prove` used in RiSE4Fun."""
8575 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8579 if keywords.get(
'show',
False):
8583 print(
"<b>proved</b>")
8585 print(
"<b>failed to prove</b>")
8588 print(
"<b>counterexample</b>")
8591 def _dict2sarray(sorts, ctx):
8593 _names = (Symbol * sz)()
8594 _sorts = (Sort * sz) ()
8599 _z3_assert(isinstance(k, str),
"String expected")
8600 _z3_assert(
is_sort(v),
"Z3 sort expected")
8604 return sz, _names, _sorts
8606 def _dict2darray(decls, ctx):
8608 _names = (Symbol * sz)()
8609 _decls = (FuncDecl * sz) ()
8614 _z3_assert(isinstance(k, str),
"String expected")
8618 _decls[i] = v.decl().ast
8622 return sz, _names, _decls
8626 """Parse a string in SMT 2.0 format using the given sorts and decls.
8628 The arguments sorts and decls are Python dictionaries used to initialize
8629 the symbol table used for the SMT 2.0 parser.
8631 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8633 >>> x, y = Ints('x y')
8634 >>> f = Function('f', IntSort(), IntSort())
8635 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8637 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
8641 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8642 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8646 """Parse a file in SMT 2.0 format using the given sorts and decls.
8648 This function is similar to parse_smt2_string().
8651 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8652 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8664 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
8665 _dflt_fpsort_ebits = 11
8666 _dflt_fpsort_sbits = 53
8669 """Retrieves the global default rounding mode."""
8670 global _dflt_rounding_mode
8671 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8673 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8675 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8677 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8679 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8683 global _dflt_rounding_mode
8685 _dflt_rounding_mode = rm.decl().kind()
8687 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO
or
8688 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE
or
8689 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE
or
8690 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
or
8691 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8692 "illegal rounding mode")
8693 _dflt_rounding_mode = rm
8696 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8699 global _dflt_fpsort_ebits
8700 global _dflt_fpsort_sbits
8701 _dflt_fpsort_ebits = ebits
8702 _dflt_fpsort_sbits = sbits
8704 def _dflt_rm(ctx=None):
8707 def _dflt_fps(ctx=None):
8710 def _coerce_fp_expr_list(alist, ctx):
8711 first_fp_sort =
None
8714 if first_fp_sort
is None:
8715 first_fp_sort = a.sort()
8716 elif first_fp_sort == a.sort():
8721 first_fp_sort =
None
8725 for i
in range(len(alist)):
8727 if (isinstance(a, str)
and a.contains(
'2**(')
and a.endswith(
')'))
or _is_int(a)
or isinstance(a, float)
or isinstance(a, bool):
8728 r.append(
FPVal(a,
None, first_fp_sort, ctx))
8731 return _coerce_expr_list(r, ctx)
8737 """Floating-point sort."""
8740 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
8741 >>> b = FPSort(8, 24)
8748 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
8749 >>> b = FPSort(8, 24)
8756 """Try to cast `val` as a floating-point expression.
8757 >>> b = FPSort(8, 24)
8760 >>> b.cast(1.0).sexpr()
8761 '(fp #b0 #x7f #b00000000000000000000000)'
8765 _z3_assert(self.
ctxctxctx == val.ctx,
"Context mismatch")
8772 """Floating-point 16-bit (half) sort."""
8777 """Floating-point 16-bit (half) sort."""
8782 """Floating-point 32-bit (single) sort."""
8787 """Floating-point 32-bit (single) sort."""
8792 """Floating-point 64-bit (double) sort."""
8797 """Floating-point 64-bit (double) sort."""
8802 """Floating-point 128-bit (quadruple) sort."""
8807 """Floating-point 128-bit (quadruple) sort."""
8812 """"Floating-point rounding mode sort."""
8816 """Return True if `s` is a Z3 floating-point sort.
8818 >>> is_fp_sort(FPSort(8, 24))
8820 >>> is_fp_sort(IntSort())
8823 return isinstance(s, FPSortRef)
8826 """Return True if `s` is a Z3 floating-point rounding mode sort.
8828 >>> is_fprm_sort(FPSort(8, 24))
8830 >>> is_fprm_sort(RNE().sort())
8833 return isinstance(s, FPRMSortRef)
8838 """Floating-point expressions."""
8841 """Return the sort of the floating-point expression `self`.
8843 >>> x = FP('1.0', FPSort(8, 24))
8846 >>> x.sort() == FPSort(8, 24)
8852 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8853 >>> b = FPSort(8, 24)
8860 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8861 >>> b = FPSort(8, 24)
8868 """Return a Z3 floating point expression as a Python string."""
8872 return fpLEQ(self, other, self.
ctxctx)
8875 return fpLT(self, other, self.
ctxctx)
8878 return fpGEQ(self, other, self.
ctxctx)
8881 return fpGT(self, other, self.
ctxctx)
8884 """Create the Z3 expression `self + other`.
8886 >>> x = FP('x', FPSort(8, 24))
8887 >>> y = FP('y', FPSort(8, 24))
8893 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
8894 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
8897 """Create the Z3 expression `other + self`.
8899 >>> x = FP('x', FPSort(8, 24))
8903 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
8904 return fpAdd(_dflt_rm(), a, b, self.
ctxctx)
8907 """Create the Z3 expression `self - other`.
8909 >>> x = FP('x', FPSort(8, 24))
8910 >>> y = FP('y', FPSort(8, 24))
8916 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
8917 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
8920 """Create the Z3 expression `other - self`.
8922 >>> x = FP('x', FPSort(8, 24))
8926 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
8927 return fpSub(_dflt_rm(), a, b, self.
ctxctx)
8930 """Create the Z3 expression `self * other`.
8932 >>> x = FP('x', FPSort(8, 24))
8933 >>> y = FP('y', FPSort(8, 24))
8941 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
8942 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
8945 """Create the Z3 expression `other * self`.
8947 >>> x = FP('x', FPSort(8, 24))
8948 >>> y = FP('y', FPSort(8, 24))
8954 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
8955 return fpMul(_dflt_rm(), a, b, self.
ctxctx)
8958 """Create the Z3 expression `+self`."""
8962 """Create the Z3 expression `-self`.
8964 >>> x = FP('x', Float32())
8971 """Create the Z3 expression `self / other`.
8973 >>> x = FP('x', FPSort(8, 24))
8974 >>> y = FP('y', FPSort(8, 24))
8982 [a, b] = _coerce_fp_expr_list([self, other], self.
ctxctx)
8983 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
8986 """Create the Z3 expression `other / self`.
8988 >>> x = FP('x', FPSort(8, 24))
8989 >>> y = FP('y', FPSort(8, 24))
8995 [a, b] = _coerce_fp_expr_list([other, self], self.
ctxctx)
8996 return fpDiv(_dflt_rm(), a, b, self.
ctxctx)
8999 """Create the Z3 expression division `self / other`."""
9000 return self.
__div____div__(other)
9003 """Create the Z3 expression division `other / self`."""
9004 return self.
__rdiv____rdiv__(other)
9007 """Create the Z3 expression mod `self % other`."""
9008 return fpRem(self, other)
9011 """Create the Z3 expression mod `other % self`."""
9012 return fpRem(other, self)
9015 """Floating-point rounding mode expressions"""
9018 """Return a Z3 floating point expression as a Python string."""
9063 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9072 return isinstance(a, FPRMRef)
9075 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9076 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9081 """The sign of the numeral.
9083 >>> x = FPVal(+1.0, FPSort(8, 24))
9086 >>> x = FPVal(-1.0, FPSort(8, 24))
9091 l = (ctypes.c_int)()
9093 raise Z3Exception(
"error retrieving the sign of a numeral.")
9096 """The sign of a floating-point numeral as a bit-vector expression.
9098 Remark: NaN's are invalid arguments.
9103 """The significand of the numeral.
9105 >>> x = FPVal(2.5, FPSort(8, 24))
9112 """The significand of the numeral as a long.
9114 >>> x = FPVal(2.5, FPSort(8, 24))
9115 >>> x.significand_as_long()
9119 ptr = (ctypes.c_ulonglong * 1)()
9121 raise Z3Exception(
"error retrieving the significand of a numeral.")
9124 """The significand of the numeral as a bit-vector expression.
9126 Remark: NaN are invalid arguments.
9131 """The exponent of the numeral.
9133 >>> x = FPVal(2.5, FPSort(8, 24))
9140 """The exponent of the numeral as a long.
9142 >>> x = FPVal(2.5, FPSort(8, 24))
9143 >>> x.exponent_as_long()
9147 ptr = (ctypes.c_longlong * 1)()
9149 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9152 """The exponent of the numeral as a bit-vector expression.
9154 Remark: NaNs are invalid arguments.
9159 """Indicates whether the numeral is a NaN."""
9163 """Indicates whether the numeral is +oo or -oo."""
9167 """Indicates whether the numeral is +zero or -zero."""
9171 """Indicates whether the numeral is normal."""
9175 """Indicates whether the numeral is subnormal."""
9179 """Indicates whether the numeral is positive."""
9183 """Indicates whether the numeral is negative."""
9188 The string representation of the numeral.
9190 >>> x = FPVal(20, FPSort(8, 24))
9196 return (
"FPVal(%s, %s)" % (s, self.
sortsortsort()))
9199 """Return `True` if `a` is a Z3 floating-point expression.
9201 >>> b = FP('b', FPSort(8, 24))
9209 return isinstance(a, FPRef)
9212 """Return `True` if `a` is a Z3 floating-point numeral value.
9214 >>> b = FP('b', FPSort(8, 24))
9217 >>> b = FPVal(1.0, FPSort(8, 24))
9223 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9226 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9228 >>> Single = FPSort(8, 24)
9229 >>> Double = FPSort(11, 53)
9232 >>> x = Const('x', Single)
9233 >>> eq(x, FP('x', FPSort(8, 24)))
9239 def _to_float_str(val, exp=0):
9240 if isinstance(val, float):
9244 sone = math.copysign(1.0, val)
9249 elif val == float(
"+inf"):
9251 elif val == float(
"-inf"):
9254 v = val.as_integer_ratio()
9257 rvs = str(num) +
'/' + str(den)
9258 res = rvs +
'p' + _to_int_str(exp)
9259 elif isinstance(val, bool):
9266 elif isinstance(val, str):
9267 inx = val.find(
'*(2**')
9270 elif val[-1] ==
')':
9272 exp = str(int(val[inx+5:-1]) + int(exp))
9274 _z3_assert(
False,
"String does not have floating-point numeral form.")
9276 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9280 return res +
'p' + exp
9284 """Create a Z3 floating-point NaN term.
9286 >>> s = FPSort(8, 24)
9287 >>> set_fpa_pretty(True)
9290 >>> pb = get_fpa_pretty()
9291 >>> set_fpa_pretty(False)
9293 fpNaN(FPSort(8, 24))
9294 >>> set_fpa_pretty(pb)
9296 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9300 """Create a Z3 floating-point +oo term.
9302 >>> s = FPSort(8, 24)
9303 >>> pb = get_fpa_pretty()
9304 >>> set_fpa_pretty(True)
9305 >>> fpPlusInfinity(s)
9307 >>> set_fpa_pretty(False)
9308 >>> fpPlusInfinity(s)
9309 fpPlusInfinity(FPSort(8, 24))
9310 >>> set_fpa_pretty(pb)
9312 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9316 """Create a Z3 floating-point -oo term."""
9317 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9321 """Create a Z3 floating-point +oo or -oo term."""
9322 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9323 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9327 """Create a Z3 floating-point +0.0 term."""
9328 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9332 """Create a Z3 floating-point -0.0 term."""
9333 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9337 """Create a Z3 floating-point +0.0 or -0.0 term."""
9338 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9339 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9342 def FPVal(sig, exp=None, fps=None, ctx=None):
9343 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9345 >>> v = FPVal(20.0, FPSort(8, 24))
9348 >>> print("0x%.8x" % v.exponent_as_long(False))
9350 >>> v = FPVal(2.25, FPSort(8, 24))
9353 >>> v = FPVal(-2.25, FPSort(8, 24))
9356 >>> FPVal(-0.0, FPSort(8, 24))
9358 >>> FPVal(0.0, FPSort(8, 24))
9360 >>> FPVal(+0.0, FPSort(8, 24))
9368 fps = _dflt_fps(ctx)
9372 val = _to_float_str(sig)
9373 if val ==
"NaN" or val ==
"nan":
9377 elif val ==
"0.0" or val ==
"+0.0":
9379 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9381 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9386 def FP(name, fpsort, ctx=None):
9387 """Return a floating-point constant named `name`.
9388 `fpsort` is the floating-point sort.
9389 If `ctx=None`, then the global context is used.
9391 >>> x = FP('x', FPSort(8, 24))
9398 >>> word = FPSort(8, 24)
9399 >>> x2 = FP('x', word)
9403 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9409 def FPs(names, fpsort, ctx=None):
9410 """Return an array of floating-point constants.
9412 >>> x, y, z = FPs('x y z', FPSort(8, 24))
9419 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9420 fpMul(RNE(), fpAdd(RNE(), x, y), z)
9423 if isinstance(names, str):
9424 names = names.split(
" ")
9425 return [
FP(name, fpsort, ctx)
for name
in names]
9428 """Create a Z3 floating-point absolute value expression.
9430 >>> s = FPSort(8, 24)
9432 >>> x = FPVal(1.0, s)
9435 >>> y = FPVal(-20.0, s)
9440 >>> fpAbs(-1.25*(2**4))
9446 [a] = _coerce_fp_expr_list([a], ctx)
9450 """Create a Z3 floating-point addition expression.
9452 >>> s = FPSort(8, 24)
9461 [a] = _coerce_fp_expr_list([a], ctx)
9464 def _mk_fp_unary(f, rm, a, ctx):
9466 [a] = _coerce_fp_expr_list([a], ctx)
9468 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9469 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9470 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9472 def _mk_fp_unary_pred(f, a, ctx):
9474 [a] = _coerce_fp_expr_list([a], ctx)
9476 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9477 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9479 def _mk_fp_bin(f, rm, a, b, ctx):
9481 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9483 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9484 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9485 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
9487 def _mk_fp_bin_norm(f, a, b, ctx):
9489 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9491 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9492 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9494 def _mk_fp_bin_pred(f, a, b, ctx):
9496 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9498 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9499 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9501 def _mk_fp_tern(f, rm, a, b, c, ctx):
9503 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
9505 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9506 _z3_assert(
is_fp(a)
or is_fp(b)
or is_fp(c),
"Second, third or fourth argument must be a Z3 floating-point expression")
9507 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
9510 """Create a Z3 floating-point addition expression.
9512 >>> s = FPSort(8, 24)
9518 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9520 >>> fpAdd(rm, x, y).sort()
9523 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9526 """Create a Z3 floating-point subtraction expression.
9528 >>> s = FPSort(8, 24)
9534 >>> fpSub(rm, x, y).sort()
9537 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9540 """Create a Z3 floating-point multiplication expression.
9542 >>> s = FPSort(8, 24)
9548 >>> fpMul(rm, x, y).sort()
9551 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9554 """Create a Z3 floating-point division expression.
9556 >>> s = FPSort(8, 24)
9562 >>> fpDiv(rm, x, y).sort()
9565 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9568 """Create a Z3 floating-point remainder expression.
9570 >>> s = FPSort(8, 24)
9575 >>> fpRem(x, y).sort()
9578 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9581 """Create a Z3 floating-point minimum expression.
9583 >>> s = FPSort(8, 24)
9589 >>> fpMin(x, y).sort()
9592 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9595 """Create a Z3 floating-point maximum expression.
9597 >>> s = FPSort(8, 24)
9603 >>> fpMax(x, y).sort()
9606 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9609 """Create a Z3 floating-point fused multiply-add expression.
9611 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9614 """Create a Z3 floating-point square root expression.
9616 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9619 """Create a Z3 floating-point roundToIntegral expression.
9621 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9624 """Create a Z3 floating-point isNaN expression.
9626 >>> s = FPSort(8, 24)
9632 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
9635 """Create a Z3 floating-point isInfinite expression.
9637 >>> s = FPSort(8, 24)
9642 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
9645 """Create a Z3 floating-point isZero expression.
9647 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
9650 """Create a Z3 floating-point isNormal expression.
9652 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
9655 """Create a Z3 floating-point isSubnormal expression.
9657 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
9660 """Create a Z3 floating-point isNegative expression.
9662 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
9665 """Create a Z3 floating-point isPositive expression.
9667 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
9669 def _check_fp_args(a, b):
9671 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9674 """Create the Z3 floating-point expression `other < self`.
9676 >>> x, y = FPs('x y', FPSort(8, 24))
9682 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9685 """Create the Z3 floating-point expression `other <= self`.
9687 >>> x, y = FPs('x y', FPSort(8, 24))
9690 >>> (x <= y).sexpr()
9693 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9696 """Create the Z3 floating-point expression `other > self`.
9698 >>> x, y = FPs('x y', FPSort(8, 24))
9704 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9707 """Create the Z3 floating-point expression `other >= self`.
9709 >>> x, y = FPs('x y', FPSort(8, 24))
9712 >>> (x >= y).sexpr()
9715 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9718 """Create the Z3 floating-point expression `fpEQ(other, self)`.
9720 >>> x, y = FPs('x y', FPSort(8, 24))
9723 >>> fpEQ(x, y).sexpr()
9726 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9729 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9731 >>> x, y = FPs('x y', FPSort(8, 24))
9734 >>> (x != y).sexpr()
9740 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9742 >>> s = FPSort(8, 24)
9743 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9745 fpFP(1, 127, 4194304)
9746 >>> xv = FPVal(-1.5, s)
9750 >>> slvr.add(fpEQ(x, xv))
9753 >>> xv = FPVal(+1.5, s)
9757 >>> slvr.add(fpEQ(x, xv))
9762 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
9764 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
9768 """Create a Z3 floating-point conversion expression from other term sorts
9771 From a bit-vector term in IEEE 754-2008 format:
9772 >>> x = FPVal(1.0, Float32())
9773 >>> x_bv = fpToIEEEBV(x)
9774 >>> simplify(fpToFP(x_bv, Float32()))
9777 From a floating-point term with different precision:
9778 >>> x = FPVal(1.0, Float32())
9779 >>> x_db = fpToFP(RNE(), x, Float64())
9784 >>> x_r = RealVal(1.5)
9785 >>> simplify(fpToFP(RNE(), x_r, Float32()))
9788 From a signed bit-vector term:
9789 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9790 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9803 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
9806 """Create a Z3 floating-point conversion expression that represents the
9807 conversion from a bit-vector term to a floating-point term.
9809 >>> x_bv = BitVecVal(0x3F800000, 32)
9810 >>> x_fp = fpBVToFP(x_bv, Float32())
9816 _z3_assert(
is_bv(v),
"First argument must be a Z3 bit-vector expression")
9817 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
9822 """Create a Z3 floating-point conversion expression that represents the
9823 conversion from a floating-point term to a floating-point term of different precision.
9825 >>> x_sgl = FPVal(1.0, Float32())
9826 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9834 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9835 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
9836 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9841 """Create a Z3 floating-point conversion expression that represents the
9842 conversion from a real term to a floating-point term.
9844 >>> x_r = RealVal(1.5)
9845 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9851 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9852 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
9853 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9858 """Create a Z3 floating-point conversion expression that represents the
9859 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9861 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9862 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9864 fpToFP(RNE(), 4294967291)
9868 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9869 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
9870 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9875 """Create a Z3 floating-point conversion expression that represents the
9876 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9878 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9879 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9881 fpToFPUnsigned(RNE(), 4294967291)
9885 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9886 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
9887 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9892 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9894 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9895 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
9896 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
9901 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9903 >>> x = FP('x', FPSort(8, 24))
9904 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9915 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9916 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9917 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9922 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9924 >>> x = FP('x', FPSort(8, 24))
9925 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9936 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9937 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9938 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9943 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9945 >>> x = FP('x', FPSort(8, 24))
9949 >>> print(is_real(y))
9953 >>> print(is_real(x))
9957 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9962 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9964 The size of the resulting bit-vector is automatically determined.
9966 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9967 knows only one NaN and it will always produce the same bit-vector representation of
9970 >>> x = FP('x', FPSort(8, 24))
9971 >>> y = fpToIEEEBV(x)
9982 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9995 """Sequence sort."""
9998 """Determine if sort is a string
9999 >>> s = StringSort()
10002 >>> s = SeqSort(IntSort())
10013 """Create a string sort
10014 >>> s = StringSort()
10018 ctx = _get_ctx(ctx)
10023 """Create a sequence sort over elements provided in the argument
10024 >>> s = SeqSort(IntSort())
10025 >>> s == Unit(IntVal(1)).sort()
10031 """Sequence expression."""
10037 return Concat(self, other)
10040 return Concat(other, self)
10060 """Return a string representation of sequence expression."""
10062 string_length = ctypes.c_uint()
10064 return string_at(chars, size=string_length.value).decode(
'latin-1')
10080 def _coerce_seq(s, ctx=None):
10081 if isinstance(s, str):
10082 ctx = _get_ctx(ctx)
10085 raise Z3Exception(
"Non-expression passed as a sequence")
10087 raise Z3Exception(
"Non-sequence passed as a sequence")
10090 def _get_ctx2(a, b, ctx=None):
10100 """Return `True` if `a` is a Z3 sequence expression.
10101 >>> print (is_seq(Unit(IntVal(0))))
10103 >>> print (is_seq(StringVal("abc")))
10106 return isinstance(a, SeqRef)
10109 """Return `True` if `a` is a Z3 string expression.
10110 >>> print (is_string(StringVal("ab")))
10113 return isinstance(a, SeqRef)
and a.is_string()
10116 """return 'True' if 'a' is a Z3 string constant expression.
10117 >>> print (is_string_value(StringVal("a")))
10119 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10122 return isinstance(a, SeqRef)
and a.is_string_value()
10126 """create a string expression"""
10127 ctx = _get_ctx(ctx)
10131 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10133 >>> x = String('x')
10135 ctx = _get_ctx(ctx)
10139 """Return string constants"""
10140 ctx = _get_ctx(ctx)
10141 if isinstance(names, str):
10142 names = names.split(
" ")
10143 return [
String(name, ctx)
for name
in names]
10146 """Extract substring or subsequence starting at offset"""
10147 return Extract(s, offset, length)
10150 """Extract substring or subsequence starting at offset"""
10151 return Extract(s, offset, length)
10153 def Strings(names, ctx=None):
10154 """Return a tuple of String constants. """
10155 ctx = _get_ctx(ctx)
10156 if isinstance(names, str):
10157 names = names.split(
" ")
10158 return [
String(name, ctx)
for name
in names]
10161 """Create the empty sequence of the given sort
10162 >>> e = Empty(StringSort())
10163 >>> e2 = StringVal("")
10164 >>> print(e.eq(e2))
10166 >>> e3 = Empty(SeqSort(IntSort()))
10169 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10171 Empty(ReSort(Seq(Int)))
10173 if isinstance(s, SeqSortRef):
10175 if isinstance(s, ReSortRef):
10177 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10180 """Create the regular expression that accepts the universal language
10181 >>> e = Full(ReSort(SeqSort(IntSort())))
10183 Full(ReSort(Seq(Int)))
10184 >>> e1 = Full(ReSort(StringSort()))
10186 Full(ReSort(String))
10188 if isinstance(s, ReSortRef):
10190 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10194 """Create a singleton sequence"""
10198 """Check if 'a' is a prefix of 'b'
10199 >>> s1 = PrefixOf("ab", "abc")
10202 >>> s2 = PrefixOf("bc", "abc")
10206 ctx = _get_ctx2(a, b)
10207 a = _coerce_seq(a, ctx)
10208 b = _coerce_seq(b, ctx)
10212 """Check if 'a' is a suffix of 'b'
10213 >>> s1 = SuffixOf("ab", "abc")
10216 >>> s2 = SuffixOf("bc", "abc")
10220 ctx = _get_ctx2(a, b)
10221 a = _coerce_seq(a, ctx)
10222 b = _coerce_seq(b, ctx)
10226 """Check if 'a' contains 'b'
10227 >>> s1 = Contains("abc", "ab")
10230 >>> s2 = Contains("abc", "bc")
10233 >>> x, y, z = Strings('x y z')
10234 >>> s3 = Contains(Concat(x,y,z), y)
10238 ctx = _get_ctx2(a, b)
10239 a = _coerce_seq(a, ctx)
10240 b = _coerce_seq(b, ctx)
10245 """Replace the first occurrence of 'src' by 'dst' in 's'
10246 >>> r = Replace("aaa", "a", "b")
10250 ctx = _get_ctx2(dst, s)
10251 if ctx
is None and is_expr(src):
10253 src = _coerce_seq(src, ctx)
10254 dst = _coerce_seq(dst, ctx)
10255 s = _coerce_seq(s, ctx)
10262 """Retrieve the index of substring within a string starting at a specified offset.
10263 >>> simplify(IndexOf("abcabc", "bc", 0))
10265 >>> simplify(IndexOf("abcabc", "bc", 2))
10271 ctx = _get_ctx2(s, substr, ctx)
10272 s = _coerce_seq(s, ctx)
10273 substr = _coerce_seq(substr, ctx)
10274 if _is_int(offset):
10275 offset =
IntVal(offset, ctx)
10279 """Retrieve the last index of substring within a string"""
10281 ctx = _get_ctx2(s, substr, ctx)
10282 s = _coerce_seq(s, ctx)
10283 substr = _coerce_seq(substr, ctx)
10288 """Obtain the length of a sequence 's'
10289 >>> l = Length(StringVal("abc"))
10297 """Convert string expression to integer
10298 >>> a = StrToInt("1")
10299 >>> simplify(1 == a)
10301 >>> b = StrToInt("2")
10302 >>> simplify(1 == b)
10304 >>> c = StrToInt(IntToStr(2))
10305 >>> simplify(1 == c)
10313 """Convert integer expression to string"""
10320 """The regular expression that accepts sequence 's'
10322 >>> s2 = Re(StringVal("ab"))
10323 >>> s3 = Re(Unit(BoolVal(True)))
10325 s = _coerce_seq(s, ctx)
10334 """Regular expression sort."""
10342 if s
is None or isinstance(s, Context):
10345 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10349 """Regular expressions."""
10352 return Union(self, other)
10355 return isinstance(s, ReRef)
10359 """Create regular expression membership test
10360 >>> re = Union(Re("a"),Re("b"))
10361 >>> print (simplify(InRe("a", re)))
10363 >>> print (simplify(InRe("b", re)))
10365 >>> print (simplify(InRe("c", re)))
10368 s = _coerce_seq(s, re.ctx)
10372 """Create union of regular expressions.
10373 >>> re = Union(Re("a"), Re("b"), Re("c"))
10374 >>> print (simplify(InRe("d", re)))
10377 args = _get_args(args)
10380 _z3_assert(sz > 0,
"At least one argument expected.")
10381 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10386 for i
in range(sz):
10387 v[i] = args[i].as_ast()
10391 """Create intersection of regular expressions.
10392 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
10394 args = _get_args(args)
10397 _z3_assert(sz > 0,
"At least one argument expected.")
10398 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10403 for i
in range(sz):
10404 v[i] = args[i].as_ast()
10408 """Create the regular expression accepting one or more repetitions of argument.
10409 >>> re = Plus(Re("a"))
10410 >>> print(simplify(InRe("aa", re)))
10412 >>> print(simplify(InRe("ab", re)))
10414 >>> print(simplify(InRe("", re)))
10420 """Create the regular expression that optionally accepts the argument.
10421 >>> re = Option(Re("a"))
10422 >>> print(simplify(InRe("a", re)))
10424 >>> print(simplify(InRe("", re)))
10426 >>> print(simplify(InRe("aa", re)))
10432 """Create the complement regular expression."""
10436 """Create the regular expression accepting zero or more repetitions of argument.
10437 >>> re = Star(Re("a"))
10438 >>> print(simplify(InRe("aa", re)))
10440 >>> print(simplify(InRe("ab", re)))
10442 >>> print(simplify(InRe("", re)))
10448 """Create the regular expression accepting between a lower and upper bound repetitions
10449 >>> re = Loop(Re("a"), 1, 3)
10450 >>> print(simplify(InRe("aa", re)))
10452 >>> print(simplify(InRe("aaaa", re)))
10454 >>> print(simplify(InRe("", re)))
10460 """Create the range regular expression over two sequences of length 1
10461 >>> range = Range("a","z")
10462 >>> print(simplify(InRe("b", range)))
10464 >>> print(simplify(InRe("bb", range)))
10467 lo = _coerce_seq(lo, ctx)
10468 hi = _coerce_seq(hi, ctx)
10486 """Given a binary relation R, such that the two arguments have the same sort
10487 create the transitive closure relation R+.
10488 The transitive closure R+ is a new relation.
10499 if self.
locklock
is None:
10501 self.
locklock = threading.thread.Lock()
10504 if self.
locklock: self.
locklock.acquire()
10505 r = self.
basesbases[ctx]
10506 if self.
locklock: self.
locklock.release()
10510 if self.
locklock: self.
locklock.acquire()
10511 self.
basesbases[ctx] = r
10512 if self.
locklock: self.
locklock.release()
10515 if self.
locklock: self.
locklock.acquire()
10516 id = len(self.
basesbases) + 3
10517 self.
basesbases[id] = r
10518 if self.
locklock: self.
locklock.release()
10521 _prop_closures =
None
10524 global _prop_closures
10525 if _prop_closures
is None:
10529 _prop_closures.get(ctx).push();
10532 _prop_closures.get(ctx).pop(num_scopes)
10535 prop = _prop_closures.get(id)
10536 _prop_closures.set_threaded()
10537 new_prop = UsePropagateBase(
None, ctx)
10538 _prop_closures.set(new_prop.id, new_prop.fresh())
10539 return ctypes.c_void_p(new_prop.id)
10542 prop = _prop_closures.get(ctx)
10544 prop.fixed(id, _to_expr_ref(ctypes.c_void_p(value), prop.ctx()))
10548 prop = _prop_closures.get(ctx)
10554 prop = _prop_closures.get(ctx)
10560 prop = _prop_closures.get(ctx)
10565 _user_prop_push = push_eh_type(user_prop_push)
10566 _user_prop_pop = pop_eh_type(user_prop_pop)
10567 _user_prop_fresh = fresh_eh_type(user_prop_fresh)
10568 _user_prop_fixed = fixed_eh_type(user_prop_fixed)
10569 _user_prop_final = final_eh_type(user_prop_final)
10570 _user_prop_eq = eq_eh_type(user_prop_eq)
10571 _user_prop_diseq = eq_eh_type(user_prop_diseq)
10583 assert s
is None or ctx
is None
10586 self.
_ctx_ctx =
None
10588 self.
idid = _prop_closures.insert(self)
10596 self.
_ctx_ctx.ctx = ctx
10602 ctypes.c_void_p(self.
idid),
10609 self.
_ctx_ctx.ctx =
None
10613 return self.
_ctx_ctx
10615 return self.
solversolver.ctx
10618 return self.
ctxctx().ref()
10621 assert not self.
fixedfixed
10622 assert not self.
_ctx_ctx
10624 self.
fixedfixed = fixed
10627 assert not self.
finalfinal
10628 assert not self.
_ctx_ctx
10630 self.
finalfinal = final
10633 assert not self.
eqeq
10634 assert not self.
_ctx_ctx
10639 assert not self.
diseqdiseq
10640 assert not self.
_ctx_ctx
10642 self.
diseqdiseq = diseq
10645 raise Z3Exception(
"push needs to be overwritten")
10648 raise Z3Exception(
"pop needs to be overwritten")
10651 raise Z3Exception(
"fresh needs to be overwritten")
10654 assert self.
solversolver
10655 assert not self.
_ctx_ctx
10662 num_fixed = len(ids)
10663 _ids = (ctypes.c_uint * num_fixed)()
10664 for i
in range(num_fixed):
10667 _lhs = (ctypes.c_uint * num_eqs)()
10668 _rhs = (ctypes.c_uint * num_eqs)()
10669 for i
in range(num_eqs):
10670 _lhs[i] = eqs[i][0]
10671 _rhs[i] = eqs[i][1]
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 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 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)
expr range(expr const &lo, expr const &hi)
def fpIsNegative(a, ctx=None)
def FreshInt(prefix='x', 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 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 user_prop_fixed(ctx, cb, id, value)
def SimpleSolver(ctx=None, logFile=None)
def SolverFor(logic, ctx=None, logFile=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 FreshBool(prefix='b', 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 FreshReal(prefix='b', ctx=None)
def solve(*args, **keywords)
def FloatSingle(ctx=None)
def user_prop_pop(ctx, num_scopes)
def prove(claim, **keywords)
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 Strings(names, ctx=None)
def is_finite_domain_value(a)
def fpToIEEEBV(x, ctx=None)
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 FreshConst(sort, prefix='c')
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 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)
Z3_ast_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
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 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.
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.
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 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_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_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_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.
Z3_ast Z3_API Z3_mk_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.
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...
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_true(Z3_context c)
Create an AST node representing true.
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.
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.
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_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
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_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.
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.
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_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_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
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_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context....
Z3_ast_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.
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 unescaped string constant stored in s.
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.
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.
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.
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.
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.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
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...
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_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_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_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
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.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
void Z3_API Z3_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.
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_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
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.
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_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
Z3_ast Z3_API Z3_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_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.
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.
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 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 Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
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.
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.
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p)
Convert a parameter set into a string. This function is mainly used for printing the contents of a pa...
void Z3_API Z3_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.
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.
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_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_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.
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_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...
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.
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_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
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_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.
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. You can use Z3_get_ast_id intercha...
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.
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_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_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.
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.
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_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.
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.
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_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_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_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_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_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
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_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_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_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
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.
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_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
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...
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 8 bit 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...
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_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.
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
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_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
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.
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_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
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.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
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.
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
void Z3_API Z3_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_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_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.
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.
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_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
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_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
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.
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_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
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_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
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_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_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_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_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.
Z3_ast 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.
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_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_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
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.
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
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.
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 Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
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.
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_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, bool biased)
Return the exponent value of a floating-point numeral as a string.
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
Z3_ast Z3_API Z3_mk_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.
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_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
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_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
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_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_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_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
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_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_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_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
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_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
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_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t)
Retrieves the sign of a floating-point literal as a bit-vector expression.
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
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.
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.
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_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 ...
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.
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_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_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast_vector Z3_API Z3_optimize_get_lower_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector ...
void Z3_API Z3_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_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.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
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_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
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...
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
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_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
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.
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_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.