11 """Z3 is a high performance theorem prover developed at Microsoft Research. Z3 is used in many applications such as: software/hardware verification and testing, constraint solving, analysis of hybrid systems, security, biology (in silico analysis), and geometrical problems. 13 Several online tutorials for Z3Py are available at: 14 http://rise4fun.com/Z3Py/tutorial/guide 16 Please send feedback, comments and/or corrections on the Issue tracker for https://github.com/Z3prover/z3.git. Your comments are very valuable. 37 ... x = BitVec('x', 32) 39 ... # the expression x + y is type incorrect 41 ... except Z3Exception as ex: 42 ... print("failed: %s" % ex) 47 from .z3types
import *
48 from .z3consts
import *
49 from .z3printer
import *
50 from fractions
import Fraction
64 return isinstance(v, (int, long))
67 return isinstance(v, int)
76 major = ctypes.c_uint(0)
77 minor = ctypes.c_uint(0)
78 build = ctypes.c_uint(0)
79 rev = ctypes.c_uint(0)
81 return "%s.%s.%s" % (major.value, minor.value, build.value)
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 (major.value, minor.value, build.value, rev.value)
96 def _z3_assert(cond, msg):
98 raise Z3Exception(msg)
100 def _z3_check_cint_overflow(n, name):
101 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
104 """Log interaction to a file. This function must be invoked immediately after init(). """ 108 """Append user-defined string to interaction log. """ 112 """Convert an integer or string into a Z3 symbol.""" 118 def _symbol2py(ctx, s):
119 """Convert a Z3 symbol back into a Python object. """ 130 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
132 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
133 return [arg
for arg
in args[0]]
140 def _get_args_ast_list(args):
142 if isinstance(args, set)
or isinstance(args, AstVector)
or isinstance(args, tuple):
143 return [arg
for arg
in args]
149 def _to_param_value(val):
150 if isinstance(val, bool):
164 """A Context manages all other Z3 objects, global configuration options, etc. 166 Z3Py uses a default global context. For most applications this is sufficient. 167 An application may use multiple Z3 contexts. Objects created in one context 168 cannot be used in another one. However, several objects may be "translated" from 169 one context to another. It is not safe to access Z3 objects from multiple threads. 170 The only exception is the method `interrupt()` that can be used to interrupt() a long 172 The initialization method receives global configuration options for the new context. 176 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
199 """Return a reference to the actual C pointer to the Z3 context.""" 203 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions. 205 This method can be invoked from a thread different from the one executing the 206 interruptible procedure. 214 """Return a reference to the global Z3 context. 217 >>> x.ctx == main_ctx() 222 >>> x2 = Real('x', c) 229 if _main_ctx
is None:
243 """Set Z3 global (or module) parameters. 245 >>> set_param(precision=10) 248 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
252 if not set_pp_option(k, v):
266 """Reset all global (or module) parameters. 271 """Alias for 'set_param' for backward compatibility. 276 """Return the value of a Z3 global (or module) parameter 278 >>> get_param('nlsat.reorder') 281 ptr = (ctypes.c_char_p * 1)()
283 r = z3core._to_pystr(ptr[0])
285 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
295 """Superclass for all Z3 objects that have support for pretty printing.""" 299 def _repr_html_(self):
300 in_html = in_html_mode()
303 set_html_mode(in_html)
308 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions.""" 315 if self.
ctx.ref()
is not None and self.
ast is not None:
320 return _to_ast_ref(self.
ast, self.
ctx)
323 return obj_to_string(self)
326 return obj_to_string(self)
329 return self.
eq(other)
342 elif is_eq(self)
and self.num_args() == 2:
343 return self.arg(0).
eq(self.arg(1))
345 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
348 """Return a string representing the AST node in s-expression notation. 351 >>> ((x + 1)*x).sexpr() 357 """Return a pointer to the corresponding C Z3_ast object.""" 361 """Return unique identifier for object. It can be used for hash-tables and maps.""" 365 """Return a reference to the C context where this AST node is stored.""" 366 return self.
ctx.ref()
369 """Return `True` if `self` and `other` are structurally identical. 376 >>> n1 = simplify(n1) 377 >>> n2 = simplify(n2) 382 _z3_assert(
is_ast(other),
"Z3 AST expected")
386 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 392 >>> # Nodes in different contexts can't be mixed. 393 >>> # However, we can translate nodes from one context to another. 394 >>> x.translate(c2) + y 398 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
405 """Return a hashcode for the `self`. 407 >>> n1 = simplify(Int('x') + 1) 408 >>> n2 = simplify(2 + Int('x') - 1) 409 >>> n1.hash() == n2.hash() 415 """Return `True` if `a` is an AST node. 419 >>> is_ast(IntVal(10)) 423 >>> is_ast(BoolSort()) 425 >>> is_ast(Function('f', IntSort(), IntSort())) 432 return isinstance(a, AstRef)
435 """Return `True` if `a` and `b` are structurally identical AST nodes. 445 >>> eq(simplify(x + 1), simplify(1 + x)) 452 def _ast_kind(ctx, a):
457 def _ctx_from_ast_arg_list(args, default_ctx=None):
465 _z3_assert(ctx == a.ctx,
"Context mismatch")
470 def _ctx_from_ast_args(*args):
471 return _ctx_from_ast_arg_list(args)
473 def _to_func_decl_array(args):
475 _args = (FuncDecl * sz)()
477 _args[i] = args[i].as_func_decl()
480 def _to_ast_array(args):
484 _args[i] = args[i].as_ast()
487 def _to_ref_array(ref, args):
491 _args[i] = args[i].as_ast()
494 def _to_ast_ref(a, ctx):
495 k = _ast_kind(ctx, a)
497 return _to_sort_ref(a, ctx)
498 elif k == Z3_FUNC_DECL_AST:
499 return _to_func_decl_ref(a, ctx)
501 return _to_expr_ref(a, ctx)
510 def _sort_kind(ctx, s):
514 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node.""" 522 """Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts. 525 >>> b.kind() == Z3_BOOL_SORT 527 >>> b.kind() == Z3_INT_SORT 529 >>> A = ArraySort(IntSort(), IntSort()) 530 >>> A.kind() == Z3_ARRAY_SORT 532 >>> A.kind() == Z3_INT_SORT 535 return _sort_kind(self.
ctx, self.
ast)
538 """Return `True` if `self` is a subsort of `other`. 540 >>> IntSort().subsort(RealSort()) 546 """Try to cast `val` as an element of sort `self`. 548 This method is used in Z3Py to convert Python objects such as integers, 549 floats, longs and strings into Z3 expressions. 552 >>> RealSort().cast(x) 556 _z3_assert(
is_expr(val),
"Z3 expression expected")
557 _z3_assert(self.
eq(val.sort()),
"Sort mismatch")
561 """Return the name (string) of sort `self`. 563 >>> BoolSort().name() 565 >>> ArraySort(IntSort(), IntSort()).name() 571 """Return `True` if `self` and `other` are the same Z3 sort. 574 >>> p.sort() == BoolSort() 576 >>> p.sort() == IntSort() 584 """Return `True` if `self` and `other` are not the same Z3 sort. 587 >>> p.sort() != BoolSort() 589 >>> p.sort() != IntSort() 596 return AstRef.__hash__(self)
599 """Return `True` if `s` is a Z3 sort. 601 >>> is_sort(IntSort()) 603 >>> is_sort(Int('x')) 605 >>> is_expr(Int('x')) 608 return isinstance(s, SortRef)
610 def _to_sort_ref(s, ctx):
612 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
613 k = _sort_kind(ctx, s)
614 if k == Z3_BOOL_SORT:
616 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
618 elif k == Z3_BV_SORT:
620 elif k == Z3_ARRAY_SORT:
622 elif k == Z3_DATATYPE_SORT:
624 elif k == Z3_FINITE_DOMAIN_SORT:
626 elif k == Z3_FLOATING_POINT_SORT:
628 elif k == Z3_ROUNDING_MODE_SORT:
630 elif k == Z3_RE_SORT:
632 elif k == Z3_SEQ_SORT:
637 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
640 """Create a new uninterpreted sort named `name`. 642 If `ctx=None`, then the new sort is declared in the global Z3Py context. 644 >>> A = DeclareSort('A') 645 >>> a = Const('a', A) 646 >>> b = Const('b', A) 664 """Function declaration. Every constant and function have an associated declaration. 666 The declaration assigns a name, a sort (i.e., type), and for function 667 the sort (i.e., type) of each of its arguments. Note that, in Z3, 668 a constant is a function with 0 arguments. 680 """Return the name of the function declaration `self`. 682 >>> f = Function('f', IntSort(), IntSort()) 685 >>> isinstance(f.name(), str) 691 """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0. 693 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 700 """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`. 702 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 709 _z3_assert(i < self.
arity(),
"Index out of bounds")
713 """Return the sort of the range of a function declaration. For constants, this is the sort of the constant. 715 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 722 """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc. 725 >>> d = (x + 1).decl() 726 >>> d.kind() == Z3_OP_ADD 728 >>> d.kind() == Z3_OP_MUL 736 result = [
None for i
in range(n) ]
739 if k == Z3_PARAMETER_INT:
741 elif k == Z3_PARAMETER_DOUBLE:
743 elif k == Z3_PARAMETER_RATIONAL:
745 elif k == Z3_PARAMETER_SYMBOL:
747 elif k == Z3_PARAMETER_SORT:
749 elif k == Z3_PARAMETER_AST:
751 elif k == Z3_PARAMETER_FUNC_DECL:
758 """Create a Z3 application expression using the function `self`, and the given arguments. 760 The arguments must be Z3 expressions. This method assumes that 761 the sorts of the elements in `args` match the sorts of the 762 domain. Limited coercion is supported. For example, if 763 args[0] is a Python integer, and the function expects a Z3 764 integer, then the argument is automatically converted into a 767 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 775 args = _get_args(args)
778 _z3_assert(num == self.
arity(),
"Incorrect number of arguments to %s" % self)
779 _args = (Ast * num)()
784 tmp = self.
domain(i).cast(args[i])
786 _args[i] = tmp.as_ast()
790 """Return `True` if `a` is a Z3 function declaration. 792 >>> f = Function('f', IntSort(), IntSort()) 799 return isinstance(a, FuncDeclRef)
802 """Create a new Z3 uninterpreted function with the given sorts. 804 >>> f = Function('f', IntSort(), IntSort()) 810 _z3_assert(len(sig) > 0,
"At least two arguments expected")
814 _z3_assert(
is_sort(rng),
"Z3 sort expected")
815 dom = (Sort * arity)()
816 for i
in range(arity):
818 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
823 def _to_func_decl_ref(a, ctx):
827 """Create a new Z3 recursive with the given sorts.""" 830 _z3_assert(len(sig) > 0,
"At least two arguments expected")
834 _z3_assert(
is_sort(rng),
"Z3 sort expected")
835 dom = (Sort * arity)()
836 for i
in range(arity):
838 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
844 """Set the body of a recursive function. 845 Recursive definitions are only unfolded during search. 847 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx)) 848 >>> n = Int('n', ctx) 849 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1))) 852 >>> s = Solver(ctx=ctx) 853 >>> s.add(fac(n) < 3) 856 >>> s.model().eval(fac(5)) 862 args = _get_args(args)
866 _args[i] = args[i].ast
876 """Constraints, formulas and terms are expressions in Z3. 878 Expressions are ASTs. Every expression has a sort. 879 There are three main kinds of expressions: 880 function applications, quantifiers and bounded variables. 881 A constant is a function application with 0 arguments. 882 For quantifier free problems, all expressions are 883 function applications. 892 """Return the sort of expression `self`. 904 """Shorthand for `self.sort().kind()`. 906 >>> a = Array('a', IntSort(), IntSort()) 907 >>> a.sort_kind() == Z3_ARRAY_SORT 909 >>> a.sort_kind() == Z3_INT_SORT 912 return self.
sort().kind()
915 """Return a Z3 expression that represents the constraint `self == other`. 917 If `other` is `None`, then this method simply returns `False`. 928 a, b = _coerce_exprs(self, other)
933 return AstRef.__hash__(self)
936 """Return a Z3 expression that represents the constraint `self != other`. 938 If `other` is `None`, then this method simply returns `True`. 949 a, b = _coerce_exprs(self, other)
950 _args, sz = _to_ast_array((a, b))
957 """Return the Z3 function declaration associated with a Z3 application. 959 >>> f = Function('f', IntSort(), IntSort()) 968 _z3_assert(
is_app(self),
"Z3 application expected")
972 """Return the number of arguments of a Z3 application. 976 >>> (a + b).num_args() 978 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort()) 984 _z3_assert(
is_app(self),
"Z3 application expected")
988 """Return argument `idx` of the application `self`. 990 This method assumes that `self` is a function application with at least `idx+1` arguments. 994 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort()) 1004 _z3_assert(
is_app(self),
"Z3 application expected")
1005 _z3_assert(idx < self.
num_args(),
"Invalid argument index")
1009 """Return a list containing the children of the given expression 1013 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort()) 1023 def _to_expr_ref(a, ctx):
1024 if isinstance(a, Pattern):
1028 if k == Z3_QUANTIFIER_AST:
1031 if sk == Z3_BOOL_SORT:
1033 if sk == Z3_INT_SORT:
1034 if k == Z3_NUMERAL_AST:
1037 if sk == Z3_REAL_SORT:
1038 if k == Z3_NUMERAL_AST:
1040 if _is_algebraic(ctx, a):
1043 if sk == Z3_BV_SORT:
1044 if k == Z3_NUMERAL_AST:
1048 if sk == Z3_ARRAY_SORT:
1050 if sk == Z3_DATATYPE_SORT:
1052 if sk == Z3_FLOATING_POINT_SORT:
1053 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1056 return FPRef(a, ctx)
1057 if sk == Z3_FINITE_DOMAIN_SORT:
1058 if k == Z3_NUMERAL_AST:
1062 if sk == Z3_ROUNDING_MODE_SORT:
1064 if sk == Z3_SEQ_SORT:
1066 if sk == Z3_RE_SORT:
1067 return ReRef(a, ctx)
1070 def _coerce_expr_merge(s, a):
1083 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1084 _z3_assert(
False,
"sort mismatch")
1088 def _coerce_exprs(a, b, ctx=None):
1090 a = _py2expr(a, ctx)
1091 b = _py2expr(b, ctx)
1093 s = _coerce_expr_merge(s, a)
1094 s = _coerce_expr_merge(s, b)
1100 def _reduce(f, l, a):
1106 def _coerce_expr_list(alist, ctx=None):
1113 alist = [ _py2expr(a, ctx)
for a
in alist ]
1114 s = _reduce(_coerce_expr_merge, alist,
None)
1115 return [ s.cast(a)
for a
in alist ]
1118 """Return `True` if `a` is a Z3 expression. 1125 >>> is_expr(IntSort()) 1129 >>> is_expr(IntVal(1)) 1132 >>> is_expr(ForAll(x, x >= 0)) 1134 >>> is_expr(FPVal(1.0)) 1137 return isinstance(a, ExprRef)
1140 """Return `True` if `a` is a Z3 function application. 1142 Note that, constants are function applications with 0 arguments. 1149 >>> is_app(IntSort()) 1153 >>> is_app(IntVal(1)) 1156 >>> is_app(ForAll(x, x >= 0)) 1159 if not isinstance(a, ExprRef):
1161 k = _ast_kind(a.ctx, a)
1162 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1165 """Return `True` if `a` is Z3 constant/variable expression. 1174 >>> is_const(IntVal(1)) 1177 >>> is_const(ForAll(x, x >= 0)) 1180 return is_app(a)
and a.num_args() == 0
1183 """Return `True` if `a` is variable. 1185 Z3 uses de-Bruijn indices for representing bound variables in 1193 >>> f = Function('f', IntSort(), IntSort()) 1194 >>> # Z3 replaces x with bound variables when ForAll is executed. 1195 >>> q = ForAll(x, f(x) == x) 1201 >>> is_var(b.arg(1)) 1204 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1207 """Return the de-Bruijn index of the Z3 bounded variable `a`. 1215 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 1216 >>> # Z3 replaces x and y with bound variables when ForAll is executed. 1217 >>> q = ForAll([x, y], f(x, y) == x + y) 1219 f(Var(1), Var(0)) == Var(1) + Var(0) 1223 >>> v1 = b.arg(0).arg(0) 1224 >>> v2 = b.arg(0).arg(1) 1229 >>> get_var_index(v1) 1231 >>> get_var_index(v2) 1235 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1239 """Return `True` if `a` is an application of the given kind `k`. 1243 >>> is_app_of(n, Z3_OP_ADD) 1245 >>> is_app_of(n, Z3_OP_MUL) 1248 return is_app(a)
and a.decl().kind() == k
1250 def If(a, b, c, ctx=None):
1251 """Create a Z3 if-then-else expression. 1255 >>> max = If(x > y, x, y) 1261 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1262 return Cond(a, b, c, ctx)
1264 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1267 b, c = _coerce_exprs(b, c, ctx)
1269 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1270 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1273 """Create a Z3 distinct expression. 1280 >>> Distinct(x, y, z) 1282 >>> simplify(Distinct(x, y, z)) 1284 >>> simplify(Distinct(x, y, z), blast_distinct=True) 1285 And(Not(x == y), Not(x == z), Not(y == z)) 1287 args = _get_args(args)
1288 ctx = _ctx_from_ast_arg_list(args)
1290 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1291 args = _coerce_expr_list(args, ctx)
1292 _args, sz = _to_ast_array(args)
1295 def _mk_bin(f, a, b):
1298 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1299 args[0] = a.as_ast()
1300 args[1] = b.as_ast()
1301 return f(a.ctx.ref(), 2, args)
1304 """Create a constant of the given sort. 1306 >>> Const('x', IntSort()) 1310 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1315 """Create several constants of the given sort. 1317 `names` is a string containing the names of all constants to be created. 1318 Blank spaces separate the names of different constants. 1320 >>> x, y, z = Consts('x y z', IntSort()) 1324 if isinstance(names, str):
1325 names = names.split(
" ")
1326 return [
Const(name, sort)
for name
in names]
1329 """Create a fresh constant of a specified sort""" 1330 ctx = _get_ctx(sort.ctx)
1334 """Create a Z3 free variable. Free variables are used to create quantified formulas. 1336 >>> Var(0, IntSort()) 1338 >>> eq(Var(0, IntSort()), Var(0, BoolSort())) 1342 _z3_assert(
is_sort(s),
"Z3 sort expected")
1343 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1347 Create a real free variable. Free variables are used to create quantified formulas. 1348 They are also used to create polynomials. 1357 Create a list of Real free variables. 1358 The variables have ids: 0, 1, ..., n-1 1360 >>> x0, x1, x2, x3 = RealVarVector(4) 1375 """Try to cast `val` as a Boolean. 1377 >>> x = BoolSort().cast(True) 1387 if isinstance(val, bool):
1391 _z3_assert(
is_expr(val),
"True, False or Z3 Boolean expression expected. Received %s" % val)
1392 if not self.
eq(val.sort()):
1393 _z3_assert(self.
eq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1397 return isinstance(other, ArithSortRef)
1407 """All Boolean expressions are instances of this class.""" 1415 """Create the Z3 expression `self * other`. 1421 return If(self, other, 0)
1425 """Return `True` if `a` is a Z3 Boolean expression. 1431 >>> is_bool(And(p, q)) 1439 return isinstance(a, BoolRef)
1442 """Return `True` if `a` is the Z3 true expression. 1447 >>> is_true(simplify(p == p)) 1452 >>> # True is a Python Boolean expression 1459 """Return `True` if `a` is the Z3 false expression. 1466 >>> is_false(BoolVal(False)) 1472 """Return `True` if `a` is a Z3 and expression. 1474 >>> p, q = Bools('p q') 1475 >>> is_and(And(p, q)) 1477 >>> is_and(Or(p, q)) 1483 """Return `True` if `a` is a Z3 or expression. 1485 >>> p, q = Bools('p q') 1488 >>> is_or(And(p, q)) 1494 """Return `True` if `a` is a Z3 implication expression. 1496 >>> p, q = Bools('p q') 1497 >>> is_implies(Implies(p, q)) 1499 >>> is_implies(And(p, q)) 1505 """Return `True` if `a` is a Z3 not expression. 1516 """Return `True` if `a` is a Z3 equality expression. 1518 >>> x, y = Ints('x y') 1525 """Return `True` if `a` is a Z3 distinct expression. 1527 >>> x, y, z = Ints('x y z') 1528 >>> is_distinct(x == y) 1530 >>> is_distinct(Distinct(x, y, z)) 1536 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used. 1540 >>> p = Const('p', BoolSort()) 1543 >>> r = Function('r', IntSort(), IntSort(), BoolSort()) 1546 >>> is_bool(r(0, 1)) 1553 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used. 1557 >>> is_true(BoolVal(True)) 1561 >>> is_false(BoolVal(False)) 1571 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used. 1582 """Return a tuple of Boolean constants. 1584 `names` is a single string containing all names separated by blank spaces. 1585 If `ctx=None`, then the global context is used. 1587 >>> p, q, r = Bools('p q r') 1588 >>> And(p, Or(q, r)) 1592 if isinstance(names, str):
1593 names = names.split(
" ")
1594 return [
Bool(name, ctx)
for name
in names]
1597 """Return a list of Boolean constants of size `sz`. 1599 The constants are named using the given prefix. 1600 If `ctx=None`, then the global context is used. 1602 >>> P = BoolVector('p', 3) 1606 And(p__0, p__1, p__2) 1608 return [
Bool(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
1611 """Return a fresh Boolean constant in the given context using the given prefix. 1613 If `ctx=None`, then the global context is used. 1615 >>> b1 = FreshBool() 1616 >>> b2 = FreshBool() 1624 """Create a Z3 implies expression. 1626 >>> p, q = Bools('p q') 1629 >>> simplify(Implies(p, q)) 1632 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1639 """Create a Z3 Xor expression. 1641 >>> p, q = Bools('p q') 1644 >>> simplify(Xor(p, q)) 1647 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1654 """Create a Z3 not expression or probe. 1659 >>> simplify(Not(Not(p))) 1662 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1677 def _has_probe(args):
1678 """Return `True` if one of the elements of the given collection is a Z3 probe.""" 1685 """Create a Z3 and-expression or and-probe. 1687 >>> p, q, r = Bools('p q r') 1690 >>> P = BoolVector('p', 5) 1692 And(p__0, p__1, p__2, p__3, p__4) 1696 last_arg = args[len(args)-1]
1697 if isinstance(last_arg, Context):
1698 ctx = args[len(args)-1]
1699 args = args[:len(args)-1]
1700 elif len(args) == 1
and isinstance(args[0], AstVector):
1702 args = [a
for a
in args[0]]
1705 args = _get_args(args)
1706 ctx_args = _ctx_from_ast_arg_list(args, ctx)
1708 _z3_assert(ctx_args
is None or ctx_args == ctx,
"context mismatch")
1709 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1710 if _has_probe(args):
1711 return _probe_and(args, ctx)
1713 args = _coerce_expr_list(args, ctx)
1714 _args, sz = _to_ast_array(args)
1718 """Create a Z3 or-expression or or-probe. 1720 >>> p, q, r = Bools('p q r') 1723 >>> P = BoolVector('p', 5) 1725 Or(p__0, p__1, p__2, p__3, p__4) 1729 last_arg = args[len(args)-1]
1730 if isinstance(last_arg, Context):
1731 ctx = args[len(args)-1]
1732 args = args[:len(args)-1]
1735 args = _get_args(args)
1736 ctx_args = _ctx_from_ast_arg_list(args, ctx)
1738 _z3_assert(ctx_args
is None or ctx_args == ctx,
"context mismatch")
1739 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1740 if _has_probe(args):
1741 return _probe_or(args, ctx)
1743 args = _coerce_expr_list(args, ctx)
1744 _args, sz = _to_ast_array(args)
1754 """Patterns are hints for quantifier instantiation. 1764 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation. 1766 >>> f = Function('f', IntSort(), IntSort()) 1768 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ]) 1770 ForAll(x, f(x) == 0) 1771 >>> q.num_patterns() 1773 >>> is_pattern(q.pattern(0)) 1778 return isinstance(a, PatternRef)
1781 """Create a Z3 multi-pattern using the given expressions `*args` 1783 >>> f = Function('f', IntSort(), IntSort()) 1784 >>> g = Function('g', IntSort(), IntSort()) 1786 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ]) 1788 ForAll(x, f(x) != g(x)) 1789 >>> q.num_patterns() 1791 >>> is_pattern(q.pattern(0)) 1794 MultiPattern(f(Var(0)), g(Var(0))) 1797 _z3_assert(len(args) > 0,
"At least one argument expected")
1798 _z3_assert(all([
is_expr(a)
for a
in args ]),
"Z3 expressions expected")
1800 args, sz = _to_ast_array(args)
1803 def _to_pattern(arg):
1816 """Universally and Existentially quantified formulas.""" 1825 """Return the Boolean sort or sort of Lambda.""" 1831 """Return `True` if `self` is a universal quantifier. 1833 >>> f = Function('f', IntSort(), IntSort()) 1835 >>> q = ForAll(x, f(x) == 0) 1838 >>> q = Exists(x, f(x) != 0) 1845 """Return `True` if `self` is an existential quantifier. 1847 >>> f = Function('f', IntSort(), IntSort()) 1849 >>> q = ForAll(x, f(x) == 0) 1852 >>> q = Exists(x, f(x) != 0) 1859 """Return `True` if `self` is a lambda expression. 1861 >>> f = Function('f', IntSort(), IntSort()) 1863 >>> q = Lambda(x, f(x)) 1866 >>> q = Exists(x, f(x) != 0) 1873 """Return the Z3 expression `self[arg]`. 1876 _z3_assert(self.
is_lambda(),
"quantifier should be a lambda expression")
1877 arg = self.
sort().domain().cast(arg)
1882 """Return the weight annotation of `self`. 1884 >>> f = Function('f', IntSort(), IntSort()) 1886 >>> q = ForAll(x, f(x) == 0) 1889 >>> q = ForAll(x, f(x) == 0, weight=10) 1896 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`. 1898 >>> f = Function('f', IntSort(), IntSort()) 1899 >>> g = Function('g', IntSort(), IntSort()) 1901 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ]) 1902 >>> q.num_patterns() 1908 """Return a pattern (i.e., quantifier instantiation hints) in `self`. 1910 >>> f = Function('f', IntSort(), IntSort()) 1911 >>> g = Function('g', IntSort(), IntSort()) 1913 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ]) 1914 >>> q.num_patterns() 1922 _z3_assert(idx < self.
num_patterns(),
"Invalid pattern idx")
1926 """Return the number of no-patterns.""" 1930 """Return a no-pattern.""" 1936 """Return the expression being quantified. 1938 >>> f = Function('f', IntSort(), IntSort()) 1940 >>> q = ForAll(x, f(x) == 0) 1947 """Return the number of variables bounded by this quantifier. 1949 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 1952 >>> q = ForAll([x, y], f(x, y) >= x) 1959 """Return a string representing a name used when displaying the quantifier. 1961 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 1964 >>> q = ForAll([x, y], f(x, y) >= x) 1971 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
1975 """Return the sort of a bound variable. 1977 >>> f = Function('f', IntSort(), RealSort(), IntSort()) 1980 >>> q = ForAll([x, y], f(x, y) >= x) 1987 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
1991 """Return a list containing a single element self.body() 1993 >>> f = Function('f', IntSort(), IntSort()) 1995 >>> q = ForAll(x, f(x) == 0) 1999 return [ self.
body() ]
2002 """Return `True` if `a` is a Z3 quantifier. 2004 >>> f = Function('f', IntSort(), IntSort()) 2006 >>> q = ForAll(x, f(x) == 0) 2007 >>> is_quantifier(q) 2009 >>> is_quantifier(f(x)) 2012 return isinstance(a, QuantifierRef)
2014 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2016 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
2017 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
2018 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
2019 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
2030 _vs = (Ast * num_vars)()
2031 for i
in range(num_vars):
2033 _vs[i] = vs[i].as_ast()
2034 patterns = [ _to_pattern(p)
for p
in patterns ]
2035 num_pats = len(patterns)
2036 _pats = (Pattern * num_pats)()
2037 for i
in range(num_pats):
2038 _pats[i] = patterns[i].ast
2039 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2045 num_no_pats, _no_pats,
2046 body.as_ast()), ctx)
2048 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2049 """Create a Z3 forall formula. 2051 The parameters `weight`, `qid`, `skid`, `patterns` and `no_patterns` are optional annotations. 2053 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 2056 >>> ForAll([x, y], f(x, y) >= x) 2057 ForAll([x, y], f(x, y) >= x) 2058 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ]) 2059 ForAll([x, y], f(x, y) >= x) 2060 >>> ForAll([x, y], f(x, y) >= x, weight=10) 2061 ForAll([x, y], f(x, y) >= x) 2063 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2065 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2066 """Create a Z3 exists formula. 2068 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations. 2071 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 2074 >>> q = Exists([x, y], f(x, y) >= x, skid="foo") 2076 Exists([x, y], f(x, y) >= x) 2077 >>> is_quantifier(q) 2079 >>> r = Tactic('nnf')(q).as_expr() 2080 >>> is_quantifier(r) 2083 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2086 """Create a Z3 lambda expression. 2088 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 2089 >>> mem0 = Array('mem0', IntSort(), IntSort()) 2090 >>> lo, hi, e, i = Ints('lo hi e i') 2091 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i])) 2093 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i])) 2099 _vs = (Ast * num_vars)()
2100 for i
in range(num_vars):
2102 _vs[i] = vs[i].as_ast()
2112 """Real and Integer sorts.""" 2115 """Return `True` if `self` is of the sort Real. 2120 >>> (x + 1).is_real() 2126 return self.
kind() == Z3_REAL_SORT
2129 """Return `True` if `self` is of the sort Integer. 2134 >>> (x + 1).is_int() 2140 return self.
kind() == Z3_INT_SORT
2143 """Return `True` if `self` is a subsort of `other`.""" 2147 """Try to cast `val` as an Integer or Real. 2149 >>> IntSort().cast(10) 2151 >>> is_int(IntSort().cast(10)) 2155 >>> RealSort().cast(10) 2157 >>> is_real(RealSort().cast(10)) 2162 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
2166 if val_s.is_int()
and self.
is_real():
2168 if val_s.is_bool()
and self.
is_int():
2169 return If(val, 1, 0)
2170 if val_s.is_bool()
and self.
is_real():
2173 _z3_assert(
False,
"Z3 Integer/Real expression expected" )
2180 _z3_assert(
False,
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s" % self)
2183 """Return `True` if s is an arithmetical sort (type). 2185 >>> is_arith_sort(IntSort()) 2187 >>> is_arith_sort(RealSort()) 2189 >>> is_arith_sort(BoolSort()) 2191 >>> n = Int('x') + 1 2192 >>> is_arith_sort(n.sort()) 2195 return isinstance(s, ArithSortRef)
2198 """Integer and Real expressions.""" 2201 """Return the sort (type) of the arithmetical expression `self`. 2205 >>> (Real('x') + 1).sort() 2211 """Return `True` if `self` is an integer expression. 2216 >>> (x + 1).is_int() 2219 >>> (x + y).is_int() 2225 """Return `True` if `self` is an real expression. 2230 >>> (x + 1).is_real() 2236 """Create the Z3 expression `self + other`. 2245 a, b = _coerce_exprs(self, other)
2246 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctx)
2249 """Create the Z3 expression `other + self`. 2255 a, b = _coerce_exprs(self, other)
2256 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctx)
2259 """Create the Z3 expression `self * other`. 2268 if isinstance(other, BoolRef):
2269 return If(other, self, 0)
2270 a, b = _coerce_exprs(self, other)
2271 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctx)
2274 """Create the Z3 expression `other * self`. 2280 a, b = _coerce_exprs(self, other)
2281 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctx)
2284 """Create the Z3 expression `self - other`. 2293 a, b = _coerce_exprs(self, other)
2294 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctx)
2297 """Create the Z3 expression `other - self`. 2303 a, b = _coerce_exprs(self, other)
2304 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctx)
2307 """Create the Z3 expression `self**other` (** is the power operator). 2314 >>> simplify(IntVal(2)**8) 2317 a, b = _coerce_exprs(self, other)
2321 """Create the Z3 expression `other**self` (** is the power operator). 2328 >>> simplify(2**IntVal(8)) 2331 a, b = _coerce_exprs(self, other)
2335 """Create the Z3 expression `other/self`. 2354 a, b = _coerce_exprs(self, other)
2358 """Create the Z3 expression `other/self`.""" 2362 """Create the Z3 expression `other/self`. 2375 a, b = _coerce_exprs(self, other)
2379 """Create the Z3 expression `other/self`.""" 2383 """Create the Z3 expression `other%self`. 2389 >>> simplify(IntVal(10) % IntVal(3)) 2392 a, b = _coerce_exprs(self, other)
2394 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2398 """Create the Z3 expression `other%self`. 2404 a, b = _coerce_exprs(self, other)
2406 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2410 """Return an expression representing `-self`. 2430 """Create the Z3 expression `other <= self`. 2432 >>> x, y = Ints('x y') 2439 a, b = _coerce_exprs(self, other)
2443 """Create the Z3 expression `other < self`. 2445 >>> x, y = Ints('x y') 2452 a, b = _coerce_exprs(self, other)
2456 """Create the Z3 expression `other > self`. 2458 >>> x, y = Ints('x y') 2465 a, b = _coerce_exprs(self, other)
2469 """Create the Z3 expression `other >= self`. 2471 >>> x, y = Ints('x y') 2478 a, b = _coerce_exprs(self, other)
2482 """Return `True` if `a` is an arithmetical expression. 2491 >>> is_arith(IntVal(1)) 2499 return isinstance(a, ArithRef)
2502 """Return `True` if `a` is an integer expression. 2509 >>> is_int(IntVal(1)) 2520 """Return `True` if `a` is a real expression. 2532 >>> is_real(RealVal(1)) 2537 def _is_numeral(ctx, a):
2540 def _is_algebraic(ctx, a):
2544 """Return `True` if `a` is an integer value of sort Int. 2546 >>> is_int_value(IntVal(1)) 2550 >>> is_int_value(Int('x')) 2552 >>> n = Int('x') + 1 2557 >>> is_int_value(n.arg(1)) 2559 >>> is_int_value(RealVal("1/3")) 2561 >>> is_int_value(RealVal(1)) 2564 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2567 """Return `True` if `a` is rational value of sort Real. 2569 >>> is_rational_value(RealVal(1)) 2571 >>> is_rational_value(RealVal("3/5")) 2573 >>> is_rational_value(IntVal(1)) 2575 >>> is_rational_value(1) 2577 >>> n = Real('x') + 1 2580 >>> is_rational_value(n.arg(1)) 2582 >>> is_rational_value(Real('x')) 2585 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2588 """Return `True` if `a` is an algebraic value of sort Real. 2590 >>> is_algebraic_value(RealVal("3/5")) 2592 >>> n = simplify(Sqrt(2)) 2595 >>> is_algebraic_value(n) 2598 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2601 """Return `True` if `a` is an expression of the form b + c. 2603 >>> x, y = Ints('x y') 2612 """Return `True` if `a` is an expression of the form b * c. 2614 >>> x, y = Ints('x y') 2623 """Return `True` if `a` is an expression of the form b - c. 2625 >>> x, y = Ints('x y') 2634 """Return `True` if `a` is an expression of the form b / c. 2636 >>> x, y = Reals('x y') 2641 >>> x, y = Ints('x y') 2650 """Return `True` if `a` is an expression of the form b div c. 2652 >>> x, y = Ints('x y') 2661 """Return `True` if `a` is an expression of the form b % c. 2663 >>> x, y = Ints('x y') 2672 """Return `True` if `a` is an expression of the form b <= c. 2674 >>> x, y = Ints('x y') 2683 """Return `True` if `a` is an expression of the form b < c. 2685 >>> x, y = Ints('x y') 2694 """Return `True` if `a` is an expression of the form b >= c. 2696 >>> x, y = Ints('x y') 2705 """Return `True` if `a` is an expression of the form b > c. 2707 >>> x, y = Ints('x y') 2716 """Return `True` if `a` is an expression of the form IsInt(b). 2719 >>> is_is_int(IsInt(x)) 2727 """Return `True` if `a` is an expression of the form ToReal(b). 2741 """Return `True` if `a` is an expression of the form ToInt(b). 2755 """Integer values.""" 2758 """Return a Z3 integer numeral as a Python long (bignum) numeral. 2767 _z3_assert(self.
is_int(),
"Integer value expected")
2771 """Return a Z3 integer numeral as a Python string. 2779 """Rational values.""" 2782 """ Return the numerator of a Z3 rational numeral. 2784 >>> is_rational_value(RealVal("3/5")) 2786 >>> n = RealVal("3/5") 2789 >>> is_rational_value(Q(3,5)) 2791 >>> Q(3,5).numerator() 2797 """ Return the denominator of a Z3 rational numeral. 2799 >>> is_rational_value(Q(3,5)) 2808 """ Return the numerator as a Python long. 2810 >>> v = RealVal(10000000000) 2815 >>> v.numerator_as_long() + 1 == 10000000001 2821 """ Return the denominator as a Python long. 2823 >>> v = RealVal("1/3") 2826 >>> v.denominator_as_long() 2841 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
2845 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places. 2847 >>> v = RealVal("1/5") 2850 >>> v = RealVal("1/3") 2857 """Return a Z3 rational numeral as a Python string. 2866 """Return a Z3 rational as a Python Fraction object. 2868 >>> v = RealVal("1/5") 2875 """Algebraic irrational values.""" 2878 """Return a Z3 rational number that approximates the algebraic number `self`. 2879 The result `r` is such that |r - self| <= 1/10^precision 2881 >>> x = simplify(Sqrt(2)) 2883 6838717160008073720548335/4835703278458516698824704 2889 """Return a string representation of the algebraic number `self` in decimal notation using `prec` decimal places 2891 >>> x = simplify(Sqrt(2)) 2892 >>> x.as_decimal(10) 2894 >>> x.as_decimal(20) 2895 '1.41421356237309504880?' 2899 def _py2expr(a, ctx=None):
2900 if isinstance(a, bool):
2904 if isinstance(a, float):
2909 _z3_assert(
False,
"Python bool, int, long or float expected")
2912 """Return the integer sort in the given context. If `ctx=None`, then the global context is used. 2916 >>> x = Const('x', IntSort()) 2919 >>> x.sort() == IntSort() 2921 >>> x.sort() == BoolSort() 2928 """Return the real sort in the given context. If `ctx=None`, then the global context is used. 2932 >>> x = Const('x', RealSort()) 2937 >>> x.sort() == RealSort() 2943 def _to_int_str(val):
2944 if isinstance(val, float):
2945 return str(int(val))
2946 elif isinstance(val, bool):
2953 elif isinstance(val, str):
2956 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
2959 """Return a Z3 integer value. If `ctx=None`, then the global context is used. 2970 """Return a Z3 real value. 2972 `val` may be a Python int, long, float or string representing a number in decimal or rational notation. 2973 If `ctx=None`, then the global context is used. 2977 >>> RealVal(1).sort() 2988 """Return a Z3 rational a/b. 2990 If `ctx=None`, then the global context is used. 2994 >>> RatVal(3,5).sort() 2998 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
2999 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
3002 def Q(a, b, ctx=None):
3003 """Return a Z3 rational a/b. 3005 If `ctx=None`, then the global context is used. 3015 """Return an integer constant named `name`. If `ctx=None`, then the global context is used. 3027 """Return a tuple of Integer constants. 3029 >>> x, y, z = Ints('x y z') 3034 if isinstance(names, str):
3035 names = names.split(
" ")
3036 return [
Int(name, ctx)
for name
in names]
3039 """Return a list of integer constants of size `sz`. 3041 >>> X = IntVector('x', 3) 3047 return [
Int(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
3050 """Return a fresh integer constant in the given context using the given prefix. 3063 """Return a real constant named `name`. If `ctx=None`, then the global context is used. 3075 """Return a tuple of real constants. 3077 >>> x, y, z = Reals('x y z') 3080 >>> Sum(x, y, z).sort() 3084 if isinstance(names, str):
3085 names = names.split(
" ")
3086 return [
Real(name, ctx)
for name
in names]
3089 """Return a list of real constants of size `sz`. 3091 >>> X = RealVector('x', 3) 3099 return [
Real(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
3102 """Return a fresh real constant in the given context using the given prefix. 3115 """ Return the Z3 expression ToReal(a). 3127 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3132 """ Return the Z3 expression ToInt(a). 3144 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3149 """ Return the Z3 predicate IsInt(a). 3152 >>> IsInt(x + "1/2") 3154 >>> solve(IsInt(x + "1/2"), x > 0, x < 1) 3156 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2") 3160 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3165 """ Return a Z3 expression which represents the square root of a. 3177 """ Return a Z3 expression which represents the cubic root of a. 3195 """Bit-vector sort.""" 3198 """Return the size (number of bits) of the bit-vector sort `self`. 3200 >>> b = BitVecSort(32) 3210 """Try to cast `val` as a Bit-Vector. 3212 >>> b = BitVecSort(32) 3215 >>> b.cast(10).sexpr() 3220 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
3227 """Return True if `s` is a Z3 bit-vector sort. 3229 >>> is_bv_sort(BitVecSort(32)) 3231 >>> is_bv_sort(IntSort()) 3234 return isinstance(s, BitVecSortRef)
3237 """Bit-vector expressions.""" 3240 """Return the sort of the bit-vector expression `self`. 3242 >>> x = BitVec('x', 32) 3245 >>> x.sort() == BitVecSort(32) 3251 """Return the number of bits of the bit-vector expression `self`. 3253 >>> x = BitVec('x', 32) 3256 >>> Concat(x, x).size() 3262 """Create the Z3 expression `self + other`. 3264 >>> x = BitVec('x', 32) 3265 >>> y = BitVec('y', 32) 3271 a, b = _coerce_exprs(self, other)
3275 """Create the Z3 expression `other + self`. 3277 >>> x = BitVec('x', 32) 3281 a, b = _coerce_exprs(self, other)
3285 """Create the Z3 expression `self * other`. 3287 >>> x = BitVec('x', 32) 3288 >>> y = BitVec('y', 32) 3294 a, b = _coerce_exprs(self, other)
3298 """Create the Z3 expression `other * self`. 3300 >>> x = BitVec('x', 32) 3304 a, b = _coerce_exprs(self, other)
3308 """Create the Z3 expression `self - other`. 3310 >>> x = BitVec('x', 32) 3311 >>> y = BitVec('y', 32) 3317 a, b = _coerce_exprs(self, other)
3321 """Create the Z3 expression `other - self`. 3323 >>> x = BitVec('x', 32) 3327 a, b = _coerce_exprs(self, other)
3331 """Create the Z3 expression bitwise-or `self | other`. 3333 >>> x = BitVec('x', 32) 3334 >>> y = BitVec('y', 32) 3340 a, b = _coerce_exprs(self, other)
3344 """Create the Z3 expression bitwise-or `other | self`. 3346 >>> x = BitVec('x', 32) 3350 a, b = _coerce_exprs(self, other)
3354 """Create the Z3 expression bitwise-and `self & other`. 3356 >>> x = BitVec('x', 32) 3357 >>> y = BitVec('y', 32) 3363 a, b = _coerce_exprs(self, other)
3367 """Create the Z3 expression bitwise-or `other & self`. 3369 >>> x = BitVec('x', 32) 3373 a, b = _coerce_exprs(self, other)
3377 """Create the Z3 expression bitwise-xor `self ^ other`. 3379 >>> x = BitVec('x', 32) 3380 >>> y = BitVec('y', 32) 3386 a, b = _coerce_exprs(self, other)
3390 """Create the Z3 expression bitwise-xor `other ^ self`. 3392 >>> x = BitVec('x', 32) 3396 a, b = _coerce_exprs(self, other)
3402 >>> x = BitVec('x', 32) 3409 """Return an expression representing `-self`. 3411 >>> x = BitVec('x', 32) 3420 """Create the Z3 expression bitwise-not `~self`. 3422 >>> x = BitVec('x', 32) 3431 """Create the Z3 expression (signed) division `self / other`. 3433 Use the function UDiv() for unsigned division. 3435 >>> x = BitVec('x', 32) 3436 >>> y = BitVec('y', 32) 3443 >>> UDiv(x, y).sexpr() 3446 a, b = _coerce_exprs(self, other)
3450 """Create the Z3 expression (signed) division `self / other`.""" 3454 """Create the Z3 expression (signed) division `other / self`. 3456 Use the function UDiv() for unsigned division. 3458 >>> x = BitVec('x', 32) 3461 >>> (10 / x).sexpr() 3462 '(bvsdiv #x0000000a x)' 3463 >>> UDiv(10, x).sexpr() 3464 '(bvudiv #x0000000a x)' 3466 a, b = _coerce_exprs(self, other)
3470 """Create the Z3 expression (signed) division `other / self`.""" 3474 """Create the Z3 expression (signed) mod `self % other`. 3476 Use the function URem() for unsigned remainder, and SRem() for signed remainder. 3478 >>> x = BitVec('x', 32) 3479 >>> y = BitVec('y', 32) 3486 >>> URem(x, y).sexpr() 3488 >>> SRem(x, y).sexpr() 3491 a, b = _coerce_exprs(self, other)
3495 """Create the Z3 expression (signed) mod `other % self`. 3497 Use the function URem() for unsigned remainder, and SRem() for signed remainder. 3499 >>> x = BitVec('x', 32) 3502 >>> (10 % x).sexpr() 3503 '(bvsmod #x0000000a x)' 3504 >>> URem(10, x).sexpr() 3505 '(bvurem #x0000000a x)' 3506 >>> SRem(10, x).sexpr() 3507 '(bvsrem #x0000000a x)' 3509 a, b = _coerce_exprs(self, other)
3513 """Create the Z3 expression (signed) `other <= self`. 3515 Use the function ULE() for unsigned less than or equal to. 3517 >>> x, y = BitVecs('x y', 32) 3520 >>> (x <= y).sexpr() 3522 >>> ULE(x, y).sexpr() 3525 a, b = _coerce_exprs(self, other)
3529 """Create the Z3 expression (signed) `other < self`. 3531 Use the function ULT() for unsigned less than. 3533 >>> x, y = BitVecs('x y', 32) 3538 >>> ULT(x, y).sexpr() 3541 a, b = _coerce_exprs(self, other)
3545 """Create the Z3 expression (signed) `other > self`. 3547 Use the function UGT() for unsigned greater than. 3549 >>> x, y = BitVecs('x y', 32) 3554 >>> UGT(x, y).sexpr() 3557 a, b = _coerce_exprs(self, other)
3561 """Create the Z3 expression (signed) `other >= self`. 3563 Use the function UGE() for unsigned greater than or equal to. 3565 >>> x, y = BitVecs('x y', 32) 3568 >>> (x >= y).sexpr() 3570 >>> UGE(x, y).sexpr() 3573 a, b = _coerce_exprs(self, other)
3577 """Create the Z3 expression (arithmetical) right shift `self >> other` 3579 Use the function LShR() for the right logical shift 3581 >>> x, y = BitVecs('x y', 32) 3584 >>> (x >> y).sexpr() 3586 >>> LShR(x, y).sexpr() 3590 >>> BitVecVal(4, 3).as_signed_long() 3592 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long() 3594 >>> simplify(BitVecVal(4, 3) >> 1) 3596 >>> simplify(LShR(BitVecVal(4, 3), 1)) 3598 >>> simplify(BitVecVal(2, 3) >> 1) 3600 >>> simplify(LShR(BitVecVal(2, 3), 1)) 3603 a, b = _coerce_exprs(self, other)
3607 """Create the Z3 expression left shift `self << other` 3609 >>> x, y = BitVecs('x y', 32) 3612 >>> (x << y).sexpr() 3614 >>> simplify(BitVecVal(2, 3) << 1) 3617 a, b = _coerce_exprs(self, other)
3621 """Create the Z3 expression (arithmetical) right shift `other` >> `self`. 3623 Use the function LShR() for the right logical shift 3625 >>> x = BitVec('x', 32) 3628 >>> (10 >> x).sexpr() 3629 '(bvashr #x0000000a x)' 3631 a, b = _coerce_exprs(self, other)
3635 """Create the Z3 expression left shift `other << self`. 3637 Use the function LShR() for the right logical shift 3639 >>> x = BitVec('x', 32) 3642 >>> (10 << x).sexpr() 3643 '(bvshl #x0000000a x)' 3645 a, b = _coerce_exprs(self, other)
3649 """Bit-vector values.""" 3652 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. 3654 >>> v = BitVecVal(0xbadc0de, 32) 3657 >>> print("0x%.8x" % v.as_long()) 3663 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign. 3665 >>> BitVecVal(4, 3).as_signed_long() 3667 >>> BitVecVal(7, 3).as_signed_long() 3669 >>> BitVecVal(3, 3).as_signed_long() 3671 >>> BitVecVal(2**32 - 1, 32).as_signed_long() 3673 >>> BitVecVal(2**64 - 1, 64).as_signed_long() 3678 if val >= 2**(sz - 1):
3680 if val < -2**(sz - 1):
3688 """Return `True` if `a` is a Z3 bit-vector expression. 3690 >>> b = BitVec('b', 32) 3698 return isinstance(a, BitVecRef)
3701 """Return `True` if `a` is a Z3 bit-vector numeral value. 3703 >>> b = BitVec('b', 32) 3706 >>> b = BitVecVal(10, 32) 3712 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3715 """Return the Z3 expression BV2Int(a). 3717 >>> b = BitVec('b', 3) 3718 >>> BV2Int(b).sort() 3723 >>> x > BV2Int(b, is_signed=False) 3725 >>> x > BV2Int(b, is_signed=True) 3726 x > If(b < 0, BV2Int(b) - 8, BV2Int(b)) 3727 >>> solve(x > BV2Int(b), b == 1, x < 3) 3731 _z3_assert(
is_bv(a),
"Z3 bit-vector expression expected")
3737 """Return the z3 expression Int2BV(a, num_bits). 3738 It is a bit-vector of width num_bits and represents the 3739 modulo of a by 2^num_bits 3745 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used. 3747 >>> Byte = BitVecSort(8) 3748 >>> Word = BitVecSort(16) 3751 >>> x = Const('x', Byte) 3752 >>> eq(x, BitVec('x', 8)) 3759 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used. 3761 >>> v = BitVecVal(10, 32) 3764 >>> print("0x%.8x" % v.as_long()) 3775 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort. 3776 If `ctx=None`, then the global context is used. 3778 >>> x = BitVec('x', 16) 3785 >>> word = BitVecSort(16) 3786 >>> x2 = BitVec('x', word) 3790 if isinstance(bv, BitVecSortRef):
3798 """Return a tuple of bit-vector constants of size bv. 3800 >>> x, y, z = BitVecs('x y z', 16) 3807 >>> Product(x, y, z) 3809 >>> simplify(Product(x, y, z)) 3813 if isinstance(names, str):
3814 names = names.split(
" ")
3815 return [
BitVec(name, bv, ctx)
for name
in names]
3818 """Create a Z3 bit-vector concatenation expression. 3820 >>> v = BitVecVal(1, 4) 3821 >>> Concat(v, v+1, v) 3822 Concat(Concat(1, 1 + 1), 1) 3823 >>> simplify(Concat(v, v+1, v)) 3825 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long()) 3828 args = _get_args(args)
3831 _z3_assert(sz >= 2,
"At least two arguments expected.")
3838 if is_seq(args[0])
or isinstance(args[0], str):
3839 args = [_coerce_seq(s, ctx)
for s
in args]
3841 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
3844 v[i] = args[i].as_ast()
3849 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
3852 v[i] = args[i].as_ast()
3856 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
3858 for i
in range(sz - 1):
3863 """Create a Z3 bit-vector extraction expression, or create a string extraction expression. 3865 >>> x = BitVec('x', 8) 3866 >>> Extract(6, 2, x) 3868 >>> Extract(6, 2, x).sort() 3870 >>> simplify(Extract(StringVal("abcd"),2,1)) 3873 if isinstance(high, str):
3877 offset, length = _coerce_exprs(low, a, s.ctx)
3880 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
3881 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
"First and second arguments must be non negative integers")
3882 _z3_assert(
is_bv(a),
"Third argument must be a Z3 Bitvector expression")
3885 def _check_bv_args(a, b):
3887 _z3_assert(
is_bv(a)
or is_bv(b),
"At least one of the arguments must be a Z3 bit-vector expression")
3890 """Create the Z3 expression (unsigned) `other <= self`. 3892 Use the operator <= for signed less than or equal to. 3894 >>> x, y = BitVecs('x y', 32) 3897 >>> (x <= y).sexpr() 3899 >>> ULE(x, y).sexpr() 3902 _check_bv_args(a, b)
3903 a, b = _coerce_exprs(a, b)
3907 """Create the Z3 expression (unsigned) `other < self`. 3909 Use the operator < for signed less than. 3911 >>> x, y = BitVecs('x y', 32) 3916 >>> ULT(x, y).sexpr() 3919 _check_bv_args(a, b)
3920 a, b = _coerce_exprs(a, b)
3924 """Create the Z3 expression (unsigned) `other >= self`. 3926 Use the operator >= for signed greater than or equal to. 3928 >>> x, y = BitVecs('x y', 32) 3931 >>> (x >= y).sexpr() 3933 >>> UGE(x, y).sexpr() 3936 _check_bv_args(a, b)
3937 a, b = _coerce_exprs(a, b)
3941 """Create the Z3 expression (unsigned) `other > self`. 3943 Use the operator > for signed greater than. 3945 >>> x, y = BitVecs('x y', 32) 3950 >>> UGT(x, y).sexpr() 3953 _check_bv_args(a, b)
3954 a, b = _coerce_exprs(a, b)
3958 """Create the Z3 expression (unsigned) division `self / other`. 3960 Use the operator / for signed division. 3962 >>> x = BitVec('x', 32) 3963 >>> y = BitVec('y', 32) 3966 >>> UDiv(x, y).sort() 3970 >>> UDiv(x, y).sexpr() 3973 _check_bv_args(a, b)
3974 a, b = _coerce_exprs(a, b)
3978 """Create the Z3 expression (unsigned) remainder `self % other`. 3980 Use the operator % for signed modulus, and SRem() for signed remainder. 3982 >>> x = BitVec('x', 32) 3983 >>> y = BitVec('y', 32) 3986 >>> URem(x, y).sort() 3990 >>> URem(x, y).sexpr() 3993 _check_bv_args(a, b)
3994 a, b = _coerce_exprs(a, b)
3998 """Create the Z3 expression signed remainder. 4000 Use the operator % for signed modulus, and URem() for unsigned remainder. 4002 >>> x = BitVec('x', 32) 4003 >>> y = BitVec('y', 32) 4006 >>> SRem(x, y).sort() 4010 >>> SRem(x, y).sexpr() 4013 _check_bv_args(a, b)
4014 a, b = _coerce_exprs(a, b)
4018 """Create the Z3 expression logical right shift. 4020 Use the operator >> for the arithmetical right shift. 4022 >>> x, y = BitVecs('x y', 32) 4025 >>> (x >> y).sexpr() 4027 >>> LShR(x, y).sexpr() 4031 >>> BitVecVal(4, 3).as_signed_long() 4033 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long() 4035 >>> simplify(BitVecVal(4, 3) >> 1) 4037 >>> simplify(LShR(BitVecVal(4, 3), 1)) 4039 >>> simplify(BitVecVal(2, 3) >> 1) 4041 >>> simplify(LShR(BitVecVal(2, 3), 1)) 4044 _check_bv_args(a, b)
4045 a, b = _coerce_exprs(a, b)
4049 """Return an expression representing `a` rotated to the left `b` times. 4051 >>> a, b = BitVecs('a b', 16) 4052 >>> RotateLeft(a, b) 4054 >>> simplify(RotateLeft(a, 0)) 4056 >>> simplify(RotateLeft(a, 16)) 4059 _check_bv_args(a, b)
4060 a, b = _coerce_exprs(a, b)
4064 """Return an expression representing `a` rotated to the right `b` times. 4066 >>> a, b = BitVecs('a b', 16) 4067 >>> RotateRight(a, b) 4069 >>> simplify(RotateRight(a, 0)) 4071 >>> simplify(RotateRight(a, 16)) 4074 _check_bv_args(a, b)
4075 a, b = _coerce_exprs(a, b)
4079 """Return a bit-vector expression with `n` extra sign-bits. 4081 >>> x = BitVec('x', 16) 4082 >>> n = SignExt(8, x) 4089 >>> v0 = BitVecVal(2, 2) 4094 >>> v = simplify(SignExt(6, v0)) 4099 >>> print("%.x" % v.as_long()) 4103 _z3_assert(_is_int(n),
"First argument must be an integer")
4104 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4108 """Return a bit-vector expression with `n` extra zero-bits. 4110 >>> x = BitVec('x', 16) 4111 >>> n = ZeroExt(8, x) 4118 >>> v0 = BitVecVal(2, 2) 4123 >>> v = simplify(ZeroExt(6, v0)) 4130 _z3_assert(_is_int(n),
"First argument must be an integer")
4131 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4135 """Return an expression representing `n` copies of `a`. 4137 >>> x = BitVec('x', 8) 4138 >>> n = RepeatBitVec(4, x) 4143 >>> v0 = BitVecVal(10, 4) 4144 >>> print("%.x" % v0.as_long()) 4146 >>> v = simplify(RepeatBitVec(4, v0)) 4149 >>> print("%.x" % v.as_long()) 4153 _z3_assert(_is_int(n),
"First argument must be an integer")
4154 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4158 """Return the reduction-and expression of `a`.""" 4160 _z3_assert(
is_bv(a),
"First argument must be a Z3 Bitvector expression")
4164 """Return the reduction-or expression of `a`.""" 4166 _z3_assert(
is_bv(a),
"First argument must be a Z3 Bitvector expression")
4170 """A predicate the determines that bit-vector addition does not overflow""" 4171 _check_bv_args(a, b)
4172 a, b = _coerce_exprs(a, b)
4176 """A predicate the determines that signed bit-vector addition does not underflow""" 4177 _check_bv_args(a, b)
4178 a, b = _coerce_exprs(a, b)
4182 """A predicate the determines that bit-vector subtraction does not overflow""" 4183 _check_bv_args(a, b)
4184 a, b = _coerce_exprs(a, b)
4189 """A predicate the determines that bit-vector subtraction does not underflow""" 4190 _check_bv_args(a, b)
4191 a, b = _coerce_exprs(a, b)
4195 """A predicate the determines that bit-vector signed division does not overflow""" 4196 _check_bv_args(a, b)
4197 a, b = _coerce_exprs(a, b)
4201 """A predicate the determines that bit-vector unary negation does not overflow""" 4203 _z3_assert(
is_bv(a),
"Argument should be a bit-vector")
4207 """A predicate the determines that bit-vector multiplication does not overflow""" 4208 _check_bv_args(a, b)
4209 a, b = _coerce_exprs(a, b)
4214 """A predicate the determines that bit-vector signed multiplication does not underflow""" 4215 _check_bv_args(a, b)
4216 a, b = _coerce_exprs(a, b)
4231 """Return the domain of the array sort `self`. 4233 >>> A = ArraySort(IntSort(), BoolSort()) 4240 """Return the range of the array sort `self`. 4242 >>> A = ArraySort(IntSort(), BoolSort()) 4249 """Array expressions. """ 4252 """Return the array sort of the array expression `self`. 4254 >>> a = Array('a', IntSort(), BoolSort()) 4261 """Shorthand for `self.sort().domain()`. 4263 >>> a = Array('a', IntSort(), BoolSort()) 4270 """Shorthand for `self.sort().range()`. 4272 >>> a = Array('a', IntSort(), BoolSort()) 4279 """Return the Z3 expression `self[arg]`. 4281 >>> a = Array('a', IntSort(), BoolSort()) 4288 arg = self.
domain().cast(arg)
4299 """Return `True` if `a` is a Z3 array expression. 4301 >>> a = Array('a', IntSort(), IntSort()) 4304 >>> is_array(Store(a, 0, 1)) 4309 return isinstance(a, ArrayRef)
4312 """Return `True` if `a` is a Z3 constant array. 4314 >>> a = K(IntSort(), 10) 4315 >>> is_const_array(a) 4317 >>> a = Array('a', IntSort(), IntSort()) 4318 >>> is_const_array(a) 4324 """Return `True` if `a` is a Z3 constant array. 4326 >>> a = K(IntSort(), 10) 4329 >>> a = Array('a', IntSort(), IntSort()) 4336 """Return `True` if `a` is a Z3 map array expression. 4338 >>> f = Function('f', IntSort(), IntSort()) 4339 >>> b = Array('b', IntSort(), IntSort()) 4351 """Return `True` if `a` is a Z3 default array expression. 4352 >>> d = Default(K(IntSort(), 10)) 4356 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4359 """Return the function declaration associated with a Z3 map array expression. 4361 >>> f = Function('f', IntSort(), IntSort()) 4362 >>> b = Array('b', IntSort(), IntSort()) 4364 >>> eq(f, get_map_func(a)) 4368 >>> get_map_func(a)(0) 4372 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4376 """Return the Z3 array sort with the given domain and range sorts. 4378 >>> A = ArraySort(IntSort(), BoolSort()) 4385 >>> AA = ArraySort(IntSort(), A) 4387 Array(Int, Array(Int, Bool)) 4389 sig = _get_args(sig)
4391 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4392 arity = len(sig) - 1
4397 _z3_assert(
is_sort(s),
"Z3 sort expected")
4398 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4402 dom = (Sort * arity)()
4403 for i
in range(arity):
4408 """Return an array constant named `name` with the given domain and range sorts. 4410 >>> a = Array('a', IntSort(), IntSort()) 4421 """Return a Z3 store array expression. 4423 >>> a = Array('a', IntSort(), IntSort()) 4424 >>> i, v = Ints('i v') 4425 >>> s = Update(a, i, v) 4428 >>> prove(s[i] == v) 4431 >>> prove(Implies(i != j, s[j] == a[j])) 4435 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4436 i = a.domain().cast(i)
4437 v = a.range().cast(v)
4439 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4442 """ Return a default value for array expression. 4443 >>> b = K(IntSort(), 1) 4444 >>> prove(Default(b) == 1) 4448 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4453 """Return a Z3 store array expression. 4455 >>> a = Array('a', IntSort(), IntSort()) 4456 >>> i, v = Ints('i v') 4457 >>> s = Store(a, i, v) 4460 >>> prove(s[i] == v) 4463 >>> prove(Implies(i != j, s[j] == a[j])) 4469 """Return a Z3 select array expression. 4471 >>> a = Array('a', IntSort(), IntSort()) 4475 >>> eq(Select(a, i), a[i]) 4479 _z3_assert(
is_array_sort(a),
"First argument must be a Z3 array expression")
4484 """Return a Z3 map array expression. 4486 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 4487 >>> a1 = Array('a1', IntSort(), IntSort()) 4488 >>> a2 = Array('a2', IntSort(), IntSort()) 4489 >>> b = Map(f, a1, a2) 4492 >>> prove(b[0] == f(a1[0], a2[0])) 4495 args = _get_args(args)
4497 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4498 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4499 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4500 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4501 _args, sz = _to_ast_array(args)
4506 """Return a Z3 constant array expression. 4508 >>> a = K(IntSort(), 10) 4520 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4523 v = _py2expr(v, ctx)
4527 """Return extensionality index for one-dimensional arrays. 4528 >> a, b = Consts('a b', SetSort(IntSort())) 4535 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
4539 k = _py2expr(k, ctx)
4543 """Return `True` if `a` is a Z3 array select application. 4545 >>> a = Array('a', IntSort(), IntSort()) 4555 """Return `True` if `a` is a Z3 array store application. 4557 >>> a = Array('a', IntSort(), IntSort()) 4560 >>> is_store(Store(a, 0, 1)) 4573 """ Create a set sort over element sort s""" 4577 """Create the empty set 4578 >>> EmptySet(IntSort()) 4585 """Create the full set 4586 >>> FullSet(IntSort()) 4593 """ Take the union of sets 4594 >>> a = Const('a', SetSort(IntSort())) 4595 >>> b = Const('b', SetSort(IntSort())) 4599 args = _get_args(args)
4600 ctx = _ctx_from_ast_arg_list(args)
4601 _args, sz = _to_ast_array(args)
4605 """ Take the union of sets 4606 >>> a = Const('a', SetSort(IntSort())) 4607 >>> b = Const('b', SetSort(IntSort())) 4608 >>> SetIntersect(a, b) 4611 args = _get_args(args)
4612 ctx = _ctx_from_ast_arg_list(args)
4613 _args, sz = _to_ast_array(args)
4617 """ Add element e to set s 4618 >>> a = Const('a', SetSort(IntSort())) 4622 ctx = _ctx_from_ast_arg_list([s,e])
4623 e = _py2expr(e, ctx)
4627 """ Remove element e to set s 4628 >>> a = Const('a', SetSort(IntSort())) 4632 ctx = _ctx_from_ast_arg_list([s,e])
4633 e = _py2expr(e, ctx)
4637 """ The complement of set s 4638 >>> a = Const('a', SetSort(IntSort())) 4639 >>> SetComplement(a) 4646 """ The set difference of a and b 4647 >>> a = Const('a', SetSort(IntSort())) 4648 >>> b = Const('b', SetSort(IntSort())) 4649 >>> SetDifference(a, b) 4652 ctx = _ctx_from_ast_arg_list([a, b])
4656 """ Check if e is a member of set s 4657 >>> a = Const('a', SetSort(IntSort())) 4661 ctx = _ctx_from_ast_arg_list([s,e])
4662 e = _py2expr(e, ctx)
4666 """ Check if a is a subset of b 4667 >>> a = Const('a', SetSort(IntSort())) 4668 >>> b = Const('b', SetSort(IntSort())) 4672 ctx = _ctx_from_ast_arg_list([a, b])
4682 def _valid_accessor(acc):
4683 """Return `True` if acc is pair of the form (String, Datatype or Sort). """ 4684 return isinstance(acc, tuple)
and len(acc) == 2
and isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4687 """Helper class for declaring Z3 datatypes. 4689 >>> List = Datatype('List') 4690 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4691 >>> List.declare('nil') 4692 >>> List = List.create() 4693 >>> # List is now a Z3 declaration 4696 >>> List.cons(10, List.nil) 4698 >>> List.cons(10, List.nil).sort() 4700 >>> cons = List.cons 4704 >>> n = cons(1, cons(0, nil)) 4706 cons(1, cons(0, nil)) 4707 >>> simplify(cdr(n)) 4709 >>> simplify(car(n)) 4724 _z3_assert(isinstance(name, str),
"String expected")
4725 _z3_assert(isinstance(rec_name, str),
"String expected")
4726 _z3_assert(all([_valid_accessor(a)
for a
in args]),
"Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
4730 """Declare constructor named `name` with the given accessors `args`. 4731 Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared. 4733 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))` 4734 declares the constructor named `cons` that builds a new List using an integer and a List. 4735 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell, 4736 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create 4737 the actual datatype in Z3. 4739 >>> List = Datatype('List') 4740 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4741 >>> List.declare('nil') 4742 >>> List = List.create() 4745 _z3_assert(isinstance(name, str),
"String expected")
4746 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4753 """Create a Z3 datatype based on the constructors declared using the method `declare()`. 4755 The function `CreateDatatypes()` must be used to define mutually recursive datatypes. 4757 >>> List = Datatype('List') 4758 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4759 >>> List.declare('nil') 4760 >>> List = List.create() 4763 >>> List.cons(10, List.nil) 4769 """Auxiliary object used to create Z3 datatypes.""" 4774 if self.
ctx.ref()
is not None:
4778 """Auxiliary object used to create Z3 datatypes.""" 4783 if self.
ctx.ref()
is not None:
4787 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects. 4789 In the following example we define a Tree-List using two mutually recursive datatypes. 4791 >>> TreeList = Datatype('TreeList') 4792 >>> Tree = Datatype('Tree') 4793 >>> # Tree has two constructors: leaf and node 4794 >>> Tree.declare('leaf', ('val', IntSort())) 4795 >>> # a node contains a list of trees 4796 >>> Tree.declare('node', ('children', TreeList)) 4797 >>> TreeList.declare('nil') 4798 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList)) 4799 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList) 4800 >>> Tree.val(Tree.leaf(10)) 4802 >>> simplify(Tree.val(Tree.leaf(10))) 4804 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil))) 4806 node(cons(leaf(10), cons(leaf(20), nil))) 4807 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil)) 4808 >>> simplify(n2 == n1) 4810 >>> simplify(TreeList.car(Tree.children(n2)) == n1) 4815 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
4816 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
4817 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
4818 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
4821 names = (Symbol * num)()
4822 out = (Sort * num)()
4823 clists = (ConstructorList * num)()
4825 for i
in range(num):
4828 num_cs = len(d.constructors)
4829 cs = (Constructor * num_cs)()
4830 for j
in range(num_cs):
4831 c = d.constructors[j]
4836 fnames = (Symbol * num_fs)()
4837 sorts = (Sort * num_fs)()
4838 refs = (ctypes.c_uint * num_fs)()
4839 for k
in range(num_fs):
4843 if isinstance(ftype, Datatype):
4845 _z3_assert(ds.count(ftype) == 1,
"One and only one occurrence of each datatype is expected")
4847 refs[k] = ds.index(ftype)
4850 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
4851 sorts[k] = ftype.ast
4860 for i
in range(num):
4862 num_cs = dref.num_constructors()
4863 for j
in range(num_cs):
4864 cref = dref.constructor(j)
4865 cref_name = cref.name()
4866 cref_arity = cref.arity()
4867 if cref.arity() == 0:
4869 setattr(dref, cref_name, cref)
4870 rref = dref.recognizer(j)
4871 setattr(dref,
"is_" + cref_name, rref)
4872 for k
in range(cref_arity):
4873 aref = dref.accessor(j, k)
4874 setattr(dref, aref.name(), aref)
4876 return tuple(result)
4879 """Datatype sorts.""" 4881 """Return the number of constructors in the given Z3 datatype. 4883 >>> List = Datatype('List') 4884 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4885 >>> List.declare('nil') 4886 >>> List = List.create() 4887 >>> # List is now a Z3 declaration 4888 >>> List.num_constructors() 4894 """Return a constructor of the datatype `self`. 4896 >>> List = Datatype('List') 4897 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4898 >>> List.declare('nil') 4899 >>> List = List.create() 4900 >>> # List is now a Z3 declaration 4901 >>> List.num_constructors() 4903 >>> List.constructor(0) 4905 >>> List.constructor(1) 4913 """In Z3, each constructor has an associated recognizer predicate. 4915 If the constructor is named `name`, then the recognizer `is_name`. 4917 >>> List = Datatype('List') 4918 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4919 >>> List.declare('nil') 4920 >>> List = List.create() 4921 >>> # List is now a Z3 declaration 4922 >>> List.num_constructors() 4924 >>> List.recognizer(0) 4926 >>> List.recognizer(1) 4928 >>> simplify(List.is_nil(List.cons(10, List.nil))) 4930 >>> simplify(List.is_cons(List.cons(10, List.nil))) 4932 >>> l = Const('l', List) 4933 >>> simplify(List.is_cons(l)) 4941 """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor. 4943 >>> List = Datatype('List') 4944 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4945 >>> List.declare('nil') 4946 >>> List = List.create() 4947 >>> List.num_constructors() 4949 >>> List.constructor(0) 4951 >>> num_accs = List.constructor(0).arity() 4954 >>> List.accessor(0, 0) 4956 >>> List.accessor(0, 1) 4958 >>> List.constructor(1) 4960 >>> num_accs = List.constructor(1).arity() 4966 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
4970 """Datatype expressions.""" 4972 """Return the datatype sort of the datatype expression `self`.""" 4976 """Create a named tuple sort base on a set of underlying sorts 4978 >>> pair, mk_pair, (first, second) = TupleSort("pair", [IntSort(), StringSort()]) 4981 projects = [ (
'project%d' % i, sorts[i])
for i
in range(len(sorts)) ]
4982 tuple.declare(name, *projects)
4983 tuple = tuple.create()
4984 return tuple, tuple.constructor(0), [tuple.accessor(0, i)
for i
in range(len(sorts))]
4987 """Create a named tagged union sort base on a set of underlying sorts 4989 >>> sum, ((inject0, extract0), (inject1, extract1)) = DisjointSum("+", [IntSort(), StringSort()]) 4992 for i
in range(len(sorts)):
4993 sum.declare(
"inject%d" % i, (
"project%d" % i, sorts[i]))
4995 return sum, [(sum.constructor(i), sum.accessor(i, 0))
for i
in range(len(sorts))]
4999 """Return a new enumeration sort named `name` containing the given values. 5001 The result is a pair (sort, list of constants). 5003 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue']) 5006 _z3_assert(isinstance(name, str),
"Name must be a string")
5007 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
5008 _z3_assert(len(values) > 0,
"At least one value expected")
5011 _val_names = (Symbol * num)()
5012 for i
in range(num):
5014 _values = (FuncDecl * num)()
5015 _testers = (FuncDecl * num)()
5019 for i
in range(num):
5021 V = [a()
for a
in V]
5031 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3. 5033 Consider using the function `args2params` to create instances of this object. 5047 if self.
ctx.ref()
is not None:
5051 """Set parameter name with value val.""" 5053 _z3_assert(isinstance(name, str),
"parameter name must be a string")
5055 if isinstance(val, bool):
5059 elif isinstance(val, float):
5061 elif isinstance(val, str):
5065 _z3_assert(
False,
"invalid parameter value")
5071 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5075 """Convert python arguments into a Z3_params object. 5076 A ':' is added to the keywords, and '_' is replaced with '-' 5078 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True}) 5079 (params model true relevancy 2 elim_and true) 5082 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5097 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3. 5100 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5106 return ParamsDescrsRef(self.
descr, self.
ctx)
5109 if self.
ctx.ref()
is not None:
5113 """Return the size of in the parameter description `self`. 5118 """Return the size of in the parameter description `self`. 5123 """Return the i-th parameter name in the parameter description `self`. 5128 """Return the kind of the parameter named `n`. 5133 """Return the documentation string of the parameter named `n`. 5153 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible). 5155 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals. 5156 A goal has a solution if one of its subgoals has a solution. 5157 A goal is unsatisfiable if all subgoals are unsatisfiable. 5160 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5162 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5165 if self.
goal is None:
5170 return Goal(
False,
False,
False, self.
ctx, self.
goal)
5173 if self.
goal is not None and self.
ctx.ref()
is not None:
5177 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`. 5179 >>> x, y = Ints('x y') 5181 >>> g.add(x == 0, y >= x + 1) 5184 >>> r = Then('simplify', 'solve-eqs')(g) 5185 >>> # r has 1 subgoal 5194 """Return `True` if `self` contains the `False` constraints. 5196 >>> x, y = Ints('x y') 5198 >>> g.inconsistent() 5200 >>> g.add(x == 0, x == 1) 5203 >>> g.inconsistent() 5205 >>> g2 = Tactic('propagate-values')(g)[0] 5206 >>> g2.inconsistent() 5212 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`. 5215 >>> g.prec() == Z3_GOAL_PRECISE 5217 >>> x, y = Ints('x y') 5218 >>> g.add(x == y + 1) 5219 >>> g.prec() == Z3_GOAL_PRECISE 5221 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10) 5224 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0] 5225 >>> g2.prec() == Z3_GOAL_PRECISE 5227 >>> g2.prec() == Z3_GOAL_UNDER 5233 """Alias for `prec()`. 5236 >>> g.precision() == Z3_GOAL_PRECISE 5242 """Return the number of constraints in the goal `self`. 5247 >>> x, y = Ints('x y') 5248 >>> g.add(x == 0, y > x) 5255 """Return the number of constraints in the goal `self`. 5260 >>> x, y = Ints('x y') 5261 >>> g.add(x == 0, y > x) 5268 """Return a constraint in the goal `self`. 5271 >>> x, y = Ints('x y') 5272 >>> g.add(x == 0, y > x) 5281 """Return a constraint in the goal `self`. 5284 >>> x, y = Ints('x y') 5285 >>> g.add(x == 0, y > x) 5291 if arg >= len(self):
5293 return self.
get(arg)
5296 """Assert constraints into the goal. 5300 >>> g.assert_exprs(x > 0, x < 2) 5304 args = _get_args(args)
5315 >>> g.append(x > 0, x < 2) 5326 >>> g.insert(x > 0, x < 2) 5337 >>> g.add(x > 0, x < 2) 5344 """Retrieve model from a satisfiable goal 5345 >>> a, b = Ints('a b') 5347 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b) 5348 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs')) 5351 [Or(b == 0, b == 1), Not(0 <= b)] 5353 [Or(b == 0, b == 1), Not(1 <= b)] 5354 >>> # Remark: the subgoal r[0] is unsatisfiable 5355 >>> # Creating a solver for solving the second subgoal 5362 >>> # Model s.model() does not assign a value to `a` 5363 >>> # It is a model for subgoal `r[1]`, but not for goal `g` 5364 >>> # The method convert_model creates a model for `g` from a model for `r[1]`. 5365 >>> r[1].convert_model(s.model()) 5369 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5373 return obj_to_string(self)
5376 """Return a textual representation of the s-expression representing the goal.""" 5380 """Return a textual representation of the goal in DIMACS format.""" 5384 """Copy goal `self` to context `target`. 5392 >>> g2 = g.translate(c2) 5395 >>> g.ctx == main_ctx() 5399 >>> g2.ctx == main_ctx() 5403 _z3_assert(isinstance(target, Context),
"target must be a context")
5413 """Return a new simplified goal. 5415 This method is essentially invoking the simplify tactic. 5419 >>> g.add(x + 1 >= 2) 5422 >>> g2 = g.simplify() 5425 >>> # g was not modified 5430 return t.apply(self, *arguments, **keywords)[0]
5433 """Return goal `self` as a single Z3 expression. 5460 """A collection (vector) of ASTs.""" 5469 assert ctx
is not None 5477 if self.
vector is not None and self.
ctx.ref()
is not None:
5481 """Return the size of the vector `self`. 5486 >>> A.push(Int('x')) 5487 >>> A.push(Int('x')) 5494 """Return the AST at position `i`. 5497 >>> A.push(Int('x') + 1) 5498 >>> A.push(Int('y')) 5505 if isinstance(i, int):
5513 elif isinstance(i, slice):
5518 """Update AST at position `i`. 5521 >>> A.push(Int('x') + 1) 5522 >>> A.push(Int('y')) 5534 """Add `v` in the end of the vector. 5539 >>> A.push(Int('x')) 5546 """Resize the vector to `sz` elements. 5552 >>> for i in range(10): A[i] = Int('x') 5559 """Return `True` if the vector contains `item`. 5582 """Copy vector `self` to context `other_ctx`. 5588 >>> B = A.translate(c2) 5601 return obj_to_string(self)
5604 """Return a textual representation of the s-expression representing the vector.""" 5613 """A mapping from ASTs to ASTs.""" 5622 assert ctx
is not None 5630 if self.
map is not None and self.
ctx.ref()
is not None:
5634 """Return the size of the map. 5640 >>> M[x] = IntVal(1) 5647 """Return `True` if the map contains key `key`. 5660 """Retrieve the value associated with key `key`. 5671 """Add/Update key `k` with value `v`. 5680 >>> M[x] = IntVal(1) 5690 """Remove the entry associated with key `k`. 5704 """Remove all entries from the map. 5709 >>> M[x+x] = IntVal(1) 5719 """Return an AstVector containing all keys in the map. 5724 >>> M[x+x] = IntVal(1) 5737 """Store the value of the interpretation of a function in a particular point.""" 5748 if self.
ctx.ref()
is not None:
5752 """Return the number of arguments in the given entry. 5754 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5756 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5761 >>> f_i.num_entries() 5763 >>> e = f_i.entry(0) 5770 """Return the value of argument `idx`. 5772 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5774 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5779 >>> f_i.num_entries() 5781 >>> e = f_i.entry(0) 5792 ... except IndexError: 5793 ... print("index error") 5801 """Return the value of the function at point `self`. 5803 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5805 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5810 >>> f_i.num_entries() 5812 >>> e = f_i.entry(0) 5823 """Return entry `self` as a Python list. 5824 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5826 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5831 >>> f_i.num_entries() 5833 >>> e = f_i.entry(0) 5838 args.append(self.
value())
5845 """Stores the interpretation of a function in a Z3 model.""" 5850 if self.
f is not None:
5857 if self.
f is not None and self.
ctx.ref()
is not None:
5862 Return the `else` value for a function interpretation. 5863 Return None if Z3 did not specify the `else` value for 5866 >>> f = Function('f', IntSort(), IntSort()) 5868 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5874 >>> m[f].else_value() 5879 return _to_expr_ref(r, self.
ctx)
5884 """Return the number of entries/points in the function interpretation `self`. 5886 >>> f = Function('f', IntSort(), IntSort()) 5888 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5894 >>> m[f].num_entries() 5900 """Return the number of arguments for each entry in the function interpretation `self`. 5902 >>> f = Function('f', IntSort(), IntSort()) 5904 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5914 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`. 5916 >>> f = Function('f', IntSort(), IntSort()) 5918 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5924 >>> m[f].num_entries() 5934 """Copy model 'self' to context 'other_ctx'. 5945 """Return the function interpretation as a Python list. 5946 >>> f = Function('f', IntSort(), IntSort()) 5948 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5962 return obj_to_string(self)
5965 """Model/Solution of a satisfiability problem (aka system of constraints).""" 5968 assert ctx
is not None 5974 if self.
ctx.ref()
is not None:
5978 return obj_to_string(self)
5981 """Return a textual representation of the s-expression representing the model.""" 5984 def eval(self, t, model_completion=False):
5985 """Evaluate the expression `t` in the model `self`. If `model_completion` is enabled, then a default interpretation is automatically added for symbols that do not have an interpretation in the model `self`. 5989 >>> s.add(x > 0, x < 2) 6002 >>> m.eval(y, model_completion=True) 6004 >>> # Now, m contains an interpretation for y 6010 return _to_expr_ref(r[0], self.
ctx)
6011 raise Z3Exception(
"failed to evaluate expression in the model")
6014 """Alias for `eval`. 6018 >>> s.add(x > 0, x < 2) 6022 >>> m.evaluate(x + 1) 6024 >>> m.evaluate(x == 1) 6027 >>> m.evaluate(y + x) 6031 >>> m.evaluate(y, model_completion=True) 6033 >>> # Now, m contains an interpretation for y 6034 >>> m.evaluate(y + x) 6037 return self.
eval(t, model_completion)
6040 """Return the number of constant and function declarations in the model `self`. 6042 >>> f = Function('f', IntSort(), IntSort()) 6045 >>> s.add(x > 0, f(x) != x) 6055 """Return the interpretation for a given declaration or constant. 6057 >>> f = Function('f', IntSort(), IntSort()) 6060 >>> s.add(x > 0, x < 2, f(x) == 0) 6070 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6074 if decl.arity() == 0:
6076 if _r.value
is None:
6078 r = _to_expr_ref(_r, self.
ctx)
6089 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`. 6091 >>> A = DeclareSort('A') 6092 >>> a, b = Consts('a b', A) 6104 """Return the uninterpreted sort at position `idx` < self.num_sorts(). 6106 >>> A = DeclareSort('A') 6107 >>> B = DeclareSort('B') 6108 >>> a1, a2 = Consts('a1 a2', A) 6109 >>> b1, b2 = Consts('b1 b2', B) 6111 >>> s.add(a1 != a2, b1 != b2) 6127 """Return all uninterpreted sorts that have an interpretation in the model `self`. 6129 >>> A = DeclareSort('A') 6130 >>> B = DeclareSort('B') 6131 >>> a1, a2 = Consts('a1 a2', A) 6132 >>> b1, b2 = Consts('b1 b2', B) 6134 >>> s.add(a1 != a2, b1 != b2) 6144 """Return the interpretation for the uninterpreted sort `s` in the model `self`. 6146 >>> A = DeclareSort('A') 6147 >>> a, b = Consts('a b', A) 6153 >>> m.get_universe(A) 6157 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6164 """If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpretation is returned. 6166 The elements can be retrieved using position or the actual declaration. 6168 >>> f = Function('f', IntSort(), IntSort()) 6171 >>> s.add(x > 0, x < 2, f(x) == 0) 6185 >>> for d in m: print("%s -> %s" % (d, m[d])) 6190 if idx >= len(self):
6193 if (idx < num_consts):
6197 if isinstance(idx, FuncDeclRef):
6201 if isinstance(idx, SortRef):
6204 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6208 """Return a list with all symbols that have an interpretation in the model `self`. 6209 >>> f = Function('f', IntSort(), IntSort()) 6212 >>> s.add(x > 0, x < 2, f(x) == 0) 6227 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 6230 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6232 return Model(model, target)
6245 """Return true if n is a Z3 expression of the form (_ as-array f).""" 6246 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6249 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f).""" 6251 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6260 """Statistics for `Solver.check()`.""" 6271 if self.
ctx.ref()
is not None:
6278 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6281 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6284 out.write(u(
'<tr>'))
6286 out.write(u(
'<td>%s</td><td>%s</td></tr>' % (k, v)))
6287 out.write(u(
'</table>'))
6288 return out.getvalue()
6293 """Return the number of statistical counters. 6296 >>> s = Then('simplify', 'nlsat').solver() 6300 >>> st = s.statistics() 6307 """Return the value of statistical counter at position `idx`. The result is a pair (key, value). 6310 >>> s = Then('simplify', 'nlsat').solver() 6314 >>> st = s.statistics() 6318 ('nlsat propagations', 2) 6322 if idx >= len(self):
6331 """Return the list of statistical counters. 6334 >>> s = Then('simplify', 'nlsat').solver() 6338 >>> st = s.statistics() 6343 """Return the value of a particular statistical counter. 6346 >>> s = Then('simplify', 'nlsat').solver() 6350 >>> st = s.statistics() 6351 >>> st.get_key_value('nlsat propagations') 6354 for idx
in range(len(self)):
6360 raise Z3Exception(
"unknown key")
6363 """Access the value of statistical using attributes. 6365 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'), 6366 we should use '_' (e.g., 'nlsat_propagations'). 6369 >>> s = Then('simplify', 'nlsat').solver() 6373 >>> st = s.statistics() 6374 >>> st.nlsat_propagations 6379 key = name.replace(
'_',
' ')
6383 raise AttributeError
6391 """Represents the result of a satisfiability check: sat, unsat, unknown. 6397 >>> isinstance(r, CheckSatResult) 6408 return isinstance(other, CheckSatResult)
and self.
r == other.r
6411 return not self.
__eq__(other)
6415 if self.
r == Z3_L_TRUE:
6417 elif self.
r == Z3_L_FALSE:
6418 return "<b>unsat</b>" 6420 return "<b>unknown</b>" 6422 if self.
r == Z3_L_TRUE:
6424 elif self.
r == Z3_L_FALSE:
6429 def _repr_html_(self):
6430 in_html = in_html_mode()
6433 set_html_mode(in_html)
6441 """Solver API provides methods for implementing the main SMT 2.0 commands: push, pop, check, get-model, etc.""" 6444 assert solver
is None or ctx
is not None 6455 if self.
solver is not None and self.
ctx.ref()
is not None:
6459 """Set a configuration option. The method `help()` return a string containing all available options. 6462 >>> # The option MBQI can be set using three different approaches. 6463 >>> s.set(mbqi=True) 6464 >>> s.set('MBQI', True) 6465 >>> s.set(':mbqi', True) 6471 """Create a backtracking point. 6493 """Backtrack \c num backtracking points. 6515 """Return the current number of backtracking points. 6533 """Remove all asserted constraints and backtracking points created using `push()`. 6547 """Assert constraints into the solver. 6551 >>> s.assert_exprs(x > 0, x < 2) 6555 args = _get_args(args)
6558 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6566 """Assert constraints into the solver. 6570 >>> s.add(x > 0, x < 2) 6581 """Assert constraints into the solver. 6585 >>> s.append(x > 0, x < 2) 6592 """Assert constraints into the solver. 6596 >>> s.insert(x > 0, x < 2) 6603 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`. 6605 If `p` is a string, it will be automatically converted into a Boolean constant. 6610 >>> s.set(unsat_core=True) 6611 >>> s.assert_and_track(x > 0, 'p1') 6612 >>> s.assert_and_track(x != 1, 'p2') 6613 >>> s.assert_and_track(x < 0, p3) 6614 >>> print(s.check()) 6616 >>> c = s.unsat_core() 6626 if isinstance(p, str):
6628 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6629 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6633 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not. 6639 >>> s.add(x > 0, x < 2) 6642 >>> s.model().eval(x) 6648 >>> s.add(2**x == 4) 6652 assumptions = _get_args(assumptions)
6653 num = len(assumptions)
6654 _assumptions = (Ast * num)()
6655 for i
in range(num):
6656 _assumptions[i] = assumptions[i].as_ast()
6661 """Return a model for the last `check()`. 6663 This function raises an exception if 6664 a model is not available (e.g., last `check()` returned unsat). 6668 >>> s.add(a + 2 == 0) 6677 raise Z3Exception(
"model is not available")
6680 """Import model converter from other into the current solver""" 6684 """Return a subset (as an AST vector) of the assumptions provided to the last check(). 6686 These are the assumptions Z3 used in the unsatisfiability proof. 6687 Assumptions are available in Z3. They are used to extract unsatisfiable cores. 6688 They may be also used to "retract" assumptions. Note that, assumptions are not really 6689 "soft constraints", but they can be used to implement them. 6691 >>> p1, p2, p3 = Bools('p1 p2 p3') 6692 >>> x, y = Ints('x y') 6694 >>> s.add(Implies(p1, x > 0)) 6695 >>> s.add(Implies(p2, y > x)) 6696 >>> s.add(Implies(p2, y < 1)) 6697 >>> s.add(Implies(p3, y > -3)) 6698 >>> s.check(p1, p2, p3) 6700 >>> core = s.unsat_core() 6709 >>> # "Retracting" p2 6716 """Determine fixed values for the variables based on the solver state and assumptions. 6718 >>> a, b, c, d = Bools('a b c d') 6719 >>> s.add(Implies(a,b), Implies(b, c)) 6720 >>> s.consequences([a],[b,c,d]) 6721 (sat, [Implies(a, b), Implies(a, c)]) 6722 >>> s.consequences([Not(c),d],[a,b,c,d]) 6723 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))]) 6725 if isinstance(assumptions, list):
6727 for a
in assumptions:
6730 if isinstance(variables, list):
6735 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
6736 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
6739 sz = len(consequences)
6740 consequences = [ consequences[i]
for i
in range(sz) ]
6744 """Parse assertions from a file""" 6748 """Parse assertions from a string""" 6753 The method takes an optional set of variables that restrict which 6754 variables may be used as a starting point for cubing. 6755 If vars is not None, then the first case split is based on a variable in 6759 if vars
is not None:
6766 if (len(r) == 1
and is_false(r[0])):
6773 """Access the set of variables that were touched by the most recently generated cube. 6774 This set of variables can be used as a starting point for additional cubes. 6775 The idea is that variables that appear in clauses that are reduced by the most recent 6776 cube are likely more useful to cube on.""" 6780 """Return a proof for the last `check()`. Proof construction must be enabled.""" 6784 """Return an AST vector containing all added constraints. 6798 """Return an AST vector containing all currently inferred units. 6803 """Return an AST vector containing all atomic formulas in solver state that are not units. 6808 """Return trail and decision levels of the solver state after a check() call. 6810 trail = self.
trail()
6811 levels = (ctypes.c_uint * len(trail))()
6813 return trail, levels
6816 """Return trail of the solver state after a check() call. 6821 """Return statistics for the last `check()`. 6823 >>> s = SimpleSolver() 6828 >>> st = s.statistics() 6829 >>> st.get_key_value('final checks') 6839 """Return a string describing why the last `check()` returned `unknown`. 6842 >>> s = SimpleSolver() 6843 >>> s.add(2**x == 4) 6846 >>> s.reason_unknown() 6847 '(incomplete (theory arithmetic))' 6852 """Display a string describing all available options.""" 6856 """Return the parameter description set.""" 6860 """Return a formatted string with all added constraints.""" 6861 return obj_to_string(self)
6864 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 6868 >>> s1 = Solver(ctx=c1) 6869 >>> s2 = s1.translate(c2) 6872 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6874 return Solver(solver, target)
6883 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format. 6894 """Return a textual representation of the solver in DIMACS format.""" 6898 """return SMTLIB2 formatted benchmark for solver's assertions""" 6905 for i
in range(sz1):
6906 v[i] = es[i].as_ast()
6908 e = es[sz1].as_ast()
6914 """Create a solver customized for the given logic. 6916 The parameter `logic` is a string. It should be contains 6917 the name of a SMT-LIB logic. 6918 See http://www.smtlib.org/ for the name of all available logics. 6920 >>> s = SolverFor("QF_LIA") 6934 """Return a simple general purpose solver with limited amount of preprocessing. 6936 >>> s = SimpleSolver() 6952 """Fixedpoint API provides methods for solving with recursive predicates""" 6955 assert fixedpoint
is None or ctx
is not None 6958 if fixedpoint
is None:
6969 if self.
fixedpoint is not None and self.
ctx.ref()
is not None:
6973 """Set a configuration option. The method `help()` return a string containing all available options. 6979 """Display a string describing all available options.""" 6983 """Return the parameter description set.""" 6987 """Assert constraints as background axioms for the fixedpoint solver.""" 6988 args = _get_args(args)
6991 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7001 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.""" 7009 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.""" 7013 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.""" 7017 """Assert rules defining recursive predicates to the fixedpoint solver. 7020 >>> s = Fixedpoint() 7021 >>> s.register_relation(a.decl()) 7022 >>> s.register_relation(b.decl()) 7035 body = _get_args(body)
7039 def rule(self, head, body = None, name = None):
7040 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule.""" 7044 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule.""" 7048 """Query the fixedpoint engine whether formula is derivable. 7049 You can also pass an tuple or list of recursive predicates. 7051 query = _get_args(query)
7053 if sz >= 1
and isinstance(query[0], FuncDeclRef):
7054 _decls = (FuncDecl * sz)()
7064 query =
And(query, self.
ctx)
7065 query = self.
abstract(query,
False)
7070 """Query the fixedpoint engine whether formula is derivable starting at the given query level. 7072 query = _get_args(query)
7074 if sz >= 1
and isinstance(query[0], FuncDecl):
7075 _z3_assert (
False,
"unsupported")
7081 query = self.
abstract(query,
False)
7082 r = Z3_fixedpoint_query_from_lvl (self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
7090 body = _get_args(body)
7095 """Retrieve answer from last query call.""" 7097 return _to_expr_ref(r, self.
ctx)
7100 """Retrieve a ground cex from last query call.""" 7101 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7102 return _to_expr_ref(r, self.
ctx)
7105 """retrieve rules along the counterexample trace""" 7109 """retrieve rule names along the counterexample trace""" 7112 names = _symbol2py (self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7114 return names.split (
';')
7117 """Retrieve number of levels used for predicate in PDR engine""" 7121 """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)""" 7123 return _to_expr_ref(r, self.
ctx)
7126 """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)""" 7130 """Register relation as recursive""" 7131 relations = _get_args(relations)
7136 """Control how relation is represented""" 7137 representations = _get_args(representations)
7138 representations = [
to_symbol(s)
for s
in representations]
7139 sz = len(representations)
7140 args = (Symbol * sz)()
7142 args[i] = representations[i]
7146 """Parse rules and queries from a string""" 7150 """Parse rules and queries from a file""" 7154 """retrieve rules that have been added to fixedpoint context""" 7158 """retrieve assertions that have been added to fixedpoint context""" 7162 """Return a formatted string with all added rules and constraints.""" 7166 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format. 7171 """Return a formatted string (in Lisp-like format) with all added constraints. 7172 We say the string is in s-expression format. 7173 Include also queries. 7175 args, len = _to_ast_array(queries)
7179 """Return statistics for the last `query()`. 7184 """Return a string describing why the last `query()` returned `unknown`. 7189 """Add variable or several variables. 7190 The added variable or variables will be bound in the rules 7193 vars = _get_args(vars)
7213 """Finite domain sort.""" 7216 """Return the size of the finite domain sort""" 7217 r = (ctypes.c_ulonglong * 1)()
7221 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7224 """Create a named finite domain sort of a given size sz""" 7225 if not isinstance(name, Symbol):
7231 """Return True if `s` is a Z3 finite-domain sort. 7233 >>> is_finite_domain_sort(FiniteDomainSort('S', 100)) 7235 >>> is_finite_domain_sort(IntSort()) 7238 return isinstance(s, FiniteDomainSortRef)
7242 """Finite-domain expressions.""" 7245 """Return the sort of the finite-domain expression `self`.""" 7249 """Return a Z3 floating point expression as a Python string.""" 7253 """Return `True` if `a` is a Z3 finite-domain expression. 7255 >>> s = FiniteDomainSort('S', 100) 7256 >>> b = Const('b', s) 7257 >>> is_finite_domain(b) 7259 >>> is_finite_domain(Int('x')) 7262 return isinstance(a, FiniteDomainRef)
7266 """Integer values.""" 7269 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral. 7271 >>> s = FiniteDomainSort('S', 100) 7272 >>> v = FiniteDomainVal(3, s) 7281 """Return a Z3 finite-domain numeral as a Python string. 7283 >>> s = FiniteDomainSort('S', 100) 7284 >>> v = FiniteDomainVal(42, s) 7292 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used. 7294 >>> s = FiniteDomainSort('S', 256) 7295 >>> FiniteDomainVal(255, s) 7297 >>> FiniteDomainVal('100', s) 7306 """Return `True` if `a` is a Z3 finite-domain value. 7308 >>> s = FiniteDomainSort('S', 100) 7309 >>> b = Const('b', s) 7310 >>> is_finite_domain_value(b) 7312 >>> b = FiniteDomainVal(10, s) 7315 >>> is_finite_domain_value(b) 7360 """Optimize API provides methods for solving using objective functions and weighted soft constraints""" 7371 if self.
optimize is not None and self.
ctx.ref()
is not None:
7375 """Set a configuration option. The method `help()` return a string containing all available options. 7381 """Display a string describing all available options.""" 7385 """Return the parameter description set.""" 7389 """Assert constraints as background axioms for the optimize solver.""" 7390 args = _get_args(args)
7393 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7401 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr.""" 7409 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`. 7411 If `p` is a string, it will be automatically converted into a Boolean constant. 7416 >>> s.assert_and_track(x > 0, 'p1') 7417 >>> s.assert_and_track(x != 1, 'p2') 7418 >>> s.assert_and_track(x < 0, p3) 7419 >>> print(s.check()) 7421 >>> c = s.unsat_core() 7431 if isinstance(p, str):
7433 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
7434 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
7438 """Add soft constraint with optional weight and optional identifier. 7439 If no weight is supplied, then the penalty for violating the soft constraint 7441 Soft constraints are grouped by identifiers. Soft constraints that are 7442 added without identifiers are grouped by default. 7445 weight =
"%d" % weight
7446 elif isinstance(weight, float):
7447 weight =
"%f" % weight
7448 if not isinstance(weight, str):
7449 raise Z3Exception(
"weight should be a string or an integer")
7457 """Add objective function to maximize.""" 7461 """Add objective function to minimize.""" 7465 """create a backtracking point for added rules, facts and assertions""" 7469 """restore to previously created backtracking point""" 7473 """Check satisfiability while optimizing objective functions.""" 7474 assumptions = _get_args(assumptions)
7475 num = len(assumptions)
7476 _assumptions = (Ast * num)()
7477 for i
in range(num):
7478 _assumptions[i] = assumptions[i].as_ast()
7482 """Return a string that describes why the last `check()` returned `unknown`.""" 7486 """Return a model for the last check().""" 7490 raise Z3Exception(
"model is not available")
7496 if not isinstance(obj, OptimizeObjective):
7497 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7501 if not isinstance(obj, OptimizeObjective):
7502 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7506 if not isinstance(obj, OptimizeObjective):
7507 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7508 return obj.lower_values()
7511 if not isinstance(obj, OptimizeObjective):
7512 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7513 return obj.upper_values()
7516 """Parse assertions and objectives from a file""" 7520 """Parse assertions and objectives from a string""" 7524 """Return an AST vector containing all added constraints.""" 7528 """returns set of objective functions""" 7532 """Return a formatted string with all added rules and constraints.""" 7536 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format. 7541 """Return statistics for the last check`. 7554 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters.""" 7565 if self.
ctx.ref()
is not None:
7569 """Return the number of subgoals in `self`. 7571 >>> a, b = Ints('a b') 7573 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b) 7574 >>> t = Tactic('split-clause') 7578 >>> t = Then(Tactic('split-clause'), Tactic('split-clause')) 7581 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values')) 7588 """Return one of the subgoals stored in ApplyResult object `self`. 7590 >>> a, b = Ints('a b') 7592 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b) 7593 >>> t = Tactic('split-clause') 7596 [a == 0, Or(b == 0, b == 1), a > b] 7598 [a == 1, Or(b == 0, b == 1), a > b] 7600 if idx >= len(self):
7605 return obj_to_string(self)
7608 """Return a textual representation of the s-expression representing the set of subgoals in `self`.""" 7613 """Return a Z3 expression consisting of all subgoals. 7618 >>> g.add(Or(x == 2, x == 3)) 7619 >>> r = Tactic('simplify')(g) 7621 [[Not(x <= 1), Or(x == 2, x == 3)]] 7623 And(Not(x <= 1), Or(x == 2, x == 3)) 7624 >>> r = Tactic('split-clause')(g) 7626 [[x > 1, x == 2], [x > 1, x == 3]] 7628 Or(And(x > 1, x == 2), And(x > 1, x == 3)) 7644 """Tactics transform, solver and/or simplify sets of constraints (Goal). A Tactic can be converted into a Solver using the method solver(). 7646 Several combinators are available for creating new tactics using the built-in ones: Then(), OrElse(), FailIf(), Repeat(), When(), Cond(). 7651 if isinstance(tactic, TacticObj):
7655 _z3_assert(isinstance(tactic, str),
"tactic name expected")
7659 raise Z3Exception(
"unknown tactic '%s'" % tactic)
7666 if self.
tactic is not None and self.
ctx.ref()
is not None:
7670 """Create a solver using the tactic `self`. 7672 The solver supports the methods `push()` and `pop()`, but it 7673 will always solve each `check()` from scratch. 7675 >>> t = Then('simplify', 'nlsat') 7678 >>> s.add(x**2 == 2, x > 0) 7686 def apply(self, goal, *arguments, **keywords):
7687 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options. 7689 >>> x, y = Ints('x y') 7690 >>> t = Tactic('solve-eqs') 7691 >>> t.apply(And(x == 0, y >= x + 1)) 7695 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expressions expected")
7696 goal = _to_goal(goal)
7697 if len(arguments) > 0
or len(keywords) > 0:
7704 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options. 7706 >>> x, y = Ints('x y') 7707 >>> t = Tactic('solve-eqs') 7708 >>> t(And(x == 0, y >= x + 1)) 7711 return self.
apply(goal, *arguments, **keywords)
7714 """Display a string containing a description of the available options for the `self` tactic.""" 7718 """Return the parameter description set.""" 7722 if isinstance(a, BoolRef):
7723 goal =
Goal(ctx = a.ctx)
7729 def _to_tactic(t, ctx=None):
7730 if isinstance(t, Tactic):
7735 def _and_then(t1, t2, ctx=None):
7736 t1 = _to_tactic(t1, ctx)
7737 t2 = _to_tactic(t2, ctx)
7739 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7742 def _or_else(t1, t2, ctx=None):
7743 t1 = _to_tactic(t1, ctx)
7744 t2 = _to_tactic(t2, ctx)
7746 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7750 """Return a tactic that applies the tactics in `*ts` in sequence. 7752 >>> x, y = Ints('x y') 7753 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs')) 7754 >>> t(And(x == 0, y > x + 1)) 7756 >>> t(And(x == 0, y > x + 1)).as_expr() 7760 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7761 ctx = ks.get(
'ctx',
None)
7764 for i
in range(num - 1):
7765 r = _and_then(r, ts[i+1], ctx)
7769 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks). 7771 >>> x, y = Ints('x y') 7772 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs')) 7773 >>> t(And(x == 0, y > x + 1)) 7775 >>> t(And(x == 0, y > x + 1)).as_expr() 7781 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail). 7784 >>> t = OrElse(Tactic('split-clause'), Tactic('skip')) 7785 >>> # Tactic split-clause fails if there is no clause in the given goal. 7788 >>> t(Or(x == 0, x == 1)) 7789 [[x == 0], [x == 1]] 7792 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7793 ctx = ks.get(
'ctx',
None)
7796 for i
in range(num - 1):
7797 r = _or_else(r, ts[i+1], ctx)
7801 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail). 7804 >>> t = ParOr(Tactic('simplify'), Tactic('fail')) 7809 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7810 ctx = _get_ctx(ks.get(
'ctx',
None))
7811 ts = [ _to_tactic(t, ctx)
for t
in ts ]
7813 _args = (TacticObj * sz)()
7815 _args[i] = ts[i].tactic
7819 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel. 7821 >>> x, y = Ints('x y') 7822 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values')) 7823 >>> t(And(Or(x == 1, x == 2), y == x + 1)) 7824 [[x == 1, y == 2], [x == 2, y == 3]] 7826 t1 = _to_tactic(t1, ctx)
7827 t2 = _to_tactic(t2, ctx)
7829 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7833 """Alias for ParThen(t1, t2, ctx).""" 7837 """Return a tactic that applies tactic `t` using the given configuration options. 7839 >>> x, y = Ints('x y') 7840 >>> t = With(Tactic('simplify'), som=True) 7841 >>> t((x + 1)*(y + 2) == 0) 7842 [[2*x + y + x*y == -2]] 7844 ctx = keys.pop(
'ctx',
None)
7845 t = _to_tactic(t, ctx)
7850 """Return a tactic that applies tactic `t` using the given configuration options. 7852 >>> x, y = Ints('x y') 7854 >>> p.set("som", True) 7855 >>> t = WithParams(Tactic('simplify'), p) 7856 >>> t((x + 1)*(y + 2) == 0) 7857 [[2*x + y + x*y == -2]] 7859 t = _to_tactic(t,
None)
7863 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached. 7865 >>> x, y = Ints('x y') 7866 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y) 7867 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip'))) 7869 >>> for subgoal in r: print(subgoal) 7870 [x == 0, y == 0, x > y] 7871 [x == 0, y == 1, x > y] 7872 [x == 1, y == 0, x > y] 7873 [x == 1, y == 1, x > y] 7874 >>> t = Then(t, Tactic('propagate-values')) 7878 t = _to_tactic(t, ctx)
7882 """Return a tactic that applies `t` to a given goal for `ms` milliseconds. 7884 If `t` does not terminate in `ms` milliseconds, then it fails. 7886 t = _to_tactic(t, ctx)
7890 """Return a list of all available tactics in Z3. 7893 >>> l.count('simplify') == 1 7900 """Return a short description for the tactic named `name`. 7902 >>> d = tactic_description('simplify') 7908 """Display a (tabular) description of all available tactics in Z3.""" 7911 print(
'<table border="1" cellpadding="2" cellspacing="0">')
7914 print(
'<tr style="background-color:#CFCFCF">')
7919 print(
'<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(
tactic_description(t), 40)))
7926 """Probes are used to inspect a goal (aka problem) and collect information that may be used to decide which solver and/or preprocessing step will be used.""" 7930 if isinstance(probe, ProbeObj):
7932 elif isinstance(probe, float):
7934 elif _is_int(probe):
7936 elif isinstance(probe, bool):
7943 _z3_assert(isinstance(probe, str),
"probe name expected")
7947 raise Z3Exception(
"unknown probe '%s'" % probe)
7954 if self.
probe is not None and self.
ctx.ref()
is not None:
7958 """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`. 7960 >>> p = Probe('size') < 10 7971 """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`. 7973 >>> p = Probe('size') > 10 7984 """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`. 7986 >>> p = Probe('size') <= 2 7997 """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`. 7999 >>> p = Probe('size') >= 2 8010 """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`. 8012 >>> p = Probe('size') == 2 8023 """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`. 8025 >>> p = Probe('size') != 2 8037 """Evaluate the probe `self` in the given goal. 8039 >>> p = Probe('size') 8049 >>> p = Probe('num-consts') 8052 >>> p = Probe('is-propositional') 8055 >>> p = Probe('is-qflia') 8060 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expression expected")
8061 goal = _to_goal(goal)
8065 """Return `True` if `p` is a Z3 probe. 8067 >>> is_probe(Int('x')) 8069 >>> is_probe(Probe('memory')) 8072 return isinstance(p, Probe)
8074 def _to_probe(p, ctx=None):
8078 return Probe(p, ctx)
8081 """Return a list of all available probes in Z3. 8084 >>> l.count('memory') == 1 8091 """Return a short description for the probe named `name`. 8093 >>> d = probe_description('memory') 8099 """Display a (tabular) description of all available probes in Z3.""" 8102 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8105 print(
'<tr style="background-color:#CFCFCF">')
8110 print(
'<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(
probe_description(p), 40)))
8116 def _probe_nary(f, args, ctx):
8118 _z3_assert(len(args) > 0,
"At least one argument expected")
8120 r = _to_probe(args[0], ctx)
8121 for i
in range(num - 1):
8122 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i+1], ctx).probe), ctx)
8125 def _probe_and(args, ctx):
8126 return _probe_nary(Z3_probe_and, args, ctx)
8128 def _probe_or(args, ctx):
8129 return _probe_nary(Z3_probe_or, args, ctx)
8132 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified. 8134 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal. 8136 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify')) 8137 >>> x, y = Ints('x y') 8143 >>> g.add(x == y + 1) 8145 [[Not(x <= 0), Not(y <= 0), x == 1 + y]] 8147 p = _to_probe(p, ctx)
8151 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified. 8153 >>> t = When(Probe('size') > 2, Tactic('simplify')) 8154 >>> x, y = Ints('x y') 8160 >>> g.add(x == y + 1) 8162 [[Not(x <= 0), Not(y <= 0), x == 1 + y]] 8164 p = _to_probe(p, ctx)
8165 t = _to_tactic(t, ctx)
8169 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise. 8171 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt')) 8173 p = _to_probe(p, ctx)
8174 t1 = _to_tactic(t1, ctx)
8175 t2 = _to_tactic(t2, ctx)
8185 """Simplify the expression `a` using the given options. 8187 This function has many options. Use `help_simplify` to obtain the complete list. 8191 >>> simplify(x + 1 + y + x + 1) 8193 >>> simplify((x + 1)*(y + 1), som=True) 8195 >>> simplify(Distinct(x, y, 1), blast_distinct=True) 8196 And(Not(x == y), Not(x == 1), Not(y == 1)) 8197 >>> simplify(And(x == 0, y == 1), elim_and=True) 8198 Not(Or(Not(x == 0), Not(y == 1))) 8201 _z3_assert(
is_expr(a),
"Z3 expression expected")
8202 if len(arguments) > 0
or len(keywords) > 0:
8204 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8206 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8209 """Return a string describing all options available for Z3 `simplify` procedure.""" 8213 """Return the set of parameter descriptions for Z3 `simplify` procedure.""" 8217 """Apply substitution m on t, m is a list of pairs of the form (from, to). Every occurrence in t of from is replaced with to. 8221 >>> substitute(x + 1, (x, y + 1)) 8223 >>> f = Function('f', IntSort(), IntSort()) 8224 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1))) 8227 if isinstance(m, tuple):
8229 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8232 _z3_assert(
is_expr(t),
"Z3 expression expected")
8233 _z3_assert(all([isinstance(p, tuple)
and is_expr(p[0])
and is_expr(p[1])
and p[0].sort().
eq(p[1].sort())
for p
in m]),
"Z3 invalid substitution, expression pairs expected.")
8235 _from = (Ast * num)()
8237 for i
in range(num):
8238 _from[i] = m[i][0].as_ast()
8239 _to[i] = m[i][1].as_ast()
8240 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8243 """Substitute the free variables in t with the expression in m. 8245 >>> v0 = Var(0, IntSort()) 8246 >>> v1 = Var(1, IntSort()) 8248 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 8249 >>> # replace v0 with x+1 and v1 with x 8250 >>> substitute_vars(f(v0, v1), x + 1, x) 8254 _z3_assert(
is_expr(t),
"Z3 expression expected")
8255 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8258 for i
in range(num):
8259 _to[i] = m[i].as_ast()
8263 """Create the sum of the Z3 expressions. 8265 >>> a, b, c = Ints('a b c') 8270 >>> A = IntVector('a', 5) 8272 a__0 + a__1 + a__2 + a__3 + a__4 8274 args = _get_args(args)
8277 ctx = _ctx_from_ast_arg_list(args)
8279 return _reduce(
lambda a, b: a + b, args, 0)
8280 args = _coerce_expr_list(args, ctx)
8282 return _reduce(
lambda a, b: a + b, args, 0)
8284 _args, sz = _to_ast_array(args)
8289 """Create the product of the Z3 expressions. 8291 >>> a, b, c = Ints('a b c') 8292 >>> Product(a, b, c) 8294 >>> Product([a, b, c]) 8296 >>> A = IntVector('a', 5) 8298 a__0*a__1*a__2*a__3*a__4 8300 args = _get_args(args)
8303 ctx = _ctx_from_ast_arg_list(args)
8305 return _reduce(
lambda a, b: a * b, args, 1)
8306 args = _coerce_expr_list(args, ctx)
8308 return _reduce(
lambda a, b: a * b, args, 1)
8310 _args, sz = _to_ast_array(args)
8314 """Create an at-most Pseudo-Boolean k constraint. 8316 >>> a, b, c = Bools('a b c') 8317 >>> f = AtMost(a, b, c, 2) 8319 args = _get_args(args)
8321 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8322 ctx = _ctx_from_ast_arg_list(args)
8324 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8325 args1 = _coerce_expr_list(args[:-1], ctx)
8327 _args, sz = _to_ast_array(args1)
8331 """Create an at-most Pseudo-Boolean k constraint. 8333 >>> a, b, c = Bools('a b c') 8334 >>> f = AtLeast(a, b, c, 2) 8336 args = _get_args(args)
8338 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8339 ctx = _ctx_from_ast_arg_list(args)
8341 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8342 args1 = _coerce_expr_list(args[:-1], ctx)
8344 _args, sz = _to_ast_array(args1)
8347 def _reorder_pb_arg(arg):
8349 if not _is_int(b)
and _is_int(a):
8353 def _pb_args_coeffs(args, default_ctx = None):
8354 args = _get_args_ast_list(args)
8356 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8357 args = [_reorder_pb_arg(arg)
for arg
in args]
8358 args, coeffs = zip(*args)
8360 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8361 ctx = _ctx_from_ast_arg_list(args)
8363 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8364 args = _coerce_expr_list(args, ctx)
8365 _args, sz = _to_ast_array(args)
8366 _coeffs = (ctypes.c_int * len(coeffs))()
8367 for i
in range(len(coeffs)):
8368 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8369 _coeffs[i] = coeffs[i]
8370 return ctx, sz, _args, _coeffs
8373 """Create a Pseudo-Boolean inequality k constraint. 8375 >>> a, b, c = Bools('a b c') 8376 >>> f = PbLe(((a,1),(b,3),(c,2)), 3) 8378 _z3_check_cint_overflow(k,
"k")
8379 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8383 """Create a Pseudo-Boolean inequality k constraint. 8385 >>> a, b, c = Bools('a b c') 8386 >>> f = PbGe(((a,1),(b,3),(c,2)), 3) 8388 _z3_check_cint_overflow(k,
"k")
8389 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8393 """Create a Pseudo-Boolean inequality k constraint. 8395 >>> a, b, c = Bools('a b c') 8396 >>> f = PbEq(((a,1),(b,3),(c,2)), 3) 8398 _z3_check_cint_overflow(k,
"k")
8399 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8404 """Solve the constraints `*args`. 8406 This is a simple function for creating demonstrations. It creates a solver, 8407 configure it using the options in `keywords`, adds the constraints 8408 in `args`, and invokes check. 8411 >>> solve(a > 0, a < 2) 8417 if keywords.get(
'show',
False):
8421 print(
"no solution")
8423 print(
"failed to solve")
8432 """Solve the constraints `*args` using solver `s`. 8434 This is a simple function for creating demonstrations. It is similar to `solve`, 8435 but it uses the given solver `s`. 8436 It configures solver `s` using the options in `keywords`, adds the constraints 8437 in `args`, and invokes check. 8440 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8443 if keywords.get(
'show',
False):
8448 print(
"no solution")
8450 print(
"failed to solve")
8456 if keywords.get(
'show',
False):
8461 """Try to prove the given claim. 8463 This is a simple function for creating demonstrations. It tries to prove 8464 `claim` by showing the negation is unsatisfiable. 8466 >>> p, q = Bools('p q') 8467 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q))) 8471 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8475 if keywords.get(
'show',
False):
8481 print(
"failed to prove")
8484 print(
"counterexample")
8487 def _solve_html(*args, **keywords):
8488 """Version of function `solve` used in RiSE4Fun.""" 8492 if keywords.get(
'show',
False):
8493 print(
"<b>Problem:</b>")
8497 print(
"<b>no solution</b>")
8499 print(
"<b>failed to solve</b>")
8505 if keywords.get(
'show',
False):
8506 print(
"<b>Solution:</b>")
8509 def _solve_using_html(s, *args, **keywords):
8510 """Version of function `solve_using` used in RiSE4Fun.""" 8512 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8515 if keywords.get(
'show',
False):
8516 print(
"<b>Problem:</b>")
8520 print(
"<b>no solution</b>")
8522 print(
"<b>failed to solve</b>")
8528 if keywords.get(
'show',
False):
8529 print(
"<b>Solution:</b>")
8532 def _prove_html(claim, **keywords):
8533 """Version of function `prove` used in RiSE4Fun.""" 8535 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8539 if keywords.get(
'show',
False):
8543 print(
"<b>proved</b>")
8545 print(
"<b>failed to prove</b>")
8548 print(
"<b>counterexample</b>")
8551 def _dict2sarray(sorts, ctx):
8553 _names = (Symbol * sz)()
8554 _sorts = (Sort * sz) ()
8559 _z3_assert(isinstance(k, str),
"String expected")
8560 _z3_assert(
is_sort(v),
"Z3 sort expected")
8564 return sz, _names, _sorts
8566 def _dict2darray(decls, ctx):
8568 _names = (Symbol * sz)()
8569 _decls = (FuncDecl * sz) ()
8574 _z3_assert(isinstance(k, str),
"String expected")
8578 _decls[i] = v.decl().ast
8582 return sz, _names, _decls
8586 """Parse a string in SMT 2.0 format using the given sorts and decls. 8588 The arguments sorts and decls are Python dictionaries used to initialize 8589 the symbol table used for the SMT 2.0 parser. 8591 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))') 8593 >>> x, y = Ints('x y') 8594 >>> f = Function('f', IntSort(), IntSort()) 8595 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f}) 8597 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() }) 8601 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8602 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8606 """Parse a file in SMT 2.0 format using the given sorts and decls. 8608 This function is similar to parse_smt2_string(). 8611 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8612 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8624 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
8625 _dflt_fpsort_ebits = 11
8626 _dflt_fpsort_sbits = 53
8629 """Retrieves the global default rounding mode.""" 8630 global _dflt_rounding_mode
8631 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8633 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8635 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8637 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8639 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8643 global _dflt_rounding_mode
8645 _dflt_rounding_mode = rm.decl().kind()
8647 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO
or 8648 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE
or 8649 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE
or 8650 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
or 8651 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8652 "illegal rounding mode")
8653 _dflt_rounding_mode = rm
8656 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8659 global _dflt_fpsort_ebits
8660 global _dflt_fpsort_sbits
8661 _dflt_fpsort_ebits = ebits
8662 _dflt_fpsort_sbits = sbits
8664 def _dflt_rm(ctx=None):
8667 def _dflt_fps(ctx=None):
8670 def _coerce_fp_expr_list(alist, ctx):
8671 first_fp_sort =
None 8674 if first_fp_sort
is None:
8675 first_fp_sort = a.sort()
8676 elif first_fp_sort == a.sort():
8681 first_fp_sort =
None 8685 for i
in range(len(alist)):
8687 if (isinstance(a, str)
and a.contains(
'2**(')
and a.endswith(
')'))
or _is_int(a)
or isinstance(a, float)
or isinstance(a, bool):
8688 r.append(
FPVal(a,
None, first_fp_sort, ctx))
8691 return _coerce_expr_list(r, ctx)
8697 """Floating-point sort.""" 8700 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`. 8701 >>> b = FPSort(8, 24) 8708 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`. 8709 >>> b = FPSort(8, 24) 8716 """Try to cast `val` as a floating-point expression. 8717 >>> b = FPSort(8, 24) 8720 >>> b.cast(1.0).sexpr() 8721 '(fp #b0 #x7f #b00000000000000000000000)' 8725 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
8728 return FPVal(val,
None, self, self.
ctx)
8732 """Floating-point 16-bit (half) sort.""" 8737 """Floating-point 16-bit (half) sort.""" 8742 """Floating-point 32-bit (single) sort.""" 8747 """Floating-point 32-bit (single) sort.""" 8752 """Floating-point 64-bit (double) sort.""" 8757 """Floating-point 64-bit (double) sort.""" 8762 """Floating-point 128-bit (quadruple) sort.""" 8767 """Floating-point 128-bit (quadruple) sort.""" 8772 """"Floating-point rounding mode sort.""" 8776 """Return True if `s` is a Z3 floating-point sort. 8778 >>> is_fp_sort(FPSort(8, 24)) 8780 >>> is_fp_sort(IntSort()) 8783 return isinstance(s, FPSortRef)
8786 """Return True if `s` is a Z3 floating-point rounding mode sort. 8788 >>> is_fprm_sort(FPSort(8, 24)) 8790 >>> is_fprm_sort(RNE().sort()) 8793 return isinstance(s, FPRMSortRef)
8798 """Floating-point expressions.""" 8801 """Return the sort of the floating-point expression `self`. 8803 >>> x = FP('1.0', FPSort(8, 24)) 8806 >>> x.sort() == FPSort(8, 24) 8812 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`. 8813 >>> b = FPSort(8, 24) 8820 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`. 8821 >>> b = FPSort(8, 24) 8828 """Return a Z3 floating point expression as a Python string.""" 8832 return fpLEQ(self, other, self.
ctx)
8835 return fpLT(self, other, self.
ctx)
8838 return fpGEQ(self, other, self.
ctx)
8841 return fpGT(self, other, self.
ctx)
8844 """Create the Z3 expression `self + other`. 8846 >>> x = FP('x', FPSort(8, 24)) 8847 >>> y = FP('y', FPSort(8, 24)) 8853 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8854 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8857 """Create the Z3 expression `other + self`. 8859 >>> x = FP('x', FPSort(8, 24)) 8863 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8864 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8867 """Create the Z3 expression `self - other`. 8869 >>> x = FP('x', FPSort(8, 24)) 8870 >>> y = FP('y', FPSort(8, 24)) 8876 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8877 return fpSub(_dflt_rm(), a, b, self.
ctx)
8880 """Create the Z3 expression `other - self`. 8882 >>> x = FP('x', FPSort(8, 24)) 8886 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8887 return fpSub(_dflt_rm(), a, b, self.
ctx)
8890 """Create the Z3 expression `self * other`. 8892 >>> x = FP('x', FPSort(8, 24)) 8893 >>> y = FP('y', FPSort(8, 24)) 8901 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8902 return fpMul(_dflt_rm(), a, b, self.
ctx)
8905 """Create the Z3 expression `other * self`. 8907 >>> x = FP('x', FPSort(8, 24)) 8908 >>> y = FP('y', FPSort(8, 24)) 8914 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8915 return fpMul(_dflt_rm(), a, b, self.
ctx)
8918 """Create the Z3 expression `+self`.""" 8922 """Create the Z3 expression `-self`. 8924 >>> x = FP('x', Float32()) 8931 """Create the Z3 expression `self / other`. 8933 >>> x = FP('x', FPSort(8, 24)) 8934 >>> y = FP('y', FPSort(8, 24)) 8942 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8943 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8946 """Create the Z3 expression `other / self`. 8948 >>> x = FP('x', FPSort(8, 24)) 8949 >>> y = FP('y', FPSort(8, 24)) 8955 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8956 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8959 """Create the Z3 expression division `self / other`.""" 8963 """Create the Z3 expression division `other / self`.""" 8967 """Create the Z3 expression mod `self % other`.""" 8968 return fpRem(self, other)
8971 """Create the Z3 expression mod `other % self`.""" 8972 return fpRem(other, self)
8975 """Floating-point rounding mode expressions""" 8978 """Return a Z3 floating point expression as a Python string.""" 9023 """Return `True` if `a` is a Z3 floating-point rounding mode expression. 9032 return isinstance(a, FPRMRef)
9035 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value.""" 9036 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
9041 """The sign of the numeral. 9043 >>> x = FPVal(+1.0, FPSort(8, 24)) 9046 >>> x = FPVal(-1.0, FPSort(8, 24)) 9051 l = (ctypes.c_int)()
9053 raise Z3Exception(
"error retrieving the sign of a numeral.")
9056 """The sign of a floating-point numeral as a bit-vector expression. 9058 Remark: NaN's are invalid arguments. 9063 """The significand of the numeral. 9065 >>> x = FPVal(2.5, FPSort(8, 24)) 9072 """The significand of the numeral as a long. 9074 >>> x = FPVal(2.5, FPSort(8, 24)) 9075 >>> x.significand_as_long() 9079 ptr = (ctypes.c_ulonglong * 1)()
9081 raise Z3Exception(
"error retrieving the significand of a numeral.")
9084 """The significand of the numeral as a bit-vector expression. 9086 Remark: NaN are invalid arguments. 9091 """The exponent of the numeral. 9093 >>> x = FPVal(2.5, FPSort(8, 24)) 9100 """The exponent of the numeral as a long. 9102 >>> x = FPVal(2.5, FPSort(8, 24)) 9103 >>> x.exponent_as_long() 9107 ptr = (ctypes.c_longlong * 1)()
9109 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9112 """The exponent of the numeral as a bit-vector expression. 9114 Remark: NaNs are invalid arguments. 9119 """Indicates whether the numeral is a NaN.""" 9123 """Indicates whether the numeral is +oo or -oo.""" 9127 """Indicates whether the numeral is +zero or -zero.""" 9131 """Indicates whether the numeral is normal.""" 9135 """Indicates whether the numeral is subnormal.""" 9139 """Indicates whether the numeral is positive.""" 9143 """Indicates whether the numeral is negative.""" 9148 The string representation of the numeral. 9150 >>> x = FPVal(20, FPSort(8, 24)) 9156 return (
"FPVal(%s, %s)" % (s, self.
sort()))
9159 """Return `True` if `a` is a Z3 floating-point expression. 9161 >>> b = FP('b', FPSort(8, 24)) 9169 return isinstance(a, FPRef)
9172 """Return `True` if `a` is a Z3 floating-point numeral value. 9174 >>> b = FP('b', FPSort(8, 24)) 9177 >>> b = FPVal(1.0, FPSort(8, 24)) 9183 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9186 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used. 9188 >>> Single = FPSort(8, 24) 9189 >>> Double = FPSort(11, 53) 9192 >>> x = Const('x', Single) 9193 >>> eq(x, FP('x', FPSort(8, 24))) 9199 def _to_float_str(val, exp=0):
9200 if isinstance(val, float):
9204 sone = math.copysign(1.0, val)
9209 elif val == float(
"+inf"):
9211 elif val == float(
"-inf"):
9214 v = val.as_integer_ratio()
9217 rvs = str(num) +
'/' + str(den)
9218 res = rvs +
'p' + _to_int_str(exp)
9219 elif isinstance(val, bool):
9226 elif isinstance(val, str):
9227 inx = val.find(
'*(2**')
9230 elif val[-1] ==
')':
9232 exp = str(int(val[inx+5:-1]) + int(exp))
9234 _z3_assert(
False,
"String does not have floating-point numeral form.")
9236 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9240 return res +
'p' + exp
9244 """Create a Z3 floating-point NaN term. 9246 >>> s = FPSort(8, 24) 9247 >>> set_fpa_pretty(True) 9250 >>> pb = get_fpa_pretty() 9251 >>> set_fpa_pretty(False) 9253 fpNaN(FPSort(8, 24)) 9254 >>> set_fpa_pretty(pb) 9256 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9260 """Create a Z3 floating-point +oo term. 9262 >>> s = FPSort(8, 24) 9263 >>> pb = get_fpa_pretty() 9264 >>> set_fpa_pretty(True) 9265 >>> fpPlusInfinity(s) 9267 >>> set_fpa_pretty(False) 9268 >>> fpPlusInfinity(s) 9269 fpPlusInfinity(FPSort(8, 24)) 9270 >>> set_fpa_pretty(pb) 9272 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9276 """Create a Z3 floating-point -oo term.""" 9277 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9281 """Create a Z3 floating-point +oo or -oo term.""" 9282 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9283 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9287 """Create a Z3 floating-point +0.0 term.""" 9288 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9292 """Create a Z3 floating-point -0.0 term.""" 9293 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9297 """Create a Z3 floating-point +0.0 or -0.0 term.""" 9298 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9299 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9302 def FPVal(sig, exp=None, fps=None, ctx=None):
9303 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used. 9305 >>> v = FPVal(20.0, FPSort(8, 24)) 9308 >>> print("0x%.8x" % v.exponent_as_long(False)) 9310 >>> v = FPVal(2.25, FPSort(8, 24)) 9313 >>> v = FPVal(-2.25, FPSort(8, 24)) 9316 >>> FPVal(-0.0, FPSort(8, 24)) 9318 >>> FPVal(0.0, FPSort(8, 24)) 9320 >>> FPVal(+0.0, FPSort(8, 24)) 9328 fps = _dflt_fps(ctx)
9332 val = _to_float_str(sig)
9333 if val ==
"NaN" or val ==
"nan":
9337 elif val ==
"0.0" or val ==
"+0.0":
9339 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9341 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9346 def FP(name, fpsort, ctx=None):
9347 """Return a floating-point constant named `name`. 9348 `fpsort` is the floating-point sort. 9349 If `ctx=None`, then the global context is used. 9351 >>> x = FP('x', FPSort(8, 24)) 9358 >>> word = FPSort(8, 24) 9359 >>> x2 = FP('x', word) 9363 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9369 def FPs(names, fpsort, ctx=None):
9370 """Return an array of floating-point constants. 9372 >>> x, y, z = FPs('x y z', FPSort(8, 24)) 9379 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z) 9380 fpMul(RNE(), fpAdd(RNE(), x, y), z) 9383 if isinstance(names, str):
9384 names = names.split(
" ")
9385 return [
FP(name, fpsort, ctx)
for name
in names]
9388 """Create a Z3 floating-point absolute value expression. 9390 >>> s = FPSort(8, 24) 9392 >>> x = FPVal(1.0, s) 9395 >>> y = FPVal(-20.0, s) 9400 >>> fpAbs(-1.25*(2**4)) 9406 [a] = _coerce_fp_expr_list([a], ctx)
9410 """Create a Z3 floating-point addition expression. 9412 >>> s = FPSort(8, 24) 9421 [a] = _coerce_fp_expr_list([a], ctx)
9424 def _mk_fp_unary(f, rm, a, ctx):
9426 [a] = _coerce_fp_expr_list([a], ctx)
9428 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9429 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9430 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9432 def _mk_fp_unary_pred(f, a, ctx):
9434 [a] = _coerce_fp_expr_list([a], ctx)
9436 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9437 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9439 def _mk_fp_bin(f, rm, a, b, ctx):
9441 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9443 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9444 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9445 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
9447 def _mk_fp_bin_norm(f, a, b, ctx):
9449 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9451 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9452 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9454 def _mk_fp_bin_pred(f, a, b, ctx):
9456 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9458 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9459 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9461 def _mk_fp_tern(f, rm, a, b, c, ctx):
9463 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
9465 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9466 _z3_assert(
is_fp(a)
or is_fp(b)
or is_fp(c),
"At least one of the arguments must be a Z3 floating-point expression")
9467 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
9470 """Create a Z3 floating-point addition expression. 9472 >>> s = FPSort(8, 24) 9478 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ 9480 >>> fpAdd(rm, x, y).sort() 9483 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9486 """Create a Z3 floating-point subtraction expression. 9488 >>> s = FPSort(8, 24) 9494 >>> fpSub(rm, x, y).sort() 9497 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9500 """Create a Z3 floating-point multiplication expression. 9502 >>> s = FPSort(8, 24) 9508 >>> fpMul(rm, x, y).sort() 9511 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9514 """Create a Z3 floating-point division expression. 9516 >>> s = FPSort(8, 24) 9522 >>> fpDiv(rm, x, y).sort() 9525 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9528 """Create a Z3 floating-point remainder expression. 9530 >>> s = FPSort(8, 24) 9535 >>> fpRem(x, y).sort() 9538 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9541 """Create a Z3 floating-point minimum expression. 9543 >>> s = FPSort(8, 24) 9549 >>> fpMin(x, y).sort() 9552 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9555 """Create a Z3 floating-point maximum expression. 9557 >>> s = FPSort(8, 24) 9563 >>> fpMax(x, y).sort() 9566 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9569 """Create a Z3 floating-point fused multiply-add expression. 9571 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9574 """Create a Z3 floating-point square root expression. 9576 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9579 """Create a Z3 floating-point roundToIntegral expression. 9581 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9584 """Create a Z3 floating-point isNaN expression. 9586 >>> s = FPSort(8, 24) 9592 return _mk_fp_unary_pred(Z3_mk_fpa_is_nan, a, ctx)
9595 """Create a Z3 floating-point isInfinite expression. 9597 >>> s = FPSort(8, 24) 9602 return _mk_fp_unary_pred(Z3_mk_fpa_is_infinite, a, ctx)
9605 """Create a Z3 floating-point isZero expression. 9607 return _mk_fp_unary_pred(Z3_mk_fpa_is_zero, a, ctx)
9610 """Create a Z3 floating-point isNormal expression. 9612 return _mk_fp_unary_pred(Z3_mk_fpa_is_normal, a, ctx)
9615 """Create a Z3 floating-point isSubnormal expression. 9617 return _mk_fp_unary_pred(Z3_mk_fpa_is_subnormal, a, ctx)
9620 """Create a Z3 floating-point isNegative expression. 9622 return _mk_fp_unary_pred(Z3_mk_fpa_is_negative, a, ctx)
9625 """Create a Z3 floating-point isPositive expression. 9627 return _mk_fp_unary_pred(Z3_mk_fpa_is_positive, a, ctx)
9629 def _check_fp_args(a, b):
9631 _z3_assert(
is_fp(a)
or is_fp(b),
"At least one of the arguments must be a Z3 floating-point expression")
9634 """Create the Z3 floating-point expression `other < self`. 9636 >>> x, y = FPs('x y', FPSort(8, 24)) 9642 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9645 """Create the Z3 floating-point expression `other <= self`. 9647 >>> x, y = FPs('x y', FPSort(8, 24)) 9650 >>> (x <= y).sexpr() 9653 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9656 """Create the Z3 floating-point expression `other > self`. 9658 >>> x, y = FPs('x y', FPSort(8, 24)) 9664 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9667 """Create the Z3 floating-point expression `other >= self`. 9669 >>> x, y = FPs('x y', FPSort(8, 24)) 9672 >>> (x >= y).sexpr() 9675 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9678 """Create the Z3 floating-point expression `fpEQ(other, self)`. 9680 >>> x, y = FPs('x y', FPSort(8, 24)) 9683 >>> fpEQ(x, y).sexpr() 9686 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9689 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`. 9691 >>> x, y = FPs('x y', FPSort(8, 24)) 9694 >>> (x != y).sexpr() 9700 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp. 9702 >>> s = FPSort(8, 24) 9703 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23)) 9705 fpFP(1, 127, 4194304) 9706 >>> xv = FPVal(-1.5, s) 9710 >>> slvr.add(fpEQ(x, xv)) 9713 >>> xv = FPVal(+1.5, s) 9717 >>> slvr.add(fpEQ(x, xv)) 9722 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
9724 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
9728 """Create a Z3 floating-point conversion expression from other term sorts 9731 From a bit-vector term in IEEE 754-2008 format: 9732 >>> x = FPVal(1.0, Float32()) 9733 >>> x_bv = fpToIEEEBV(x) 9734 >>> simplify(fpToFP(x_bv, Float32())) 9737 From a floating-point term with different precision: 9738 >>> x = FPVal(1.0, Float32()) 9739 >>> x_db = fpToFP(RNE(), x, Float64()) 9744 >>> x_r = RealVal(1.5) 9745 >>> simplify(fpToFP(RNE(), x_r, Float32())) 9748 From a signed bit-vector term: 9749 >>> x_signed = BitVecVal(-5, BitVecSort(32)) 9750 >>> simplify(fpToFP(RNE(), x_signed, Float32())) 9763 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
9766 """Create a Z3 floating-point conversion expression that represents the 9767 conversion from a bit-vector term to a floating-point term. 9769 >>> x_bv = BitVecVal(0x3F800000, 32) 9770 >>> x_fp = fpBVToFP(x_bv, Float32()) 9776 _z3_assert(
is_bv(v),
"First argument must be a Z3 floating-point rounding mode expression.")
9777 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
9782 """Create a Z3 floating-point conversion expression that represents the 9783 conversion from a floating-point term to a floating-point term of different precision. 9785 >>> x_sgl = FPVal(1.0, Float32()) 9786 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64()) 9794 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9795 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
9796 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9801 """Create a Z3 floating-point conversion expression that represents the 9802 conversion from a real term to a floating-point term. 9804 >>> x_r = RealVal(1.5) 9805 >>> x_fp = fpRealToFP(RNE(), x_r, Float32()) 9811 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9812 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
9813 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9818 """Create a Z3 floating-point conversion expression that represents the 9819 conversion from a signed bit-vector term (encoding an integer) to a floating-point term. 9821 >>> x_signed = BitVecVal(-5, BitVecSort(32)) 9822 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32()) 9824 fpToFP(RNE(), 4294967291) 9828 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9829 _z3_assert(
is_bv(v),
"Second argument must be a Z3 expression or real sort.")
9830 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9835 """Create a Z3 floating-point conversion expression that represents the 9836 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term. 9838 >>> x_signed = BitVecVal(-5, BitVecSort(32)) 9839 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32()) 9841 fpToFPUnsigned(RNE(), 4294967291) 9845 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9846 _z3_assert(
is_bv(v),
"Second argument must be a Z3 expression or real sort.")
9847 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9852 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression.""" 9854 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9855 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
9856 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
9861 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector. 9863 >>> x = FP('x', FPSort(8, 24)) 9864 >>> y = fpToSBV(RTZ(), x, BitVecSort(32)) 9875 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9876 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9877 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9882 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector. 9884 >>> x = FP('x', FPSort(8, 24)) 9885 >>> y = fpToUBV(RTZ(), x, BitVecSort(32)) 9896 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9897 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9898 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9903 """Create a Z3 floating-point conversion expression, from floating-point expression to real. 9905 >>> x = FP('x', FPSort(8, 24)) 9909 >>> print(is_real(y)) 9913 >>> print(is_real(x)) 9917 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9922 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. 9924 The size of the resulting bit-vector is automatically determined. 9926 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion 9927 knows only one NaN and it will always produce the same bit-vector representation of 9930 >>> x = FP('x', FPSort(8, 24)) 9931 >>> y = fpToIEEEBV(x) 9942 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9955 """Sequence sort.""" 9958 """Determine if sort is a string 9959 >>> s = StringSort() 9962 >>> s = SeqSort(IntSort()) 9973 """Create a string sort 9974 >>> s = StringSort() 9983 """Create a sequence sort over elements provided in the argument 9984 >>> s = SeqSort(IntSort()) 9985 >>> s == Unit(IntVal(1)).sort() 9991 """Sequence expression.""" 9997 return Concat(self, other)
10000 return Concat(other, self)
10019 """Return a string representation of sequence expression.""" 10037 def _coerce_seq(s, ctx=None):
10038 if isinstance(s, str):
10039 ctx = _get_ctx(ctx)
10042 raise Z3Exception(
"Non-expression passed as a sequence")
10044 raise Z3Exception(
"Non-sequence passed as a sequence")
10047 def _get_ctx2(a, b, ctx=None):
10057 """Return `True` if `a` is a Z3 sequence expression. 10058 >>> print (is_seq(Unit(IntVal(0)))) 10060 >>> print (is_seq(StringVal("abc"))) 10063 return isinstance(a, SeqRef)
10066 """Return `True` if `a` is a Z3 string expression. 10067 >>> print (is_string(StringVal("ab"))) 10070 return isinstance(a, SeqRef)
and a.is_string()
10073 """return 'True' if 'a' is a Z3 string constant expression. 10074 >>> print (is_string_value(StringVal("a"))) 10076 >>> print (is_string_value(StringVal("a") + StringVal("b"))) 10079 return isinstance(a, SeqRef)
and a.is_string_value()
10083 """create a string expression""" 10084 ctx = _get_ctx(ctx)
10088 """Return a string constant named `name`. If `ctx=None`, then the global context is used. 10090 >>> x = String('x') 10092 ctx = _get_ctx(ctx)
10096 """Return string constants""" 10097 ctx = _get_ctx(ctx)
10098 if isinstance(names, str):
10099 names = names.split(
" ")
10100 return [
String(name, ctx)
for name
in names]
10103 """Extract substring or subsequence starting at offset""" 10104 return Extract(s, offset, length)
10107 """Extract substring or subsequence starting at offset""" 10108 return Extract(s, offset, length)
10110 def Strings(names, ctx=None):
10111 """Return a tuple of String constants. """ 10112 ctx = _get_ctx(ctx)
10113 if isinstance(names, str):
10114 names = names.split(
" ")
10115 return [
String(name, ctx)
for name
in names]
10118 """Create the empty sequence of the given sort 10119 >>> e = Empty(StringSort()) 10120 >>> e2 = StringVal("") 10121 >>> print(e.eq(e2)) 10123 >>> e3 = Empty(SeqSort(IntSort())) 10126 >>> e4 = Empty(ReSort(SeqSort(IntSort()))) 10128 Empty(ReSort(Seq(Int))) 10130 if isinstance(s, SeqSortRef):
10132 if isinstance(s, ReSortRef):
10134 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10137 """Create the regular expression that accepts the universal language 10138 >>> e = Full(ReSort(SeqSort(IntSort()))) 10140 Full(ReSort(Seq(Int))) 10141 >>> e1 = Full(ReSort(StringSort())) 10143 Full(ReSort(String)) 10145 if isinstance(s, ReSortRef):
10147 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10151 """Create a singleton sequence""" 10155 """Check if 'a' is a prefix of 'b' 10156 >>> s1 = PrefixOf("ab", "abc") 10159 >>> s2 = PrefixOf("bc", "abc") 10163 ctx = _get_ctx2(a, b)
10164 a = _coerce_seq(a, ctx)
10165 b = _coerce_seq(b, ctx)
10169 """Check if 'a' is a suffix of 'b' 10170 >>> s1 = SuffixOf("ab", "abc") 10173 >>> s2 = SuffixOf("bc", "abc") 10177 ctx = _get_ctx2(a, b)
10178 a = _coerce_seq(a, ctx)
10179 b = _coerce_seq(b, ctx)
10183 """Check if 'a' contains 'b' 10184 >>> s1 = Contains("abc", "ab") 10187 >>> s2 = Contains("abc", "bc") 10190 >>> x, y, z = Strings('x y z') 10191 >>> s3 = Contains(Concat(x,y,z), y) 10195 ctx = _get_ctx2(a, b)
10196 a = _coerce_seq(a, ctx)
10197 b = _coerce_seq(b, ctx)
10202 """Replace the first occurrence of 'src' by 'dst' in 's' 10203 >>> r = Replace("aaa", "a", "b") 10207 ctx = _get_ctx2(dst, s)
10208 if ctx
is None and is_expr(src):
10210 src = _coerce_seq(src, ctx)
10211 dst = _coerce_seq(dst, ctx)
10212 s = _coerce_seq(s, ctx)
10219 """Retrieve the index of substring within a string starting at a specified offset. 10220 >>> simplify(IndexOf("abcabc", "bc", 0)) 10222 >>> simplify(IndexOf("abcabc", "bc", 2)) 10228 ctx = _get_ctx2(s, substr, ctx)
10229 s = _coerce_seq(s, ctx)
10230 substr = _coerce_seq(substr, ctx)
10231 if _is_int(offset):
10232 offset =
IntVal(offset, ctx)
10236 """Retrieve the last index of substring within a string""" 10238 ctx = _get_ctx2(s, substr, ctx)
10239 s = _coerce_seq(s, ctx)
10240 substr = _coerce_seq(substr, ctx)
10245 """Obtain the length of a sequence 's' 10246 >>> l = Length(StringVal("abc")) 10254 """Convert string expression to integer 10255 >>> a = StrToInt("1") 10256 >>> simplify(1 == a) 10258 >>> b = StrToInt("2") 10259 >>> simplify(1 == b) 10261 >>> c = StrToInt(IntToStr(2)) 10262 >>> simplify(1 == c) 10270 """Convert integer expression to string""" 10277 """The regular expression that accepts sequence 's' 10279 >>> s2 = Re(StringVal("ab")) 10280 >>> s3 = Re(Unit(BoolVal(True))) 10282 s = _coerce_seq(s, ctx)
10291 """Regular expression sort.""" 10299 if s
is None or isinstance(s, Context):
10302 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10306 """Regular expressions.""" 10309 return Union(self, other)
10312 return isinstance(s, ReRef)
10316 """Create regular expression membership test 10317 >>> re = Union(Re("a"),Re("b")) 10318 >>> print (simplify(InRe("a", re))) 10320 >>> print (simplify(InRe("b", re))) 10322 >>> print (simplify(InRe("c", re))) 10325 s = _coerce_seq(s, re.ctx)
10329 """Create union of regular expressions. 10330 >>> re = Union(Re("a"), Re("b"), Re("c")) 10331 >>> print (simplify(InRe("d", re))) 10334 args = _get_args(args)
10337 _z3_assert(sz > 0,
"At least one argument expected.")
10338 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10343 for i
in range(sz):
10344 v[i] = args[i].as_ast()
10348 """Create intersection of regular expressions. 10349 >>> re = Intersect(Re("a"), Re("b"), Re("c")) 10351 args = _get_args(args)
10354 _z3_assert(sz > 0,
"At least one argument expected.")
10355 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10360 for i
in range(sz):
10361 v[i] = args[i].as_ast()
10365 """Create the regular expression accepting one or more repetitions of argument. 10366 >>> re = Plus(Re("a")) 10367 >>> print(simplify(InRe("aa", re))) 10369 >>> print(simplify(InRe("ab", re))) 10371 >>> print(simplify(InRe("", re))) 10377 """Create the regular expression that optionally accepts the argument. 10378 >>> re = Option(Re("a")) 10379 >>> print(simplify(InRe("a", re))) 10381 >>> print(simplify(InRe("", re))) 10383 >>> print(simplify(InRe("aa", re))) 10389 """Create the complement regular expression.""" 10393 """Create the regular expression accepting zero or more repetitions of argument. 10394 >>> re = Star(Re("a")) 10395 >>> print(simplify(InRe("aa", re))) 10397 >>> print(simplify(InRe("ab", re))) 10399 >>> print(simplify(InRe("", re))) 10405 """Create the regular expression accepting between a lower and upper bound repetitions 10406 >>> re = Loop(Re("a"), 1, 3) 10407 >>> print(simplify(InRe("aa", re))) 10409 >>> print(simplify(InRe("aaaa", re))) 10411 >>> print(simplify(InRe("", re))) 10417 """Create the range regular expression over two sequences of length 1 10418 >>> range = Range("a","z") 10419 >>> print(simplify(InRe("b", range))) 10421 >>> print(simplify(InRe("bb", range))) 10424 lo = _coerce_seq(lo, ctx)
10425 hi = _coerce_seq(hi, ctx)
10443 """Given a binary relation R, such that the two arguments have the same sort 10444 create the transitive closure relation R+. 10445 The transitive closure R+ is a new relation. Z3_sort Z3_API Z3_mk_fpa_sort_32(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
void Z3_API Z3_solver_push(Z3_context c, Z3_solver s)
Create a backtracking point.
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.
def translate(self, target)
def __rrshift__(self, other)
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_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_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...
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...
def significand_as_long(self)
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
def fpToIEEEBV(x, ctx=None)
Z3_ast Z3_API Z3_mk_true(Z3_context c)
Create an AST node representing true.
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_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c)
Create a new fixedpoint context.
def __init__(self, entry, ctx)
Z3_probe Z3_API Z3_probe_le(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is less than or equal to the va...
Z3_ast Z3_API Z3_mk_real2int(Z3_context c, Z3_ast t1)
Coerce a real to an integer.
Z3_sort Z3_API Z3_mk_bv_sort(Z3_context c, unsigned sz)
Create a bit-vector type of the given size.
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value)
Set a global (or module) parameter. This setting is shared by all Z3 contexts.
def __rdiv__(self, other)
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p)
Set the given solver using the given parameters.
def FreshReal(prefix='b', ctx=None)
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_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.
void Z3_API Z3_fixedpoint_add_rule(Z3_context c, Z3_fixedpoint d, Z3_ast rule, Z3_symbol name)
Add a universal Horn clause as a named rule. The horn_rule should be of the form:
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
def fpIsNegative(a, ctx=None)
def __rxor__(self, other)
Z3_sort Z3_API Z3_model_get_sort(Z3_context c, Z3_model m, unsigned i)
Return a uninterpreted sort that m assigns an interpretation.
def update_rule(self, head, body, name)
Z3_ast Z3_API Z3_mk_bvredand(Z3_context c, Z3_ast t1)
Take conjunction of bits in vector, return vector of length 1.
Z3_ast Z3_API Z3_mk_false(Z3_context c)
Create an AST node representing false.
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s)
Return the set of asserted formulas on the solver.
Z3_ast Z3_API Z3_mk_mod(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 mod arg2.
def exponent_as_bv(self, biased=True)
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_sort Z3_API Z3_mk_fpa_sort_quadruple(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
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.
void Z3_API Z3_del_constructor(Z3_context c, Z3_constructor constr)
Reclaim memory allocated to constructor.
def BVSubNoUnderflow(a, b, signed)
Z3_param_descrs Z3_API Z3_tactic_get_param_descrs(Z3_context c, Z3_tactic t)
Return the parameter description set for the given tactic object.
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig)
Create an expression of FloatingPoint sort from three bit-vector expressions.
def args2params(arguments, keywords, ctx=None)
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.
def get_cover_delta(self, level, predicate)
def TupleSort(name, sorts, ctx=None)
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a)
Return idx_a'th accessor for the idx_c'th constructor.
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t)
Return a tactic that applies t to a given goal is the probe p evaluates to true. If p evaluates to fa...
def RoundTowardPositive(ctx=None)
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty)
Create a bound variable.
def FloatSingle(ctx=None)
def upper_values(self, obj)
def set_param(*args, **kws)
def RatVal(a, b, ctx=None)
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a)
def __rmod__(self, other)
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
def __deepcopy__(self, memo={})
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_mul(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] * ... * args[num_args-1].
Z3_ast Z3_API Z3_mk_seq_concat(Z3_context c, unsigned n, Z3_ast const args[])
Concatenate sequences.
Z3_func_decl Z3_API Z3_mk_transitive_closure(Z3_context c, Z3_func_decl f)
create transitive closure of binary relation.
def __getitem__(self, idx)
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t)
Increment the reference counter of the given tactic.
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.
void Z3_API Z3_solver_pop(Z3_context c, Z3_solver s, unsigned n)
Backtrack n backtracking points.
Z3_symbol Z3_API Z3_get_decl_name(Z3_context c, Z3_func_decl d)
Return the constant declaration name as a symbol.
def RealVector(prefix, sz, ctx=None)
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s)
Retrieve documentation string corresponding to parameter name s.
Z3_sort Z3_API Z3_mk_fpa_sort(Z3_context c, unsigned ebits, unsigned sbits)
Create a FloatingPoint sort.
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_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g)
Convert a goal into a DIMACS formatted string. The goal must be in CNF. You can convert a goal to CNF...
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.
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_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain)
Create the full set.
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...
def DisjointSum(name, sorts, ctx=None)
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...
Z3_sort Z3_API Z3_get_seq_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for sequence sort.
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_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...
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
def translate(self, other_ctx)
Z3_string Z3_API Z3_ast_to_string(Z3_context c, Z3_ast a)
Convert the given AST node into a string.
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_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_unary_minus(Z3_context c, Z3_ast arg)
Create an AST node representing - arg.
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.
def set(self, *args, **keys)
def SubSeq(s, offset, length)
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.
expr range(expr const &lo, expr const &hi)
def fpBVToFP(v, sort, ctx=None)
def SubString(s, offset, length)
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.
Z3_ast Z3_API Z3_mk_bvlshr(Z3_context c, Z3_ast t1, Z3_ast t2)
Logical shift right.
Z3_func_decl Z3_API Z3_model_get_func_decl(Z3_context c, Z3_model m, unsigned i)
Return the declaration of the i-th function in the given model.
def FPs(names, fpsort, ctx=None)
def FPVal(sig, exp=None, fps=None, ctx=None)
Z3_sort Z3_API Z3_mk_int_sort(Z3_context c)
Create the integer type.
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....
def RealVarVector(n, ctx=None)
def __rmul__(self, other)
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_xor(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 xor t2.
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...
def __deepcopy__(self, memo={})
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a)
Return true if the given AST is a real algebraic number.
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v)
Array update.
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty)
Declare and create a constant.
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_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name)
Return a tactic associated with the given name. The complete list of tactics may be obtained using th...
def Strings(names, ctx=None)
def __call__(self, goal, *arguments, **keywords)
Z3_probe Z3_API Z3_probe_const(Z3_context x, double val)
Return a probe that always evaluates to val.
def fpRoundToIntegral(rm, a, ctx=None)
def to_symbol(s, ctx=None)
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t)
Return the range of the given array sort.
def __init__(self, descr, ctx=None)
Z3_probe Z3_API Z3_probe_eq(Z3_context x, Z3_probe p1, Z3_probe p2)
Return a probe that evaluates to "true" when the value returned by p1 is equal to the value returned ...
Z3_ast Z3_API Z3_mk_concat(Z3_context c, Z3_ast t1, Z3_ast t2)
Concatenate the given bit-vectors.
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_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....
def __getattr__(self, name)
Z3_ast Z3_API Z3_mk_bvuge(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than or equal to.
Z3_ast Z3_API Z3_mk_bvugt(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned greater than.
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_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
def __deepcopy__(self, memo={})
def IntVal(val, ctx=None)
Z3_sort Z3_API Z3_mk_fpa_sort_single(Z3_context c)
Create the single-precision (32-bit) FloatingPoint sort.
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.
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_ast Z3_API Z3_mk_str_to_int(Z3_context c, Z3_ast s)
Convert string to integer.
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_set_union(Z3_context c, unsigned num_args, Z3_ast const args[])
Take the union of a list of sets.
Z3_func_decl Z3_API Z3_model_get_const_decl(Z3_context c, Z3_model m, unsigned i)
Return the i-th constant in the given model.
Z3_ast Z3_API Z3_mk_le(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than or equal to.
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2)
compare sorts.
def exponent_as_long(self, biased=True)
def BVSubNoOverflow(a, b)
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_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_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...
def parse_smt2_string(s, sorts={}, decls={}, ctx=None)
Z3_string Z3_API Z3_solver_to_dimacs_string(Z3_context c, Z3_solver s)
Convert a solver into a DIMACS formatted string.
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].
def RoundTowardNegative(ctx=None)
Z3_ast Z3_API Z3_fpa_get_numeral_sign_bv(Z3_context c, Z3_ast t)
Retrieves the sign of a floating-point literal as a bit-vector expression.
Z3_ast Z3_API Z3_func_entry_get_arg(Z3_context c, Z3_func_entry e, unsigned i)
Return an argument of a Z3_func_entry object.
def __init__(self, ctx=None)
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.
unsigned Z3_API Z3_get_decl_num_parameters(Z3_context c, Z3_func_decl d)
Return the number of parameters associated with a declaration.
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast t1, Z3_ast t2)
Compare terms.
def as_decimal(self, prec)
def __init__(self, c, ctx)
def fpToFP(a1, a2=None, a3=None, ctx=None)
Z3_ast Z3_API Z3_mk_bvule(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than or equal to.
Z3_probe Z3_API Z3_mk_probe(Z3_context c, Z3_string name)
Return a probe associated with the given name. The complete list of probes may be obtained using the ...
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
unsigned Z3_API Z3_model_get_num_sorts(Z3_context c, Z3_model m)
Return the number of uninterpreted sorts that m assigns an interpretation to.
Z3_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,...
def simplify(a, *arguments, **keywords)
Utils.
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_decl_kind Z3_API Z3_get_decl_kind(Z3_context c, Z3_func_decl d)
Return declaration kind corresponding to declaration.
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.
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a)
Determine if ast is an existential quantifier.
def declare_core(self, name, rec_name, *args)
Z3_string Z3_API Z3_get_tactic_name(Z3_context c, unsigned i)
Return the name of the idx tactic.
def fpUnsignedToFP(rm, v, sort, ctx=None)
Z3_ast Z3_API Z3_mk_re_intersect(Z3_context c, unsigned n, Z3_ast const args[])
Create the intersection of the regular languages.
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c)
Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode.
def lower_values(self, obj)
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s)
Retrieve the proof for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_lbool Z3_API Z3_solver_check_assumptions(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[])
Check whether the assertions in the given solver and optional assumptions are consistent or not.
def solve(*args, **keywords)
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_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.
def RoundNearestTiesToEven(ctx=None)
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v)
Create the constant array.
Z3_ast Z3_API Z3_func_decl_to_ast(Z3_context c, Z3_func_decl f)
Convert a Z3_func_decl into Z3_ast. This is just type casting.
Z3_ast Z3_API Z3_mk_add(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] + ... + args[num_args-1].
def translate(self, target)
Z3_stats Z3_API Z3_fixedpoint_get_statistics(Z3_context c, Z3_fixedpoint d)
Retrieve statistics information from the last call to Z3_fixedpoint_query.
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast a, Z3_params p)
Interface to simplifier.
def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context....
Z3_apply_result Z3_API Z3_tactic_apply(Z3_context c, Z3_tactic t, Z3_goal g)
Apply tactic t to the goal g.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain)
Create the empty set.
Z3_ast Z3_API Z3_mk_ext_rotate_right(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the right t2 times.
def get_documentation(self, n)
def With(t, *args, **keys)
unsigned Z3_API Z3_fpa_get_sbits(Z3_context c, Z3_sort s)
Retrieves the number of bits reserved for the significand in a FloatingPoint sort.
def as_decimal(self, prec)
void Z3_API Z3_solver_reset(Z3_context c, Z3_solver s)
Remove all assertions from the solver.
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g)
Return true if the given goal contains the formula false.
def __deepcopy__(self, memo={})
def fpToUBV(rm, x, s, ctx=None)
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i)
Return sort of the i'th bound variable.
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
def simplify(self, *arguments, **keywords)
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_seq_length(Z3_context c, Z3_ast s)
Return the length of the sequence s.
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_mk_seq_prefix(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if prefix is a prefix of s.
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s)
Return the set of units modulo model conversion.
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_get_app_arg(Z3_context c, Z3_app a, unsigned i)
Return the i-th argument of the given application.
Z3_string Z3_API Z3_solver_get_help(Z3_context c, Z3_solver s)
Return a string describing all solver available parameters.
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th recognizer.
Z3_ast Z3_API Z3_mk_re_complement(Z3_context c, Z3_ast re)
Create the complement of the regular language re.
def __deepcopy__(self, memo={})
def get_universe(self, s)
Z3_ast Z3_API Z3_mk_seq_nth(Z3_context c, Z3_ast s, Z3_ast index)
Retrieve from s the element positioned at position index. The function is under-specified if the inde...
def assert_exprs(self, *args)
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.
def __rtruediv__(self, other)
def fpGEQ(a, b, ctx=None)
Z3_stats Z3_API Z3_solver_get_statistics(Z3_context c, Z3_solver s)
Return statistics for the given solver.
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_mk_fpa_round_toward_zero(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardZero rounding mode.
def num_no_patterns(self)
def PbEq(args, k, ctx=None)
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_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_array_default(Z3_context c, Z3_ast array)
Access the array default value. Produces the default range value, for arrays that can be represented ...
def rule(self, head, body=None, name=None)
Z3_ast Z3_API Z3_mk_re_concat(Z3_context c, unsigned n, Z3_ast const args[])
Create the concatenation of the regular languages.
def __call__(self, *args)
Z3_func_decl Z3_API Z3_get_app_decl(Z3_context c, Z3_app a)
Return the declaration of a constant or function application.
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p)
Convert a parameter description set into a string. This function is mainly used for printing the cont...
def fpRem(a, b, ctx=None)
void Z3_API Z3_fixedpoint_assert(Z3_context c, Z3_fixedpoint d, Z3_ast axiom)
Assert a constraint to the fixedpoint context.
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.
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
def set(self, *args, **keys)
Z3_ast Z3_API Z3_mk_lambda_const(Z3_context c, unsigned num_bound, Z3_app const bound[], Z3_ast body)
Create a lambda expression using a list of constants that form the set of bound variables.
def __setitem__(self, k, v)
def exponent(self, biased=True)
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is normal.
def assert_exprs(self, *args)
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.
void Z3_API Z3_append_log(Z3_string string)
Append user-defined string to interaction log.
def Range(lo, hi, ctx=None)
unsigned Z3_API Z3_get_index_value(Z3_context c, Z3_ast a)
Return index of de-Bruijn bound variable.
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.
def __rsub__(self, other)
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t)
Floating-point absolute value.
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a string.
def is_finite_domain_sort(s)
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.
def __init__(self, stats, ctx)
def z3_error_handler(c, e)
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed less than.
def denominator_as_long(self)
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
def assert_and_track(self, a, p)
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c)
Create a sort for 8 bit strings.
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
def BoolVector(prefix, sz, ctx=None)
void Z3_API Z3_solver_assert(Z3_context c, Z3_solver s, Z3_ast a)
Assert a constraint into the solver.
def __deepcopy__(self, memo={})
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2)
Return a tactic that first applies t1 to a given goal, if it fails then returns the result of t2 appl...
def significand_as_bv(self)
def Array(name, dom, rng)
Z3_model Z3_API Z3_solver_get_model(Z3_context c, Z3_solver s)
Retrieve the model for the last Z3_solver_check or Z3_solver_check_assumptions.
Z3_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_del_constructor_list(Z3_context c, Z3_constructor_list clist)
Reclaim memory allocated for constructor list.
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_ast Z3_API Z3_mk_set_difference(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Take the set difference between two sets.
Z3_ast_kind Z3_API Z3_get_ast_kind(Z3_context c, Z3_ast a)
Return the kind of the given AST.
def If(a, b, c, ctx=None)
def BitVecVal(val, bv, ctx=None)
bool Z3_API Z3_open_log(Z3_string filename)
Log interaction to a file.
def query_from_lvl(self, lvl, *query)
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.
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_bvsrem(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed remainder (sign follows dividend).
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.
def set_default_rounding_mode(rm, ctx=None)
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.
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.
def Cond(p, t1, t2, ctx=None)
Z3_ast Z3_API Z3_mk_fpa_to_fp_bv(Z3_context c, Z3_ast bv, Z3_sort s)
Conversion of a single IEEE 754-2008 bit-vector into a floating-point number.
Z3_param_descrs Z3_API Z3_simplify_get_param_descrs(Z3_context c)
Return the parameter description set for the simplify procedure.
Z3_func_decl Z3_API Z3_to_func_decl(Z3_context c, Z3_ast a)
Convert an AST into a FUNC_DECL_AST. This is just type casting.
def fpMax(a, b, ctx=None)
Z3_func_decl Z3_API Z3_mk_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const domain[], Z3_sort range)
Declare a constant or function.
def get_rule_names_along_trace(self)
def register_relation(self, *relations)
def __init__(self, fixedpoint=None, ctx=None)
def set(self, *args, **keys)
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.
def simplify_param_descrs()
def approx(self, precision=10)
def fpToFPUnsigned(rm, x, s, ctx=None)
def fpMul(rm, a, b, ctx=None)
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is subnormal.
void Z3_API Z3_param_descrs_inc_ref(Z3_context c, Z3_param_descrs p)
Increment the reference counter of the given parameter description set.
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f)
Return the 'else' value of the given function interpretation.
def BitVec(name, bv, ctx=None)
Z3_ast Z3_API Z3_mk_ext_rotate_left(Z3_context c, Z3_ast t1, Z3_ast t2)
Rotate bits of t1 to the left t2 times.
Z3_ast Z3_API Z3_mk_div(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Create an AST node representing arg1 div arg2.
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint d)
Increment the reference counter of the given fixedpoint context.
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p)
Increment the reference counter of the given probe.
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a)
Return number of bound variables of quantifier.
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_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
Z3_bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast *v)
Evaluate the AST node t in the given model. Return true if succeeded, and store the result in v.
def __getitem__(self, arg)
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_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort.
Z3_ast Z3_API Z3_mk_int2real(Z3_context c, Z3_ast t1)
Coerce an integer to a real.
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...
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.
def __getitem__(self, arg)
def FiniteDomainSort(name, sz, ctx=None)
Z3_sort Z3_API Z3_mk_uninterpreted_sort(Z3_context c, Z3_symbol s)
Create a free (uninterpreted) type using the given name (symbol).
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s)
Conversion of a term of real sort into a term of FloatingPoint sort.
def __init__(self, v=None, ctx=None)
Z3_ast Z3_API Z3_mk_lt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create less than.
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.
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.
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.
def BVAddNoOverflow(a, b, signed)
def __radd__(self, other)
def __rdiv__(self, other)
def fpIsNormal(a, ctx=None)
void Z3_API Z3_func_entry_inc_ref(Z3_context c, Z3_func_entry e)
Increment the reference counter of the given Z3_func_entry object.
void Z3_API Z3_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_...
def FreshConst(sort, prefix='c')
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.
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
def fpSignedToFP(rm, v, sort, ctx=None)
def get_default_rounding_mode(ctx=None)
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
def fact(self, head, name=None)
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
Z3_ast Z3_API Z3_mk_not(Z3_context c, Z3_ast a)
Create an AST node representing not(a).
def convert_model(self, model)
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_and(Z3_context c, unsigned num_args, Z3_ast const args[])
Create an AST node representing args[0] and ... and args[num_args-1].
def __getitem__(self, arg)
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_ge(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater than or equal to.
Z3_ast Z3_API Z3_get_quantifier_no_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th no_pattern.
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t)
Return the size of the given bit-vector sort.
Z3_ast Z3_API Z3_mk_str_le(Z3_context c, Z3_ast prefix, Z3_ast s)
Check if s1 is equal or lexicographically strictly less than s2.
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_sort Z3_API Z3_mk_array_sort(Z3_context c, Z3_sort domain, Z3_sort range)
Create an array type.
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_ast Z3_API Z3_mk_set_subset(Z3_context c, Z3_ast arg1, Z3_ast arg2)
Check for subsetness of sets.
def __init__(self, solver=None, ctx=None)
def ParAndThen(t1, t2, ctx=None)
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_goal_prec Z3_API Z3_goal_precision(Z3_context c, Z3_goal g)
Return the "precision" of the given goal. Goals can be transformed using over and under approximation...
def __rtruediv__(self, other)
def Bools(names, ctx=None)
def RoundNearestTiesToAway(ctx=None)
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.
Z3_pattern Z3_API Z3_get_quantifier_pattern_ast(Z3_context c, Z3_ast a, unsigned i)
Return i'th pattern.
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_set_add(Z3_context c, Z3_ast set, Z3_ast elem)
Add an element to a set.
double Z3_API Z3_get_decl_double_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the double value associated with an double parameter.
Z3_ast Z3_API Z3_mk_set_complement(Z3_context c, Z3_ast arg)
Take the complement of a set.
unsigned Z3_API Z3_get_ast_hash(Z3_context c, Z3_ast a)
Return a hash code for the given AST. The hash code is structural. You can use Z3_get_ast_id intercha...
Z3_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...
def RealVal(val, ctx=None)
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.
def Extract(high, low, a)
def __getitem__(self, idx)
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
def apply(self, goal, *arguments, **keywords)
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const *domain, Z3_sort range)
Create an array type with N arguments.
def RealVar(idx, ctx=None)
def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[])
Z3_string Z3_API Z3_get_full_version(void)
Return a string that fully describes the version of Z3 in use.
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(Z3_context c, Z3_fixedpoint f, Z3_string s)
Parse an SMT-LIB2 file with fixedpoint rules. Add the rules to the current fixedpoint context....
def FloatQuadruple(ctx=None)
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_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....
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.
void Z3_API Z3_goal_dec_ref(Z3_context c, Z3_goal g)
Decrement the reference counter of the given goal.
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.
def FloatDouble(ctx=None)
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.
def declare_var(self, *vars)
Z3_sort Z3_API Z3_get_re_sort_basis(Z3_context c, Z3_sort s)
Retrieve basis sort for regex sort.
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.
void Z3_API Z3_solver_from_file(Z3_context c, Z3_solver s, Z3_string file_name)
load solver assertions from a file.
def add_soft(self, arg, weight="1", id=None)
def parse_smt2_file(f, sorts={}, decls={}, ctx=None)
def substitute_vars(t, *m)
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.
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
void Z3_API Z3_enable_trace(Z3_string tag)
Enable tracing messages tagged as tag when Z3 is compiled in debug mode. It is a NOOP otherwise.
def get_key_value(self, key)
def fpFMA(rm, a, b, c, ctx=None)
def __deepcopy__(self, memo={})
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,...
Strings, Sequences and Regular expressions.
def Implies(a, b, ctx=None)
def __init__(self, tactic, ctx=None)
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f)
Return the interpretation of the function f in the model m. Return NULL, if the model does not assign...
void Z3_API Z3_model_dec_ref(Z3_context c, Z3_model m)
Decrement the reference counter of the given model.
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_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.
Z3_string Z3_API Z3_get_string(Z3_context c, Z3_ast s)
Retrieve the string constant stored in s.
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.
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_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,...
def __deepcopy__(self, memo={})
void Z3_API Z3_fixedpoint_dec_ref(Z3_context c, Z3_fixedpoint d)
Decrement the reference counter of the given fixedpoint context.
def __truediv__(self, other)
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t)
Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
Z3_ast Z3_API Z3_mk_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.
unsigned Z3_API Z3_goal_size(Z3_context c, Z3_goal g)
Return the number of formulas in the given goal.
def __init__(self, opt, value, is_max)
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,...
def LastIndexOf(s, substr)
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules(Z3_context c, Z3_fixedpoint f)
Retrieve set of rules from fixedpoint context.
Z3_model Z3_API Z3_mk_model(Z3_context c)
Create a fresh model object. It has reference count 0.
def solve_using(s, *args, **keywords)
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_solver Z3_API Z3_solver_translate(Z3_context source, Z3_solver s, Z3_context target)
Copy a solver s from the context source to the context target.
def StringVal(s, ctx=None)
int Z3_API Z3_get_symbol_int(Z3_context c, Z3_symbol s)
Return the symbol int value.
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_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
def FiniteDomainVal(val, sort, ctx=None)
double Z3_API Z3_probe_apply(Z3_context c, Z3_probe p, Z3_goal g)
Execute the probe over the goal. The probe always produce a double value. "Boolean" probes return 0....
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s)
Retrieve the unsat core for the last Z3_solver_check_assumptions The unsat core is a subset of the as...
def __deepcopy__(self, memo={})
def FPSort(ebits, sbits, ctx=None)
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_ast Z3_API Z3_func_entry_get_value(Z3_context c, Z3_func_entry e)
Return the value of this point.
def DeclareSort(name, ctx=None)
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
def LinearOrder(a, index)
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
def Ints(names, ctx=None)
Z3_ast Z3_API Z3_mk_bvult(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned less than.
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g)
Convert a goal into a string.
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.
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m)
Return the number of function interpretations in the given model.
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.
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.
unsigned Z3_API Z3_get_num_tactics(Z3_context c)
Return the number of builtin tactics available in Z3.
def is_finite_domain_value(a)
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a string of a numeric constant term.
def assert_exprs(self, *args)
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s)
Determine if s is a string constant.
def FreshBool(prefix='b', ctx=None)
def probe_description(name, ctx=None)
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.
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.
def get_rules_along_trace(self)
def __deepcopy__(self, memo={})
def tactic_description(name, ctx=None)
def BVAddNoUnderflow(a, b)
Z3_ast Z3_API Z3_mk_re_plus(Z3_context c, Z3_ast re)
Create the regular language re+.
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast a)
Interface to simplifier.
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
def __rshift__(self, other)
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is positive.
def is_string_value(self)
def num_constructors(self)
unsigned Z3_API Z3_get_quantifier_num_patterns(Z3_context c, Z3_ast a)
Return number of patterns used in quantifier.
def __contains__(self, item)
def eval(self, t, model_completion=False)
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers,...
def __contains__(self, key)
def __rmul__(self, other)
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id)
create a tree ordering relation over signature a identified using index id.
def numerator_as_long(self)
def FP(name, fpsort, ctx=None)
Z3_param_descrs Z3_API Z3_fixedpoint_get_param_descrs(Z3_context c, Z3_fixedpoint f)
Return the parameter description set for the given fixedpoint object.
def fpToSBV(rm, x, s, ctx=None)
def assert_and_track(self, a, p)
def fpDiv(rm, a, b, ctx=None)
def get_default_fp_sort(ctx=None)
def set_default_fp_sort(ebits, sbits, ctx=None)
def BVSDivNoOverflow(a, b)
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.
Z3_ast Z3_API Z3_mk_bvsdiv_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2)
Create a predicate that checks that the bit-wise signed division of t1 and t2 does not overflow.
Z3_sort Z3_API Z3_mk_seq_sort(Z3_context c, Z3_sort s)
Create a sequence sort out of the sort for the elements.
Z3_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.
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s)
Check if s is a string sort.
def BitVecs(names, bv, ctx=None)
def translate(self, target)
def from_file(self, filename)
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t *r)
Store the size of the sort in r. Return false if the call failed. That is, Z3_get_sort_kind(s) == Z3_...
def __init__(self, probe, ctx=None)
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_ast Z3_API Z3_mk_repeat(Z3_context c, unsigned i, Z3_ast t1)
Repeat the given bit-vector up length i.
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_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx)
Return the expression value associated with an expression parameter.
def __init__(self, f, ctx)
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_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_solver_to_string(Z3_context c, Z3_solver s)
Convert a solver into a string.
Z3_ast Z3_API Z3_mk_re_star(Z3_context c, Z3_ast re)
Create the regular language re*.
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context dst)
translate model from context c to context dst.
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_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.
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_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t)
Floating-point negation.
Z3_ast Z3_API Z3_mk_is_int(Z3_context c, Z3_ast t1)
Check if a real number is an integer.
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c)
Create the real type.
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_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places.
Z3_ast Z3_API Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set)
Check for set membership.
unsigned Z3_API Z3_get_quantifier_weight(Z3_context c, Z3_ast a)
Obtain weight of 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.
def __radd__(self, other)
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_ast Z3_API Z3_mk_seq_index(Z3_context c, Z3_ast s, Z3_ast substr, Z3_ast offset)
Return index of first occurrence of substr in s starting from offset offset. If s does not contain su...
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
def to_string(self, queries)
Z3_ast Z3_API Z3_mk_re_range(Z3_context c, Z3_ast lo, Z3_ast hi)
Create the range regular expression over two sequences of length 1.
def constructor(self, idx)
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_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
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...
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.
def __getitem__(self, key)
def fpSub(rm, a, b, ctx=None)
def fpFP(sgn, exp, sig, ctx=None)
void Z3_API Z3_mk_datatypes(Z3_context c, unsigned num_sorts, Z3_symbol const sort_names[], Z3_sort sorts[], Z3_constructor_list constructor_lists[])
Create mutually recursive datatypes.
Z3_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_gt(Z3_context c, Z3_ast t1, Z3_ast t2)
Create greater 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.
void Z3_API Z3_solver_assert_and_track(Z3_context c, Z3_solver s, Z3_ast a, Z3_ast p)
Assert a constraint a into the solver, and track it (in the unsat) core using the Boolean constant p.
def __setitem__(self, i, v)
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_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_pble(Z3_context c, unsigned num_args, Z3_ast const args[], int const coeffs[], int k)
Pseudo-Boolean relations.
def parse_string(self, s)
Z3_solver Z3_API Z3_mk_simple_solver(Z3_context c)
Create a new incremental solver.
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_implies(Z3_context c, Z3_ast t1, Z3_ast t2)
Create an AST node representing t1 implies t2.
def fpSqrt(rm, a, ctx=None)
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...
def __init__(self, *args, **kws)
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.
def fpLEQ(a, b, ctx=None)
def get_ground_sat_answer(self)
def EnumSort(name, values, ctx=None)
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_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.
Z3_ast Z3_API Z3_mk_re_empty(Z3_context c, Z3_sort re)
Create an empty regular expression of sort re.
def get_interp(self, decl)
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
def __init__(self, c, ctx)
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.
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_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...
def __init__(self, name, ctx=None)
Z3_string Z3_API Z3_fixedpoint_get_help(Z3_context c, Z3_fixedpoint f)
Return a string describing all fixedpoint available parameters.
void Z3_API Z3_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.
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_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c)
Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode.
Z3_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.
def RoundTowardZero(ctx=None)
def consequences(self, assumptions, variables)
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.
def PiecewiseLinearOrder(a, index)
Z3_string Z3_API Z3_get_symbol_string(Z3_context c, Z3_symbol s)
Return the symbol name.
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_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_pattern Z3_API Z3_mk_pattern(Z3_context c, unsigned num_patterns, Z3_ast const terms[])
Create a pattern for quantifier instantiation.
def declare(self, name, *args)
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.
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_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.
def check(self, *assumptions)
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).
def add_rule(self, head, body=None, name=None)
def __rmul__(self, other)
def from_file(self, filename)
def RecAddDefinition(f, args, body)
def BoolVal(val, ctx=None)
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_bvredor(Z3_context c, Z3_ast t1)
Take disjunction of bits in vector, return vector of length 1.
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.
unsigned Z3_API Z3_get_quantifier_num_no_patterns(Z3_context c, Z3_ast a)
Return number of no_patterns used in quantifier.
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_re_full(Z3_context c, Z3_sort re)
Create an universal regular expression of sort re.
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is a NaN.
def fpMin(a, b, ctx=None)
def cube(self, vars=None)
Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s)
Create a string constant out of the string that is passed in It takes the length of the string as wel...
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.
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.
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a)
Determine if an ast is a universal quantifier.
def __init__(self, m, ctx)
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(Z3_context c, Z3_fixedpoint f)
Retrieve set of background assertions from fixedpoint context.
def BVMulNoOverflow(a, b, signed)
def no_pattern(self, idx)
def FreshInt(prefix='x', ctx=None)
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_goal_inc_ref(Z3_context c, Z3_goal g)
Increment the reference counter of the given goal.
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_get_quantifier_body(Z3_context c, Z3_ast a)
Return body of quantifier.
unsigned Z3_API Z3_get_num_probes(Z3_context c)
Return the number of builtin probes available in Z3.
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...
void Z3_API Z3_get_version(unsigned *major, unsigned *minor, unsigned *build_number, unsigned *revision_number)
Return Z3 version number information.
def __rmod__(self, other)
Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c, Z3_fixedpoint d, Z3_ast query)
Pose a query against the asserted rules.
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c)
Create the Boolean type.
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_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.
def __deepcopy__(self, memo={})
def __deepcopy__(self, memo={})
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_bvudiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned division.
def __init__(self, m=None, ctx=None)
def recognizer(self, idx)
def BitVecSort(sz, ctx=None)
void Z3_API Z3_params_inc_ref(Z3_context c, Z3_params p)
Increment the reference counter of the given parameter set.
def __getitem__(self, arg)
def PartialOrder(a, index)
def set_predicate_representation(self, f, *representations)
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.
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.
def IntVector(prefix, sz, ctx=None)
def fpAdd(rm, a, b, ctx=None)
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_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m)
Increment the reference counter of the given model.
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
def get_num_levels(self, predicate)
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_string Z3_API Z3_simplify_get_help(Z3_context c)
Return a string describing all available parameters.
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_seq_in_re(Z3_context c, Z3_ast seq, Z3_ast re)
Check if seq is in the language generated by the regular expression re.
def check(self, *assumptions)
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id)
create a linear ordering relation over signature a. The relation is identified by the index id.
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is negative.
def BV2Int(a, is_signed=False)
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
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_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_fpa_is_numeral_zero(Z3_context c, Z3_ast t)
Checks whether a given floating-point numeral is +zero or -zero.
Z3_symbol Z3_API Z3_mk_int_symbol(Z3_context c, int i)
Create a Z3 symbol using an integer.
Z3_sort Z3_API Z3_mk_fpa_sort_64(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
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_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.
def TryFor(t, ms, ctx=None)
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.
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_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...
def __init__(self, ctx=None, params=None)
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,...
def BVMulNoUnderflow(a, b)
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.
Z3_ast Z3_API Z3_mk_seq_empty(Z3_context c, Z3_sort seq)
Create an empty sequence of the sequence sort seq.
Z3_ast Z3_API Z3_mk_seq_to_re(Z3_context c, Z3_ast seq)
Create a regular expression that accepts the sequence seq.
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_fpa_zero(Z3_context c, Z3_sort s, bool negative)
Create a floating-point zero of sort s.
Z3_sort Z3_API Z3_mk_fpa_sort_double(Z3_context c)
Create the double-precision (64-bit) FloatingPoint sort.
def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None)
def __rmod__(self, other)
def __init__(self, ast, ctx=None)
Z3_ast Z3_API Z3_mk_bvurem(Z3_context c, Z3_ast t1, Z3_ast t2)
Unsigned remainder.
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.
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.
def __radd__(self, other)
def __init__(self, result, ctx)
def abstract(self, fml, is_forall=True)
def RecFunction(name, *sig)
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).
def fpToReal(x, ctx=None)
def __rtruediv__(self, other)
def set_option(*args, **kws)
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_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.
def __rlshift__(self, other)
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_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.
def add_cover(self, level, predicate, property)
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.
def __truediv__(self, other)
def evaluate(self, t, model_completion=False)
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative)
Create a floating-point infinity of sort s.
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d)
Alias for Z3_get_domain_size.
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.
def translate(self, other_ctx)
Z3_ast Z3_API Z3_mk_re_union(Z3_context c, unsigned n, Z3_ast const args[])
Create the union of the regular languages.
def prove(claim, **keywords)
def assert_exprs(self, *args)
def Reals(names, ctx=None)
void Z3_API Z3_probe_dec_ref(Z3_context c, Z3_probe p)
Decrement the reference counter of the given probe.
def __rpow__(self, other)
def fpInfinity(s, negative)
Z3_constructor_list Z3_API Z3_mk_constructor_list(Z3_context c, unsigned num_constructors, Z3_constructor const constructors[])
Create list of constructors.
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....
def __rdiv__(self, other)
def fpFPToFP(rm, v, sort, ctx=None)
def fpNEQ(a, b, ctx=None)
Z3_ast Z3_API Z3_goal_formula(Z3_context c, Z3_goal g, unsigned idx)
Return a formula from the given goal.
Z3_symbol Z3_API Z3_get_sort_name(Z3_context c, Z3_sort d)
Return the sort name as a symbol.
def Repeat(t, max=4294967295, ctx=None)
Z3_ast_vector Z3_API Z3_optimize_get_lower_as_vector(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective. The returned vector ...
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint f, Z3_params p)
Set parameters on fixedpoint context.
Z3_ast Z3_API Z3_mk_fpa_nan(Z3_context c, Z3_sort s)
Create a floating-point NaN of sort s.
def __getitem__(self, idx)
def SolverFor(logic, ctx=None)
def import_model_converter(self, other)
def ParThen(t1, t2, ctx=None)
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.
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_string Z3_API Z3_probe_get_descr(Z3_context c, Z3_string name)
Return a string containing a description of the probe with the given name.
Z3_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_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.
Z3_sort Z3_API Z3_mk_fpa_sort_16(Z3_context c)
Create the half-precision (16-bit) FloatingPoint sort.
def __rmul__(self, other)
Z3_bool Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value)
Get a global (or module) parameter.
void Z3_API Z3_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_sort Z3_API Z3_mk_fpa_sort_128(Z3_context c)
Create the quadruple-precision (128-bit) FloatingPoint sort.
def fpIsZero(a, ctx=None)
def __rand__(self, other)
def fpIsSubnormal(a, ctx=None)
Z3_ast Z3_API Z3_mk_seq_unit(Z3_context c, Z3_ast a)
Create a unit sequence of a.
void Z3_API Z3_solver_dec_ref(Z3_context c, Z3_solver s)
Decrement the reference counter of the given solver.
void Z3_API Z3_inc_ref(Z3_context c, Z3_ast a)
Increment the reference counter of the given AST. The context c should have been created using Z3_mk_...
def __deepcopy__(self, memo={})
Z3_ast Z3_API Z3_mk_numeral(Z3_context c, Z3_string numeral, Z3_sort ty)
Create a numeral of a given sort.
void Z3_API Z3_func_entry_dec_ref(Z3_context c, Z3_func_entry e)
Decrement the reference counter of the given Z3_func_entry object.
def fpRealToFP(rm, v, sort, ctx=None)
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
def __deepcopy__(self, memo={})
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.
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
def __truediv__(self, other)
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.
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....
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_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_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_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_fixedpoint_to_string(Z3_context c, Z3_fixedpoint f, unsigned num_queries, Z3_ast queries[])
Print the current rules and background axioms as a string.
Z3_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.
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.
def fpIsPositive(a, ctx=None)
def __rsub__(self, other)
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
Z3_ast Z3_API Z3_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_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_func_decl Z3_API Z3_get_datatype_sort_constructor(Z3_context c, Z3_sort t, unsigned idx)
Return idx'th constructor.
def is_algebraic_value(a)
unsigned Z3_API Z3_solver_get_num_scopes(Z3_context c, Z3_solver s)
Return the number of backtracking points.
void Z3_API Z3_tactic_dec_ref(Z3_context c, Z3_tactic g)
Decrement the reference counter of the given tactic.
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.
def __deepcopy__(self, memo={})
def String(name, ctx=None)
def __deepcopy__(self, memo={})
def __radd__(self, other)
def translate(self, target)
Z3_ast Z3_API Z3_mk_int_to_str(Z3_context c, Z3_ast s)
Integer to string conversion.
def __lshift__(self, other)
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
Z3_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.
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a)
Determine if ast is a lambda expression.
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_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_ast Z3_API Z3_mk_seq_last_index(Z3_context c, Z3_ast, Z3_ast substr)
Return the last occurrence of substr in s. If s does not contain substr, then the value is -1,...
Z3_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...
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_ast Z3_API Z3_mk_seq_contains(Z3_context c, Z3_ast container, Z3_ast containee)
Check if container contains containee.
Z3_ast Z3_API Z3_mk_zero_ext(Z3_context c, unsigned i, Z3_ast t1)
Extend the given bit-vector with zeros to the (unsigned) equivalent bit-vector of size m+i,...
Z3_string Z3_API Z3_model_to_string(Z3_context c, Z3_model m)
Convert the given model into a string.
def SimpleSolver(ctx=None)
def __rsub__(self, other)
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, Z3_string prefix, Z3_sort ty)
Declare and create a fresh constant.