def solve(self, assumptions=None): if assumptions is not None: bool_ass = [] other_ass = [] for x in assumptions: if x.is_literal(): bool_ass.append(self.converter.convert(x)) else: other_ass.append(x) if len(other_ass) > 0: self.push() self.add_assertion(self.mgr.And(other_ass)) self.pending_pop = True res = self.z3.check(*bool_ass) else: res = self.z3.check() sres = str(res) assert sres in ['unknown', 'sat', 'unsat'] if sres == 'unknown': raise SolverReturnedUnknownResultError() return sres == 'sat'
def _solve(self, assumptions=None): if assumptions is None: assumptions = () bool_ass = [] other_ass = [] for x in assumptions: if x.is_literal(): bool_ass.append(self.converter.convert(x)) else: other_ass.append(x) if other_ass: self.push() self.add_assertion(self.mgr.And(other_ass)) self.pending_pop = True if bool_ass: res = self.solver.check_sat_assuming(bool_ass) else: res = self.solver.check_sat() if res.is_sat(): return True elif res.is_unsat(): return False else: raise SolverReturnedUnknownResultError()
def solve(self, assumptions=None): res = None if assumptions is not None: bool_ass = [] other_ass = [] for x in assumptions: if x.is_literal(): bool_ass.append(self.converter.convert(x)) else: other_ass.append(x) if len(other_ass) > 0: self.push() self.add_assertion(self.mgr.And(other_ass)) self.pending_pop = True if len(bool_ass) > 0: res = mathsat.msat_solve_with_assumptions(self.msat_env, bool_ass) else: res = mathsat.msat_solve(self.msat_env) else: res = mathsat.msat_solve(self.msat_env) assert res in [mathsat.MSAT_UNKNOWN,mathsat.MSAT_SAT,mathsat.MSAT_UNSAT] if res == mathsat.MSAT_UNKNOWN: raise SolverReturnedUnknownResultError() return res == mathsat.MSAT_SAT
def walk_symbol(self, formula, **kwargs): symbol_type = formula.symbol_type() if symbol_type.is_bool_type(): res = self._btor.Var(self._btor.BitVecSort(1), formula.symbol_name()) elif symbol_type.is_real_type(): raise ConvertExpressionError elif symbol_type.is_int_type(): raise ConvertExpressionError elif symbol_type.is_array_type(): # BTOR supports only Arrays of Type (BV, BV) index_type = symbol_type.index_type elem_type = symbol_type.elem_type if not (index_type.is_bv_type() and elem_type.is_bv_type()): raise ConvertExpressionError("BTOR supports only Array(BV,BV). "\ "Type '%s' was given." % str(symbol_type)) res = self._btor.Array( self._btor.ArraySort(self._btor.BitVecSort(index_type.width), self._btor.BitVecSort(elem_type.width)), formula.symbol_name()) elif symbol_type.is_bv_type(): res = self._btor.Var(self._btor.BitVecSort(formula.bv_width()), formula.symbol_name()) else: raise SolverReturnedUnknownResultError("Unknown type for BTOR") self.declared_vars[formula] = res return res
def solve(self, assumptions=None): if assumptions is not None: conj_assumptions = self.environment.formula_manager.And( assumptions) cvc4_assumption = self.converter.convert(conj_assumptions) res = self.cvc4.checkSat(cvc4_assumption) else: res = self.cvc4.checkSat() # Convert returned type res_type = res.isSat() if res_type == CVC4.Result.SAT_UNKNOWN: raise SolverReturnedUnknownResultError() else: return res_type == CVC4.Result.SAT return
def _solve(self, assumptions=None): count = 0 if assumptions is not None: bool_ass = [] other_ass = [] assert(len(self.yices_assumptions) == 0) for x in assumptions: if x.is_literal(): self.yices_assumptions.append(self.get_term(x)) count += 1 else: other_ass.append(x) if len(other_ass) > 0: self.push() self.add_assertion(self.mgr.And(other_ass)) self.pending_pop = True if len(self.yices_assumptions) == 0: out = yicespy.yices_check_context(self.yices, self.yices_params) else: out = yicespy.yices_check_context_with_assumptions(self.yices, self.yices_params, len(self.yices_assumptions), yicespy.make_term_array(self.yices_assumptions)) if self.model is not None: yicespy.yices_free_model(self.model) self.model = None if count != 0: for i in range(count): self.yices_assumptions.pop() sres = 'unknown' assert out in [STATUS_SAT, STATUS_UNSAT, STATUS_UNKNOWN] if out == STATUS_UNKNOWN: raise SolverReturnedUnknownResultError() elif out == STATUS_SAT: sres = 'sat' self.model = yicespy.yices_get_model(self.yices, 1) else: sres = 'unsat' return (sres == 'sat')
def solve(self, assumptions=None): if assumptions is not None: self.push() self.add_assertion(self.mgr.And(assumptions)) self.pending_pop = True out = yicespy.yices_check_context(self.yices, self.yices_params) if self.model is not None: yicespy.yices_free_model(self.model) self.model = None assert out in [STATUS_SAT, STATUS_UNSAT, STATUS_UNKNOWN] if out == STATUS_UNKNOWN: raise SolverReturnedUnknownResultError() elif out == STATUS_SAT: self.model = yicespy.yices_get_model(self.yices, 1) return True else: return False