<<

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 CNF

L ::= p | ¬p literal D ::= L | L ∨ D disjuntion of literals C ::= D | D ∧ C conjunction of disjunctions

DNF

L ::= p | ¬p literal C ::= L | L ∧ C conjunction of literals D ::= C | C ∨ D disjunction of conjunctions

&

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 2 of 28 DNF

L ::= p | ¬p literal C ::= L | L ∧ C conjunction of literals D ::= C | C ∨ D disjunction of conjunctions

conjunctive normal form & disjunctive normal form

CNF

L ::= p | ¬p literal D ::= L | L ∨ D disjuntion of literals C ::= D | D ∧ C 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 literal D ::= L | L ∨ D disjuntion of literals C ::= D | D ∧ C conjunction of disjunctions

DNF

L ::= p | ¬p literal C ::= L | L ∧ C conjunction of literals D ::= C | C ∨ D disjunction of conjunctions

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 4 of 28 I A disjunction of literals L1 ∨ · · · ∨ Lm is valid (equivalently, is a ) iff there are 1 6 i, j 6 m with i 6= j such that Li is ¬Lj.

I A conjunction of disjunctions D1 ∧ · · · ∧ Dn is valid (equivalently, is a tautology) iff for every 1 6 i 6 n it is the case that Di is valid. I CNF allows for a fast and easy syntactic test of validity.

I Unfortunately, conversion into CNF may lead to exponential blow-up:

(x1 ∧ y1) ∨ (x2 ∧ y2) ∨ · · · ∨ (xn ∧ yn) becomes

(x1 ∨ · · · ∨ xn−1 ∨ xn) ∧ (x1 ∨ · · · ∨ xn−1 ∨ yn) ∧ · · · ∧ (y1 ∨ · · · ∨ yn−1 ∨ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

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.)

Why CNF?

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 5 of 28 I A conjunction of disjunctions D1 ∧ · · · ∧ Dn is valid (equivalently, is a tautology) iff for every 1 6 i 6 n it is the case that Di is valid. I CNF allows for a fast and easy syntactic test of validity.

I Unfortunately, conversion into CNF may lead to exponential blow-up:

(x1 ∧ y1) ∨ (x2 ∧ y2) ∨ · · · ∨ (xn ∧ yn) becomes

(x1 ∨ · · · ∨ xn−1 ∨ xn) ∧ (x1 ∨ · · · ∨ xn−1 ∨ yn) ∧ · · · ∧ (y1 ∨ · · · ∨ yn−1 ∨ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

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.)

Why CNF?

I A disjunction of literals L1 ∨ · · · ∨ Lm is valid (equivalently, is a tautology) iff there are 1 6 i, j 6 m with i 6= j such that Li is ¬Lj.

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 6 of 28 I CNF allows for a fast and easy syntactic test of validity.

I Unfortunately, conversion into CNF may lead to exponential blow-up:

(x1 ∧ y1) ∨ (x2 ∧ y2) ∨ · · · ∨ (xn ∧ yn) becomes

(x1 ∨ · · · ∨ xn−1 ∨ xn) ∧ (x1 ∨ · · · ∨ xn−1 ∨ yn) ∧ · · · ∧ (y1 ∨ · · · ∨ yn−1 ∨ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

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.)

Why CNF?

I A disjunction of literals L1 ∨ · · · ∨ Lm is valid (equivalently, is a tautology) iff there are 1 6 i, j 6 m with i 6= j such that Li is ¬Lj.

I A conjunction of disjunctions D1 ∧ · · · ∧ Dn is valid (equivalently, is a tautology) iff for every 1 6 i 6 n it is the case that Di is valid.

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 7 of 28 I Unfortunately, conversion into CNF may lead to exponential blow-up:

(x1 ∧ y1) ∨ (x2 ∧ y2) ∨ · · · ∨ (xn ∧ yn) becomes

(x1 ∨ · · · ∨ xn−1 ∨ xn) ∧ (x1 ∨ · · · ∨ xn−1 ∨ yn) ∧ · · · ∧ (y1 ∨ · · · ∨ yn−1 ∨ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

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.)

Why CNF?

I A disjunction of literals L1 ∨ · · · ∨ Lm is valid (equivalently, is a tautology) iff there are 1 6 i, j 6 m with i 6= j such that Li is ¬Lj.

