In
classical logic each
propositional formula can be converted to an
equivalent formula that is in CNF. This transformation is based on rules about
logical equivalences:
double negation elimination,
De Morgan's laws, and the
distributive law.
Basic algorithm The algorithm to compute a CNF-equivalent of a given propositional formula \phi builds upon \lnot \phi in
disjunctive normal form (DNF): step 1. \lnot \phi_{DNF} = (C_1 \lor C_2 \lor \ldots \lor C_i \lor \ldots \lor C_m), where each C_i is a conjunction of literals l_{i1} \land l_{i2} \land \ldots \land l_{in_i}.
Step 2: Negate \lnot \phi_{DNF}. Then shift \lnot inwards by applying the
(generalized) De Morgan's equivalences until no longer possible. \begin{align} \phi &\leftrightarrow \lnot \lnot \phi_{DNF} \\ &= \lnot (C_1 \lor C_2 \lor \ldots \lor C_i \lor \ldots \lor C_m) \\ &\leftrightarrow \lnot C_1 \land \lnot C_2 \land \ldots \land \lnot C_i \land \ldots \land \lnot C_m &&\text{// (generalized) D.M.} \end{align} where\begin{align} \lnot C_i &= \lnot (l_{i1} \land l_{i2} \land \ldots \land l_{in_i}) \\ &\leftrightarrow (\lnot l_{i1} \lor \lnot l_{i2} \lor \ldots \lor \lnot l_{in_i}) &&\text{// (generalized) D.M.} \end{align}
Step 3: Remove all double negations.
Example Convert to CNF the propositional formula \phi = ((\lnot (p \land q)) \leftrightarrow (\lnot r \uparrow (p \oplus q))). The (full) DNF equivalent of its negation is \lnot \phi_{DNF} = ( p \land q \land r) \lor ( p \land q \land \lnot r) \lor ( p \land \lnot q \land \lnot r) \lor (\lnot p \land q \land \lnot r) \begin{align} \phi &\leftrightarrow \lnot \lnot \phi_{DNF} \\ &= \lnot \{ ( p \land q \land r) \lor ( p \land q \land \lnot r) \lor ( p \land \lnot q \land \lnot r) \lor (\lnot p \land q \land \lnot r) \} \\ &\leftrightarrow \underline{\lnot( p \land q \land r)} \land \underline{\lnot( p \land q \land \lnot r)} \land \underline{\lnot( p \land \lnot q \land \lnot r)} \land \underline{\lnot(\lnot p \land q \land \lnot r)} &&\text{// generalized D.M. } \\ &\leftrightarrow (\lnot p \lor \lnot q \lor \lnot r) \land (\lnot p \lor \lnot q \lor \lnot \lnot r) \land (\lnot p \lor \lnot \lnot q \lor \lnot \lnot r) \land (\lnot \lnot p \lor \lnot q \lor \lnot \lnot r) &&\text{// generalized D.M. } (4 \times) \\ &\leftrightarrow (\lnot p \lor \lnot q \lor \lnot r) \land (\lnot p \lor \lnot q \lor r) \land (\lnot p \lor q \lor r) \land ( p \lor \lnot q \lor r) &&\text{// remove all } \lnot \lnot \\ &= \phi_{CNF} \end{align}
Conversion by semantic means A CNF equivalent of a formula can be derived from its
truth table. Again, consider the formula \phi = ((\lnot (p \land q)) \leftrightarrow (\lnot r \uparrow (p \oplus q))). The corresponding
truth table is A CNF equivalent of \phi is (\lnot p \lor \lnot q \lor \lnot r) \land (\lnot p \lor \lnot q \lor r) \land (\lnot p \lor q \lor r) \land ( p \lor \lnot q \lor r) Each disjunction reflects an assignment of variables for which \phi evaluates to F(alse). If in such an assignment a variable V • is T(rue), then the literal is set to \lnot V in the disjunction, • is F(alse), then the literal is set to V in the disjunction.
Other approaches Since all propositional formulas can be converted into an equivalent formula in conjunctive normal form, proofs are often based on the assumption that all formulae are CNF. However, in some cases this conversion to CNF can lead to an exponential explosion of the formula. For example, translating the non-CNF formula (X_1 \wedge Y_1) \vee (X_2 \wedge Y_2) \vee \ldots \vee (X_n \wedge Y_n) into CNF produces a formula with 2^n clauses: (X_1 \vee X_2 \vee \ldots \vee X_n) \wedge (Y_1 \vee X_2 \vee \ldots \vee X_n) \wedge (X_1 \vee Y_2 \vee \ldots \vee X_n) \wedge (Y_1 \vee Y_2 \vee \ldots \vee X_n) \wedge \ldots \wedge (Y_1 \vee Y_2 \vee \ldots \vee Y_n). Each clause contains either X_i or Y_i for each i. There exist transformations into CNF that avoid an exponential increase in size by preserving
satisfiability rather than
equivalence. These transformations are guaranteed to only linearly increase the size of the formula, but introduce new variables. For example, the above formula can be transformed into CNF by adding variables Z_1,\ldots,Z_n as follows: (Z_1 \vee \ldots \vee Z_n) \wedge (\neg Z_1 \vee X_1) \wedge (\neg Z_1 \vee Y_1) \wedge \ldots \wedge (\neg Z_n \vee X_n) \wedge (\neg Z_n \vee Y_n). An
interpretation satisfies this formula only if at least one of the new variables is true. If this variable is Z_i, then both X_i and Y_i are true as well. This means that every
model that satisfies this formula also satisfies the original one. On the other hand, only some of the models of the original formula satisfy this one: since the Z_i are not mentioned in the original formula, their values are irrelevant to satisfaction of it, which is not the case in the last formula. This means that the original formula and the result of the translation are
equisatisfiable but not
equivalent. An alternative translation, the
Tseitin transformation, also includes the clauses Z_i \vee \neg X_i \vee \neg Y_i. With these clauses, the formula implies Z_i \equiv X_i \wedge Y_i; this formula is often regarded to "define" Z_i to be a name for X_i \wedge Y_i. == Maximum number of disjunctions ==