本文整理匯總了Python中z3.unsat方法的典型用法代碼示例。如果您正苦於以下問題:Python z3.unsat方法的具體用法?Python z3.unsat怎麽用?Python z3.unsat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類z3
的用法示例。
在下文中一共展示了z3.unsat方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import unsat [as 別名]
def check(expr_in, expr_out):
"""Check that expr_in is always equals to expr_out"""
print("Ensure %s = %s" % (expr_in, expr_out))
solver = z3.Solver()
solver.add(trans.from_expr(expr_in) != trans.from_expr(expr_out))
result = solver.check()
if result != z3.unsat:
print("ERROR: a counter-example has been founded:")
model = solver.model()
print(model)
print("Reinjecting in the simplifier:")
to_rep = {}
expressions = expr_in.get_r().union(expr_out.get_r())
for expr in expressions:
value = model.eval(trans.from_expr(expr))
if hasattr(value, "as_long"):
new_val = ExprInt(value.as_long(), expr.size)
else:
raise RuntimeError("Unable to reinject %r" % value)
to_rep[expr] = new_val
new_expr_in = expr_in.replace_expr(to_rep)
new_expr_out = expr_out.replace_expr(to_rep)
print("Check %s = %s" % (new_expr_in, new_expr_out))
simp_in = expr_simp_explicit(new_expr_in)
simp_out = expr_simp_explicit(new_expr_out)
print("[%s] %s = %s" % (simp_in == simp_out, simp_in, simp_out))
# Either the simplification does not stand, either the test is wrong
raise RuntimeError("Bad simplification")
示例2: trim_unrechable_states
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import unsat [as 別名]
def trim_unrechable_states(self):
# (parent, trace, child) tuples
pending_parent_trace_child_tuples = [(None, None, self.root_wstate)]
deleted_counter = 0
s = Solver()
while(len(pending_parent_trace_child_tuples)):
s.push()
parent_wstate, trace, curr_wstate = pending_parent_trace_child_tuples.pop()
if curr_wstate.status != WorldStateStatus.REACHABLE:
s.add(curr_wstate.constraints)
res = s.check()
if res == sat:
curr_wstate.status = WorldStateStatus.REACHABLE
elif res == unsat:
curr_wstate.status = WorldStateStatus.UNREACHABLE
elif res == z3.unknown:
print(curr_wstate.get_full_trace())
raise Exception("pdb")
if curr_wstate.status == WorldStateStatus.REACHABLE:
if curr_wstate != self.root_wstate:
parent_wstate.trace_to_children[trace].append(curr_wstate)
for child_trace, children in curr_wstate.trace_to_children.items():
for child_wstate in children:
pending_parent_trace_child_tuples.append((curr_wstate, child_trace, child_wstate))
curr_wstate.trace_to_children.clear()
else:
curr_wstate.status = WorldStateStatus.DELETED
self.gen_to_wstates[curr_wstate.gen].remove(curr_wstate)
deleted_counter += 1
s.pop()
logging.info('%d WorldStates are deleted', deleted_counter)
logging.info('SVM initialized')
示例3: resolve_address
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import unsat [as 別名]
def resolve_address(wstate, address_bv, frame_predicates=[]):
if is_bv_concrete(address_bv):
return get_concrete_int(address_bv)
frame_constraints = [wstate.predicate_to_constraints[fpred] for fpred in frame_predicates]
solver = z3.Solver()
solver.set('timeout', 2000)
solver.add(frame_constraints)
res = solver.check()
assert res != z3.unsat
model = solver.model()
address = model.evaluate(address_bv)
if not is_bv_concrete(address):
return None
address = address.as_long()
return address if address in wstate.address_to_account else None
示例4: check_wstate_reachable
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import unsat [as 別名]
def check_wstate_reachable(wstate, timeout=None):
s = z3.Solver()
if timeout is not None:
s.set('timeout', timeout)
s.add(wstate.constraints)
res = s.check()
if res != z3.unsat:
return True
else:
logging.debug(f'deleted wstate {wstate.trace}; len constraints:{len(wstate.constraints)}')
return False
示例5: isSatisfiable
# 需要導入模塊: import z3 [as 別名]
# 或者: from z3 import unsat [as 別名]
def isSatisfiable(self):
r = self.solver.check()
if r == z3.sat:
return True
elif r == z3.unsat:
return False
else:
raise ValueError("got neither sat nor unsat from solver")