cpsc 121 models of computation
play

CPSC 121: Models of Computation Module 2: Conditionals and Logical - PowerPoint PPT Presentation

CPSC 121: Models of Computation Module 2: Conditionals and Logical Equivalences Module 2: Coming up... Pre-class quiz #3: due Wednesday September 19 th at 19:00. Assigned reading for the quiz: Epp, 4th edition: 2.5 Epp, 3rd edition: 1.5


  1. CPSC 121: Models of Computation Module 2: Conditionals and Logical Equivalences

  2. Module 2: Coming up... Pre-class quiz #3: due Wednesday September 19 th at 19:00. Assigned reading for the quiz: Epp, 4th edition: 2.5 Epp, 3rd edition: 1.5 http://en.wikipedia.org/wiki/Binary_numeral_system Also read: http://www.ugrad.cs.ubc.ca/~cs121/current/handouts/signed- binary-decimal-conversions.html Assignment #1 is due Monday September 24 th at 16:00. CPSC 121 – 2018W T1 2

  3. Module 2: Coming up... Pre-class quiz #4: tentatively due Monday September 24 th at 19:00. Assigned reading for the quiz: Epp, 4th edition: 2.3 Epp, 3rd edition: 1.3 Rosen, 6th edition: 1.5 up to the bottom of page 69. Rosen, 7th edition: 1.6 up to the bottom of page 75. CPSC 121 – 2018W T1 3

  4. Module 2: Conditionals and Logical Equivalences By the start of this class you should be able to 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 rule, apply the rule to create an equivalent statement. CPSC 121 – 2018W T1 4

  5. Module 2: Conditionals and Logical Equivalences CPSC 121: the BIG questions: ? ? ? We are not quite ready yet to directly address any ? ? of the big questions. Our discussion of propositional logic gets us closer ? ? to proving facts about our algorithms. ? ? ? We will look at circuits a bit more, and talk about a multiplexer : a component that is very useful when ? building computers. ? ? ? ? ? ? CPSC 121 – 2018W T1 5

  6. Module 2: Conditionals and Logical Equivalences 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, including at least one explicit shortfall (e.g., referencing gate delays, fan-out, transistor count, wire length, instabilities, shared sub-circuits, etc.). CPSC 121 – 2018W T1 6

  7. Module 2: Conditionals and Logical Equivalences Module Outline: Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises CPSC 121 – 2018W T1 7

  8. Module 2.1: Logic vs Everyday English Be careful! The meaning of if p then q in propositional logic is not quite the same as in normal language. Consider: if it's 20ºC tomorrow, then I will come to UBC in shorts and T-shirt. Suppose it's -2ºC and snowing. Based on the above proposition, will I come to UBC in shorts and T- shirt? a) Yes b) No c) Maybe ▷ CPSC 121 – 2018W T1 8

  9. Module 2.1: Logic vs Everyday English Consider the proposition p: If you fail the final exam, then you will fail the course You need to distinguish between The truth value of p (whether or not I lied). The truth value of the conclusion (whether or not you failed the course). CPSC 121 – 2018W T1 10

  10. Module 2.1: Logic vs Everyday English If you fail the final exam, will you pass the course? a) Yes b) No c) Maybe ▷ CPSC 121 – 2018W T1 11

  11. Module 2.1: Logic vs Everyday English If you pass the final exam, will you pass the course? a) Yes b) No c) Maybe ▷ CPSC 121 – 2018W T1 13

  12. Module 2: Conditionals and Logical Equivalences Module Outline: Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises CPSC 121 – 2018W T1 15

  13. Module 2.2: Logical Equivalence Proofs How do we write a logical equivalence proof? We state the theorem we want to prove. We indicate the beginning of the proof by Proof: We start with one side and work towards the other, one step at a time, without forgetting to justify each step usually we will simplify the more complicated proposition, instead of trying to complicate the simpler one. We indicate the end of the proof by QED or CPSC 121 – 2018W T1 16

  14. Module 2.2: Logical Equivalence Proofs Example: prove that (~a ^ b) v a ≡ a v b Proof: (~a ^ b) v a ≡ a v (~a ^ b) commutative law ≡ (a v ~a) ^ (a v b) distributive law ≡ ≡ a v b identity law What is missing? a) (a v b) b) F ^ (a v b) c) a ^ (a v b) d) Something else e) Not enough info to tell ▷ CPSC 121 – 2018W T1 17

  15. Module 2.2: Logical Equivalence Proofs Rule Name Rule Name Identity laws p ^ T ≡ p Universal bounds p ^ F ≡ F p v F ≡ p laws p v T ≡ T Idempotent laws p ^ p ≡ p Commutative laws p ^ q ≡ q ^ p p v p ≡ p p v q ≡ q v p Associative laws p ^ (q ^ r) ≡ (p ^ q) ^ r Distributive laws p v (q ^ r) ≡ (p v q) ^ (p v r) p v (q v r) ≡ (p v q) v r p ^ (q v r) ≡ (p ^ q) v (p ^ r) Absorption laws p v (p ^ q) ≡ p Negation laws p ^ ~p ≡ F p ^ (p v q) ≡ p p v ~p ≡ T Double negative ~(~p) ≡ p DeMorgan's laws ~(p ^ q) ≡ (~p) v (~q) law ~(p v q) ≡ (~p) ^ (~q) Definition of ⊕ p ⊕ q ≡ (p v q) ^ ~(p ^ q) Definition of → p → q ≡ ~p v q Contrapositive p → q ≡ (~q) → ( ~p) law CPSC 121 – 2018W T1 19

  16. Module 2.2: Logical Equivalence Proofs Examples: prove that ~p → ~q ≡ q → p ∧ ∨ ∧ ∨ ~p q ≡ (~p q) ~ (~q p) We will do these on the board with the slides providing a list of equivalences. CPSC 121 – 2018W T1 20

  17. Module 2: Conditionals and Logical Equivalences Module Outline: Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises CPSC 121 – 2018W T1 21

  18. Module 2.3: Multiplexers Propositional Logic is not a perfect model of how gates work. To understand why, we will look at a multiplexer A circuit that chooses between two or more values. In its simplest form, it takes 3 inputs An input a, an input b, and a control input select. It outputs a if select is false, and b if select is true. CPSC 121 – 2018W T1 22

  19. Module 2.3: Multiplexers b select output a Truth table: F F F F F F T F F T F F F T T T T F F T T F T F T T F T T T T T CPSC 121 – 2018W T1 23

  20. Module 2.3: Multiplexers Here is one possible implementation: select Let us see why this may not work as we expect... CPSC 121 – 2018W T1 24

  21. Module 2.3: Multiplexers Suppose a, b, select are initially T T F T F T T T select Assume the gate delay is 10ns CPSC 121 – 2018W T1 25

  22. Module 2.3: Multiplexers How long will it take before output reflects any changes in a, b, select and is stable? a) 10ns T b) 20ns F T F c) 30ns T T d) 40ns T e) It may never be stable select ▷ CPSC 121 – 2018W T1 26

  23. Module 2.3: Multiplexers Now we switch select to F. At time 5ns: T F T F T T F select CPSC 121 – 2018W T1 28

  24. Module 2.3: Multiplexers At time 10ns: T F T T F T F select CPSC 121 – 2018W T1 29

  25. Module 2.3: Multiplexers At time 20ns: T T F T F T F select Note: the output is now F CPSC 121 – 2018W T1 30

  26. Module 2.3: Multiplexers At time 30ns: T T T T F T F select Note: the output is now T again. CPSC 121 – 2018W T1 31

  27. Module 2.3: Multiplexers The cause of the problem: the information from select travels on two different paths to the output these paths contain different numbers of gates so the shorter path may affect the output until the information on the longer path catches up. CPSC 121 – 2018W T1 32

  28. Module 2.3: Multiplexers Which one(s) of the following operation may cause an instability? a) Changing a or b only b) Changing select, when at exactly one of a, b is F c) Changing select, when both a, b are F d) Both (a) and (b) e) None of (a), (b) or (c). ▷ select CPSC 121 – 2018W T1 33

  29. Module 2.3: Multiplexers Here is a multiplexer that avoid the instability: select CPSC 121 – 2018W T1 35

  30. Module 2: Conditionals and Logical Equivalences Module Outline: Logic vs Everyday English Logical Equivalence Proofs Multiplexers More exercises CPSC 121 – 2018W T1 36

  31. Module 2.4: More exercises Consider the code: if target = value then if lean-left-mode = true then call the go-left() routine else call the go-right() routine else if target < value then call the go-left() routine else call the go-right routine Let gl mean “the go-left() routine is called”. Complete the following: gl ↔ CPSC 121 – 2018W T1 37

  32. Module 2.4: More exercises Consider: The Java [String] equals() method returns true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. Let n1: the string is null n2: the argument is null nt: the method returns true s: the two objects are strings that represent the same sequence of characters. CPSC 121 – 2018W T1 38

  33. Module 2.4: More exercises Is the sentence logically equivalent to nt ↔ (n1 ^ n2) v s? Why or why not? Prove : (a ^ ~b) v (~a ^ b) ≡ (a v b) ^ ~ (a ^ b) CPSC 121 – 2018W T1 39

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend