Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 121: Models of Computation 2016W2

Similar presentations


Presentation on theme: "CPSC 121: Models of Computation 2016W2"— Presentation transcript:

1 CPSC 121: Models of Computation 2016W2
Propositional Logic, Continued Steve Wolfman, based on notes by Patrice Belleville and others TODO (future terms): correct term                            This work is licensed under a Creative Commons Attribution 3.0 Unported License.

2 Outline Learning Goals Problems and Discussion
Side note: numbers from Booleans Expressiveness of Propositional Logic Next Lecture Notes No new online quiz this time.

3 Learning Goals: In-Class
By the end of this unit, you should be able to: Build combinational computational systems using propositional logic expressions and equivalent digital logic circuits that solve real problems, e.g., our 7- or 4-segment LED displays (using a “DNF” or any other successful approach). Discuss point of learning goals.

4 Where We Are in The Big Stories
Theory Hardware How do we model computational systems? Now: learning the underpinnings of all our models (formal logical reasoning with Boolean values). How do we build devices to compute? Now: establishing our baseline tool (gates), briefly justifying these as baselines, and designing complex functions from gates.

5 Outline Learning Goals Problems and Discussion
Side note: numbers from Booleans Expressiveness of Propositional Logic Next Lecture Notes

6 Problem: 7-Segment LED Display
Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated above. SOME OLD NOTES: Pose a classic computational problem: Control a 7-segment LED display so that, given a number 0-9, the display shows the symbol representing that number. (Include figure showing the LEDs.) Make clear that we’re NOT going to attack that problem now (so we can do a more novel one instead!). Codify the problem. What is the input? How do we control the LEDs? What are the symbols? Pose a new problem: Control a 4-LED display so that, given a number 0-9, the display shows a symbol representing that number. Codify the problem: Input, same as before. Arrangement? Up to us. Symbols? Also up to us. For now, let’s agree on a square as the arrangement and the symbols: [[list the tic-tac-toe symbols]]. Give class ~10 seconds to look at symbols and then do PARTICIPATION CREDIT clicker quiz. Show key (tic-tac-toe board) and then repeat quiz with new values. Discuss power of representations briefly? Now, work through the problem. As a class, solve ONE column. Have students pick another column and work on it. Write up two DIFFERENT solutions on the board. Ask if they’re equivalent. Logical equivalence proof! Happily, they may NOT be equivalent (because are “don’t cares”... Best to have two non-equivalent formulae on hand in case students don’t come up with them!). Discuss and deal with non-equivalent case. (Gloss both of these first time through, hit them hard the next time?) Show sample of circuit that solves the problem. Lab Homework: students must create their own DISTINCT representation with four LEDs arrayed as they like. All off may ONLY mean zero (but they can choose to use something else for 0 and not use all off if they like). Each of 0-9 must have a distinct symbol. They must build a circuit to drive their LEDs.

