Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 121: Models of Computation 2012 Summer Term 2

Similar presentations


Presentation on theme: "CPSC 121: Models of Computation 2012 Summer Term 2"— Presentation transcript:

1 CPSC 121: Models of Computation 2012 Summer Term 2
Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by Patrice Belleville and others [wolf, 2009W1] The approach seemed to work well this term. Students were less stressed about and more capable with circuits. This also paired well with the deeper focus on understanding and “deconstructing” the computational process inside the working computer. [wolf, 2009 summer] Note: in 2008W2, we focused heavily on circuits, which allowed us to do some cool stuff in labs, homeworks, and exams. However, students felt out of their depth in circuit design, probably with some justification, b/c we didn’t give them the tools they needed to quickly design small/elegant circuits. Unfortunately, we also don’t have the TIME to provide those tools. I suggest, therefore, that we consciously restrict ourselves to problems that can be solved plausibly via either DNF or negation + DNF (i.e., CNF-ish by flipping T/F in the output column), EXPLICITLY teach those approaches, provide other approaches as references (and guide them through them in labs), and be cautious about timing and space allocation so DNF-style solutions can succeed, particularly on exam problems. That lets us cut out a lot of circuit instruction without cutting out key learning goals. [wolf 2008W2] Old thoughts: add a planning compilation problem add a bit of lecture on the idea of prop logic as the foundation for almost every other formal rep system? (probabilistic expert system/Bayesian network, pred logic, etc.)                            This work is licensed under a Creative Commons Attribution 3.0 Unported License.

2 Introductions, again Steven Wolfman <wolf@cs.ubc.ca>
ICICS 239; office hours listed on the website I also have an open door policy: If my door is open, come in and talk! Also, I will usually be available after class. And, you can make appointments with me Additionally, you can use TA office hours [2011W1, wolf] TODO update for single/multiple instructors! Explain what “office hours” are. (Many students seem to be under the delusion that office hours are times when they can make an appointment to see the prof if there’s something REALLY important to discuss. Pah.) Spend a bit of time on this slide introducing yourself, including telling at least one personal thing about yourself (to set up for next two slides).

3 Outline Prereqs, Learning Goals, and Quiz Notes
True, False, and Gates. Why Start Here? Problems and Discussion Next Lecture Notes: Unit Continues...

4 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. Evaluate the truth of propositional logic statements using truth tables. Translate back and forth between propositional logic statements and circuits that assess the truth of those statements. Discuss point of learning goals.

5 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.

6 Where We Are in The Big Stories
Theory Hardware How do we model computational systems? Now: learning the underpinning 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.

7 Outline Prereqs, Learning Goals, and Quiz Notes
True, False, and Gates. Why Start Here? Problems and Discussion Next Lecture Notes: Unit Continues...

8 Logic for Reasoning about Truth: Where Should We Start?
I will suppose that ... some malicious demon of the utmost power and cunning has employed all his energies in order to deceive me. I shall think that the sky, the air, the earth, colours, shapes, sounds and all external things are merely the delusions of dreams which he has devised to ensnare my judgement. I shall consider myself as not having hands or eyes, or flesh, or blood or senses, but as falsely believing that I have all these things. - René Descartes Useful quote from S1: "Some people will try to convince you that numbers are more primitive than other things or that 0 and 1 are the most primitive numbers, and that's not true." ~"WITHOUT interpretation". (Worth connecting to; not wrong at all, but depends very much on context.) [2009W1] You could spend a lot of time on these two slides... Try not to! You’re setting the “lecture” pace for the WHOLE term here. Get to the students’ part fairly quickly! Why start with propositional logic? Because the idea of breaking the world into two diametrically opposed parts is fundamental to almost any reasoning. Steve: personally, I’m not religious. However, existential questions that are addressed in the intersection of religion and philosophy have been a fundamental driver for development in logic in the last few thousand years. So, let’s turn to a classic source to think about where we should start with our reasoning about truth... 2: And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. 3: And God said, Let there be light: and there was light. 4: And God saw the light, that it was good: and God divided the light from the darkness. The universe in the Hebrew Bible/Old Testament begins with duality, two opposing notions, and many other religions’ and philosophies’ universes do as well. Until we divide the universe into two distinct pieces, we cannot really talk about anything meaningful at all. Once we do, all of propositional logic immediately blooms. Prop logic is fundamentally about reasoning about a binary world: one that is split between two “mutually exclusive and exhaustive” concepts, which we choose to call truth and falsehood: T and F. (WE will assign special meaning to these, but all prop logic cares about is that they are opposite and there is nothing else.) 2: And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters. 3: And God said, Let there be light: and there was light. 4: And God saw the light, that it was good: and God divided the light from the darkness. True… followed immediately by false. Now we have enough to define our key concept. It’s absolutely stunning how far that gets us!

