CSE20: Discrete Mathematics for Computer Science Lecture Unit 2: Boolan Functions, Logic Circuits, and Implication
Disjunctive normal form Example: Let f (x, y, z) =xy z. Write this function in DNF. Minterm xy z xyz xȳz takes the value 1 only when x = 1, 0, y = 1, 0, z = 0 1 x y z xy 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1 f P 1 P 2 P 3 P 4 P 5 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 P 1 = xȳz P 2 = xyz P 3 = xȳz P 4 = xy z P 5 = xyz DNF: f (x, y, z) = xȳz xyz xȳz xy z xyz Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 2
Conjunctive normal form Example: Let f (x, y, z) =xy z. Write this function in CNF. Maxterm takes the value 0 only when x y z x = y = z = 0 x y z xy f M 1 M 2 M 3 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 M 1 = x y z 0 1 0 0 0 1 0 1 M 2 = x ȳ z 0 1 1 0 1 1 0 0 0 0 1 1 1 1 1 0 M 3 = x y z 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 CNF: f (x, y, z) = x y z x ȳ z x y z Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 3
Canonical forms of boolean functions Summary: Disjunctive normal form (DNF) is OR of ANDs of all the variables or their negations. Conjunctive normal form (CNF) is AND of ORs of all the variables or their negations. Which of the following is in disjunctive normal form? A: p\/ q B: (p\/ q) \/ (p /\ q) C: (p\/ q) /\ (p\/ q) D: E: (p /\ q) \/ ( p /\ q) More than one of the above Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 4
Canonical forms of boolean functions Summary: Disjunctive normal form (DNF) is OR of ANDs of all the variables or their negations. Conjunctive normal form (CNF) is AND of ORs of all the variables or their negations. Which of the following is in conjunctive normal form? A: p /\ q B: (p\/ q) \/ (p /\ q) C: (p\/ q) /\ (p\/ q) D: E: (p /\ q) \/ ( p /\ q) None of the above Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 5
Simple two-input logic gates Here are the common symbols for some simple logic gates, along with the functions they implement: NOT gate AND gate OR gate f (x) = x f (x, y) =x f (x, y) =x y y NAND gate NOR gate XOR gate f (x, y) =(x y) = x ȳ f (x, y) =(x y) = x ȳ f (x, y) =x y = xy xȳ Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 6
Equivalent circuits and simplification Definition: Two logic circuits are logically equivalent if they implement the same boolean function. Is there a simpler circuit equivalent to the one below? xy f (x,y) y x f (x,y) x y x y f (x, y) = xy (x y) = xy ( xy xȳ) =(xy xy) xȳ = y(x x) xȳ = y xȳ = y x Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 7
Designing logic circuits Example: There are three light switches in a room. Design a circuit so that each switch is a toggle: moving it to the opposite position turns the lights on if they were off, and off is they were on. x y z ~f f 0 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 x y z Circuit? f (x,y,z) Disjunctive normal form for f (x,y,z): f (x, y, z) = xȳz xy z xȳ z xyz We need six NOT gates, eight AND gates, and three OR gates. Is it possible to simplify this? Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 8
Functionally complete set of gates For every statement form (compound proposition, propositional formula), there is a logically equivalent statement form that can be implemented using... A: only AND gates and OR gates B: only AND gates C: only NAND gates D: only NOT gates E: None or more than one of the above Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 9
Contrapositive, converse, and inverse Example: Consider the following implication statement: If you study hard, then you get an A in CSE20 Write down the contrapositive, the inverse, and the converse of this implication statement. Solution: Let us define: p = study hard and q = get an A in CSE20 Contrapositive (~q ~p): If you do not get an A in CSE20, then you did not study hard. Inverse (~p ~q): If you do not study hard, then you will not get an A in CSE20. Converse (q p): If you get an A in CSE20, then you did study hard. Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 10
Contrapositive, converse, and inverse The following chart summarizes the relationships between an implication, its contrapositive, its converse, and its inverse: p q Converse q p Contrapositive. ~q ~p Logically Equivalent Inverse Inverse Converse ~p ~q Contrapositive. Logically Equivalent Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 11
Contrapositive, converse, and inverse Example: Consider the following implication statement: If the program is running, then there is at least 64KB of RAM Which of the following is logically equivalent to this statement? a: b: c: d: e: f: If there is at least 64KB of RAM, then the program is running. If there is less than 64KB of RAM, then the program is running. The program will run only if there is at least 64KB or RAM. If the program is not running, there is less than 64KB of RAM. A necessary condition for the program to run is that there is at least 64KB of RAM. A sufficient condition for the program to run is that there is at least 64KB of RAM. Lecture Unit 1 CSE 20: Discrete Mathematics for Computer Science 12