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 """Return a Z3 integer numeral as a Python binary string.
2798 >>> v.as_binary_string()
2804 """Rational values."""
2807 """ Return the numerator of a Z3 rational numeral.
2809 >>> is_rational_value(RealVal("3/5"))
2811 >>> n = RealVal("3/5")
2814 >>> is_rational_value(Q(3,5))
2816 >>> Q(3,5).numerator()
2822 """ Return the denominator of a Z3 rational numeral.
2824 >>> is_rational_value(Q(3,5))
2833 """ Return the numerator as a Python long.
2835 >>> v = RealVal(10000000000)
2840 >>> v.numerator_as_long() + 1 == 10000000001
2846 """ Return the denominator as a Python long.
2848 >>> v = RealVal("1/3")
2851 >>> v.denominator_as_long()
2866 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
2870 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2872 >>> v = RealVal("1/5")
2875 >>> v = RealVal("1/3")
2882 """Return a Z3 rational numeral as a Python string.
2891 """Return a Z3 rational as a Python Fraction object.
2893 >>> v = RealVal("1/5")
2900 """Algebraic irrational values."""
2903 """Return a Z3 rational number that approximates the algebraic number `self`.
2904 The result `r` is such that |r - self| <= 1/10^precision
2906 >>> x = simplify(Sqrt(2))
2908 6838717160008073720548335/4835703278458516698824704
2914 """Return a string representation of the algebraic number `self` in decimal notation using `prec` decimal places
2916 >>> x = simplify(Sqrt(2))
2917 >>> x.as_decimal(10)
2919 >>> x.as_decimal(20)
2920 '1.41421356237309504880?'
2930 def _py2expr(a, ctx=None):
2931 if isinstance(a, bool):
2935 if isinstance(a, float):
2940 _z3_assert(
False,
"Python bool, int, long or float expected")
2943 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
2947 >>> x = Const('x', IntSort())
2950 >>> x.sort() == IntSort()
2952 >>> x.sort() == BoolSort()
2959 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
2963 >>> x = Const('x', RealSort())
2968 >>> x.sort() == RealSort()
2974 def _to_int_str(val):
2975 if isinstance(val, float):
2976 return str(int(val))
2977 elif isinstance(val, bool):
2984 elif isinstance(val, str):
2987 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
2990 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3001 """Return a Z3 real value.
3003 `val` may be a Python int, long, float or string representing a number in decimal or rational notation.
3004 If `ctx=None`, then the global context is used.
3008 >>> RealVal(1).sort()
3019 """Return a Z3 rational a/b.
3021 If `ctx=None`, then the global context is used.
3025 >>> RatVal(3,5).sort()
3029 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3030 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3033 def Q(a, b, ctx=None):
3034 """Return a Z3 rational a/b.
3036 If `ctx=None`, then the global context is used.
3046 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3058 """Return a tuple of Integer constants.
3060 >>> x, y, z = Ints('x y z')
3065 if isinstance(names, str):
3066 names = names.split(
" ")
3067 return [
Int(name, ctx)
for name
in names]
3070 """Return a list of integer constants of size `sz`.
3072 >>> X = IntVector('x', 3)
3079 return [
Int(
'%s__%s' % (prefix, i), ctx)
for i
in range(sz) ]
3082 """Return a fresh integer constant in the given context using the given prefix.
3095 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3107 """Return a tuple of real constants.
3109 >>> x, y, z = Reals('x y z')
3112 >>> Sum(x, y, z).sort()
3116 if isinstance(names, str):
3117 names = names.split(
" ")
3118 return [
Real(name, ctx)
for name
in names]
3121 """Return a list of real constants of size `sz`.
3123 >>> X = RealVector('x', 3)
3132 return [
Real(
'%s__%s' % (prefix, i), ctx)
for i
in range(sz) ]
3135 """Return a fresh real constant in the given context using the given prefix.
3148 """ Return the Z3 expression ToReal(a).
3160 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3165 """ Return the Z3 expression ToInt(a).
3177 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3182 """ Return the Z3 predicate IsInt(a).
3185 >>> IsInt(x + "1/2")
3187 >>> solve(IsInt(x + "1/2"), x > 0, x < 1)
3189 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
3193 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3198 """ Return a Z3 expression which represents the square root of a.
3210 """ Return a Z3 expression which represents the cubic root of a.
3228 """Bit-vector sort."""
3231 """Return the size (number of bits) of the bit-vector sort `self`.
3233 >>> b = BitVecSort(32)
3243 """Try to cast `val` as a Bit-Vector.
3245 >>> b = BitVecSort(32)
3248 >>> b.cast(10).sexpr()
3253 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
3260 """Return True if `s` is a Z3 bit-vector sort.
3262 >>> is_bv_sort(BitVecSort(32))
3264 >>> is_bv_sort(IntSort())
3267 return isinstance(s, BitVecSortRef)
3270 """Bit-vector expressions."""
3273 """Return the sort of the bit-vector expression `self`.
3275 >>> x = BitVec('x', 32)
3278 >>> x.sort() == BitVecSort(32)
3284 """Return the number of bits of the bit-vector expression `self`.
3286 >>> x = BitVec('x', 32)
3289 >>> Concat(x, x).size()
3295 """Create the Z3 expression `self + other`.
3297 >>> x = BitVec('x', 32)
3298 >>> y = BitVec('y', 32)
3304 a, b = _coerce_exprs(self, other)
3308 """Create the Z3 expression `other + self`.
3310 >>> x = BitVec('x', 32)
3314 a, b = _coerce_exprs(self, other)
3318 """Create the Z3 expression `self * other`.
3320 >>> x = BitVec('x', 32)
3321 >>> y = BitVec('y', 32)
3327 a, b = _coerce_exprs(self, other)
3331 """Create the Z3 expression `other * self`.
3333 >>> x = BitVec('x', 32)
3337 a, b = _coerce_exprs(self, other)
3341 """Create the Z3 expression `self - other`.
3343 >>> x = BitVec('x', 32)
3344 >>> y = BitVec('y', 32)
3350 a, b = _coerce_exprs(self, other)
3354 """Create the Z3 expression `other - self`.
3356 >>> x = BitVec('x', 32)
3360 a, b = _coerce_exprs(self, other)
3364 """Create the Z3 expression bitwise-or `self | other`.
3366 >>> x = BitVec('x', 32)
3367 >>> y = BitVec('y', 32)
3373 a, b = _coerce_exprs(self, other)
3377 """Create the Z3 expression bitwise-or `other | self`.
3379 >>> x = BitVec('x', 32)
3383 a, b = _coerce_exprs(self, other)
3387 """Create the Z3 expression bitwise-and `self & other`.
3389 >>> x = BitVec('x', 32)
3390 >>> y = BitVec('y', 32)
3396 a, b = _coerce_exprs(self, other)
3400 """Create the Z3 expression bitwise-or `other & self`.
3402 >>> x = BitVec('x', 32)
3406 a, b = _coerce_exprs(self, other)
3410 """Create the Z3 expression bitwise-xor `self ^ other`.
3412 >>> x = BitVec('x', 32)
3413 >>> y = BitVec('y', 32)
3419 a, b = _coerce_exprs(self, other)
3423 """Create the Z3 expression bitwise-xor `other ^ self`.
3425 >>> x = BitVec('x', 32)
3429 a, b = _coerce_exprs(self, other)
3435 >>> x = BitVec('x', 32)
3442 """Return an expression representing `-self`.
3444 >>> x = BitVec('x', 32)
3453 """Create the Z3 expression bitwise-not `~self`.
3455 >>> x = BitVec('x', 32)
3464 """Create the Z3 expression (signed) division `self / other`.
3466 Use the function UDiv() for unsigned division.
3468 >>> x = BitVec('x', 32)
3469 >>> y = BitVec('y', 32)
3476 >>> UDiv(x, y).sexpr()
3479 a, b = _coerce_exprs(self, other)
3483 """Create the Z3 expression (signed) division `self / other`."""
3487 """Create the Z3 expression (signed) division `other / self`.
3489 Use the function UDiv() for unsigned division.
3491 >>> x = BitVec('x', 32)
3494 >>> (10 / x).sexpr()
3495 '(bvsdiv #x0000000a x)'
3496 >>> UDiv(10, x).sexpr()
3497 '(bvudiv #x0000000a x)'
3499 a, b = _coerce_exprs(self, other)
3503 """Create the Z3 expression (signed) division `other / self`."""
3507 """Create the Z3 expression (signed) mod `self % other`.
3509 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3511 >>> x = BitVec('x', 32)
3512 >>> y = BitVec('y', 32)
3519 >>> URem(x, y).sexpr()
3521 >>> SRem(x, y).sexpr()
3524 a, b = _coerce_exprs(self, other)
3528 """Create the Z3 expression (signed) mod `other % self`.
3530 Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3532 >>> x = BitVec('x', 32)
3535 >>> (10 % x).sexpr()
3536 '(bvsmod #x0000000a x)'
3537 >>> URem(10, x).sexpr()
3538 '(bvurem #x0000000a x)'
3539 >>> SRem(10, x).sexpr()
3540 '(bvsrem #x0000000a x)'
3542 a, b = _coerce_exprs(self, other)
3546 """Create the Z3 expression (signed) `other <= self`.
3548 Use the function ULE() for unsigned less than or equal to.
3550 >>> x, y = BitVecs('x y', 32)
3553 >>> (x <= y).sexpr()
3555 >>> ULE(x, y).sexpr()
3558 a, b = _coerce_exprs(self, other)
3562 """Create the Z3 expression (signed) `other < self`.
3564 Use the function ULT() for unsigned less than.
3566 >>> x, y = BitVecs('x y', 32)
3571 >>> ULT(x, y).sexpr()
3574 a, b = _coerce_exprs(self, other)
3578 """Create the Z3 expression (signed) `other > self`.
3580 Use the function UGT() for unsigned greater than.
3582 >>> x, y = BitVecs('x y', 32)
3587 >>> UGT(x, y).sexpr()
3590 a, b = _coerce_exprs(self, other)
3594 """Create the Z3 expression (signed) `other >= self`.
3596 Use the function UGE() for unsigned greater than or equal to.
3598 >>> x, y = BitVecs('x y', 32)
3601 >>> (x >= y).sexpr()
3603 >>> UGE(x, y).sexpr()
3606 a, b = _coerce_exprs(self, other)
3610 """Create the Z3 expression (arithmetical) right shift `self >> other`
3612 Use the function LShR() for the right logical shift
3614 >>> x, y = BitVecs('x y', 32)
3617 >>> (x >> y).sexpr()
3619 >>> LShR(x, y).sexpr()
3623 >>> BitVecVal(4, 3).as_signed_long()
3625 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3627 >>> simplify(BitVecVal(4, 3) >> 1)
3629 >>> simplify(LShR(BitVecVal(4, 3), 1))
3631 >>> simplify(BitVecVal(2, 3) >> 1)
3633 >>> simplify(LShR(BitVecVal(2, 3), 1))
3636 a, b = _coerce_exprs(self, other)
3640 """Create the Z3 expression left shift `self << other`
3642 >>> x, y = BitVecs('x y', 32)
3645 >>> (x << y).sexpr()
3647 >>> simplify(BitVecVal(2, 3) << 1)
3650 a, b = _coerce_exprs(self, other)
3654 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3656 Use the function LShR() for the right logical shift
3658 >>> x = BitVec('x', 32)
3661 >>> (10 >> x).sexpr()
3662 '(bvashr #x0000000a x)'
3664 a, b = _coerce_exprs(self, other)
3668 """Create the Z3 expression left shift `other << self`.
3670 Use the function LShR() for the right logical shift
3672 >>> x = BitVec('x', 32)
3675 >>> (10 << x).sexpr()
3676 '(bvshl #x0000000a x)'
3678 a, b = _coerce_exprs(self, other)
3682 """Bit-vector values."""
3685 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3687 >>> v = BitVecVal(0xbadc0de, 32)
3690 >>> print("0x%.8x" % v.as_long())
3696 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign.
3698 >>> BitVecVal(4, 3).as_signed_long()
3700 >>> BitVecVal(7, 3).as_signed_long()
3702 >>> BitVecVal(3, 3).as_signed_long()
3704 >>> BitVecVal(2**32 - 1, 32).as_signed_long()
3706 >>> BitVecVal(2**64 - 1, 64).as_signed_long()
3711 if val >= 2**(sz - 1):
3713 if val < -2**(sz - 1):
3725 """Return `True` if `a` is a Z3 bit-vector expression.
3727 >>> b = BitVec('b', 32)
3735 return isinstance(a, BitVecRef)
3738 """Return `True` if `a` is a Z3 bit-vector numeral value.
3740 >>> b = BitVec('b', 32)
3743 >>> b = BitVecVal(10, 32)
3749 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3752 """Return the Z3 expression BV2Int(a).
3754 >>> b = BitVec('b', 3)
3755 >>> BV2Int(b).sort()
3760 >>> x > BV2Int(b, is_signed=False)
3762 >>> x > BV2Int(b, is_signed=True)
3763 x > If(b < 0, BV2Int(b) - 8, BV2Int(b))
3764 >>> solve(x > BV2Int(b), b == 1, x < 3)
3768 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3774 """Return the z3 expression Int2BV(a, num_bits).
3775 It is a bit-vector of width num_bits and represents the
3776 modulo of a by 2^num_bits
3782 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3784 >>> Byte = BitVecSort(8)
3785 >>> Word = BitVecSort(16)
3788 >>> x = Const('x', Byte)
3789 >>> eq(x, BitVec('x', 8))
3796 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3798 >>> v = BitVecVal(10, 32)
3801 >>> print("0x%.8x" % v.as_long())
3812 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
3813 If `ctx=None`, then the global context is used.
3815 >>> x = BitVec('x', 16)
3822 >>> word = BitVecSort(16)
3823 >>> x2 = BitVec('x', word)
3827 if isinstance(bv, BitVecSortRef):
3835 """Return a tuple of bit-vector constants of size bv.
3837 >>> x, y, z = BitVecs('x y z', 16)
3844 >>> Product(x, y, z)
3846 >>> simplify(Product(x, y, z))
3850 if isinstance(names, str):
3851 names = names.split(
" ")
3852 return [
BitVec(name, bv, ctx)
for name
in names]
3855 """Create a Z3 bit-vector concatenation expression.
3857 >>> v = BitVecVal(1, 4)
3858 >>> Concat(v, v+1, v)
3859 Concat(Concat(1, 1 + 1), 1)
3860 >>> simplify(Concat(v, v+1, v))
3862 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
3865 args = _get_args(args)
3868 _z3_assert(sz >= 2,
"At least two arguments expected.")
3875 if is_seq(args[0])
or isinstance(args[0], str):
3876 args = [_coerce_seq(s, ctx)
for s
in args]
3878 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
3881 v[i] = args[i].as_ast()
3886 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
3889 v[i] = args[i].as_ast()
3893 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
3895 for i
in range(sz - 1):
3900 """Create a Z3 bit-vector extraction expression, or create a string extraction expression.
3902 >>> x = BitVec('x', 8)
3903 >>> Extract(6, 2, x)
3905 >>> Extract(6, 2, x).sort()
3907 >>> simplify(Extract(StringVal("abcd"),2,1))
3910 if isinstance(high, str):
3914 offset, length = _coerce_exprs(low, a, s.ctx)
3917 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
3918 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
"First and second arguments must be non negative integers")
3919 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
3922 def _check_bv_args(a, b):
3924 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
3927 """Create the Z3 expression (unsigned) `other <= self`.
3929 Use the operator <= for signed less than or equal to.
3931 >>> x, y = BitVecs('x y', 32)
3934 >>> (x <= y).sexpr()
3936 >>> ULE(x, y).sexpr()
3939 _check_bv_args(a, b)
3940 a, b = _coerce_exprs(a, b)
3944 """Create the Z3 expression (unsigned) `other < self`.
3946 Use the operator < for signed less than.
3948 >>> x, y = BitVecs('x y', 32)
3953 >>> ULT(x, y).sexpr()
3956 _check_bv_args(a, b)
3957 a, b = _coerce_exprs(a, b)
3961 """Create the Z3 expression (unsigned) `other >= self`.
3963 Use the operator >= for signed greater than or equal to.
3965 >>> x, y = BitVecs('x y', 32)
3968 >>> (x >= y).sexpr()
3970 >>> UGE(x, y).sexpr()
3973 _check_bv_args(a, b)
3974 a, b = _coerce_exprs(a, b)
3978 """Create the Z3 expression (unsigned) `other > self`.
3980 Use the operator > for signed greater than.
3982 >>> x, y = BitVecs('x y', 32)
3987 >>> UGT(x, y).sexpr()
3990 _check_bv_args(a, b)
3991 a, b = _coerce_exprs(a, b)
3995 """Create the Z3 expression (unsigned) division `self / other`.
3997 Use the operator / for signed division.
3999 >>> x = BitVec('x', 32)
4000 >>> y = BitVec('y', 32)
4003 >>> UDiv(x, y).sort()
4007 >>> UDiv(x, y).sexpr()
4010 _check_bv_args(a, b)
4011 a, b = _coerce_exprs(a, b)
4015 """Create the Z3 expression (unsigned) remainder `self % other`.
4017 Use the operator % for signed modulus, and SRem() for signed remainder.
4019 >>> x = BitVec('x', 32)
4020 >>> y = BitVec('y', 32)
4023 >>> URem(x, y).sort()
4027 >>> URem(x, y).sexpr()
4030 _check_bv_args(a, b)
4031 a, b = _coerce_exprs(a, b)
4035 """Create the Z3 expression signed remainder.
4037 Use the operator % for signed modulus, and URem() for unsigned remainder.
4039 >>> x = BitVec('x', 32)
4040 >>> y = BitVec('y', 32)
4043 >>> SRem(x, y).sort()
4047 >>> SRem(x, y).sexpr()
4050 _check_bv_args(a, b)
4051 a, b = _coerce_exprs(a, b)
4055 """Create the Z3 expression logical right shift.
4057 Use the operator >> for the arithmetical right shift.
4059 >>> x, y = BitVecs('x y', 32)
4062 >>> (x >> y).sexpr()
4064 >>> LShR(x, y).sexpr()
4068 >>> BitVecVal(4, 3).as_signed_long()
4070 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
4072 >>> simplify(BitVecVal(4, 3) >> 1)
4074 >>> simplify(LShR(BitVecVal(4, 3), 1))
4076 >>> simplify(BitVecVal(2, 3) >> 1)
4078 >>> simplify(LShR(BitVecVal(2, 3), 1))
4081 _check_bv_args(a, b)
4082 a, b = _coerce_exprs(a, b)
4086 """Return an expression representing `a` rotated to the left `b` times.
4088 >>> a, b = BitVecs('a b', 16)
4089 >>> RotateLeft(a, b)
4091 >>> simplify(RotateLeft(a, 0))
4093 >>> simplify(RotateLeft(a, 16))
4096 _check_bv_args(a, b)
4097 a, b = _coerce_exprs(a, b)
4101 """Return an expression representing `a` rotated to the right `b` times.
4103 >>> a, b = BitVecs('a b', 16)
4104 >>> RotateRight(a, b)
4106 >>> simplify(RotateRight(a, 0))
4108 >>> simplify(RotateRight(a, 16))
4111 _check_bv_args(a, b)
4112 a, b = _coerce_exprs(a, b)
4116 """Return a bit-vector expression with `n` extra sign-bits.
4118 >>> x = BitVec('x', 16)
4119 >>> n = SignExt(8, x)
4126 >>> v0 = BitVecVal(2, 2)
4131 >>> v = simplify(SignExt(6, v0))
4136 >>> print("%.x" % v.as_long())
4140 _z3_assert(_is_int(n),
"First argument must be an integer")
4141 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4145 """Return a bit-vector expression with `n` extra zero-bits.
4147 >>> x = BitVec('x', 16)
4148 >>> n = ZeroExt(8, x)
4155 >>> v0 = BitVecVal(2, 2)
4160 >>> v = simplify(ZeroExt(6, v0))
4167 _z3_assert(_is_int(n),
"First argument must be an integer")
4168 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4172 """Return an expression representing `n` copies of `a`.
4174 >>> x = BitVec('x', 8)
4175 >>> n = RepeatBitVec(4, x)
4180 >>> v0 = BitVecVal(10, 4)
4181 >>> print("%.x" % v0.as_long())
4183 >>> v = simplify(RepeatBitVec(4, v0))
4186 >>> print("%.x" % v.as_long())
4190 _z3_assert(_is_int(n),
"First argument must be an integer")
4191 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4195 """Return the reduction-and expression of `a`."""
4197 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4201 """Return the reduction-or expression of `a`."""
4203 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4207 """A predicate the determines that bit-vector addition does not overflow"""
4208 _check_bv_args(a, b)
4209 a, b = _coerce_exprs(a, b)
4213 """A predicate the determines that signed bit-vector addition does not underflow"""
4214 _check_bv_args(a, b)
4215 a, b = _coerce_exprs(a, b)
4219 """A predicate the determines that bit-vector subtraction does not overflow"""
4220 _check_bv_args(a, b)
4221 a, b = _coerce_exprs(a, b)
4226 """A predicate the determines that bit-vector subtraction does not underflow"""
4227 _check_bv_args(a, b)
4228 a, b = _coerce_exprs(a, b)
4232 """A predicate the determines that bit-vector signed division does not overflow"""
4233 _check_bv_args(a, b)
4234 a, b = _coerce_exprs(a, b)
4238 """A predicate the determines that bit-vector unary negation does not overflow"""
4240 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4244 """A predicate the determines that bit-vector multiplication does not overflow"""
4245 _check_bv_args(a, b)
4246 a, b = _coerce_exprs(a, b)
4251 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4252 _check_bv_args(a, b)
4253 a, b = _coerce_exprs(a, b)
4268 """Return the domain of the array sort `self`.
4270 >>> A = ArraySort(IntSort(), BoolSort())
4277 """Return the range of the array sort `self`.
4279 >>> A = ArraySort(IntSort(), BoolSort())
4286 """Array expressions. """
4289 """Return the array sort of the array expression `self`.
4291 >>> a = Array('a', IntSort(), BoolSort())
4298 """Shorthand for `self.sort().domain()`.
4300 >>> a = Array('a', IntSort(), BoolSort())
4307 """Shorthand for `self.sort().range()`.
4309 >>> a = Array('a', IntSort(), BoolSort())
4316 """Return the Z3 expression `self[arg]`.
4318 >>> a = Array('a', IntSort(), BoolSort())
4325 arg = self.
domain().cast(arg)
4336 """Return `True` if `a` is a Z3 array expression.
4338 >>> a = Array('a', IntSort(), IntSort())
4341 >>> is_array(Store(a, 0, 1))
4346 return isinstance(a, ArrayRef)
4349 """Return `True` if `a` is a Z3 constant array.
4351 >>> a = K(IntSort(), 10)
4352 >>> is_const_array(a)
4354 >>> a = Array('a', IntSort(), IntSort())
4355 >>> is_const_array(a)
4361 """Return `True` if `a` is a Z3 constant array.
4363 >>> a = K(IntSort(), 10)
4366 >>> a = Array('a', IntSort(), IntSort())
4373 """Return `True` if `a` is a Z3 map array expression.
4375 >>> f = Function('f', IntSort(), IntSort())
4376 >>> b = Array('b', IntSort(), IntSort())
4388 """Return `True` if `a` is a Z3 default array expression.
4389 >>> d = Default(K(IntSort(), 10))
4393 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4396 """Return the function declaration associated with a Z3 map array expression.
4398 >>> f = Function('f', IntSort(), IntSort())
4399 >>> b = Array('b', IntSort(), IntSort())
4401 >>> eq(f, get_map_func(a))
4405 >>> get_map_func(a)(0)
4409 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4413 """Return the Z3 array sort with the given domain and range sorts.
4415 >>> A = ArraySort(IntSort(), BoolSort())
4422 >>> AA = ArraySort(IntSort(), A)
4424 Array(Int, Array(Int, Bool))
4426 sig = _get_args(sig)
4428 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4429 arity = len(sig) - 1
4434 _z3_assert(
is_sort(s),
"Z3 sort expected")
4435 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4439 dom = (Sort * arity)()
4440 for i
in range(arity):
4445 """Return an array constant named `name` with the given domain and range sorts.
4447 >>> a = Array('a', IntSort(), IntSort())
4458 """Return a Z3 store array expression.
4460 >>> a = Array('a', IntSort(), IntSort())
4461 >>> i, v = Ints('i v')
4462 >>> s = Update(a, i, v)
4465 >>> prove(s[i] == v)
4468 >>> prove(Implies(i != j, s[j] == a[j]))
4472 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4473 i = a.sort().domain().cast(i)
4474 v = a.sort().
range().cast(v)
4476 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4479 """ Return a default value for array expression.
4480 >>> b = K(IntSort(), 1)
4481 >>> prove(Default(b) == 1)
4485 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4490 """Return a Z3 store array expression.
4492 >>> a = Array('a', IntSort(), IntSort())
4493 >>> i, v = Ints('i v')
4494 >>> s = Store(a, i, v)
4497 >>> prove(s[i] == v)
4500 >>> prove(Implies(i != j, s[j] == a[j]))
4506 """Return a Z3 select array expression.
4508 >>> a = Array('a', IntSort(), IntSort())
4512 >>> eq(Select(a, i), a[i])
4516 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4521 """Return a Z3 map array expression.
4523 >>> f = Function('f', IntSort(), IntSort(), IntSort())
4524 >>> a1 = Array('a1', IntSort(), IntSort())
4525 >>> a2 = Array('a2', IntSort(), IntSort())
4526 >>> b = Map(f, a1, a2)
4529 >>> prove(b[0] == f(a1[0], a2[0]))
4532 args = _get_args(args)
4534 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4535 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4536 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4537 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4538 _args, sz = _to_ast_array(args)
4543 """Return a Z3 constant array expression.
4545 >>> a = K(IntSort(), 10)
4557 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4560 v = _py2expr(v, ctx)
4564 """Return extensionality index for one-dimensional arrays.
4565 >> a, b = Consts('a b', SetSort(IntSort()))
4572 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4576 k = _py2expr(k, ctx)
4580 """Return `True` if `a` is a Z3 array select application.
4582 >>> a = Array('a', IntSort(), IntSort())
4592 """Return `True` if `a` is a Z3 array store application.
4594 >>> a = Array('a', IntSort(), IntSort())
4597 >>> is_store(Store(a, 0, 1))
4610 """ Create a set sort over element sort s"""
4614 """Create the empty set
4615 >>> EmptySet(IntSort())
4622 """Create the full set
4623 >>> FullSet(IntSort())
4630 """ Take the union of sets
4631 >>> a = Const('a', SetSort(IntSort()))
4632 >>> b = Const('b', SetSort(IntSort()))
4636 args = _get_args(args)
4637 ctx = _ctx_from_ast_arg_list(args)
4638 _args, sz = _to_ast_array(args)
4642 """ Take the union of sets
4643 >>> a = Const('a', SetSort(IntSort()))
4644 >>> b = Const('b', SetSort(IntSort()))
4645 >>> SetIntersect(a, b)
4648 args = _get_args(args)
4649 ctx = _ctx_from_ast_arg_list(args)
4650 _args, sz = _to_ast_array(args)
4654 """ Add element e to set s
4655 >>> a = Const('a', SetSort(IntSort()))
4659 ctx = _ctx_from_ast_arg_list([s,e])
4660 e = _py2expr(e, ctx)
4664 """ Remove element e to set s
4665 >>> a = Const('a', SetSort(IntSort()))
4669 ctx = _ctx_from_ast_arg_list([s,e])
4670 e = _py2expr(e, ctx)
4674 """ The complement of set s
4675 >>> a = Const('a', SetSort(IntSort()))
4676 >>> SetComplement(a)
4683 """ The set difference of a and b
4684 >>> a = Const('a', SetSort(IntSort()))
4685 >>> b = Const('b', SetSort(IntSort()))
4686 >>> SetDifference(a, b)
4689 ctx = _ctx_from_ast_arg_list([a, b])
4693 """ Check if e is a member of set s
4694 >>> a = Const('a', SetSort(IntSort()))
4698 ctx = _ctx_from_ast_arg_list([s,e])
4699 e = _py2expr(e, ctx)
4703 """ Check if a is a subset of b
4704 >>> a = Const('a', SetSort(IntSort()))
4705 >>> b = Const('b', SetSort(IntSort()))
4709 ctx = _ctx_from_ast_arg_list([a, b])
4719 def _valid_accessor(acc):
4720 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4721 return isinstance(acc, tuple)
and len(acc) == 2
and isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4724 """Helper class for declaring Z3 datatypes.
4726 >>> List = Datatype('List')
4727 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4728 >>> List.declare('nil')
4729 >>> List = List.create()
4730 >>> # List is now a Z3 declaration
4733 >>> List.cons(10, List.nil)
4735 >>> List.cons(10, List.nil).sort()
4737 >>> cons = List.cons
4741 >>> n = cons(1, cons(0, nil))
4743 cons(1, cons(0, nil))
4744 >>> simplify(cdr(n))
4746 >>> simplify(car(n))
4761 _z3_assert(isinstance(name, str),
"String expected")
4762 _z3_assert(isinstance(rec_name, str),
"String expected")
4763 _z3_assert(all([_valid_accessor(a)
for a
in args]),
"Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
4767 """Declare constructor named `name` with the given accessors `args`.
4768 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared.
4770 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
4771 declares the constructor named `cons` that builds a new List using an integer and a List.
4772 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
4773 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
4774 the actual datatype in Z3.
4776 >>> List = Datatype('List')
4777 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4778 >>> List.declare('nil')
4779 >>> List = List.create()
4782 _z3_assert(isinstance(name, str),
"String expected")
4783 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4790 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
4792 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
4794 >>> List = Datatype('List')
4795 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4796 >>> List.declare('nil')
4797 >>> List = List.create()
4800 >>> List.cons(10, List.nil)
4806 """Auxiliary object used to create Z3 datatypes."""
4811 if self.
ctx.ref()
is not None:
4815 """Auxiliary object used to create Z3 datatypes."""
4820 if self.
ctx.ref()
is not None:
4824 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
4826 In the following example we define a Tree-List using two mutually recursive datatypes.
4828 >>> TreeList = Datatype('TreeList')
4829 >>> Tree = Datatype('Tree')
4830 >>> # Tree has two constructors: leaf and node
4831 >>> Tree.declare('leaf', ('val', IntSort()))
4832 >>> # a node contains a list of trees
4833 >>> Tree.declare('node', ('children', TreeList))
4834 >>> TreeList.declare('nil')
4835 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
4836 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
4837 >>> Tree.val(Tree.leaf(10))
4839 >>> simplify(Tree.val(Tree.leaf(10)))
4841 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
4843 node(cons(leaf(10), cons(leaf(20), nil)))
4844 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
4845 >>> simplify(n2 == n1)
4847 >>> simplify(TreeList.car(Tree.children(n2)) == n1)
4852 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
4853 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
4854 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
4855 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
4858 names = (Symbol * num)()
4859 out = (Sort * num)()
4860 clists = (ConstructorList * num)()
4862 for i
in range(num):
4865 num_cs = len(d.constructors)
4866 cs = (Constructor * num_cs)()
4867 for j
in range(num_cs):
4868 c = d.constructors[j]
4873 fnames = (Symbol * num_fs)()
4874 sorts = (Sort * num_fs)()
4875 refs = (ctypes.c_uint * num_fs)()
4876 for k
in range(num_fs):
4880 if isinstance(ftype, Datatype):
4882 _z3_assert(ds.count(ftype) == 1,
"One and only one occurrence of each datatype is expected")
4884 refs[k] = ds.index(ftype)
4887 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
4888 sorts[k] = ftype.ast
4897 for i
in range(num):
4899 num_cs = dref.num_constructors()
4900 for j
in range(num_cs):
4901 cref = dref.constructor(j)
4902 cref_name = cref.name()
4903 cref_arity = cref.arity()
4904 if cref.arity() == 0:
4906 setattr(dref, cref_name, cref)
4907 rref = dref.recognizer(j)
4908 setattr(dref,
"is_" + cref_name, rref)
4909 for k
in range(cref_arity):
4910 aref = dref.accessor(j, k)
4911 setattr(dref, aref.name(), aref)
4913 return tuple(result)
4916 """Datatype sorts."""
4918 """Return the number of constructors in the given Z3 datatype.
4920 >>> List = Datatype('List')
4921 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4922 >>> List.declare('nil')
4923 >>> List = List.create()
4924 >>> # List is now a Z3 declaration
4925 >>> List.num_constructors()
4931 """Return a constructor of the datatype `self`.
4933 >>> List = Datatype('List')
4934 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4935 >>> List.declare('nil')
4936 >>> List = List.create()
4937 >>> # List is now a Z3 declaration
4938 >>> List.num_constructors()
4940 >>> List.constructor(0)
4942 >>> List.constructor(1)
4950 """In Z3, each constructor has an associated recognizer predicate.
4952 If the constructor is named `name`, then the recognizer `is_name`.
4954 >>> List = Datatype('List')
4955 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4956 >>> List.declare('nil')
4957 >>> List = List.create()
4958 >>> # List is now a Z3 declaration
4959 >>> List.num_constructors()
4961 >>> List.recognizer(0)
4963 >>> List.recognizer(1)
4965 >>> simplify(List.is_nil(List.cons(10, List.nil)))
4967 >>> simplify(List.is_cons(List.cons(10, List.nil)))
4969 >>> l = Const('l', List)
4970 >>> simplify(List.is_cons(l))
4978 """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor.
4980 >>> List = Datatype('List')
4981 >>> List.declare('cons', ('car', IntSort()), ('cdr', List))
4982 >>> List.declare('nil')
4983 >>> List = List.create()
4984 >>> List.num_constructors()
4986 >>> List.constructor(0)
4988 >>> num_accs = List.constructor(0).arity()
4991 >>> List.accessor(0, 0)
4993 >>> List.accessor(0, 1)
4995 >>> List.constructor(1)
4997 >>> num_accs = List.constructor(1).arity()
5003 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
5007 """Datatype expressions."""
5009 """Return the datatype sort of the datatype expression `self`."""
5013 """Create a named tuple sort base on a set of underlying sorts
5015 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()])
5018 projects = [ (
'project%d' % i, sorts[i])
for i
in range(len(sorts)) ]
5019 tuple.declare(name, *projects)
5020 tuple = tuple.create()
5021 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5024 """Create a named tagged union sort base on a set of underlying sorts
5026 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()])
5029 for i
in range(len(sorts)):
5030 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5032 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5036 """Return a new enumeration sort named `name` containing the given values.
5038 The result is a pair (sort, list of constants).
5040 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
5043 _z3_assert(isinstance(name, str),
"Name must be a string")
5044 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5045 _z3_assert(len(values) > 0,
"At least one value expected")
5048 _val_names = (Symbol * num)()
5049 for i
in range(num):
5051 _values = (FuncDecl * num)()
5052 _testers = (FuncDecl * num)()
5056 for i
in range(num):
5058 V = [a()
for a
in V]
5068 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5070 Consider using the function `args2params` to create instances of this object.
5084 if self.
ctx.ref()
is not None:
5088 """Set parameter name with value val."""
5090 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5092 if isinstance(val, bool):
5096 elif isinstance(val, float):
5098 elif isinstance(val, str):
5102 _z3_assert(
False,
"invalid parameter value")
5108 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5112 """Convert python arguments into a Z3_params object.
5113 A ':' is added to the keywords, and '_' is replaced with '-'
5115 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
5116 (params model true relevancy 2 elim_and true)
5119 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5134 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5137 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5143 return ParamsDescrsRef(self.
descr, self.
ctx)
5146 if self.
ctx.ref()
is not None:
5150 """Return the size of in the parameter description `self`.
5155 """Return the size of in the parameter description `self`.
5160 """Return the i-th parameter name in the parameter description `self`.
5165 """Return the kind of the parameter named `n`.
5170 """Return the documentation string of the parameter named `n`.
5190 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5192 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5193 A goal has a solution if one of its subgoals has a solution.
5194 A goal is unsatisfiable if all subgoals are unsatisfiable.
5197 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5199 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5202 if self.
goal is None:
5207 return Goal(
False,
False,
False, self.
ctx, self.
goal)
5210 if self.
goal is not None and self.
ctx.ref()
is not None:
5214 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`.
5216 >>> x, y = Ints('x y')
5218 >>> g.add(x == 0, y >= x + 1)
5221 >>> r = Then('simplify', 'solve-eqs')(g)
5222 >>> # r has 1 subgoal
5231 """Return `True` if `self` contains the `False` constraints.
5233 >>> x, y = Ints('x y')
5235 >>> g.inconsistent()
5237 >>> g.add(x == 0, x == 1)
5240 >>> g.inconsistent()
5242 >>> g2 = Tactic('propagate-values')(g)[0]
5243 >>> g2.inconsistent()
5249 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5252 >>> g.prec() == Z3_GOAL_PRECISE
5254 >>> x, y = Ints('x y')
5255 >>> g.add(x == y + 1)
5256 >>> g.prec() == Z3_GOAL_PRECISE
5258 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10)
5261 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5262 >>> g2.prec() == Z3_GOAL_PRECISE
5264 >>> g2.prec() == Z3_GOAL_UNDER
5270 """Alias for `prec()`.
5273 >>> g.precision() == Z3_GOAL_PRECISE
5279 """Return the number of constraints in the goal `self`.
5284 >>> x, y = Ints('x y')
5285 >>> g.add(x == 0, y > x)
5292 """Return the number of constraints in the goal `self`.
5297 >>> x, y = Ints('x y')
5298 >>> g.add(x == 0, y > x)
5305 """Return a constraint in the goal `self`.
5308 >>> x, y = Ints('x y')
5309 >>> g.add(x == 0, y > x)
5318 """Return a constraint in the goal `self`.
5321 >>> x, y = Ints('x y')
5322 >>> g.add(x == 0, y > x)
5328 if arg >= len(self):
5330 return self.
get(arg)
5333 """Assert constraints into the goal.
5337 >>> g.assert_exprs(x > 0, x < 2)
5341 args = _get_args(args)
5352 >>> g.append(x > 0, x < 2)
5363 >>> g.insert(x > 0, x < 2)
5374 >>> g.add(x > 0, x < 2)
5381 """Retrieve model from a satisfiable goal
5382 >>> a, b = Ints('a b')
5384 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
5385 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
5388 [Or(b == 0, b == 1), Not(0 <= b)]
5390 [Or(b == 0, b == 1), Not(1 <= b)]
5391 >>> # Remark: the subgoal r[0] is unsatisfiable
5392 >>> # Creating a solver for solving the second subgoal
5399 >>> # Model s.model() does not assign a value to `a`
5400 >>> # It is a model for subgoal `r[1]`, but not for goal `g`
5401 >>> # The method convert_model creates a model for `g` from a model for `r[1]`.
5402 >>> r[1].convert_model(s.model())
5406 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5410 return obj_to_string(self)
5413 """Return a textual representation of the s-expression representing the goal."""
5417 """Return a textual representation of the goal in DIMACS format."""
5421 """Copy goal `self` to context `target`.
5429 >>> g2 = g.translate(c2)
5432 >>> g.ctx == main_ctx()
5436 >>> g2.ctx == main_ctx()
5440 _z3_assert(isinstance(target, Context),
"target must be a context")
5450 """Return a new simplified goal.
5452 This method is essentially invoking the simplify tactic.
5456 >>> g.add(x + 1 >= 2)
5459 >>> g2 = g.simplify()
5462 >>> # g was not modified
5467 return t.apply(self, *arguments, **keywords)[0]
5470 """Return goal `self` as a single Z3 expression.
5497 """A collection (vector) of ASTs."""
5506 assert ctx
is not None
5514 if self.
vector is not None and self.
ctx.ref()
is not None:
5518 """Return the size of the vector `self`.
5523 >>> A.push(Int('x'))
5524 >>> A.push(Int('x'))
5531 """Return the AST at position `i`.
5534 >>> A.push(Int('x') + 1)
5535 >>> A.push(Int('y'))
5542 if isinstance(i, int):
5550 elif isinstance(i, slice):
5555 """Update AST at position `i`.
5558 >>> A.push(Int('x') + 1)
5559 >>> A.push(Int('y'))
5571 """Add `v` in the end of the vector.
5576 >>> A.push(Int('x'))
5583 """Resize the vector to `sz` elements.
5589 >>> for i in range(10): A[i] = Int('x')
5596 """Return `True` if the vector contains `item`.
5619 """Copy vector `self` to context `other_ctx`.
5625 >>> B = A.translate(c2)
5638 return obj_to_string(self)
5641 """Return a textual representation of the s-expression representing the vector."""
5650 """A mapping from ASTs to ASTs."""
5659 assert ctx
is not None
5667 if self.
map is not None and self.
ctx.ref()
is not None:
5671 """Return the size of the map.
5677 >>> M[x] = IntVal(1)
5684 """Return `True` if the map contains key `key`.
5697 """Retrieve the value associated with key `key`.
5708 """Add/Update key `k` with value `v`.
5717 >>> M[x] = IntVal(1)
5727 """Remove the entry associated with key `k`.
5741 """Remove all entries from the map.
5746 >>> M[x+x] = IntVal(1)
5756 """Return an AstVector containing all keys in the map.
5761 >>> M[x+x] = IntVal(1)
5774 """Store the value of the interpretation of a function in a particular point."""
5785 if self.
ctx.ref()
is not None:
5789 """Return the number of arguments in the given entry.
5791 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5793 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5798 >>> f_i.num_entries()
5800 >>> e = f_i.entry(0)
5807 """Return the value of argument `idx`.
5809 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5811 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5816 >>> f_i.num_entries()
5818 >>> e = f_i.entry(0)
5829 ... except IndexError:
5830 ... print("index error")
5838 """Return the value of the function at point `self`.
5840 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5842 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5847 >>> f_i.num_entries()
5849 >>> e = f_i.entry(0)
5860 """Return entry `self` as a Python list.
5861 >>> f = Function('f', IntSort(), IntSort(), IntSort())
5863 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
5868 >>> f_i.num_entries()
5870 >>> e = f_i.entry(0)
5875 args.append(self.
value())
5882 """Stores the interpretation of a function in a Z3 model."""
5887 if self.
f is not None:
5894 if self.
f is not None and self.
ctx.ref()
is not None:
5899 Return the `else` value for a function interpretation.
5900 Return None if Z3 did not specify the `else` value for
5903 >>> f = Function('f', IntSort(), IntSort())
5905 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5911 >>> m[f].else_value()
5916 return _to_expr_ref(r, self.
ctx)
5921 """Return the number of entries/points in the function interpretation `self`.
5923 >>> f = Function('f', IntSort(), IntSort())
5925 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5931 >>> m[f].num_entries()
5937 """Return the number of arguments for each entry in the function interpretation `self`.
5939 >>> f = Function('f', IntSort(), IntSort())
5941 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5951 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
5953 >>> f = Function('f', IntSort(), IntSort())
5955 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5961 >>> m[f].num_entries()
5971 """Copy model 'self' to context 'other_ctx'.
5982 """Return the function interpretation as a Python list.
5983 >>> f = Function('f', IntSort(), IntSort())
5985 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0)
5999 return obj_to_string(self)
6002 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6005 assert ctx
is not None
6011 if self.
ctx.ref()
is not None:
6015 return obj_to_string(self)
6018 """Return a textual representation of the s-expression representing the model."""
6021 def eval(self, t, model_completion=False):
6022 """Evaluate the expression `t` in the model `self`. If `model_completion` is enabled, then a default interpretation is automatically added for symbols that do not have an interpretation in the model `self`.
6026 >>> s.add(x > 0, x < 2)
6039 >>> m.eval(y, model_completion=True)
6041 >>> # Now, m contains an interpretation for y
6047 return _to_expr_ref(r[0], self.
ctx)
6048 raise Z3Exception(
"failed to evaluate expression in the model")
6051 """Alias for `eval`.
6055 >>> s.add(x > 0, x < 2)
6059 >>> m.evaluate(x + 1)
6061 >>> m.evaluate(x == 1)
6064 >>> m.evaluate(y + x)
6068 >>> m.evaluate(y, model_completion=True)
6070 >>> # Now, m contains an interpretation for y
6071 >>> m.evaluate(y + x)
6074 return self.
eval(t, model_completion)
6077 """Return the number of constant and function declarations in the model `self`.
6079 >>> f = Function('f', IntSort(), IntSort())
6082 >>> s.add(x > 0, f(x) != x)
6092 """Return the interpretation for a given declaration or constant.
6094 >>> f = Function('f', IntSort(), IntSort())
6097 >>> s.add(x > 0, x < 2, f(x) == 0)
6107 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6111 if decl.arity() == 0:
6113 if _r.value
is None:
6115 r = _to_expr_ref(_r, self.
ctx)
6126 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6128 >>> A = DeclareSort('A')
6129 >>> a, b = Consts('a b', A)
6141 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6143 >>> A = DeclareSort('A')
6144 >>> B = DeclareSort('B')
6145 >>> a1, a2 = Consts('a1 a2', A)
6146 >>> b1, b2 = Consts('b1 b2', B)
6148 >>> s.add(a1 != a2, b1 != b2)
6164 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6166 >>> A = DeclareSort('A')
6167 >>> B = DeclareSort('B')
6168 >>> a1, a2 = Consts('a1 a2', A)
6169 >>> b1, b2 = Consts('b1 b2', B)
6171 >>> s.add(a1 != a2, b1 != b2)
6181 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6183 >>> A = DeclareSort('A')
6184 >>> a, b = Consts('a b', A)
6190 >>> m.get_universe(A)
6194 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6201 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpretation is returned.
6203 The elements can be retrieved using position or the actual declaration.
6205 >>> f = Function('f', IntSort(), IntSort())
6208 >>> s.add(x > 0, x < 2, f(x) == 0)
6222 >>> for d in m: print("%s -> %s" % (d, m[d]))
6227 if idx >= len(self):
6230 if (idx < num_consts):
6234 if isinstance(idx, FuncDeclRef):
6238 if isinstance(idx, SortRef):
6241 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6245 """Return a list with all symbols that have an interpretation in the model `self`.
6246 >>> f = Function('f', IntSort(), IntSort())
6249 >>> s.add(x > 0, x < 2, f(x) == 0)
6264 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6267 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6269 return Model(model, target)
6282 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6283 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6286 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6288 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6297 """Statistics for `Solver.check()`."""
6308 if self.
ctx.ref()
is not None:
6315 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6318 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6321 out.write(u(
'<tr>'))
6323 out.write(u(
'<td>%s</td><td>%s</td></tr>' % (k, v)))
6324 out.write(u(
'</table>'))
6325 return out.getvalue()
6330 """Return the number of statistical counters.
6333 >>> s = Then('simplify', 'nlsat').solver()
6337 >>> st = s.statistics()
6344 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6347 >>> s = Then('simplify', 'nlsat').solver()
6351 >>> st = s.statistics()
6355 ('nlsat propagations', 2)
6359 if idx >= len(self):
6368 """Return the list of statistical counters.
6371 >>> s = Then('simplify', 'nlsat').solver()
6375 >>> st = s.statistics()
6380 """Return the value of a particular statistical counter.
6383 >>> s = Then('simplify', 'nlsat').solver()
6387 >>> st = s.statistics()
6388 >>> st.get_key_value('nlsat propagations')
6391 for idx
in range(len(self)):
6397 raise Z3Exception(
"unknown key")
6400 """Access the value of statistical using attributes.
6402 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6403 we should use '_' (e.g., 'nlsat_propagations').
6406 >>> s = Then('simplify', 'nlsat').solver()
6410 >>> st = s.statistics()
6411 >>> st.nlsat_propagations
6416 key = name.replace(
'_',
' ')
6420 raise AttributeError
6428 """Represents the result of a satisfiability check: sat, unsat, unknown.
6434 >>> isinstance(r, CheckSatResult)
6445 return isinstance(other, CheckSatResult)
and self.
r == other.r
6448 return not self.
__eq__(other)
6452 if self.
r == Z3_L_TRUE:
6454 elif self.
r == Z3_L_FALSE:
6455 return "<b>unsat</b>"
6457 return "<b>unknown</b>"
6459 if self.
r == Z3_L_TRUE:
6461 elif self.
r == Z3_L_FALSE:
6466 def _repr_html_(self):
6467 in_html = in_html_mode()
6470 set_html_mode(in_html)
6478 """Solver API provides methods for implementing the main SMT 2.0 commands: push, pop, check, get-model, etc."""
6480 def __init__(self, solver=None, ctx=None, logFile=None):
6481 assert solver
is None or ctx
is not None
6490 if logFile
is not None:
6491 self.
set(
"smtlib2_log", logFile)
6494 if self.
solver is not None and self.
ctx.ref()
is not None:
6498 """Set a configuration option. The method `help()` return a string containing all available options.
6501 >>> # The option MBQI can be set using three different approaches.
6502 >>> s.set(mbqi=True)
6503 >>> s.set('MBQI', True)
6504 >>> s.set(':mbqi', True)
6510 """Create a backtracking point.
6532 """Backtrack \c num backtracking points.
6554 """Return the current number of backtracking points.
6572 """Remove all asserted constraints and backtracking points created using `push()`.
6586 """Assert constraints into the solver.
6590 >>> s.assert_exprs(x > 0, x < 2)
6594 args = _get_args(args)
6597 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6605 """Assert constraints into the solver.
6609 >>> s.add(x > 0, x < 2)
6620 """Assert constraints into the solver.
6624 >>> s.append(x > 0, x < 2)
6631 """Assert constraints into the solver.
6635 >>> s.insert(x > 0, x < 2)
6642 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6644 If `p` is a string, it will be automatically converted into a Boolean constant.
6649 >>> s.set(unsat_core=True)
6650 >>> s.assert_and_track(x > 0, 'p1')
6651 >>> s.assert_and_track(x != 1, 'p2')
6652 >>> s.assert_and_track(x < 0, p3)
6653 >>> print(s.check())
6655 >>> c = s.unsat_core()
6665 if isinstance(p, str):
6667 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6668 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6672 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
6678 >>> s.add(x > 0, x < 2)
6681 >>> s.model().eval(x)
6687 >>> s.add(2**x == 4)
6692 assumptions = _get_args(assumptions)
6693 num = len(assumptions)
6694 _assumptions = (Ast * num)()
6695 for i
in range(num):
6696 _assumptions[i] = s.cast(assumptions[i]).as_ast()
6701 """Return a model for the last `check()`.
6703 This function raises an exception if
6704 a model is not available (e.g., last `check()` returned unsat).
6708 >>> s.add(a + 2 == 0)
6717 raise Z3Exception(
"model is not available")
6720 """Import model converter from other into the current solver"""
6724 """Return a subset (as an AST vector) of the assumptions provided to the last check().
6726 These are the assumptions Z3 used in the unsatisfiability proof.
6727 Assumptions are available in Z3. They are used to extract unsatisfiable cores.
6728 They may be also used to "retract" assumptions. Note that, assumptions are not really
6729 "soft constraints", but they can be used to implement them.
6731 >>> p1, p2, p3 = Bools('p1 p2 p3')
6732 >>> x, y = Ints('x y')
6734 >>> s.add(Implies(p1, x > 0))
6735 >>> s.add(Implies(p2, y > x))
6736 >>> s.add(Implies(p2, y < 1))
6737 >>> s.add(Implies(p3, y > -3))
6738 >>> s.check(p1, p2, p3)
6740 >>> core = s.unsat_core()
6749 >>> # "Retracting" p2
6756 """Determine fixed values for the variables based on the solver state and assumptions.
6758 >>> a, b, c, d = Bools('a b c d')
6759 >>> s.add(Implies(a,b), Implies(b, c))
6760 >>> s.consequences([a],[b,c,d])
6761 (sat, [Implies(a, b), Implies(a, c)])
6762 >>> s.consequences([Not(c),d],[a,b,c,d])
6763 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))])
6765 if isinstance(assumptions, list):
6767 for a
in assumptions:
6770 if isinstance(variables, list):
6775 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
6776 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
6779 sz = len(consequences)
6780 consequences = [ consequences[i]
for i
in range(sz) ]
6784 """Parse assertions from a file"""
6788 """Parse assertions from a string"""
6793 The method takes an optional set of variables that restrict which
6794 variables may be used as a starting point for cubing.
6795 If vars is not None, then the first case split is based on a variable in
6799 if vars
is not None:
6806 if (len(r) == 1
and is_false(r[0])):
6813 """Access the set of variables that were touched by the most recently generated cube.
6814 This set of variables can be used as a starting point for additional cubes.
6815 The idea is that variables that appear in clauses that are reduced by the most recent
6816 cube are likely more useful to cube on."""
6820 """Return a proof for the last `check()`. Proof construction must be enabled."""
6824 """Return an AST vector containing all added constraints.
6838 """Return an AST vector containing all currently inferred units.
6843 """Return an AST vector containing all atomic formulas in solver state that are not units.
6848 """Return trail and decision levels of the solver state after a check() call.
6850 trail = self.
trail()
6851 levels = (ctypes.c_uint * len(trail))()
6853 return trail, levels
6856 """Return trail of the solver state after a check() call.
6861 """Return value of term in solver, if any is given.
6866 """Return lower bound known to solver based on the last call.
6871 """Return upper bound known to solver based on the last call.
6876 """Return statistics for the last `check()`.
6878 >>> s = SimpleSolver()
6883 >>> st = s.statistics()
6884 >>> st.get_key_value('final checks')
6894 """Return a string describing why the last `check()` returned `unknown`.
6897 >>> s = SimpleSolver()
6898 >>> s.add(2**x == 4)
6901 >>> s.reason_unknown()
6902 '(incomplete (theory arithmetic))'
6907 """Display a string describing all available options."""
6911 """Return the parameter description set."""
6915 """Return a formatted string with all added constraints."""
6916 return obj_to_string(self)
6919 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6923 >>> s1 = Solver(ctx=c1)
6924 >>> s2 = s1.translate(c2)
6927 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6929 return Solver(solver, target)
6938 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
6949 """Return a textual representation of the solver in DIMACS format."""
6953 """return SMTLIB2 formatted benchmark for solver's assertions"""
6960 for i
in range(sz1):
6961 v[i] = es[i].as_ast()
6963 e = es[sz1].as_ast()
6969 """Create a solver customized for the given logic.
6971 The parameter `logic` is a string. It should be contains
6972 the name of a SMT-LIB logic.
6973 See http://www.smtlib.org/ for the name of all available logics.
6975 >>> s = SolverFor("QF_LIA")
6989 """Return a simple general purpose solver with limited amount of preprocessing.
6991 >>> s = SimpleSolver()
7007 """Fixedpoint API provides methods for solving with recursive predicates"""
7010 assert fixedpoint
is None or ctx
is not None
7013 if fixedpoint
is None:
7024 if self.
fixedpoint is not None and self.
ctx.ref()
is not None:
7028 """Set a configuration option. The method `help()` return a string containing all available options.
7034 """Display a string describing all available options."""
7038 """Return the parameter description set."""
7042 """Assert constraints as background axioms for the fixedpoint solver."""
7043 args = _get_args(args)
7046 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7056 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7064 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7068 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7072 """Assert rules defining recursive predicates to the fixedpoint solver.
7075 >>> s = Fixedpoint()
7076 >>> s.register_relation(a.decl())
7077 >>> s.register_relation(b.decl())
7090 body = _get_args(body)
7094 def rule(self, head, body = None, name = None):
7095 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7099 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7103 """Query the fixedpoint engine whether formula is derivable.
7104 You can also pass an tuple or list of recursive predicates.
7106 query = _get_args(query)
7108 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7109 _decls = (FuncDecl * sz)()
7119 query =
And(query, self.
ctx)
7120 query = self.
abstract(query,
False)
7125 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7127 query = _get_args(query)
7129 if sz >= 1
and isinstance(query[0], FuncDecl):
7130 _z3_assert (
False,
"unsupported")
7136 query = self.
abstract(query,
False)
7137 r = Z3_fixedpoint_query_from_lvl (self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
7145 body = _get_args(body)
7150 """Retrieve answer from last query call."""
7152 return _to_expr_ref(r, self.
ctx)
7155 """Retrieve a ground cex from last query call."""
7156 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7157 return _to_expr_ref(r, self.
ctx)
7160 """retrieve rules along the counterexample trace"""
7164 """retrieve rule names along the counterexample trace"""
7167 names = _symbol2py (self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7169 return names.split (
';')
7172 """Retrieve number of levels used for predicate in PDR engine"""
7176 """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)"""
7178 return _to_expr_ref(r, self.
ctx)
7181 """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)"""
7185 """Register relation as recursive"""
7186 relations = _get_args(relations)
7191 """Control how relation is represented"""
7192 representations = _get_args(representations)
7193 representations = [
to_symbol(s)
for s
in representations]
7194 sz = len(representations)
7195 args = (Symbol * sz)()
7197 args[i] = representations[i]
7201 """Parse rules and queries from a string"""
7205 """Parse rules and queries from a file"""
7209 """retrieve rules that have been added to fixedpoint context"""
7213 """retrieve assertions that have been added to fixedpoint context"""
7217 """Return a formatted string with all added rules and constraints."""
7221 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7226 """Return a formatted string (in Lisp-like format) with all added constraints.
7227 We say the string is in s-expression format.
7228 Include also queries.
7230 args, len = _to_ast_array(queries)
7234 """Return statistics for the last `query()`.
7239 """Return a string describing why the last `query()` returned `unknown`.
7244 """Add variable or several variables.
7245 The added variable or variables will be bound in the rules
7248 vars = _get_args(vars)
7268 """Finite domain sort."""
7271 """Return the size of the finite domain sort"""
7272 r = (ctypes.c_ulonglong * 1)()
7276 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7279 """Create a named finite domain sort of a given size sz"""
7280 if not isinstance(name, Symbol):
7286 """Return True if `s` is a Z3 finite-domain sort.
7288 >>> is_finite_domain_sort(FiniteDomainSort('S', 100))
7290 >>> is_finite_domain_sort(IntSort())
7293 return isinstance(s, FiniteDomainSortRef)
7297 """Finite-domain expressions."""
7300 """Return the sort of the finite-domain expression `self`."""
7304 """Return a Z3 floating point expression as a Python string."""
7308 """Return `True` if `a` is a Z3 finite-domain expression.
7310 >>> s = FiniteDomainSort('S', 100)
7311 >>> b = Const('b', s)
7312 >>> is_finite_domain(b)
7314 >>> is_finite_domain(Int('x'))
7317 return isinstance(a, FiniteDomainRef)
7321 """Integer values."""
7324 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7326 >>> s = FiniteDomainSort('S', 100)
7327 >>> v = FiniteDomainVal(3, s)
7336 """Return a Z3 finite-domain numeral as a Python string.
7338 >>> s = FiniteDomainSort('S', 100)
7339 >>> v = FiniteDomainVal(42, s)
7347 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7349 >>> s = FiniteDomainSort('S', 256)
7350 >>> FiniteDomainVal(255, s)
7352 >>> FiniteDomainVal('100', s)
7361 """Return `True` if `a` is a Z3 finite-domain value.
7363 >>> s = FiniteDomainSort('S', 100)
7364 >>> b = Const('b', s)
7365 >>> is_finite_domain_value(b)
7367 >>> b = FiniteDomainVal(10, s)
7370 >>> is_finite_domain_value(b)
7415 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7426 if self.
optimize is not None and self.
ctx.ref()
is not None:
7430 """Set a configuration option. The method `help()` return a string containing all available options.
7436 """Display a string describing all available options."""
7440 """Return the parameter description set."""
7444 """Assert constraints as background axioms for the optimize solver."""
7445 args = _get_args(args)
7448 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7456 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7464 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7466 If `p` is a string, it will be automatically converted into a Boolean constant.
7471 >>> s.assert_and_track(x > 0, 'p1')
7472 >>> s.assert_and_track(x != 1, 'p2')
7473 >>> s.assert_and_track(x < 0, p3)
7474 >>> print(s.check())
7476 >>> c = s.unsat_core()
7486 if isinstance(p, str):
7488 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7489 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7493 """Add soft constraint with optional weight and optional identifier.
7494 If no weight is supplied, then the penalty for violating the soft constraint
7496 Soft constraints are grouped by identifiers. Soft constraints that are
7497 added without identifiers are grouped by default.
7500 weight =
"%d" % weight
7501 elif isinstance(weight, float):
7502 weight =
"%f" % weight
7503 if not isinstance(weight, str):
7504 raise Z3Exception(
"weight should be a string or an integer")
7512 """Add objective function to maximize."""
7516 """Add objective function to minimize."""
7520 """create a backtracking point for added rules, facts and assertions"""
7524 """restore to previously created backtracking point"""
7528 """Check satisfiability while optimizing objective functions."""
7529 assumptions = _get_args(assumptions)
7530 num = len(assumptions)
7531 _assumptions = (Ast * num)()
7532 for i
in range(num):
7533 _assumptions[i] = assumptions[i].as_ast()
7537 """Return a string that describes why the last `check()` returned `unknown`."""
7541 """Return a model for the last check()."""
7545 raise Z3Exception(
"model is not available")
7551 if not isinstance(obj, OptimizeObjective):
7552 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7556 if not isinstance(obj, OptimizeObjective):
7557 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7561 if not isinstance(obj, OptimizeObjective):
7562 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7563 return obj.lower_values()
7566 if not isinstance(obj, OptimizeObjective):
7567 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7568 return obj.upper_values()
7571 """Parse assertions and objectives from a file"""
7575 """Parse assertions and objectives from a string"""
7579 """Return an AST vector containing all added constraints."""
7583 """returns set of objective functions"""
7587 """Return a formatted string with all added rules and constraints."""
7591 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
7596 """Return statistics for the last check`.
7609 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters."""
7620 if self.
ctx.ref()
is not None:
7624 """Return the number of subgoals in `self`.
7626 >>> a, b = Ints('a b')
7628 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7629 >>> t = Tactic('split-clause')
7633 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'))
7636 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values'))
7643 """Return one of the subgoals stored in ApplyResult object `self`.
7645 >>> a, b = Ints('a b')
7647 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
7648 >>> t = Tactic('split-clause')
7651 [a == 0, Or(b == 0, b == 1), a > b]
7653 [a == 1, Or(b == 0, b == 1), a > b]
7655 if idx >= len(self):
7660 return obj_to_string(self)
7663 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
7668 """Return a Z3 expression consisting of all subgoals.
7673 >>> g.add(Or(x == 2, x == 3))
7674 >>> r = Tactic('simplify')(g)
7676 [[Not(x <= 1), Or(x == 2, x == 3)]]
7678 And(Not(x <= 1), Or(x == 2, x == 3))
7679 >>> r = Tactic('split-clause')(g)
7681 [[x > 1, x == 2], [x > 1, x == 3]]
7683 Or(And(x > 1, x == 2), And(x > 1, x == 3))
7699 """Tactics transform, solver and/or simplify sets of constraints (Goal). A Tactic can be converted into a Solver using the method solver().
7701 Several combinators are available for creating new tactics using the built-in ones: Then(), OrElse(), FailIf(), Repeat(), When(), Cond().
7706 if isinstance(tactic, TacticObj):
7710 _z3_assert(isinstance(tactic, str),
"tactic name expected")
7714 raise Z3Exception(
"unknown tactic '%s'" % tactic)
7721 if self.
tactic is not None and self.
ctx.ref()
is not None:
7725 """Create a solver using the tactic `self`.
7727 The solver supports the methods `push()` and `pop()`, but it
7728 will always solve each `check()` from scratch.
7730 >>> t = Then('simplify', 'nlsat')
7733 >>> s.add(x**2 == 2, x > 0)
7741 def apply(self, goal, *arguments, **keywords):
7742 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7744 >>> x, y = Ints('x y')
7745 >>> t = Tactic('solve-eqs')
7746 >>> t.apply(And(x == 0, y >= x + 1))
7750 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expressions expected")
7751 goal = _to_goal(goal)
7752 if len(arguments) > 0
or len(keywords) > 0:
7759 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
7761 >>> x, y = Ints('x y')
7762 >>> t = Tactic('solve-eqs')
7763 >>> t(And(x == 0, y >= x + 1))
7766 return self.
apply(goal, *arguments, **keywords)
7769 """Display a string containing a description of the available options for the `self` tactic."""
7773 """Return the parameter description set."""
7777 if isinstance(a, BoolRef):
7778 goal =
Goal(ctx = a.ctx)
7784 def _to_tactic(t, ctx=None):
7785 if isinstance(t, Tactic):
7790 def _and_then(t1, t2, ctx=None):
7791 t1 = _to_tactic(t1, ctx)
7792 t2 = _to_tactic(t2, ctx)
7794 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7797 def _or_else(t1, t2, ctx=None):
7798 t1 = _to_tactic(t1, ctx)
7799 t2 = _to_tactic(t2, ctx)
7801 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7805 """Return a tactic that applies the tactics in `*ts` in sequence.
7807 >>> x, y = Ints('x y')
7808 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
7809 >>> t(And(x == 0, y > x + 1))
7811 >>> t(And(x == 0, y > x + 1)).as_expr()
7815 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7816 ctx = ks.get(
'ctx',
None)
7819 for i
in range(num - 1):
7820 r = _and_then(r, ts[i+1], ctx)
7824 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
7826 >>> x, y = Ints('x y')
7827 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
7828 >>> t(And(x == 0, y > x + 1))
7830 >>> t(And(x == 0, y > x + 1)).as_expr()
7836 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
7839 >>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
7840 >>> # Tactic split-clause fails if there is no clause in the given goal.
7843 >>> t(Or(x == 0, x == 1))
7844 [[x == 0], [x == 1]]
7847 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7848 ctx = ks.get(
'ctx',
None)
7851 for i
in range(num - 1):
7852 r = _or_else(r, ts[i+1], ctx)
7856 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
7859 >>> t = ParOr(Tactic('simplify'), Tactic('fail'))
7864 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7865 ctx = _get_ctx(ks.get(
'ctx',
None))
7866 ts = [ _to_tactic(t, ctx)
for t
in ts ]
7868 _args = (TacticObj * sz)()
7870 _args[i] = ts[i].tactic
7874 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
7876 >>> x, y = Ints('x y')
7877 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
7878 >>> t(And(Or(x == 1, x == 2), y == x + 1))
7879 [[x == 1, y == 2], [x == 2, y == 3]]
7881 t1 = _to_tactic(t1, ctx)
7882 t2 = _to_tactic(t2, ctx)
7884 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7888 """Alias for ParThen(t1, t2, ctx)."""
7892 """Return a tactic that applies tactic `t` using the given configuration options.
7894 >>> x, y = Ints('x y')
7895 >>> t = With(Tactic('simplify'), som=True)
7896 >>> t((x + 1)*(y + 2) == 0)
7897 [[2*x + y + x*y == -2]]
7899 ctx = keys.pop(
'ctx',
None)
7900 t = _to_tactic(t, ctx)
7905 """Return a tactic that applies tactic `t` using the given configuration options.
7907 >>> x, y = Ints('x y')
7909 >>> p.set("som", True)
7910 >>> t = WithParams(Tactic('simplify'), p)
7911 >>> t((x + 1)*(y + 2) == 0)
7912 [[2*x + y + x*y == -2]]
7914 t = _to_tactic(t,
None)
7918 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
7920 >>> x, y = Ints('x y')
7921 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
7922 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
7924 >>> for subgoal in r: print(subgoal)
7925 [x == 0, y == 0, x > y]
7926 [x == 0, y == 1, x > y]
7927 [x == 1, y == 0, x > y]
7928 [x == 1, y == 1, x > y]
7929 >>> t = Then(t, Tactic('propagate-values'))
7933 t = _to_tactic(t, ctx)
7937 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
7939 If `t` does not terminate in `ms` milliseconds, then it fails.
7941 t = _to_tactic(t, ctx)
7945 """Return a list of all available tactics in Z3.
7948 >>> l.count('simplify') == 1
7955 """Return a short description for the tactic named `name`.
7957 >>> d = tactic_description('simplify')
7963 """Display a (tabular) description of all available tactics in Z3."""
7966 print(
'<table border="1" cellpadding="2" cellspacing="0">')
7969 print(
'<tr style="background-color:#CFCFCF">')
7974 print(
'<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(
tactic_description(t), 40)))
7981 """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."""
7985 if isinstance(probe, ProbeObj):
7987 elif isinstance(probe, float):
7989 elif _is_int(probe):
7991 elif isinstance(probe, bool):
7998 _z3_assert(isinstance(probe, str),
"probe name expected")
8002 raise Z3Exception(
"unknown probe '%s'" % probe)
8009 if self.
probe is not None and self.
ctx.ref()
is not None:
8013 """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`.
8015 >>> p = Probe('size') < 10
8026 """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`.
8028 >>> p = Probe('size') > 10
8039 """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`.
8041 >>> p = Probe('size') <= 2
8052 """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`.
8054 >>> p = Probe('size') >= 2
8065 """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`.
8067 >>> p = Probe('size') == 2
8078 """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`.
8080 >>> p = Probe('size') != 2
8092 """Evaluate the probe `self` in the given goal.
8094 >>> p = Probe('size')
8104 >>> p = Probe('num-consts')
8107 >>> p = Probe('is-propositional')
8110 >>> p = Probe('is-qflia')
8115 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expression expected")
8116 goal = _to_goal(goal)
8120 """Return `True` if `p` is a Z3 probe.
8122 >>> is_probe(Int('x'))
8124 >>> is_probe(Probe('memory'))
8127 return isinstance(p, Probe)
8129 def _to_probe(p, ctx=None):
8133 return Probe(p, ctx)
8136 """Return a list of all available probes in Z3.
8139 >>> l.count('memory') == 1
8146 """Return a short description for the probe named `name`.
8148 >>> d = probe_description('memory')
8154 """Display a (tabular) description of all available probes in Z3."""
8157 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8160 print(
'<tr style="background-color:#CFCFCF">')
8165 print(
'<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(
probe_description(p), 40)))
8171 def _probe_nary(f, args, ctx):
8173 _z3_assert(len(args) > 0,
"At least one argument expected")
8175 r = _to_probe(args[0], ctx)
8176 for i
in range(num - 1):
8177 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i+1], ctx).probe), ctx)
8180 def _probe_and(args, ctx):
8181 return _probe_nary(Z3_probe_and, args, ctx)
8183 def _probe_or(args, ctx):
8184 return _probe_nary(Z3_probe_or, args, ctx)
8187 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8189 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
8191 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
8192 >>> x, y = Ints('x y')
8198 >>> g.add(x == y + 1)
8200 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8202 p = _to_probe(p, ctx)
8206 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
8208 >>> t = When(Probe('size') > 2, Tactic('simplify'))
8209 >>> x, y = Ints('x y')
8215 >>> g.add(x == y + 1)
8217 [[Not(x <= 0), Not(y <= 0), x == 1 + y]]
8219 p = _to_probe(p, ctx)
8220 t = _to_tactic(t, ctx)
8224 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8226 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
8228 p = _to_probe(p, ctx)
8229 t1 = _to_tactic(t1, ctx)
8230 t2 = _to_tactic(t2, ctx)
8240 """Simplify the expression `a` using the given options.
8242 This function has many options. Use `help_simplify` to obtain the complete list.
8246 >>> simplify(x + 1 + y + x + 1)
8248 >>> simplify((x + 1)*(y + 1), som=True)
8250 >>> simplify(Distinct(x, y, 1), blast_distinct=True)
8251 And(Not(x == y), Not(x == 1), Not(y == 1))
8252 >>> simplify(And(x == 0, y == 1), elim_and=True)
8253 Not(Or(Not(x == 0), Not(y == 1)))
8256 _z3_assert(
is_expr(a),
"Z3 expression expected")
8257 if len(arguments) > 0
or len(keywords) > 0:
8259 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8261 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8264 """Return a string describing all options available for Z3 `simplify` procedure."""
8268 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8272 """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.
8276 >>> substitute(x + 1, (x, y + 1))
8278 >>> f = Function('f', IntSort(), IntSort())
8279 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
8282 if isinstance(m, tuple):
8284 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8287 _z3_assert(
is_expr(t),
"Z3 expression expected")
8288 _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.")
8290 _from = (Ast * num)()
8292 for i
in range(num):
8293 _from[i] = m[i][0].as_ast()
8294 _to[i] = m[i][1].as_ast()
8295 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8298 """Substitute the free variables in t with the expression in m.
8300 >>> v0 = Var(0, IntSort())
8301 >>> v1 = Var(1, IntSort())
8303 >>> f = Function('f', IntSort(), IntSort(), IntSort())
8304 >>> # replace v0 with x+1 and v1 with x
8305 >>> substitute_vars(f(v0, v1), x + 1, x)
8309 _z3_assert(
is_expr(t),
"Z3 expression expected")
8310 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8313 for i
in range(num):
8314 _to[i] = m[i].as_ast()
8318 """Create the sum of the Z3 expressions.
8320 >>> a, b, c = Ints('a b c')
8325 >>> A = IntVector('a', 5)
8327 a__0 + a__1 + a__2 + a__3 + a__4
8329 args = _get_args(args)
8332 ctx = _ctx_from_ast_arg_list(args)
8334 return _reduce(
lambda a, b: a + b, args, 0)
8335 args = _coerce_expr_list(args, ctx)
8337 return _reduce(
lambda a, b: a + b, args, 0)
8339 _args, sz = _to_ast_array(args)
8344 """Create the product of the Z3 expressions.
8346 >>> a, b, c = Ints('a b c')
8347 >>> Product(a, b, c)
8349 >>> Product([a, b, c])
8351 >>> A = IntVector('a', 5)
8353 a__0*a__1*a__2*a__3*a__4
8355 args = _get_args(args)
8358 ctx = _ctx_from_ast_arg_list(args)
8360 return _reduce(
lambda a, b: a * b, args, 1)
8361 args = _coerce_expr_list(args, ctx)
8363 return _reduce(
lambda a, b: a * b, args, 1)
8365 _args, sz = _to_ast_array(args)
8369 """Create an at-most Pseudo-Boolean k constraint.
8371 >>> a, b, c = Bools('a b c')
8372 >>> f = AtMost(a, b, c, 2)
8374 args = _get_args(args)
8376 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8377 ctx = _ctx_from_ast_arg_list(args)
8379 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8380 args1 = _coerce_expr_list(args[:-1], ctx)
8382 _args, sz = _to_ast_array(args1)
8386 """Create an at-most Pseudo-Boolean k constraint.
8388 >>> a, b, c = Bools('a b c')
8389 >>> f = AtLeast(a, b, c, 2)
8391 args = _get_args(args)
8393 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8394 ctx = _ctx_from_ast_arg_list(args)
8396 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8397 args1 = _coerce_expr_list(args[:-1], ctx)
8399 _args, sz = _to_ast_array(args1)
8402 def _reorder_pb_arg(arg):
8404 if not _is_int(b)
and _is_int(a):
8408 def _pb_args_coeffs(args, default_ctx = None):
8409 args = _get_args_ast_list(args)
8411 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8412 args = [_reorder_pb_arg(arg)
for arg
in args]
8413 args, coeffs = zip(*args)
8415 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8416 ctx = _ctx_from_ast_arg_list(args)
8418 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8419 args = _coerce_expr_list(args, ctx)
8420 _args, sz = _to_ast_array(args)
8421 _coeffs = (ctypes.c_int * len(coeffs))()
8422 for i
in range(len(coeffs)):
8423 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8424 _coeffs[i] = coeffs[i]
8425 return ctx, sz, _args, _coeffs
8428 """Create a Pseudo-Boolean inequality k constraint.
8430 >>> a, b, c = Bools('a b c')
8431 >>> f = PbLe(((a,1),(b,3),(c,2)), 3)
8433 _z3_check_cint_overflow(k,
"k")
8434 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8438 """Create a Pseudo-Boolean inequality k constraint.
8440 >>> a, b, c = Bools('a b c')
8441 >>> f = PbGe(((a,1),(b,3),(c,2)), 3)
8443 _z3_check_cint_overflow(k,
"k")
8444 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8448 """Create a Pseudo-Boolean inequality k constraint.
8450 >>> a, b, c = Bools('a b c')
8451 >>> f = PbEq(((a,1),(b,3),(c,2)), 3)
8453 _z3_check_cint_overflow(k,
"k")
8454 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8459 """Solve the constraints `*args`.
8461 This is a simple function for creating demonstrations. It creates a solver,
8462 configure it using the options in `keywords`, adds the constraints
8463 in `args`, and invokes check.
8466 >>> solve(a > 0, a < 2)
8472 if keywords.get(
'show',
False):
8476 print(
"no solution")
8478 print(
"failed to solve")
8487 """Solve the constraints `*args` using solver `s`.
8489 This is a simple function for creating demonstrations. It is similar to `solve`,
8490 but it uses the given solver `s`.
8491 It configures solver `s` using the options in `keywords`, adds the constraints
8492 in `args`, and invokes check.
8495 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8498 if keywords.get(
'show',
False):
8503 print(
"no solution")
8505 print(
"failed to solve")
8511 if keywords.get(
'show',
False):
8516 """Try to prove the given claim.
8518 This is a simple function for creating demonstrations. It tries to prove
8519 `claim` by showing the negation is unsatisfiable.
8521 >>> p, q = Bools('p q')
8522 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
8526 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8530 if keywords.get(
'show',
False):
8536 print(
"failed to prove")
8539 print(
"counterexample")
8542 def _solve_html(*args, **keywords):
8543 """Version of function `solve` used in RiSE4Fun."""
8547 if keywords.get(
'show',
False):
8548 print(
"<b>Problem:</b>")
8552 print(
"<b>no solution</b>")
8554 print(
"<b>failed to solve</b>")
8560 if keywords.get(
'show',
False):
8561 print(
"<b>Solution:</b>")
8564 def _solve_using_html(s, *args, **keywords):
8565 """Version of function `solve_using` used in RiSE4Fun."""
8567 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8570 if keywords.get(
'show',
False):
8571 print(
"<b>Problem:</b>")
8575 print(
"<b>no solution</b>")
8577 print(
"<b>failed to solve</b>")
8583 if keywords.get(
'show',
False):
8584 print(
"<b>Solution:</b>")
8587 def _prove_html(claim, **keywords):
8588 """Version of function `prove` used in RiSE4Fun."""
8590 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8594 if keywords.get(
'show',
False):
8598 print(
"<b>proved</b>")
8600 print(
"<b>failed to prove</b>")
8603 print(
"<b>counterexample</b>")
8606 def _dict2sarray(sorts, ctx):
8608 _names = (Symbol * sz)()
8609 _sorts = (Sort * sz) ()
8614 _z3_assert(isinstance(k, str),
"String expected")
8615 _z3_assert(
is_sort(v),
"Z3 sort expected")
8619 return sz, _names, _sorts
8621 def _dict2darray(decls, ctx):
8623 _names = (Symbol * sz)()
8624 _decls = (FuncDecl * sz) ()
8629 _z3_assert(isinstance(k, str),
"String expected")
8633 _decls[i] = v.decl().ast
8637 return sz, _names, _decls
8641 """Parse a string in SMT 2.0 format using the given sorts and decls.
8643 The arguments sorts and decls are Python dictionaries used to initialize
8644 the symbol table used for the SMT 2.0 parser.
8646 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
8648 >>> x, y = Ints('x y')
8649 >>> f = Function('f', IntSort(), IntSort())
8650 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
8652 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
8656 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8657 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8661 """Parse a file in SMT 2.0 format using the given sorts and decls.
8663 This function is similar to parse_smt2_string().
8666 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8667 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8679 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
8680 _dflt_fpsort_ebits = 11
8681 _dflt_fpsort_sbits = 53
8684 """Retrieves the global default rounding mode."""
8685 global _dflt_rounding_mode
8686 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8688 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8690 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8692 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8694 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8698 global _dflt_rounding_mode
8700 _dflt_rounding_mode = rm.decl().kind()
8702 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO
or
8703 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE
or
8704 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE
or
8705 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
or
8706 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8707 "illegal rounding mode")
8708 _dflt_rounding_mode = rm
8711 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8714 global _dflt_fpsort_ebits
8715 global _dflt_fpsort_sbits
8716 _dflt_fpsort_ebits = ebits
8717 _dflt_fpsort_sbits = sbits
8719 def _dflt_rm(ctx=None):
8722 def _dflt_fps(ctx=None):
8725 def _coerce_fp_expr_list(alist, ctx):
8726 first_fp_sort =
None
8729 if first_fp_sort
is None:
8730 first_fp_sort = a.sort()
8731 elif first_fp_sort == a.sort():
8736 first_fp_sort =
None
8740 for i
in range(len(alist)):
8742 if (isinstance(a, str)
and a.contains(
'2**(')
and a.endswith(
')'))
or _is_int(a)
or isinstance(a, float)
or isinstance(a, bool):
8743 r.append(
FPVal(a,
None, first_fp_sort, ctx))
8746 return _coerce_expr_list(r, ctx)
8752 """Floating-point sort."""
8755 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
8756 >>> b = FPSort(8, 24)
8763 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
8764 >>> b = FPSort(8, 24)
8771 """Try to cast `val` as a floating-point expression.
8772 >>> b = FPSort(8, 24)
8775 >>> b.cast(1.0).sexpr()
8776 '(fp #b0 #x7f #b00000000000000000000000)'
8780 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
8783 return FPVal(val,
None, self, self.
ctx)
8787 """Floating-point 16-bit (half) sort."""
8792 """Floating-point 16-bit (half) sort."""
8797 """Floating-point 32-bit (single) sort."""
8802 """Floating-point 32-bit (single) sort."""
8807 """Floating-point 64-bit (double) sort."""
8812 """Floating-point 64-bit (double) sort."""
8817 """Floating-point 128-bit (quadruple) sort."""
8822 """Floating-point 128-bit (quadruple) sort."""
8827 """"Floating-point rounding mode sort."""
8831 """Return True if `s` is a Z3 floating-point sort.
8833 >>> is_fp_sort(FPSort(8, 24))
8835 >>> is_fp_sort(IntSort())
8838 return isinstance(s, FPSortRef)
8841 """Return True if `s` is a Z3 floating-point rounding mode sort.
8843 >>> is_fprm_sort(FPSort(8, 24))
8845 >>> is_fprm_sort(RNE().sort())
8848 return isinstance(s, FPRMSortRef)
8853 """Floating-point expressions."""
8856 """Return the sort of the floating-point expression `self`.
8858 >>> x = FP('1.0', FPSort(8, 24))
8861 >>> x.sort() == FPSort(8, 24)
8867 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8868 >>> b = FPSort(8, 24)
8875 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
8876 >>> b = FPSort(8, 24)
8883 """Return a Z3 floating point expression as a Python string."""
8887 return fpLEQ(self, other, self.
ctx)
8890 return fpLT(self, other, self.
ctx)
8893 return fpGEQ(self, other, self.
ctx)
8896 return fpGT(self, other, self.
ctx)
8899 """Create the Z3 expression `self + other`.
8901 >>> x = FP('x', FPSort(8, 24))
8902 >>> y = FP('y', FPSort(8, 24))
8908 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8909 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8912 """Create the Z3 expression `other + self`.
8914 >>> x = FP('x', FPSort(8, 24))
8918 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8919 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8922 """Create the Z3 expression `self - other`.
8924 >>> x = FP('x', FPSort(8, 24))
8925 >>> y = FP('y', FPSort(8, 24))
8931 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8932 return fpSub(_dflt_rm(), a, b, self.
ctx)
8935 """Create the Z3 expression `other - self`.
8937 >>> x = FP('x', FPSort(8, 24))
8941 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8942 return fpSub(_dflt_rm(), a, b, self.
ctx)
8945 """Create the Z3 expression `self * other`.
8947 >>> x = FP('x', FPSort(8, 24))
8948 >>> y = FP('y', FPSort(8, 24))
8956 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8957 return fpMul(_dflt_rm(), a, b, self.
ctx)
8960 """Create the Z3 expression `other * self`.
8962 >>> x = FP('x', FPSort(8, 24))
8963 >>> y = FP('y', FPSort(8, 24))
8969 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8970 return fpMul(_dflt_rm(), a, b, self.
ctx)
8973 """Create the Z3 expression `+self`."""
8977 """Create the Z3 expression `-self`.
8979 >>> x = FP('x', Float32())
8986 """Create the Z3 expression `self / other`.
8988 >>> x = FP('x', FPSort(8, 24))
8989 >>> y = FP('y', FPSort(8, 24))
8997 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8998 return fpDiv(_dflt_rm(), a, b, self.
ctx)
9001 """Create the Z3 expression `other / self`.
9003 >>> x = FP('x', FPSort(8, 24))
9004 >>> y = FP('y', FPSort(8, 24))
9010 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
9011 return fpDiv(_dflt_rm(), a, b, self.
ctx)
9014 """Create the Z3 expression division `self / other`."""
9018 """Create the Z3 expression division `other / self`."""
9022 """Create the Z3 expression mod `self % other`."""
9023 return fpRem(self, other)
9026 """Create the Z3 expression mod `other % self`."""
9027 return fpRem(other, self)
9030 """Floating-point rounding mode expressions"""
9033 """Return a Z3 floating point expression as a Python string."""
9078 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9087 return isinstance(a, FPRMRef)
9090 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9091 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9096 """The sign of the numeral.
9098 >>> x = FPVal(+1.0, FPSort(8, 24))
9101 >>> x = FPVal(-1.0, FPSort(8, 24))
9106 l = (ctypes.c_int)()
9108 raise Z3Exception(
"error retrieving the sign of a numeral.")
9111 """The sign of a floating-point numeral as a bit-vector expression.
9113 Remark: NaN's are invalid arguments.
9118 """The significand of the numeral.
9120 >>> x = FPVal(2.5, FPSort(8, 24))
9127 """The significand of the numeral as a long.
9129 >>> x = FPVal(2.5, FPSort(8, 24))
9130 >>> x.significand_as_long()
9134 ptr = (ctypes.c_ulonglong * 1)()
9136 raise Z3Exception(
"error retrieving the significand of a numeral.")
9139 """The significand of the numeral as a bit-vector expression.
9141 Remark: NaN are invalid arguments.
9146 """The exponent of the numeral.
9148 >>> x = FPVal(2.5, FPSort(8, 24))
9155 """The exponent of the numeral as a long.
9157 >>> x = FPVal(2.5, FPSort(8, 24))
9158 >>> x.exponent_as_long()
9162 ptr = (ctypes.c_longlong * 1)()
9164 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9167 """The exponent of the numeral as a bit-vector expression.
9169 Remark: NaNs are invalid arguments.
9174 """Indicates whether the numeral is a NaN."""
9178 """Indicates whether the numeral is +oo or -oo."""
9182 """Indicates whether the numeral is +zero or -zero."""
9186 """Indicates whether the numeral is normal."""
9190 """Indicates whether the numeral is subnormal."""
9194 """Indicates whether the numeral is positive."""
9198 """Indicates whether the numeral is negative."""
9203 The string representation of the numeral.
9205 >>> x = FPVal(20, FPSort(8, 24))
9211 return (
"FPVal(%s, %s)" % (s, self.
sort()))
9214 """Return `True` if `a` is a Z3 floating-point expression.
9216 >>> b = FP('b', FPSort(8, 24))
9224 return isinstance(a, FPRef)
9227 """Return `True` if `a` is a Z3 floating-point numeral value.
9229 >>> b = FP('b', FPSort(8, 24))
9232 >>> b = FPVal(1.0, FPSort(8, 24))
9238 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9241 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9243 >>> Single = FPSort(8, 24)
9244 >>> Double = FPSort(11, 53)
9247 >>> x = Const('x', Single)
9248 >>> eq(x, FP('x', FPSort(8, 24)))
9254 def _to_float_str(val, exp=0):
9255 if isinstance(val, float):
9259 sone = math.copysign(1.0, val)
9264 elif val == float(
"+inf"):
9266 elif val == float(
"-inf"):
9269 v = val.as_integer_ratio()
9272 rvs = str(num) +
'/' + str(den)
9273 res = rvs +
'p' + _to_int_str(exp)
9274 elif isinstance(val, bool):
9281 elif isinstance(val, str):
9282 inx = val.find(
'*(2**')
9285 elif val[-1] ==
')':
9287 exp = str(int(val[inx+5:-1]) + int(exp))
9289 _z3_assert(
False,
"String does not have floating-point numeral form.")
9291 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9295 return res +
'p' + exp
9299 """Create a Z3 floating-point NaN term.
9301 >>> s = FPSort(8, 24)
9302 >>> set_fpa_pretty(True)
9305 >>> pb = get_fpa_pretty()
9306 >>> set_fpa_pretty(False)
9308 fpNaN(FPSort(8, 24))
9309 >>> set_fpa_pretty(pb)
9311 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9315 """Create a Z3 floating-point +oo term.
9317 >>> s = FPSort(8, 24)
9318 >>> pb = get_fpa_pretty()
9319 >>> set_fpa_pretty(True)
9320 >>> fpPlusInfinity(s)
9322 >>> set_fpa_pretty(False)
9323 >>> fpPlusInfinity(s)
9324 fpPlusInfinity(FPSort(8, 24))
9325 >>> set_fpa_pretty(pb)
9327 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9331 """Create a Z3 floating-point -oo term."""
9332 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9336 """Create a Z3 floating-point +oo or -oo term."""
9337 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9338 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9342 """Create a Z3 floating-point +0.0 term."""
9343 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9347 """Create a Z3 floating-point -0.0 term."""
9348 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9352 """Create a Z3 floating-point +0.0 or -0.0 term."""
9353 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9354 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9357 def FPVal(sig, exp=None, fps=None, ctx=None):
9358 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
9360 >>> v = FPVal(20.0, FPSort(8, 24))
9363 >>> print("0x%.8x" % v.exponent_as_long(False))
9365 >>> v = FPVal(2.25, FPSort(8, 24))
9368 >>> v = FPVal(-2.25, FPSort(8, 24))
9371 >>> FPVal(-0.0, FPSort(8, 24))
9373 >>> FPVal(0.0, FPSort(8, 24))
9375 >>> FPVal(+0.0, FPSort(8, 24))
9383 fps = _dflt_fps(ctx)
9387 val = _to_float_str(sig)
9388 if val ==
"NaN" or val ==
"nan":
9392 elif val ==
"0.0" or val ==
"+0.0":
9394 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9396 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9401 def FP(name, fpsort, ctx=None):
9402 """Return a floating-point constant named `name`.
9403 `fpsort` is the floating-point sort.
9404 If `ctx=None`, then the global context is used.
9406 >>> x = FP('x', FPSort(8, 24))
9413 >>> word = FPSort(8, 24)
9414 >>> x2 = FP('x', word)
9418 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9424 def FPs(names, fpsort, ctx=None):
9425 """Return an array of floating-point constants.
9427 >>> x, y, z = FPs('x y z', FPSort(8, 24))
9434 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
9435 fpMul(RNE(), fpAdd(RNE(), x, y), z)
9438 if isinstance(names, str):
9439 names = names.split(
" ")
9440 return [
FP(name, fpsort, ctx)
for name
in names]
9443 """Create a Z3 floating-point absolute value expression.
9445 >>> s = FPSort(8, 24)
9447 >>> x = FPVal(1.0, s)
9450 >>> y = FPVal(-20.0, s)
9455 >>> fpAbs(-1.25*(2**4))
9461 [a] = _coerce_fp_expr_list([a], ctx)
9465 """Create a Z3 floating-point addition expression.
9467 >>> s = FPSort(8, 24)
9476 [a] = _coerce_fp_expr_list([a], ctx)
9479 def _mk_fp_unary(f, rm, a, ctx):
9481 [a] = _coerce_fp_expr_list([a], ctx)
9483 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9484 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9485 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9487 def _mk_fp_unary_pred(f, a, ctx):
9489 [a] = _coerce_fp_expr_list([a], ctx)
9491 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9492 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9494 def _mk_fp_bin(f, rm, a, b, ctx):
9496 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9498 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9499 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9500 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
9502 def _mk_fp_bin_norm(f, a, b, ctx):
9504 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9506 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9507 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9509 def _mk_fp_bin_pred(f, a, b, ctx):
9511 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9513 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9514 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9516 def _mk_fp_tern(f, rm, a, b, c, ctx):
9518 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
9520 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9521 _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")
9522 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
9525 """Create a Z3 floating-point addition expression.
9527 >>> s = FPSort(8, 24)
9533 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ
9535 >>> fpAdd(rm, x, y).sort()
9538 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9541 """Create a Z3 floating-point subtraction expression.
9543 >>> s = FPSort(8, 24)
9549 >>> fpSub(rm, x, y).sort()
9552 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9555 """Create a Z3 floating-point multiplication expression.
9557 >>> s = FPSort(8, 24)
9563 >>> fpMul(rm, x, y).sort()
9566 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9569 """Create a Z3 floating-point division expression.
9571 >>> s = FPSort(8, 24)
9577 >>> fpDiv(rm, x, y).sort()
9580 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9583 """Create a Z3 floating-point remainder expression.
9585 >>> s = FPSort(8, 24)
9590 >>> fpRem(x, y).sort()
9593 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9596 """Create a Z3 floating-point minimum expression.
9598 >>> s = FPSort(8, 24)
9604 >>> fpMin(x, y).sort()
9607 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9610 """Create a Z3 floating-point maximum expression.
9612 >>> s = FPSort(8, 24)
9618 >>> fpMax(x, y).sort()
9621 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9624 """Create a Z3 floating-point fused multiply-add expression.
9626 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9629 """Create a Z3 floating-point square root expression.
9631 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9634 """Create a Z3 floating-point roundToIntegral expression.
9636 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9639 """Create a Z3 floating-point isNaN expression.
9641 >>> s = FPSort(8, 24)
9647 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
9650 """Create a Z3 floating-point isInfinite expression.
9652 >>> s = FPSort(8, 24)
9657 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
9660 """Create a Z3 floating-point isZero expression.
9662 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
9665 """Create a Z3 floating-point isNormal expression.
9667 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
9670 """Create a Z3 floating-point isSubnormal expression.
9672 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
9675 """Create a Z3 floating-point isNegative expression.
9677 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
9680 """Create a Z3 floating-point isPositive expression.
9682 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
9684 def _check_fp_args(a, b):
9686 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9689 """Create the Z3 floating-point expression `other < self`.
9691 >>> x, y = FPs('x y', FPSort(8, 24))
9697 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9700 """Create the Z3 floating-point expression `other <= self`.
9702 >>> x, y = FPs('x y', FPSort(8, 24))
9705 >>> (x <= y).sexpr()
9708 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9711 """Create the Z3 floating-point expression `other > self`.
9713 >>> x, y = FPs('x y', FPSort(8, 24))
9719 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9722 """Create the Z3 floating-point expression `other >= self`.
9724 >>> x, y = FPs('x y', FPSort(8, 24))
9727 >>> (x >= y).sexpr()
9730 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9733 """Create the Z3 floating-point expression `fpEQ(other, self)`.
9735 >>> x, y = FPs('x y', FPSort(8, 24))
9738 >>> fpEQ(x, y).sexpr()
9741 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9744 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
9746 >>> x, y = FPs('x y', FPSort(8, 24))
9749 >>> (x != y).sexpr()
9755 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
9757 >>> s = FPSort(8, 24)
9758 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23))
9760 fpFP(1, 127, 4194304)
9761 >>> xv = FPVal(-1.5, s)
9765 >>> slvr.add(fpEQ(x, xv))
9768 >>> xv = FPVal(+1.5, s)
9772 >>> slvr.add(fpEQ(x, xv))
9777 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
9779 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
9783 """Create a Z3 floating-point conversion expression from other term sorts
9786 From a bit-vector term in IEEE 754-2008 format:
9787 >>> x = FPVal(1.0, Float32())
9788 >>> x_bv = fpToIEEEBV(x)
9789 >>> simplify(fpToFP(x_bv, Float32()))
9792 From a floating-point term with different precision:
9793 >>> x = FPVal(1.0, Float32())
9794 >>> x_db = fpToFP(RNE(), x, Float64())
9799 >>> x_r = RealVal(1.5)
9800 >>> simplify(fpToFP(RNE(), x_r, Float32()))
9803 From a signed bit-vector term:
9804 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9805 >>> simplify(fpToFP(RNE(), x_signed, Float32()))
9818 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
9821 """Create a Z3 floating-point conversion expression that represents the
9822 conversion from a bit-vector term to a floating-point term.
9824 >>> x_bv = BitVecVal(0x3F800000, 32)
9825 >>> x_fp = fpBVToFP(x_bv, Float32())
9831 _z3_assert(
is_bv(v),
"First argument must be a Z3 bit-vector expression")
9832 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
9837 """Create a Z3 floating-point conversion expression that represents the
9838 conversion from a floating-point term to a floating-point term of different precision.
9840 >>> x_sgl = FPVal(1.0, Float32())
9841 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64())
9849 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9850 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point 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 a real term to a floating-point term.
9859 >>> x_r = RealVal(1.5)
9860 >>> x_fp = fpRealToFP(RNE(), x_r, Float32())
9866 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9867 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
9868 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9873 """Create a Z3 floating-point conversion expression that represents the
9874 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
9876 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9877 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32())
9879 fpToFP(RNE(), 4294967291)
9883 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9884 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
9885 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9890 """Create a Z3 floating-point conversion expression that represents the
9891 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
9893 >>> x_signed = BitVecVal(-5, BitVecSort(32))
9894 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32())
9896 fpToFPUnsigned(RNE(), 4294967291)
9900 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9901 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
9902 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9907 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
9909 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9910 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
9911 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
9916 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
9918 >>> x = FP('x', FPSort(8, 24))
9919 >>> y = fpToSBV(RTZ(), x, BitVecSort(32))
9930 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9931 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9932 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9937 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
9939 >>> x = FP('x', FPSort(8, 24))
9940 >>> y = fpToUBV(RTZ(), x, BitVecSort(32))
9951 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9952 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9953 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9958 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
9960 >>> x = FP('x', FPSort(8, 24))
9964 >>> print(is_real(y))
9968 >>> print(is_real(x))
9972 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9977 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
9979 The size of the resulting bit-vector is automatically determined.
9981 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
9982 knows only one NaN and it will always produce the same bit-vector representation of
9985 >>> x = FP('x', FPSort(8, 24))
9986 >>> y = fpToIEEEBV(x)
9997 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10010 """Sequence sort."""
10013 """Determine if sort is a string
10014 >>> s = StringSort()
10017 >>> s = SeqSort(IntSort())
10028 """Create a string sort
10029 >>> s = StringSort()
10033 ctx = _get_ctx(ctx)
10038 """Create a sequence sort over elements provided in the argument
10039 >>> s = SeqSort(IntSort())
10040 >>> s == Unit(IntVal(1)).sort()
10046 """Sequence expression."""
10052 return Concat(self, other)
10055 return Concat(other, self)
10075 """Return a string representation of sequence expression."""
10077 string_length = ctypes.c_uint()
10079 return string_at(chars, size=string_length.value).decode(
'latin-1')
10095 def _coerce_seq(s, ctx=None):
10096 if isinstance(s, str):
10097 ctx = _get_ctx(ctx)
10100 raise Z3Exception(
"Non-expression passed as a sequence")
10102 raise Z3Exception(
"Non-sequence passed as a sequence")
10105 def _get_ctx2(a, b, ctx=None):
10115 """Return `True` if `a` is a Z3 sequence expression.
10116 >>> print (is_seq(Unit(IntVal(0))))
10118 >>> print (is_seq(StringVal("abc")))
10121 return isinstance(a, SeqRef)
10124 """Return `True` if `a` is a Z3 string expression.
10125 >>> print (is_string(StringVal("ab")))
10128 return isinstance(a, SeqRef)
and a.is_string()
10131 """return 'True' if 'a' is a Z3 string constant expression.
10132 >>> print (is_string_value(StringVal("a")))
10134 >>> print (is_string_value(StringVal("a") + StringVal("b")))
10137 return isinstance(a, SeqRef)
and a.is_string_value()
10141 """create a string expression"""
10142 ctx = _get_ctx(ctx)
10146 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10148 >>> x = String('x')
10150 ctx = _get_ctx(ctx)
10154 """Return string constants"""
10155 ctx = _get_ctx(ctx)
10156 if isinstance(names, str):
10157 names = names.split(
" ")
10158 return [
String(name, ctx)
for name
in names]
10161 """Extract substring or subsequence starting at offset"""
10162 return Extract(s, offset, length)
10165 """Extract substring or subsequence starting at offset"""
10166 return Extract(s, offset, length)
10168 def Strings(names, ctx=None):
10169 """Return a tuple of String constants. """
10170 ctx = _get_ctx(ctx)
10171 if isinstance(names, str):
10172 names = names.split(
" ")
10173 return [
String(name, ctx)
for name
in names]
10176 """Create the empty sequence of the given sort
10177 >>> e = Empty(StringSort())
10178 >>> e2 = StringVal("")
10179 >>> print(e.eq(e2))
10181 >>> e3 = Empty(SeqSort(IntSort()))
10184 >>> e4 = Empty(ReSort(SeqSort(IntSort())))
10186 Empty(ReSort(Seq(Int)))
10188 if isinstance(s, SeqSortRef):
10190 if isinstance(s, ReSortRef):
10192 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10195 """Create the regular expression that accepts the universal language
10196 >>> e = Full(ReSort(SeqSort(IntSort())))
10198 Full(ReSort(Seq(Int)))
10199 >>> e1 = Full(ReSort(StringSort()))
10201 Full(ReSort(String))
10203 if isinstance(s, ReSortRef):
10205 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10209 """Create a singleton sequence"""
10213 """Check if 'a' is a prefix of 'b'
10214 >>> s1 = PrefixOf("ab", "abc")
10217 >>> s2 = PrefixOf("bc", "abc")
10221 ctx = _get_ctx2(a, b)
10222 a = _coerce_seq(a, ctx)
10223 b = _coerce_seq(b, ctx)
10227 """Check if 'a' is a suffix of 'b'
10228 >>> s1 = SuffixOf("ab", "abc")
10231 >>> s2 = SuffixOf("bc", "abc")
10235 ctx = _get_ctx2(a, b)
10236 a = _coerce_seq(a, ctx)
10237 b = _coerce_seq(b, ctx)
10241 """Check if 'a' contains 'b'
10242 >>> s1 = Contains("abc", "ab")
10245 >>> s2 = Contains("abc", "bc")
10248 >>> x, y, z = Strings('x y z')
10249 >>> s3 = Contains(Concat(x,y,z), y)
10253 ctx = _get_ctx2(a, b)
10254 a = _coerce_seq(a, ctx)
10255 b = _coerce_seq(b, ctx)
10260 """Replace the first occurrence of 'src' by 'dst' in 's'
10261 >>> r = Replace("aaa", "a", "b")
10265 ctx = _get_ctx2(dst, s)
10266 if ctx
is None and is_expr(src):
10268 src = _coerce_seq(src, ctx)
10269 dst = _coerce_seq(dst, ctx)
10270 s = _coerce_seq(s, ctx)
10277 """Retrieve the index of substring within a string starting at a specified offset.
10278 >>> simplify(IndexOf("abcabc", "bc", 0))
10280 >>> simplify(IndexOf("abcabc", "bc", 2))
10286 ctx = _get_ctx2(s, substr, ctx)
10287 s = _coerce_seq(s, ctx)
10288 substr = _coerce_seq(substr, ctx)
10289 if _is_int(offset):
10290 offset =
IntVal(offset, ctx)
10294 """Retrieve the last index of substring within a string"""
10296 ctx = _get_ctx2(s, substr, ctx)
10297 s = _coerce_seq(s, ctx)
10298 substr = _coerce_seq(substr, ctx)
10303 """Obtain the length of a sequence 's'
10304 >>> l = Length(StringVal("abc"))
10312 """Convert string expression to integer
10313 >>> a = StrToInt("1")
10314 >>> simplify(1 == a)
10316 >>> b = StrToInt("2")
10317 >>> simplify(1 == b)
10319 >>> c = StrToInt(IntToStr(2))
10320 >>> simplify(1 == c)
10328 """Convert integer expression to string"""
10335 """The regular expression that accepts sequence 's'
10337 >>> s2 = Re(StringVal("ab"))
10338 >>> s3 = Re(Unit(BoolVal(True)))
10340 s = _coerce_seq(s, ctx)
10349 """Regular expression sort."""
10357 if s
is None or isinstance(s, Context):
10360 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10364 """Regular expressions."""
10367 return Union(self, other)
10370 return isinstance(s, ReRef)
10374 """Create regular expression membership test
10375 >>> re = Union(Re("a"),Re("b"))
10376 >>> print (simplify(InRe("a", re)))
10378 >>> print (simplify(InRe("b", re)))
10380 >>> print (simplify(InRe("c", re)))
10383 s = _coerce_seq(s, re.ctx)
10387 """Create union of regular expressions.
10388 >>> re = Union(Re("a"), Re("b"), Re("c"))
10389 >>> print (simplify(InRe("d", re)))
10392 args = _get_args(args)
10395 _z3_assert(sz > 0,
"At least one argument expected.")
10396 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10401 for i
in range(sz):
10402 v[i] = args[i].as_ast()
10406 """Create intersection of regular expressions.
10407 >>> re = Intersect(Re("a"), Re("b"), Re("c"))
10409 args = _get_args(args)
10412 _z3_assert(sz > 0,
"At least one argument expected.")
10413 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10418 for i
in range(sz):
10419 v[i] = args[i].as_ast()
10423 """Create the regular expression accepting one or more repetitions of argument.
10424 >>> re = Plus(Re("a"))
10425 >>> print(simplify(InRe("aa", re)))
10427 >>> print(simplify(InRe("ab", re)))
10429 >>> print(simplify(InRe("", re)))
10435 """Create the regular expression that optionally accepts the argument.
10436 >>> re = Option(Re("a"))
10437 >>> print(simplify(InRe("a", re)))
10439 >>> print(simplify(InRe("", re)))
10441 >>> print(simplify(InRe("aa", re)))
10447 """Create the complement regular expression."""
10451 """Create the regular expression accepting zero or more repetitions of argument.
10452 >>> re = Star(Re("a"))
10453 >>> print(simplify(InRe("aa", re)))
10455 >>> print(simplify(InRe("ab", re)))
10457 >>> print(simplify(InRe("", re)))
10463 """Create the regular expression accepting between a lower and upper bound repetitions
10464 >>> re = Loop(Re("a"), 1, 3)
10465 >>> print(simplify(InRe("aa", re)))
10467 >>> print(simplify(InRe("aaaa", re)))
10469 >>> print(simplify(InRe("", re)))
10475 """Create the range regular expression over two sequences of length 1
10476 >>> range = Range("a","z")
10477 >>> print(simplify(InRe("b", range)))
10479 >>> print(simplify(InRe("bb", range)))
10482 lo = _coerce_seq(lo, ctx)
10483 hi = _coerce_seq(hi, ctx)
10501 """Given a binary relation R, such that the two arguments have the same sort
10502 create the transitive closure relation R+.
10503 The transitive closure R+ is a new relation.
10514 if self.
lock is None:
10516 self.
lock = threading.thread.Lock()
10520 r = self.
bases[ctx]
10526 self.
bases[ctx] = r
10531 id = len(self.
bases) + 3
10536 _prop_closures =
None
10539 global _prop_closures
10540 if _prop_closures
is None:
10544 _prop_closures.get(ctx).push();
10547 _prop_closures.get(ctx).pop(num_scopes)
10550 prop = _prop_closures.get(id)
10551 _prop_closures.set_threaded()
10552 new_prop = UsePropagateBase(
None, ctx)
10553 _prop_closures.set(new_prop.id, new_prop.fresh())
10554 return ctypes.c_void_p(new_prop.id)
10557 prop = _prop_closures.get(ctx)
10559 prop.fixed(id, _to_expr_ref(ctypes.c_void_p(value), prop.ctx()))
10563 prop = _prop_closures.get(ctx)
10569 prop = _prop_closures.get(ctx)
10575 prop = _prop_closures.get(ctx)
10580 _user_prop_push = push_eh_type(user_prop_push)
10581 _user_prop_pop = pop_eh_type(user_prop_pop)
10582 _user_prop_fresh = fresh_eh_type(user_prop_fresh)
10583 _user_prop_fixed = fixed_eh_type(user_prop_fixed)
10584 _user_prop_final = final_eh_type(user_prop_final)
10585 _user_prop_eq = eq_eh_type(user_prop_eq)
10586 _user_prop_diseq = eq_eh_type(user_prop_diseq)
10598 assert s
is None or ctx
is None
10603 self.
id = _prop_closures.insert(self)
10611 self.
_ctx.ctx = ctx
10617 ctypes.c_void_p(self.
id),
10624 self.
_ctx.ctx =
None
10633 return self.
ctx().ref()
10636 assert not self.
fixed
10637 assert not self.
_ctx
10642 assert not self.
final
10643 assert not self.
_ctx
10649 assert not self.
_ctx
10654 assert not self.
diseq
10655 assert not self.
_ctx
10660 raise Z3Exception(
"push needs to be overwritten")
10663 raise Z3Exception(
"pop needs to be overwritten")
10666 raise Z3Exception(
"fresh needs to be overwritten")
10670 assert not self.
_ctx
10677 num_fixed = len(ids)
10678 _ids = (ctypes.c_uint * num_fixed)()
10679 for i
in range(num_fixed):
10682 _lhs = (ctypes.c_uint * num_eqs)()
10683 _rhs = (ctypes.c_uint * num_eqs)()
10684 for i
in range(num_eqs):
10685 _lhs[i] = eqs[i][0]
10686 _rhs[i] = eqs[i][1]
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 ...
Z3_ast Z3_API Z3_solver_get_implied_lower(Z3_context c, Z3_solver s, Z3_ast e)
retrieve implied lower bound value for arithmetic expression. If a lower bound is implied at search l...
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_solver_propagate_diseq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression dis-equalities.
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)
def __init__(self, s, 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)
def add_diseq(self, diseq)
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)
def as_binary_string(self)
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.
def user_prop_fixed(ctx, cb, id, value)
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.
def user_prop_fresh(id, ctx)
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)
Z3_string Z3_API Z3_get_numeral_binary_string(Z3_context c, Z3_ast a)
Return numeral value, as a binary string of a numeric constant term.
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.
def ensure_prop_closures()
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].
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
void Z3_API Z3_solver_propagate_init(Z3_context c, Z3_solver s, void *user_context, Z3_push_eh push_eh, Z3_pop_eh pop_eh, Z3_fresh_eh fresh_eh)
register a user-properator with the solver.
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)
def pop(self, num_scopes)
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)
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
def fpRem(a, b, ctx=None)
def add_final(self, final)
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 decimal 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_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.
void Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback, unsigned num_fixed, unsigned const *fixed_ids, unsigned num_eqs, unsigned const *eq_lhs, unsigned const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values. This is a callback a client may invoke during the fixe...
def from_file(self, filename)
def RealVal(val, ctx=None)
def translate(self, target)
def solve(*args, **keywords)
def __rdiv__(self, other)
Z3_ast_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
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 user_prop_eq(ctx, cb, x, y)
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.
def user_prop_diseq(ctx, cb, x, y)
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.
def dimacs(self, include_names=True)
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.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
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.
Z3_ast Z3_API Z3_solver_get_implied_value(Z3_context c, Z3_solver s, Z3_ast e)
retrieve implied value for expression, if any is implied by solver at search level....
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.
void Z3_API Z3_solver_propagate_final(Z3_context c, Z3_solver s, Z3_final_eh final_eh)
register a callback on final check. This provides freedom to the propagator to delay actions or imple...
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 as_binary_string(self)
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.
def user_prop_final(ctx, cb)
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)
def add_fixed(self, fixed)
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.
unsigned Z3_API Z3_solver_propagate_register(Z3_context c, Z3_solver s, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
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_ast Z3_API Z3_solver_get_implied_upper(Z3_context c, Z3_solver s, Z3_ast e)
retrieve implied upper bound value for arithmetic expression. If an upper bound is implied at search ...
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 user_prop_pop(ctx, num_scopes)
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)
void Z3_API Z3_solver_propagate_fixed(Z3_context c, Z3_solver s, Z3_fixed_eh fixed_eh)
register a callback for when an expression is bound to a fixed value. The supported expression types ...
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.
def propagate(self, e, ids, eqs=[])
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.