CPSC 121: Models of Computation 2018S Propositional Logic: A First - - PowerPoint PPT Presentation

cpsc 121 models of computation 2018s
SMART_READER_LITE
LIVE PREVIEW

CPSC 121: Models of Computation 2018S Propositional Logic: A First - - PowerPoint PPT Presentation

CPSC 121: Models of Computation 2018S Propositional Logic: A First Model of Computation Meghan Allen, based on notes by Steve Wolfman, Patrice Belleville and others 1 This work is licensed under a Creative Commons Attribution 3.0 Unported


slide-1
SLIDE 1

CPSC 121: Models of Computation 2018S

Propositional Logic: A First Model of Computation Meghan Allen, based on notes by Steve Wolfman, Patrice Belleville and others

1

This work is licensed under a Creative Commons Attribution 3.0 Unported License.

slide-2
SLIDE 2

Reminder

  • join Piazza! The access code is models

2

slide-3
SLIDE 3

Outline

  • Prereqs, Learning Goals, and Quiz Notes
  • True, False, and Gates. Why Start Here?
  • Problems and Discussion

– Side note: numbers from Booleans

  • Expressiveness of Propositional Logic
  • Next Unit Notes

3

slide-4
SLIDE 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

  • f those statements.

4

How should you achieve pre-class goals? Use the quiz to guide your readings!

slide-5
SLIDE 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.,

  • ur 7‐ or 4‐segment LED displays (using a “DNF”
  • r any other successful approach).

5

slide-6
SLIDE 6

Quiz 1 Notes 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 a,b,c represent 3 switches

from left to right”

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

(~x ^ y ^ ~z) v (~x ^ ~y ^ z)”

  • Try a simpler problem: “I decided to just focus on two

parts [switches] of the circuit”

  • Test your answer: “The light switches cannot both be on

at the same, but they can both be off. By working out the truth table, it proofs to be correct.”

6

slide-7
SLIDE 7

Quiz 1 Notes

“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

7

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!

slide-8
SLIDE 8

Quiz 1 Notes

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

  • Epp (the textbook)
  • Friends
  • Wikipedia (especially its page of logic gate symbols)
  • Lecture notes
  • Online videos related to logic and circuits

8

But… follow the quiz collaboration guidelines. Closed-ended part: work alone (but open book). Open-ended part: work with anyone (but acknowledge).

slide-9
SLIDE 9

Where We Are in The 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

  • ur baseline tool

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

9

slide-10
SLIDE 10

Outline

  • Prereqs, Learning Goals, and Quiz Notes
  • True, False, and Gates. Why Start Here?
  • Problems and Discussion

– Side note: numbers from Booleans

  • Expressiveness of Propositional Logic
  • Next Unit notes

10

slide-11
SLIDE 11

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,

  • r blood or senses, but as falsely believing that I have

all these things. ‐ René Descartes

11

slide-12
SLIDE 12

Logic as Model for Physical Computations

12

Input a Input b a  b ~a a 5V 0V

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

slide-13
SLIDE 13

“OR” operator and gate

a b

  • utput

Physical System “Truth Table” model

a b a  b T T T T F T F T T F F F

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

slide-14
SLIDE 14

Outline

  • Prereqs, Learning Goals, and Quiz Notes
  • True, False, and Gates. Why Start Here?
  • Problems and Discussion

– Side note: numbers from Booleans

  • Expressiveness of Propositional Logic
  • Next Unit notes

14

slide-15
SLIDE 15

Problem: Light Switch

Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped.

15

?

The problem gives the story we have to implement. Be sure you understand the story and always keep it in mind!

slide-16
SLIDE 16

Problem: Light Switch

Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped.

16

Identifying inputs/outputs: consider these possible inputs and outputs: Input: the switch flipped or the switch is up Output: the light is shining or the light changed states Which are most useful for this problem?

  • a. flipped and shining
  • b. flipped and changed
  • c. up and shining
  • d. up and changed
  • e. None of these

?

slide-17
SLIDE 17

Problem: Light Switch

Problem: Design a circuit to control a light so that the light changes state any time its switch is flipped.

17

?

Consider these possible solutions: Which of these solves the problem?

  • a. Only #1
  • b. Only #2
  • c. Only #3
  • d. #1 and #2
  • e. Some other combination
slide-18
SLIDE 18

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.

18

?

slide-19
SLIDE 19

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.

19

?

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.

slide-20
SLIDE 20

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

Which of these circuits solves the problem?

  • a. Only #1
  • b. Only #2
  • c. #1 and #2
  • d. #1 and #3
  • e. All three

?

slide-21
SLIDE 21

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.

21

?

slide-22
SLIDE 22

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.

22

?

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.

  • ut

T F F T F T T F

  • ut

F T T F T F F T

  • ut

F T F T F T F T

  • ut

T F T F T F T F

None

  • f

these

slide-23
SLIDE 23

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

?

Getting the Story Right: Which of these is enough alone to always know whether the light is on or off? 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.

slide-24
SLIDE 24

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.

24

?

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.

slide-25
SLIDE 25

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.

25

?

...

slide-26
SLIDE 26

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.

26

slide-27
SLIDE 27

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?

  • a. One
  • b. Seven
  • c. Ten
  • d. Sixteen
  • e. None of these

27

slide-28
SLIDE 28

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?

28

slide-29
SLIDE 29

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?

  • a. One
  • b. Seven
  • c. Ten
  • d. Sixteen
  • e. None of these

29

A bit like a parameter like in CPSC 110, but we only get 1/0 parameters (Booleans).

slide-30
SLIDE 30

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?

  • a. One
  • b. Seven
  • c. Ten
  • d. Sixteen
  • e. None of these

30