9 Logic as Model for Physical Computations
Input a Input b a  b 5V Three of these are AND gates. The fourth, for simplicity, is just a negation gate (the CMOS transistor diagram). The one in the upper-right is from [2009W1] Actually, if we can make it fit, a CMOS AND would be great, since it too would have series switches like the circuit in the lower right. (Would look like: two pMOS xtors in series at the top, two nMOS xtors in parallel at the bottom, IIRC.) a ~a 0V

10 Outline Prereqs, Learning Goals, and Quiz Notes
True, False, and Gates. Why Start Here? Problems and Discussion Next Lecture Notes: Unit Continues...

11 A Motivating Problem I’m going to try to include one assignment/exam-like problem with each in-class learning goal. We’ll distribute these as worked problems. They will not necessarily be our focus in a lecture, however. Design a representation (for a digital logic circuit) for the state of a stop light. Design a circuit that takes the current states of a stop light and produces the next state. (Left as an exercise.) Design a circuit that takes the current states of two stop 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.

12 Problem: Light Switch Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped. ? Talk about how to approach a problem: understanding language, defining inputs and outputs, deciding on technology and models needed, choosing an approach, and changing all of these frequently as needed to solve the problem, testing and verifying correctness, etc. BANG THIS HOME (esp. the choosing several approaches part). The problem gives the story we have to implement. Be sure you understand the story and always keep it in mind!

13 Problem: Light Switch ? Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped. Identifying inputs/outputs: consider these possible inputs and outputs: Input1: the switch flipped Input2: the switch is up Output1: the light is on Output2: the light changed states Which are most useful for this problem? Input1 and Output1 Input1 and Output2 Input2 and Output1 Input2 and Output2 None of these [2012S2] Works well just to say roughly: they’re both right. Sadly, we can only do one of them. What do we need for the other? Comes down to: “events” and “memory”, which are just what we get when we develop flip-flops. [2011W1] Let’s try it this way: Short version: ask students “how long is f true for?” and “how long is s true for?”. [Pretty successful. Note: 2/3 of students liked b!] Long version: which input is “best” depends on what your tools are. Say it’s your job to handle turning the light on whenever the switch is flipped. It’s a boring job; so, you’d rather ignore it most of the time. Solution: have an alarm go off each time the switch flips. That’s a valuable input! What does it correspond to in propositional logic, however? Prop logic is our model of how combinational circuits work (and it’s a fairly good model, too). If this is outside the capabilities of prop logic, we should perhaps set it aside, at least for now. Answer: it doesn’t correspond to ANYTHING in prop logic. A prop logic expression is like an arithmetic expression: it calculates a value. It doesn’t include a notion of things changing over time, of “events” that occur suddenly, of “remembering” what has gone before. If we want to add that, we’ll need to change our model. Meanwhile, prop logic NEVER gets bored (note: bored, not boring). So, it can just “watch” all the time to see what the switch’s state is and respond (constantly) to that. [2010W2] This made a good point but without crisp clarity. It takes a LOOONG time for student to understand why “c” and “f” are not what we want. Not sure how to say it better  The answer is c. NOTE: we WILL see this problem again when we have memory and events.

14 Problem: Light Switch ? Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped. Consider these possible solutions: Which of these solves the problem? Only #1 Only #2 Only #3 #1 and #2 Some other combination SEE NOTE AT BOTTOM. The bottom one can be mistaken for an OR gate with a big box-like “thing” sticking out of it (so the negative space between the wire and the OR becomes positive space). Might explain to students that that’s one wire that at the dot splits into two wires and leads into both inputs of the OR gate. The “answer” is e.  Again, discussion is fruitful on this. Students CAN get the wrong idea, however (that they’re “always” free to flip T and F in a circuit). NOTE: I STRONGLY recommend drawing truth tables as you go (might be worth more slides) where you put the inputs on the left, leave the right blank, decide what happens when all switches are on (or off) and then show how flipping switches consecutively takes us to different rows and how those rows are constrained to be filled in. (So, draw an arrow from FFF row to FTF row for “turning on the middle switch” and say “according to the story, since the light was off in the FFF row, it must be on (T) in the FTF row”.)

15 Problem: Two-Switch Problem: Design a circuit to control a light so that the light changes state any time either of the two switches that control it is flipped. ?

