conjunctive normal form

{{Short description|Standard form of Boolean function}}

{{distinguish|Chomsky normal form}}

In Boolean algebra, a formula is in conjunctive normal form (CNF) or clausal normal form if it is a conjunction of one or more clauses, where a clause is a disjunction of literals; otherwise put, it is a product of sums or an AND of ORs.

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.

Definition

A logical formula is considered to be in CNF if it is a conjunction of one or more disjunctions of one or more literals. As in disjunctive normal form (DNF), the only propositional operators in CNF are or (\vee), and (\and), and not (\neg). The not operator can only be used as part of a literal, which means that it can only precede a propositional variable.

The following is a context-free grammar for CNF:

: CNF \, \to \, Disjunct \, \mid \, Disjunct \, \land \, CNF

: Disjunct \, \to \, Literal \, \mid\, Literal \, \lor \, Disjunct

: Literal \, \to \, Variable \, \mid \, \, \neg \, Variable

Where Variable is any variable.

All of the following formulas in the variables A,B,C,D,E, and F are in conjunctive normal form:

  • (A \lor \neg B \lor \neg C) \land (\neg D \lor E \lor F \lor D \lor F)
  • (A \lor B) \land (C)
  • (A \lor B)
  • (A)

The following formulas are not in conjunctive normal form:

  • \neg (A \land B), since an AND is nested within a NOT
  • \neg(A \lor B) \land C, since an OR is nested within a NOT
  • A \land (B \lor (D \land E)), since an AND is nested within an OR

Conversion to CNF

In classical logic each propositional formula can be converted to an equivalent formula that is in CNF.{{sfn|Howson|2005|page=46}} 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.

Then \lnot \phi_{DNF} is converted to \phi_{CNF} by swapping ANDs with ORs and vice versa while negating all the literals. Remove all \lnot \lnot.{{sfn|Howson|2005|page=46}}

== Conversion by syntactic means ==

Convert to CNF the propositional formula \phi.

