Introduction to Computers and Programming Prof. I. K. Lundqvist Lecture 18 May 3 2004 Four Variable K-Maps Example-2 Using a 4-variable K-Map, simplify the following Truth table A B C D Output 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 AB CD 00 01 11 0 1 0 0 0 0 0 1 11 0 0 0 0 10 0 0 1 0 00 01 10 Output = ABCD + ABCD + ABCD 3 Four Variable K-Maps Example-2 Using a 4-variable K-Map, simplify the following Truth table A B C D Output 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 1 1 1 AB CD 00 01 11 10 00 01 11 10 4 Product-of-Sums from a Truth Table A 0 0 0 0 1 1 1 1 B 0 0 1 1 0 0 1 1 C 0 1 0 1 0 1 0 1 F 0 0 0 1 1 1 1 1 F 1 1 1 0 0 0 0 0 Find an expression for F F = ABC + ABC + ABC F = ABC + ABC + ABC F = ABC • ABC • ABC F = ( A + B + C) • ( A + B + C ) • ( A + B + C) 6 Maxterms A 0 0 0 0 1 1 1 1 B 0 0 1 1 0 0 1 1 C 0 1 0 1 0 1 0 1 F 0 0 0 1 1 1 1 1 F 1 1 1 0 0 0 0 0 Maxterms F = ( A + B + C) • ( A + B + C ) • ( A + B + C) • To find a Product-of-Sums form for a truth table – Make one maxterm for each row in which the function is zero – For each maxterm, each variable appears once • In its complemented form if it is one in the row • In its regular form if it is zero in the row 7 Today • Propositional Logic • From English to propositions • Quantified statements • Tomorrow: Methods of proving theorems 8 Propositional Logic • Logic at the sentential level – Smallest unit: sentence – Sentences that can be either true or false – This kind of sentences are called Propositions • If a propositions is true, then its truth value is “true”, if proposition if false, then the truth value is “false” 9 Propositional Logic • The following are propositions: – Grass is green –2+4=4 • The following are not propositions: – – – – Wake up Is it raining today? X>2 X=X 10 Elements of Propositional Logic Connectives not ¬ and ∧ or ∨ if_then (implies) iff → ↔ 11 Connectives P Q (P ∨ Q) P Q (P ∧ Q) P Q (P → Q) F F T T F T F T F T T T F F T T F T F T F F F T F F T T F T F T T T F T P ¬P P Q (P ↔ Q) T F F T F F T T F T F T T F F T Truth tables 12 Concept Question Given P Æ Q, Is Q Æ P True? 1. Yes 2. No 3. I don’t know 4. What is P->Q 13 Converse and Contrapositive • For P Æ Q QÆP ¬Q Æ ¬P is called its converse is called its contrapositive Example: If it rains, then I get soaked converse : If I get soaked, then it rains contrapositive : If I don’t get soaked, then it does not rain 14 From English to Proposition • Premises: P Q – It snows – If it snows, then the school is closed The school is closed • Rules of inference [P ∧ (P Æ Q)] Æ Q 15 From English to Proposition • Restate given statements using building blocks and the connectives • Propositions –P –Q –R it is raining I will go to the beach I have time • “I will go to the beach if it is not raining” restate “If it is not raining, I will go to the beach” restate ¬PÆQ 16 Exercise • Restate: ” I will go to the beach if is not raining and I have time ” “If it is not raining and I have time, then I will go to the beach” (¬P ∧ R) Æ Q 17 Rule of Inference: Modus Ponens (p ∧ (p → q)) → q is a tautology. It states that if we know that both an implication p → q is true and that its hypothesis, p, is true, then the conclusion, q, is true. Ex: Suppose the implication “If the bus breaks down, then I will have to walk” and its hypothesis “the bus breaks down” are true. Then by modus ponens it follows that “I will have to walk”. Ex: Assume that the implication (n > 3) → (n2 > 9) is true. Suppose also that n > 3. Then by modus ponens, it follows that n2 > 9. 18 Fallacy: Affirming the Conclusion (q ∧ (p → q)) → p is a contingency. It states that if we know that both an implication p → q is true and that its conclusion, q, is true, then the hypothesis, p, is true. Ex: Suppose the implication “If the bus breaks down, then I will have to walk” and its conclusion “I will have to walk” is true. It does not follow that the bus broke down. Perhaps I simply missed the bus. Ex: Consider the implication (n > 3) → (n2 > 9) which is true. Suppose also that n2 > 9. It does not follow that n > 3. It might be that n = -4 for example. 19