Conjunctive normal form

From The Right Wiki
(Redirected from Clause normal form)
Jump to navigationJump to search

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. 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 (), and (), and not (¬). 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) CNF
  2. CNF → (Disjunction)
  3. DisjunctionLiteral Disjunction
  4. DisjunctionLiteral
  5. Literal¬Variable
  6. 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¬B¬C)(¬DEFDF)
  • (AB)(C)
  • (AB)
  • (A)

The following formulas are not in conjunctive normal form:

  • ¬(AB), since an AND is nested within a NOT
  • ¬(AB)C, since an OR is nested within a NOT
  • A(B(DE)), 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.[1] 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 ϕ builds upon ¬ϕ in disjunctive normal form (DNF): step 1.[2]
Then ¬ϕDNF is converted to ϕCNF by swapping ANDs with ORs and vice versa while negating all the literals. Remove all ¬¬.[1]

Conversion by syntactic means

Convert to CNF the propositional formula ϕ. Step 1: Convert its negation to disjunctive normal form.[2] ¬ϕDNF=(C1C2CiCm),[lower-alpha 1] where each Ci is a conjunction of literals li1li2lini.[lower-alpha 2] Step 2: Negate ¬ϕDNF. Then shift ¬ inwards by applying the (generalized) De Morgan's equivalences until no longer possible. ϕ¬¬ϕDNF=¬(C1C2CiCm)¬C1¬C2¬Ci¬Cm// (generalized) D.M. where¬Ci=¬(li1li2lini)(¬li1¬li2¬lini)// (generalized) D.M. Step 3: Remove all double negations. Example Convert to CNF the propositional formula ϕ=((¬(pq))(¬r(pq))).[lower-alpha 3] The (full) DNF equivalent of its negation is[2]
¬ϕDNF=(pqr)(pq¬r)(p¬q¬r)(¬pq¬r) ϕ¬¬ϕDNF=¬{(pqr)(pq¬r)(p¬q¬r)(¬pq¬r)}¬(pqr)_¬(pq¬r)_¬(p¬q¬r)_¬(¬pq¬r)_// generalized D.M. (¬p¬q¬r)(¬p¬q¬¬r)(¬p¬¬q¬¬r)(¬¬p¬q¬¬r)// generalized D.M. (4×)(¬p¬q¬r)(¬p¬qr)(¬pqr)(p¬qr)// remove all ¬¬=ϕCNF

Conversion by semantic means

A CNF equivalent of a formula can be derived from its truth table. Again, consider the formula ϕ=((¬(pq))(¬r(pq))).[lower-alpha 3] The corresponding truth table is

