def _mk_lemma_parser(self): if self._lemma_parser is not None: return self._lemma_parser = SmtLibZ3Parser() # register symbols that are expected to appear in the lemma for i, symbol in enumerate(self._pysmt_sig): name = self._mk_lemma_arg_name(i) self._lemma_parser.cache.bind(name, symbol)
def load_model_from_smt2_str(smt2_str): model = FolModel() b = io.StringIO(smt2_str) parser = SmtLibZ3Parser() for cmd in parser.get_command_generator(b): if type(cmd) == SmtLibCommand and cmd.name == 'define-fun': name = cmd.args[0] lmbd = define_fun_to_lambda(parser.env, cmd) model[name] = lmbd return model
def load_model_from_file(fname): log.info('Loading model file {}'.format(fname)) model = FolModel() with open(fname, 'r') as script: parser = SmtLibZ3Parser() for cmd in parser.get_command_generator(script): if type(cmd) == SmtLibCommand and cmd.name == 'define-fun': name = cmd.args[0] lmbd = define_fun_to_lambda(parser.env, cmd) model[name] = lmbd return model
def back_via_smtlib(self, expr): """Back convert a Z3 Expression by translation to SMT-LIB.""" from six import StringIO from pysmt.smtlib.parser import SmtLibZ3Parser parser = SmtLibZ3Parser(self.env) z3.Z3_set_ast_print_mode(expr.ctx.ref(), z3.Z3_PRINT_SMTLIB2_COMPLIANT) s = z3.Z3_benchmark_to_smtlib_string(expr.ctx.ref(), None, None, None, None, 0, None, expr.ast) stream_in = StringIO(s) r = parser.get_script(stream_in).get_last_formula(self.mgr) key = (askey(expr), None) self._back_memoization[key] = r return r