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
58 return isinstance(v, (int, long))
61 return isinstance(v, int)
70 major = ctypes.c_uint(0)
71 minor = ctypes.c_uint(0)
72 build = ctypes.c_uint(0)
73 rev = ctypes.c_uint(0)
75 return "%s.%s.%s" % (major.value, minor.value, build.value)
78 major = ctypes.c_uint(0)
79 minor = ctypes.c_uint(0)
80 build = ctypes.c_uint(0)
81 rev = ctypes.c_uint(0)
83 return (major.value, minor.value, build.value, rev.value)
90 def _z3_assert(cond, msg):
92 raise Z3Exception(msg)
94 def _z3_check_cint_overflow(n, name):
95 _z3_assert(ctypes.c_int(n).value == n, name +
" is too large")
98 """Log interaction to a file. This function must be invoked immediately after init(). """ 102 """Append user-defined string to interaction log. """ 106 """Convert an integer or string into a Z3 symbol.""" 112 def _symbol2py(ctx, s):
113 """Convert a Z3 symbol back into a Python object. """ 124 if len(args) == 1
and (isinstance(args[0], tuple)
or isinstance(args[0], list)):
126 elif len(args) == 1
and (isinstance(args[0], set)
or isinstance(args[0], AstVector)):
127 return [arg
for arg
in args[0]]
134 def _get_args_ast_list(args):
136 if isinstance(args, set)
or isinstance(args, AstVector)
or isinstance(args, tuple):
137 return [arg
for arg
in args]
143 def _to_param_value(val):
144 if isinstance(val, bool):
158 """A Context manages all other Z3 objects, global configuration options, etc. 160 Z3Py uses a default global context. For most applications this is sufficient. 161 An application may use multiple Z3 contexts. Objects created in one context 162 cannot be used in another one. However, several objects may be "translated" from 163 one context to another. It is not safe to access Z3 objects from multiple threads. 164 The only exception is the method `interrupt()` that can be used to interrupt() a long 166 The initialization method receives global configuration options for the new context. 170 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
193 """Return a reference to the actual C pointer to the Z3 context.""" 197 """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions. 199 This method can be invoked from a thread different from the one executing the 200 interruptible procedure. 208 """Return a reference to the global Z3 context. 211 >>> x.ctx == main_ctx() 216 >>> x2 = Real('x', c) 223 if _main_ctx
is None:
234 """Set Z3 global (or module) parameters. 236 >>> set_param(precision=10) 239 _z3_assert(len(args) % 2 == 0,
"Argument list must have an even number of elements.")
243 if not set_pp_option(k, v):
257 """Reset all global (or module) parameters. 262 """Alias for 'set_param' for backward compatibility. 267 """Return the value of a Z3 global (or module) parameter 269 >>> get_param('nlsat.reorder') 272 ptr = (ctypes.c_char_p * 1)()
274 r = z3core._to_pystr(ptr[0])
276 raise Z3Exception(
"failed to retrieve value for '%s'" % name)
286 """Superclass for all Z3 objects that have support for pretty printing.""" 291 """AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions.""" 298 if self.
ctx.ref()
is not None:
302 return _to_ast_ref(self.
ast, self.
ctx)
305 return obj_to_string(self)
308 return obj_to_string(self)
311 return self.
eq(other)
324 elif is_eq(self)
and self.num_args() == 2:
325 return self.arg(0).
eq(self.arg(1))
327 raise Z3Exception(
"Symbolic expressions cannot be cast to concrete Boolean values.")
330 """Return a string representing the AST node in s-expression notation. 333 >>> ((x + 1)*x).sexpr() 339 """Return a pointer to the corresponding C Z3_ast object.""" 343 """Return unique identifier for object. It can be used for hash-tables and maps.""" 347 """Return a reference to the C context where this AST node is stored.""" 348 return self.
ctx.ref()
351 """Return `True` if `self` and `other` are structurally identical. 358 >>> n1 = simplify(n1) 359 >>> n2 = simplify(n2) 364 _z3_assert(
is_ast(other),
"Z3 AST expected")
368 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 374 >>> # Nodes in different contexts can't be mixed. 375 >>> # However, we can translate nodes from one context to another. 376 >>> x.translate(c2) + y 380 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
387 """Return a hashcode for the `self`. 389 >>> n1 = simplify(Int('x') + 1) 390 >>> n2 = simplify(2 + Int('x') - 1) 391 >>> n1.hash() == n2.hash() 397 """Return `True` if `a` is an AST node. 401 >>> is_ast(IntVal(10)) 405 >>> is_ast(BoolSort()) 407 >>> is_ast(Function('f', IntSort(), IntSort())) 414 return isinstance(a, AstRef)
417 """Return `True` if `a` and `b` are structurally identical AST nodes. 427 >>> eq(simplify(x + 1), simplify(1 + x)) 434 def _ast_kind(ctx, a):
439 def _ctx_from_ast_arg_list(args, default_ctx=None):
447 _z3_assert(ctx == a.ctx,
"Context mismatch")
452 def _ctx_from_ast_args(*args):
453 return _ctx_from_ast_arg_list(args)
455 def _to_func_decl_array(args):
457 _args = (FuncDecl * sz)()
459 _args[i] = args[i].as_func_decl()
462 def _to_ast_array(args):
466 _args[i] = args[i].as_ast()
469 def _to_ref_array(ref, args):
473 _args[i] = args[i].as_ast()
476 def _to_ast_ref(a, ctx):
477 k = _ast_kind(ctx, a)
479 return _to_sort_ref(a, ctx)
480 elif k == Z3_FUNC_DECL_AST:
481 return _to_func_decl_ref(a, ctx)
483 return _to_expr_ref(a, ctx)
491 def _sort_kind(ctx, s):
495 """A Sort is essentially a type. Every Z3 expression has a sort. A sort is an AST node.""" 503 """Return the Z3 internal kind of a sort. This method can be used to test if `self` is one of the Z3 builtin sorts. 506 >>> b.kind() == Z3_BOOL_SORT 508 >>> b.kind() == Z3_INT_SORT 510 >>> A = ArraySort(IntSort(), IntSort()) 511 >>> A.kind() == Z3_ARRAY_SORT 513 >>> A.kind() == Z3_INT_SORT 516 return _sort_kind(self.
ctx, self.
ast)
519 """Return `True` if `self` is a subsort of `other`. 521 >>> IntSort().subsort(RealSort()) 527 """Try to cast `val` as an element of sort `self`. 529 This method is used in Z3Py to convert Python objects such as integers, 530 floats, longs and strings into Z3 expressions. 533 >>> RealSort().cast(x) 537 _z3_assert(
is_expr(val),
"Z3 expression expected")
538 _z3_assert(self.
eq(val.sort()),
"Sort mismatch")
542 """Return the name (string) of sort `self`. 544 >>> BoolSort().name() 546 >>> ArraySort(IntSort(), IntSort()).name() 552 """Return `True` if `self` and `other` are the same Z3 sort. 555 >>> p.sort() == BoolSort() 557 >>> p.sort() == IntSort() 565 """Return `True` if `self` and `other` are not the same Z3 sort. 568 >>> p.sort() != BoolSort() 570 >>> p.sort() != IntSort() 577 return AstRef.__hash__(self)
580 """Return `True` if `s` is a Z3 sort. 582 >>> is_sort(IntSort()) 584 >>> is_sort(Int('x')) 586 >>> is_expr(Int('x')) 589 return isinstance(s, SortRef)
591 def _to_sort_ref(s, ctx):
593 _z3_assert(isinstance(s, Sort),
"Z3 Sort expected")
594 k = _sort_kind(ctx, s)
595 if k == Z3_BOOL_SORT:
597 elif k == Z3_INT_SORT
or k == Z3_REAL_SORT:
599 elif k == Z3_BV_SORT:
601 elif k == Z3_ARRAY_SORT:
603 elif k == Z3_DATATYPE_SORT:
605 elif k == Z3_FINITE_DOMAIN_SORT:
607 elif k == Z3_FLOATING_POINT_SORT:
609 elif k == Z3_ROUNDING_MODE_SORT:
614 return _to_sort_ref(
Z3_get_sort(ctx.ref(), a), ctx)
617 """Create a new uninterpreted sort named `name`. 619 If `ctx=None`, then the new sort is declared in the global Z3Py context. 621 >>> A = DeclareSort('A') 622 >>> a = Const('a', A) 623 >>> b = Const('b', A) 641 """Function declaration. Every constant and function have an associated declaration. 643 The declaration assigns a name, a sort (i.e., type), and for function 644 the sort (i.e., type) of each of its arguments. Note that, in Z3, 645 a constant is a function with 0 arguments. 657 """Return the name of the function declaration `self`. 659 >>> f = Function('f', IntSort(), IntSort()) 662 >>> isinstance(f.name(), str) 668 """Return the number of arguments of a function declaration. If `self` is a constant, then `self.arity()` is 0. 670 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 677 """Return the sort of the argument `i` of a function declaration. This method assumes that `0 <= i < self.arity()`. 679 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 686 _z3_assert(i < self.
arity(),
"Index out of bounds")
690 """Return the sort of the range of a function declaration. For constants, this is the sort of the constant. 692 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 699 """Return the internal kind of a function declaration. It can be used to identify Z3 built-in functions such as addition, multiplication, etc. 702 >>> d = (x + 1).decl() 703 >>> d.kind() == Z3_OP_ADD 705 >>> d.kind() == Z3_OP_MUL 713 result = [
None for i
in range(n) ]
716 if k == Z3_PARAMETER_INT:
718 elif k == Z3_PARAMETER_DOUBLE:
720 elif k == Z3_PARAMETER_RATIONAL:
722 elif k == Z3_PARAMETER_SYMBOL:
724 elif k == Z3_PARAMETER_SORT:
726 elif k == Z3_PARAMETER_AST:
728 elif k == Z3_PARAMETER_FUNC_DECL:
735 """Create a Z3 application expression using the function `self`, and the given arguments. 737 The arguments must be Z3 expressions. This method assumes that 738 the sorts of the elements in `args` match the sorts of the 739 domain. Limited coercion is supported. For example, if 740 args[0] is a Python integer, and the function expects a Z3 741 integer, then the argument is automatically converted into a 744 >>> f = Function('f', IntSort(), RealSort(), BoolSort()) 752 args = _get_args(args)
755 _z3_assert(num == self.
arity(),
"Incorrect number of arguments to %s" % self)
756 _args = (Ast * num)()
761 tmp = self.
domain(i).cast(args[i])
763 _args[i] = tmp.as_ast()
767 """Return `True` if `a` is a Z3 function declaration. 769 >>> f = Function('f', IntSort(), IntSort()) 776 return isinstance(a, FuncDeclRef)
779 """Create a new Z3 uninterpreted function with the given sorts. 781 >>> f = Function('f', IntSort(), IntSort()) 787 _z3_assert(len(sig) > 0,
"At least two arguments expected")
791 _z3_assert(
is_sort(rng),
"Z3 sort expected")
792 dom = (Sort * arity)()
793 for i
in range(arity):
795 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
800 def _to_func_decl_ref(a, ctx):
804 """Create a new Z3 recursive with the given sorts.""" 807 _z3_assert(len(sig) > 0,
"At least two arguments expected")
811 _z3_assert(
is_sort(rng),
"Z3 sort expected")
812 dom = (Sort * arity)()
813 for i
in range(arity):
815 _z3_assert(
is_sort(sig[i]),
"Z3 sort expected")
821 """Set the body of a recursive function. 822 Recursive definitions are only unfolded during search. 824 >>> fac = RecFunction('fac', IntSort(ctx), IntSort(ctx)) 825 >>> n = Int('n', ctx) 826 >>> RecAddDefinition(fac, n, If(n == 0, 1, n*fac(n-1))) 829 >>> s = Solver(ctx=ctx) 830 >>> s.add(fac(n) < 3) 833 >>> s.model().eval(fac(5)) 839 args = _get_args(args)
843 _args[i] = args[i].ast
853 """Constraints, formulas and terms are expressions in Z3. 855 Expressions are ASTs. Every expression has a sort. 856 There are three main kinds of expressions: 857 function applications, quantifiers and bounded variables. 858 A constant is a function application with 0 arguments. 859 For quantifier free problems, all expressions are 860 function applications. 869 """Return the sort of expression `self`. 881 """Shorthand for `self.sort().kind()`. 883 >>> a = Array('a', IntSort(), IntSort()) 884 >>> a.sort_kind() == Z3_ARRAY_SORT 886 >>> a.sort_kind() == Z3_INT_SORT 889 return self.
sort().kind()
892 """Return a Z3 expression that represents the constraint `self == other`. 894 If `other` is `None`, then this method simply returns `False`. 905 a, b = _coerce_exprs(self, other)
910 return AstRef.__hash__(self)
913 """Return a Z3 expression that represents the constraint `self != other`. 915 If `other` is `None`, then this method simply returns `True`. 926 a, b = _coerce_exprs(self, other)
927 _args, sz = _to_ast_array((a, b))
934 """Return the Z3 function declaration associated with a Z3 application. 936 >>> f = Function('f', IntSort(), IntSort()) 945 _z3_assert(
is_app(self),
"Z3 application expected")
949 """Return the number of arguments of a Z3 application. 953 >>> (a + b).num_args() 955 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort()) 961 _z3_assert(
is_app(self),
"Z3 application expected")
965 """Return argument `idx` of the application `self`. 967 This method assumes that `self` is a function application with at least `idx+1` arguments. 971 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort()) 981 _z3_assert(
is_app(self),
"Z3 application expected")
982 _z3_assert(idx < self.
num_args(),
"Invalid argument index")
986 """Return a list containing the children of the given expression 990 >>> f = Function('f', IntSort(), IntSort(), IntSort(), IntSort()) 1000 def _to_expr_ref(a, ctx):
1001 if isinstance(a, Pattern):
1005 if k == Z3_QUANTIFIER_AST:
1008 if sk == Z3_BOOL_SORT:
1010 if sk == Z3_INT_SORT:
1011 if k == Z3_NUMERAL_AST:
1014 if sk == Z3_REAL_SORT:
1015 if k == Z3_NUMERAL_AST:
1017 if _is_algebraic(ctx, a):
1020 if sk == Z3_BV_SORT:
1021 if k == Z3_NUMERAL_AST:
1025 if sk == Z3_ARRAY_SORT:
1027 if sk == Z3_DATATYPE_SORT:
1029 if sk == Z3_FLOATING_POINT_SORT:
1030 if k == Z3_APP_AST
and _is_numeral(ctx, a):
1033 return FPRef(a, ctx)
1034 if sk == Z3_FINITE_DOMAIN_SORT:
1035 if k == Z3_NUMERAL_AST:
1039 if sk == Z3_ROUNDING_MODE_SORT:
1041 if sk == Z3_SEQ_SORT:
1043 if sk == Z3_RE_SORT:
1044 return ReRef(a, ctx)
1047 def _coerce_expr_merge(s, a):
1060 _z3_assert(s1.ctx == s.ctx,
"context mismatch")
1061 _z3_assert(
False,
"sort mismatch")
1065 def _coerce_exprs(a, b, ctx=None):
1067 a = _py2expr(a, ctx)
1068 b = _py2expr(b, ctx)
1070 s = _coerce_expr_merge(s, a)
1071 s = _coerce_expr_merge(s, b)
1077 def _reduce(f, l, a):
1083 def _coerce_expr_list(alist, ctx=None):
1090 alist = [ _py2expr(a, ctx)
for a
in alist ]
1091 s = _reduce(_coerce_expr_merge, alist,
None)
1092 return [ s.cast(a)
for a
in alist ]
1095 """Return `True` if `a` is a Z3 expression. 1102 >>> is_expr(IntSort()) 1106 >>> is_expr(IntVal(1)) 1109 >>> is_expr(ForAll(x, x >= 0)) 1111 >>> is_expr(FPVal(1.0)) 1114 return isinstance(a, ExprRef)
1117 """Return `True` if `a` is a Z3 function application. 1119 Note that, constants are function applications with 0 arguments. 1126 >>> is_app(IntSort()) 1130 >>> is_app(IntVal(1)) 1133 >>> is_app(ForAll(x, x >= 0)) 1136 if not isinstance(a, ExprRef):
1138 k = _ast_kind(a.ctx, a)
1139 return k == Z3_NUMERAL_AST
or k == Z3_APP_AST
1142 """Return `True` if `a` is Z3 constant/variable expression. 1151 >>> is_const(IntVal(1)) 1154 >>> is_const(ForAll(x, x >= 0)) 1157 return is_app(a)
and a.num_args() == 0
1160 """Return `True` if `a` is variable. 1162 Z3 uses de-Bruijn indices for representing bound variables in 1170 >>> f = Function('f', IntSort(), IntSort()) 1171 >>> # Z3 replaces x with bound variables when ForAll is executed. 1172 >>> q = ForAll(x, f(x) == x) 1178 >>> is_var(b.arg(1)) 1181 return is_expr(a)
and _ast_kind(a.ctx, a) == Z3_VAR_AST
1184 """Return the de-Bruijn index of the Z3 bounded variable `a`. 1192 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 1193 >>> # Z3 replaces x and y with bound variables when ForAll is executed. 1194 >>> q = ForAll([x, y], f(x, y) == x + y) 1196 f(Var(1), Var(0)) == Var(1) + Var(0) 1200 >>> v1 = b.arg(0).arg(0) 1201 >>> v2 = b.arg(0).arg(1) 1206 >>> get_var_index(v1) 1208 >>> get_var_index(v2) 1212 _z3_assert(
is_var(a),
"Z3 bound variable expected")
1216 """Return `True` if `a` is an application of the given kind `k`. 1220 >>> is_app_of(n, Z3_OP_ADD) 1222 >>> is_app_of(n, Z3_OP_MUL) 1225 return is_app(a)
and a.decl().kind() == k
1227 def If(a, b, c, ctx=None):
1228 """Create a Z3 if-then-else expression. 1232 >>> max = If(x > y, x, y) 1238 if isinstance(a, Probe)
or isinstance(b, Tactic)
or isinstance(c, Tactic):
1239 return Cond(a, b, c, ctx)
1241 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx))
1244 b, c = _coerce_exprs(b, c, ctx)
1246 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1247 return _to_expr_ref(
Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
1250 """Create a Z3 distinct expression. 1257 >>> Distinct(x, y, z) 1259 >>> simplify(Distinct(x, y, z)) 1261 >>> simplify(Distinct(x, y, z), blast_distinct=True) 1262 And(Not(x == y), Not(x == z), Not(y == z)) 1264 args = _get_args(args)
1265 ctx = _ctx_from_ast_arg_list(args)
1267 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
1268 args = _coerce_expr_list(args, ctx)
1269 _args, sz = _to_ast_array(args)
1272 def _mk_bin(f, a, b):
1275 _z3_assert(a.ctx == b.ctx,
"Context mismatch")
1276 args[0] = a.as_ast()
1277 args[1] = b.as_ast()
1278 return f(a.ctx.ref(), 2, args)
1281 """Create a constant of the given sort. 1283 >>> Const('x', IntSort()) 1287 _z3_assert(isinstance(sort, SortRef),
"Z3 sort expected")
1292 """Create a several constants of the given sort. 1294 `names` is a string containing the names of all constants to be created. 1295 Blank spaces separate the names of different constants. 1297 >>> x, y, z = Consts('x y z', IntSort()) 1301 if isinstance(names, str):
1302 names = names.split(
" ")
1303 return [
Const(name, sort)
for name
in names]
1306 """Create a fresh constant of a specified sort""" 1307 ctx = _get_ctx(sort.ctx)
1311 """Create a Z3 free variable. Free variables are used to create quantified formulas. 1313 >>> Var(0, IntSort()) 1315 >>> eq(Var(0, IntSort()), Var(0, BoolSort())) 1319 _z3_assert(
is_sort(s),
"Z3 sort expected")
1320 return _to_expr_ref(
Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
1324 Create a real free variable. Free variables are used to create quantified formulas. 1325 They are also used to create polynomials. 1334 Create a list of Real free variables. 1335 The variables have ids: 0, 1, ..., n-1 1337 >>> x0, x1, x2, x3 = RealVarVector(4) 1352 """Try to cast `val` as a Boolean. 1354 >>> x = BoolSort().cast(True) 1364 if isinstance(val, bool):
1368 _z3_assert(
is_expr(val),
"True, False or Z3 Boolean expression expected. Received %s" % val)
1369 if not self.
eq(val.sort()):
1370 _z3_assert(self.
eq(val.sort()),
"Value cannot be converted into a Z3 Boolean value")
1374 return isinstance(other, ArithSortRef)
1384 """All Boolean expressions are instances of this class.""" 1392 """Create the Z3 expression `self * other`. 1398 return If(self, other, 0)
1402 """Return `True` if `a` is a Z3 Boolean expression. 1408 >>> is_bool(And(p, q)) 1416 return isinstance(a, BoolRef)
1419 """Return `True` if `a` is the Z3 true expression. 1424 >>> is_true(simplify(p == p)) 1429 >>> # True is a Python Boolean expression 1436 """Return `True` if `a` is the Z3 false expression. 1443 >>> is_false(BoolVal(False)) 1449 """Return `True` if `a` is a Z3 and expression. 1451 >>> p, q = Bools('p q') 1452 >>> is_and(And(p, q)) 1454 >>> is_and(Or(p, q)) 1460 """Return `True` if `a` is a Z3 or expression. 1462 >>> p, q = Bools('p q') 1465 >>> is_or(And(p, q)) 1471 """Return `True` if `a` is a Z3 implication expression. 1473 >>> p, q = Bools('p q') 1474 >>> is_implies(Implies(p, q)) 1476 >>> is_implies(And(p, q)) 1482 """Return `True` if `a` is a Z3 not expression. 1493 """Return `True` if `a` is a Z3 equality expression. 1495 >>> x, y = Ints('x y') 1502 """Return `True` if `a` is a Z3 distinct expression. 1504 >>> x, y, z = Ints('x y z') 1505 >>> is_distinct(x == y) 1507 >>> is_distinct(Distinct(x, y, z)) 1513 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used. 1517 >>> p = Const('p', BoolSort()) 1520 >>> r = Function('r', IntSort(), IntSort(), BoolSort()) 1523 >>> is_bool(r(0, 1)) 1530 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used. 1534 >>> is_true(BoolVal(True)) 1538 >>> is_false(BoolVal(False)) 1548 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used. 1559 """Return a tuple of Boolean constants. 1561 `names` is a single string containing all names separated by blank spaces. 1562 If `ctx=None`, then the global context is used. 1564 >>> p, q, r = Bools('p q r') 1565 >>> And(p, Or(q, r)) 1569 if isinstance(names, str):
1570 names = names.split(
" ")
1571 return [
Bool(name, ctx)
for name
in names]
1574 """Return a list of Boolean constants of size `sz`. 1576 The constants are named using the given prefix. 1577 If `ctx=None`, then the global context is used. 1579 >>> P = BoolVector('p', 3) 1583 And(p__0, p__1, p__2) 1585 return [
Bool(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
1588 """Return a fresh Boolean constant in the given context using the given prefix. 1590 If `ctx=None`, then the global context is used. 1592 >>> b1 = FreshBool() 1593 >>> b2 = FreshBool() 1601 """Create a Z3 implies expression. 1603 >>> p, q = Bools('p q') 1606 >>> simplify(Implies(p, q)) 1609 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1616 """Create a Z3 Xor expression. 1618 >>> p, q = Bools('p q') 1621 >>> simplify(Xor(p, q)) 1624 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx))
1631 """Create a Z3 not expression or probe. 1636 >>> simplify(Not(Not(p))) 1639 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
1654 def _has_probe(args):
1655 """Return `True` if one of the elements of the given collection is a Z3 probe.""" 1662 """Create a Z3 and-expression or and-probe. 1664 >>> p, q, r = Bools('p q r') 1667 >>> P = BoolVector('p', 5) 1669 And(p__0, p__1, p__2, p__3, p__4) 1673 last_arg = args[len(args)-1]
1674 if isinstance(last_arg, Context):
1675 ctx = args[len(args)-1]
1676 args = args[:len(args)-1]
1677 elif len(args) == 1
and isinstance(args[0], AstVector):
1679 args = [a
for a
in args[0]]
1682 args = _get_args(args)
1683 ctx_args = _ctx_from_ast_arg_list(args, ctx)
1685 _z3_assert(ctx_args
is None or ctx_args == ctx,
"context mismatch")
1686 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1687 if _has_probe(args):
1688 return _probe_and(args, ctx)
1690 args = _coerce_expr_list(args, ctx)
1691 _args, sz = _to_ast_array(args)
1695 """Create a Z3 or-expression or or-probe. 1697 >>> p, q, r = Bools('p q r') 1700 >>> P = BoolVector('p', 5) 1702 Or(p__0, p__1, p__2, p__3, p__4) 1706 last_arg = args[len(args)-1]
1707 if isinstance(last_arg, Context):
1708 ctx = args[len(args)-1]
1709 args = args[:len(args)-1]
1712 args = _get_args(args)
1713 ctx_args = _ctx_from_ast_arg_list(args, ctx)
1715 _z3_assert(ctx_args
is None or ctx_args == ctx,
"context mismatch")
1716 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression or probe")
1717 if _has_probe(args):
1718 return _probe_or(args, ctx)
1720 args = _coerce_expr_list(args, ctx)
1721 _args, sz = _to_ast_array(args)
1731 """Patterns are hints for quantifier instantiation. 1741 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation. 1743 >>> f = Function('f', IntSort(), IntSort()) 1745 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ]) 1747 ForAll(x, f(x) == 0) 1748 >>> q.num_patterns() 1750 >>> is_pattern(q.pattern(0)) 1755 return isinstance(a, PatternRef)
1758 """Create a Z3 multi-pattern using the given expressions `*args` 1760 >>> f = Function('f', IntSort(), IntSort()) 1761 >>> g = Function('g', IntSort(), IntSort()) 1763 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ]) 1765 ForAll(x, f(x) != g(x)) 1766 >>> q.num_patterns() 1768 >>> is_pattern(q.pattern(0)) 1771 MultiPattern(f(Var(0)), g(Var(0))) 1774 _z3_assert(len(args) > 0,
"At least one argument expected")
1775 _z3_assert(all([
is_expr(a)
for a
in args ]),
"Z3 expressions expected")
1777 args, sz = _to_ast_array(args)
1780 def _to_pattern(arg):
1793 """Universally and Existentially quantified formulas.""" 1802 """Return the Boolean sort or sort of Lambda.""" 1808 """Return `True` if `self` is a universal quantifier. 1810 >>> f = Function('f', IntSort(), IntSort()) 1812 >>> q = ForAll(x, f(x) == 0) 1815 >>> q = Exists(x, f(x) != 0) 1822 """Return `True` if `self` is an existential quantifier. 1824 >>> f = Function('f', IntSort(), IntSort()) 1826 >>> q = ForAll(x, f(x) == 0) 1829 >>> q = Exists(x, f(x) != 0) 1836 """Return `True` if `self` is a lambda expression. 1838 >>> f = Function('f', IntSort(), IntSort()) 1840 >>> q = Lambda(x, f(x)) 1843 >>> q = Exists(x, f(x) != 0) 1850 """Return the weight annotation of `self`. 1852 >>> f = Function('f', IntSort(), IntSort()) 1854 >>> q = ForAll(x, f(x) == 0) 1857 >>> q = ForAll(x, f(x) == 0, weight=10) 1864 """Return the number of patterns (i.e., quantifier instantiation hints) in `self`. 1866 >>> f = Function('f', IntSort(), IntSort()) 1867 >>> g = Function('g', IntSort(), IntSort()) 1869 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ]) 1870 >>> q.num_patterns() 1876 """Return a pattern (i.e., quantifier instantiation hints) in `self`. 1878 >>> f = Function('f', IntSort(), IntSort()) 1879 >>> g = Function('g', IntSort(), IntSort()) 1881 >>> q = ForAll(x, f(x) != g(x), patterns = [ f(x), g(x) ]) 1882 >>> q.num_patterns() 1890 _z3_assert(idx < self.
num_patterns(),
"Invalid pattern idx")
1894 """Return the number of no-patterns.""" 1898 """Return a no-pattern.""" 1904 """Return the expression being quantified. 1906 >>> f = Function('f', IntSort(), IntSort()) 1908 >>> q = ForAll(x, f(x) == 0) 1915 """Return the number of variables bounded by this quantifier. 1917 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 1920 >>> q = ForAll([x, y], f(x, y) >= x) 1927 """Return a string representing a name used when displaying the quantifier. 1929 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 1932 >>> q = ForAll([x, y], f(x, y) >= x) 1939 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
1943 """Return the sort of a bound variable. 1945 >>> f = Function('f', IntSort(), RealSort(), IntSort()) 1948 >>> q = ForAll([x, y], f(x, y) >= x) 1955 _z3_assert(idx < self.
num_vars(),
"Invalid variable idx")
1959 """Return a list containing a single element self.body() 1961 >>> f = Function('f', IntSort(), IntSort()) 1963 >>> q = ForAll(x, f(x) == 0) 1967 return [ self.
body() ]
1970 """Return `True` if `a` is a Z3 quantifier. 1972 >>> f = Function('f', IntSort(), IntSort()) 1974 >>> q = ForAll(x, f(x) == 0) 1975 >>> is_quantifier(q) 1977 >>> is_quantifier(f(x)) 1980 return isinstance(a, QuantifierRef)
1982 def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
1984 _z3_assert(
is_bool(body)
or is_app(vs)
or (len(vs) > 0
and is_app(vs[0])),
"Z3 expression expected")
1985 _z3_assert(
is_const(vs)
or (len(vs) > 0
and all([
is_const(v)
for v
in vs])),
"Invalid bounded variable(s)")
1986 _z3_assert(all([
is_pattern(a)
or is_expr(a)
for a
in patterns]),
"Z3 patterns expected")
1987 _z3_assert(all([
is_expr(p)
for p
in no_patterns]),
"no patterns are Z3 expressions")
1998 _vs = (Ast * num_vars)()
1999 for i
in range(num_vars):
2001 _vs[i] = vs[i].as_ast()
2002 patterns = [ _to_pattern(p)
for p
in patterns ]
2003 num_pats = len(patterns)
2004 _pats = (Pattern * num_pats)()
2005 for i
in range(num_pats):
2006 _pats[i] = patterns[i].ast
2007 _no_pats, num_no_pats = _to_ast_array(no_patterns)
2013 num_no_pats, _no_pats,
2014 body.as_ast()), ctx)
2016 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2017 """Create a Z3 forall formula. 2019 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations. 2021 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 2024 >>> ForAll([x, y], f(x, y) >= x) 2025 ForAll([x, y], f(x, y) >= x) 2026 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ]) 2027 ForAll([x, y], f(x, y) >= x) 2028 >>> ForAll([x, y], f(x, y) >= x, weight=10) 2029 ForAll([x, y], f(x, y) >= x) 2031 return _mk_quantifier(
True, vs, body, weight, qid, skid, patterns, no_patterns)
2033 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
2034 """Create a Z3 exists formula. 2036 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations. 2039 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 2042 >>> q = Exists([x, y], f(x, y) >= x, skid="foo") 2044 Exists([x, y], f(x, y) >= x) 2045 >>> is_quantifier(q) 2047 >>> r = Tactic('nnf')(q).as_expr() 2048 >>> is_quantifier(r) 2051 return _mk_quantifier(
False, vs, body, weight, qid, skid, patterns, no_patterns)
2054 """Create a Z3 lambda expression. 2056 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 2057 >>> mem0 = Array('mem0', IntSort(), IntSort()) 2058 >>> lo, hi, e, i = Ints('lo hi e i') 2059 >>> mem1 = Lambda([i], If(And(lo <= i, i <= hi), e, mem0[i])) 2061 Lambda(i, If(And(lo <= i, i <= hi), e, mem0[i])) 2067 _vs = (Ast * num_vars)()
2068 for i
in range(num_vars):
2070 _vs[i] = vs[i].as_ast()
2080 """Real and Integer sorts.""" 2083 """Return `True` if `self` is of the sort Real. 2088 >>> (x + 1).is_real() 2094 return self.
kind() == Z3_REAL_SORT
2097 """Return `True` if `self` is of the sort Integer. 2102 >>> (x + 1).is_int() 2108 return self.
kind() == Z3_INT_SORT
2111 """Return `True` if `self` is a subsort of `other`.""" 2115 """Try to cast `val` as an Integer or Real. 2117 >>> IntSort().cast(10) 2119 >>> is_int(IntSort().cast(10)) 2123 >>> RealSort().cast(10) 2125 >>> is_real(RealSort().cast(10)) 2130 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
2134 if val_s.is_int()
and self.
is_real():
2136 if val_s.is_bool()
and self.
is_int():
2137 return If(val, 1, 0)
2138 if val_s.is_bool()
and self.
is_real():
2141 _z3_assert(
False,
"Z3 Integer/Real expression expected" )
2148 _z3_assert(
False,
"int, long, float, string (numeral), or Z3 Integer/Real expression expected. Got %s" % self)
2151 """Return `True` if s is an arithmetical sort (type). 2153 >>> is_arith_sort(IntSort()) 2155 >>> is_arith_sort(RealSort()) 2157 >>> is_arith_sort(BoolSort()) 2159 >>> n = Int('x') + 1 2160 >>> is_arith_sort(n.sort()) 2163 return isinstance(s, ArithSortRef)
2166 """Integer and Real expressions.""" 2169 """Return the sort (type) of the arithmetical expression `self`. 2173 >>> (Real('x') + 1).sort() 2179 """Return `True` if `self` is an integer expression. 2184 >>> (x + 1).is_int() 2187 >>> (x + y).is_int() 2193 """Return `True` if `self` is an real expression. 2198 >>> (x + 1).is_real() 2204 """Create the Z3 expression `self + other`. 2213 a, b = _coerce_exprs(self, other)
2214 return ArithRef(_mk_bin(Z3_mk_add, a, b), self.
ctx)
2217 """Create the Z3 expression `other + self`. 2223 a, b = _coerce_exprs(self, other)
2224 return ArithRef(_mk_bin(Z3_mk_add, b, a), self.
ctx)
2227 """Create the Z3 expression `self * other`. 2236 if isinstance(other, BoolRef):
2237 return If(other, self, 0)
2238 a, b = _coerce_exprs(self, other)
2239 return ArithRef(_mk_bin(Z3_mk_mul, a, b), self.
ctx)
2242 """Create the Z3 expression `other * self`. 2248 a, b = _coerce_exprs(self, other)
2249 return ArithRef(_mk_bin(Z3_mk_mul, b, a), self.
ctx)
2252 """Create the Z3 expression `self - other`. 2261 a, b = _coerce_exprs(self, other)
2262 return ArithRef(_mk_bin(Z3_mk_sub, a, b), self.
ctx)
2265 """Create the Z3 expression `other - self`. 2271 a, b = _coerce_exprs(self, other)
2272 return ArithRef(_mk_bin(Z3_mk_sub, b, a), self.
ctx)
2275 """Create the Z3 expression `self**other` (** is the power operator). 2282 >>> simplify(IntVal(2)**8) 2285 a, b = _coerce_exprs(self, other)
2289 """Create the Z3 expression `other**self` (** is the power operator). 2296 >>> simplify(2**IntVal(8)) 2299 a, b = _coerce_exprs(self, other)
2303 """Create the Z3 expression `other/self`. 2322 a, b = _coerce_exprs(self, other)
2326 """Create the Z3 expression `other/self`.""" 2330 """Create the Z3 expression `other/self`. 2343 a, b = _coerce_exprs(self, other)
2347 """Create the Z3 expression `other/self`.""" 2351 """Create the Z3 expression `other%self`. 2357 >>> simplify(IntVal(10) % IntVal(3)) 2360 a, b = _coerce_exprs(self, other)
2362 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2366 """Create the Z3 expression `other%self`. 2372 a, b = _coerce_exprs(self, other)
2374 _z3_assert(a.is_int(),
"Z3 integer expression expected")
2378 """Return an expression representing `-self`. 2398 """Create the Z3 expression `other <= self`. 2400 >>> x, y = Ints('x y') 2407 a, b = _coerce_exprs(self, other)
2411 """Create the Z3 expression `other < self`. 2413 >>> x, y = Ints('x y') 2420 a, b = _coerce_exprs(self, other)
2424 """Create the Z3 expression `other > self`. 2426 >>> x, y = Ints('x y') 2433 a, b = _coerce_exprs(self, other)
2437 """Create the Z3 expression `other >= self`. 2439 >>> x, y = Ints('x y') 2446 a, b = _coerce_exprs(self, other)
2450 """Return `True` if `a` is an arithmetical expression. 2459 >>> is_arith(IntVal(1)) 2467 return isinstance(a, ArithRef)
2470 """Return `True` if `a` is an integer expression. 2477 >>> is_int(IntVal(1)) 2488 """Return `True` if `a` is a real expression. 2500 >>> is_real(RealVal(1)) 2505 def _is_numeral(ctx, a):
2508 def _is_algebraic(ctx, a):
2512 """Return `True` if `a` is an integer value of sort Int. 2514 >>> is_int_value(IntVal(1)) 2518 >>> is_int_value(Int('x')) 2520 >>> n = Int('x') + 1 2525 >>> is_int_value(n.arg(1)) 2527 >>> is_int_value(RealVal("1/3")) 2529 >>> is_int_value(RealVal(1)) 2532 return is_arith(a)
and a.is_int()
and _is_numeral(a.ctx, a.as_ast())
2535 """Return `True` if `a` is rational value of sort Real. 2537 >>> is_rational_value(RealVal(1)) 2539 >>> is_rational_value(RealVal("3/5")) 2541 >>> is_rational_value(IntVal(1)) 2543 >>> is_rational_value(1) 2545 >>> n = Real('x') + 1 2548 >>> is_rational_value(n.arg(1)) 2550 >>> is_rational_value(Real('x')) 2553 return is_arith(a)
and a.is_real()
and _is_numeral(a.ctx, a.as_ast())
2556 """Return `True` if `a` is an algebraic value of sort Real. 2558 >>> is_algebraic_value(RealVal("3/5")) 2560 >>> n = simplify(Sqrt(2)) 2563 >>> is_algebraic_value(n) 2566 return is_arith(a)
and a.is_real()
and _is_algebraic(a.ctx, a.as_ast())
2569 """Return `True` if `a` is an expression of the form b + c. 2571 >>> x, y = Ints('x y') 2580 """Return `True` if `a` is an expression of the form b * c. 2582 >>> x, y = Ints('x y') 2591 """Return `True` if `a` is an expression of the form b - c. 2593 >>> x, y = Ints('x y') 2602 """Return `True` if `a` is an expression of the form b / c. 2604 >>> x, y = Reals('x y') 2609 >>> x, y = Ints('x y') 2618 """Return `True` if `a` is an expression of the form b div c. 2620 >>> x, y = Ints('x y') 2629 """Return `True` if `a` is an expression of the form b % c. 2631 >>> x, y = Ints('x y') 2640 """Return `True` if `a` is an expression of the form b <= c. 2642 >>> x, y = Ints('x y') 2651 """Return `True` if `a` is an expression of the form b < c. 2653 >>> x, y = Ints('x y') 2662 """Return `True` if `a` is an expression of the form b >= c. 2664 >>> x, y = Ints('x y') 2673 """Return `True` if `a` is an expression of the form b > c. 2675 >>> x, y = Ints('x y') 2684 """Return `True` if `a` is an expression of the form IsInt(b). 2687 >>> is_is_int(IsInt(x)) 2695 """Return `True` if `a` is an expression of the form ToReal(b). 2709 """Return `True` if `a` is an expression of the form ToInt(b). 2723 """Integer values.""" 2726 """Return a Z3 integer numeral as a Python long (bignum) numeral. 2735 _z3_assert(self.
is_int(),
"Integer value expected")
2739 """Return a Z3 integer numeral as a Python string. 2747 """Rational values.""" 2750 """ Return the numerator of a Z3 rational numeral. 2752 >>> is_rational_value(RealVal("3/5")) 2754 >>> n = RealVal("3/5") 2757 >>> is_rational_value(Q(3,5)) 2759 >>> Q(3,5).numerator() 2765 """ Return the denominator of a Z3 rational numeral. 2767 >>> is_rational_value(Q(3,5)) 2776 """ Return the numerator as a Python long. 2778 >>> v = RealVal(10000000000) 2783 >>> v.numerator_as_long() + 1 == 10000000001 2789 """ Return the denominator as a Python long. 2791 >>> v = RealVal("1/3") 2794 >>> v.denominator_as_long() 2809 _z3_assert(self.
is_int_value(),
"Expected integer fraction")
2813 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places. 2815 >>> v = RealVal("1/5") 2818 >>> v = RealVal("1/3") 2825 """Return a Z3 rational numeral as a Python string. 2834 """Return a Z3 rational as a Python Fraction object. 2836 >>> v = RealVal("1/5") 2843 """Algebraic irrational values.""" 2846 """Return a Z3 rational number that approximates the algebraic number `self`. 2847 The result `r` is such that |r - self| <= 1/10^precision 2849 >>> x = simplify(Sqrt(2)) 2851 6838717160008073720548335/4835703278458516698824704 2857 """Return a string representation of the algebraic number `self` in decimal notation using `prec` decimal places 2859 >>> x = simplify(Sqrt(2)) 2860 >>> x.as_decimal(10) 2862 >>> x.as_decimal(20) 2863 '1.41421356237309504880?' 2867 def _py2expr(a, ctx=None):
2868 if isinstance(a, bool):
2872 if isinstance(a, float):
2877 _z3_assert(
False,
"Python bool, int, long or float expected")
2880 """Return the integer sort in the given context. If `ctx=None`, then the global context is used. 2884 >>> x = Const('x', IntSort()) 2887 >>> x.sort() == IntSort() 2889 >>> x.sort() == BoolSort() 2896 """Return the real sort in the given context. If `ctx=None`, then the global context is used. 2900 >>> x = Const('x', RealSort()) 2905 >>> x.sort() == RealSort() 2911 def _to_int_str(val):
2912 if isinstance(val, float):
2913 return str(int(val))
2914 elif isinstance(val, bool):
2921 elif isinstance(val, str):
2924 _z3_assert(
False,
"Python value cannot be used as a Z3 integer")
2927 """Return a Z3 integer value. If `ctx=None`, then the global context is used. 2938 """Return a Z3 real value. 2940 `val` may be a Python int, long, float or string representing a number in decimal or rational notation. 2941 If `ctx=None`, then the global context is used. 2945 >>> RealVal(1).sort() 2956 """Return a Z3 rational a/b. 2958 If `ctx=None`, then the global context is used. 2962 >>> RatVal(3,5).sort() 2966 _z3_assert(_is_int(a)
or isinstance(a, str),
"First argument cannot be converted into an integer")
2967 _z3_assert(_is_int(b)
or isinstance(b, str),
"Second argument cannot be converted into an integer")
2970 def Q(a, b, ctx=None):
2971 """Return a Z3 rational a/b. 2973 If `ctx=None`, then the global context is used. 2983 """Return an integer constant named `name`. If `ctx=None`, then the global context is used. 2995 """Return a tuple of Integer constants. 2997 >>> x, y, z = Ints('x y z') 3002 if isinstance(names, str):
3003 names = names.split(
" ")
3004 return [
Int(name, ctx)
for name
in names]
3007 """Return a list of integer constants of size `sz`. 3009 >>> X = IntVector('x', 3) 3015 return [
Int(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
3018 """Return a fresh integer constant in the given context using the given prefix. 3031 """Return a real constant named `name`. If `ctx=None`, then the global context is used. 3043 """Return a tuple of real constants. 3045 >>> x, y, z = Reals('x y z') 3048 >>> Sum(x, y, z).sort() 3052 if isinstance(names, str):
3053 names = names.split(
" ")
3054 return [
Real(name, ctx)
for name
in names]
3057 """Return a list of real constants of size `sz`. 3059 >>> X = RealVector('x', 3) 3067 return [
Real(
'%s__%s' % (prefix, i))
for i
in range(sz) ]
3070 """Return a fresh real constant in the given context using the given prefix. 3083 """ Return the Z3 expression ToReal(a). 3095 _z3_assert(a.is_int(),
"Z3 integer expression expected.")
3100 """ Return the Z3 expression ToInt(a). 3112 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3117 """ Return the Z3 predicate IsInt(a). 3120 >>> IsInt(x + "1/2") 3122 >>> solve(IsInt(x + "1/2"), x > 0, x < 1) 3124 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2") 3128 _z3_assert(a.is_real(),
"Z3 real expression expected.")
3133 """ Return a Z3 expression which represents the square root of a. 3145 """ Return a Z3 expression which represents the cubic root of a. 3163 """Bit-vector sort.""" 3166 """Return the size (number of bits) of the bit-vector sort `self`. 3168 >>> b = BitVecSort(32) 3178 """Try to cast `val` as a Bit-Vector. 3180 >>> b = BitVecSort(32) 3183 >>> b.cast(10).sexpr() 3188 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
3195 """Return True if `s` is a Z3 bit-vector sort. 3197 >>> is_bv_sort(BitVecSort(32)) 3199 >>> is_bv_sort(IntSort()) 3202 return isinstance(s, BitVecSortRef)
3205 """Bit-vector expressions.""" 3208 """Return the sort of the bit-vector expression `self`. 3210 >>> x = BitVec('x', 32) 3213 >>> x.sort() == BitVecSort(32) 3219 """Return the number of bits of the bit-vector expression `self`. 3221 >>> x = BitVec('x', 32) 3224 >>> Concat(x, x).size() 3230 """Create the Z3 expression `self + other`. 3232 >>> x = BitVec('x', 32) 3233 >>> y = BitVec('y', 32) 3239 a, b = _coerce_exprs(self, other)
3243 """Create the Z3 expression `other + self`. 3245 >>> x = BitVec('x', 32) 3249 a, b = _coerce_exprs(self, other)
3253 """Create the Z3 expression `self * other`. 3255 >>> x = BitVec('x', 32) 3256 >>> y = BitVec('y', 32) 3262 a, b = _coerce_exprs(self, other)
3266 """Create the Z3 expression `other * self`. 3268 >>> x = BitVec('x', 32) 3272 a, b = _coerce_exprs(self, other)
3276 """Create the Z3 expression `self - other`. 3278 >>> x = BitVec('x', 32) 3279 >>> y = BitVec('y', 32) 3285 a, b = _coerce_exprs(self, other)
3289 """Create the Z3 expression `other - self`. 3291 >>> x = BitVec('x', 32) 3295 a, b = _coerce_exprs(self, other)
3299 """Create the Z3 expression bitwise-or `self | other`. 3301 >>> x = BitVec('x', 32) 3302 >>> y = BitVec('y', 32) 3308 a, b = _coerce_exprs(self, other)
3312 """Create the Z3 expression bitwise-or `other | self`. 3314 >>> x = BitVec('x', 32) 3318 a, b = _coerce_exprs(self, other)
3322 """Create the Z3 expression bitwise-and `self & other`. 3324 >>> x = BitVec('x', 32) 3325 >>> y = BitVec('y', 32) 3331 a, b = _coerce_exprs(self, other)
3335 """Create the Z3 expression bitwise-or `other & self`. 3337 >>> x = BitVec('x', 32) 3341 a, b = _coerce_exprs(self, other)
3345 """Create the Z3 expression bitwise-xor `self ^ other`. 3347 >>> x = BitVec('x', 32) 3348 >>> y = BitVec('y', 32) 3354 a, b = _coerce_exprs(self, other)
3358 """Create the Z3 expression bitwise-xor `other ^ self`. 3360 >>> x = BitVec('x', 32) 3364 a, b = _coerce_exprs(self, other)
3370 >>> x = BitVec('x', 32) 3377 """Return an expression representing `-self`. 3379 >>> x = BitVec('x', 32) 3388 """Create the Z3 expression bitwise-not `~self`. 3390 >>> x = BitVec('x', 32) 3399 """Create the Z3 expression (signed) division `self / other`. 3401 Use the function UDiv() for unsigned division. 3403 >>> x = BitVec('x', 32) 3404 >>> y = BitVec('y', 32) 3411 >>> UDiv(x, y).sexpr() 3414 a, b = _coerce_exprs(self, other)
3418 """Create the Z3 expression (signed) division `self / other`.""" 3422 """Create the Z3 expression (signed) division `other / self`. 3424 Use the function UDiv() for unsigned division. 3426 >>> x = BitVec('x', 32) 3429 >>> (10 / x).sexpr() 3430 '(bvsdiv #x0000000a x)' 3431 >>> UDiv(10, x).sexpr() 3432 '(bvudiv #x0000000a x)' 3434 a, b = _coerce_exprs(self, other)
3438 """Create the Z3 expression (signed) division `other / self`.""" 3442 """Create the Z3 expression (signed) mod `self % other`. 3444 Use the function URem() for unsigned remainder, and SRem() for signed remainder. 3446 >>> x = BitVec('x', 32) 3447 >>> y = BitVec('y', 32) 3454 >>> URem(x, y).sexpr() 3456 >>> SRem(x, y).sexpr() 3459 a, b = _coerce_exprs(self, other)
3463 """Create the Z3 expression (signed) mod `other % self`. 3465 Use the function URem() for unsigned remainder, and SRem() for signed remainder. 3467 >>> x = BitVec('x', 32) 3470 >>> (10 % x).sexpr() 3471 '(bvsmod #x0000000a x)' 3472 >>> URem(10, x).sexpr() 3473 '(bvurem #x0000000a x)' 3474 >>> SRem(10, x).sexpr() 3475 '(bvsrem #x0000000a x)' 3477 a, b = _coerce_exprs(self, other)
3481 """Create the Z3 expression (signed) `other <= self`. 3483 Use the function ULE() for unsigned less than or equal to. 3485 >>> x, y = BitVecs('x y', 32) 3488 >>> (x <= y).sexpr() 3490 >>> ULE(x, y).sexpr() 3493 a, b = _coerce_exprs(self, other)
3497 """Create the Z3 expression (signed) `other < self`. 3499 Use the function ULT() for unsigned less than. 3501 >>> x, y = BitVecs('x y', 32) 3506 >>> ULT(x, y).sexpr() 3509 a, b = _coerce_exprs(self, other)
3513 """Create the Z3 expression (signed) `other > self`. 3515 Use the function UGT() for unsigned greater than. 3517 >>> x, y = BitVecs('x y', 32) 3522 >>> UGT(x, y).sexpr() 3525 a, b = _coerce_exprs(self, other)
3529 """Create the Z3 expression (signed) `other >= self`. 3531 Use the function UGE() for unsigned greater than or equal to. 3533 >>> x, y = BitVecs('x y', 32) 3536 >>> (x >= y).sexpr() 3538 >>> UGE(x, y).sexpr() 3541 a, b = _coerce_exprs(self, other)
3545 """Create the Z3 expression (arithmetical) right shift `self >> other` 3547 Use the function LShR() for the right logical shift 3549 >>> x, y = BitVecs('x y', 32) 3552 >>> (x >> y).sexpr() 3554 >>> LShR(x, y).sexpr() 3558 >>> BitVecVal(4, 3).as_signed_long() 3560 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long() 3562 >>> simplify(BitVecVal(4, 3) >> 1) 3564 >>> simplify(LShR(BitVecVal(4, 3), 1)) 3566 >>> simplify(BitVecVal(2, 3) >> 1) 3568 >>> simplify(LShR(BitVecVal(2, 3), 1)) 3571 a, b = _coerce_exprs(self, other)
3575 """Create the Z3 expression left shift `self << other` 3577 >>> x, y = BitVecs('x y', 32) 3580 >>> (x << y).sexpr() 3582 >>> simplify(BitVecVal(2, 3) << 1) 3585 a, b = _coerce_exprs(self, other)
3589 """Create the Z3 expression (arithmetical) right shift `other` >> `self`. 3591 Use the function LShR() for the right logical shift 3593 >>> x = BitVec('x', 32) 3596 >>> (10 >> x).sexpr() 3597 '(bvashr #x0000000a x)' 3599 a, b = _coerce_exprs(self, other)
3603 """Create the Z3 expression left shift `other << self`. 3605 Use the function LShR() for the right logical shift 3607 >>> x = BitVec('x', 32) 3610 >>> (10 << x).sexpr() 3611 '(bvshl #x0000000a x)' 3613 a, b = _coerce_exprs(self, other)
3617 """Bit-vector values.""" 3620 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. 3622 >>> v = BitVecVal(0xbadc0de, 32) 3625 >>> print("0x%.8x" % v.as_long()) 3631 """Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign. 3633 >>> BitVecVal(4, 3).as_signed_long() 3635 >>> BitVecVal(7, 3).as_signed_long() 3637 >>> BitVecVal(3, 3).as_signed_long() 3639 >>> BitVecVal(2**32 - 1, 32).as_signed_long() 3641 >>> BitVecVal(2**64 - 1, 64).as_signed_long() 3646 if val >= 2**(sz - 1):
3648 if val < -2**(sz - 1):
3656 """Return `True` if `a` is a Z3 bit-vector expression. 3658 >>> b = BitVec('b', 32) 3666 return isinstance(a, BitVecRef)
3669 """Return `True` if `a` is a Z3 bit-vector numeral value. 3671 >>> b = BitVec('b', 32) 3674 >>> b = BitVecVal(10, 32) 3680 return is_bv(a)
and _is_numeral(a.ctx, a.as_ast())
3683 """Return the Z3 expression BV2Int(a). 3685 >>> b = BitVec('b', 3) 3686 >>> BV2Int(b).sort() 3691 >>> x > BV2Int(b, is_signed=False) 3693 >>> x > BV2Int(b, is_signed=True) 3694 x > If(b < 0, BV2Int(b) - 8, BV2Int(b)) 3695 >>> solve(x > BV2Int(b), b == 1, x < 3) 3699 _z3_assert(
is_bv(a),
"Z3 bit-vector expression expected")
3705 """Return the z3 expression Int2BV(a, num_bits). 3706 It is a bit-vector of width num_bits and represents the 3707 modulo of a by 2^num_bits 3713 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used. 3715 >>> Byte = BitVecSort(8) 3716 >>> Word = BitVecSort(16) 3719 >>> x = Const('x', Byte) 3720 >>> eq(x, BitVec('x', 8)) 3727 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used. 3729 >>> v = BitVecVal(10, 32) 3732 >>> print("0x%.8x" % v.as_long()) 3743 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort. 3744 If `ctx=None`, then the global context is used. 3746 >>> x = BitVec('x', 16) 3753 >>> word = BitVecSort(16) 3754 >>> x2 = BitVec('x', word) 3758 if isinstance(bv, BitVecSortRef):
3766 """Return a tuple of bit-vector constants of size bv. 3768 >>> x, y, z = BitVecs('x y z', 16) 3775 >>> Product(x, y, z) 3777 >>> simplify(Product(x, y, z)) 3781 if isinstance(names, str):
3782 names = names.split(
" ")
3783 return [
BitVec(name, bv, ctx)
for name
in names]
3786 """Create a Z3 bit-vector concatenation expression. 3788 >>> v = BitVecVal(1, 4) 3789 >>> Concat(v, v+1, v) 3790 Concat(Concat(1, 1 + 1), 1) 3791 >>> simplify(Concat(v, v+1, v)) 3793 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long()) 3796 args = _get_args(args)
3799 _z3_assert(sz >= 2,
"At least two arguments expected.")
3806 if is_seq(args[0])
or isinstance(args[0], str):
3807 args = [_coerce_seq(s, ctx)
for s
in args]
3809 _z3_assert(all([
is_seq(a)
for a
in args]),
"All arguments must be sequence expressions.")
3812 v[i] = args[i].as_ast()
3817 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
3820 v[i] = args[i].as_ast()
3824 _z3_assert(all([
is_bv(a)
for a
in args]),
"All arguments must be Z3 bit-vector expressions.")
3826 for i
in range(sz - 1):
3831 """Create a Z3 bit-vector extraction expression, or create a string extraction expression. 3833 >>> x = BitVec('x', 8) 3834 >>> Extract(6, 2, x) 3836 >>> Extract(6, 2, x).sort() 3838 >>> simplify(Extract(StringVal("abcd"),2,1)) 3841 if isinstance(high, str):
3845 offset, length = _coerce_exprs(low, a, s.ctx)
3848 _z3_assert(low <= high,
"First argument must be greater than or equal to second argument")
3849 _z3_assert(_is_int(high)
and high >= 0
and _is_int(low)
and low >= 0,
"First and second arguments must be non negative integers")
3850 _z3_assert(
is_bv(a),
"Third argument must be a Z3 Bitvector expression")
3853 def _check_bv_args(a, b):
3855 _z3_assert(
is_bv(a)
or is_bv(b),
"At least one of the arguments must be a Z3 bit-vector expression")
3858 """Create the Z3 expression (unsigned) `other <= self`. 3860 Use the operator <= for signed less than or equal to. 3862 >>> x, y = BitVecs('x y', 32) 3865 >>> (x <= y).sexpr() 3867 >>> ULE(x, y).sexpr() 3870 _check_bv_args(a, b)
3871 a, b = _coerce_exprs(a, b)
3875 """Create the Z3 expression (unsigned) `other < self`. 3877 Use the operator < for signed less than. 3879 >>> x, y = BitVecs('x y', 32) 3884 >>> ULT(x, y).sexpr() 3887 _check_bv_args(a, b)
3888 a, b = _coerce_exprs(a, b)
3892 """Create the Z3 expression (unsigned) `other >= self`. 3894 Use the operator >= for signed greater than or equal to. 3896 >>> x, y = BitVecs('x y', 32) 3899 >>> (x >= y).sexpr() 3901 >>> UGE(x, y).sexpr() 3904 _check_bv_args(a, b)
3905 a, b = _coerce_exprs(a, b)
3909 """Create the Z3 expression (unsigned) `other > self`. 3911 Use the operator > for signed greater than. 3913 >>> x, y = BitVecs('x y', 32) 3918 >>> UGT(x, y).sexpr() 3921 _check_bv_args(a, b)
3922 a, b = _coerce_exprs(a, b)
3926 """Create the Z3 expression (unsigned) division `self / other`. 3928 Use the operator / for signed division. 3930 >>> x = BitVec('x', 32) 3931 >>> y = BitVec('y', 32) 3934 >>> UDiv(x, y).sort() 3938 >>> UDiv(x, y).sexpr() 3941 _check_bv_args(a, b)
3942 a, b = _coerce_exprs(a, b)
3946 """Create the Z3 expression (unsigned) remainder `self % other`. 3948 Use the operator % for signed modulus, and SRem() for signed remainder. 3950 >>> x = BitVec('x', 32) 3951 >>> y = BitVec('y', 32) 3954 >>> URem(x, y).sort() 3958 >>> URem(x, y).sexpr() 3961 _check_bv_args(a, b)
3962 a, b = _coerce_exprs(a, b)
3966 """Create the Z3 expression signed remainder. 3968 Use the operator % for signed modulus, and URem() for unsigned remainder. 3970 >>> x = BitVec('x', 32) 3971 >>> y = BitVec('y', 32) 3974 >>> SRem(x, y).sort() 3978 >>> SRem(x, y).sexpr() 3981 _check_bv_args(a, b)
3982 a, b = _coerce_exprs(a, b)
3986 """Create the Z3 expression logical right shift. 3988 Use the operator >> for the arithmetical right shift. 3990 >>> x, y = BitVecs('x y', 32) 3993 >>> (x >> y).sexpr() 3995 >>> LShR(x, y).sexpr() 3999 >>> BitVecVal(4, 3).as_signed_long() 4001 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long() 4003 >>> simplify(BitVecVal(4, 3) >> 1) 4005 >>> simplify(LShR(BitVecVal(4, 3), 1)) 4007 >>> simplify(BitVecVal(2, 3) >> 1) 4009 >>> simplify(LShR(BitVecVal(2, 3), 1)) 4012 _check_bv_args(a, b)
4013 a, b = _coerce_exprs(a, b)
4017 """Return an expression representing `a` rotated to the left `b` times. 4019 >>> a, b = BitVecs('a b', 16) 4020 >>> RotateLeft(a, b) 4022 >>> simplify(RotateLeft(a, 0)) 4024 >>> simplify(RotateLeft(a, 16)) 4027 _check_bv_args(a, b)
4028 a, b = _coerce_exprs(a, b)
4032 """Return an expression representing `a` rotated to the right `b` times. 4034 >>> a, b = BitVecs('a b', 16) 4035 >>> RotateRight(a, b) 4037 >>> simplify(RotateRight(a, 0)) 4039 >>> simplify(RotateRight(a, 16)) 4042 _check_bv_args(a, b)
4043 a, b = _coerce_exprs(a, b)
4047 """Return a bit-vector expression with `n` extra sign-bits. 4049 >>> x = BitVec('x', 16) 4050 >>> n = SignExt(8, x) 4057 >>> v0 = BitVecVal(2, 2) 4062 >>> v = simplify(SignExt(6, v0)) 4067 >>> print("%.x" % v.as_long()) 4071 _z3_assert(_is_int(n),
"First argument must be an integer")
4072 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4076 """Return a bit-vector expression with `n` extra zero-bits. 4078 >>> x = BitVec('x', 16) 4079 >>> n = ZeroExt(8, x) 4086 >>> v0 = BitVecVal(2, 2) 4091 >>> v = simplify(ZeroExt(6, v0)) 4098 _z3_assert(_is_int(n),
"First argument must be an integer")
4099 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4103 """Return an expression representing `n` copies of `a`. 4105 >>> x = BitVec('x', 8) 4106 >>> n = RepeatBitVec(4, x) 4111 >>> v0 = BitVecVal(10, 4) 4112 >>> print("%.x" % v0.as_long()) 4114 >>> v = simplify(RepeatBitVec(4, v0)) 4117 >>> print("%.x" % v.as_long()) 4121 _z3_assert(_is_int(n),
"First argument must be an integer")
4122 _z3_assert(
is_bv(a),
"Second argument must be a Z3 Bitvector expression")
4126 """Return the reduction-and expression of `a`.""" 4128 _z3_assert(
is_bv(a),
"First argument must be a Z3 Bitvector expression")
4132 """Return the reduction-or expression of `a`.""" 4134 _z3_assert(
is_bv(a),
"First argument must be a Z3 Bitvector expression")
4138 """A predicate the determines that bit-vector addition does not overflow""" 4139 _check_bv_args(a, b)
4140 a, b = _coerce_exprs(a, b)
4144 """A predicate the determines that signed bit-vector addition does not underflow""" 4145 _check_bv_args(a, b)
4146 a, b = _coerce_exprs(a, b)
4150 """A predicate the determines that bit-vector subtraction does not overflow""" 4151 _check_bv_args(a, b)
4152 a, b = _coerce_exprs(a, b)
4157 """A predicate the determines that bit-vector subtraction does not underflow""" 4158 _check_bv_args(a, b)
4159 a, b = _coerce_exprs(a, b)
4163 """A predicate the determines that bit-vector signed division does not overflow""" 4164 _check_bv_args(a, b)
4165 a, b = _coerce_exprs(a, b)
4169 """A predicate the determines that bit-vector unary negation does not overflow""" 4171 _z3_assert(
is_bv(a),
"Argument should be a bit-vector")
4175 """A predicate the determines that bit-vector multiplication does not overflow""" 4176 _check_bv_args(a, b)
4177 a, b = _coerce_exprs(a, b)
4182 """A predicate the determines that bit-vector signed multiplication does not underflow""" 4183 _check_bv_args(a, b)
4184 a, b = _coerce_exprs(a, b)
4199 """Return the domain of the array sort `self`. 4201 >>> A = ArraySort(IntSort(), BoolSort()) 4208 """Return the range of the array sort `self`. 4210 >>> A = ArraySort(IntSort(), BoolSort()) 4217 """Array expressions. """ 4220 """Return the array sort of the array expression `self`. 4222 >>> a = Array('a', IntSort(), BoolSort()) 4229 """Shorthand for `self.sort().domain()`. 4231 >>> a = Array('a', IntSort(), BoolSort()) 4238 """Shorthand for `self.sort().range()`. 4240 >>> a = Array('a', IntSort(), BoolSort()) 4247 """Return the Z3 expression `self[arg]`. 4249 >>> a = Array('a', IntSort(), BoolSort()) 4256 arg = self.
domain().cast(arg)
4264 """Return `True` if `a` is a Z3 array expression. 4266 >>> a = Array('a', IntSort(), IntSort()) 4269 >>> is_array(Store(a, 0, 1)) 4274 return isinstance(a, ArrayRef)
4277 """Return `True` if `a` is a Z3 constant array. 4279 >>> a = K(IntSort(), 10) 4280 >>> is_const_array(a) 4282 >>> a = Array('a', IntSort(), IntSort()) 4283 >>> is_const_array(a) 4289 """Return `True` if `a` is a Z3 constant array. 4291 >>> a = K(IntSort(), 10) 4294 >>> a = Array('a', IntSort(), IntSort()) 4301 """Return `True` if `a` is a Z3 map array expression. 4303 >>> f = Function('f', IntSort(), IntSort()) 4304 >>> b = Array('b', IntSort(), IntSort()) 4316 """Return `True` if `a` is a Z3 default array expression. 4317 >>> d = Default(K(IntSort(), 10)) 4321 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
4324 """Return the function declaration associated with a Z3 map array expression. 4326 >>> f = Function('f', IntSort(), IntSort()) 4327 >>> b = Array('b', IntSort(), IntSort()) 4329 >>> eq(f, get_map_func(a)) 4333 >>> get_map_func(a)(0) 4337 _z3_assert(
is_map(a),
"Z3 array map expression expected.")
4341 """Return the Z3 array sort with the given domain and range sorts. 4343 >>> A = ArraySort(IntSort(), BoolSort()) 4350 >>> AA = ArraySort(IntSort(), A) 4352 Array(Int, Array(Int, Bool)) 4354 sig = _get_args(sig)
4356 _z3_assert(len(sig) > 1,
"At least two arguments expected")
4357 arity = len(sig) - 1
4362 _z3_assert(
is_sort(s),
"Z3 sort expected")
4363 _z3_assert(s.ctx == r.ctx,
"Context mismatch")
4367 dom = (Sort * arity)()
4368 for i
in range(arity):
4373 """Return an array constant named `name` with the given domain and range sorts. 4375 >>> a = Array('a', IntSort(), IntSort()) 4386 """Return a Z3 store array expression. 4388 >>> a = Array('a', IntSort(), IntSort()) 4389 >>> i, v = Ints('i v') 4390 >>> s = Update(a, i, v) 4393 >>> prove(s[i] == v) 4396 >>> prove(Implies(i != j, s[j] == a[j])) 4400 _z3_assert(
is_array(a),
"First argument must be a Z3 array expression")
4401 i = a.domain().cast(i)
4402 v = a.range().cast(v)
4404 return _to_expr_ref(
Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
4407 """ Return a default value for array expression. 4408 >>> b = K(IntSort(), 1) 4409 >>> prove(Default(b) == 1) 4413 _z3_assert(
is_array(a),
"First argument must be a Z3 array expression")
4418 """Return a Z3 store array expression. 4420 >>> a = Array('a', IntSort(), IntSort()) 4421 >>> i, v = Ints('i v') 4422 >>> s = Store(a, i, v) 4425 >>> prove(s[i] == v) 4428 >>> prove(Implies(i != j, s[j] == a[j])) 4434 """Return a Z3 select array expression. 4436 >>> a = Array('a', IntSort(), IntSort()) 4440 >>> eq(Select(a, i), a[i]) 4444 _z3_assert(
is_array(a),
"First argument must be a Z3 array expression")
4449 """Return a Z3 map array expression. 4451 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 4452 >>> a1 = Array('a1', IntSort(), IntSort()) 4453 >>> a2 = Array('a2', IntSort(), IntSort()) 4454 >>> b = Map(f, a1, a2) 4457 >>> prove(b[0] == f(a1[0], a2[0])) 4460 args = _get_args(args)
4462 _z3_assert(len(args) > 0,
"At least one Z3 array expression expected")
4463 _z3_assert(
is_func_decl(f),
"First argument must be a Z3 function declaration")
4464 _z3_assert(all([
is_array(a)
for a
in args]),
"Z3 array expected expected")
4465 _z3_assert(len(args) == f.arity(),
"Number of arguments mismatch")
4466 _args, sz = _to_ast_array(args)
4471 """Return a Z3 constant array expression. 4473 >>> a = K(IntSort(), 10) 4485 _z3_assert(
is_sort(dom),
"Z3 sort expected")
4488 v = _py2expr(v, ctx)
4492 """Return extensionality index for arrays. 4496 return _to_expr_ref(
Z3_mk_array_ext(ctx.ref(), a.as_ast(), b.as_ast()));
4499 """Return `True` if `a` is a Z3 array select application. 4501 >>> a = Array('a', IntSort(), IntSort()) 4511 """Return `True` if `a` is a Z3 array store application. 4513 >>> a = Array('a', IntSort(), IntSort()) 4516 >>> is_store(Store(a, 0, 1)) 4529 """ Create a set sort over element sort s""" 4533 """Create the empty set 4534 >>> EmptySet(IntSort()) 4541 """Create the full set 4542 >>> FullSet(IntSort()) 4549 """ Take the union of sets 4550 >>> a = Const('a', SetSort(IntSort())) 4551 >>> b = Const('b', SetSort(IntSort())) 4555 args = _get_args(args)
4556 ctx = _ctx_from_ast_arg_list(args)
4557 _args, sz = _to_ast_array(args)
4561 """ Take the union of sets 4562 >>> a = Const('a', SetSort(IntSort())) 4563 >>> b = Const('b', SetSort(IntSort())) 4564 >>> SetIntersect(a, b) 4567 args = _get_args(args)
4568 ctx = _ctx_from_ast_arg_list(args)
4569 _args, sz = _to_ast_array(args)
4573 """ Add element e to set s 4574 >>> a = Const('a', SetSort(IntSort())) 4578 ctx = _ctx_from_ast_arg_list([s,e])
4579 e = _py2expr(e, ctx)
4583 """ Remove element e to set s 4584 >>> a = Const('a', SetSort(IntSort())) 4588 ctx = _ctx_from_ast_arg_list([s,e])
4589 e = _py2expr(e, ctx)
4593 """ The complement of set s 4594 >>> a = Const('a', SetSort(IntSort())) 4595 >>> SetComplement(a) 4602 """ The set difference of a and b 4603 >>> a = Const('a', SetSort(IntSort())) 4604 >>> b = Const('b', SetSort(IntSort())) 4605 >>> SetDifference(a, b) 4608 ctx = _ctx_from_ast_arg_list([a, b])
4612 """ Check if e is a member of set s 4613 >>> a = Const('a', SetSort(IntSort())) 4617 ctx = _ctx_from_ast_arg_list([s,e])
4618 e = _py2expr(e, ctx)
4622 """ Check if a is a subset of b 4623 >>> a = Const('a', SetSort(IntSort())) 4624 >>> b = Const('b', SetSort(IntSort())) 4628 ctx = _ctx_from_ast_arg_list([a, b])
4638 def _valid_accessor(acc):
4639 """Return `True` if acc is pair of the form (String, Datatype or Sort). """ 4640 return isinstance(acc, tuple)
and len(acc) == 2
and isinstance(acc[0], str)
and (isinstance(acc[1], Datatype)
or is_sort(acc[1]))
4643 """Helper class for declaring Z3 datatypes. 4645 >>> List = Datatype('List') 4646 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4647 >>> List.declare('nil') 4648 >>> List = List.create() 4649 >>> # List is now a Z3 declaration 4652 >>> List.cons(10, List.nil) 4654 >>> List.cons(10, List.nil).sort() 4656 >>> cons = List.cons 4660 >>> n = cons(1, cons(0, nil)) 4662 cons(1, cons(0, nil)) 4663 >>> simplify(cdr(n)) 4665 >>> simplify(car(n)) 4680 _z3_assert(isinstance(name, str),
"String expected")
4681 _z3_assert(isinstance(rec_name, str),
"String expected")
4682 _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)")
4686 """Declare constructor named `name` with the given accessors `args`. 4687 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. 4689 In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))` 4690 declares the constructor named `cons` that builds a new List using an integer and a List. 4691 It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell, 4692 and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create 4693 the actual datatype in Z3. 4695 >>> List = Datatype('List') 4696 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4697 >>> List.declare('nil') 4698 >>> List = List.create() 4701 _z3_assert(isinstance(name, str),
"String expected")
4702 _z3_assert(name !=
"",
"Constructor name cannot be empty")
4709 """Create a Z3 datatype based on the constructors declared using the method `declare()`. 4711 The function `CreateDatatypes()` must be used to define mutually recursive datatypes. 4713 >>> List = Datatype('List') 4714 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4715 >>> List.declare('nil') 4716 >>> List = List.create() 4719 >>> List.cons(10, List.nil) 4725 """Auxiliary object used to create Z3 datatypes.""" 4730 if self.
ctx.ref()
is not None:
4734 """Auxiliary object used to create Z3 datatypes.""" 4739 if self.
ctx.ref()
is not None:
4743 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects. 4745 In the following example we define a Tree-List using two mutually recursive datatypes. 4747 >>> TreeList = Datatype('TreeList') 4748 >>> Tree = Datatype('Tree') 4749 >>> # Tree has two constructors: leaf and node 4750 >>> Tree.declare('leaf', ('val', IntSort())) 4751 >>> # a node contains a list of trees 4752 >>> Tree.declare('node', ('children', TreeList)) 4753 >>> TreeList.declare('nil') 4754 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList)) 4755 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList) 4756 >>> Tree.val(Tree.leaf(10)) 4758 >>> simplify(Tree.val(Tree.leaf(10))) 4760 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil))) 4762 node(cons(leaf(10), cons(leaf(20), nil))) 4763 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil)) 4764 >>> simplify(n2 == n1) 4766 >>> simplify(TreeList.car(Tree.children(n2)) == n1) 4771 _z3_assert(len(ds) > 0,
"At least one Datatype must be specified")
4772 _z3_assert(all([isinstance(d, Datatype)
for d
in ds]),
"Arguments must be Datatypes")
4773 _z3_assert(all([d.ctx == ds[0].ctx
for d
in ds]),
"Context mismatch")
4774 _z3_assert(all([d.constructors != []
for d
in ds]),
"Non-empty Datatypes expected")
4777 names = (Symbol * num)()
4778 out = (Sort * num)()
4779 clists = (ConstructorList * num)()
4781 for i
in range(num):
4784 num_cs = len(d.constructors)
4785 cs = (Constructor * num_cs)()
4786 for j
in range(num_cs):
4787 c = d.constructors[j]
4792 fnames = (Symbol * num_fs)()
4793 sorts = (Sort * num_fs)()
4794 refs = (ctypes.c_uint * num_fs)()
4795 for k
in range(num_fs):
4799 if isinstance(ftype, Datatype):
4801 _z3_assert(ds.count(ftype) == 1,
"One and only one occurrence of each datatype is expected")
4803 refs[k] = ds.index(ftype)
4806 _z3_assert(
is_sort(ftype),
"Z3 sort expected")
4807 sorts[k] = ftype.ast
4816 for i
in range(num):
4818 num_cs = dref.num_constructors()
4819 for j
in range(num_cs):
4820 cref = dref.constructor(j)
4821 cref_name = cref.name()
4822 cref_arity = cref.arity()
4823 if cref.arity() == 0:
4825 setattr(dref, cref_name, cref)
4826 rref = dref.recognizer(j)
4827 setattr(dref,
"is_" + cref_name, rref)
4828 for k
in range(cref_arity):
4829 aref = dref.accessor(j, k)
4830 setattr(dref, aref.name(), aref)
4832 return tuple(result)
4835 """Datatype sorts.""" 4837 """Return the number of constructors in the given Z3 datatype. 4839 >>> List = Datatype('List') 4840 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4841 >>> List.declare('nil') 4842 >>> List = List.create() 4843 >>> # List is now a Z3 declaration 4844 >>> List.num_constructors() 4850 """Return a constructor of the datatype `self`. 4852 >>> List = Datatype('List') 4853 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4854 >>> List.declare('nil') 4855 >>> List = List.create() 4856 >>> # List is now a Z3 declaration 4857 >>> List.num_constructors() 4859 >>> List.constructor(0) 4861 >>> List.constructor(1) 4869 """In Z3, each constructor has an associated recognizer predicate. 4871 If the constructor is named `name`, then the recognizer `is_name`. 4873 >>> List = Datatype('List') 4874 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4875 >>> List.declare('nil') 4876 >>> List = List.create() 4877 >>> # List is now a Z3 declaration 4878 >>> List.num_constructors() 4880 >>> List.recognizer(0) 4882 >>> List.recognizer(1) 4884 >>> simplify(List.is_nil(List.cons(10, List.nil))) 4886 >>> simplify(List.is_cons(List.cons(10, List.nil))) 4888 >>> l = Const('l', List) 4889 >>> simplify(List.is_cons(l)) 4897 """In Z3, each constructor has 0 or more accessor. The number of accessors is equal to the arity of the constructor. 4899 >>> List = Datatype('List') 4900 >>> List.declare('cons', ('car', IntSort()), ('cdr', List)) 4901 >>> List.declare('nil') 4902 >>> List = List.create() 4903 >>> List.num_constructors() 4905 >>> List.constructor(0) 4907 >>> num_accs = List.constructor(0).arity() 4910 >>> List.accessor(0, 0) 4912 >>> List.accessor(0, 1) 4914 >>> List.constructor(1) 4916 >>> num_accs = List.constructor(1).arity() 4922 _z3_assert(j < self.
constructor(i).arity(),
"Invalid accessor index")
4926 """Datatype expressions.""" 4928 """Return the datatype sort of the datatype expression `self`.""" 4932 """Return a new enumeration sort named `name` containing the given values. 4934 The result is a pair (sort, list of constants). 4936 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue']) 4939 _z3_assert(isinstance(name, str),
"Name must be a string")
4940 _z3_assert(all([isinstance(v, str)
for v
in values]),
"Eumeration sort values must be strings")
4941 _z3_assert(len(values) > 0,
"At least one value expected")
4944 _val_names = (Symbol * num)()
4945 for i
in range(num):
4947 _values = (FuncDecl * num)()
4948 _testers = (FuncDecl * num)()
4952 for i
in range(num):
4954 V = [a()
for a
in V]
4964 """Set of parameters used to configure Solvers, Tactics and Simplifiers in Z3. 4966 Consider using the function `args2params` to create instances of this object. 4980 if self.
ctx.ref()
is not None:
4984 """Set parameter name with value val.""" 4986 _z3_assert(isinstance(name, str),
"parameter name must be a string")
4988 if isinstance(val, bool):
4992 elif isinstance(val, float):
4994 elif isinstance(val, str):
4998 _z3_assert(
False,
"invalid parameter value")
5004 _z3_assert(isinstance(ds, ParamDescrsRef),
"parameter description set expected")
5008 """Convert python arguments into a Z3_params object. 5009 A ':' is added to the keywords, and '_' is replaced with '-' 5011 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True}) 5012 (params model true relevancy 2 elim_and true) 5015 _z3_assert(len(arguments) % 2 == 0,
"Argument list must have an even number of elements.")
5030 """Set of parameter descriptions for Solvers, Tactics and Simplifiers in Z3. 5033 _z3_assert(isinstance(descr, ParamDescrs),
"parameter description object expected")
5039 return ParamsDescrsRef(self.
descr, self.
ctx)
5042 if self.
ctx.ref()
is not None:
5046 """Return the size of in the parameter description `self`. 5051 """Return the size of in the parameter description `self`. 5056 """Return the i-th parameter name in the parameter description `self`. 5061 """Return the kind of the parameter named `n`. 5066 """Return the documentation string of the parameter named `n`. 5086 """Goal is a collection of constraints we want to find a solution or show to be unsatisfiable (infeasible). 5088 Goals are processed using Tactics. A Tactic transforms a goal into a set of subgoals. 5089 A goal has a solution if one of its subgoals has a solution. 5090 A goal is unsatisfiable if all subgoals are unsatisfiable. 5093 def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=None):
5095 _z3_assert(goal
is None or ctx
is not None,
"If goal is different from None, then ctx must be also different from None")
5098 if self.
goal is None:
5103 return Goal(
False,
False,
False, self.
ctx, self.
goal)
5106 if self.
goal is not None and self.
ctx.ref()
is not None:
5110 """Return the depth of the goal `self`. The depth corresponds to the number of tactics applied to `self`. 5112 >>> x, y = Ints('x y') 5114 >>> g.add(x == 0, y >= x + 1) 5117 >>> r = Then('simplify', 'solve-eqs')(g) 5118 >>> # r has 1 subgoal 5127 """Return `True` if `self` contains the `False` constraints. 5129 >>> x, y = Ints('x y') 5131 >>> g.inconsistent() 5133 >>> g.add(x == 0, x == 1) 5136 >>> g.inconsistent() 5138 >>> g2 = Tactic('propagate-values')(g)[0] 5139 >>> g2.inconsistent() 5145 """Return the precision (under-approximation, over-approximation, or precise) of the goal `self`. 5148 >>> g.prec() == Z3_GOAL_PRECISE 5150 >>> x, y = Ints('x y') 5151 >>> g.add(x == y + 1) 5152 >>> g.prec() == Z3_GOAL_PRECISE 5154 >>> t = With(Tactic('add-bounds'), add_bound_lower=0, add_bound_upper=10) 5157 [x == y + 1, x <= 10, x >= 0, y <= 10, y >= 0] 5158 >>> g2.prec() == Z3_GOAL_PRECISE 5160 >>> g2.prec() == Z3_GOAL_UNDER 5166 """Alias for `prec()`. 5169 >>> g.precision() == Z3_GOAL_PRECISE 5175 """Return the number of constraints in the goal `self`. 5180 >>> x, y = Ints('x y') 5181 >>> g.add(x == 0, y > x) 5188 """Return the number of constraints in the goal `self`. 5193 >>> x, y = Ints('x y') 5194 >>> g.add(x == 0, y > x) 5201 """Return a constraint in the goal `self`. 5204 >>> x, y = Ints('x y') 5205 >>> g.add(x == 0, y > x) 5214 """Return a constraint in the goal `self`. 5217 >>> x, y = Ints('x y') 5218 >>> g.add(x == 0, y > x) 5224 if arg >= len(self):
5226 return self.
get(arg)
5229 """Assert constraints into the goal. 5233 >>> g.assert_exprs(x > 0, x < 2) 5237 args = _get_args(args)
5248 >>> g.append(x > 0, x < 2) 5259 >>> g.insert(x > 0, x < 2) 5270 >>> g.add(x > 0, x < 2) 5277 """Retrieve model from a satisfiable goal 5278 >>> a, b = Ints('a b') 5280 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b) 5281 >>> t = Then(Tactic('split-clause'), Tactic('solve-eqs')) 5284 [Or(b == 0, b == 1), Not(0 <= b)] 5286 [Or(b == 0, b == 1), Not(1 <= b)] 5287 >>> # Remark: the subgoal r[0] is unsatisfiable 5288 >>> # Creating a solver for solving the second subgoal 5295 >>> # Model s.model() does not assign a value to `a` 5296 >>> # It is a model for subgoal `r[1]`, but not for goal `g` 5297 >>> # The method convert_model creates a model for `g` from a model for `r[1]`. 5298 >>> r[1].convert_model(s.model()) 5302 _z3_assert(isinstance(model, ModelRef),
"Z3 Model expected")
5306 return obj_to_string(self)
5309 """Return a textual representation of the s-expression representing the goal.""" 5313 """Return a textual representation of the goal in DIMACS format.""" 5317 """Copy goal `self` to context `target`. 5325 >>> g2 = g.translate(c2) 5328 >>> g.ctx == main_ctx() 5332 >>> g2.ctx == main_ctx() 5336 _z3_assert(isinstance(target, Context),
"target must be a context")
5346 """Return a new simplified goal. 5348 This method is essentially invoking the simplify tactic. 5352 >>> g.add(x + 1 >= 2) 5355 >>> g2 = g.simplify() 5358 >>> # g was not modified 5363 return t.apply(self, *arguments, **keywords)[0]
5366 """Return goal `self` as a single Z3 expression. 5393 """A collection (vector) of ASTs.""" 5402 assert ctx
is not None 5410 if self.
vector is not None and self.
ctx.ref()
is not None:
5414 """Return the size of the vector `self`. 5419 >>> A.push(Int('x')) 5420 >>> A.push(Int('x')) 5427 """Return the AST at position `i`. 5430 >>> A.push(Int('x') + 1) 5431 >>> A.push(Int('y')) 5438 if isinstance(i, int):
5446 elif isinstance(i, slice):
5451 """Update AST at position `i`. 5454 >>> A.push(Int('x') + 1) 5455 >>> A.push(Int('y')) 5467 """Add `v` in the end of the vector. 5472 >>> A.push(Int('x')) 5479 """Resize the vector to `sz` elements. 5485 >>> for i in range(10): A[i] = Int('x') 5492 """Return `True` if the vector contains `item`. 5515 """Copy vector `self` to context `other_ctx`. 5521 >>> B = A.translate(c2) 5534 return obj_to_string(self)
5537 """Return a textual representation of the s-expression representing the vector.""" 5546 """A mapping from ASTs to ASTs.""" 5555 assert ctx
is not None 5563 if self.
map is not None and self.
ctx.ref()
is not None:
5567 """Return the size of the map. 5573 >>> M[x] = IntVal(1) 5580 """Return `True` if the map contains key `key`. 5593 """Retrieve the value associated with key `key`. 5604 """Add/Update key `k` with value `v`. 5613 >>> M[x] = IntVal(1) 5623 """Remove the entry associated with key `k`. 5637 """Remove all entries from the map. 5642 >>> M[x+x] = IntVal(1) 5652 """Return an AstVector containing all keys in the map. 5657 >>> M[x+x] = IntVal(1) 5670 """Store the value of the interpretation of a function in a particular point.""" 5681 if self.
ctx.ref()
is not None:
5685 """Return the number of arguments in the given entry. 5687 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5689 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5694 >>> f_i.num_entries() 5696 >>> e = f_i.entry(0) 5703 """Return the value of argument `idx`. 5705 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5707 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5712 >>> f_i.num_entries() 5714 >>> e = f_i.entry(0) 5725 ... except IndexError: 5726 ... print("index error") 5734 """Return the value of the function at point `self`. 5736 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5738 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5743 >>> f_i.num_entries() 5745 >>> e = f_i.entry(0) 5756 """Return entry `self` as a Python list. 5757 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 5759 >>> s.add(f(0, 1) == 10, f(1, 2) == 20, f(1, 0) == 10) 5764 >>> f_i.num_entries() 5766 >>> e = f_i.entry(0) 5771 args.append(self.
value())
5778 """Stores the interpretation of a function in a Z3 model.""" 5783 if self.
f is not None:
5790 if self.
f is not None and self.
ctx.ref()
is not None:
5795 Return the `else` value for a function interpretation. 5796 Return None if Z3 did not specify the `else` value for 5799 >>> f = Function('f', IntSort(), IntSort()) 5801 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5807 >>> m[f].else_value() 5812 return _to_expr_ref(r, self.
ctx)
5817 """Return the number of entries/points in the function interpretation `self`. 5819 >>> f = Function('f', IntSort(), IntSort()) 5821 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5827 >>> m[f].num_entries() 5833 """Return the number of arguments for each entry in the function interpretation `self`. 5835 >>> f = Function('f', IntSort(), IntSort()) 5837 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5847 """Return an entry at position `idx < self.num_entries()` in the function interpretation `self`. 5849 >>> f = Function('f', IntSort(), IntSort()) 5851 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5857 >>> m[f].num_entries() 5867 """Copy model 'self' to context 'other_ctx'. 5878 """Return the function interpretation as a Python list. 5879 >>> f = Function('f', IntSort(), IntSort()) 5881 >>> s.add(f(0) == 1, f(1) == 1, f(2) == 0) 5895 return obj_to_string(self)
5898 """Model/Solution of a satisfiability problem (aka system of constraints).""" 5901 assert ctx
is not None 5907 if self.
ctx.ref()
is not None:
5911 return obj_to_string(self)
5914 """Return a textual representation of the s-expression representing the model.""" 5917 def eval(self, t, model_completion=False):
5918 """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`. 5922 >>> s.add(x > 0, x < 2) 5935 >>> m.eval(y, model_completion=True) 5937 >>> # Now, m contains an interpretation for y 5943 return _to_expr_ref(r[0], self.
ctx)
5944 raise Z3Exception(
"failed to evaluate expression in the model")
5947 """Alias for `eval`. 5951 >>> s.add(x > 0, x < 2) 5955 >>> m.evaluate(x + 1) 5957 >>> m.evaluate(x == 1) 5960 >>> m.evaluate(y + x) 5964 >>> m.evaluate(y, model_completion=True) 5966 >>> # Now, m contains an interpretation for y 5967 >>> m.evaluate(y + x) 5970 return self.
eval(t, model_completion)
5973 """Return the number of constant and function declarations in the model `self`. 5975 >>> f = Function('f', IntSort(), IntSort()) 5978 >>> s.add(x > 0, f(x) != x) 5988 """Return the interpretation for a given declaration or constant. 5990 >>> f = Function('f', IntSort(), IntSort()) 5993 >>> s.add(x > 0, x < 2, f(x) == 0) 6003 _z3_assert(isinstance(decl, FuncDeclRef)
or is_const(decl),
"Z3 declaration expected")
6007 if decl.arity() == 0:
6009 if _r.value
is None:
6011 r = _to_expr_ref(_r, self.
ctx)
6022 """Return the number of uninterpreted sorts that contain an interpretation in the model `self`. 6024 >>> A = DeclareSort('A') 6025 >>> a, b = Consts('a b', A) 6037 """Return the uninterpreted sort at position `idx` < self.num_sorts(). 6039 >>> A = DeclareSort('A') 6040 >>> B = DeclareSort('B') 6041 >>> a1, a2 = Consts('a1 a2', A) 6042 >>> b1, b2 = Consts('b1 b2', B) 6044 >>> s.add(a1 != a2, b1 != b2) 6060 """Return all uninterpreted sorts that have an interpretation in the model `self`. 6062 >>> A = DeclareSort('A') 6063 >>> B = DeclareSort('B') 6064 >>> a1, a2 = Consts('a1 a2', A) 6065 >>> b1, b2 = Consts('b1 b2', B) 6067 >>> s.add(a1 != a2, b1 != b2) 6077 """Return the interpretation for the uninterpreted sort `s` in the model `self`. 6079 >>> A = DeclareSort('A') 6080 >>> a, b = Consts('a b', A) 6086 >>> m.get_universe(A) 6090 _z3_assert(isinstance(s, SortRef),
"Z3 sort expected")
6097 """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. 6099 The elements can be retrieved using position or the actual declaration. 6101 >>> f = Function('f', IntSort(), IntSort()) 6104 >>> s.add(x > 0, x < 2, f(x) == 0) 6118 >>> for d in m: print("%s -> %s" % (d, m[d])) 6123 if idx >= len(self):
6126 if (idx < num_consts):
6130 if isinstance(idx, FuncDeclRef):
6134 if isinstance(idx, SortRef):
6137 _z3_assert(
False,
"Integer, Z3 declaration, or Z3 constant expected")
6141 """Return a list with all symbols that have an interpretation in the model `self`. 6142 >>> f = Function('f', IntSort(), IntSort()) 6145 >>> s.add(x > 0, x < 2, f(x) == 0) 6160 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 6163 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6165 return Model(model, target)
6178 """Return true if n is a Z3 expression of the form (_ as-array f).""" 6179 return isinstance(n, ExprRef)
and Z3_is_as_array(n.ctx.ref(), n.as_ast())
6182 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f).""" 6184 _z3_assert(
is_as_array(n),
"as-array Z3 expression expected.")
6193 """Statistics for `Solver.check()`.""" 6204 if self.
ctx.ref()
is not None:
6211 out.write(u(
'<table border="1" cellpadding="2" cellspacing="0">'))
6214 out.write(u(
'<tr style="background-color:#CFCFCF">'))
6217 out.write(u(
'<tr>'))
6219 out.write(u(
'<td>%s</td><td>%s</td></tr>' % (k, v)))
6220 out.write(u(
'</table>'))
6221 return out.getvalue()
6226 """Return the number of statistical counters. 6229 >>> s = Then('simplify', 'nlsat').solver() 6233 >>> st = s.statistics() 6240 """Return the value of statistical counter at position `idx`. The result is a pair (key, value). 6243 >>> s = Then('simplify', 'nlsat').solver() 6247 >>> st = s.statistics() 6251 ('nlsat propagations', 2) 6255 if idx >= len(self):
6264 """Return the list of statistical counters. 6267 >>> s = Then('simplify', 'nlsat').solver() 6271 >>> st = s.statistics() 6276 """Return the value of a particular statistical counter. 6279 >>> s = Then('simplify', 'nlsat').solver() 6283 >>> st = s.statistics() 6284 >>> st.get_key_value('nlsat propagations') 6287 for idx
in range(len(self)):
6293 raise Z3Exception(
"unknown key")
6296 """Access the value of statistical using attributes. 6298 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'), 6299 we should use '_' (e.g., 'nlsat_propagations'). 6302 >>> s = Then('simplify', 'nlsat').solver() 6306 >>> st = s.statistics() 6307 >>> st.nlsat_propagations 6312 key = name.replace(
'_',
' ')
6316 raise AttributeError
6324 """Represents the result of a satisfiability check: sat, unsat, unknown. 6330 >>> isinstance(r, CheckSatResult) 6341 return isinstance(other, CheckSatResult)
and self.
r == other.r
6344 return not self.
__eq__(other)
6348 if self.
r == Z3_L_TRUE:
6350 elif self.
r == Z3_L_FALSE:
6351 return "<b>unsat</b>" 6353 return "<b>unknown</b>" 6355 if self.
r == Z3_L_TRUE:
6357 elif self.
r == Z3_L_FALSE:
6367 """Solver API provides methods for implementing the main SMT 2.0 commands: push, pop, check, get-model, etc.""" 6370 assert solver
is None or ctx
is not None 6381 if self.
solver is not None and self.
ctx.ref()
is not None:
6385 """Set a configuration option. The method `help()` return a string containing all available options. 6388 >>> # The option MBQI can be set using three different approaches. 6389 >>> s.set(mbqi=True) 6390 >>> s.set('MBQI', True) 6391 >>> s.set(':mbqi', True) 6397 """Create a backtracking point. 6419 """Backtrack \c num backtracking points. 6441 """Return the current number of backtracking points. 6459 """Remove all asserted constraints and backtracking points created using `push()`. 6473 """Assert constraints into the solver. 6477 >>> s.assert_exprs(x > 0, x < 2) 6481 args = _get_args(args)
6484 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6492 """Assert constraints into the solver. 6496 >>> s.add(x > 0, x < 2) 6507 """Assert constraints into the solver. 6511 >>> s.append(x > 0, x < 2) 6518 """Assert constraints into the solver. 6522 >>> s.insert(x > 0, x < 2) 6529 """Assert constraint `a` and track it in the unsat core using the Boolean constant `p`. 6531 If `p` is a string, it will be automatically converted into a Boolean constant. 6536 >>> s.set(unsat_core=True) 6537 >>> s.assert_and_track(x > 0, 'p1') 6538 >>> s.assert_and_track(x != 1, 'p2') 6539 >>> s.assert_and_track(x < 0, p3) 6540 >>> print(s.check()) 6542 >>> c = s.unsat_core() 6552 if isinstance(p, str):
6554 _z3_assert(isinstance(a, BoolRef),
"Boolean expression expected")
6555 _z3_assert(isinstance(p, BoolRef)
and is_const(p),
"Boolean expression expected")
6559 """Check whether the assertions in the given solver plus the optional assumptions are consistent or not. 6565 >>> s.add(x > 0, x < 2) 6568 >>> s.model().eval(x) 6574 >>> s.add(2**x == 4) 6578 assumptions = _get_args(assumptions)
6579 num = len(assumptions)
6580 _assumptions = (Ast * num)()
6581 for i
in range(num):
6582 _assumptions[i] = assumptions[i].as_ast()
6587 """Return a model for the last `check()`. 6589 This function raises an exception if 6590 a model is not available (e.g., last `check()` returned unsat). 6594 >>> s.add(a + 2 == 0) 6603 raise Z3Exception(
"model is not available")
6606 """Return a subset (as an AST vector) of the assumptions provided to the last check(). 6608 These are the assumptions Z3 used in the unsatisfiability proof. 6609 Assumptions are available in Z3. They are used to extract unsatisfiable cores. 6610 They may be also used to "retract" assumptions. Note that, assumptions are not really 6611 "soft constraints", but they can be used to implement them. 6613 >>> p1, p2, p3 = Bools('p1 p2 p3') 6614 >>> x, y = Ints('x y') 6616 >>> s.add(Implies(p1, x > 0)) 6617 >>> s.add(Implies(p2, y > x)) 6618 >>> s.add(Implies(p2, y < 1)) 6619 >>> s.add(Implies(p3, y > -3)) 6620 >>> s.check(p1, p2, p3) 6622 >>> core = s.unsat_core() 6631 >>> # "Retracting" p2 6638 """Determine fixed values for the variables based on the solver state and assumptions. 6640 >>> a, b, c, d = Bools('a b c d') 6641 >>> s.add(Implies(a,b), Implies(b, c)) 6642 >>> s.consequences([a],[b,c,d]) 6643 (sat, [Implies(a, b), Implies(a, c)]) 6644 >>> s.consequences([Not(c),d],[a,b,c,d]) 6645 (sat, [Implies(d, d), Implies(Not(c), Not(c)), Implies(Not(c), Not(b)), Implies(Not(c), Not(a))]) 6647 if isinstance(assumptions, list):
6649 for a
in assumptions:
6652 if isinstance(variables, list):
6657 _z3_assert(isinstance(assumptions, AstVector),
"ast vector expected")
6658 _z3_assert(isinstance(variables, AstVector),
"ast vector expected")
6661 sz = len(consequences)
6662 consequences = [ consequences[i]
for i
in range(sz) ]
6666 """Parse assertions from a file""" 6669 except Z3Exception
as e:
6670 _handle_parse_error(e, self.
ctx)
6673 """Parse assertions from a string""" 6676 except Z3Exception
as e:
6677 _handle_parse_error(e, self.
ctx)
6681 The method takes an optional set of variables that restrict which 6682 variables may be used as a starting point for cubing. 6683 If vars is not None, then the first case split is based on a variable in 6687 if vars
is not None:
6694 if (len(r) == 1
and is_false(r[0])):
6701 """Access the set of variables that were touched by the most recently generated cube. 6702 This set of variables can be used as a starting point for additional cubes. 6703 The idea is that variables that appear in clauses that are reduced by the most recent 6704 cube are likely more useful to cube on.""" 6708 """Return a proof for the last `check()`. Proof construction must be enabled.""" 6712 """Return an AST vector containing all added constraints. 6726 """Return an AST vector containing all currently inferred units. 6731 """Return an AST vector containing all atomic formulas in solver state that are not units. 6736 """Return statistics for the last `check()`. 6738 >>> s = SimpleSolver() 6743 >>> st = s.statistics() 6744 >>> st.get_key_value('final checks') 6754 """Return a string describing why the last `check()` returned `unknown`. 6757 >>> s = SimpleSolver() 6758 >>> s.add(2**x == 4) 6761 >>> s.reason_unknown() 6762 '(incomplete (theory arithmetic))' 6767 """Display a string describing all available options.""" 6771 """Return the parameter description set.""" 6775 """Return a formatted string with all added constraints.""" 6776 return obj_to_string(self)
6779 """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 6783 >>> s1 = Solver(ctx=c1) 6784 >>> s2 = s1.translate(c2) 6787 _z3_assert(isinstance(target, Context),
"argument must be a Z3 context")
6789 return Solver(solver, target)
6798 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format. 6809 """return SMTLIB2 formatted benchmark for solver's assertions""" 6816 for i
in range(sz1):
6817 v[i] = es[i].as_ast()
6819 e = es[sz1].as_ast()
6825 """Create a solver customized for the given logic. 6827 The parameter `logic` is a string. It should be contains 6828 the name of a SMT-LIB logic. 6829 See http://www.smtlib.org/ for the name of all available logics. 6831 >>> s = SolverFor("QF_LIA") 6845 """Return a simple general purpose solver with limited amount of preprocessing. 6847 >>> s = SimpleSolver() 6863 """Fixedpoint API provides methods for solving with recursive predicates""" 6866 assert fixedpoint
is None or ctx
is not None 6869 if fixedpoint
is None:
6880 if self.
fixedpoint is not None and self.
ctx.ref()
is not None:
6884 """Set a configuration option. The method `help()` return a string containing all available options. 6890 """Display a string describing all available options.""" 6894 """Return the parameter description set.""" 6898 """Assert constraints as background axioms for the fixedpoint solver.""" 6899 args = _get_args(args)
6902 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
6912 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.""" 6920 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.""" 6924 """Assert constraints as background axioms for the fixedpoint solver. Alias for assert_expr.""" 6928 """Assert rules defining recursive predicates to the fixedpoint solver. 6931 >>> s = Fixedpoint() 6932 >>> s.register_relation(a.decl()) 6933 >>> s.register_relation(b.decl()) 6946 body = _get_args(body)
6950 def rule(self, head, body = None, name = None):
6951 """Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule.""" 6955 """Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule.""" 6959 """Query the fixedpoint engine whether formula is derivable. 6960 You can also pass an tuple or list of recursive predicates. 6962 query = _get_args(query)
6964 if sz >= 1
and isinstance(query[0], FuncDeclRef):
6965 _decls = (FuncDecl * sz)()
6975 query =
And(query, self.
ctx)
6976 query = self.
abstract(query,
False)
6981 """Query the fixedpoint engine whether formula is derivable starting at the given query level. 6983 query = _get_args(query)
6985 if sz >= 1
and isinstance(query[0], FuncDecl):
6986 _z3_assert (
False,
"unsupported")
6992 query = self.
abstract(query,
False)
6993 r = Z3_fixedpoint_query_from_lvl (self.
ctx.ref(), self.
fixedpoint, query.as_ast(), lvl)
6997 """create a backtracking point for added rules, facts and assertions""" 7001 """restore to previously created backtracking point""" 7009 body = _get_args(body)
7014 """Retrieve answer from last query call.""" 7016 return _to_expr_ref(r, self.
ctx)
7019 """Retrieve a ground cex from last query call.""" 7020 r = Z3_fixedpoint_get_ground_sat_answer(self.
ctx.ref(), self.
fixedpoint)
7021 return _to_expr_ref(r, self.
ctx)
7024 """retrieve rules along the counterexample trace""" 7028 """retrieve rule names along the counterexample trace""" 7031 names = _symbol2py (self.
ctx, Z3_fixedpoint_get_rule_names_along_trace(self.
ctx.ref(), self.
fixedpoint))
7033 return names.split (
';')
7036 """Retrieve number of levels used for predicate in PDR engine""" 7040 """Retrieve properties known about predicate for the level'th unfolding. -1 is treated as the limit (infinity)""" 7042 return _to_expr_ref(r, self.
ctx)
7045 """Add property to predicate for the level'th unfolding. -1 is treated as infinity (infinity)""" 7049 """Register relation as recursive""" 7050 relations = _get_args(relations)
7055 """Control how relation is represented""" 7056 representations = _get_args(representations)
7057 representations = [
to_symbol(s)
for s
in representations]
7058 sz = len(representations)
7059 args = (Symbol * sz)()
7061 args[i] = representations[i]
7065 """Parse rules and queries from a string""" 7068 except Z3Exception
as e:
7069 _handle_parse_error(e, self.
ctx)
7072 """Parse rules and queries from a file""" 7075 except Z3Exception
as e:
7076 _handle_parse_error(e, self.
ctx)
7079 """retrieve rules that have been added to fixedpoint context""" 7083 """retrieve assertions that have been added to fixedpoint context""" 7087 """Return a formatted string with all added rules and constraints.""" 7091 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format. 7096 """Return a formatted string (in Lisp-like format) with all added constraints. 7097 We say the string is in s-expression format. 7098 Include also queries. 7100 args, len = _to_ast_array(queries)
7104 """Return statistics for the last `query()`. 7109 """Return a string describing why the last `query()` returned `unknown`. 7114 """Add variable or several variables. 7115 The added variable or variables will be bound in the rules 7118 vars = _get_args(vars)
7138 """Finite domain sort.""" 7141 """Return the size of the finite domain sort""" 7142 r = (ctypes.c_ulonglong * 1)()
7146 raise Z3Exception(
"Failed to retrieve finite domain sort size")
7149 """Create a named finite domain sort of a given size sz""" 7150 if not isinstance(name, Symbol):
7156 """Return True if `s` is a Z3 finite-domain sort. 7158 >>> is_finite_domain_sort(FiniteDomainSort('S', 100)) 7160 >>> is_finite_domain_sort(IntSort()) 7163 return isinstance(s, FiniteDomainSortRef)
7167 """Finite-domain expressions.""" 7170 """Return the sort of the finite-domain expression `self`.""" 7174 """Return a Z3 floating point expression as a Python string.""" 7178 """Return `True` if `a` is a Z3 finite-domain expression. 7180 >>> s = FiniteDomainSort('S', 100) 7181 >>> b = Const('b', s) 7182 >>> is_finite_domain(b) 7184 >>> is_finite_domain(Int('x')) 7187 return isinstance(a, FiniteDomainRef)
7191 """Integer values.""" 7194 """Return a Z3 finite-domain numeral as a Python long (bignum) numeral. 7196 >>> s = FiniteDomainSort('S', 100) 7197 >>> v = FiniteDomainVal(3, s) 7206 """Return a Z3 finite-domain numeral as a Python string. 7208 >>> s = FiniteDomainSort('S', 100) 7209 >>> v = FiniteDomainVal(42, s) 7217 """Return a Z3 finite-domain value. If `ctx=None`, then the global context is used. 7219 >>> s = FiniteDomainSort('S', 256) 7220 >>> FiniteDomainVal(255, s) 7222 >>> FiniteDomainVal('100', s) 7231 """Return `True` if `a` is a Z3 finite-domain value. 7233 >>> s = FiniteDomainSort('S', 100) 7234 >>> b = Const('b', s) 7235 >>> is_finite_domain_value(b) 7237 >>> b = FiniteDomainVal(10, s) 7240 >>> is_finite_domain_value(b) 7285 """Optimize API provides methods for solving using objective functions and weighted soft constraints""" 7296 if self.
optimize is not None and self.
ctx.ref()
is not None:
7300 """Set a configuration option. The method `help()` return a string containing all available options. 7306 """Display a string describing all available options.""" 7310 """Return the parameter description set.""" 7314 """Assert constraints as background axioms for the optimize solver.""" 7315 args = _get_args(args)
7318 if isinstance(arg, Goal)
or isinstance(arg, AstVector):
7326 """Assert constraints as background axioms for the optimize solver. Alias for assert_expr.""" 7334 """Add soft constraint with optional weight and optional identifier. 7335 If no weight is supplied, then the penalty for violating the soft constraint 7337 Soft constraints are grouped by identifiers. Soft constraints that are 7338 added without identifiers are grouped by default. 7341 weight =
"%d" % weight
7342 elif isinstance(weight, float):
7343 weight =
"%f" % weight
7344 if not isinstance(weight, str):
7345 raise Z3Exception(
"weight should be a string or an integer")
7353 """Add objective function to maximize.""" 7357 """Add objective function to minimize.""" 7361 """create a backtracking point for added rules, facts and assertions""" 7365 """restore to previously created backtracking point""" 7369 """Check satisfiability while optimizing objective functions.""" 7370 assumptions = _get_args(assumptions)
7371 num = len(assumptions)
7372 _assumptions = (Ast * num)()
7373 for i
in range(num):
7374 _assumptions[i] = assumptions[i].as_ast()
7378 """Return a string that describes why the last `check()` returned `unknown`.""" 7382 """Return a model for the last check().""" 7386 raise Z3Exception(
"model is not available")
7392 if not isinstance(obj, OptimizeObjective):
7393 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7397 if not isinstance(obj, OptimizeObjective):
7398 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7402 if not isinstance(obj, OptimizeObjective):
7403 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7404 return obj.lower_values()
7407 if not isinstance(obj, OptimizeObjective):
7408 raise Z3Exception(
"Expecting objective handle returned by maximize/minimize")
7409 return obj.upper_values()
7412 """Parse assertions and objectives from a file""" 7415 except Z3Exception
as e:
7416 _handle_parse_error(e, self.
ctx)
7419 """Parse assertions and objectives from a string""" 7422 except Z3Exception
as e:
7423 _handle_parse_error(e, self.
ctx)
7426 """Return an AST vector containing all added constraints.""" 7430 """returns set of objective functions""" 7434 """Return a formatted string with all added rules and constraints.""" 7438 """Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format. 7443 """Return statistics for the last check`. 7456 """An ApplyResult object contains the subgoals produced by a tactic when applied to a goal. It also contains model and proof converters.""" 7467 if self.
ctx.ref()
is not None:
7471 """Return the number of subgoals in `self`. 7473 >>> a, b = Ints('a b') 7475 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b) 7476 >>> t = Tactic('split-clause') 7480 >>> t = Then(Tactic('split-clause'), Tactic('split-clause')) 7483 >>> t = Then(Tactic('split-clause'), Tactic('split-clause'), Tactic('propagate-values')) 7490 """Return one of the subgoals stored in ApplyResult object `self`. 7492 >>> a, b = Ints('a b') 7494 >>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b) 7495 >>> t = Tactic('split-clause') 7498 [a == 0, Or(b == 0, b == 1), a > b] 7500 [a == 1, Or(b == 0, b == 1), a > b] 7502 if idx >= len(self):
7507 return obj_to_string(self)
7510 """Return a textual representation of the s-expression representing the set of subgoals in `self`.""" 7515 """Return a Z3 expression consisting of all subgoals. 7520 >>> g.add(Or(x == 2, x == 3)) 7521 >>> r = Tactic('simplify')(g) 7523 [[Not(x <= 1), Or(x == 2, x == 3)]] 7525 And(Not(x <= 1), Or(x == 2, x == 3)) 7526 >>> r = Tactic('split-clause')(g) 7528 [[x > 1, x == 2], [x > 1, x == 3]] 7530 Or(And(x > 1, x == 2), And(x > 1, x == 3)) 7546 """Tactics transform, solver and/or simplify sets of constraints (Goal). A Tactic can be converted into a Solver using the method solver(). 7548 Several combinators are available for creating new tactics using the built-in ones: Then(), OrElse(), FailIf(), Repeat(), When(), Cond(). 7553 if isinstance(tactic, TacticObj):
7557 _z3_assert(isinstance(tactic, str),
"tactic name expected")
7561 raise Z3Exception(
"unknown tactic '%s'" % tactic)
7568 if self.
tactic is not None and self.
ctx.ref()
is not None:
7572 """Create a solver using the tactic `self`. 7574 The solver supports the methods `push()` and `pop()`, but it 7575 will always solve each `check()` from scratch. 7577 >>> t = Then('simplify', 'nlsat') 7580 >>> s.add(x**2 == 2, x > 0) 7588 def apply(self, goal, *arguments, **keywords):
7589 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options. 7591 >>> x, y = Ints('x y') 7592 >>> t = Tactic('solve-eqs') 7593 >>> t.apply(And(x == 0, y >= x + 1)) 7597 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expressions expected")
7598 goal = _to_goal(goal)
7599 if len(arguments) > 0
or len(keywords) > 0:
7606 """Apply tactic `self` to the given goal or Z3 Boolean expression using the given options. 7608 >>> x, y = Ints('x y') 7609 >>> t = Tactic('solve-eqs') 7610 >>> t(And(x == 0, y >= x + 1)) 7613 return self.
apply(goal, *arguments, **keywords)
7616 """Display a string containing a description of the available options for the `self` tactic.""" 7620 """Return the parameter description set.""" 7624 if isinstance(a, BoolRef):
7625 goal =
Goal(ctx = a.ctx)
7631 def _to_tactic(t, ctx=None):
7632 if isinstance(t, Tactic):
7637 def _and_then(t1, t2, ctx=None):
7638 t1 = _to_tactic(t1, ctx)
7639 t2 = _to_tactic(t2, ctx)
7641 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7644 def _or_else(t1, t2, ctx=None):
7645 t1 = _to_tactic(t1, ctx)
7646 t2 = _to_tactic(t2, ctx)
7648 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7652 """Return a tactic that applies the tactics in `*ts` in sequence. 7654 >>> x, y = Ints('x y') 7655 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs')) 7656 >>> t(And(x == 0, y > x + 1)) 7658 >>> t(And(x == 0, y > x + 1)).as_expr() 7662 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7663 ctx = ks.get(
'ctx',
None)
7666 for i
in range(num - 1):
7667 r = _and_then(r, ts[i+1], ctx)
7671 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks). 7673 >>> x, y = Ints('x y') 7674 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs')) 7675 >>> t(And(x == 0, y > x + 1)) 7677 >>> t(And(x == 0, y > x + 1)).as_expr() 7683 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail). 7686 >>> t = OrElse(Tactic('split-clause'), Tactic('skip')) 7687 >>> # Tactic split-clause fails if there is no clause in the given goal. 7690 >>> t(Or(x == 0, x == 1)) 7691 [[x == 0], [x == 1]] 7694 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7695 ctx = ks.get(
'ctx',
None)
7698 for i
in range(num - 1):
7699 r = _or_else(r, ts[i+1], ctx)
7703 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail). 7706 >>> t = ParOr(Tactic('simplify'), Tactic('fail')) 7711 _z3_assert(len(ts) >= 2,
"At least two arguments expected")
7712 ctx = _get_ctx(ks.get(
'ctx',
None))
7713 ts = [ _to_tactic(t, ctx)
for t
in ts ]
7715 _args = (TacticObj * sz)()
7717 _args[i] = ts[i].tactic
7721 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel. 7723 >>> x, y = Ints('x y') 7724 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values')) 7725 >>> t(And(Or(x == 1, x == 2), y == x + 1)) 7726 [[x == 1, y == 2], [x == 2, y == 3]] 7728 t1 = _to_tactic(t1, ctx)
7729 t2 = _to_tactic(t2, ctx)
7731 _z3_assert(t1.ctx == t2.ctx,
"Context mismatch")
7735 """Alias for ParThen(t1, t2, ctx).""" 7739 """Return a tactic that applies tactic `t` using the given configuration options. 7741 >>> x, y = Ints('x y') 7742 >>> t = With(Tactic('simplify'), som=True) 7743 >>> t((x + 1)*(y + 2) == 0) 7744 [[2*x + y + x*y == -2]] 7746 ctx = keys.pop(
'ctx',
None)
7747 t = _to_tactic(t, ctx)
7752 """Return a tactic that applies tactic `t` using the given configuration options. 7754 >>> x, y = Ints('x y') 7756 >>> p.set("som", True) 7757 >>> t = WithParams(Tactic('simplify'), p) 7758 >>> t((x + 1)*(y + 2) == 0) 7759 [[2*x + y + x*y == -2]] 7761 t = _to_tactic(t,
None)
7765 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached. 7767 >>> x, y = Ints('x y') 7768 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y) 7769 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip'))) 7771 >>> for subgoal in r: print(subgoal) 7772 [x == 0, y == 0, x > y] 7773 [x == 0, y == 1, x > y] 7774 [x == 1, y == 0, x > y] 7775 [x == 1, y == 1, x > y] 7776 >>> t = Then(t, Tactic('propagate-values')) 7780 t = _to_tactic(t, ctx)
7784 """Return a tactic that applies `t` to a given goal for `ms` milliseconds. 7786 If `t` does not terminate in `ms` milliseconds, then it fails. 7788 t = _to_tactic(t, ctx)
7792 """Return a list of all available tactics in Z3. 7795 >>> l.count('simplify') == 1 7802 """Return a short description for the tactic named `name`. 7804 >>> d = tactic_description('simplify') 7810 """Display a (tabular) description of all available tactics in Z3.""" 7813 print(
'<table border="1" cellpadding="2" cellspacing="0">')
7816 print(
'<tr style="background-color:#CFCFCF">')
7821 print(
'<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(
tactic_description(t), 40)))
7828 """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.""" 7832 if isinstance(probe, ProbeObj):
7834 elif isinstance(probe, float):
7836 elif _is_int(probe):
7838 elif isinstance(probe, bool):
7845 _z3_assert(isinstance(probe, str),
"probe name expected")
7849 raise Z3Exception(
"unknown probe '%s'" % probe)
7856 if self.
probe is not None and self.
ctx.ref()
is not None:
7860 """Return a probe that evaluates to "true" when the value returned by `self` is less than the value returned by `other`. 7862 >>> p = Probe('size') < 10 7873 """Return a probe that evaluates to "true" when the value returned by `self` is greater than the value returned by `other`. 7875 >>> p = Probe('size') > 10 7886 """Return a probe that evaluates to "true" when the value returned by `self` is less than or equal to the value returned by `other`. 7888 >>> p = Probe('size') <= 2 7899 """Return a probe that evaluates to "true" when the value returned by `self` is greater than or equal to the value returned by `other`. 7901 >>> p = Probe('size') >= 2 7912 """Return a probe that evaluates to "true" when the value returned by `self` is equal to the value returned by `other`. 7914 >>> p = Probe('size') == 2 7925 """Return a probe that evaluates to "true" when the value returned by `self` is not equal to the value returned by `other`. 7927 >>> p = Probe('size') != 2 7939 """Evaluate the probe `self` in the given goal. 7941 >>> p = Probe('size') 7951 >>> p = Probe('num-consts') 7954 >>> p = Probe('is-propositional') 7957 >>> p = Probe('is-qflia') 7962 _z3_assert(isinstance(goal, Goal)
or isinstance(goal, BoolRef),
"Z3 Goal or Boolean expression expected")
7963 goal = _to_goal(goal)
7967 """Return `True` if `p` is a Z3 probe. 7969 >>> is_probe(Int('x')) 7971 >>> is_probe(Probe('memory')) 7974 return isinstance(p, Probe)
7976 def _to_probe(p, ctx=None):
7980 return Probe(p, ctx)
7983 """Return a list of all available probes in Z3. 7986 >>> l.count('memory') == 1 7993 """Return a short description for the probe named `name`. 7995 >>> d = probe_description('memory') 8001 """Display a (tabular) description of all available probes in Z3.""" 8004 print(
'<table border="1" cellpadding="2" cellspacing="0">')
8007 print(
'<tr style="background-color:#CFCFCF">')
8012 print(
'<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(
probe_description(p), 40)))
8018 def _probe_nary(f, args, ctx):
8020 _z3_assert(len(args) > 0,
"At least one argument expected")
8022 r = _to_probe(args[0], ctx)
8023 for i
in range(num - 1):
8024 r =
Probe(f(ctx.ref(), r.probe, _to_probe(args[i+1], ctx).probe), ctx)
8027 def _probe_and(args, ctx):
8028 return _probe_nary(Z3_probe_and, args, ctx)
8030 def _probe_or(args, ctx):
8031 return _probe_nary(Z3_probe_or, args, ctx)
8034 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified. 8036 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal. 8038 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify')) 8039 >>> x, y = Ints('x y') 8045 >>> g.add(x == y + 1) 8047 [[Not(x <= 0), Not(y <= 0), x == 1 + y]] 8049 p = _to_probe(p, ctx)
8053 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified. 8055 >>> t = When(Probe('size') > 2, Tactic('simplify')) 8056 >>> x, y = Ints('x y') 8062 >>> g.add(x == y + 1) 8064 [[Not(x <= 0), Not(y <= 0), x == 1 + y]] 8066 p = _to_probe(p, ctx)
8067 t = _to_tactic(t, ctx)
8071 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise. 8073 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt')) 8075 p = _to_probe(p, ctx)
8076 t1 = _to_tactic(t1, ctx)
8077 t2 = _to_tactic(t2, ctx)
8087 """Simplify the expression `a` using the given options. 8089 This function has many options. Use `help_simplify` to obtain the complete list. 8093 >>> simplify(x + 1 + y + x + 1) 8095 >>> simplify((x + 1)*(y + 1), som=True) 8097 >>> simplify(Distinct(x, y, 1), blast_distinct=True) 8098 And(Not(x == y), Not(x == 1), Not(y == 1)) 8099 >>> simplify(And(x == 0, y == 1), elim_and=True) 8100 Not(Or(Not(x == 0), Not(y == 1))) 8103 _z3_assert(
is_expr(a),
"Z3 expression expected")
8104 if len(arguments) > 0
or len(keywords) > 0:
8106 return _to_expr_ref(
Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx)
8108 return _to_expr_ref(
Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
8111 """Return a string describing all options available for Z3 `simplify` procedure.""" 8115 """Return the set of parameter descriptions for Z3 `simplify` procedure.""" 8119 """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. 8123 >>> substitute(x + 1, (x, y + 1)) 8125 >>> f = Function('f', IntSort(), IntSort()) 8126 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1))) 8129 if isinstance(m, tuple):
8131 if isinstance(m1, list)
and all(isinstance(p, tuple)
for p
in m1):
8134 _z3_assert(
is_expr(t),
"Z3 expression expected")
8135 _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.")
8137 _from = (Ast * num)()
8139 for i
in range(num):
8140 _from[i] = m[i][0].as_ast()
8141 _to[i] = m[i][1].as_ast()
8142 return _to_expr_ref(
Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
8145 """Substitute the free variables in t with the expression in m. 8147 >>> v0 = Var(0, IntSort()) 8148 >>> v1 = Var(1, IntSort()) 8150 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 8151 >>> # replace v0 with x+1 and v1 with x 8152 >>> substitute_vars(f(v0, v1), x + 1, x) 8156 _z3_assert(
is_expr(t),
"Z3 expression expected")
8157 _z3_assert(all([
is_expr(n)
for n
in m]),
"Z3 invalid substitution, list of expressions expected.")
8160 for i
in range(num):
8161 _to[i] = m[i].as_ast()
8165 """Create the sum of the Z3 expressions. 8167 >>> a, b, c = Ints('a b c') 8172 >>> A = IntVector('a', 5) 8174 a__0 + a__1 + a__2 + a__3 + a__4 8176 args = _get_args(args)
8179 ctx = _ctx_from_ast_arg_list(args)
8181 return _reduce(
lambda a, b: a + b, args, 0)
8182 args = _coerce_expr_list(args, ctx)
8184 return _reduce(
lambda a, b: a + b, args, 0)
8186 _args, sz = _to_ast_array(args)
8191 """Create the product of the Z3 expressions. 8193 >>> a, b, c = Ints('a b c') 8194 >>> Product(a, b, c) 8196 >>> Product([a, b, c]) 8198 >>> A = IntVector('a', 5) 8200 a__0*a__1*a__2*a__3*a__4 8202 args = _get_args(args)
8205 ctx = _ctx_from_ast_arg_list(args)
8207 return _reduce(
lambda a, b: a * b, args, 1)
8208 args = _coerce_expr_list(args, ctx)
8210 return _reduce(
lambda a, b: a * b, args, 1)
8212 _args, sz = _to_ast_array(args)
8216 """Create an at-most Pseudo-Boolean k constraint. 8218 >>> a, b, c = Bools('a b c') 8219 >>> f = AtMost(a, b, c, 2) 8221 args = _get_args(args)
8223 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8224 ctx = _ctx_from_ast_arg_list(args)
8226 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8227 args1 = _coerce_expr_list(args[:-1], ctx)
8229 _args, sz = _to_ast_array(args1)
8233 """Create an at-most Pseudo-Boolean k constraint. 8235 >>> a, b, c = Bools('a b c') 8236 >>> f = AtLeast(a, b, c, 2) 8238 args = _get_args(args)
8240 _z3_assert(len(args) > 1,
"Non empty list of arguments expected")
8241 ctx = _ctx_from_ast_arg_list(args)
8243 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8244 args1 = _coerce_expr_list(args[:-1], ctx)
8246 _args, sz = _to_ast_array(args1)
8250 def _pb_args_coeffs(args, default_ctx = None):
8251 args = _get_args_ast_list(args)
8253 return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
8254 args, coeffs = zip(*args)
8256 _z3_assert(len(args) > 0,
"Non empty list of arguments expected")
8257 ctx = _ctx_from_ast_arg_list(args)
8259 _z3_assert(ctx
is not None,
"At least one of the arguments must be a Z3 expression")
8260 args = _coerce_expr_list(args, ctx)
8261 _args, sz = _to_ast_array(args)
8262 _coeffs = (ctypes.c_int * len(coeffs))()
8263 for i
in range(len(coeffs)):
8264 _z3_check_cint_overflow(coeffs[i],
"coefficient")
8265 _coeffs[i] = coeffs[i]
8266 return ctx, sz, _args, _coeffs
8269 """Create a Pseudo-Boolean inequality k constraint. 8271 >>> a, b, c = Bools('a b c') 8272 >>> f = PbLe(((a,1),(b,3),(c,2)), 3) 8274 _z3_check_cint_overflow(k,
"k")
8275 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8279 """Create a Pseudo-Boolean inequality k constraint. 8281 >>> a, b, c = Bools('a b c') 8282 >>> f = PbGe(((a,1),(b,3),(c,2)), 3) 8284 _z3_check_cint_overflow(k,
"k")
8285 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8289 """Create a Pseudo-Boolean inequality k constraint. 8291 >>> a, b, c = Bools('a b c') 8292 >>> f = PbEq(((a,1),(b,3),(c,2)), 3) 8294 _z3_check_cint_overflow(k,
"k")
8295 ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
8300 """Solve the constraints `*args`. 8302 This is a simple function for creating demonstrations. It creates a solver, 8303 configure it using the options in `keywords`, adds the constraints 8304 in `args`, and invokes check. 8307 >>> solve(a > 0, a < 2) 8313 if keywords.get(
'show',
False):
8317 print(
"no solution")
8319 print(
"failed to solve")
8328 """Solve the constraints `*args` using solver `s`. 8330 This is a simple function for creating demonstrations. It is similar to `solve`, 8331 but it uses the given solver `s`. 8332 It configures solver `s` using the options in `keywords`, adds the constraints 8333 in `args`, and invokes check. 8336 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8339 if keywords.get(
'show',
False):
8344 print(
"no solution")
8346 print(
"failed to solve")
8352 if keywords.get(
'show',
False):
8357 """Try to prove the given claim. 8359 This is a simple function for creating demonstrations. It tries to prove 8360 `claim` by showing the negation is unsatisfiable. 8362 >>> p, q = Bools('p q') 8363 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q))) 8367 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8371 if keywords.get(
'show',
False):
8377 print(
"failed to prove")
8380 print(
"counterexample")
8383 def _solve_html(*args, **keywords):
8384 """Version of function `solve` used in RiSE4Fun.""" 8388 if keywords.get(
'show',
False):
8389 print(
"<b>Problem:</b>")
8393 print(
"<b>no solution</b>")
8395 print(
"<b>failed to solve</b>")
8401 if keywords.get(
'show',
False):
8402 print(
"<b>Solution:</b>")
8405 def _solve_using_html(s, *args, **keywords):
8406 """Version of function `solve_using` used in RiSE4Fun.""" 8408 _z3_assert(isinstance(s, Solver),
"Solver object expected")
8411 if keywords.get(
'show',
False):
8412 print(
"<b>Problem:</b>")
8416 print(
"<b>no solution</b>")
8418 print(
"<b>failed to solve</b>")
8424 if keywords.get(
'show',
False):
8425 print(
"<b>Solution:</b>")
8428 def _prove_html(claim, **keywords):
8429 """Version of function `prove` used in RiSE4Fun.""" 8431 _z3_assert(
is_bool(claim),
"Z3 Boolean expression expected")
8435 if keywords.get(
'show',
False):
8439 print(
"<b>proved</b>")
8441 print(
"<b>failed to prove</b>")
8444 print(
"<b>counterexample</b>")
8447 def _dict2sarray(sorts, ctx):
8449 _names = (Symbol * sz)()
8450 _sorts = (Sort * sz) ()
8455 _z3_assert(isinstance(k, str),
"String expected")
8456 _z3_assert(
is_sort(v),
"Z3 sort expected")
8460 return sz, _names, _sorts
8462 def _dict2darray(decls, ctx):
8464 _names = (Symbol * sz)()
8465 _decls = (FuncDecl * sz) ()
8470 _z3_assert(isinstance(k, str),
"String expected")
8474 _decls[i] = v.decl().ast
8478 return sz, _names, _decls
8482 """Parse a string in SMT 2.0 format using the given sorts and decls. 8484 The arguments sorts and decls are Python dictionaries used to initialize 8485 the symbol table used for the SMT 2.0 parser. 8487 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))') 8489 >>> x, y = Ints('x y') 8490 >>> f = Function('f', IntSort(), IntSort()) 8491 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f}) 8493 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() }) 8497 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8498 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8502 """Parse a file in SMT 2.0 format using the given sorts and decls. 8504 This function is similar to parse_smt2_string(). 8507 ssz, snames, ssorts = _dict2sarray(sorts, ctx)
8508 dsz, dnames, ddecls = _dict2darray(decls, ctx)
8520 _dflt_rounding_mode = Z3_OP_FPA_RM_TOWARD_ZERO
8521 _dflt_fpsort_ebits = 11
8522 _dflt_fpsort_sbits = 53
8525 """Retrieves the global default rounding mode.""" 8526 global _dflt_rounding_mode
8527 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO:
8529 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE:
8531 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE:
8533 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN:
8535 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY:
8539 global _dflt_rounding_mode
8541 _dflt_rounding_mode = rm.decl().kind()
8543 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO
or 8544 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE
or 8545 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE
or 8546 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN
or 8547 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY,
8548 "illegal rounding mode")
8549 _dflt_rounding_mode = rm
8552 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
8555 global _dflt_fpsort_ebits
8556 global _dflt_fpsort_sbits
8557 _dflt_fpsort_ebits = ebits
8558 _dflt_fpsort_sbits = sbits
8560 def _dflt_rm(ctx=None):
8563 def _dflt_fps(ctx=None):
8566 def _coerce_fp_expr_list(alist, ctx):
8567 first_fp_sort =
None 8570 if first_fp_sort
is None:
8571 first_fp_sort = a.sort()
8572 elif first_fp_sort == a.sort():
8577 first_fp_sort =
None 8581 for i
in range(len(alist)):
8583 if (isinstance(a, str)
and a.contains(
'2**(')
and a.endswith(
')'))
or _is_int(a)
or isinstance(a, float)
or isinstance(a, bool):
8584 r.append(
FPVal(a,
None, first_fp_sort, ctx))
8587 return _coerce_expr_list(r, ctx)
8593 """Floating-point sort.""" 8596 """Retrieves the number of bits reserved for the exponent in the FloatingPoint sort `self`. 8597 >>> b = FPSort(8, 24) 8604 """Retrieves the number of bits reserved for the significand in the FloatingPoint sort `self`. 8605 >>> b = FPSort(8, 24) 8612 """Try to cast `val` as a floating-point expression. 8613 >>> b = FPSort(8, 24) 8616 >>> b.cast(1.0).sexpr() 8617 '(fp #b0 #x7f #b00000000000000000000000)' 8621 _z3_assert(self.
ctx == val.ctx,
"Context mismatch")
8624 return FPVal(val,
None, self, self.
ctx)
8628 """Floating-point 16-bit (half) sort.""" 8633 """Floating-point 16-bit (half) sort.""" 8638 """Floating-point 32-bit (single) sort.""" 8643 """Floating-point 32-bit (single) sort.""" 8648 """Floating-point 64-bit (double) sort.""" 8653 """Floating-point 64-bit (double) sort.""" 8658 """Floating-point 128-bit (quadruple) sort.""" 8663 """Floating-point 128-bit (quadruple) sort.""" 8668 """"Floating-point rounding mode sort.""" 8672 """Return True if `s` is a Z3 floating-point sort. 8674 >>> is_fp_sort(FPSort(8, 24)) 8676 >>> is_fp_sort(IntSort()) 8679 return isinstance(s, FPSortRef)
8682 """Return True if `s` is a Z3 floating-point rounding mode sort. 8684 >>> is_fprm_sort(FPSort(8, 24)) 8686 >>> is_fprm_sort(RNE().sort()) 8689 return isinstance(s, FPRMSortRef)
8694 """Floating-point expressions.""" 8697 """Return the sort of the floating-point expression `self`. 8699 >>> x = FP('1.0', FPSort(8, 24)) 8702 >>> x.sort() == FPSort(8, 24) 8708 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`. 8709 >>> b = FPSort(8, 24) 8716 """Retrieves the number of bits reserved for the exponent in the FloatingPoint expression `self`. 8717 >>> b = FPSort(8, 24) 8724 """Return a Z3 floating point expression as a Python string.""" 8728 return fpLEQ(self, other, self.
ctx)
8731 return fpLT(self, other, self.
ctx)
8734 return fpGEQ(self, other, self.
ctx)
8737 return fpGT(self, other, self.
ctx)
8740 """Create the Z3 expression `self + other`. 8742 >>> x = FP('x', FPSort(8, 24)) 8743 >>> y = FP('y', FPSort(8, 24)) 8749 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8750 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8753 """Create the Z3 expression `other + self`. 8755 >>> x = FP('x', FPSort(8, 24)) 8759 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8760 return fpAdd(_dflt_rm(), a, b, self.
ctx)
8763 """Create the Z3 expression `self - other`. 8765 >>> x = FP('x', FPSort(8, 24)) 8766 >>> y = FP('y', FPSort(8, 24)) 8772 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8773 return fpSub(_dflt_rm(), a, b, self.
ctx)
8776 """Create the Z3 expression `other - self`. 8778 >>> x = FP('x', FPSort(8, 24)) 8782 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8783 return fpSub(_dflt_rm(), a, b, self.
ctx)
8786 """Create the Z3 expression `self * other`. 8788 >>> x = FP('x', FPSort(8, 24)) 8789 >>> y = FP('y', FPSort(8, 24)) 8797 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8798 return fpMul(_dflt_rm(), a, b, self.
ctx)
8801 """Create the Z3 expression `other * self`. 8803 >>> x = FP('x', FPSort(8, 24)) 8804 >>> y = FP('y', FPSort(8, 24)) 8810 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8811 return fpMul(_dflt_rm(), a, b, self.
ctx)
8814 """Create the Z3 expression `+self`.""" 8818 """Create the Z3 expression `-self`. 8820 >>> x = FP('x', Float32()) 8827 """Create the Z3 expression `self / other`. 8829 >>> x = FP('x', FPSort(8, 24)) 8830 >>> y = FP('y', FPSort(8, 24)) 8838 [a, b] = _coerce_fp_expr_list([self, other], self.
ctx)
8839 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8842 """Create the Z3 expression `other / self`. 8844 >>> x = FP('x', FPSort(8, 24)) 8845 >>> y = FP('y', FPSort(8, 24)) 8851 [a, b] = _coerce_fp_expr_list([other, self], self.
ctx)
8852 return fpDiv(_dflt_rm(), a, b, self.
ctx)
8854 if not sys.version <
'3':
8856 """Create the Z3 expression division `self / other`.""" 8860 """Create the Z3 expression division `other / self`.""" 8864 """Create the Z3 expression mod `self % other`.""" 8865 return fpRem(self, other)
8868 """Create the Z3 expression mod `other % self`.""" 8869 return fpRem(other, self)
8872 """Floating-point rounding mode expressions""" 8875 """Return a Z3 floating point expression as a Python string.""" 8920 """Return `True` if `a` is a Z3 floating-point rounding mode expression. 8929 return isinstance(a, FPRMRef)
8932 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value.""" 8933 return is_fprm(a)
and _is_numeral(a.ctx, a.ast)
8938 """The sign of the numeral. 8940 >>> x = FPVal(+1.0, FPSort(8, 24)) 8943 >>> x = FPVal(-1.0, FPSort(8, 24)) 8948 l = (ctypes.c_int)()
8950 raise Z3Exception(
"error retrieving the sign of a numeral.")
8953 """The sign of a floating-point numeral as a bit-vector expression. 8955 Remark: NaN's are invalid arguments. 8960 """The significand of the numeral. 8962 >>> x = FPVal(2.5, FPSort(8, 24)) 8969 """The significand of the numeral as a long. 8971 >>> x = FPVal(2.5, FPSort(8, 24)) 8972 >>> x.significand_as_long() 8976 ptr = (ctypes.c_ulonglong * 1)()
8978 raise Z3Exception(
"error retrieving the significand of a numeral.")
8981 """The significand of the numeral as a bit-vector expression. 8983 Remark: NaN are invalid arguments. 8988 """The exponent of the numeral. 8990 >>> x = FPVal(2.5, FPSort(8, 24)) 8997 """The exponent of the numeral as a long. 8999 >>> x = FPVal(2.5, FPSort(8, 24)) 9000 >>> x.exponent_as_long() 9004 ptr = (ctypes.c_longlong * 1)()
9006 raise Z3Exception(
"error retrieving the exponent of a numeral.")
9009 """The exponent of the numeral as a bit-vector expression. 9011 Remark: NaNs are invalid arguments. 9016 """Indicates whether the numeral is a NaN.""" 9020 """Indicates whether the numeral is +oo or -oo.""" 9024 """Indicates whether the numeral is +zero or -zero.""" 9028 """Indicates whether the numeral is normal.""" 9032 """Indicates whether the numeral is subnormal.""" 9036 """Indicates whether the numeral is positive.""" 9040 """Indicates whether the numeral is negative.""" 9045 The string representation of the numeral. 9047 >>> x = FPVal(20, FPSort(8, 24)) 9053 return (
"FPVal(%s, %s)" % (s, self.
sort()))
9056 """Return `True` if `a` is a Z3 floating-point expression. 9058 >>> b = FP('b', FPSort(8, 24)) 9066 return isinstance(a, FPRef)
9069 """Return `True` if `a` is a Z3 floating-point numeral value. 9071 >>> b = FP('b', FPSort(8, 24)) 9074 >>> b = FPVal(1.0, FPSort(8, 24)) 9080 return is_fp(a)
and _is_numeral(a.ctx, a.ast)
9083 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used. 9085 >>> Single = FPSort(8, 24) 9086 >>> Double = FPSort(11, 53) 9089 >>> x = Const('x', Single) 9090 >>> eq(x, FP('x', FPSort(8, 24))) 9096 def _to_float_str(val, exp=0):
9097 if isinstance(val, float):
9101 sone = math.copysign(1.0, val)
9106 elif val == float(
"+inf"):
9108 elif val == float(
"-inf"):
9111 v = val.as_integer_ratio()
9114 rvs = str(num) +
'/' + str(den)
9115 res = rvs +
'p' + _to_int_str(exp)
9116 elif isinstance(val, bool):
9123 elif isinstance(val, str):
9124 inx = val.find(
'*(2**')
9127 elif val[-1] ==
')':
9129 exp = str(int(val[inx+5:-1]) + int(exp))
9131 _z3_assert(
False,
"String does not have floating-point numeral form.")
9133 _z3_assert(
False,
"Python value cannot be used to create floating-point numerals.")
9137 return res +
'p' + exp
9141 """Create a Z3 floating-point NaN term. 9143 >>> s = FPSort(8, 24) 9144 >>> set_fpa_pretty(True) 9147 >>> pb = get_fpa_pretty() 9148 >>> set_fpa_pretty(False) 9150 fpNaN(FPSort(8, 24)) 9151 >>> set_fpa_pretty(pb) 9153 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9157 """Create a Z3 floating-point +oo term. 9159 >>> s = FPSort(8, 24) 9160 >>> pb = get_fpa_pretty() 9161 >>> set_fpa_pretty(True) 9162 >>> fpPlusInfinity(s) 9164 >>> set_fpa_pretty(False) 9165 >>> fpPlusInfinity(s) 9166 fpPlusInfinity(FPSort(8, 24)) 9167 >>> set_fpa_pretty(pb) 9169 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9173 """Create a Z3 floating-point -oo term.""" 9174 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9178 """Create a Z3 floating-point +oo or -oo term.""" 9179 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9180 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9184 """Create a Z3 floating-point +0.0 term.""" 9185 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9189 """Create a Z3 floating-point -0.0 term.""" 9190 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9194 """Create a Z3 floating-point +0.0 or -0.0 term.""" 9195 _z3_assert(isinstance(s, FPSortRef),
"sort mismatch")
9196 _z3_assert(isinstance(negative, bool),
"expected Boolean flag")
9199 def FPVal(sig, exp=None, fps=None, ctx=None):
9200 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used. 9202 >>> v = FPVal(20.0, FPSort(8, 24)) 9205 >>> print("0x%.8x" % v.exponent_as_long(False)) 9207 >>> v = FPVal(2.25, FPSort(8, 24)) 9210 >>> v = FPVal(-2.25, FPSort(8, 24)) 9213 >>> FPVal(-0.0, FPSort(8, 24)) 9215 >>> FPVal(0.0, FPSort(8, 24)) 9217 >>> FPVal(+0.0, FPSort(8, 24)) 9225 fps = _dflt_fps(ctx)
9229 val = _to_float_str(sig)
9230 if val ==
"NaN" or val ==
"nan":
9234 elif val ==
"0.0" or val ==
"+0.0":
9236 elif val ==
"+oo" or val ==
"+inf" or val ==
"+Inf":
9238 elif val ==
"-oo" or val ==
"-inf" or val ==
"-Inf":
9243 def FP(name, fpsort, ctx=None):
9244 """Return a floating-point constant named `name`. 9245 `fpsort` is the floating-point sort. 9246 If `ctx=None`, then the global context is used. 9248 >>> x = FP('x', FPSort(8, 24)) 9255 >>> word = FPSort(8, 24) 9256 >>> x2 = FP('x', word) 9260 if isinstance(fpsort, FPSortRef)
and ctx
is None:
9266 def FPs(names, fpsort, ctx=None):
9267 """Return an array of floating-point constants. 9269 >>> x, y, z = FPs('x y z', FPSort(8, 24)) 9276 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z) 9277 fpMul(RNE(), fpAdd(RNE(), x, y), z) 9280 if isinstance(names, str):
9281 names = names.split(
" ")
9282 return [
FP(name, fpsort, ctx)
for name
in names]
9285 """Create a Z3 floating-point absolute value expression. 9287 >>> s = FPSort(8, 24) 9289 >>> x = FPVal(1.0, s) 9292 >>> y = FPVal(-20.0, s) 9297 >>> fpAbs(-1.25*(2**4)) 9303 [a] = _coerce_fp_expr_list([a], ctx)
9307 """Create a Z3 floating-point addition expression. 9309 >>> s = FPSort(8, 24) 9318 [a] = _coerce_fp_expr_list([a], ctx)
9321 def _mk_fp_unary(f, rm, a, ctx):
9323 [a] = _coerce_fp_expr_list([a], ctx)
9325 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9326 _z3_assert(
is_fp(a),
"Second argument must be a Z3 floating-point expression")
9327 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast()), ctx)
9329 def _mk_fp_unary_norm(f, a, ctx):
9331 [a] = _coerce_fp_expr_list([a], ctx)
9333 _z3_assert(
is_fp(a),
"First argument must be a Z3 floating-point expression")
9334 return FPRef(f(ctx.ref(), a.as_ast()), ctx)
9336 def _mk_fp_unary_pred(f, a, ctx):
9338 [a] = _coerce_fp_expr_list([a], ctx)
9340 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9341 return BoolRef(f(ctx.ref(), a.as_ast()), ctx)
9343 def _mk_fp_bin(f, rm, a, b, ctx):
9345 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9347 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9348 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9349 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast()), ctx)
9351 def _mk_fp_bin_norm(f, a, b, ctx):
9353 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9355 _z3_assert(
is_fp(a)
or is_fp(b),
"First or second argument must be a Z3 floating-point expression")
9356 return FPRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9358 def _mk_fp_bin_pred(f, a, b, ctx):
9360 [a, b] = _coerce_fp_expr_list([a, b], ctx)
9362 _z3_assert(
is_fp(a)
or is_fp(b),
"Second or third argument must be a Z3 floating-point expression")
9363 return BoolRef(f(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
9365 def _mk_fp_tern(f, rm, a, b, c, ctx):
9367 [a, b, c] = _coerce_fp_expr_list([a, b, c], ctx)
9369 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9370 _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")
9371 return FPRef(f(ctx.ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
9374 """Create a Z3 floating-point addition expression. 9376 >>> s = FPSort(8, 24) 9382 >>> fpAdd(RTZ(), x, y) # default rounding mode is RTZ 9384 >>> fpAdd(rm, x, y).sort() 9387 return _mk_fp_bin(Z3_mk_fpa_add, rm, a, b, ctx)
9390 """Create a Z3 floating-point subtraction expression. 9392 >>> s = FPSort(8, 24) 9398 >>> fpSub(rm, x, y).sort() 9401 return _mk_fp_bin(Z3_mk_fpa_sub, rm, a, b, ctx)
9404 """Create a Z3 floating-point multiplication expression. 9406 >>> s = FPSort(8, 24) 9412 >>> fpMul(rm, x, y).sort() 9415 return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
9418 """Create a Z3 floating-point division expression. 9420 >>> s = FPSort(8, 24) 9426 >>> fpDiv(rm, x, y).sort() 9429 return _mk_fp_bin(Z3_mk_fpa_div, rm, a, b, ctx)
9432 """Create a Z3 floating-point remainder expression. 9434 >>> s = FPSort(8, 24) 9439 >>> fpRem(x, y).sort() 9442 return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
9445 """Create a Z3 floating-point minimum expression. 9447 >>> s = FPSort(8, 24) 9453 >>> fpMin(x, y).sort() 9456 return _mk_fp_bin_norm(Z3_mk_fpa_min, a, b, ctx)
9459 """Create a Z3 floating-point maximum expression. 9461 >>> s = FPSort(8, 24) 9467 >>> fpMax(x, y).sort() 9470 return _mk_fp_bin_norm(Z3_mk_fpa_max, a, b, ctx)
9473 """Create a Z3 floating-point fused multiply-add expression. 9475 return _mk_fp_tern(Z3_mk_fpa_fma, rm, a, b, c, ctx)
9478 """Create a Z3 floating-point square root expression. 9480 return _mk_fp_unary(Z3_mk_fpa_sqrt, rm, a, ctx)
9483 """Create a Z3 floating-point roundToIntegral expression. 9485 return _mk_fp_unary(Z3_mk_fpa_round_to_integral, rm, a, ctx)
9488 """Create a Z3 floating-point isNaN expression. 9490 >>> s = FPSort(8, 24) 9496 return _mk_fp_unary_norm(Z3_mk_fpa_is_nan, a, ctx)
9499 """Create a Z3 floating-point isInfinite expression. 9501 >>> s = FPSort(8, 24) 9506 return _mk_fp_unary_norm(Z3_mk_fpa_is_infinite, a, ctx)
9509 """Create a Z3 floating-point isZero expression. 9511 return _mk_fp_unary_norm(Z3_mk_fpa_is_zero, a, ctx)
9514 """Create a Z3 floating-point isNormal expression. 9516 return _mk_fp_unary_norm(Z3_mk_fpa_is_normal, a, ctx)
9519 """Create a Z3 floating-point isSubnormal expression. 9521 return _mk_fp_unary_norm(Z3_mk_fpa_is_subnormal, a, ctx)
9524 """Create a Z3 floating-point isNegative expression. 9526 return _mk_fp_unary_norm(Z3_mk_fpa_is_negative, a, ctx)
9529 """Create a Z3 floating-point isPositive expression. 9531 return _mk_fp_unary_norm(Z3_mk_fpa_is_positive, a, ctx)
9534 def _check_fp_args(a, b):
9536 _z3_assert(
is_fp(a)
or is_fp(b),
"At least one of the arguments must be a Z3 floating-point expression")
9539 """Create the Z3 floating-point expression `other < self`. 9541 >>> x, y = FPs('x y', FPSort(8, 24)) 9547 return _mk_fp_bin_pred(Z3_mk_fpa_lt, a, b, ctx)
9550 """Create the Z3 floating-point expression `other <= self`. 9552 >>> x, y = FPs('x y', FPSort(8, 24)) 9555 >>> (x <= y).sexpr() 9558 return _mk_fp_bin_pred(Z3_mk_fpa_leq, a, b, ctx)
9561 """Create the Z3 floating-point expression `other > self`. 9563 >>> x, y = FPs('x y', FPSort(8, 24)) 9569 return _mk_fp_bin_pred(Z3_mk_fpa_gt, a, b, ctx)
9572 """Create the Z3 floating-point expression `other >= self`. 9574 >>> x, y = FPs('x y', FPSort(8, 24)) 9577 >>> (x >= y).sexpr() 9580 return _mk_fp_bin_pred(Z3_mk_fpa_geq, a, b, ctx)
9583 """Create the Z3 floating-point expression `fpEQ(other, self)`. 9585 >>> x, y = FPs('x y', FPSort(8, 24)) 9588 >>> fpEQ(x, y).sexpr() 9591 return _mk_fp_bin_pred(Z3_mk_fpa_eq, a, b, ctx)
9594 """Create the Z3 floating-point expression `Not(fpEQ(other, self))`. 9596 >>> x, y = FPs('x y', FPSort(8, 24)) 9599 >>> (x != y).sexpr() 9605 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectors sgn, sig, and exp. 9607 >>> s = FPSort(8, 24) 9608 >>> x = fpFP(BitVecVal(1, 1), BitVecVal(2**7-1, 8), BitVecVal(2**22, 23)) 9610 fpFP(1, 127, 4194304) 9611 >>> xv = FPVal(-1.5, s) 9615 >>> slvr.add(fpEQ(x, xv)) 9618 >>> xv = FPVal(+1.5, s) 9622 >>> slvr.add(fpEQ(x, xv)) 9627 _z3_assert(sgn.sort().size() == 1,
"sort mismatch")
9629 _z3_assert(ctx == sgn.ctx == exp.ctx == sig.ctx,
"context mismatch")
9633 """Create a Z3 floating-point conversion expression from other term sorts 9636 From a bit-vector term in IEEE 754-2008 format: 9637 >>> x = FPVal(1.0, Float32()) 9638 >>> x_bv = fpToIEEEBV(x) 9639 >>> simplify(fpToFP(x_bv, Float32())) 9642 From a floating-point term with different precision: 9643 >>> x = FPVal(1.0, Float32()) 9644 >>> x_db = fpToFP(RNE(), x, Float64()) 9649 >>> x_r = RealVal(1.5) 9650 >>> simplify(fpToFP(RNE(), x_r, Float32())) 9653 From a signed bit-vector term: 9654 >>> x_signed = BitVecVal(-5, BitVecSort(32)) 9655 >>> simplify(fpToFP(RNE(), x_signed, Float32())) 9668 raise Z3Exception(
"Unsupported combination of arguments for conversion to floating-point term.")
9671 """Create a Z3 floating-point conversion expression that represents the 9672 conversion from a bit-vector term to a floating-point term. 9674 >>> x_bv = BitVecVal(0x3F800000, 32) 9675 >>> x_fp = fpBVToFP(x_bv, Float32()) 9681 _z3_assert(
is_bv(v),
"First argument must be a Z3 floating-point rounding mode expression.")
9682 _z3_assert(
is_fp_sort(sort),
"Second argument must be a Z3 floating-point sort.")
9687 """Create a Z3 floating-point conversion expression that represents the 9688 conversion from a floating-point term to a floating-point term of different precision. 9690 >>> x_sgl = FPVal(1.0, Float32()) 9691 >>> x_dbl = fpFPToFP(RNE(), x_sgl, Float64()) 9699 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9700 _z3_assert(
is_fp(v),
"Second argument must be a Z3 floating-point expression.")
9701 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9706 """Create a Z3 floating-point conversion expression that represents the 9707 conversion from a real term to a floating-point term. 9709 >>> x_r = RealVal(1.5) 9710 >>> x_fp = fpRealToFP(RNE(), x_r, Float32()) 9716 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9717 _z3_assert(
is_real(v),
"Second argument must be a Z3 expression or real sort.")
9718 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9723 """Create a Z3 floating-point conversion expression that represents the 9724 conversion from a signed bit-vector term (encoding an integer) to a floating-point term. 9726 >>> x_signed = BitVecVal(-5, BitVecSort(32)) 9727 >>> x_fp = fpSignedToFP(RNE(), x_signed, Float32()) 9729 fpToFP(RNE(), 4294967291) 9733 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9734 _z3_assert(
is_bv(v),
"Second argument must be a Z3 expression or real sort.")
9735 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9740 """Create a Z3 floating-point conversion expression that represents the 9741 conversion from an unsigned bit-vector term (encoding an integer) to a floating-point term. 9743 >>> x_signed = BitVecVal(-5, BitVecSort(32)) 9744 >>> x_fp = fpUnsignedToFP(RNE(), x_signed, Float32()) 9746 fpToFPUnsigned(RNE(), 4294967291) 9750 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression.")
9751 _z3_assert(
is_bv(v),
"Second argument must be a Z3 expression or real sort.")
9752 _z3_assert(
is_fp_sort(sort),
"Third argument must be a Z3 floating-point sort.")
9757 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression.""" 9759 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9760 _z3_assert(
is_bv(x),
"Second argument must be a Z3 bit-vector expression")
9761 _z3_assert(
is_fp_sort(s),
"Third argument must be Z3 floating-point sort")
9766 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector. 9768 >>> x = FP('x', FPSort(8, 24)) 9769 >>> y = fpToSBV(RTZ(), x, BitVecSort(32)) 9780 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9781 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9782 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9787 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector. 9789 >>> x = FP('x', FPSort(8, 24)) 9790 >>> y = fpToUBV(RTZ(), x, BitVecSort(32)) 9801 _z3_assert(
is_fprm(rm),
"First argument must be a Z3 floating-point rounding mode expression")
9802 _z3_assert(
is_fp(x),
"Second argument must be a Z3 floating-point expression")
9803 _z3_assert(
is_bv_sort(s),
"Third argument must be Z3 bit-vector sort")
9808 """Create a Z3 floating-point conversion expression, from floating-point expression to real. 9810 >>> x = FP('x', FPSort(8, 24)) 9814 >>> print(is_real(y)) 9818 >>> print(is_real(x)) 9822 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9827 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. 9829 The size of the resulting bit-vector is automatically determined. 9831 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion 9832 knows only one NaN and it will always produce the same bit-vector representation of 9835 >>> x = FP('x', FPSort(8, 24)) 9836 >>> y = fpToIEEEBV(x) 9847 _z3_assert(
is_fp(x),
"First argument must be a Z3 floating-point expression")
9860 """Sequence sort.""" 9863 """Determine if sort is a string 9864 >>> s = StringSort() 9867 >>> s = SeqSort(IntSort()) 9875 """Create a string sort 9876 >>> s = StringSort() 9885 """Create a sequence sort over elements provided in the argument 9886 >>> s = SeqSort(IntSort()) 9887 >>> s == Unit(IntVal(1)).sort() 9893 """Sequence expression.""" 9899 return Concat(self, other)
9902 return Concat(other, self)
9916 """Return a string representation of sequence expression.""" 9922 def _coerce_seq(s, ctx=None):
9923 if isinstance(s, str):
9927 raise Z3Exception(
"Non-expression passed as a sequence")
9929 raise Z3Exception(
"Non-sequence passed as a sequence")
9932 def _get_ctx2(a, b, ctx=None):
9942 """Return `True` if `a` is a Z3 sequence expression. 9943 >>> print (is_seq(Unit(IntVal(0)))) 9945 >>> print (is_seq(StringVal("abc"))) 9948 return isinstance(a, SeqRef)
9951 """Return `True` if `a` is a Z3 string expression. 9952 >>> print (is_string(StringVal("ab"))) 9955 return isinstance(a, SeqRef)
and a.is_string()
9958 """return 'True' if 'a' is a Z3 string constant expression. 9959 >>> print (is_string_value(StringVal("a"))) 9961 >>> print (is_string_value(StringVal("a") + StringVal("b"))) 9964 return isinstance(a, SeqRef)
and a.is_string_value()
9968 """create a string expression""" 9973 """Return a string constant named `name`. If `ctx=None`, then the global context is used. 9981 """Extract substring or subsequence starting at offset""" 9982 return Extract(s, offset, length)
9985 """Extract substring or subsequence starting at offset""" 9986 return Extract(s, offset, length)
9989 """Return a tuple of String constants. """ 9991 if isinstance(names, str):
9992 names = names.split(
" ")
9993 return [
String(name, ctx)
for name
in names]
9996 """Create the empty sequence of the given sort 9997 >>> e = Empty(StringSort()) 9998 >>> e2 = StringVal("") 10001 >>> e3 = Empty(SeqSort(IntSort())) 10004 >>> e4 = Empty(ReSort(SeqSort(IntSort()))) 10008 if isinstance(s, SeqSortRef):
10010 if isinstance(s, ReSortRef):
10012 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Empty")
10015 """Create the regular expression that accepts the universal language 10016 >>> e = Full(ReSort(SeqSort(IntSort()))) 10019 >>> e1 = Full(ReSort(StringSort())) 10023 if isinstance(s, ReSortRef):
10025 raise Z3Exception(
"Non-sequence, non-regular expression sort passed to Full")
10029 """Create a singleton sequence""" 10033 """Check if 'a' is a prefix of 'b' 10034 >>> s1 = PrefixOf("ab", "abc") 10037 >>> s2 = PrefixOf("bc", "abc") 10041 ctx = _get_ctx2(a, b)
10042 a = _coerce_seq(a, ctx)
10043 b = _coerce_seq(b, ctx)
10047 """Check if 'a' is a suffix of 'b' 10048 >>> s1 = SuffixOf("ab", "abc") 10051 >>> s2 = SuffixOf("bc", "abc") 10055 ctx = _get_ctx2(a, b)
10056 a = _coerce_seq(a, ctx)
10057 b = _coerce_seq(b, ctx)
10061 """Check if 'a' contains 'b' 10062 >>> s1 = Contains("abc", "ab") 10065 >>> s2 = Contains("abc", "bc") 10068 >>> x, y, z = Strings('x y z') 10069 >>> s3 = Contains(Concat(x,y,z), y) 10073 ctx = _get_ctx2(a, b)
10074 a = _coerce_seq(a, ctx)
10075 b = _coerce_seq(b, ctx)
10080 """Replace the first occurrence of 'src' by 'dst' in 's' 10081 >>> r = Replace("aaa", "a", "b") 10085 ctx = _get_ctx2(dst, s)
10086 if ctx
is None and is_expr(src):
10088 src = _coerce_seq(src, ctx)
10089 dst = _coerce_seq(dst, ctx)
10090 s = _coerce_seq(s, ctx)
10097 """Retrieve the index of substring within a string starting at a specified offset. 10098 >>> simplify(IndexOf("abcabc", "bc", 0)) 10100 >>> simplify(IndexOf("abcabc", "bc", 2)) 10106 ctx = _get_ctx2(s, substr, ctx)
10107 s = _coerce_seq(s, ctx)
10108 substr = _coerce_seq(substr, ctx)
10109 if _is_int(offset):
10110 offset =
IntVal(offset, ctx)
10114 """Obtain the length of a sequence 's' 10115 >>> l = Length(StringVal("abc")) 10123 """Convert string expression to integer 10124 >>> a = StrToInt("1") 10125 >>> simplify(1 == a) 10127 >>> b = StrToInt("2") 10128 >>> simplify(1 == b) 10130 >>> c = StrToInt(IntToStr(2)) 10131 >>> simplify(1 == c) 10139 """Convert integer expression to string""" 10146 """The regular expression that accepts sequence 's' 10148 >>> s2 = Re(StringVal("ab")) 10149 >>> s3 = Re(Unit(BoolVal(True))) 10151 s = _coerce_seq(s, ctx)
10160 """Regular expression sort.""" 10166 if s
is None or isinstance(s, Context):
10169 raise Z3Exception(
"Regular expression sort constructor expects either a string or a context or no argument")
10173 """Regular expressions.""" 10176 return Union(self, other)
10180 return isinstance(s, ReRef)
10184 """Create regular expression membership test 10185 >>> re = Union(Re("a"),Re("b")) 10186 >>> print (simplify(InRe("a", re))) 10188 >>> print (simplify(InRe("b", re))) 10190 >>> print (simplify(InRe("c", re))) 10193 s = _coerce_seq(s, re.ctx)
10197 """Create union of regular expressions. 10198 >>> re = Union(Re("a"), Re("b"), Re("c")) 10199 >>> print (simplify(InRe("d", re))) 10202 args = _get_args(args)
10205 _z3_assert(sz > 0,
"At least one argument expected.")
10206 _z3_assert(all([
is_re(a)
for a
in args]),
"All arguments must be regular expressions.")
10211 for i
in range(sz):
10212 v[i] = args[i].as_ast()
10216 """Create the regular expression accepting one or more repetitions of argument. 10217 >>> re = Plus(Re("a")) 10218 >>> print(simplify(InRe("aa", re))) 10220 >>> print(simplify(InRe("ab", re))) 10222 >>> print(simplify(InRe("", re))) 10228 """Create the regular expression that optionally accepts the argument. 10229 >>> re = Option(Re("a")) 10230 >>> print(simplify(InRe("a", re))) 10232 >>> print(simplify(InRe("", re))) 10234 >>> print(simplify(InRe("aa", re))) 10240 """Create the complement regular expression.""" 10244 """Create the regular expression accepting zero or more repetitions of argument. 10245 >>> re = Star(Re("a")) 10246 >>> print(simplify(InRe("aa", re))) 10248 >>> print(simplify(InRe("ab", re))) 10250 >>> print(simplify(InRe("", re))) 10256 """Create the regular expression accepting between a lower and upper bound repetitions 10257 >>> re = Loop(Re("a"), 1, 3) 10258 >>> print(simplify(InRe("aa", re))) 10260 >>> print(simplify(InRe("aaaa", re))) 10262 >>> print(simplify(InRe("", re))) 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)
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.
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.
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.
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_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 __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_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_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)
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)
void Z3_API Z3_fixedpoint_pop(Z3_context c, Z3_fixedpoint d)
Backtrack one backtracking point.
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.
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).
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.
void Z3_API Z3_fixedpoint_push(Z3_context c, Z3_fixedpoint d)
Create a backtracking point.
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].
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_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.
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.
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s)
Create a string constant out of the string that is passed in.
def declare_var(self, *vars)
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_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,...
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)
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.
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)
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 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.
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)
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.
def Strings(names, ctx=None)
void Z3_API Z3_fixedpoint_update_rule(Z3_context c, Z3_fixedpoint d, Z3_ast a, Z3_symbol name)
Update a named rule. A rule with the same name must have been previously created.
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.
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_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 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)
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_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.
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_ast Z3_API Z3_mk_fpa_is_positive(Z3_context c, Z3_ast t)
Predicate indicating whether t is a positive floating-point number.
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 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_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.
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.