def find_predecessor( self, pre_frame: Frame, current_phase: Phase, diag: Diagram ) -> Tuple[z3.CheckSatResult, Union[Optional[MySet[int]], Tuple[ PhaseTransition, Tuple[Phase, Diagram]]]]: t = self.solver.get_translator(KEY_NEW, KEY_OLD) if utils.args.use_z3_unsat_cores: core: Optional[MySet[int]] = MySet() else: core = None with self.solver: with self.solver.mark_assumptions_necessary(): self.solver.add(diag.to_z3(t)) transitions_into = self.automaton.transitions_to_grouped_by_src( current_phase) for src in self._predecessor_precedence( current_phase, list(transitions_into.keys())): transitions = transitions_into[src] assert transitions utils.logger.debug( "check predecessor of %s from %s by %s" % (current_phase.name(), src.name(), transitions)) (sat_res, pre_diag) = self.find_predecessor_from_src_phase( t, pre_frame, src, transitions, diag, core) if sat_res == z3.unsat: continue return (sat_res, pre_diag) if utils.args.use_z3_unsat_cores: assert core is not None ret_core: Optional[MySet[int]] = MySet(sorted(core)) else: ret_core = None return (z3.unsat, ret_core)
def augment_core_for_init(self, p: Phase, diag: Diagram, core: Optional[MySet[int]]) -> None: if core is None or not utils.args.use_z3_unsat_cores: return t = self.solver.get_translator(KEY_ONE) with self.solver: for init in self.fs[0].summary_of(p): self.solver.add(t.translate_expr(init)) self.solver.add(diag.to_z3(t)) res = self.solver.check(diag.trackers) assert res == z3.unsat uc = self.solver.unsat_core() # if utils.logger.isEnabledFor(logging.DEBUG): # utils.logger.debug('uc') # utils.logger.debug(str(sorted(uc, key=lambda y: y.decl().name()))) # utils.logger.debug('assertions') # utils.logger.debug(str(self.solver.assertions())) res = self.solver.check([diag.trackers[i] for i in core]) if res == z3.unsat: utils.logger.debug( 'augment_core_for_init: existing core sufficient') return for x in sorted(uc, key=lambda y: y.decl().name()): assert isinstance(x, z3.ExprRef) core.add(int(x.decl().name()[1:])) if utils.logger.isEnabledFor(logging.DEBUG): utils.logger.debug('augment_core_for_init: new core') utils.logger.debug(str(sorted(core)))