p q r ( ¬ (pq) ) ( ¬r (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 ϕ is (¬p¬q¬r)(¬p¬qr)(¬pqr)(p¬qr) Each disjunction reflects an assignment of variables for which ϕ evaluates to F(alse).
If in such an assignment a variable V

  • is T(rue), then the literal is set to ¬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 (X1Y1)(X2Y2)(XnYn) into CNF produces a formula with 2n clauses: (X1X2Xn)(Y1X2Xn)(X1Y2Xn)(Y1Y2Xn)(Y1Y2Yn). 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.[3][4] 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,,Zn as follows: (Z1Zn)(¬Z1X1)(¬Z1Y1)(¬ZnXn)(¬ZnYn). 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¬Xi¬Yi. With these clauses, the formula implies ZiXiYi; this formula is often regarded to "define" Zi to be a name for XiYi.

Maximum number of disjunctions

Consider a propositional formula with n variables, n1. There are 2n possible literals: L={p1,¬p1,p2,¬p2,,pn,¬pn}. L has (22n1) non-empty subsets.[lower-alpha 4] This is the maximum number of disjunctions a CNF can have.[lower-alpha 5] 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×2)1=15 disjunctions:[lower-alpha 5] (¬p)(p)(¬q)(q)(¬pp)(¬p¬q)_(¬pq)_(p¬q)_(pq)_(¬qq)(¬pp¬q)(¬ppq)(¬p¬qq)(p¬qq)(¬pp¬qq) 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,[lower-alpha 6] 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 X1XkXn by two conjuncts X1Xk1Z and ¬ZXkXn with 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

( l11 l1n1 ) ( lm1 lmnm ) ,[lower-alpha 7] is commonly represented as a set of sets
{ { l11 , , l1n1 } , , { lm1 , , lmnm } } .

See below for an example.

Converting from first-order logic

To convert first-order logic to CNF:[5]

  1. Convert to negation normal form.
    1. Eliminate implications and equivalences: repeatedly replace PQ with ¬PQ; replace PQ with (P¬Q)(¬PQ). Eventually, this will eliminate all occurrences of and .
    2. Move NOTs inwards by repeatedly applying De Morgan's law. Specifically, replace ¬(PQ) with (¬P)(¬Q); replace ¬(PQ) with (¬P)(¬Q); and replace ¬¬P with P; replace ¬(xP(x)) with x¬P(x); ¬(xP(x)) with x¬P(x). After that, a ¬ may occur only immediately before a predicate symbol.
  2. Standardize variables
    1. For sentences like (xP(x))(xQ(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, x[yAnimal(y)¬Loves(x,y)][yLoves(y,x)] is renamed to x[yAnimal(y)¬Loves(x,y)][zLoves(z,x)].
  3. Skolemize the statement
    1. Move quantifiers outwards: repeatedly replace P(xQ(x)) with x(PQ(x)); replace P(xQ(x)) with x(PQ(x)); replace P(xQ(x)) with x(PQ(x)); replace P(xQ(x)) with x(PQ(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 ¬, , or .
    2. Repeatedly replace x1xnyP(y) with x1xnP(f(x1,,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.
  4. Drop all universal quantifiers.
  5. Distribute ORs inwards over ANDs: repeatedly replace P(QR) with (PQ)(PR).

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

x ( y Animal( y ) Loves(x, y ) ) ( y Loves( y ,x) )
x ( y ¬ Animal( y ) Loves(x, y ) ) ( y Loves( y ,x) ) by 1.1
x ¬ ( y ¬ Animal( y ) Loves(x, y ) ) ( y Loves( y ,x) ) by 1.1
x ( y ¬ ( ¬ Animal( y ) Loves(x, y ) ) ) ( y Loves( y ,x) ) by 1.2
x ( y ¬ ¬ Animal( y ) ¬ Loves(x, y ) ) ( y Loves( y ,x) ) by 1.2
x ( y Animal( y ) ¬ Loves(x, y ) ) ( y Loves( y ,x) ) by 1.2
x ( y Animal( y ) ¬ Loves(x, y ) ) ( z Loves( z ,x) ) by 2
x z ( y Animal( y ) ¬ Loves(x, y ) ) Loves( z ,x) by 3.1
x z y ( Animal( y ) ¬ Loves(x, y ) ) Loves( z ,x) by 3.1
x y ( Animal( y ) ¬ Loves(x, y ) ) Loves( g(x) ,x) by 3.2
( Animal( f(x) ) ¬ Loves(x, f(x) ) ) Loves( g(x) ,x) by 4
( Animal( f(x) ) Loves( g(x) ,x) ) ( ¬Loves(x,f(x)) Loves(g(x),x) ) by 5
{ { Animal( f(x) ) , Loves( g(x) ,x) } , { ¬Loves(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))Loves(g(x),x))(¬Loves(x,f(x))Loves(g(x),x)), is the CNF.

See also

Notes

  1. 1m maximum number of conjunctions for ϕ
  2. 1ini maximum number of literals for ϕ
  3. 3.0 3.1 ϕ = ((NOT (p AND q)) IFF ((NOT r) NAND (p XOR q)))
  4. |𝒫(L)|=22n
  5. 5.0 5.1 It is assumed that repetitions and variations (like (ab)(ba)(abb)) based on the commutativity and associativity of and do not occur.
  6. 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
  7. 1m maximum number of disjunctions
    1ini maximum number of literals

References

  1. 1.0 1.1 Howson 2005, p. 46.
  2. 2.0 2.1 2.2 see Disjunctive normal form § Conversion to DNF
  3. Tseitin 1968.
  4. Jackson & Sheridan 2004.
  5. Russel & Norvig 2010, pp. 345–347, 9.5.1 Conjunctive normal form for first-order logic.
  • Andrews, Peter B. (2013). An Introduction to Mathematical Logic and Type Theory: To Truth Through Proof. Springer. ISBN 978-9401599344.
  • Howson, Colin (11 October 2005) [1997]. Logic with trees: an introduction to symbolic logic. Routledge. ISBN 978-1-134-78550-6.
  • Jackson, Paul; Sheridan, Daniel (10 May 2004). "Clause Form Conversions for Boolean Circuits" (PDF). In Hoos, Holger H.; Mitchell, David G. (eds.). Theory and Applications of Satisfiability Testing. 7th International Conference on Theory and Applications of Satisfiability Testing, SAT. Revised Selected Papers. Lecture Notes in Computer Science. Vol. 3542. Vancouver, BC, Canada: Springer 2005. pp. 183–198. doi:10.1007/11527695_15. ISBN 978-3-540-31580-3.
  • Kleine Büning, Hans; Lettmann, Theodor (28 August 1999). Propositional Logic: Deduction and Algorithms. Cambridge University Press. ISBN 978-0-521-63017-7.
  • Russel, Stuart; Norvig, Peter, eds. (2010) [1995]. Artificial Intelligence : A Modern Approach (PDF) (3rd ed.). Upper Saddle River, NJ: Prentice Hall. ISBN 978-0-13-604259-4. Archived (PDF) from the original on 31 August 2017.
  • Tseitin, Grigori S. (1968). "On the Complexity of Derivation in Propositional Calculus" (PDF). In Slisenko, A.O. (ed.). Structures in Constructive Mathematics and Mathematical Logic, Part II, Seminars in Mathematics (translated from Russian). Steklov Mathematical Institute. pp. 115–125.
  • Whitesitt, J. Eldon (24 May 2012) [1961]. Boolean Algebra and Its Applications. Courier Corporation. ISBN 978-0-486-15816-7.

External links