Step 1: Convert its negation to disjunctive normal form.see {{slink|Disjunctive normal form#Conversion to DNF}}

\lnot \phi_{DNF} = (C_1 \lor C_2 \lor \ldots \lor C_i \lor \ldots \lor C_m),{{refn|1 \le m \le maximum number of conjunctions for \phi}}

where each C_i is a conjunction of literals l_{i1} \land l_{i2} \land \ldots \land l_{in_i}.{{refn|1 \le in_i \le maximum number of literals for \phi}}

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))).{{refn|name=phiverbose|1=\phi = ((NOT (p AND q)) IFF ((NOT r) NAND (p XOR 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))).{{refn|name=phiverbose}}

The corresponding truth table is

class="wikitable" style="text-align:center; padding-left: 1.5em;"

! p

! q

! r

! style="background:black"|

! (

! \lnot

! (p \land q)

! )

! \leftrightarrow

! (

! \lnot r

! \uparrow

! (p \oplus q)

! )

style="background:lightgreen"|Tstyle="background:lightgreen"|Tstyle="background:lightgreen"|Tstyle="background:black"|FTstyle="background:papayawhip" | FFTF
style="background:lightgreen"|Tstyle="background:lightgreen"|Tstyle="background:lightgreen"|Fstyle="background:black"|FTstyle="background:papayawhip" | FTTF
TFTstyle="background:black"|TFstyle="background:papayawhip" | TFTT
style="background:lightgreen"|Tstyle="background:lightgreen"|Fstyle="background:lightgreen"|Fstyle="background:black"|TFstyle="background:papayawhip" | FTFT
FTTstyle="background:black"|TFstyle="background:papayawhip" | TFTT
style="background:lightgreen"|Fstyle="background:lightgreen"|Tstyle="background:lightgreen"|Fstyle="background:black"|TFstyle="background:papayawhip" | FTFT
FFTstyle="background:black"|TFstyle="background:papayawhip" | TFTF
FFFstyle="background:black"|TFstyle="background:papayawhip" | TTTF

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.{{sfn|Tseitin |1968}}{{sfn|Jackson|Sheridan|2004}} 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, includes also 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

Consider a propositional formula with n variables, n \ge 1.

There are 2n possible literals: L = \{ p_1, \lnot p_1, p_2, \lnot p_2, \ldots, p_n, \lnot p_n\}.

L has (2^{2n} -1) non-empty subsets.{{refn|\left|\mathcal{P}(L)\right| = 2^{2n}}}

This is the maximum number of disjunctions a CNF can have.{{refn|name=noreps|It is assumed that repetitions and variations (like (a \land b) \lor (b \land a) \lor (a \land b \land b)) based on the commutativity and associativity of \lor and \land do not occur.}}

All truth-functional combinations can be expressed with 2^{n} disjunctions, one for each row of the truth table.
In the example below they are underlined.

Example

Consider a formula with two variables p and q.

The longest possible CNF has 2^{(2 \times 2)} -1 = 15 disjunctions:{{refn|name=noreps}}

\begin{array}{lcl}

(\lnot p) \land (p) \land (\lnot q) \land (q) \land \\

(\lnot p \or p) \land

\underline{(\lnot p \or \lnot q)} \land

\underline{(\lnot p \or q)} \land

\underline{( p \or \lnot q)} \land

\underline{( p \or q)} \land

(\lnot q \or q) \land \\

(\lnot p \or p \or \lnot q) \land

(\lnot p \or p \or q) \land

(\lnot p \or \lnot q \or q) \land

( p \or \lnot q \or q) \land \\

(\lnot p \or p \or \lnot q \or q)

\end{array}

This formula is a contradiction. It can be simplified to (\neg p \land p) or to (\neg q \land q), which are also contradictions, as well as valid CNFs.

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,{{refn|since one way to check a CNF for satisfiability is to convert it into a DNF, the satisfiability of which can be checked in linear time}} 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 X_1 \vee \ldots \vee X_k \vee \ldots \vee X_n by two conjuncts X_1 \vee \ldots \vee X_{k-1} \vee Z and \neg Z \vee X_k \lor \ldots \vee X_n with {{mvar|Z}} a new variable, and repeating as often as necessary.

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

|(l_{11}\lor\ldots\lorl_{1n_1})\land\ldots\land(l_{m1}\lor\ldots\lorl_{mn_m}),{{refn|1 \le m \le maximum number of disjunctions
1 \le in_i \le maximum number of literals}} is commonly represented as a set of sets
| \{\{l_{11},\ldots,l_{1n_1}\},\ldots,\{l_{m1},\ldots,l_{mn_m}\}\}.

See below for an example.

=Converting from first-order logic=

To convert first-order logic to CNF:{{sfn|Russel|Norvig|2010|pages=345-347|loc=9.5.1 Conjunctive normal form for first-order logic}}

  1. Convert to negation normal form.
  2. Eliminate implications and equivalences: repeatedly replace P \rightarrow Q with \lnot P \lor Q; replace P \leftrightarrow Q with (P \lor \lnot Q) \land (\lnot P \lor Q). Eventually, this will eliminate all occurrences of \rightarrow and \leftrightarrow.
  3. Move NOTs inwards by repeatedly applying De Morgan's law. Specifically, replace \lnot (P \lor Q) with (\lnot P) \land (\lnot Q); replace \lnot (P \land Q) with (\lnot P) \lor (\lnot Q); and replace \lnot\lnot P with P; replace \lnot (\forall x P(x)) with \exists x \lnot P(x); \lnot (\exists x P(x)) with \forall x \lnot P(x). After that, a \lnot may occur only immediately before a predicate symbol.
  4. Standardize variables
  5. For sentences like (\forall x P(x)) \lor (\exists 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. For example, \forall x [\exists y \mathrm{Animal}(y) \land \lnot \mathrm{Loves}(x, y)] \lor [\exists y \mathrm{Loves}(y, x)] is renamed to \forall x [\exists y \mathrm{Animal}(y) \land \lnot \mathrm{Loves}(x, y)] \lor [\exists z \mathrm{Loves}(z,x)].
  6. Skolemize the statement
  7. Move quantifiers outwards: repeatedly replace P \land (\forall x Q(x)) with \forall x (P \land Q(x)); replace P \lor (\forall x Q(x)) with \forall x (P \lor Q(x)); replace P \land (\exists x Q(x)) with \exists x (P \land Q(x)); replace P \lor (\exists x Q(x)) with \exists x (P \lor Q(x)). These replacements preserve equivalence, since the previous variable standardization step ensured that x doesn't occur in P. After these replacements, a quantifier may occur only in the initial prefix of the formula, but never inside a \lnot, \land, or \lor.
  8. Repeatedly replace \forall x_1 \ldots \forall x_n \; \exists y \; P(y) with \forall x_1 \ldots \forall x_n \; P(f(x_1,\ldots,x_n)), where f is a new n-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.
  9. Drop all universal quantifiers.
  10. Distribute ORs inwards over ANDs: repeatedly replace P \lor (Q \land R) with (P \lor Q) \land (P \lor R).

Example

As an example, the formula saying "Anyone 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 redexes in {\color{red}{\text{red}}}):

|\forall x(\forall y\mathrm{Animal}(y)\color{red}\rightarrow\mathrm{Loves}(x,y))\rightarrow(\existsy\mathrm{Loves}(y,x))
|\forall x(\forall y\lnot\mathrm{Animal}(y)\lor\mathrm{Loves}(x,y))\color{red}\rightarrow(\existsy\mathrm{Loves}(y,x))by 1.1
|\forall x\color{red}\lnot({\color{red}{\forall y}}\lnot\mathrm{Animal}(y)\lor\mathrm{Loves}(x,y))\lor(\existsy\mathrm{Loves}(y,x))by 1.1
|\forall x(\exists y\color{red}\lnot(\lnot\mathrm{Animal}(y)\color{red}\lor\mathrm{Loves}(x,y)))\lor(\existsy\mathrm{Loves}(y,x))by 1.2
|\forall x(\exists y\color{red}\lnot\color{red}\lnot\mathrm{Animal}(y)\land\lnot\mathrm{Loves}(x,y))\lor(\existsy\mathrm{Loves}(y,x))by 1.2
|\forall x({\color{red}{\exists y}}\mathrm{Animal}(y)\land\lnot\mathrm{Loves}(x,y))\lor(\color{red}\exists\color{red}y\mathrm{Loves}(y,x))by 1.2
|\forall x(\exists y\mathrm{Animal}(y)\land\lnot\mathrm{Loves}(x,y))\color{red}\lor(\color{red}\exists\color{red}z\mathrm{Loves}(z,x))by 2
|\forall x\exists z({\color{red}{\exists y}}\mathrm{Animal}(y)\land\lnot\mathrm{Loves}(x,y))\color{red}\lor\mathrm{Loves}(z,x)by 3.1
|\forall x{\color{red}{\exists z}}\exists y(\mathrm{Animal}(y)\land\lnot\mathrm{Loves}(x,y))\lor\mathrm{Loves}(z,x)by 3.1
|\forall x{\color{red}{\exists y}}(\mathrm{Animal}(y)\land\lnot\mathrm{Loves}(x,y))\lor\mathrm{Loves}(g(x),x)by 3.2
|(\mathrm{Animal}(f(x))\color{red}\land\lnot\mathrm{Loves}(x,f(x)))\color{red}\lor\mathrm{Loves}(g(x),x)by 4
|(\mathrm{Animal}(f(x))\color{red}\lor\mathrm{Loves}(g(x),x))\color{red}\land(\lnot \mathrm{Loves}(x,f(x))\color{red}\lor\mathrm{Loves}(g(x),x))by 5
|\{\{\mathrm{Animal}(f(x)),\mathrm{Loves}(g(x),x)\},\{\lnot \mathrm{Loves}(x,f(x)),\mathrm{Loves}(g(x),x)\}\}(clause representation)

Informally, the Skolem function g(x) can be thought of as yielding the person by whom x is loved, while f(x) yields the animal (if any) that x doesn't love. The 3rd last line from below then reads as "x doesn't love the animal f(x), or else x is loved by g(x)".

The 2nd last line from above, (\mathrm{Animal}(f(x)) \lor \mathrm{Loves}(g(x), x)) \land (\lnot \mathrm{Loves}(x, f(x)) \lor \mathrm{Loves}(g(x), x)), is the CNF.

See also

Notes

{{reflist}}

References

{{refbegin}}

  • {{Cite book

|last=Andrews

|first=Peter B.

|year=2013

|title=An Introduction to Mathematical Logic and Type Theory: To Truth Through Proof

|publisher=Springer

|isbn=978-9401599344

}}

  • {{cite book

|last=Howson

|first=Colin

|author-link=Colin Howson

|title=Logic with trees: an introduction to symbolic logic

|url=https://books.google.com/books?id=Y4WGAgAAQBAJ&q=%22conjunctive+normal+form%22

|date=11 October 2005

|orig-date=1997

|publisher=Routledge

|isbn=978-1-134-78550-6

}}

  • {{Cite conference

|last1=Jackson

|first1=Paul

|last2=Sheridan

|first2=Daniel

|url=https://homepages.inf.ed.ac.uk/pbj/papers/sat04-bc-conv.pdf

|title=Clause Form Conversions for Boolean Circuits

|editor1-last=Hoos

|editor1-first=Holger H.

|editor2-last=Mitchell

|editor2-first=David G.

|book-title=Theory and Applications of Satisfiability Testing

|conference=7th International Conference on Theory and Applications of Satisfiability Testing, SAT

|conference-url=https://link.springer.com/book/10.1007/11527695

|date=10 May 2004

|location=Vancouver, BC, Canada

|pages=183{{ndash}}198

|series=Revised Selected Papers. Lecture Notes in Computer Science

|volume=3542

|publisher=Springer 2005

|doi=10.1007/11527695_15

|isbn=978-3-540-31580-3

}}

  • {{cite book

|last1=Kleine Büning

|first1=Hans

|last2=Lettmann

|first2=Theodor

|date=28 August 1999

|title=Propositional Logic: Deduction and Algorithms

|url=https://books.google.com/books?id=3oJE9yczr3EC&q=%22conjunctive+normal+form%22

|publisher=Cambridge University Press

|isbn=978-0-521-63017-7

}}

  • {{Cite book

|editor1-last=Russel

|editor1-first=Stuart

|editor1-link=Stuart J. Russell

|editor2-last=Norvig

|editor2-first=Peter

|editor2-link=Peter Norvig

|date=2010

|orig-date=1995

|title=Artificial Intelligence : A Modern Approach

|url=https://people.engr.tamu.edu/guni/csce421/files/AI_Russell_Norvig.pdf

|edition=3rd

|publisher=Prentice Hall

|location=Upper Saddle River, NJ

|isbn=978-0-13-604259-4

|archive-url=https://web.archive.org/web/20170831090316/https://pdfs.semanticscholar.org/bef0/731f247a1d01c9e0ff52f2412007c143899d.pdf

|archive-date=31 August 2017

|url-status=live

}}

  • {{Cite book

|last=Tseitin

|first=Grigori S.

|author-link=Grigori Tseitin

|year=1968

|chapter=On the Complexity of Derivation in Propositional Calculus

|chapter-url=http://www.decision-procedures.org/handouts/Tseitin70.pdf

|editor-last=Slisenko

|editor-first=A.O.

|title=Structures in Constructive Mathematics and Mathematical Logic, Part II, Seminars in Mathematics (translated from Russian)

|pages=115–125

|publisher=Steklov Mathematical Institute

}}

  • {{cite book

|last=Whitesitt

|first=J. Eldon

|date=24 May 2012

|orig-year=1961

|title=Boolean Algebra and Its Applications

|url=https://books.google.com/books?id=20Un1T78GlMC&q=%22conjunctive+normal+form%22

|publisher=Courier Corporation

|isbn=978-0-486-15816-7

}}

{{refend}}