9"""Z3 is a high performance theorem prover developed at Microsoft Research.
11Z3 is used in many applications such as: software/hardware verification and testing,
12constraint solving, analysis of hybrid systems, security, biology (in silico analysis),
13and geometrical problems.
15Several online tutorials for Z3Py are available at:
16http://rise4fun.com/Z3Py/tutorial/guide
18Please send feedback, comments and/or corrections on the Issue tracker for
19https://github.com/Z3prover/z3.git. Your comments are very valuable.
44...
except Z3Exception
as ex:
45... print(
"failed: %s" % ex)
51from .z3consts import *
52from .z3printer import *
53from fractions import Fraction
58if sys.version_info.major >= 3:
59 from typing
import Iterable
69if sys.version_info.major < 3:
71 return isinstance(v, (int, long))
74 return isinstance(v, int)
86 major = ctypes.c_uint(0)
87 minor = ctypes.c_uint(0)
88 build = ctypes.c_uint(0)
89 rev = ctypes.c_uint(0)
91 return "%s.%s.%s" % (major.value, minor.value, build.value)
95 major = ctypes.c_uint(0)
96 minor = ctypes.c_uint(0)
97 build = ctypes.c_uint(0)
98 rev = ctypes.c_uint(0)
100 return (major.value, minor.value, build.value, rev.value)
110def _z3_assert(cond, msg):
112 raise Z3Exception(msg)
115def _z3_check_cint_overflow(n, name):
116 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
120 """Log interaction to a file. This function must be invoked immediately after init(). """
125 """Append user-defined string to interaction log. """
130 """Convert an integer or string into a Z3 symbol."""
137def _symbol2py(ctx, s):
138 """Convert a Z3 symbol back into a Python object. """
151 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
153 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
154 return [arg
for arg
in args[0]]
163def _get_args_ast_list(args):
165 if isinstance(args, (set, AstVector, tuple)):
166 return [arg
for arg
in args]
173def _to_param_value(val):
174 if isinstance(val, bool):
175 return "true" if val
else "false"
186 """A Context manages all other Z3 objects, global configuration options, etc.
188 Z3Py uses a default global context. For most applications this
is sufficient.
189 An application may use multiple Z3 contexts. Objects created
in one context
190 cannot be used
in another one. However, several objects may be
"translated" from
191 one context to another. It
is not safe to access Z3 objects
from multiple threads.
194 The initialization method receives
global configuration options
for the new context.
199 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
222 """Return a reference to the actual C pointer to the Z3 context."""
226 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
228 This method can be invoked from a thread different
from the one executing the
229 interruptible procedure.
239 """Return a reference to the global Z3 context.
247 >>> x2 =
Real(
'x', c)
254 if _main_ctx
is None:
271 """Set Z3 global (or module) parameters.
276 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
280 if not set_pp_option(k, v):
295 """Reset all global (or module) parameters.
301 """Alias for 'set_param' for backward compatibility.
307 """Return the value of a Z3 global (or module) parameter
312 ptr = (ctypes.c_char_p * 1)()
314 r = z3core._to_pystr(ptr[0])
316 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
328 """Superclass for all Z3 objects that have support for pretty printing."""
333 def _repr_html_(self):
334 in_html = in_html_mode()
337 set_html_mode(in_html)
342 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
350 if self.
ctx.ref()
is not None and self.
ast is not None:
355 return _to_ast_ref(self.
ast, self.
ctx)
358 return obj_to_string(self)
361 return obj_to_string(self)
364 return self.
eq(other)
377 elif is_eq(self)
and self.num_args() == 2:
378 return self.arg(0).
eq(self.arg(1))
380 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
383 """Return a string representing the AST node in s-expression notation.
386 >>> ((x + 1)*x).
sexpr()
392 """Return a pointer to the corresponding C Z3_ast object."""
396 """Return unique identifier for object. It can be used for hash-tables and maps."""
400 """Return a reference to the C context where this AST node is stored."""
401 return self.
ctx.ref()
404 """Return `True` if `self` and `other` are structurally identical.
417 _z3_assert(
is_ast(other),
"Z3 AST expected")
421 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
429 >>> x.translate(c2) + y
433 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
440 """Return a hashcode for the `self`.
444 >>> n1.hash() == n2.hash()
451 """Return `True` if `a` is an AST node.
468 return isinstance(a, AstRef)
472 """Return `True` if `a` and `b` are structurally identical AST nodes.
490def _ast_kind(ctx, a):
496def _ctx_from_ast_arg_list(args, default_ctx=None):
504 _z3_assert(ctx == a.ctx,
"Context mismatch")
510def _ctx_from_ast_args(*args):
511 return _ctx_from_ast_arg_list(args)
514def _to_func_decl_array(args):
516 _args = (FuncDecl * sz)()
518 _args[i] = args[i].as_func_decl()
522def _to_ast_array(args):
526 _args[i] = args[i].as_ast()
530def _to_ref_array(ref, args):
534 _args[i] = args[i].as_ast()
538def _to_ast_ref(a, ctx):
539 k = _ast_kind(ctx, a)
541 return _to_sort_ref(a, ctx)
542 elif k == Z3_FUNC_DECL_AST:
543 return _to_func_decl_ref(a, ctx)
545 return _to_expr_ref(a, ctx)
554def _sort_kind(ctx, s):
559 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
568 """Return the Z3 internal kind of a sort.
569 This method can be used to test if `self`
is one of the Z3 builtin sorts.
572 >>> b.kind() == Z3_BOOL_SORT
574 >>> b.kind() == Z3_INT_SORT
577 >>> A.kind() == Z3_ARRAY_SORT
579 >>> A.kind() == Z3_INT_SORT
582 return _sort_kind(self.
ctx, self.
ast)
585 """Return `True` if `self` is a subsort of `other`.
593 """Try to cast `val` as an element of sort `self`.
595 This method is used
in Z3Py to convert Python objects such
as integers,
596 floats, longs
and strings into Z3 expressions.
603 _z3_assert(
is_expr(val),
"Z3 expression expected")
604 _z3_assert(self.
eq(val.sort()),
"Sort mismatch")
608 """Return the name (string) of sort `self`.
618 """Return `True` if `self` and `other` are the same Z3 sort.
631 """Return `True` if `self` and `other` are not the same Z3 sort.
643 return AstRef.__hash__(self)
647 """Return `True` if `s` is a Z3 sort.
656 return isinstance(s, SortRef)
659def _to_sort_ref(s, ctx):
661 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
662 k = _sort_kind(ctx, s)
663 if k == Z3_BOOL_SORT:
665 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
667 elif k == Z3_BV_SORT:
669 elif k == Z3_ARRAY_SORT:
671 elif k == Z3_DATATYPE_SORT:
673 elif k == Z3_FINITE_DOMAIN_SORT:
675 elif k == Z3_FLOATING_POINT_SORT:
677 elif k == Z3_ROUNDING_MODE_SORT:
679 elif k == Z3_RE_SORT:
681 elif k == Z3_SEQ_SORT:
687 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
691 """Create a new uninterpreted sort named `name`.
693 If `ctx=None`, then the new sort
is declared
in the
global Z3Py context.
696 >>> a =
Const(
'a', A)
697 >>> b =
Const(
'b', A)
716 """Function declaration. Every constant and function have an associated declaration.
718 The declaration assigns a name, a sort (i.e., type), and for function
719 the sort (i.e., type) of each of its arguments. Note that,
in Z3,
720 a constant
is a function
with 0 arguments.
733 """Return the name of the function declaration `self`.
738 >>> isinstance(f.name(), str)
744 """Return the number of arguments of a function declaration.
745 If `self` is a constant, then `self.
arity()`
is 0.
754 """Return the sort of the argument `i` of a function declaration.
755 This method assumes that `0 <= i < self.arity()`.
764 _z3_assert(i < self.
arity(),
"Index out of bounds")
768 """Return the sort of the range of a function declaration.
769 For constants, this is the sort of the constant.
778 """Return the internal kind of a function declaration.
779 It can be used to identify Z3 built-in functions such
as addition, multiplication, etc.
782 >>> d = (x + 1).decl()
783 >>> d.kind() == Z3_OP_ADD
785 >>> d.kind() == Z3_OP_MUL
793 result = [
None for i
in range(n)]
796 if k == Z3_PARAMETER_INT:
798 elif k == Z3_PARAMETER_DOUBLE:
800 elif k == Z3_PARAMETER_RATIONAL:
802 elif k == Z3_PARAMETER_SYMBOL:
804 elif k == Z3_PARAMETER_SORT:
806 elif k == Z3_PARAMETER_AST:
808 elif k == Z3_PARAMETER_FUNC_DECL:
815 """Create a Z3 application expression using the function `self`, and the given arguments.
817 The arguments must be Z3 expressions. This method assumes that
818 the sorts of the elements in `args` match the sorts of the
819 domain. Limited coercion
is supported. For example,
if
820 args[0]
is a Python integer,
and the function expects a Z3
821 integer, then the argument
is automatically converted into a
832 args = _get_args(args)
835 _z3_assert(num == self.
arity(),
"Incorrect number of arguments to %s" % self)
836 _args = (Ast * num)()
841 tmp = self.
domain(i).cast(args[i])
843 _args[i] = tmp.as_ast()
848 """Return `True` if `a` is a Z3 function declaration.
857 return isinstance(a, FuncDeclRef)
861 """Create a new Z3 uninterpreted function with the given sorts.
869 _z3_assert(len(sig) > 0,
"At least two arguments expected")
873 _z3_assert(
is_sort(rng),
"Z3 sort expected")
874 dom = (Sort * arity)()
875 for i
in range(arity):
877 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
884 """Create a new fresh Z3 uninterpreted function with the given sorts.
888 _z3_assert(len(sig) > 0,
"At least two arguments expected")
892 _z3_assert(
is_sort(rng),
"Z3 sort expected")
893 dom = (z3.Sort * arity)()
894 for i
in range(arity):
896 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
902def _to_func_decl_ref(a, ctx):
907 """Create a new Z3 recursive with the given sorts."""
910 _z3_assert(len(sig) > 0,
"At least two arguments expected")
914 _z3_assert(
is_sort(rng),
"Z3 sort expected")
915 dom = (Sort * arity)()
916 for i
in range(arity):
918 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
925 """Set the body of a recursive function.
926 Recursive definitions can be simplified if they are applied to ground
930 >>> n =
Int(
'n', ctx)
935 >>> s.add(fac(n) < 3)
938 >>> s.model().eval(fac(5))
944 args = _get_args(args)
948 _args[i] = args[i].ast
959 """Constraints, formulas and terms are expressions in Z3.
961 Expressions are ASTs. Every expression has a sort.
962 There are three main kinds of expressions:
963 function applications, quantifiers and bounded variables.
964 A constant
is a function application
with 0 arguments.
965 For quantifier free problems, all expressions are
966 function applications.
976 """Return the sort of expression `self`.
988 """Shorthand for `self.sort().kind()`.
991 >>> a.sort_kind() == Z3_ARRAY_SORT
993 >>> a.sort_kind() == Z3_INT_SORT
996 return self.
sort().kind()
999 """Return a Z3 expression that represents the constraint `self == other`.
1001 If `other` is `
None`, then this method simply returns `
False`.
1012 a, b = _coerce_exprs(self, other)
1017 return AstRef.__hash__(self)
1020 """Return a Z3 expression that represents the constraint `self != other`.
1022 If `other` is `
None`, then this method simply returns `
True`.
1033 a, b = _coerce_exprs(self, other)
1034 _args, sz = _to_ast_array((a, b))
1041 """Return the Z3 function declaration associated with a Z3 application.
1052 _z3_assert(
is_app(self),
"Z3 application expected")
1056 """Return the number of arguments of a Z3 application.
1068 _z3_assert(
is_app(self),
"Z3 application expected")
1072 """Return argument `idx` of the application `self`.
1074 This method assumes that `self` is a function application
with at least `idx+1` arguments.
1088 _z3_assert(
is_app(self),
"Z3 application expected")
1089 _z3_assert(idx < self.
num_args(),
"Invalid argument index")
1093 """Return a list containing the children of the given expression
1108def _to_expr_ref(a, ctx):
1109 if isinstance(a, Pattern):
1113 if k == Z3_QUANTIFIER_AST:
1116 if sk == Z3_BOOL_SORT:
1118 if sk == Z3_INT_SORT:
1119 if k == Z3_NUMERAL_AST:
1122 if sk == Z3_REAL_SORT:
1123 if k == Z3_NUMERAL_AST:
1125 if _is_algebraic(ctx, a):
1128 if sk == Z3_BV_SORT:
1129 if k == Z3_NUMERAL_AST:
1133 if sk == Z3_ARRAY_SORT:
1135 if sk == Z3_DATATYPE_SORT:
1137 if sk == Z3_FLOATING_POINT_SORT:
1138 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1141 return FPRef(a, ctx)
1142 if sk == Z3_FINITE_DOMAIN_SORT:
1143 if k == Z3_NUMERAL_AST:
1147 if sk == Z3_ROUNDING_MODE_SORT:
1149 if sk == Z3_SEQ_SORT:
1151 if sk == Z3_RE_SORT:
1152 return ReRef(a, ctx)
1156def _coerce_expr_merge(s, a):
1169 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1170 _z3_assert(
False,
"sort mismatch")
1175def _coerce_exprs(a, b, ctx=None):
1177 a = _py2expr(a, ctx)
1178 b = _py2expr(b, ctx)
1179 if isinstance(a, str)
and isinstance(b, SeqRef):
1181 if isinstance(b, str)
and isinstance(a, SeqRef):
1184 s = _coerce_expr_merge(s, a)
1185 s = _coerce_expr_merge(s, b)
1191def _reduce(func, sequence, initial):
1193 for element
in sequence:
1194 result = func(result, element)
1198def _coerce_expr_list(alist, ctx=None):
1205 alist = [_py2expr(a, ctx)
for a
in alist]
1206 s = _reduce(_coerce_expr_merge, alist,
None)
1207 return [s.cast(a)
for a
in alist]
1211 """Return `True` if `a` is a Z3 expression.
1230 return isinstance(a, ExprRef)
1234 """Return `True` if `a` is a Z3 function application.
1236 Note that, constants are function applications with 0 arguments.
1253 if not isinstance(a, ExprRef):
1255 k = _ast_kind(a.ctx, a)
1256 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1260 """Return `True` if `a` is Z3 constant/variable expression.
1275 return is_app(a)
and a.num_args() == 0
1279 """Return `True` if `a` is variable.
1281 Z3 uses de-Bruijn indices for representing bound variables
in
1291 >>> q =
ForAll(x, f(x) == x)
1300 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1304 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1314 >>> q =
ForAll([x, y], f(x, y) == x + y)
1320 >>> v1 = b.arg(0).arg(0)
1321 >>> v2 = b.arg(0).arg(1)
1332 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1337 """Return `True` if `a` is an application of the given kind `k`.
1346 return is_app(a)
and a.decl().kind() == k
1349def If(a, b, c, ctx=None):
1350 """Create a Z3 if-then-else expression.
1354 >>> max =
If(x > y, x, y)
1360 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1361 return Cond(a, b, c, ctx)
1363 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1366 b, c = _coerce_exprs(b, c, ctx)
1368 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1369 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1373 """Create a Z3 distinct expression.
1387 args = _get_args(args)
1388 ctx = _ctx_from_ast_arg_list(args)
1390 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1391 args = _coerce_expr_list(args, ctx)
1392 _args, sz = _to_ast_array(args)
1396def _mk_bin(f, a, b):
1399 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1400 args[0] = a.as_ast()
1401 args[1] = b.as_ast()
1402 return f(a.ctx.ref(), 2, args)
1406 """Create a constant of the given sort.
1412 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1418 """Create several constants of the given sort.
1420 `names` is a string containing the names of all constants to be created.
1421 Blank spaces separate the names of different constants.
1427 if isinstance(names, str):
1428 names = names.split(
" ")
1429 return [
Const(name, sort)
for name
in names]
1433 """Create a fresh constant of a specified sort"""
1434 ctx = _get_ctx(sort.ctx)
1439 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1447 _z3_assert(
is_sort(s),
"Z3 sort expected")
1448 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1453 Create a real free variable. Free variables are used to create quantified formulas.
1454 They are also used to create polynomials.
1464 Create a list of Real free variables.
1465 The variables have ids: 0, 1, ..., n-1
1484 """Try to cast `val` as a Boolean.
1496 if isinstance(val, bool):
1500 msg =
"True, False or Z3 Boolean expression expected. Received %s of type %s"
1501 _z3_assert(
is_expr(val), msg % (val, type(val)))
1502 if not self.
eq(val.sort()):
1503 _z3_assert(self.
eq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1507 return isinstance(other, ArithSortRef)
1517 """All Boolean expressions are instances of this class."""
1526 """Create the Z3 expression `self * other`.
1532 return If(self, other, 0)
1536 """Return `True` if `a` is a Z3 Boolean expression.
1550 return isinstance(a, BoolRef)
1554 """Return `True` if `a` is the Z3 true expression.
1572 """Return `True` if `a` is the Z3 false expression.
1586 """Return `True` if `a` is a Z3 and expression.
1588 >>> p, q = Bools('p q')
1598 """Return `True` if `a` is a Z3 or expression.
1600 >>> p, q = Bools('p q')
1610 """Return `True` if `a` is a Z3 implication expression.
1612 >>> p, q = Bools('p q')
1622 """Return `True` if `a` is a Z3 not expression.
1634 """Return `True` if `a` is a Z3 equality expression.
1636 >>> x, y = Ints('x y')
1644 """Return `True` if `a` is a Z3 distinct expression.
1646 >>> x, y, z = Ints('x y z')
1656 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1674 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1693 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1705 """Return a tuple of Boolean constants.
1707 `names` is a single string containing all names separated by blank spaces.
1708 If `ctx=
None`, then the
global context
is used.
1710 >>> p, q, r =
Bools(
'p q r')
1711 >>>
And(p,
Or(q, r))
1715 if isinstance(names, str):
1716 names = names.split(
" ")
1717 return [
Bool(name, ctx)
for name
in names]
1721 """Return a list of Boolean constants of size `sz`.
1723 The constants are named using the given prefix.
1724 If `ctx=None`, then the
global context
is used.
1730 And(p__0, p__1, p__2)
1732 return [
Bool(
"%s__%s" % (prefix, i))
for i
in range(sz)]
1736 """Return a fresh Boolean constant in the given context using the given prefix.
1738 If `ctx=None`, then the
global context
is used.
1750 """Create a Z3 implies expression.
1752 >>> p, q = Bools('p q')
1756 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1764 """Create a Z3 Xor expression.
1766 >>> p, q = Bools('p q')
1772 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1780 """Create a Z3 not expression or probe.
1788 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1805def _has_probe(args):
1806 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1814 """Create a Z3 and-expression or and-probe.
1816 >>> p, q, r = Bools('p q r')
1821 And(p__0, p__1, p__2, p__3, p__4)
1825 last_arg = args[len(args) - 1]
1826 if isinstance(last_arg, Context):
1827 ctx = args[len(args) - 1]
1828 args = args[:len(args) - 1]
1829 elif len(args) == 1
and isinstance(args[0], AstVector):
1831 args = [a
for a
in args[0]]
1834 args = _get_args(args)
1835 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1837 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1838 if _has_probe(args):
1839 return _probe_and(args, ctx)
1841 args = _coerce_expr_list(args, ctx)
1842 _args, sz = _to_ast_array(args)
1847 """Create a Z3 or-expression or or-probe.
1849 >>> p, q, r = Bools('p q r')
1854 Or(p__0, p__1, p__2, p__3, p__4)
1858 last_arg = args[len(args) - 1]
1859 if isinstance(last_arg, Context):
1860 ctx = args[len(args) - 1]
1861 args = args[:len(args) - 1]
1862 elif len(args) == 1
and isinstance(args[0], AstVector):
1864 args = [a
for a
in args[0]]
1867 args = _get_args(args)
1868 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1870 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1871 if _has_probe(args):
1872 return _probe_or(args, ctx)
1874 args = _coerce_expr_list(args, ctx)
1875 _args, sz = _to_ast_array(args)
1886 """Patterns are hints for quantifier instantiation.
1898 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1902 >>> q =
ForAll(x, f(x) == 0, patterns = [ f(x) ])
1905 >>> q.num_patterns()
1912 return isinstance(a, PatternRef)
1916 """Create a Z3 multi-pattern using the given expressions `*args`
1924 >>> q.num_patterns()
1932 _z3_assert(len(args) > 0,
"At least one argument expected")
1933 _z3_assert(all([
is_expr(a)
for a
in args]),
"Z3 expressions expected")
1935 args, sz = _to_ast_array(args)
1939def _to_pattern(arg):
1953 """Universally and Existentially quantified formulas."""
1962 """Return the Boolean sort or sort of Lambda."""
1968 """Return `True` if `self` is a universal quantifier.
1972 >>> q =
ForAll(x, f(x) == 0)
1975 >>> q =
Exists(x, f(x) != 0)
1982 """Return `True` if `self` is an existential quantifier.
1986 >>> q =
ForAll(x, f(x) == 0)
1989 >>> q =
Exists(x, f(x) != 0)
1996 """Return `True` if `self` is a lambda expression.
2003 >>> q =
Exists(x, f(x) != 0)
2010 """Return the Z3 expression `self[arg]`.
2013 _z3_assert(self.
is_lambda(),
"quantifier should be a lambda expression")
2018 """Return the weight annotation of `self`.
2022 >>> q =
ForAll(x, f(x) == 0)
2025 >>> q =
ForAll(x, f(x) == 0, weight=10)
2032 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2037 >>> q =
ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2038 >>> q.num_patterns()
2044 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2049 >>> q =
ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2050 >>> q.num_patterns()
2058 _z3_assert(idx < self.
num_patterns(),
"Invalid pattern idx")
2062 """Return the number of no-patterns."""
2066 """Return a no-pattern."""
2072 """Return the expression being quantified.
2076 >>> q =
ForAll(x, f(x) == 0)
2083 """Return the number of variables bounded by this quantifier.
2088 >>> q =
ForAll([x, y], f(x, y) >= x)
2095 """Return a string representing a name used when displaying the quantifier.
2100 >>> q =
ForAll([x, y], f(x, y) >= x)
2107 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
2111 """Return the sort of a bound variable.
2116 >>> q =
ForAll([x, y], f(x, y) >= x)
2123 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
2127 """Return a list containing a single element self.body()
2131 >>> q =
ForAll(x, f(x) == 0)
2135 return [self.
body()]
2139 """Return `True` if `a` is a Z3 quantifier.
2143 >>> q =
ForAll(x, f(x) == 0)
2149 return isinstance(a, QuantifierRef)
2152def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2154 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2155 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2156 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2157 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2168 _vs = (Ast * num_vars)()
2169 for i
in range(num_vars):
2171 _vs[i] = vs[i].as_ast()
2172 patterns = [_to_pattern(p)
for p
in patterns]
2173 num_pats = len(patterns)
2174 _pats = (Pattern * num_pats)()
2175 for i
in range(num_pats):
2176 _pats[i] = patterns[i].ast
2177 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2183 num_no_pats, _no_pats,
2184 body.as_ast()), ctx)
2187def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2188 """Create a Z3 forall formula.
2190 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2195 >>>
ForAll([x, y], f(x, y) >= x)
2196 ForAll([x, y], f(x, y) >= x)
2197 >>>
ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2198 ForAll([x, y], f(x, y) >= x)
2199 >>>
ForAll([x, y], f(x, y) >= x, weight=10)
2200 ForAll([x, y], f(x, y) >= x)
2202 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2205def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2206 """Create a Z3 exists formula.
2208 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2214 >>> q =
Exists([x, y], f(x, y) >= x, skid=
"foo")
2216 Exists([x, y], f(x, y) >= x)
2219 >>> r =
Tactic(
'nnf')(q).as_expr()
2223 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2227 """Create a Z3 lambda expression.
2231 >>> lo, hi, e, i =
Ints(
'lo hi e i')
2232 >>> mem1 =
Lambda([i],
If(
And(lo <= i, i <= hi), e, mem0[i]))
2240 _vs = (Ast * num_vars)()
2241 for i
in range(num_vars):
2243 _vs[i] = vs[i].as_ast()
2254 """Real and Integer sorts."""
2257 """Return `True` if `self` is of the sort Real.
2268 return self.
kind() == Z3_REAL_SORT
2271 """Return `True` if `self` is of the sort Integer.
2282 return self.
kind() == Z3_INT_SORT
2285 """Return `True` if `self` is a subsort of `other`."""
2289 """Try to cast `val` as an Integer or Real.
2304 _z3_assert(self.
ctxctx == val.ctx,
"Context mismatch")
2308 if val_s.is_int()
and self.
is_real():
2310 if val_s.is_bool()
and self.
is_int():
2311 return If(val, 1, 0)
2312 if val_s.is_bool()
and self.
is_real():
2315 _z3_assert(
False,
"Z3 Integer/Real expression expected")
2322 msg =
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2323 _z3_assert(
False, msg % self)
2327 """Return `True` if s is an arithmetical sort (type).
2335 >>> n =
Int(
'x') + 1
2339 return isinstance(s, ArithSortRef)
2343 """Integer and Real expressions."""
2346 """Return the sort (type) of the arithmetical expression `self`.
2356 """Return `True` if `self` is an integer expression.
2370 """Return `True` if `self` is an real expression.
2381 """Create the Z3 expression `self + other`.
2390 a, b = _coerce_exprs(self, other)
2391 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctx)
2394 """Create the Z3 expression `other + self`.
2400 a, b = _coerce_exprs(self, other)
2401 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctx)
2404 """Create the Z3 expression `self * other`.
2413 if isinstance(other, BoolRef):
2414 return If(other, self, 0)
2415 a, b = _coerce_exprs(self, other)
2416 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctx)
2419 """Create the Z3 expression `other * self`.
2425 a, b = _coerce_exprs(self, other)
2426 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctx)
2429 """Create the Z3 expression `self - other`.
2438 a, b = _coerce_exprs(self, other)
2439 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctx)
2442 """Create the Z3 expression `other - self`.
2448 a, b = _coerce_exprs(self, other)
2449 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctx)
2452 """Create the Z3 expression `self**other` (** is the power operator).
2462 a, b = _coerce_exprs(self, other)
2466 """Create the Z3 expression `other**self` (** is the power operator).
2476 a, b = _coerce_exprs(self, other)
2480 """Create the Z3 expression `other/self`.
2499 a, b = _coerce_exprs(self, other)
2503 """Create the Z3 expression `other/self`."""
2507 """Create the Z3 expression `other/self`.
2520 a, b = _coerce_exprs(self, other)
2524 """Create the Z3 expression `other/self`."""
2528 """Create the Z3 expression `other%self`.
2537 a, b = _coerce_exprs(self, other)
2539 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2543 """Create the Z3 expression `other%self`.
2549 a, b = _coerce_exprs(self, other)
2551 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2555 """Return an expression representing `-self`.
2575 """Create the Z3 expression `other <= self`.
2577 >>> x, y = Ints('x y')
2584 a, b = _coerce_exprs(self, other)
2588 """Create the Z3 expression `other < self`.
2590 >>> x, y = Ints('x y')
2597 a, b = _coerce_exprs(self, other)
2601 """Create the Z3 expression `other > self`.
2603 >>> x, y = Ints('x y')
2610 a, b = _coerce_exprs(self, other)
2614 """Create the Z3 expression `other >= self`.
2616 >>> x, y = Ints('x y')
2623 a, b = _coerce_exprs(self, other)
2628 """Return `True` if `a` is an arithmetical expression.
2645 return isinstance(a, ArithRef)
2649 """Return `True` if `a` is an integer expression.
2668 """Return `True` if `a` is a real expression.
2686def _is_numeral(ctx, a):
2690def _is_algebraic(ctx, a):
2695 """Return `True` if `a` is an integer value of sort Int.
2703 >>> n =
Int(
'x') + 1
2715 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2719 """Return `True` if `a` is rational value of sort Real.
2729 >>> n =
Real(
'x') + 1
2737 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2741 """Return `True` if `a` is an algebraic value of sort Real.
2751 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2755 """Return `True` if `a` is an expression of the form b + c.
2757 >>> x, y = Ints('x y')
2767 """Return `True` if `a` is an expression of the form b * c.
2769 >>> x, y = Ints('x y')
2779 """Return `True` if `a` is an expression of the form b - c.
2781 >>> x, y = Ints('x y')
2791 """Return `True` if `a` is an expression of the form b / c.
2793 >>> x, y = Reals('x y')
2798 >>> x, y =
Ints(
'x y')
2808 """Return `True` if `a` is an expression of the form b div c.
2810 >>> x, y = Ints('x y')
2820 """Return `True` if `a` is an expression of the form b % c.
2822 >>> x, y = Ints('x y')
2832 """Return `True` if `a` is an expression of the form b <= c.
2834 >>> x, y = Ints('x y')
2844 """Return `True` if `a` is an expression of the form b < c.
2846 >>> x, y = Ints('x y')
2856 """Return `True` if `a` is an expression of the form b >= c.
2858 >>> x, y = Ints('x y')
2868 """Return `True` if `a` is an expression of the form b > c.
2870 >>> x, y = Ints('x y')
2880 """Return `True` if `a` is an expression of the form IsInt(b).
2892 """Return `True` if `a` is an expression of the form ToReal(b).
2907 """Return `True` if `a` is an expression of the form ToInt(b).
2922 """Integer values."""
2925 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2934 _z3_assert(self.
is_int(),
"Integer value expected")
2938 """Return a Z3 integer numeral as a Python string.
2946 """Return a Z3 integer numeral as a Python binary string.
2948 >>> v.as_binary_string()
2955 """Rational values."""
2958 """ Return the numerator of a Z3 rational numeral.
2973 """ Return the denominator of a Z3 rational numeral.
2984 """ Return the numerator as a Python long.
2991 >>> v.numerator_as_long() + 1 == 10000000001
2997 """ Return the denominator as a Python long.
3002 >>> v.denominator_as_long()
3017 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
3021 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3033 """Return a Z3 rational numeral as a Python string.
3042 """Return a Z3 rational as a Python Fraction object.
3052 """Algebraic irrational values."""
3055 """Return a Z3 rational number that approximates the algebraic number `self`.
3056 The result `r` is such that |r - self| <= 1/10^precision
3060 6838717160008073720548335/4835703278458516698824704
3067 """Return a string representation of the algebraic number `self` in decimal notation
3068 using `prec` decimal places.
3071 >>> x.as_decimal(10)
3073 >>> x.as_decimal(20)
3074 '1.41421356237309504880?'
3085def _py2expr(a, ctx=None):
3086 if isinstance(a, bool):
3090 if isinstance(a, float):
3092 if isinstance(a, str):
3097 _z3_assert(
False,
"Python bool, int, long or float expected")
3101 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3118 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3134def _to_int_str(val):
3135 if isinstance(val, float):
3136 return str(int(val))
3137 elif isinstance(val, bool):
3144 elif isinstance(val, str):
3147 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
3151 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3163 """Return a Z3 real value.
3165 `val` may be a Python int, long, float or string representing a number
in decimal
or rational notation.
3166 If `ctx=
None`, then the
global context
is used.
3182 """Return a Z3 rational a/b.
3184 If `ctx=None`, then the
global context
is used.
3192 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3193 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3197def Q(a, b, ctx=None):
3198 """Return a Z3 rational a/b.
3200 If `ctx=None`, then the
global context
is used.
3211 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3224 """Return a tuple of Integer constants.
3226 >>> x, y, z = Ints('x y z')
3231 if isinstance(names, str):
3232 names = names.split(
" ")
3233 return [
Int(name, ctx)
for name
in names]
3237 """Return a list of integer constants of size `sz`.
3246 return [
Int(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3250 """Return a fresh integer constant in the given context using the given prefix.
3264 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3277 """Return a tuple of real constants.
3279 >>> x, y, z = Reals('x y z')
3282 >>>
Sum(x, y, z).sort()
3286 if isinstance(names, str):
3287 names = names.split(
" ")
3288 return [
Real(name, ctx)
for name
in names]
3292 """Return a list of real constants of size `sz`.
3303 return [
Real(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3307 """Return a fresh real constant in the given context using the given prefix.
3321 """ Return the Z3 expression ToReal(a).
3333 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3339 """ Return the Z3 expression ToInt(a).
3351 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3357 """ Return the Z3 predicate IsInt(a).
3360 >>>
IsInt(x +
"1/2")
3364 >>>
solve(
IsInt(x +
"1/2"), x > 0, x < 1, x !=
"1/2")
3368 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3374 """ Return a Z3 expression which represents the square root of a.
3387 """ Return a Z3 expression which represents the cubic root of a.
3406 """Bit-vector sort."""
3409 """Return the size (number of bits) of the bit-vector sort `self`.
3421 """Try to cast `val` as a Bit-Vector.
3426 >>> b.cast(10).sexpr()
3431 _z3_assert(self.
ctxctx == val.ctx,
"Context mismatch")
3439 """Return True if `s` is a Z3 bit-vector sort.
3446 return isinstance(s, BitVecSortRef)
3450 """Bit-vector expressions."""
3453 """Return the sort of the bit-vector expression `self`.
3464 """Return the number of bits of the bit-vector expression `self`.
3475 """Create the Z3 expression `self + other`.
3484 a, b = _coerce_exprs(self, other)
3488 """Create the Z3 expression `other + self`.
3494 a, b = _coerce_exprs(self, other)
3498 """Create the Z3 expression `self * other`.
3507 a, b = _coerce_exprs(self, other)
3511 """Create the Z3 expression `other * self`.
3517 a, b = _coerce_exprs(self, other)
3521 """Create the Z3 expression `self - other`.
3530 a, b = _coerce_exprs(self, other)
3534 """Create the Z3 expression `other - self`.
3540 a, b = _coerce_exprs(self, other)
3544 """Create the Z3 expression bitwise-or `self | other`.
3553 a, b = _coerce_exprs(self, other)
3557 """Create the Z3 expression bitwise-or `other | self`.
3563 a, b = _coerce_exprs(self, other)
3567 """Create the Z3 expression bitwise-and `self & other`.
3576 a, b = _coerce_exprs(self, other)
3580 """Create the Z3 expression bitwise-or `other & self`.
3586 a, b = _coerce_exprs(self, other)
3590 """Create the Z3 expression bitwise-xor `self ^ other`.
3599 a, b = _coerce_exprs(self, other)
3603 """Create the Z3 expression bitwise-xor `other ^ self`.
3609 a, b = _coerce_exprs(self, other)
3622 """Return an expression representing `-self`.
3633 """Create the Z3 expression bitwise-not `~self`.
3644 """Create the Z3 expression (signed) division `self / other`.
3646 Use the function UDiv() for unsigned division.
3659 a, b = _coerce_exprs(self, other)
3663 """Create the Z3 expression (signed) division `self / other`."""
3667 """Create the Z3 expression (signed) division `other / self`.
3669 Use the function UDiv() for unsigned division.
3674 >>> (10 / x).
sexpr()
3675 '(bvsdiv #x0000000a x)'
3677 '(bvudiv #x0000000a x)'
3679 a, b = _coerce_exprs(self, other)
3683 """Create the Z3 expression (signed) division `other / self`."""
3687 """Create the Z3 expression (signed) mod `self % other`.
3689 Use the function URem() for unsigned remainder,
and SRem()
for signed remainder.
3704 a, b = _coerce_exprs(self, other)
3708 """Create the Z3 expression (signed) mod `other % self`.
3710 Use the function URem() for unsigned remainder,
and SRem()
for signed remainder.
3715 >>> (10 % x).
sexpr()
3716 '(bvsmod #x0000000a x)'
3718 '(bvurem #x0000000a x)'
3720 '(bvsrem #x0000000a x)'
3722 a, b = _coerce_exprs(self, other)
3726 """Create the Z3 expression (signed) `other <= self`.
3728 Use the function ULE() for unsigned less than
or equal to.
3733 >>> (x <= y).
sexpr()
3738 a, b = _coerce_exprs(self, other)
3742 """Create the Z3 expression (signed) `other < self`.
3744 Use the function ULT() for unsigned less than.
3754 a, b = _coerce_exprs(self, other)
3758 """Create the Z3 expression (signed) `other > self`.
3760 Use the function UGT() for unsigned greater than.
3770 a, b = _coerce_exprs(self, other)
3774 """Create the Z3 expression (signed) `other >= self`.
3776 Use the function UGE() for unsigned greater than
or equal to.
3781 >>> (x >= y).
sexpr()
3786 a, b = _coerce_exprs(self, other)
3790 """Create the Z3 expression (arithmetical) right shift `self >> other`
3792 Use the function LShR() for the right logical shift
3797 >>> (x >> y).
sexpr()
3816 a, b = _coerce_exprs(self, other)
3820 """Create the Z3 expression left shift `self << other`
3825 >>> (x << y).
sexpr()
3830 a, b = _coerce_exprs(self, other)
3834 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3836 Use the function LShR() for the right logical shift
3841 >>> (10 >> x).
sexpr()
3842 '(bvashr #x0000000a x)'
3844 a, b = _coerce_exprs(self, other)
3848 """Create the Z3 expression left shift `other << self`.
3850 Use the function LShR() for the right logical shift
3855 >>> (10 << x).
sexpr()
3856 '(bvshl #x0000000a x)'
3858 a, b = _coerce_exprs(self, other)
3863 """Bit-vector values."""
3866 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3871 >>> print("0x%.8x" % v.as_long())
3877 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3878 The most significant bit is assumed to be the sign.
3893 if val >= 2**(sz - 1):
3895 if val < -2**(sz - 1):
3907 """Return `True` if `a` is a Z3 bit-vector expression.
3917 return isinstance(a, BitVecRef)
3921 """Return `True` if `a` is a Z3 bit-vector numeral value.
3932 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3936 """Return the Z3 expression BV2Int(a).
3944 >>> x >
BV2Int(b, is_signed=
False)
3946 >>> x >
BV2Int(b, is_signed=
True)
3952 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3959 """Return the z3 expression Int2BV(a, num_bits).
3960 It is a bit-vector of width num_bits
and represents the
3961 modulo of a by 2^num_bits
3968 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
3974 >>> x = Const('x', Byte)
3983 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
3988 >>> print("0x%.8x" % v.as_long())
4000 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4001 If `ctx=None`, then the
global context
is used.
4011 >>> x2 =
BitVec(
'x', word)
4015 if isinstance(bv, BitVecSortRef):
4024 """Return a tuple of bit-vector constants of size bv.
4026 >>> x, y, z = BitVecs('x y z', 16)
4039 if isinstance(names, str):
4040 names = names.split(
" ")
4041 return [
BitVec(name, bv, ctx)
for name
in names]
4045 """Create a Z3 bit-vector concatenation expression.
4055 args = _get_args(args)
4058 _z3_assert(sz >= 2,
"At least two arguments expected.")
4065 if is_seq(args[0])
or isinstance(args[0], str):
4066 args = [_coerce_seq(s, ctx)
for s
in args]
4068 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
4071 v[i] = args[i].as_ast()
4076 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
4079 v[i] = args[i].as_ast()
4083 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
4085 for i
in range(sz - 1):
4091 """Create a Z3 bit-vector extraction expression.
4092 Extract is overloaded to also work on sequence extraction.
4093 The functions SubString
and SubSeq are redirected to Extract.
4094 For this case, the arguments are reinterpreted
as:
4095 high -
is a sequence (string)
4097 a -
is the length to be extracted
4107 if isinstance(high, str):
4111 offset, length = _coerce_exprs(low, a, s.ctx)
4114 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
4115 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
4116 "First and second arguments must be non negative integers")
4117 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
4121def _check_bv_args(a, b):
4123 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
4127 """Create the Z3 expression (unsigned) `other <= self`.
4129 Use the operator <= for signed less than
or equal to.
4134 >>> (x <= y).sexpr()
4136 >>>
ULE(x, y).sexpr()
4139 _check_bv_args(a, b)
4140 a, b = _coerce_exprs(a, b)
4145 """Create the Z3 expression (unsigned) `other < self`.
4147 Use the operator < for signed less than.
4154 >>>
ULT(x, y).sexpr()
4157 _check_bv_args(a, b)
4158 a, b = _coerce_exprs(a, b)
4163 """Create the Z3 expression (unsigned) `other >= self`.
4165 Use the operator >= for signed greater than
or equal to.
4170 >>> (x >= y).sexpr()
4172 >>>
UGE(x, y).sexpr()
4175 _check_bv_args(a, b)
4176 a, b = _coerce_exprs(a, b)
4181 """Create the Z3 expression (unsigned) `other > self`.
4183 Use the operator > for signed greater than.
4190 >>>
UGT(x, y).sexpr()
4193 _check_bv_args(a, b)
4194 a, b = _coerce_exprs(a, b)
4199 """Create the Z3 expression (unsigned) division `self / other`.
4201 Use the operator / for signed division.
4207 >>>
UDiv(x, y).sort()
4211 >>>
UDiv(x, y).sexpr()
4214 _check_bv_args(a, b)
4215 a, b = _coerce_exprs(a, b)
4220 """Create the Z3 expression (unsigned) remainder `self % other`.
4222 Use the operator % for signed modulus,
and SRem()
for signed remainder.
4228 >>>
URem(x, y).sort()
4232 >>>
URem(x, y).sexpr()
4235 _check_bv_args(a, b)
4236 a, b = _coerce_exprs(a, b)
4241 """Create the Z3 expression signed remainder.
4243 Use the operator % for signed modulus,
and URem()
for unsigned remainder.
4249 >>>
SRem(x, y).sort()
4253 >>>
SRem(x, y).sexpr()
4256 _check_bv_args(a, b)
4257 a, b = _coerce_exprs(a, b)
4262 """Create the Z3 expression logical right shift.
4264 Use the operator >> for the arithmetical right shift.
4269 >>> (x >> y).sexpr()
4271 >>>
LShR(x, y).sexpr()
4288 _check_bv_args(a, b)
4289 a, b = _coerce_exprs(a, b)
4294 """Return an expression representing `a` rotated to the left `b` times.
4304 _check_bv_args(a, b)
4305 a, b = _coerce_exprs(a, b)
4310 """Return an expression representing `a` rotated to the right `b` times.
4320 _check_bv_args(a, b)
4321 a, b = _coerce_exprs(a, b)
4326 """Return a bit-vector expression with `n` extra sign-bits.
4346 >>> print(
"%.x" % v.as_long())
4350 _z3_assert(_is_int(n),
"First argument must be an integer")
4351 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4356 """Return a bit-vector expression with `n` extra zero-bits.
4378 _z3_assert(_is_int(n),
"First argument must be an integer")
4379 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4384 """Return an expression representing `n` copies of `a`.
4393 >>> print(
"%.x" % v0.as_long())
4398 >>> print(
"%.x" % v.as_long())
4402 _z3_assert(_is_int(n),
"First argument must be an integer")
4403 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4408 """Return the reduction-and expression of `a`."""
4410 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4415 """Return the reduction-or expression of `a`."""
4417 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4422 """A predicate the determines that bit-vector addition does not overflow"""
4423 _check_bv_args(a, b)
4424 a, b = _coerce_exprs(a, b)
4429 """A predicate the determines that signed bit-vector addition does not underflow"""
4430 _check_bv_args(a, b)
4431 a, b = _coerce_exprs(a, b)
4436 """A predicate the determines that bit-vector subtraction does not overflow"""
4437 _check_bv_args(a, b)
4438 a, b = _coerce_exprs(a, b)
4443 """A predicate the determines that bit-vector subtraction does not underflow"""
4444 _check_bv_args(a, b)
4445 a, b = _coerce_exprs(a, b)
4450 """A predicate the determines that bit-vector signed division does not overflow"""
4451 _check_bv_args(a, b)
4452 a, b = _coerce_exprs(a, b)
4457 """A predicate the determines that bit-vector unary negation does not overflow"""
4459 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4464 """A predicate the determines that bit-vector multiplication does not overflow"""
4465 _check_bv_args(a, b)
4466 a, b = _coerce_exprs(a, b)
4471 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4472 _check_bv_args(a, b)
4473 a, b = _coerce_exprs(a, b)
4487 """Return the domain of the array sort `self`.
4496 """Return the range of the array sort `self`.
4506 """Array expressions. """
4509 """Return the array sort of the array expression `self`.
4518 """Shorthand for `self.sort().domain()`.
4527 """Shorthand for `self.sort().range()`.
4536 """Return the Z3 expression `self[arg]`.
4545 arg = self.domain().cast(arg)
4557 """Return `True` if `a` is a Z3 array expression.
4567 return isinstance(a, ArrayRef)
4571 """Return `True` if `a` is a Z3 constant array.
4584 """Return `True` if `a` is a Z3 constant array.
4597 """Return `True` if `a` is a Z3 map array expression.
4613 """Return `True` if `a` is a Z3 default array expression.
4618 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4622 """Return the function declaration associated with a Z3 map array expression.
4635 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4646 """Return the Z3 array sort with the given domain and range sorts.
4659 sig = _get_args(sig)
4661 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4662 arity = len(sig) - 1
4667 _z3_assert(
is_sort(s),
"Z3 sort expected")
4668 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4672 dom = (Sort * arity)()
4673 for i
in range(arity):
4679 """Return an array constant named `name` with the given domain and range sorts.
4693 """Return a Z3 store array expression.
4696 >>> i, v =
Ints(
'i v')
4700 >>>
prove(s[i] == v)
4707 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4708 i = a.sort().domain().cast(i)
4709 v = a.sort().
range().cast(v)
4711 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4715 """ Return a default value for array expression.
4721 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4726 """Return a Z3 store array expression.
4729 >>> i, v =
Ints(
'i v')
4730 >>> s =
Store(a, i, v)
4733 >>>
prove(s[i] == v)
4743 """Return a Z3 select array expression.
4753 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4758 """Return a Z3 map array expression.
4763 >>> b =
Map(f, a1, a2)
4766 >>>
prove(b[0] == f(a1[0], a2[0]))
4769 args = _get_args(args)
4771 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4772 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4773 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4774 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4775 _args, sz = _to_ast_array(args)
4781 """Return a Z3 constant array expression.
4795 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4798 v = _py2expr(v, ctx)
4803 """Return extensionality index for one-dimensional arrays.
4811 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4816 k = _py2expr(k, ctx)
4821 """Return `True` if `a` is a Z3 array select application.
4834 """Return `True` if `a` is a Z3 array store application.
4852 """ Create a set sort over element sort s"""
4857 """Create the empty set
4866 """Create the full set
4875 """ Take the union of sets
4881 args = _get_args(args)
4882 ctx = _ctx_from_ast_arg_list(args)
4883 _args, sz = _to_ast_array(args)
4888 """ Take the union of sets
4894 args = _get_args(args)
4895 ctx = _ctx_from_ast_arg_list(args)
4896 _args, sz = _to_ast_array(args)
4901 """ Add element e to set s
4906 ctx = _ctx_from_ast_arg_list([s, e])
4907 e = _py2expr(e, ctx)
4912 """ Remove element e to set s
4917 ctx = _ctx_from_ast_arg_list([s, e])
4918 e = _py2expr(e, ctx)
4923 """ The complement of set s
4933 """ The set difference of a and b
4939 ctx = _ctx_from_ast_arg_list([a, b])
4944 """ Check if e is a member of set s
4949 ctx = _ctx_from_ast_arg_list([s, e])
4950 e = _py2expr(e, ctx)
4955 """ Check if a is a subset of b
4961 ctx = _ctx_from_ast_arg_list([a, b])
4971def _valid_accessor(acc):
4972 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
4973 if not isinstance(acc, tuple):
4977 return isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4981 """Helper class for declaring Z3 datatypes.
4984 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
4985 >>> List.declare(
'nil')
4986 >>> List = List.create()
4990 >>> List.cons(10, List.nil)
4992 >>> List.cons(10, List.nil).sort()
4994 >>> cons = List.cons
4998 >>> n = cons(1, cons(0, nil))
5000 cons(1, cons(0, nil))
5019 _z3_assert(isinstance(name, str),
"String expected")
5020 _z3_assert(isinstance(rec_name, str),
"String expected")
5022 all([_valid_accessor(a)
for a
in args]),
5023 "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)",
5028 """Declare constructor named `name` with the given accessors `args`.
5029 Each accessor is a pair `(name, sort)`, where `name`
is a string
and `sort` a Z3 sort
5030 or a reference to the datatypes being declared.
5032 In the following example `List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))`
5033 declares the constructor named `cons` that builds a new List using an integer
and a List.
5034 It also declares the accessors `car`
and `cdr`. The accessor `car` extracts the integer
5035 of a `cons` cell,
and `cdr` the list of a `cons` cell. After all constructors were declared,
5036 we use the method
create() to create the actual datatype
in Z3.
5039 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5040 >>> List.declare(
'nil')
5041 >>> List = List.create()
5044 _z3_assert(isinstance(name, str),
"String expected")
5045 _z3_assert(name !=
"",
"Constructor name cannot be empty")
5052 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
5054 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
5057 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5058 >>> List.declare(
'nil')
5059 >>> List = List.create()
5062 >>> List.cons(10, List.nil)
5069 """Auxiliary object used to create Z3 datatypes."""
5076 if self.
ctx.ref()
is not None:
5081 """Auxiliary object used to create Z3 datatypes."""
5088 if self.
ctx.ref()
is not None:
5093 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5095 In the following example we define a Tree-List using two mutually recursive datatypes.
5097 >>> TreeList = Datatype('TreeList')
5100 >>> Tree.declare(
'leaf', (
'val',
IntSort()))
5102 >>> Tree.declare(
'node', (
'children', TreeList))
5103 >>> TreeList.declare(
'nil')
5104 >>> TreeList.declare(
'cons', (
'car', Tree), (
'cdr', TreeList))
5106 >>> Tree.val(Tree.leaf(10))
5108 >>>
simplify(Tree.val(Tree.leaf(10)))
5110 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5112 node(cons(leaf(10), cons(leaf(20), nil)))
5113 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5116 >>>
simplify(TreeList.car(Tree.children(n2)) == n1)
5121 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
5122 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
5123 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
5124 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
5127 names = (Symbol * num)()
5128 out = (Sort * num)()
5129 clists = (ConstructorList * num)()
5131 for i
in range(num):
5134 num_cs = len(d.constructors)
5135 cs = (Constructor * num_cs)()
5136 for j
in range(num_cs):
5137 c = d.constructors[j]
5142 fnames = (Symbol * num_fs)()
5143 sorts = (Sort * num_fs)()
5144 refs = (ctypes.c_uint * num_fs)()
5145 for k
in range(num_fs):
5149 if isinstance(ftype, Datatype):
5152 ds.count(ftype) == 1,
5153 "One and only one occurrence of each datatype is expected",
5156 refs[k] = ds.index(ftype)
5159 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
5160 sorts[k] = ftype.ast
5169 for i
in range(num):
5171 num_cs = dref.num_constructors()
5172 for j
in range(num_cs):
5173 cref = dref.constructor(j)
5174 cref_name = cref.name()
5175 cref_arity = cref.arity()
5176 if cref.arity() == 0:
5178 setattr(dref, cref_name, cref)
5179 rref = dref.recognizer(j)
5180 setattr(dref,
"is_" + cref_name, rref)
5181 for k
in range(cref_arity):
5182 aref = dref.accessor(j, k)
5183 setattr(dref, aref.name(), aref)
5185 return tuple(result)
5189 """Datatype sorts."""
5192 """Return the number of constructors in the given Z3 datatype.
5195 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5196 >>> List.declare(
'nil')
5197 >>> List = List.create()
5199 >>> List.num_constructors()
5205 """Return a constructor of the datatype `self`.
5208 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5209 >>> List.declare(
'nil')
5210 >>> List = List.create()
5212 >>> List.num_constructors()
5214 >>> List.constructor(0)
5216 >>> List.constructor(1)
5224 """In Z3, each constructor has an associated recognizer predicate.
5226 If the constructor is named `name`, then the recognizer `is_name`.
5229 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5230 >>> List.declare(
'nil')
5231 >>> List = List.create()
5233 >>> List.num_constructors()
5235 >>> List.recognizer(0)
5237 >>> List.recognizer(1)
5239 >>>
simplify(List.is_nil(List.cons(10, List.nil)))
5241 >>>
simplify(List.is_cons(List.cons(10, List.nil)))
5243 >>> l =
Const(
'l', List)
5252 """In Z3, each constructor has 0 or more accessor.
5253 The number of accessors is equal to the arity of the constructor.
5256 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5257 >>> List.declare(
'nil')
5258 >>> List = List.create()
5259 >>> List.num_constructors()
5261 >>> List.constructor(0)
5263 >>> num_accs = List.constructor(0).arity()
5266 >>> List.accessor(0, 0)
5268 >>> List.accessor(0, 1)
5270 >>> List.constructor(1)
5272 >>> num_accs = List.constructor(1).arity()
5278 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
5286 """Datatype expressions."""
5289 """Return the datatype sort of the datatype expression `self`."""
5294 """Create a named tuple sort base on a set of underlying sorts
5299 projects = [("project%d" % i, sorts[i])
for i
in range(len(sorts))]
5300 tuple.declare(name, *projects)
5301 tuple = tuple.create()
5302 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5306 """Create a named tagged union sort base on a set of underlying sorts
5311 for i
in range(len(sorts)):
5312 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5314 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5318 """Return a new enumeration sort named `name` containing the given values.
5320 The result is a pair (sort, list of constants).
5322 >>> Color, (red, green, blue) =
EnumSort(
'Color', [
'red',
'green',
'blue'])
5325 _z3_assert(isinstance(name, str),
"Name must be a string")
5326 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5327 _z3_assert(len(values) > 0,
"At least one value expected")
5330 _val_names = (Symbol * num)()
5331 for i
in range(num):
5333 _values = (FuncDecl * num)()
5334 _testers = (FuncDecl * num)()
5338 for i
in range(num):
5340 V = [a()
for a
in V]
5351 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5353 Consider using the function `args2params` to create instances of this object.
5368 if self.
ctx.ref()
is not None:
5372 """Set parameter name with value val."""
5374 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5376 if isinstance(val, bool):
5380 elif isinstance(val, float):
5382 elif isinstance(val, str):
5386 _z3_assert(
False,
"invalid parameter value")
5392 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5397 """Convert python arguments into a Z3_params object.
5398 A ':' is added to the keywords,
and '_' is replaced
with '-'
5400 >>>
args2params([
'model',
True,
'relevancy', 2], {
'elim_and' :
True})
5401 (params model true relevancy 2 elim_and true)
5404 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5420 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5424 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5430 return ParamsDescrsRef(self.
descr, self.
ctx)
5433 if self.
ctx.ref()
is not None:
5437 """Return the size of in the parameter description `self`.
5442 """Return the size of in the parameter description `self`.
5447 """Return the i-th parameter name in the parameter description `self`.
5452 """Return the kind of the parameter named `n`.
5457 """Return the documentation string of the parameter named `n`.
5478 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5480 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5481 A goal has a solution if one of its subgoals has a solution.
5482 A goal
is unsatisfiable
if all subgoals are unsatisfiable.
5485 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5487 _z3_assert(goal
is None or ctx
is not None,
5488 "If goal is different from None, then ctx must be also different from None")
5491 if self.
goal is None:
5496 if self.
goal is not None and self.
ctx.ref()
is not None:
5500 """Return the depth of the goal `self`.
5501 The depth corresponds to the number of tactics applied to `self`.
5503 >>> x, y = Ints('x y')
5505 >>> g.add(x == 0, y >= x + 1)
5508 >>> r =
Then(
'simplify',
'solve-eqs')(g)
5518 """Return `True` if `self` contains the `False` constraints.
5520 >>> x, y = Ints('x y')
5522 >>> g.inconsistent()
5524 >>> g.add(x == 0, x == 1)
5527 >>> g.inconsistent()
5529 >>> g2 =
Tactic(
'propagate-values')(g)[0]
5530 >>> g2.inconsistent()
5536 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5539 >>> g.prec() == Z3_GOAL_PRECISE
5541 >>> x, y =
Ints(
'x y')
5542 >>> g.add(x == y + 1)
5543 >>> g.prec() == Z3_GOAL_PRECISE
5545 >>> t =
With(
Tactic(
'add-bounds'), add_bound_lower=0, add_bound_upper=10)
5548 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5549 >>> g2.prec() == Z3_GOAL_PRECISE
5551 >>> g2.prec() == Z3_GOAL_UNDER
5557 """Alias for `prec()`.
5560 >>> g.precision() == Z3_GOAL_PRECISE
5566 """Return the number of constraints in the goal `self`.
5571 >>> x, y = Ints('x y')
5572 >>> g.add(x == 0, y > x)
5579 """Return the number of constraints in the goal `self`.
5584 >>> x, y = Ints('x y')
5585 >>> g.add(x == 0, y > x)
5592 """Return a constraint in the goal `self`.
5595 >>> x, y = Ints('x y')
5596 >>> g.add(x == 0, y > x)
5605 """Return a constraint in the goal `self`.
5608 >>> x, y = Ints('x y')
5609 >>> g.add(x == 0, y > x)
5615 if arg >= len(self):
5617 return self.
get(arg)
5620 """Assert constraints into the goal.
5624 >>> g.assert_exprs(x > 0, x < 2)
5628 args = _get_args(args)
5639 >>> g.append(x > 0, x < 2)
5650 >>> g.insert(x > 0, x < 2)
5661 >>> g.add(x > 0, x < 2)
5668 """Retrieve model from a satisfiable goal
5669 >>> a, b = Ints('a b')
5671 >>> g.add(
Or(a == 0, a == 1),
Or(b == 0, b == 1), a > b)
5675 [
Or(b == 0, b == 1),
Not(0 <= b)]
5677 [
Or(b == 0, b == 1),
Not(1 <= b)]
5693 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5697 return obj_to_string(self)
5700 """Return a textual representation of the s-expression representing the goal."""
5704 """Return a textual representation of the goal in DIMACS format."""
5708 """Copy goal `self` to context `target`.
5716 >>> g2 = g.translate(c2)
5727 _z3_assert(isinstance(target, Context),
"target must be a context")
5737 """Return a new simplified goal.
5739 This method is essentially invoking the simplify tactic.
5743 >>> g.add(x + 1 >= 2)
5746 >>> g2 = g.simplify()
5754 return t.apply(self, *arguments, **keywords)[0]
5757 """Return goal `self` as a single Z3 expression.
5786 """A collection (vector) of ASTs."""
5795 assert ctx
is not None
5800 if self.
vector is not None and self.
ctx.ref()
is not None:
5804 """Return the size of the vector `self`.
5809 >>> A.push(Int('x'))
5810 >>> A.push(
Int(
'x'))
5817 """Return the AST at position `i`.
5820 >>> A.push(Int('x') + 1)
5821 >>> A.push(
Int(
'y'))
5828 if isinstance(i, int):
5836 elif isinstance(i, slice):
5839 result.append(_to_ast_ref(
5846 """Update AST at position `i`.
5849 >>> A.push(Int('x') + 1)
5850 >>> A.push(
Int(
'y'))
5862 """Add `v` in the end of the vector.
5867 >>> A.push(Int('x'))
5874 """Resize the vector to `sz` elements.
5880 >>> for i
in range(10): A[i] =
Int(
'x')
5887 """Return `True` if the vector contains `item`.
5910 """Copy vector `self` to context `other_ctx`.
5916 >>> B = A.translate(c2)
5932 return obj_to_string(self)
5935 """Return a textual representation of the s-expression representing the vector."""
5946 """A mapping from ASTs to ASTs."""
5955 assert ctx
is not None
5963 if self.
map is not None and self.
ctx.ref()
is not None:
5967 """Return the size of the map.
5980 """Return `True` if the map contains key `key`.
5993 """Retrieve the value associated with key `key`.
6004 """Add/Update key `k` with value `v`.
6023 """Remove the entry associated with key `k`.
6037 """Remove all entries from the map.
6052 """Return an AstVector containing all keys in the map.
6071 """Store the value of the interpretation of a function in a particular point."""
6082 if self.
ctx.ref()
is not None:
6086 """Return the number of arguments in the given entry.
6090 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6095 >>> f_i.num_entries()
6097 >>> e = f_i.entry(0)
6104 """Return the value of argument `idx`.
6108 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6113 >>> f_i.num_entries()
6115 >>> e = f_i.entry(0)
6126 ...
except IndexError:
6127 ... print(
"index error")
6135 """Return the value of the function at point `self`.
6139 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6144 >>> f_i.num_entries()
6146 >>> e = f_i.entry(0)
6157 """Return entry `self` as a Python list.
6160 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6165 >>> f_i.num_entries()
6167 >>> e = f_i.entry(0)
6172 args.append(self.
value())
6180 """Stores the interpretation of a function in a Z3 model."""
6185 if self.
f is not None:
6189 if self.
f is not None and self.
ctx.ref()
is not None:
6194 Return the `else` value
for a function interpretation.
6195 Return
None if Z3 did
not specify the `
else` value
for
6200 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6211 return _to_expr_ref(r, self.
ctx)
6216 """Return the number of entries/points in the function interpretation `self`.
6220 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6232 """Return the number of arguments for each entry in the function interpretation `self`.
6236 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6246 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
6250 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6266 """Copy model 'self' to context 'other_ctx'.
6277 """Return the function interpretation as a Python list.
6280 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6294 return obj_to_string(self)
6298 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6301 assert ctx
is not None
6307 if self.
ctx.ref()
is not None:
6311 return obj_to_string(self)
6314 """Return a textual representation of the s-expression representing the model."""
6317 def eval(self, t, model_completion=False):
6318 """Evaluate the expression `t` in the model `self`.
6319 If `model_completion` is enabled, then a default interpretation
is automatically added
6320 for symbols that do
not have an interpretation
in the model `self`.
6324 >>> s.add(x > 0, x < 2)
6337 >>> m.eval(y, model_completion=
True)
6345 return _to_expr_ref(r[0], self.
ctx)
6346 raise Z3Exception(
"failed to evaluate expression in the model")
6349 """Alias for `eval`.
6353 >>> s.add(x > 0, x < 2)
6357 >>> m.evaluate(x + 1)
6359 >>> m.evaluate(x == 1)
6362 >>> m.evaluate(y + x)
6366 >>> m.evaluate(y, model_completion=
True)
6369 >>> m.evaluate(y + x)
6372 return self.
eval(t, model_completion)
6375 """Return the number of constant and function declarations in the model `self`.
6380 >>> s.add(x > 0, f(x) != x)
6389 return num_consts + num_funcs
6392 """Return the interpretation for a given declaration or constant.
6397 >>> s.add(x > 0, x < 2, f(x) == 0)
6407 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6411 if decl.arity() == 0:
6413 if _r.value
is None:
6415 r = _to_expr_ref(_r, self.
ctx)
6426 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6429 >>> a, b =
Consts(
'a b', A)
6441 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6445 >>> a1, a2 =
Consts(
'a1 a2', A)
6446 >>> b1, b2 =
Consts(
'b1 b2', B)
6448 >>> s.add(a1 != a2, b1 != b2)
6464 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6468 >>> a1, a2 =
Consts(
'a1 a2', A)
6469 >>> b1, b2 =
Consts(
'b1 b2', B)
6471 >>> s.add(a1 != a2, b1 != b2)
6481 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6484 >>> a, b =
Consts(
'a b', A)
6490 >>> m.get_universe(A)
6494 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6501 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
6502 If `idx` is a declaration, then the actual interpretation
is returned.
6504 The elements can be retrieved using position
or the actual declaration.
6509 >>> s.add(x > 0, x < 2, f(x) == 0)
6523 >>>
for d
in m: print(
"%s -> %s" % (d, m[d]))
6528 if idx >= len(self):
6531 if (idx < num_consts):
6535 if isinstance(idx, FuncDeclRef):
6539 if isinstance(idx, SortRef):
6542 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6546 """Return a list with all symbols that have an interpretation in the model `self`.
6550 >>> s.add(x > 0, x < 2, f(x) == 0)
6565 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6568 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6585 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6586 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6590 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6592 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6603 """Statistics for `Solver.check()`."""
6614 if self.
ctx.ref()
is not None:
6621 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6624 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6627 out.write(u(
"<tr>"))
6629 out.write(u(
"<td>%s</td><td>%s</td></tr>" % (k, v)))
6630 out.write(u(
"</table>"))
6631 return out.getvalue()
6636 """Return the number of statistical counters.
6639 >>> s =
Then(
'simplify',
'nlsat').solver()
6643 >>> st = s.statistics()
6650 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6653 >>> s =
Then(
'simplify',
'nlsat').solver()
6657 >>> st = s.statistics()
6661 (
'nlsat propagations', 2)
6665 if idx >= len(self):
6674 """Return the list of statistical counters.
6677 >>> s =
Then(
'simplify',
'nlsat').solver()
6681 >>> st = s.statistics()
6686 """Return the value of a particular statistical counter.
6689 >>> s =
Then(
'simplify',
'nlsat').solver()
6693 >>> st = s.statistics()
6694 >>> st.get_key_value(
'nlsat propagations')
6697 for idx
in range(len(self)):
6703 raise Z3Exception(
"unknown key")
6706 """Access the value of statistical using attributes.
6708 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6709 we should use
'_' (e.g.,
'nlsat_propagations').
6712 >>> s =
Then(
'simplify',
'nlsat').solver()
6716 >>> st = s.statistics()
6717 >>> st.nlsat_propagations
6722 key = name.replace("_",
" ")
6726 raise AttributeError
6736 """Represents the result of a satisfiability check: sat, unsat, unknown.
6742 >>> isinstance(r, CheckSatResult)
6753 return isinstance(other, CheckSatResult)
and self.
r == other.r
6756 return not self.
__eq__(other)
6760 if self.
r == Z3_L_TRUE:
6762 elif self.
r == Z3_L_FALSE:
6763 return "<b>unsat</b>"
6765 return "<b>unknown</b>"
6767 if self.
r == Z3_L_TRUE:
6769 elif self.
r == Z3_L_FALSE:
6774 def _repr_html_(self):
6775 in_html = in_html_mode()
6778 set_html_mode(in_html)
6789 Solver API provides methods for implementing the main SMT 2.0 commands:
6790 push, pop, check, get-model, etc.
6793 def __init__(self, solver=None, ctx=None, logFile=None):
6794 assert solver
is None or ctx
is not None
6803 if logFile
is not None:
6804 self.
set(
"smtlib2_log", logFile)
6807 if self.
solver is not None and self.
ctx.ref()
is not None:
6811 """Set a configuration option.
6812 The method `help()` return a string containing all available options.
6816 >>> s.set(mbqi=
True)
6817 >>> s.set(
'MBQI',
True)
6818 >>> s.set(
':mbqi',
True)
6824 """Create a backtracking point.
6846 """Backtrack \\c num backtracking points.
6868 """Return the current number of backtracking points.
6886 """Remove all asserted constraints and backtracking points created using `push()`.
6900 """Assert constraints into the solver.
6904 >>> s.assert_exprs(x > 0, x < 2)
6908 args = _get_args(args)
6911 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6919 """Assert constraints into the solver.
6923 >>> s.add(x > 0, x < 2)
6934 """Assert constraints into the solver.
6938 >>> s.append(x > 0, x < 2)
6945 """Assert constraints into the solver.
6949 >>> s.insert(x > 0, x < 2)
6956 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
6958 If `p` is a string, it will be automatically converted into a Boolean constant.
6963 >>> s.set(unsat_core=
True)
6964 >>> s.assert_and_track(x > 0,
'p1')
6965 >>> s.assert_and_track(x != 1,
'p2')
6966 >>> s.assert_and_track(x < 0, p3)
6967 >>> print(s.check())
6969 >>> c = s.unsat_core()
6979 if isinstance(p, str):
6981 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6982 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6986 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
6992 >>> s.add(x > 0, x < 2)
6995 >>> s.model().eval(x)
7001 >>> s.add(2**x == 4)
7006 assumptions = _get_args(assumptions)
7007 num = len(assumptions)
7008 _assumptions = (Ast * num)()
7009 for i
in range(num):
7010 _assumptions[i] = s.cast(assumptions[i]).as_ast()
7015 """Return a model for the last `check()`.
7017 This function raises an exception if
7018 a model
is not available (e.g., last `
check()` returned unsat).
7022 >>> s.add(a + 2 == 0)
7031 raise Z3Exception(
"model is not available")
7034 """Import model converter from other into the current solver"""
7038 """Return a subset (as an AST vector) of the assumptions provided to the last check().
7040 These are the assumptions Z3 used in the unsatisfiability proof.
7041 Assumptions are available
in Z3. They are used to extract unsatisfiable cores.
7042 They may be also used to
"retract" assumptions. Note that, assumptions are
not really
7043 "soft constraints", but they can be used to implement them.
7045 >>> p1, p2, p3 =
Bools(
'p1 p2 p3')
7046 >>> x, y =
Ints(
'x y')
7051 >>> s.add(
Implies(p3, y > -3))
7052 >>> s.check(p1, p2, p3)
7054 >>> core = s.unsat_core()
7070 """Determine fixed values for the variables based on the solver state and assumptions.
7072 >>> a, b, c, d = Bools('a b c d')
7074 >>> s.consequences([a],[b,c,d])
7076 >>> s.consequences([
Not(c),d],[a,b,c,d])
7079 if isinstance(assumptions, list):
7081 for a
in assumptions:
7084 if isinstance(variables, list):
7089 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
7090 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
7093 variables.vector, consequences.vector)
7094 sz = len(consequences)
7095 consequences = [consequences[i]
for i
in range(sz)]
7099 """Parse assertions from a file"""
7103 """Parse assertions from a string"""
7108 The method takes an optional set of variables that restrict which
7109 variables may be used as a starting point
for cubing.
7110 If vars
is not None, then the first case split
is based on a variable
in
7114 if vars
is not None:
7121 if (len(r) == 1
and is_false(r[0])):
7128 """Access the set of variables that were touched by the most recently generated cube.
7129 This set of variables can be used as a starting point
for additional cubes.
7130 The idea
is that variables that appear
in clauses that are reduced by the most recent
7131 cube are likely more useful to cube on.
"""
7135 """Return a proof for the last `check()`. Proof construction must be enabled."""
7139 """Return an AST vector containing all added constraints.
7153 """Return an AST vector containing all currently inferred units.
7158 """Return an AST vector containing all atomic formulas in solver state that are not units.
7163 """Return trail and decision levels of the solver state after a check() call.
7165 trail = self.trail()
7166 levels = (ctypes.c_uint * len(trail))()
7168 return trail, levels
7171 """Return trail of the solver state after a check() call.
7176 """Return statistics for the last `check()`.
7183 >>> st = s.statistics()
7184 >>> st.get_key_value(
'final checks')
7194 """Return a string describing why the last `check()` returned `unknown`.
7198 >>> s.add(2**x == 4)
7201 >>> s.reason_unknown()
7202 '(incomplete (theory arithmetic))'
7207 """Display a string describing all available options."""
7211 """Return the parameter description set."""
7215 """Return a formatted string with all added constraints."""
7216 return obj_to_string(self)
7219 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
7224 >>> s2 = s1.translate(c2)
7227 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
7229 return Solver(solver, target)
7238 """Return a formatted string (in Lisp-like format) with all added constraints.
7239 We say the string is in s-expression format.
7250 """Return a textual representation of the solver in DIMACS format."""
7254 """return SMTLIB2 formatted benchmark for solver's assertions"""
7261 for i
in range(sz1):
7262 v[i] = es[i].as_ast()
7264 e = es[sz1].as_ast()
7268 self.
ctx.ref(),
"benchmark generated from python API",
"",
"unknown",
"", sz1, v, e,
7273 """Create a solver customized for the given logic.
7275 The parameter `logic` is a string. It should be contains
7276 the name of a SMT-LIB logic.
7277 See http://www.smtlib.org/
for the name of all available logics.
7294 """Return a simple general purpose solver with limited amount of preprocessing.
7313 """Fixedpoint API provides methods for solving with recursive predicates"""
7316 assert fixedpoint
is None or ctx
is not None
7319 if fixedpoint
is None:
7330 if self.
fixedpoint is not None and self.
ctx.ref()
is not None:
7334 """Set a configuration option. The method `help()` return a string containing all available options.
7340 """Display a string describing all available options."""
7344 """Return the parameter description set."""
7348 """Assert constraints as background axioms for the fixedpoint solver."""
7349 args = _get_args(args)
7352 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7362 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7370 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7374 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7378 """Assert rules defining recursive predicates to the fixedpoint solver.
7382 >>> s.register_relation(a.decl())
7383 >>> s.register_relation(b.decl())
7396 body = _get_args(body)
7400 def rule(self, head, body=None, name=None):
7401 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7405 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7409 """Query the fixedpoint engine whether formula is derivable.
7410 You can also pass an tuple
or list of recursive predicates.
7412 query = _get_args(query)
7414 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7415 _decls = (FuncDecl * sz)()
7425 query =
And(query, self.
ctx)
7426 query = self.
abstract(query,
False)
7431 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7433 query = _get_args(query)
7435 if sz >= 1
and isinstance(query[0], FuncDecl):
7436 _z3_assert(
False,
"unsupported")
7442 query = self.
abstract(query,
False)
7443 r = Z3_fixedpoint_query_from_lvl(self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
7451 body = _get_args(body)
7456 """Retrieve answer from last query call."""
7458 return _to_expr_ref(r, self.
ctx)
7461 """Retrieve a ground cex from last query call."""
7462 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7463 return _to_expr_ref(r, self.
ctx)
7466 """retrieve rules along the counterexample trace"""
7470 """retrieve rule names along the counterexample trace"""
7473 names = _symbol2py(self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7475 return names.split(
";")
7478 """Retrieve number of levels used for predicate in PDR engine"""
7482 """Retrieve properties known about predicate for the level'th unfolding.
7483 -1 is treated
as the limit (infinity)
7486 return _to_expr_ref(r, self.
ctx)
7489 """Add property to predicate for the level'th unfolding.
7490 -1 is treated
as infinity (infinity)
7495 """Register relation as recursive"""
7496 relations = _get_args(relations)
7501 """Control how relation is represented"""
7502 representations = _get_args(representations)
7503 representations = [
to_symbol(s)
for s
in representations]
7504 sz = len(representations)
7505 args = (Symbol * sz)()
7507 args[i] = representations[i]
7511 """Parse rules and queries from a string"""
7515 """Parse rules and queries from a file"""
7519 """retrieve rules that have been added to fixedpoint context"""
7523 """retrieve assertions that have been added to fixedpoint context"""
7527 """Return a formatted string with all added rules and constraints."""
7531 """Return a formatted string (in Lisp-like format) with all added constraints.
7532 We say the string is in s-expression format.
7537 """Return a formatted string (in Lisp-like format) with all added constraints.
7538 We say the string is in s-expression format.
7539 Include also queries.
7541 args, len = _to_ast_array(queries)
7545 """Return statistics for the last `query()`.
7550 """Return a string describing why the last `query()` returned `unknown`.
7555 """Add variable or several variables.
7556 The added variable or variables will be bound
in the rules
7559 vars = _get_args(vars)
7579 """Finite domain sort."""
7582 """Return the size of the finite domain sort"""
7583 r = (ctypes.c_ulonglong * 1)()
7587 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7591 """Create a named finite domain sort of a given size sz"""
7592 if not isinstance(name, Symbol):
7599 """Return True if `s` is a Z3 finite-domain sort.
7606 return isinstance(s, FiniteDomainSortRef)
7610 """Finite-domain expressions."""
7613 """Return the sort of the finite-domain expression `self`."""
7617 """Return a Z3 floating point expression as a Python string."""
7622 """Return `True` if `a` is a Z3 finite-domain expression.
7625 >>> b =
Const(
'b', s)
7631 return isinstance(a, FiniteDomainRef)
7635 """Integer values."""
7638 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7650 """Return a Z3 finite-domain numeral as a Python string.
7661 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7676 """Return `True` if `a` is a Z3 finite-domain value.
7679 >>> b =
Const(
'b', s)
7732def _global_on_model(ctx):
7733 (fn, mdl) = _on_models[ctx]
7737_on_model_eh = on_model_eh_type(_global_on_model)
7741 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7753 if self.
optimize is not None and self.
ctx.ref()
is not None:
7759 """Set a configuration option.
7760 The method `help()` return a string containing all available options.
7766 """Display a string describing all available options."""
7770 """Return the parameter description set."""
7774 """Assert constraints as background axioms for the optimize solver."""
7775 args = _get_args(args)
7778 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7786 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7794 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7796 If `p` is a string, it will be automatically converted into a Boolean constant.
7801 >>> s.assert_and_track(x > 0,
'p1')
7802 >>> s.assert_and_track(x != 1,
'p2')
7803 >>> s.assert_and_track(x < 0, p3)
7804 >>> print(s.check())
7806 >>> c = s.unsat_core()
7816 if isinstance(p, str):
7818 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7819 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7823 """Add soft constraint with optional weight and optional identifier.
7824 If no weight is supplied, then the penalty
for violating the soft constraint
7826 Soft constraints are grouped by identifiers. Soft constraints that are
7827 added without identifiers are grouped by default.
7830 weight =
"%d" % weight
7831 elif isinstance(weight, float):
7832 weight =
"%f" % weight
7833 if not isinstance(weight, str):
7834 raise Z3Exception(
"weight should be a string or an integer")
7842 if sys.version_info.major >= 3
and isinstance(arg, Iterable):
7843 return [asoft(a)
for a
in arg]
7847 """Add objective function to maximize."""
7855 """Add objective function to minimize."""
7863 """create a backtracking point for added rules, facts and assertions"""
7867 """restore to previously created backtracking point"""
7871 """Check satisfiability while optimizing objective functions."""
7872 assumptions = _get_args(assumptions)
7873 num = len(assumptions)
7874 _assumptions = (Ast * num)()
7875 for i
in range(num):
7876 _assumptions[i] = assumptions[i].as_ast()
7880 """Return a string that describes why the last `check()` returned `unknown`."""
7884 """Return a model for the last check()."""
7888 raise Z3Exception(
"model is not available")
7894 if not isinstance(obj, OptimizeObjective):
7895 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7899 if not isinstance(obj, OptimizeObjective):
7900 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7904 if not isinstance(obj, OptimizeObjective):
7905 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7906 return obj.lower_values()
7909 if not isinstance(obj, OptimizeObjective):
7910 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7911 return obj.upper_values()
7914 """Parse assertions and objectives from a file"""
7918 """Parse assertions and objectives from a string"""
7922 """Return an AST vector containing all added constraints."""
7926 """returns set of objective functions"""
7930 """Return a formatted string with all added rules and constraints."""
7934 """Return a formatted string (in Lisp-like format) with all added constraints.
7935 We say the string is in s-expression format.
7940 """Return statistics for the last check`.
7945 """Register a callback that is invoked with every incremental improvement to
7946 objective values. The callback takes a model as argument.
7947 The life-time of the model
is limited to the callback so the
7948 model has to be (deep) copied
if it
is to be used after the callback
7950 id = len(_on_models) + 41
7952 _on_models[id] = (on_model, mdl)
7955 self.ctx.ref(), self.optimize, mdl.model, ctypes.c_void_p(id), _on_model_eh,
7965 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal.
7966 It also contains model and proof converters.
7978 if self.
ctx.ref()
is not None:
7982 """Return the number of subgoals in `self`.
7984 >>> a, b = Ints('a b')
7986 >>> g.add(
Or(a == 0, a == 1),
Or(b == 0, b == 1), a > b)
7987 >>> t =
Tactic(
'split-clause')
8001 """Return one of the subgoals stored in ApplyResult object `self`.
8003 >>> a, b = Ints('a b')
8005 >>> g.add(
Or(a == 0, a == 1),
Or(b == 0, b == 1), a > b)
8006 >>> t =
Tactic(
'split-clause')
8009 [a == 0,
Or(b == 0, b == 1), a > b]
8011 [a == 1,
Or(b == 0, b == 1), a > b]
8013 if idx >= len(self):
8018 return obj_to_string(self)
8021 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
8025 """Return a Z3 expression consisting of all subgoals.
8030 >>> g.add(
Or(x == 2, x == 3))
8031 >>> r =
Tactic(
'simplify')(g)
8033 [[
Not(x <= 1),
Or(x == 2, x == 3)]]
8035 And(
Not(x <= 1),
Or(x == 2, x == 3))
8036 >>> r =
Tactic(
'split-clause')(g)
8038 [[x > 1, x == 2], [x > 1, x == 3]]
8040 Or(
And(x > 1, x == 2),
And(x > 1, x == 3))
8058 """Tactics transform, solver and/or simplify sets of constraints (Goal).
8059 A Tactic can be converted into a Solver using the method solver().
8061 Several combinators are available for creating new tactics using the built-
in ones:
8068 if isinstance(tactic, TacticObj):
8072 _z3_assert(isinstance(tactic, str),
"tactic name expected")
8076 raise Z3Exception(
"unknown tactic '%s'" % tactic)
8083 if self.
tactic is not None and self.
ctx.ref()
is not None:
8087 """Create a solver using the tactic `self`.
8089 The solver supports the methods `push()` and `pop()`, but it
8090 will always solve each `check()`
from scratch.
8092 >>> t =
Then(
'simplify',
'nlsat')
8095 >>> s.add(x**2 == 2, x > 0)
8103 def apply(self, goal, *arguments, **keywords):
8104 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8106 >>> x, y = Ints('x y')
8107 >>> t =
Tactic(
'solve-eqs')
8108 >>> t.apply(
And(x == 0, y >= x + 1))
8112 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expressions expected")
8113 goal = _to_goal(goal)
8114 if len(arguments) > 0
or len(keywords) > 0:
8121 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8123 >>> x, y = Ints('x y')
8124 >>> t =
Tactic(
'solve-eqs')
8125 >>> t(
And(x == 0, y >= x + 1))
8128 return self.
apply(goal, *arguments, **keywords)
8131 """Display a string containing a description of the available options for the `self` tactic."""
8135 """Return the parameter description set."""
8140 if isinstance(a, BoolRef):
8141 goal =
Goal(ctx=a.ctx)
8148def _to_tactic(t, ctx=None):
8149 if isinstance(t, Tactic):
8155def _and_then(t1, t2, ctx=None):
8156 t1 = _to_tactic(t1, ctx)
8157 t2 = _to_tactic(t2, ctx)
8159 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8163def _or_else(t1, t2, ctx=None):
8164 t1 = _to_tactic(t1, ctx)
8165 t2 = _to_tactic(t2, ctx)
8167 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8172 """Return a tactic that applies the tactics in `*ts` in sequence.
8174 >>> x, y = Ints('x y')
8176 >>> t(
And(x == 0, y > x + 1))
8178 >>> t(
And(x == 0, y > x + 1)).as_expr()
8182 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8183 ctx = ks.get(
"ctx",
None)
8186 for i
in range(num - 1):
8187 r = _and_then(r, ts[i + 1], ctx)
8192 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8194 >>> x, y = Ints('x y')
8196 >>> t(
And(x == 0, y > x + 1))
8198 >>> t(
And(x == 0, y > x + 1)).as_expr()
8205 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8212 >>> t(
Or(x == 0, x == 1))
8213 [[x == 0], [x == 1]]
8216 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8217 ctx = ks.get(
"ctx",
None)
8220 for i
in range(num - 1):
8221 r = _or_else(r, ts[i + 1], ctx)
8226 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8234 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8235 ctx = _get_ctx(ks.get(
"ctx",
None))
8236 ts = [_to_tactic(t, ctx)
for t
in ts]
8238 _args = (TacticObj * sz)()
8240 _args[i] = ts[i].tactic
8245 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8246 The subgoals are processed in parallel.
8248 >>> x, y =
Ints(
'x y')
8250 >>> t(
And(
Or(x == 1, x == 2), y == x + 1))
8251 [[x == 1, y == 2], [x == 2, y == 3]]
8253 t1 = _to_tactic(t1, ctx)
8254 t2 = _to_tactic(t2, ctx)
8256 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8261 """Alias for ParThen(t1, t2, ctx)."""
8266 """Return a tactic that applies tactic `t` using the given configuration options.
8268 >>> x, y = Ints('x y')
8270 >>> t((x + 1)*(y + 2) == 0)
8271 [[2*x + y + x*y == -2]]
8273 ctx = keys.pop("ctx",
None)
8274 t = _to_tactic(t, ctx)
8280 """Return a tactic that applies tactic `t` using the given configuration options.
8282 >>> x, y = Ints('x y')
8284 >>> p.set(
"som",
True)
8286 >>> t((x + 1)*(y + 2) == 0)
8287 [[2*x + y + x*y == -2]]
8289 t = _to_tactic(t, None)
8294 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8295 or the maximum number of iterations `max`
is reached.
8297 >>> x, y =
Ints(
'x y')
8298 >>> c =
And(
Or(x == 0, x == 1),
Or(y == 0, y == 1), x > y)
8301 >>>
for subgoal
in r: print(subgoal)
8302 [x == 0, y == 0, x > y]
8303 [x == 0, y == 1, x > y]
8304 [x == 1, y == 0, x > y]
8305 [x == 1, y == 1, x > y]
8310 t = _to_tactic(t, ctx)
8315 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8317 If `t` does not terminate
in `ms` milliseconds, then it fails.
8319 t = _to_tactic(t, ctx)
8324 """Return a list of all available tactics in Z3.
8327 >>> l.count('simplify') == 1
8335 """Return a short description for the tactic named `name`.
8344 """Display a (tabular) description of all available tactics in Z3."""
8347 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8350 print(
'<tr style="background-color:#CFCFCF">')
8355 print(
"<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(
tactic_description(t), 40)))
8363 """Probes are used to inspect a goal (aka problem) and collect information that may be used
8364 to decide which solver and/
or preprocessing step will be used.
8370 if isinstance(probe, ProbeObj):
8372 elif isinstance(probe, float):
8374 elif _is_int(probe):
8376 elif isinstance(probe, bool):
8383 _z3_assert(isinstance(probe, str),
"probe name expected")
8387 raise Z3Exception(
"unknown probe '%s'" % probe)
8394 if self.
probe is not None and self.
ctx.ref()
is not None:
8398 """Return a probe that evaluates to "true" when the value returned by `self`
8399 is less than the value returned by `other`.
8401 >>> p =
Probe(
'size') < 10
8412 """Return a probe that evaluates to "true" when the value returned by `self`
8413 is greater than the value returned by `other`.
8415 >>> p =
Probe(
'size') > 10
8426 """Return a probe that evaluates to "true" when the value returned by `self`
8427 is less than
or equal to the value returned by `other`.
8429 >>> p =
Probe(
'size') <= 2
8440 """Return a probe that evaluates to "true" when the value returned by `self`
8441 is greater than
or equal to the value returned by `other`.
8443 >>> p =
Probe(
'size') >= 2
8454 """Return a probe that evaluates to "true" when the value returned by `self`
8455 is equal to the value returned by `other`.
8457 >>> p =
Probe(
'size') == 2
8468 """Return a probe that evaluates to "true" when the value returned by `self`
8469 is not equal to the value returned by `other`.
8471 >>> p =
Probe(
'size') != 2
8483 """Evaluate the probe `self` in the given goal.
8485 >>> p = Probe('size')
8495 >>> p =
Probe(
'num-consts')
8498 >>> p =
Probe(
'is-propositional')
8501 >>> p =
Probe(
'is-qflia')
8506 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expression expected")
8507 goal = _to_goal(goal)
8512 """Return `True` if `p` is a Z3 probe.
8519 return isinstance(p, Probe)
8522def _to_probe(p, ctx=None):
8526 return Probe(p, ctx)
8530 """Return a list of all available probes in Z3.
8533 >>> l.count('memory') == 1
8541 """Return a short description for the probe named `name`.
8550 """Display a (tabular) description of all available probes in Z3."""
8553 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8556 print(
'<tr style="background-color:#CFCFCF">')
8561 print(
"<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(
probe_description(p), 40)))
8568def _probe_nary(f, args, ctx):
8570 _z3_assert(len(args) > 0,
"At least one argument expected")
8572 r = _to_probe(args[0], ctx)
8573 for i
in range(num - 1):
8574 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8578def _probe_and(args, ctx):
8579 return _probe_nary(Z3_probe_and, args, ctx)
8582def _probe_or(args, ctx):
8583 return _probe_nary(Z3_probe_or, args, ctx)
8587 """Return a tactic that fails if the probe `p` evaluates to true.
8588 Otherwise, it returns the input goal unmodified.
8590 In the following example, the tactic applies 'simplify' if and only
if there are
8591 more than 2 constraints
in the goal.
8594 >>> x, y =
Ints(
'x y')
8600 >>> g.add(x == y + 1)
8602 [[
Not(x <= 0),
Not(y <= 0), x == 1 + y]]
8604 p = _to_probe(p, ctx)
8609 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8610 Otherwise, it returns the input goal unmodified.
8613 >>> x, y =
Ints(
'x y')
8619 >>> g.add(x == y + 1)
8621 [[
Not(x <= 0),
Not(y <= 0), x == 1 + y]]
8623 p = _to_probe(p, ctx)
8624 t = _to_tactic(t, ctx)
8629 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8633 p = _to_probe(p, ctx)
8634 t1 = _to_tactic(t1, ctx)
8635 t2 = _to_tactic(t2, ctx)
8646 """Simplify the expression `a` using the given options.
8648 This function has many options. Use `help_simplify` to obtain the complete list.
8654 >>>
simplify((x + 1)*(y + 1), som=
True)
8662 _z3_assert(
is_expr(a),
"Z3 expression expected")
8663 if len(arguments) > 0
or len(keywords) > 0:
8665 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8667 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8671 """Return a string describing all options available for Z3 `simplify` procedure."""
8676 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8681 """Apply substitution m on t, m is a list of pairs of the form (from, to).
8682 Every occurrence in t of
from is replaced
with to.
8692 if isinstance(m, tuple):
8694 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8697 _z3_assert(
is_expr(t),
"Z3 expression expected")
8698 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(
8699 p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8701 _from = (Ast * num)()
8703 for i
in range(num):
8704 _from[i] = m[i][0].as_ast()
8705 _to[i] = m[i][1].as_ast()
8706 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8710 """Substitute the free variables in t with the expression in m.
8721 _z3_assert(
is_expr(t),
"Z3 expression expected")
8722 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8725 for i
in range(num):
8726 _to[i] = m[i].as_ast()
8731 """Create the sum of the Z3 expressions.
8733 >>> a, b, c = Ints('a b c')
8740 a__0 + a__1 + a__2 + a__3 + a__4
8742 args = _get_args(args)
8745 ctx = _ctx_from_ast_arg_list(args)
8747 return _reduce(
lambda a, b: a + b, args, 0)
8748 args = _coerce_expr_list(args, ctx)
8750 return _reduce(
lambda a, b: a + b, args, 0)
8752 _args, sz = _to_ast_array(args)
8757 """Create the product of the Z3 expressions.
8759 >>> a, b, c = Ints('a b c')
8766 a__0*a__1*a__2*a__3*a__4
8768 args = _get_args(args)
8771 ctx = _ctx_from_ast_arg_list(args)
8773 return _reduce(
lambda a, b: a * b, args, 1)
8774 args = _coerce_expr_list(args, ctx)
8776 return _reduce(
lambda a, b: a * b, args, 1)
8778 _args, sz = _to_ast_array(args)
8783 """Create an at-most Pseudo-Boolean k constraint.
8785 >>> a, b, c = Bools('a b c')
8786 >>> f =
AtMost(a, b, c, 2)
8788 args = _get_args(args)
8790 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8791 ctx = _ctx_from_ast_arg_list(args)
8793 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8794 args1 = _coerce_expr_list(args[:-1], ctx)
8796 _args, sz = _to_ast_array(args1)
8801 """Create an at-most Pseudo-Boolean k constraint.
8803 >>> a, b, c = Bools('a b c')
8806 args = _get_args(args)
8808 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8809 ctx = _ctx_from_ast_arg_list(args)
8811 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8812 args1 = _coerce_expr_list(args[:-1], ctx)
8814 _args, sz = _to_ast_array(args1)
8818def _reorder_pb_arg(arg):
8820 if not _is_int(b)
and _is_int(a):
8825def _pb_args_coeffs(args, default_ctx=None):
8826 args = _get_args_ast_list(args)
8828 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8829 args = [_reorder_pb_arg(arg)
for arg
in args]
8830 args, coeffs = zip(*args)
8832 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8833 ctx = _ctx_from_ast_arg_list(args)
8835 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8836 args = _coerce_expr_list(args, ctx)
8837 _args, sz = _to_ast_array(args)
8838 _coeffs = (ctypes.c_int * len(coeffs))()
8839 for i
in range(len(coeffs)):
8840 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8841 _coeffs[i] = coeffs[i]
8842 return ctx, sz, _args, _coeffs
8846 """Create a Pseudo-Boolean inequality k constraint.
8848 >>> a, b, c = Bools('a b c')
8849 >>> f =
PbLe(((a,1),(b,3),(c,2)), 3)
8851 _z3_check_cint_overflow(k, "k")
8852 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8857 """Create a Pseudo-Boolean inequality k constraint.
8859 >>> a, b, c = Bools('a b c')
8860 >>> f =
PbGe(((a,1),(b,3),(c,2)), 3)
8862 _z3_check_cint_overflow(k, "k")
8863 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8868 """Create a Pseudo-Boolean inequality k constraint.
8870 >>> a, b, c = Bools('a b c')
8871 >>> f =
PbEq(((a,1),(b,3),(c,2)), 3)
8873 _z3_check_cint_overflow(k, "k")
8874 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8879 """Solve the constraints `*args`.
8881 This is a simple function
for creating demonstrations. It creates a solver,
8882 configure it using the options
in `keywords`, adds the constraints
8883 in `args`,
and invokes check.
8886 >>>
solve(a > 0, a < 2)
8889 show = keywords.pop("show",
False)
8897 print(
"no solution")
8899 print(
"failed to solve")
8909 """Solve the constraints `*args` using solver `s`.
8911 This is a simple function
for creating demonstrations. It
is similar to `solve`,
8912 but it uses the given solver `s`.
8913 It configures solver `s` using the options
in `keywords`, adds the constraints
8914 in `args`,
and invokes check.
8916 show = keywords.pop("show",
False)
8918 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8926 print(
"no solution")
8928 print(
"failed to solve")
8939def prove(claim, show=False, **keywords):
8940 """Try to prove the given claim.
8942 This is a simple function
for creating demonstrations. It tries to prove
8943 `claim` by showing the negation
is unsatisfiable.
8945 >>> p, q =
Bools(
'p q')
8950 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8960 print(
"failed to prove")
8963 print(
"counterexample")
8967def _solve_html(*args, **keywords):
8968 """Version of function `solve` used in RiSE4Fun."""
8969 show = keywords.pop(
"show",
False)
8974 print(
"<b>Problem:</b>")
8978 print(
"<b>no solution</b>")
8980 print(
"<b>failed to solve</b>")
8987 print(
"<b>Solution:</b>")
8991def _solve_using_html(s, *args, **keywords):
8992 """Version of function `solve_using` used in RiSE4Fun."""
8993 show = keywords.pop(
"show",
False)
8995 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8999 print(
"<b>Problem:</b>")
9003 print(
"<b>no solution</b>")
9005 print(
"<b>failed to solve</b>")
9012 print(
"<b>Solution:</b>")
9016def _prove_html(claim, show=False, **keywords):
9017 """Version of function `prove` used in RiSE4Fun."""
9019 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9027 print(
"<b>proved</b>")
9029 print(
"<b>failed to prove</b>")
9032 print(
"<b>counterexample</b>")
9036def _dict2sarray(sorts, ctx):
9038 _names = (Symbol * sz)()
9039 _sorts = (Sort * sz)()
9044 _z3_assert(isinstance(k, str),
"String expected")
9045 _z3_assert(
is_sort(v),
"Z3 sort expected")
9049 return sz, _names, _sorts
9052def _dict2darray(decls, ctx):
9054 _names = (Symbol * sz)()
9055 _decls = (FuncDecl * sz)()
9060 _z3_assert(isinstance(k, str),
"String expected")
9064 _decls[i] = v.decl().ast
9068 return sz, _names, _decls
9072 """Parse a string in SMT 2.0 format using the given sorts and decls.
9074 The arguments sorts and decls are Python dictionaries used to initialize
9075 the symbol table used
for the SMT 2.0 parser.
9077 >>>
parse_smt2_string(
'(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9079 >>> x, y =
Ints(
'x y')
9081 >>>
parse_smt2_string(
'(assert (> (+ foo (g bar)) 0))', decls={
'foo' : x,
'bar' : y,
'g' : f})
9087 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9088 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9093 """Parse a file in SMT 2.0 format using the given sorts and decls.
9098 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9099 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9111_dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
9112_dflt_fpsort_ebits = 11
9113_dflt_fpsort_sbits = 53
9117 """Retrieves the global default rounding mode."""
9118 global _dflt_rounding_mode
9119 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9121 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9123 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9125 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9127 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9131_ROUNDING_MODES = frozenset({
9132 Z3_OP_FPA_RM_TOWARD_ZERO,
9133 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
9134 Z3_OP_FPA_RM_TOWARD_POSITIVE,
9135 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
9136 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
9141 global _dflt_rounding_mode
9143 _dflt_rounding_mode = rm.decl().kind()
9145 _z3_assert(_dflt_rounding_mode
in _ROUNDING_MODES,
"illegal rounding mode")
9146 _dflt_rounding_mode = rm
9150 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9154 global _dflt_fpsort_ebits
9155 global _dflt_fpsort_sbits
9156 _dflt_fpsort_ebits = ebits
9157 _dflt_fpsort_sbits = sbits
9160def _dflt_rm(ctx=None):
9164def _dflt_fps(ctx=None):
9168def _coerce_fp_expr_list(alist, ctx):
9169 first_fp_sort =
None
9172 if first_fp_sort
is None:
9173 first_fp_sort = a.sort()
9174 elif first_fp_sort == a.sort():
9179 first_fp_sort =
None
9183 for i
in range(len(alist)):
9185 is_repr = isinstance(a, str)
and a.contains(
"2**(")
and a.endswith(
")")
9186 if is_repr
or _is_int(a)
or isinstance(a, (float, bool)):
9187 r.append(
FPVal(a,
None, first_fp_sort, ctx))
9190 return _coerce_expr_list(r, ctx)
9196 """Floating-point sort."""
9199 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
9207 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
9215 """Try to cast `val` as a floating-point expression.
9219 >>> b.cast(1.0).sexpr()
9220 '(fp #b0 #x7f #b00000000000000000000000)'
9224 _z3_assert(self.
ctxctx == val.ctx,
"Context mismatch")
9231 """Floating-point 16-bit (half) sort."""
9237 """Floating-point 16-bit (half) sort."""
9243 """Floating-point 32-bit (single) sort."""
9249 """Floating-point 32-bit (single) sort."""
9255 """Floating-point 64-bit (double) sort."""
9261 """Floating-point 64-bit (double) sort."""
9267 """Floating-point 128-bit (quadruple) sort."""
9273 """Floating-point 128-bit (quadruple) sort."""
9279 """"Floating-point rounding mode sort."""
9283 """Return True if `s` is a Z3 floating-point sort.
9290 return isinstance(s, FPSortRef)
9294 """Return True if `s` is a Z3 floating-point rounding mode sort.
9301 return isinstance(s, FPRMSortRef)
9307 """Floating-point expressions."""
9310 """Return the sort of the floating-point expression `self`.
9315 >>> x.sort() ==
FPSort(8, 24)
9321 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9329 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9337 """Return a Z3 floating point expression as a Python string."""
9341 return fpLEQ(self, other, self.
ctx)
9344 return fpLT(self, other, self.
ctx)
9347 return fpGEQ(self, other, self.
ctx)
9350 return fpGT(self, other, self.
ctx)
9353 """Create the Z3 expression `self + other`.
9362 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9363 return fpAdd(_dflt_rm(), a, b, self.
ctx)
9366 """Create the Z3 expression `other + self`.
9372 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9373 return fpAdd(_dflt_rm(), a, b, self.
ctx)
9376 """Create the Z3 expression `self - other`.
9385 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9386 return fpSub(_dflt_rm(), a, b, self.
ctx)
9389 """Create the Z3 expression `other - self`.
9395 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9396 return fpSub(_dflt_rm(), a, b, self.
ctx)
9399 """Create the Z3 expression `self * other`.
9410 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9411 return fpMul(_dflt_rm(), a, b, self.
ctx)
9414 """Create the Z3 expression `other * self`.
9423 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9424 return fpMul(_dflt_rm(), a, b, self.
ctx)
9427 """Create the Z3 expression `+self`."""
9431 """Create the Z3 expression `-self`.
9440 """Create the Z3 expression `self / other`.
9451 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9452 return fpDiv(_dflt_rm(), a, b, self.
ctx)
9455 """Create the Z3 expression `other / self`.
9464 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9465 return fpDiv(_dflt_rm(), a, b, self.
ctx)
9468 """Create the Z3 expression division `self / other`."""
9472 """Create the Z3 expression division `other / self`."""
9476 """Create the Z3 expression mod `self % other`."""
9477 return fpRem(self, other)
9480 """Create the Z3 expression mod `other % self`."""
9481 return fpRem(other, self)
9485 """Floating-point rounding mode expressions"""
9488 """Return a Z3 floating point expression as a Python string."""
9543 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9552 return isinstance(a, FPRMRef)
9556 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9557 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9563 """The sign of the numeral.
9574 num = (ctypes.c_int)()
9577 raise Z3Exception(
"error retrieving the sign of a numeral.")
9578 return num.value != 0
9580 """The sign of a floating-point numeral as a bit-vector expression.
9582 Remark: NaN's are invalid arguments.
9588 """The significand of the numeral.
9598 """The significand of the numeral as a long.
9601 >>> x.significand_as_long()
9606 ptr = (ctypes.c_ulonglong * 1)()
9608 raise Z3Exception(
"error retrieving the significand of a numeral.")
9611 """The significand of the numeral as a bit-vector expression.
9613 Remark: NaN are invalid arguments.
9619 """The exponent of the numeral.
9629 """The exponent of the numeral as a long.
9632 >>> x.exponent_as_long()
9637 ptr = (ctypes.c_longlong * 1)()
9639 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9642 """The exponent of the numeral as a bit-vector expression.
9644 Remark: NaNs are invalid arguments.
9650 """Indicates whether the numeral is a NaN."""
9655 """Indicates whether the numeral is +oo or -oo."""
9660 """Indicates whether the numeral is +zero or -zero."""
9665 """Indicates whether the numeral is normal."""
9670 """Indicates whether the numeral is subnormal."""
9675 """Indicates whether the numeral is positive."""
9680 """Indicates whether the numeral is negative."""
9686 The string representation of the numeral.
9695 return (
"FPVal(%s, %s)" % (s, self.
sortsort()))
9699 """Return `True` if `a` is a Z3 floating-point expression.
9709 return isinstance(a, FPRef)
9713 """Return `True` if `a` is a Z3 floating-point numeral value.
9724 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9728 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9730 >>> Single = FPSort(8, 24)
9731 >>> Double = FPSort(11, 53)
9734 >>> x = Const('x', Single)
9742def _to_float_str(val, exp=0):
9743 if isinstance(val, float):
9747 sone = math.copysign(1.0, val)
9752 elif val == float(
"+inf"):
9754 elif val == float(
"-inf"):
9757 v = val.as_integer_ratio()
9760 rvs = str(num) +
"/" + str(den)
9761 res = rvs +
"p" + _to_int_str(exp)
9762 elif isinstance(val, bool):
9769 elif isinstance(val, str):
9770 inx = val.find(
"*(2**")
9773 elif val[-1] ==
")":
9775 exp = str(int(val[inx + 5:-1]) + int(exp))
9777 _z3_assert(
False,
"String does not have floating-point numeral form.")
9779 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9783 return res +
"p" + exp
9787 """Create a Z3 floating-point NaN term.
9790 >>> set_fpa_pretty(True)
9793 >>> pb = get_fpa_pretty()
9794 >>> set_fpa_pretty(
False)
9797 >>> set_fpa_pretty(pb)
9799 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9804 """Create a Z3 floating-point +oo term.
9807 >>> pb = get_fpa_pretty()
9808 >>> set_fpa_pretty(True)
9811 >>> set_fpa_pretty(
False)
9814 >>> set_fpa_pretty(pb)
9816 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9821 """Create a Z3 floating-point -oo term."""
9822 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9827 """Create a Z3 floating-point +oo or -oo term."""
9828 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9829 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9834 """Create a Z3 floating-point +0.0 term."""
9835 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9840 """Create a Z3 floating-point -0.0 term."""
9841 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9846 """Create a Z3 floating-point +0.0 or -0.0 term."""
9847 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9848 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9852def FPVal(sig, exp=None, fps=None, ctx=None):
9853 """Return a floating-point value of value `val` and sort `fps`.
9854 If `ctx=None`, then the
global context
is used.
9859 >>> print(
"0x%.8x" % v.exponent_as_long(
False))
9879 fps = _dflt_fps(ctx)
9883 val = _to_float_str(sig)
9884 if val ==
"NaN" or val ==
"nan":
9888 elif val ==
"0.0" or val ==
"+0.0":
9890 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9892 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9898def FP(name, fpsort, ctx=None):
9899 """Return a floating-point constant named `name`.
9900 `fpsort` is the floating-point sort.
9901 If `ctx=
None`, then the
global context
is used.
9911 >>> x2 =
FP(
'x', word)
9915 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9922def FPs(names, fpsort, ctx=None):
9923 """Return an array of floating-point constants.
9925 >>> x, y, z = FPs('x y z',
FPSort(8, 24))
9936 if isinstance(names, str):
9937 names = names.split(
" ")
9938 return [
FP(name, fpsort, ctx)
for name
in names]
9942 """Create a Z3 floating-point absolute value expression.
9946 >>> x = FPVal(1.0, s)
9949 >>> y = FPVal(-20.0, s)
9954 >>> fpAbs(-1.25*(2**4))
9960 [a] = _coerce_fp_expr_list([a], ctx)
9965 """Create a Z3 floating-point addition expression.
9976 [a] = _coerce_fp_expr_list([a], ctx)
9980def _mk_fp_unary(f, rm, a, ctx):
9982 [a] = _coerce_fp_expr_list([a], ctx)
9984 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9985 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9986 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9989def _mk_fp_unary_pred(f, a, ctx):
9991 [a] = _coerce_fp_expr_list([a], ctx)
9993 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9994 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9997def _mk_fp_bin(f, rm, a, b, ctx):
9999 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10001 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10002 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
10003 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10006def _mk_fp_bin_norm(f, a, b, ctx):
10007 ctx = _get_ctx(ctx)
10008 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10010 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10011 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10014def _mk_fp_bin_pred(f, a, b, ctx):
10015 ctx = _get_ctx(ctx)
10016 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10018 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10019 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10022def _mk_fp_tern(f, rm, a, b, c, ctx):
10023 ctx = _get_ctx(ctx)
10024 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10026 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10028 c),
"Second, third or fourth argument must be a Z3 floating-point expression")
10029 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10033 """Create a Z3 floating-point addition expression.
10039 >>>
fpAdd(rm, x, y)
10043 >>>
fpAdd(rm, x, y).sort()
10046 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10050 """Create a Z3 floating-point subtraction expression.
10056 >>>
fpSub(rm, x, y)
10058 >>>
fpSub(rm, x, y).sort()
10061 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10065 """Create a Z3 floating-point multiplication expression.
10071 >>>
fpMul(rm, x, y)
10073 >>>
fpMul(rm, x, y).sort()
10076 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10080 """Create a Z3 floating-point division expression.
10086 >>>
fpDiv(rm, x, y)
10088 >>>
fpDiv(rm, x, y).sort()
10091 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10095 """Create a Z3 floating-point remainder expression.
10102 >>>
fpRem(x, y).sort()
10105 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10109 """Create a Z3 floating-point minimum expression.
10117 >>>
fpMin(x, y).sort()
10120 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10124 """Create a Z3 floating-point maximum expression.
10132 >>>
fpMax(x, y).sort()
10135 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10139 """Create a Z3 floating-point fused multiply-add expression.
10141 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10145 """Create a Z3 floating-point square root expression.
10147 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10151 """Create a Z3 floating-point roundToIntegral expression.
10153 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10157 """Create a Z3 floating-point isNaN expression.
10165 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10169 """Create a Z3 floating-point isInfinite expression.
10176 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10180 """Create a Z3 floating-point isZero expression.
10182 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10186 """Create a Z3 floating-point isNormal expression.
10188 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10192 """Create a Z3 floating-point isSubnormal expression.
10194 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10198 """Create a Z3 floating-point isNegative expression.
10200 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10204 """Create a Z3 floating-point isPositive expression.
10206 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10209def _check_fp_args(a, b):
10211 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10215 """Create the Z3 floating-point expression `other < self`.
10220 >>> (x < y).sexpr()
10223 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10227 """Create the Z3 floating-point expression `other <= self`.
10232 >>> (x <= y).sexpr()
10235 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10239 """Create the Z3 floating-point expression `other > self`.
10244 >>> (x > y).sexpr()
10247 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10251 """Create the Z3 floating-point expression `other >= self`.
10256 >>> (x >= y).sexpr()
10259 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10263 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10268 >>>
fpEQ(x, y).sexpr()
10271 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10275 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10280 >>> (x != y).sexpr()
10287 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10292 fpFP(1, 127, 4194304)
10293 >>> xv = FPVal(-1.5, s)
10297 >>> slvr.add(fpEQ(x, xv))
10300 >>> xv = FPVal(+1.5, s)
10304 >>> slvr.add(fpEQ(x, xv))
10308 _z3_assert(is_bv(sgn) and is_bv(exp)
and is_bv(sig),
"sort mismatch")
10309 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
10310 ctx = _get_ctx(ctx)
10311 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
10316 """Create a Z3 floating-point conversion expression from other term sorts
10319 From a bit-vector term in IEEE 754-2008 format:
10325 From a floating-point term
with different precision:
10336 From a signed bit-vector term:
10341 ctx = _get_ctx(ctx)
10351 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
10355 """Create a Z3 floating-point conversion expression that represents the
10356 conversion from a bit-vector term to a floating-point term.
10365 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10366 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
10367 ctx = _get_ctx(ctx)
10372 """Create a Z3 floating-point conversion expression that represents the
10373 conversion from a floating-point term to a floating-point term of different precision.
10384 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10385 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
10386 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10387 ctx = _get_ctx(ctx)
10392 """Create a Z3 floating-point conversion expression that represents the
10393 conversion from a real term to a floating-point term.
10402 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10403 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
10404 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10405 ctx = _get_ctx(ctx)
10410 """Create a Z3 floating-point conversion expression that represents the
10411 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10420 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10421 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10422 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10423 ctx = _get_ctx(ctx)
10428 """Create a Z3 floating-point conversion expression that represents the
10429 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10438 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10439 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10440 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10441 ctx = _get_ctx(ctx)
10446 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10448 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10449 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
10450 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
10451 ctx = _get_ctx(ctx)
10456 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10460 >>> print(
is_fp(x))
10462 >>> print(
is_bv(y))
10464 >>> print(
is_fp(y))
10466 >>> print(
is_bv(x))
10470 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10471 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10472 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10473 ctx = _get_ctx(ctx)
10478 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10482 >>> print(
is_fp(x))
10484 >>> print(
is_bv(y))
10486 >>> print(
is_fp(y))
10488 >>> print(
is_bv(x))
10492 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10493 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10494 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10495 ctx = _get_ctx(ctx)
10500 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10504 >>> print(
is_fp(x))
10508 >>> print(
is_fp(y))
10514 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10515 ctx = _get_ctx(ctx)
10520 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10522 The size of the resulting bit-vector is automatically determined.
10524 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10525 knows only one NaN
and it will always produce the same bit-vector representation of
10530 >>> print(
is_fp(x))
10532 >>> print(
is_bv(y))
10534 >>> print(
is_fp(y))
10536 >>> print(
is_bv(x))
10540 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10541 ctx = _get_ctx(ctx)
10552 """Sequence sort."""
10555 """Determine if sort is a string
10570 """Create a string sort
10575 ctx = _get_ctx(ctx)
10580 """Create a sequence sort over elements provided in the argument
10589 """Sequence expression."""
10595 return Concat(self, other)
10598 return Concat(other, self)
10617 """Return a string representation of sequence expression."""
10619 string_length = ctypes.c_uint()
10621 return string_at(chars, size=string_length.value).decode(
"latin-1")
10637def _coerce_seq(s, ctx=None):
10638 if isinstance(s, str):
10639 ctx = _get_ctx(ctx)
10642 raise Z3Exception(
"Non-expression passed as a sequence")
10644 raise Z3Exception(
"Non-sequence passed as a sequence")
10648def _get_ctx2(a, b, ctx=None):
10659 """Return `True` if `a` is a Z3 sequence expression.
10665 return isinstance(a, SeqRef)
10669 """Return `True` if `a` is a Z3 string expression.
10673 return isinstance(a, SeqRef)
and a.is_string()
10677 """return 'True' if 'a' is a Z3 string constant expression.
10683 return isinstance(a, SeqRef)
and a.is_string_value()
10687 """create a string expression"""
10688 s =
"".join(str(ch)
if ord(ch) < 128
else "\\u{%x}" % (ord(ch))
for ch
in s)
10689 ctx = _get_ctx(ctx)
10694 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10698 ctx = _get_ctx(ctx)
10703 """Return a tuple of String constants. """
10704 ctx = _get_ctx(ctx)
10705 if isinstance(names, str):
10706 names = names.split(
" ")
10707 return [
String(name, ctx)
for name
in names]
10711 """Extract substring or subsequence starting at offset"""
10712 return Extract(s, offset, length)
10716 """Extract substring or subsequence starting at offset"""
10717 return Extract(s, offset, length)
10721 """Create the empty sequence of the given sort
10724 >>> print(e.eq(e2))
10733 if isinstance(s, SeqSortRef):
10735 if isinstance(s, ReSortRef):
10737 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10741 """Create the regular expression that accepts the universal language
10749 if isinstance(s, ReSortRef):
10751 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10755 """Create a singleton sequence"""
10760 """Check if 'a' is a prefix of 'b'
10768 ctx = _get_ctx2(a, b)
10769 a = _coerce_seq(a, ctx)
10770 b = _coerce_seq(b, ctx)
10775 """Check if 'a' is a suffix of 'b'
10783 ctx = _get_ctx2(a, b)
10784 a = _coerce_seq(a, ctx)
10785 b = _coerce_seq(b, ctx)
10790 """Check if 'a' contains 'b'
10797 >>> x, y, z =
Strings(
'x y z')
10802 ctx = _get_ctx2(a, b)
10803 a = _coerce_seq(a, ctx)
10804 b = _coerce_seq(b, ctx)
10809 """Replace the first occurrence of 'src' by 'dst' in 's'
10810 >>> r = Replace("aaa",
"a",
"b")
10814 ctx = _get_ctx2(dst, s)
10815 if ctx
is None and is_expr(src):
10817 src = _coerce_seq(src, ctx)
10818 dst = _coerce_seq(dst, ctx)
10819 s = _coerce_seq(s, ctx)
10824 """Retrieve the index of substring within a string starting at a specified offset.
10835 ctx = _get_ctx2(s, substr, ctx)
10836 s = _coerce_seq(s, ctx)
10837 substr = _coerce_seq(substr, ctx)
10838 if _is_int(offset):
10839 offset =
IntVal(offset, ctx)
10844 """Retrieve the last index of substring within a string"""
10846 ctx = _get_ctx2(s, substr, ctx)
10847 s = _coerce_seq(s, ctx)
10848 substr = _coerce_seq(substr, ctx)
10853 """Obtain the length of a sequence 's'
10863 """Convert string expression to integer
10879 """Convert integer expression to string"""
10886 """The regular expression that accepts sequence 's'
10891 s = _coerce_seq(s, ctx)
10898 """Regular expression sort."""
10907 if s
is None or isinstance(s, Context):
10910 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10914 """Regular expressions."""
10917 return Union(self, other)
10921 return isinstance(s, ReRef)
10925 """Create regular expression membership test
10934 s = _coerce_seq(s, re.ctx)
10939 """Create union of regular expressions.
10944 args = _get_args(args)
10947 _z3_assert(sz > 0,
"At least one argument expected.")
10948 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10953 for i
in range(sz):
10954 v[i] = args[i].as_ast()
10959 """Create intersection of regular expressions.
10962 args = _get_args(args)
10965 _z3_assert(sz > 0,
"At least one argument expected.")
10966 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10971 for i
in range(sz):
10972 v[i] = args[i].as_ast()
10977 """Create the regular expression accepting one or more repetitions of argument.
10990 """Create the regular expression that optionally accepts the argument.
11003 """Create the complement regular expression."""
11008 """Create the regular expression accepting zero or more repetitions of argument.
11021 """Create the regular expression accepting between a lower and upper bound repetitions
11022 >>> re = Loop(Re("a"), 1, 3)
11034 """Create the range regular expression over two sequences of length 1
11035 >>> range = Range("a",
"z")
11041 lo = _coerce_seq(lo, ctx)
11042 hi = _coerce_seq(hi, ctx)
11065 """Given a binary relation R, such that the two arguments have the same sort
11066 create the transitive closure relation R+.
11067 The transitive closure R+ is a new relation.
11078 if self.
lock is None:
11080 self.
lock = threading.thread.Lock()
11084 self.
lock.acquire()
11085 r = self.
bases[ctx]
11087 self.
lock.release()
11092 self.
lock.acquire()
11093 self.
bases[ctx] = r
11095 self.
lock.release()
11099 self.
lock.acquire()
11100 id = len(self.
bases) + 3
11103 self.
lock.release()
11107_prop_closures =
None
11111 global _prop_closures
11112 if _prop_closures
is None:
11117 _prop_closures.get(ctx).push()
11121 _prop_closures.get(ctx).pop(num_scopes)
11125 _prop_closures.set_threaded()
11126 new_prop = UsePropagateBase(
None, ctx)
11127 _prop_closures.set(new_prop.id, new_prop.fresh())
11128 return ctypes.c_void_p(new_prop.id)
11132 prop = _prop_closures.get(ctx)
11134 prop.fixed(id, _to_expr_ref(ctypes.c_void_p(value), prop.ctx()))
11139 prop = _prop_closures.get(ctx)
11146 prop = _prop_closures.get(ctx)
11153 prop = _prop_closures.get(ctx)
11159_user_prop_push = push_eh_type(user_prop_push)
11160_user_prop_pop = pop_eh_type(user_prop_pop)
11161_user_prop_fresh = fresh_eh_type(user_prop_fresh)
11162_user_prop_fixed = fixed_eh_type(user_prop_fixed)
11163_user_prop_final = final_eh_type(user_prop_final)
11164_user_prop_eq = eq_eh_type(user_prop_eq)
11165_user_prop_diseq = eq_eh_type(user_prop_diseq)
11178 assert s
is None or ctx
is None
11183 self.
id = _prop_closures.insert(self)
11191 self.
_ctx.ctx = ctx
11197 ctypes.c_void_p(self.
id),
11204 self.
_ctx.ctx =
None
11213 return self.
ctx().ref()
11216 assert not self.
fixed
11217 assert not self.
_ctx
11222 assert not self.
final
11223 assert not self.
_ctx
11229 assert not self.
_ctx
11234 assert not self.
diseq
11235 assert not self.
_ctx
11240 raise Z3Exception(
"push needs to be overwritten")
11243 raise Z3Exception(
"pop needs to be overwritten")
11246 raise Z3Exception(
"fresh needs to be overwritten")
11250 assert not self.
_ctx
11257 num_fixed = len(ids)
11258 _ids = (ctypes.c_uint * num_fixed)()
11259 for i
in range(num_fixed):
11262 _lhs = (ctypes.c_uint * num_eqs)()
11263 _rhs = (ctypes.c_uint * num_eqs)()
11264 for i
in range(num_eqs):
11265 _lhs[i] = eqs[i][0]
11266 _rhs[i] = eqs[i][1]
11268 self.
cb), num_fixed, _ids, num_eqs, _lhs, _rhs, e.ast)
def as_decimal(self, prec)
def approx(self, precision=10)
def __getitem__(self, idx)
def __init__(self, result, ctx)
def __deepcopy__(self, memo={})
def __radd__(self, other)
def __rmul__(self, other)
def __rsub__(self, other)
def __rtruediv__(self, other)
def __rdiv__(self, other)
def __truediv__(self, other)
def __rpow__(self, other)
def __rmod__(self, other)
def __getitem__(self, arg)
def __init__(self, m=None, ctx=None)
def __getitem__(self, key)
def __deepcopy__(self, memo={})
def __setitem__(self, k, v)
def __contains__(self, key)
def __init__(self, ast, ctx=None)
def translate(self, target)
def __deepcopy__(self, memo={})
def __contains__(self, item)
def __init__(self, v=None, ctx=None)
def __setitem__(self, i, v)
def translate(self, other_ctx)
def __deepcopy__(self, memo={})
def as_binary_string(self)
def __rlshift__(self, other)
def __radd__(self, other)
def __rxor__(self, other)
def __rshift__(self, other)
def __rand__(self, other)
def __rmul__(self, other)
def __rsub__(self, other)
def __rtruediv__(self, other)
def __rdiv__(self, other)
def __lshift__(self, other)
def __rrshift__(self, other)
def __truediv__(self, other)
def __rmod__(self, other)
def __rmul__(self, other)
def __deepcopy__(self, memo={})
def __init__(self, *args, **kws)
def __init__(self, name, ctx=None)
def declare(self, name, *args)
def declare_core(self, name, rec_name, *args)
def __deepcopy__(self, memo={})
def recognizer(self, idx)
def num_constructors(self)
def constructor(self, idx)
def exponent(self, biased=True)
def significand_as_bv(self)
def exponent_as_long(self, biased=True)
def significand_as_long(self)
def exponent_as_bv(self, biased=True)
def __radd__(self, other)
def __rmul__(self, other)
def __rsub__(self, other)
def __rtruediv__(self, other)
def __rdiv__(self, other)
def __truediv__(self, other)
def __rmod__(self, other)
def abstract(self, fml, is_forall=True)
def fact(self, head, name=None)
def rule(self, head, body=None, name=None)
def to_string(self, queries)
def add_cover(self, level, predicate, property)
def add_rule(self, head, body=None, name=None)
def assert_exprs(self, *args)
def update_rule(self, head, body, name)
def query_from_lvl(self, lvl, *query)
def parse_string(self, s)
def get_rules_along_trace(self)
def get_ground_sat_answer(self)
def set_predicate_representation(self, f, *representations)
def get_cover_delta(self, level, predicate)
def __deepcopy__(self, memo={})
def get_num_levels(self, predicate)
def declare_var(self, *vars)
def set(self, *args, **keys)
def __init__(self, fixedpoint=None, ctx=None)
def register_relation(self, *relations)
def get_rule_names_along_trace(self)
def __call__(self, *args)
def __init__(self, entry, ctx)
def __deepcopy__(self, memo={})
def __init__(self, f, ctx)
def translate(self, other_ctx)
def __deepcopy__(self, memo={})
def dimacs(self, include_names=True)
def convert_model(self, model)
def assert_exprs(self, *args)
def __getitem__(self, arg)
def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None)
def translate(self, target)
def __deepcopy__(self, memo={})
def simplify(self, *arguments, **keywords)
def as_binary_string(self)
def get_universe(self, s)
def eval(self, t, model_completion=False)
def __init__(self, m, ctx)
def __getitem__(self, idx)
def translate(self, target)
def evaluate(self, t, model_completion=False)
def __deepcopy__(self, memo={})
def get_interp(self, decl)
def add_soft(self, arg, weight="1", id=None)
def assert_exprs(self, *args)
def upper_values(self, obj)
def from_file(self, filename)
def set_on_model(self, on_model)
def check(self, *assumptions)
def __deepcopy__(self, memo={})
def assert_and_track(self, a, p)
def set(self, *args, **keys)
def lower_values(self, obj)
def __init__(self, ctx=None)
def __init__(self, opt, value, is_max)
def __getitem__(self, arg)
def __init__(self, descr, ctx=None)
def get_documentation(self, n)
def __deepcopy__(self, memo={})
def __init__(self, ctx=None, params=None)
def __deepcopy__(self, memo={})
def __init__(self, probe, ctx=None)
def __deepcopy__(self, memo={})
def no_pattern(self, idx)
def num_no_patterns(self)
def __getitem__(self, arg)
def as_decimal(self, prec)
def numerator_as_long(self)
def denominator_as_long(self)
def __init__(self, c, ctx)
def __init__(self, c, ctx)
def __radd__(self, other)
def is_string_value(self)
Strings, Sequences and Regular expressions.
def dimacs(self, include_names=True)
def import_model_converter(self, other)
def __init__(self, solver=None, ctx=None, logFile=None)
def assert_exprs(self, *args)
def cube(self, vars=None)
def from_file(self, filename)
def check(self, *assumptions)
def translate(self, target)
def __deepcopy__(self, memo={})
def consequences(self, assumptions, variables)
def assert_and_track(self, a, p)
def set(self, *args, **keys)
def __getattr__(self, name)
def __getitem__(self, idx)
def __init__(self, stats, ctx)
def get_key_value(self, key)
def __deepcopy__(self, memo={})
def __call__(self, goal, *arguments, **keywords)
def solver(self, logFile=None)
def __init__(self, tactic, ctx=None)
def __deepcopy__(self, memo={})
def apply(self, goal, *arguments, **keywords)
def add_fixed(self, fixed)
def add_diseq(self, diseq)
def pop(self, num_scopes)
def __init__(self, s, ctx=None)
def propagate(self, e, ids, eqs=[])
def add_final(self, final)
expr range(expr const &lo, expr const &hi)
def fpIsNegative(a, ctx=None)
def fpFP(sgn, exp, sig, ctx=None)
def fpToFP(a1, a2=None, a3=None, ctx=None)
def PiecewiseLinearOrder(a, index)
def fpRealToFP(rm, v, sort, ctx=None)
def fpUnsignedToFP(rm, v, sort, ctx=None)
def fpAdd(rm, a, b, ctx=None)
def RealVarVector(n, ctx=None)
def RoundNearestTiesToEven(ctx=None)
def fpRoundToIntegral(rm, a, ctx=None)
def BVMulNoOverflow(a, b, signed)
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
def BVSDivNoOverflow(a, b)
def get_default_rounding_mode(ctx=None)
def fpFPToFP(rm, v, sort, ctx=None)
def simplify(a, *arguments, **keywords)
Utils.
def ParThen(t1, t2, ctx=None)
def substitute_vars(t, *m)
def fpToReal(x, ctx=None)
def BoolVector(prefix, sz, ctx=None)
def BitVec(name, bv, ctx=None)
def Repeat(t, max=4294967295, ctx=None)
def BitVecs(names, bv, ctx=None)
def DeclareSort(name, ctx=None)
def With(t, *args, **keys)
def args2params(arguments, keywords, ctx=None)
def PbEq(args, k, ctx=None)
def fpSqrt(rm, a, ctx=None)
def Reals(names, ctx=None)
def fpGEQ(a, b, ctx=None)
def FiniteDomainVal(val, sort, ctx=None)
def set_default_rounding_mode(rm, ctx=None)
def z3_error_handler(c, e)
def TryFor(t, ms, ctx=None)
def simplify_param_descrs()
def ensure_prop_closures()
def fpIsPositive(a, ctx=None)
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
def set_option(*args, **kws)
def Extract(high, low, a)
def BVAddNoUnderflow(a, b)
def get_default_fp_sort(ctx=None)
def fpIsZero(a, ctx=None)
def Range(lo, hi, ctx=None)
def set_param(*args, **kws)
def Bools(names, ctx=None)
def fpToFPUnsigned(rm, x, s, ctx=None)
def FloatQuadruple(ctx=None)
def fpToUBV(rm, x, s, ctx=None)
def fpMax(a, b, ctx=None)
def FPVal(sig, exp=None, fps=None, ctx=None)
def solve_using(s, *args, **keywords)
def FloatDouble(ctx=None)
def LinearOrder(a, index)
def probe_description(name, ctx=None)
def IndexOf(s, substr, offset=None)
def user_prop_fixed(ctx, cb, id, value)
def SimpleSolver(ctx=None, logFile=None)
def FreshInt(prefix="x", ctx=None)
def SolverFor(logic, ctx=None, logFile=None)
def FreshBool(prefix="b", ctx=None)
def BVAddNoOverflow(a, b, signed)
def SubString(s, offset, length)
def RecAddDefinition(f, args, body)
def fpRem(a, b, ctx=None)
def BitVecVal(val, bv, ctx=None)
def If(a, b, c, ctx=None)
def fpSignedToFP(rm, v, sort, ctx=None)
def BV2Int(a, is_signed=False)
def Cond(p, t1, t2, ctx=None)
def PartialOrder(a, index)
def RoundNearestTiesToAway(ctx=None)
def IntVector(prefix, sz, ctx=None)
def FPs(names, fpsort, ctx=None)
def BVSubNoOverflow(a, b)
def solve(*args, **keywords)
def FloatSingle(ctx=None)
def user_prop_pop(ctx, num_scopes)
def user_prop_fresh(id, ctx)
def RealVar(idx, ctx=None)
def SubSeq(s, offset, length)
def fpNEQ(a, b, ctx=None)
def Ints(names, ctx=None)
def fpIsNormal(a, ctx=None)
def RatVal(a, b, ctx=None)
def fpMin(a, b, ctx=None)
def EnumSort(name, values, ctx=None)
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
def fpSub(rm, a, b, ctx=None)
def is_finite_domain_sort(s)
def LastIndexOf(s, substr)
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
def RealVector(prefix, sz, ctx=None)
def is_finite_domain_value(a)
def fpToIEEEBV(x, ctx=None)
def FreshConst(sort, prefix="c")
def Implies(a, b, ctx=None)
def RoundTowardZero(ctx=None)
def RealVal(val, ctx=None)
def is_algebraic_value(a)
def String(name, ctx=None)
def user_prop_final(ctx, cb)
def fpLEQ(a, b, ctx=None)
def FiniteDomainSort(name, sz, ctx=None)
def fpDiv(rm, a, b, ctx=None)
def user_prop_eq(ctx, cb, x, y)
def FP(name, fpsort, ctx=None)
def BVSubNoUnderflow(a, b, signed)
def RecFunction(name, *sig)
def user_prop_diseq(ctx, cb, x, y)
def fpBVToFP(v, sort, ctx=None)
def RoundTowardNegative(ctx=None)
def FPSort(ebits, sbits, ctx=None)
def tactic_description(name, ctx=None)
def Strings(names, ctx=None)
def BVMulNoUnderflow(a, b)
def TupleSort(name, sorts, ctx=None)
def fpMul(rm, a, b, ctx=None)
def StringVal(s, ctx=None)
def to_symbol(s, ctx=None)
def ParAndThen(t1, t2, ctx=None)
def RoundTowardPositive(ctx=None)
def BoolVal(val, ctx=None)
def FreshReal(prefix="b", ctx=None)
def fpFMA(rm, a, b, c, ctx=None)
def Array(name, dom, rng)
def set_default_fp_sort(ebits, sbits, ctx=None)
def fpIsSubnormal(a, ctx=None)
def DisjointSum(name, sorts, ctx=None)
def fpToSBV(rm, x, s, ctx=None)
def BitVecSort(sz, ctx=None)
def fpInfinity(s, negative)
def IntVal(val, ctx=None)
def prove(claim, show=False, **keywords)
Z3_ast_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL,...
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
void Z3_API Z3_solver_propagate_diseq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression dis-equalities.
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than or equal to.
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs....
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p)
Convert a parameter description set into a string. This function is mainly used for printing the cont...
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
Z3_ast Z3_API Z3_mk_str_le(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is equal or lexicographically strictly less than s2.
Z3_params Z3_API Z3_mk_params(Z3_context c)
Create a Z3 (empty) parameter set. Starting at Z3 4.0, parameter sets are used to configure many comp...
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_param_kind Z3_API Z3_param_descrs_get_kind(Z3_context c, Z3_param_descrs p, Z3_symbol n)
Return the kind associated with the given parameter name n.
unsigned Z3_API Z3_solver_propagate_register(Z3_context c, Z3_solver s, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.
Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s)
Return the parameter description set for the given solver object.
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1....
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i)
Return the name of the parameter at given index i.
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
Z3_ast Z3_API Z3_mk_seq_at(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the unit sequence positioned at position index. The sequence is empty if the index is...
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context....
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
Z3_symbol Z3_API Z3_get_quantifier_bound_name(Z3_context c, Z3_ast a, unsigned i)
Return symbol of the i'th bound variable.
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
Z3_char_ptr Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned *length)
Retrieve the unescaped string constant stored in s.
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n,...
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode)
Select mode for the format used for pretty-printing AST nodes.
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.
Z3_goal Z3_API Z3_goal_translate(Z3_context source, Z3_goal g, Z3_context target)
Copy a goal g from the context source to the context target.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
Z3_ast_vector Z3_API Z3_solver_get_trail(Z3_context c, Z3_solver s)
Return the trail modulo model conversion, in order of decision level The decision level can be retrie...
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a)
The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3....
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v)
Add a Boolean parameter k with value v to the parameter set p.
unsigned Z3_API Z3_apply_result_get_num_subgoals(Z3_context c, Z3_apply_result r)
Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i,...
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vars, unsigned backtrack_level)
extract a next cube for a solver. The last cube is the constant true or false. The number of (non-con...
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s)
Check if s is a string sort.
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.
void Z3_API Z3_params_set_double(Z3_context c, Z3_params p, Z3_symbol k, double v)
Add a double parameter k with value v to the parameter set p.
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s)
Retrieve documentation string corresponding to parameter name s.
Z3_solver Z3_API Z3_mk_solver(Z3_context c)
Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally ...
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
void Z3_API Z3_params_set_uint(Z3_context c, Z3_params p, Z3_symbol k, unsigned v)
Add a unsigned parameter k with value v to the parameter set p.
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not.
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
void Z3_API Z3_solver_import_model_converter(Z3_context ctx, Z3_solver src, Z3_solver dst)
Ad-hoc method for importing model conversion from solver.
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, bool is_forall, unsigned weight, Z3_symbol quantifier_id, Z3_symbol skolem_id, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], unsigned num_no_patterns, Z3_ast const no_patterns[], Z3_ast body)
Create a universal or existential quantifier using a list of constants that will form the set of boun...
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s)
Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if th...
Z3_sort Z3_API Z3_get_re_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for regex sort.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
Z3_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s)
Return a string describing all solver available parameters.
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
Z3_sort Z3_API Z3_get_array_sort_domain(Z3_context c, Z3_sort t)
Return the domain of the given array sort. In the case of a multi-dimensional array,...
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
Z3_ast Z3_API Z3_func_decl_to_ast(Z3_context c, Z3_func_decl f)
Convert a Z3_func_decl into Z3_ast. This is just type casting.
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
Z3_ast Z3_API Z3_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.
Z3_ast Z3_API Z3_mk_str_lt(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is lexicographically strictly less than s2.
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
Z3_func_decl Z3_API Z3_mk_fresh_func_decl(Z3_context c, Z3_string prefix, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a fresh constant or function.
void Z3_API Z3_solver_propagate_final(Z3_context c, Z3_solver s, Z3_final_eh final_eh)
register a callback on final check. This provides freedom to the propagator to delay actions or imple...
unsigned Z3_API Z3_param_descrs_size(Z3_context c, Z3_param_descrs p)
Return the number of parameters in the given parameter description set.
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p)
Convert a Z3_pattern into Z3_ast. This is just type casting.
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
unsigned Z3_API Z3_func_interp_get_arity(Z3_context c, Z3_func_interp f)
Return the arity (number of arguments) of the given function interpretation.
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s)
Return the set of non units in the solver state.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
Z3_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of first occurrence of substr in s starting from offset offset. If s does not contain su...
Z3_ast Z3_API Z3_get_algebraic_number_upper(Z3_context c, Z3_ast a, unsigned precision)
Return a upper bound for the given real algebraic number. The interval isolating the number is smalle...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p)
Convert a parameter set into a string. This function is mainly used for printing the contents of a pa...
void Z3_API Z3_solver_propagate_init(Z3_context c, Z3_solver s, void *user_context, Z3_push_eh push_eh, Z3_pop_eh pop_eh, Z3_fresh_eh fresh_eh)
register a user-properator with the solver.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
Z3_ast Z3_API Z3_translate(Z3_context source, Z3_ast a, Z3_context target)
Translate/Copy the AST a from context source to context target. AST a must have been created using co...
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s.
Z3_string Z3_API Z3_benchmark_to_smtlib_string(Z3_context c, Z3_string name, Z3_string logic, Z3_string status, Z3_string attributes, unsigned num_assumptions, Z3_ast const assumptions[], Z3_ast formula)
Convert the given benchmark into SMT-LIB formatted string.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
void Z3_API Z3_param_descrs_dec_ref(Z3_context c, Z3_param_descrs p)
Decrement the reference counter of the given parameter description set.
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size)
Create a named finite domain sort.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz, unsigned levels[])
retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat c...
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
Z3_apply_result Z3_API Z3_tactic_apply_ex(Z3_context c, Z3_tactic t, Z3_goal g, Z3_params p)
Apply tactic t to the goal g using the parameter set p.
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.
void Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback, unsigned num_fixed, unsigned const *fixed_ids, unsigned num_eqs, unsigned const *eq_lhs, unsigned const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values. This is a callback a client may invoke during the fixe...
unsigned Z3_API Z3_solver_get_num_scopes(Z3_context c, Z3_solver s)
Return the number of backtracking points.
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
void Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.
unsigned Z3_API Z3_get_app_num_args(Z3_context c, Z3_app a)
Return the number of argument of an application. If t is an constant, then the number of arguments is...
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
void Z3_API Z3_dec_ref(Z3_context c, Z3_ast a)
Decrement the reference counter of the given AST. The context c should have been created using Z3_mk_...
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s)
Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the as...
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
Z3_ast Z3_API Z3_mk_set_has_size(Z3_context c, Z3_ast set, Z3_ast k)
Create predicate that holds if Boolean array set has k elements set to true.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the tactic with the given name.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural but two different AST objects can m...
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
void Z3_API Z3_params_validate(Z3_context c, Z3_params p, Z3_param_descrs d)
Validate the parameter set p against the parameter description set d.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms)
Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms mil...
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return the last occurrence of substr in s. If s does not contain substr, then the value is -1,...
Z3_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p)
Increment the reference counter of the given parameter description set.
Z3_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_ast Z3_API Z3_sort_to_ast(Z3_context c, Z3_sort s)
Convert a Z3_sort into Z3_ast. This is just type casting.
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function interpretation. It represents the value of f in a particular p...
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality....
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t *r)
Store the size of the sort in r. Return false if the call failed. That is, Z3_get_sort_kind(s) == Z3_...
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const args[])
Create a constant or function application.
Z3_sort_kind Z3_API Z3_get_sort_kind(Z3_context c, Z3_sort t)
Return the sort kind (e.g., array, tuple, int, bool, etc).
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
Z3_sort Z3_API Z3_get_domain(Z3_context c, Z3_func_decl d, unsigned i)
Return the sort of the i-th parameter of the given function declaration.
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
void Z3_API Z3_params_set_symbol(Z3_context c, Z3_params p, Z3_symbol k, Z3_symbol v)
Add a symbol parameter k with value v to the parameter set p.
Z3_string Z3_API Z3_solver_to_dimacs_string(Z3_context c, Z3_solver s, bool include_names)
Convert a solver into a DIMACS formatted string.
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
Z3_ast Z3_API Z3_substitute_vars(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const to[])
Substitute the free variables in a with the expressions in to. For every i smaller than num_exprs,...
Z3_ast Z3_API Z3_mk_or(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] or ... or args[num_args-1].
Z3_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
Z3_ast Z3_API Z3_mk_seq_extract(Z3_context c, Z3_ast s, Z3_ast offset, Z3_ast length)
Extract subsequence starting at offset of length.
Z3_bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a decimal string of a numeric constant term.
void Z3_API Z3_solver_propagate_fixed(Z3_context c, Z3_solver s, Z3_fixed_eh fixed_eh)
register a callback for when an expression is bound to a fixed value. The supported expression types ...
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s)
Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_ch...
Z3_string Z3_API Z3_get_numeral_binary_string(Z3_context c, Z3_ast a)
Return numeral value, as a binary string of a numeric constant term.
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i)
Return sort of the i'th bound variable.
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.
Z3_ast Z3_API Z3_mk_ext_rotate_right(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the right t2 times.
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places.
Z3_bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
Z3_ast Z3_API Z3_mk_seq_nth(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the element positioned at position index. The function is under-specified if the inde...
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k)
Return the value associated with the key k.
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k)
Return true if the map m contains the AST key k.
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
void Z3_API Z3_fixedpoint_set_predicate_representation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f, unsigned num_relations, Z3_symbol const relation_kinds[])
Configure the predicate representation.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
void Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property)
Add property about the predicate pred. Add a property of predicate pred at level. It gets pushed forw...
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int *sgn)
Retrieves the sign of a floating-point literal.
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
unsigned Z3_API Z3_fpa_get_ebits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the exponent in a FloatingPoint sort.
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t *n, bool biased)
Return the exponent value of a floating-point numeral as a signed 64-bit integer.
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a NaN.
unsigned Z3_API Z3_fpa_get_sbits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the significand in a FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t *n)
Return the significand value of a floating-point numeral as a uint64.
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, bool biased)
Return the exponent value of a floating-point numeral as a string.
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is subnormal.
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
Z3_ast Z3_API Z3_fpa_get_numeral_significand_bv(Z3_context c, Z3_ast t)
Retrieves the significand of a floating-point literal as a bit-vector expression.
Z3_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, bool biased)
Retrieves the exponent of a floating-point literal as a bit-vector expression.
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t)
Return the significand value of a floating-point numeral as a string.
Z3_ast Z3_API Z3_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t)
Retrieves the sign of a floating-point literal as a bit-vector expression.
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a +oo or -oo.
bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is +zero or -zero.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
Z3_ast_vector Z3_API Z3_optimize_get_upper_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast_vector Z3_API Z3_optimize_get_lower_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector ...
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
Z3_param_descrs Z3_API Z3_optimize_get_param_descrs(Z3_context c, Z3_optimize o)
Return the parameter description set for the given optimize object.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_string Z3_API Z3_optimize_get_help(Z3_context c, Z3_optimize t)
Return a string containing a description of parameters accepted by optimize.
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_string Z3_API Z3_optimize_get_reason_unknown(Z3_context c, Z3_optimize d)
Retrieve a string that describes the last status returned by Z3_optimize_check.
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
void Z3_API Z3_optimize_register_model_eh(Z3_context c, Z3_optimize o, Z3_model m, void *ctx, Z3_model_eh model_eh)
register a model event handler for new models.
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.