def eresolution(clause) -> list: res = [] for l in range(len(clause)): lit = clause.getLiteral(l) if lit.atom[0] == '=' and lit.isNegative(): left = lit.atom[1] right = lit.atom[2] unifier = mgu(left, right) if unifier is not None: others = [] for ll in range(len(clause)): lit2 = clause.getLiteral(ll) if ll != l: if unifier is None: others.append(lit2) else: others.append(lit2.instantiate(unifier)) new_clause = Clause(others) new_clause.setDerivation( flatDerivation("eresolution", [clause, clause])) res.append(new_clause) return res
def wFormulaClausify(wf): """ Convert a formula into Clause Normal Form. """ wf = wFormulaCNF(wf) clauses = formulaCNFSplit(wf) for c in clauses: c.setDerivation(flatDerivation("split_conjunct", [wf])) return clauses
def negateConjecture(wform): """ If wform is a conjecture, return its negation. Otherwise return it unchanged. """ if wform.type == "conjecture": negf = Formula("~", wform.formula) negw = WFormula(negf, "negated_conjecture") negw.setDerivation(flatDerivation("assume_negation",\ [wform],\ "status(cth)")) return negw else: return wform
def factor(clause, lit1, lit2): """ Check if it is possible to form a factor between lit1 and lit2. If yes, return it, otherwise return None. """ l1 = clause.getLiteral(lit1) l2 = clause.getLiteral(lit2) if l1.isNegative() != l2.isNegative(): return None sigma = mgu(l1.atom, l2.atom) if sigma == None: return None lits = [l.instantiate(sigma) for l in clause.literals if l != l2] res = clauses.Clause(lits) res.removeDupLits() res.setDerivation(flatDerivation("factor", [clause])) return res
def wFormulaCNF(wf): """ Convert a (wrapped) formula to Conjunctive Normal Form. """ f, m0 = formulaOpSimplify(wf.formula) f, m1 = formulaSimplify(f) if m0 or m1: tmp = WFormula(f, wf.type) tmp.setDerivation(flatDerivation("fof_simplification", [wf])) wf = tmp f, m = formulaNNF(f, 1) if m: tmp = WFormula(f, wf.type) tmp.setDerivation(flatDerivation("fof_nnf", [wf])) wf = tmp f, m = formulaMiniScope(f) if m: tmp = WFormula(f, wf.type) tmp.setDerivation(flatDerivation("shift_quantors", [wf])) wf = tmp f = formulaVarRename(f) if not f.isEqual(wf.formula): tmp = WFormula(f, wf.type) tmp.setDerivation(flatDerivation("variable_rename", [wf])) wf = tmp f = formulaSkolemize(f) if not f.isEqual(wf.formula): tmp = WFormula(f, wf.type) tmp.setDerivation(flatDerivation("skolemize", [wf], "status(esa)")) wf = tmp f = formulaShiftQuantorsOut(f) if not f.isEqual(wf.formula): tmp = WFormula(f, wf.type) tmp.setDerivation(Derivation("shift_quantors", [wf])) wf = tmp f = formulaDistributeDisjunctions(f) if not f.isEqual(wf.formula): tmp = WFormula(f, wf.type) tmp.setDerivation(flatDerivation("distribute", [wf])) wf = tmp return wf
def resolution(clause1, lit1, clause2, lit2): """ Implementation of the Resolution rule. lit1 and lit2 are indices of literals in clause1 and clause2, respectively, so clause1|lit1 and clause2|lit2 are literals. Try to resolve clause1|lit1 against clause2|lit2. If this is possible, return the resolvent. Otherwise, return None. """ l1 = clause1.getLiteral(lit1) l2 = clause2.getLiteral(lit2) if l1.isNegative() == l2.isNegative(): return None sigma = mgu(l1.atom, l2.atom) if sigma is None: return None lits1 = [l.instantiate(sigma) for l in clause1.literals if l!=l1] lits2 = [l.instantiate(sigma) for l in clause2.literals if l!=l2] lits1.extend(lits2) res = clauses.Clause(lits1) res.removeDupLits() res.setDerivation(flatDerivation("resolution", [clause1, clause2])) return res
proof = res.orderedDerivation() enableDerivationOutput() print("# SZS output start CNFRefutation") for s in proof: print(s) print("# SZS output end CNFRefutation") disableDerivationOutput() else: if problem.isFof and problem.hasConj: print("# SZS status CounterSatisfiable") else: print("# SZS status Satisfiable") if proofObject: dummy = Derivable( "dummy", flatDerivation("pseudoreference", state.processed.clauses)) sat = dummy.orderedDerivation() enableDerivationOutput() print("# SZS output start Saturation") for s in sat[:-1]: print(s) print("# SZS output end Saturation") disableDerivationOutput() print(state.statisticsStr()) # We use the resources interface to get and print the CPU time resources = getrusage(RUSAGE_SELF) print("# -------- CPU Time ---------") print("# User time : %.3f s" % (resources.ru_utime, )) print("# System time : %.3f s" % (resources.ru_stime, )) print("# Total time : %.3f s" %