disjunctive normal form cs 270: math foundation of cs jeremy johnson

22
Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Upload: aleesha-simpson

Post on 17-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Disjunctive Normal Form

CS 270: Math Foundation of CSJeremy Johnson

Page 2: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Objective

To review disjunctive normal form (dnf) and present an algorithm to convert an arbitrary Boolean expression to an equivalent one in dnf

Equivalence of any particular Boolean expression and the one returned can be proven with natural deduction, but the correctness for all possible inputs requires additional proof techniques (induction)

Page 3: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

3

Boolean Expressions A Boolean expression is a Boolean function Any Boolean function can be written as a Boolean

expression

Disjunctive normal form (sums of products) For each row in the truth table where the output is true,

write a product such that the corresponding input is the only input combination that is true

Not unique

E.G. (multiplexor function)

s x0 x1 f

0 0 0 0

0 0 1 0

0 1 0 1

0 1 1 1

1 0 0 0

1 0 1 1

1 1 0 0

1 1 1 1

Page 4: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Disjunctive Normal Form

Theorem. Any boolean expression can be converted to an equivalent boolean exprssion in DNF. Proof. Any boolean expression defines a

boolean function. Construct the truth table for the boolean expression and use the procedure on the previous slide to construct a boolean expression in DNF for the function defined by the truth table.

Page 5: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Alternative Proof

A recursive conversion algorithm with corresponding inductive proof of correctness. Assume that implications and equivalences have

been removed Assume that constants have been eliminated First convert to Negative Normal Form (NNF)

(not expr) only occurs when expr is a variable Use DeMorgan’s Law and Double Negation Law

Then convert to DNF Distribute and over or

Page 6: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

DeMorgan’s Law

(E F) E F

E F

E F

Page 7: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Double Negation

E E

E

E

Page 8: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

NNF Example

a

b c

Page 9: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

NNF Example

[DeMorgan’s Law]

a

b c

Page 10: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

NNF Example

[DeMorgan’s Law]Recursively convert operands

a

b c

Page 11: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

NNF Example

[DeMorgan’s Law] [Double Negation Law]

a

b c

Page 12: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

NNF Example

[DeMorgan’s Law] [Double Negation Law]

) [DeMorgan’s Law]

a

b c

Page 13: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Conversion to NNFDefine NNF(expr)

Input: expr is a Boolean Expression,

Output: an equivalent Boolean Expression in NNF

if isConstant(expr) return expr

if isVariable(expr) return expr

if isNegation(expr) return NNF_Not(expr)

if isDisjunction(expr) return NNF(op1(expr)) NNF(op2(expr))

if isConjunction(expr) return NNF(op1(expr)) NNF(op2(expr))

Page 14: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

NNF_NotDefine NNF_Not(expr)

Input: is a Boolean Expression with expr = expr1

Output: an equivalent Boolean Expression in NNF

expr1 = op(expr)

if isConstant(expr1) return expr

if isVariable(expr1) return expr

if isNegation(expr1) return NNF(op(expr1)) [remove double negation]

if isDisjunction(expr1) return NNF( op1(expr1) NNF( op2(expr1)) [DeMorgan’s Law]

if isConjunction(expr1) return NNF( op1(expr1)) NNF( op2(expr1))

[DeMorgan’s Law]

Page 15: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Alternative Proof

A recursive conversion algorithm with corresponding inductive proof of correctness. Assume that implications and equivalences have

been removed Assume that constants have been eliminated First convert to Negative Normal Form (NNF)

(not expr) only occurs when expr is a variable Use DeMorgan’s Law and Double Negation Law

Then convert to DNF Distribute and over or

Page 16: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Distribute And over Or

1. E (F1 F2)º (E F1) (E F2)

2. (E1 E2) Fº (E1 F) (E2 F)

F1 F2

E

E F2

E F1

Page 17: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

DNF Example

c 𝑑

a b

Page 18: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

DNF Example

( ))

𝑑

𝑐

a b

a b

Page 19: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

DNF Example

( )) ( ) )

𝑑

a 𝑐

a b

b 𝑐

Page 20: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

DNF Example

( )) ( ) ) ( )

a 𝑐

b 𝑐

a 𝑑

b 𝑑

Page 21: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Conversion to DNFDefine DNF(expr)

Input: expr is a Boolean Expression in NNF

Output: an equivalent Boolean Expression in DNF

if isConstant(expr) return expr

if isVariable(expr) return expr

if isNegation(expr) return expr

if isDisjunction(expr) return DNF(op1(expr)) DNF(op2(expr))

if isConjunction(expr) return DistributeAndOverOr (DNF(op1(expr)) DNF(op2(expr)))

Page 22: Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson

Exponential Blowup

Converting the following expression shows that an exponential increase in the size of the DNF form of a boolean expression is possible

(x1 y1) (xn yn)

(x1 xn) (y1 yn)