本文整理汇总了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")