9/30/2013 announcements CSE 311: Foundations of Computing Fall 2013 Reading assignments Lecture 3: Logic and Boolean algebra – Propositional Logic 1.1 -1.3 7 th Edition 1.1 -1.2 6 th Edition – Boolean Algebra 12.1 – 12.3 7 th Edition 11.1 – 11.3 6 th Edition combinational logic circuits some other gates X Y Z X 0 0 1 NAND Z 0 1 1 Y 1 0 1 ¬ ∧ ¬ 1 1 0 X Y Z Design a circuit to compute the majority of 3 bits. NOR 0 0 1 X Z 0 1 0 ¬ ∨ ¬ Y 1 0 0 1 1 0 X Y Z XOR X 0 0 0 Z ⊕ 0 1 1 Y 1 0 1 What about majority of 5 bits? 1 1 0 XNOR ↔ , = X Y Z X 0 0 1 Z 0 1 0 Y 1 0 0 1 1 1 1
9/30/2013 review: logical equivalence review: logical equivalence Terminology: A compound proposition is a p and q are logically equivalent if and only if Tautology if it is always true p q is a tautology Contradiction if it is always false i.e. p and q have the same truth table Contingency if it can be either true or false The notation p q denotes p and q are logically equivalent p ∨ ¬ p p ¬ ¬ p p p Example: ( p q ) p ¬ p ¬ ¬ p p ↔ ¬ ¬ p p ( p q ) ( p q ) ( p q ) ( p q ) review: De Morgan’s laws review: De Morgan’s laws (p q) p q Example: ( p ∧ q ) ( p q ) (p q) p q ¬ p ¬ q ¬ p ∨ ¬ q p ∧ q ¬ ( p ∧ q ) ¬ ( p ∧ q ) ↔ ( ¬ p ∨ ¬ q ) p q What are the negations of: T T T F The Yankees and the Phillies will play F T in the World Series. F F It will rain today or it will snow on New Year’s Day. 2
9/30/2013 review: Law of Implication understanding connectives • Reflect basic rules of reasoning and logic ( p q ) ( p q ) • Allow manipulation of logical formulas – Simplification – Testing for equivalence p → q ¬ p ¬ p ∨ q ( p → q ) ↔ ( ¬ p ∨ q ) p q • Applications T T – Query optimization T F F T – Search optimization and caching F F – Artificial Intelligence – Program verification review: properties of logical connectives some equivalences related to implication • Identity p q p q • Domination p q q p • Idempotent p q p q • Commutative p q (p q) • Associative p q (p q) (q p) • Distributive p q p q • Absorption p q (p q) ( p q) • Negation (p q) p q • De Morgan’s Laws Textbook: 1.3 7 th Edition/1.2 6 th Edition, Table 6 3
9/30/2013 some equivalences related to implication logical proofs To show P is equivalent to Q p q q p – Apply a series of logical equivalences to subexpressions to convert P to Q To show P is a tautology – Apply a series of logical equivalences to subexpressions to convert P to T prove this is a tautology prove this is a tautology ( p ( p q )) q ( p q ) ( p q ) 4
9/30/2013 proving non-equivalence boolean logic Combinational logic ( p q ) r p ( q r) – output = input Sequential logic – output = output , input • output dependent on history • concept of a time step (clock) An algebraic structure consists of – a set of elements B = {0, 1} – binary operations { + , • } (OR, AND) – and a unary operation { ’ } (NOT ) a quick combinational logic example implementation in software Calendar subsystem: integer number_of_days (month, leap_year_flag){ # of days in a month (to control watch display) switch (month) { case 1: return (31); case 2: if (leap_year_flag == 1) then – used in controlling the display of a wrist-watch return (29) else return (28); LCD screen case 3: return (31); ... – inputs: month, leap year flag case 12: return (31); – outputs: number of days default: return (0); } } Example: (March, non-leap year) → 31 20 5
9/30/2013 implementation with combinatorial logic implementation with combinatorial logic Truth-table to logic to switches to gates Encoding: - how many bits for each input/output? d28 = “1 when month=0010 and leap=0” - binary number for month d28 = m8'•m4'•m2•m1'•leap‘ month leap d28 d29 d30 d31 - four wires for 28, 29, 30, and 31 d31 = “1 when month=0001 or month=0011 or ... month=1100” 0000 – – – – – 0001 – 0 0 0 1 d31 = (m8'•m4'•m2'•m1) + (m8'•m4'•m2•m1) + 0010 0 1 0 0 0 0010 1 0 1 0 0 ... + (m8•m4•m2'•m1') month leap 0011 – 0 0 0 1 0100 – 0 0 1 0 d31 = can we simplify more? 0101 – 0 0 0 1 month leap d28 d29 d30 d31 0110 – 0 0 1 0 0000 – – – – – 0111 – 0 0 0 1 0001 – 0 0 0 1 1000 – 0 0 0 1 0010 0 1 0 0 0 1001 – 0 0 1 0 0010 1 0 1 0 0 1010 – 0 0 0 1 0011 – 0 0 0 1 1011 – 0 0 1 0 0100 – 0 0 1 0 1100 – 0 0 0 1 ... d28 d29 d30 d31 1101 – – – – – 1100 – 0 0 0 1 1110 – – – – – 1101 – – – – – 1111 – – – – – 111– – – – – – implementation with combinatorial logic combinational logic d28 = m8'•m4'•m2•m1'•leap’ • Switches d29 = m8'•m4'•m2•m1'•leap • Basic logic and truth tables d30 = (m8'•m4•m2'•m1') + (m8'•m4•m2•m1') + • Logic functions (m8•m4'•m2'•m1) + (m8•m4'•m2•m1) • Boolean algebra = (m8'•m4•m1') + (m8•m4'•m1) • Proofs by re-writing and by truth table d31 = (m8'•m4'•m2'•m1) + (m8'•m4'•m2•m1) + (m8'•m4•m2'•m1) + (m8'•m4•m2•m1) + (m8•m4'•m2'•m1') + (m8•m4'•m2•m1') + (m8•m4•m2'•m1') 6
Recommend
More recommend