Resolution
From two clauses, one containing ℓ and the other ¬ℓ, build a new clause holding the rest of both. Reaching the empty clause shows the clauses are unsatisfiable; proof by contradiction works this way.
From the clauses p ∨ A and ¬p ∨ B follows A ∨ B: if p is true, B must be, and if it is false, A must be.
The new clause is the resolvent.
- Time:
exponential in the worst case - Space:
up to 3^n clauses on n variables - Johnsonbaugh, chapter 1
Proving q from p ∨ q, ¬p ∨ r and ¬r: add the negated conclusion (¬q) and reach the empty clause.
def resolution(clauses):# clauses: "p|q, ~p|r, ~q": a conjunction of disjunctions. Each clause becomes a sorted list of literals.known = []rows = [] # for the picture: number, clause, where it came fromfor part in clauses.split(","):lits = sorted(set(x.strip() for x in part.split("|") if x.strip()))if lits and lits not in known:known.append(lits)rows.append([len(rows) + 1, " ∨ ".join(lits), "given"])count = len(known)i = 0while i < len(known):for j in range(i):for lit in known[i]:other = lit[1:] if lit.startswith("~") else "~" + litif other not in known[j]:continuer = []for x in known[i] + known[j]:if x != lit and x != other and x not in r:r.append(x)r.sort()tautology = Falsefor x in r:if "~" + x in r:tautology = Trueif tautology or r in known:continueknown.append(r)rows.append([len(rows) + 1, " ∨ ".join(r) if r else "□", str(j + 1) + ", " + str(i + 1)])if not r:return Falsei = i + 1return True
Start
The table is still empty.
Local variables
Orange = changed in this step
Call stack
- resolution()line 1
Explanation
The resolution rule
From the clauses p ∨ A and ¬p ∨ B follows A ∨ B: if p is true, B must be, and if it is false, A must be.
The new clause is the resolvent.
Proof by resolution
To prove that q follows from some premises:
- write the premises and the negation of
qas clauses (CNF); - resolve as long as anything new appears;
- if the empty clause
□appears (fromrand¬r, say), the set is unsatisfiable, soqfollows (proof by contradiction).
Resolution is complete: if a set is unsatisfiable, it eventually produces the empty clause. If nothing new appears and the empty clause has not, the set is satisfiable.
The input
Clauses are separated by commas and the literals of a clause by |; ~ means not. The variables are p, q, r
and s.