CS 512, Spring 2017, Handout 10 Propositional Logic: Conjunctive Normal Forms, Disjunctive Normal Forms, Horn Formulas, and other special forms Assaf Kfoury 5 February 2017 Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 1 of 28
conjunctive normal form & disjunctive normal form Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 2 of 28
conjunctive normal form & disjunctive normal form CNF L ::= p p D ::= L L D C ::= D D C literal disjuntion of literals conjunction of disjunctions Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 3 of 28
conjunctive normal form & disjunctive normal form CNF L ::= p p D ::= L L D C ::= D D C literal disjuntion of literals conjunction of disjunctions DNF L ::= p p C ::= L L C D ::= C C D literal conjunction of literals disjunction of conjunctions Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 4 of 28
Why CNF? Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 5 of 28
Why CNF? A disjunction of literals L 1 L m is valid (equivalently, is a tautology) iff there are 1 i, j m with i j such that L i is L j. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 6 of 28
Why CNF? A disjunction of literals L 1 L m is valid (equivalently, is a tautology) iff there are 1 i, j m with i j such that L i is L j. A conjunction of disjunctions D 1 D n is valid (equivalently, is a tautology) iff for every 1 i n it is the case that D i is valid. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 7 of 28
Why CNF? A disjunction of literals L 1 L m is valid (equivalently, is a tautology) iff there are 1 i, j m with i j such that L i is L j. A conjunction of disjunctions D 1 D n is valid (equivalently, is a tautology) iff for every 1 i n it is the case that D i is valid. CNF allows for a fast and easy syntactic test of validity. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 8 of 28
Why CNF? A disjunction of literals L 1 L m is valid (equivalently, is a tautology) iff there are 1 i, j m with i j such that L i is L j. A conjunction of disjunctions D 1 D n is valid (equivalently, is a tautology) iff for every 1 i n it is the case that D i is valid. CNF allows for a fast and easy syntactic test of validity. Unfortunately, conversion into CNF may lead to exponential blow-up: (x 1 y 1) (x 2 y 2) (x n y n) becomes (x 1 x n 1 x n) (x 1 x n 1 y n) (y 1 y n 1 y n) i.e., the initial WFF of size O(n) becomes an equivalent WFF of size O(2 n ), because each clause in the latter contains either x i or y i for every i. Converting a WFF into an equivalent WFF in CNF, preserving validity, is NP-hard! (However, converting a WFF into another WFF, not necessarily equivalent, preserving satisfiability can be carried out in linear time more in a later handout.) Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 9 of 28
Why DNF? Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 10 of 28
Why DNF? A conjunction of literals L 1 L m is satisfiable iff {L 1,..., L m } does not include both a propositional atom P and its negation P. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 11 of 28
Why DNF? A conjunction of literals L 1 L m is satisfiable iff {L 1,..., L m } does not include both a propositional atom P and its negation P. A disjunction of conjunctions C 1 C n is satisfiable iff there is some 1 i n such that C i is satisfiable. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 12 of 28
Why DNF? A conjunction of literals L 1 L m is satisfiable iff {L 1,..., L m } does not include both a propositional atom P and its negation P. A disjunction of conjunctions C 1 C n is satisfiable iff there is some 1 i n such that C i is satisfiable. DNF allows for a fast and easy syntactic test of satisfiability. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 13 of 28
Why DNF? A conjunction of literals L 1 L m is satisfiable iff {L 1,..., L m } does not include both a propositional atom P and its negation P. A disjunction of conjunctions C 1 C n is satisfiable iff there is some 1 i n such that C i is satisfiable. DNF allows for a fast and easy syntactic test of satisfiability. Unfortunately, conversion into DNF may lead to exponential blow-up: (x 1 y 1) (x 2 y 2) (x n y n) becomes (x 1 x n 1 x n) (x 1 x n 1 y n) (y 1 y n 1 y n) i.e., the initial WFF of size O(n) becomes an equivalent WFF of size O(2 n ), because each clause in the latter contains either x i or y i for every i. Converting a WFF into an equivalent WFF in DNF, preserving satisfiability, is NP-hard! Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 14 of 28
further comments on CNF and DNF, summing up: propositional WFF s can be partitioned into three disjoint subsets: 1. tautologies, or unfalsifiable WFF s 2. contradictions, or unsatisfiable WFF s 3. WFF s that are both satisfiable and falsifiable satisfiability of: CNF is in NP DNF is in P tautology of: CNF is in P DNF is in co-np falsifiability of: CNF is in P DNF is in NP Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 15 of 28
other special forms of propositional WFF s: One such form is that of the WFF s in negation normal form (NNF): the negation operator ( ) is only applied to variables, and the only logical operators are conjunction ( ) and disjunction ( ). Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 16 of 28
other special forms of propositional WFF s: One such form is that of the WFF s in negation normal form (NNF): the negation operator ( ) is only applied to variables, and the only logical operators are conjunction ( ) and disjunction ( ). More formally: L ::= p p ϕ ::= L ϕ ψ ϕ ψ Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 17 of 28
other special forms of propositional WFF s: One such form is that of the WFF s in negation normal form (NNF): the negation operator ( ) is only applied to variables, and the only logical operators are conjunction ( ) and disjunction ( ). More formally: L ::= p p ϕ ::= L ϕ ψ ϕ ψ Fact: Every WFF in CNF or in DNF is also in NNF, but the converse is not true in general. See next slide for an example. Fact: NNF is not a canonical form, in contrast to CNF and DNF. Example: x (y z) and (x y) (x z) are equivalent and both in NNF. Fact: Every propositional WFF ϕ can be translated in linear time into an equivalent propositional WFF ψ in NNF such that ψ < (3/2) ϕ. Proof. Left to you. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 18 of 28
example of a WFF in NNF, which is neither in CNF nor in DNF ( (( p q) ( q p) ) ( (r s) ( s r) ) ) ( (( p q) (q p) ) ( (r s) (s r) ) ) Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 19 of 28
example of a WFF in NNF, which is neither in CNF nor in DNF ( (( p q) ( q p) ) ( (r s) ( s r) ) ) ( (( p q) (q p) ) ( (r s) (s r) ) ) and its parse tree after merging identical leaf nodes, turning it into a more compact dag: p q q p r s s r Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 20 of 28
another special form of propositional WFFs: Decomposable Negation Normal Form (DNNF) Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 21 of 28
another special form of propositional WFFs: Decomposable Negation Normal Form (DNNF) A propositional WFF ϕ is a decomposable negation normal form (DNNF) if it is a NNF satisfying the decomposability property: for every conjunction ψ = ψ 1 ψ n which is a sub-wff of ϕ, no propositional variable/atom is shared by any two distinct conjuncts of ψ: Var(ψ i) Var(ψ j) = for every i j Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 22 of 28
another special form of propositional WFFs: Decomposable Negation Normal Form (DNNF) A propositional WFF ϕ is a decomposable negation normal form (DNNF) if it is a NNF satisfying the decomposability property: for every conjunction ψ = ψ 1 ψ n which is a sub-wff of ϕ, no propositional variable/atom is shared by any two distinct conjuncts of ψ: Var(ψ i) Var(ψ j) = for every i j Example: The NNF shown on page 19 is in fact a DNNF. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 23 of 28
another special form of propositional WFFs: Decomposable Negation Normal Form (DNNF) A propositional WFF ϕ is a decomposable negation normal form (DNNF) if it is a NNF satisfying the decomposability property: for every conjunction ψ = ψ 1 ψ n which is a sub-wff of ϕ, no propositional variable/atom is shared by any two distinct conjuncts of ψ: Var(ψ i) Var(ψ j) = for every i j Example: The NNF shown on page 19 is in fact a DNNF. Fact: Satisfiability of WFF in DNNF is decidable in linear time. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 24 of 28
an important restricted class: Horn formulas Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 25 of 28
an important restricted class: Horn formulas P ::= p A ::= P P A C ::= A P Horn clause H ::= C C H Horn formula Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 26 of 28
an important restricted class: Horn formulas P ::= p A ::= P P A C ::= A P Horn clause H ::= C C H Horn formula Fact: Satisfiability of Horn clauses is decidable in linear time. Proof: To see this, rewrite a Horn clause into an equivalent disjunction of literals: L 1 L n L L 1 L n L. Fact: Satisfiability of Horn formulas is decidable in linear time. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 27 of 28
Exercise Search the Web to identify one or two applications, or areas of computer science, where each of the following forms are encountered: 1. Propositional WFF s in NNF. 2. Propositional WFF s in DNNF. 3. Propositional WFF s that are Horn formulas. Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 28 of 28