Horn Formula Satisfiability is Polynomial Time Decidable
Mar. 18, 2023
A propositional logic formula is in conjuncitve normal form (CNF) if it is a conjunction of disjunctions of literals :
Horn formula is special class of CNF formula that each clause contains at most one positive literal. For instance, for the literals ,
is a Horn formula, but
is not a Horn formula. is a clause that contains two positive literals.
In general, satisfiability of CNF formula is NP-complete by Cook-Levin theorem. What makes Horn formula special is, satifiability of any Horn formula is solvable in polynomial time. In other words, Horn formula is a special type of CNF formula that poly-time satisfiability is guaranteed. Let’s call the satisfiability problem of Horn formula as Horn-SAT.
Implication Form
Horn formulas can be rewritten as conjunections of implications(), called implication form. From the fact that is equilvalent to , we can convert every clauses in Horn formula into an implication. You can check that Horn formula (1) is easily rewritable into following form.
Horn Satisfiability Algorithm
Theorem. Horn-SAT is polynomial-time solvable.
To show this, claim that following algorithm is a Horn-SAT solver.
In this algorithm, is an encoding of an assignment which collects only true variables. It starts with emptyset, which means every variable is assigned as false. After that, while loop chooses unsatisfied loop and change variables into true until there is no unsatisfied loop.
Soundness
It is untrivial that this algorithm is valid for all Horn-SAT. What happens if it goes the wrong way? What if, the algorithm assigns some variable after several iterations and concluded the formula is unsatisfiable, however there is a satisfying assignment that ?
To show that no such case exists, we need to show that the algorithm assigns , then is true for all satisfying assignment. Let’s formalize this by claiming an invariant for the while loop - forall satisfying assignment , .
The invariant holds because
(base) If , it is straight-forward. For all (satisfying) assignment , .
(step) Suppose that for all satisfying assignment and does not satisfy , then satisfies the invariant. ( is the positive variable in picked unsatisfied clause)
Let the picked unsatisfied clause as where are variables. Then is true, and is false. Therefore since these variables should be assigned as true. By the assumption, for every satisfying assignment, so . Since is a satisfying assignment, holds, so for every .
Now we can show that the algorithm always solves Horn-SAT in polynomial time.
If the algorithm returns satisfying assignment , the formula is satisfiable.
If algorithm returns UNSAT, take a look on the last iteration of while loop. By invariant , forall satisfying assignment, and there exists an unsatisfied clause that . Then by the same argument hence the clause is unsatisfied in . Therefore, there is no such such that satisfies , so is unsatisfiable.
The algorithm ends in finite time. has finite number of variable, and the while loop assigns one variable as true in each iteration. It takes quadratic time to finish this in the worst case where is number of literals. quadratic time is because, the satisfied clause can be updated to unsatisfied as the algorithm assigns true to variables. Thus this naive algorithm needs to check all clauses to identify an unsatisfied clause.
Exercise. Refine this algorithm to run in . (Hint: track the number of negatives in each clause and update the number of negatives after each iteration)