def check_bmc(s: Solver, safety: Expr, depth: int, preconds: Optional[Iterable[Expr]] = None, minimize: Optional[bool] = None) -> Optional[Trace]: prog = syntax.the_program if preconds is None: preconds = (init.expr for init in prog.inits()) t = s.get_translator(depth + 1) with s.new_frame(): for precond in preconds: s.add(t.translate_expr(precond)) s.add(t.translate_expr(syntax.New(syntax.Not(safety), depth))) for i in range(depth): s.add(t.translate_expr(New(safety, i))) assert_any_transition(s, t, i, allow_stutter=False) res = s.check() if res == solver.sat: z3m = s.model(minimize=minimize) m = Z3Translator.model_to_trace(z3m, depth + 1) return m elif res == solver.unknown: print('unknown!') return None
def check_solver(s: Solver, num_states: int, minimize: Optional[bool] = None) -> Optional[Trace]: res = s.check() m = None if res != solver.unsat: if res != solver.sat: assert res == solver.unknown utils.logger.always_print('unknown!') utils.logger.always_print('reason unknown: ' + s.reason_unknown()) assert False, 'unexpected unknown from z3!' assert res == solver.sat m = Z3Translator.model_to_trace(s.model(minimize=minimize), num_states) return m
def check_implication( s: Solver, hyps: Iterable[Expr], concs: Iterable[Expr], minimize: Optional[bool] = None) -> Optional[z3.ModelRef]: t = s.get_translator(1) with s.new_frame(): for e in hyps: s.add(t.translate_expr(e)) for e in concs: with s.new_frame(): s.add(t.translate_expr(Not(e))) if s.check() != solver.unsat: return s.model(minimize=minimize) return None
def check_two_state_implication_all_transitions( s: Solver, old_hyps: Iterable[Expr], new_conc: Expr, minimize: Optional[bool] = None, ) -> Optional[Tuple[z3.ModelRef, DefinitionDecl]]: t = s.get_translator(2) prog = syntax.the_program with s.new_frame(): for h in old_hyps: s.add(t.translate_expr(h)) s.add(t.translate_expr(New(Not(new_conc)))) for trans in prog.transitions(): with s.new_frame(): s.add(t.translate_expr(trans.as_twostate_formula(prog.scope))) res = s.check() assert res in (solver.sat, solver.unsat), res if res != solver.unsat: return s.model(minimize=minimize), trans return None