Conjunctive normal form explained

Conjunctive normal form should not be confused with Chomsky normal form.

In Boolean logic, 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. As a canonical normal form, it is useful in automated theorem proving and circuit theory.

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 (

\wedge

), 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:

  1. CNF → (Disjunction)

\land

CNF
  1. CNF → (Disjunction)
  2. DisjunctionLiteral

\lor

Disjunction
  1. DisjunctionLiteral
  2. Literal

\neg

Variable
  1. LiteralVariable

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\negB\lor\negC)\land(\negD\lorE\lorF\lorD\lorF)

(A\lorB)\land(C)

(A\lorB)

(A)

The following formulas are not in conjunctive normal form:

\neg(A\landB)

, since an AND is nested within a NOT

\neg(A\lorB)\landC

, since an OR is nested within a NOT

A\land(B\lor(D\landE))

, 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. 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\phiDNF

is converted to

\phiCNF

by swapping ANDs with ORs and vice versa while negating all the literals. Remove all

lnotlnot

.

Conversion by syntactic means

Convert to CNF the propositional formula

\phi

.

Step 1: Convert its negation to disjunctive normal form.[1]

lnot\phiDNF=(C1\lorC2\lor\ldots\lorCi\lor\ldots\lorCm)

,

where each

Ci

is a conjunction of literals

li1\landli2\land\ldots\land

l
ini
.

Step 2: Negate

lnot\phiDNF

.Then shift

lnot

inwards by applying the (generalized) De Morgan's equivalences until no longer possible.\begin\phi &\leftrightarrow \lnot \lnot \phi_ \\&= \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 \endwhere\begin\lnot C_i &= \lnot (l_ \land l_ \land \ldots \land l_) \\&\leftrightarrow (\lnot l_ \lor \lnot l_ \lor \ldots \lor \lnot l_) &&\text\end

Step 3: Remove all double negations.

Example

Convert to CNF the propositional formula

\phi=((lnot(p\landq))\leftrightarrow(lnotr\uparrow(pq)))

.

The (full) DNF equivalent of its negation is

lnot\phiDNF= (p\landq\landr)\lor (p\landq\landlnotr)\lor (p\landlnotq\landlnotr)\lor (lnotp\landq\landlnotr)

