def _exit(self): self._send_command(SmtLibCommand(smtcmd.EXIT, [])) self.solver_stdin.close() self.solver_stdout.close() self.solver.stderr.close() self.solver.terminate() return
def add_assertion(self, formula, named=None): # This is needed because Z3 (and possibly other solvers) incorrectly # recognize N * M * x as a non-linear term formula = formula.simplify() deps = formula.get_free_variables() for d in deps: if d not in self.declared_vars: self._declare_variable(d) self._send_silent_command(SmtLibCommand(smtcmd.ASSERT, [formula]))
def solve(self, assumptions=None): assert assumptions is None self._send_command(SmtLibCommand(smtcmd.CHECK_SAT, [])) ans = self._get_answer() if ans == "sat": return True elif ans == "unsat": return False elif ans == "unknown": raise SolverReturnedUnknownResultError else: raise UnknownSolverAnswerError("Solver returned: " + ans)
def get_value(self, item): self._send_command(SmtLibCommand(smtcmd.GET_VALUE, [item])) lst = self._get_value_answer() assert len(lst) == 1 assert len(lst[0]) == 2 return lst[0][1]
def pop(self, levels=1): self._send_silent_command(SmtLibCommand(smtcmd.POP, [levels]))
def push(self, levels=1): self._send_silent_command(SmtLibCommand(smtcmd.PUSH, [levels]))
def reset_assertions(self): self._send_silent_command(SmtLibCommand(smtcmd.RESET_ASSERTIONS, [])) return
def _declare_variable(self, symbol): cmd = SmtLibCommand(smtcmd.DECLARE_FUN, [symbol]) self._send_silent_command(cmd) self.declared_vars.add(symbol)
def set_logic(self, logic): self._send_silent_command(SmtLibCommand(smtcmd.SET_LOGIC, [logic]))
def set_option(self, name, value): self._send_silent_command( SmtLibCommand(smtcmd.SET_OPTION, [name, value]))