Presentation is loading. Please wait.

Presentation is loading. Please wait.

Disjunctive Normal Form

Similar presentations


Presentation on theme: "Disjunctive Normal Form"— Presentation transcript:

1 Disjunctive Normal Form
Math Foundations of Computer Science

2 Boolean Expressions A Boolean expression is a Boolean function
September 4, 1997 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 2 2

3 Disjunctive Normal Form
Theorem. Any boolean expression can be converted to an equivalent boolean exprssion in DNF. Proof. Any boolean expression defined 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.

4 Alternative Proof A recursive conversion algorithm with corresponding inductive proof of correctness. We can 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

5 Is-NNF (defun is-nnf (expr) (cond ( (is-constant expr) t) ( (is-variable expr) t ) ( (is-not expr) (is-variable (op1 expr)) ) ( (is-or expr) (and (is-nnf (op1 expr)) (is-nnf (op2 expr))) ) ( (is-and expr) (and (is-nnf (op1 expr)) (is-nnf (op2 expr))) ) )

6 NNF (mutual-recursion (defun nnf-not (expr) (cond ( (is-constant (op1 expr)) expr ) ( (is-variable (op1 expr)) expr ) ( (is-not (op1 expr)) (nnf (op1 (op1 expr))) ) ( (is-or (op1 expr)) (list 'and (nnf (list 'not (op1 (op1 expr)))) (nnf (list 'not (op2 (op1 expr))))) ) ( (is-and (op1 expr)) (list 'or (nnf (list 'not (op1 (op1 expr)))) )

7 NNF (defun nnf (expr) (cond ( (is-constant expr) expr ) ( (is-variable expr) expr ) ( (is-not expr) (nnf-not expr) ) ( (is-or expr) (list 'or (nnf (op1 expr)) (nnf (op2 expr))) ) ( (is-and expr) (list 'or (nnf (op1 expr)) (nnf (op2 expr))) ) )

8 Correctness (is-nnf (nnf expr)
Structural induction on expr using De Morgan’s laws and Double Negation law (not (and p q))  (or (not p) (not q)) (not (or p q))  (and (not p) (not q)) (not (not p))  p Base case. Expr = var or (not var) Assume true for expr1 and expr2 and show for (not expr), (or expr1 expr2), and (and expr1 expr2) and and or are trivial

9 Correctness for (not expr)
(is-nnf (nnf ‘(not expr)) (nnf ‘(not expr)) (nnf-not ‘(not expr)) Case 1. (nnf-not ‘(not (not expr))) = (nnf expr)) which is correct by induction and double negation Case 2. (nnf-not ‘(not (and expr1 expr2))) = (nnf ‘(or (not expr1) (not expr2))) = (list ‘or (nnf ‘(not expr1)) (nnf ‘(not expr2))) which is correct by induction and De Morgan Case 3. (nnf-not ‘(not (or expr1 expr2)))

10 Is-DNF (defun is-dnf (expr) (and (is-nnf expr) (no-andor expr)) ) ; no and above or (defun no-andor (expr) (cond ( (is-constant expr) t ) ( (is-variable expr) t ) ( (is-not expr) (no-andor (op1 expr)) ) ( (is-or expr) (and (no-andor (op1 expr)) (no-andor (op2 expr))) ) ( (is-and expr) (and (no-or (op1 expr)) (no-or (op2 expr))) )

11 Is-DNF (defun no-or (expr) (cond ( (is-constant expr) t) ( (is-variable expr) t ) ( (is-not expr) (no-or (op1 expr)) ) ( (is-or expr) nil ) ( (is-and expr) (and (no-or (op1 expr)) (no-or (op2 expr))) ) )

12 DNF (defun dnf (expr) (nnf2dnf (nnf expr)) ) (defun nnf2dnf (expr) (cond ( (is-constant expr) expr ) ( (is-variable expr) expr ) ( (is-not expr) expr ) ( (is-or expr) (list 'or (nnf2dnf (op1 expr)) (nnf2dnf (op2 expr))) ) ( (is-and expr) (distrib-andor (nnf2dnf (op1 expr)) (nnf2dnf (op2 expr))) )

13 Distribute And over Or (and E (or F1 F2)) (and (or E1 E2) F)
(or (and E F1) (and E F2)) (and (or E1 E2) F) (or (and E1 F) (and E2 F)) (and (or E1 E2) (or (F1 F2))  (or (and E1 F1) (and E1 F2) (and E2 F1) (and E2 F2)) (or (and E1 F1) (or (and E1 F2) (or (and E2 F1) (and E2 F2))))

14 DNF ; assume (and (is-dnf expr1) (is-dnf expr2)) ; distribute and over or in (and expr1 expr2) (defun distrib-andor (expr1 expr2) (cond ( (and (not (is-or expr1)) (not (is-or expr2))) (list 'and expr1 expr2) ) ( (and (not (is-or expr1)) (is-or expr2)) (list 'or (distrib-andor expr1 (op1 expr2)) (distrib-andor expr1 (op2 expr2))) ) ( (and (is-or expr1) (not (is-or expr2))) (list 'or (distrib-andor (op1 expr1) expr2) (distrib-andor (op2 expr1) expr2)) ) ( (and (is-or expr1) (is-or expr2)) (list 'or (distrib-andor (op1 expr1) (op1 expr2)) (list 'or (distrib-andor (op1 expr1) (op2 expr2)) (list 'or (distrib-andor (op2 expr1) (op1 expr2)) (distrib-andor (op2 expr1) (op2 expr2))))) ) ) )

15 Exponential Blowup (x1  y1)    (xn  yn)
(x1    xn)    (y1    yn) How many conjunctions in the converted expression?


Download ppt "Disjunctive Normal Form"

Similar presentations


Ads by Google