32
snick snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by Patrice Belleville and others 1

Snick snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

snick

snack

CPSC 121: Models of Computation2010/11 Winter Term 2

Propositional Logic: A First Model of Computation

Steve Wolfman, based on notes by Patrice Belleville and others

1

Page 2: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Introductions, again

Steven Wolfman <[email protected]>

ICICS 239; office hours listed on the websiteI 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 meAdditionally, you can use TA office hoursPlus, you can use Patrice’s office hours

2

Page 3: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Outline

• Prereqs, Learning Goals, and Quiz Notes

• True, False, and Gates. Why Start Here?

• Problems and Discussion

• Next Lecture Notes: Unit Continues...

3

Page 4: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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.

4

Page 5: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Quiz 1 Notes (1)

Which circle needs to be fixed to implement: ~(p v q v ~(r ^ ~s)) ^ ~r

5

AB

C

D

E. None of these; there’s something else wrong with the circuit.

Page 6: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Quiz 1 Notes (2)

Let s = “Bob is registered for CPSC 121” and b = “Bob has taken CPSC 110”.

Why isn’t ~b v ~s equivalent to:“Bob isn’t registered for CPSC 121 nor has he taken CPSC 110”?

(How do we show these aren’t equivalent? Give a “state of the world” that makes them have different truth values.)

Page 7: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Quiz 1 Notes (3)

There’s a pattern here:~a ~b is NOT the same as ~(a b)~a ~b is NOT the same as ~(a b)

Page 8: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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

8

Page 9: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Quiz 1 Notes (4)

Some good approaches:• Try to understand the “story”: “no matter with

switch is flipped, the result will always result in the light turning on” [not quite what we intended]

• Formalize the problem: “Let x be switch 1 open, ~x be switch 1 closed; y is…”

• Solve in propositional logic: “(x ^ y ^ z) v (x ^ ~y ^ ~z) v (~x ^ y ^ ~z) v (~x ^ ~y ^ z)”

• Try a simpler problem: several people tried the two-switch version

9

Page 10: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Quiz 1 Notes (5)“Marked for Completeness”?

Compare these two responses

I'm not sure I understand the question...how does a logic circuit diagram connect to an electrical circuit?

I understand this question but i dont know how to write it in terms of this circuit and logic stuff

10

Somewhere between these is the “marked for completeness line”.

(The left one gets credit; the right does not.)

At minimum: give the question a shot or ask a meaningful question in return!

Page 11: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Quiz 1 Notes (6)

Popular sources of help (especially on the open-ended light-bulb problem):

• Epp• Friends and family members• Wikipedia (especially its page of logic gate symbols)

• Lecture notes• Random websites:

• HTTP://MATHDL.MAA.ORG/IMAGES/UPLOAD_LIBRARY/47/MCCLUNG/INDEX.HTML• HTTP://WWW.KPSEC.FREEUK.COM/GATES.HTM• HTTPS://WWW.SEAS.UPENN.EDU/~CIT595/.../BOOLEANLOGICPROBSOL.PDF

11

Page 12: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Where We Are inThe Big Stories

Theory

How do we model computational systems?

Now: learning the underpinning of all our models (formal logical reasoning with Boolean values).

Hardware

How do we build devices to compute?

Now: establishing our baseline tool

(gates), briefly justifying these as baselines, and designing complex

functions from gates.

12

Page 13: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Outline

• Prereqs, Learning Goals, and Quiz Notes

• True, False, and Gates. Why Start Here?

• Problems and Discussion

• Next Lecture Notes: Unit Continues...

13

Page 14: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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

14

Page 15: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Logic as Model for Physical Computations

Input a Input b

a b

~aa

5V

0V

http://alumni.media.mit.edu/~paulo/courses/howmake/mlfabfinalproject.htm

15

Page 16: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Outline

• Prereqs, Learning Goals, and Quiz Notes

• True, False, and Gates. Why Start Here?

• Problems and Discussion

• Next Lecture Notes: Unit Continues...

16

Page 17: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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.Be sure you understand the story and always keep it in mind!

17

Page 18: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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:

1.Input f: the switch flipped2.Input s: the switch is on3.Output l: the light is on4.Output c: the light changed states

Which are most useful for this problem?

a.f and lb.f and cc.s and ld.s and ce.None of these

18

Page 19: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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

19

Page 20: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Two-Way 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

Page 21: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Two-Way 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.e.Neither on nor off. 21

Page 22: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Two-Way 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.Only #1b.Only #2c.#1 and #2d.#1 and #3e.All three

??

22

Page 23: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Three-Way 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

Page 24: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Three-Way 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:s1 s2 s3

T T T

T T F

T F T

T F F

F T T

F T F

F F T

F F F

a. b. c. d. e.out

T

F

F

T

F

T

T

F

out

F

T

T

F

T

F

F

T

out

F

T

F

T

F

T

F

T

out

T

F

T

F

T

F

T

F

None of

these

24

Page 25: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Three-Way 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.Whether an odd number of switches is on.b.Whether the majority (two or more) of switches are on.c.Whether all the switches are on.d.Whether a switch has been flipped recently.e.None of these. 25

Page 26: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: Three-Way 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.(s1 s2 s3) (s1 ~s2 ~s3) (~s1 s2 ~s3) (~s1 ~s2 s3)

b.s1 s2 s3 (s1 s2 s3)

c.s1 (s2 s3)

d.(s1 ~(s2 s3)) (~s1 (s2 s3))

e.None of these is incorrect.26

Page 27: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Problem: n-Way 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

Page 28: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

Outline

• Prereqs, Learning Goals, and Quiz Notes

• True, False, and Gates. Why Start Here?

• Problems and Discussion

• Next Lecture Notes: Unit Continues...

28

Page 29: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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

Page 30: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

snick

snack

Some Things to Try...

(on your own if you have time and interest, not required)

30

Page 31: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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.

31

Page 32: Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic: A First Model of Computation Steve Wolfman, based on notes by

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 three-way light switch might give you a hint.32