7 Problem: 7-Segment LED Display
Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated above. Understanding the story: How many inputs to our circuit are there? One Seven Ten Sixteen None of these Do NOT have them answer in pairs after individual, instead go straight to: “there’s at least two good interpretations here!” [2010W2] MANY pick seven, some each other except zero. Dropping zero. This is VERY tricky for students. What is an “input”? (I use it in TWO ways myself. In one sense to mean an “input wire” and in another to mean an “input value”. Zero and seven are definitely misconceptions, however.

8 Problem: 7-Segment LED Display
Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated above. First: what’s the circuit’s job? Story! The circuit’s job isn’t just to connect a switch to each light. That would just mean seven plain wires. The circuit’s job is to INTERPRET a numerical input and turn it into an output.

9 Problem: 7-Segment LED Display “Input Lines”
Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated above. How many different input wires does the circuit have? One Seven Ten Sixteen None of these [2011W1] CPSC 110 HAD talked about parameters by this time. This is VERY tricky for students. What is an “input”? (I use it in TWO ways myself. In one sense to mean an “input wire” and in another to mean an “input value”. Zero and seven are definitely misconceptions, however. A bit like a parameter like in CPSC 110, but we only get 1/0 parameters (Booleans).

10 Problem: 7-Segment LED Display “Input Symbols”
Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated above. How many different messages (values) must the circuit understand? One Seven Ten Sixteen None of these This is VERY tricky for students. What is an “input”? (I use it in TWO ways myself. In one sense to mean an “input wire” and in another to mean an “input value”. Zero and seven are definitely misconceptions, however.

11 Side Note: Truth Tables and Numbers
If we agree on a convention for the rows of a truth table, we can assign a number to each row… # a b c F 1 T 2 3 4 5 6 7 Of course, as Epp says, we could agree on a different convention.

12 Representing Positive Integers
This is the convention we use for the positive integers 0-9, which requires (at least) 4 variables: # a b c d F 1 T 2 3 4 5 6 7 8 9 ... Notice the order: Fs first.

13 Problem: 7-Segment LED Display
Problem: Design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated above. Understanding the story: How many outputs from our circuit are there? One Seven Ten Sixteen None of these Again, this is an ambiguous question. Wait for the students to clarify. One is conceptually correct in the sense that we have one “four-bit wide output channel”. Seven is the number of output wires. Ten (or possibly 128) is the number of output values. Zero is a misconception. BEFORE we answer it: Is that a good question?

14 Exercise: Human Circuit
Let’s simulate the display with people. If you’re not at the front, pick one person and think about what their algorithm is. Have seven volunteers simulate the LEDs. Need big blue sheets of paper! [2009W1] Actually, just having them throw their hands up or not works in a raked classroom. Put tall people nearest the board and have them crouch down as they approach the front.

15 Exercise: Human Circuit
Which other people’s algorithms does your person need to know about? No one else’s Only their neighbours’ Everyone else’s Some other group This was a VERY successful clicker Q and cleared up a perennial confusion for students. (EXTREMELY limited problems with multiple outputs compared to previous terms!) The answer is a.

16 Analyzing One Segment What’s the truth table for the lower-left segment? a. b. c. d. e. None of these. # a b c d F 1 T 2 3 4 5 6 7 8 9 out F T out 2 6 8 out T F out F T This is a good point to note that the negation of an output is NOT always a viable solution. The answer is c. D is its negation and is INCORRECT.

17 Analyzing One Segment From the truth table, we can make an expression for each true row and OR them together. # a b c d out F T 1 2 3 4 5 6 7 8 9 (??)  (??) Let’s try one! EMPHASIZE that they MUST MUST MUST MUST MUST read through and understand 1.4.5! See Epp (4th ed) Example 2.4.5! (3rd ed Example 1.4.5)

18 Analyzing One Segment From the truth table, we can make an expression for each true row and OR them together. # a b c d out F T 1 2 3 4 5 6 7 8 9 Which logical statement is true only in this row? ~a  ~b  c  ~d a  b  c  d ~a  ~b  c  ~d a  b  ~c  d None of these 2011W1: BE SURE to call out the bogus statement d. (We won’t use operator precedence to disambiguate that; so, it’s meaningless. USE PARENTHESES!)

19 Analyzing One Segment From the truth table, we can make an expression for each true row and OR them together. # a b c d out F T 1 2 3 4 5 6 7 8 9 (~a  ~b  ~c  ~d)  (~a  ~b  c  ~d)  (~a  b  c  ~d)  ( a  ~b  ~c  ~d) EMPHASIZE that they MUST MUST MUST MUST MUST read through and understand 2.4.5!

20 Designing the Expression with Many Ts
Let’s try another LED: the upper-right. With eight Ts, we’d need eight expressions! Too bad we can’t model Fs rather than Ts! # a b c d out F T 1 2 3 4 5 6 7 8 9

21 Designing the Expression with Many Ts
We can by negating statement we construct! (Instead of building out, we build ~out and then negate it.) # a b c d out F T 1 2 3 4 5 6 7 8 9 Which of these correctly models the LED? ~(~a  b  ~c  d)  ~(~a  b  c  ~d) ~(a  ~b  c  ~d)  ~(a  ~b  ~c  d) ~[(~a  b  ~c  d)  (~a  b  c  ~d)] ~[(a  ~b  c  ~d)  (a  ~b  ~c  d)] None of these A bit hard to read  The answer is c. Based on De Morgan’s, some of the others come CLOSE to being right.

22 Problem: 7-Segment LED Display
Problem: Design the seven LED display circuit. Approach: Solve each of the seven outputs separately and put the whole thing together. Here’s the two LEDs we’ve solved, simplified: [2011W1] Patched a to ~a in bottom circuit, thanks to Katie, one of the students.

23 PRACTICE Exercise for NEXT UNIT (logical equiv)
Prove that our solution for the upper-right LED is logically equivalent to the corresponding circuit on the previous slide. Prove that our solution for the lower-left LED is not logically equivalent to the corresponding circuit on the previous slide, and explain why not. Note: to disprove a logical equivalence, you must give truth values for the inputs that yield different outputs.

24 PRACTICE Exercise for Circuit Design
Finish the problem!

25 Concept Q: 7-Segment LED
Imagine we were solving for an LED in a display for “Brahmi” numerals. Which of these is most likely to make our problem easier? More entries in that LED’s column of the truth table that are true (turn some Fs into Ts). Fewer entries in that LED’s column of the truth table that are true (turn some Ts into Fs). More legal input symbols (e.g., 0-15 instead of 0-9). Fewer legal input symbols (e.g., 0-4 instead of 0-9). None of these will make the problem easier. The really important lesson here is that “a” and “b” are “it depends” responses. (May make things easier or harder.) Only d clearly makes things easier.. or at least not harder (because in either solution we can make the “missing” values work the way we WANT the circuit to work).

26 Outline Prereqs, Learning Goals, and Quiz Notes
Problems and Discussion Side note: numbers from Booleans Expressiveness of Propositional Logic Next Lecture Notes

27 Expressiveness of Propositional Logic
Problem: Is propositional logic (and combinational circuits) universal for Boolean functions—able to implement a truth table with any number of columns and list of T and F in the output? ? a b c d out F T ...

28 Expressiveness of Propositional Logic
Problem: Is propositional logic universal for Boolean functions? Yes! We’ve already given an algorithm to turn any truth table into a corresponding propositional logic statement. Universality is a pretty cool result for our very first model! NORMALLY ON THE HOMEWORK!

29 Outline Prereqs, Learning Goals, and Quiz Notes
Problems and Discussion Side note: numbers from Booleans Expressiveness of Propositional Logic Next Lecture Notes

30 Learning Goals: In-Class
By the end of this unit, you should be able to: Build combinational computational systems using propositional logic expressions and equivalent digital logic circuits that solve real problems, e.g., our 7- or 4-segment LED displays. Discuss point of learning goals.

31 Next Lecture Learning Goals: Pre-Class
By the start of 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. Example: given (u  s)  s, apply p  q  ~p  q. Note: p maps to (u  s) and q maps to s. Result: ~(u  s)  s Discuss point of learning goals.

32 Next Lecture Prerequisites
Reread Sections 1.1 and 1.4 (3rd ed) or 2.1 and 2.4 (4th ed). Read Section 1.2 (3rd ed) or 2.2 (4th ed). Complete the open-book, untimed quiz on Vista that’s due before the next class.

33 Motivating Problem Design a representation (for a digital logic circuit) for the state of a traffic light. Design a circuit that takes the current states of a traffic light and produces the next state. Design a circuit that takes the current states of two traffic lights and produces true if they are “safe in combination” and false otherwise. (By “in combination” we mean that one of the states is the state of the lights along one road at an intersection and the other is the state of the lights along the other road. Try to solve it. Follow along with us if you need help!

34 Reminder: Motivating Problem
Design a representation for the traffic light state. What are the states? Red, yellow, green. How can we represent this in a circuit? We could number them, and we know how to represent numbers. We’ll use (arbitrarily) red = 0, yellow = 1, green = 2. These will be 2-bit values, then, and 3 will be invalid/unused.

35 Reminder: Motivating Problem
Design a circuit that takes the states of two traffic lights and produces true iff they are “safe in combination”. How many input lines does this have? Two traffic light states, which we decided were 2-bit numbers. So, 2*2 = 4 input lines. How many output lines does it have? We only need to say “true = safe/false = unsafe”; so, one.

36 Reminder: Motivating Problem
Design a circuit that takes the states of two traffic lights and produces true iff they are “safe in combination”. What does “safe” really mean here? It’s unsafe if cars can go in both directions. So, at least one direction needs to be red.

37 Reminder: Motivating Problem
Designing a “safe” circuit. R = 00, Y = 01, G = 10. Draw a truth table. We only need R/Y/G, not the invalid values; so, we’ll do a 9-row truth table instead of the full 16-row table (although 16 rows would not be wrong). a and b are our signals. We’ll use colour to track their meaning in the table, but you could also add extra columns with R, Y, G symbols in them! a1 a2 b1 b2 Safe F T

38 Reminder: Motivating Problem
Designing a “safe” circuit. From here out we can ignore the domain and solve the logic problem. We just need to model the T rows (or the F ones if we prefer). That’s: (~a1~a2~b1~b2)  (~a1~a2~b1b2)  (~a1~a2b1~b2)  (~a1a2~b1~b2)  (a1~a2~b1~b2) You can then translate this directly to a circuit. a1 a2 b1 b2 Safe F T

39 Reminder: Motivating Problem
Here’s a different way to go. Design a circuit that takes the states of two traffic lights and produce true iff they are “safe in combination”. What does “safe” really mean here? It’s unsafe if cars can go in both directions. So, at least one direction needs to be red.

40 Reminder: Motivating Problem
What does “safe” really mean here? It’s unsafe if cars can go in both directions. So, at least one direction needs to be red. So, we need a circuit that says “a is red  b is red”. We can then write a circuit that tests whether a light is red as a (pretty easy!) sub-problem, copy that twice (once with a as the input and once with b) and then feed the outputs into an OR gate! Try solving the problem this way!

41 (on your own if you have time, not required)
Some Things to Try... (on your own if you have time, not required)

42 Problem: 4-Segment LED Display
Problem: build a circuit that displays the numbers 1 through 9 represented by four Boolean values p, q, r, and s on a 4-segment Boolean display. 1 2 3 4 5 REPRESENTATION MATTERS! Models matter. They can make all the difference in a problem. Here, try to remember the mapping as it stands. Then, look below... 1|2|3 -+-+- 4|5|6 7|8|9 Concept question: How many gates did you use to build control for the top LED? 1 2 3-4 5-8 9 or more 6 7 8 9

43 Problem: One-Bit Addition
Problem: build a circuit that takes three one-bit numbers as input and outputs their sum as a two-bit number. Foreshadowing the lab. Does building the circuit for the first (higher-order) bit of the output depend on the circuit for the second (lower-order) bit of the output? (There may be multiple correct answers. Choose what you think is the best.) Yes, because the output is a single unit (one number). Yes, because when the result is too big to fit into the second bit, that affects the first bit. It depends, because some solutions might use the second bit’s value in computing the first bit. No, because the value of the first bit is completely determined by the values of the input bits. None of these.

44 Problem: Updating the “PC”
Problem: Create logic that calculates the amount to increase the PC by, given the values NeedValC and NeedRegIDs.

45 Problem: Updating the “PC”
Old example stolen from CPSC This is the fetch logic for a full computer implementation.

46 Concept Q: Fetch Logic What’s the minimum number of Boolean outputs necessary for this circuit? 1 2 3 4 Cannot be determined from the information given.


Download ppt "CPSC 121: Models of Computation 2016W2"

Similar presentations


Ads by Google