I A conjunction of disjunctions D1 ∧ · · · ∧ Dn is valid (equivalently, is a tautology) iff for every 1 6 i 6 n it is the case that Di is valid. I 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?

I A disjunction of literals L1 ∨ · · · ∨ Lm is valid (equivalently, is a tautology) iff there are 1 6 i, j 6 m with i 6= j such that Li is ¬Lj.

I A conjunction of disjunctions D1 ∧ · · · ∧ Dn is valid (equivalently, is a tautology) iff for every 1 6 i 6 n it is the case that Di is valid. I CNF allows for a fast and easy syntactic test of validity.

I Unfortunately, conversion into CNF may lead to exponential blow-up:

(x1 ∧ y1) ∨ (x2 ∧ y2) ∨ · · · ∨ (xn ∧ yn) becomes

(x1 ∨ · · · ∨ xn−1 ∨ xn) ∧ (x1 ∨ · · · ∨ xn−1 ∨ yn) ∧ · · · ∧ (y1 ∨ · · · ∨ yn−1 ∨ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

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 I A conjunction of literals L1 ∧ · · · ∧ Lm is satisfiable iff {L1,..., Lm} does not include both a propositional atom P and its ¬P.

I A disjunction of conjunctions C1 ∨ · · · ∨ Cn is satisfiable iff there is some 1 6 i 6 n such that Ci is satisfiable. I DNF allows for a fast and easy syntactic test of satisfiability.

I Unfortunately, conversion into DNF may lead to exponential blow-up:

(x1 ∨ y1) ∧ (x2 ∨ y2) ∧ · · · ∧ (xn ∨ yn) becomes

(x1 ∧ · · · ∧ xn−1 ∧ xn) ∨ (x1 ∧ · · · ∧ xn−1 ∧ yn) ∨ · · · ∨ (y1 ∧ · · · ∧ yn−1 ∧ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

I Converting a WFF into an equivalent WFF in DNF, preserving satisfiability, is NP-hard!

Why DNF?

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 10 of 28 I A disjunction of conjunctions C1 ∨ · · · ∨ Cn is satisfiable iff there is some 1 6 i 6 n such that Ci is satisfiable. I DNF allows for a fast and easy syntactic test of satisfiability.

I Unfortunately, conversion into DNF may lead to exponential blow-up:

(x1 ∨ y1) ∧ (x2 ∨ y2) ∧ · · · ∧ (xn ∨ yn) becomes

(x1 ∧ · · · ∧ xn−1 ∧ xn) ∨ (x1 ∧ · · · ∧ xn−1 ∧ yn) ∨ · · · ∨ (y1 ∧ · · · ∧ yn−1 ∧ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

I Converting a WFF into an equivalent WFF in DNF, preserving satisfiability, is NP-hard!

Why DNF?

I A conjunction of literals L1 ∧ · · · ∧ Lm is satisfiable iff {L1,..., Lm} does not include both a propositional atom P and its negation ¬P.

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 11 of 28 I DNF allows for a fast and easy syntactic test of satisfiability.

I Unfortunately, conversion into DNF may lead to exponential blow-up:

(x1 ∨ y1) ∧ (x2 ∨ y2) ∧ · · · ∧ (xn ∨ yn) becomes

(x1 ∧ · · · ∧ xn−1 ∧ xn) ∨ (x1 ∧ · · · ∧ xn−1 ∧ yn) ∨ · · · ∨ (y1 ∧ · · · ∧ yn−1 ∧ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

I Converting a WFF into an equivalent WFF in DNF, preserving satisfiability, is NP-hard!

Why DNF?

I A conjunction of literals L1 ∧ · · · ∧ Lm is satisfiable iff {L1,..., Lm} does not include both a propositional atom P and its negation ¬P.

I A disjunction of conjunctions C1 ∨ · · · ∨ Cn is satisfiable iff there is some 1 6 i 6 n such that Ci is satisfiable.

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 12 of 28 I Unfortunately, conversion into DNF may lead to exponential blow-up:

(x1 ∨ y1) ∧ (x2 ∨ y2) ∧ · · · ∧ (xn ∨ yn) becomes

(x1 ∧ · · · ∧ xn−1 ∧ xn) ∨ (x1 ∧ · · · ∧ xn−1 ∧ yn) ∨ · · · ∨ (y1 ∧ · · · ∧ yn−1 ∧ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

I Converting a WFF into an equivalent WFF in DNF, preserving satisfiability, is NP-hard!

Why DNF?

I A conjunction of literals L1 ∧ · · · ∧ Lm is satisfiable iff {L1,..., Lm} does not include both a propositional atom P and its negation ¬P.

I A disjunction of conjunctions C1 ∨ · · · ∨ Cn is satisfiable iff there is some 1 6 i 6 n such that Ci is satisfiable. I 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?

I A conjunction of literals L1 ∧ · · · ∧ Lm is satisfiable iff {L1,..., Lm} does not include both a propositional atom P and its negation ¬P.

I A disjunction of conjunctions C1 ∨ · · · ∨ Cn is satisfiable iff there is some 1 6 i 6 n such that Ci is satisfiable. I DNF allows for a fast and easy syntactic test of satisfiability.

I Unfortunately, conversion into DNF may lead to exponential blow-up:

(x1 ∨ y1) ∧ (x2 ∨ y2) ∧ · · · ∧ (xn ∨ yn) becomes

(x1 ∧ · · · ∧ xn−1 ∧ xn) ∨ (x1 ∧ · · · ∧ xn−1 ∧ yn) ∨ · · · ∨ (y1 ∧ · · · ∧ yn−1 ∧ yn)

i.e., the initial WFF of size O(n) becomes an equivalent WFF of size n O(2 ), because each clause in the latter contains either xi or yi for every i.

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:

I 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

I satisfiability of:

I CNF is in NP I DNF is in P

I tautology of:

I CNF is in P I DNF is in co-NP

I falsifiability of:

I CNF is in P I DNF is in NP

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 15 of 28 I More formally:

L ::= p | ¬p ϕ ::= L | ϕ ∧ ψ | ϕ ∨ ψ

I 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.

I Fact: NNF is not a , in contrast to CNF and DNF. Example: x ∧ (y ∨ ¬z) and (x ∧ y) ∨ (x ∧ ¬z) are equivalent and both in NNF.

I 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.

other special forms of propositional WFF’s:

I One such form is that of the WFF’s in (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 I 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.

I 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.

I 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.

other special forms of propositional WFF’s:

I 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 (∨).

I 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:

I 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 (∨).

I More formally:

L ::= p | ¬p ϕ ::= L | ϕ ∧ ψ | ϕ ∨ ψ

I 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.

I 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.

I 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 and its parse tree after merging identical leaf nodes, turning it into a more compact dag: ∨

∧ ∧

∨ ∨ ∨ ∨

∧ ∧ ∧ ∧ ∧ ∧ ∧ ∧

¬p q ¬q p r ¬s s ¬r

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 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 6= j

Example: The NNF shown on page 19 is in fact a DNNF.

Fact: Satisfiability of WFF in DNNF is decidable in linear time.

another special form of propositional WFFs: Decomposable Negation Normal Form (DNNF)

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 21 of 28 Example: The NNF shown on page 19 is in fact a DNNF.

Fact: Satisfiability of WFF in DNNF is decidable in linear time.

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 6= j

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 22 of 28 Fact: Satisfiability of WFF in DNNF is decidable in linear time.

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 6= 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 6= 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 P ::= ⊥ | > | p A ::= P | P ∧ A C ::= A → P 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: L1 ∧ · · · ∧ Ln → L ≡ ¬L1 ∨ · · · ∨ ¬Ln ∨ L.

Fact: Satisfiability of Horn formulas is decidable in linear time.

an important restricted class: Horn formulas

Assaf Kfoury, CS 512, Spring 2017, Handout 10 page 25 of 28 Fact: Satisfiability of Horn clauses is decidable in linear time. Proof: To see this, rewrite a Horn clause into an equivalent disjunction of literals: L1 ∧ · · · ∧ Ln → L ≡ ¬L1 ∨ · · · ∨ ¬Ln ∨ L.

Fact: Satisfiability of Horn formulas is decidable in linear time.

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: L1 ∧ · · · ∧ Ln → L ≡ ¬L1 ∨ · · · ∨ ¬Ln ∨ 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