\begin\phi &\leftrightarrow \lnot \lnot \phi_ \\&= \lnot \ \\&\leftrightarrow\underline \land\underline \land\underline \land\underline &&\text \\&\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 (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 \lnot \lnot \\&= \phi_\end

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

p

q

r

(

lnot

(p\landq)

)

\leftrightarrow

(

lnotr

\uparrow

(pq)

)

T T T F T F F T F
T T F F T F T T F
T F T T F T F T T
T F F T F F T F T
F T T T F T F T T
F T F T F F T F T
F F T T F T F T F
F F F T F T T T F

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

lnotV

in the disjunction,

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

2n

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

Xi

or

Yi

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

Z1,\ldots,Zn

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

Zi

, then both

Xi

and

Yi

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

Zi

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

Zi\vee\negXi\vee\negYi

. With these clauses, the formula implies

Zi\equivXi\wedgeYi

; this formula is often regarded to "define"

Zi

to be a name for

Xi\wedgeYi

.

Maximum number of disjunctions

Consider a propositional formula with

n

variables,

n\ge1

.

There are

2n

possible literals:

L=\{p1,lnotp1,p2,lnotp2,\ldots,pn,lnotpn\}

.

L

has

(22n-1)

non-empty subsets.

This is the maximum number of disjunctions a CNF can have.

All truth-functional combinations can be expressed with

2n

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-1=15

disjunctions: \begin(\lnot p) \land (p) \land (\lnot q) \land (q) \land \\(\lnot p \or p) \land\underline \land\underline \land\underline \land\underline \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

This formula is a contradiction.

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

X1\vee\ldots\veeXk\vee\ldots\veeXn

by two conjuncts

X1\vee\ldots\veeXk-1\veeZ

and

\negZ\veeXk\lor\ldots\veeXn

with 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

(

l11

\lor

\ldots

\lor

l
1n1

)

\land

\ldots

\land

(

lm1

\lor

\ldots

\lor

l
mnm

)

, is commonly represented as a set of sets

\{

||

\{

||

l11

||

,

||

\ldots

||

,

||
l
1n1
||

\}

||

,

||

\ldots

||

,

||

\{

||

lm1

||

,

||

\ldots

||

,

||
l
mnm
||

\}

||

\}

.
See below for an example.

Converting from first-order logic

To convert first-order logic to CNF:

  1. Convert to negation normal form.
    1. Eliminate implications and equivalences: repeatedly replace

PQ

with

lnotP\lorQ

; replace

P\leftrightarrowQ

with

(P\lorlnotQ)\land(lnotP\lorQ)

. Eventually, this will eliminate all occurrences of

and

\leftrightarrow

.
    1. Move NOTs inwards by repeatedly applying De Morgan's law. Specifically, replace

lnot(P\lorQ)

with

(lnotP)\land(lnotQ)

; replace

lnot(P\landQ)

with

(lnotP)\lor(lnotQ)

; and replace

lnotlnotP

with

P

; replace

lnot(\forallxP(x))

with

\existsxlnotP(x)

;

lnot(\existsxP(x))

with

\forallxlnotP(x)

. After that, a

lnot

may occur only immediately before a predicate symbol.
  1. Standardize variables
    1. For sentences like

(\forallxP(x))\lor(\existsxQ(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,

\forallx[\existsyAnimal(y)\landlnotLoves(x,y)]\lor[\existsyLoves(y,x)]

is renamed to

\forallx[\existsyAnimal(y)\landlnotLoves(x,y)]\lor[\existszLoves(z,x)]

.
  1. Skolemize the statement
    1. Move quantifiers outwards: repeatedly replace

P\land(\forallxQ(x))

with

\forallx(P\landQ(x))

; replace

P\lor(\forallxQ(x))

with

\forallx(P\lorQ(x))

; replace

P\land(\existsxQ(x))

with

\existsx(P\landQ(x))

; replace

P\lor(\existsxQ(x))

with

\existsx(P\lorQ(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

.
    1. Repeatedly replace

\forallx1\ldots\forallxn\existsyP(y)

with

\forallx1\ldots\forallxnP(f(x1,\ldots,xn))

, 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.
  1. Drop all universal quantifiers.
  2. Distribute ORs inwards over ANDs: repeatedly replace

P\lor(Q\landR)

with

(P\lorQ)\land(P\lorR)

.

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}{red

}}):

\forallx

(

\forally

Animal(

y

)

\color{red}

Loves(x,

y

)

)

(

\exists

y

Loves(

y

,x)

)

\forallx

(

\forally

lnot

Animal(

y

)

\lor

Loves(x,

y

)

)

\color{red}

(

\exists

y

Loves(

y

,x)

)

by 1.1

\forallx

\color{red}lnot

(

{\color{red}{\forally}}

lnot

Animal(

y

)

\lor

Loves(x,

y

)

)

\lor

(

\exists

y

Loves(

y

,x)

)

by 1.1

\forallx

(

\existsy

\color{red}lnot

(

lnot

Animal(

y

)

\color{red}\lor

Loves(x,

y

)

)

)

\lor

(

\exists

y

Loves(

y

,x)

)

by 1.2

\forallx

(

\existsy

\color{red}lnot

\color{red}lnot

Animal(

y

)

\land

lnot

Loves(x,

y

)

)

\lor

(

\exists

y

Loves(

y

,x)

)

by 1.2

\forallx

(

{\color{red}{\existsy}}

Animal(

y

)

\land

lnot

Loves(x,

y

)

)

\lor

(

\color{red}\exists

\color{red}y

Loves(

y

,x)

)

by 1.2

\forallx

(

\existsy

Animal(

y

)

\land

lnot

Loves(x,

y

)

)

\color{red}\lor

(

\color{red}\exists

\color{red}z

Loves(

z

,x)

)

by 2

\forallx

\existsz

(

{\color{red}{\existsy}}

Animal(

y

)

\land

lnot

Loves(x,

y

)

)

\color{red}\lor

Loves(

z

,x)

by 3.1

\forallx

{\color{red}{\existsz}}

\existsy

(

Animal(

y

)

\land

lnot

Loves(x,

y

)

)

\lor

Loves(

z

,x)

by 3.1

\forallx

{\color{red}{\existsy}}

(

Animal(

y

)

\land

lnot

Loves(x,

y

)

)

\lor

Loves(

g(x)

,x)

by 3.2

(

Animal(

f(x)

)

\color{red}\land

lnot

Loves(x,

f(x)

)

)

\color{red}\lor

Loves(

g(x)

,x)

by 4

(

Animal(

f(x)

)

\color{red}\lor

Loves(

g(x)

,x)

)

\color{red}\land

(

lnotLoves(x,f(x))

\color{red}\lor

Loves(g(x),x)

)

by 5

\{

||

\{

||||||||||||||

Animal(

||

f(x)

||

)

||||||||||||||||

,

||||||||

Loves(

||

g(x)

||

,x)

||||

\}

||

,

||

\{

||

lnotLoves(x,f(x))

||

,

||

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,

(Animal(f(x))\lorLoves(g(x),x))\land(lnotLoves(x,f(x))\lorLoves(g(x),x))

, is the CNF.

See also

Notes

References

External links

Notes and References

  1. see