def unsat_core(clauses1, clauses2, implies=None, unlikely=lambda x: False): # print "unsat_core clauses1 = {}, clauses2 = {}".format(clauses1,clauses2) # assert clauses1.defs == [] fmlas = clauses1.fmlas s2 = z3.Solver() alits = [z3.Const("__c%s" % n, z3.BoolSort()) for n, c in enumerate(fmlas)] cc = [z3.Or(z3.Not(a), formula_to_z3(c)) for a, c in zip(alits, fmlas)] foo = [(a, f) for a, f in zip(alits, fmlas) if unlikely(f)] unlikely_lits = [a for a, f in foo] for d in clauses1.defs: s2.add(formula_to_z3(d.to_constraint())) for c in cc: s2.add(c) s2.add(clauses_to_z3(clauses2)) if implies != None: s2.add(not_clauses_to_z3(implies)) is_sat = s2.check(alits) if is_sat == z3.sat: # print "unsat_core model = {}".format(get_model(s2)) return None if unlikely_lits: core = biased_core(s2, alits, unlikely_lits) else: core = minimize_core(s2) core_ids = [get_id(a) for a in core] res = [c for a, c in zip(alits, fmlas) if get_id(a) in core_ids] # print "unsat_core res = {}".format(res) return Clauses(res, list(clauses1.defs))
def unsat_core(clauses1, clauses2, implies=None, unlikely=lambda x: False): # print "unsat_core clauses1 = {}, clauses2 = {}".format(clauses1,clauses2) # assert clauses1.defs == [] fmlas = clauses1.fmlas s2 = z3.Solver() alits = [z3.Const("__c%s" % n, z3.BoolSort()) for n, c in enumerate(fmlas)] cc = [z3.Or(z3.Not(a), formula_to_z3(c)) for a, c in zip(alits, fmlas)] foo = [(a, f) for a, f in zip(alits, fmlas) if unlikely(f)] unlikely_lits = [a for a, f in foo] for d in clauses1.defs: s2.add(formula_to_z3(d.to_constraint())) for c in cc: s2.add(c) s2.add(clauses_to_z3(clauses2)) if implies is not None: s2.add(not_clauses_to_z3(implies)) is_sat = s2.check(alits) if is_sat == z3.sat: # print "unsat_core model = {}".format(get_model(s2)) return None if unlikely_lits: core = biased_core(s2, alits, unlikely_lits) else: core = minimize_core(s2) core_ids = [get_id(a) for a in core] res = [c for a, c in zip(alits, fmlas) if get_id(a) in core_ids] # print "unsat_core res = {}".format(res) return Clauses(res, list(clauses1.defs))