snick snack CPSC 121 Models of Computation 2013

  • Slides: 28
Download presentation
snick snack CPSC 121: Models of Computation 2013 W 2 Propositional Logic: A First

snick snack CPSC 121: Models of Computation 2013 W 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by Patrice Belleville and others 1 This work is licensed under a Creative Commons Attribution 3. 0 Unported License.

Introductions, again Steven Wolfman <wolf@cs. ubc. ca> ICICS 239; office hours listed on the

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 2

Outline • • Prereqs, Learning Goals, and Quiz Notes True, False, and Gates. Why

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

Learning Goals: Pre-Class By the start of class, you should be able to: –

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. How should you achieve pre-class goals? Use the quiz to guide your readings! 4

Learning Goals: In-Class By the end of this unit, you should be able to:

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

Where We Are in The Big Stories Theory Hardware How do we model computational

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

Outline • • Prereqs, Learning Goals, and Quiz Notes True, False, and Gates. Why

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

Logic for Reasoning about Truth: Where Should We Start? I will suppose that. .

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 13

Logic as Model for Physical Computations Input b Input a http: //alumni. media. mit.

Logic as Model for Physical Computations Input b Input a http: //alumni. media. mit. edu/~paulo/courses /howmake/mlfabfinalproject. htm a b 5 V a ~a 0 V 14

“OR” operator and gate Physical System b a output We think of “flowing water”

“OR” operator and gate Physical System b a output We think of “flowing water” as true and “no water” as false, and the physical world becomes an effective representation for our ideas! Propositional logic model: a b means “a OR b” Circuit diagram model: the “OR” gate “Truth Table” model a b T T F F F

Outline • • Prereqs, Learning Goals, and Quiz Notes True, False, and Gates. Why

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

Problem: Light Switch Problem: Design a circuit to control a light so that the

Problem: Light Switch Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped. ? The problem gives the story we have to implement. 17 Be sure you understand the story and always keep it in mind!

Problem: Light Switch ? Problem: Design a circuit to control a light so that

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 Which are most useful for these possible inputs and outputs: this problem? Input: the switch flipped or the switch is up Output: the light is shining or the light changed states a. b. c. d. e. flipped and shining flipped and changed up and shining up and changed None of these 18

Problem: Light Switch ? Problem: Design a circuit to control a light so that

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? a. b. c. d. e. Only #1 Only #2 Only #3 #1 and #2 Some other combination 19

Problem: Two-Switch Problem: Design a circuit to control a light so that the light

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. ? 20

Problem: Two-Switch ? Problem: Design a circuit to control a light so that the

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? a. On, in every correct solution. b. Off, in every correct solution. c. It depends, but a correct solution should always do the same thing given the same settings for the switches. d. It depends, and a correct solution might do different things at different times with the same switch settings. 21 e. Neither on nor off.

Problem: Two-Switch ? Problem: Design a circuit to control a light so that the

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? a. b. c. d. e. Only #1 Only #2 #1 and #3 All three 22

Problem: Three-Switch Problem: Design a circuit to control a light so that the light

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. ? 23

Problem: Three-Switch ? Problem: Design a circuit to control a light so that the

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. s 1 s 2 s 3 out out T T F F T T F T F T T F F T T F T F T F F F T T F e. None of these 24

Problem: Three-Switch ? Problem: Design a circuit to control a light so that the

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? a. b. c. d. e. 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. 25 None of these.

Problem: Three-Switch ? Problem: Design a circuit to control a light so that the

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? a. (s 1 s 2 s 3) (s 1 ~s 2 ~s 3) (~s 1 ~s 2 s 3) b. s 1 s 2 s 3 (s 1 s 2 s 3) c. s 1 (s 2 s 3) d. (s 1 ~(s 2 s 3)) (~s 1 (s 2 s 3)) e. None of these is incorrect. 26

Problem: n-Switch Problem: Describe an algorithm for designing a circuit to control a light

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. . ? 27

Outline • • Prereqs, Learning Goals, and Quiz Notes True, False, and Gates. Why

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

Learning Goals: In-Class By the end of this unit, you should be able to:

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

snick snack Some Things to Try. . . (on your own if you have

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

Some Practice Problems Here are some assignment/exam-like practice problems related to this lecture’s in-class

Some Practice Problems Here are some assignment/exam-like practice problems related to this lecture’s in-class learning goals. Give them a shot! 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. 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 perpendicular road. 31

Problem: Logicians and Hats Problem: Three logicians are each wearing a black hat or

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

Problem: Criminals and Hats Problem: A warden plans to line up 100 prisoners in

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? The switch problems might give you a hint. 33