Go to the documentation of this file.
9 """Z3 is a high performance theorem prover developed at Microsoft Research. Z3 is used in many applications such as: software/hardware verification and testing, constraint solving, analysis of hybrid systems, security, biology (in silico analysis), and geometrical problems.
11 Several online tutorials for Z3Py are available at:
12 http://rise4fun.com/Z3Py/tutorial/guide
14 Please send feedback, comments and/or corrections on the Issue tracker for https://github.com/Z3prover/z3.git. Your comments are very valuable.
35 ... x = BitVec('x', 32)
37 ... # the expression x + y is type incorrect
39 ... except Z3Exception as ex:
40 ... print("failed: %s" % ex)
45 from .z3types
import *
46 from .z3consts
import *
47 from .z3printer
import *
48 from fractions
import Fraction
62 return isinstance(v, (int, long))
65 return isinstance(v, int)
74 major = ctypes.c_uint(0)
75 minor = ctypes.c_uint(0)
76 build = ctypes.c_uint(0)
77 rev = ctypes.c_uint(0)
79 return "%s.%s.%s" % (major.value, minor.value, build.value)
82 major = ctypes.c_uint(0)
83 minor = ctypes.c_uint(0)
84 build = ctypes.c_uint(0)
85 rev = ctypes.c_uint(0)
87 return (major.value, minor.value, build.value, rev.value)
94 def _z3_assert(cond, msg):
96 raise Z3Exception(msg)
98 def _z3_check_cint_overflow(n, name):
99 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
102 """Log interaction to a file. This function must be invoked immediately after init(). """
106 """Append user-defined string to interaction log. """
110 """Convert an integer or string into a Z3 symbol."""
116 def _symbol2py(ctx, s):
117 """Convert a Z3 symbol back into a Python object. """
128 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
130 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
131 return [arg
for arg
in args[0]]
138 def _get_args_ast_list(args):
140 if isinstance(args, set)
or isinstance(args, AstVector)
or isinstance(args, tuple):
141 return [arg
for arg
in args]
147 def _to_param_value(val):
148 if isinstance(val, bool):
162 """A Context manages all other Z3 objects, global configuration options, etc.
164 Z3Py uses a default global context. For most applications this is sufficient.
165 An application may use multiple Z3 contexts. Objects created in one context
166 cannot be used in another one. However, several objects may be "translated" from
167 one context to another. It is not safe to access Z3 objects from multiple threads.
168 The only exception is the method `interrupt()` that can be used to interrupt() a long
170 The initialization method receives global configuration options for the new context.
174 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
197 """Return a reference to the actual C pointer to the Z3 context."""
201 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
203 This method can be invoked from a thread different from the one executing the
204 interruptible procedure.
212 """Return a reference to the global Z3 context.
215 >>> x.ctx == main_ctx()
220 >>> x2 = Real('x', c)
227 if _main_ctx
is None:
241 """Set Z3 global (or module) parameters.
243 >>> set_param(precision=10)
246 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
250 if not set_pp_option(k, v):
264 """Reset all global (or module) parameters.
269 """Alias for 'set_param' for backward compatibility.
274 """Return the value of a Z3 global (or module) parameter
276 >>> get_param('nlsat.reorder')
279 ptr = (ctypes.c_char_p * 1)()
281 r = z3core._to_pystr(ptr[0])
283 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
293 """Superclass for all Z3 objects that have support for pretty printing."""
297 def _repr_html_(self):
298 in_html = in_html_mode()
301 set_html_mode(in_html)
306 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
313 if self.
ctx.ref()
is not None and self.
ast is not None:
318 return _to_ast_ref(self.
ast, self.
ctx)
321 return obj_to_string(self)
324 return obj_to_string(self)
327 return self.
eq(other)
340 elif is_eq(self)
and self.num_args() == 2:
341 return self.arg(0).
eq(self.arg(1))
343 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
346 """Return a string representing the AST node in s-expression notation.
349 >>> ((x + 1)*x).sexpr()
355 """Return a pointer to the corresponding C Z3_ast object."""
359 """Return unique identifier for object. It can be used for hash-tables and maps."""
363 """Return a reference to the C context where this AST node is stored."""
364 return self.
ctx.ref()
367 """Return `True` if `self` and `other` are structurally identical.
374 >>> n1 = simplify(n1)
375 >>> n2 = simplify(n2)
380 _z3_assert(
is_ast(other),
"Z3 AST expected")
384 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
390 >>> # Nodes in different contexts can't be mixed.
391 >>> # However, we can translate nodes from one context to another.
392 >>> x.translate(c2) + y
396 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
403 """Return a hashcode for the `self`.
405 >>> n1 = simplify(Int('x') + 1)
406 >>> n2 = simplify(2 + Int('x') - 1)
407 >>> n1.hash() == n2.hash()
413 """Return `True` if `a` is an AST node.
417 >>> is_ast(IntVal(10))
421 >>> is_ast(BoolSort())
423 >>> is_ast(Function('f', IntSort(), IntSort()))
430 return isinstance(a, AstRef)
433 """Return `True` if `a` and `b` are structurally identical AST nodes.
443 >>> eq(simplify(x + 1), simplify(1 + x))
450 def _ast_kind(ctx, a):
455 def _ctx_from_ast_arg_list(args, default_ctx=None):
463 _z3_assert(ctx == a.ctx,
"Context mismatch")
468 def _ctx_from_ast_args(*args):
469 return _ctx_from_ast_arg_list(args)
471 def _to_func_decl_array(args):
473 _args = (FuncDecl * sz)()
475 _args[i] = args[i].as_func_decl()
478 def _to_ast_array(args):
482 _args[i] = args[i].as_ast()
485 def _to_ref_array(ref, args):
489 _args[i] = args[i].as_ast()
492 def _to_ast_ref(a, ctx):
493 k = _ast_kind(ctx, a)
495 return _to_sort_ref(a, ctx)
496 elif k == Z3_FUNC_DECL_AST:
497 return _to_func_decl_ref(a, ctx)
499 return _to_expr_ref(a, ctx)
508 def _sort_kind(ctx, s):
512 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
520 """Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts.
523 >>> b.kind() == Z3_BOOL_SORT
525 >>> b.kind() == Z3_INT_SORT
527 >>> A = ArraySort(IntSort(), IntSort())
528 >>> A.kind() == Z3_ARRAY_SORT
530 >>> A.kind() == Z3_INT_SORT
533 return _sort_kind(self.
ctx, self.
ast)
536 """Return `True` if `self` is a subsort of `other`.
538 >>> IntSort().subsort(RealSort())
544 """Try to cast `val` as an element of sort `self`.
546 This method is used in Z3Py to convert Python objects such as integers,
547 floats, longs and strings into Z3 expressions.
550 >>> RealSort().cast(x)
554 _z3_assert(
is_expr(val),
"Z3 expression expected")
555 _z3_assert(self.
eq(val.sort()),
"Sort mismatch")
559 """Return the name (string) of sort `self`.
561 >>> BoolSort().name()
563 >>> ArraySort(IntSort(), IntSort()).name()
569 """Return `True` if `self` and `other` are the same Z3 sort.
572 >>> p.sort() == BoolSort()
574 >>> p.sort() == IntSort()
582 """Return `True` if `self` and `other` are not the same Z3 sort.
585 >>> p.sort() != BoolSort()
587 >>> p.sort() != IntSort()
594 return AstRef.__hash__(self)
597 """Return `True` if `s` is a Z3 sort.
599 >>> is_sort(IntSort())
601 >>> is_sort(Int('x'))
603 >>> is_expr(Int('x'))
606 return isinstance(s, SortRef)
608 def _to_sort_ref(s, ctx):
610 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
611 k = _sort_kind(ctx, s)
612 if k == Z3_BOOL_SORT:
614 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
616 elif k == Z3_BV_SORT:
618 elif k == Z3_ARRAY_SORT:
620 elif k == Z3_DATATYPE_SORT:
622 elif k == Z3_FINITE_DOMAIN_SORT:
624 elif k == Z3_FLOATING_POINT_SORT:
626 elif k == Z3_ROUNDING_MODE_SORT:
628 elif k == Z3_RE_SORT:
630 elif k == Z3_SEQ_SORT:
635 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
638 """Create a new uninterpreted sort named `name`.
640 If `ctx=None`, then the new sort is declared in the global Z3Py context.
642 >>> A = DeclareSort('A')
643 >>> a = Const('a', A)
644 >>> b = Const('b', A)
662 """Function declaration. Every constant and function have an associated declaration.
664 The declaration assigns a name, a sort (i.e., type), and for function
665 the sort (i.e., type) of each of its arguments. Note that, in Z3,
666 a constant is a function with 0 arguments.
678 """Return the name of the function declaration `self`.
680 >>> f = Function('f', IntSort(), IntSort())
683 >>> isinstance(f.name(), str)
689 """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0.
691 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
698 """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`.
700 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
707 _z3_assert(i < self.
arity(),
"Index out of bounds")
711 """Return the sort of the range of a function declaration. For constants, this is the sort of the constant.
713 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
720 """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc.
723 >>> d = (x + 1).decl()
724 >>> d.kind() == Z3_OP_ADD
726 >>> d.kind() == Z3_OP_MUL
734 result = [
None for i
in range(n) ]
737 if k == Z3_PARAMETER_INT:
739 elif k == Z3_PARAMETER_DOUBLE:
741 elif k == Z3_PARAMETER_RATIONAL:
743 elif k == Z3_PARAMETER_SYMBOL:
745 elif k == Z3_PARAMETER_SORT:
747 elif k == Z3_PARAMETER_AST:
749 elif k == Z3_PARAMETER_FUNC_DECL:
756 """Create a Z3 application expression using the function `self`, and the given arguments.
758 The arguments must be Z3 expressions. This method assumes that
759 the sorts of the elements in `args` match the sorts of the
760 domain. Limited coercion is supported. For example, if
761 args[0] is a Python integer, and the function expects a Z3
762 integer, then the argument is automatically converted into a
765 >>> f = Function('f', IntSort(), RealSort(), BoolSort())
773 args = _get_args(args)
776 _z3_assert(num == self.
arity(),
"Incorrect number of arguments to %s" % self)
777 _args = (Ast * num)()
782 tmp = self.
domain(i).cast(args[i])
784 _args[i] = tmp.as_ast()
788 """Return `True` if `a` is a Z3 function declaration.
790 >>> f = Function('f', IntSort(), IntSort())
797 return isinstance(a, FuncDeclRef)
800 """Create a new Z3 uninterpreted function with the given sorts.
802 >>> f = Function('f', IntSort(), IntSort())
808 _z3_assert(len(sig) > 0,
"At least two arguments expected")
812 _z3_assert(
is_sort(rng),
"Z3 sort expected")
813 dom = (Sort * arity)()
814 for i
in range(arity):
816 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
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.
sort().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_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.
eq(val.sort()):
1411 _z3_assert(self.
eq(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_lambda(),
"quantifier should be a lambda expression")
1894 arg = self.
sort().domain().cast(arg)
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_patterns(),
"Invalid pattern idx")
1943 """Return the number of no-patterns."""
1947 """Return a no-pattern."""
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_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_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.
body() ]
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.
kind() == Z3_REAL_SORT
2146 """Return `True` if `self` is of the sort Integer.
2151 >>> (x + 1).is_int()
2157 return self.
kind() == 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.
ctx == val.ctx,
"Context mismatch")
2183 if val_s.is_int()
and self.
is_real():
2185 if val_s.is_bool()
and self.
is_int():
2186 return If(val, 1, 0)
2187 if val_s.is_bool()
and self.
is_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.
ctx)
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.
ctx)
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.
ctx)
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.
ctx)
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.
ctx)
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.
ctx)
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`."""
2379 """Create the Z3 expression `other/self`.
2392 a, b = _coerce_exprs(self, other)
2396 """Create the Z3 expression `other/self`."""
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_int(),
"Integer value expected")
2788 """Return a Z3 integer numeral as a Python string.
2796 """Rational values."""
2799 """ Return the numerator of a Z3 rational numeral.
2801 >>> is_rational_value(RealVal("3/5"))
2803 >>> n = RealVal("3/5")
2806 >>> is_rational_value(Q(3,5))
2808 >>> Q(3,5).numerator()
2814 """ Return the denominator of a Z3 rational numeral.
2816 >>> is_rational_value(Q(3,5))
2825 """ Return the numerator as a Python long.
2827 >>> v = RealVal(10000000000)
2832 >>> v.numerator_as_long() + 1 == 10000000001
2838 """ Return the denominator as a Python long.
2840 >>> v = RealVal("1/3")
2843 >>> v.denominator_as_long()
2858 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
2862 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2864 >>> v = RealVal("1/5")
2867 >>> v = RealVal("1/3")
2874 """Return a Z3 rational numeral as a Python string.
2883 """Return a Z3 rational as a Python Fraction object.
2885 >>> v = RealVal("1/5")
2892 """Algebraic irrational values."""
2895 """Return a Z3 rational number that approximates the algebraic number `self`.
2896 The result `r` is such that |r - self| <= 1/10^precision
2898 >>> x = simplify(Sqrt(2))
2900 6838717160008073720548335/4835703278458516698824704
2906 """Return a string representation of the algebraic number `self` in decimal notation using `prec` decimal places
2908 >>> x = simplify(Sqrt(2))
2909 >>> x.as_decimal(10)
2911 >>> x.as_decimal(20)
2912 '1.41421356237309504880?'
2916 def _py2expr(a, ctx=None):
2917 if isinstance(a, bool):
2921 if isinstance(a, float):
2926 _z3_assert(
False,
"Python bool, int, long or float expected")
2929 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2933 >>> x = Const('x', IntSort())
2936 >>> x.sort() == IntSort()
2938 >>> x.sort() == BoolSort()
2945 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2949 >>> x = Const('x', RealSort())
2954 >>> x.sort() == RealSort()
2960 def _to_int_str(val):
2961 if isinstance(val, float):
2962 return str(int(val))
2963 elif isinstance(val, bool):
2970 elif isinstance(val, str):
2973 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
2976 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
2987 """Return a Z3 real value.
2989 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
2990 If `ctx=None`, then the global context is used.
2994 >>> RealVal(1).sort()
3005 """Return a Z3 rational a/b.
3007 If `ctx=None`, then the global context is used.
3011 >>> RatVal(3,5).sort()
3015 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3016 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3019 def Q(a, b, ctx=None):
3020 """Return a Z3 rational a/b.
3022 If `ctx=None`, then the global context is used.
3032 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3044 """Return a tuple of Integer constants.
3046 >>> x, y, z = Ints('x y z')
3051 if isinstance(names, str):
3052 names = names.split(
" ")
3053 return [
Int(name, ctx)
for name
in names]
3056 """Return a list of integer constants of size `sz`.
3058 >>> X = IntVector('x', 3)
3065 return [
Int(
'%s__%s' % (prefix, i), ctx)
for i
in range(sz) ]
3068 """Return a fresh integer constant in the given context using the given prefix.
3081 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3093 """Return a tuple of real constants.
3095 >>> x, y, z = Reals('x y z')
3098 >>> Sum(x, y, z).sort()
3102 if isinstance(names, str):
3103 names = names.split(
" ")
3104 return [
Real(name, ctx)
for name
in names]
3107 """Return a list of real constants of size `sz`.
3109 >>> X = RealVector('x', 3)
3118 return [
Real(
'%s__%s' % (prefix, i), ctx)
for i
in range(sz) ]
3121 """Return a fresh real constant in the given context using the given prefix.
3134 """ Return the Z3 expression ToReal(a).
3146 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3151 """ Return the Z3 expression ToInt(a).
3163 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3168 """ Return the Z3 predicate IsInt(a).
3171 >>> IsInt(x + "1/2")
3173 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3175 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3179 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3184 """ Return a Z3 expression which represents the square root of a.
3196 """ Return a Z3 expression which represents the cubic root of a.
3214 """Bit-vector sort."""
3217 """Return the size (number of bits) of the bit-vector sort `self`.
3219 >>> b = BitVecSort(32)
3229 """Try to cast `val` as a Bit-Vector.
3231 >>> b = BitVecSort(32)
3234 >>> b.cast(10).sexpr()
3239 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
3246 """Return True if `s` is a Z3 bit-vector sort.
3248 >>> is_bv_sort(BitVecSort(32))
3250 >>> is_bv_sort(IntSort())
3253 return isinstance(s, BitVecSortRef)
3256 """Bit-vector expressions."""
3259 """Return the sort of the bit-vector expression `self`.
3261 >>> x = BitVec('x', 32)
3264 >>> x.sort() == BitVecSort(32)
3270 """Return the number of bits of the bit-vector expression `self`.
3272 >>> x = BitVec('x', 32)
3275 >>> Concat(x, x).size()
3281 """Create the Z3 expression `self + other`.
3283 >>> x = BitVec('x', 32)
3284 >>> y = BitVec('y', 32)
3290 a, b = _coerce_exprs(self, other)
3294 """Create the Z3 expression `other + self`.
3296 >>> x = BitVec('x', 32)
3300 a, b = _coerce_exprs(self, other)
3304 """Create the Z3 expression `self * other`.
3306 >>> x = BitVec('x', 32)
3307 >>> y = BitVec('y', 32)
3313 a, b = _coerce_exprs(self, other)
3317 """Create the Z3 expression `other * self`.
3319 >>> x = BitVec('x', 32)
3323 a, b = _coerce_exprs(self, other)
3327 """Create the Z3 expression `self - other`.
3329 >>> x = BitVec('x', 32)
3330 >>> y = BitVec('y', 32)
3336 a, b = _coerce_exprs(self, other)
3340 """Create the Z3 expression `other - self`.
3342 >>> x = BitVec('x', 32)
3346 a, b = _coerce_exprs(self, other)
3350 """Create the Z3 expression bitwise-or `self | other`.
3352 >>> x = BitVec('x', 32)
3353 >>> y = BitVec('y', 32)
3359 a, b = _coerce_exprs(self, other)
3363 """Create the Z3 expression bitwise-or `other | self`.
3365 >>> x = BitVec('x', 32)
3369 a, b = _coerce_exprs(self, other)
3373 """Create the Z3 expression bitwise-and `self & other`.
3375 >>> x = BitVec('x', 32)
3376 >>> y = BitVec('y', 32)
3382 a, b = _coerce_exprs(self, other)
3386 """Create the Z3 expression bitwise-or `other & self`.
3388 >>> x = BitVec('x', 32)
3392 a, b = _coerce_exprs(self, other)
3396 """Create the Z3 expression bitwise-xor `self ^ other`.
3398 >>> x = BitVec('x', 32)
3399 >>> y = BitVec('y', 32)
3405 a, b = _coerce_exprs(self, other)
3409 """Create the Z3 expression bitwise-xor `other ^ self`.
3411 >>> x = BitVec('x', 32)
3415 a, b = _coerce_exprs(self, other)
3421 >>> x = BitVec('x', 32)
3428 """Return an expression representing `-self`.
3430 >>> x = BitVec('x', 32)
3439 """Create the Z3 expression bitwise-not `~self`.
3441 >>> x = BitVec('x', 32)
3450 """Create the Z3 expression (signed) division `self / other`.
3452 Use the function UDiv() for unsigned division.
3454 >>> x = BitVec('x', 32)
3455 >>> y = BitVec('y', 32)
3462 >>> UDiv(x, y).sexpr()
3465 a, b = _coerce_exprs(self, other)
3469 """Create the Z3 expression (signed) division `self / other`."""
3473 """Create the Z3 expression (signed) division `other / self`.
3475 Use the function UDiv() for unsigned division.
3477 >>> x = BitVec('x', 32)
3480 >>> (10 / x).sexpr()
3481 '(bvsdiv #x0000000a x)'
3482 >>> UDiv(10, x).sexpr()
3483 '(bvudiv #x0000000a x)'
3485 a, b = _coerce_exprs(self, other)
3489 """Create the Z3 expression (signed) division `other / self`."""
3493 """Create the Z3 expression (signed) mod `self % other`.
3495 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3497 >>> x = BitVec('x', 32)
3498 >>> y = BitVec('y', 32)
3505 >>> URem(x, y).sexpr()
3507 >>> SRem(x, y).sexpr()
3510 a, b = _coerce_exprs(self, other)
3514 """Create the Z3 expression (signed) mod `other % self`.
3516 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3518 >>> x = BitVec('x', 32)
3521 >>> (10 % x).sexpr()
3522 '(bvsmod #x0000000a x)'
3523 >>> URem(10, x).sexpr()
3524 '(bvurem #x0000000a x)'
3525 >>> SRem(10, x).sexpr()
3526 '(bvsrem #x0000000a x)'
3528 a, b = _coerce_exprs(self, other)
3532 """Create the Z3 expression (signed) `other <= self`.
3534 Use the function ULE() for unsigned less than or equal to.
3536 >>> x, y = BitVecs('x y', 32)
3539 >>> (x <= y).sexpr()
3541 >>> ULE(x, y).sexpr()
3544 a, b = _coerce_exprs(self, other)
3548 """Create the Z3 expression (signed) `other < self`.
3550 Use the function ULT() for unsigned less than.
3552 >>> x, y = BitVecs('x y', 32)
3557 >>> ULT(x, y).sexpr()
3560 a, b = _coerce_exprs(self, other)
3564 """Create the Z3 expression (signed) `other > self`.
3566 Use the function UGT() for unsigned greater than.
3568 >>> x, y = BitVecs('x y', 32)
3573 >>> UGT(x, y).sexpr()
3576 a, b = _coerce_exprs(self, other)
3580 """Create the Z3 expression (signed) `other >= self`.
3582 Use the function UGE() for unsigned greater than or equal to.
3584 >>> x, y = BitVecs('x y', 32)
3587 >>> (x >= y).sexpr()
3589 >>> UGE(x, y).sexpr()
3592 a, b = _coerce_exprs(self, other)
3596 """Create the Z3 expression (arithmetical) right shift `self >> other`
3598 Use the function LShR() for the right logical shift
3600 >>> x, y = BitVecs('x y', 32)
3603 >>> (x >> y).sexpr()
3605 >>> LShR(x, y).sexpr()
3609 >>> BitVecVal(4, 3).as_signed_long()
3611 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3613 >>> simplify(BitVecVal(4, 3) >> 1)
3615 >>> simplify(LShR(BitVecVal(4, 3), 1))
3617 >>> simplify(BitVecVal(2, 3) >> 1)
3619 >>> simplify(LShR(BitVecVal(2, 3), 1))
3622 a, b = _coerce_exprs(self, other)
3626 """Create the Z3 expression left shift `self << other`
3628 >>> x, y = BitVecs('x y', 32)
3631 >>> (x << y).sexpr()
3633 >>> simplify(BitVecVal(2, 3) << 1)
3636 a, b = _coerce_exprs(self, other)
3640 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3642 Use the function LShR() for the right logical shift
3644 >>> x = BitVec('x', 32)
3647 >>> (10 >> x).sexpr()
3648 '(bvashr #x0000000a x)'
3650 a, b = _coerce_exprs(self, other)
3654 """Create the Z3 expression left shift `other << self`.
3656 Use the function LShR() for the right logical shift
3658 >>> x = BitVec('x', 32)
3661 >>> (10 << x).sexpr()
3662 '(bvshl #x0000000a x)'
3664 a, b = _coerce_exprs(self, other)
3668 """Bit-vector values."""
3671 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3673 >>> v = BitVecVal(0xbadc0de, 32)
3676 >>> print("0x%.8x" % v.as_long())
3682 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign.
3684 >>> BitVecVal(4, 3).as_signed_long()
3686 >>> BitVecVal(7, 3).as_signed_long()
3688 >>> BitVecVal(3, 3).as_signed_long()
3690 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3692 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3697 if val >= 2**(sz - 1):
3699 if val < -2**(sz - 1):
3707 """Return `True` if `a` is a Z3 bit-vector expression.
3709 >>> b = BitVec('b', 32)
3717 return isinstance(a, BitVecRef)
3720 """Return `True` if `a` is a Z3 bit-vector numeral value.
3722 >>> b = BitVec('b', 32)
3725 >>> b = BitVecVal(10, 32)
3731 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3734 """Return the Z3 expression BV2Int(a).
3736 >>> b = BitVec('b', 3)
3737 >>> BV2Int(b).sort()
3742 >>> x > BV2Int(b, is_signed=False)
3744 >>> x > BV2Int(b, is_signed=True)
3745 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3746 >>> solve(x > BV2Int(b), b == 1, x < 3)
3750 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3756 """Return the z3 expression Int2BV(a, num_bits).
3757 It is a bit-vector of width num_bits and represents the
3758 modulo of a by 2^num_bits
3764 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3766 >>> Byte = BitVecSort(8)
3767 >>> Word = BitVecSort(16)
3770 >>> x = Const('x', Byte)
3771 >>> eq(x, BitVec('x', 8))
3778 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3780 >>> v = BitVecVal(10, 32)
3783 >>> print("0x%.8x" % v.as_long())
3794 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3795 If `ctx=None`, then the global context is used.
3797 >>> x = BitVec('x', 16)
3804 >>> word = BitVecSort(16)
3805 >>> x2 = BitVec('x', word)
3809 if isinstance(bv, BitVecSortRef):
3817 """Return a tuple of bit-vector constants of size bv.
3819 >>> x, y, z = BitVecs('x y z', 16)
3826 >>> Product(x, y, z)
3828 >>> simplify(Product(x, y, z))
3832 if isinstance(names, str):
3833 names = names.split(
" ")
3834 return [
BitVec(name, bv, ctx)
for name
in names]
3837 """Create a Z3 bit-vector concatenation expression.
3839 >>> v = BitVecVal(1, 4)
3840 >>> Concat(v, v+1, v)
3841 Concat(Concat(1, 1 + 1), 1)
3842 >>> simplify(Concat(v, v+1, v))
3844 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3847 args = _get_args(args)
3850 _z3_assert(sz >= 2,
"At least two arguments expected.")
3857 if is_seq(args[0])
or isinstance(args[0], str):
3858 args = [_coerce_seq(s, ctx)
for s
in args]
3860 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
3863 v[i] = args[i].as_ast()
3868 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
3871 v[i] = args[i].as_ast()
3875 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
3877 for i
in range(sz - 1):
3882 """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3884 >>> x = BitVec('x', 8)
3885 >>> Extract(6, 2, x)
3887 >>> Extract(6, 2, x).sort()
3889 >>> simplify(Extract(StringVal("abcd"),2,1))
3892 if isinstance(high, str):
3896 offset, length = _coerce_exprs(low, a, s.ctx)
3899 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
3900 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
"First and second arguments must be non negative integers")
3901 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
3904 def _check_bv_args(a, b):
3906 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
3909 """Create the Z3 expression (unsigned) `other <= self`.
3911 Use the operator <= for signed less than or equal to.
3913 >>> x, y = BitVecs('x y', 32)
3916 >>> (x <= y).sexpr()
3918 >>> ULE(x, y).sexpr()
3921 _check_bv_args(a, b)
3922 a, b = _coerce_exprs(a, b)
3926 """Create the Z3 expression (unsigned) `other < self`.
3928 Use the operator < for signed less than.
3930 >>> x, y = BitVecs('x y', 32)
3935 >>> ULT(x, y).sexpr()
3938 _check_bv_args(a, b)
3939 a, b = _coerce_exprs(a, b)
3943 """Create the Z3 expression (unsigned) `other >= self`.
3945 Use the operator >= for signed greater than or equal to.
3947 >>> x, y = BitVecs('x y', 32)
3950 >>> (x >= y).sexpr()
3952 >>> UGE(x, y).sexpr()
3955 _check_bv_args(a, b)
3956 a, b = _coerce_exprs(a, b)
3960 """Create the Z3 expression (unsigned) `other > self`.
3962 Use the operator > for signed greater than.
3964 >>> x, y = BitVecs('x y', 32)
3969 >>> UGT(x, y).sexpr()
3972 _check_bv_args(a, b)
3973 a, b = _coerce_exprs(a, b)
3977 """Create the Z3 expression (unsigned) division `self / other`.
3979 Use the operator / for signed division.
3981 >>> x = BitVec('x', 32)
3982 >>> y = BitVec('y', 32)
3985 >>> UDiv(x, y).sort()
3989 >>> UDiv(x, y).sexpr()
3992 _check_bv_args(a, b)
3993 a, b = _coerce_exprs(a, b)
3997 """Create the Z3 expression (unsigned) remainder `self % other`.
3999 Use the operator % for signed modulus, and SRem() for signed remainder.
4001 >>> x = BitVec('x', 32)
4002 >>> y = BitVec('y', 32)
4005 >>> URem(x, y).sort()
4009 >>> URem(x, y).sexpr()
4012 _check_bv_args(a, b)
4013 a, b = _coerce_exprs(a, b)
4017 """Create the Z3 expression signed remainder.
4019 Use the operator % for signed modulus, and URem() for unsigned remainder.
4021 >>> x = BitVec('x', 32)
4022 >>> y = BitVec('y', 32)
4025 >>> SRem(x, y).sort()
4029 >>> SRem(x, y).sexpr()
4032 _check_bv_args(a, b)
4033 a, b = _coerce_exprs(a, b)
4037 """Create the Z3 expression logical right shift.
4039 Use the operator >> for the arithmetical right shift.
4041 >>> x, y = BitVecs('x y', 32)
4044 >>> (x >> y).sexpr()
4046 >>> LShR(x, y).sexpr()
4050 >>> BitVecVal(4, 3).as_signed_long()
4052 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4054 >>> simplify(BitVecVal(4, 3) >> 1)
4056 >>> simplify(LShR(BitVecVal(4, 3), 1))
4058 >>> simplify(BitVecVal(2, 3) >> 1)
4060 >>> simplify(LShR(BitVecVal(2, 3), 1))
4063 _check_bv_args(a, b)
4064 a, b = _coerce_exprs(a, b)
4068 """Return an expression representing `a` rotated to the left `b` times.
4070 >>> a, b = BitVecs('a b', 16)
4071 >>> RotateLeft(a, b)
4073 >>> simplify(RotateLeft(a, 0))
4075 >>> simplify(RotateLeft(a, 16))
4078 _check_bv_args(a, b)
4079 a, b = _coerce_exprs(a, b)
4083 """Return an expression representing `a` rotated to the right `b` times.
4085 >>> a, b = BitVecs('a b', 16)
4086 >>> RotateRight(a, b)
4088 >>> simplify(RotateRight(a, 0))
4090 >>> simplify(RotateRight(a, 16))
4093 _check_bv_args(a, b)
4094 a, b = _coerce_exprs(a, b)
4098 """Return a bit-vector expression with `n` extra sign-bits.
4100 >>> x = BitVec('x', 16)
4101 >>> n = SignExt(8, x)
4108 >>> v0 = BitVecVal(2, 2)
4113 >>> v = simplify(SignExt(6, v0))
4118 >>> print("%.x" % v.as_long())
4122 _z3_assert(_is_int(n),
"First argument must be an integer")
4123 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4127 """Return a bit-vector expression with `n` extra zero-bits.
4129 >>> x = BitVec('x', 16)
4130 >>> n = ZeroExt(8, x)
4137 >>> v0 = BitVecVal(2, 2)
4142 >>> v = simplify(ZeroExt(6, v0))
4149 _z3_assert(_is_int(n),
"First argument must be an integer")
4150 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4154 """Return an expression representing `n` copies of `a`.
4156 >>> x = BitVec('x', 8)
4157 >>> n = RepeatBitVec(4, x)
4162 >>> v0 = BitVecVal(10, 4)
4163 >>> print("%.x" % v0.as_long())
4165 >>> v = simplify(RepeatBitVec(4, v0))
4168 >>> print("%.x" % v.as_long())
4172 _z3_assert(_is_int(n),
"First argument must be an integer")
4173 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4177 """Return the reduction-and expression of `a`."""
4179 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4183 """Return the reduction-or expression of `a`."""
4185 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4189 """A predicate the determines that bit-vector addition does not overflow"""
4190 _check_bv_args(a, b)
4191 a, b = _coerce_exprs(a, b)
4195 """A predicate the determines that signed bit-vector addition does not underflow"""
4196 _check_bv_args(a, b)
4197 a, b = _coerce_exprs(a, b)
4201 """A predicate the determines that bit-vector subtraction does not overflow"""
4202 _check_bv_args(a, b)
4203 a, b = _coerce_exprs(a, b)
4208 """A predicate the determines that bit-vector subtraction does not underflow"""
4209 _check_bv_args(a, b)
4210 a, b = _coerce_exprs(a, b)
4214 """A predicate the determines that bit-vector signed division does not overflow"""
4215 _check_bv_args(a, b)
4216 a, b = _coerce_exprs(a, b)
4220 """A predicate the determines that bit-vector unary negation does not overflow"""
4222 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4226 """A predicate the determines that bit-vector multiplication does not overflow"""
4227 _check_bv_args(a, b)
4228 a, b = _coerce_exprs(a, b)
4233 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4234 _check_bv_args(a, b)
4235 a, b = _coerce_exprs(a, b)
4250 """Return the domain of the array sort `self`.
4252 >>> A = ArraySort(IntSort(), BoolSort())
4259 """Return the range of the array sort `self`.
4261 >>> A = ArraySort(IntSort(), BoolSort())
4268 """Array expressions. """
4271 """Return the array sort of the array expression `self`.
4273 >>> a = Array('a', IntSort(), BoolSort())
4280 """Shorthand for `self.sort().domain()`.
4282 >>> a = Array('a', IntSort(), BoolSort())
4289 """Shorthand for `self.sort().range()`.
4291 >>> a = Array('a', IntSort(), BoolSort())
4298 """Return the Z3 expression `self[arg]`.
4300 >>> a = Array('a', IntSort(), BoolSort())
4307 arg = self.
domain().cast(arg)
4318 """Return `True` if `a` is a Z3 array expression.
4320 >>> a = Array('a', IntSort(), IntSort())
4323 >>> is_array(Store(a, 0, 1))
4328 return isinstance(a, ArrayRef)
4331 """Return `True` if `a` is a Z3 constant array.
4333 >>> a = K(IntSort(), 10)
4334 >>> is_const_array(a)
4336 >>> a = Array('a', IntSort(), IntSort())
4337 >>> is_const_array(a)
4343 """Return `True` if `a` is a Z3 constant array.
4345 >>> a = K(IntSort(), 10)
4348 >>> a = Array('a', IntSort(), IntSort())
4355 """Return `True` if `a` is a Z3 map array expression.
4357 >>> f = Function('f', IntSort(), IntSort())
4358 >>> b = Array('b', IntSort(), IntSort())
4370 """Return `True` if `a` is a Z3 default array expression.
4371 >>> d = Default(K(IntSort(), 10))
4375 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4378 """Return the function declaration associated with a Z3 map array expression.
4380 >>> f = Function('f', IntSort(), IntSort())
4381 >>> b = Array('b', IntSort(), IntSort())
4383 >>> eq(f, get_map_func(a))
4387 >>> get_map_func(a)(0)
4391 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4395 """Return the Z3 array sort with the given domain and range sorts.
4397 >>> A = ArraySort(IntSort(), BoolSort())
4404 >>> AA = ArraySort(IntSort(), A)
4406 Array(Int, Array(Int, Bool))
4408 sig = _get_args(sig)
4410 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4411 arity = len(sig) - 1
4416 _z3_assert(
is_sort(s),
"Z3 sort expected")
4417 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4421 dom = (Sort * arity)()
4422 for i
in range(arity):
4427 """Return an array constant named `name` with the given domain and range sorts.
4429 >>> a = Array('a', IntSort(), IntSort())
4440 """Return a Z3 store array expression.
4442 >>> a = Array('a', IntSort(), IntSort())
4443 >>> i, v = Ints('i v')
4444 >>> s = Update(a, i, v)
4447 >>> prove(s[i] == v)
4450 >>> prove(Implies(i != j, s[j] == a[j]))
4454 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4455 i = a.sort().domain().cast(i)
4456 v = a.sort().
range().cast(v)
4458 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4461 """ Return a default value for array expression.
4462 >>> b = K(IntSort(), 1)
4463 >>> prove(Default(b) == 1)
4467 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4472 """Return a Z3 store array expression.
4474 >>> a = Array('a', IntSort(), IntSort())
4475 >>> i, v = Ints('i v')
4476 >>> s = Store(a, i, v)
4479 >>> prove(s[i] == v)
4482 >>> prove(Implies(i != j, s[j] == a[j]))
4488 """Return a Z3 select array expression.
4490 >>> a = Array('a', IntSort(), IntSort())
4494 >>> eq(Select(a, i), a[i])
4498 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4503 """Return a Z3 map array expression.
4505 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4506 >>> a1 = Array('a1', IntSort(), IntSort())
4507 >>> a2 = Array('a2', IntSort(), IntSort())
4508 >>> b = Map(f, a1, a2)
4511 >>> prove(b[0] == f(a1[0], a2[0]))
4514 args = _get_args(args)
4516 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4517 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4518 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4519 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4520 _args, sz = _to_ast_array(args)
4525 """Return a Z3 constant array expression.
4527 >>> a = K(IntSort(), 10)
4539 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4542 v = _py2expr(v, ctx)
4546 """Return extensionality index for one-dimensional arrays.
4547 >> a, b = Consts('a b', SetSort(IntSort()))
4554 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4558 k = _py2expr(k, ctx)
4562 """Return `True` if `a` is a Z3 array select application.
4564 >>> a = Array('a', IntSort(), IntSort())
4574 """Return `True` if `a` is a Z3 array store application.
4576 >>> a = Array('a', IntSort(), IntSort())
4579 >>> is_store(Store(a, 0, 1))
4592 """ Create a set sort over element sort s"""
4596 """Create the empty set
4597 >>> EmptySet(IntSort())
4604 """Create the full set
4605 >>> FullSet(IntSort())
4612 """ Take the union of sets
4613 >>> a = Const('a', SetSort(IntSort()))
4614 >>> b = Const('b', SetSort(IntSort()))
4618 args = _get_args(args)
4619 ctx = _ctx_from_ast_arg_list(args)
4620 _args, sz = _to_ast_array(args)
4624 """ Take the union of sets
4625 >>> a = Const('a', SetSort(IntSort()))
4626 >>> b = Const('b', SetSort(IntSort()))
4627 >>> SetIntersect(a, b)
4630 args = _get_args(args)
4631 ctx = _ctx_from_ast_arg_list(args)
4632 _args, sz = _to_ast_array(args)
4636 """ Add element e to set s
4637 >>> a = Const('a', SetSort(IntSort()))
4641 ctx = _ctx_from_ast_arg_list([s,e])
4642 e = _py2expr(e, ctx)
4646 """ Remove element e to set s
4647 >>> a = Const('a', SetSort(IntSort()))
4651 ctx = _ctx_from_ast_arg_list([s,e])
4652 e = _py2expr(e, ctx)
4656 """ The complement of set s
4657 >>> a = Const('a', SetSort(IntSort()))
4658 >>> SetComplement(a)
4665 """ The set difference of a and b
4666 >>> a = Const('a', SetSort(IntSort()))
4667 >>> b = Const('b', SetSort(IntSort()))
4668 >>> SetDifference(a, b)
4671 ctx = _ctx_from_ast_arg_list([a, b])
4675 """ Check if e is a member of set s
4676 >>> a = Const('a', SetSort(IntSort()))
4680 ctx = _ctx_from_ast_arg_list([s,e])
4681 e = _py2expr(e, ctx)
4685 """ Check if a is a subset of b
4686 >>> a = Const('a', SetSort(IntSort()))
4687 >>> b = Const('b', SetSort(IntSort()))
4691 ctx = _ctx_from_ast_arg_list([a, b])
4701 def _valid_accessor(acc):
4702 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4703 return isinstance(acc, tuple)
and len(acc) == 2
and isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4706 """Helper class for declaring Z3 datatypes.
4708 >>> List = Datatype('List')
4709 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4710 >>> List.declare('nil')
4711 >>> List = List.create()
4712 >>> # List is now a Z3 declaration
4715 >>> List.cons(10, List.nil)
4717 >>> List.cons(10, List.nil).sort()
4719 >>> cons = List.cons
4723 >>> n = cons(1, cons(0, nil))
4725 cons(1, cons(0, nil))
4726 >>> simplify(cdr(n))
4728 >>> simplify(car(n))
4743 _z3_assert(isinstance(name, str),
"String expected")
4744 _z3_assert(isinstance(rec_name, str),
"String expected")
4745 _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)")
4749 """Declare constructor named `name` with the given accessors `args`.
4750 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.
4752 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4753 declares the constructor named `cons` that builds a new List using an integer and a List.
4754 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4755 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4756 the actual datatype in Z3.
4758 >>> List = Datatype('List')
4759 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4760 >>> List.declare('nil')
4761 >>> List = List.create()
4764 _z3_assert(isinstance(name, str),
"String expected")
4765 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4772 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
4774 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4776 >>> List = Datatype('List')
4777 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4778 >>> List.declare('nil')
4779 >>> List = List.create()
4782 >>> List.cons(10, List.nil)
4788 """Auxiliary object used to create Z3 datatypes."""
4793 if self.
ctx.ref()
is not None:
4797 """Auxiliary object used to create Z3 datatypes."""
4802 if self.
ctx.ref()
is not None:
4806 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4808 In the following example we define a Tree-List using two mutually recursive datatypes.
4810 >>> TreeList = Datatype('TreeList')
4811 >>> Tree = Datatype('Tree')
4812 >>> # Tree has two constructors: leaf and node
4813 >>> Tree.declare('leaf', ('val', IntSort()))
4814 >>> # a node contains a list of trees
4815 >>> Tree.declare('node', ('children', TreeList))
4816 >>> TreeList.declare('nil')
4817 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4818 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4819 >>> Tree.val(Tree.leaf(10))
4821 >>> simplify(Tree.val(Tree.leaf(10)))
4823 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4825 node(cons(leaf(10), cons(leaf(20), nil)))
4826 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4827 >>> simplify(n2 == n1)
4829 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4834 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
4835 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
4836 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
4837 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
4840 names = (Symbol * num)()
4841 out = (Sort * num)()
4842 clists = (ConstructorList * num)()
4844 for i
in range(num):
4847 num_cs = len(d.constructors)
4848 cs = (Constructor * num_cs)()
4849 for j
in range(num_cs):
4850 c = d.constructors[j]
4855 fnames = (Symbol * num_fs)()
4856 sorts = (Sort * num_fs)()
4857 refs = (ctypes.c_uint * num_fs)()
4858 for k
in range(num_fs):
4862 if isinstance(ftype, Datatype):
4864 _z3_assert(ds.count(ftype) == 1,
"One and only one occurrence of each datatype is expected")
4866 refs[k] = ds.index(ftype)
4869 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
4870 sorts[k] = ftype.ast
4879 for i
in range(num):
4881 num_cs = dref.num_constructors()
4882 for j
in range(num_cs):
4883 cref = dref.constructor(j)
4884 cref_name = cref.name()
4885 cref_arity = cref.arity()
4886 if cref.arity() == 0:
4888 setattr(dref, cref_name, cref)
4889 rref = dref.recognizer(j)
4890 setattr(dref,
"is_" + cref_name, rref)
4891 for k
in range(cref_arity):
4892 aref = dref.accessor(j, k)
4893 setattr(dref, aref.name(), aref)
4895 return tuple(result)
4898 """Datatype sorts."""
4900 """Return the number of constructors in the given Z3 datatype.
4902 >>> List = Datatype('List')
4903 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4904 >>> List.declare('nil')
4905 >>> List = List.create()
4906 >>> # List is now a Z3 declaration
4907 >>> List.num_constructors()
4913 """Return a constructor of the datatype `self`.
4915 >>> List = Datatype('List')
4916 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4917 >>> List.declare('nil')
4918 >>> List = List.create()
4919 >>> # List is now a Z3 declaration
4920 >>> List.num_constructors()
4922 >>> List.constructor(0)
4924 >>> List.constructor(1)
4932 """In Z3, each constructor has an associated recognizer predicate.
4934 If the constructor is named `name`, then the recognizer `is_name`.
4936 >>> List = Datatype('List')
4937 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4938 >>> List.declare('nil')
4939 >>> List = List.create()
4940 >>> # List is now a Z3 declaration
4941 >>> List.num_constructors()
4943 >>> List.recognizer(0)
4945 >>> List.recognizer(1)
4947 >>> simplify(List.is_nil(List.cons(10, List.nil)))
4949 >>> simplify(List.is_cons(List.cons(10, List.nil)))
4951 >>> l = Const('l', List)
4952 >>> simplify(List.is_cons(l))
4960 """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4962 >>> List = Datatype('List')
4963 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4964 >>> List.declare('nil')
4965 >>> List = List.create()
4966 >>> List.num_constructors()
4968 >>> List.constructor(0)
4970 >>> num_accs = List.constructor(0).arity()
4973 >>> List.accessor(0, 0)
4975 >>> List.accessor(0, 1)
4977 >>> List.constructor(1)
4979 >>> num_accs = List.constructor(1).arity()
4985 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
4989 """Datatype expressions."""
4991 """Return the datatype sort of the datatype expression `self`."""
4995 """Create a named tuple sort base on a set of underlying sorts
4997 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5000 projects = [ (
'project%d' % i, sorts[i])
for i
in range(len(sorts)) ]
5001 tuple.declare(name, *projects)
5002 tuple = tuple.create()
5003 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5006 """Create a named tagged union sort base on a set of underlying sorts
5008 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5011 for i
in range(len(sorts)):
5012 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5014 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5018 """Return a new enumeration sort named `name` containing the given values.
5020 The result is a pair (sort, list of constants).
5022 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5025 _z3_assert(isinstance(name, str),
"Name must be a string")
5026 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5027 _z3_assert(len(values) > 0,
"At least one value expected")
5030 _val_names = (Symbol * num)()
5031 for i
in range(num):
5033 _values = (FuncDecl * num)()
5034 _testers = (FuncDecl * num)()
5038 for i
in range(num):
5040 V = [a()
for a
in V]
5050 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5052 Consider using the function `args2params` to create instances of this object.
5066 if self.
ctx.ref()
is not None:
5070 """Set parameter name with value val."""
5072 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5074 if isinstance(val, bool):
5078 elif isinstance(val, float):
5080 elif isinstance(val, str):
5084 _z3_assert(
False,
"invalid parameter value")
5090 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5094 """Convert python arguments into a Z3_params object.
5095 A ':' is added to the keywords, and '_' is replaced with '-'
5097 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5098 (params model true relevancy 2 elim_and true)
5101 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5116 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5119 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5125 return ParamsDescrsRef(self.
descr, self.
ctx)
5128 if self.
ctx.ref()
is not None:
5132 """Return the size of in the parameter description `self`.
5137 """Return the size of in the parameter description `self`.
5142 """Return the i-th parameter name in the parameter description `self`.
5147 """Return the kind of the parameter named `n`.
5152 """Return the documentation string of the parameter named `n`.
5172 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5174 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5175 A goal has a solution if one of its subgoals has a solution.
5176 A goal is unsatisfiable if all subgoals are unsatisfiable.
5179 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5181 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5184 if self.
goal is None:
5189 return Goal(
False,
False,
False, self.
ctx, self.
goal)
5192 if self.
goal is not None and self.
ctx.ref()
is not None:
5196 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
5198 >>> x, y = Ints('x y')
5200 >>> g.add(x == 0, y >= x + 1)
5203 >>> r = Then('simplify', 'solve-eqs')(g)
5204 >>> # r has 1 subgoal
5213 """Return `True` if `self` contains the `False` constraints.
5215 >>> x, y = Ints('x y')
5217 >>> g.inconsistent()
5219 >>> g.add(x == 0, x == 1)
5222 >>> g.inconsistent()
5224 >>> g2 = Tactic('propagate-values')(g)[0]
5225 >>> g2.inconsistent()
5231 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5234 >>> g.prec() == Z3_GOAL_PRECISE
5236 >>> x, y = Ints('x y')
5237 >>> g.add(x == y + 1)
5238 >>> g.prec() == Z3_GOAL_PRECISE
5240 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5243 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5244 >>> g2.prec() == Z3_GOAL_PRECISE
5246 >>> g2.prec() == Z3_GOAL_UNDER
5252 """Alias for `prec()`.
5255 >>> g.precision() == Z3_GOAL_PRECISE
5261 """Return the number of constraints in the goal `self`.
5266 >>> x, y = Ints('x y')
5267 >>> g.add(x == 0, y > x)
5274 """Return the number of constraints in the goal `self`.
5279 >>> x, y = Ints('x y')
5280 >>> g.add(x == 0, y > x)
5287 """Return a constraint in the goal `self`.
5290 >>> x, y = Ints('x y')
5291 >>> g.add(x == 0, y > x)
5300 """Return a constraint in the goal `self`.
5303 >>> x, y = Ints('x y')
5304 >>> g.add(x == 0, y > x)
5310 if arg >= len(self):
5312 return self.
get(arg)
5315 """Assert constraints into the goal.
5319 >>> g.assert_exprs(x > 0, x < 2)
5323 args = _get_args(args)
5334 >>> g.append(x > 0, x < 2)
5345 >>> g.insert(x > 0, x < 2)
5356 >>> g.add(x > 0, x < 2)
5363 """Retrieve model from a satisfiable goal
5364 >>> a, b = Ints('a b')
5366 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5367 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5370 [Or(b == 0, b == 1), Not(0 <= b)]
5372 [Or(b == 0, b == 1), Not(1 <= b)]
5373 >>> # Remark: the subgoal r[0] is unsatisfiable
5374 >>> # Creating a solver for solving the second subgoal
5381 >>> # Model s.model() does not assign a value to `a`
5382 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5383 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5384 >>> r[1].convert_model(s.model())
5388 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5392 return obj_to_string(self)
5395 """Return a textual representation of the s-expression representing the goal."""
5399 """Return a textual representation of the goal in DIMACS format."""
5403 """Copy goal `self` to context `target`.
5411 >>> g2 = g.translate(c2)
5414 >>> g.ctx == main_ctx()
5418 >>> g2.ctx == main_ctx()
5422 _z3_assert(isinstance(target, Context),
"target must be a context")
5432 """Return a new simplified goal.
5434 This method is essentially invoking the simplify tactic.
5438 >>> g.add(x + 1 >= 2)
5441 >>> g2 = g.simplify()
5444 >>> # g was not modified
5449 return t.apply(self, *arguments, **keywords)[0]
5452 """Return goal `self` as a single Z3 expression.
5479 """A collection (vector) of ASTs."""
5488 assert ctx
is not None
5496 if self.
vector is not None and self.
ctx.ref()
is not None:
5500 """Return the size of the vector `self`.
5505 >>> A.push(Int('x'))
5506 >>> A.push(Int('x'))
5513 """Return the AST at position `i`.
5516 >>> A.push(Int('x') + 1)
5517 >>> A.push(Int('y'))
5524 if isinstance(i, int):
5532 elif isinstance(i, slice):
5537 """Update AST at position `i`.
5540 >>> A.push(Int('x') + 1)
5541 >>> A.push(Int('y'))
5553 """Add `v` in the end of the vector.
5558 >>> A.push(Int('x'))
5565 """Resize the vector to `sz` elements.
5571 >>> for i in range(10): A[i] = Int('x')
5578 """Return `True` if the vector contains `item`.
5601 """Copy vector `self` to context `other_ctx`.
5607 >>> B = A.translate(c2)
5620 return obj_to_string(self)
5623 """Return a textual representation of the s-expression representing the vector."""
5632 """A mapping from ASTs to ASTs."""
5641 assert ctx
is not None
5649 if self.
map is not None and self.
ctx.ref()
is not None:
5653 """Return the size of the map.
5659 >>> M[x] = IntVal(1)
5666 """Return `True` if the map contains key `key`.
5679 """Retrieve the value associated with key `key`.
5690 """Add/Update key `k` with value `v`.
5699 >>> M[x] = IntVal(1)
5709 """Remove the entry associated with key `k`.
5723 """Remove all entries from the map.
5728 >>> M[x+x] = IntVal(1)
5738 """Return an AstVector containing all keys in the map.
5743 >>> M[x+x] = IntVal(1)
5756 """Store the value of the interpretation of a function in a particular point."""
5767 if self.
ctx.ref()
is not None:
5771 """Return the number of arguments in the given entry.
5773 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5775 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5780 >>> f_i.num_entries()
5782 >>> e = f_i.entry(0)
5789 """Return the value of argument `idx`.
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)
5811 ... except IndexError:
5812 ... print("index error")
5820 """Return the value of the function at point `self`.
5822 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5824 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5829 >>> f_i.num_entries()
5831 >>> e = f_i.entry(0)
5842 """Return entry `self` as a Python list.
5843 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5845 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5850 >>> f_i.num_entries()
5852 >>> e = f_i.entry(0)
5857 args.append(self.
value())
5864 """Stores the interpretation of a function in a Z3 model."""
5869 if self.
f is not None:
5876 if self.
f is not None and self.
ctx.ref()
is not None:
5881 Return the `else` value for a function interpretation.
5882 Return None if Z3 did not specify the `else` value for
5885 >>> f = Function('f', IntSort(), IntSort())
5887 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5893 >>> m[f].else_value()
5898 return _to_expr_ref(r, self.
ctx)
5903 """Return the number of entries/points in the function interpretation `self`.
5905 >>> f = Function('f', IntSort(), IntSort())
5907 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5913 >>> m[f].num_entries()
5919 """Return the number of arguments for each entry in the function interpretation `self`.
5921 >>> f = Function('f', IntSort(), IntSort())
5923 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5933 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5935 >>> f = Function('f', IntSort(), IntSort())
5937 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5943 >>> m[f].num_entries()
5953 """Copy model 'self' to context 'other_ctx'.
5964 """Return the function interpretation as a Python list.
5965 >>> f = Function('f', IntSort(), IntSort())
5967 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5981 return obj_to_string(self)
5984 """Model/Solution of a satisfiability problem (aka system of constraints)."""
5987 assert ctx
is not None
5993 if self.
ctx.ref()
is not None:
5997 return obj_to_string(self)
6000 """Return a textual representation of the s-expression representing the model."""
6003 def eval(self, t, model_completion=False):
6004 """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`.
6008 >>> s.add(x > 0, x < 2)
6021 >>> m.eval(y, model_completion=True)
6023 >>> # Now, m contains an interpretation for y
6029 return _to_expr_ref(r[0], self.
ctx)
6030 raise Z3Exception(
"failed to evaluate expression in the model")
6033 """Alias for `eval`.
6037 >>> s.add(x > 0, x < 2)
6041 >>> m.evaluate(x + 1)
6043 >>> m.evaluate(x == 1)
6046 >>> m.evaluate(y + x)
6050 >>> m.evaluate(y, model_completion=True)
6052 >>> # Now, m contains an interpretation for y
6053 >>> m.evaluate(y + x)
6056 return self.
eval(t, model_completion)
6059 """Return the number of constant and function declarations in the model `self`.
6061 >>> f = Function('f', IntSort(), IntSort())
6064 >>> s.add(x > 0, f(x) != x)
6074 """Return the interpretation for a given declaration or constant.
6076 >>> f = Function('f', IntSort(), IntSort())
6079 >>> s.add(x > 0, x < 2, f(x) == 0)
6089 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6093 if decl.arity() == 0:
6095 if _r.value
is None:
6097 r = _to_expr_ref(_r, self.
ctx)
6108 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6110 >>> A = DeclareSort('A')
6111 >>> a, b = Consts('a b', A)
6123 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6125 >>> A = DeclareSort('A')
6126 >>> B = DeclareSort('B')
6127 >>> a1, a2 = Consts('a1 a2', A)
6128 >>> b1, b2 = Consts('b1 b2', B)
6130 >>> s.add(a1 != a2, b1 != b2)
6146 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6148 >>> A = DeclareSort('A')
6149 >>> B = DeclareSort('B')
6150 >>> a1, a2 = Consts('a1 a2', A)
6151 >>> b1, b2 = Consts('b1 b2', B)
6153 >>> s.add(a1 != a2, b1 != b2)
6163 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6165 >>> A = DeclareSort('A')
6166 >>> a, b = Consts('a b', A)
6172 >>> m.get_universe(A)
6176 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6183 """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.
6185 The elements can be retrieved using position or the actual declaration.
6187 >>> f = Function('f', IntSort(), IntSort())
6190 >>> s.add(x > 0, x < 2, f(x) == 0)
6204 >>> for d in m: print("%s -> %s" % (d, m[d]))
6209 if idx >= len(self):
6212 if (idx < num_consts):
6216 if isinstance(idx, FuncDeclRef):
6220 if isinstance(idx, SortRef):
6223 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6227 """Return a list with all symbols that have an interpretation in the model `self`.
6228 >>> f = Function('f', IntSort(), IntSort())
6231 >>> s.add(x > 0, x < 2, f(x) == 0)
6246 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6249 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6251 return Model(model, target)
6264 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6265 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6268 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6270 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6279 """Statistics for `Solver.check()`."""
6290 if self.
ctx.ref()
is not None:
6297 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6300 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6303 out.write(u(
'<tr>'))
6305 out.write(u(
'<td>%s</td><td>%s</td></tr>' % (k, v)))
6306 out.write(u(
'</table>'))
6307 return out.getvalue()
6312 """Return the number of statistical counters.
6315 >>> s = Then('simplify', 'nlsat').solver()
6319 >>> st = s.statistics()
6326 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6329 >>> s = Then('simplify', 'nlsat').solver()
6333 >>> st = s.statistics()
6337 ('nlsat propagations', 2)
6341 if idx >= len(self):
6350 """Return the list of statistical counters.
6353 >>> s = Then('simplify', 'nlsat').solver()
6357 >>> st = s.statistics()
6362 """Return the value of a particular statistical counter.
6365 >>> s = Then('simplify', 'nlsat').solver()
6369 >>> st = s.statistics()
6370 >>> st.get_key_value('nlsat propagations')
6373 for idx
in range(len(self)):
6379 raise Z3Exception(
"unknown key")
6382 """Access the value of statistical using attributes.
6384 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6385 we should use '_' (e.g., 'nlsat_propagations').
6388 >>> s = Then('simplify', 'nlsat').solver()
6392 >>> st = s.statistics()
6393 >>> st.nlsat_propagations
6398 key = name.replace(
'_',
' ')
6402 raise AttributeError
6410 """Represents the result of a satisfiability check: sat, unsat, unknown.
6416 >>> isinstance(r, CheckSatResult)
6427 return isinstance(other, CheckSatResult)
and self.
r == other.r
6430 return not self.
__eq__(other)
6434 if self.
r == Z3_L_TRUE:
6436 elif self.
r == Z3_L_FALSE:
6437 return "<b>unsat</b>"
6439 return "<b>unknown</b>"
6441 if self.
r == Z3_L_TRUE:
6443 elif self.
r == Z3_L_FALSE:
6448 def _repr_html_(self):
6449 in_html = in_html_mode()
6452 set_html_mode(in_html)
6460 """Solver API provides methods for implementing the main SMT 2.0 commands: push, pop, check, get-model, etc."""
6462 def __init__(self, solver=None, ctx=None, logFile=None):
6463 assert solver
is None or ctx
is not None
6472 if logFile
is not None:
6473 self.
set(
"solver.smtlib2_log", logFile)
6476 if self.
solver is not None and self.
ctx.ref()
is not None:
6480 """Set a configuration option. The method `help()` return a string containing all available options.
6483 >>> # The option MBQI can be set using three different approaches.
6484 >>> s.set(mbqi=True)
6485 >>> s.set('MBQI', True)
6486 >>> s.set(':mbqi', True)
6492 """Create a backtracking point.
6514 """Backtrack \c num backtracking points.
6536 """Return the current number of backtracking points.
6554 """Remove all asserted constraints and backtracking points created using `push()`.
6568 """Assert constraints into the solver.
6572 >>> s.assert_exprs(x > 0, x < 2)
6576 args = _get_args(args)
6579 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6587 """Assert constraints into the solver.
6591 >>> s.add(x > 0, x < 2)
6602 """Assert constraints into the solver.
6606 >>> s.append(x > 0, x < 2)
6613 """Assert constraints into the solver.
6617 >>> s.insert(x > 0, x < 2)
6624 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6626 If `p` is a string, it will be automatically converted into a Boolean constant.
6631 >>> s.set(unsat_core=True)
6632 >>> s.assert_and_track(x > 0, 'p1')
6633 >>> s.assert_and_track(x != 1, 'p2')
6634 >>> s.assert_and_track(x < 0, p3)
6635 >>> print(s.check())
6637 >>> c = s.unsat_core()
6647 if isinstance(p, str):
6649 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6650 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6654 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
6660 >>> s.add(x > 0, x < 2)
6663 >>> s.model().eval(x)
6669 >>> s.add(2**x == 4)
6673 assumptions = _get_args(assumptions)
6674 num = len(assumptions)
6675 _assumptions = (Ast * num)()
6676 for i
in range(num):
6677 _assumptions[i] = assumptions[i].as_ast()
6682 """Return a model for the last `check()`.
6684 This function raises an exception if
6685 a model is not available (e.g., last `check()` returned unsat).
6689 >>> s.add(a + 2 == 0)
6698 raise Z3Exception(
"model is not available")
6701 """Import model converter from other into the current solver"""
6705 """Return a subset (as an AST vector) of the assumptions provided to the last check().
6707 These are the assumptions Z3 used in the unsatisfiability proof.
6708 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
6709 They may be also used to "retract" assumptions. Note that, assumptions are not really
6710 "soft constraints", but they can be used to implement them.
6712 >>> p1, p2, p3 = Bools('p1 p2 p3')
6713 >>> x, y = Ints('x y')
6715 >>> s.add(Implies(p1, x > 0))
6716 >>> s.add(Implies(p2, y > x))
6717 >>> s.add(Implies(p2, y < 1))
6718 >>> s.add(Implies(p3, y > -3))
6719 >>> s.check(p1, p2, p3)
6721 >>> core = s.unsat_core()
6730 >>> # "Retracting" p2
6737 """Determine fixed values for the variables based on the solver state and assumptions.
6739 >>> a, b, c, d = Bools('a b c d')
6740 >>> s.add(Implies(a,b), Implies(b, c))
6741 >>> s.consequences([a],[b,c,d])
6742 (sat, [Implies(a, b), Implies(a, c)])
6743 >>> s.consequences([Not(c),d],[a,b,c,d])
6744 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
6746 if isinstance(assumptions, list):
6748 for a
in assumptions:
6751 if isinstance(variables, list):
6756 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
6757 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
6760 sz = len(consequences)
6761 consequences = [ consequences[i]
for i
in range(sz) ]
6765 """Parse assertions from a file"""
6769 """Parse assertions from a string"""
6774 The method takes an optional set of variables that restrict which
6775 variables may be used as a starting point for cubing.
6776 If vars is not None, then the first case split is based on a variable in
6780 if vars
is not None:
6787 if (len(r) == 1
and is_false(r[0])):
6794 """Access the set of variables that were touched by the most recently generated cube.
6795 This set of variables can be used as a starting point for additional cubes.
6796 The idea is that variables that appear in clauses that are reduced by the most recent
6797 cube are likely more useful to cube on."""
6801 """Return a proof for the last `check()`. Proof construction must be enabled."""
6805 """Return an AST vector containing all added constraints.
6819 """Return an AST vector containing all currently inferred units.
6824 """Return an AST vector containing all atomic formulas in solver state that are not units.
6829 """Return trail and decision levels of the solver state after a check() call.
6831 trail = self.
trail()
6832 levels = (ctypes.c_uint * len(trail))()
6834 return trail, levels
6837 """Return trail of the solver state after a check() call.
6842 """Return statistics for the last `check()`.
6844 >>> s = SimpleSolver()
6849 >>> st = s.statistics()
6850 >>> st.get_key_value('final checks')
6860 """Return a string describing why the last `check()` returned `unknown`.
6863 >>> s = SimpleSolver()
6864 >>> s.add(2**x == 4)
6867 >>> s.reason_unknown()
6868 '(incomplete (theory arithmetic))'
6873 """Display a string describing all available options."""
6877 """Return the parameter description set."""
6881 """Return a formatted string with all added constraints."""
6882 return obj_to_string(self)
6885 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6889 >>> s1 = Solver(ctx=c1)
6890 >>> s2 = s1.translate(c2)
6893 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6895 return Solver(solver, target)
6904 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
6915 """Return a textual representation of the solver in DIMACS format."""
6919 """return SMTLIB2 formatted benchmark for solver's assertions"""
6926 for i
in range(sz1):
6927 v[i] = es[i].as_ast()
6929 e = es[sz1].as_ast()
6935 """Create a solver customized for the given logic.
6937 The parameter `logic` is a string. It should be contains
6938 the name of a SMT-LIB logic.
6939 See http://www.smtlib.org/ for the name of all available logics.
6941 >>> s = SolverFor("QF_LIA")
6955 """Return a simple general purpose solver with limited amount of preprocessing.
6957 >>> s = SimpleSolver()
6973 """Fixedpoint API provides methods for solving with recursive predicates"""
6976 assert fixedpoint
is None or ctx
is not None
6979 if fixedpoint
is None:
6990 if self.
fixedpoint is not None and self.
ctx.ref()
is not None:
6994 """Set a configuration option. The method `help()` return a string containing all available options.
7000 """Display a string describing all available options."""
7004 """Return the parameter description set."""
7008 """Assert constraints as background axioms for the fixedpoint solver."""
7009 args = _get_args(args)
7012 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7022 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7030 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7034 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7038 """Assert rules defining recursive predicates to the fixedpoint solver.
7041 >>> s = Fixedpoint()
7042 >>> s.register_relation(a.decl())
7043 >>> s.register_relation(b.decl())
7056 body = _get_args(body)
7060 def rule(self, head, body = None, name = None):
7061 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7065 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7069 """Query the fixedpoint engine whether formula is derivable.
7070 You can also pass an tuple or list of recursive predicates.
7072 query = _get_args(query)
7074 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7075 _decls = (FuncDecl * sz)()
7085 query =
And(query, self.
ctx)
7086 query = self.
abstract(query,
False)
7091 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7093 query = _get_args(query)
7095 if sz >= 1
and isinstance(query[0], FuncDecl):
7096 _z3_assert (
False,
"unsupported")
7102 query = self.
abstract(query,
False)
7103 r = Z3_fixedpoint_query_from_lvl (self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
7111 body = _get_args(body)
7116 """Retrieve answer from last query call."""
7118 return _to_expr_ref(r, self.
ctx)
7121 """Retrieve a ground cex from last query call."""
7122 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7123 return _to_expr_ref(r, self.
ctx)
7126 """retrieve rules along the counterexample trace"""
7130 """retrieve rule names along the counterexample trace"""
7133 names = _symbol2py (self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7135 return names.split (
';')
7138 """Retrieve number of levels used for predicate in PDR engine"""
7142 """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)"""
7144 return _to_expr_ref(r, self.
ctx)
7147 """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)"""
7151 """Register relation as recursive"""
7152 relations = _get_args(relations)
7157 """Control how relation is represented"""
7158 representations = _get_args(representations)
7159 representations = [
to_symbol(s)
for s
in representations]
7160 sz = len(representations)
7161 args = (Symbol * sz)()
7163 args[i] = representations[i]
7167 """Parse rules and queries from a string"""
7171 """Parse rules and queries from a file"""
7175 """retrieve rules that have been added to fixedpoint context"""
7179 """retrieve assertions that have been added to fixedpoint context"""
7183 """Return a formatted string with all added rules and constraints."""
7187 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7192 """Return a formatted string (in Lisp-like format) with all added constraints.
7193 We say the string is in s-expression format.
7194 Include also queries.
7196 args, len = _to_ast_array(queries)
7200 """Return statistics for the last `query()`.
7205 """Return a string describing why the last `query()` returned `unknown`.
7210 """Add variable or several variables.
7211 The added variable or variables will be bound in the rules
7214 vars = _get_args(vars)
7234 """Finite domain sort."""
7237 """Return the size of the finite domain sort"""
7238 r = (ctypes.c_ulonglong * 1)()
7242 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7245 """Create a named finite domain sort of a given size sz"""
7246 if not isinstance(name, Symbol):
7252 """Return True if `s` is a Z3 finite-domain sort.
7254 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7256 >>> is_finite_domain_sort(IntSort())
7259 return isinstance(s, FiniteDomainSortRef)
7263 """Finite-domain expressions."""
7266 """Return the sort of the finite-domain expression `self`."""
7270 """Return a Z3 floating point expression as a Python string."""
7274 """Return `True` if `a` is a Z3 finite-domain expression.
7276 >>> s = FiniteDomainSort('S', 100)
7277 >>> b = Const('b', s)
7278 >>> is_finite_domain(b)
7280 >>> is_finite_domain(Int('x'))
7283 return isinstance(a, FiniteDomainRef)
7287 """Integer values."""
7290 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7292 >>> s = FiniteDomainSort('S', 100)
7293 >>> v = FiniteDomainVal(3, s)
7302 """Return a Z3 finite-domain numeral as a Python string.
7304 >>> s = FiniteDomainSort('S', 100)
7305 >>> v = FiniteDomainVal(42, s)
7313 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7315 >>> s = FiniteDomainSort('S', 256)
7316 >>> FiniteDomainVal(255, s)
7318 >>> FiniteDomainVal('100', s)
7327 """Return `True` if `a` is a Z3 finite-domain value.
7329 >>> s = FiniteDomainSort('S', 100)
7330 >>> b = Const('b', s)
7331 >>> is_finite_domain_value(b)
7333 >>> b = FiniteDomainVal(10, s)
7336 >>> is_finite_domain_value(b)
7381 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7392 if self.
optimize is not None and self.
ctx.ref()
is not None:
7396 """Set a configuration option. The method `help()` return a string containing all available options.
7402 """Display a string describing all available options."""
7406 """Return the parameter description set."""
7410 """Assert constraints as background axioms for the optimize solver."""
7411 args = _get_args(args)
7414 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7422 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7430 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7432 If `p` is a string, it will be automatically converted into a Boolean constant.
7437 >>> s.assert_and_track(x > 0, 'p1')
7438 >>> s.assert_and_track(x != 1, 'p2')
7439 >>> s.assert_and_track(x < 0, p3)
7440 >>> print(s.check())
7442 >>> c = s.unsat_core()
7452 if isinstance(p, str):
7454 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7455 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7459 """Add soft constraint with optional weight and optional identifier.
7460 If no weight is supplied, then the penalty for violating the soft constraint
7462 Soft constraints are grouped by identifiers. Soft constraints that are
7463 added without identifiers are grouped by default.
7466 weight =
"%d" % weight
7467 elif isinstance(weight, float):
7468 weight =
"%f" % weight
7469 if not isinstance(weight, str):
7470 raise Z3Exception(
"weight should be a string or an integer")
7478 """Add objective function to maximize."""
7482 """Add objective function to minimize."""
7486 """create a backtracking point for added rules, facts and assertions"""
7490 """restore to previously created backtracking point"""
7494 """Check satisfiability while optimizing objective functions."""
7495 assumptions = _get_args(assumptions)
7496 num = len(assumptions)
7497 _assumptions = (Ast * num)()
7498 for i
in range(num):
7499 _assumptions[i] = assumptions[i].as_ast()
7503 """Return a string that describes why the last `check()` returned `unknown`."""
7507 """Return a model for the last check()."""
7511 raise Z3Exception(
"model is not available")
7517 if not isinstance(obj, OptimizeObjective):
7518 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7522 if not isinstance(obj, OptimizeObjective):
7523 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7527 if not isinstance(obj, OptimizeObjective):
7528 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7529 return obj.lower_values()
7532 if not isinstance(obj, OptimizeObjective):
7533 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7534 return obj.upper_values()
7537 """Parse assertions and objectives from a file"""
7541 """Parse assertions and objectives from a string"""
7545 """Return an AST vector containing all added constraints."""
7549 """returns set of objective functions"""
7553 """Return a formatted string with all added rules and constraints."""
7557 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7562 """Return statistics for the last check`.
7575 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters."""
7586 if self.
ctx.ref()
is not None:
7590 """Return the number of subgoals in `self`.
7592 >>> a, b = Ints('a b')
7594 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7595 >>> t = Tactic('split-clause')
7599 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
7602 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
7609 """Return one of the subgoals stored in ApplyResult object `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')
7617 [a == 0, Or(b == 0, b == 1), a > b]
7619 [a == 1, Or(b == 0, b == 1), a > b]
7621 if idx >= len(self):
7626 return obj_to_string(self)
7629 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
7634 """Return a Z3 expression consisting of all subgoals.
7639 >>> g.add(Or(x == 2, x == 3))
7640 >>> r = Tactic('simplify')(g)
7642 [[Not(x <= 1), Or(x == 2, x == 3)]]
7644 And(Not(x <= 1), Or(x == 2, x == 3))
7645 >>> r = Tactic('split-clause')(g)
7647 [[x > 1, x == 2], [x > 1, x == 3]]
7649 Or(And(x > 1, x == 2), And(x > 1, x == 3))
7665 """Tactics transform, solver and/or simplify sets of constraints (Goal). A Tactic can be converted into a Solver using the method solver().
7667 Several combinators are available for creating new tactics using the built-in ones: Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
7672 if isinstance(tactic, TacticObj):
7676 _z3_assert(isinstance(tactic, str),
"tactic name expected")
7680 raise Z3Exception(
"unknown tactic '%s'" % tactic)
7687 if self.
tactic is not None and self.
ctx.ref()
is not None:
7691 """Create a solver using the tactic `self`.
7693 The solver supports the methods `push()` and `pop()`, but it
7694 will always solve each `check()` from scratch.
7696 >>> t = Then('simplify', 'nlsat')
7699 >>> s.add(x**2 == 2, x > 0)
7707 def apply(self, goal, *arguments, **keywords):
7708 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7710 >>> x, y = Ints('x y')
7711 >>> t = Tactic('solve-eqs')
7712 >>> t.apply(And(x == 0, y >= x + 1))
7716 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expressions expected")
7717 goal = _to_goal(goal)
7718 if len(arguments) > 0
or len(keywords) > 0:
7725 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7727 >>> x, y = Ints('x y')
7728 >>> t = Tactic('solve-eqs')
7729 >>> t(And(x == 0, y >= x + 1))
7732 return self.
apply(goal, *arguments, **keywords)
7735 """Display a string containing a description of the available options for the `self` tactic."""
7739 """Return the parameter description set."""
7743 if isinstance(a, BoolRef):
7744 goal =
Goal(ctx = a.ctx)
7750 def _to_tactic(t, ctx=None):
7751 if isinstance(t, Tactic):
7756 def _and_then(t1, t2, ctx=None):
7757 t1 = _to_tactic(t1, ctx)
7758 t2 = _to_tactic(t2, ctx)
7760 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7763 def _or_else(t1, t2, ctx=None):
7764 t1 = _to_tactic(t1, ctx)
7765 t2 = _to_tactic(t2, ctx)
7767 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7771 """Return a tactic that applies the tactics in `*ts` in sequence.
7773 >>> x, y = Ints('x y')
7774 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7775 >>> t(And(x == 0, y > x + 1))
7777 >>> t(And(x == 0, y > x + 1)).as_expr()
7781 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7782 ctx = ks.get(
'ctx',
None)
7785 for i
in range(num - 1):
7786 r = _and_then(r, ts[i+1], ctx)
7790 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7792 >>> x, y = Ints('x y')
7793 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7794 >>> t(And(x == 0, y > x + 1))
7796 >>> t(And(x == 0, y > x + 1)).as_expr()
7802 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7805 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7806 >>> # Tactic split-clause fails if there is no clause in the given goal.
7809 >>> t(Or(x == 0, x == 1))
7810 [[x == 0], [x == 1]]
7813 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7814 ctx = ks.get(
'ctx',
None)
7817 for i
in range(num - 1):
7818 r = _or_else(r, ts[i+1], ctx)
7822 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7825 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7830 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7831 ctx = _get_ctx(ks.get(
'ctx',
None))
7832 ts = [ _to_tactic(t, ctx)
for t
in ts ]
7834 _args = (TacticObj * sz)()
7836 _args[i] = ts[i].tactic
7840 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7842 >>> x, y = Ints('x y')
7843 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7844 >>> t(And(Or(x == 1, x == 2), y == x + 1))
7845 [[x == 1, y == 2], [x == 2, y == 3]]
7847 t1 = _to_tactic(t1, ctx)
7848 t2 = _to_tactic(t2, ctx)
7850 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7854 """Alias for ParThen(t1, t2, ctx)."""
7858 """Return a tactic that applies tactic `t` using the given configuration options.
7860 >>> x, y = Ints('x y')
7861 >>> t = With(Tactic('simplify'), som=True)
7862 >>> t((x + 1)*(y + 2) == 0)
7863 [[2*x + y + x*y == -2]]
7865 ctx = keys.pop(
'ctx',
None)
7866 t = _to_tactic(t, ctx)
7871 """Return a tactic that applies tactic `t` using the given configuration options.
7873 >>> x, y = Ints('x y')
7875 >>> p.set("som", True)
7876 >>> t = WithParams(Tactic('simplify'), p)
7877 >>> t((x + 1)*(y + 2) == 0)
7878 [[2*x + y + x*y == -2]]
7880 t = _to_tactic(t,
None)
7884 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7886 >>> x, y = Ints('x y')
7887 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7888 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7890 >>> for subgoal in r: print(subgoal)
7891 [x == 0, y == 0, x > y]
7892 [x == 0, y == 1, x > y]
7893 [x == 1, y == 0, x > y]
7894 [x == 1, y == 1, x > y]
7895 >>> t = Then(t, Tactic('propagate-values'))
7899 t = _to_tactic(t, ctx)
7903 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7905 If `t` does not terminate in `ms` milliseconds, then it fails.
7907 t = _to_tactic(t, ctx)
7911 """Return a list of all available tactics in Z3.
7914 >>> l.count('simplify') == 1
7921 """Return a short description for the tactic named `name`.
7923 >>> d = tactic_description('simplify')
7929 """Display a (tabular) description of all available tactics in Z3."""
7932 print(
'<table border="1" cellpadding="2" cellspacing="0">')
7935 print(
'<tr style="background-color:#CFCFCF">')
7940 print(
'<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(
tactic_description(t), 40)))
7947 """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."""
7951 if isinstance(probe, ProbeObj):
7953 elif isinstance(probe, float):
7955 elif _is_int(probe):
7957 elif isinstance(probe, bool):
7964 _z3_assert(isinstance(probe, str),
"probe name expected")
7968 raise Z3Exception(
"unknown probe '%s'" % probe)
7975 if self.
probe is not None and self.
ctx.ref()
is not None:
7979 """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
7981 >>> p = Probe('size') < 10
7992 """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
7994 >>> p = Probe('size') > 10
8005 """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
8007 >>> p = Probe('size') <= 2
8018 """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
8020 >>> p = Probe('size') >= 2
8031 """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
8033 >>> p = Probe('size') == 2
8044 """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
8046 >>> p = Probe('size') != 2
8058 """Evaluate the probe `self` in the given goal.
8060 >>> p = Probe('size')
8070 >>> p = Probe('num-consts')
8073 >>> p = Probe('is-propositional')
8076 >>> p = Probe('is-qflia')
8081 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expression expected")
8082 goal = _to_goal(goal)
8086 """Return `True` if `p` is a Z3 probe.
8088 >>> is_probe(Int('x'))
8090 >>> is_probe(Probe('memory'))
8093 return isinstance(p, Probe)
8095 def _to_probe(p, ctx=None):
8099 return Probe(p, ctx)
8102 """Return a list of all available probes in Z3.
8105 >>> l.count('memory') == 1
8112 """Return a short description for the probe named `name`.
8114 >>> d = probe_description('memory')
8120 """Display a (tabular) description of all available probes in Z3."""
8123 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8126 print(
'<tr style="background-color:#CFCFCF">')
8131 print(
'<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(
probe_description(p), 40)))
8137 def _probe_nary(f, args, ctx):
8139 _z3_assert(len(args) > 0,
"At least one argument expected")
8141 r = _to_probe(args[0], ctx)
8142 for i
in range(num - 1):
8143 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i+1], ctx).probe), ctx)
8146 def _probe_and(args, ctx):
8147 return _probe_nary(Z3_probe_and, args, ctx)
8149 def _probe_or(args, ctx):
8150 return _probe_nary(Z3_probe_or, args, ctx)
8153 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8155 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
8157 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8158 >>> x, y = Ints('x y')
8164 >>> g.add(x == y + 1)
8166 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8168 p = _to_probe(p, ctx)
8172 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8174 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8175 >>> x, y = Ints('x y')
8181 >>> g.add(x == y + 1)
8183 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8185 p = _to_probe(p, ctx)
8186 t = _to_tactic(t, ctx)
8190 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8192 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8194 p = _to_probe(p, ctx)
8195 t1 = _to_tactic(t1, ctx)
8196 t2 = _to_tactic(t2, ctx)
8206 """Simplify the expression `a` using the given options.
8208 This function has many options. Use `help_simplify` to obtain the complete list.
8212 >>> simplify(x + 1 + y + x + 1)
8214 >>> simplify((x + 1)*(y + 1), som=True)
8216 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8217 And(Not(x == y), Not(x == 1), Not(y == 1))
8218 >>> simplify(And(x == 0, y == 1), elim_and=True)
8219 Not(Or(Not(x == 0), Not(y == 1)))
8222 _z3_assert(
is_expr(a),
"Z3 expression expected")
8223 if len(arguments) > 0
or len(keywords) > 0:
8225 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8227 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8230 """Return a string describing all options available for Z3 `simplify` procedure."""
8234 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8238 """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.
8242 >>> substitute(x + 1, (x, y + 1))
8244 >>> f = Function('f', IntSort(), IntSort())
8245 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8248 if isinstance(m, tuple):
8250 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8253 _z3_assert(
is_expr(t),
"Z3 expression expected")
8254 _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.")
8256 _from = (Ast * num)()
8258 for i
in range(num):
8259 _from[i] = m[i][0].as_ast()
8260 _to[i] = m[i][1].as_ast()
8261 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8264 """Substitute the free variables in t with the expression in m.
8266 >>> v0 = Var(0, IntSort())
8267 >>> v1 = Var(1, IntSort())
8269 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8270 >>> # replace v0 with x+1 and v1 with x
8271 >>> substitute_vars(f(v0, v1), x + 1, x)
8275 _z3_assert(
is_expr(t),
"Z3 expression expected")
8276 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8279 for i
in range(num):
8280 _to[i] = m[i].as_ast()
8284 """Create the sum of the Z3 expressions.
8286 >>> a, b, c = Ints('a b c')
8291 >>> A = IntVector('a', 5)
8293 a__0 + a__1 + a__2 + a__3 + a__4
8295 args = _get_args(args)
8298 ctx = _ctx_from_ast_arg_list(args)
8300 return _reduce(
lambda a, b: a + b, args, 0)
8301 args = _coerce_expr_list(args, ctx)
8303 return _reduce(
lambda a, b: a + b, args, 0)
8305 _args, sz = _to_ast_array(args)
8310 """Create the product of the Z3 expressions.
8312 >>> a, b, c = Ints('a b c')
8313 >>> Product(a, b, c)
8315 >>> Product([a, b, c])
8317 >>> A = IntVector('a', 5)
8319 a__0*a__1*a__2*a__3*a__4
8321 args = _get_args(args)
8324 ctx = _ctx_from_ast_arg_list(args)
8326 return _reduce(
lambda a, b: a * b, args, 1)
8327 args = _coerce_expr_list(args, ctx)
8329 return _reduce(
lambda a, b: a * b, args, 1)
8331 _args, sz = _to_ast_array(args)
8335 """Create an at-most Pseudo-Boolean k constraint.
8337 >>> a, b, c = Bools('a b c')
8338 >>> f = AtMost(a, b, c, 2)
8340 args = _get_args(args)
8342 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8343 ctx = _ctx_from_ast_arg_list(args)
8345 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8346 args1 = _coerce_expr_list(args[:-1], ctx)
8348 _args, sz = _to_ast_array(args1)
8352 """Create an at-most Pseudo-Boolean k constraint.
8354 >>> a, b, c = Bools('a b c')
8355 >>> f = AtLeast(a, b, c, 2)
8357 args = _get_args(args)
8359 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8360 ctx = _ctx_from_ast_arg_list(args)
8362 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8363 args1 = _coerce_expr_list(args[:-1], ctx)
8365 _args, sz = _to_ast_array(args1)
8368 def _reorder_pb_arg(arg):
8370 if not _is_int(b)
and _is_int(a):
8374 def _pb_args_coeffs(args, default_ctx = None):
8375 args = _get_args_ast_list(args)
8377 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8378 args = [_reorder_pb_arg(arg)
for arg
in args]
8379 args, coeffs = zip(*args)
8381 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8382 ctx = _ctx_from_ast_arg_list(args)
8384 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8385 args = _coerce_expr_list(args, ctx)
8386 _args, sz = _to_ast_array(args)
8387 _coeffs = (ctypes.c_int * len(coeffs))()
8388 for i
in range(len(coeffs)):
8389 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8390 _coeffs[i] = coeffs[i]
8391 return ctx, sz, _args, _coeffs
8394 """Create a Pseudo-Boolean inequality k constraint.
8396 >>> a, b, c = Bools('a b c')
8397 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8399 _z3_check_cint_overflow(k,
"k")
8400 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8404 """Create a Pseudo-Boolean inequality k constraint.
8406 >>> a, b, c = Bools('a b c')
8407 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8409 _z3_check_cint_overflow(k,
"k")
8410 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8414 """Create a Pseudo-Boolean inequality k constraint.
8416 >>> a, b, c = Bools('a b c')
8417 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8419 _z3_check_cint_overflow(k,
"k")
8420 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8425 """Solve the constraints `*args`.
8427 This is a simple function for creating demonstrations. It creates a solver,
8428 configure it using the options in `keywords`, adds the constraints
8429 in `args`, and invokes check.
8432 >>> solve(a > 0, a < 2)
8438 if keywords.get(
'show',
False):
8442 print(
"no solution")
8444 print(
"failed to solve")
8453 """Solve the constraints `*args` using solver `s`.
8455 This is a simple function for creating demonstrations. It is similar to `solve`,
8456 but it uses the given solver `s`.
8457 It configures solver `s` using the options in `keywords`, adds the constraints
8458 in `args`, and invokes check.
8461 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8464 if keywords.get(
'show',
False):
8469 print(
"no solution")
8471 print(
"failed to solve")
8477 if keywords.get(
'show',
False):
8482 """Try to prove the given claim.
8484 This is a simple function for creating demonstrations. It tries to prove
8485 `claim` by showing the negation is unsatisfiable.
8487 >>> p, q = Bools('p q')
8488 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8492 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8496 if keywords.get(
'show',
False):
8502 print(
"failed to prove")
8505 print(
"counterexample")
8508 def _solve_html(*args, **keywords):
8509 """Version of function `solve` used in RiSE4Fun."""
8513 if keywords.get(
'show',
False):
8514 print(
"<b>Problem:</b>")
8518 print(
"<b>no solution</b>")
8520 print(
"<b>failed to solve</b>")
8526 if keywords.get(
'show',
False):
8527 print(
"<b>Solution:</b>")
8530 def _solve_using_html(s, *args, **keywords):
8531 """Version of function `solve_using` used in RiSE4Fun."""
8533 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8536 if keywords.get(
'show',
False):
8537 print(
"<b>Problem:</b>")
8541 print(
"<b>no solution</b>")
8543 print(
"<b>failed to solve</b>")
8549 if keywords.get(
'show',
False):
8550 print(
"<b>Solution:</b>")
8553 def _prove_html(claim, **keywords):
8554 """Version of function `prove` used in RiSE4Fun."""
8556 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8560 if keywords.get(
'show',
False):
8564 print(
"<b>proved</b>")
8566 print(
"<b>failed to prove</b>")
8569 print(
"<b>counterexample</b>")
8572 def _dict2sarray(sorts, ctx):
8574 _names = (Symbol * sz)()
8575 _sorts = (Sort * sz) ()
8580 _z3_assert(isinstance(k, str),
"String expected")
8581 _z3_assert(
is_sort(v),
"Z3 sort expected")
8585 return sz, _names, _sorts
8587 def _dict2darray(decls, ctx):
8589 _names = (Symbol * sz)()
8590 _decls = (FuncDecl * sz) ()
8595 _z3_assert(isinstance(k, str),
"String expected")
8599 _decls[i] = v.decl().ast
8603 return sz, _names, _decls
8607 """Parse a string in SMT 2.0 format using the given sorts and decls.
8609 The arguments sorts and decls are Python dictionaries used to initialize
8610 the symbol table used for the SMT 2.0 parser.
8612 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8614 >>> x, y = Ints('x y')
8615 >>> f = Function('f', IntSort(), IntSort())
8616 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8618 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
8622 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8623 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8627 """Parse a file in SMT 2.0 format using the given sorts and decls.
8629 This function is similar to parse_smt2_string().
8632 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8633 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8645 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
8646 _dflt_fpsort_ebits = 11
8647 _dflt_fpsort_sbits = 53
8650 """Retrieves the global default rounding mode."""
8651 global _dflt_rounding_mode
8652 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8654 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8656 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8658 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8660 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8664 global _dflt_rounding_mode
8666 _dflt_rounding_mode = rm.decl().kind()
8668 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO
or
8669 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE
or
8670 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE
or
8671 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
or
8672 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8673 "illegal rounding mode")
8674 _dflt_rounding_mode = rm
8677 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8680 global _dflt_fpsort_ebits
8681 global _dflt_fpsort_sbits
8682 _dflt_fpsort_ebits = ebits
8683 _dflt_fpsort_sbits = sbits
8685 def _dflt_rm(ctx=None):
8688 def _dflt_fps(ctx=None):
8691 def _coerce_fp_expr_list(alist, ctx):
8692 first_fp_sort =
None
8695 if first_fp_sort
is None:
8696 first_fp_sort = a.sort()
8697 elif first_fp_sort == a.sort():
8702 first_fp_sort =
None
8706 for i
in range(len(alist)):
8708 if (isinstance(a, str)
and a.contains(
'2**(')
and a.endswith(
')'))
or _is_int(a)
or isinstance(a, float)
or isinstance(a, bool):
8709 r.append(
FPVal(a,
None, first_fp_sort, ctx))
8712 return _coerce_expr_list(r, ctx)
8718 """Floating-point sort."""
8721 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
8722 >>> b = FPSort(8, 24)
8729 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
8730 >>> b = FPSort(8, 24)
8737 """Try to cast `val` as a floating-point expression.
8738 >>> b = FPSort(8, 24)
8741 >>> b.cast(1.0).sexpr()
8742 '(fp #b0 #x7f #b00000000000000000000000)'
8746 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
8749 return FPVal(val,
None, self, self.
ctx)
8753 """Floating-point 16-bit (half) sort."""
8758 """Floating-point 16-bit (half) sort."""
8763 """Floating-point 32-bit (single) sort."""
8768 """Floating-point 32-bit (single) sort."""
8773 """Floating-point 64-bit (double) sort."""
8778 """Floating-point 64-bit (double) sort."""
8783 """Floating-point 128-bit (quadruple) sort."""
8788 """Floating-point 128-bit (quadruple) sort."""
8793 """"Floating-point rounding mode sort."""
8797 """Return True if `s` is a Z3 floating-point sort.
8799 >>> is_fp_sort(FPSort(8, 24))
8801 >>> is_fp_sort(IntSort())
8804 return isinstance(s, FPSortRef)
8807 """Return True if `s` is a Z3 floating-point rounding mode sort.
8809 >>> is_fprm_sort(FPSort(8, 24))
8811 >>> is_fprm_sort(RNE().sort())
8814 return isinstance(s, FPRMSortRef)
8819 """Floating-point expressions."""
8822 """Return the sort of the floating-point expression `self`.
8824 >>> x = FP('1.0', FPSort(8, 24))
8827 >>> x.sort() == FPSort(8, 24)
8833 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8834 >>> b = FPSort(8, 24)
8841 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8842 >>> b = FPSort(8, 24)
8849 """Return a Z3 floating point expression as a Python string."""
8853 return fpLEQ(self, other, self.
ctx)
8856 return fpLT(self, other, self.
ctx)
8859 return fpGEQ(self, other, self.
ctx)
8862 return fpGT(self, other, self.
ctx)
8865 """Create the Z3 expression `self + other`.
8867 >>> x = FP('x', FPSort(8, 24))
8868 >>> y = FP('y', FPSort(8, 24))
8874 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8875 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8878 """Create the Z3 expression `other + self`.
8880 >>> x = FP('x', FPSort(8, 24))
8884 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8885 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8888 """Create the Z3 expression `self - other`.
8890 >>> x = FP('x', FPSort(8, 24))
8891 >>> y = FP('y', FPSort(8, 24))
8897 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8898 return fpSub(_dflt_rm(), a, b, self.
ctx)
8901 """Create the Z3 expression `other - self`.
8903 >>> x = FP('x', FPSort(8, 24))
8907 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8908 return fpSub(_dflt_rm(), a, b, self.
ctx)
8911 """Create the Z3 expression `self * other`.
8913 >>> x = FP('x', FPSort(8, 24))
8914 >>> y = FP('y', FPSort(8, 24))
8922 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8923 return fpMul(_dflt_rm(), a, b, self.
ctx)
8926 """Create the Z3 expression `other * self`.
8928 >>> x = FP('x', FPSort(8, 24))
8929 >>> y = FP('y', FPSort(8, 24))
8935 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8936 return fpMul(_dflt_rm(), a, b, self.
ctx)
8939 """Create the Z3 expression `+self`."""
8943 """Create the Z3 expression `-self`.
8945 >>> x = FP('x', Float32())
8952 """Create the Z3 expression `self / other`.
8954 >>> x = FP('x', FPSort(8, 24))
8955 >>> y = FP('y', FPSort(8, 24))
8963 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8964 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8967 """Create the Z3 expression `other / self`.
8969 >>> x = FP('x', FPSort(8, 24))
8970 >>> y = FP('y', FPSort(8, 24))
8976 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8977 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8980 """Create the Z3 expression division `self / other`."""
8984 """Create the Z3 expression division `other / self`."""
8988 """Create the Z3 expression mod `self % other`."""
8989 return fpRem(self, other)
8992 """Create the Z3 expression mod `other % self`."""
8993 return fpRem(other, self)
8996 """Floating-point rounding mode expressions"""
8999 """Return a Z3 floating point expression as a Python string."""
9044 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9053 return isinstance(a, FPRMRef)
9056 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9057 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9062 """The sign of the numeral.
9064 >>> x = FPVal(+1.0, FPSort(8, 24))
9067 >>> x = FPVal(-1.0, FPSort(8, 24))
9072 l = (ctypes.c_int)()
9074 raise Z3Exception(
"error retrieving the sign of a numeral.")
9077 """The sign of a floating-point numeral as a bit-vector expression.
9079 Remark: NaN's are invalid arguments.
9084 """The significand of the numeral.
9086 >>> x = FPVal(2.5, FPSort(8, 24))
9093 """The significand of the numeral as a long.
9095 >>> x = FPVal(2.5, FPSort(8, 24))
9096 >>> x.significand_as_long()
9100 ptr = (ctypes.c_ulonglong * 1)()
9102 raise Z3Exception(
"error retrieving the significand of a numeral.")
9105 """The significand of the numeral as a bit-vector expression.
9107 Remark: NaN are invalid arguments.
9112 """The exponent of the numeral.
9114 >>> x = FPVal(2.5, FPSort(8, 24))
9121 """The exponent of the numeral as a long.
9123 >>> x = FPVal(2.5, FPSort(8, 24))
9124 >>> x.exponent_as_long()
9128 ptr = (ctypes.c_longlong * 1)()
9130 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9133 """The exponent of the numeral as a bit-vector expression.
9135 Remark: NaNs are invalid arguments.
9140 """Indicates whether the numeral is a NaN."""
9144 """Indicates whether the numeral is +oo or -oo."""
9148 """Indicates whether the numeral is +zero or -zero."""
9152 """Indicates whether the numeral is normal."""
9156 """Indicates whether the numeral is subnormal."""
9160 """Indicates whether the numeral is positive."""
9164 """Indicates whether the numeral is negative."""
9169 The string representation of the numeral.
9171 >>> x = FPVal(20, FPSort(8, 24))
9177 return (
"FPVal(%s, %s)" % (s, self.
sort()))
9180 """Return `True` if `a` is a Z3 floating-point expression.
9182 >>> b = FP('b', FPSort(8, 24))
9190 return isinstance(a, FPRef)
9193 """Return `True` if `a` is a Z3 floating-point numeral value.
9195 >>> b = FP('b', FPSort(8, 24))
9198 >>> b = FPVal(1.0, FPSort(8, 24))
9204 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9207 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9209 >>> Single = FPSort(8, 24)
9210 >>> Double = FPSort(11, 53)
9213 >>> x = Const('x', Single)
9214 >>> eq(x, FP('x', FPSort(8, 24)))
9220 def _to_float_str(val, exp=0):
9221 if isinstance(val, float):
9225 sone = math.copysign(1.0, val)
9230 elif val == float(
"+inf"):
9232 elif val == float(
"-inf"):
9235 v = val.as_integer_ratio()
9238 rvs = str(num) +
'/' + str(den)
9239 res = rvs +
'p' + _to_int_str(exp)
9240 elif isinstance(val, bool):
9247 elif isinstance(val, str):
9248 inx = val.find(
'*(2**')
9251 elif val[-1] ==
')':
9253 exp = str(int(val[inx+5:-1]) + int(exp))
9255 _z3_assert(
False,
"String does not have floating-point numeral form.")
9257 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9261 return res +
'p' + exp
9265 """Create a Z3 floating-point NaN term.
9267 >>> s = FPSort(8, 24)
9268 >>> set_fpa_pretty(True)
9271 >>> pb = get_fpa_pretty()
9272 >>> set_fpa_pretty(False)
9274 fpNaN(FPSort(8, 24))
9275 >>> set_fpa_pretty(pb)
9277 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9281 """Create a Z3 floating-point +oo term.
9283 >>> s = FPSort(8, 24)
9284 >>> pb = get_fpa_pretty()
9285 >>> set_fpa_pretty(True)
9286 >>> fpPlusInfinity(s)
9288 >>> set_fpa_pretty(False)
9289 >>> fpPlusInfinity(s)
9290 fpPlusInfinity(FPSort(8, 24))
9291 >>> set_fpa_pretty(pb)
9293 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9297 """Create a Z3 floating-point -oo term."""
9298 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9302 """Create a Z3 floating-point +oo or -oo term."""
9303 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9304 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9308 """Create a Z3 floating-point +0.0 term."""
9309 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9313 """Create a Z3 floating-point -0.0 term."""
9314 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9318 """Create a Z3 floating-point +0.0 or -0.0 term."""
9319 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9320 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9323 def FPVal(sig, exp=None, fps=None, ctx=None):
9324 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9326 >>> v = FPVal(20.0, FPSort(8, 24))
9329 >>> print("0x%.8x" % v.exponent_as_long(False))
9331 >>> v = FPVal(2.25, FPSort(8, 24))
9334 >>> v = FPVal(-2.25, FPSort(8, 24))
9337 >>> FPVal(-0.0, FPSort(8, 24))
9339 >>> FPVal(0.0, FPSort(8, 24))
9341 >>> FPVal(+0.0, FPSort(8, 24))
9349 fps = _dflt_fps(ctx)
9353 val = _to_float_str(sig)
9354 if val ==
"NaN" or val ==
"nan":
9358 elif val ==
"0.0" or val ==
"+0.0":
9360 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9362 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9367 def FP(name, fpsort, ctx=None):
9368 """Return a floating-point constant named `name`.
9369 `fpsort` is the floating-point sort.
9370 If `ctx=None`, then the global context is used.
9372 >>> x = FP('x', FPSort(8, 24))
9379 >>> word = FPSort(8, 24)
9380 >>> x2 = FP('x', word)
9384 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9390 def FPs(names, fpsort, ctx=None):
9391 """Return an array of floating-point constants.
9393 >>> x, y, z = FPs('x y z', FPSort(8, 24))
9400 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9401 fpMul(RNE(), fpAdd(RNE(), x, y), z)
9404 if isinstance(names, str):
9405 names = names.split(
" ")
9406 return [
FP(name, fpsort, ctx)
for name
in names]
9409 """Create a Z3 floating-point absolute value expression.
9411 >>> s = FPSort(8, 24)
9413 >>> x = FPVal(1.0, s)
9416 >>> y = FPVal(-20.0, s)
9421 >>> fpAbs(-1.25*(2**4))
9427 [a] = _coerce_fp_expr_list([a], ctx)
9431 """Create a Z3 floating-point addition expression.
9433 >>> s = FPSort(8, 24)
9442 [a] = _coerce_fp_expr_list([a], ctx)
9445 def _mk_fp_unary(f, rm, a, ctx):
9447 [a] = _coerce_fp_expr_list([a], ctx)
9449 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9450 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9451 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9453 def _mk_fp_unary_pred(f, a, ctx):
9455 [a] = _coerce_fp_expr_list([a], ctx)
9457 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9458 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9460 def _mk_fp_bin(f, rm, a, b, ctx):
9462 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9464 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9465 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9466 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
9468 def _mk_fp_bin_norm(f, a, b, ctx):
9470 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9472 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9473 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9475 def _mk_fp_bin_pred(f, a, b, ctx):
9477 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9479 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9480 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9482 def _mk_fp_tern(f, rm, a, b, c, ctx):
9484 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
9486 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9487 _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")
9488 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
9491 """Create a Z3 floating-point addition expression.
9493 >>> s = FPSort(8, 24)
9499 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9501 >>> fpAdd(rm, x, y).sort()
9504 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9507 """Create a Z3 floating-point subtraction expression.
9509 >>> s = FPSort(8, 24)
9515 >>> fpSub(rm, x, y).sort()
9518 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9521 """Create a Z3 floating-point multiplication expression.
9523 >>> s = FPSort(8, 24)
9529 >>> fpMul(rm, x, y).sort()
9532 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9535 """Create a Z3 floating-point division expression.
9537 >>> s = FPSort(8, 24)
9543 >>> fpDiv(rm, x, y).sort()
9546 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9549 """Create a Z3 floating-point remainder expression.
9551 >>> s = FPSort(8, 24)
9556 >>> fpRem(x, y).sort()
9559 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9562 """Create a Z3 floating-point minimum expression.
9564 >>> s = FPSort(8, 24)
9570 >>> fpMin(x, y).sort()
9573 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9576 """Create a Z3 floating-point maximum expression.
9578 >>> s = FPSort(8, 24)
9584 >>> fpMax(x, y).sort()
9587 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9590 """Create a Z3 floating-point fused multiply-add expression.
9592 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9595 """Create a Z3 floating-point square root expression.
9597 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9600 """Create a Z3 floating-point roundToIntegral expression.
9602 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9605 """Create a Z3 floating-point isNaN expression.
9607 >>> s = FPSort(8, 24)
9613 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
9616 """Create a Z3 floating-point isInfinite expression.
9618 >>> s = FPSort(8, 24)
9623 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
9626 """Create a Z3 floating-point isZero expression.
9628 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
9631 """Create a Z3 floating-point isNormal expression.
9633 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
9636 """Create a Z3 floating-point isSubnormal expression.
9638 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
9641 """Create a Z3 floating-point isNegative expression.
9643 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
9646 """Create a Z3 floating-point isPositive expression.
9648 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
9650 def _check_fp_args(a, b):
9652 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9655 """Create the Z3 floating-point expression `other < self`.
9657 >>> x, y = FPs('x y', FPSort(8, 24))
9663 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9666 """Create the Z3 floating-point expression `other <= self`.
9668 >>> x, y = FPs('x y', FPSort(8, 24))
9671 >>> (x <= y).sexpr()
9674 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9677 """Create the Z3 floating-point expression `other > self`.
9679 >>> x, y = FPs('x y', FPSort(8, 24))
9685 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9688 """Create the Z3 floating-point expression `other >= self`.
9690 >>> x, y = FPs('x y', FPSort(8, 24))
9693 >>> (x >= y).sexpr()
9696 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9699 """Create the Z3 floating-point expression `fpEQ(other, self)`.
9701 >>> x, y = FPs('x y', FPSort(8, 24))
9704 >>> fpEQ(x, y).sexpr()
9707 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9710 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9712 >>> x, y = FPs('x y', FPSort(8, 24))
9715 >>> (x != y).sexpr()
9721 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9723 >>> s = FPSort(8, 24)
9724 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9726 fpFP(1, 127, 4194304)
9727 >>> xv = FPVal(-1.5, s)
9731 >>> slvr.add(fpEQ(x, xv))
9734 >>> xv = FPVal(+1.5, s)
9738 >>> slvr.add(fpEQ(x, xv))
9743 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
9745 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
9749 """Create a Z3 floating-point conversion expression from other term sorts
9752 From a bit-vector term in IEEE 754-2008 format:
9753 >>> x = FPVal(1.0, Float32())
9754 >>> x_bv = fpToIEEEBV(x)
9755 >>> simplify(fpToFP(x_bv, Float32()))
9758 From a floating-point term with different precision:
9759 >>> x = FPVal(1.0, Float32())
9760 >>> x_db = fpToFP(RNE(), x, Float64())
9765 >>> x_r = RealVal(1.5)
9766 >>> simplify(fpToFP(RNE(), x_r, Float32()))
9769 From a signed bit-vector term:
9770 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9771 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9784 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
9787 """Create a Z3 floating-point conversion expression that represents the
9788 conversion from a bit-vector term to a floating-point term.
9790 >>> x_bv = BitVecVal(0x3F800000, 32)
9791 >>> x_fp = fpBVToFP(x_bv, Float32())
9797 _z3_assert(
is_bv(v),
"First argument must be a Z3 bit-vector expression")
9798 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
9803 """Create a Z3 floating-point conversion expression that represents the
9804 conversion from a floating-point term to a floating-point term of different precision.
9806 >>> x_sgl = FPVal(1.0, Float32())
9807 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9815 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9816 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
9817 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9822 """Create a Z3 floating-point conversion expression that represents the
9823 conversion from a real term to a floating-point term.
9825 >>> x_r = RealVal(1.5)
9826 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9832 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9833 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
9834 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9839 """Create a Z3 floating-point conversion expression that represents the
9840 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9842 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9843 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9845 fpToFP(RNE(), 4294967291)
9849 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9850 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
9851 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9856 """Create a Z3 floating-point conversion expression that represents the
9857 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9859 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9860 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9862 fpToFPUnsigned(RNE(), 4294967291)
9866 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9867 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
9868 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9873 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9875 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9876 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
9877 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
9882 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9884 >>> x = FP('x', FPSort(8, 24))
9885 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9896 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9897 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9898 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9903 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9905 >>> x = FP('x', FPSort(8, 24))
9906 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9917 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9918 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9919 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9924 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9926 >>> x = FP('x', FPSort(8, 24))
9930 >>> print(is_real(y))
9934 >>> print(is_real(x))
9938 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9943 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9945 The size of the resulting bit-vector is automatically determined.
9947 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9948 knows only one NaN and it will always produce the same bit-vector representation of
9951 >>> x = FP('x', FPSort(8, 24))
9952 >>> y = fpToIEEEBV(x)
9963 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9976 """Sequence sort."""
9979 """Determine if sort is a string
9980 >>> s = StringSort()
9983 >>> s = SeqSort(IntSort())
9994 """Create a string sort
9995 >>> s = StringSort()
10004 """Create a sequence sort over elements provided in the argument
10005 >>> s = SeqSort(IntSort())
10006 >>> s == Unit(IntVal(1)).sort()
10012 """Sequence expression."""
10018 return Concat(self, other)
10021 return Concat(other, self)
10041 """Return a string representation of sequence expression."""
10043 string_length = ctypes.c_uint()
10045 return string_at(chars, size=string_length.value).decode(
'latin-1')
10061 def _coerce_seq(s, ctx=None):
10062 if isinstance(s, str):
10063 ctx = _get_ctx(ctx)
10066 raise Z3Exception(
"Non-expression passed as a sequence")
10068 raise Z3Exception(
"Non-sequence passed as a sequence")
10071 def _get_ctx2(a, b, ctx=None):
10081 """Return `True` if `a` is a Z3 sequence expression.
10082 >>> print (is_seq(Unit(IntVal(0))))
10084 >>> print (is_seq(StringVal("abc")))
10087 return isinstance(a, SeqRef)
10090 """Return `True` if `a` is a Z3 string expression.
10091 >>> print (is_string(StringVal("ab")))
10094 return isinstance(a, SeqRef)
and a.is_string()
10097 """return 'True' if 'a' is a Z3 string constant expression.
10098 >>> print (is_string_value(StringVal("a")))
10100 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10103 return isinstance(a, SeqRef)
and a.is_string_value()
10107 """create a string expression"""
10108 ctx = _get_ctx(ctx)
10112 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10114 >>> x = String('x')
10116 ctx = _get_ctx(ctx)
10120 """Return string constants"""
10121 ctx = _get_ctx(ctx)
10122 if isinstance(names, str):
10123 names = names.split(
" ")
10124 return [
String(name, ctx)
for name
in names]
10127 """Extract substring or subsequence starting at offset"""
10128 return Extract(s, offset, length)
10131 """Extract substring or subsequence starting at offset"""
10132 return Extract(s, offset, length)
10134 def Strings(names, ctx=None):
10135 """Return a tuple of String constants. """
10136 ctx = _get_ctx(ctx)
10137 if isinstance(names, str):
10138 names = names.split(
" ")
10139 return [
String(name, ctx)
for name
in names]
10142 """Create the empty sequence of the given sort
10143 >>> e = Empty(StringSort())
10144 >>> e2 = StringVal("")
10145 >>> print(e.eq(e2))
10147 >>> e3 = Empty(SeqSort(IntSort()))
10150 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10152 Empty(ReSort(Seq(Int)))
10154 if isinstance(s, SeqSortRef):
10156 if isinstance(s, ReSortRef):
10158 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10161 """Create the regular expression that accepts the universal language
10162 >>> e = Full(ReSort(SeqSort(IntSort())))
10164 Full(ReSort(Seq(Int)))
10165 >>> e1 = Full(ReSort(StringSort()))
10167 Full(ReSort(String))
10169 if isinstance(s, ReSortRef):
10171 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10175 """Create a singleton sequence"""
10179 """Check if 'a' is a prefix of 'b'
10180 >>> s1 = PrefixOf("ab", "abc")
10183 >>> s2 = PrefixOf("bc", "abc")
10187 ctx = _get_ctx2(a, b)
10188 a = _coerce_seq(a, ctx)
10189 b = _coerce_seq(b, ctx)
10193 """Check if 'a' is a suffix of 'b'
10194 >>> s1 = SuffixOf("ab", "abc")
10197 >>> s2 = SuffixOf("bc", "abc")
10201 ctx = _get_ctx2(a, b)
10202 a = _coerce_seq(a, ctx)
10203 b = _coerce_seq(b, ctx)
10207 """Check if 'a' contains 'b'
10208 >>> s1 = Contains("abc", "ab")
10211 >>> s2 = Contains("abc", "bc")
10214 >>> x, y, z = Strings('x y z')
10215 >>> s3 = Contains(Concat(x,y,z), y)
10219 ctx = _get_ctx2(a, b)
10220 a = _coerce_seq(a, ctx)
10221 b = _coerce_seq(b, ctx)
10226 """Replace the first occurrence of 'src' by 'dst' in 's'
10227 >>> r = Replace("aaa", "a", "b")
10231 ctx = _get_ctx2(dst, s)
10232 if ctx
is None and is_expr(src):
10234 src = _coerce_seq(src, ctx)
10235 dst = _coerce_seq(dst, ctx)
10236 s = _coerce_seq(s, ctx)
10243 """Retrieve the index of substring within a string starting at a specified offset.
10244 >>> simplify(IndexOf("abcabc", "bc", 0))
10246 >>> simplify(IndexOf("abcabc", "bc", 2))
10252 ctx = _get_ctx2(s, substr, ctx)
10253 s = _coerce_seq(s, ctx)
10254 substr = _coerce_seq(substr, ctx)
10255 if _is_int(offset):
10256 offset =
IntVal(offset, ctx)
10260 """Retrieve the last index of substring within a string"""
10262 ctx = _get_ctx2(s, substr, ctx)
10263 s = _coerce_seq(s, ctx)
10264 substr = _coerce_seq(substr, ctx)
10269 """Obtain the length of a sequence 's'
10270 >>> l = Length(StringVal("abc"))
10278 """Convert string expression to integer
10279 >>> a = StrToInt("1")
10280 >>> simplify(1 == a)
10282 >>> b = StrToInt("2")
10283 >>> simplify(1 == b)
10285 >>> c = StrToInt(IntToStr(2))
10286 >>> simplify(1 == c)
10294 """Convert integer expression to string"""
10301 """The regular expression that accepts sequence 's'
10303 >>> s2 = Re(StringVal("ab"))
10304 >>> s3 = Re(Unit(BoolVal(True)))
10306 s = _coerce_seq(s, ctx)
10315 """Regular expression sort."""
10323 if s
is None or isinstance(s, Context):
10326 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10330 """Regular expressions."""
10333 return Union(self, other)
10336 return isinstance(s, ReRef)
10340 """Create regular expression membership test
10341 >>> re = Union(Re("a"),Re("b"))
10342 >>> print (simplify(InRe("a", re)))
10344 >>> print (simplify(InRe("b", re)))
10346 >>> print (simplify(InRe("c", re)))
10349 s = _coerce_seq(s, re.ctx)
10353 """Create union of regular expressions.
10354 >>> re = Union(Re("a"), Re("b"), Re("c"))
10355 >>> print (simplify(InRe("d", re)))
10358 args = _get_args(args)
10361 _z3_assert(sz > 0,
"At least one argument expected.")
10362 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10367 for i
in range(sz):
10368 v[i] = args[i].as_ast()
10372 """Create intersection of regular expressions.
10373 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
10375 args = _get_args(args)
10378 _z3_assert(sz > 0,
"At least one argument expected.")
10379 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10384 for i
in range(sz):
10385 v[i] = args[i].as_ast()
10389 """Create the regular expression accepting one or more repetitions of argument.
10390 >>> re = Plus(Re("a"))
10391 >>> print(simplify(InRe("aa", re)))
10393 >>> print(simplify(InRe("ab", re)))
10395 >>> print(simplify(InRe("", re)))
10401 """Create the regular expression that optionally accepts the argument.
10402 >>> re = Option(Re("a"))
10403 >>> print(simplify(InRe("a", re)))
10405 >>> print(simplify(InRe("", re)))
10407 >>> print(simplify(InRe("aa", re)))
10413 """Create the complement regular expression."""
10417 """Create the regular expression accepting zero or more repetitions of argument.
10418 >>> re = Star(Re("a"))
10419 >>> print(simplify(InRe("aa", re)))
10421 >>> print(simplify(InRe("ab", re)))
10423 >>> print(simplify(InRe("", re)))
10429 """Create the regular expression accepting between a lower and upper bound repetitions
10430 >>> re = Loop(Re("a"), 1, 3)
10431 >>> print(simplify(InRe("aa", re)))
10433 >>> print(simplify(InRe("aaaa", re)))
10435 >>> print(simplify(InRe("", re)))
10441 """Create the range regular expression over two sequences of length 1
10442 >>> range = Range("a","z")
10443 >>> print(simplify(InRe("b", range)))
10445 >>> print(simplify(InRe("bb", range)))
10448 lo = _coerce_seq(lo, ctx)
10449 hi = _coerce_seq(hi, ctx)
10467 """Given a binary relation R, such that the two arguments have the same sort
10468 create the transitive closure relation R+.
10469 The transitive closure R+ is a new relation.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
def Reals(names, ctx=None)
Z3_bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...
def __rand__(self, other)
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
def fpInfinity(s, negative)
bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a +oo or -oo.
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p)
Convert a Z3_pattern into Z3_ast. This is just type casting.
Z3_ast_vector Z3_API Z3_optimize_get_lower_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector ...
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
def fpRoundToIntegral(rm, a, ctx=None)
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
def __rsub__(self, other)
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
def __init__(self, stats, ctx)
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
void Z3_API Z3_solver_import_model_converter(Z3_context ctx, Z3_solver src, Z3_solver dst)
Ad-hoc method for importing model conversion from solver.
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
def __init__(self, descr, ctx=None)
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1....
def RoundTowardPositive(ctx=None)
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
def is_string_value(self)
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
def FreshReal(prefix='b', ctx=None)
def fact(self, head, name=None)
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, bool biased)
Retrieves the exponent of a floating-point literal as a bit-vector expression.
void Z3_API Z3_params_set_uint(Z3_context c, Z3_params p, Z3_symbol k, unsigned v)
Add a unsigned parameter k with value v to the parameter set p.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
void Z3_API Z3_params_set_double(Z3_context c, Z3_params p, Z3_symbol k, double v)
Add a double parameter k with value v to the parameter set p.
def exponent(self, biased=True)
def parse_string(self, s)
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
def __deepcopy__(self, memo={})
def __rxor__(self, other)
void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz, unsigned levels[])
retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat c...
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t *n, bool biased)
Return the exponent value of a floating-point numeral as a signed 64-bit integer.
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
def TupleSort(name, sorts, ctx=None)
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
def evaluate(self, t, model_completion=False)
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
def fpBVToFP(v, sort, ctx=None)
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
def __truediv__(self, other)
void Z3_API Z3_dec_ref(Z3_context c, Z3_ast a)
Decrement the reference counter of the given AST. The context c should have been created using Z3_mk_...
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i)
Return the name of the parameter at given index i.
def FPs(names, fpsort, ctx=None)
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.
def __contains__(self, item)
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.
def DisjointSum(name, sorts, ctx=None)
def Strings(names, ctx=None)
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
def __deepcopy__(self, memo={})
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
Z3_string Z3_API Z3_optimize_get_reason_unknown(Z3_context c, Z3_optimize d)
Retrieve a string that describes the last status returned by Z3_optimize_check.
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
def __init__(self, ctx=None, params=None)
def cube(self, vars=None)
def __rlshift__(self, other)
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
def FPVal(sig, exp=None, fps=None, ctx=None)
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_translate(Z3_context source, Z3_ast a, Z3_context target)
Translate/Copy the AST a from context source to context target. AST a must have been created using co...
def RealVarVector(n, ctx=None)
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
def fpToUBV(rm, x, s, ctx=None)
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms)
Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms mil...
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s)
Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if th...
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p)
Convert a parameter description set into a string. This function is mainly used for printing the cont...
def set(self, *args, **keys)
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.
expr range(expr const &lo, expr const &hi)
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
def BVSubNoOverflow(a, b)
unsigned Z3_API Z3_get_app_num_args(Z3_context c, Z3_app a)
Return the number of argument of an application. If t is an constant, then the number of arguments is...
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural. You can use Z3_get_ast_id intercha...
def __init__(self, *args, **kws)
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
Z3_char_ptr Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned *length)
Retrieve the unescaped string constant stored in s.
def declare_core(self, name, rec_name, *args)
def RoundTowardNegative(ctx=None)
def __init__(self, result, ctx)
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
unsigned Z3_API Z3_apply_result_get_num_subgoals(Z3_context c, Z3_apply_result r)
Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
def set_param(*args, **kws)
def __deepcopy__(self, memo={})
def RatVal(a, b, ctx=None)
def IntVal(val, ctx=None)
def translate(self, target)
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s)
Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_ch...
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.
def fpToFP(a1, a2=None, a3=None, ctx=None)
def eval(self, t, model_completion=False)
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p)
Convert a parameter set into a string. This function is mainly used for printing the contents of a pa...
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
def __init__(self, tactic, ctx=None)
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
def to_string(self, queries)
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
Z3_ast Z3_API Z3_mk_set_has_size(Z3_context c, Z3_ast set, Z3_ast k)
Create predicate that holds if Boolean array set has k elements set to true.
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
def fpUnsignedToFP(rm, v, sort, ctx=None)
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
def register_relation(self, *relations)
Z3_ast Z3_API Z3_func_decl_to_ast(Z3_context c, Z3_func_decl f)
Convert a Z3_func_decl into Z3_ast. This is just type casting.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
def add_rule(self, head, body=None, name=None)
def numerator_as_long(self)
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
def add_cover(self, level, predicate, property)
def BoolVector(prefix, sz, ctx=None)
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
def __init__(self, ast, ctx=None)
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
def SubSeq(s, offset, length)
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
unsigned Z3_API Z3_param_descrs_size(Z3_context c, Z3_param_descrs p)
Return the number of parameters in the given parameter description set.
def SimpleSolver(ctx=None, logFile=None)
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not.
def With(t, *args, **keys)
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
def simplify(a, *arguments, **keywords)
Utils.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
def __deepcopy__(self, memo={})
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_param_descrs Z3_API Z3_optimize_get_param_descrs(Z3_context c, Z3_optimize o)
Return the parameter description set for the given optimize object.
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
def num_no_patterns(self)
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size)
Create a named finite domain sort.
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
def __init__(self, ctx=None)
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
def __call__(self, goal, *arguments, **keywords)
def __rdiv__(self, other)
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
def to_symbol(s, ctx=None)
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
def fpMul(rm, a, b, ctx=None)
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
def dimacs(self, include_names=True)
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
def fpGEQ(a, b, ctx=None)
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
def translate(self, target)
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
def __init__(self, v=None, ctx=None)
def consequences(self, assumptions, variables)
def fpRem(a, b, ctx=None)
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)
def set(self, *args, **keys)
def FiniteDomainSort(name, sz, ctx=None)
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a string of a numeric constant term.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a)
The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3....
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
def abstract(self, fml, is_forall=True)
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
def z3_error_handler(c, e)
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
def __init__(self, entry, ctx)
def BitVecVal(val, bv, ctx=None)
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode)
Select mode for the format used for pretty-printing AST nodes.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
void Z3_API Z3_param_descrs_dec_ref(Z3_context c, Z3_param_descrs p)
Decrement the reference counter of the given parameter description set.
def __radd__(self, other)
def __setitem__(self, k, v)
def Range(lo, hi, ctx=None)
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
Z3_ast Z3_API Z3_get_algebraic_number_upper(Z3_context c, Z3_ast a, unsigned precision)
Return a upper bound for the given real algebraic number. The interval isolating the number is smalle...
def exponent_as_long(self, biased=True)
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.
def Cond(p, t1, t2, ctx=None)
def __truediv__(self, other)
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const args[])
Create a constant or function application.
def is_finite_domain_sort(s)
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
def fpMax(a, b, ctx=None)
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
def from_file(self, filename)
def RealVal(val, ctx=None)
def translate(self, target)
def solve(*args, **keywords)
def __rdiv__(self, other)
def RoundNearestTiesToEven(ctx=None)
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def __getitem__(self, arg)
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t *n)
Return the significand value of a floating-point numeral as a uint64.
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v)
Add a Boolean parameter k with value v to the parameter set p.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
def fpToFPUnsigned(rm, x, s, ctx=None)
def set_predicate_representation(self, f, *representations)
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
def FloatQuadruple(ctx=None)
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
def __deepcopy__(self, memo={})
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
def If(a, b, c, ctx=None)
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
unsigned Z3_API Z3_fpa_get_sbits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the significand in a FloatingPoint sort.
def denominator_as_long(self)
Z3_ast Z3_API Z3_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t)
Retrieves the sign of a floating-point literal as a bit-vector expression.
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
def set_default_rounding_mode(rm, ctx=None)
def get_documentation(self, n)
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
def __rpow__(self, other)
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k)
Return true if the map m contains the AST key k.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
def lower_values(self, obj)
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
Z3_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
Z3_ast Z3_API Z3_sort_to_ast(Z3_context c, Z3_sort s)
Convert a Z3_sort into Z3_ast. This is just type casting.
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.
def __getitem__(self, idx)
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, bool is_forall, unsigned weight, Z3_symbol quantifier_id, Z3_symbol skolem_id, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], unsigned num_no_patterns, Z3_ast const no_patterns[], Z3_ast body)
Create a universal or existential quantifier using a list of constants that will form the set of boun...
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function interpretation. It represents the value of f in a particular p...
def fpFMA(rm, a, b, c, ctx=None)
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
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.
def __deepcopy__(self, memo={})
def __rmul__(self, other)
def simplify_param_descrs()
def exponent_as_bv(self, biased=True)
def fpSignedToFP(rm, v, sort, ctx=None)
def get_default_rounding_mode(ctx=None)
def __getitem__(self, idx)
Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s)
Return the parameter description set for the given solver object.
def PbEq(args, k, ctx=None)
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k)
Return the value associated with the key k.
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
def __getitem__(self, key)
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return the last occurrence of substr in s. If s does not contain substr, then the value is -1,...
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
def BVAddNoOverflow(a, b, signed)
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
def __rmod__(self, other)
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
def get_cover_delta(self, level, predicate)
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
def __rtruediv__(self, other)
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
def Ints(names, ctx=None)
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
def Extract(high, low, a)
Z3_sort Z3_API Z3_get_domain(Z3_context c, Z3_func_decl d, unsigned i)
Return the sort of the i-th parameter of the given function declaration.
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
def FreshBool(prefix='b', ctx=None)
def approx(self, precision=10)
def Array(name, dom, rng)
def __rdiv__(self, other)
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
unsigned Z3_API Z3_solver_get_num_scopes(Z3_context c, Z3_solver s)
Return the number of backtracking points.
def assert_exprs(self, *args)
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.
def ParAndThen(t1, t2, ctx=None)
def BVAddNoUnderflow(a, b)
def FloatDouble(ctx=None)
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality....
def Bools(names, ctx=None)
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
def __rmul__(self, other)
def RoundNearestTiesToAway(ctx=None)
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i)
Return sort of the i'th bound variable.
Z3_ast_vector Z3_API Z3_solver_get_trail(Z3_context c, Z3_solver s)
Return the trail modulo model conversion, in order of decision level The decision level can be retrie...
def __deepcopy__(self, memo={})
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p)
Increment the reference counter of the given parameter description set.
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
def recognizer(self, idx)
def substitute_vars(t, *m)
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_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n,...
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
def Implies(a, b, ctx=None)
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
def constructor(self, idx)
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.
def get_rules_along_trace(self)
def BVSDivNoOverflow(a, b)
def BitVec(name, bv, ctx=None)
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL,...
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
def __deepcopy__(self, memo={})
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
def __rtruediv__(self, other)
def __radd__(self, other)
def BitVecs(names, bv, ctx=None)
Z3_goal Z3_API Z3_goal_translate(Z3_context source, Z3_goal g, Z3_context target)
Copy a goal g from the context source to the context target.
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...
def LastIndexOf(s, substr)
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
def __deepcopy__(self, memo={})
Z3_bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
def fpIsNormal(a, ctx=None)
def __init__(self, fixedpoint=None, ctx=None)
def get_universe(self, s)
def FreshConst(sort, prefix='c')
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
Z3_ast Z3_API Z3_mk_ext_rotate_right(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the right t2 times.
def __deepcopy__(self, memo={})
Z3_sort Z3_API Z3_get_re_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for regex sort.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
def add_soft(self, arg, weight="1", id=None)
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
def __deepcopy__(self, memo={})
def probe_description(name, ctx=None)
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Strings, Sequences and Regular expressions.
def solver(self, logFile=None)
def assert_and_track(self, a, p)
def tactic_description(name, ctx=None)
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
def StringVal(s, ctx=None)
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
def update_rule(self, head, body, name)
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
def fpFP(sgn, exp, sig, ctx=None)
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
Z3_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...
def significand_as_long(self)
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s)
Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the as...
def FPSort(ebits, sbits, ctx=None)
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a NaN.
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
void Z3_API Z3_fixedpoint_set_predicate_representation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f, unsigned num_relations, Z3_symbol const relation_kinds[])
Configure the predicate representation.
def DeclareSort(name, ctx=None)
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
def __rmod__(self, other)
def fpSqrt(rm, a, ctx=None)
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.
def __deepcopy__(self, memo={})
def apply(self, goal, *arguments, **keywords)
def RealVar(idx, ctx=None)
def FP(name, fpsort, ctx=None)
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context....
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
def fpDiv(rm, a, b, ctx=None)
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
def __getitem__(self, arg)
def set_default_fp_sort(ebits, sbits, ctx=None)
def __init__(self, c, ctx)
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.
void Z3_API Z3_params_validate(Z3_context c, Z3_params p, Z3_param_descrs d)
Validate the parameter set p against the parameter description set d.
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
def __init__(self, m, ctx)
def PiecewiseLinearOrder(a, index)
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
def __radd__(self, other)
Z3_params Z3_API Z3_mk_params(Z3_context c)
Create a Z3 (empty) parameter set. Starting at Z3 4.0, parameter sets are used to configure many comp...
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
def get_ground_sat_answer(self)
def RecAddDefinition(f, args, body)
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
def fpToSBV(rm, x, s, ctx=None)
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.
def __contains__(self, key)
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
def assert_and_track(self, a, p)
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
def rule(self, head, body=None, name=None)
Z3_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than or equal to.
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
def __getattr__(self, name)
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
def FreshInt(prefix='x', ctx=None)
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
def solve_using(s, *args, **keywords)
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
def FiniteDomainVal(val, sort, ctx=None)
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
def __init__(self, m=None, ctx=None)
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s)
Return the set of non units in the solver state.
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
Z3_apply_result Z3_API Z3_tactic_apply_ex(Z3_context c, Z3_tactic t, Z3_goal g, Z3_params p)
Apply tactic t to the goal g using the parameter set p.
def num_constructors(self)
def LinearOrder(a, index)
def BitVecSort(sz, ctx=None)
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vars, unsigned backtrack_level)
extract a next cube for a solver. The last cube is the constant true or false. The number of (non-con...
void Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
Z3_ast Z3_API Z3_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.
def translate(self, target)
def __rmul__(self, other)
def fpAdd(rm, a, b, ctx=None)
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
def is_finite_domain_value(a)
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
def __deepcopy__(self, memo={})
Z3_ast_vector Z3_API Z3_optimize_get_upper_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the tactic with the given name.
def fpSub(rm, a, b, ctx=None)
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
def __init__(self, c, ctx)
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
def no_pattern(self, idx)
def TryFor(t, ms, ctx=None)
def __init__(self, probe, ctx=None)
def get_interp(self, decl)
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t)
Return the significand value of a floating-point numeral as a string.
Z3_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
def fpLEQ(a, b, ctx=None)
def EnumSort(name, values, ctx=None)
def BoolVal(val, ctx=None)
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
def significand_as_bv(self)
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
def get_default_fp_sort(ctx=None)
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None)
def __call__(self, *args)
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
def check(self, *assumptions)
def convert_model(self, model)
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i,...
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
def __init__(self, f, ctx)
unsigned Z3_API Z3_func_interp_get_arity(Z3_context c, Z3_func_interp f)
Return the arity (number of arguments) of the given function interpretation.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
def SolverFor(logic, ctx=None, logFile=None)
Z3_symbol Z3_API Z3_get_quantifier_bound_name(Z3_context c, Z3_ast a, unsigned i)
Return symbol of the i'th bound variable.
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def __rrshift__(self, other)
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_solver Z3_API Z3_mk_solver(Z3_context c)
Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally ...
unsigned Z3_API Z3_fpa_get_ebits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the exponent in a FloatingPoint sort.
Z3_param_kind Z3_API Z3_param_descrs_get_kind(Z3_context c, Z3_param_descrs p, Z3_symbol n)
Return the kind associated with the given parameter name n.
def simplify(self, *arguments, **keywords)
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, bool biased)
Return the exponent value of a floating-point numeral as a string.
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs....
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
def __rmul__(self, other)
def __init__(self, name, ctx=None)
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t *r)
Store the size of the sort in r. Return false if the call failed. That is, Z3_get_sort_kind(s) == Z3_...
Z3_sort Z3_API Z3_get_array_sort_domain(Z3_context c, Z3_sort t)
Return the domain of the given array sort. In the case of a multi-dimensional array,...
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
def from_file(self, filename)
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
def IntVector(prefix, sz, ctx=None)
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
def translate(self, other_ctx)
def query_from_lvl(self, lvl, *query)
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
def as_decimal(self, prec)
def get_key_value(self, key)
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
def __rsub__(self, other)
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
def __radd__(self, other)
def __init__(self, opt, value, is_max)
def fpIsZero(a, ctx=None)
def assert_exprs(self, *args)
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
def PartialOrder(a, index)
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
def __setitem__(self, i, v)
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
def assert_exprs(self, *args)
def __rtruediv__(self, other)
def set(self, *args, **keys)
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of first occurrence of substr in s starting from offset offset. If s does not contain su...
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_ast Z3_API Z3_mk_str_lt(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is lexicographically strictly less than s2.
void Z3_API Z3_params_set_symbol(Z3_context c, Z3_params p, Z3_symbol k, Z3_symbol v)
Add a symbol parameter k with value v to the parameter set p.
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the free variables in a with the expressions in to. For every i smaller than num_exprs,...
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
def BV2Int(a, is_signed=False)
def __init__(self, solver=None, ctx=None, logFile=None)
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
def RoundTowardZero(ctx=None)
def __rshift__(self, other)
def get_rule_names_along_trace(self)
def RecFunction(name, *sig)
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is subnormal.
def assert_exprs(self, *args)
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
def is_algebraic_value(a)
def BVMulNoUnderflow(a, b)
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s)
Return a string describing all solver available parameters.
def translate(self, other_ctx)
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
def __rsub__(self, other)
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
def prove(claim, **keywords)
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s)
Check if s is a string sort.
def fpMin(a, b, ctx=None)
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
def declare(self, name, *args)
def __getitem__(self, idx)
def BVMulNoOverflow(a, b, signed)
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
def Repeat(t, max=4294967295, ctx=None)
def fpToReal(x, ctx=None)
def check(self, *assumptions)
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
Z3_ast Z3_API Z3_mk_seq_at(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the unit sequence positioned at position index. The sequence is empty if the index is...
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
def __lshift__(self, other)
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
def as_decimal(self, prec)
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
void Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property)
Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forw...
def upper_values(self, obj)
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
def get_num_levels(self, predicate)
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_str_le(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is equal or lexicographically strictly less than s2.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
def __rmod__(self, other)
def fpIsSubnormal(a, ctx=None)
def __getitem__(self, arg)
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
def fpIsNegative(a, ctx=None)
def declare_var(self, *vars)
def fpFPToFP(rm, v, sort, ctx=None)
def fpNEQ(a, b, ctx=None)
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.
bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int *sgn)
Retrieves the sign of a floating-point literal.
def __truediv__(self, other)
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...
def BVSubNoUnderflow(a, b, signed)
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
def ParThen(t1, t2, ctx=None)
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
def args2params(arguments, keywords, ctx=None)
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def FloatSingle(ctx=None)
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
Z3_string Z3_API Z3_benchmark_to_smtlib_string(Z3_context c, Z3_string name, Z3_string logic, Z3_string status, Z3_string attributes, unsigned num_assumptions, Z3_ast const assumptions[], Z3_ast formula)
Convert the given benchmark into SMT-LIB formatted string.
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is +zero or -zero.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
def fpRealToFP(rm, v, sort, ctx=None)
Z3_ast Z3_API Z3_mk_seq_nth(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the element positioned at position index. The function is under-specified if the inde...
def RealVector(prefix, sz, ctx=None)
def __getitem__(self, arg)
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
def fpIsPositive(a, ctx=None)
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_string Z3_API Z3_optimize_get_help(Z3_context c, Z3_optimize t)
Return a string containing a description of parameters accepted by optimize.
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_ast Z3_API Z3_fpa_get_numeral_significand_bv(Z3_context c, Z3_ast t)
Retrieves the significand of a floating-point literal as a bit-vector expression.
Z3_ast Z3_API Z3_mk_seq_extract(Z3_context c, Z3_ast s, Z3_ast offset, Z3_ast length)
Extract subsequence starting at offset of length.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
def set_option(*args, **kws)
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
def import_model_converter(self, other)
def SubString(s, offset, length)
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
def fpToIEEEBV(x, ctx=None)
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s)
Retrieve documentation string corresponding to parameter name s.
def String(name, ctx=None)
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.