In Boolean logic, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of clauses, where a clause is a disjunction of literals; otherwise put, it is an AND of ORs. As a normal form, it is useful in automated theorem proving. It is similar to the product of sums form used in circuit theory.
Contents
- Examples and non examples
- Conversion into CNF
- First order logic
- Computational complexity
- Converting from first order logic
- References
All conjunctions of literals and all disjunctions of literals are in CNF, as they can be seen as conjunctions of one-literal clauses and conjunctions of a single clause, respectively. As in the disjunctive normal form (DNF), the only propositional connectives a formula in CNF can contain are and, or, and not. The not operator can only be used as part of a literal, which means that it can only precede a propositional variable or a predicate symbol.
In automated theorem proving, the notion "clausal normal form" is often used in a narrower sense, meaning a particular representation of a CNF formula as a set of sets of literals.
Examples and non-examples
All of the following formulas in the variables A, B, C, D, and E are in conjunctive normal form:
The third formula is in conjunctive normal form because it can be seen as the conjunction of the two single-literal clauses
The following formulas are not in conjunctive normal form:
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: the double negative law, De Morgan's laws, and the distributive law.
Since all logical formulae 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
In particular, the generated formula is:
This formula contains
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
An interpretation satisfies this formula only if at least one of the new variables is true. If this variable is
An alternative translation, the Tseitin transformation, includes also the clauses
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 (like any other k-SAT problem with k>2) 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" (for k≥3) by replacing each conjunct with more than k variables
Converting from first-order logic
To convert first-order logic to CNF:
- Convert to negation normal form.
- Eliminate implications and equivalences: repeatedly replace
P → Q with¬ P ∨ Q ; replaceP ↔ Q with( P ∨ ¬ Q ) ∧ ( ¬ P ∨ Q ) . Eventually, this will eliminate all occurrences of→ and↔ . - Move NOTs inwards by repeatedly applying De Morgan's Law. Specifically, replace
¬ ( P ∨ Q ) with( ¬ P ) ∧ ( ¬ Q ) ; replace¬ ( P ∧ Q ) with( ¬ P ) ∨ ( ¬ Q ) ; and replace¬ ¬ P withP ; replace¬ ( ∀ x P ( x ) ) with∃ x ¬ P ( x ) ;¬ ( ∃ x P ( x ) ) with∀ x ¬ P ( x ) . After that, a¬ may occur only immediately before a predicate symbol.
- Eliminate implications and equivalences: repeatedly replace
- Standardize variables
- For sentences like
( ∀ x P ( x ) ) ∨ ( ∃ x Q ( x ) ) which use the same variable name twice, change the name of one of the variables. This avoids confusion later when dropping quantifiers later. For example,∀ x [ ∃ y A n i m a l ( y ) ∧ ¬ L o v e s ( x , y ) ] ∨ [ ∃ y L o v e s ( y , x ) ] is renamed to∀ x [ ∃ y A n i m a l ( y ) ∧ ¬ L o v e s ( x , y ) ] ∨ [ ∃ z L o v e s ( z , x ) ] .
- For sentences like
- Skolemize the statement
- Move quantifiers outwards: repeatedly replace
P ∧ ( ∀ x Q ( x ) ) with∀ x ( P ∧ Q ( x ) ) ; replaceP ∨ ( ∀ x Q ( x ) ) with∀ x ( P ∨ Q ( x ) ) ; replaceP ∧ ( ∃ x Q ( x ) ) with∃ x ( P ∧ Q ( x ) ) ; replaceP ∨ ( ∃ x Q ( x ) ) with∃ x ( P ∨ Q ( x ) ) . These replacements preserve equivalence, since the previous variable standardization step ensured thatx doesn't occur inP . After these replacements, a quantifier may occur only in the initial prefix of the formula, but never inside a¬ ,∧ , or∨ . - Repeatedly replace
∀ x 1 … ∀ x n ∃ y P ( y ) with∀ x 1 … ∀ x n P ( f ( x 1 , … , x n ) ) , wheref is a newn -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.
- Move quantifiers outwards: repeatedly replace
- Drop all universal quantifiers.
- Distribute ORs inwards over ANDs: repeatedly replace
P ∨ ( Q ∧ R ) with( P ∨ Q ) ∧ ( P ∨ R ) .
As an example, the formula saying "Who loves all animals, is in turn loved by someone" is converted into CNF (and subsequently into clause form in the last line) as follows (highlighting replacement rule redices in
Informally, the skolem function
The 2nd last line from above,