cpsc 121 models of computation
play

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

CPSC 121: Models of Computation Unit 2: Conditionals and Logical Equivalences CPSC 121 2011W T2 Unit 2: Conditionals and Logical Equivalences The third online quiz is due Sunday at 21:00. Assigned reading for the quiz: Epp, 4 th


  1. CPSC 121: Models of Computation Unit 2: Conditionals and Logical Equivalences CPSC 121 – 2011W T2

  2. Unit 2: Conditionals and Logical Equivalences The third online quiz is due Sunday at 21:00.  Assigned reading for the quiz:  Epp, 4 th edition: 2.5  Epp, 3 rd edition: 1.5  Rosen, any edition: not much  http://en.wikipedia.org/wiki/Binary_numeral_system  Also read:  http://www.ugrad.cs.ubc.ca/~cs121/2009W1/Handouts/signed- binary-decimal-conversions.html Assignment #1 is due Thursday at 17:00. CPSC 121 – 2011W T2

  3. Unit 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 – 2011W T2

  4. Unit 2: Conditionals and Logical Equivalences Quiz 2 feedback:  Very well done.  We discussed the open-ended question as part of the previous topic, so there is no need to go over it again. CPSC 121 – 2011W T2

  5. Unit 1: Propositional Logic 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 a circuits a bit more, and talk about a multiplexer : an component that is very useful when ? building computers. ? ? ? ? ? ? CPSC 121 – 2011W T2

  6. Unit 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 – 2011W T2

  7. Unit 2: Conditionals and Logical Equivalences 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 – 2011W T2

  8. Unit 2: Conditionals and Logical Equivalences 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 – 2011W T2

  9. Unit 2: Conditionals and Logical Equivalences If you fail the final exam, will you pass the course? a) Yes b) No c) Maybe If you pass the final exam, will you pass the course? a) Yes b) No c) Maybe CPSC 121 – 2011W T2

  10. Unit 2: Conditionals and Logical Equivalences 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 – 2011W T2

  11. Unit 2: Conditionals and Logical Equivalences 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 – 2011W T2

  12. Unit 2: Conditionals and Logical Equivalences Name Rule Name Rule Identity law p ^ T ≡ p Domination law p ^ F ≡ F p v F ≡ p p v T ≡ T Idempotent law p ^ p ≡ p Commutative law p ^ q ≡ q ^ p p v p ≡ p p v q ≡ q v p Associative law p ^ (q ^ r) ≡ (p ^ q) ^ r Distributive law 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 law p v (p ^ q) ≡ p Negation law p ^ ~p ≡ F p ^ (p v q) ≡ p p v ~p ≡ T Double negative ~(~p) ≡ p DeMorgan's law ~(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 p → q ≡ (~q) → ( ~p) Contrapositive law CPSC 121 – 2011W T2

  13. Unit 2: Conditionals and Logical Equivalences 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 – 2011W T2

  14. Unit 2: Conditionals and Logical Equivalences a b select output 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 – 2011W T2

  15. Unit 2: Conditionals and Logical Equivalences Here is one possible implementation (call select “c”): Let us see why this may not work as we expect... CPSC 121 – 2011W T2

  16. Unit 2: Conditionals and Logical Equivalences Suppose a, b, c are initially T T F F T T T T Assume the gate delay is 10ns CPSC 121 – 2011W T2

  17. Unit 2: Conditionals and Logical Equivalences How long will it take before output reflects any changes in a, b, c and is stable? a) 5ns T b) 10ns F F c) 20ns T T T d) 30ns e) 40ns f) It may never be stable T g) None of the above. CPSC 121 – 2011W T2

  18. Unit 2: Conditionals and Logical Equivalences Now we switch c to F. At time 5ns: T F F T T T F CPSC 121 – 2011W T2

  19. Unit 2: Conditionals and Logical Equivalences At time 10ns: T T F T T F F CPSC 121 – 2011W T2

  20. Unit 2: Conditionals and Logical Equivalences At time 20ns: T T T T F F F Note: the output is now F CPSC 121 – 2011W T2

  21. Unit 2: Conditionals and Logical Equivalences At time 30ns: T T T T T F F Note: the output is now T again. CPSC 121 – 2011W T2

  22. Unit 2: Conditionals and Logical Equivalences 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) e) All of (a), (b) and (c) f) None of (a), (b) and (c) CPSC 121 – 2011W T2

  23. Unit 2: Conditionals and Logical Equivalences Here is a multiplexer that avoid the instability: CPSC 121 – 2011W T2

  24. Unit 2: Conditionals and Logical Equivalences For additional practice:  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 – 2011W T2

  25. Unit 2: Conditionals and Logical Equivalences  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.  Is the sentence logically equivalent to nt ↔ (n1 ^ n2) v s? Why or why not? CPSC 121 – 2011W T2

  26. Unit 2: Conditionals and Logical Equivalences  Prove:  (a ^ ~b) v (~a ^ b) (a v b) ^ ~ (a ^ b) CPSC 121 – 2011W T2

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