All of the following formulas in the variables A, B, C, D, E, and F are in conjunctive normal form:
The third formula is in conjunctive normal form because it is viewed as a "conjunction" with just one conjunct, namely the clause. Incidentally, the last two formulas are also in disjunctive normal form. The following formulas are not in conjunctive normal form:
, since an OR is nested within a NOT
, since an AND is nested within an OR
Every formula can be equivalently written as a formula in conjunctive normal form. In particular this is the case for the three non-examples just mentioned; they are respectively equivalent to the following three formulas, which are in conjunctive normal form:
Conversion into CNF
Every propositional formula can be converted into 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. 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 following non-CNF formula into CNF produces a formula with clauses: In particular, the generated formula is: This formula contains clauses; each clause contains either or for each. 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 as follows: An interpretation satisfies this formula only if at least one of the new variables is true. If this variable is, then both and 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 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, includes also the clauses. With these clauses, the formula implies ; this formula is often regarded to "define" to be a name for.
First-order logic
In first order logic, conjunctive normal form can be taken further to yield the clausal normal form of a logical formula, which can be then used to perform first-order resolution. In resolution-based automated theorem-proving, a CNF formula See [|below] for an example.
Computational complexity
An important set of problems in computational complexity involves finding assignments to the variables of a boolean formula expressed in Conjunctive Normal Form, such that the formula is true. The k-SAT problem is the problem of finding a satisfying assignment to a boolean formula expressed in CNF in which each disjunction contains at most k variables. 3-SAT is NP-complete while 2-SAT is known to have solutions in polynomial time. As a consequence, the task of converting a formula into a DNF, preserving satisfiability, is NP-hard; dually, converting into CNF, preserving validity, is also NP-hard; hence equivalence-preserving conversion into DNF or CNF is again NP-hard. Typical problems in this case involve formulas in "3CNF": conjunctive normal form with no more than three variables per conjunct. Examples of such formulas encountered in practice can be very large, for example with 100,000 variables and 1,000,000 conjuncts. A formula in CNF can be converted into an equisatisfiable formula in "kCNF" by replacing each conjunct with more than k variables by two conjuncts and with a new variable, and repeating as often as necessary.
# Eliminate implications and equivalences: repeatedly replace with ; replace with. Eventually, this will eliminate all occurrences of and.
#Move NOTs inwards by repeatedly applying De Morgan's Law. Specifically, replace with ; replace with ; and replace with ; replace with ; with. After that, a may occur only immediately before a predicate symbol.
Standardize variables
#For sentences like which use the same variable name twice, change the name of one of the variables. This avoids confusion later when dropping quantifiers. For example, is renamed to.
#Move quantifiers outwards: repeatedly replace with ; replace with ; replace with ; replace with. These replacements preserve equivalence, since the previous variable standardization step ensured that doesn't occur in. After these replacements, a quantifier may occur only in the initial prefix of the formula, but never inside a,, or.
#Repeatedly replace with, where is a new -ary function symbol, a so-called "skolem function". This is the only step that preserves only satisfiability rather than equivalence. It eliminates all existential quantifiers.
Distribute ORs inwards over ANDs: repeatedly replace with.
As an example, the formula saying "Anyone who loves all animals, is in turn loved by someone" is converted into CNF as follows : Informally, the skolem function can be thought of as yielding the person by whom is loved, while yields the animal that doesn't love. The 3rd last line from below then reads as " doesn't love the animal, or else is loved by ". The 2nd last line from above,, is the CNF.