Jochen Burghardt (talk | contribs) completed CNF computation exm |
Jochen Burghardt (talk | contribs) improved example |
||
Line 74: | Line 74: | ||
#[[Skolemize]] the statement |
#[[Skolemize]] the statement |
||
##Move quantifiers outwards: repeatedly replace <math>P \land (\forall x Q(x))</math> with <math>\forall x (P \land Q(x))</math>; replace <math>P \lor (\forall x Q(x))</math> with <math>\forall x (P \lor Q(x))</math>; replace <math>P \land (\exists x Q(x))</math> with <math>\exists x (P \land Q(x))</math>; replace <math>P \lor (\exists x Q(x))</math> with <math>\exists x (P \lor Q(x))</math>. These replacements preserve equivalence, since the previous variable standardization step ensured that <math>x</math> doesn't occur in <math>P</math>. After these replacements, a quantifier may occur only in the initial prefix of the formula, but never inside a <math>\lnot</math>, <math>\land</math>, or <math>\lor</math>. |
##Move quantifiers outwards: repeatedly replace <math>P \land (\forall x Q(x))</math> with <math>\forall x (P \land Q(x))</math>; replace <math>P \lor (\forall x Q(x))</math> with <math>\forall x (P \lor Q(x))</math>; replace <math>P \land (\exists x Q(x))</math> with <math>\exists x (P \land Q(x))</math>; replace <math>P \lor (\exists x Q(x))</math> with <math>\exists x (P \lor Q(x))</math>. These replacements preserve equivalence, since the previous variable standardization step ensured that <math>x</math> doesn't occur in <math>P</math>. After these replacements, a quantifier may occur only in the initial prefix of the formula, but never inside a <math>\lnot</math>, <math>\land</math>, or <math>\lor</math>. |
||
##Repeatedly replace <math>\forall x_1 \ldots \forall x_n \; \exists y \; P(y)</math> with <math>\forall x_1 \ldots \forall x_n \; P(f(x_1,\ldots,x_n))</math>, where <math>f</math> is a new <math>n</math>-ary function symbol. This is the only step that preserves only satisfiability rather than equivalence. It eliminates all existential quantifiers. |
##Repeatedly replace <math>\forall x_1 \ldots \forall x_n \; \exists y \; P(y)</math> with <math>\forall x_1 \ldots \forall x_n \; P(f(x_1,\ldots,x_n))</math>, where <math>f</math> is a new <math>n</math>-ary function symbol, a so-called "[[Skolem normal form|skolem function]]". This is the only step that preserves only satisfiability rather than equivalence. It eliminates all existential quantifiers. |
||
#Drop all universal quantifiers. |
#Drop all universal quantifiers. |
||
#Distribute ORs inwards over ANDs: repeatedly replace <math>P \lor (Q \land R)</math> with <math>(P \lor Q) \land (P \lor R)</math>. |
#Distribute ORs inwards over ANDs: repeatedly replace <math>P \lor (Q \land R)</math> with <math>(P \lor Q) \land (P \lor R)</math>. |
||
As an example, the formula saying ''"Who loves all animals, is in turn loved by someone"'' is converted into CNF (and subsequently into [[clause (logic)|clause]] form in the last line) as follows: |
|||
{| |
{| |
||
Line 87: | Line 87: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\forall y</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 126: | Line 126: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\forall y</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 165: | Line 165: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\color{red}\forall y</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 204: | Line 204: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\exists y</math> |
||
||<math>\color{red}\lnot</math> |
||<math>\color{red}\lnot</math> |
||
||<math>(</math> |
||<math>(</math> |
||
Line 212: | Line 212: | ||
||<math>y</math> |
||<math>y</math> |
||
||<math>)</math> |
||<math>)</math> |
||
||<math>\lor</math> |
||<math>\color{red}\lor</math> |
||
|| |
|| |
||
||<math>Loves(x,</math> |
||<math>Loves(x,</math> |
||
Line 243: | Line 243: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\exists y</math> |
||
|| |
|| |
||
|| |
|| |
||
||<math>\color{red}\lnot</math> |
||<math>\color{red}\lnot</math> |
||
||<math>\lnot</math> |
||<math>\color{red}\lnot</math> |
||
||<math>Animal(</math> |
||<math>Animal(</math> |
||
||<math>y</math> |
||<math>y</math> |
||
Line 282: | Line 282: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\color{red}\exists y</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 321: | Line 321: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\ |
||<math>\exists y</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 336: | Line 336: | ||
|| |
|| |
||
||<math>)</math> |
||<math>)</math> |
||
||<math>\lor</math> |
||<math>\color{red}\lor</math> |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\color{red}\exists</math> |
||<math>\color{red}\exists</math> |
||
Line 360: | Line 360: | ||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\color{red}\ |
||<math>\color{red}\exists y</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 375: | Line 375: | ||
|| |
|| |
||
||<math>)</math> |
||<math>)</math> |
||
||<math>\lor</math> |
||<math>\color{red}\lor</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 395: | Line 395: | ||
|- |
|- |
||
||<math>\forall x</math> |
||<math>\forall x</math> |
||
||<math>\exists z</math> |
||<math>\color{red}\exists z</math> |
||
|| |
|| |
||
|| |
|| |
||
|| |
|| |
||
||<math>\ |
||<math>\exists y</math> |
||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
Line 438: | Line 438: | ||
|| |
|| |
||
|| |
|| |
||
||<math>\ |
||<math>\color{red}\exists y</math> |
||
|| |
|| |
||
||<math>(</math> |
||<math>(</math> |
||
Line 483: | Line 483: | ||
|| |
|| |
||
||<math>Animal(</math> |
||<math>Animal(</math> |
||
||<math> |
||<math>f(x)</math> |
||
||<math>)</math> |
||<math>)</math> |
||
||<math>\land</math> |
||<math>\color{red}\land</math> |
||
||<math>\lnot</math> |
||<math>\lnot</math> |
||
||<math>Loves(x,</math> |
||<math>Loves(x,</math> |
||
||<math> |
||<math>f(x)</math> |
||
||<math>)</math> |
||<math>)</math> |
||
||<math>)</math> |
||<math>)</math> |
||
|| |
|| |
||
||<math>\lor</math> |
||<math>\color{red}\lor</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 522: | Line 522: | ||
|| |
|| |
||
||<math>Animal(</math> |
||<math>Animal(</math> |
||
||<math> |
||<math>f(x)</math> |
||
||<math>)</math> |
||<math>)</math> |
||
|| |
|| |
||
Line 531: | Line 531: | ||
|| |
|| |
||
|| |
|| |
||
||<math>\lor</math> |
||<math>\color{red}\lor</math> |
||
|| |
|| |
||
|| |
|| |
||
Line 540: | Line 540: | ||
|| |
|| |
||
||<math>)</math> |
||<math>)</math> |
||
||<math>\land</math> |
||<math>\color{red}\land</math> |
||
||<math>(</math> |
||<math>(</math> |
||
||<math>\lnot Loves(x, |
||<math>\lnot Loves(x,f(x))</math> |
||
||<math>\lor</math> |
||<math>\color{red}\lor</math> |
||
||<math>Loves(g(x),x)</math> |
||<math>Loves(g(x),x)</math> |
||
||<math>)</math> |
||<math>)</math> |
||
Line 561: | Line 561: | ||
|| |
|| |
||
||<math>Animal(</math> |
||<math>Animal(</math> |
||
||<math> |
||<math>f(x)</math> |
||
||<math>)</math> |
||<math>)</math> |
||
|| |
|| |
||
Line 581: | Line 581: | ||
||<math>,</math> |
||<math>,</math> |
||
||<math>\{</math> |
||<math>\{</math> |
||
||<math>\lnot Loves(x, |
||<math>\lnot Loves(x,f(x))</math> |
||
||<math>,</math> |
||<math>,</math> |
||
||<math>Loves(g(x),x)</math> |
||<math>Loves(g(x),x)</math> |
||
||<math>\}</math> |
||<math>\}</math> |
||
||<math>\}</math> |
||<math>\}</math> |
||
||([[clause (logic)|clause]] representation) |
|||
|| |
|||
|} |
|} |
||
Informally, the skolem function <math>g(x)</math> can be thought of as yielding the person by whom <math>x</math> is loved, while <math>f(x)</math> yields the animal (if any) that <math>x</math> doesn't love. The 2nd last line from below then reads as ''"<math>x</math> doesn't love the animal <math>f(x)</math>, or else <math>x</math> is loved by <math>g(x)</math>"''. |
|||
==Notes== |
==Notes== |
Revision as of 12:09, 1 June 2013
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. As a normal form, it is useful in automated theorem proving. It is similar to the product of sums form used in circuit theory.
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.
Examples and counterexamples
All of the following formulas are in CNF:
The last formula is in CNF because it can be seen as the conjunction of the two single-literal clauses and . Incidentally, the last two formulae are also in disjunctive normal form.
The following formulas are not in CNF:
The above three formulas are respectively equivalent to the following three formulas that are in CNF:
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 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.[1][2] 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 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.
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 [3], 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 by two conjuncts and with a new variable, and repeating as often as necessary.
Converting from first-order logic
To convert first-order logic to CNF:[4]
- Convert to negation normal form.
- Eliminate implications and equivalences: repatedly replace with ; replace with . Eventually, this will eliminate all occurrences of and .
- Move NOTs inwards by repeatedly applying DeMorgan'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 later. For example, is renamed to .
- Skolemize the statement
- 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.
- Drop all universal quantifiers.
- Distribute ORs inwards over ANDs: repeatedly replace with .
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:
by 1.1 | ||||||||||||||||||||||||||||||||||||
by 1.1 | ||||||||||||||||||||||||||||||||||||
by 1.2 | ||||||||||||||||||||||||||||||||||||
by 1.2 | ||||||||||||||||||||||||||||||||||||
by 1.2 | ||||||||||||||||||||||||||||||||||||
by 2 | ||||||||||||||||||||||||||||||||||||
by 3.1 | ||||||||||||||||||||||||||||||||||||
by 3.1 | ||||||||||||||||||||||||||||||||||||
by 3.2 | ||||||||||||||||||||||||||||||||||||
by 4 | ||||||||||||||||||||||||||||||||||||
by 5 | ||||||||||||||||||||||||||||||||||||
(clause representation) |
Informally, the skolem function can be thought of as yielding the person by whom is loved, while yields the animal (if any) that doesn't love. The 2nd last line from below then reads as " doesn't love the animal , or else is loved by ".
Notes
See also
References
- Paul Jackson, Daniel Sheridan: Clause Form Conversions for Boolean Circuits. In: Holger H. Hoos, David G. Mitchell (Eds.): Theory and Applications of Satisfiability Testing, 7th International Conference, SAT 2004, Vancouver, BC, Canada, May 10–13, 2004, Revised Selected Papers. Lecture Notes in Computer Science 3542, Springer 2005, pp. 183–198
- G.S. Tseitin: On the complexity of derivation in propositional calculus. In: Slisenko, A.O. (ed.) Structures in Constructive Mathematics and Mathematical Logic, Part II, Seminars in Mathematics (translated from Russian), pp. 115–125. Steklov Mathematical Institute (1968)