| def z3py.And | ( | args | ) |
Create a Z3 and-expression or and-probe.
>>> p, q, r = Bools('p q r')
>>> And(p, q, r)
And(p, q, r)
>>> P = BoolVector('p', 5)
>>> And(P)
And(p__0, p__1, p__2, p__3, p__4)
Definition at line 1489 of file z3py.py.
Referenced by Fixedpoint.add_rule(), Goal.as_expr(), Bool(), Bools(), BoolVector(), Fixedpoint.query(), tree_interpolant(), and Fixedpoint.update_rule().
01489 01490 def And(*args): 01491 """Create a Z3 and-expression or and-probe. 01492 01493 >>> p, q, r = Bools('p q r') 01494 >>> And(p, q, r) 01495 And(p, q, r) 01496 >>> P = BoolVector('p', 5) 01497 >>> And(P) 01498 And(p__0, p__1, p__2, p__3, p__4) 01499 """ 01500 last_arg = None 01501 if len(args) > 0: 01502 last_arg = args[len(args)-1] 01503 if isinstance(last_arg, Context): 01504 ctx = args[len(args)-1] 01505 args = args[:len(args)-1] 01506 else: 01507 ctx = main_ctx() 01508 args = _get_args(args) 01509 ctx_args = _ctx_from_ast_arg_list(args, ctx) 01510 if __debug__: 01511 _z3_assert(ctx_args == None or ctx_args == ctx, "context mismatch") 01512 _z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression or probe") 01513 if _has_probe(args): 01514 return _probe_and(args, ctx) 01515 else: 01516 args = _coerce_expr_list(args, ctx) 01517 _args, sz = _to_ast_array(args) 01518 return BoolRef(Z3_mk_and(ctx.ref(), sz, _args), ctx)
| def z3py.AndThen | ( | ts, | |
| ks | |||
| ) |
Return a tactic that applies the tactics in `*ts` in sequence.
>>> x, y = Ints('x y')
>>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs'))
>>> t(And(x == 0, y > x + 1))
[[Not(y <= 1)]]
>>> t(And(x == 0, y > x + 1)).as_expr()
Not(y <= 1)
Definition at line 6759 of file z3py.py.
Referenced by Context.Then(), and Then().
06759 06760 def AndThen(*ts, **ks): 06761 """Return a tactic that applies the tactics in `*ts` in sequence. 06762 06763 >>> x, y = Ints('x y') 06764 >>> t = AndThen(Tactic('simplify'), Tactic('solve-eqs')) 06765 >>> t(And(x == 0, y > x + 1)) 06766 [[Not(y <= 1)]] 06767 >>> t(And(x == 0, y > x + 1)).as_expr() 06768 Not(y <= 1) 06769 """ 06770 if __debug__: 06771 _z3_assert(len(ts) >= 2, "At least two arguments expected") 06772 ctx = ks.get('ctx', None) 06773 num = len(ts) 06774 r = ts[0] 06775 for i in range(num - 1): 06776 r = _and_then(r, ts[i+1], ctx) 06777 return r
| def z3py.append_log | ( | s | ) |
Append user-defined string to interaction log.
Definition at line 90 of file z3py.py.
00090 00091 def append_log(s): 00092 """Append user-defined string to interaction log. """ 00093 Z3_append_log(s)
| def z3py.args2params | ( | arguments, | |
| keywords, | |||
ctx = None |
|||
| ) |
Convert python arguments into a Z3_params object.
A ':' is added to the keywords, and '_' is replaced with '-'
>>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True})
(params model true relevancy 2 elim_and true)
Definition at line 4527 of file z3py.py.
Referenced by Tactic.apply(), Fixedpoint.set(), Optimize.set(), simplify(), and With().
04527 04528 def args2params(arguments, keywords, ctx=None): 04529 """Convert python arguments into a Z3_params object. 04530 A ':' is added to the keywords, and '_' is replaced with '-' 04531 04532 >>> args2params(['model', True, 'relevancy', 2], {'elim_and' : True}) 04533 (params model true relevancy 2 elim_and true) 04534 """ 04535 if __debug__: 04536 _z3_assert(len(arguments) % 2 == 0, "Argument list must have an even number of elements.") 04537 prev = None 04538 r = ParamsRef(ctx) 04539 for a in arguments: 04540 if prev == None: 04541 prev = a 04542 else: 04543 r.set(prev, a) 04544 prev = None 04545 for k in keywords: 04546 v = keywords[k] 04547 r.set(k, v) 04548 return r
| def z3py.Array | ( | name, | |
| dom, | |||
| rng | |||
| ) |
Return an array constant named `name` with the given domain and range sorts.
>>> a = Array('a', IntSort(), IntSort())
>>> a.sort()
Array(Int, Int)
>>> a[0]
a[0]
Definition at line 4025 of file z3py.py.
Referenced by ArrayRef.__getitem__(), ArraySort(), ArrayRef.domain(), get_map_func(), is_array(), is_const_array(), is_K(), is_map(), is_select(), is_store(), K(), Map(), ArrayRef.range(), Select(), ArrayRef.sort(), Store(), and Update().
04025 04026 def Array(name, dom, rng): 04027 """Return an array constant named `name` with the given domain and range sorts. 04028 04029 >>> a = Array('a', IntSort(), IntSort()) 04030 >>> a.sort() 04031 Array(Int, Int) 04032 >>> a[0] 04033 a[0] 04034 """ 04035 s = ArraySort(dom, rng) 04036 ctx = s.ctx 04037 return ArrayRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), s.ast), ctx)
| def z3py.ArraySort | ( | d, | |
| r | |||
| ) |
Return the Z3 array sort with the given domain and range sorts. >>> A = ArraySort(IntSort(), BoolSort()) >>> A Array(Int, Bool) >>> A.domain() Int >>> A.range() Bool >>> AA = ArraySort(IntSort(), A) >>> AA Array(Int, Array(Int, Bool))
Definition at line 4004 of file z3py.py.
Referenced by Array(), Sort.create(), ArraySortRef.domain(), Context.mkArraySort(), Context.MkArraySort(), and ArraySortRef.range().
04004 04005 def ArraySort(d, r): 04006 """Return the Z3 array sort with the given domain and range sorts. 04007 04008 >>> A = ArraySort(IntSort(), BoolSort()) 04009 >>> A 04010 Array(Int, Bool) 04011 >>> A.domain() 04012 Int 04013 >>> A.range() 04014 Bool 04015 >>> AA = ArraySort(IntSort(), A) 04016 >>> AA 04017 Array(Int, Array(Int, Bool)) 04018 """ 04019 if __debug__: 04020 _z3_assert(is_sort(d), "Z3 sort expected") 04021 _z3_assert(is_sort(r), "Z3 sort expected") 04022 _z3_assert(d.ctx == r.ctx, "Context mismatch") 04023 ctx = d.ctx 04024 return ArraySortRef(Z3_mk_array_sort(ctx.ref(), d.ast, r.ast), ctx)
| def z3py.binary_interpolant | ( | a, | |
| b, | |||
p = None, |
|||
ctx = None |
|||
| ) |
Compute an interpolant for a binary conjunction.
If a & b is unsatisfiable, returns an interpolant for a & b.
This is a formula phi such that
1) a implies phi
2) b implies not phi
3) All the uninterpreted symbols of phi occur in both a and b.
If a & b is satisfiable, raises an object of class ModelRef
that represents a model of a &b.
If parameters p are supplied, these are used in creating the
solver that determines satisfiability.
x = Int('x')
print binary_interpolant(x<0,x>2)
Not(x >= 0)
Definition at line 7590 of file z3py.py.
07590 07591 def binary_interpolant(a,b,p=None,ctx=None): 07592 """Compute an interpolant for a binary conjunction. 07593 07594 If a & b is unsatisfiable, returns an interpolant for a & b. 07595 This is a formula phi such that 07596 07597 1) a implies phi 07598 2) b implies not phi 07599 3) All the uninterpreted symbols of phi occur in both a and b. 07600 07601 If a & b is satisfiable, raises an object of class ModelRef 07602 that represents a model of a &b. 07603 07604 If parameters p are supplied, these are used in creating the 07605 solver that determines satisfiability. 07606 07607 x = Int('x') 07608 print binary_interpolant(x<0,x>2) 07609 Not(x >= 0) 07610 """ 07611 f = And(Interpolant(a),b) 07612 return tree_interpolant(f,p,ctx)[0]
| def z3py.BitVec | ( | name, | |
| bv, | |||
ctx = None |
|||
| ) |
Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort.
If `ctx=None`, then the global context is used.
>>> x = BitVec('x', 16)
>>> is_bv(x)
True
>>> x.size()
16
>>> x.sort()
BitVec(16)
>>> word = BitVecSort(16)
>>> x2 = BitVec('x', word)
>>> eq(x, x2)
True
Definition at line 3490 of file z3py.py.
Referenced by BitVecRef.__add__(), BitVecRef.__and__(), BitVecRef.__div__(), BitVecRef.__invert__(), BitVecRef.__mod__(), BitVecRef.__mul__(), BitVecRef.__neg__(), BitVecRef.__or__(), BitVecRef.__pos__(), BitVecRef.__radd__(), BitVecRef.__rand__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), BitVecRef.__rmod__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), BitVecRef.__rrshift__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), BitVecRef.__sub__(), BitVecRef.__xor__(), BitVecs(), BitVecSort(), BV2Int(), Extract(), is_bv(), is_bv_value(), RepeatBitVec(), SignExt(), BitVecRef.size(), BitVecRef.sort(), SRem(), UDiv(), URem(), and ZeroExt().
03490 03491 def BitVec(name, bv, ctx=None): 03492 """Return a bit-vector constant named `name`. `bv` may be the number of bits of a bit-vector sort. 03493 If `ctx=None`, then the global context is used. 03494 03495 >>> x = BitVec('x', 16) 03496 >>> is_bv(x) 03497 True 03498 >>> x.size() 03499 16 03500 >>> x.sort() 03501 BitVec(16) 03502 >>> word = BitVecSort(16) 03503 >>> x2 = BitVec('x', word) 03504 >>> eq(x, x2) 03505 True 03506 """ 03507 if isinstance(bv, BitVecSortRef): 03508 ctx = bv.ctx 03509 else: 03510 ctx = _get_ctx(ctx) 03511 bv = BitVecSort(bv, ctx) 03512 return BitVecRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), bv.ast), ctx)
| def z3py.BitVecs | ( | names, | |
| bv, | |||
ctx = None |
|||
| ) |
Return a tuple of bit-vector constants of size bv.
>>> x, y, z = BitVecs('x y z', 16)
>>> x.size()
16
>>> x.sort()
BitVec(16)
>>> Sum(x, y, z)
0 + x + y + z
>>> Product(x, y, z)
1*x*y*z
>>> simplify(Product(x, y, z))
x*y*z
Definition at line 3513 of file z3py.py.
Referenced by BitVecRef.__ge__(), BitVecRef.__gt__(), BitVecRef.__le__(), BitVecRef.__lshift__(), BitVecRef.__lt__(), BitVecRef.__rshift__(), LShR(), RotateLeft(), RotateRight(), UGE(), UGT(), ULE(), and ULT().
03513 03514 def BitVecs(names, bv, ctx=None): 03515 """Return a tuple of bit-vector constants of size bv. 03516 03517 >>> x, y, z = BitVecs('x y z', 16) 03518 >>> x.size() 03519 16 03520 >>> x.sort() 03521 BitVec(16) 03522 >>> Sum(x, y, z) 03523 0 + x + y + z 03524 >>> Product(x, y, z) 03525 1*x*y*z 03526 >>> simplify(Product(x, y, z)) 03527 x*y*z 03528 """ 03529 ctx = _get_ctx(ctx) 03530 if isinstance(names, str): 03531 names = names.split(" ") 03532 return [BitVec(name, bv, ctx) for name in names]
| def z3py.BitVecSort | ( | sz, | |
ctx = None |
|||
| ) |
Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
>>> Byte = BitVecSort(8)
>>> Word = BitVecSort(16)
>>> Byte
BitVec(8)
>>> x = Const('x', Byte)
>>> eq(x, BitVec('x', 8))
True
Definition at line 3460 of file z3py.py.
Referenced by BitVec(), BitVecSortRef.cast(), Sort.create(), fpToSBV(), fpToUBV(), is_bv_sort(), Context.mkBitVecSort(), Context.MkBitVecSort(), BitVecSortRef.size(), and BitVecRef.sort().
03460 03461 def BitVecSort(sz, ctx=None): 03462 """Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used. 03463 03464 >>> Byte = BitVecSort(8) 03465 >>> Word = BitVecSort(16) 03466 >>> Byte 03467 BitVec(8) 03468 >>> x = Const('x', Byte) 03469 >>> eq(x, BitVec('x', 8)) 03470 True 03471 """ 03472 ctx = _get_ctx(ctx) 03473 return BitVecSortRef(Z3_mk_bv_sort(ctx.ref(), sz), ctx)
| def z3py.BitVecVal | ( | val, | |
| bv, | |||
ctx = None |
|||
| ) |
Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used.
>>> v = BitVecVal(10, 32)
>>> v
10
>>> print("0x%.8x" % v.as_long())
0x0000000a
Definition at line 3474 of file z3py.py.
Referenced by BitVecRef.__lshift__(), BitVecRef.__rshift__(), BitVecNumRef.as_long(), BitVecNumRef.as_signed_long(), Concat(), is_bv_value(), LShR(), RepeatBitVec(), SignExt(), and ZeroExt().
03474 03475 def BitVecVal(val, bv, ctx=None): 03476 """Return a bit-vector value with the given number of bits. If `ctx=None`, then the global context is used. 03477 03478 >>> v = BitVecVal(10, 32) 03479 >>> v 03480 10 03481 >>> print("0x%.8x" % v.as_long()) 03482 0x0000000a 03483 """ 03484 if is_bv_sort(bv): 03485 ctx = bv.ctx 03486 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), bv.ast), ctx) 03487 else: 03488 ctx = _get_ctx(ctx) 03489 return BitVecNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), BitVecSort(bv, ctx).ast), ctx)
| def z3py.Bool | ( | name, | |
ctx = None |
|||
| ) |
Return a Boolean constant named `name`. If `ctx=None`, then the global context is used.
>>> p = Bool('p')
>>> q = Bool('q')
>>> And(p, q)
And(p, q)
Definition at line 1381 of file z3py.py.
Referenced by Solver.assert_and_track(), and Not().
01381 01382 def Bool(name, ctx=None): 01383 """Return a Boolean constant named `name`. If `ctx=None`, then the global context is used. 01384 01385 >>> p = Bool('p') 01386 >>> q = Bool('q') 01387 >>> And(p, q) 01388 And(p, q) 01389 """ 01390 ctx = _get_ctx(ctx) 01391 return BoolRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), BoolSort(ctx).ast), ctx)
| def z3py.Bools | ( | names, | |
ctx = None |
|||
| ) |
Return a tuple of Boolean constants.
`names` is a single string containing all names separated by blank spaces.
If `ctx=None`, then the global context is used.
>>> p, q, r = Bools('p q r')
>>> And(p, Or(q, r))
And(p, Or(q, r))
Definition at line 1392 of file z3py.py.
Referenced by And(), Implies(), Or(), Solver.unsat_core(), and Xor().
01392 01393 def Bools(names, ctx=None): 01394 """Return a tuple of Boolean constants. 01395 01396 `names` is a single string containing all names separated by blank spaces. 01397 If `ctx=None`, then the global context is used. 01398 01399 >>> p, q, r = Bools('p q r') 01400 >>> And(p, Or(q, r)) 01401 And(p, Or(q, r)) 01402 """ 01403 ctx = _get_ctx(ctx) 01404 if isinstance(names, str): 01405 names = names.split(" ") 01406 return [Bool(name, ctx) for name in names]
| def z3py.BoolSort | ( | ctx = None | ) |
Return the Boolean Z3 sort. If `ctx=None`, then the global context is used.
>>> BoolSort()
Bool
>>> p = Const('p', BoolSort())
>>> is_bool(p)
True
>>> r = Function('r', IntSort(), IntSort(), BoolSort())
>>> r(0, 1)
r(0, 1)
>>> is_bool(r(0, 1))
True
Definition at line 1346 of file z3py.py.
Referenced by ArrayRef.__getitem__(), ArraySort(), Fixedpoint.assert_exprs(), Bool(), Sort.create(), ArraySortRef.domain(), ArrayRef.domain(), Context.getBoolSort(), If(), IntSort(), is_arith_sort(), Context.mkBoolSort(), Context.MkBoolSort(), ArraySortRef.range(), ArrayRef.range(), and ArrayRef.sort().
01346 01347 def BoolSort(ctx=None): 01348 """Return the Boolean Z3 sort. If `ctx=None`, then the global context is used. 01349 01350 >>> BoolSort() 01351 Bool 01352 >>> p = Const('p', BoolSort()) 01353 >>> is_bool(p) 01354 True 01355 >>> r = Function('r', IntSort(), IntSort(), BoolSort()) 01356 >>> r(0, 1) 01357 r(0, 1) 01358 >>> is_bool(r(0, 1)) 01359 True 01360 """ 01361 ctx = _get_ctx(ctx) 01362 return BoolSortRef(Z3_mk_bool_sort(ctx.ref()), ctx)
| def z3py.BoolVal | ( | val, | |
ctx = None |
|||
| ) |
Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used. >>> BoolVal(True) True >>> is_true(BoolVal(True)) True >>> is_true(True) False >>> is_false(BoolVal(False)) True
Definition at line 1363 of file z3py.py.
Referenced by ApplyResult.as_expr(), BoolSortRef.cast(), and Solver.to_smt2().
01363 01364 def BoolVal(val, ctx=None): 01365 """Return the Boolean value `True` or `False`. If `ctx=None`, then the global context is used. 01366 01367 >>> BoolVal(True) 01368 True 01369 >>> is_true(BoolVal(True)) 01370 True 01371 >>> is_true(True) 01372 False 01373 >>> is_false(BoolVal(False)) 01374 True 01375 """ 01376 ctx = _get_ctx(ctx) 01377 if val == False: 01378 return BoolRef(Z3_mk_false(ctx.ref()), ctx) 01379 else: 01380 return BoolRef(Z3_mk_true(ctx.ref()), ctx)
| def z3py.BoolVector | ( | prefix, | |
| sz, | |||
ctx = None |
|||
| ) |
Return a list of Boolean constants of size `sz`.
The constants are named using the given prefix.
If `ctx=None`, then the global context is used.
>>> P = BoolVector('p', 3)
>>> P
[p__0, p__1, p__2]
>>> And(P)
And(p__0, p__1, p__2)
Definition at line 1407 of file z3py.py.
Referenced by And(), and Or().
01407 01408 def BoolVector(prefix, sz, ctx=None): 01409 """Return a list of Boolean constants of size `sz`. 01410 01411 The constants are named using the given prefix. 01412 If `ctx=None`, then the global context is used. 01413 01414 >>> P = BoolVector('p', 3) 01415 >>> P 01416 [p__0, p__1, p__2] 01417 >>> And(P) 01418 And(p__0, p__1, p__2) 01419 """ 01420 return [ Bool('%s__%s' % (prefix, i)) for i in range(sz) ]
| def z3py.BV2Int | ( | a | ) |
Return the Z3 expression BV2Int(a).
>>> b = BitVec('b', 3)
>>> BV2Int(b).sort()
Int
>>> x = Int('x')
>>> x > BV2Int(b)
x > BV2Int(b)
>>> solve(x > BV2Int(b), b == 1, x < 3)
[b = 1, x = 2]
Definition at line 3442 of file z3py.py.
03442 03443 def BV2Int(a): 03444 """Return the Z3 expression BV2Int(a). 03445 03446 >>> b = BitVec('b', 3) 03447 >>> BV2Int(b).sort() 03448 Int 03449 >>> x = Int('x') 03450 >>> x > BV2Int(b) 03451 x > BV2Int(b) 03452 >>> solve(x > BV2Int(b), b == 1, x < 3) 03453 [b = 1, x = 2] 03454 """ 03455 if __debug__: 03456 _z3_assert(is_bv(a), "Z3 bit-vector expression expected") 03457 ctx = a.ctx 03458 ## investigate problem with bv2int 03459 return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), 0), ctx)
| def z3py.BVRedAnd | ( | a | ) |
Return the reduction-and expression of `a`.
Definition at line 3841 of file z3py.py.
03841 03842 def BVRedAnd(a): 03843 """Return the reduction-and expression of `a`.""" 03844 if __debug__: 03845 _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression") 03846 return BitVecRef(Z3_mk_bvredand(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.BVRedOr | ( | a | ) |
Return the reduction-or expression of `a`.
Definition at line 3847 of file z3py.py.
03847 03848 def BVRedOr(a): 03849 """Return the reduction-or expression of `a`.""" 03850 if __debug__: 03851 _z3_assert(is_bv(a), "First argument must be a Z3 Bitvector expression") 03852 return BitVecRef(Z3_mk_bvredor(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.Cbrt | ( | a, | |
ctx = None |
|||
| ) |
Return a Z3 expression which represents the cubic root of a.
>>> x = Real('x')
>>> Cbrt(x)
x**(1/3)
| def z3py.Concat | ( | args | ) |
Create a Z3 bit-vector concatenation expression.
>>> v = BitVecVal(1, 4)
>>> Concat(v, v+1, v)
Concat(Concat(1, 1 + 1), 1)
>>> simplify(Concat(v, v+1, v))
289
>>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
121
Definition at line 3533 of file z3py.py.
Referenced by BitVecRef.size().
03533 03534 def Concat(*args): 03535 """Create a Z3 bit-vector concatenation expression. 03536 03537 >>> v = BitVecVal(1, 4) 03538 >>> Concat(v, v+1, v) 03539 Concat(Concat(1, 1 + 1), 1) 03540 >>> simplify(Concat(v, v+1, v)) 03541 289 03542 >>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long()) 03543 121 03544 """ 03545 args = _get_args(args) 03546 if __debug__: 03547 _z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.") 03548 _z3_assert(len(args) >= 2, "At least two arguments expected.") 03549 ctx = args[0].ctx 03550 r = args[0] 03551 for i in range(len(args) - 1): 03552 r = BitVecRef(Z3_mk_concat(ctx.ref(), r.as_ast(), args[i+1].as_ast()), ctx) 03553 return r
| def z3py.Cond | ( | p, | |
| t1, | |||
| t2, | |||
ctx = None |
|||
| ) |
Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise.
>>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt'))
Definition at line 7162 of file z3py.py.
Referenced by If().
07162 07163 def Cond(p, t1, t2, ctx=None): 07164 """Return a tactic that applies tactic `t1` to a goal if probe `p` evaluates to true, and `t2` otherwise. 07165 07166 >>> t = Cond(Probe('is-qfnra'), Tactic('qfnra'), Tactic('smt')) 07167 """ 07168 p = _to_probe(p, ctx) 07169 t1 = _to_tactic(t1, ctx) 07170 t2 = _to_tactic(t2, ctx) 07171 return Tactic(Z3_tactic_cond(t1.ctx.ref(), p.probe, t1.tactic, t2.tactic), t1.ctx)
| def z3py.Const | ( | name, | |
| sort | |||
| ) |
Create a constant of the given sort.
>>> Const('x', IntSort())
x
Definition at line 1145 of file z3py.py.
Referenced by BitVecSort(), Consts(), FPSort(), IntSort(), RealSort(), and DatatypeSortRef.recognizer().
01145 01146 def Const(name, sort): 01147 """Create a constant of the given sort. 01148 01149 >>> Const('x', IntSort()) 01150 x 01151 """ 01152 if __debug__: 01153 _z3_assert(isinstance(sort, SortRef), "Z3 sort expected") 01154 ctx = sort.ctx 01155 return _to_expr_ref(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), sort.ast), ctx)
| def z3py.Consts | ( | names, | |
| sort | |||
| ) |
Create a several constants of the given sort.
`names` is a string containing the names of all constants to be created.
Blank spaces separate the names of different constants.
>>> x, y, z = Consts('x y z', IntSort())
>>> x + y + z
x + y + z
Definition at line 1156 of file z3py.py.
Referenced by ModelRef.get_sort(), ModelRef.get_universe(), ModelRef.num_sorts(), and ModelRef.sorts().
01156 01157 def Consts(names, sort): 01158 """Create a several constants of the given sort. 01159 01160 `names` is a string containing the names of all constants to be created. 01161 Blank spaces separate the names of different constants. 01162 01163 >>> x, y, z = Consts('x y z', IntSort()) 01164 >>> x + y + z 01165 x + y + z 01166 """ 01167 if isinstance(names, str): 01168 names = names.split(" ") 01169 return [Const(name, sort) for name in names]
| def z3py.CreateDatatypes | ( | ds | ) |
Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects.
In the following example we define a Tree-List using two mutually recursive datatypes.
>>> TreeList = Datatype('TreeList')
>>> Tree = Datatype('Tree')
>>> # Tree has two constructors: leaf and node
>>> Tree.declare('leaf', ('val', IntSort()))
>>> # a node contains a list of trees
>>> Tree.declare('node', ('children', TreeList))
>>> TreeList.declare('nil')
>>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList))
>>> Tree, TreeList = CreateDatatypes(Tree, TreeList)
>>> Tree.val(Tree.leaf(10))
val(leaf(10))
>>> simplify(Tree.val(Tree.leaf(10)))
10
>>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil)))
>>> n1
node(cons(leaf(10), cons(leaf(20), nil)))
>>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil))
>>> simplify(n2 == n1)
False
>>> simplify(TreeList.car(Tree.children(n2)) == n1)
True
Definition at line 4269 of file z3py.py.
Referenced by Datatype.create().
04269 04270 def CreateDatatypes(*ds): 04271 """Create mutually recursive Z3 datatypes using 1 or more Datatype helper objects. 04272 04273 In the following example we define a Tree-List using two mutually recursive datatypes. 04274 04275 >>> TreeList = Datatype('TreeList') 04276 >>> Tree = Datatype('Tree') 04277 >>> # Tree has two constructors: leaf and node 04278 >>> Tree.declare('leaf', ('val', IntSort())) 04279 >>> # a node contains a list of trees 04280 >>> Tree.declare('node', ('children', TreeList)) 04281 >>> TreeList.declare('nil') 04282 >>> TreeList.declare('cons', ('car', Tree), ('cdr', TreeList)) 04283 >>> Tree, TreeList = CreateDatatypes(Tree, TreeList) 04284 >>> Tree.val(Tree.leaf(10)) 04285 val(leaf(10)) 04286 >>> simplify(Tree.val(Tree.leaf(10))) 04287 10 04288 >>> n1 = Tree.node(TreeList.cons(Tree.leaf(10), TreeList.cons(Tree.leaf(20), TreeList.nil))) 04289 >>> n1 04290 node(cons(leaf(10), cons(leaf(20), nil))) 04291 >>> n2 = Tree.node(TreeList.cons(n1, TreeList.nil)) 04292 >>> simplify(n2 == n1) 04293 False 04294 >>> simplify(TreeList.car(Tree.children(n2)) == n1) 04295 True 04296 """ 04297 ds = _get_args(ds) 04298 if __debug__: 04299 _z3_assert(len(ds) > 0, "At least one Datatype must be specified") 04300 _z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes") 04301 _z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch") 04302 _z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected") 04303 ctx = ds[0].ctx 04304 num = len(ds) 04305 names = (Symbol * num)() 04306 out = (Sort * num)() 04307 clists = (ConstructorList * num)() 04308 to_delete = [] 04309 for i in range(num): 04310 d = ds[i] 04311 names[i] = to_symbol(d.name, ctx) 04312 num_cs = len(d.constructors) 04313 cs = (Constructor * num_cs)() 04314 for j in range(num_cs): 04315 c = d.constructors[j] 04316 cname = to_symbol(c[0], ctx) 04317 rname = to_symbol(c[1], ctx) 04318 fs = c[2] 04319 num_fs = len(fs) 04320 fnames = (Symbol * num_fs)() 04321 sorts = (Sort * num_fs)() 04322 refs = (ctypes.c_uint * num_fs)() 04323 for k in range(num_fs): 04324 fname = fs[k][0] 04325 ftype = fs[k][1] 04326 fnames[k] = to_symbol(fname, ctx) 04327 if isinstance(ftype, Datatype): 04328 if __debug__: 04329 _z3_assert(ds.count(ftype) == 1, "One and only one occurrence of each datatype is expected") 04330 sorts[k] = None 04331 refs[k] = ds.index(ftype) 04332 else: 04333 if __debug__: 04334 _z3_assert(is_sort(ftype), "Z3 sort expected") 04335 sorts[k] = ftype.ast 04336 refs[k] = 0 04337 cs[j] = Z3_mk_constructor(ctx.ref(), cname, rname, num_fs, fnames, sorts, refs) 04338 to_delete.append(ScopedConstructor(cs[j], ctx)) 04339 clists[i] = Z3_mk_constructor_list(ctx.ref(), num_cs, cs) 04340 to_delete.append(ScopedConstructorList(clists[i], ctx)) 04341 Z3_mk_datatypes(ctx.ref(), num, names, out, clists) 04342 result = [] 04343 ## Create a field for every constructor, recognizer and accessor 04344 for i in range(num): 04345 dref = DatatypeSortRef(out[i], ctx) 04346 num_cs = dref.num_constructors() 04347 for j in range(num_cs): 04348 cref = dref.constructor(j) 04349 cref_name = cref.name() 04350 cref_arity = cref.arity() 04351 if cref.arity() == 0: 04352 cref = cref() 04353 setattr(dref, cref_name, cref) 04354 rref = dref.recognizer(j) 04355 setattr(dref, rref.name(), rref) 04356 for k in range(cref_arity): 04357 aref = dref.accessor(j, k) 04358 setattr(dref, aref.name(), aref) 04359 result.append(dref) 04360 return tuple(result)
| def z3py.DeclareSort | ( | name, | |
ctx = None |
|||
| ) |
Create a new uninterpred sort named `name`.
If `ctx=None`, then the new sort is declared in the global Z3Py context.
>>> A = DeclareSort('A')
>>> a = Const('a', A)
>>> b = Const('b', A)
>>> a.sort() == A
True
>>> b.sort() == A
True
>>> a == b
a == b
Definition at line 567 of file z3py.py.
Referenced by ModelRef.get_sort(), ModelRef.get_universe(), ModelRef.num_sorts(), and ModelRef.sorts().
00567 00568 def DeclareSort(name, ctx=None): 00569 """Create a new uninterpred sort named `name`. 00570 00571 If `ctx=None`, then the new sort is declared in the global Z3Py context. 00572 00573 >>> A = DeclareSort('A') 00574 >>> a = Const('a', A) 00575 >>> b = Const('b', A) 00576 >>> a.sort() == A 00577 True 00578 >>> b.sort() == A 00579 True 00580 >>> a == b 00581 a == b 00582 """ 00583 ctx = _get_ctx(ctx) 00584 return SortRef(Z3_mk_uninterpreted_sort(ctx.ref(), to_symbol(name, ctx)), ctx)
| def z3py.Default | ( | a | ) |
Return a default value for array expression. >>> b = K(IntSort(), 1) >>> prove(Default(b) == 1) proved
Definition at line 4059 of file z3py.py.
Referenced by is_default().
04059 04060 def Default(a): 04061 """ Return a default value for array expression. 04062 >>> b = K(IntSort(), 1) 04063 >>> prove(Default(b) == 1) 04064 proved 04065 """ 04066 if __debug__: 04067 _z3_assert(is_array(a), "First argument must be a Z3 array expression") 04068 return a.mk_default() 04069
| def z3py.describe_probes | ( | ) |
Display a (tabular) description of all available probes in Z3.
Definition at line 7092 of file z3py.py.
07092 07093 def describe_probes(): 07094 """Display a (tabular) description of all available probes in Z3.""" 07095 if in_html_mode(): 07096 even = True 07097 print('<table border="1" cellpadding="2" cellspacing="0">') 07098 for p in probes(): 07099 if even: 07100 print('<tr style="background-color:#CFCFCF">') 07101 even = False 07102 else: 07103 print('<tr>') 07104 even = True 07105 print('<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40))) 07106 print('</table>') 07107 else: 07108 for p in probes(): 07109 print('%s : %s' % (p, probe_description(p)))
| def z3py.describe_tactics | ( | ) |
Display a (tabular) description of all available tactics in Z3.
Definition at line 6904 of file z3py.py.
06904 06905 def describe_tactics(): 06906 """Display a (tabular) description of all available tactics in Z3.""" 06907 if in_html_mode(): 06908 even = True 06909 print('<table border="1" cellpadding="2" cellspacing="0">') 06910 for t in tactics(): 06911 if even: 06912 print('<tr style="background-color:#CFCFCF">') 06913 even = False 06914 else: 06915 print('<tr>') 06916 even = True 06917 print('<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40))) 06918 print('</table>') 06919 else: 06920 for t in tactics(): 06921 print('%s : %s' % (t, tactic_description(t)))
| def z3py.disable_trace | ( | msg | ) |
Definition at line 61 of file z3py.py.
00061 00062 def disable_trace(msg): 00063 Z3_disable_trace(msg)
| def z3py.Distinct | ( | args | ) |
Create a Z3 distinct expression.
>>> x = Int('x')
>>> y = Int('y')
>>> Distinct(x, y)
x != y
>>> z = Int('z')
>>> Distinct(x, y, z)
Distinct(x, y, z)
>>> simplify(Distinct(x, y, z))
Distinct(x, y, z)
>>> simplify(Distinct(x, y, z), blast_distinct=True)
And(Not(x == y), Not(x == z), Not(y == z))
Definition at line 1114 of file z3py.py.
01114 01115 def Distinct(*args): 01116 """Create a Z3 distinct expression. 01117 01118 >>> x = Int('x') 01119 >>> y = Int('y') 01120 >>> Distinct(x, y) 01121 x != y 01122 >>> z = Int('z') 01123 >>> Distinct(x, y, z) 01124 Distinct(x, y, z) 01125 >>> simplify(Distinct(x, y, z)) 01126 Distinct(x, y, z) 01127 >>> simplify(Distinct(x, y, z), blast_distinct=True) 01128 And(Not(x == y), Not(x == z), Not(y == z)) 01129 """ 01130 args = _get_args(args) 01131 ctx = _ctx_from_ast_arg_list(args) 01132 if __debug__: 01133 _z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression") 01134 args = _coerce_expr_list(args, ctx) 01135 _args, sz = _to_ast_array(args) 01136 return BoolRef(Z3_mk_distinct(ctx.ref(), sz, _args), ctx)
| def z3py.enable_trace | ( | msg | ) |
Definition at line 58 of file z3py.py.
00058 00059 def enable_trace(msg): 00060 Z3_enable_trace(msg)
| def z3py.EnumSort | ( | name, | |
| values, | |||
ctx = None |
|||
| ) |
Return a new enumeration sort named `name` containing the given values.
The result is a pair (sort, list of constants).
Example:
>>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue'])
Definition at line 4458 of file z3py.py.
Referenced by Context.mkEnumSort(), and Context.MkEnumSort().
04458 04459 def EnumSort(name, values, ctx=None): 04460 """Return a new enumeration sort named `name` containing the given values. 04461 04462 The result is a pair (sort, list of constants). 04463 Example: 04464 >>> Color, (red, green, blue) = EnumSort('Color', ['red', 'green', 'blue']) 04465 """ 04466 if __debug__: 04467 _z3_assert(isinstance(name, str), "Name must be a string") 04468 _z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings") 04469 _z3_assert(len(values) > 0, "At least one value expected") 04470 ctx = _get_ctx(ctx) 04471 num = len(values) 04472 _val_names = (Symbol * num)() 04473 for i in range(num): 04474 _val_names[i] = to_symbol(values[i]) 04475 _values = (FuncDecl * num)() 04476 _testers = (FuncDecl * num)() 04477 name = to_symbol(name) 04478 S = DatatypeSortRef(Z3_mk_enumeration_sort(ctx.ref(), name, num, _val_names, _values, _testers), ctx) 04479 V = [] 04480 for i in range(num): 04481 V.append(FuncDeclRef(_values[i], ctx)) 04482 V = [a() for a in V] 04483 return S, V
| def z3py.eq | ( | a, | |
| b | |||
| ) |
Return `True` if `a` and `b` are structurally identical AST nodes.
>>> x = Int('x')
>>> y = Int('y')
>>> eq(x, y)
False
>>> eq(x + 1, x + 1)
True
>>> eq(x + 1, 1 + x)
False
>>> eq(simplify(x + 1), simplify(1 + x))
True
Definition at line 371 of file z3py.py.
Referenced by BitVec(), BitVecSort(), FP(), FPSort(), FreshBool(), FreshInt(), FreshReal(), get_map_func(), Select(), and substitute().
00371 00372 def eq(a, b): 00373 """Return `True` if `a` and `b` are structurally identical AST nodes. 00374 00375 >>> x = Int('x') 00376 >>> y = Int('y') 00377 >>> eq(x, y) 00378 False 00379 >>> eq(x + 1, x + 1) 00380 True 00381 >>> eq(x + 1, 1 + x) 00382 False 00383 >>> eq(simplify(x + 1), simplify(1 + x)) 00384 True 00385 """ 00386 if __debug__: 00387 _z3_assert(is_ast(a) and is_ast(b), "Z3 ASTs expected") 00388 return a.eq(b)
| def z3py.Exists | ( | vs, | |
| body, | |||
weight = 1, |
|||
qid = "", |
|||
skid = "", |
|||
patterns = [], |
|||
no_patterns = [] |
|||
| ) |
Create a Z3 exists formula.
The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> q = Exists([x, y], f(x, y) >= x, skid="foo")
>>> q
Exists([x, y], f(x, y) >= x)
>>> is_quantifier(q)
True
>>> r = Tactic('nnf')(q).as_expr()
>>> is_quantifier(r)
False
Definition at line 1829 of file z3py.py.
Referenced by Fixedpoint.abstract(), and QuantifierRef.is_forall().
01829 01830 def Exists(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]): 01831 """Create a Z3 exists formula. 01832 01833 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations. 01834 01835 See http://rise4fun.com/Z3Py/tutorial/advanced for more details. 01836 01837 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 01838 >>> x = Int('x') 01839 >>> y = Int('y') 01840 >>> q = Exists([x, y], f(x, y) >= x, skid="foo") 01841 >>> q 01842 Exists([x, y], f(x, y) >= x) 01843 >>> is_quantifier(q) 01844 True 01845 >>> r = Tactic('nnf')(q).as_expr() 01846 >>> is_quantifier(r) 01847 False 01848 """ 01849 return _mk_quantifier(False, vs, body, weight, qid, skid, patterns, no_patterns)
| def z3py.Extract | ( | high, | |
| low, | |||
| a | |||
| ) |
Create a Z3 bit-vector extraction expression.
>>> x = BitVec('x', 8)
>>> Extract(6, 2, x)
Extract(6, 2, x)
>>> Extract(6, 2, x).sort()
BitVec(5)
Definition at line 3554 of file z3py.py.
03554 03555 def Extract(high, low, a): 03556 """Create a Z3 bit-vector extraction expression. 03557 03558 >>> x = BitVec('x', 8) 03559 >>> Extract(6, 2, x) 03560 Extract(6, 2, x) 03561 >>> Extract(6, 2, x).sort() 03562 BitVec(5) 03563 """ 03564 if __debug__: 03565 _z3_assert(low <= high, "First argument must be greater than or equal to second argument") 03566 _z3_assert(isinstance(high, int) and high >= 0 and isinstance(low, int) and low >= 0, "First and second arguments must be non negative integers") 03567 _z3_assert(is_bv(a), "Third argument must be a Z3 Bitvector expression") 03568 return BitVecRef(Z3_mk_extract(a.ctx_ref(), high, low, a.as_ast()), a.ctx)
| def z3py.FailIf | ( | p, | |
ctx = None |
|||
| ) |
Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal.
>>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify'))
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(y > 0)
>>> t(g)
[[x > 0, y > 0]]
>>> g.add(x == y + 1)
>>> t(g)
[[Not(x <= 0), Not(y <= 0), x == 1 + y]]
Definition at line 7125 of file z3py.py.
07125 07126 def FailIf(p, ctx=None): 07127 """Return a tactic that fails if the probe `p` evaluates to true. Otherwise, it returns the input goal unmodified. 07128 07129 In the following example, the tactic applies 'simplify' if and only if there are more than 2 constraints in the goal. 07130 07131 >>> t = OrElse(FailIf(Probe('size') > 2), Tactic('simplify')) 07132 >>> x, y = Ints('x y') 07133 >>> g = Goal() 07134 >>> g.add(x > 0) 07135 >>> g.add(y > 0) 07136 >>> t(g) 07137 [[x > 0, y > 0]] 07138 >>> g.add(x == y + 1) 07139 >>> t(g) 07140 [[Not(x <= 0), Not(y <= 0), x == 1 + y]] 07141 """ 07142 p = _to_probe(p, ctx) 07143 return Tactic(Z3_tactic_fail_if(p.ctx.ref(), p.probe), p.ctx)
| def z3py.FiniteDomainSort | ( | name, | |
| sz, | |||
ctx = None |
|||
| ) |
Create a named finite domain sort of a given size sz
Definition at line 6389 of file z3py.py.
Referenced by Sort.create(), Context.mkFiniteDomainSort(), and Context.MkFiniteDomainSort().
06389 06390 def FiniteDomainSort(name, sz, ctx=None): 06391 """Create a named finite domain sort of a given size sz""" 06392 ctx = _get_ctx(ctx) 06393 return FiniteDomainSortRef(Z3_mk_finite_domain_sort(ctx.ref(), name, sz), ctx)
| def z3py.Float128 | ( | ctx = None | ) |
| def z3py.Float16 | ( | ctx = None | ) |
| def z3py.Float32 | ( | ctx = None | ) |
| def z3py.Float64 | ( | ctx = None | ) |
| def z3py.FloatHalf | ( | ctx = None | ) |
| def FloatSingle | ( | ctx = None | ) |
Floating-point 32-bit (single) sort.
Floating-point 64-bit (double) sort.
Floating-point 128-bit (quadruple) sort.
Definition at line 7749 of file z3py.py.
07749 07750 def FloatSingle(ctx=None): 07751 """Floating-point 32-bit (single) sort.""" 07752 ctx = _get_ctx(ctx) 07753 return FPSortRef(Z3_mk_fpa_sort_single(ctx.ref()), ctx)
| def z3py.ForAll | ( | vs, | |
| body, | |||
weight = 1, |
|||
qid = "", |
|||
skid = "", |
|||
patterns = [], |
|||
no_patterns = [] |
|||
| ) |
Create a Z3 forall formula.
The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations.
See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> x = Int('x')
>>> y = Int('y')
>>> ForAll([x, y], f(x, y) >= x)
ForAll([x, y], f(x, y) >= x)
>>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ])
ForAll([x, y], f(x, y) >= x)
>>> ForAll([x, y], f(x, y) >= x, weight=10)
ForAll([x, y], f(x, y) >= x)
Definition at line 1810 of file z3py.py.
Referenced by Fixedpoint.abstract(), QuantifierRef.body(), QuantifierRef.children(), QuantifierRef.is_forall(), is_pattern(), is_quantifier(), MultiPattern(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().
01810 01811 def ForAll(vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]): 01812 """Create a Z3 forall formula. 01813 01814 The parameters `weight`, `qif`, `skid`, `patterns` and `no_patterns` are optional annotations. 01815 01816 See http://rise4fun.com/Z3Py/tutorial/advanced for more details. 01817 01818 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 01819 >>> x = Int('x') 01820 >>> y = Int('y') 01821 >>> ForAll([x, y], f(x, y) >= x) 01822 ForAll([x, y], f(x, y) >= x) 01823 >>> ForAll([x, y], f(x, y) >= x, patterns=[ f(x, y) ]) 01824 ForAll([x, y], f(x, y) >= x) 01825 >>> ForAll([x, y], f(x, y) >= x, weight=10) 01826 ForAll([x, y], f(x, y) >= x) 01827 """ 01828 return _mk_quantifier(True, vs, body, weight, qid, skid, patterns, no_patterns)
| def z3py.FP | ( | name, | |
| fpsort, | |||
ctx = None |
|||
| ) |
Return a floating-point constant named `name`.
`fpsort` is the floating-point sort.
If `ctx=None`, then the global context is used.
>>> x = FP('x', FPSort(8, 24))
>>> is_fp(x)
True
>>> x.ebits()
8
>>> x.sort()
FPSort(8, 24)
>>> word = FPSort(8, 24)
>>> x2 = FP('x', word)
>>> eq(x, x2)
True
Definition at line 8207 of file z3py.py.
Referenced by FPRef.__add__(), FPRef.__mul__(), FPRef.__radd__(), FPRef.__rmul__(), FPRef.__rsub__(), FPRef.__sub__(), fpAdd(), fpDiv(), fpMax(), fpMin(), fpMul(), fpNeg(), fpRem(), FPSort(), fpSub(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), is_fp(), is_fp_value(), and FPRef.sort().
08207 08208 def FP(name, fpsort, ctx=None): 08209 """Return a floating-point constant named `name`. 08210 `fpsort` is the floating-point sort. 08211 If `ctx=None`, then the global context is used. 08212 08213 >>> x = FP('x', FPSort(8, 24)) 08214 >>> is_fp(x) 08215 True 08216 >>> x.ebits() 08217 8 08218 >>> x.sort() 08219 FPSort(8, 24) 08220 >>> word = FPSort(8, 24) 08221 >>> x2 = FP('x', word) 08222 >>> eq(x, x2) 08223 True 08224 """ 08225 if isinstance(fpsort, FPSortRef): 08226 ctx = fpsort.ctx 08227 else: 08228 ctx = _get_ctx(ctx) 08229 return FPRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), fpsort.ast), ctx)
| def z3py.fpAbs | ( | a | ) |
Create a Z3 floating-point absolute value expression. >>> s = FPSort(8, 24) >>> rm = RNE() >>> x = FPVal(1.0, s) >>> fpAbs(x) fpAbs(1) >>> y = FPVal(-20.0, s) >>> y -1.25*(2**4) >>> fpAbs(y) fpAbs(-1.25*(2**4)) >>> fpAbs(-1.25*(2**4)) fpAbs(-1.25*(2**4)) >>> fpAbs(x).sort() FPSort(8, 24)
Definition at line 8248 of file z3py.py.
08248 08249 def fpAbs(a): 08250 """Create a Z3 floating-point absolute value expression. 08251 08252 >>> s = FPSort(8, 24) 08253 >>> rm = RNE() 08254 >>> x = FPVal(1.0, s) 08255 >>> fpAbs(x) 08256 fpAbs(1) 08257 >>> y = FPVal(-20.0, s) 08258 >>> y 08259 -1.25*(2**4) 08260 >>> fpAbs(y) 08261 fpAbs(-1.25*(2**4)) 08262 >>> fpAbs(-1.25*(2**4)) 08263 fpAbs(-1.25*(2**4)) 08264 >>> fpAbs(x).sort() 08265 FPSort(8, 24) 08266 """ 08267 ctx = None 08268 if not is_expr(a): 08269 ctx =_get_ctx(ctx) 08270 s = get_default_fp_sort(ctx) 08271 a = FPVal(a, s) 08272 else: 08273 ctx = a.ctx 08274 if __debug__: 08275 _z3_assert(is_fp(a), "First argument must be Z3 floating-point expression") 08276 return FPRef(Z3_mk_fpa_abs(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpAdd | ( | rm, | |
| a, | |||
| b | |||
| ) |
Create a Z3 floating-point addition expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpAdd(rm, x, y)
fpAdd(RNE(), x, y)
>>> fpAdd(rm, x, y).sort()
FPSort(8, 24)
Definition at line 8299 of file z3py.py.
Referenced by FPs().
08299 08300 def fpAdd(rm, a, b): 08301 """Create a Z3 floating-point addition expression. 08302 08303 >>> s = FPSort(8, 24) 08304 >>> rm = RNE() 08305 >>> x = FP('x', s) 08306 >>> y = FP('y', s) 08307 >>> fpAdd(rm, x, y) 08308 fpAdd(RNE(), x, y) 08309 >>> fpAdd(rm, x, y).sort() 08310 FPSort(8, 24) 08311 """ 08312 if __debug__: 08313 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08314 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08315 a, b = _coerce_exprs(a, b) 08316 return FPRef(Z3_mk_fpa_add(rm.ctx_ref(), rm.as_ast(), a.as_ast(), b.as_ast()), rm.ctx)
| def z3py.fpDiv | ( | rm, | |
| a, | |||
| b | |||
| ) |
Create a Z3 floating-point divison expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpDiv(rm, x, y)
fpDiv(RNE(), x, y)
>>> fpDiv(rm, x, y).sort()
FPSort(8, 24)
Definition at line 8353 of file z3py.py.
08353 08354 def fpDiv(rm, a, b): 08355 """Create a Z3 floating-point divison expression. 08356 08357 >>> s = FPSort(8, 24) 08358 >>> rm = RNE() 08359 >>> x = FP('x', s) 08360 >>> y = FP('y', s) 08361 >>> fpDiv(rm, x, y) 08362 fpDiv(RNE(), x, y) 08363 >>> fpDiv(rm, x, y).sort() 08364 FPSort(8, 24) 08365 """ 08366 if __debug__: 08367 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08368 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08369 a, b = _coerce_exprs(a, b) 08370 return FPRef(Z3_mk_fpa_div(rm.ctx_ref(), rm.as_ast(), a.as_ast(), b.as_ast()), rm.ctx)
| def z3py.fpEQ | ( | a, | |
| b | |||
| ) |
Create the Z3 floating-point expression `other <= self`.
>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpEQ(x, y)
fpEQ(x, y)
>>> fpEQ(x, y).sexpr()
'(fp.eq x y)'
Definition at line 8568 of file z3py.py.
Referenced by fpNEQ().
08568 08569 def fpEQ(a, b): 08570 """Create the Z3 floating-point expression `other <= self`. 08571 08572 >>> x, y = FPs('x y', FPSort(8, 24)) 08573 >>> fpEQ(x, y) 08574 fpEQ(x, y) 08575 >>> fpEQ(x, y).sexpr() 08576 '(fp.eq x y)' 08577 """ 08578 _check_fp_args(a, b) 08579 a, b = _coerce_exprs(a, b) 08580 return BoolRef(Z3_mk_fpa_eq(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpFMA | ( | rm, | |
| a, | |||
| b, | |||
| c | |||
| ) |
Create a Z3 floating-point fused multiply-add expression.
Definition at line 8421 of file z3py.py.
08421 08422 def fpFMA(rm, a, b, c): 08423 """Create a Z3 floating-point fused multiply-add expression. 08424 """ 08425 if __debug__: 08426 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08427 _z3_assert(is_fp(a) or is_fp(b) or is_fp(c), "Second, third, or fourth argument must be a Z3 floating-point expression") 08428 a, b, c = _coerce_expr_list([a, b, c]) 08429 return FPRef(Z3_mk_fpa_fma(rm.ctx_ref(), rm.as_ast(), a.as_ast(), b.as_ast(), c.as_ast()), rm.ctx)
| def z3py.fpFP | ( | sgn, | |
| exp, | |||
| sig | |||
| ) |
Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectorssgn, sig, and exp.
Definition at line 8596 of file z3py.py.
08596 08597 def fpFP(sgn, exp, sig): 08598 """Create the Z3 floating-point value `fpFP(sgn, sig, exp)` from the three bit-vectorssgn, sig, and exp.""" 08599 _z3_assert(is_bv(sgn) and is_bv(exp) and is_bv(sig), "sort mismatch") 08600 _z3_assert(sgn.sort().size() == 1, "sort mismatch") 08601 return FPRef(Z3_mk_fpa_fp(sgn.ctx_ref(), sgn.ast, exp.ast, sig.ast), sgn.ctx) 08602
| def z3py.fpGEQ | ( | a, | |
| b | |||
| ) |
Create the Z3 floating-point expression `other <= self`.
>>> x, y = FPs('x y', FPSort(8, 24))
>>> x + y
x + y
>>> fpGEQ(x, y)
x >= y
>>> (x >= y).sexpr()
'(fp.geq x y)'
Definition at line 8553 of file z3py.py.
08553 08554 def fpGEQ(a, b): 08555 """Create the Z3 floating-point expression `other <= self`. 08556 08557 >>> x, y = FPs('x y', FPSort(8, 24)) 08558 >>> x + y 08559 x + y 08560 >>> fpGEQ(x, y) 08561 x >= y 08562 >>> (x >= y).sexpr() 08563 '(fp.geq x y)' 08564 """ 08565 _check_fp_args(a, b) 08566 a, b = _coerce_exprs(a, b) 08567 return BoolRef(Z3_mk_fpa_geq(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpGT | ( | a, | |
| b | |||
| ) |
Create the Z3 floating-point expression `other <= self`.
>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpGT(x, y)
x > y
>>> (x > y).sexpr()
'(fp.gt x y)'
Definition at line 8539 of file z3py.py.
08539 08540 def fpGT(a, b): 08541 """Create the Z3 floating-point expression `other <= self`. 08542 08543 >>> x, y = FPs('x y', FPSort(8, 24)) 08544 >>> fpGT(x, y) 08545 x > y 08546 >>> (x > y).sexpr() 08547 '(fp.gt x y)' 08548 """ 08549 _check_fp_args(a, b) 08550 a, b = _coerce_exprs(a, b) 08551 return BoolRef(Z3_mk_fpa_gt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx) 08552
| def z3py.fpInfinity | ( | s, | |
| negative | |||
| ) |
Definition at line 8160 of file z3py.py.
08160 08161 def fpInfinity(s, negative): 08162 _z3_assert(isinstance(s, FPSortRef), "sort mismatch") 08163 _z3_assert(isinstance(negative, bool), "expected Boolean flag") 08164 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, negative), s.ctx)
| def z3py.fpIsInfinite | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8467 of file z3py.py.
08467 08468 def fpIsInfinite(a): 08469 """Create a Z3 floating-point isNaN expression. 08470 """ 08471 if __debug__: 08472 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08473 return FPRef(Z3_mk_fpa_is_infinite(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpIsNaN | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8460 of file z3py.py.
08460 08461 def fpIsNaN(a): 08462 """Create a Z3 floating-point isNaN expression. 08463 """ 08464 if __debug__: 08465 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08466 return FPRef(Z3_mk_fpa_is_nan(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpIsNegative | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8495 of file z3py.py.
08495 08496 def fpIsNegative(a): 08497 """Create a Z3 floating-point isNaN expression. 08498 """ 08499 if __debug__: 08500 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08501 return FPRef(Z3_mk_fpa_is_negative(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpIsNormal | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8481 of file z3py.py.
08481 08482 def fpIsNormal(a): 08483 """Create a Z3 floating-point isNaN expression. 08484 """ 08485 if __debug__: 08486 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08487 return FPRef(Z3_mk_fpa_is_normal(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpIsPositive | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8502 of file z3py.py.
08502 08503 def fpIsPositive(a): 08504 """Create a Z3 floating-point isNaN expression. 08505 """ 08506 if __debug__: 08507 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08508 return FPRef(Z3_mk_fpa_is_positive(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpIsSubnormal | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8488 of file z3py.py.
08488 08489 def fpIsSubnormal(a): 08490 """Create a Z3 floating-point isNaN expression. 08491 """ 08492 if __debug__: 08493 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08494 return FPRef(Z3_mk_fpa_is_subnormal(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpIsZero | ( | a | ) |
Create a Z3 floating-point isNaN expression.
Definition at line 8474 of file z3py.py.
08474 08475 def fpIsZero(a): 08476 """Create a Z3 floating-point isNaN expression. 08477 """ 08478 if __debug__: 08479 _z3_assert(is_fp(a), "Argument must be Z3 floating-point expressions") 08480 return FPRef(Z3_mk_fpa_is_zero(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpLEQ | ( | a, | |
| b | |||
| ) |
Create the Z3 floating-point expression `other <= self`.
>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpLEQ(x, y)
x <= y
>>> (x <= y).sexpr()
'(fp.leq x y)'
Definition at line 8526 of file z3py.py.
08526 08527 def fpLEQ(a, b): 08528 """Create the Z3 floating-point expression `other <= self`. 08529 08530 >>> x, y = FPs('x y', FPSort(8, 24)) 08531 >>> fpLEQ(x, y) 08532 x <= y 08533 >>> (x <= y).sexpr() 08534 '(fp.leq x y)' 08535 """ 08536 _check_fp_args(a, b) 08537 a, b = _coerce_exprs(a, b) 08538 return BoolRef(Z3_mk_fpa_leq(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpLT | ( | a, | |
| b | |||
| ) |
Create the Z3 floating-point expression `other <= self`.
>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpLT(x, y)
x < y
>>> (x <= y).sexpr()
'(fp.leq x y)'
Definition at line 8513 of file z3py.py.
08513 08514 def fpLT(a, b): 08515 """Create the Z3 floating-point expression `other <= self`. 08516 08517 >>> x, y = FPs('x y', FPSort(8, 24)) 08518 >>> fpLT(x, y) 08519 x < y 08520 >>> (x <= y).sexpr() 08521 '(fp.leq x y)' 08522 """ 08523 _check_fp_args(a, b) 08524 a, b = _coerce_exprs(a, b) 08525 return BoolRef(Z3_mk_fpa_lt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpMax | ( | a, | |
| b | |||
| ) |
Create a Z3 floating-point maximum expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpMax(x, y)
fpMax(x, y)
>>> fpMax(x, y).sort()
FPSort(8, 24)
Definition at line 8404 of file z3py.py.
08404 08405 def fpMax(a, b): 08406 """Create a Z3 floating-point maximum expression. 08407 08408 >>> s = FPSort(8, 24) 08409 >>> rm = RNE() 08410 >>> x = FP('x', s) 08411 >>> y = FP('y', s) 08412 >>> fpMax(x, y) 08413 fpMax(x, y) 08414 >>> fpMax(x, y).sort() 08415 FPSort(8, 24) 08416 """ 08417 if __debug__: 08418 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08419 a, b = _coerce_exprs(a, b) 08420 return FPRef(Z3_mk_fpa_max(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpMin | ( | a, | |
| b | |||
| ) |
Create a Z3 floating-point minimium expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpMin(x, y)
fpMin(x, y)
>>> fpMin(x, y).sort()
FPSort(8, 24)
Definition at line 8387 of file z3py.py.
08387 08388 def fpMin(a, b): 08389 """Create a Z3 floating-point minimium expression. 08390 08391 >>> s = FPSort(8, 24) 08392 >>> rm = RNE() 08393 >>> x = FP('x', s) 08394 >>> y = FP('y', s) 08395 >>> fpMin(x, y) 08396 fpMin(x, y) 08397 >>> fpMin(x, y).sort() 08398 FPSort(8, 24) 08399 """ 08400 if __debug__: 08401 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08402 a, b = _coerce_exprs(a, b) 08403 return FPRef(Z3_mk_fpa_min(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpMinusInfinity | ( | s | ) |
Definition at line 8156 of file z3py.py.
08156 08157 def fpMinusInfinity(s): 08158 _z3_assert(isinstance(s, FPSortRef), "sort mismatch") 08159 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, True), s.ctx)
| def z3py.fpMinusZero | ( | s | ) |
Definition at line 8169 of file z3py.py.
08169 08170 def fpMinusZero(s): 08171 _z3_assert(isinstance(s, FPSortRef), "sort mismatch") 08172 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, True), s.ctx)
| def z3py.fpMul | ( | rm, | |
| a, | |||
| b | |||
| ) |
Create a Z3 floating-point multiplication expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpMul(rm, x, y)
fpMul(RNE(), x, y)
>>> fpMul(rm, x, y).sort()
FPSort(8, 24)
Definition at line 8335 of file z3py.py.
Referenced by FPs().
08335 08336 def fpMul(rm, a, b): 08337 """Create a Z3 floating-point multiplication expression. 08338 08339 >>> s = FPSort(8, 24) 08340 >>> rm = RNE() 08341 >>> x = FP('x', s) 08342 >>> y = FP('y', s) 08343 >>> fpMul(rm, x, y) 08344 fpMul(RNE(), x, y) 08345 >>> fpMul(rm, x, y).sort() 08346 FPSort(8, 24) 08347 """ 08348 if __debug__: 08349 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08350 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08351 a, b = _coerce_exprs(a, b) 08352 return FPRef(Z3_mk_fpa_mul(rm.ctx_ref(), rm.as_ast(), a.as_ast(), b.as_ast()), rm.ctx)
| def z3py.fpNaN | ( | s | ) |
| def z3py.fpNeg | ( | a | ) |
Create a Z3 floating-point addition expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> fpNeg(x)
-x
>>> fpNeg(x).sort()
FPSort(8, 24)
Definition at line 8277 of file z3py.py.
08277 08278 def fpNeg(a): 08279 """Create a Z3 floating-point addition expression. 08280 08281 >>> s = FPSort(8, 24) 08282 >>> rm = RNE() 08283 >>> x = FP('x', s) 08284 >>> fpNeg(x) 08285 -x 08286 >>> fpNeg(x).sort() 08287 FPSort(8, 24) 08288 """ 08289 ctx = None 08290 if not is_expr(a): 08291 ctx =_get_ctx(ctx) 08292 s = get_default_fp_sort(ctx) 08293 a = FPVal(a, s) 08294 else: 08295 ctx = a.ctx 08296 if __debug__: 08297 _z3_assert(is_fp(a), "First argument must be Z3 floating-point expression") 08298 return FPRef(Z3_mk_fpa_neg(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.fpNEQ | ( | a, | |
| b | |||
| ) |
Create the Z3 floating-point expression `other <= self`.
>>> x, y = FPs('x y', FPSort(8, 24))
>>> fpNEQ(x, y)
Not(fpEQ(x, y))
>>> (x != y).sexpr()
'(not (fp.eq x y))'
Definition at line 8581 of file z3py.py.
08581 08582 def fpNEQ(a, b): 08583 """Create the Z3 floating-point expression `other <= self`. 08584 08585 >>> x, y = FPs('x y', FPSort(8, 24)) 08586 >>> fpNEQ(x, y) 08587 Not(fpEQ(x, y)) 08588 >>> (x != y).sexpr() 08589 '(not (fp.eq x y))' 08590 """ 08591 _check_fp_args(a, b) 08592 a, b = _coerce_exprs(a, b) 08593 return Not(BoolRef(Z3_mk_fpa_eq(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx), a.ctx) 08594 08595
| def z3py.fpPlusInfinity | ( | s | ) |
Definition at line 8152 of file z3py.py.
08152 08153 def fpPlusInfinity(s): 08154 _z3_assert(isinstance(s, FPSortRef), "sort mismatch") 08155 return FPNumRef(Z3_mk_fpa_inf(s.ctx_ref(), s.ast, False), s.ctx)
| def z3py.fpPlusZero | ( | s | ) |
Definition at line 8165 of file z3py.py.
08165 08166 def fpPlusZero(s): 08167 _z3_assert(isinstance(s, FPSortRef), "sort mismatch") 08168 return FPNumRef(Z3_mk_fpa_zero(s.ctx_ref(), s.ast, False), s.ctx)
| def z3py.fpRem | ( | a, | |
| b | |||
| ) |
Create a Z3 floating-point remainder expression.
>>> s = FPSort(8, 24)
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpRem(x, y)
fpRem(x, y)
>>> fpRem(x, y).sort()
FPSort(8, 24)
Definition at line 8371 of file z3py.py.
08371 08372 def fpRem(a, b): 08373 """Create a Z3 floating-point remainder expression. 08374 08375 >>> s = FPSort(8, 24) 08376 >>> x = FP('x', s) 08377 >>> y = FP('y', s) 08378 >>> fpRem(x, y) 08379 fpRem(x, y) 08380 >>> fpRem(x, y).sort() 08381 FPSort(8, 24) 08382 """ 08383 if __debug__: 08384 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08385 a, b = _coerce_exprs(a, b) 08386 return FPRef(Z3_mk_fpa_rem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.fpRoundToIntegral | ( | rm, | |
| a | |||
| ) |
Create a Z3 floating-point roundToIntegral expression.
Definition at line 8445 of file z3py.py.
08445 08446 def fpRoundToIntegral(rm, a): 08447 """Create a Z3 floating-point roundToIntegral expression. 08448 """ 08449 ctx = None 08450 if not is_expr(a): 08451 ctx =_get_ctx(ctx) 08452 s = get_default_fp_sort(ctx) 08453 a = FPVal(a, s) 08454 else: 08455 ctx = a.ctx 08456 if __debug__: 08457 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08458 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expressions") 08459 return FPRef(Z3_mk_fpa_round_to_integral(rm.ctx_ref(), rm.as_ast(), a.as_ast()), rm.ctx)
| def z3py.FPs | ( | names, | |
| fpsort, | |||
ctx = None |
|||
| ) |
Return an array of floating-point constants.
>>> x, y, z = FPs('x y z', FPSort(8, 24))
>>> x.sort()
FPSort(8, 24)
>>> x.sbits()
24
>>> x.ebits()
8
>>> fpMul(RNE(), fpAdd(RNE(), x, y), z)
fpMul(RNE(), fpAdd(RNE(), x, y), z)
Definition at line 8230 of file z3py.py.
Referenced by fpEQ(), fpGEQ(), fpGT(), fpLEQ(), fpLT(), and fpNEQ().
08230 08231 def FPs(names, fpsort, ctx=None): 08232 """Return an array of floating-point constants. 08233 08234 >>> x, y, z = FPs('x y z', FPSort(8, 24)) 08235 >>> x.sort() 08236 FPSort(8, 24) 08237 >>> x.sbits() 08238 24 08239 >>> x.ebits() 08240 8 08241 >>> fpMul(RNE(), fpAdd(RNE(), x, y), z) 08242 fpMul(RNE(), fpAdd(RNE(), x, y), z) 08243 """ 08244 ctx = z3._get_ctx(ctx) 08245 if isinstance(names, str): 08246 names = names.split(" ") 08247 return [FP(name, fpsort, ctx) for name in names]
| def z3py.FPSort | ( | ebits, | |
| sbits, | |||
ctx = None |
|||
| ) |
Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used.
>>> Single = FPSort(8, 24)
>>> Double = FPSort(11, 53)
>>> Single
FPSort(8, 24)
>>> x = Const('x', Single)
>>> eq(x, FP('x', FPSort(8, 24)))
True
Definition at line 8119 of file z3py.py.
Referenced by FPRef.__add__(), FPRef.__mul__(), FPRef.__radd__(), FPRef.__rmul__(), FPRef.__rsub__(), FPRef.__sub__(), FPSortRef.cast(), Sort.create(), FPSortRef.ebits(), FPRef.ebits(), FPNumRef.exponent(), FPNumRef.exponent_as_long(), FP(), fpAbs(), fpAdd(), fpDiv(), fpEQ(), fpGEQ(), fpGT(), fpLEQ(), fpLT(), fpMax(), fpMin(), fpMul(), fpNeg(), fpNEQ(), fpRem(), FPs(), fpSub(), fpToIEEEBV(), fpToReal(), fpToSBV(), fpToUBV(), FPVal(), is_fp(), is_fp_sort(), is_fp_value(), is_fprm_sort(), FPNumRef.isNegative(), Context.mkFPSort(), Context.MkFPSort(), Context.mkFPSort128(), Context.MkFPSort128(), Context.mkFPSort16(), Context.MkFPSort16(), Context.mkFPSort32(), Context.MkFPSort32(), Context.mkFPSort64(), Context.MkFPSort64(), Context.mkFPSortDouble(), Context.MkFPSortDouble(), Context.mkFPSortHalf(), Context.MkFPSortHalf(), Context.mkFPSortQuadruple(), Context.MkFPSortQuadruple(), Context.mkFPSortSingle(), Context.MkFPSortSingle(), FPSortRef.sbits(), FPRef.sbits(), FPNumRef.sign(), FPNumRef.significand(), and FPRef.sort().
08119 08120 def FPSort(ebits, sbits, ctx=None): 08121 """Return a Z3 floating-point sort of the given sizes. If `ctx=None`, then the global context is used. 08122 08123 >>> Single = FPSort(8, 24) 08124 >>> Double = FPSort(11, 53) 08125 >>> Single 08126 FPSort(8, 24) 08127 >>> x = Const('x', Single) 08128 >>> eq(x, FP('x', FPSort(8, 24))) 08129 True 08130 """ 08131 ctx = z3._get_ctx(ctx) 08132 return FPSortRef(Z3_mk_fpa_sort(ctx.ref(), ebits, sbits), ctx)
| def z3py.fpSqrt | ( | rm, | |
| a | |||
| ) |
Create a Z3 floating-point square root expression.
Definition at line 8430 of file z3py.py.
08430 08431 def fpSqrt(rm, a): 08432 """Create a Z3 floating-point square root expression. 08433 """ 08434 ctx = None 08435 if not is_expr(a): 08436 ctx =_get_ctx(ctx) 08437 s = get_default_fp_sort(ctx) 08438 a = FPVal(a, s) 08439 else: 08440 ctx = a.ctx 08441 if __debug__: 08442 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08443 _z3_assert(is_fp(a), "Second argument must be a Z3 floating-point expressions") 08444 return FPRef(Z3_mk_fpa_sqrt(rm.ctx_ref(), rm.as_ast(), a.as_ast()), rm.ctx)
| def z3py.fpSub | ( | rm, | |
| a, | |||
| b | |||
| ) |
Create a Z3 floating-point subtraction expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
>>> x = FP('x', s)
>>> y = FP('y', s)
>>> fpSub(rm, x, y)
fpSub(RNE(), x, y)
>>> fpSub(rm, x, y).sort()
FPSort(8, 24)
Definition at line 8317 of file z3py.py.
08317 08318 def fpSub(rm, a, b): 08319 """Create a Z3 floating-point subtraction expression. 08320 08321 >>> s = FPSort(8, 24) 08322 >>> rm = RNE() 08323 >>> x = FP('x', s) 08324 >>> y = FP('y', s) 08325 >>> fpSub(rm, x, y) 08326 fpSub(RNE(), x, y) 08327 >>> fpSub(rm, x, y).sort() 08328 FPSort(8, 24) 08329 """ 08330 if __debug__: 08331 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08332 _z3_assert(is_fp(a) or is_fp(b), "Second or third argument must be a Z3 floating-point expression") 08333 a, b = _coerce_exprs(a, b) 08334 return FPRef(Z3_mk_fpa_sub(rm.ctx_ref(), rm.as_ast(), a.as_ast(), b.as_ast()), rm.ctx)
| def z3py.fpToFP | ( | a1, | |
a2 = None, |
|||
a3 = None |
|||
| ) |
Create a Z3 floating-point conversion expression from other terms.
Definition at line 8603 of file z3py.py.
08603 08604 def fpToFP(a1, a2=None, a3=None): 08605 """Create a Z3 floating-point conversion expression from other terms.""" 08606 if is_bv(a1) and is_fp_sort(a2): 08607 return FPRef(Z3_mk_fpa_to_fp_bv(a1.ctx_ref(), a1.ast, a2.ast), a1.ctx) 08608 elif is_fprm(a1) and is_fp(a2) and is_fp_sort(a3): 08609 return FPRef(Z3_mk_fpa_to_fp_float(a1.ctx_ref(), a1.ast, a2.ast, a3.ast), a1.ctx) 08610 elif is_fprm(a1) and is_real(a2) and is_fp_sort(a3): 08611 return FPRef(Z3_mk_fpa_to_fp_real(a1.ctx_ref(), a1.ast, a2.ast, a3.ast), a1.ctx) 08612 elif is_fprm(a1) and is_bv(a2) and is_fp_sort(a3): 08613 return FPRef(Z3_mk_fpa_to_fp_signed(a1.ctx_ref(), a1.ast, a2.ast, a3.ast), a1.ctx) 08614 else: 08615 raise Z3Exception("Unsupported combination of arguments for conversion to floating-point term.")
| def z3py.fpToFPUnsigned | ( | rm, | |
| x, | |||
| s | |||
| ) |
Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression.
Definition at line 8616 of file z3py.py.
08616 08617 def fpToFPUnsigned(rm, x, s): 08618 """Create a Z3 floating-point conversion expression, from unsigned bit-vector to floating-point expression.""" 08619 if __debug__: 08620 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08621 _z3_assert(is_bv(x), "Second argument must be a Z3 bit-vector expression") 08622 _z3_assert(is_fp_sort(s), "Third argument must be Z3 floating-point sort") 08623 return FPRef(Z3_mk_fpa_to_fp_unsigned(rm.ctx_ref(), rm.ast, x.ast, s.ast), rm.ctx)
| def z3py.fpToIEEEBV | ( | x | ) |
\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format.
The size of the resulting bit-vector is automatically determined.
Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
knows only one NaN and it will always produce the same bit-vector represenatation of
that NaN.
>>> x = FP('x', FPSort(8, 24))
>>> y = fpToIEEEBV(x)
>>> print is_fp(x)
True
>>> print is_bv(y)
True
>>> print is_fp(y)
False
>>> print is_bv(x)
False
Definition at line 8682 of file z3py.py.
08682 08683 def fpToIEEEBV(x): 08684 """\brief Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. 08685 08686 The size of the resulting bit-vector is automatically determined. 08687 08688 Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion 08689 knows only one NaN and it will always produce the same bit-vector represenatation of 08690 that NaN. 08691 08692 >>> x = FP('x', FPSort(8, 24)) 08693 >>> y = fpToIEEEBV(x) 08694 >>> print is_fp(x) 08695 True 08696 >>> print is_bv(y) 08697 True 08698 >>> print is_fp(y) 08699 False 08700 >>> print is_bv(x) 08701 False 08702 """ 08703 if __debug__: 08704 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression") 08705 return BitVecRef(Z3_mk_fpa_to_ieee_bv(x.ctx_ref(), x.ast), x.ctx)
| def z3py.fpToReal | ( | x | ) |
Create a Z3 floating-point conversion expression, from floating-point expression to real.
>>> x = FP('x', FPSort(8, 24))
>>> y = fpToReal(x)
>>> print is_fp(x)
True
>>> print is_real(y)
True
>>> print is_fp(y)
False
>>> print is_real(x)
False
Definition at line 8664 of file z3py.py.
08664 08665 def fpToReal(x): 08666 """Create a Z3 floating-point conversion expression, from floating-point expression to real. 08667 08668 >>> x = FP('x', FPSort(8, 24)) 08669 >>> y = fpToReal(x) 08670 >>> print is_fp(x) 08671 True 08672 >>> print is_real(y) 08673 True 08674 >>> print is_fp(y) 08675 False 08676 >>> print is_real(x) 08677 False 08678 """ 08679 if __debug__: 08680 _z3_assert(is_fp(x), "First argument must be a Z3 floating-point expression") 08681 return ArithRef(Z3_mk_fpa_to_real(x.ctx_ref(), x.ast), x.ctx)
| def z3py.fpToSBV | ( | rm, | |
| x, | |||
| s | |||
| ) |
Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector.
>>> x = FP('x', FPSort(8, 24))
>>> y = fpToSBV(RTZ(), x, BitVecSort(32))
>>> print is_fp(x)
True
>>> print is_bv(y)
True
>>> print is_fp(y)
False
>>> print is_bv(x)
False
Definition at line 8624 of file z3py.py.
08624 08625 def fpToSBV(rm, x, s): 08626 """Create a Z3 floating-point conversion expression, from floating-point expression to signed bit-vector. 08627 08628 >>> x = FP('x', FPSort(8, 24)) 08629 >>> y = fpToSBV(RTZ(), x, BitVecSort(32)) 08630 >>> print is_fp(x) 08631 True 08632 >>> print is_bv(y) 08633 True 08634 >>> print is_fp(y) 08635 False 08636 >>> print is_bv(x) 08637 False 08638 """ 08639 if __debug__: 08640 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08641 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression") 08642 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort") 08643 return BitVecRef(Z3_mk_fpa_to_sbv(rm.ctx_ref(), rm.ast, x.ast, s.size()), rm.ctx)
| def z3py.fpToUBV | ( | rm, | |
| x, | |||
| s | |||
| ) |
Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector.
>>> x = FP('x', FPSort(8, 24))
>>> y = fpToUBV(RTZ(), x, BitVecSort(32))
>>> print is_fp(x)
True
>>> print is_bv(y)
True
>>> print is_fp(y)
False
>>> print is_bv(x)
False
Definition at line 8644 of file z3py.py.
08644 08645 def fpToUBV(rm, x, s): 08646 """Create a Z3 floating-point conversion expression, from floating-point expression to unsigned bit-vector. 08647 08648 >>> x = FP('x', FPSort(8, 24)) 08649 >>> y = fpToUBV(RTZ(), x, BitVecSort(32)) 08650 >>> print is_fp(x) 08651 True 08652 >>> print is_bv(y) 08653 True 08654 >>> print is_fp(y) 08655 False 08656 >>> print is_bv(x) 08657 False 08658 """ 08659 if __debug__: 08660 _z3_assert(is_fprm(rm), "First argument must be a Z3 floating-point rounding mode expression") 08661 _z3_assert(is_fp(x), "Second argument must be a Z3 floating-point expression") 08662 _z3_assert(is_bv_sort(s), "Third argument must be Z3 bit-vector sort") 08663 return BitVecRef(Z3_mk_fpa_to_ubv(rm.ctx_ref(), rm.ast, x.ast, s.size()), rm.ctx)
| def z3py.FPVal | ( | sig, | |
exp = None, |
|||
fps = None, |
|||
ctx = None |
|||
| ) |
Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used.
>>> v = FPVal(20.0, FPSort(8, 24))
>>> v
1.25*(2**4)
>>> print("0x%.8x" % v.exponent_as_long())
0x00000004
>>> v = FPVal(2.25, FPSort(8, 24))
>>> v
1.125*(2**1)
>>> v = FPVal(-2.25, FPSort(8, 24))
>>> v
-1.125*(2**1)
Definition at line 8178 of file z3py.py.
Referenced by fpAbs(), fpNeg(), fpRoundToIntegral(), fpSqrt(), and is_fp_value().
08178 08179 def FPVal(sig, exp=None, fps=None, ctx=None): 08180 """Return a floating-point value of value `val` and sort `fps`. If `ctx=None`, then the global context is used. 08181 08182 >>> v = FPVal(20.0, FPSort(8, 24)) 08183 >>> v 08184 1.25*(2**4) 08185 >>> print("0x%.8x" % v.exponent_as_long()) 08186 0x00000004 08187 >>> v = FPVal(2.25, FPSort(8, 24)) 08188 >>> v 08189 1.125*(2**1) 08190 >>> v = FPVal(-2.25, FPSort(8, 24)) 08191 >>> v 08192 -1.125*(2**1) 08193 """ 08194 ctx = _get_ctx(ctx) 08195 if is_fp_sort(exp): 08196 fps = exp 08197 exp = None 08198 elif fps == None: 08199 fps = _dflt_fps(ctx) 08200 _z3_assert(is_fp_sort(fps), "sort mismatch") 08201 if exp == None: 08202 exp = 0 08203 val = _to_float_str(sig) 08204 val = val + 'p' 08205 val = val + _to_int_str(exp) 08206 return FPNumRef(Z3_mk_numeral(ctx.ref(), val, fps.ast), ctx)
| def z3py.fpZero | ( | s, | |
| negative | |||
| ) |
| def z3py.FreshBool | ( | prefix = 'b', |
|
ctx = None |
|||
| ) |
Return a fresh Boolean constant in the given context using the given prefix. If `ctx=None`, then the global context is used. >>> b1 = FreshBool() >>> b2 = FreshBool() >>> eq(b1, b2) False
Definition at line 1421 of file z3py.py.
01421 01422 def FreshBool(prefix='b', ctx=None): 01423 """Return a fresh Boolean constant in the given context using the given prefix. 01424 01425 If `ctx=None`, then the global context is used. 01426 01427 >>> b1 = FreshBool() 01428 >>> b2 = FreshBool() 01429 >>> eq(b1, b2) 01430 False 01431 """ 01432 ctx = _get_ctx(ctx) 01433 return BoolRef(Z3_mk_fresh_const(ctx.ref(), prefix, BoolSort(ctx).ast), ctx)
| def z3py.FreshInt | ( | prefix = 'x', |
|
ctx = None |
|||
| ) |
Return a fresh integer constant in the given context using the given prefix. >>> x = FreshInt() >>> y = FreshInt() >>> eq(x, y) False >>> x.sort() Int
Definition at line 2777 of file z3py.py.
02777 02778 def FreshInt(prefix='x', ctx=None): 02779 """Return a fresh integer constant in the given context using the given prefix. 02780 02781 >>> x = FreshInt() 02782 >>> y = FreshInt() 02783 >>> eq(x, y) 02784 False 02785 >>> x.sort() 02786 Int 02787 """ 02788 ctx = _get_ctx(ctx) 02789 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, IntSort(ctx).ast), ctx)
| def z3py.FreshReal | ( | prefix = 'b', |
|
ctx = None |
|||
| ) |
Return a fresh real constant in the given context using the given prefix. >>> x = FreshReal() >>> y = FreshReal() >>> eq(x, y) False >>> x.sort() Real
Definition at line 2829 of file z3py.py.
02829 02830 def FreshReal(prefix='b', ctx=None): 02831 """Return a fresh real constant in the given context using the given prefix. 02832 02833 >>> x = FreshReal() 02834 >>> y = FreshReal() 02835 >>> eq(x, y) 02836 False 02837 >>> x.sort() 02838 Real 02839 """ 02840 ctx = _get_ctx(ctx) 02841 return ArithRef(Z3_mk_fresh_const(ctx.ref(), prefix, RealSort(ctx).ast), ctx)
| def z3py.Function | ( | name, | |
| sig | |||
| ) |
Create a new Z3 uninterpreted function with the given sorts.
>>> f = Function('f', IntSort(), IntSort())
>>> f(f(0))
f(f(0))
Definition at line 705 of file z3py.py.
Referenced by ModelRef.__getitem__(), ModelRef.__len__(), FuncEntry.arg_value(), FuncInterp.arity(), FuncEntry.as_list(), FuncInterp.as_list(), QuantifierRef.body(), QuantifierRef.children(), ModelRef.decls(), FuncInterp.else_value(), FuncInterp.entry(), Exists(), ForAll(), ModelRef.get_interp(), get_map_func(), QuantifierRef.is_forall(), is_map(), is_pattern(), is_quantifier(), Map(), MultiPattern(), FuncEntry.num_args(), FuncInterp.num_entries(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), FuncEntry.value(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().
00705 00706 def Function(name, *sig): 00707 """Create a new Z3 uninterpreted function with the given sorts. 00708 00709 >>> f = Function('f', IntSort(), IntSort()) 00710 >>> f(f(0)) 00711 f(f(0)) 00712 """ 00713 sig = _get_args(sig) 00714 if __debug__: 00715 _z3_assert(len(sig) > 0, "At least two arguments expected") 00716 arity = len(sig) - 1 00717 rng = sig[arity] 00718 if __debug__: 00719 _z3_assert(is_sort(rng), "Z3 sort expected") 00720 dom = (Sort * arity)() 00721 for i in range(arity): 00722 if __debug__: 00723 _z3_assert(is_sort(sig[i]), "Z3 sort expected") 00724 dom[i] = sig[i].ast 00725 ctx = rng.ctx 00726 return FuncDeclRef(Z3_mk_func_decl(ctx.ref(), to_symbol(name, ctx), arity, dom, rng.ast), ctx)
| def z3py.get_as_array_func | ( | n | ) |
Return the function declaration f associated with a Z3 expression of the form (_ as-array f).
Definition at line 5593 of file z3py.py.
05593 05594 def get_as_array_func(n): 05595 """Return the function declaration f associated with a Z3 expression of the form (_ as-array f).""" 05596 if __debug__: 05597 _z3_assert(is_as_array(n), "as-array Z3 expression expected.") 05598 return FuncDeclRef(Z3_get_as_array_func_decl(n.ctx.ref(), n.as_ast()), n.ctx)
| def z3py.get_default_fp_sort | ( | ctx = None | ) |
Definition at line 7681 of file z3py.py.
Referenced by fpAbs(), fpNeg(), fpRoundToIntegral(), and fpSqrt().
07681 07682 def get_default_fp_sort(ctx=None): 07683 return FPSort(_dflt_fpsort_ebits, _dflt_fpsort_sbits, ctx)
| def z3py.get_default_rounding_mode | ( | ctx = None | ) |
Retrieves the global default rounding mode.
Definition at line 7654 of file z3py.py.
07654 07655 def get_default_rounding_mode(ctx=None): 07656 """Retrieves the global default rounding mode.""" 07657 global _dflt_rounding_mode 07658 if _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO: 07659 return RTZ(ctx) 07660 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE: 07661 return RTN(ctx) 07662 elif _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE: 07663 return RTP(ctx) 07664 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN: 07665 return RNE(ctx) 07666 elif _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY: 07667 return RNA(ctx)
| def z3py.get_map_func | ( | a | ) |
Return the function declaration associated with a Z3 map array expression.
>>> f = Function('f', IntSort(), IntSort())
>>> b = Array('b', IntSort(), IntSort())
>>> a = Map(f, b)
>>> eq(f, get_map_func(a))
True
>>> get_map_func(a)
f
>>> get_map_func(a)(0)
f(0)
Definition at line 3987 of file z3py.py.
03987 03988 def get_map_func(a): 03989 """Return the function declaration associated with a Z3 map array expression. 03990 03991 >>> f = Function('f', IntSort(), IntSort()) 03992 >>> b = Array('b', IntSort(), IntSort()) 03993 >>> a = Map(f, b) 03994 >>> eq(f, get_map_func(a)) 03995 True 03996 >>> get_map_func(a) 03997 f 03998 >>> get_map_func(a)(0) 03999 f(0) 04000 """ 04001 if __debug__: 04002 _z3_assert(is_map(a), "Z3 array map expression expected.") 04003 return FuncDeclRef(Z3_to_func_decl(a.ctx_ref(), Z3_get_decl_ast_parameter(a.ctx_ref(), a.decl().ast, 0)), a.ctx)
| def z3py.get_param | ( | name | ) |
Return the value of a Z3 global (or module) parameter
>>> get_param('nlsat.reorder')
'true'
Definition at line 247 of file z3py.py.
00247 00248 def get_param(name): 00249 """Return the value of a Z3 global (or module) parameter 00250 00251 >>> get_param('nlsat.reorder') 00252 'true' 00253 """ 00254 ptr = (ctypes.c_char_p * 1)() 00255 if Z3_global_param_get(str(name), ptr): 00256 r = z3core._to_pystr(ptr[0]) 00257 return r 00258 raise Z3Exception("failed to retrieve value for '%s'" % name)
| def z3py.get_var_index | ( | a | ) |
Return the de-Bruijn index of the Z3 bounded variable `a`.
>>> x = Int('x')
>>> y = Int('y')
>>> is_var(x)
False
>>> is_const(x)
True
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> # Z3 replaces x and y with bound variables when ForAll is executed.
>>> q = ForAll([x, y], f(x, y) == x + y)
>>> q.body()
f(Var(1), Var(0)) == Var(1) + Var(0)
>>> b = q.body()
>>> b.arg(0)
f(Var(1), Var(0))
>>> v1 = b.arg(0).arg(0)
>>> v2 = b.arg(0).arg(1)
>>> v1
Var(1)
>>> v2
Var(0)
>>> get_var_index(v1)
1
>>> get_var_index(v2)
0
Definition at line 1048 of file z3py.py.
01048 01049 def get_var_index(a): 01050 """Return the de-Bruijn index of the Z3 bounded variable `a`. 01051 01052 >>> x = Int('x') 01053 >>> y = Int('y') 01054 >>> is_var(x) 01055 False 01056 >>> is_const(x) 01057 True 01058 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 01059 >>> # Z3 replaces x and y with bound variables when ForAll is executed. 01060 >>> q = ForAll([x, y], f(x, y) == x + y) 01061 >>> q.body() 01062 f(Var(1), Var(0)) == Var(1) + Var(0) 01063 >>> b = q.body() 01064 >>> b.arg(0) 01065 f(Var(1), Var(0)) 01066 >>> v1 = b.arg(0).arg(0) 01067 >>> v2 = b.arg(0).arg(1) 01068 >>> v1 01069 Var(1) 01070 >>> v2 01071 Var(0) 01072 >>> get_var_index(v1) 01073 1 01074 >>> get_var_index(v2) 01075 0 01076 """ 01077 if __debug__: 01078 _z3_assert(is_var(a), "Z3 bound variable expected") 01079 return int(Z3_get_index_value(a.ctx.ref(), a.as_ast()))
| def z3py.get_version | ( | ) |
Definition at line 72 of file z3py.py.
00072 00073 def get_version(): 00074 major = ctypes.c_uint(0) 00075 minor = ctypes.c_uint(0) 00076 build = ctypes.c_uint(0) 00077 rev = ctypes.c_uint(0) 00078 Z3_get_version(major, minor, build, rev) 00079 return (major.value, minor.value, build.value, rev.value) 00080 00081 # We use _z3_assert instead of the assert command because we want to # produce nice error messages in Z3Py at rise4fun.com
| def z3py.get_version_string | ( | ) |
Definition at line 64 of file z3py.py.
00064 00065 def get_version_string(): 00066 major = ctypes.c_uint(0) 00067 minor = ctypes.c_uint(0) 00068 build = ctypes.c_uint(0) 00069 rev = ctypes.c_uint(0) 00070 Z3_get_version(major, minor, build, rev) 00071 return "%s.%s.%s" % (major.value, minor.value, build.value)
| def z3py.help_simplify | ( | ) |
Return a string describing all options available for Z3 `simplify` procedure.
Definition at line 7202 of file z3py.py.
07202 07203 def help_simplify(): 07204 """Return a string describing all options available for Z3 `simplify` procedure.""" 07205 print(Z3_simplify_get_help(main_ctx().ref()))
| def z3py.If | ( | a, | |
| b, | |||
| c, | |||
ctx = None |
|||
| ) |
Create a Z3 if-then-else expression.
>>> x = Int('x')
>>> y = Int('y')
>>> max = If(x > y, x, y)
>>> max
If(x > y, x, y)
>>> simplify(max)
If(x <= y, y, x)
Definition at line 1092 of file z3py.py.
01092 01093 def If(a, b, c, ctx=None): 01094 """Create a Z3 if-then-else expression. 01095 01096 >>> x = Int('x') 01097 >>> y = Int('y') 01098 >>> max = If(x > y, x, y) 01099 >>> max 01100 If(x > y, x, y) 01101 >>> simplify(max) 01102 If(x <= y, y, x) 01103 """ 01104 if isinstance(a, Probe) or isinstance(b, Tactic) or isinstance(c, Tactic): 01105 return Cond(a, b, c, ctx) 01106 else: 01107 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b, c], ctx)) 01108 s = BoolSort(ctx) 01109 a = s.cast(a) 01110 b, c = _coerce_exprs(b, c, ctx) 01111 if __debug__: 01112 _z3_assert(a.ctx == b.ctx, "Context mismatch") 01113 return _to_expr_ref(Z3_mk_ite(ctx.ref(), a.as_ast(), b.as_ast(), c.as_ast()), ctx)
| def z3py.Implies | ( | a, | |
| b, | |||
ctx = None |
|||
| ) |
Create a Z3 implies expression.
>>> p, q = Bools('p q')
>>> Implies(p, q)
Implies(p, q)
>>> simplify(Implies(p, q))
Or(Not(p), q)
Definition at line 1434 of file z3py.py.
Referenced by Fixedpoint.add_rule(), Store(), Solver.unsat_core(), Update(), and Fixedpoint.update_rule().
01434 01435 def Implies(a, b, ctx=None): 01436 """Create a Z3 implies expression. 01437 01438 >>> p, q = Bools('p q') 01439 >>> Implies(p, q) 01440 Implies(p, q) 01441 >>> simplify(Implies(p, q)) 01442 Or(Not(p), q) 01443 """ 01444 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx)) 01445 s = BoolSort(ctx) 01446 a = s.cast(a) 01447 b = s.cast(b) 01448 return BoolRef(Z3_mk_implies(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
| def z3py.Int | ( | name, | |
ctx = None |
|||
| ) |
Return an integer constant named `name`. If `ctx=None`, then the global context is used.
>>> x = Int('x')
>>> is_int(x)
True
>>> is_int(x + 1)
True
Definition at line 2742 of file z3py.py.
Referenced by ArithRef.__add__(), AstVector.__contains__(), AstMap.__contains__(), ArithRef.__div__(), Statistics.__getattr__(), ArrayRef.__getitem__(), AstVector.__getitem__(), AstMap.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), AstVector.__len__(), AstMap.__len__(), ModelRef.__len__(), Statistics.__len__(), ArithRef.__mod__(), ArithRef.__neg__(), ArithRef.__pos__(), ArithRef.__radd__(), ArithRef.__rdiv__(), ArithRef.__rmod__(), ArithRef.__rsub__(), AstVector.__setitem__(), AstMap.__setitem__(), ArithRef.__sub__(), Goal.add(), Solver.add(), Goal.append(), Solver.append(), Goal.as_expr(), Solver.assert_and_track(), Goal.assert_exprs(), Solver.assert_exprs(), Solver.assertions(), binary_interpolant(), QuantifierRef.body(), BV2Int(), Solver.check(), QuantifierRef.children(), ModelRef.decls(), AstMap.erase(), ModelRef.eval(), ModelRef.evaluate(), Exists(), ForAll(), ModelRef.get_interp(), Statistics.get_key_value(), Goal.insert(), Solver.insert(), Interpolant(), is_arith(), is_arith_sort(), is_bv(), QuantifierRef.is_forall(), is_fp(), ArithSortRef.is_int(), ArithRef.is_int(), is_int(), is_int_value(), is_pattern(), is_quantifier(), ArithSortRef.is_real(), is_real(), is_select(), is_to_real(), K(), AstMap.keys(), Statistics.keys(), Solver.model(), MultiPattern(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), Solver.pop(), AstVector.push(), Solver.push(), Solver.reason_unknown(), AstMap.reset(), Solver.reset(), AstVector.resize(), Select(), sequence_interpolant(), Solver.sexpr(), Goal.simplify(), ArithRef.sort(), Solver.statistics(), Store(), ToReal(), Goal.translate(), AstVector.translate(), tree_interpolant(), Update(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().
02742 02743 def Int(name, ctx=None): 02744 """Return an integer constant named `name`. If `ctx=None`, then the global context is used. 02745 02746 >>> x = Int('x') 02747 >>> is_int(x) 02748 True 02749 >>> is_int(x + 1) 02750 True 02751 """ 02752 ctx = _get_ctx(ctx) 02753 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
| def z3py.Interpolant | ( | a, | |
ctx = None |
|||
| ) |
Create an interpolation operator.
The argument is an interpolation pattern (see tree_interpolant).
>>> x = Int('x')
>>> print Interpolant(x>0)
interp(x > 0)
Definition at line 7517 of file z3py.py.
Referenced by binary_interpolant(), and tree_interpolant().
07517 07518 def Interpolant(a,ctx=None): 07519 """Create an interpolation operator. 07520 07521 The argument is an interpolation pattern (see tree_interpolant). 07522 07523 >>> x = Int('x') 07524 >>> print Interpolant(x>0) 07525 interp(x > 0) 07526 """ 07527 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx)) 07528 s = BoolSort(ctx) 07529 a = s.cast(a) 07530 return BoolRef(Z3_mk_interpolant(ctx.ref(), a.as_ast()), ctx)
| def z3py.Ints | ( | names, | |
ctx = None |
|||
| ) |
Return a tuple of Integer constants.
>>> x, y, z = Ints('x y z')
>>> Sum(x, y, z)
x + y + z
Definition at line 2754 of file z3py.py.
Referenced by ArithRef.__ge__(), Goal.__getitem__(), ArithRef.__gt__(), ArithRef.__le__(), Goal.__len__(), ArithRef.__lt__(), Goal.depth(), Goal.get(), Goal.inconsistent(), is_add(), is_div(), is_ge(), is_gt(), is_idiv(), is_le(), is_lt(), is_mod(), is_mul(), is_sub(), Goal.prec(), Goal.size(), Store(), Solver.unsat_core(), and Update().
02754 02755 def Ints(names, ctx=None): 02756 """Return a tuple of Integer constants. 02757 02758 >>> x, y, z = Ints('x y z') 02759 >>> Sum(x, y, z) 02760 x + y + z 02761 """ 02762 ctx = _get_ctx(ctx) 02763 if isinstance(names, str): 02764 names = names.split(" ") 02765 return [Int(name, ctx) for name in names]
| def z3py.IntSort | ( | ctx = None | ) |
Return the interger sort in the given context. If `ctx=None`, then the global context is used.
>>> IntSort()
Int
>>> x = Const('x', IntSort())
>>> is_int(x)
True
>>> x.sort() == IntSort()
True
>>> x.sort() == BoolSort()
False
Definition at line 2639 of file z3py.py.
Referenced by ArrayRef.__getitem__(), ModelRef.__getitem__(), ModelRef.__len__(), DatatypeSortRef.accessor(), FuncEntry.arg_value(), FuncInterp.arity(), Array(), ArraySort(), FuncEntry.as_list(), FuncInterp.as_list(), QuantifierRef.body(), ArithSortRef.cast(), QuantifierRef.children(), DatatypeSortRef.constructor(), Sort.create(), Datatype.create(), CreateDatatypes(), Datatype.declare(), ModelRef.decls(), Default(), ArraySortRef.domain(), ArrayRef.domain(), FuncInterp.else_value(), FuncInterp.entry(), Exists(), ForAll(), FreshInt(), ModelRef.get_interp(), get_map_func(), Context.getIntSort(), Int(), is_arith_sort(), is_array(), is_bv_sort(), is_const_array(), is_default(), QuantifierRef.is_forall(), is_fp_sort(), is_K(), is_map(), is_pattern(), is_quantifier(), is_select(), is_store(), K(), Map(), Context.mkIntSort(), Context.MkIntSort(), MultiPattern(), FuncEntry.num_args(), DatatypeSortRef.num_constructors(), FuncInterp.num_entries(), QuantifierRef.num_patterns(), QuantifierRef.num_vars(), QuantifierRef.pattern(), ArraySortRef.range(), ArrayRef.range(), DatatypeSortRef.recognizer(), Select(), ArrayRef.sort(), Store(), Update(), FuncEntry.value(), QuantifierRef.var_name(), QuantifierRef.var_sort(), and QuantifierRef.weight().
02639 02640 def IntSort(ctx=None): 02641 """Return the interger sort in the given context. If `ctx=None`, then the global context is used. 02642 02643 >>> IntSort() 02644 Int 02645 >>> x = Const('x', IntSort()) 02646 >>> is_int(x) 02647 True 02648 >>> x.sort() == IntSort() 02649 True 02650 >>> x.sort() == BoolSort() 02651 False 02652 """ 02653 ctx = _get_ctx(ctx) 02654 return ArithSortRef(Z3_mk_int_sort(ctx.ref()), ctx)
| def z3py.IntVal | ( | val, | |
ctx = None |
|||
| ) |
Return a Z3 integer value. If `ctx=None`, then the global context is used.
>>> IntVal(1)
1
>>> IntVal("100")
100
Definition at line 2686 of file z3py.py.
Referenced by AstMap.__len__(), ArithRef.__mod__(), ArithRef.__pow__(), ArithRef.__rpow__(), AstMap.__setitem__(), IntNumRef.as_long(), IntNumRef.as_string(), is_arith(), is_int(), is_int_value(), is_rational_value(), AstMap.keys(), and AstMap.reset().
02686 02687 def IntVal(val, ctx=None): 02688 """Return a Z3 integer value. If `ctx=None`, then the global context is used. 02689 02690 >>> IntVal(1) 02691 1 02692 >>> IntVal("100") 02693 100 02694 """ 02695 ctx = _get_ctx(ctx) 02696 return IntNumRef(Z3_mk_numeral(ctx.ref(), _to_int_str(val), IntSort(ctx).ast), ctx)
| def z3py.IntVector | ( | prefix, | |
| sz, | |||
ctx = None |
|||
| ) |
Return a list of integer constants of size `sz`.
>>> X = IntVector('x', 3)
>>> X
[x__0, x__1, x__2]
>>> Sum(X)
x__0 + x__1 + x__2
| def z3py.is_add | ( | a | ) |
Return `True` if `a` is an expression of the form b + c.
>>> x, y = Ints('x y')
>>> is_add(x + y)
True
>>> is_add(x - y)
False
| def z3py.is_algebraic_value | ( | a | ) |
Return `True` if `a` is an algerbraic value of sort Real.
>>> is_algebraic_value(RealVal("3/5"))
False
>>> n = simplify(Sqrt(2))
>>> n
1.4142135623?
>>> is_algebraic_value(n)
True
Definition at line 2330 of file z3py.py.
02330 02331 def is_algebraic_value(a): 02332 """Return `True` if `a` is an algerbraic value of sort Real. 02333 02334 >>> is_algebraic_value(RealVal("3/5")) 02335 False 02336 >>> n = simplify(Sqrt(2)) 02337 >>> n 02338 1.4142135623? 02339 >>> is_algebraic_value(n) 02340 True 02341 """ 02342 return is_arith(a) and a.is_real() and _is_algebraic(a.ctx, a.as_ast())
| def z3py.is_and | ( | a | ) |
Return `True` if `a` is a Z3 and expression.
>>> p, q = Bools('p q')
>>> is_and(And(p, q))
True
>>> is_and(Or(p, q))
False
| def z3py.is_app | ( | a | ) |
Return `True` if `a` is a Z3 function application.
Note that, constants are function applications with 0 arguments.
>>> a = Int('a')
>>> is_app(a)
True
>>> is_app(a + 1)
True
>>> is_app(IntSort())
False
>>> is_app(1)
False
>>> is_app(IntVal(1))
True
>>> x = Int('x')
>>> is_app(ForAll(x, x >= 0))
False
Definition at line 981 of file z3py.py.
Referenced by ExprRef.arg(), ExprRef.children(), ExprRef.decl(), is_app_of(), is_const(), and ExprRef.num_args().
00981 00982 def is_app(a): 00983 """Return `True` if `a` is a Z3 function application. 00984 00985 Note that, constants are function applications with 0 arguments. 00986 00987 >>> a = Int('a') 00988 >>> is_app(a) 00989 True 00990 >>> is_app(a + 1) 00991 True 00992 >>> is_app(IntSort()) 00993 False 00994 >>> is_app(1) 00995 False 00996 >>> is_app(IntVal(1)) 00997 True 00998 >>> x = Int('x') 00999 >>> is_app(ForAll(x, x >= 0)) 01000 False 01001 """ 01002 if not isinstance(a, ExprRef): 01003 return False 01004 k = _ast_kind(a.ctx, a) 01005 return k == Z3_NUMERAL_AST or k == Z3_APP_AST
| def z3py.is_app_of | ( | a, | |
| k | |||
| ) |
Return `True` if `a` is an application of the given kind `k`.
>>> x = Int('x')
>>> n = x + 1
>>> is_app_of(n, Z3_OP_ADD)
True
>>> is_app_of(n, Z3_OP_MUL)
False
Definition at line 1080 of file z3py.py.
Referenced by is_add(), is_and(), is_distinct(), is_eq(), is_false(), is_not(), is_or(), and is_true().
01080 01081 def is_app_of(a, k): 01082 """Return `True` if `a` is an application of the given kind `k`. 01083 01084 >>> x = Int('x') 01085 >>> n = x + 1 01086 >>> is_app_of(n, Z3_OP_ADD) 01087 True 01088 >>> is_app_of(n, Z3_OP_MUL) 01089 False 01090 """ 01091 return is_app(a) and a.decl().kind() == k
| def z3py.is_arith | ( | a | ) |
Return `True` if `a` is an arithmetical expression.
>>> x = Int('x')
>>> is_arith(x)
True
>>> is_arith(x + 1)
True
>>> is_arith(1)
False
>>> is_arith(IntVal(1))
True
>>> y = Real('y')
>>> is_arith(y)
True
>>> is_arith(y + 1)
True
Definition at line 2224 of file z3py.py.
Referenced by is_algebraic_value().
02224 02225 def is_arith(a): 02226 """Return `True` if `a` is an arithmetical expression. 02227 02228 >>> x = Int('x') 02229 >>> is_arith(x) 02230 True 02231 >>> is_arith(x + 1) 02232 True 02233 >>> is_arith(1) 02234 False 02235 >>> is_arith(IntVal(1)) 02236 True 02237 >>> y = Real('y') 02238 >>> is_arith(y) 02239 True 02240 >>> is_arith(y + 1) 02241 True 02242 """ 02243 return isinstance(a, ArithRef)
| def z3py.is_arith_sort | ( | s | ) |
Return `True` if s is an arithmetical sort (type).
>>> is_arith_sort(IntSort())
True
>>> is_arith_sort(RealSort())
True
>>> is_arith_sort(BoolSort())
False
>>> n = Int('x') + 1
>>> is_arith_sort(n.sort())
True
Definition at line 1927 of file z3py.py.
01927 01928 def is_arith_sort(s): 01929 """Return `True` if s is an arithmetical sort (type). 01930 01931 >>> is_arith_sort(IntSort()) 01932 True 01933 >>> is_arith_sort(RealSort()) 01934 True 01935 >>> is_arith_sort(BoolSort()) 01936 False 01937 >>> n = Int('x') + 1 01938 >>> is_arith_sort(n.sort()) 01939 True 01940 """ 01941 return isinstance(s, ArithSortRef)
| def z3py.is_array | ( | a | ) |
Return `True` if `a` is a Z3 array expression.
>>> a = Array('a', IntSort(), IntSort())
>>> is_array(a)
True
>>> is_array(Store(a, 0, 1))
True
>>> is_array(a[0])
False
Definition at line 3927 of file z3py.py.
Referenced by Default().
03927 03928 def is_array(a): 03929 """Return `True` if `a` is a Z3 array expression. 03930 03931 >>> a = Array('a', IntSort(), IntSort()) 03932 >>> is_array(a) 03933 True 03934 >>> is_array(Store(a, 0, 1)) 03935 True 03936 >>> is_array(a[0]) 03937 False 03938 """ 03939 return isinstance(a, ArrayRef)
| def z3py.is_as_array | ( | n | ) |
Return true if n is a Z3 expression of the form (_ as-array f).
Definition at line 5589 of file z3py.py.
Referenced by get_as_array_func().
05589 05590 def is_as_array(n): 05591 """Return true if n is a Z3 expression of the form (_ as-array f).""" 05592 return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
| def z3py.is_ast | ( | a | ) |
Return `True` if `a` is an AST node.
>>> is_ast(10)
False
>>> is_ast(IntVal(10))
True
>>> is_ast(Int('x'))
True
>>> is_ast(BoolSort())
True
>>> is_ast(Function('f', IntSort(), IntSort()))
True
>>> is_ast("x")
False
>>> is_ast(Solver())
False
Definition at line 351 of file z3py.py.
Referenced by AstRef.eq(), and eq().
00351 00352 def is_ast(a): 00353 """Return `True` if `a` is an AST node. 00354 00355 >>> is_ast(10) 00356 False 00357 >>> is_ast(IntVal(10)) 00358 True 00359 >>> is_ast(Int('x')) 00360 True 00361 >>> is_ast(BoolSort()) 00362 True 00363 >>> is_ast(Function('f', IntSort(), IntSort())) 00364 True 00365 >>> is_ast("x") 00366 False 00367 >>> is_ast(Solver()) 00368 False 00369 """ 00370 return isinstance(a, AstRef)
| def z3py.is_bool | ( | a | ) |
Return `True` if `a` is a Z3 Boolean expression.
>>> p = Bool('p')
>>> is_bool(p)
True
>>> q = Bool('q')
>>> is_bool(And(p, q))
True
>>> x = Real('x')
>>> is_bool(x)
False
>>> is_bool(x == 0)
True
Definition at line 1246 of file z3py.py.
Referenced by BoolSort(), and prove().
01246 01247 def is_bool(a): 01248 """Return `True` if `a` is a Z3 Boolean expression. 01249 01250 >>> p = Bool('p') 01251 >>> is_bool(p) 01252 True 01253 >>> q = Bool('q') 01254 >>> is_bool(And(p, q)) 01255 True 01256 >>> x = Real('x') 01257 >>> is_bool(x) 01258 False 01259 >>> is_bool(x == 0) 01260 True 01261 """ 01262 return isinstance(a, BoolRef)
| def z3py.is_bv | ( | a | ) |
Return `True` if `a` is a Z3 bit-vector expression.
>>> b = BitVec('b', 32)
>>> is_bv(b)
True
>>> is_bv(b + 10)
True
>>> is_bv(Int('x'))
False
Definition at line 3415 of file z3py.py.
Referenced by BitVec(), BV2Int(), BVRedAnd(), BVRedOr(), Concat(), Extract(), fpFP(), fpToFP(), fpToFPUnsigned(), fpToIEEEBV(), fpToSBV(), fpToUBV(), Product(), and Sum().
| def z3py.is_bv_sort | ( | s | ) |
Return True if `s` is a Z3 bit-vector sort. >>> is_bv_sort(BitVecSort(32)) True >>> is_bv_sort(IntSort()) False
Definition at line 2954 of file z3py.py.
Referenced by BitVecVal(), fpToSBV(), and fpToUBV().
02954 02955 def is_bv_sort(s): 02956 """Return True if `s` is a Z3 bit-vector sort. 02957 02958 >>> is_bv_sort(BitVecSort(32)) 02959 True 02960 >>> is_bv_sort(IntSort()) 02961 False 02962 """ 02963 return isinstance(s, BitVecSortRef)
| def z3py.is_bv_value | ( | a | ) |
Return `True` if `a` is a Z3 bit-vector numeral value.
>>> b = BitVec('b', 32)
>>> is_bv_value(b)
False
>>> b = BitVecVal(10, 32)
>>> b
10
>>> is_bv_value(b)
True
Definition at line 3428 of file z3py.py.
03428 03429 def is_bv_value(a): 03430 """Return `True` if `a` is a Z3 bit-vector numeral value. 03431 03432 >>> b = BitVec('b', 32) 03433 >>> is_bv_value(b) 03434 False 03435 >>> b = BitVecVal(10, 32) 03436 >>> b 03437 10 03438 >>> is_bv_value(b) 03439 True 03440 """ 03441 return is_bv(a) and _is_numeral(a.ctx, a.as_ast())
| def z3py.is_const | ( | a | ) |
Return `True` if `a` is Z3 constant/variable expression.
>>> a = Int('a')
>>> is_const(a)
True
>>> is_const(a + 1)
False
>>> is_const(1)
False
>>> is_const(IntVal(1))
True
>>> x = Int('x')
>>> is_const(ForAll(x, x >= 0))
False
Definition at line 1006 of file z3py.py.
Referenced by prove().
01006 01007 def is_const(a): 01008 """Return `True` if `a` is Z3 constant/variable expression. 01009 01010 >>> a = Int('a') 01011 >>> is_const(a) 01012 True 01013 >>> is_const(a + 1) 01014 False 01015 >>> is_const(1) 01016 False 01017 >>> is_const(IntVal(1)) 01018 True 01019 >>> x = Int('x') 01020 >>> is_const(ForAll(x, x >= 0)) 01021 False 01022 """ 01023 return is_app(a) and a.num_args() == 0
| def z3py.is_const_array | ( | a | ) |
Return `True` if `a` is a Z3 constant array.
>>> a = K(IntSort(), 10)
>>> is_const_array(a)
True
>>> a = Array('a', IntSort(), IntSort())
>>> is_const_array(a)
False
Definition at line 3940 of file z3py.py.
03940 03941 def is_const_array(a): 03942 """Return `True` if `a` is a Z3 constant array. 03943 03944 >>> a = K(IntSort(), 10) 03945 >>> is_const_array(a) 03946 True 03947 >>> a = Array('a', IntSort(), IntSort()) 03948 >>> is_const_array(a) 03949 False 03950 """ 03951 return is_app_of(a, Z3_OP_CONST_ARRAY)
| def z3py.is_default | ( | a | ) |
Return `True` if `a` is a Z3 default array expression. >>> d = Default(K(IntSort(), 10)) >>> is_default(d) True
Definition at line 3979 of file z3py.py.
03979 03980 def is_default(a): 03981 """Return `True` if `a` is a Z3 default array expression. 03982 >>> d = Default(K(IntSort(), 10)) 03983 >>> is_default(d) 03984 True 03985 """ 03986 return is_app_of(a, Z3_OP_ARRAY_DEFAULT)
| def z3py.is_distinct | ( | a | ) |
Return `True` if `a` is a Z3 distinct expression.
>>> x, y, z = Ints('x y z')
>>> is_distinct(x == y)
False
>>> is_distinct(Distinct(x, y, z))
True
Definition at line 1335 of file z3py.py.
01335 01336 def is_distinct(a): 01337 """Return `True` if `a` is a Z3 distinct expression. 01338 01339 >>> x, y, z = Ints('x y z') 01340 >>> is_distinct(x == y) 01341 False 01342 >>> is_distinct(Distinct(x, y, z)) 01343 True 01344 """ 01345 return is_app_of(a, Z3_OP_DISTINCT)
| def z3py.is_div | ( | a | ) |
Return `True` if `a` is an expression of the form b / c.
>>> x, y = Reals('x y')
>>> is_div(x / y)
True
>>> is_div(x + y)
False
>>> x, y = Ints('x y')
>>> is_div(x / y)
False
>>> is_idiv(x / y)
True
Definition at line 2376 of file z3py.py.
02376 02377 def is_div(a): 02378 """Return `True` if `a` is an expression of the form b / c. 02379 02380 >>> x, y = Reals('x y') 02381 >>> is_div(x / y) 02382 True 02383 >>> is_div(x + y) 02384 False 02385 >>> x, y = Ints('x y') 02386 >>> is_div(x / y) 02387 False 02388 >>> is_idiv(x / y) 02389 True 02390 """ 02391 return is_app_of(a, Z3_OP_DIV)
| def z3py.is_eq | ( | a | ) |
Return `True` if `a` is a Z3 equality expression.
>>> x, y = Ints('x y')
>>> is_eq(x == y)
True
| def z3py.is_expr | ( | a | ) |
Return `True` if `a` is a Z3 expression.
>>> a = Int('a')
>>> is_expr(a)
True
>>> is_expr(a + 1)
True
>>> is_expr(IntSort())
False
>>> is_expr(1)
False
>>> is_expr(IntVal(1))
True
>>> x = Int('x')
>>> is_expr(ForAll(x, x >= 0))
True
Definition at line 961 of file z3py.py.
Referenced by SortRef.cast(), BoolSortRef.cast(), Cbrt(), ExprRef.children(), fpAbs(), fpNeg(), fpRoundToIntegral(), fpSqrt(), is_var(), simplify(), substitute(), and substitute_vars().
00961 00962 def is_expr(a): 00963 """Return `True` if `a` is a Z3 expression. 00964 00965 >>> a = Int('a') 00966 >>> is_expr(a) 00967 True 00968 >>> is_expr(a + 1) 00969 True 00970 >>> is_expr(IntSort()) 00971 False 00972 >>> is_expr(1) 00973 False 00974 >>> is_expr(IntVal(1)) 00975 True 00976 >>> x = Int('x') 00977 >>> is_expr(ForAll(x, x >= 0)) 00978 True 00979 """ 00980 return isinstance(a, ExprRef)
| def z3py.is_false | ( | a | ) |
| def z3py.is_fp | ( | a | ) |
Return `True` if `a` is a Z3 floating-point expression.
>>> b = FP('b', FPSort(8, 24))
>>> is_fp(b)
True
>>> is_fp(b + 1.0)
True
>>> is_fp(Int('x'))
False
Definition at line 8092 of file z3py.py.
Referenced by FP(), fpAbs(), fpAdd(), fpDiv(), fpFMA(), fpIsInfinite(), fpIsNaN(), fpIsNegative(), fpIsNormal(), fpIsPositive(), fpIsSubnormal(), fpIsZero(), fpMax(), fpMin(), fpMul(), fpNeg(), fpRem(), fpRoundToIntegral(), fpSqrt(), fpSub(), fpToFP(), fpToIEEEBV(), fpToReal(), fpToSBV(), and fpToUBV().
| def z3py.is_fp_sort | ( | s | ) |
Return True if `s` is a Z3 floating-point sort. >>> is_fp_sort(FPSort(8, 24)) True >>> is_fp_sort(IntSort()) False
Definition at line 7778 of file z3py.py.
Referenced by fpToFP(), fpToFPUnsigned(), and FPVal().
07778 07779 def is_fp_sort(s): 07780 """Return True if `s` is a Z3 floating-point sort. 07781 07782 >>> is_fp_sort(FPSort(8, 24)) 07783 True 07784 >>> is_fp_sort(IntSort()) 07785 False 07786 """ 07787 return isinstance(s, FPSortRef)
| def z3py.is_fp_value | ( | a | ) |
Return `True` if `a` is a Z3 floating-point numeral value.
>>> b = FP('b', FPSort(8, 24))
>>> is_fp_value(b)
False
>>> b = FPVal(1.0, FPSort(8, 24))
>>> b
1
>>> is_fp_value(b)
True
Definition at line 8105 of file z3py.py.
08105 08106 def is_fp_value(a): 08107 """Return `True` if `a` is a Z3 floating-point numeral value. 08108 08109 >>> b = FP('b', FPSort(8, 24)) 08110 >>> is_fp_value(b) 08111 False 08112 >>> b = FPVal(1.0, FPSort(8, 24)) 08113 >>> b 08114 1 08115 >>> is_fp_value(b) 08116 True 08117 """ 08118 return is_fp(a) and _is_numeral(a.ctx, a.ast)
| def z3py.is_fprm | ( | a | ) |
Return `True` if `a` is a Z3 floating-point rounding mode expression. >>> rm = RNE() >>> is_fprm(rm) True >>> rm = 1.0 >>> is_fprm(rm) False
Definition at line 7996 of file z3py.py.
Referenced by fpAdd(), fpDiv(), fpFMA(), fpMul(), fpRoundToIntegral(), fpSqrt(), fpSub(), fpToFP(), fpToFPUnsigned(), fpToSBV(), and fpToUBV().
| def z3py.is_fprm_sort | ( | s | ) |
Return True if `s` is a Z3 floating-point rounding mode sort. >>> is_fprm_sort(FPSort(8, 24)) False >>> is_fprm_sort(RNE().sort()) True
Definition at line 7788 of file z3py.py.
07788 07789 def is_fprm_sort(s): 07790 """Return True if `s` is a Z3 floating-point rounding mode sort. 07791 07792 >>> is_fprm_sort(FPSort(8, 24)) 07793 False 07794 >>> is_fprm_sort(RNE().sort()) 07795 True 07796 """ 07797 return isinstance(s, FPRMSortRef)
| def z3py.is_fprm_value | ( | a | ) |
Return `True` if `a` is a Z3 floating-point rounding mode numeral value.
Definition at line 8008 of file z3py.py.
08008 08009 def is_fprm_value(a): 08010 """Return `True` if `a` is a Z3 floating-point rounding mode numeral value.""" 08011 return is_fprm(a) and _is_numeral(a.ctx, a.ast)
| def z3py.is_func_decl | ( | a | ) |
Return `True` if `a` is a Z3 function declaration.
>>> f = Function('f', IntSort(), IntSort())
>>> is_func_decl(f)
True
>>> x = Real('x')
>>> is_func_decl(x)
False
Definition at line 693 of file z3py.py.
Referenced by prove().
00693 00694 def is_func_decl(a): 00695 """Return `True` if `a` is a Z3 function declaration. 00696 00697 >>> f = Function('f', IntSort(), IntSort()) 00698 >>> is_func_decl(f) 00699 True 00700 >>> x = Real('x') 00701 >>> is_func_decl(x) 00702 False 00703 """ 00704 return isinstance(a, FuncDeclRef)
| def z3py.is_ge | ( | a | ) |
Return `True` if `a` is an expression of the form b >= c.
>>> x, y = Ints('x y')
>>> is_ge(x >= y)
True
>>> is_ge(x == y)
False
| def z3py.is_gt | ( | a | ) |
Return `True` if `a` is an expression of the form b > c.
>>> x, y = Ints('x y')
>>> is_gt(x > y)
True
>>> is_gt(x == y)
False
| def z3py.is_idiv | ( | a | ) |
| def z3py.is_int | ( | a | ) |
Return `True` if `a` is an integer expression.
>>> x = Int('x')
>>> is_int(x + 1)
True
>>> is_int(1)
False
>>> is_int(IntVal(1))
True
>>> y = Real('y')
>>> is_int(y)
False
>>> is_int(y + 1)
False
Definition at line 2244 of file z3py.py.
Referenced by Int(), IntSort(), and RealSort().
02244 02245 def is_int(a): 02246 """Return `True` if `a` is an integer expression. 02247 02248 >>> x = Int('x') 02249 >>> is_int(x + 1) 02250 True 02251 >>> is_int(1) 02252 False 02253 >>> is_int(IntVal(1)) 02254 True 02255 >>> y = Real('y') 02256 >>> is_int(y) 02257 False 02258 >>> is_int(y + 1) 02259 False 02260 """ 02261 return is_arith(a) and a.is_int()
| def z3py.is_int_value | ( | a | ) |
Return `True` if `a` is an integer value of sort Int.
>>> is_int_value(IntVal(1))
True
>>> is_int_value(1)
False
>>> is_int_value(Int('x'))
False
>>> n = Int('x') + 1
>>> n
x + 1
>>> n.arg(1)
1
>>> is_int_value(n.arg(1))
True
>>> is_int_value(RealVal("1/3"))
False
>>> is_int_value(RealVal(1))
False
Definition at line 2286 of file z3py.py.
02286 02287 def is_int_value(a): 02288 """Return `True` if `a` is an integer value of sort Int. 02289 02290 >>> is_int_value(IntVal(1)) 02291 True 02292 >>> is_int_value(1) 02293 False 02294 >>> is_int_value(Int('x')) 02295 False 02296 >>> n = Int('x') + 1 02297 >>> n 02298 x + 1 02299 >>> n.arg(1) 02300 1 02301 >>> is_int_value(n.arg(1)) 02302 True 02303 >>> is_int_value(RealVal("1/3")) 02304 False 02305 >>> is_int_value(RealVal(1)) 02306 False 02307 """ 02308 return is_arith(a) and a.is_int() and _is_numeral(a.ctx, a.as_ast())
| def z3py.is_is_int | ( | a | ) |
Return `True` if `a` is an expression of the form IsInt(b).
>>> x = Real('x')
>>> is_is_int(IsInt(x))
True
>>> is_is_int(x)
False
| def z3py.is_K | ( | a | ) |
Return `True` if `a` is a Z3 constant array.
>>> a = K(IntSort(), 10)
>>> is_K(a)
True
>>> a = Array('a', IntSort(), IntSort())
>>> is_K(a)
False
| def z3py.is_le | ( | a | ) |
Return `True` if `a` is an expression of the form b <= c.
>>> x, y = Ints('x y')
>>> is_le(x <= y)
True
>>> is_le(x < y)
False
| def z3py.is_lt | ( | a | ) |
Return `True` if `a` is an expression of the form b < c.
>>> x, y = Ints('x y')
>>> is_lt(x < y)
True
>>> is_lt(x == y)
False
| def z3py.is_map | ( | a | ) |
Return `True` if `a` is a Z3 map array expression.
>>> f = Function('f', IntSort(), IntSort())
>>> b = Array('b', IntSort(), IntSort())
>>> a = Map(f, b)
>>> a
Map(f, b)
>>> is_map(a)
True
>>> is_map(b)
False
Definition at line 3964 of file z3py.py.
Referenced by get_map_func().
03964 03965 def is_map(a): 03966 """Return `True` if `a` is a Z3 map array expression. 03967 03968 >>> f = Function('f', IntSort(), IntSort()) 03969 >>> b = Array('b', IntSort(), IntSort()) 03970 >>> a = Map(f, b) 03971 >>> a 03972 Map(f, b) 03973 >>> is_map(a) 03974 True 03975 >>> is_map(b) 03976 False 03977 """ 03978 return is_app_of(a, Z3_OP_ARRAY_MAP)
| def z3py.is_mod | ( | a | ) |
Return `True` if `a` is an expression of the form b % c.
>>> x, y = Ints('x y')
>>> is_mod(x % y)
True
>>> is_mod(x + y)
False
| def z3py.is_mul | ( | a | ) |
Return `True` if `a` is an expression of the form b * c.
>>> x, y = Ints('x y')
>>> is_mul(x * y)
True
>>> is_mul(x - y)
False
| def z3py.is_not | ( | a | ) |
Return `True` if `a` is a Z3 not expression.
>>> p = Bool('p')
>>> is_not(p)
False
>>> is_not(Not(p))
True
| def z3py.is_or | ( | a | ) |
Return `True` if `a` is a Z3 or expression.
>>> p, q = Bools('p q')
>>> is_or(Or(p, q))
True
>>> is_or(And(p, q))
False
| def z3py.is_pattern | ( | a | ) |
Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation.
See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ])
>>> q
ForAll(x, f(x) == 0)
>>> q.num_patterns()
1
>>> is_pattern(q.pattern(0))
True
>>> q.pattern(0)
f(Var(0))
Definition at line 1566 of file z3py.py.
Referenced by MultiPattern().
01566 01567 def is_pattern(a): 01568 """Return `True` if `a` is a Z3 pattern (hint for quantifier instantiation. 01569 01570 See http://rise4fun.com/Z3Py/tutorial/advanced for more details. 01571 01572 >>> f = Function('f', IntSort(), IntSort()) 01573 >>> x = Int('x') 01574 >>> q = ForAll(x, f(x) == 0, patterns = [ f(x) ]) 01575 >>> q 01576 ForAll(x, f(x) == 0) 01577 >>> q.num_patterns() 01578 1 01579 >>> is_pattern(q.pattern(0)) 01580 True 01581 >>> q.pattern(0) 01582 f(Var(0)) 01583 """ 01584 return isinstance(a, PatternRef)
| def z3py.is_probe | ( | p | ) |
| def z3py.is_quantifier | ( | a | ) |
Return `True` if `a` is a Z3 quantifier.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) == 0)
>>> is_quantifier(q)
True
>>> is_quantifier(f(x))
False
Definition at line 1769 of file z3py.py.
Referenced by Exists().
01769 01770 def is_quantifier(a): 01771 """Return `True` if `a` is a Z3 quantifier. 01772 01773 >>> f = Function('f', IntSort(), IntSort()) 01774 >>> x = Int('x') 01775 >>> q = ForAll(x, f(x) == 0) 01776 >>> is_quantifier(q) 01777 True 01778 >>> is_quantifier(f(x)) 01779 False 01780 """ 01781 return isinstance(a, QuantifierRef)
| def z3py.is_rational_value | ( | a | ) |
Return `True` if `a` is rational value of sort Real.
>>> is_rational_value(RealVal(1))
True
>>> is_rational_value(RealVal("3/5"))
True
>>> is_rational_value(IntVal(1))
False
>>> is_rational_value(1)
False
>>> n = Real('x') + 1
>>> n.arg(1)
1
>>> is_rational_value(n.arg(1))
True
>>> is_rational_value(Real('x'))
False
Definition at line 2309 of file z3py.py.
Referenced by RatNumRef.denominator(), and RatNumRef.numerator().
02309 02310 def is_rational_value(a): 02311 """Return `True` if `a` is rational value of sort Real. 02312 02313 >>> is_rational_value(RealVal(1)) 02314 True 02315 >>> is_rational_value(RealVal("3/5")) 02316 True 02317 >>> is_rational_value(IntVal(1)) 02318 False 02319 >>> is_rational_value(1) 02320 False 02321 >>> n = Real('x') + 1 02322 >>> n.arg(1) 02323 1 02324 >>> is_rational_value(n.arg(1)) 02325 True 02326 >>> is_rational_value(Real('x')) 02327 False 02328 """ 02329 return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
| def z3py.is_real | ( | a | ) |
Return `True` if `a` is a real expression.
>>> x = Int('x')
>>> is_real(x + 1)
False
>>> y = Real('y')
>>> is_real(y)
True
>>> is_real(y + 1)
True
>>> is_real(1)
False
>>> is_real(RealVal(1))
True
Definition at line 2262 of file z3py.py.
Referenced by fpToFP(), fpToReal(), Real(), and RealSort().
02262 02263 def is_real(a): 02264 """Return `True` if `a` is a real expression. 02265 02266 >>> x = Int('x') 02267 >>> is_real(x + 1) 02268 False 02269 >>> y = Real('y') 02270 >>> is_real(y) 02271 True 02272 >>> is_real(y + 1) 02273 True 02274 >>> is_real(1) 02275 False 02276 >>> is_real(RealVal(1)) 02277 True 02278 """ 02279 return is_arith(a) and a.is_real()
| def z3py.is_select | ( | a | ) |
Return `True` if `a` is a Z3 array select application.
>>> a = Array('a', IntSort(), IntSort())
>>> is_select(a)
False
>>> i = Int('i')
>>> is_select(a[i])
True
| def z3py.is_sort | ( | s | ) |
Return `True` if `s` is a Z3 sort.
>>> is_sort(IntSort())
True
>>> is_sort(Int('x'))
False
>>> is_expr(Int('x'))
True
Definition at line 530 of file z3py.py.
Referenced by ArraySort(), CreateDatatypes(), Function(), prove(), and Var().
| def z3py.is_store | ( | a | ) |
Return `True` if `a` is a Z3 array store application.
>>> a = Array('a', IntSort(), IntSort())
>>> is_store(a)
False
>>> is_store(Store(a, 0, 1))
True
| def z3py.is_sub | ( | a | ) |
Return `True` if `a` is an expression of the form b - c.
>>> x, y = Ints('x y')
>>> is_sub(x - y)
True
>>> is_sub(x + y)
False
| def z3py.is_to_int | ( | a | ) |
Return `True` if `a` is an expression of the form ToInt(b).
>>> x = Real('x')
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> is_to_int(n)
True
>>> is_to_int(x)
False
| def z3py.is_to_real | ( | a | ) |
Return `True` if `a` is an expression of the form ToReal(b).
>>> x = Int('x')
>>> n = ToReal(x)
>>> n
ToReal(x)
>>> is_to_real(n)
True
>>> is_to_real(x)
False
Definition at line 2469 of file z3py.py.
02469 02470 def is_to_real(a): 02471 """Return `True` if `a` is an expression of the form ToReal(b). 02472 02473 >>> x = Int('x') 02474 >>> n = ToReal(x) 02475 >>> n 02476 ToReal(x) 02477 >>> is_to_real(n) 02478 True 02479 >>> is_to_real(x) 02480 False 02481 """ 02482 return is_app_of(a, Z3_OP_TO_REAL)
| def z3py.is_true | ( | a | ) |
Return `True` if `a` is the Z3 true expression.
>>> p = Bool('p')
>>> is_true(p)
False
>>> is_true(simplify(p == p))
True
>>> x = Real('x')
>>> is_true(x == 0)
False
>>> # True is a Python Boolean expression
>>> is_true(True)
False
Definition at line 1263 of file z3py.py.
Referenced by BoolVal().
01263 01264 def is_true(a): 01265 """Return `True` if `a` is the Z3 true expression. 01266 01267 >>> p = Bool('p') 01268 >>> is_true(p) 01269 False 01270 >>> is_true(simplify(p == p)) 01271 True 01272 >>> x = Real('x') 01273 >>> is_true(x == 0) 01274 False 01275 >>> # True is a Python Boolean expression 01276 >>> is_true(True) 01277 False 01278 """ 01279 return is_app_of(a, Z3_OP_TRUE)
| def z3py.is_var | ( | a | ) |
Return `True` if `a` is variable.
Z3 uses de-Bruijn indices for representing bound variables in
quantifiers.
>>> x = Int('x')
>>> is_var(x)
False
>>> is_const(x)
True
>>> f = Function('f', IntSort(), IntSort())
>>> # Z3 replaces x with bound variables when ForAll is executed.
>>> q = ForAll(x, f(x) == x)
>>> b = q.body()
>>> b
f(Var(0)) == Var(0)
>>> b.arg(1)
Var(0)
>>> is_var(b.arg(1))
True
Definition at line 1024 of file z3py.py.
Referenced by get_var_index().
01024 01025 def is_var(a): 01026 """Return `True` if `a` is variable. 01027 01028 Z3 uses de-Bruijn indices for representing bound variables in 01029 quantifiers. 01030 01031 >>> x = Int('x') 01032 >>> is_var(x) 01033 False 01034 >>> is_const(x) 01035 True 01036 >>> f = Function('f', IntSort(), IntSort()) 01037 >>> # Z3 replaces x with bound variables when ForAll is executed. 01038 >>> q = ForAll(x, f(x) == x) 01039 >>> b = q.body() 01040 >>> b 01041 f(Var(0)) == Var(0) 01042 >>> b.arg(1) 01043 Var(0) 01044 >>> is_var(b.arg(1)) 01045 True 01046 """ 01047 return is_expr(a) and _ast_kind(a.ctx, a) == Z3_VAR_AST
| def z3py.IsInt | ( | a | ) |
Return the Z3 predicate IsInt(a).
>>> x = Real('x')
>>> IsInt(x + "1/2")
IsInt(x + 1/2)
>>> solve(IsInt(x + "1/2"), x > 0, x < 1)
[x = 1/2]
>>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2")
no solution
Definition at line 2876 of file z3py.py.
Referenced by is_is_int().
02876 02877 def IsInt(a): 02878 """ Return the Z3 predicate IsInt(a). 02879 02880 >>> x = Real('x') 02881 >>> IsInt(x + "1/2") 02882 IsInt(x + 1/2) 02883 >>> solve(IsInt(x + "1/2"), x > 0, x < 1) 02884 [x = 1/2] 02885 >>> solve(IsInt(x + "1/2"), x > 0, x < 1, x != "1/2") 02886 no solution 02887 """ 02888 if __debug__: 02889 _z3_assert(a.is_real(), "Z3 real expression expected.") 02890 ctx = a.ctx 02891 return BoolRef(Z3_mk_is_int(ctx.ref(), a.as_ast()), ctx)
| def z3py.K | ( | dom, | |
| v | |||
| ) |
Return a Z3 constant array expression.
>>> a = K(IntSort(), 10)
>>> a
K(Int, 10)
>>> a.sort()
Array(Int, Int)
>>> i = Int('i')
>>> a[i]
K(Int, 10)[i]
>>> simplify(a[i])
10
Definition at line 4122 of file z3py.py.
Referenced by Default(), is_const_array(), is_default(), and is_K().
04122 04123 def K(dom, v): 04124 """Return a Z3 constant array expression. 04125 04126 >>> a = K(IntSort(), 10) 04127 >>> a 04128 K(Int, 10) 04129 >>> a.sort() 04130 Array(Int, Int) 04131 >>> i = Int('i') 04132 >>> a[i] 04133 K(Int, 10)[i] 04134 >>> simplify(a[i]) 04135 10 04136 """ 04137 if __debug__: 04138 _z3_assert(is_sort(dom), "Z3 sort expected") 04139 ctx = dom.ctx 04140 if not is_expr(v): 04141 v = _py2expr(v, ctx) 04142 return ArrayRef(Z3_mk_const_array(ctx.ref(), dom.ast, v.as_ast()), ctx)
| def z3py.LShR | ( | a, | |
| b | |||
| ) |
Create the Z3 expression logical right shift.
Use the operator >> for the arithmetical right shift.
>>> x, y = BitVecs('x y', 32)
>>> LShR(x, y)
LShR(x, y)
>>> (x >> y).sexpr()
'(bvashr x y)'
>>> LShR(x, y).sexpr()
'(bvlshr x y)'
>>> BitVecVal(4, 3)
4
>>> BitVecVal(4, 3).as_signed_long()
-4
>>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
-2
>>> simplify(BitVecVal(4, 3) >> 1)
6
>>> simplify(LShR(BitVecVal(4, 3), 1))
2
>>> simplify(BitVecVal(2, 3) >> 1)
1
>>> simplify(LShR(BitVecVal(2, 3), 1))
1
Definition at line 3701 of file z3py.py.
Referenced by BitVecRef.__rlshift__(), BitVecRef.__rrshift__(), and BitVecRef.__rshift__().
03701 03702 def LShR(a, b): 03703 """Create the Z3 expression logical right shift. 03704 03705 Use the operator >> for the arithmetical right shift. 03706 03707 >>> x, y = BitVecs('x y', 32) 03708 >>> LShR(x, y) 03709 LShR(x, y) 03710 >>> (x >> y).sexpr() 03711 '(bvashr x y)' 03712 >>> LShR(x, y).sexpr() 03713 '(bvlshr x y)' 03714 >>> BitVecVal(4, 3) 03715 4 03716 >>> BitVecVal(4, 3).as_signed_long() 03717 -4 03718 >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long() 03719 -2 03720 >>> simplify(BitVecVal(4, 3) >> 1) 03721 6 03722 >>> simplify(LShR(BitVecVal(4, 3), 1)) 03723 2 03724 >>> simplify(BitVecVal(2, 3) >> 1) 03725 1 03726 >>> simplify(LShR(BitVecVal(2, 3), 1)) 03727 1 03728 """ 03729 _check_bv_args(a, b) 03730 a, b = _coerce_exprs(a, b) 03731 return BitVecRef(Z3_mk_bvlshr(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.main_ctx | ( | ) |
Return a reference to the global Z3 context.
>>> x = Real('x')
>>> x.ctx == main_ctx()
True
>>> c = Context()
>>> c == main_ctx()
False
>>> x2 = Real('x', c)
>>> x2.ctx == c
True
>>> eq(x, x2)
False
Definition at line 188 of file z3py.py.
Referenced by And(), help_simplify(), simplify_param_descrs(), and Goal.translate().
00188 00189 def main_ctx(): 00190 """Return a reference to the global Z3 context. 00191 00192 >>> x = Real('x') 00193 >>> x.ctx == main_ctx() 00194 True 00195 >>> c = Context() 00196 >>> c == main_ctx() 00197 False 00198 >>> x2 = Real('x', c) 00199 >>> x2.ctx == c 00200 True 00201 >>> eq(x, x2) 00202 False 00203 """ 00204 global _main_ctx 00205 if _main_ctx == None: 00206 _main_ctx = Context() 00207 return _main_ctx
| def z3py.Map | ( | f, | |
| args | |||
| ) |
Return a Z3 map array expression.
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> a1 = Array('a1', IntSort(), IntSort())
>>> a2 = Array('a2', IntSort(), IntSort())
>>> b = Map(f, a1, a2)
>>> b
Map(f, a1, a2)
>>> prove(b[0] == f(a1[0], a2[0]))
proved
Definition at line 4100 of file z3py.py.
Referenced by Context.Context(), get_map_func(), InterpolationContext.InterpolationContext(), and is_map().
04100 04101 def Map(f, *args): 04102 """Return a Z3 map array expression. 04103 04104 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 04105 >>> a1 = Array('a1', IntSort(), IntSort()) 04106 >>> a2 = Array('a2', IntSort(), IntSort()) 04107 >>> b = Map(f, a1, a2) 04108 >>> b 04109 Map(f, a1, a2) 04110 >>> prove(b[0] == f(a1[0], a2[0])) 04111 proved 04112 """ 04113 args = _get_args(args) 04114 if __debug__: 04115 _z3_assert(len(args) > 0, "At least one Z3 array expression expected") 04116 _z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration") 04117 _z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected") 04118 _z3_assert(len(args) == f.arity(), "Number of arguments mismatch") 04119 _args, sz = _to_ast_array(args) 04120 ctx = f.ctx 04121 return ArrayRef(Z3_mk_map(ctx.ref(), f.ast, sz, _args), ctx)
| def z3py.MultiPattern | ( | args | ) |
Create a Z3 multi-pattern using the given expressions `*args`
See http://rise4fun.com/Z3Py/tutorial/advanced for more details.
>>> f = Function('f', IntSort(), IntSort())
>>> g = Function('g', IntSort(), IntSort())
>>> x = Int('x')
>>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ])
>>> q
ForAll(x, f(x) != g(x))
>>> q.num_patterns()
1
>>> is_pattern(q.pattern(0))
True
>>> q.pattern(0)
MultiPattern(f(Var(0)), g(Var(0)))
Definition at line 1585 of file z3py.py.
01585 01586 def MultiPattern(*args): 01587 """Create a Z3 multi-pattern using the given expressions `*args` 01588 01589 See http://rise4fun.com/Z3Py/tutorial/advanced for more details. 01590 01591 >>> f = Function('f', IntSort(), IntSort()) 01592 >>> g = Function('g', IntSort(), IntSort()) 01593 >>> x = Int('x') 01594 >>> q = ForAll(x, f(x) != g(x), patterns = [ MultiPattern(f(x), g(x)) ]) 01595 >>> q 01596 ForAll(x, f(x) != g(x)) 01597 >>> q.num_patterns() 01598 1 01599 >>> is_pattern(q.pattern(0)) 01600 True 01601 >>> q.pattern(0) 01602 MultiPattern(f(Var(0)), g(Var(0))) 01603 """ 01604 if __debug__: 01605 _z3_assert(len(args) > 0, "At least one argument expected") 01606 _z3_assert(all([ is_expr(a) for a in args ]), "Z3 expressions expected") 01607 ctx = args[0].ctx 01608 args, sz = _to_ast_array(args) 01609 return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
| def z3py.Not | ( | a, | |
ctx = None |
|||
| ) |
Create a Z3 not expression or probe.
>>> p = Bool('p')
>>> Not(Not(p))
Not(Not(p))
>>> simplify(Not(Not(p)))
p
Definition at line 1464 of file z3py.py.
Referenced by binary_interpolant(), fpNEQ(), Implies(), prove(), sequence_interpolant(), tree_interpolant(), and Xor().
01464 01465 def Not(a, ctx=None): 01466 """Create a Z3 not expression or probe. 01467 01468 >>> p = Bool('p') 01469 >>> Not(Not(p)) 01470 Not(Not(p)) 01471 >>> simplify(Not(Not(p))) 01472 p 01473 """ 01474 ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx)) 01475 if is_probe(a): 01476 # Not is also used to build probes 01477 return Probe(Z3_probe_not(ctx.ref(), a.probe), ctx) 01478 else: 01479 s = BoolSort(ctx) 01480 a = s.cast(a) 01481 return BoolRef(Z3_mk_not(ctx.ref(), a.as_ast()), ctx)
| def z3py.open_log | ( | fname | ) |
Log interaction to a file. This function must be invoked immediately after init().
Definition at line 86 of file z3py.py.
00086 00087 def open_log(fname): 00088 """Log interaction to a file. This function must be invoked immediately after init(). """ 00089 Z3_open_log(fname)
| def z3py.Or | ( | args | ) |
Create a Z3 or-expression or or-probe.
>>> p, q, r = Bools('p q r')
>>> Or(p, q, r)
Or(p, q, r)
>>> P = BoolVector('p', 5)
>>> Or(P)
Or(p__0, p__1, p__2, p__3, p__4)
Definition at line 1519 of file z3py.py.
Referenced by ApplyResult.as_expr(), Bools(), and Implies().
01519 01520 def Or(*args): 01521 """Create a Z3 or-expression or or-probe. 01522 01523 >>> p, q, r = Bools('p q r') 01524 >>> Or(p, q, r) 01525 Or(p, q, r) 01526 >>> P = BoolVector('p', 5) 01527 >>> Or(P) 01528 Or(p__0, p__1, p__2, p__3, p__4) 01529 """ 01530 last_arg = None 01531 if len(args) > 0: 01532 last_arg = args[len(args)-1] 01533 if isinstance(last_arg, Context): 01534 ctx = args[len(args)-1] 01535 args = args[:len(args)-1] 01536 else: 01537 ctx = main_ctx() 01538 args = _get_args(args) 01539 ctx_args = _ctx_from_ast_arg_list(args, ctx) 01540 if __debug__: 01541 _z3_assert(ctx_args == None or ctx_args == ctx, "context mismatch") 01542 _z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression or probe") 01543 if _has_probe(args): 01544 return _probe_or(args, ctx) 01545 else: 01546 args = _coerce_expr_list(args, ctx) 01547 _args, sz = _to_ast_array(args) 01548 return BoolRef(Z3_mk_or(ctx.ref(), sz, _args), ctx)
| def z3py.OrElse | ( | ts, | |
| ks | |||
| ) |
Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail).
>>> x = Int('x')
>>> t = OrElse(Tactic('split-clause'), Tactic('skip'))
>>> # Tactic split-clause fails if there is no clause in the given goal.
>>> t(x == 0)
[[x == 0]]
>>> t(Or(x == 0, x == 1))
[[x == 0], [x == 1]]
Definition at line 6790 of file z3py.py.
06790 06791 def OrElse(*ts, **ks): 06792 """Return a tactic that applies the tactics in `*ts` until one of them succeeds (it doesn't fail). 06793 06794 >>> x = Int('x') 06795 >>> t = OrElse(Tactic('split-clause'), Tactic('skip')) 06796 >>> # Tactic split-clause fails if there is no clause in the given goal. 06797 >>> t(x == 0) 06798 [[x == 0]] 06799 >>> t(Or(x == 0, x == 1)) 06800 [[x == 0], [x == 1]] 06801 """ 06802 if __debug__: 06803 _z3_assert(len(ts) >= 2, "At least two arguments expected") 06804 ctx = ks.get('ctx', None) 06805 num = len(ts) 06806 r = ts[0] 06807 for i in range(num - 1): 06808 r = _or_else(r, ts[i+1], ctx) 06809 return r
| def z3py.ParAndThen | ( | t1, | |
| t2, | |||
ctx = None |
|||
| ) |
Alias for ParThen(t1, t2, ctx).
Definition at line 6842 of file z3py.py.
06842 06843 def ParAndThen(t1, t2, ctx=None): 06844 """Alias for ParThen(t1, t2, ctx).""" 06845 return ParThen(t1, t2, ctx)
| def z3py.ParOr | ( | ts, | |
| ks | |||
| ) |
Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail).
>>> x = Int('x')
>>> t = ParOr(Tactic('simplify'), Tactic('fail'))
>>> t(x + 1 == 2)
[[x == 1]]
Definition at line 6810 of file z3py.py.
06810 06811 def ParOr(*ts, **ks): 06812 """Return a tactic that applies the tactics in `*ts` in parallel until one of them succeeds (it doesn't fail). 06813 06814 >>> x = Int('x') 06815 >>> t = ParOr(Tactic('simplify'), Tactic('fail')) 06816 >>> t(x + 1 == 2) 06817 [[x == 1]] 06818 """ 06819 if __debug__: 06820 _z3_assert(len(ts) >= 2, "At least two arguments expected") 06821 ctx = _get_ctx(ks.get('ctx', None)) 06822 ts = [ _to_tactic(t, ctx) for t in ts ] 06823 sz = len(ts) 06824 _args = (TacticObj * sz)() 06825 for i in range(sz): 06826 _args[i] = ts[i].tactic 06827 return Tactic(Z3_tactic_par_or(ctx.ref(), sz, _args), ctx)
| def z3py.parse_smt2_file | ( | f, | |
sorts = {}, |
|||
decls = {}, |
|||
ctx = None |
|||
| ) |
Parse a file in SMT 2.0 format using the given sorts and decls. This function is similar to parse_smt2_string().
Definition at line 7507 of file z3py.py.
07507 07508 def parse_smt2_file(f, sorts={}, decls={}, ctx=None): 07509 """Parse a file in SMT 2.0 format using the given sorts and decls. 07510 07511 This function is similar to parse_smt2_string(). 07512 """ 07513 ctx = _get_ctx(ctx) 07514 ssz, snames, ssorts = _dict2sarray(sorts, ctx) 07515 dsz, dnames, ddecls = _dict2darray(decls, ctx) 07516 return _to_expr_ref(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
| def z3py.parse_smt2_string | ( | s, | |
sorts = {}, |
|||
decls = {}, |
|||
ctx = None |
|||
| ) |
Parse a string in SMT 2.0 format using the given sorts and decls.
The arguments sorts and decls are Python dictionaries used to initialize
the symbol table used for the SMT 2.0 parser.
>>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
And(x > 0, x < 10)
>>> x, y = Ints('x y')
>>> f = Function('f', IntSort(), IntSort())
>>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
x + f(y) > 0
>>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
a > 0
Definition at line 7487 of file z3py.py.
Referenced by parse_smt2_file().
07487 07488 def parse_smt2_string(s, sorts={}, decls={}, ctx=None): 07489 """Parse a string in SMT 2.0 format using the given sorts and decls. 07490 07491 The arguments sorts and decls are Python dictionaries used to initialize 07492 the symbol table used for the SMT 2.0 parser. 07493 07494 >>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))') 07495 And(x > 0, x < 10) 07496 >>> x, y = Ints('x y') 07497 >>> f = Function('f', IntSort(), IntSort()) 07498 >>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f}) 07499 x + f(y) > 0 07500 >>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() }) 07501 a > 0 07502 """ 07503 ctx = _get_ctx(ctx) 07504 ssz, snames, ssorts = _dict2sarray(sorts, ctx) 07505 dsz, dnames, ddecls = _dict2darray(decls, ctx) 07506 return _to_expr_ref(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
| def z3py.ParThen | ( | t1, | |
| t2, | |||
ctx = None |
|||
| ) |
Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel.
>>> x, y = Ints('x y')
>>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values'))
>>> t(And(Or(x == 1, x == 2), y == x + 1))
[[x == 1, y == 2], [x == 2, y == 3]]
Definition at line 6828 of file z3py.py.
Referenced by ParAndThen().
06828 06829 def ParThen(t1, t2, ctx=None): 06830 """Return a tactic that applies t1 and then t2 to every subgoal produced by t1. The subgoals are processed in parallel. 06831 06832 >>> x, y = Ints('x y') 06833 >>> t = ParThen(Tactic('split-clause'), Tactic('propagate-values')) 06834 >>> t(And(Or(x == 1, x == 2), y == x + 1)) 06835 [[x == 1, y == 2], [x == 2, y == 3]] 06836 """ 06837 t1 = _to_tactic(t1, ctx) 06838 t2 = _to_tactic(t2, ctx) 06839 if __debug__: 06840 _z3_assert(t1.ctx == t2.ctx, "Context mismatch") 06841 return Tactic(Z3_tactic_par_and_then(t1.ctx.ref(), t1.tactic, t2.tactic), t1.ctx)
| def z3py.probe_description | ( | name, | |
ctx = None |
|||
| ) |
Return a short description for the probe named `name`.
>>> d = probe_description('memory')
Definition at line 7084 of file z3py.py.
Referenced by describe_probes().
07084 07085 def probe_description(name, ctx=None): 07086 """Return a short description for the probe named `name`. 07087 07088 >>> d = probe_description('memory') 07089 """ 07090 ctx = _get_ctx(ctx) 07091 return Z3_probe_get_descr(ctx.ref(), name)
| def z3py.probes | ( | ctx = None | ) |
Return a list of all available probes in Z3.
>>> l = probes()
>>> l.count('memory') == 1
True
Definition at line 7074 of file z3py.py.
Referenced by describe_probes().
07074 07075 def probes(ctx=None): 07076 """Return a list of all available probes in Z3. 07077 07078 >>> l = probes() 07079 >>> l.count('memory') == 1 07080 True 07081 """ 07082 ctx = _get_ctx(ctx) 07083 return [ Z3_get_probe_name(ctx.ref(), i) for i in range(Z3_get_num_probes(ctx.ref())) ]
| def z3py.Product | ( | args | ) |
Create the product of the Z3 expressions.
>>> a, b, c = Ints('a b c')
>>> Product(a, b, c)
a*b*c
>>> Product([a, b, c])
a*b*c
>>> A = IntVector('a', 5)
>>> Product(A)
a__0*a__1*a__2*a__3*a__4
Definition at line 7281 of file z3py.py.
Referenced by BitVecs().
07281 07282 def Product(*args): 07283 """Create the product of the Z3 expressions. 07284 07285 >>> a, b, c = Ints('a b c') 07286 >>> Product(a, b, c) 07287 a*b*c 07288 >>> Product([a, b, c]) 07289 a*b*c 07290 >>> A = IntVector('a', 5) 07291 >>> Product(A) 07292 a__0*a__1*a__2*a__3*a__4 07293 """ 07294 args = _get_args(args) 07295 if __debug__: 07296 _z3_assert(len(args) > 0, "Non empty list of arguments expected") 07297 ctx = _ctx_from_ast_arg_list(args) 07298 if __debug__: 07299 _z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression") 07300 args = _coerce_expr_list(args, ctx) 07301 if is_bv(args[0]): 07302 return _reduce(lambda a, b: a * b, args, 1) 07303 else: 07304 _args, sz = _to_ast_array(args) 07305 return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
| def z3py.prove | ( | claim, | |
| keywords | |||
| ) |
Try to prove the given claim.
This is a simple function for creating demonstrations. It tries to prove
`claim` by showing the negation is unsatisfiable.
>>> p, q = Bools('p q')
>>> prove(Not(And(p, q)) == Or(Not(p), Not(q)))
proved
Definition at line 7363 of file z3py.py.
Referenced by Default(), Map(), Store(), and Update().
07363 07364 def prove(claim, **keywords): 07365 """Try to prove the given claim. 07366 07367 This is a simple function for creating demonstrations. It tries to prove 07368 `claim` by showing the negation is unsatisfiable. 07369 07370 >>> p, q = Bools('p q') 07371 >>> prove(Not(And(p, q)) == Or(Not(p), Not(q))) 07372 proved 07373 """ 07374 if __debug__: 07375 _z3_assert(is_bool(claim), "Z3 Boolean expression expected") 07376 s = Solver() 07377 s.set(**keywords) 07378 s.add(Not(claim)) 07379 if keywords.get('show', False): 07380 print(s) 07381 r = s.check() 07382 if r == unsat: 07383 print("proved") 07384 elif r == unknown: 07385 print("failed to prove") 07386 print(s.model()) 07387 else: 07388 print("counterexample") 07389 print(s.model())
| def z3py.Q | ( | a, | |
| b, | |||
ctx = None |
|||
| ) |
Return a Z3 rational a/b. If `ctx=None`, then the global context is used. >>> Q(3,5) 3/5 >>> Q(3,5).sort() Real
Definition at line 2730 of file z3py.py.
Referenced by RatNumRef.as_string(), RatNumRef.denominator(), and RatNumRef.numerator().
| def z3py.RatVal | ( | a, | |
| b, | |||
ctx = None |
|||
| ) |
Return a Z3 rational a/b. If `ctx=None`, then the global context is used. >>> RatVal(3,5) 3/5 >>> RatVal(3,5).sort() Real
Definition at line 2715 of file z3py.py.
Referenced by Q().
02715 02716 def RatVal(a, b, ctx=None): 02717 """Return a Z3 rational a/b. 02718 02719 If `ctx=None`, then the global context is used. 02720 02721 >>> RatVal(3,5) 02722 3/5 02723 >>> RatVal(3,5).sort() 02724 Real 02725 """ 02726 if __debug__: 02727 _z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer") 02728 _z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer") 02729 return simplify(RealVal(a, ctx)/RealVal(b, ctx))
| def z3py.Real | ( | name, | |
ctx = None |
|||
| ) |
Return a real constant named `name`. If `ctx=None`, then the global context is used.
>>> x = Real('x')
>>> is_real(x)
True
>>> is_real(x + 1)
True
Definition at line 2790 of file z3py.py.
Referenced by ArithRef.__div__(), ArithRef.__ge__(), ArithRef.__gt__(), ArithRef.__le__(), ArithRef.__lt__(), ArithRef.__mul__(), ArithRef.__pow__(), ArithRef.__rdiv__(), ArithRef.__rmul__(), ArithRef.__rpow__(), Cbrt(), is_arith(), ArithSortRef.is_int(), ArithRef.is_int(), is_int(), is_is_int(), is_rational_value(), ArithSortRef.is_real(), ArithRef.is_real(), is_real(), is_to_int(), IsInt(), ArithRef.sort(), Sqrt(), ToInt(), and QuantifierRef.var_sort().
02790 02791 def Real(name, ctx=None): 02792 """Return a real constant named `name`. If `ctx=None`, then the global context is used. 02793 02794 >>> x = Real('x') 02795 >>> is_real(x) 02796 True 02797 >>> is_real(x + 1) 02798 True 02799 """ 02800 ctx = _get_ctx(ctx) 02801 return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), RealSort(ctx).ast), ctx)
| def z3py.Reals | ( | names, | |
ctx = None |
|||
| ) |
Return a tuple of real constants.
>>> x, y, z = Reals('x y z')
>>> Sum(x, y, z)
x + y + z
>>> Sum(x, y, z).sort()
Real
Definition at line 2802 of file z3py.py.
Referenced by is_div().
02802 02803 def Reals(names, ctx=None): 02804 """Return a tuple of real constants. 02805 02806 >>> x, y, z = Reals('x y z') 02807 >>> Sum(x, y, z) 02808 x + y + z 02809 >>> Sum(x, y, z).sort() 02810 Real 02811 """ 02812 ctx = _get_ctx(ctx) 02813 if isinstance(names, str): 02814 names = names.split(" ") 02815 return [Real(name, ctx) for name in names]
| def z3py.RealSort | ( | ctx = None | ) |
Return the real sort in the given context. If `ctx=None`, then the global context is used.
>>> RealSort()
Real
>>> x = Const('x', RealSort())
>>> is_real(x)
True
>>> is_int(x)
False
>>> x.sort() == RealSort()
True
Definition at line 2655 of file z3py.py.
Referenced by ArithSortRef.cast(), Sort.create(), FreshReal(), Context.getRealSort(), is_arith_sort(), Context.mkRealSort(), Context.MkRealSort(), Real(), RealVar(), and QuantifierRef.var_sort().
02655 02656 def RealSort(ctx=None): 02657 """Return the real sort in the given context. If `ctx=None`, then the global context is used. 02658 02659 >>> RealSort() 02660 Real 02661 >>> x = Const('x', RealSort()) 02662 >>> is_real(x) 02663 True 02664 >>> is_int(x) 02665 False 02666 >>> x.sort() == RealSort() 02667 True 02668 """ 02669 ctx = _get_ctx(ctx) 02670 return ArithSortRef(Z3_mk_real_sort(ctx.ref()), ctx)
| def z3py.RealVal | ( | val, | |
ctx = None |
|||
| ) |
Return a Z3 real value.
`val` may be a Python int, long, float or string representing a number in decimal or rational notation.
If `ctx=None`, then the global context is used.
>>> RealVal(1)
1
>>> RealVal(1).sort()
Real
>>> RealVal("3/5")
3/5
>>> RealVal("1.5")
3/2
Definition at line 2697 of file z3py.py.
Referenced by RatNumRef.as_decimal(), RatNumRef.as_fraction(), Cbrt(), RatNumRef.denominator_as_long(), is_algebraic_value(), is_int_value(), is_rational_value(), is_real(), RatNumRef.numerator(), RatNumRef.numerator_as_long(), and RatVal().
02697 02698 def RealVal(val, ctx=None): 02699 """Return a Z3 real value. 02700 02701 `val` may be a Python int, long, float or string representing a number in decimal or rational notation. 02702 If `ctx=None`, then the global context is used. 02703 02704 >>> RealVal(1) 02705 1 02706 >>> RealVal(1).sort() 02707 Real 02708 >>> RealVal("3/5") 02709 3/5 02710 >>> RealVal("1.5") 02711 3/2 02712 """ 02713 ctx = _get_ctx(ctx) 02714 return RatNumRef(Z3_mk_numeral(ctx.ref(), str(val), RealSort(ctx).ast), ctx)
| def z3py.RealVar | ( | idx, | |
ctx = None |
|||
| ) |
Create a real free variable. Free variables are used to create quantified formulas. They are also used to create polynomials. >>> RealVar(0) Var(0)
Definition at line 1182 of file z3py.py.
Referenced by RealVarVector().
| def z3py.RealVarVector | ( | n, | |
ctx = None |
|||
| ) |
Create a list of Real free variables. The variables have ids: 0, 1, ..., n-1 >>> x0, x1, x2, x3 = RealVarVector(4) >>> x2 Var(2)
Definition at line 1192 of file z3py.py.
01192 01193 def RealVarVector(n, ctx=None): 01194 """ 01195 Create a list of Real free variables. 01196 The variables have ids: 0, 1, ..., n-1 01197 01198 >>> x0, x1, x2, x3 = RealVarVector(4) 01199 >>> x2 01200 Var(2) 01201 """ 01202 return [ RealVar(i, ctx) for i in range(n) ]
| def z3py.RealVector | ( | prefix, | |
| sz, | |||
ctx = None |
|||
| ) |
Return a list of real constants of size `sz`.
>>> X = RealVector('x', 3)
>>> X
[x__0, x__1, x__2]
>>> Sum(X)
x__0 + x__1 + x__2
>>> Sum(X).sort()
Real
Definition at line 2816 of file z3py.py.
02816 02817 def RealVector(prefix, sz, ctx=None): 02818 """Return a list of real constants of size `sz`. 02819 02820 >>> X = RealVector('x', 3) 02821 >>> X 02822 [x__0, x__1, x__2] 02823 >>> Sum(X) 02824 x__0 + x__1 + x__2 02825 >>> Sum(X).sort() 02826 Real 02827 """ 02828 return [ Real('%s__%s' % (prefix, i)) for i in range(sz) ]
| def z3py.Repeat | ( | t, | |
max = 4294967295, |
|||
ctx = None |
|||
| ) |
Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
>>> x, y = Ints('x y')
>>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
>>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
>>> r = t(c)
>>> for subgoal in r: print(subgoal)
[x == 0, y == 0, x > y]
[x == 0, y == 1, x > y]
[x == 1, y == 0, x > y]
[x == 1, y == 1, x > y]
>>> t = Then(t, Tactic('propagate-values'))
>>> t(c)
[[x == 1, y == 0]]
Definition at line 6859 of file z3py.py.
06859 06860 def Repeat(t, max=4294967295, ctx=None): 06861 """Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached. 06862 06863 >>> x, y = Ints('x y') 06864 >>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y) 06865 >>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip'))) 06866 >>> r = t(c) 06867 >>> for subgoal in r: print(subgoal) 06868 [x == 0, y == 0, x > y] 06869 [x == 0, y == 1, x > y] 06870 [x == 1, y == 0, x > y] 06871 [x == 1, y == 1, x > y] 06872 >>> t = Then(t, Tactic('propagate-values')) 06873 >>> t(c) 06874 [[x == 1, y == 0]] 06875 """ 06876 t = _to_tactic(t, ctx) 06877 return Tactic(Z3_tactic_repeat(t.ctx.ref(), t.tactic, max), t.ctx)
| def z3py.RepeatBitVec | ( | n, | |
| a | |||
| ) |
Return an expression representing `n` copies of `a`.
>>> x = BitVec('x', 8)
>>> n = RepeatBitVec(4, x)
>>> n
RepeatBitVec(4, x)
>>> n.size()
32
>>> v0 = BitVecVal(10, 4)
>>> print("%.x" % v0.as_long())
a
>>> v = simplify(RepeatBitVec(4, v0))
>>> v.size()
16
>>> print("%.x" % v.as_long())
aaaa
Definition at line 3818 of file z3py.py.
03818 03819 def RepeatBitVec(n, a): 03820 """Return an expression representing `n` copies of `a`. 03821 03822 >>> x = BitVec('x', 8) 03823 >>> n = RepeatBitVec(4, x) 03824 >>> n 03825 RepeatBitVec(4, x) 03826 >>> n.size() 03827 32 03828 >>> v0 = BitVecVal(10, 4) 03829 >>> print("%.x" % v0.as_long()) 03830 a 03831 >>> v = simplify(RepeatBitVec(4, v0)) 03832 >>> v.size() 03833 16 03834 >>> print("%.x" % v.as_long()) 03835 aaaa 03836 """ 03837 if __debug__: 03838 _z3_assert(isinstance(n, int), "First argument must be an integer") 03839 _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression") 03840 return BitVecRef(Z3_mk_repeat(a.ctx_ref(), n, a.as_ast()), a.ctx)
| def z3py.reset_params | ( | ) |
Reset all global (or module) parameters.
Definition at line 237 of file z3py.py.
00237 00238 def reset_params(): 00239 """Reset all global (or module) parameters. 00240 """ 00241 Z3_global_param_reset_all()
| def z3py.RNA | ( | ctx = None | ) |
Definition at line 7968 of file z3py.py.
Referenced by get_default_rounding_mode().
07968 07969 def RNA (ctx=None): 07970 ctx = _get_ctx(ctx) 07971 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
| def z3py.RNE | ( | ctx = None | ) |
Definition at line 7960 of file z3py.py.
Referenced by fpAbs(), fpAdd(), fpDiv(), fpMax(), fpMin(), fpMul(), fpNeg(), FPs(), fpSub(), get_default_rounding_mode(), is_fprm(), and is_fprm_sort().
07960 07961 def RNE (ctx=None): 07962 ctx = _get_ctx(ctx) 07963 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
| def z3py.RotateLeft | ( | a, | |
| b | |||
| ) |
Return an expression representing `a` rotated to the left `b` times.
>>> a, b = BitVecs('a b', 16)
>>> RotateLeft(a, b)
RotateLeft(a, b)
>>> simplify(RotateLeft(a, 0))
a
>>> simplify(RotateLeft(a, 16))
a
Definition at line 3732 of file z3py.py.
03732 03733 def RotateLeft(a, b): 03734 """Return an expression representing `a` rotated to the left `b` times. 03735 03736 >>> a, b = BitVecs('a b', 16) 03737 >>> RotateLeft(a, b) 03738 RotateLeft(a, b) 03739 >>> simplify(RotateLeft(a, 0)) 03740 a 03741 >>> simplify(RotateLeft(a, 16)) 03742 a 03743 """ 03744 _check_bv_args(a, b) 03745 a, b = _coerce_exprs(a, b) 03746 return BitVecRef(Z3_mk_ext_rotate_left(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.RotateRight | ( | a, | |
| b | |||
| ) |
Return an expression representing `a` rotated to the right `b` times.
>>> a, b = BitVecs('a b', 16)
>>> RotateRight(a, b)
RotateRight(a, b)
>>> simplify(RotateRight(a, 0))
a
>>> simplify(RotateRight(a, 16))
a
Definition at line 3747 of file z3py.py.
03747 03748 def RotateRight(a, b): 03749 """Return an expression representing `a` rotated to the right `b` times. 03750 03751 >>> a, b = BitVecs('a b', 16) 03752 >>> RotateRight(a, b) 03753 RotateRight(a, b) 03754 >>> simplify(RotateRight(a, 0)) 03755 a 03756 >>> simplify(RotateRight(a, 16)) 03757 a 03758 """ 03759 _check_bv_args(a, b) 03760 a, b = _coerce_exprs(a, b) 03761 return BitVecRef(Z3_mk_ext_rotate_right(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.RoundNearestTiesToAway | ( | ctx = None | ) |
Definition at line 7964 of file z3py.py.
07964 07965 def RoundNearestTiesToAway(ctx=None): 07966 ctx = _get_ctx(ctx) 07967 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_away(ctx.ref()), ctx)
| def z3py.RoundNearestTiesToEven | ( | ctx = None | ) |
Definition at line 7956 of file z3py.py.
07956 07957 def RoundNearestTiesToEven(ctx=None): 07958 ctx = _get_ctx(ctx) 07959 return FPRMRef(Z3_mk_fpa_round_nearest_ties_to_even(ctx.ref()), ctx)
| def z3py.RoundTowardNegative | ( | ctx = None | ) |
Definition at line 7980 of file z3py.py.
07980 07981 def RoundTowardNegative(ctx=None): 07982 ctx = _get_ctx(ctx) 07983 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
| def z3py.RoundTowardPositive | ( | ctx = None | ) |
Definition at line 7972 of file z3py.py.
07972 07973 def RoundTowardPositive(ctx=None): 07974 ctx = _get_ctx(ctx) 07975 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
| def z3py.RoundTowardZero | ( | ctx = None | ) |
Definition at line 7988 of file z3py.py.
07988 07989 def RoundTowardZero(ctx=None): 07990 ctx = _get_ctx(ctx) 07991 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
| def z3py.RTN | ( | ctx = None | ) |
Definition at line 7984 of file z3py.py.
Referenced by get_default_rounding_mode().
07984 07985 def RTN(ctx=None): 07986 ctx = _get_ctx(ctx) 07987 return FPRMRef(Z3_mk_fpa_round_toward_negative(ctx.ref()), ctx)
| def z3py.RTP | ( | ctx = None | ) |
Definition at line 7976 of file z3py.py.
Referenced by get_default_rounding_mode().
07976 07977 def RTP(ctx=None): 07978 ctx = _get_ctx(ctx) 07979 return FPRMRef(Z3_mk_fpa_round_toward_positive(ctx.ref()), ctx)
| def z3py.RTZ | ( | ctx = None | ) |
Definition at line 7992 of file z3py.py.
Referenced by fpToSBV(), fpToUBV(), and get_default_rounding_mode().
07992 07993 def RTZ(ctx=None): 07994 ctx = _get_ctx(ctx) 07995 return FPRMRef(Z3_mk_fpa_round_toward_zero(ctx.ref()), ctx)
| def z3py.Select | ( | a, | |
| i | |||
| ) |
Return a Z3 select array expression.
>>> a = Array('a', IntSort(), IntSort())
>>> i = Int('i')
>>> Select(a, i)
a[i]
>>> eq(Select(a, i), a[i])
True
Definition at line 4086 of file z3py.py.
04086 04087 def Select(a, i): 04088 """Return a Z3 select array expression. 04089 04090 >>> a = Array('a', IntSort(), IntSort()) 04091 >>> i = Int('i') 04092 >>> Select(a, i) 04093 a[i] 04094 >>> eq(Select(a, i), a[i]) 04095 True 04096 """ 04097 if __debug__: 04098 _z3_assert(is_array(a), "First argument must be a Z3 array expression") 04099 return a[i]
| def z3py.sequence_interpolant | ( | v, | |
p = None, |
|||
ctx = None |
|||
| ) |
Compute interpolant for a sequence of formulas.
If len(v) == N, and if the conjunction of the formulas in v is
unsatisfiable, the interpolant is a sequence of formulas w
such that len(w) = N-1 and v[0] implies w[0] and for i in 0..N-1:
1) w[i] & v[i+1] implies w[i+1] (or false if i+1 = N)
2) All uninterpreted symbols in w[i] occur in both v[0]..v[i]
and v[i+1]..v[n]
Requires len(v) >= 1.
If a & b is satisfiable, raises an object of class ModelRef
that represents a model of a & b.
If parameters p are supplied, these are used in creating the
solver that determines satisfiability.
>>> x = Int('x')
>>> y = Int('y')
>>> print sequence_interpolant([x < 0, y == x , y > 2])
[Not(x >= 0), Not(y >= 0)]
Definition at line 7613 of file z3py.py.
07613 07614 def sequence_interpolant(v,p=None,ctx=None): 07615 """Compute interpolant for a sequence of formulas. 07616 07617 If len(v) == N, and if the conjunction of the formulas in v is 07618 unsatisfiable, the interpolant is a sequence of formulas w 07619 such that len(w) = N-1 and v[0] implies w[0] and for i in 0..N-1: 07620 07621 1) w[i] & v[i+1] implies w[i+1] (or false if i+1 = N) 07622 2) All uninterpreted symbols in w[i] occur in both v[0]..v[i] 07623 and v[i+1]..v[n] 07624 07625 Requires len(v) >= 1. 07626 07627 If a & b is satisfiable, raises an object of class ModelRef 07628 that represents a model of a & b. 07629 07630 If parameters p are supplied, these are used in creating the 07631 solver that determines satisfiability. 07632 07633 >>> x = Int('x') 07634 >>> y = Int('y') 07635 >>> print sequence_interpolant([x < 0, y == x , y > 2]) 07636 [Not(x >= 0), Not(y >= 0)] 07637 """ 07638 f = v[0] 07639 for i in range(1,len(v)): 07640 f = And(Interpolant(f),v[i]) 07641 return tree_interpolant(f,p,ctx)
| def z3py.set_default_fp_sort | ( | ebits, | |
| sbits, | |||
ctx = None |
|||
| ) |
Definition at line 7684 of file z3py.py.
07684 07685 def set_default_fp_sort(ebits, sbits, ctx=None): 07686 global _dflt_fpsort_ebits 07687 global _dflt_fpsort_sbits 07688 _dflt_fpsort_ebits = ebits 07689 _dflt_fpsort_sbits = sbits
| def z3py.set_default_rounding_mode | ( | rm, | |
ctx = None |
|||
| ) |
Definition at line 7668 of file z3py.py.
07668 07669 def set_default_rounding_mode(rm, ctx=None): 07670 global _dflt_rounding_mode 07671 if is_fprm_value(rm): 07672 _dflt_rounding_mode = rm.decl().kind() 07673 else: 07674 _z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO or 07675 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_NEGATIVE or 07676 _dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_POSITIVE or 07677 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_EVEN or 07678 _dflt_rounding_mode == Z3_OP_FPA_RM_NEAREST_TIES_TO_AWAY, 07679 "illegal rounding mode") 07680 _dflt_rounding_mode = rm
| def z3py.set_option | ( | args, | |
| kws | |||
| ) |
Alias for 'set_param' for backward compatibility.
Definition at line 242 of file z3py.py.
00242 00243 def set_option(*args, **kws): 00244 """Alias for 'set_param' for backward compatibility. 00245 """ 00246 return set_param(*args, **kws)
| def z3py.set_param | ( | args, | |
| kws | |||
| ) |
Set Z3 global (or module) parameters. >>> set_param(precision=10)
Definition at line 214 of file z3py.py.
Referenced by set_option().
00214 00215 def set_param(*args, **kws): 00216 """Set Z3 global (or module) parameters. 00217 00218 >>> set_param(precision=10) 00219 """ 00220 if __debug__: 00221 _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.") 00222 new_kws = {} 00223 for k in kws: 00224 v = kws[k] 00225 if not set_pp_option(k, v): 00226 new_kws[k] = v 00227 for key in new_kws: 00228 value = new_kws[key] 00229 Z3_global_param_set(str(key).upper(), _to_param_value(value)) 00230 prev = None 00231 for a in args: 00232 if prev == None: 00233 prev = a 00234 else: 00235 Z3_global_param_set(str(prev), _to_param_value(a)) 00236 prev = None
| def z3py.SignExt | ( | n, | |
| a | |||
| ) |
Return a bit-vector expression with `n` extra sign-bits.
>>> x = BitVec('x', 16)
>>> n = SignExt(8, x)
>>> n.size()
24
>>> n
SignExt(8, x)
>>> n.sort()
BitVec(24)
>>> v0 = BitVecVal(2, 2)
>>> v0
2
>>> v0.size()
2
>>> v = simplify(SignExt(6, v0))
>>> v
254
>>> v.size()
8
>>> print("%.x" % v.as_long())
fe
Definition at line 3762 of file z3py.py.
03762 03763 def SignExt(n, a): 03764 """Return a bit-vector expression with `n` extra sign-bits. 03765 03766 >>> x = BitVec('x', 16) 03767 >>> n = SignExt(8, x) 03768 >>> n.size() 03769 24 03770 >>> n 03771 SignExt(8, x) 03772 >>> n.sort() 03773 BitVec(24) 03774 >>> v0 = BitVecVal(2, 2) 03775 >>> v0 03776 2 03777 >>> v0.size() 03778 2 03779 >>> v = simplify(SignExt(6, v0)) 03780 >>> v 03781 254 03782 >>> v.size() 03783 8 03784 >>> print("%.x" % v.as_long()) 03785 fe 03786 """ 03787 if __debug__: 03788 _z3_assert(isinstance(n, int), "First argument must be an integer") 03789 _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression") 03790 return BitVecRef(Z3_mk_sign_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
| def z3py.SimpleSolver | ( | ctx = None | ) |
Return a simple general purpose solver with limited amount of preprocessing.
>>> s = SimpleSolver()
>>> x = Int('x')
>>> s.add(x > 0)
>>> s.check()
sat
Definition at line 6131 of file z3py.py.
Referenced by Solver.reason_unknown(), and Solver.statistics().
06131 06132 def SimpleSolver(ctx=None): 06133 """Return a simple general purpose solver with limited amount of preprocessing. 06134 06135 >>> s = SimpleSolver() 06136 >>> x = Int('x') 06137 >>> s.add(x > 0) 06138 >>> s.check() 06139 sat 06140 """ 06141 ctx = _get_ctx(ctx) 06142 return Solver(Z3_mk_simple_solver(ctx.ref()), ctx)
| def z3py.simplify | ( | a, | |
| arguments, | |||
| keywords | |||
| ) |
Utils.
Simplify the expression `a` using the given options.
This function has many options. Use `help_simplify` to obtain the complete list.
>>> x = Int('x')
>>> y = Int('y')
>>> simplify(x + 1 + y + x + 1)
2 + 2*x + y
>>> simplify((x + 1)*(y + 1), som=True)
1 + x + y + x*y
>>> simplify(Distinct(x, y, 1), blast_distinct=True)
And(Not(x == y), Not(x == 1), Not(y == 1))
>>> simplify(And(x == 0, y == 1), elim_and=True)
Not(Or(Not(x == 0), Not(y == 1)))
Definition at line 7178 of file z3py.py.
Referenced by BitVecRef.__invert__(), BitVecRef.__lshift__(), ArithRef.__mod__(), ArithRef.__neg__(), BitVecRef.__neg__(), ArithRef.__pow__(), ArithRef.__rpow__(), BitVecRef.__rshift__(), AlgebraicNumRef.approx(), AlgebraicNumRef.as_decimal(), BitVecs(), Concat(), CreateDatatypes(), Implies(), is_algebraic_value(), K(), LShR(), Not(), Q(), RatVal(), DatatypeSortRef.recognizer(), RepeatBitVec(), RotateLeft(), RotateRight(), SignExt(), Xor(), and ZeroExt().
07178 07179 def simplify(a, *arguments, **keywords): 07180 """Simplify the expression `a` using the given options. 07181 07182 This function has many options. Use `help_simplify` to obtain the complete list. 07183 07184 >>> x = Int('x') 07185 >>> y = Int('y') 07186 >>> simplify(x + 1 + y + x + 1) 07187 2 + 2*x + y 07188 >>> simplify((x + 1)*(y + 1), som=True) 07189 1 + x + y + x*y 07190 >>> simplify(Distinct(x, y, 1), blast_distinct=True) 07191 And(Not(x == y), Not(x == 1), Not(y == 1)) 07192 >>> simplify(And(x == 0, y == 1), elim_and=True) 07193 Not(Or(Not(x == 0), Not(y == 1))) 07194 """ 07195 if __debug__: 07196 _z3_assert(is_expr(a), "Z3 expression expected") 07197 if len(arguments) > 0 or len(keywords) > 0: 07198 p = args2params(arguments, keywords, a.ctx) 07199 return _to_expr_ref(Z3_simplify_ex(a.ctx_ref(), a.as_ast(), p.params), a.ctx) 07200 else: 07201 return _to_expr_ref(Z3_simplify(a.ctx_ref(), a.as_ast()), a.ctx)
| def z3py.simplify_param_descrs | ( | ) |
Return the set of parameter descriptions for Z3 `simplify` procedure.
Definition at line 7206 of file z3py.py.
07206 07207 def simplify_param_descrs(): 07208 """Return the set of parameter descriptions for Z3 `simplify` procedure.""" 07209 return ParamDescrsRef(Z3_simplify_get_param_descrs(main_ctx().ref()), main_ctx())
| def z3py.solve | ( | args, | |
| keywords | |||
| ) |
Solve the constraints `*args`.
This is a simple function for creating demonstrations. It creates a solver,
configure it using the options in `keywords`, adds the constraints
in `args`, and invokes check.
>>> a = Int('a')
>>> solve(a > 0, a < 2)
[a = 1]
Definition at line 7306 of file z3py.py.
Referenced by BV2Int(), and IsInt().
07306 07307 def solve(*args, **keywords): 07308 """Solve the constraints `*args`. 07309 07310 This is a simple function for creating demonstrations. It creates a solver, 07311 configure it using the options in `keywords`, adds the constraints 07312 in `args`, and invokes check. 07313 07314 >>> a = Int('a') 07315 >>> solve(a > 0, a < 2) 07316 [a = 1] 07317 """ 07318 s = Solver() 07319 s.set(**keywords) 07320 s.add(*args) 07321 if keywords.get('show', False): 07322 print(s) 07323 r = s.check() 07324 if r == unsat: 07325 print("no solution") 07326 elif r == unknown: 07327 print("failed to solve") 07328 try: 07329 print(s.model()) 07330 except Z3Exception: 07331 return 07332 else: 07333 print(s.model())
| def z3py.solve_using | ( | s, | |
| args, | |||
| keywords | |||
| ) |
Solve the constraints `*args` using solver `s`. This is a simple function for creating demonstrations. It is similar to `solve`, but it uses the given solver `s`. It configures solver `s` using the options in `keywords`, adds the constraints in `args`, and invokes check.
Definition at line 7334 of file z3py.py.
07334 07335 def solve_using(s, *args, **keywords): 07336 """Solve the constraints `*args` using solver `s`. 07337 07338 This is a simple function for creating demonstrations. It is similar to `solve`, 07339 but it uses the given solver `s`. 07340 It configures solver `s` using the options in `keywords`, adds the constraints 07341 in `args`, and invokes check. 07342 """ 07343 if __debug__: 07344 _z3_assert(isinstance(s, Solver), "Solver object expected") 07345 s.set(**keywords) 07346 s.add(*args) 07347 if keywords.get('show', False): 07348 print("Problem:") 07349 print(s) 07350 r = s.check() 07351 if r == unsat: 07352 print("no solution") 07353 elif r == unknown: 07354 print("failed to solve") 07355 try: 07356 print(s.model()) 07357 except Z3Exception: 07358 return 07359 else: 07360 if keywords.get('show', False): 07361 print("Solution:") 07362 print(s.model())
| def z3py.SolverFor | ( | logic, | |
ctx = None |
|||
| ) |
Create a solver customized for the given logic.
The parameter `logic` is a string. It should be contains
the name of a SMT-LIB logic.
See http://www.smtlib.org/ for the name of all available logics.
>>> s = SolverFor("QF_LIA")
>>> x = Int('x')
>>> s.add(x > 0)
>>> s.add(x < 2)
>>> s.check()
sat
>>> s.model()
[x = 1]
Definition at line 6111 of file z3py.py.
06111 06112 def SolverFor(logic, ctx=None): 06113 """Create a solver customized for the given logic. 06114 06115 The parameter `logic` is a string. It should be contains 06116 the name of a SMT-LIB logic. 06117 See http://www.smtlib.org/ for the name of all available logics. 06118 06119 >>> s = SolverFor("QF_LIA") 06120 >>> x = Int('x') 06121 >>> s.add(x > 0) 06122 >>> s.add(x < 2) 06123 >>> s.check() 06124 sat 06125 >>> s.model() 06126 [x = 1] 06127 """ 06128 ctx = _get_ctx(ctx) 06129 logic = to_symbol(logic) 06130 return Solver(Z3_mk_solver_for_logic(ctx.ref(), logic), ctx)
| def z3py.Sqrt | ( | a, | |
ctx = None |
|||
| ) |
Return a Z3 expression which represents the square root of a.
>>> x = Real('x')
>>> Sqrt(x)
x**(1/2)
Definition at line 2892 of file z3py.py.
Referenced by AlgebraicNumRef.approx(), AlgebraicNumRef.as_decimal(), and is_algebraic_value().
| def z3py.SRem | ( | a, | |
| b | |||
| ) |
Create the Z3 expression signed remainder.
Use the operator % for signed modulus, and URem() for unsigned remainder.
>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> SRem(x, y)
SRem(x, y)
>>> SRem(x, y).sort()
BitVec(32)
>>> (x % y).sexpr()
'(bvsmod x y)'
>>> SRem(x, y).sexpr()
'(bvsrem x y)'
Definition at line 3681 of file z3py.py.
Referenced by BitVecRef.__mod__(), BitVecRef.__rmod__(), and URem().
03681 03682 def SRem(a, b): 03683 """Create the Z3 expression signed remainder. 03684 03685 Use the operator % for signed modulus, and URem() for unsigned remainder. 03686 03687 >>> x = BitVec('x', 32) 03688 >>> y = BitVec('y', 32) 03689 >>> SRem(x, y) 03690 SRem(x, y) 03691 >>> SRem(x, y).sort() 03692 BitVec(32) 03693 >>> (x % y).sexpr() 03694 '(bvsmod x y)' 03695 >>> SRem(x, y).sexpr() 03696 '(bvsrem x y)' 03697 """ 03698 _check_bv_args(a, b) 03699 a, b = _coerce_exprs(a, b) 03700 return BitVecRef(Z3_mk_bvsrem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.Store | ( | a, | |
| i, | |||
| v | |||
| ) |
Return a Z3 store array expression.
>>> a = Array('a', IntSort(), IntSort())
>>> i, v = Ints('i v')
>>> s = Store(a, i, v)
>>> s.sort()
Array(Int, Int)
>>> prove(s[i] == v)
proved
>>> j = Int('j')
>>> prove(Implies(i != j, s[j] == a[j]))
proved
Definition at line 4070 of file z3py.py.
Referenced by is_array(), and is_store().
04070 04071 def Store(a, i, v): 04072 """Return a Z3 store array expression. 04073 04074 >>> a = Array('a', IntSort(), IntSort()) 04075 >>> i, v = Ints('i v') 04076 >>> s = Store(a, i, v) 04077 >>> s.sort() 04078 Array(Int, Int) 04079 >>> prove(s[i] == v) 04080 proved 04081 >>> j = Int('j') 04082 >>> prove(Implies(i != j, s[j] == a[j])) 04083 proved 04084 """ 04085 return Update(a, i, v)
| def z3py.substitute | ( | t, | |
| m | |||
| ) |
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.
>>> x = Int('x')
>>> y = Int('y')
>>> substitute(x + 1, (x, y + 1))
y + 1 + 1
>>> f = Function('f', IntSort(), IntSort())
>>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1)))
1 + 1
Definition at line 7210 of file z3py.py.
07210 07211 def substitute(t, *m): 07212 """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. 07213 07214 >>> x = Int('x') 07215 >>> y = Int('y') 07216 >>> substitute(x + 1, (x, y + 1)) 07217 y + 1 + 1 07218 >>> f = Function('f', IntSort(), IntSort()) 07219 >>> substitute(f(x) + f(y), (f(x), IntVal(1)), (f(y), IntVal(1))) 07220 1 + 1 07221 """ 07222 if isinstance(m, tuple): 07223 m1 = _get_args(m) 07224 if isinstance(m1, list): 07225 m = m1 07226 if __debug__: 07227 _z3_assert(is_expr(t), "Z3 expression expected") 07228 _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.") 07229 num = len(m) 07230 _from = (Ast * num)() 07231 _to = (Ast * num)() 07232 for i in range(num): 07233 _from[i] = m[i][0].as_ast() 07234 _to[i] = m[i][1].as_ast() 07235 return _to_expr_ref(Z3_substitute(t.ctx.ref(), t.as_ast(), num, _from, _to), t.ctx)
| def z3py.substitute_vars | ( | t, | |
| m | |||
| ) |
Substitute the free variables in t with the expression in m.
>>> v0 = Var(0, IntSort())
>>> v1 = Var(1, IntSort())
>>> x = Int('x')
>>> f = Function('f', IntSort(), IntSort(), IntSort())
>>> # replace v0 with x+1 and v1 with x
>>> substitute_vars(f(v0, v1), x + 1, x)
f(x + 1, x)
Definition at line 7236 of file z3py.py.
07236 07237 def substitute_vars(t, *m): 07238 """Substitute the free variables in t with the expression in m. 07239 07240 >>> v0 = Var(0, IntSort()) 07241 >>> v1 = Var(1, IntSort()) 07242 >>> x = Int('x') 07243 >>> f = Function('f', IntSort(), IntSort(), IntSort()) 07244 >>> # replace v0 with x+1 and v1 with x 07245 >>> substitute_vars(f(v0, v1), x + 1, x) 07246 f(x + 1, x) 07247 """ 07248 if __debug__: 07249 _z3_assert(is_expr(t), "Z3 expression expected") 07250 _z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.") 07251 num = len(m) 07252 _to = (Ast * num)() 07253 for i in range(num): 07254 _to[i] = m[i].as_ast() 07255 return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)
| def z3py.Sum | ( | args | ) |
Create the sum of the Z3 expressions.
>>> a, b, c = Ints('a b c')
>>> Sum(a, b, c)
a + b + c
>>> Sum([a, b, c])
a + b + c
>>> A = IntVector('a', 5)
>>> Sum(A)
a__0 + a__1 + a__2 + a__3 + a__4
Definition at line 7256 of file z3py.py.
Referenced by BitVecs(), Ints(), IntVector(), Reals(), and RealVector().
07256 07257 def Sum(*args): 07258 """Create the sum of the Z3 expressions. 07259 07260 >>> a, b, c = Ints('a b c') 07261 >>> Sum(a, b, c) 07262 a + b + c 07263 >>> Sum([a, b, c]) 07264 a + b + c 07265 >>> A = IntVector('a', 5) 07266 >>> Sum(A) 07267 a__0 + a__1 + a__2 + a__3 + a__4 07268 """ 07269 args = _get_args(args) 07270 if __debug__: 07271 _z3_assert(len(args) > 0, "Non empty list of arguments expected") 07272 ctx = _ctx_from_ast_arg_list(args) 07273 if __debug__: 07274 _z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression") 07275 args = _coerce_expr_list(args, ctx) 07276 if is_bv(args[0]): 07277 return _reduce(lambda a, b: a + b, args, 0) 07278 else: 07279 _args, sz = _to_ast_array(args) 07280 return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
| def z3py.tactic_description | ( | name, | |
ctx = None |
|||
| ) |
Return a short description for the tactic named `name`.
>>> d = tactic_description('simplify')
Definition at line 6896 of file z3py.py.
Referenced by describe_tactics().
06896 06897 def tactic_description(name, ctx=None): 06898 """Return a short description for the tactic named `name`. 06899 06900 >>> d = tactic_description('simplify') 06901 """ 06902 ctx = _get_ctx(ctx) 06903 return Z3_tactic_get_descr(ctx.ref(), name)
| def z3py.tactics | ( | ctx = None | ) |
Return a list of all available tactics in Z3.
>>> l = tactics()
>>> l.count('simplify') == 1
True
Definition at line 6886 of file z3py.py.
Referenced by describe_tactics().
06886 06887 def tactics(ctx=None): 06888 """Return a list of all available tactics in Z3. 06889 06890 >>> l = tactics() 06891 >>> l.count('simplify') == 1 06892 True 06893 """ 06894 ctx = _get_ctx(ctx) 06895 return [ Z3_get_tactic_name(ctx.ref(), i) for i in range(Z3_get_num_tactics(ctx.ref())) ]
| def z3py.Then | ( | ts, | |
| ks | |||
| ) |
Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks).
>>> x, y = Ints('x y')
>>> t = Then(Tactic('simplify'), Tactic('solve-eqs'))
>>> t(And(x == 0, y > x + 1))
[[Not(y <= 1)]]
>>> t(And(x == 0, y > x + 1)).as_expr()
Not(y <= 1)
Definition at line 6778 of file z3py.py.
Referenced by Statistics.__getattr__(), Statistics.__getitem__(), Statistics.__len__(), Goal.depth(), Statistics.get_key_value(), and Statistics.keys().
06778 06779 def Then(*ts, **ks): 06780 """Return a tactic that applies the tactics in `*ts` in sequence. Shorthand for AndThen(*ts, **ks). 06781 06782 >>> x, y = Ints('x y') 06783 >>> t = Then(Tactic('simplify'), Tactic('solve-eqs')) 06784 >>> t(And(x == 0, y > x + 1)) 06785 [[Not(y <= 1)]] 06786 >>> t(And(x == 0, y > x + 1)).as_expr() 06787 Not(y <= 1) 06788 """ 06789 return AndThen(*ts, **ks)
| def z3py.to_symbol | ( | s, | |
ctx = None |
|||
| ) |
Convert an integer or string into a Z3 symbol.
Definition at line 94 of file z3py.py.
Referenced by Fixedpoint.add_rule(), Optimize.add_soft(), Array(), BitVec(), Bool(), Const(), CreateDatatypes(), DeclareSort(), EnumSort(), FP(), Function(), Int(), prove(), Real(), Fixedpoint.set_predicate_representation(), SolverFor(), and Fixedpoint.update_rule().
00094 00095 def to_symbol(s, ctx=None): 00096 """Convert an integer or string into a Z3 symbol.""" 00097 if isinstance(s, int): 00098 return Z3_mk_int_symbol(_get_ctx(ctx).ref(), s) 00099 else: 00100 return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
| def z3py.ToInt | ( | a | ) |
Return the Z3 expression ToInt(a).
>>> x = Real('x')
>>> x.sort()
Real
>>> n = ToInt(x)
>>> n
ToInt(x)
>>> n.sort()
Int
Definition at line 2859 of file z3py.py.
Referenced by is_to_int().
02859 02860 def ToInt(a): 02861 """ Return the Z3 expression ToInt(a). 02862 02863 >>> x = Real('x') 02864 >>> x.sort() 02865 Real 02866 >>> n = ToInt(x) 02867 >>> n 02868 ToInt(x) 02869 >>> n.sort() 02870 Int 02871 """ 02872 if __debug__: 02873 _z3_assert(a.is_real(), "Z3 real expression expected.") 02874 ctx = a.ctx 02875 return ArithRef(Z3_mk_real2int(ctx.ref(), a.as_ast()), ctx)
| def z3py.ToReal | ( | a | ) |
Return the Z3 expression ToReal(a).
>>> x = Int('x')
>>> x.sort()
Int
>>> n = ToReal(x)
>>> n
ToReal(x)
>>> n.sort()
Real
Definition at line 2842 of file z3py.py.
Referenced by ArithRef.__ge__(), ArithRef.__gt__(), ArithRef.__le__(), ArithRef.__lt__(), and is_to_real().
02842 02843 def ToReal(a): 02844 """ Return the Z3 expression ToReal(a). 02845 02846 >>> x = Int('x') 02847 >>> x.sort() 02848 Int 02849 >>> n = ToReal(x) 02850 >>> n 02851 ToReal(x) 02852 >>> n.sort() 02853 Real 02854 """ 02855 if __debug__: 02856 _z3_assert(a.is_int(), "Z3 integer expression expected.") 02857 ctx = a.ctx 02858 return ArithRef(Z3_mk_int2real(ctx.ref(), a.as_ast()), ctx)
| def z3py.tree_interpolant | ( | pat, | |
p = None, |
|||
ctx = None |
|||
| ) |
Compute interpolant for a tree of formulas.
The input is an interpolation pattern over a set of formulas C.
The pattern pat is a formula combining the formulas in C using
logical conjunction and the "interp" operator (see Interp). This
interp operator is logically the identity operator. It marks the
sub-formulas of the pattern for which interpolants should be
computed. The interpolant is a map sigma from marked subformulas
to formulas, such that, for each marked subformula phi of pat
(where phi sigma is phi with sigma(psi) substituted for each
subformula psi of phi such that psi in dom(sigma)):
1) phi sigma implies sigma(phi), and
2) sigma(phi) is in the common uninterpreted vocabulary between
the formulas of C occurring in phi and those not occurring in
phi
and moreover pat sigma implies false. In the simplest case
an interpolant for the pattern "(and (interp A) B)" maps A
to an interpolant for A /\ B.
The return value is a vector of formulas representing sigma. This
vector contains sigma(phi) for each marked subformula of pat, in
pre-order traversal. This means that subformulas of phi occur before phi
in the vector. Also, subformulas that occur multiply in pat will
occur multiply in the result vector.
If pat is satisfiable, raises an object of class ModelRef
that represents a model of pat.
If parameters p are supplied, these are used in creating the
solver that determines satisfiability.
>>> x = Int('x')
>>> y = Int('y')
>>> print tree_interpolant(And(Interpolant(x < 0), Interpolant(y > 2), x == y))
[Not(x >= 0), Not(y <= 2)]
>>> g = And(Interpolant(x<0),x<2)
>>> try:
... print tree_interpolant(g).sexpr()
... except ModelRef as m:
... print m.sexpr()
(define-fun x () Int
(- 1))
Definition at line 7531 of file z3py.py.
Referenced by binary_interpolant(), and sequence_interpolant().
07531 07532 def tree_interpolant(pat,p=None,ctx=None): 07533 """Compute interpolant for a tree of formulas. 07534 07535 The input is an interpolation pattern over a set of formulas C. 07536 The pattern pat is a formula combining the formulas in C using 07537 logical conjunction and the "interp" operator (see Interp). This 07538 interp operator is logically the identity operator. It marks the 07539 sub-formulas of the pattern for which interpolants should be 07540 computed. The interpolant is a map sigma from marked subformulas 07541 to formulas, such that, for each marked subformula phi of pat 07542 (where phi sigma is phi with sigma(psi) substituted for each 07543 subformula psi of phi such that psi in dom(sigma)): 07544 07545 1) phi sigma implies sigma(phi), and 07546 07547 2) sigma(phi) is in the common uninterpreted vocabulary between 07548 the formulas of C occurring in phi and those not occurring in 07549 phi 07550 07551 and moreover pat sigma implies false. In the simplest case 07552 an interpolant for the pattern "(and (interp A) B)" maps A 07553 to an interpolant for A /\ B. 07554 07555 The return value is a vector of formulas representing sigma. This 07556 vector contains sigma(phi) for each marked subformula of pat, in 07557 pre-order traversal. This means that subformulas of phi occur before phi 07558 in the vector. Also, subformulas that occur multiply in pat will 07559 occur multiply in the result vector. 07560 07561 If pat is satisfiable, raises an object of class ModelRef 07562 that represents a model of pat. 07563 07564 If parameters p are supplied, these are used in creating the 07565 solver that determines satisfiability. 07566 07567 >>> x = Int('x') 07568 >>> y = Int('y') 07569 >>> print tree_interpolant(And(Interpolant(x < 0), Interpolant(y > 2), x == y)) 07570 [Not(x >= 0), Not(y <= 2)] 07571 07572 >>> g = And(Interpolant(x<0),x<2) 07573 >>> try: 07574 ... print tree_interpolant(g).sexpr() 07575 ... except ModelRef as m: 07576 ... print m.sexpr() 07577 (define-fun x () Int 07578 (- 1)) 07579 """ 07580 f = pat 07581 ctx = _get_ctx(_ctx_from_ast_arg_list([f], ctx)) 07582 ptr = (AstVectorObj * 1)() 07583 mptr = (Model * 1)() 07584 if p == None: 07585 p = ParamsRef(ctx) 07586 res = Z3_compute_interpolant(ctx.ref(),f.as_ast(),p.params,ptr,mptr) 07587 if res == Z3_L_FALSE: 07588 return AstVector(ptr[0],ctx) 07589 raise ModelRef(mptr[0], ctx)
| def z3py.TryFor | ( | t, | |
| ms, | |||
ctx = None |
|||
| ) |
Return a tactic that applies `t` to a given goal for `ms` milliseconds. If `t` does not terminate in `ms` milliseconds, then it fails.
Definition at line 6878 of file z3py.py.
06878 06879 def TryFor(t, ms, ctx=None): 06880 """Return a tactic that applies `t` to a given goal for `ms` milliseconds. 06881 06882 If `t` does not terminate in `ms` milliseconds, then it fails. 06883 """ 06884 t = _to_tactic(t, ctx) 06885 return Tactic(Z3_tactic_try_for(t.ctx.ref(), t.tactic, ms), t.ctx)
| def z3py.UDiv | ( | a, | |
| b | |||
| ) |
Create the Z3 expression (unsigned) division `self / other`.
Use the operator / for signed division.
>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> UDiv(x, y)
UDiv(x, y)
>>> UDiv(x, y).sort()
BitVec(32)
>>> (x / y).sexpr()
'(bvsdiv x y)'
>>> UDiv(x, y).sexpr()
'(bvudiv x y)'
Definition at line 3641 of file z3py.py.
Referenced by BitVecRef.__div__(), and BitVecRef.__rdiv__().
03641 03642 def UDiv(a, b): 03643 """Create the Z3 expression (unsigned) division `self / other`. 03644 03645 Use the operator / for signed division. 03646 03647 >>> x = BitVec('x', 32) 03648 >>> y = BitVec('y', 32) 03649 >>> UDiv(x, y) 03650 UDiv(x, y) 03651 >>> UDiv(x, y).sort() 03652 BitVec(32) 03653 >>> (x / y).sexpr() 03654 '(bvsdiv x y)' 03655 >>> UDiv(x, y).sexpr() 03656 '(bvudiv x y)' 03657 """ 03658 _check_bv_args(a, b) 03659 a, b = _coerce_exprs(a, b) 03660 return BitVecRef(Z3_mk_bvudiv(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.UGE | ( | a, | |
| b | |||
| ) |
Create the Z3 expression (unsigned) `other >= self`.
Use the operator >= for signed greater than or equal to.
>>> x, y = BitVecs('x y', 32)
>>> UGE(x, y)
UGE(x, y)
>>> (x >= y).sexpr()
'(bvsge x y)'
>>> UGE(x, y).sexpr()
'(bvuge x y)'
Definition at line 3607 of file z3py.py.
Referenced by BitVecRef.__ge__().
03607 03608 def UGE(a, b): 03609 """Create the Z3 expression (unsigned) `other >= self`. 03610 03611 Use the operator >= for signed greater than or equal to. 03612 03613 >>> x, y = BitVecs('x y', 32) 03614 >>> UGE(x, y) 03615 UGE(x, y) 03616 >>> (x >= y).sexpr() 03617 '(bvsge x y)' 03618 >>> UGE(x, y).sexpr() 03619 '(bvuge x y)' 03620 """ 03621 _check_bv_args(a, b) 03622 a, b = _coerce_exprs(a, b) 03623 return BoolRef(Z3_mk_bvuge(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.UGT | ( | a, | |
| b | |||
| ) |
Create the Z3 expression (unsigned) `other > self`.
Use the operator > for signed greater than.
>>> x, y = BitVecs('x y', 32)
>>> UGT(x, y)
UGT(x, y)
>>> (x > y).sexpr()
'(bvsgt x y)'
>>> UGT(x, y).sexpr()
'(bvugt x y)'
Definition at line 3624 of file z3py.py.
Referenced by BitVecRef.__gt__().
03624 03625 def UGT(a, b): 03626 """Create the Z3 expression (unsigned) `other > self`. 03627 03628 Use the operator > for signed greater than. 03629 03630 >>> x, y = BitVecs('x y', 32) 03631 >>> UGT(x, y) 03632 UGT(x, y) 03633 >>> (x > y).sexpr() 03634 '(bvsgt x y)' 03635 >>> UGT(x, y).sexpr() 03636 '(bvugt x y)' 03637 """ 03638 _check_bv_args(a, b) 03639 a, b = _coerce_exprs(a, b) 03640 return BoolRef(Z3_mk_bvugt(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.ULE | ( | a, | |
| b | |||
| ) |
Create the Z3 expression (unsigned) `other <= self`.
Use the operator <= for signed less than or equal to.
>>> x, y = BitVecs('x y', 32)
>>> ULE(x, y)
ULE(x, y)
>>> (x <= y).sexpr()
'(bvsle x y)'
>>> ULE(x, y).sexpr()
'(bvule x y)'
Definition at line 3573 of file z3py.py.
Referenced by BitVecRef.__le__().
03573 03574 def ULE(a, b): 03575 """Create the Z3 expression (unsigned) `other <= self`. 03576 03577 Use the operator <= for signed less than or equal to. 03578 03579 >>> x, y = BitVecs('x y', 32) 03580 >>> ULE(x, y) 03581 ULE(x, y) 03582 >>> (x <= y).sexpr() 03583 '(bvsle x y)' 03584 >>> ULE(x, y).sexpr() 03585 '(bvule x y)' 03586 """ 03587 _check_bv_args(a, b) 03588 a, b = _coerce_exprs(a, b) 03589 return BoolRef(Z3_mk_bvule(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.ULT | ( | a, | |
| b | |||
| ) |
Create the Z3 expression (unsigned) `other < self`.
Use the operator < for signed less than.
>>> x, y = BitVecs('x y', 32)
>>> ULT(x, y)
ULT(x, y)
>>> (x < y).sexpr()
'(bvslt x y)'
>>> ULT(x, y).sexpr()
'(bvult x y)'
Definition at line 3590 of file z3py.py.
Referenced by BitVecRef.__lt__().
03590 03591 def ULT(a, b): 03592 """Create the Z3 expression (unsigned) `other < self`. 03593 03594 Use the operator < for signed less than. 03595 03596 >>> x, y = BitVecs('x y', 32) 03597 >>> ULT(x, y) 03598 ULT(x, y) 03599 >>> (x < y).sexpr() 03600 '(bvslt x y)' 03601 >>> ULT(x, y).sexpr() 03602 '(bvult x y)' 03603 """ 03604 _check_bv_args(a, b) 03605 a, b = _coerce_exprs(a, b) 03606 return BoolRef(Z3_mk_bvult(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.Update | ( | a, | |
| i, | |||
| v | |||
| ) |
Return a Z3 store array expression.
>>> a = Array('a', IntSort(), IntSort())
>>> i, v = Ints('i v')
>>> s = Update(a, i, v)
>>> s.sort()
Array(Int, Int)
>>> prove(s[i] == v)
proved
>>> j = Int('j')
>>> prove(Implies(i != j, s[j] == a[j]))
proved
Definition at line 4038 of file z3py.py.
Referenced by Store().
04038 04039 def Update(a, i, v): 04040 """Return a Z3 store array expression. 04041 04042 >>> a = Array('a', IntSort(), IntSort()) 04043 >>> i, v = Ints('i v') 04044 >>> s = Update(a, i, v) 04045 >>> s.sort() 04046 Array(Int, Int) 04047 >>> prove(s[i] == v) 04048 proved 04049 >>> j = Int('j') 04050 >>> prove(Implies(i != j, s[j] == a[j])) 04051 proved 04052 """ 04053 if __debug__: 04054 _z3_assert(is_array(a), "First argument must be a Z3 array expression") 04055 i = a.domain().cast(i) 04056 v = a.range().cast(v) 04057 ctx = a.ctx 04058 return _to_expr_ref(Z3_mk_store(ctx.ref(), a.as_ast(), i.as_ast(), v.as_ast()), ctx)
| def z3py.URem | ( | a, | |
| b | |||
| ) |
Create the Z3 expression (unsigned) remainder `self % other`.
Use the operator % for signed modulus, and SRem() for signed remainder.
>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> URem(x, y)
URem(x, y)
>>> URem(x, y).sort()
BitVec(32)
>>> (x % y).sexpr()
'(bvsmod x y)'
>>> URem(x, y).sexpr()
'(bvurem x y)'
Definition at line 3661 of file z3py.py.
Referenced by BitVecRef.__mod__(), BitVecRef.__rmod__(), and SRem().
03661 03662 def URem(a, b): 03663 """Create the Z3 expression (unsigned) remainder `self % other`. 03664 03665 Use the operator % for signed modulus, and SRem() for signed remainder. 03666 03667 >>> x = BitVec('x', 32) 03668 >>> y = BitVec('y', 32) 03669 >>> URem(x, y) 03670 URem(x, y) 03671 >>> URem(x, y).sort() 03672 BitVec(32) 03673 >>> (x % y).sexpr() 03674 '(bvsmod x y)' 03675 >>> URem(x, y).sexpr() 03676 '(bvurem x y)' 03677 """ 03678 _check_bv_args(a, b) 03679 a, b = _coerce_exprs(a, b) 03680 return BitVecRef(Z3_mk_bvurem(a.ctx_ref(), a.as_ast(), b.as_ast()), a.ctx)
| def z3py.Var | ( | idx, | |
| s | |||
| ) |
Create a Z3 free variable. Free variables are used to create quantified formulas. >>> Var(0, IntSort()) Var(0) >>> eq(Var(0, IntSort()), Var(0, BoolSort())) False
Definition at line 1170 of file z3py.py.
Referenced by QuantifierRef.body(), QuantifierRef.children(), is_pattern(), MultiPattern(), QuantifierRef.pattern(), and RealVar().
01170 01171 def Var(idx, s): 01172 """Create a Z3 free variable. Free variables are used to create quantified formulas. 01173 01174 >>> Var(0, IntSort()) 01175 Var(0) 01176 >>> eq(Var(0, IntSort()), Var(0, BoolSort())) 01177 False 01178 """ 01179 if __debug__: 01180 _z3_assert(is_sort(s), "Z3 sort expected") 01181 return _to_expr_ref(Z3_mk_bound(s.ctx_ref(), idx, s.ast), s.ctx)
| def z3py.When | ( | p, | |
| t, | |||
ctx = None |
|||
| ) |
Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified.
>>> t = When(Probe('size') > 2, Tactic('simplify'))
>>> x, y = Ints('x y')
>>> g = Goal()
>>> g.add(x > 0)
>>> g.add(y > 0)
>>> t(g)
[[x > 0, y > 0]]
>>> g.add(x == y + 1)
>>> t(g)
[[Not(x <= 0), Not(y <= 0), x == 1 + y]]
Definition at line 7144 of file z3py.py.
07144 07145 def When(p, t, ctx=None): 07146 """Return a tactic that applies tactic `t` only if probe `p` evaluates to true. Otherwise, it returns the input goal unmodified. 07147 07148 >>> t = When(Probe('size') > 2, Tactic('simplify')) 07149 >>> x, y = Ints('x y') 07150 >>> g = Goal() 07151 >>> g.add(x > 0) 07152 >>> g.add(y > 0) 07153 >>> t(g) 07154 [[x > 0, y > 0]] 07155 >>> g.add(x == y + 1) 07156 >>> t(g) 07157 [[Not(x <= 0), Not(y <= 0), x == 1 + y]] 07158 """ 07159 p = _to_probe(p, ctx) 07160 t = _to_tactic(t, ctx) 07161 return Tactic(Z3_tactic_when(t.ctx.ref(), p.probe, t.tactic), t.ctx)
| def z3py.With | ( | t, | |
| args, | |||
| keys | |||
| ) |
Return a tactic that applies tactic `t` using the given configuration options.
>>> x, y = Ints('x y')
>>> t = With(Tactic('simplify'), som=True)
>>> t((x + 1)*(y + 2) == 0)
[[2*x + y + x*y == -2]]
Definition at line 6846 of file z3py.py.
Referenced by Goal.prec().
06846 06847 def With(t, *args, **keys): 06848 """Return a tactic that applies tactic `t` using the given configuration options. 06849 06850 >>> x, y = Ints('x y') 06851 >>> t = With(Tactic('simplify'), som=True) 06852 >>> t((x + 1)*(y + 2) == 0) 06853 [[2*x + y + x*y == -2]] 06854 """ 06855 ctx = keys.get('ctx', None) 06856 t = _to_tactic(t, ctx) 06857 p = args2params(args, keys, t.ctx) 06858 return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
| def z3py.Xor | ( | a, | |
| b, | |||
ctx = None |
|||
| ) |
Create a Z3 Xor expression.
>>> p, q = Bools('p q')
>>> Xor(p, q)
Xor(p, q)
>>> simplify(Xor(p, q))
Not(p) == q
Definition at line 1449 of file z3py.py.
01449 01450 def Xor(a, b, ctx=None): 01451 """Create a Z3 Xor expression. 01452 01453 >>> p, q = Bools('p q') 01454 >>> Xor(p, q) 01455 Xor(p, q) 01456 >>> simplify(Xor(p, q)) 01457 Not(p) == q 01458 """ 01459 ctx = _get_ctx(_ctx_from_ast_arg_list([a, b], ctx)) 01460 s = BoolSort(ctx) 01461 a = s.cast(a) 01462 b = s.cast(b) 01463 return BoolRef(Z3_mk_xor(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
| def z3py.ZeroExt | ( | n, | |
| a | |||
| ) |
Return a bit-vector expression with `n` extra zero-bits.
>>> x = BitVec('x', 16)
>>> n = ZeroExt(8, x)
>>> n.size()
24
>>> n
ZeroExt(8, x)
>>> n.sort()
BitVec(24)
>>> v0 = BitVecVal(2, 2)
>>> v0
2
>>> v0.size()
2
>>> v = simplify(ZeroExt(6, v0))
>>> v
2
>>> v.size()
8
Definition at line 3791 of file z3py.py.
03791 03792 def ZeroExt(n, a): 03793 """Return a bit-vector expression with `n` extra zero-bits. 03794 03795 >>> x = BitVec('x', 16) 03796 >>> n = ZeroExt(8, x) 03797 >>> n.size() 03798 24 03799 >>> n 03800 ZeroExt(8, x) 03801 >>> n.sort() 03802 BitVec(24) 03803 >>> v0 = BitVecVal(2, 2) 03804 >>> v0 03805 2 03806 >>> v0.size() 03807 2 03808 >>> v = simplify(ZeroExt(6, v0)) 03809 >>> v 03810 2 03811 >>> v.size() 03812 8 03813 """ 03814 if __debug__: 03815 _z3_assert(isinstance(n, int), "First argument must be an integer") 03816 _z3_assert(is_bv(a), "Second argument must be a Z3 Bitvector expression") 03817 return BitVecRef(Z3_mk_zero_ext(a.ctx_ref(), n, a.as_ast()), a.ctx)
| int _dflt_fpsort_ebits = 11 |
| int _dflt_fpsort_sbits = 53 |
| tuple _error_handler_fptr = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint) |
| tuple _Z3Python_error_handler = _error_handler_fptr(_Z3python_error_handler_core) |
| tuple sat = CheckSatResult(Z3_L_TRUE) |
| tuple unknown = CheckSatResult(Z3_L_UNDEF) |
| tuple unsat = CheckSatResult(Z3_L_FALSE) |
1.7.6.1