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.
16Please send feedback, comments and/or corrections on the Issue tracker for
17https://github.com/Z3prover/z3.git. Your comments are very valuable.
42...
except Z3Exception
as ex:
43... print(
"failed: %s" % ex)
49from .z3consts import *
50from .z3printer import *
51from fractions import Fraction
56if sys.version_info.major >= 3:
57 from typing
import Iterable
67if sys.version_info.major < 3:
69 return isinstance(v, (int, long))
72 return isinstance(v, int)
84 major = ctypes.c_uint(0)
85 minor = ctypes.c_uint(0)
86 build = ctypes.c_uint(0)
87 rev = ctypes.c_uint(0)
89 return "%s.%s.%s" % (major.value, minor.value, build.value)
93 major = ctypes.c_uint(0)
94 minor = ctypes.c_uint(0)
95 build = ctypes.c_uint(0)
96 rev = ctypes.c_uint(0)
98 return (major.value, minor.value, build.value, rev.value)
105def _z3_assert(cond, msg):
107 raise Z3Exception(msg)
110def _z3_check_cint_overflow(n, name):
111 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
115 """Log interaction to a file. This function must be invoked immediately after init(). """
120 """Append user-defined string to interaction log. """
125 """Convert an integer or string into a Z3 symbol."""
132def _symbol2py(ctx, s):
133 """Convert a Z3 symbol back into a Python object. """
146 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
148 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
149 return [arg
for arg
in args[0]]
158def _get_args_ast_list(args):
160 if isinstance(args, (set, AstVector, tuple)):
161 return [arg
for arg
in args]
168def _to_param_value(val):
169 if isinstance(val, bool):
170 return "true" if val
else "false"
181 """A Context manages all other Z3 objects, global configuration options, etc.
183 Z3Py uses a default global context. For most applications this
is sufficient.
184 An application may use multiple Z3 contexts. Objects created
in one context
185 cannot be used
in another one. However, several objects may be
"translated" from
186 one context to another. It
is not safe to access Z3 objects
from multiple threads.
189 The initialization method receives
global configuration options
for the new context.
194 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
213 if Z3_del_context
is not None and self.
owner:
219 """Return a reference to the actual C pointer to the Z3 context."""
223 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
225 This method can be invoked from a thread different
from the one executing the
226 interruptible procedure.
231 """Return the global parameter description set."""
240 """Return a reference to the global Z3 context.
248 >>> x2 =
Real(
'x', c)
255 if _main_ctx
is None:
272 """Set Z3 global (or module) parameters.
277 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
281 if not set_pp_option(k, v):
296 """Reset all global (or module) parameters.
302 """Alias for 'set_param' for backward compatibility.
308 """Return the value of a Z3 global (or module) parameter
313 ptr = (ctypes.c_char_p * 1)()
315 r = z3core._to_pystr(ptr[0])
317 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
329 """Superclass for all Z3 objects that have support for pretty printing."""
334 def _repr_html_(self):
335 in_html = in_html_mode()
338 set_html_mode(in_html)
343 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions."""
351 if self.
ctx.ref()
is not None and self.
ast is not None and Z3_dec_ref
is not None:
356 return _to_ast_ref(self.
ast, self.
ctx)
359 return obj_to_string(self)
362 return obj_to_string(self)
365 return self.
eq(other)
378 elif is_eq(self)
and self.num_args() == 2:
379 return self.arg(0).
eq(self.arg(1))
381 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
384 """Return a string representing the AST node in s-expression notation.
387 >>> ((x + 1)*x).
sexpr()
393 """Return a pointer to the corresponding C Z3_ast object."""
397 """Return unique identifier for object. It can be used for hash-tables and maps."""
401 """Return a reference to the C context where this AST node is stored."""
402 return self.
ctx.ref()
405 """Return `True` if `self` and `other` are structurally identical.
418 _z3_assert(
is_ast(other),
"Z3 AST expected")
422 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
430 >>> x.translate(c2) + y
434 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
441 """Return a hashcode for the `self`.
445 >>> n1.hash() == n2.hash()
452 """Return `True` if `a` is an AST node.
469 return isinstance(a, AstRef)
473 """Return `True` if `a` and `b` are structurally identical AST nodes.
491def _ast_kind(ctx, a):
497def _ctx_from_ast_arg_list(args, default_ctx=None):
505 _z3_assert(ctx == a.ctx,
"Context mismatch")
511def _ctx_from_ast_args(*args):
512 return _ctx_from_ast_arg_list(args)
515def _to_func_decl_array(args):
517 _args = (FuncDecl * sz)()
519 _args[i] = args[i].as_func_decl()
523def _to_ast_array(args):
527 _args[i] = args[i].as_ast()
531def _to_ref_array(ref, args):
535 _args[i] = args[i].as_ast()
539def _to_ast_ref(a, ctx):
540 k = _ast_kind(ctx, a)
542 return _to_sort_ref(a, ctx)
543 elif k == Z3_FUNC_DECL_AST:
544 return _to_func_decl_ref(a, ctx)
546 return _to_expr_ref(a, ctx)
555def _sort_kind(ctx, s):
560 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node."""
569 """Return the Z3 internal kind of a sort.
570 This method can be used to test if `self`
is one of the Z3 builtin sorts.
573 >>> b.kind() == Z3_BOOL_SORT
575 >>> b.kind() == Z3_INT_SORT
578 >>> A.kind() == Z3_ARRAY_SORT
580 >>> A.kind() == Z3_INT_SORT
583 return _sort_kind(self.
ctx, self.
ast)
586 """Return `True` if `self` is a subsort of `other`.
594 """Try to cast `val` as an element of sort `self`.
596 This method is used
in Z3Py to convert Python objects such
as integers,
597 floats, longs
and strings into Z3 expressions.
604 _z3_assert(
is_expr(val),
"Z3 expression expected")
605 _z3_assert(self.
eq(val.sort()),
"Sort mismatch")
609 """Return the name (string) of sort `self`.
619 """Return `True` if `self` and `other` are the same Z3 sort.
632 """Return `True` if `self` and `other` are not the same Z3 sort.
644 return AstRef.__hash__(self)
648 """Return `True` if `s` is a Z3 sort.
657 return isinstance(s, SortRef)
660def _to_sort_ref(s, ctx):
662 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
663 k = _sort_kind(ctx, s)
664 if k == Z3_BOOL_SORT:
666 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
668 elif k == Z3_BV_SORT:
670 elif k == Z3_ARRAY_SORT:
672 elif k == Z3_DATATYPE_SORT:
674 elif k == Z3_FINITE_DOMAIN_SORT:
676 elif k == Z3_FLOATING_POINT_SORT:
678 elif k == Z3_ROUNDING_MODE_SORT:
680 elif k == Z3_RE_SORT:
682 elif k == Z3_SEQ_SORT:
684 elif k == Z3_CHAR_SORT:
690 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
694 """Create a new uninterpreted sort named `name`.
696 If `ctx=None`, then the new sort
is declared
in the
global Z3Py context.
699 >>> a =
Const(
'a', A)
700 >>> b =
Const(
'b', A)
719 """Function declaration. Every constant and function have an associated declaration.
721 The declaration assigns a name, a sort (i.e., type), and for function
722 the sort (i.e., type) of each of its arguments. Note that,
in Z3,
723 a constant
is a function
with 0 arguments.
736 """Return the name of the function declaration `self`.
741 >>> isinstance(f.name(), str)
747 """Return the number of arguments of a function declaration.
748 If `self` is a constant, then `self.
arity()`
is 0.
757 """Return the sort of the argument `i` of a function declaration.
758 This method assumes that `0 <= i < self.arity()`.
767 _z3_assert(i < self.
arity(),
"Index out of bounds")
771 """Return the sort of the range of a function declaration.
772 For constants, this is the sort of the constant.
781 """Return the internal kind of a function declaration.
782 It can be used to identify Z3 built-in functions such
as addition, multiplication, etc.
785 >>> d = (x + 1).decl()
786 >>> d.kind() == Z3_OP_ADD
788 >>> d.kind() == Z3_OP_MUL
796 result = [
None for i
in range(n)]
799 if k == Z3_PARAMETER_INT:
801 elif k == Z3_PARAMETER_DOUBLE:
803 elif k == Z3_PARAMETER_RATIONAL:
805 elif k == Z3_PARAMETER_SYMBOL:
807 elif k == Z3_PARAMETER_SORT:
809 elif k == Z3_PARAMETER_AST:
811 elif k == Z3_PARAMETER_FUNC_DECL:
818 """Create a Z3 application expression using the function `self`, and the given arguments.
820 The arguments must be Z3 expressions. This method assumes that
821 the sorts of the elements in `args` match the sorts of the
822 domain. Limited coercion
is supported. For example,
if
823 args[0]
is a Python integer,
and the function expects a Z3
824 integer, then the argument
is automatically converted into a
835 args = _get_args(args)
838 _z3_assert(num == self.
arity(),
"Incorrect number of arguments to %s" % self)
839 _args = (Ast * num)()
844 tmp = self.
domain(i).cast(args[i])
846 _args[i] = tmp.as_ast()
851 """Return `True` if `a` is a Z3 function declaration.
860 return isinstance(a, FuncDeclRef)
864 """Create a new Z3 uninterpreted function with the given sorts.
872 _z3_assert(len(sig) > 0,
"At least two arguments expected")
876 _z3_assert(
is_sort(rng),
"Z3 sort expected")
877 dom = (Sort * arity)()
878 for i
in range(arity):
880 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
887 """Create a new fresh Z3 uninterpreted function with the given sorts.
891 _z3_assert(len(sig) > 0,
"At least two arguments expected")
895 _z3_assert(
is_sort(rng),
"Z3 sort expected")
896 dom = (z3.Sort * arity)()
897 for i
in range(arity):
899 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
905def _to_func_decl_ref(a, ctx):
910 """Create a new Z3 recursive with the given sorts."""
913 _z3_assert(len(sig) > 0,
"At least two arguments expected")
917 _z3_assert(
is_sort(rng),
"Z3 sort expected")
918 dom = (Sort * arity)()
919 for i
in range(arity):
921 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
928 """Set the body of a recursive function.
929 Recursive definitions can be simplified if they are applied to ground
933 >>> n =
Int(
'n', ctx)
938 >>> s.add(fac(n) < 3)
941 >>> s.model().eval(fac(5))
947 args = _get_args(args)
951 _args[i] = args[i].ast
962 """Constraints, formulas and terms are expressions in Z3.
964 Expressions are ASTs. Every expression has a sort.
965 There are three main kinds of expressions:
966 function applications, quantifiers and bounded variables.
967 A constant
is a function application
with 0 arguments.
968 For quantifier free problems, all expressions are
969 function applications.
979 """Return the sort of expression `self`.
991 """Shorthand for `self.sort().kind()`.
994 >>> a.sort_kind() == Z3_ARRAY_SORT
996 >>> a.sort_kind() == Z3_INT_SORT
999 return self.
sort().kind()
1002 """Return a Z3 expression that represents the constraint `self == other`.
1004 If `other` is `
None`, then this method simply returns `
False`.
1015 a, b = _coerce_exprs(self, other)
1020 return AstRef.__hash__(self)
1023 """Return a Z3 expression that represents the constraint `self != other`.
1025 If `other` is `
None`, then this method simply returns `
True`.
1036 a, b = _coerce_exprs(self, other)
1037 _args, sz = _to_ast_array((a, b))
1044 """Return the Z3 function declaration associated with a Z3 application.
1055 _z3_assert(
is_app(self),
"Z3 application expected")
1059 """Return the number of arguments of a Z3 application.
1071 _z3_assert(
is_app(self),
"Z3 application expected")
1075 """Return argument `idx` of the application `self`.
1077 This method assumes that `self` is a function application
with at least `idx+1` arguments.
1091 _z3_assert(
is_app(self),
"Z3 application expected")
1092 _z3_assert(idx < self.
num_args(),
"Invalid argument index")
1096 """Return a list containing the children of the given expression
1120 """inverse function to the serialize method on ExprRef.
1121 It is made available to make it easier
for users to serialize expressions back
and forth between
1122 strings. Solvers can be serialized using the
'sexpr()' method.
1126 if len(s.assertions()) != 1:
1127 raise Z3Exception(
"single assertion expected")
1128 fml = s.assertions()[0]
1129 if fml.num_args() != 1:
1130 raise Z3Exception(
"dummy function 'F' expected")
1133def _to_expr_ref(a, ctx):
1134 if isinstance(a, Pattern):
1138 if k == Z3_QUANTIFIER_AST:
1141 if sk == Z3_BOOL_SORT:
1143 if sk == Z3_INT_SORT:
1144 if k == Z3_NUMERAL_AST:
1147 if sk == Z3_REAL_SORT:
1148 if k == Z3_NUMERAL_AST:
1150 if _is_algebraic(ctx, a):
1153 if sk == Z3_BV_SORT:
1154 if k == Z3_NUMERAL_AST:
1158 if sk == Z3_ARRAY_SORT:
1160 if sk == Z3_DATATYPE_SORT:
1162 if sk == Z3_FLOATING_POINT_SORT:
1163 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1166 return FPRef(a, ctx)
1167 if sk == Z3_FINITE_DOMAIN_SORT:
1168 if k == Z3_NUMERAL_AST:
1172 if sk == Z3_ROUNDING_MODE_SORT:
1174 if sk == Z3_SEQ_SORT:
1176 if sk == Z3_CHAR_SORT:
1178 if sk == Z3_RE_SORT:
1179 return ReRef(a, ctx)
1183def _coerce_expr_merge(s, a):
1196 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1197 _z3_assert(
False,
"sort mismatch")
1202def _coerce_exprs(a, b, ctx=None):
1204 a = _py2expr(a, ctx)
1205 b = _py2expr(b, ctx)
1206 if isinstance(a, str)
and isinstance(b, SeqRef):
1208 if isinstance(b, str)
and isinstance(a, SeqRef):
1211 s = _coerce_expr_merge(s, a)
1212 s = _coerce_expr_merge(s, b)
1218def _reduce(func, sequence, initial):
1220 for element
in sequence:
1221 result = func(result, element)
1225def _coerce_expr_list(alist, ctx=None):
1232 alist = [_py2expr(a, ctx)
for a
in alist]
1233 s = _reduce(_coerce_expr_merge, alist,
None)
1234 return [s.cast(a)
for a
in alist]
1238 """Return `True` if `a` is a Z3 expression.
1257 return isinstance(a, ExprRef)
1261 """Return `True` if `a` is a Z3 function application.
1263 Note that, constants are function applications with 0 arguments.
1280 if not isinstance(a, ExprRef):
1282 k = _ast_kind(a.ctx, a)
1283 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1287 """Return `True` if `a` is Z3 constant/variable expression.
1302 return is_app(a)
and a.num_args() == 0
1306 """Return `True` if `a` is variable.
1308 Z3 uses de-Bruijn indices for representing bound variables
in
1318 >>> q =
ForAll(x, f(x) == x)
1327 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1331 """Return the de-Bruijn index of the Z3 bounded variable `a`.
1341 >>> q =
ForAll([x, y], f(x, y) == x + y)
1347 >>> v1 = b.arg(0).arg(0)
1348 >>> v2 = b.arg(0).arg(1)
1359 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1364 """Return `True` if `a` is an application of the given kind `k`.
1373 return is_app(a)
and a.decl().kind() == k
1376def If(a, b, c, ctx=None):
1377 """Create a Z3 if-then-else expression.
1381 >>> max =
If(x > y, x, y)
1387 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1388 return Cond(a, b, c, ctx)
1390 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1393 b, c = _coerce_exprs(b, c, ctx)
1395 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1396 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1400 """Create a Z3 distinct expression.
1414 args = _get_args(args)
1415 ctx = _ctx_from_ast_arg_list(args)
1417 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1418 args = _coerce_expr_list(args, ctx)
1419 _args, sz = _to_ast_array(args)
1423def _mk_bin(f, a, b):
1426 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1427 args[0] = a.as_ast()
1428 args[1] = b.as_ast()
1429 return f(a.ctx.ref(), 2, args)
1433 """Create a constant of the given sort.
1439 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1445 """Create several constants of the given sort.
1447 `names` is a string containing the names of all constants to be created.
1448 Blank spaces separate the names of different constants.
1454 if isinstance(names, str):
1455 names = names.split(
" ")
1456 return [
Const(name, sort)
for name
in names]
1460 """Create a fresh constant of a specified sort"""
1461 ctx = _get_ctx(sort.ctx)
1466 """Create a Z3 free variable. Free variables are used to create quantified formulas.
1474 _z3_assert(
is_sort(s),
"Z3 sort expected")
1475 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1480 Create a real free variable. Free variables are used to create quantified formulas.
1481 They are also used to create polynomials.
1491 Create a list of Real free variables.
1492 The variables have ids: 0, 1, ..., n-1
1511 """Try to cast `val` as a Boolean.
1523 if isinstance(val, bool):
1527 msg =
"True, False or Z3 Boolean expression expected. Received %s of type %s"
1528 _z3_assert(
is_expr(val), msg % (val, type(val)))
1529 if not self.
eq(val.sort()):
1530 _z3_assert(self.
eq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1534 return isinstance(other, ArithSortRef)
1544 """All Boolean expressions are instances of this class."""
1553 """Create the Z3 expression `self * other`.
1559 return If(self, other, 0)
1563 """Return `True` if `a` is a Z3 Boolean expression.
1577 return isinstance(a, BoolRef)
1581 """Return `True` if `a` is the Z3 true expression.
1599 """Return `True` if `a` is the Z3 false expression.
1613 """Return `True` if `a` is a Z3 and expression.
1615 >>> p, q = Bools('p q')
1625 """Return `True` if `a` is a Z3 or expression.
1627 >>> p, q = Bools('p q')
1637 """Return `True` if `a` is a Z3 implication expression.
1639 >>> p, q = Bools('p q')
1649 """Return `True` if `a` is a Z3 not expression.
1661 """Return `True` if `a` is a Z3 equality expression.
1663 >>> x, y = Ints('x y')
1671 """Return `True` if `a` is a Z3 distinct expression.
1673 >>> x, y, z = Ints('x y z')
1683 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
1701 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used.
1720 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
1732 """Return a tuple of Boolean constants.
1734 `names` is a single string containing all names separated by blank spaces.
1735 If `ctx=
None`, then the
global context
is used.
1737 >>> p, q, r =
Bools(
'p q r')
1738 >>>
And(p,
Or(q, r))
1742 if isinstance(names, str):
1743 names = names.split(
" ")
1744 return [
Bool(name, ctx)
for name
in names]
1748 """Return a list of Boolean constants of size `sz`.
1750 The constants are named using the given prefix.
1751 If `ctx=None`, then the
global context
is used.
1757 And(p__0, p__1, p__2)
1759 return [
Bool(
"%s__%s" % (prefix, i))
for i
in range(sz)]
1763 """Return a fresh Boolean constant in the given context using the given prefix.
1765 If `ctx=None`, then the
global context
is used.
1777 """Create a Z3 implies expression.
1779 >>> p, q = Bools('p q')
1783 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1791 """Create a Z3 Xor expression.
1793 >>> p, q = Bools('p q')
1799 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1807 """Create a Z3 not expression or probe.
1815 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1832def _has_probe(args):
1833 """Return `True` if one of the elements of the given collection is a Z3 probe."""
1841 """Create a Z3 and-expression or and-probe.
1843 >>> p, q, r = Bools('p q r')
1848 And(p__0, p__1, p__2, p__3, p__4)
1852 last_arg = args[len(args) - 1]
1853 if isinstance(last_arg, Context):
1854 ctx = args[len(args) - 1]
1855 args = args[:len(args) - 1]
1856 elif len(args) == 1
and isinstance(args[0], AstVector):
1858 args = [a
for a
in args[0]]
1861 args = _get_args(args)
1862 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1864 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1865 if _has_probe(args):
1866 return _probe_and(args, ctx)
1868 args = _coerce_expr_list(args, ctx)
1869 _args, sz = _to_ast_array(args)
1874 """Create a Z3 or-expression or or-probe.
1876 >>> p, q, r = Bools('p q r')
1881 Or(p__0, p__1, p__2, p__3, p__4)
1885 last_arg = args[len(args) - 1]
1886 if isinstance(last_arg, Context):
1887 ctx = args[len(args) - 1]
1888 args = args[:len(args) - 1]
1889 elif len(args) == 1
and isinstance(args[0], AstVector):
1891 args = [a
for a
in args[0]]
1894 args = _get_args(args)
1895 ctx = _get_ctx(_ctx_from_ast_arg_list(args, ctx))
1897 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1898 if _has_probe(args):
1899 return _probe_or(args, ctx)
1901 args = _coerce_expr_list(args, ctx)
1902 _args, sz = _to_ast_array(args)
1913 """Patterns are hints for quantifier instantiation.
1925 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
1929 >>> q =
ForAll(x, f(x) == 0, patterns = [ f(x) ])
1932 >>> q.num_patterns()
1939 return isinstance(a, PatternRef)
1943 """Create a Z3 multi-pattern using the given expressions `*args`
1951 >>> q.num_patterns()
1959 _z3_assert(len(args) > 0,
"At least one argument expected")
1960 _z3_assert(all([
is_expr(a)
for a
in args]),
"Z3 expressions expected")
1962 args, sz = _to_ast_array(args)
1966def _to_pattern(arg):
1980 """Universally and Existentially quantified formulas."""
1989 """Return the Boolean sort or sort of Lambda."""
1995 """Return `True` if `self` is a universal quantifier.
1999 >>> q =
ForAll(x, f(x) == 0)
2002 >>> q =
Exists(x, f(x) != 0)
2009 """Return `True` if `self` is an existential quantifier.
2013 >>> q =
ForAll(x, f(x) == 0)
2016 >>> q =
Exists(x, f(x) != 0)
2023 """Return `True` if `self` is a lambda expression.
2030 >>> q =
Exists(x, f(x) != 0)
2037 """Return the Z3 expression `self[arg]`.
2040 _z3_assert(self.
is_lambda(),
"quantifier should be a lambda expression")
2041 return _array_select(self, arg)
2044 """Return the weight annotation of `self`.
2048 >>> q =
ForAll(x, f(x) == 0)
2051 >>> q =
ForAll(x, f(x) == 0, weight=10)
2058 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`.
2063 >>> q =
ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2064 >>> q.num_patterns()
2070 """Return a pattern (i.e., quantifier instantiation hints) in `self`.
2075 >>> q =
ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ])
2076 >>> q.num_patterns()
2084 _z3_assert(idx < self.
num_patterns(),
"Invalid pattern idx")
2088 """Return the number of no-patterns."""
2092 """Return a no-pattern."""
2098 """Return the expression being quantified.
2102 >>> q =
ForAll(x, f(x) == 0)
2109 """Return the number of variables bounded by this quantifier.
2114 >>> q =
ForAll([x, y], f(x, y) >= x)
2121 """Return a string representing a name used when displaying the quantifier.
2126 >>> q =
ForAll([x, y], f(x, y) >= x)
2133 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
2137 """Return the sort of a bound variable.
2142 >>> q =
ForAll([x, y], f(x, y) >= x)
2149 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
2153 """Return a list containing a single element self.body()
2157 >>> q =
ForAll(x, f(x) == 0)
2161 return [self.
body()]
2165 """Return `True` if `a` is a Z3 quantifier.
2169 >>> q =
ForAll(x, f(x) == 0)
2175 return isinstance(a, QuantifierRef)
2178def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2180 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2181 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2182 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2183 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2194 _vs = (Ast * num_vars)()
2195 for i
in range(num_vars):
2197 _vs[i] = vs[i].as_ast()
2198 patterns = [_to_pattern(p)
for p
in patterns]
2199 num_pats = len(patterns)
2200 _pats = (Pattern * num_pats)()
2201 for i
in range(num_pats):
2202 _pats[i] = patterns[i].ast
2203 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2209 num_no_pats, _no_pats,
2210 body.as_ast()), ctx)
2213def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2214 """Create a Z3 forall formula.
2216 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations.
2221 >>>
ForAll([x, y], f(x, y) >= x)
2222 ForAll([x, y], f(x, y) >= x)
2223 >>>
ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
2224 ForAll([x, y], f(x, y) >= x)
2225 >>>
ForAll([x, y], f(x, y) >= x, weight=10)
2226 ForAll([x, y], f(x, y) >= x)
2228 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2231def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2232 """Create a Z3 exists formula.
2234 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
2240 >>> q =
Exists([x, y], f(x, y) >= x, skid=
"foo")
2242 Exists([x, y], f(x, y) >= x)
2245 >>> r =
Tactic(
'nnf')(q).as_expr()
2249 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2253 """Create a Z3 lambda expression.
2257 >>> lo, hi, e, i =
Ints(
'lo hi e i')
2258 >>> mem1 =
Lambda([i],
If(
And(lo <= i, i <= hi), e, mem0[i]))
2266 _vs = (Ast * num_vars)()
2267 for i
in range(num_vars):
2269 _vs[i] = vs[i].as_ast()
2280 """Real and Integer sorts."""
2283 """Return `True` if `self` is of the sort Real.
2294 return self.
kind() == Z3_REAL_SORT
2297 """Return `True` if `self` is of the sort Integer.
2308 return self.
kind() == Z3_INT_SORT
2314 """Return `True` if `self` is a subsort of `other`."""
2318 """Try to cast `val` as an Integer or Real.
2333 _z3_assert(self.
ctxctx == val.ctx,
"Context mismatch")
2337 if val_s.is_int()
and self.
is_real():
2339 if val_s.is_bool()
and self.
is_int():
2340 return If(val, 1, 0)
2341 if val_s.is_bool()
and self.
is_real():
2344 _z3_assert(
False,
"Z3 Integer/Real expression expected")
2351 msg =
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s"
2352 _z3_assert(
False, msg % self)
2356 """Return `True` if s is an arithmetical sort (type).
2364 >>> n =
Int(
'x') + 1
2368 return isinstance(s, ArithSortRef)
2372 """Integer and Real expressions."""
2375 """Return the sort (type) of the arithmetical expression `self`.
2385 """Return `True` if `self` is an integer expression.
2399 """Return `True` if `self` is an real expression.
2410 """Create the Z3 expression `self + other`.
2419 a, b = _coerce_exprs(self, other)
2420 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctx)
2423 """Create the Z3 expression `other + self`.
2429 a, b = _coerce_exprs(self, other)
2430 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctx)
2433 """Create the Z3 expression `self * other`.
2442 if isinstance(other, BoolRef):
2443 return If(other, self, 0)
2444 a, b = _coerce_exprs(self, other)
2445 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctx)
2448 """Create the Z3 expression `other * self`.
2454 a, b = _coerce_exprs(self, other)
2455 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctx)
2458 """Create the Z3 expression `self - other`.
2467 a, b = _coerce_exprs(self, other)
2468 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctx)
2471 """Create the Z3 expression `other - self`.
2477 a, b = _coerce_exprs(self, other)
2478 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctx)
2481 """Create the Z3 expression `self**other` (** is the power operator).
2491 a, b = _coerce_exprs(self, other)
2495 """Create the Z3 expression `other**self` (** is the power operator).
2505 a, b = _coerce_exprs(self, other)
2509 """Create the Z3 expression `other/self`.
2528 a, b = _coerce_exprs(self, other)
2532 """Create the Z3 expression `other/self`."""
2536 """Create the Z3 expression `other/self`.
2549 a, b = _coerce_exprs(self, other)
2553 """Create the Z3 expression `other/self`."""
2557 """Create the Z3 expression `other%self`.
2566 a, b = _coerce_exprs(self, other)
2568 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2572 """Create the Z3 expression `other%self`.
2578 a, b = _coerce_exprs(self, other)
2580 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2584 """Return an expression representing `-self`.
2604 """Create the Z3 expression `other <= self`.
2606 >>> x, y = Ints('x y')
2613 a, b = _coerce_exprs(self, other)
2617 """Create the Z3 expression `other < self`.
2619 >>> x, y = Ints('x y')
2626 a, b = _coerce_exprs(self, other)
2630 """Create the Z3 expression `other > self`.
2632 >>> x, y = Ints('x y')
2639 a, b = _coerce_exprs(self, other)
2643 """Create the Z3 expression `other >= self`.
2645 >>> x, y = Ints('x y')
2652 a, b = _coerce_exprs(self, other)
2657 """Return `True` if `a` is an arithmetical expression.
2674 return isinstance(a, ArithRef)
2678 """Return `True` if `a` is an integer expression.
2697 """Return `True` if `a` is a real expression.
2715def _is_numeral(ctx, a):
2719def _is_algebraic(ctx, a):
2724 """Return `True` if `a` is an integer value of sort Int.
2732 >>> n =
Int(
'x') + 1
2744 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2748 """Return `True` if `a` is rational value of sort Real.
2758 >>> n =
Real(
'x') + 1
2766 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2770 """Return `True` if `a` is an algebraic value of sort Real.
2780 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2784 """Return `True` if `a` is an expression of the form b + c.
2786 >>> x, y = Ints('x y')
2796 """Return `True` if `a` is an expression of the form b * c.
2798 >>> x, y = Ints('x y')
2808 """Return `True` if `a` is an expression of the form b - c.
2810 >>> x, y = Ints('x y')
2820 """Return `True` if `a` is an expression of the form b / c.
2822 >>> x, y = Reals('x y')
2827 >>> x, y =
Ints(
'x y')
2837 """Return `True` if `a` is an expression of the form b div c.
2839 >>> x, y = Ints('x y')
2849 """Return `True` if `a` is an expression of the form b % c.
2851 >>> x, y = Ints('x y')
2861 """Return `True` if `a` is an expression of the form b <= c.
2863 >>> x, y = Ints('x y')
2873 """Return `True` if `a` is an expression of the form b < c.
2875 >>> x, y = Ints('x y')
2885 """Return `True` if `a` is an expression of the form b >= c.
2887 >>> x, y = Ints('x y')
2897 """Return `True` if `a` is an expression of the form b > c.
2899 >>> x, y = Ints('x y')
2909 """Return `True` if `a` is an expression of the form IsInt(b).
2921 """Return `True` if `a` is an expression of the form ToReal(b).
2936 """Return `True` if `a` is an expression of the form ToInt(b).
2951 """Integer values."""
2954 """Return a Z3 integer numeral as a Python long (bignum) numeral.
2963 _z3_assert(self.
is_int(),
"Integer value expected")
2967 """Return a Z3 integer numeral as a Python string.
2975 """Return a Z3 integer numeral as a Python binary string.
2977 >>> v.as_binary_string()
2984 """Rational values."""
2987 """ Return the numerator of a Z3 rational numeral.
3002 """ Return the denominator of a Z3 rational numeral.
3013 """ Return the numerator as a Python long.
3020 >>> v.numerator_as_long() + 1 == 10000000001
3026 """ Return the denominator as a Python long.
3031 >>> v.denominator_as_long()
3046 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
3050 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3062 """Return a Z3 rational numeral as a Python string.
3071 """Return a Z3 rational as a Python Fraction object.
3081 """Algebraic irrational values."""
3084 """Return a Z3 rational number that approximates the algebraic number `self`.
3085 The result `r` is such that |r - self| <= 1/10^precision
3089 6838717160008073720548335/4835703278458516698824704
3096 """Return a string representation of the algebraic number `self` in decimal notation
3097 using `prec` decimal places.
3100 >>> x.as_decimal(10)
3102 >>> x.as_decimal(20)
3103 '1.41421356237309504880?'
3114def _py2expr(a, ctx=None):
3115 if isinstance(a, bool):
3119 if isinstance(a, float):
3121 if isinstance(a, str):
3126 _z3_assert(
False,
"Python bool, int, long or float expected")
3130 """Return the integer sort in the given context. If `ctx=None`, then the global context is used.
3147 """Return the real sort in the given context. If `ctx=None`, then the global context is used.
3163def _to_int_str(val):
3164 if isinstance(val, float):
3165 return str(int(val))
3166 elif isinstance(val, bool):
3173 elif isinstance(val, str):
3176 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
3180 """Return a Z3 integer value. If `ctx=None`, then the global context is used.
3192 """Return a Z3 real value.
3194 `val` may be a Python int, long, float or string representing a number
in decimal
or rational notation.
3195 If `ctx=
None`, then the
global context
is used.
3211 """Return a Z3 rational a/b.
3213 If `ctx=None`, then the
global context
is used.
3221 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
3222 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3226def Q(a, b, ctx=None):
3227 """Return a Z3 rational a/b.
3229 If `ctx=None`, then the
global context
is used.
3240 """Return an integer constant named `name`. If `ctx=None`, then the global context is used.
3253 """Return a tuple of Integer constants.
3255 >>> x, y, z = Ints('x y z')
3260 if isinstance(names, str):
3261 names = names.split(
" ")
3262 return [
Int(name, ctx)
for name
in names]
3266 """Return a list of integer constants of size `sz`.
3275 return [
Int(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3279 """Return a fresh integer constant in the given context using the given prefix.
3293 """Return a real constant named `name`. If `ctx=None`, then the global context is used.
3306 """Return a tuple of real constants.
3308 >>> x, y, z = Reals('x y z')
3311 >>>
Sum(x, y, z).sort()
3315 if isinstance(names, str):
3316 names = names.split(
" ")
3317 return [
Real(name, ctx)
for name
in names]
3321 """Return a list of real constants of size `sz`.
3332 return [
Real(
"%s__%s" % (prefix, i), ctx)
for i
in range(sz)]
3336 """Return a fresh real constant in the given context using the given prefix.
3350 """ Return the Z3 expression ToReal(a).
3362 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3368 """ Return the Z3 expression ToInt(a).
3380 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3386 """ Return the Z3 predicate IsInt(a).
3389 >>>
IsInt(x +
"1/2")
3393 >>>
solve(
IsInt(x +
"1/2"), x > 0, x < 1, x !=
"1/2")
3397 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3403 """ Return a Z3 expression which represents the square root of a.
3416 """ Return a Z3 expression which represents the cubic root of a.
3435 """Bit-vector sort."""
3438 """Return the size (number of bits) of the bit-vector sort `self`.
3450 """Try to cast `val` as a Bit-Vector.
3455 >>> b.cast(10).sexpr()
3460 _z3_assert(self.
ctxctx == val.ctx,
"Context mismatch")
3468 """Return True if `s` is a Z3 bit-vector sort.
3475 return isinstance(s, BitVecSortRef)
3479 """Bit-vector expressions."""
3482 """Return the sort of the bit-vector expression `self`.
3493 """Return the number of bits of the bit-vector expression `self`.
3504 """Create the Z3 expression `self + other`.
3513 a, b = _coerce_exprs(self, other)
3517 """Create the Z3 expression `other + self`.
3523 a, b = _coerce_exprs(self, other)
3527 """Create the Z3 expression `self * other`.
3536 a, b = _coerce_exprs(self, other)
3540 """Create the Z3 expression `other * self`.
3546 a, b = _coerce_exprs(self, other)
3550 """Create the Z3 expression `self - other`.
3559 a, b = _coerce_exprs(self, other)
3563 """Create the Z3 expression `other - self`.
3569 a, b = _coerce_exprs(self, other)
3573 """Create the Z3 expression bitwise-or `self | other`.
3582 a, b = _coerce_exprs(self, other)
3586 """Create the Z3 expression bitwise-or `other | self`.
3592 a, b = _coerce_exprs(self, other)
3596 """Create the Z3 expression bitwise-and `self & other`.
3605 a, b = _coerce_exprs(self, other)
3609 """Create the Z3 expression bitwise-or `other & self`.
3615 a, b = _coerce_exprs(self, other)
3619 """Create the Z3 expression bitwise-xor `self ^ other`.
3628 a, b = _coerce_exprs(self, other)
3632 """Create the Z3 expression bitwise-xor `other ^ self`.
3638 a, b = _coerce_exprs(self, other)
3651 """Return an expression representing `-self`.
3662 """Create the Z3 expression bitwise-not `~self`.
3673 """Create the Z3 expression (signed) division `self / other`.
3675 Use the function UDiv() for unsigned division.
3688 a, b = _coerce_exprs(self, other)
3692 """Create the Z3 expression (signed) division `self / other`."""
3696 """Create the Z3 expression (signed) division `other / self`.
3698 Use the function UDiv() for unsigned division.
3703 >>> (10 / x).
sexpr()
3704 '(bvsdiv #x0000000a x)'
3706 '(bvudiv #x0000000a x)'
3708 a, b = _coerce_exprs(self, other)
3712 """Create the Z3 expression (signed) division `other / self`."""
3716 """Create the Z3 expression (signed) mod `self % other`.
3718 Use the function URem() for unsigned remainder,
and SRem()
for signed remainder.
3733 a, b = _coerce_exprs(self, other)
3737 """Create the Z3 expression (signed) mod `other % self`.
3739 Use the function URem() for unsigned remainder,
and SRem()
for signed remainder.
3744 >>> (10 % x).
sexpr()
3745 '(bvsmod #x0000000a x)'
3747 '(bvurem #x0000000a x)'
3749 '(bvsrem #x0000000a x)'
3751 a, b = _coerce_exprs(self, other)
3755 """Create the Z3 expression (signed) `other <= self`.
3757 Use the function ULE() for unsigned less than
or equal to.
3762 >>> (x <= y).
sexpr()
3767 a, b = _coerce_exprs(self, other)
3771 """Create the Z3 expression (signed) `other < self`.
3773 Use the function ULT() for unsigned less than.
3783 a, b = _coerce_exprs(self, other)
3787 """Create the Z3 expression (signed) `other > self`.
3789 Use the function UGT() for unsigned greater than.
3799 a, b = _coerce_exprs(self, other)
3803 """Create the Z3 expression (signed) `other >= self`.
3805 Use the function UGE() for unsigned greater than
or equal to.
3810 >>> (x >= y).
sexpr()
3815 a, b = _coerce_exprs(self, other)
3819 """Create the Z3 expression (arithmetical) right shift `self >> other`
3821 Use the function LShR() for the right logical shift
3826 >>> (x >> y).
sexpr()
3845 a, b = _coerce_exprs(self, other)
3849 """Create the Z3 expression left shift `self << other`
3854 >>> (x << y).
sexpr()
3859 a, b = _coerce_exprs(self, other)
3863 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3865 Use the function LShR() for the right logical shift
3870 >>> (10 >> x).
sexpr()
3871 '(bvashr #x0000000a x)'
3873 a, b = _coerce_exprs(self, other)
3877 """Create the Z3 expression left shift `other << self`.
3879 Use the function LShR() for the right logical shift
3884 >>> (10 << x).
sexpr()
3885 '(bvshl #x0000000a x)'
3887 a, b = _coerce_exprs(self, other)
3892 """Bit-vector values."""
3895 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3900 >>> print("0x%.8x" % v.as_long())
3906 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral.
3907 The most significant bit is assumed to be the sign.
3922 if val >= 2**(sz - 1):
3924 if val < -2**(sz - 1):
3936 """Return `True` if `a` is a Z3 bit-vector expression.
3946 return isinstance(a, BitVecRef)
3950 """Return `True` if `a` is a Z3 bit-vector numeral value.
3961 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3965 """Return the Z3 expression BV2Int(a).
3973 >>> x >
BV2Int(b, is_signed=
False)
3975 >>> x >
BV2Int(b, is_signed=
True)
3981 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
3988 """Return the z3 expression Int2BV(a, num_bits).
3989 It is a bit-vector of width num_bits
and represents the
3990 modulo of a by 2^num_bits
3997 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
4003 >>> x = Const('x', Byte)
4012 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
4017 >>> print("0x%.8x" % v.as_long())
4029 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
4030 If `ctx=None`, then the
global context
is used.
4040 >>> x2 =
BitVec(
'x', word)
4044 if isinstance(bv, BitVecSortRef):
4053 """Return a tuple of bit-vector constants of size bv.
4055 >>> x, y, z = BitVecs('x y z', 16)
4068 if isinstance(names, str):
4069 names = names.split(
" ")
4070 return [
BitVec(name, bv, ctx)
for name
in names]
4074 """Create a Z3 bit-vector concatenation expression.
4084 args = _get_args(args)
4087 _z3_assert(sz >= 2,
"At least two arguments expected.")
4094 if is_seq(args[0])
or isinstance(args[0], str):
4095 args = [_coerce_seq(s, ctx)
for s
in args]
4097 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
4100 v[i] = args[i].as_ast()
4105 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
4108 v[i] = args[i].as_ast()
4112 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
4114 for i
in range(sz - 1):
4120 """Create a Z3 bit-vector extraction expression.
4121 Extract is overloaded to also work on sequence extraction.
4122 The functions SubString
and SubSeq are redirected to Extract.
4123 For this case, the arguments are reinterpreted
as:
4124 high -
is a sequence (string)
4126 a -
is the length to be extracted
4136 if isinstance(high, str):
4140 offset, length = _coerce_exprs(low, a, s.ctx)
4143 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
4144 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
4145 "First and second arguments must be non negative integers")
4146 _z3_assert(
is_bv(a),
"Third argument must be a Z3 bit-vector expression")
4150def _check_bv_args(a, b):
4152 _z3_assert(
is_bv(a)
or is_bv(b),
"First or second argument must be a Z3 bit-vector expression")
4156 """Create the Z3 expression (unsigned) `other <= self`.
4158 Use the operator <= for signed less than
or equal to.
4163 >>> (x <= y).sexpr()
4165 >>>
ULE(x, y).sexpr()
4168 _check_bv_args(a, b)
4169 a, b = _coerce_exprs(a, b)
4174 """Create the Z3 expression (unsigned) `other < self`.
4176 Use the operator < for signed less than.
4183 >>>
ULT(x, y).sexpr()
4186 _check_bv_args(a, b)
4187 a, b = _coerce_exprs(a, b)
4192 """Create the Z3 expression (unsigned) `other >= self`.
4194 Use the operator >= for signed greater than
or equal to.
4199 >>> (x >= y).sexpr()
4201 >>>
UGE(x, y).sexpr()
4204 _check_bv_args(a, b)
4205 a, b = _coerce_exprs(a, b)
4210 """Create the Z3 expression (unsigned) `other > self`.
4212 Use the operator > for signed greater than.
4219 >>>
UGT(x, y).sexpr()
4222 _check_bv_args(a, b)
4223 a, b = _coerce_exprs(a, b)
4228 """Create the Z3 expression (unsigned) division `self / other`.
4230 Use the operator / for signed division.
4236 >>>
UDiv(x, y).sort()
4240 >>>
UDiv(x, y).sexpr()
4243 _check_bv_args(a, b)
4244 a, b = _coerce_exprs(a, b)
4249 """Create the Z3 expression (unsigned) remainder `self % other`.
4251 Use the operator % for signed modulus,
and SRem()
for signed remainder.
4257 >>>
URem(x, y).sort()
4261 >>>
URem(x, y).sexpr()
4264 _check_bv_args(a, b)
4265 a, b = _coerce_exprs(a, b)
4270 """Create the Z3 expression signed remainder.
4272 Use the operator % for signed modulus,
and URem()
for unsigned remainder.
4278 >>>
SRem(x, y).sort()
4282 >>>
SRem(x, y).sexpr()
4285 _check_bv_args(a, b)
4286 a, b = _coerce_exprs(a, b)
4291 """Create the Z3 expression logical right shift.
4293 Use the operator >> for the arithmetical right shift.
4298 >>> (x >> y).sexpr()
4300 >>>
LShR(x, y).sexpr()
4317 _check_bv_args(a, b)
4318 a, b = _coerce_exprs(a, b)
4323 """Return an expression representing `a` rotated to the left `b` times.
4333 _check_bv_args(a, b)
4334 a, b = _coerce_exprs(a, b)
4339 """Return an expression representing `a` rotated to the right `b` times.
4349 _check_bv_args(a, b)
4350 a, b = _coerce_exprs(a, b)
4355 """Return a bit-vector expression with `n` extra sign-bits.
4375 >>> print(
"%.x" % v.as_long())
4379 _z3_assert(_is_int(n),
"First argument must be an integer")
4380 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4385 """Return a bit-vector expression with `n` extra zero-bits.
4407 _z3_assert(_is_int(n),
"First argument must be an integer")
4408 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4413 """Return an expression representing `n` copies of `a`.
4422 >>> print(
"%.x" % v0.as_long())
4427 >>> print(
"%.x" % v.as_long())
4431 _z3_assert(_is_int(n),
"First argument must be an integer")
4432 _z3_assert(
is_bv(a),
"Second argument must be a Z3 bit-vector expression")
4437 """Return the reduction-and expression of `a`."""
4439 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4444 """Return the reduction-or expression of `a`."""
4446 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4451 """A predicate the determines that bit-vector addition does not overflow"""
4452 _check_bv_args(a, b)
4453 a, b = _coerce_exprs(a, b)
4458 """A predicate the determines that signed bit-vector addition does not underflow"""
4459 _check_bv_args(a, b)
4460 a, b = _coerce_exprs(a, b)
4465 """A predicate the determines that bit-vector subtraction does not overflow"""
4466 _check_bv_args(a, b)
4467 a, b = _coerce_exprs(a, b)
4472 """A predicate the determines that bit-vector subtraction does not underflow"""
4473 _check_bv_args(a, b)
4474 a, b = _coerce_exprs(a, b)
4479 """A predicate the determines that bit-vector signed division does not overflow"""
4480 _check_bv_args(a, b)
4481 a, b = _coerce_exprs(a, b)
4486 """A predicate the determines that bit-vector unary negation does not overflow"""
4488 _z3_assert(
is_bv(a),
"First argument must be a Z3 bit-vector expression")
4493 """A predicate the determines that bit-vector multiplication does not overflow"""
4494 _check_bv_args(a, b)
4495 a, b = _coerce_exprs(a, b)
4500 """A predicate the determines that bit-vector signed multiplication does not underflow"""
4501 _check_bv_args(a, b)
4502 a, b = _coerce_exprs(a, b)
4516 """Return the domain of the array sort `self`.
4525 """Return the domain of the array sort `self`.
4530 """Return the range of the array sort `self`.
4540 """Array expressions. """
4543 """Return the array sort of the array expression `self`.
4552 """Shorthand for `self.sort().domain()`.
4561 """Shorthand for self.sort().domain_n(i)`."""
4565 """Shorthand for `self.sort().range()`.
4574 """Return the Z3 expression `self[arg]`.
4583 return _array_select(self, arg)
4589def _array_select(ar, arg):
4590 if isinstance(arg, tuple):
4591 args = [ar.domain_n(i).cast(arg[i])
for i
in range(len(arg))]
4592 _args, sz = _to_ast_array(args)
4593 return _to_expr_ref(
Z3_mk_select_n(ar.ctx_ref(), ar.as_ast(), sz, _args), ar.ctx)
4594 arg = ar.domain().cast(arg)
4595 return _to_expr_ref(
Z3_mk_select(ar.ctx_ref(), ar.as_ast(), arg.as_ast()), ar.ctx)
4603 """Return `True` if `a` is a Z3 array expression.
4613 return isinstance(a, ArrayRef)
4617 """Return `True` if `a` is a Z3 constant array.
4630 """Return `True` if `a` is a Z3 constant array.
4643 """Return `True` if `a` is a Z3 map array expression.
4659 """Return `True` if `a` is a Z3 default array expression.
4664 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4668 """Return the function declaration associated with a Z3 map array expression.
4681 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4692 """Return the Z3 array sort with the given domain and range sorts.
4705 sig = _get_args(sig)
4707 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4708 arity = len(sig) - 1
4713 _z3_assert(
is_sort(s),
"Z3 sort expected")
4714 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4718 dom = (Sort * arity)()
4719 for i
in range(arity):
4725 """Return an array constant named `name` with the given domain and range sorts.
4739 """Return a Z3 store array expression.
4742 >>> i, v =
Ints(
'i v')
4746 >>>
prove(s[i] == v)
4753 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4754 args = _get_args(args)
4757 raise Z3Exception(
"array update requires index and value arguments")
4761 i = a.sort().domain().cast(i)
4762 v = a.sort().
range().cast(v)
4763 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4764 v = a.sort().
range().cast(args[-1])
4765 idxs = [a.sort().domain_n(i).cast(args[i])
for i
in range(len(args)-1)]
4766 _args, sz = _to_ast_array(idxs)
4767 return _to_expr_ref(
Z3_mk_store_n(ctx.ref(), a.as_ast(), sz, _args, v.as_ast()), ctx)
4771 """ Return a default value for array expression.
4777 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4782 """Return a Z3 store array expression.
4785 >>> i, v =
Ints(
'i v')
4786 >>> s =
Store(a, i, v)
4789 >>>
prove(s[i] == v)
4799 """Return a Z3 select array expression.
4808 args = _get_args(args)
4810 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4815 """Return a Z3 map array expression.
4820 >>> b =
Map(f, a1, a2)
4823 >>>
prove(b[0] == f(a1[0], a2[0]))
4826 args = _get_args(args)
4828 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4829 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4830 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4831 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4832 _args, sz = _to_ast_array(args)
4838 """Return a Z3 constant array expression.
4852 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4855 v = _py2expr(v, ctx)
4860 """Return extensionality index for one-dimensional arrays.
4868 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4873 k = _py2expr(k, ctx)
4878 """Return `True` if `a` is a Z3 array select application.
4891 """Return `True` if `a` is a Z3 array store application.
4909 """ Create a set sort over element sort s"""
4914 """Create the empty set
4923 """Create the full set
4932 """ Take the union of sets
4938 args = _get_args(args)
4939 ctx = _ctx_from_ast_arg_list(args)
4940 _args, sz = _to_ast_array(args)
4945 """ Take the union of sets
4951 args = _get_args(args)
4952 ctx = _ctx_from_ast_arg_list(args)
4953 _args, sz = _to_ast_array(args)
4958 """ Add element e to set s
4963 ctx = _ctx_from_ast_arg_list([s, e])
4964 e = _py2expr(e, ctx)
4969 """ Remove element e to set s
4974 ctx = _ctx_from_ast_arg_list([s, e])
4975 e = _py2expr(e, ctx)
4980 """ The complement of set s
4990 """ The set difference of a and b
4996 ctx = _ctx_from_ast_arg_list([a, b])
5001 """ Check if e is a member of set s
5006 ctx = _ctx_from_ast_arg_list([s, e])
5007 e = _py2expr(e, ctx)
5012 """ Check if a is a subset of b
5018 ctx = _ctx_from_ast_arg_list([a, b])
5028def _valid_accessor(acc):
5029 """Return `True` if acc is pair of the form (String, Datatype or Sort). """
5030 if not isinstance(acc, tuple):
5034 return isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
5038 """Helper class for declaring Z3 datatypes.
5041 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5042 >>> List.declare(
'nil')
5043 >>> List = List.create()
5047 >>> List.cons(10, List.nil)
5049 >>> List.cons(10, List.nil).sort()
5051 >>> cons = List.cons
5055 >>> n = cons(1, cons(0, nil))
5057 cons(1, cons(0, nil))
5076 _z3_assert(isinstance(name, str),
"String expected")
5077 _z3_assert(isinstance(rec_name, str),
"String expected")
5079 all([_valid_accessor(a)
for a
in args]),
5080 "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)",
5085 """Declare constructor named `name` with the given accessors `args`.
5086 Each accessor is a pair `(name, sort)`, where `name`
is a string
and `sort` a Z3 sort
5087 or a reference to the datatypes being declared.
5089 In the following example `List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))`
5090 declares the constructor named `cons` that builds a new List using an integer
and a List.
5091 It also declares the accessors `car`
and `cdr`. The accessor `car` extracts the integer
5092 of a `cons` cell,
and `cdr` the list of a `cons` cell. After all constructors were declared,
5093 we use the method
create() to create the actual datatype
in Z3.
5096 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5097 >>> List.declare(
'nil')
5098 >>> List = List.create()
5101 _z3_assert(isinstance(name, str),
"String expected")
5102 _z3_assert(name !=
"",
"Constructor name cannot be empty")
5109 """Create a Z3 datatype based on the constructors declared using the method `declare()`.
5111 The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
5114 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5115 >>> List.declare(
'nil')
5116 >>> List = List.create()
5119 >>> List.cons(10, List.nil)
5126 """Auxiliary object used to create Z3 datatypes."""
5133 if self.
ctx.ref()
is not None and Z3_del_constructor
is not None:
5138 """Auxiliary object used to create Z3 datatypes."""
5145 if self.
ctx.ref()
is not None and Z3_del_constructor_list
is not None:
5150 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
5152 In the following example we define a Tree-List using two mutually recursive datatypes.
5154 >>> TreeList = Datatype('TreeList')
5157 >>> Tree.declare(
'leaf', (
'val',
IntSort()))
5159 >>> Tree.declare(
'node', (
'children', TreeList))
5160 >>> TreeList.declare(
'nil')
5161 >>> TreeList.declare(
'cons', (
'car', Tree), (
'cdr', TreeList))
5163 >>> Tree.val(Tree.leaf(10))
5165 >>>
simplify(Tree.val(Tree.leaf(10)))
5167 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
5169 node(cons(leaf(10), cons(leaf(20), nil)))
5170 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
5173 >>>
simplify(TreeList.car(Tree.children(n2)) == n1)
5178 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
5179 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
5180 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
5181 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
5184 names = (Symbol * num)()
5185 out = (Sort * num)()
5186 clists = (ConstructorList * num)()
5188 for i
in range(num):
5191 num_cs = len(d.constructors)
5192 cs = (Constructor * num_cs)()
5193 for j
in range(num_cs):
5194 c = d.constructors[j]
5199 fnames = (Symbol * num_fs)()
5200 sorts = (Sort * num_fs)()
5201 refs = (ctypes.c_uint * num_fs)()
5202 for k
in range(num_fs):
5206 if isinstance(ftype, Datatype):
5209 ds.count(ftype) == 1,
5210 "One and only one occurrence of each datatype is expected",
5213 refs[k] = ds.index(ftype)
5216 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
5217 sorts[k] = ftype.ast
5226 for i
in range(num):
5228 num_cs = dref.num_constructors()
5229 for j
in range(num_cs):
5230 cref = dref.constructor(j)
5231 cref_name = cref.name()
5232 cref_arity = cref.arity()
5233 if cref.arity() == 0:
5235 setattr(dref, cref_name, cref)
5236 rref = dref.recognizer(j)
5237 setattr(dref,
"is_" + cref_name, rref)
5238 for k
in range(cref_arity):
5239 aref = dref.accessor(j, k)
5240 setattr(dref, aref.name(), aref)
5242 return tuple(result)
5246 """Datatype sorts."""
5249 """Return the number of constructors in the given Z3 datatype.
5252 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5253 >>> List.declare(
'nil')
5254 >>> List = List.create()
5256 >>> List.num_constructors()
5262 """Return a constructor of the datatype `self`.
5265 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5266 >>> List.declare(
'nil')
5267 >>> List = List.create()
5269 >>> List.num_constructors()
5271 >>> List.constructor(0)
5273 >>> List.constructor(1)
5281 """In Z3, each constructor has an associated recognizer predicate.
5283 If the constructor is named `name`, then the recognizer `is_name`.
5286 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5287 >>> List.declare(
'nil')
5288 >>> List = List.create()
5290 >>> List.num_constructors()
5292 >>> List.recognizer(0)
5294 >>> List.recognizer(1)
5296 >>>
simplify(List.is_nil(List.cons(10, List.nil)))
5298 >>>
simplify(List.is_cons(List.cons(10, List.nil)))
5300 >>> l =
Const(
'l', List)
5309 """In Z3, each constructor has 0 or more accessor.
5310 The number of accessors is equal to the arity of the constructor.
5313 >>> List.declare(
'cons', (
'car',
IntSort()), (
'cdr', List))
5314 >>> List.declare(
'nil')
5315 >>> List = List.create()
5316 >>> List.num_constructors()
5318 >>> List.constructor(0)
5320 >>> num_accs = List.constructor(0).arity()
5323 >>> List.accessor(0, 0)
5325 >>> List.accessor(0, 1)
5327 >>> List.constructor(1)
5329 >>> num_accs = List.constructor(1).arity()
5335 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
5343 """Datatype expressions."""
5346 """Return the datatype sort of the datatype expression `self`."""
5350 """Create a reference to a sort that was declared, or will be declared, as a recursive datatype"""
5355 """Create a named tuple sort base on a set of underlying sorts
5360 projects = [("project%d" % i, sorts[i])
for i
in range(len(sorts))]
5361 tuple.declare(name, *projects)
5362 tuple = tuple.create()
5363 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
5367 """Create a named tagged union sort base on a set of underlying sorts
5372 for i
in range(len(sorts)):
5373 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
5375 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
5379 """Return a new enumeration sort named `name` containing the given values.
5381 The result is a pair (sort, list of constants).
5383 >>> Color, (red, green, blue) =
EnumSort(
'Color', [
'red',
'green',
'blue'])
5386 _z3_assert(isinstance(name, str),
"Name must be a string")
5387 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5388 _z3_assert(len(values) > 0,
"At least one value expected")
5391 _val_names = (Symbol * num)()
5392 for i
in range(num):
5394 _values = (FuncDecl * num)()
5395 _testers = (FuncDecl * num)()
5399 for i
in range(num):
5401 V = [a()
for a
in V]
5412 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3.
5414 Consider using the function `args2params` to create instances of this object.
5429 if self.
ctx.ref()
is not None and Z3_params_dec_ref
is not None:
5433 """Set parameter name with value val."""
5435 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5437 if isinstance(val, bool):
5441 elif isinstance(val, float):
5443 elif isinstance(val, str):
5447 _z3_assert(
False,
"invalid parameter value")
5453 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5458 """Convert python arguments into a Z3_params object.
5459 A ':' is added to the keywords,
and '_' is replaced
with '-'
5461 >>>
args2params([
'model',
True,
'relevancy', 2], {
'elim_and' :
True})
5462 (params model true relevancy 2 elim_and true)
5465 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5481 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3.
5485 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5491 return ParamsDescrsRef(self.
descr, self.
ctx)
5494 if self.
ctx.ref()
is not None and Z3_param_descrs_dec_ref
is not None:
5498 """Return the size of in the parameter description `self`.
5503 """Return the size of in the parameter description `self`.
5508 """Return the i-th parameter name in the parameter description `self`.
5513 """Return the kind of the parameter named `n`.
5518 """Return the documentation string of the parameter named `n`.
5539 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible).
5541 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals.
5542 A goal has a solution if one of its subgoals has a solution.
5543 A goal
is unsatisfiable
if all subgoals are unsatisfiable.
5546 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5548 _z3_assert(goal
is None or ctx
is not None,
5549 "If goal is different from None, then ctx must be also different from None")
5552 if self.
goal is None:
5557 if self.
goal is not None and self.
ctx.ref()
is not None and Z3_goal_dec_ref
is not None:
5561 """Return the depth of the goal `self`.
5562 The depth corresponds to the number of tactics applied to `self`.
5564 >>> x, y = Ints('x y')
5566 >>> g.add(x == 0, y >= x + 1)
5569 >>> r =
Then(
'simplify',
'solve-eqs')(g)
5579 """Return `True` if `self` contains the `False` constraints.
5581 >>> x, y = Ints('x y')
5583 >>> g.inconsistent()
5585 >>> g.add(x == 0, x == 1)
5588 >>> g.inconsistent()
5590 >>> g2 =
Tactic(
'propagate-values')(g)[0]
5591 >>> g2.inconsistent()
5597 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`.
5600 >>> g.prec() == Z3_GOAL_PRECISE
5602 >>> x, y =
Ints(
'x y')
5603 >>> g.add(x == y + 1)
5604 >>> g.prec() == Z3_GOAL_PRECISE
5606 >>> t =
With(
Tactic(
'add-bounds'), add_bound_lower=0, add_bound_upper=10)
5609 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0]
5610 >>> g2.prec() == Z3_GOAL_PRECISE
5612 >>> g2.prec() == Z3_GOAL_UNDER
5618 """Alias for `prec()`.
5621 >>> g.precision() == Z3_GOAL_PRECISE
5627 """Return the number of constraints in the goal `self`.
5632 >>> x, y = Ints('x y')
5633 >>> g.add(x == 0, y > x)
5640 """Return the number of constraints in the goal `self`.
5645 >>> x, y = Ints('x y')
5646 >>> g.add(x == 0, y > x)
5653 """Return a constraint in the goal `self`.
5656 >>> x, y = Ints('x y')
5657 >>> g.add(x == 0, y > x)
5666 """Return a constraint in the goal `self`.
5669 >>> x, y = Ints('x y')
5670 >>> g.add(x == 0, y > x)
5676 if arg >= len(self):
5678 return self.
get(arg)
5681 """Assert constraints into the goal.
5685 >>> g.assert_exprs(x > 0, x < 2)
5689 args = _get_args(args)
5700 >>> g.append(x > 0, x < 2)
5711 >>> g.insert(x > 0, x < 2)
5722 >>> g.add(x > 0, x < 2)
5729 """Retrieve model from a satisfiable goal
5730 >>> a, b = Ints('a b')
5732 >>> g.add(
Or(a == 0, a == 1),
Or(b == 0, b == 1), a > b)
5736 [
Or(b == 0, b == 1),
Not(0 <= b)]
5738 [
Or(b == 0, b == 1),
Not(1 <= b)]
5754 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5758 return obj_to_string(self)
5761 """Return a textual representation of the s-expression representing the goal."""
5765 """Return a textual representation of the goal in DIMACS format."""
5769 """Copy goal `self` to context `target`.
5777 >>> g2 = g.translate(c2)
5788 _z3_assert(isinstance(target, Context),
"target must be a context")
5798 """Return a new simplified goal.
5800 This method is essentially invoking the simplify tactic.
5804 >>> g.add(x + 1 >= 2)
5807 >>> g2 = g.simplify()
5815 return t.apply(self, *arguments, **keywords)[0]
5818 """Return goal `self` as a single Z3 expression.
5847 """A collection (vector) of ASTs."""
5856 assert ctx
is not None
5861 if self.
vector is not None and self.
ctx.ref()
is not None and Z3_ast_vector_dec_ref
is not None:
5865 """Return the size of the vector `self`.
5870 >>> A.push(Int('x'))
5871 >>> A.push(
Int(
'x'))
5878 """Return the AST at position `i`.
5881 >>> A.push(Int('x') + 1)
5882 >>> A.push(
Int(
'y'))
5889 if isinstance(i, int):
5897 elif isinstance(i, slice):
5900 result.append(_to_ast_ref(
5907 """Update AST at position `i`.
5910 >>> A.push(Int('x') + 1)
5911 >>> A.push(
Int(
'y'))
5923 """Add `v` in the end of the vector.
5928 >>> A.push(Int('x'))
5935 """Resize the vector to `sz` elements.
5941 >>> for i
in range(10): A[i] =
Int(
'x')
5948 """Return `True` if the vector contains `item`.
5971 """Copy vector `self` to context `other_ctx`.
5977 >>> B = A.translate(c2)
5993 return obj_to_string(self)
5996 """Return a textual representation of the s-expression representing the vector."""
6007 """A mapping from ASTs to ASTs."""
6016 assert ctx
is not None
6024 if self.
map is not None and self.
ctx.ref()
is not None and Z3_ast_map_dec_ref
is not None:
6028 """Return the size of the map.
6041 """Return `True` if the map contains key `key`.
6054 """Retrieve the value associated with key `key`.
6065 """Add/Update key `k` with value `v`.
6084 """Remove the entry associated with key `k`.
6098 """Remove all entries from the map.
6113 """Return an AstVector containing all keys in the map.
6132 """Store the value of the interpretation of a function in a particular point."""
6143 if self.
ctx.ref()
is not None and Z3_func_entry_dec_ref
is not None:
6147 """Return the number of arguments in the given entry.
6151 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6156 >>> f_i.num_entries()
6158 >>> e = f_i.entry(0)
6165 """Return the value of argument `idx`.
6169 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6174 >>> f_i.num_entries()
6176 >>> e = f_i.entry(0)
6187 ...
except IndexError:
6188 ... print(
"index error")
6196 """Return the value of the function at point `self`.
6200 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6205 >>> f_i.num_entries()
6207 >>> e = f_i.entry(0)
6218 """Return entry `self` as a Python list.
6221 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10)
6226 >>> f_i.num_entries()
6228 >>> e = f_i.entry(0)
6233 args.append(self.
value())
6241 """Stores the interpretation of a function in a Z3 model."""
6246 if self.
f is not None:
6250 if self.
f is not None and self.
ctx.ref()
is not None and Z3_func_interp_dec_ref
is not None:
6255 Return the `else` value
for a function interpretation.
6256 Return
None if Z3 did
not specify the `
else` value
for
6261 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6272 return _to_expr_ref(r, self.
ctx)
6277 """Return the number of entries/points in the function interpretation `self`.
6281 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6293 """Return the number of arguments for each entry in the function interpretation `self`.
6297 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6307 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`.
6311 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6327 """Copy model 'self' to context 'other_ctx'.
6338 """Return the function interpretation as a Python list.
6341 >>> s.add(
f(0) == 1,
f(1) == 1,
f(2) == 0)
6355 return obj_to_string(self)
6359 """Model/Solution of a satisfiability problem (aka system of constraints)."""
6362 assert ctx
is not None
6368 if self.
ctx.ref()
is not None and Z3_model_dec_ref
is not None:
6372 return obj_to_string(self)
6375 """Return a textual representation of the s-expression representing the model."""
6378 def eval(self, t, model_completion=False):
6379 """Evaluate the expression `t` in the model `self`.
6380 If `model_completion` is enabled, then a default interpretation
is automatically added
6381 for symbols that do
not have an interpretation
in the model `self`.
6385 >>> s.add(x > 0, x < 2)
6398 >>> m.eval(y, model_completion=
True)
6406 return _to_expr_ref(r[0], self.
ctx)
6407 raise Z3Exception(
"failed to evaluate expression in the model")
6410 """Alias for `eval`.
6414 >>> s.add(x > 0, x < 2)
6418 >>> m.evaluate(x + 1)
6420 >>> m.evaluate(x == 1)
6423 >>> m.evaluate(y + x)
6427 >>> m.evaluate(y, model_completion=
True)
6430 >>> m.evaluate(y + x)
6433 return self.
eval(t, model_completion)
6436 """Return the number of constant and function declarations in the model `self`.
6441 >>> s.add(x > 0, f(x) != x)
6450 return num_consts + num_funcs
6453 """Return the interpretation for a given declaration or constant.
6458 >>> s.add(x > 0, x < 2, f(x) == 0)
6468 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6472 if decl.arity() == 0:
6474 if _r.value
is None:
6476 r = _to_expr_ref(_r, self.
ctx)
6490 sz = fi.num_entries()
6494 e =
Store(e, fe.arg_value(0), fe.value())
6505 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
6508 >>> a, b =
Consts(
'a b', A)
6520 """Return the uninterpreted sort at position `idx` < self.num_sorts().
6524 >>> a1, a2 =
Consts(
'a1 a2', A)
6525 >>> b1, b2 =
Consts(
'b1 b2', B)
6527 >>> s.add(a1 != a2, b1 != b2)
6543 """Return all uninterpreted sorts that have an interpretation in the model `self`.
6547 >>> a1, a2 =
Consts(
'a1 a2', A)
6548 >>> b1, b2 =
Consts(
'b1 b2', B)
6550 >>> s.add(a1 != a2, b1 != b2)
6560 """Return the interpretation for the uninterpreted sort `s` in the model `self`.
6563 >>> a, b =
Consts(
'a b', A)
6569 >>> m.get_universe(A)
6573 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6580 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned.
6581 If `idx` is a declaration, then the actual interpretation
is returned.
6583 The elements can be retrieved using position
or the actual declaration.
6588 >>> s.add(x > 0, x < 2, f(x) == 0)
6602 >>>
for d
in m: print(
"%s -> %s" % (d, m[d]))
6607 if idx >= len(self):
6610 if (idx < num_consts):
6614 if isinstance(idx, FuncDeclRef):
6618 if isinstance(idx, SortRef):
6621 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6625 """Return a list with all symbols that have an interpretation in the model `self`.
6629 >>> s.add(x > 0, x < 2, f(x) == 0)
6644 """Update the interpretation of a constant"""
6647 if is_func_decl(x)
and x.arity() != 0
and isinstance(value, FuncInterp):
6651 for i
in range(value.num_entries()):
6656 v.push(entry.arg_value(j))
6661 raise Z3Exception(
"Expecting 0-ary function or constant expression")
6662 value = _py2expr(value)
6666 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
6669 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6686 """Return true if n is a Z3 expression of the form (_ as-array f)."""
6687 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6691 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f)."""
6693 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6704 """Statistics for `Solver.check()`."""
6715 if self.
ctx.ref()
is not None and Z3_stats_dec_ref
is not None:
6722 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6725 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6728 out.write(u(
"<tr>"))
6730 out.write(u(
"<td>%s</td><td>%s</td></tr>" % (k, v)))
6731 out.write(u(
"</table>"))
6732 return out.getvalue()
6737 """Return the number of statistical counters.
6740 >>> s =
Then(
'simplify',
'nlsat').solver()
6744 >>> st = s.statistics()
6751 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6754 >>> s =
Then(
'simplify',
'nlsat').solver()
6758 >>> st = s.statistics()
6762 (
'nlsat propagations', 2)
6766 if idx >= len(self):
6775 """Return the list of statistical counters.
6778 >>> s =
Then(
'simplify',
'nlsat').solver()
6782 >>> st = s.statistics()
6787 """Return the value of a particular statistical counter.
6790 >>> s =
Then(
'simplify',
'nlsat').solver()
6794 >>> st = s.statistics()
6795 >>> st.get_key_value(
'nlsat propagations')
6798 for idx
in range(len(self)):
6804 raise Z3Exception(
"unknown key")
6807 """Access the value of statistical using attributes.
6809 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6810 we should use
'_' (e.g.,
'nlsat_propagations').
6813 >>> s =
Then(
'simplify',
'nlsat').solver()
6817 >>> st = s.statistics()
6818 >>> st.nlsat_propagations
6823 key = name.replace("_",
" ")
6827 raise AttributeError
6837 """Represents the result of a satisfiability check: sat, unsat, unknown.
6843 >>> isinstance(r, CheckSatResult)
6854 return isinstance(other, CheckSatResult)
and self.
r == other.r
6857 return not self.
__eq__(other)
6861 if self.
r == Z3_L_TRUE:
6863 elif self.
r == Z3_L_FALSE:
6864 return "<b>unsat</b>"
6866 return "<b>unknown</b>"
6868 if self.
r == Z3_L_TRUE:
6870 elif self.
r == Z3_L_FALSE:
6875 def _repr_html_(self):
6876 in_html = in_html_mode()
6879 set_html_mode(in_html)
6890 Solver API provides methods for implementing the main SMT 2.0 commands:
6891 push, pop, check, get-model, etc.
6894 def __init__(self, solver=None, ctx=None, logFile=None):
6895 assert solver
is None or ctx
is not None
6904 if logFile
is not None:
6905 self.
set(
"smtlib2_log", logFile)
6908 if self.
solver is not None and self.
ctx.ref()
is not None and Z3_solver_dec_ref
is not None:
6912 """Set a configuration option.
6913 The method `help()` return a string containing all available options.
6917 >>> s.set(mbqi=
True)
6918 >>> s.set(
'MBQI',
True)
6919 >>> s.set(
':mbqi',
True)
6925 """Create a backtracking point.
6947 """Backtrack \\c num backtracking points.
6969 """Return the current number of backtracking points.
6987 """Remove all asserted constraints and backtracking points created using `push()`.
7001 """Assert constraints into the solver.
7005 >>> s.assert_exprs(x > 0, x < 2)
7009 args = _get_args(args)
7012 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7020 """Assert constraints into the solver.
7024 >>> s.add(x > 0, x < 2)
7035 """Assert constraints into the solver.
7039 >>> s.append(x > 0, x < 2)
7046 """Assert constraints into the solver.
7050 >>> s.insert(x > 0, x < 2)
7057 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7059 If `p` is a string, it will be automatically converted into a Boolean constant.
7064 >>> s.set(unsat_core=
True)
7065 >>> s.assert_and_track(x > 0,
'p1')
7066 >>> s.assert_and_track(x != 1,
'p2')
7067 >>> s.assert_and_track(x < 0, p3)
7068 >>> print(s.check())
7070 >>> c = s.unsat_core()
7080 if isinstance(p, str):
7082 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7083 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7087 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not.
7093 >>> s.add(x > 0, x < 2)
7096 >>> s.model().eval(x)
7102 >>> s.add(2**x == 4)
7107 assumptions = _get_args(assumptions)
7108 num = len(assumptions)
7109 _assumptions = (Ast * num)()
7110 for i
in range(num):
7111 _assumptions[i] = s.cast(assumptions[i]).as_ast()
7116 """Return a model for the last `check()`.
7118 This function raises an exception if
7119 a model
is not available (e.g., last `
check()` returned unsat).
7123 >>> s.add(a + 2 == 0)
7132 raise Z3Exception(
"model is not available")
7135 """Import model converter from other into the current solver"""
7139 """Return a subset (as an AST vector) of the assumptions provided to the last check().
7141 These are the assumptions Z3 used in the unsatisfiability proof.
7142 Assumptions are available
in Z3. They are used to extract unsatisfiable cores.
7143 They may be also used to
"retract" assumptions. Note that, assumptions are
not really
7144 "soft constraints", but they can be used to implement them.
7146 >>> p1, p2, p3 =
Bools(
'p1 p2 p3')
7147 >>> x, y =
Ints(
'x y')
7152 >>> s.add(
Implies(p3, y > -3))
7153 >>> s.check(p1, p2, p3)
7155 >>> core = s.unsat_core()
7171 """Determine fixed values for the variables based on the solver state and assumptions.
7173 >>> a, b, c, d = Bools('a b c d')
7175 >>> s.consequences([a],[b,c,d])
7177 >>> s.consequences([
Not(c),d],[a,b,c,d])
7180 if isinstance(assumptions, list):
7182 for a
in assumptions:
7185 if isinstance(variables, list):
7190 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
7191 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
7194 variables.vector, consequences.vector)
7195 sz = len(consequences)
7196 consequences = [consequences[i]
for i
in range(sz)]
7200 """Parse assertions from a file"""
7204 """Parse assertions from a string"""
7209 The method takes an optional set of variables that restrict which
7210 variables may be used as a starting point
for cubing.
7211 If vars
is not None, then the first case split
is based on a variable
in
7215 if vars
is not None:
7222 if (len(r) == 1
and is_false(r[0])):
7229 """Access the set of variables that were touched by the most recently generated cube.
7230 This set of variables can be used as a starting point
for additional cubes.
7231 The idea
is that variables that appear
in clauses that are reduced by the most recent
7232 cube are likely more useful to cube on.
"""
7236 """Return a proof for the last `check()`. Proof construction must be enabled."""
7240 """Return an AST vector containing all added constraints.
7254 """Return an AST vector containing all currently inferred units.
7259 """Return an AST vector containing all atomic formulas in solver state that are not units.
7264 """Return trail and decision levels of the solver state after a check() call.
7266 trail = self.trail()
7267 levels = (ctypes.c_uint * len(trail))()
7269 return trail, levels
7272 """Return trail of the solver state after a check() call.
7277 """Return statistics for the last `check()`.
7284 >>> st = s.statistics()
7285 >>> st.get_key_value(
'final checks')
7295 """Return a string describing why the last `check()` returned `unknown`.
7299 >>> s.add(2**x == 4)
7302 >>> s.reason_unknown()
7303 '(incomplete (theory arithmetic))'
7308 """Display a string describing all available options."""
7312 """Return the parameter description set."""
7316 """Return a formatted string with all added constraints."""
7317 return obj_to_string(self)
7320 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
7325 >>> s2 = s1.translate(c2)
7328 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
7330 return Solver(solver, target)
7339 """Return a formatted string (in Lisp-like format) with all added constraints.
7340 We say the string is in s-expression format.
7351 """Return a textual representation of the solver in DIMACS format."""
7355 """return SMTLIB2 formatted benchmark for solver's assertions"""
7362 for i
in range(sz1):
7363 v[i] = es[i].as_ast()
7365 e = es[sz1].as_ast()
7369 self.
ctx.ref(),
"benchmark generated from python API",
"",
"unknown",
"", sz1, v, e,
7374 """Create a solver customized for the given logic.
7376 The parameter `logic` is a string. It should be contains
7377 the name of a SMT-LIB logic.
7378 See http://www.smtlib.org/
for the name of all available logics.
7395 """Return a simple general purpose solver with limited amount of preprocessing.
7414 """Fixedpoint API provides methods for solving with recursive predicates"""
7417 assert fixedpoint
is None or ctx
is not None
7420 if fixedpoint
is None:
7431 if self.
fixedpoint is not None and self.
ctx.ref()
is not None and Z3_fixedpoint_dec_ref
is not None:
7435 """Set a configuration option. The method `help()` return a string containing all available options.
7441 """Display a string describing all available options."""
7445 """Return the parameter description set."""
7449 """Assert constraints as background axioms for the fixedpoint solver."""
7450 args = _get_args(args)
7453 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7463 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7471 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7475 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr."""
7479 """Assert rules defining recursive predicates to the fixedpoint solver.
7483 >>> s.register_relation(a.decl())
7484 >>> s.register_relation(b.decl())
7497 body = _get_args(body)
7501 def rule(self, head, body=None, name=None):
7502 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7506 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
7510 """Query the fixedpoint engine whether formula is derivable.
7511 You can also pass an tuple
or list of recursive predicates.
7513 query = _get_args(query)
7515 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7516 _decls = (FuncDecl * sz)()
7526 query =
And(query, self.
ctx)
7527 query = self.
abstract(query,
False)
7532 """Query the fixedpoint engine whether formula is derivable starting at the given query level.
7534 query = _get_args(query)
7536 if sz >= 1
and isinstance(query[0], FuncDecl):
7537 _z3_assert(
False,
"unsupported")
7543 query = self.
abstract(query,
False)
7544 r = Z3_fixedpoint_query_from_lvl(self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
7552 body = _get_args(body)
7557 """Retrieve answer from last query call."""
7559 return _to_expr_ref(r, self.
ctx)
7562 """Retrieve a ground cex from last query call."""
7563 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7564 return _to_expr_ref(r, self.
ctx)
7567 """retrieve rules along the counterexample trace"""
7571 """retrieve rule names along the counterexample trace"""
7574 names = _symbol2py(self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7576 return names.split(
";")
7579 """Retrieve number of levels used for predicate in PDR engine"""
7583 """Retrieve properties known about predicate for the level'th unfolding.
7584 -1 is treated
as the limit (infinity)
7587 return _to_expr_ref(r, self.
ctx)
7590 """Add property to predicate for the level'th unfolding.
7591 -1 is treated
as infinity (infinity)
7596 """Register relation as recursive"""
7597 relations = _get_args(relations)
7602 """Control how relation is represented"""
7603 representations = _get_args(representations)
7604 representations = [
to_symbol(s)
for s
in representations]
7605 sz = len(representations)
7606 args = (Symbol * sz)()
7608 args[i] = representations[i]
7612 """Parse rules and queries from a string"""
7616 """Parse rules and queries from a file"""
7620 """retrieve rules that have been added to fixedpoint context"""
7624 """retrieve assertions that have been added to fixedpoint context"""
7628 """Return a formatted string with all added rules and constraints."""
7632 """Return a formatted string (in Lisp-like format) with all added constraints.
7633 We say the string is in s-expression format.
7638 """Return a formatted string (in Lisp-like format) with all added constraints.
7639 We say the string is in s-expression format.
7640 Include also queries.
7642 args, len = _to_ast_array(queries)
7646 """Return statistics for the last `query()`.
7651 """Return a string describing why the last `query()` returned `unknown`.
7656 """Add variable or several variables.
7657 The added variable or variables will be bound
in the rules
7660 vars = _get_args(vars)
7680 """Finite domain sort."""
7683 """Return the size of the finite domain sort"""
7684 r = (ctypes.c_ulonglong * 1)()
7688 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7692 """Create a named finite domain sort of a given size sz"""
7693 if not isinstance(name, Symbol):
7700 """Return True if `s` is a Z3 finite-domain sort.
7707 return isinstance(s, FiniteDomainSortRef)
7711 """Finite-domain expressions."""
7714 """Return the sort of the finite-domain expression `self`."""
7718 """Return a Z3 floating point expression as a Python string."""
7723 """Return `True` if `a` is a Z3 finite-domain expression.
7726 >>> b =
Const(
'b', s)
7732 return isinstance(a, FiniteDomainRef)
7736 """Integer values."""
7739 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral.
7751 """Return a Z3 finite-domain numeral as a Python string.
7762 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used.
7777 """Return `True` if `a` is a Z3 finite-domain value.
7780 >>> b =
Const(
'b', s)
7833def _global_on_model(ctx):
7834 (fn, mdl) = _on_models[ctx]
7838_on_model_eh = on_model_eh_type(_global_on_model)
7842 """Optimize API provides methods for solving using objective functions and weighted soft constraints"""
7854 if self.
optimize is not None and self.
ctx.ref()
is not None and Z3_optimize_dec_ref
is not None:
7860 """Set a configuration option.
7861 The method `help()` return a string containing all available options.
7867 """Display a string describing all available options."""
7871 """Return the parameter description set."""
7875 """Assert constraints as background axioms for the optimize solver."""
7876 args = _get_args(args)
7879 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7887 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr."""
7895 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`.
7897 If `p` is a string, it will be automatically converted into a Boolean constant.
7902 >>> s.assert_and_track(x > 0,
'p1')
7903 >>> s.assert_and_track(x != 1,
'p2')
7904 >>> s.assert_and_track(x < 0, p3)
7905 >>> print(s.check())
7907 >>> c = s.unsat_core()
7917 if isinstance(p, str):
7919 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7920 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7924 """Add soft constraint with optional weight and optional identifier.
7925 If no weight is supplied, then the penalty
for violating the soft constraint
7927 Soft constraints are grouped by identifiers. Soft constraints that are
7928 added without identifiers are grouped by default.
7931 weight =
"%d" % weight
7932 elif isinstance(weight, float):
7933 weight =
"%f" % weight
7934 if not isinstance(weight, str):
7935 raise Z3Exception(
"weight should be a string or an integer")
7943 if sys.version_info.major >= 3
and isinstance(arg, Iterable):
7944 return [asoft(a)
for a
in arg]
7948 """Add objective function to maximize."""
7956 """Add objective function to minimize."""
7964 """create a backtracking point for added rules, facts and assertions"""
7968 """restore to previously created backtracking point"""
7972 """Check satisfiability while optimizing objective functions."""
7973 assumptions = _get_args(assumptions)
7974 num = len(assumptions)
7975 _assumptions = (Ast * num)()
7976 for i
in range(num):
7977 _assumptions[i] = assumptions[i].as_ast()
7981 """Return a string that describes why the last `check()` returned `unknown`."""
7985 """Return a model for the last check()."""
7989 raise Z3Exception(
"model is not available")
7995 if not isinstance(obj, OptimizeObjective):
7996 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
8000 if not isinstance(obj, OptimizeObjective):
8001 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
8005 if not isinstance(obj, OptimizeObjective):
8006 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
8007 return obj.lower_values()
8010 if not isinstance(obj, OptimizeObjective):
8011 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
8012 return obj.upper_values()
8015 """Parse assertions and objectives from a file"""
8019 """Parse assertions and objectives from a string"""
8023 """Return an AST vector containing all added constraints."""
8027 """returns set of objective functions"""
8031 """Return a formatted string with all added rules and constraints."""
8035 """Return a formatted string (in Lisp-like format) with all added constraints.
8036 We say the string is in s-expression format.
8041 """Return statistics for the last check`.
8046 """Register a callback that is invoked with every incremental improvement to
8047 objective values. The callback takes a model as argument.
8048 The life-time of the model
is limited to the callback so the
8049 model has to be (deep) copied
if it
is to be used after the callback
8051 id = len(_on_models) + 41
8053 _on_models[id] = (on_model, mdl)
8056 self.ctx.ref(), self.optimize, mdl.model, ctypes.c_void_p(id), _on_model_eh,
8066 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal.
8067 It also contains model and proof converters.
8079 if self.
ctx.ref()
is not None and Z3_apply_result_dec_ref
is not None:
8083 """Return the number of subgoals in `self`.
8085 >>> a, b = Ints('a b')
8087 >>> g.add(
Or(a == 0, a == 1),
Or(b == 0, b == 1), a > b)
8088 >>> t =
Tactic(
'split-clause')
8102 """Return one of the subgoals stored in ApplyResult object `self`.
8104 >>> a, b = Ints('a b')
8106 >>> g.add(
Or(a == 0, a == 1),
Or(b == 0, b == 1), a > b)
8107 >>> t =
Tactic(
'split-clause')
8110 [a == 0,
Or(b == 0, b == 1), a > b]
8112 [a == 1,
Or(b == 0, b == 1), a > b]
8114 if idx >= len(self):
8119 return obj_to_string(self)
8122 """Return a textual representation of the s-expression representing the set of subgoals in `self`."""
8126 """Return a Z3 expression consisting of all subgoals.
8131 >>> g.add(
Or(x == 2, x == 3))
8132 >>> r =
Tactic(
'simplify')(g)
8134 [[
Not(x <= 1),
Or(x == 2, x == 3)]]
8136 And(
Not(x <= 1),
Or(x == 2, x == 3))
8137 >>> r =
Tactic(
'split-clause')(g)
8139 [[x > 1, x == 2], [x > 1, x == 3]]
8141 Or(
And(x > 1, x == 2),
And(x > 1, x == 3))
8159 """Tactics transform, solver and/or simplify sets of constraints (Goal).
8160 A Tactic can be converted into a Solver using the method solver().
8162 Several combinators are available for creating new tactics using the built-
in ones:
8169 if isinstance(tactic, TacticObj):
8173 _z3_assert(isinstance(tactic, str),
"tactic name expected")
8177 raise Z3Exception(
"unknown tactic '%s'" % tactic)
8184 if self.
tactic is not None and self.
ctx.ref()
is not None and Z3_tactic_dec_ref
is not None:
8188 """Create a solver using the tactic `self`.
8190 The solver supports the methods `push()` and `pop()`, but it
8191 will always solve each `check()`
from scratch.
8193 >>> t =
Then(
'simplify',
'nlsat')
8196 >>> s.add(x**2 == 2, x > 0)
8204 def apply(self, goal, *arguments, **keywords):
8205 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8207 >>> x, y = Ints('x y')
8208 >>> t =
Tactic(
'solve-eqs')
8209 >>> t.apply(
And(x == 0, y >= x + 1))
8213 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expressions expected")
8214 goal = _to_goal(goal)
8215 if len(arguments) > 0
or len(keywords) > 0:
8222 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options.
8224 >>> x, y = Ints('x y')
8225 >>> t =
Tactic(
'solve-eqs')
8226 >>> t(
And(x == 0, y >= x + 1))
8229 return self.
apply(goal, *arguments, **keywords)
8232 """Display a string containing a description of the available options for the `self` tactic."""
8236 """Return the parameter description set."""
8241 if isinstance(a, BoolRef):
8242 goal =
Goal(ctx=a.ctx)
8249def _to_tactic(t, ctx=None):
8250 if isinstance(t, Tactic):
8256def _and_then(t1, t2, ctx=None):
8257 t1 = _to_tactic(t1, ctx)
8258 t2 = _to_tactic(t2, ctx)
8260 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8264def _or_else(t1, t2, ctx=None):
8265 t1 = _to_tactic(t1, ctx)
8266 t2 = _to_tactic(t2, ctx)
8268 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8273 """Return a tactic that applies the tactics in `*ts` in sequence.
8275 >>> x, y = Ints('x y')
8277 >>> t(
And(x == 0, y > x + 1))
8279 >>> t(
And(x == 0, y > x + 1)).as_expr()
8283 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8284 ctx = ks.get(
"ctx",
None)
8287 for i
in range(num - 1):
8288 r = _and_then(r, ts[i + 1], ctx)
8293 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
8295 >>> x, y = Ints('x y')
8297 >>> t(
And(x == 0, y > x + 1))
8299 >>> t(
And(x == 0, y > x + 1)).as_expr()
8306 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
8313 >>> t(
Or(x == 0, x == 1))
8314 [[x == 0], [x == 1]]
8317 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8318 ctx = ks.get(
"ctx",
None)
8321 for i
in range(num - 1):
8322 r = _or_else(r, ts[i + 1], ctx)
8327 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
8335 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
8336 ctx = _get_ctx(ks.get(
"ctx",
None))
8337 ts = [_to_tactic(t, ctx)
for t
in ts]
8339 _args = (TacticObj * sz)()
8341 _args[i] = ts[i].tactic
8346 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1.
8347 The subgoals are processed in parallel.
8349 >>> x, y =
Ints(
'x y')
8351 >>> t(
And(
Or(x == 1, x == 2), y == x + 1))
8352 [[x == 1, y == 2], [x == 2, y == 3]]
8354 t1 = _to_tactic(t1, ctx)
8355 t2 = _to_tactic(t2, ctx)
8357 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
8362 """Alias for ParThen(t1, t2, ctx)."""
8367 """Return a tactic that applies tactic `t` using the given configuration options.
8369 >>> x, y = Ints('x y')
8371 >>> t((x + 1)*(y + 2) == 0)
8372 [[2*x + y + x*y == -2]]
8374 ctx = keys.pop("ctx",
None)
8375 t = _to_tactic(t, ctx)
8381 """Return a tactic that applies tactic `t` using the given configuration options.
8383 >>> x, y = Ints('x y')
8385 >>> p.set(
"som",
True)
8387 >>> t((x + 1)*(y + 2) == 0)
8388 [[2*x + y + x*y == -2]]
8390 t = _to_tactic(t, None)
8395 """Return a tactic that keeps applying `t` until the goal is not modified anymore
8396 or the maximum number of iterations `max`
is reached.
8398 >>> x, y =
Ints(
'x y')
8399 >>> c =
And(
Or(x == 0, x == 1),
Or(y == 0, y == 1), x > y)
8402 >>>
for subgoal
in r: print(subgoal)
8403 [x == 0, y == 0, x > y]
8404 [x == 0, y == 1, x > y]
8405 [x == 1, y == 0, x > y]
8406 [x == 1, y == 1, x > y]
8411 t = _to_tactic(t, ctx)
8416 """Return a tactic that applies `t` to a given goal for `ms` milliseconds.
8418 If `t` does not terminate
in `ms` milliseconds, then it fails.
8420 t = _to_tactic(t, ctx)
8425 """Return a list of all available tactics in Z3.
8428 >>> l.count('simplify') == 1
8436 """Return a short description for the tactic named `name`.
8445 """Display a (tabular) description of all available tactics in Z3."""
8448 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8451 print(
'<tr style="background-color:#CFCFCF">')
8456 print(
"<td>%s</td><td>%s</td></tr>" % (t, insert_line_breaks(
tactic_description(t), 40)))
8464 """Probes are used to inspect a goal (aka problem) and collect information that may be used
8465 to decide which solver and/
or preprocessing step will be used.
8471 if isinstance(probe, ProbeObj):
8473 elif isinstance(probe, float):
8475 elif _is_int(probe):
8477 elif isinstance(probe, bool):
8484 _z3_assert(isinstance(probe, str),
"probe name expected")
8488 raise Z3Exception(
"unknown probe '%s'" % probe)
8495 if self.
probe is not None and self.
ctx.ref()
is not None and Z3_probe_dec_ref
is not None:
8499 """Return a probe that evaluates to "true" when the value returned by `self`
8500 is less than the value returned by `other`.
8502 >>> p =
Probe(
'size') < 10
8513 """Return a probe that evaluates to "true" when the value returned by `self`
8514 is greater than the value returned by `other`.
8516 >>> p =
Probe(
'size') > 10
8527 """Return a probe that evaluates to "true" when the value returned by `self`
8528 is less than
or equal to the value returned by `other`.
8530 >>> p =
Probe(
'size') <= 2
8541 """Return a probe that evaluates to "true" when the value returned by `self`
8542 is greater than
or equal to the value returned by `other`.
8544 >>> p =
Probe(
'size') >= 2
8555 """Return a probe that evaluates to "true" when the value returned by `self`
8556 is equal to the value returned by `other`.
8558 >>> p =
Probe(
'size') == 2
8569 """Return a probe that evaluates to "true" when the value returned by `self`
8570 is not equal to the value returned by `other`.
8572 >>> p =
Probe(
'size') != 2
8584 """Evaluate the probe `self` in the given goal.
8586 >>> p = Probe('size')
8596 >>> p =
Probe(
'num-consts')
8599 >>> p =
Probe(
'is-propositional')
8602 >>> p =
Probe(
'is-qflia')
8607 _z3_assert(isinstance(goal, (Goal, BoolRef)),
"Z3 Goal or Boolean expression expected")
8608 goal = _to_goal(goal)
8613 """Return `True` if `p` is a Z3 probe.
8620 return isinstance(p, Probe)
8623def _to_probe(p, ctx=None):
8627 return Probe(p, ctx)
8631 """Return a list of all available probes in Z3.
8634 >>> l.count('memory') == 1
8642 """Return a short description for the probe named `name`.
8651 """Display a (tabular) description of all available probes in Z3."""
8654 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8657 print(
'<tr style="background-color:#CFCFCF">')
8662 print(
"<td>%s</td><td>%s</td></tr>" % (p, insert_line_breaks(
probe_description(p), 40)))
8669def _probe_nary(f, args, ctx):
8671 _z3_assert(len(args) > 0,
"At least one argument expected")
8673 r = _to_probe(args[0], ctx)
8674 for i
in range(num - 1):
8675 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i + 1], ctx).probe), ctx)
8679def _probe_and(args, ctx):
8680 return _probe_nary(Z3_probe_and, args, ctx)
8683def _probe_or(args, ctx):
8684 return _probe_nary(Z3_probe_or, args, ctx)
8688 """Return a tactic that fails if the probe `p` evaluates to true.
8689 Otherwise, it returns the input goal unmodified.
8691 In the following example, the tactic applies 'simplify' if and only
if there are
8692 more than 2 constraints
in the goal.
8695 >>> x, y =
Ints(
'x y')
8701 >>> g.add(x == y + 1)
8703 [[
Not(x <= 0),
Not(y <= 0), x == 1 + y]]
8705 p = _to_probe(p, ctx)
8710 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true.
8711 Otherwise, it returns the input goal unmodified.
8714 >>> x, y =
Ints(
'x y')
8720 >>> g.add(x == y + 1)
8722 [[
Not(x <= 0),
Not(y <= 0), x == 1 + y]]
8724 p = _to_probe(p, ctx)
8725 t = _to_tactic(t, ctx)
8730 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
8734 p = _to_probe(p, ctx)
8735 t1 = _to_tactic(t1, ctx)
8736 t2 = _to_tactic(t2, ctx)
8747 """Simplify the expression `a` using the given options.
8749 This function has many options. Use `help_simplify` to obtain the complete list.
8755 >>>
simplify((x + 1)*(y + 1), som=
True)
8763 _z3_assert(
is_expr(a),
"Z3 expression expected")
8764 if len(arguments) > 0
or len(keywords) > 0:
8766 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8768 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8772 """Return a string describing all options available for Z3 `simplify` procedure."""
8777 """Return the set of parameter descriptions for Z3 `simplify` procedure."""
8782 """Apply substitution m on t, m is a list of pairs of the form (from, to).
8783 Every occurrence in t of
from is replaced
with to.
8793 if isinstance(m, tuple):
8795 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8798 _z3_assert(
is_expr(t),
"Z3 expression expected")
8800 all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
for p
in m]),
8801 "Z3 invalid substitution, expression pairs expected.")
8803 all([p[0].sort().
eq(p[1].sort())
for p
in m]),
8804 'Z3 invalid substitution, mismatching "from" and "to" sorts.')
8806 _from = (Ast * num)()
8808 for i
in range(num):
8809 _from[i] = m[i][0].as_ast()
8810 _to[i] = m[i][1].as_ast()
8811 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8815 """Substitute the free variables in t with the expression in m.
8826 _z3_assert(
is_expr(t),
"Z3 expression expected")
8827 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8830 for i
in range(num):
8831 _to[i] = m[i].as_ast()
8835 """Apply subistitution m on t, m is a list of pairs of a function and expression (from, to)
8836 Every occurrence in to of the function
from is replaced
with the expression to.
8837 The expression to can have free variables, that refer to the arguments of
from.
8840 if isinstance(m, tuple):
8842 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8845 _z3_assert(
is_expr(t),
"Z3 expression expected")
8846 _z3_assert(all([isinstance(p, tuple)
and is_func_decl(p[0])
and is_expr(p[1])
for p
in m]),
"Z3 invalid substitution, funcion pairs expected.")
8848 _from = (FuncDecl * num)()
8850 for i
in range(num):
8851 _from[i] = m[i][0].as_func_decl()
8852 _to[i] = m[i][1].as_ast()
8853 return _to_expr_ref(
Z3_substitute_funs(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8857 """Create the sum of the Z3 expressions.
8859 >>> a, b, c = Ints('a b c')
8866 a__0 + a__1 + a__2 + a__3 + a__4
8868 args = _get_args(args)
8871 ctx = _ctx_from_ast_arg_list(args)
8873 return _reduce(
lambda a, b: a + b, args, 0)
8874 args = _coerce_expr_list(args, ctx)
8876 return _reduce(
lambda a, b: a + b, args, 0)
8878 _args, sz = _to_ast_array(args)
8883 """Create the product of the Z3 expressions.
8885 >>> a, b, c = Ints('a b c')
8892 a__0*a__1*a__2*a__3*a__4
8894 args = _get_args(args)
8897 ctx = _ctx_from_ast_arg_list(args)
8899 return _reduce(
lambda a, b: a * b, args, 1)
8900 args = _coerce_expr_list(args, ctx)
8902 return _reduce(
lambda a, b: a * b, args, 1)
8904 _args, sz = _to_ast_array(args)
8908 """Create the absolute value of an arithmetic expression"""
8909 return If(arg > 0, arg, -arg)
8913 """Create an at-most Pseudo-Boolean k constraint.
8915 >>> a, b, c = Bools('a b c')
8916 >>> f =
AtMost(a, b, c, 2)
8918 args = _get_args(args)
8920 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8921 ctx = _ctx_from_ast_arg_list(args)
8923 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8924 args1 = _coerce_expr_list(args[:-1], ctx)
8926 _args, sz = _to_ast_array(args1)
8931 """Create an at-most Pseudo-Boolean k constraint.
8933 >>> a, b, c = Bools('a b c')
8936 args = _get_args(args)
8938 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8939 ctx = _ctx_from_ast_arg_list(args)
8941 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8942 args1 = _coerce_expr_list(args[:-1], ctx)
8944 _args, sz = _to_ast_array(args1)
8948def _reorder_pb_arg(arg):
8950 if not _is_int(b)
and _is_int(a):
8955def _pb_args_coeffs(args, default_ctx=None):
8956 args = _get_args_ast_list(args)
8958 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8959 args = [_reorder_pb_arg(arg)
for arg
in args]
8960 args, coeffs = zip(*args)
8962 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8963 ctx = _ctx_from_ast_arg_list(args)
8965 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8966 args = _coerce_expr_list(args, ctx)
8967 _args, sz = _to_ast_array(args)
8968 _coeffs = (ctypes.c_int * len(coeffs))()
8969 for i
in range(len(coeffs)):
8970 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8971 _coeffs[i] = coeffs[i]
8972 return ctx, sz, _args, _coeffs, args
8976 """Create a Pseudo-Boolean inequality k constraint.
8978 >>> a, b, c = Bools('a b c')
8979 >>> f =
PbLe(((a,1),(b,3),(c,2)), 3)
8981 _z3_check_cint_overflow(k, "k")
8982 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8987 """Create a Pseudo-Boolean inequality k constraint.
8989 >>> a, b, c = Bools('a b c')
8990 >>> f =
PbGe(((a,1),(b,3),(c,2)), 3)
8992 _z3_check_cint_overflow(k, "k")
8993 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
8998 """Create a Pseudo-Boolean inequality k constraint.
9000 >>> a, b, c = Bools('a b c')
9001 >>> f =
PbEq(((a,1),(b,3),(c,2)), 3)
9003 _z3_check_cint_overflow(k, "k")
9004 ctx, sz, _args, _coeffs, args = _pb_args_coeffs(args)
9009 """Solve the constraints `*args`.
9011 This is a simple function
for creating demonstrations. It creates a solver,
9012 configure it using the options
in `keywords`, adds the constraints
9013 in `args`,
and invokes check.
9016 >>>
solve(a > 0, a < 2)
9019 show = keywords.pop("show",
False)
9027 print(
"no solution")
9029 print(
"failed to solve")
9039 """Solve the constraints `*args` using solver `s`.
9041 This is a simple function
for creating demonstrations. It
is similar to `solve`,
9042 but it uses the given solver `s`.
9043 It configures solver `s` using the options
in `keywords`, adds the constraints
9044 in `args`,
and invokes check.
9046 show = keywords.pop("show",
False)
9048 _z3_assert(isinstance(s, Solver),
"Solver object expected")
9056 print(
"no solution")
9058 print(
"failed to solve")
9069def prove(claim, show=False, **keywords):
9070 """Try to prove the given claim.
9072 This is a simple function
for creating demonstrations. It tries to prove
9073 `claim` by showing the negation
is unsatisfiable.
9075 >>> p, q =
Bools(
'p q')
9080 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9090 print(
"failed to prove")
9093 print(
"counterexample")
9097def _solve_html(*args, **keywords):
9098 """Version of function `solve` that renders HTML output."""
9099 show = keywords.pop(
"show",
False)
9104 print(
"<b>Problem:</b>")
9108 print(
"<b>no solution</b>")
9110 print(
"<b>failed to solve</b>")
9117 print(
"<b>Solution:</b>")
9121def _solve_using_html(s, *args, **keywords):
9122 """Version of function `solve_using` that renders HTML."""
9123 show = keywords.pop(
"show",
False)
9125 _z3_assert(isinstance(s, Solver),
"Solver object expected")
9129 print(
"<b>Problem:</b>")
9133 print(
"<b>no solution</b>")
9135 print(
"<b>failed to solve</b>")
9142 print(
"<b>Solution:</b>")
9146def _prove_html(claim, show=False, **keywords):
9147 """Version of function `prove` that renders HTML."""
9149 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
9157 print(
"<b>proved</b>")
9159 print(
"<b>failed to prove</b>")
9162 print(
"<b>counterexample</b>")
9166def _dict2sarray(sorts, ctx):
9168 _names = (Symbol * sz)()
9169 _sorts = (Sort * sz)()
9174 _z3_assert(isinstance(k, str),
"String expected")
9175 _z3_assert(
is_sort(v),
"Z3 sort expected")
9179 return sz, _names, _sorts
9182def _dict2darray(decls, ctx):
9184 _names = (Symbol * sz)()
9185 _decls = (FuncDecl * sz)()
9190 _z3_assert(isinstance(k, str),
"String expected")
9194 _decls[i] = v.decl().ast
9198 return sz, _names, _decls
9207 if self.
ctx.ref()
is not None and self.
pctx is not None and Z3_parser_context_dec_ref
is not None:
9221 """Parse a string in SMT 2.0 format using the given sorts and decls.
9223 The arguments sorts and decls are Python dictionaries used to initialize
9224 the symbol table used
for the SMT 2.0 parser.
9226 >>>
parse_smt2_string(
'(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
9228 >>> x, y =
Ints(
'x y')
9230 >>>
parse_smt2_string(
'(assert (> (+ foo (g bar)) 0))', decls={
'foo' : x,
'bar' : y,
'g' : f})
9236 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9237 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9242 """Parse a file in SMT 2.0 format using the given sorts and decls.
9247 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
9248 dsz, dnames, ddecls = _dict2darray(decls, ctx)
9260_dflt_rounding_mode = Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
9261_dflt_fpsort_ebits = 11
9262_dflt_fpsort_sbits = 53
9266 """Retrieves the global default rounding mode."""
9267 global _dflt_rounding_mode
9268 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
9270 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
9272 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
9274 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
9276 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
9280_ROUNDING_MODES = frozenset({
9281 Z3_OP_FPA_RM_TOWARD_ZERO,
9282 Z3_OP_FPA_RM_TOWARD_NEGATIVE,
9283 Z3_OP_FPA_RM_TOWARD_POSITIVE,
9284 Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN,
9285 Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY
9290 global _dflt_rounding_mode
9292 _dflt_rounding_mode = rm.decl().kind()
9294 _z3_assert(_dflt_rounding_mode
in _ROUNDING_MODES,
"illegal rounding mode")
9295 _dflt_rounding_mode = rm
9299 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
9303 global _dflt_fpsort_ebits
9304 global _dflt_fpsort_sbits
9305 _dflt_fpsort_ebits = ebits
9306 _dflt_fpsort_sbits = sbits
9309def _dflt_rm(ctx=None):
9313def _dflt_fps(ctx=None):
9317def _coerce_fp_expr_list(alist, ctx):
9318 first_fp_sort =
None
9321 if first_fp_sort
is None:
9322 first_fp_sort = a.sort()
9323 elif first_fp_sort == a.sort():
9328 first_fp_sort =
None
9332 for i
in range(len(alist)):
9334 is_repr = isinstance(a, str)
and a.contains(
"2**(")
and a.endswith(
")")
9335 if is_repr
or _is_int(a)
or isinstance(a, (float, bool)):
9336 r.append(
FPVal(a,
None, first_fp_sort, ctx))
9339 return _coerce_expr_list(r, ctx)
9345 """Floating-point sort."""
9348 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`.
9356 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`.
9364 """Try to cast `val` as a floating-point expression.
9368 >>> b.cast(1.0).sexpr()
9369 '(fp #b0 #x7f #b00000000000000000000000)'
9373 _z3_assert(self.
ctxctx == val.ctx,
"Context mismatch")
9380 """Floating-point 16-bit (half) sort."""
9386 """Floating-point 16-bit (half) sort."""
9392 """Floating-point 32-bit (single) sort."""
9398 """Floating-point 32-bit (single) sort."""
9404 """Floating-point 64-bit (double) sort."""
9410 """Floating-point 64-bit (double) sort."""
9416 """Floating-point 128-bit (quadruple) sort."""
9422 """Floating-point 128-bit (quadruple) sort."""
9428 """"Floating-point rounding mode sort."""
9432 """Return True if `s` is a Z3 floating-point sort.
9439 return isinstance(s, FPSortRef)
9443 """Return True if `s` is a Z3 floating-point rounding mode sort.
9450 return isinstance(s, FPRMSortRef)
9456 """Floating-point expressions."""
9459 """Return the sort of the floating-point expression `self`.
9464 >>> x.sort() ==
FPSort(8, 24)
9470 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9478 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`.
9486 """Return a Z3 floating point expression as a Python string."""
9490 return fpLEQ(self, other, self.
ctx)
9493 return fpLT(self, other, self.
ctx)
9496 return fpGEQ(self, other, self.
ctx)
9499 return fpGT(self, other, self.
ctx)
9502 """Create the Z3 expression `self + other`.
9511 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9512 return fpAdd(_dflt_rm(), a, b, self.
ctx)
9515 """Create the Z3 expression `other + self`.
9521 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9522 return fpAdd(_dflt_rm(), a, b, self.
ctx)
9525 """Create the Z3 expression `self - other`.
9534 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9535 return fpSub(_dflt_rm(), a, b, self.
ctx)
9538 """Create the Z3 expression `other - self`.
9544 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9545 return fpSub(_dflt_rm(), a, b, self.
ctx)
9548 """Create the Z3 expression `self * other`.
9559 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9560 return fpMul(_dflt_rm(), a, b, self.
ctx)
9563 """Create the Z3 expression `other * self`.
9572 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9573 return fpMul(_dflt_rm(), a, b, self.
ctx)
9576 """Create the Z3 expression `+self`."""
9580 """Create the Z3 expression `-self`.
9589 """Create the Z3 expression `self / other`.
9600 [a, b] = _coerce_fp_expr_list([self, other], self.ctx)
9601 return fpDiv(_dflt_rm(), a, b, self.
ctx)
9604 """Create the Z3 expression `other / self`.
9613 [a, b] = _coerce_fp_expr_list([other, self], self.ctx)
9614 return fpDiv(_dflt_rm(), a, b, self.
ctx)
9617 """Create the Z3 expression division `self / other`."""
9621 """Create the Z3 expression division `other / self`."""
9625 """Create the Z3 expression mod `self % other`."""
9626 return fpRem(self, other)
9629 """Create the Z3 expression mod `other % self`."""
9630 return fpRem(other, self)
9634 """Floating-point rounding mode expressions"""
9637 """Return a Z3 floating point expression as a Python string."""
9692 """Return `True` if `a` is a Z3 floating-point rounding mode expression.
9701 return isinstance(a, FPRMRef)
9705 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value."""
9706 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9712 """The sign of the numeral.
9723 num = (ctypes.c_int)()
9726 raise Z3Exception(
"error retrieving the sign of a numeral.")
9727 return num.value != 0
9729 """The sign of a floating-point numeral as a bit-vector expression.
9731 Remark: NaN's are invalid arguments.
9737 """The significand of the numeral.
9747 """The significand of the numeral as a long.
9750 >>> x.significand_as_long()
9755 ptr = (ctypes.c_ulonglong * 1)()
9757 raise Z3Exception(
"error retrieving the significand of a numeral.")
9760 """The significand of the numeral as a bit-vector expression.
9762 Remark: NaN are invalid arguments.
9768 """The exponent of the numeral.
9778 """The exponent of the numeral as a long.
9781 >>> x.exponent_as_long()
9786 ptr = (ctypes.c_longlong * 1)()
9788 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9791 """The exponent of the numeral as a bit-vector expression.
9793 Remark: NaNs are invalid arguments.
9799 """Indicates whether the numeral is a NaN."""
9804 """Indicates whether the numeral is +oo or -oo."""
9809 """Indicates whether the numeral is +zero or -zero."""
9814 """Indicates whether the numeral is normal."""
9819 """Indicates whether the numeral is subnormal."""
9824 """Indicates whether the numeral is positive."""
9829 """Indicates whether the numeral is negative."""
9835 The string representation of the numeral.
9844 return (
"FPVal(%s, %s)" % (s, self.
sortsort()))
9848 """Return `True` if `a` is a Z3 floating-point expression.
9858 return isinstance(a, FPRef)
9862 """Return `True` if `a` is a Z3 floating-point numeral value.
9873 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9877 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
9879 >>> Single = FPSort(8, 24)
9880 >>> Double = FPSort(11, 53)
9883 >>> x = Const('x', Single)
9891def _to_float_str(val, exp=0):
9892 if isinstance(val, float):
9896 sone = math.copysign(1.0, val)
9901 elif val == float(
"+inf"):
9903 elif val == float(
"-inf"):
9906 v = val.as_integer_ratio()
9909 rvs = str(num) +
"/" + str(den)
9910 res = rvs +
"p" + _to_int_str(exp)
9911 elif isinstance(val, bool):
9918 elif isinstance(val, str):
9919 inx = val.find(
"*(2**")
9922 elif val[-1] ==
")":
9924 exp = str(int(val[inx + 5:-1]) + int(exp))
9926 _z3_assert(
False,
"String does not have floating-point numeral form.")
9928 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9932 return res +
"p" + exp
9936 """Create a Z3 floating-point NaN term.
9939 >>> set_fpa_pretty(True)
9942 >>> pb = get_fpa_pretty()
9943 >>> set_fpa_pretty(
False)
9946 >>> set_fpa_pretty(pb)
9948 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9953 """Create a Z3 floating-point +oo term.
9956 >>> pb = get_fpa_pretty()
9957 >>> set_fpa_pretty(True)
9960 >>> set_fpa_pretty(
False)
9963 >>> set_fpa_pretty(pb)
9965 _z3_assert(isinstance(s, FPSortRef), "sort mismatch")
9970 """Create a Z3 floating-point -oo term."""
9971 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9976 """Create a Z3 floating-point +oo or -oo term."""
9977 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9978 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9983 """Create a Z3 floating-point +0.0 term."""
9984 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9989 """Create a Z3 floating-point -0.0 term."""
9990 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9995 """Create a Z3 floating-point +0.0 or -0.0 term."""
9996 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9997 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
10001def FPVal(sig, exp=None, fps=None, ctx=None):
10002 """Return a floating-point value of value `val` and sort `fps`.
10003 If `ctx=None`, then the
global context
is used.
10008 >>> print(
"0x%.8x" % v.exponent_as_long(
False))
10023 ctx = _get_ctx(ctx)
10028 fps = _dflt_fps(ctx)
10029 _z3_assert(
is_fp_sort(fps),
"sort mismatch")
10032 val = _to_float_str(sig)
10033 if val ==
"NaN" or val ==
"nan":
10035 elif val ==
"-0.0":
10037 elif val ==
"0.0" or val ==
"+0.0":
10039 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
10041 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
10047def FP(name, fpsort, ctx=None):
10048 """Return a floating-point constant named `name`.
10049 `fpsort` is the floating-point sort.
10050 If `ctx=
None`, then the
global context
is used.
10059 >>> word =
FPSort(8, 24)
10060 >>> x2 =
FP(
'x', word)
10064 if isinstance(fpsort, FPSortRef)
and ctx
is None:
10067 ctx = _get_ctx(ctx)
10072 """Return an array of floating-point constants.
10074 >>> x, y, z = FPs('x y z',
FPSort(8, 24))
10084 ctx = _get_ctx(ctx)
10085 if isinstance(names, str):
10086 names = names.split(
" ")
10087 return [
FP(name, fpsort, ctx)
for name
in names]
10091 """Create a Z3 floating-point absolute value expression.
10095 >>> x = FPVal(1.0, s)
10098 >>> y = FPVal(-20.0, s)
10102 fpAbs(-1.25*(2**4))
10103 >>> fpAbs(-1.25*(2**4))
10104 fpAbs(-1.25*(2**4))
10105 >>> fpAbs(x).sort()
10108 ctx = _get_ctx(ctx)
10109 [a] = _coerce_fp_expr_list([a], ctx)
10114 """Create a Z3 floating-point addition expression.
10121 >>>
fpNeg(x).sort()
10124 ctx = _get_ctx(ctx)
10125 [a] = _coerce_fp_expr_list([a], ctx)
10129def _mk_fp_unary(f, rm, a, ctx):
10130 ctx = _get_ctx(ctx)
10131 [a] = _coerce_fp_expr_list([a], ctx)
10133 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10134 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
10135 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
10138def _mk_fp_unary_pred(f, a, ctx):
10139 ctx = _get_ctx(ctx)
10140 [a] = _coerce_fp_expr_list([a], ctx)
10142 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
10143 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
10146def _mk_fp_bin(f, rm, a, b, ctx):
10147 ctx = _get_ctx(ctx)
10148 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10150 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10151 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
10152 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
10155def _mk_fp_bin_norm(f, a, b, ctx):
10156 ctx = _get_ctx(ctx)
10157 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10159 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10160 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10163def _mk_fp_bin_pred(f, a, b, ctx):
10164 ctx = _get_ctx(ctx)
10165 [a, b] = _coerce_fp_expr_list([a, b], ctx)
10167 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10168 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
10171def _mk_fp_tern(f, rm, a, b, c, ctx):
10172 ctx = _get_ctx(ctx)
10173 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
10175 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10177 c),
"Second, third or fourth argument must be a Z3 floating-point expression")
10178 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
10182 """Create a Z3 floating-point addition expression.
10188 >>>
fpAdd(rm, x, y)
10192 >>>
fpAdd(rm, x, y).sort()
10195 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
10199 """Create a Z3 floating-point subtraction expression.
10205 >>>
fpSub(rm, x, y)
10207 >>>
fpSub(rm, x, y).sort()
10210 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
10214 """Create a Z3 floating-point multiplication expression.
10220 >>>
fpMul(rm, x, y)
10222 >>>
fpMul(rm, x, y).sort()
10225 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
10229 """Create a Z3 floating-point division expression.
10235 >>>
fpDiv(rm, x, y)
10237 >>>
fpDiv(rm, x, y).sort()
10240 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
10244 """Create a Z3 floating-point remainder expression.
10251 >>>
fpRem(x, y).sort()
10254 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
10258 """Create a Z3 floating-point minimum expression.
10266 >>>
fpMin(x, y).sort()
10269 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
10273 """Create a Z3 floating-point maximum expression.
10281 >>>
fpMax(x, y).sort()
10284 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
10288 """Create a Z3 floating-point fused multiply-add expression.
10290 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
10294 """Create a Z3 floating-point square root expression.
10296 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
10300 """Create a Z3 floating-point roundToIntegral expression.
10302 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
10306 """Create a Z3 floating-point isNaN expression.
10314 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
10318 """Create a Z3 floating-point isInfinite expression.
10325 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
10329 """Create a Z3 floating-point isZero expression.
10331 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
10335 """Create a Z3 floating-point isNormal expression.
10337 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
10341 """Create a Z3 floating-point isSubnormal expression.
10343 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
10347 """Create a Z3 floating-point isNegative expression.
10349 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
10353 """Create a Z3 floating-point isPositive expression.
10355 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
10358def _check_fp_args(a, b):
10360 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
10364 """Create the Z3 floating-point expression `other < self`.
10369 >>> (x < y).sexpr()
10372 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
10376 """Create the Z3 floating-point expression `other <= self`.
10381 >>> (x <= y).sexpr()
10384 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
10388 """Create the Z3 floating-point expression `other > self`.
10393 >>> (x > y).sexpr()
10396 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
10400 """Create the Z3 floating-point expression `other >= self`.
10405 >>> (x >= y).sexpr()
10408 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
10412 """Create the Z3 floating-point expression `fpEQ(other, self)`.
10417 >>>
fpEQ(x, y).sexpr()
10420 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
10424 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`.
10429 >>> (x != y).sexpr()
10436 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp.
10441 fpFP(1, 127, 4194304)
10442 >>> xv = FPVal(-1.5, s)
10446 >>> slvr.add(fpEQ(x, xv))
10449 >>> xv = FPVal(+1.5, s)
10453 >>> slvr.add(fpEQ(x, xv))
10457 _z3_assert(is_bv(sgn) and is_bv(exp)
and is_bv(sig),
"sort mismatch")
10458 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
10459 ctx = _get_ctx(ctx)
10460 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
10465 """Create a Z3 floating-point conversion expression from other term sorts
10468 From a bit-vector term in IEEE 754-2008 format:
10474 From a floating-point term
with different precision:
10485 From a signed bit-vector term:
10490 ctx = _get_ctx(ctx)
10500 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
10504 """Create a Z3 floating-point conversion expression that represents the
10505 conversion from a bit-vector term to a floating-point term.
10514 _z3_assert(is_bv(v), "First argument must be a Z3 bit-vector expression")
10515 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
10516 ctx = _get_ctx(ctx)
10521 """Create a Z3 floating-point conversion expression that represents the
10522 conversion from a floating-point term to a floating-point term of different precision.
10533 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10534 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
10535 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10536 ctx = _get_ctx(ctx)
10541 """Create a Z3 floating-point conversion expression that represents the
10542 conversion from a real term to a floating-point term.
10551 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10552 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
10553 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10554 ctx = _get_ctx(ctx)
10559 """Create a Z3 floating-point conversion expression that represents the
10560 conversion from a signed bit-vector term (encoding an integer) to a floating-point term.
10569 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10570 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10571 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10572 ctx = _get_ctx(ctx)
10577 """Create a Z3 floating-point conversion expression that represents the
10578 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term.
10587 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression.")
10588 _z3_assert(
is_bv(v),
"Second argument must be a Z3 bit-vector expression")
10589 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
10590 ctx = _get_ctx(ctx)
10595 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression."""
10597 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10598 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
10599 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
10600 ctx = _get_ctx(ctx)
10605 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
10609 >>> print(
is_fp(x))
10611 >>> print(
is_bv(y))
10613 >>> print(
is_fp(y))
10615 >>> print(
is_bv(x))
10619 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10620 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10621 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10622 ctx = _get_ctx(ctx)
10627 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
10631 >>> print(
is_fp(x))
10633 >>> print(
is_bv(y))
10635 >>> print(
is_fp(y))
10637 >>> print(
is_bv(x))
10641 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
10642 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
10643 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
10644 ctx = _get_ctx(ctx)
10649 """Create a Z3 floating-point conversion expression, from floating-point expression to real.
10653 >>> print(
is_fp(x))
10657 >>> print(
is_fp(y))
10663 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10664 ctx = _get_ctx(ctx)
10669 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
10671 The size of the resulting bit-vector is automatically determined.
10673 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
10674 knows only one NaN
and it will always produce the same bit-vector representation of
10679 >>> print(
is_fp(x))
10681 >>> print(
is_bv(y))
10683 >>> print(
is_fp(y))
10685 >>> print(
is_bv(x))
10689 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
10690 ctx = _get_ctx(ctx)
10701 """Sequence sort."""
10704 """Determine if sort is a string
10718 """Character sort."""
10722 """Create a string sort
10727 ctx = _get_ctx(ctx)
10731 """Create a character sort
10736 ctx = _get_ctx(ctx)
10741 """Create a sequence sort over elements provided in the argument
10750 """Sequence expression."""
10756 return Concat(self, other)
10759 return Concat(other, self)
10778 """Return a string representation of sequence expression."""
10780 string_length = ctypes.c_uint()
10782 return string_at(chars, size=string_length.value).decode(
"latin-1")
10798def _coerce_char(ch, ctx=None):
10799 if isinstance(ch, str):
10800 ctx = _get_ctx(ctx)
10803 raise Z3Exception(
"Character expression expected")
10807 """Character expression."""
10810 other = _coerce_char(other, self.
ctx)
10824 ctx = _get_ctx(ctx)
10825 if isinstance(ch, str):
10827 if not isinstance(ch, int):
10828 raise Z3Exception(
"character value should be an ordinal")
10829 return _to_expr_ref(
Z3_mk_char(ctx.ref(), ch), ctx)
10833 raise Z3Expression(
"Bit-vector expression needed")
10837 ch = _coerce_char(ch, ctx)
10841 ch = _coerce_char(ch, ctx)
10845 ch = _coerce_char(ch, ctx)
10846 return ch.is_digit()
10848def _coerce_seq(s, ctx=None):
10849 if isinstance(s, str):
10850 ctx = _get_ctx(ctx)
10853 raise Z3Exception(
"Non-expression passed as a sequence")
10855 raise Z3Exception(
"Non-sequence passed as a sequence")
10859def _get_ctx2(a, b, ctx=None):
10870 """Return `True` if `a` is a Z3 sequence expression.
10876 return isinstance(a, SeqRef)
10880 """Return `True` if `a` is a Z3 string expression.
10884 return isinstance(a, SeqRef)
and a.is_string()
10888 """return 'True' if 'a' is a Z3 string constant expression.
10894 return isinstance(a, SeqRef)
and a.is_string_value()
10897 """create a string expression"""
10898 s =
"".join(str(ch)
if 32 <= ord(ch)
and ord(ch) < 127
else "\\u{%x}" % (ord(ch))
for ch
in s)
10899 ctx = _get_ctx(ctx)
10904 """Return a string constant named `name`. If `ctx=None`, then the global context is used.
10908 ctx = _get_ctx(ctx)
10913 """Return a tuple of String constants. """
10914 ctx = _get_ctx(ctx)
10915 if isinstance(names, str):
10916 names = names.split(
" ")
10917 return [
String(name, ctx)
for name
in names]
10921 """Extract substring or subsequence starting at offset"""
10922 return Extract(s, offset, length)
10926 """Extract substring or subsequence starting at offset"""
10927 return Extract(s, offset, length)
10931 """Create the empty sequence of the given sort
10934 >>> print(e.eq(e2))
10943 if isinstance(s, SeqSortRef):
10945 if isinstance(s, ReSortRef):
10947 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10951 """Create the regular expression that accepts the universal language
10959 if isinstance(s, ReSortRef):
10961 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10966 """Create a singleton sequence"""
10971 """Check if 'a' is a prefix of 'b'
10979 ctx = _get_ctx2(a, b)
10980 a = _coerce_seq(a, ctx)
10981 b = _coerce_seq(b, ctx)
10986 """Check if 'a' is a suffix of 'b'
10994 ctx = _get_ctx2(a, b)
10995 a = _coerce_seq(a, ctx)
10996 b = _coerce_seq(b, ctx)
11001 """Check if 'a' contains 'b'
11008 >>> x, y, z =
Strings(
'x y z')
11013 ctx = _get_ctx2(a, b)
11014 a = _coerce_seq(a, ctx)
11015 b = _coerce_seq(b, ctx)
11020 """Replace the first occurrence of 'src' by 'dst' in 's'
11021 >>> r = Replace("aaa",
"a",
"b")
11025 ctx = _get_ctx2(dst, s)
11026 if ctx
is None and is_expr(src):
11028 src = _coerce_seq(src, ctx)
11029 dst = _coerce_seq(dst, ctx)
11030 s = _coerce_seq(s, ctx)
11035 """Retrieve the index of substring within a string starting at a specified offset.
11046 ctx = _get_ctx2(s, substr, ctx)
11047 s = _coerce_seq(s, ctx)
11048 substr = _coerce_seq(substr, ctx)
11049 if _is_int(offset):
11050 offset =
IntVal(offset, ctx)
11055 """Retrieve the last index of substring within a string"""
11057 ctx = _get_ctx2(s, substr, ctx)
11058 s = _coerce_seq(s, ctx)
11059 substr = _coerce_seq(substr, ctx)
11064 """Obtain the length of a sequence 's'
11074 """Convert string expression to integer
11090 """Convert integer expression to string"""
11097 """Convert a unit length string to integer code"""
11103 """Convert code to a string"""
11109 """The regular expression that accepts sequence 's'
11114 s = _coerce_seq(s, ctx)
11121 """Regular expression sort."""
11130 if s
is None or isinstance(s, Context):
11133 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
11137 """Regular expressions."""
11140 return Union(self, other)
11144 return isinstance(s, ReRef)
11148 """Create regular expression membership test
11157 s = _coerce_seq(s, re.ctx)
11162 """Create union of regular expressions.
11167 args = _get_args(args)
11170 _z3_assert(sz > 0,
"At least one argument expected.")
11171 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
11176 for i
in range(sz):
11177 v[i] = args[i].as_ast()
11182 """Create intersection of regular expressions.
11185 args = _get_args(args)
11188 _z3_assert(sz > 0,
"At least one argument expected.")
11189 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
11194 for i
in range(sz):
11195 v[i] = args[i].as_ast()
11200 """Create the regular expression accepting one or more repetitions of argument.
11213 """Create the regular expression that optionally accepts the argument.
11226 """Create the complement regular expression."""
11231 """Create the regular expression accepting zero or more repetitions of argument.
11244 """Create the regular expression accepting between a lower and upper bound repetitions
11245 >>> re = Loop(Re("a"), 1, 3)
11257 """Create the range regular expression over two sequences of length 1
11258 >>> range = Range("a",
"z")
11264 lo = _coerce_seq(lo, ctx)
11265 hi = _coerce_seq(hi, ctx)
11269 """Create the difference regular epression
11274 """Create a regular expression that accepts all single character strings
11298 """Given a binary relation R, such that the two arguments have the same sort
11299 create the transitive closure relation R+.
11300 The transitive closure R+ is a new relation.
11311 if self.
lock is None:
11313 self.
lock = threading.Lock()
11318 r = self.
bases[ctx]
11320 r = self.
bases[ctx]
11326 self.
bases[ctx] = r
11328 self.
bases[ctx] = r
11333 id = len(self.
bases) + 3
11336 id = len(self.
bases) + 3
11341_prop_closures =
None
11345 global _prop_closures
11346 if _prop_closures
is None:
11351 prop = _prop_closures.get(ctx)
11357 prop = _prop_closures.get(ctx)
11359 prop.pop(num_scopes)
11362 ctx = ContextObj(ptr)
11363 super(ctypes.c_void_p, ctx).__init__(ptr)
11368 _prop_closures.set_threaded()
11369 prop = _prop_closures.get(ctx)
11376 new_prop = prop.fresh(nctx)
11377 _prop_closures.set(new_prop.id, new_prop)
11382 super(ctypes.c_void_p, ast).__init__(ptr)
11386 prop = _prop_closures.get(ctx)
11388 id = _to_expr_ref(
to_Ast(id), prop.ctx())
11389 value = _to_expr_ref(
to_Ast(value), prop.ctx())
11390 prop.fixed(id, value)
11394 prop = _prop_closures.get(ctx)
11396 id = _to_expr_ref(
to_Ast(id), prop.ctx())
11401 prop = _prop_closures.get(ctx)
11407 prop = _prop_closures.get(ctx)
11409 x = _to_expr_ref(
to_Ast(x), prop.ctx())
11410 y = _to_expr_ref(
to_Ast(y), prop.ctx())
11415 prop = _prop_closures.get(ctx)
11417 x = _to_expr_ref(
to_Ast(x), prop.ctx())
11418 y = _to_expr_ref(
to_Ast(y), prop.ctx())
11425 prop = _prop_closures.get(ctx)
11427 t = _to_expr_ref(
to_Ast(t_ref), prop.ctx())
11428 t, idx, phase = prop.decide(t, idx, phase)
11435_user_prop_push = Z3_push_eh(user_prop_push)
11436_user_prop_pop = Z3_pop_eh(user_prop_pop)
11437_user_prop_fresh = Z3_fresh_eh(user_prop_fresh)
11438_user_prop_fixed = Z3_fixed_eh(user_prop_fixed)
11439_user_prop_created = Z3_created_eh(user_prop_created)
11440_user_prop_final = Z3_final_eh(user_prop_final)
11441_user_prop_eq = Z3_eq_eh(user_prop_eq)
11442_user_prop_diseq = Z3_eq_eh(user_prop_diseq)
11443_user_prop_decide = Z3_decide_eh(user_prop_decide)
11446 """Create a function that gets tracked by user propagator.
11447 Every term headed by this function symbol is tracked.
11448 If a term
is fixed
and the fixed callback
is registered a
11449 callback
is invoked that the term headed by this function
is fixed.
11451 sig = _get_args(sig)
11453 _z3_assert(len(sig) > 0,
"At least two arguments expected")
11454 arity = len(sig) - 1
11457 _z3_assert(
is_sort(rng),
"Z3 sort expected")
11458 dom = (Sort * arity)()
11459 for i
in range(arity):
11461 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
11462 dom[i] = sig[i].ast
11477 assert s
is None or ctx
is None
11483 self.
id = _prop_closures.insert(self)
11494 ctypes.c_void_p(self.
id),
11501 self.
_ctx.ctx =
None
11510 return self.
ctx().ref()
11513 assert not self.
fixed
11514 assert not self.
_ctx
11521 assert not self.
_ctx
11527 assert not self.
final
11528 assert not self.
_ctx
11535 assert not self.
_ctx
11541 assert not self.
diseq
11542 assert not self.
_ctx
11549 assert not self.
_ctx
11555 raise Z3Exception(
"push needs to be overwritten")
11558 raise Z3Exception(
"pop needs to be overwritten")
11561 raise Z3Exception(
"fresh needs to be overwritten")
11564 assert not self.
_ctx
11582 _ids, num_fixed = _to_ast_array(ids)
11584 _lhs, _num_lhs = _to_ast_array([x
for x, y
in eqs])
11585 _rhs, _num_rhs = _to_ast_array([y
for x, y
in eqs])
11587 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 update_value(self, x, value)
def translate(self, target)
def evaluate(self, t, model_completion=False)
def __deepcopy__(self, memo={})
def get_interp(self, decl)
def add_soft(self, arg, weight="1", id=None)
def assert_exprs(self, *args)
def upper_values(self, obj)
def from_file(self, filename)
def set_on_model(self, on_model)
def check(self, *assumptions)
def __deepcopy__(self, memo={})
def assert_and_track(self, a, p)
def set(self, *args, **keys)
def lower_values(self, obj)
def __init__(self, ctx=None)
def __init__(self, opt, value, is_max)
def __getitem__(self, arg)
def __init__(self, descr, ctx=None)
def get_documentation(self, n)
def __deepcopy__(self, memo={})
def __init__(self, ctx=None, params=None)
def __deepcopy__(self, memo={})
def __init__(self, ctx=None)
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 next_split(self, t, idx, phase)
def __init__(self, s, ctx=None)
def propagate(self, e, ids, eqs=[])
def add_decide(self, decide)
def add_created(self, created)
def conflict(self, deps=[], eqs=[])
def add_final(self, final)
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
Z3_ast Z3_API Z3_model_get_const_interp(Z3_context c, Z3_model m, Z3_func_decl a)
Return the interpretation (i.e., assignment) of constant a in the model m. Return NULL,...
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
Z3_probe Z3_API Z3_probe_lt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than the value returned...
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
Z3_parameter_kind Z3_API Z3_get_decl_parameter_kind(Z3_context c, Z3_func_decl d, unsigned idx)
Return the parameter type associated with a declaration.
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
Z3_probe Z3_API Z3_probe_not(Z3_context x, Z3_probe p)
Return a probe that evaluates to "true" when p does not evaluate to true.
Z3_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
Z3_ast Z3_API Z3_mk_char_to_bv(Z3_context c, Z3_ast ch)
Create a bit-vector (code point) from character.
void Z3_API Z3_solver_propagate_diseq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression dis-equalities.
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p)
Return a tactic that applies t using the given set of parameters.
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
void Z3_API Z3_fixedpoint_set_predicate_representation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f, unsigned num_relations, Z3_symbol const relation_kinds[])
Configure the predicate representation.
Z3_sort Z3_API Z3_mk_char_sort(Z3_context c)
Create a sort for unicode characters.
Z3_ast Z3_API Z3_mk_re_option(Z3_context c, Z3_ast re)
Create the regular language [re].
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than or equal to.
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
Z3_ast Z3_API Z3_substitute(Z3_context c, Z3_ast a, unsigned num_exprs, Z3_ast const from[], Z3_ast const to[])
Substitute every occurrence of from[i] in a with to[i], for i smaller than num_exprs....
Z3_ast Z3_API Z3_mk_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k)
Return the value associated with the key k.
Z3_ast Z3_API Z3_mk_seq_replace(Z3_context c, Z3_ast s, Z3_ast src, Z3_ast dst)
Replace the first occurrence of src with dst in s.
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p)
Convert a parameter description set into a string. This function is mainly used for printing the cont...
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
Z3_ast Z3_API Z3_mk_set_intersect(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the intersection of a list of sets.
Z3_ast Z3_API Z3_mk_str_le(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is equal or lexicographically strictly less than s2.
Z3_params Z3_API Z3_mk_params(Z3_context c)
Create a Z3 (empty) parameter set. Starting at Z3 4.0, parameter sets are used to configure many comp...
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, Z3_solver s, Z3_ast_vector assumptions, Z3_ast_vector variables, Z3_ast_vector consequences)
retrieve consequences from solver that determine values of the supplied function symbols.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
Z3_param_kind Z3_API Z3_param_descrs_get_kind(Z3_context c, Z3_param_descrs p, Z3_symbol n)
Return the kind associated with the given parameter name n.
Z3_ast Z3_API Z3_mk_char_le(Z3_context c, Z3_ast ch1, Z3_ast ch2)
Create less than or equal to between two characters.
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_vector Z3_API Z3_optimize_get_upper_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body)
Define the body of a recursive function.
Z3_param_descrs Z3_API Z3_solver_get_param_descrs(Z3_context c, Z3_solver s)
Return the parameter description set for the given solver object.
void Z3_API Z3_solver_next_split(Z3_context c, Z3_solver_callback cb, Z3_ast t, unsigned idx, Z3_lbool phase)
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into a signed bit-vector.
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
Z3_ast Z3_API Z3_mk_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r)
Increment the reference counter of the given Z3_apply_result object.
Z3_func_interp Z3_API Z3_add_func_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast default_value)
Create a fresh func_interp object, add it to a model for a specified function. It has reference count...
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.
void Z3_API Z3_parser_context_add_decl(Z3_context c, Z3_parser_context pc, Z3_func_decl f)
Add a function declaration.
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
Z3_ast Z3_API Z3_mk_string_from_code(Z3_context c, Z3_ast a)
Code to string conversion.
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives....
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and then t2 to every subgoal produced by t1....
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k)
Return true if the map m contains the AST key k.
Z3_ast Z3_API Z3_mk_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e)
Return the number of arguments in a Z3_func_entry object.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
Z3_symbol Z3_API Z3_get_decl_symbol_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.
bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int *sgn)
Retrieves the sign of a floating-point literal.
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
Z3_probe Z3_API Z3_probe_ge(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than or equal to the...
Z3_ast Z3_API Z3_mk_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
Z3_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
void Z3_API Z3_goal_assert(Z3_context c, Z3_goal g, Z3_ast a)
Add a new formula a to the given goal. The formula is split according to the following procedure that...
Z3_symbol Z3_API Z3_param_descrs_get_name(Z3_context c, Z3_param_descrs p, unsigned i)
Return the name of the parameter at given index i.
Z3_ast Z3_API Z3_mk_re_allchar(Z3_context c, Z3_sort regex_sort)
Create a regular expression that accepts all singleton sequences of the regular expression sort.
Z3_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
Z3_ast_vector Z3_API Z3_fixedpoint_from_string(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 string with fixedpoint rules. Add the rules to the current fixedpoint context....
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz)
Conversion of a floating-point term into an unsigned bit-vector.
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
Z3_ast Z3_API Z3_mk_seq_at(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the unit sequence positioned at position index. The sequence is empty if the index is...
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m)
Convert a model of the formulas of a goal to a model of an original goal. The model may be null,...
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context....
unsigned Z3_API Z3_fpa_get_ebits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the exponent in a FloatingPoint sort.
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t)
Create a new solver that is implemented using the given tactic. The solver supports the commands Z3_s...
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
Z3_symbol Z3_API Z3_get_quantifier_bound_name(Z3_context c, Z3_ast a, unsigned i)
Return symbol of the i'th bound variable.
Z3_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m)
Return the number of constants assigned by the given model.
Z3_char_ptr Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned *length)
Retrieve the string constant stored in s. The string can contain escape sequences....
Z3_ast Z3_API Z3_mk_extract(Z3_context c, unsigned high, unsigned low, Z3_ast t1)
Extract the bits high down to low from a bit-vector of size m to yield a new bit-vector of size n,...
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t *n, bool biased)
Return the exponent value of a floating-point numeral as a signed 64-bit integer.
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
Z3_ast Z3_API Z3_mk_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
Z3_ast Z3_API Z3_mk_bvadd_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed addition of t1 and t2 does not underflow.
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise addition of t1 and t2 does not overflow.
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode)
Select mode for the format used for pretty-printing AST nodes.
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a NaN.
unsigned Z3_API Z3_fpa_get_sbits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the significand in a FloatingPoint sort.
Z3_ast_vector Z3_API Z3_optimize_get_lower_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector ...
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
void Z3_API Z3_parser_context_dec_ref(Z3_context c, Z3_parser_context pc)
Decrement the reference counter of the given Z3_parser_context object.
Z3_constructor Z3_API Z3_mk_constructor(Z3_context c, Z3_symbol name, Z3_symbol recognizer, unsigned num_fields, Z3_symbol const field_names[], Z3_sort_opt const sorts[], unsigned sort_refs[])
Create a constructor.
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.
Z3_ast Z3_API Z3_mk_bvsub_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed subtraction of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise subtraction of t1 and t2 does not underflow.
Z3_goal Z3_API Z3_goal_translate(Z3_context source, Z3_goal g, Z3_context target)
Copy a goal g from the context source to the context target.
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
Z3_ast Z3_API Z3_mk_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
Z3_ast_vector Z3_API Z3_solver_get_trail(Z3_context c, Z3_solver s)
Return the trail modulo model conversion, in order of decision level The decision level can be retrie...
bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t *n)
Return the significand value of a floating-point numeral as a uint64.
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)
Z3_ast Z3_API Z3_mk_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a)
The (_ as-array f) AST node is a construct for assigning interpretations for arrays in Z3....
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic)
Create a new solver customized for the given logic. It behaves like Z3_mk_solver if the logic is unkn...
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v)
Add a Boolean parameter k with value v to the parameter set p.
unsigned Z3_API Z3_apply_result_get_num_subgoals(Z3_context c, Z3_apply_result r)
Return the number of subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
Z3_ast Z3_API Z3_mk_ite(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3)
Create an AST node representing an if-then-else: ite(t1, t2, t3).
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i)
Array read. The argument a is the array and i is the index of the array that gets read.
Z3_ast Z3_API Z3_mk_sign_ext(Z3_context c, unsigned i, Z3_ast t1)
Sign-extend of the given bit-vector to the (signed) equivalent bit-vector of size m+i,...
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vars, unsigned backtrack_level)
extract a next cube for a solver. The last cube is the constant true or false. The number of (non-con...
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
Z3_func_decl Z3_API Z3_solver_propagate_declare(Z3_context c, Z3_symbol name, unsigned n, Z3_sort *domain, Z3_sort range)
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs)
n-ary Array read. The argument a is the array and idxs are the indices of the array that gets read.
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s)
Check if s is a string sort.
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, bool biased)
Return the exponent value of a floating-point numeral as a string.
Z3_ast_vector Z3_API Z3_algebraic_get_poly(Z3_context c, Z3_ast a)
Return the coefficients of the defining polynomial.
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
Z3_param_descrs Z3_API Z3_optimize_get_param_descrs(Z3_context c, Z3_optimize o)
Return the parameter description set for the given optimize object.
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort seq)
Create a regular expression sort out of a sequence sort.
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
void Z3_API Z3_func_interp_inc_ref(Z3_context c, Z3_func_interp f)
Increment the reference counter of the given Z3_func_interp object.
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a piecewise linear ordering relation over signature a and index id.
void Z3_API Z3_params_set_double(Z3_context c, Z3_params p, Z3_symbol k, double v)
Add a double parameter k with value v to the parameter set p.
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s)
Retrieve documentation string corresponding to parameter name s.
Z3_sort Z3_API Z3_mk_datatype_sort(Z3_context c, Z3_symbol name)
create a forward reference to a recursive datatype being declared. The forward reference can be used ...
Z3_solver Z3_API Z3_mk_solver(Z3_context c)
Create a new solver. This solver is a "combined solver" (see combined_solver module) that internally ...
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a)
Return the function declaration f associated with a (_ as_array f) node.
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[])
Return a tactic that applies the given tactics in parallel.
Z3_ast Z3_API Z3_mk_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is subnormal.
unsigned Z3_API Z3_get_datatype_sort_num_constructors(Z3_context c, Z3_sort t)
Return number of constructors for datatype.
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
void Z3_API Z3_params_set_uint(Z3_context c, Z3_params p, Z3_symbol k, unsigned v)
Add a unsigned parameter k with value v to the parameter set p.
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not.
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast t1, bool is_signed)
Create an integer from the bit-vector argument t1. If is_signed is false, then the bit-vector t1 is t...
Z3_sort Z3_API Z3_get_array_sort_domain_n(Z3_context c, Z3_sort t, unsigned idx)
Return the i'th domain sort of an n-dimensional array.
void Z3_API Z3_solver_import_model_converter(Z3_context ctx, Z3_solver src, Z3_solver dst)
Ad-hoc method for importing model conversion from solver.
Z3_ast Z3_API Z3_mk_set_del(Z3_context c, Z3_ast set, Z3_ast elem)
Remove an element to a set.
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed)
Create a predicate that checks that the bit-wise multiplication of t1 and t2 does not overflow.
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
int Z3_API Z3_get_decl_int_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the integer value associated with an integer parameter.
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c, bool is_forall, unsigned weight, Z3_symbol quantifier_id, Z3_symbol skolem_id, unsigned num_bound, Z3_app const bound[], unsigned num_patterns, Z3_pattern const patterns[], unsigned num_no_patterns, Z3_ast const no_patterns[], Z3_ast body)
Create a universal or existential quantifier using a list of constants that will form the set of boun...
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
Z3_ast Z3_API Z3_mk_seq_suffix(Z3_context c, Z3_ast suffix, Z3_ast s)
Check if suffix is a suffix of s.
Z3_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s)
Return Z3_INT_SYMBOL if the symbol was constructed using Z3_mk_int_symbol, and Z3_STRING_SYMBOL if th...
Z3_sort Z3_API Z3_get_re_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for regex sort.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
Z3_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s)
Return a string describing all solver available parameters.
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
Z3_sort Z3_API Z3_get_array_sort_domain(Z3_context c, Z3_sort t)
Return the domain of the given array sort. In the case of a multi-dimensional array,...
void Z3_API Z3_solver_propagate_register_cb(Z3_context c, Z3_solver_callback cb, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
Z3_ast Z3_API Z3_mk_bvmul_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed multiplication of t1 and t2 does not underflo...
Z3_string Z3_API Z3_get_probe_name(Z3_context c, unsigned i)
Return the name of the i probe.
Z3_ast Z3_API Z3_func_decl_to_ast(Z3_context c, Z3_func_decl f)
Convert a Z3_func_decl into Z3_ast. This is just type casting.
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a)
Add a constant interpretation.
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
unsigned Z3_API Z3_algebraic_get_i(Z3_context c, Z3_ast a)
Return which root of the polynomial the algebraic number represents.
void Z3_API Z3_params_dec_ref(Z3_context c, Z3_params p)
Decrement the reference counter of the given parameter set.
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
Z3_ast Z3_API Z3_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.
Z3_ast Z3_API Z3_mk_str_lt(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is lexicographically strictly less than s2.
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
Z3_string Z3_API Z3_tactic_get_help(Z3_context c, Z3_tactic t)
Return a string containing a description of parameters accepted by the given tactic.
Z3_func_decl Z3_API Z3_mk_fresh_func_decl(Z3_context c, Z3_string prefix, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a fresh constant or function.
void Z3_API Z3_solver_propagate_final(Z3_context c, Z3_solver s, Z3_final_eh final_eh)
register a callback on final check. This provides freedom to the propagator to delay actions or imple...
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
unsigned Z3_API Z3_param_descrs_size(Z3_context c, Z3_param_descrs p)
Return the number of parameters in the given parameter description set.
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Parse the given string using the SMT-LIB2 parser.
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g, bool include_names)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g)
Return the depth of the given goal. It tracks how many transformations were applied to it.
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p)
Convert a Z3_pattern into Z3_ast. This is just type casting.
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
unsigned Z3_API Z3_func_interp_get_arity(Z3_context c, Z3_func_interp f)
Return the arity (number of arguments) of the given function interpretation.
Z3_ast_vector Z3_API Z3_solver_get_non_units(Z3_context c, Z3_solver s)
Return the set of non units in the solver state.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
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_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of the first occurrence of substr in s starting from offset offset. If s does not contai...
Z3_ast Z3_API Z3_get_algebraic_number_upper(Z3_context c, Z3_ast a, unsigned precision)
Return a upper bound for the given real algebraic number. The interval isolating the number is smalle...
Z3_ast Z3_API Z3_mk_power(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 ^ arg2.
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c, Z3_symbol name, unsigned n, Z3_symbol const enum_names[], Z3_func_decl enum_consts[], Z3_func_decl enum_testers[])
Create a enumeration sort.
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.
Z3_ast Z3_API Z3_fpa_get_numeral_significand_bv(Z3_context c, Z3_ast t)
Retrieves the significand of a floating-point literal as a bit-vector expression.
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p)
Return a tactic that fails if the probe p evaluates to false.
void Z3_API Z3_func_interp_dec_ref(Z3_context c, Z3_func_interp f)
Decrement the reference counter of the given Z3_func_interp object.
Z3_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
Z3_ast Z3_API Z3_mk_distinct(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing distinct(args[0], ..., args[num_args-1]).
Z3_ast Z3_API Z3_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
Z3_string Z3_API Z3_params_to_string(Z3_context c, Z3_params p)
Convert a parameter set into a string. This function is mainly used for printing the contents of a pa...
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode.
Z3_param_descrs Z3_API Z3_get_global_param_descrs(Z3_context c)
Retrieve description of global parameters.
void Z3_API Z3_solver_propagate_init(Z3_context c, Z3_solver s, void *user_context, Z3_push_eh push_eh, Z3_pop_eh pop_eh, Z3_fresh_eh fresh_eh)
register a user-properator with the solver.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
Z3_ast Z3_API Z3_translate(Z3_context source, Z3_ast a, Z3_context target)
Translate/Copy the AST a from context source to context target. AST a must have been created using co...
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d)
Return the range of the given declaration.
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s)
Return the finite set of distinct values that represent the interpretation for sort s.
Z3_string Z3_API Z3_benchmark_to_smtlib_string(Z3_context c, Z3_string name, Z3_string logic, Z3_string status, Z3_string attributes, unsigned num_assumptions, Z3_ast const assumptions[], Z3_ast formula)
Convert the given benchmark into SMT-LIB formatted string.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
Z3_ast Z3_API Z3_mk_char(Z3_context c, unsigned ch)
Create a character literal.
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
void Z3_API Z3_param_descrs_dec_ref(Z3_context c, Z3_param_descrs p)
Decrement the reference counter of the given parameter description set.
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
Z3_ast Z3_API Z3_mk_bvneg_no_overflow(Z3_context c, Z3_ast t1)
Check that bit-wise negation does not overflow when t1 is interpreted as a signed bit-vector.
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
Z3_ast Z3_API Z3_mk_re_diff(Z3_context c, Z3_ast re1, Z3_ast re2)
Create the difference of regular expressions.
unsigned Z3_API Z3_fixedpoint_get_num_levels(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred)
Query the PDR engine for the maximal levels properties are known about predicate.
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a real-numbered term.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
Z3_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size)
Create a named finite domain sort.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort const sorts[], unsigned num_decls, Z3_symbol const decl_names[], Z3_func_decl const decls[])
Similar to Z3_parse_smtlib2_string, but reads the benchmark from a file.
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows divisor).
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal if the probe p evaluates to true, and t2 if p evaluat...
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
Z3_string Z3_API Z3_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz, unsigned levels[])
retrieve the decision depth of Boolean literals (variables or their negations). Assumes a check-sat c...
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
Z3_ast Z3_API Z3_fixedpoint_get_cover_delta(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred)
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
Z3_apply_result Z3_API Z3_tactic_apply_ex(Z3_context c, Z3_tactic t, Z3_goal g, Z3_params p)
Apply tactic t to the goal g using the parameter set p.
Z3_ast Z3_API Z3_mk_int2bv(Z3_context c, unsigned n, Z3_ast t1)
Create an n bit bit-vector from the integer argument t1.
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_parser_context_add_sort(Z3_context c, Z3_parser_context pc, Z3_sort s)
Add a sort declaration.
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of quantifier.
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.
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_substitute_funs(Z3_context c, Z3_ast a, unsigned num_funs, Z3_func_decl const from[], Z3_ast const to[])
Substitute funcions in from with new expressions in to.
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.
void Z3_API Z3_solver_propagate_consequence(Z3_context c, Z3_solver_callback, unsigned num_fixed, Z3_ast const *fixed, unsigned num_eqs, Z3_ast const *eq_lhs, Z3_ast const *eq_rhs, Z3_ast conseq)
propagate a consequence based on fixed values. This is a callback a client may invoke during the fixe...
Z3_ast Z3_API Z3_mk_eq(Z3_context c, Z3_ast l, Z3_ast r)
Create an AST node representing l = r.
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
void Z3_API Z3_parser_context_inc_ref(Z3_context c, Z3_parser_context pc)
Increment the reference counter of the given Z3_parser_context object.
void Z3_API Z3_dec_ref(Z3_context c, Z3_ast a)
Decrement the reference counter of the given AST. The context c should have been created using Z3_mk_...
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s)
Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the as...
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id)
create a partial ordering relation over signature a and index id.
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, bool biased)
Retrieves the exponent of a floating-point literal as a bit-vector expression.
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_mk_set_has_size(Z3_context c, Z3_ast set, Z3_ast k)
Create predicate that holds if Boolean array set has k elements set to true.
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
Z3_ast Z3_API Z3_mk_re_loop(Z3_context c, Z3_ast r, unsigned lo, unsigned hi)
Create a regular expression loop. The supplied regular expression r is repeated between lo and hi tim...
Z3_ast Z3_API Z3_mk_char_to_int(Z3_context c, Z3_ast ch)
Create an integer (code point) from character.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the tactic with the given name.
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs)
Create a goal (aka problem). A goal is essentially a set of formulas, that can be solved and/or trans...
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural but two different AST objects can m...
Z3_string Z3_API Z3_optimize_get_help(Z3_context c, Z3_optimize t)
Return a string containing a description of parameters accepted by optimize.
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
void Z3_API Z3_params_validate(Z3_context c, Z3_params p, Z3_param_descrs d)
Validate the parameter set p against the parameter description set d.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
void Z3_API Z3_global_param_reset_all(void)
Restore the value of all global (and module) parameters. This command will not affect already created...
Z3_ast Z3_API Z3_mk_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than.
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_probe Z3_API Z3_probe_gt(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is greater than the value retur...
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the rational value, as a string, associated with a rational parameter.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
Z3_parser_context Z3_API Z3_mk_parser_context(Z3_context c)
Create a parser context.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
Z3_ast Z3_API Z3_mk_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
void Z3_API Z3_solver_propagate_eq(Z3_context c, Z3_solver s, Z3_eq_eh eq_eh)
register a callback on expression equalities.
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in The string may contain escape encoding f...
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms)
Return a tactic that applies t to a given goal for ms milliseconds. If t does not terminate in ms mil...
void Z3_API Z3_apply_result_dec_ref(Z3_context c, Z3_apply_result r)
Decrement the reference counter of the given Z3_apply_result object.
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const *args)
Map f on the argument arrays.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, Z3_string s)
Create a Z3 symbol using a C string.
Z3_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return index of the last occurrence of substr in s. If s does not contain substr, then the value is -...
Z3_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p)
Increment the reference counter of the given parameter description set.
Z3_goal Z3_API Z3_apply_result_get_subgoal(Z3_context c, Z3_apply_result r, unsigned i)
Return one of the subgoals in the Z3_apply_result object returned by Z3_tactic_apply.
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_ast Z3_API Z3_mk_array_ext(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create array extensionality index given two arrays with the same sort. The meaning is given by the ax...
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
Z3_ast Z3_API Z3_sort_to_ast(Z3_context c, Z3_sort s)
Convert a Z3_sort into Z3_ast. This is just type casting.
Z3_func_entry Z3_API Z3_func_interp_get_entry(Z3_context c, Z3_func_interp f, unsigned i)
Return a "point" of the given function interpretation. It represents the value of f in a particular p...
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a recursive function.
unsigned Z3_API Z3_get_ast_id(Z3_context c, Z3_ast t)
Return a unique identifier for t. The identifier is unique up to structural equality....
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a FloatingPoint term into another term of different FloatingPoint sort.
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the sort value associated with a sort parameter.
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
void Z3_API Z3_solver_propagate_created(Z3_context c, Z3_solver s, Z3_created_eh created_eh)
register a callback when a new expression with a registered function is used by the solver The regist...
Z3_ast_vector Z3_API Z3_parser_context_from_string(Z3_context c, Z3_parser_context pc, Z3_string s)
Parse a string of SMTLIB2 commands. Return assertions.
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_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const *idxs, Z3_ast v)
n-ary Array update.
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c, Z3_fixedpoint d)
Retrieve a string that describes the last status returned by Z3_fixedpoint_query.
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
Z3_sort Z3_API Z3_get_domain(Z3_context c, Z3_func_decl d, unsigned i)
Return the sort of the i-th parameter of the given function declaration.
Z3_ast Z3_API Z3_mk_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
void Z3_API Z3_params_set_symbol(Z3_context c, Z3_params p, Z3_symbol k, Z3_symbol v)
Add a symbol parameter k with value v to the parameter set p.
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
Z3_string Z3_API Z3_solver_to_dimacs_string(Z3_context c, Z3_solver s, bool include_names)
Convert a solver into a DIMACS formatted string.
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
Z3_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
void Z3_API Z3_solver_propagate_decide(Z3_context c, Z3_solver s, Z3_decide_eh decide_eh)
register a callback when the solver decides to split on a registered expression. The callback may set...
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
Z3_string Z3_API Z3_optimize_get_reason_unknown(Z3_context c, Z3_optimize d)
Retrieve a string that describes the last status returned by Z3_optimize_check.
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
void Z3_API Z3_solver_propagate_register(Z3_context c, Z3_solver s, Z3_ast e)
register an expression to propagate on with the solver. Only expressions of type Bool and type Bit-Ve...
Z3_ast 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_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives....
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t)
Return the significand value of a floating-point numeral as a string.
Z3_ast Z3_API Z3_fixedpoint_get_answer(Z3_context c, Z3_fixedpoint d)
Retrieve a formula that encodes satisfying answers to the query.
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a decimal string of a numeric constant term.
void Z3_API Z3_solver_propagate_fixed(Z3_context c, Z3_solver s, Z3_fixed_eh fixed_eh)
register a callback for when an expression is bound to a fixed value. The supported expression types ...
Z3_ast Z3_API Z3_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t)
Retrieves the sign of a floating-point literal as a bit-vector expression.
void Z3_API Z3_fixedpoint_register_relation(Z3_context c, Z3_fixedpoint d, Z3_func_decl f)
Register relation as Fixedpoint defined. Fixedpoint defined relations have least-fixedpoint semantics...
Z3_ast Z3_API Z3_mk_char_is_digit(Z3_context c, Z3_ast ch)
Create a check if the character is a digit.
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...
void Z3_API Z3_func_interp_add_entry(Z3_context c, Z3_func_interp fi, Z3_ast_vector args, Z3_ast value)
add a function entry to a function interpretation.
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_lbool Z3_API Z3_fixedpoint_query_relations(Z3_context c, Z3_fixedpoint d, unsigned num_relations, Z3_func_decl const relations[])
Pose multiple queries against the asserted rules.
Z3_string Z3_API Z3_apply_result_to_string(Z3_context c, Z3_apply_result r)
Convert the Z3_apply_result object returned by Z3_tactic_apply into a string.
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
void Z3_API Z3_optimize_register_model_eh(Z3_context c, Z3_optimize o, Z3_model m, void *ctx, Z3_model_eh model_eh)
register a model event handler for new models.
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s)
Return a brief justification for an "unknown" result (i.e., Z3_L_UNDEF) for the commands Z3_solver_ch...
Z3_string Z3_API Z3_get_numeral_binary_string(Z3_context c, Z3_ast a)
Return numeral value, as a binary string of a numeric constant term.
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i)
Return sort of the i'th bound variable.
void Z3_API Z3_disable_trace(Z3_string tag)
Disable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max)
Return a tactic that keeps applying t until the goal is not modified anymore or the maximum number of...
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
Z3_ast Z3_API Z3_mk_char_from_bv(Z3_context c, Z3_ast bv)
Create a character from a bit-vector (code point).
unsigned Z3_API Z3_func_interp_get_num_entries(Z3_context c, Z3_func_interp f)
Return the number of entries in the given function interpretation.
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, Z3_ast const args[], unsigned k)
Pseudo-Boolean relations.
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
Z3_tactic Z3_API Z3_tactic_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that applies t1 to a given goal and t2 to every subgoal produced by t1.
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
void Z3_API Z3_solver_inc_ref(Z3_context c, Z3_solver s)
Increment the reference counter of the given solver.
Z3_ast Z3_API Z3_mk_string_to_code(Z3_context c, Z3_ast a)
String to code conversion.
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for unicode strings.
Z3_ast Z3_API Z3_mk_ext_rotate_right(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the right t2 times.
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
Z3_ast Z3_API Z3_mk_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
Z3_ast Z3_API Z3_mk_seq_nth(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the element positioned at position index. The function is under-specified if the inde...
bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a +oo or -oo.
Z3_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is +zero or -zero.
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
expr range(expr const &lo, expr const &hi)
def PbEq(args, k, ctx=None)
def fpBVToFP(v, sort, ctx=None)
def user_prop_created(ctx, cb, id)
def Repeat(t, max=4294967295, ctx=None)
def PropagateFunction(name, *sig)
def fpLEQ(a, b, ctx=None)
def RealVar(idx, ctx=None)
def If(a, b, c, ctx=None)
def fpIsPositive(a, ctx=None)
def substitute_vars(t, *m)
def simplify(a, *arguments, **keywords)
Utils.
def fpSub(rm, a, b, ctx=None)
def args2params(arguments, keywords, ctx=None)
def EnumSort(name, values, ctx=None)
def prove(claim, show=False, **keywords)
def RecAddDefinition(f, args, body)
def IndexOf(s, substr, offset=None)
def RoundNearestTiesToAway(ctx=None)
def simplify_param_descrs()
def fpMax(a, b, ctx=None)
def RecFunction(name, *sig)
def PiecewiseLinearOrder(a, index)
def fpRealToFP(rm, v, sort, ctx=None)
def SimpleSolver(ctx=None, logFile=None)
def user_prop_fresh(ctx, _new_ctx)
def fpToFPUnsigned(rm, x, s, ctx=None)
def BVMulNoUnderflow(a, b)
def fpMul(rm, a, b, ctx=None)
def FPVal(sig, exp=None, fps=None, ctx=None)
def RoundTowardPositive(ctx=None)
def fpIsNormal(a, ctx=None)
def get_default_fp_sort(ctx=None)
def fpDiv(rm, a, b, ctx=None)
def Implies(a, b, ctx=None)
def probe_description(name, ctx=None)
def DatatypeSort(name, ctx=None)
def BVSubNoOverflow(a, b)
def tactic_description(name, ctx=None)
def FloatSingle(ctx=None)
def RoundTowardNegative(ctx=None)
def TupleSort(name, sorts, ctx=None)
def fpIsZero(a, ctx=None)
def ParAndThen(t1, t2, ctx=None)
def BitVecVal(val, bv, ctx=None)
def FloatQuadruple(ctx=None)
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
def fpGEQ(a, b, ctx=None)
def fpAdd(rm, a, b, ctx=None)
def user_prop_final(ctx, cb)
def CharVal(ch, ctx=None)
def solve_using(s, *args, **keywords)
def SubString(s, offset, length)
def user_prop_diseq(ctx, cb, x, y)
def With(t, *args, **keys)
def DisjointSum(name, sorts, ctx=None)
def PartialOrder(a, index)
def fpRoundToIntegral(rm, a, ctx=None)
def set_option(*args, **kws)
def fpUnsignedToFP(rm, v, sort, ctx=None)
def user_prop_decide(ctx, cb, t_ref, idx_ref, phase_ref)
def user_prop_pop(ctx, cb, num_scopes)
def solve(*args, **keywords)
def is_algebraic_value(a)
def String(name, ctx=None)
def user_prop_eq(ctx, cb, x, y)
def get_default_rounding_mode(ctx=None)
def user_prop_fixed(ctx, cb, id, value)
def CharIsDigit(ch, ctx=None)
def fpMin(a, b, ctx=None)
def fpFP(sgn, exp, sig, ctx=None)
def RealVal(val, ctx=None)
def CharToBv(ch, ctx=None)
def set_param(*args, **kws)
def fpIsSubnormal(a, ctx=None)
def BoolVal(val, ctx=None)
def fpInfinity(s, negative)
def SolverFor(logic, ctx=None, logFile=None)
def Bools(names, ctx=None)
def FP(name, fpsort, ctx=None)
def Range(lo, hi, ctx=None)
def BVMulNoOverflow(a, b, signed)
def fpSqrt(rm, a, ctx=None)
def StringVal(s, ctx=None)
def fpSignedToFP(rm, v, sort, ctx=None)
def BVAddNoOverflow(a, b, signed)
def TryFor(t, ms, ctx=None)
def FPSort(ebits, sbits, ctx=None)
def FiniteDomainVal(val, sort, ctx=None)
def IntVector(prefix, sz, ctx=None)
def fpToSBV(rm, x, s, ctx=None)
def BVAddNoUnderflow(a, b)
def substitute_funs(t, *m)
def LastIndexOf(s, substr)
def FloatDouble(ctx=None)
def BoolVector(prefix, sz, ctx=None)
def FiniteDomainSort(name, sz, ctx=None)
def Strings(names, ctx=None)
def fpToIEEEBV(x, ctx=None)
def BitVecs(names, bv, ctx=None)
def Cond(p, t1, t2, ctx=None)
def user_prop_push(ctx, cb)
def fpFPToFP(rm, v, sort, ctx=None)
def is_finite_domain_sort(s)
def IntVal(val, ctx=None)
def CharFromBv(ch, ctx=None)
def RatVal(a, b, ctx=None)
def DeclareSort(name, ctx=None)
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
def BV2Int(a, is_signed=False)
def SubSeq(s, offset, length)
def RealVector(prefix, sz, ctx=None)
def fpIsNegative(a, ctx=None)
def Reals(names, ctx=None)
def BitVec(name, bv, ctx=None)
def Ints(names, ctx=None)
def FreshInt(prefix="x", ctx=None)
def LinearOrder(a, index)
def FPs(names, fpsort, ctx=None)
def BVSubNoUnderflow(a, b, signed)
def AllChar(regex_sort, ctx=None)
def ParThen(t1, t2, ctx=None)
def RealVarVector(n, ctx=None)
def FreshReal(prefix="b", ctx=None)
def BitVecSort(sz, ctx=None)
def fpRem(a, b, ctx=None)
def set_default_rounding_mode(rm, ctx=None)
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
def BVSDivNoOverflow(a, b)
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
def fpFMA(rm, a, b, c, ctx=None)
def RoundNearestTiesToEven(ctx=None)
def Extract(high, low, a)
def to_symbol(s, ctx=None)
def set_default_fp_sort(ebits, sbits, ctx=None)
def CharToInt(ch, ctx=None)
def FreshBool(prefix="b", ctx=None)
def fpToUBV(rm, x, s, ctx=None)
def is_finite_domain_value(a)
def FreshConst(sort, prefix="c")
def fpNEQ(a, b, ctx=None)
def RoundTowardZero(ctx=None)
def ensure_prop_closures()
def fpToFP(a1, a2=None, a3=None, ctx=None)
def z3_error_handler(c, e)
def fpToReal(x, ctx=None)