slide-31
SLIDE 31

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 F F 1 F F T 2 F T F 3 F T T 4 T F F 5 T F T 6 T T F 7 T T T

Of course, as Epp says, we could agree on a different convention.

31

slide-32
SLIDE 32

Representing Positive Integers

This is the convention we use for the positive integers 0‐9, which requires (at least) 4 variables:

Notice the order: Fs first.

# a b c d F F F F 1 F F F T 2 F F T F 3 F F T T 4 F T F F 5 F T F T 6 F T T F 7 F T T T 8 T F F F 9 T F F T ...

32

slide-33
SLIDE 33

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?

  • a. One
  • b. Seven
  • c. Ten
  • d. Sixteen
  • e. None of these

33

BEFORE we answer it: Is that a good question?

slide-34
SLIDE 34

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.

34

slide-35
SLIDE 35

Exercise: Human Circuit

Which other people’s algorithms does your person need to know about?

  • a. No one else’s
  • b. Only their neighbours’
  • c. Everyone else’s
  • d. Some other group

35

slide-36
SLIDE 36

Analyzing One Segment

What’s the truth table for the lower‐left segment?

# a b c d F F F F 1 F F F T 2 F F T F 3 F F T T 4 F T F F 5 F T F T 6 F T T F 7 F T T T 8 T F F F 9 T F F T

  • ut

F T F T F T F T F T

a. b. c. d.

  • e. None of

these.

  • ut

2 6 8

  • ut

T F T F F F T F T F

  • ut

F T F T T T F T F T

36

slide-37
SLIDE 37

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 F F F T 1 F F F T F 2 F F T F T 3 F F T T F 4 F T F F F 5 F T F T F 6 F T T F T 7 F T T T F 8 T F F F T 9 T F F T F

37

(??)  (??)  (??)  (??) See Epp (4th ed) Example 2.4.5! (3rd ed Example 1.4.5) Let’s try one!

slide-38
SLIDE 38

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 F F F T 1 F F F T F 2 F F T F T 3 F F T T F 4 F T F F F 5 F T F T F 6 F T T F T 7 F T T T F 8 T F F F T 9 T F F T F

38

Which logical statement is true

  • nly in this row?
  • a. ~a  ~b  c  ~d
  • b. a  b  c  d
  • c. ~a  ~b  c  ~d
  • d. a  b  ~c  d
  • e. None of these
slide-39
SLIDE 39

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 F F F T 1 F F F T F 2 F F T F T 3 F F T T F 4 F T F F F 5 F T F T F 6 F T T F T 7 F T T T F 8 T F F F T 9 T F F T F

39

(~a  ~b  ~c  ~d)  (~a  ~b  c  ~d)  (~a  b  c  ~d)  ( a  ~b  ~c  ~d)

slide-40
SLIDE 40

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

  • ut

F F F F T 1 F F F T T 2 F F T F T 3 F F T T T 4 F T F F T 5 F T F T F 6 F T T F F 7 F T T T T 8 T F F F T 9 T F F T T

40

slide-41
SLIDE 41

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

  • ut

F F F F T 1 F F F T T 2 F F T F T 3 F F T T T 4 F T F F T 5 F T F T F 6 F T T F F 7 F T T T T 8 T F F F T 9 T F F T T

Which of these correctly models the LED? a. ~(~a  b  ~c  d)  ~(~a  b  c  ~d) b. ~(a  ~b  c  ~d)  ~(a  ~b  ~c  d) c. ~[(~a  b  ~c  d)  (~a  b  c  ~d)] d. ~[(a  ~b  c  ~d)  (a  ~b  ~c  d)] e. None of these

41

slide-42
SLIDE 42

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:

42

slide-43
SLIDE 43

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

  • utputs.

43

slide-44
SLIDE 44

PRACTICE Exercise for Circuit Design

Finish the problem!

44

slide-45
SLIDE 45

Outline

  • Prereqs, Learning Goals, and Quiz Notes
  • Problems and Discussion

– Side note: numbers from Booleans

  • Expressiveness of Propositional Logic
  • Next Unit Notes

45

slide-46
SLIDE 46

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

  • ut

F F F F F F F F T T F F T F T F F T T F F T F F T

...

46

slide-47
SLIDE 47

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!

47

slide-48
SLIDE 48

Outline

  • Prereqs, Learning Goals, and Quiz Notes
  • Problems and Discussion

– Side note: numbers from Booleans

  • Expressiveness of Propositional Logic
  • Next Unit Notes

48

slide-49
SLIDE 49

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

  • ur 7‐ or 4‐segment LED displays.

49

slide-50
SLIDE 50

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

50

slide-51
SLIDE 51

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 on Tuesday, May 23.

51

slide-52
SLIDE 52

Some Things to Try...

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

60

slide-53
SLIDE 53

Some Practice Problems

Here are some assignment/exam‐like practice problems related to this lecture’s in‐class learning goals. Give them a shot!

61

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.

slide-54
SLIDE 54

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

  • f 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.

62

slide-55
SLIDE 55

Problem: Criminals and Hats

Problem: A warden plans to line up 100 prisoners in

  • rder 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

  • f 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

  • ne hour as a group to plan their strategy.

How many prisoners can be saved?

63

The switch problems might give you a hint.

slide-56
SLIDE 56

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 6 7 8 9

64

slide-57
SLIDE 57

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.

65

slide-58
SLIDE 58

Problem: Updating the “PC”

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

66

slide-59
SLIDE 59

Problem: Updating the “PC”

67

slide-60
SLIDE 60

Concept Q: Fetch Logic

What’s the minimum number of Boolean

  • utputs necessary for this circuit?
  • a. 1
  • b. 2
  • c. 3
  • d. 4
  • e. Cannot be determined from the information

given.

68