CSE 311 Foundations of Administrative Computing I • Course web: http://www.cs.washington.edu/311 Spring 2013, Lecture 3 – Homework, Lecture slides, Office Hours ... Propositional Logic, Boolean Logic/Boolean Algebra • Homework: – Due Wednesday at the start of class 1 2 Announcements So far • Reading assignments • Propositional/Boolean logic – Propositional Logic – Basic logical connectives • 1.1 -1.3 7 th Edition • If pigs can whistle, then horses can fly • 1.1 -1.2 6 th Edition – Basic circuits – Boolean Algebra – Tautologies, equivalences (in progress) • 12.1 – 12.3 7 th Edition • 11.1 – 11.3 6 th Edition 3 4
Other gates (more later) Combinational Logic Circuits X Y Z X 0 0 1 • NAND Z 0 1 1 AND Y 1 0 1 1 1 0 OR X Y Z • NOR 0 0 1 X Z 0 1 0 AND Y 1 0 0 1 1 0 • XOR X Y Z X Design a 3 input circuit to compute the majority of 3. Output 1 if at least two 0 0 0 X ⊕ Y Z 0 1 1 inputs are 1, output 0 otherwise Y 1 0 1 1 1 0 • XNOR X Y Z X ↔ Y, X = Y X 0 0 1 What about a majority of 5 circuit? Z 0 1 0 Y 1 0 0 1 1 1 6 5 Review Review Logical equivalence Logical Equivalence • p and q are logically equivalent iff • Terminology: A compound proposition is a p ↔ q is a tautology – Tautology if it is always true – i.e. p and q have the same truth table – Contradiction if it is always false – Contingency if it can be either true or false • The notation p ≡ q denotes p and q are logically equivalent p ∨ ¬ p ∨ ∨ ¬ ∨ ¬ ¬ • Example: p ≡ ¬ ¬ p ¬ ¬ ¬ ¬ ¬ ¬ p ⊕ p p ¬ ¬ ¬ ¬ p ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ p p ↔ ↔ ↔ ¬ ↔ ¬ ¬ ¬ ¬ ¬ ¬ ¬ p ( p → q ) ∧ p ( p ∧ q ) ∨ ( p ∧ ¬ q ) ∨ ( ¬ p ∧ q ) ∨ ( ¬ p ∧ ¬ q ) 7 8
De Morgan ’ s Laws De Morgan ’ s Laws Review Review • ¬ (p ∧ q) ≡ ¬ p ∨ ¬ q Example: ¬ ( p ∧ ∧ q ) ≡ ( ¬ p ∨ ¬ q ) • ¬ (p ∨ q) ≡ ¬ p ∧ ¬ q ∧ ∧ • What are the negations of: p q ¬ ¬ ¬ ¬ p ¬ q ¬ ¬ ¬ ¬ ¬ ¬ p ∨ ¬ ∨ ∨ ∨ ¬ ¬ ¬ ¬ q p ∧ ∧ q ∧ ∧ ¬( ¬ ¬ ¬ ( ( ( p ∧ ∧ ∧ ∧ q) ¬ ¬( ¬ ¬ ( p ∧ ( ( ∧ ∧ ∧ q) ↔ ↔ ↔ ↔( ( ( (¬ ¬ ¬ ¬ p ∨ ∨ ¬ ∨ ∨ ¬ ¬ q) ¬ – The Yankees and the Phillies will play in the T T World Series – It will rain today or it will snow on New Year ’ s T F F T F F Day 9 10 Law of Implication Understanding connectives • Reflect basic rules of reasoning and logic Example: ( p → q ) ≡ ( ¬ p ∨ q ) • Allow manipulation of logical formulas – Simplification – Testing for equivalence p q p → → q ¬ p ¬ p ∨ ∨ q (p → → q) ↔ ↔ ( ¬ ¬ p ∨ ∨ q) → → ¬ ¬ ¬ ¬ ¬ ¬ ∨ ∨ → → ↔ ↔ ¬ ¬ ∨ ∨ • Applications – Query optimization – Search optimization and caching – Artificial Intelligence – Program verification 11 12
Equivalences relating to Properties of logical connectives implication • Identity • p → q ≡ ¬ p ∨ q • Domination • p → q ≡ ¬ q → ¬ p • Idempotent • Commutative • p ∨ q ≡ ¬ p → q • Associative • p ∧ q ≡ ¬ (p → ¬ q) • Distributive • p ↔ q ≡ (p → q) ∧ (q → p) • Absorption • Negation • p ↔ q ≡ ¬ p ↔ ¬ q • DeMorgan’s Laws • p ↔ q ≡ (p ∧ q) ∨ ( ¬ p ∧ ¬ q) • Double Negation • ¬ (p ↔ q) ≡ p ↔ ¬ q Textbook, 1.3 7 th Edition/1.2 6 th Edition, Table 6 13 14 Show ( p ∧ q ) → ( p ∨ q ) is a Logical Proofs tautology • To show P is equivalent to Q – 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 15 16
Show (p → q) → r and r → (q → p) are not equivalent Boolean Logic Applications of Propositional Logic for Circuits 17 18 A quick combinational logic Boolean logic example • Combinational logic • Calendar subsystem: number of days in a – output t = F(input t ) month (to control watch display) • Sequential logic – used in controlling the display of a wrist-watch – output t = F(output t-1 , input t ) LCD screen • output dependent on history • concept of a time step (clock) – inputs: month, leap year flag • An algebraic structure consists of – a set of elements B = {0, 1} – outputs: number of days – binary operations { + , • } (OR, AND) – and a unary operation { ’ } (NOT ) 19 20
Implementation as a Implementation in software combinational digital system integer number_of_days ( month, leap_year_flag) { • Encoding: switch (month) { – how many bits for each input/output? case 1: return (31); month leap d28 d29 d30 d31 – binary number for month 0000 – – – – – – four wires for 28, 29, 30, and 31 0001 – 0 0 0 1 case 2: if (leap_year_flag == 1) then 0010 0 1 0 0 0 return (29) else return (28); 0010 1 0 1 0 0 0011 – 0 0 0 1 case 3: return (31); 0100 – 0 0 1 0 month leap 0101 – 0 0 0 1 ... 0110 – 0 0 1 0 0111 – 0 0 0 1 case 12: return (31); 1000 – 0 0 0 1 1001 – 0 0 1 0 default: return (0); 1010 – 0 0 0 1 1011 – 0 0 1 0 } 1100 – 0 0 0 1 1101 – – – – – } d28 d29 d30 d31 1110 – – – – – 1111 – – – – – 21 22 Combinational example (cont.) Combinational example (cont.) • Truth-table to logic to switches to gates d28 = m8'•m4'•m2•m1'•leap’ – d28 = “1 when month=0010 and leap=0” d29 = m8'•m4'•m2•m1'•leap – d28 = m8'•m4'•m2•m1'•leap' d30 = (m8'•m4•m2'•m1') + (m8'•m4•m2•m1') + (m8•m4'•m2'•m1) + (m8•m4'•m2•m1) – d31 = “1 when month=0001 or month=0011 or ... month=1100” = (m8'•m4•m1') + (m8•m4'•m1) – d31 = (m8'•m4'•m2'•m1) + (m8'•m4'•m2•m1) + ... d31 = (m8'•m4'•m2'•m1) + (m8'•m4'•m2•m1) + (m8•m4•m2'•m1') (m8'•m4•m2'•m1) + (m8'•m4•m2•m1) + month leap d28 d29 d30 d31 – d31 = can we simplify more? 0000 – – – – – (m8•m4'•m2'•m1') + (m8•m4'•m2•m1') + 0001 – 0 0 0 1 (m8•m4•m2'•m1') 0010 0 1 0 0 0 0010 1 0 1 0 0 0011 – 0 0 0 1 0100 – 0 0 1 0 ... 1100 – 0 0 0 1 1101 – – – – – 111– – – – – – 23 CSE 311 24
Switches: basic element of physical Combinational logic implementations • Switches • Implementing a simple circuit (arrow • Basic logic and truth tables shows action if wire changes to “1”): • Logic functions A Z • Boolean algebra • Proofs by re-writing and by perfect induction close switch (if A is “1” or asserted) and turn on light bulb (Z) Z A open switch (if A is “0” or unasserted) and turn off light bulb (Z) Z ≡ A 25 26 Switches (cont.) Transistor networks • Modern digital systems are designed in • Compose switches into more complex ones CMOS technology (Boolean functions): B A – MOS stands for Metal-Oxide on AND Z ≡ A and B Semiconductor – C is for complementary because there are both normally-open and A normally-closed switches OR • MOS transistors act as voltage-controlled Z ≡ A or B switches – similar, though easier to work with than relays. B 27 28
Possible logic functions of two Multi-input logic gates variables • CMOS logic gates are inverting • There are 16 possible functions of 2 input variables: – Easy to implement NAND, NOR, NOT while AND, OR, and Buffer are harder – in general, there are 2**(2**n) functions of n inputs Claude Shannon – 1938 X 1.8V 1.8V 1.8V 1.8V F Y X X Y Z X Y X Y 16 possible functions (F 0 –F 15 ) Y 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 Z Z 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 X Y Z 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 X 0 0 1 X 0 1 1 0 1 X Y not X not Y X xor Y X = Y 1 0 1 X and Y X nand Y Y not (X and Y) 1 1 0 X or Y X nor Y Y not (X or Y) 0V 0V 29 30 Logic functions and Boolean Boolean algebra algebra • An algebraic structure consisting of Any logic function that can be expressed as a truth table can be written as an expression in Boolean algebra using the operators: ’, +, and • – a set of elements B George Boole – 1854 X, Y are Boolean algebra variables – binary operations { + , • } X Y X • Y X Y X’ X’ • Y – and a unary operation { ’ } 0 0 0 0 0 1 0 0 1 0 0 1 1 1 – such that the following axioms hold: 1 0 0 1 0 0 0 1 1 1 1 1 0 0 1. the set B contains at least two elements: a, b X Y X’ Y’ X • Y X’ • Y’ ( X • Y ) + ( X’ • Y’ ) 2. closure: a + b is in B a • b is in B 0 0 1 1 0 1 1 3. commutativity: a + b = b + a a • b = b • a 0 1 1 0 0 0 0 ( X • Y ) + ( X’ • Y’ ) � X = Y 4. associativity: a + (b + c) = (a + b) + c a • (b • c) = (a • b) • c 1 0 0 1 0 0 0 5. identity: a + 0 = a a • 1 = a 1 1 0 0 1 0 1 6. distributivity: a + (b • c) = (a + b) • (a + c) a • (b + c) = (a • b) + (a • c) 7. complementarity: a + a’ = 1 a • a’ = 0 Boolean expression that is true when the variables X and Y have the same value and false, otherwise 31 32
Recommend
More recommend