16 ? Problem: Two-Switch Problem: Design a circuit to control a light so that the light changes state any time either of the two switches that control it is flipped. Getting the Story Right: Is the light on or off when both switches are up? On, in every correct solution. Off, in every correct solution. It depends, but a correct solution should always do the same thing given the same settings for the switches. It depends, and a correct solution might do different things at different times with the same switch settings. Neither on nor off. Good design question. The answer is c. Students do not always interpret c and d as I do. Perhaps some rephrasing? Not sure how. [2010W2] Attempting a rephrase, adding the “given the same settings” phrases.

17 ? Problem: Two-Switch Problem: Design a circuit to control a light so that the light changes state any time either of the two switches that control it is flipped. Which of these circuits solves the problem? Only #1 Only #2 #1 and #2 #1 and #3 All three 1 and 3 are logically equivalent and correct. 2 is NOT correct. (Show students why by trying out some switch configurations.)

18 Problem: Three-Switch
Problem: Design a circuit to control a light so that the light changes state any time any of the three switches that control it is flipped. ?

19 Problem: Three-Switch
? Problem: Three-Switch Problem: Design a circuit to control a light so that the light changes state any time any of the three switches that control it is flipped. Fill in the circuit’s truth table: a. b. c. d. e. s1 s2 s3 T F out T F out F T out F T out T F None of these A and b are both perfectly fine.

20 Problem: Three-Switch
? Problem: Three-Switch Problem: Design a circuit to control a light so that the light changes state any time any of the three switches that control it is flipped. Getting the Story Right: Which of these indicates whether the light is on or off in a particular correct solution? Whether an odd number of switches is on. Whether the majority (two or more) of switches are on. Whether all the switches are on. Whether a switch has been flipped recently. None of these. Only a (of a-d) is always enough information to tell us whether the light is on or not.

21 Problem: Three-Switch
? Problem: Three-Switch Problem: Design a circuit to control a light so that the light changes state any time any of the three switches that control it is flipped. Modelling the Circuit: Which of these describes an incorrect solution? (s1  s2  s3)  (s1  ~s2  ~s3)  (~s1  s2  ~s3)  (~s1  ~s2  s3) s1  s2  s3  (s1  s2  s3) s1  (s2  s3) (s1  ~(s2  s3))  (~s1  (s2  s3)) None of these is incorrect. B is incorrect. (The others are logically equivalent to each other.)

22 Problem: n-Switch Problem: Describe an algorithm for designing a circuit to control a light so that the light changes state any time any of its n switches is flipped. XOR a bunch of switches together, basically. The result will be true any time an odd number of the switches is up. Later, we can even PROVE that this even/odd based scheme will work. (WLOG, consider a collection of n switches. Put them in some configuration with some output for the light (doesn’t matter whether on or off). Let p be the parity of the lights (p is true of there’s on odd number up, false otherwise). If we flip one switch, it MUST change the parity (because it either reduces or increases the number of switches on by 1, and an even number +/- 1 is odd and vice versa).) We can also prove (later) than XORing a bunch of inputs together results in T when an odd number of the inputs are T (by induction). ... ?

23 Outline Prereqs, Learning Goals, and Quiz Notes
True, False, and Gates. Why Start Here? Problems and Discussion Next Lecture Notes: Unit Continues...

24 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. OLD text: Bonus goal that foreshadows “induction”: Give two examples of recursive definitions. Discuss point of learning goals.

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

26 Problem: Logicians and Hats
Problem: Three logicians are each wearing a black hat or a white hat, but not all white. Nobody can see their own hat. However, A can see the hats of B and C, and B can see the hats of A and C. C is blind. You go and ask them one by one in the order A, B, C, whether they know the color of their own hat. A answers “No”. B answers “No”. Then C answers “Yes”. Explain how this is possible. Straightforward if you work it out step by step.

27 Problem: Criminals and Hats
Problem: A warden plans to line up 100 prisoners in order tomorrow. The warden will place a white or black hat on each prisoner’s head so that no prisoner can see the hat on his or her own head, but they can see the hats of the prisoners in front of them. From the back of the line, the warden will ask each prisoner “Is your hat black?” If the prisoner answers correctly, he or she is set free. Incorrect answers lead to immediate and noisy beheading. If they answer anything other than “yes” or “no”, all prisoners are beheaded. They get one hour as a group to plan their strategy. How many prisoners can be saved? Think about a parity strategy. (I.e., SPOILER: have the statement “yes” mean either “an even number of hats ahead of me are white” or “an odd number of hats ahead of me are white”.) The switch problems might give you a hint.


Download ppt "CPSC 121: Models of Computation 2012 Summer Term 2"

Similar presentations


Ads by Google