models of computation
play

Models of Computation Boolean logic Logic circuits January 08, - PowerPoint PPT Presentation

CPSC 121 Models of Computation Boolean logic Logic circuits January 08, 2020 Patrice Belleville / Geoffrey Tien 1 Announcements Pre-lecture quiz #2 due Tuesday Jan.14, 19:00 Read Epp 4e/5e: Chapter 2.2 HW1 out soon, due Tuesday,


  1. CPSC 121 Models of Computation Boolean logic Logic circuits January 08, 2020 Patrice Belleville / Geoffrey Tien 1

  2. Announcements • Pre-lecture quiz #2 due Tuesday Jan.14, 19:00 – Read Epp 4e/5e: Chapter 2.2 • HW1 out soon, due Tuesday, Jan.21, 19:00 • Pre-lecture quiz #3 due Sunday, Jan.19, 19:00 – Read Epp 4e/5e: Chapter 2.5 – http://www.students.cs.ubc.ca/~cs-121/current/handouts /signed-binary- decimal-conversions.html – http://en.wikipedia.org/wiki/Binary_number January 08, 2020 Patrice Belleville / Geoffrey Tien 2

  3. Logical operators • AND ∧ (between two variables or expressions) • OR ∨ (between two variables or expressions) • NOT ∼ (in front of a variable or expression) • Examples: – 𝑍 = 𝐵 ∧ 𝐶 is read as " 𝑍 equals 𝐵 AND 𝐶 " – 𝑔 = 𝑦 ∨ 𝑧 is read as " 𝑔 equals 𝑦 OR 𝑧 " – 𝑎 = ~𝐵 is read as " 𝑎 equals NOT 𝐵 " January 08, 2020 Patrice Belleville / Geoffrey Tien 3

  4. Truth tables • Shows the relationship between the values of the input variables, and the value of the result of the operation – compute the result, based on all possible combinations of the inputs • Example, inputs 𝑌 , 𝑍 , result 𝑎 : – let 𝑌 be "I'm nervous" – let 𝑍 be "My socks are too loose" – let 𝑎 be "Having a bad day at school", 𝑎 = 𝑌 ∧ 𝑍 𝑎 = 𝑌 ∧ 𝑍 𝐷 = 𝐵 ∨ 𝐶 𝐻 = ~𝐺 AND OR NOT 𝑌 𝑍 𝑎 𝐵 𝐶 𝐷 𝐺 𝐻 F F F F F F F T F T F F T T T F T F F T F T T T T T T T January 08, 2020 Patrice Belleville / Geoffrey Tien 4

  5. Larger truth tables • As we introduce more variables, truth tables become larger to accommodate all combinations of input values – arrange the input combinations in a consistent, predictable order • Quick way: – entries in rightmost input column alternate as "F T F T F T F T..." – entries in second column from right alternate as "F F T T F F T T ..." – entries in third column from right repeat as "F F F F T T T T ..." – fourth from right? – ... – What's the pattern for a system with 𝑙 variables? January 08, 2020 Patrice Belleville / Geoffrey Tien 5

  6. Determining truth values for compound statements via intermediate values • Should I go to class? Let: 𝑏 𝑐 𝑑 𝑒 𝑕 ? ? ? ? – 𝑏 = need it to graduate F F F F F F F T – 𝑐 = class is boring F F T F – 𝑑 = I'm stuck in traffic F F T T – 𝑒 = I slept in F T F F F T F T F T T F • 𝑕 = 𝑏 ∨ ~𝑐 ∧ ~(𝑑 ∨ 𝑒) F T T T T F F F T F F T T F T F T F T T T T F F T T F T T T T F T T T T January 08, 2020 Patrice Belleville / Geoffrey Tien 6

  7. Digital logic circuits January 08, 2020 Patrice Belleville / Geoffrey Tien 7

  8. Data representation • Information in the real world can take many values, e.g. – Temperature, weight, pressure (continuous, numeric) – Price, quantity (discrete, numeric) – Names, descriptions (discrete, alphabetic) • Data representation in digital systems uses voltage – Voltage is also continuous – Control the voltage to two discrete levels high low • Two discrete voltage levels allow a binary alphabet – {high, low}, {true, false}, {1, 0} January 08, 2020 Patrice Belleville / Geoffrey Tien 8

  9. Logic gates • Logic gates are electronic circuits that operate on one or more input signals to produce an output signal(s). – signal: a connection that can transmit one bit of information at a time • Electric signals exist throughout a digital system as high or low voltages (we will call 1 or 0). • Gates are electronic circuits which produce the high and low voltage equivalents of logic-1 (T) and logic-0 (F) output signals according to their specified truth tables AND NOT, aka inverter OR January 08, 2020 Patrice Belleville / Geoffrey Tien 9

  10. From circuits to propositions ...and back AND NOT, aka inverter OR • These gates correspond to the Boolean operations introduced last class – Can build circuits to evaluate logical propositions – e.g. "should I go to class?" 𝑕 = 𝑏 ∨ ~𝑐 ∧ ~(𝑑 ∨ 𝑒) • Another useful (non-Boolean) function: XOR (exclusive-OR) 𝑎 = 𝑌 ⊕ 𝑍 XOR 𝑌 𝑍 𝑎 F F F F T T T F T T T F January 08, 2020 Patrice Belleville / Geoffrey Tien 10

  11. From circuits to propositions • Propositions can be used to model circuits – Each variable corresponds to an input – The value of the proposition (for a given combination of input values) is the output of the circuit • Example: the segments in a 7-segment display – Each integer from 0 to 9 is represented by a specific combination of input values – We can write a proposition for each segment, which combinations of input values will activate the segment January 08, 2020 Patrice Belleville / Geoffrey Tien 11

  12. From circuits to propositions Exercise • Consider the following circuit: The "bubble" means the value is inverted before entering the AND gate • Write a proposition corresponding to this circuit • What does this circuit compute? – Complete a truth table for the proposition you obtained above – Study the truth table for patterns or characteristics, to express the circuit behaviour January 08, 2020 Patrice Belleville / Geoffrey Tien 12

  13. From circuits to propositions Exercise • What is the simplest logical expression that corresponds to the following circuit? Note the inversions on the outputs of the OR and AND gates These are called NOR and NAND gates and are logically equivalent to inverting the OR/AND functions. Also note the 3-input AND function. January 08, 2020 Patrice Belleville / Geoffrey Tien 13

  14. A (sort of) real problem Light switches • Consider the problem of designing a light that changes state whenever any of the switches that control it is flipped. Ideally your solution would work with any number of switches! ? January 08, 2020 Patrice Belleville / Geoffrey Tien 14

  15. Light switches • How do we approach this? – We first need to make sure we understand what we are designing – Then we use propositional logic to model the circuit's desired output • It's helpful to start with very simple versions of the problem – First try 1 switch – Then try 2 switches – Then try 3 switches – Then see if we can generalize to 𝑜 switches January 08, 2020 Patrice Belleville / Geoffrey Tien 15

  16. Light switches Output • Making sure we understand what we are designing • Which of these would be usable (most useful) as the output of our circuit? a) the switch is flipped b) the switch is on c) the light is on d) the light changed state January 08, 2020 Patrice Belleville / Geoffrey Tien 16

  17. Light switches Input • Making sure we understand what we are designing • Which of these would be usable (most useful) as the input of our circuit? a) the switch is flipped b) the switch is on c) the light is on d) the light changed state January 08, 2020 Patrice Belleville / Geoffrey Tien 17

  18. Light switches Requirements • Make sure we understand the problem • For one switch, is the light on or off when the switch is "on"? a) Always on b) Always off c) Depends, but a correct solution should always do the same thing d) Depends, and a correct solution might do different things at different times January 08, 2020 Patrice Belleville / Geoffrey Tien 18

  19. Light switches One switch • Which circuit(s) is/are correct solution(s)? a) b) c) d) two of (a), (b), (c) e) all three of (a), (b), (c) January 08, 2020 Patrice Belleville / Geoffrey Tien 19

  20. Readings for this lesson • Pre-class quiz #2 due Tuesday Jan.14, 19:00 – Read Epp 4e/5e: Chapter 2.2 • Homework #1 will be available soon! – due Tuesday, Jan.21, 19:00 January 08, 2020 Patrice Belleville / Geoffrey Tien 20

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