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 Li,jL_{i,j}:

F=i=1n(j=1mLi,j) F = \bigwedge _{i=1} ^{n} \left( \bigvee _{j=1} ^m L_{i, j} \right)

Horn formula is special class of CNF formula that each clause contains at most one positive literal. For instance, for the literals x1,x2,x3x_1, x_2, x_3,

(¬x1¬x2x3)(¬x1x2)(¬x1¬x3)x2(1) (\neg x_1 \vee \neg x_2 \vee x_3) \wedge (\neg x_1 \vee x_2) \wedge (\neg x_1 \vee \neg x_3) \wedge x_2 \tag{1}

is a Horn formula, but

(¬x1¬x2x3)(x1x2)(¬x1¬x3) (\neg x_1 \vee \neg x_2 \vee x_3) \wedge (x_1 \vee x_2) \wedge (\neg x_1 \vee \neg x_3)

is not a Horn formula. (x1x2)(x_1 \vee x_2) 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(\rightarrow), called implication form. From the fact that pqp \rightarrow q is equilvalent to ¬pq\neg p \vee q, we can convert every clauses in Horn formula into an implication. You can check that Horn formula (1) is easily rewritable into following form.

(x1x2x3)(x1x2)(x1x3false)(truex2) (x_1 \wedge x_2 \rightarrow x_3) \wedge (x_1 \rightarrow x_2) \wedge (x_1 \wedge x_3 \rightarrow false) \wedge (true \rightarrow x_2)

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, TT 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 x=truex=true after several iterations and concluded the formula is unsatisfiable, however there is a satisfying assignment that x=falsex=false?

To show that no such case exists, we need to show that the algorithm assigns x=truex=true, then xx is true for all satisfying assignment. Let’s formalize this by claiming an invariant II for the while loop - forall satisfying assignment AF\mathcal{A} \models F, TAT \subseteq \mathcal{A}.

The invariant holds because

Now we can show that the algorithm always solves Horn-SAT in polynomial time.

Exercise. Refine this algorithm to run in O(N)O(N). (Hint: track the number of negatives in each clause and update the number of negatives after each iteration)