Pre-Class Learning Outcomes By the start of this class you should be able to CPSC 121: Models of Computation Translate back and forth between simple natural language statements and propositional logic, now with conditionals and biconditionals. Evaluate the truth of propositional logical statements that include conditionals and biconditionals using truth tables Given a propositional logic statement and an equivalence Unit 2 rule, apply the rule to create an equivalent statement. Conditionals and Logical Equivalences Based on slides by Patrice Belleville and Steve Wolfman Unit 2 - Conditionals Unit 2 - Conditionals 1 2 Quiz 2 feedback In-Class Learning Goals Most frequent mistakes: By the end of this unit, you should be able to: Explore alternate forms of propositional logic statements by application of equivalence rules, especially in order to simplify complex statements or massage statements into a desired form. Evaluate propositional logic as a “model of computation” for combinational circuits and identify at Open-ended question? least one explicit shortfall (e.g., referencing gate delays, wire length, instabilities, shared sub-circuits, etc.).. Unit 2 - Conditionals 3 4 1
The Meaning of Where We Are inThe Big Stories Theory The meaning of if p then q in propositional logic is not Hardware quite the same as in normal language. How do we model How do we build devices Consider: computational systems? to compute? if it's at least 20ºC tomorrow, then I will come to UBC in shorts and T-shirt Now: Now: Suppose it's -2ºC and snowing. Based on the above practicing a second learning to modify circuit proposition, will I come to UBC in shorts and T-shirt? technique for formally designs using our logical A. Yes establishing the truth of model B. No a statement (logical gaining more practice C. Maybe equivalence proofs). designing circuits (the first technique was identifying a flaw in our truth tables.) model for circuits. Unit 2 - Conditionals 5 6 The Meaning of The Meaning of Consider the proposition Consider again: p: If you fail the final exam, then you will fail the course p: If you fail the final exam, then you will fail the course If you fail the final exam, will you fail the course? You need to distinguish between A. Yes The truth value of p (whether or not I lied). B. No The truth value of the conclusion (whether or not you failed C. Maybe the course). If you pass the final exam, will you fail the course? A. Yes B. No C. Maybe Unit 2 - Conditionals Unit 2 - Conditionals 7 8 2
More on the Meaning of Equivalence Proofs Which of the following statements are equivalent to : How do we write a logical equivalence proof? if p then q ? We state the theorem we want to prove. 1. if not p then not q p q p q p unless q p only if q We indicate the beginning of the proof by Proof: A. YES B. NO F F T 2. if not q then not p We start with one side and work towards the other, A. YES B. NO F T T o one step at a time, using the basic equivalences 3. p unless q T F F shown on next page A. YES B. NO o without forgetting to justify each step T T T 4. q unless not p A. YES B. NO o usually we will simplify the more complicated 5. q only if p Note: proposition, instead of trying to complicate the r unless s A. YES B. NO simpler one. means 6. p only if q We indicate the end of the proof by QED or if ~s then r A. YES B. NO Unit 2 - Conditionals Unit 2 - Conditionals 9 10 Writing an Equivalence Proof Basic Logical Equivalences Name Rule Name Rule Theorem: (~a b) a a b p ^ T ≡ p p ^ F ≡ F Identity law Domination law p v F ≡ p p v T ≡ T Proof: p ^ p ≡ p p ^ q ≡ q ^ p Idempotent law Commutative (~a b) a p v p ≡ p p v q ≡ q v p law a (~a b) commutative p ^ (q ^ r) ≡ (p ^ q) ^ r p v (q ^ r) ≡ (p v q) ^ (p v r) (a ~a) (a b) distributive Associative law Distributive law p v (q v r) ≡ (p v q) v r p ^ (q v r) ≡ (p ^ q) v (p ^ r) What’s missing? ______________ a b identity a. (a b) p v (p ^ q) ≡ p p ^ ~p ≡ F Absorption law Negation law b. F (a b) p ^ (p v q) ≡ p p v ~p ≡ T QED c. a (a b) ~(~p) ≡ p DeMorgan's law ~(p ^ q) ≡ (~p) v (~q) Double negative ~(p v q) ≡ (~p) ^ (~q) law d. None of these, but I know what it is. Definition of ⊕ p ⊕ q ≡ (p v q) ^ ~(p ^ Definition of → p → q ≡ ~p v q e. None of these, and there’s q) not enough information to p → q ≡ (~q) → ( ~p) Contrapositive law tell. Unit 2 - Conditionals 11 12 3
Examples of Equivalence Proofs How Good Propositional Logic Is? Prove that Propositional Logic is not a perfect model of how gates ~p → ~q ≡ q → p work. ~p ∧ q ≡ (~p ∨ q) ∧ ~ (~q ∨ p) To understand why, we will look at a multiplexer We will do these on the board . A circuit that chooses between two or more values. In its simplest form, it takes 3 inputs o An input a , an input b , and a control input select . NOTE: From now on we can skip the steps for the o It outputs a if select is false, and b if select is true. following rules: commutative associative double negation Unit 2 - Conditionals Unit 2 - Conditionals 13 14 Multiplexer MUX Design Truth table: Here is one possible implementation (call select “c”): a b c output call it c F F F F Outputs a ’s value F F T F when c is F and b ’s when c is T: F T F F F T T T (~a b c) T F F T ( a ~b ~c) ( a b ~c) T F T F Let us see why this may not work as we ( a b c) T T F T expect... ≡ T T T T ( a ~c) (b c) Unit 2 - Conditionals Unit 2 - Conditionals 15 16 4
Truthy MUX Glitch in MUX Design Suppose the circuit is in steady-state with a, b, c all T What is the intended output if both a and b are T? T F F A. T T B. F T T C. Unknown... but could be answered given a value for c. D. Unknown... and might still be unknown even given a T value for c. Assume the gate delay is 10ns Unit 2 - Conditionals 17 18 Trace – 5 ns Trace How long will it take before output reflects any Suppose that at time 0 we switch c to F. changes in a, b, c and is stable? At time 5ns: A. 5ns T F B. 10ns F T C. 20ns T F D. 30ns F T T E. 40ns T T T F. It may never be stable G. None of the above. F T Unit 2 - Conditionals Unit 2 - Conditionals 19 20 5
Trace – 10 ns Trace – 20 ns At time 10ns: At time 20ns: T T F T T T T T T F F F F F Note: the output is now F Unit 2 - Conditionals Unit 2 - Conditionals 21 22 Trace – 30 ns Trace – 40 ns At time 30ns: At time 40ns: T T T T T T T T T T F F F F Note: the output is now T again. Unit 2 - Conditionals Unit 2 - Conditionals 23 24 6
More MUX Glitches A Correct Design for MUX Cause of the problem: information from c travels two Here is a multiplexer that avoids the instability: paths with different delays. Output can be incorrect until the longer path “catches up”. Which one(s) of the following operation may cause an instability? A. Changing a only B. Changing b only C. Changing c, when at least one of a, b is F D. Both (a) and (b) Exercise: Prove that it’s logically equivalent to the E. None of (a), (b) and (c) original MUX Hint: write (a ^ b) as (a ^ b ^ (c v ~c)) Unit 2 - Conditionals Unit 2 - Conditionals 25 26 Exercises Exercises Consider the sentence: “Two strings s1 and s2 are Consider the code: if target = value then equal if either both strings are null or neither s1 nor s2 is null and both strings have the same sequence of o if lean-left-mode = true then • call the go-left() routine characters”. o else Let • call the go-right() routine o n1: the string s1 is null else if target < value then o n2: the string s2 is null o call the go-left() routine o eq: s1 and s2 are equal else o s: the two strings have the same sequence of characters. o call the go-right routine Is the given sentence logically equivalent to Let gl mean “the go - left() routine is called”. Complete eq ↔ (n1 ^ n2) v s ? the following: gl ↔ Unit 2 - Conditionals Unit 2 - Conditionals 27 28 7
Exercises What is coming up? The third online quiz is due ______________________ Prove: Assigned reading for the quiz: (a ^ ~b) v (~a ^ b) ≡ (a v b) ^ ~ (a ^ b) o Epp, 4th edition: 2.5 o Epp, 3rd edition: 1.5 o Rosen, any edition: not much • http://en.wikipedia.org/wiki/Binary_numeral_system o Also read: • http://www.ugrad.cs.ubc.ca/~cs121/2009W1/Handouts /signed-binary-decimal-conversions.html Unit 2 - Conditionals Unit 2 - Conditionals 29 30 8
Recommend
More recommend