145
1 February 1st, 2016 Dave Abel Unit 1: Logic & Gates

Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

1

February 1st, 2016

Dave Abel

Unit 1: Logic & Gates

Page 2: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Takeaway: Logic

2

(1) There is a notion of correct reasoning (Logic)

(2) Computers automate this reasoning process

Page 3: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Outline of Unit

3

‣ Quick Review of Binary

‣ Physical Bits!

‣ Ambiguity of Regular Languages

‣ Logical Inference

‣ Logical Functions: AND, OR, NOT

‣ Truth Tables

Page 4: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

1. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Reading Binary: 27

4

Our Number: Twenty Seven

Page 5: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Reading Binary: 27

5

Our Number: Twenty Seven

1. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 6: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

6

Our Number: Twenty Seven

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 7: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

7

Our Number: Twenty Seven

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 8: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

8

Our Number: Eleven

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 9: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

9

Our Number: Eleven

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 10: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

10

Our Number: Eleven

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 11: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

11

Our Number: Eleven

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 12: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

12

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 13: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

13

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 14: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

14

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 15: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

15

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 16: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

16

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 17: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

17

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 18: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

18

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 19: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

19

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 20: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

20

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 21: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

21

Our Number: Three

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 22: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

22

Our Number: One

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 23: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

23

Our Number: One

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 24: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

24

Our Number: One

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 25: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

25

Our Number: One

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 26: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

26

Our Number: Zero

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 27: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

27

Our Number: Zero

Reading Binary: 271. Start with the biggest power of 2 no bigger than your number.

2. Write down a 1 in that power of two’s column.

3. Subtract that power of 2 from your number.

4. Go to the next smallest power of 2.

5. If your remaining number is greater than or equal to the power of 2, write down a 1 and subtract the power of 2.

6. If not, write down 0.

7. Repeat from [4].

Page 28: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

28

1 0 0 1+ 1 0 1 0

Page 29: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

29

1 0 0 1+ 1 0 1 0

1

Page 30: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

30

1 0 0 1+ 1 0 1 0

1 1

Page 31: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

31

1 0 0 1+ 1 0 1 0

0 1 1

Page 32: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

32

1 0 0 1+ 1 0 1 0

0 0 1 1

1

Page 33: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

33

1 0 0 1+ 1 0 1 01 0 0 1 1

1

Page 34: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Addition

34

1 0 0 1+ 1 0 1 01 0 0 1 1

1

Sanity check: nine + ten = nineteen.

Page 35: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

35

1- 0

1

1- 1

0

0- 0

0

A: B: C:

Page 36: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

36

D:

1 0- 0 1

1

11

Page 37: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

37

1 1 0 1- 0 0 1 0

Page 38: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

38

1 1 0 1- 0 0 1 0

0

Page 39: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

39

1 1 0 1- 0 0 1 0

0

11

Page 40: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

40

1 1 0 1- 0 0 1 0

1 0

11

Page 41: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

41

1 0 0 1- 0 0 1 0

1 0

11

Page 42: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

42

1 0 0 1- 0 0 1 0

1 0

11

Page 43: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

43

1 0 0 1- 0 0 1 0

0 1 0

11

Page 44: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Binary Subtraction

44

1 0 0 1- 0 0 1 0

1 0 1 0

11

Sanity check: nine - two = seven

Page 45: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Idea: move over each bit in bottom number, if there’s a 1, add the entire top number, otherwise, shift over and repeat:

Review: Binary Multiplication

45

1 1 1* 0 1 0

Page 46: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Idea: move over each bit in bottom number, if there’s a 1, add the entire top number, otherwise, shift over and repeat:

Review: Binary Multiplication

46

1 1 1* 0 1 0

0 0 0

(Recall: we’re really just multiplying by 0)

Page 47: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Idea: move over each bit in bottom number, if there’s a 1, add the entire top number, otherwise, shift over and repeat:

Review: Binary Multiplication

47

1 1 1* 0 1 01 1 1

Page 48: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Idea: move over each bit in bottom number, if there’s a 1, add the entire top number, otherwise, shift over and repeat:

Review: Binary Multiplication

48

1 1 1* 0 1 01 1 1

Page 49: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Idea: move over each bit in bottom number, if there’s a 1, add the entire top number, otherwise, shift over and repeat:

Review: Binary Multiplication

49

1 1 1* 0 1 01 1 1 0

Page 50: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Idea: move over each bit in bottom number, if there’s a 1, add the entire top number, otherwise, shift over and repeat:

Review: Binary Multiplication

50

1 1 1* 0 1 01 1 1 0

Sanity Check: seven * two = fourteen

Page 51: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Representation

51

Page 52: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Representation

52

blue bits

green bits

red bits

Page 53: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Image 1Image 1

Review: Representation

53

Image 1

Page 54: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Review: Representation

54

0 1 10 11

a b c d

c = 10, h = 100 …

Page 55: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

55

Q: How can we represent 0’s and 1’s in the real world?

Page 56: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

56

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

Page 57: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

57

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Page 58: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

58

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Q: Try to represent six with your hands!

Page 59: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

59

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Q: Try to represent six with your hands!

A:

Page 60: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

60

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Q: What can we count up to by using binary with hands?

Page 61: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

61

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Q: What can we count up to by using binary with hands?

A: Homework question

Page 62: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

62

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Page 63: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Onward! Physical Bits

63

A: How about people! Raising hand, not raising hand.

Q: How can we represent 0’s and 1’s in the real world?

A: How about fingers! Raising finger, not raising finger.

Thought: but we need something smaller…

Page 64: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Some History

64

Page 65: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Some History

65

Proposed by Ada Lovelace/Charles Babbage in 1837

Page 66: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Some History

66

Proposed by Ada Lovelace/Charles Babbage in 1837

Page 67: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Some History

67

Proposed by Ada Lovelace/Charles Babbage in 1837

Built in 1910

Page 68: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Some History

68

Bits

Page 69: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Bits: Levers

69

OFFON

0

Page 70: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Bits: Levers

70

OFFON

1

Page 71: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Q: What Is This Number?

71

Page 72: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Q: What Is This Number?

72

1 1 0 1

Page 73: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

73

Page 74: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

74

Page 75: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

75

(Called a “Triode”, because three prongs)

Page 76: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

76

When cathode heated, emits electrons attracted to the plate

Page 77: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

77

Grid controls the flow of electrons:

Page 78: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

78

Grid controls the flow of electrons: Negative: electrons bounce back to Cathode

Page 79: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

79

Grid controls the flow of electrons: Negative: electrons bounce back to Cathode

Positive: electrons travel through to Cathode

Page 80: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

80

Page 81: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

81

Q: What if one breaks?

Page 82: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Next Up: Vacuum Tubes!

82

Q: What if one breaks? A: Better check all 19,000 tubes…

Page 83: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Now: The Transistor

83

Page 84: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Now: The Transistor

84

‣ Takes in electric current:

- Amplifies it! (ON, 1)

- Or not… (OFF, 0)

Page 85: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

85

‣ Takes in electric current:

- Amplifies it! (ON, 1)

- Or not… (OFF, 0)

Low voltage pulse of electricity = 0High voltage pulse of electricity = 1

Now: The Transistor

Page 86: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

86

‣ Q: Roughly how many in your phone/computer?

Now: The Transistor

Page 87: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

87

‣ Q: Roughly how many in your phone/computer?

‣ A: On the order of billions…

Now: The Transistor

Page 88: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

88

Moore’s Law (Predicted)N

umbe

r Tra

nsis

tors

0

7500000

15000000

22500000

30000000

Year1972 1978 1984 1990 1996 2002 2008 2014

Page 89: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

We Know How To Do This…

89

Page 90: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Still Need: Reasoning

90

Page 91: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Enter:

91

Page 92: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Enter:

92

Idea: What is valid reasoning?

Page 93: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: Some History

93

Mohism: ~400 B.C.E.

Nyaya: 200 C.E.

Aristotle: ~350 B.C.E.

Page 94: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: Example

94

‣ If the snozzberry is a berry, then it is a fruit.

‣ The snozzberry is a berry.

‣ Conclusion: The snozzberry is a fruit.

Q: Is this reasoning valid?

Page 95: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: Example

95

‣ If the snozzberry is a berry, then it is a fruit.

‣ The snozzberry is a berry.

‣ Conclusion: The snozzberry is a fruit.

Q: Is this reasoning valid?

A: Yes! In this unit, we’ll learn what is and is not valid reasoning.

Page 96: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic

96

Problem: Language is ambiguous, so truth can be finicky!

Page 97: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Language is Ambiguous

97

Problem: Language is ambiguous, so truth can be finicky!

Q: What is art?

Page 98: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Language is Ambiguous

98

Problem: Language is ambiguous, so truth can be finicky!

Q: What is a sport?

Page 99: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Language is Ambiguous

99

‣ Example 1: “I never said she stole my money”

- Changes meaning depending on the emphasis!

‣ Example 2: “Time flies like an arrow”

- Is time a noun? (e.g. “Fruit flies like a banana”)

‣ Example 3: “I have not slept for ten days”

- Has the speaker not slept in the last ten days? Or have they never slept for a period of ten days?

Page 100: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: A Formal Language

100

‣ Variables that stand for sentences: P, Q, R, S

Page 101: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If the snozzberry is a berry, then it is a fruit.

- The snozzberry is a berry.

- Therefore, the snozzberry is a fruit.

Logic: A Formal Language

101

Page 102: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: A Formal Language

102

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If the snozzberry is a berry, then it is a fruit.

- The snozzberry is a berry.

- Therefore, the snozzberry is a fruit.

Page 103: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If the snozzberry is a berry, then it is a fruit.

- The snozzberry is a berry.

- Therefore, the snozzberry is a fruit.

Logic: A Formal Language

103

P Q

Page 104: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If t then it is a fruit.

-

- Therefore, the snozzberry is a fruit.

Logic: A Formal Language

104

P Q

P

Q

= The snozzberry is a berry.

= The snozzberry is a fruit.

P

Q

Page 105: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If t then it is a fruit.

-

- Therefore, the snozzberry is a fruit.

Logic: A Formal Language

105

P Q

P

Q

True for all sentences P,

All sentences Q!

Page 106: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: A Formal Language

106

Premises: assume to be true.

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If t then it is a fruit.

-

- Therefore, the snozzberry is a fruit.

P Q

P

Q

Page 107: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: A Formal Language

107

‣ Variables that stand for sentences: P, Q, R, S

‣ Example:

- If t then it is a fruit.

-

- Therefore, the snozzberry is a fruit.

P Q

P

Q

Premises: assume to be true.

Q: What can we conclude from our

premises?

Page 108: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ We call sentences that can be True or False “Boolean”, after Goerge Boole (1800’s)

Logic: A Formal Language

108

Page 109: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ We call sentences that can be True or False “Boolean”, after Goerge Boole (1800’s)

‣ Henceforth, P, Q, R, S, etc., will be called Boolean Sentences.

Logic: A Formal Language

109

Page 110: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

‣ Variables that stand for sentences: P, Q, R, S

‣ We call sentences that can be True or False “Boolean”, after Goerge Boole (1800’s)

‣ Henceforth, P, Q, R, S, etc., will be called Boolean Sentences.

The question is: in what ways can we reason (about Boolean Sentences)?

Logic: A Formal Language

110

Page 111: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

The question is: in what ways can we reason (about Boolean Sentences)?

Logic: Inference Rules

111

We saw one:

If P, then Q P Therefore Q.

Page 112: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

The question is: in what ways can we reason (about Boolean Sentences)?

Logic: Inference Rules

112

We saw one:

If P, then Q P Therefore Q.

Modus Ponens

Page 113: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

The question is: in what ways can we reason (about Boolean Sentences)?

Logic: Inference Rules

113

Modus Ponens‣ There are others!

‣ Our rules come from thousands of years of intuition about what is perfect reasoning.

Page 114: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

The question is: in what ways can we reason (about Boolean Sentences)?

Logic: Inference Rules

114

Modus Ponens‣ There are others!

‣ We get three functions:

AND(-,-) OR(-,-) NOT(-)

Page 115: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: Boolean Functions

115

‣ We get three functions: AND, OR, NOT

- Each function takes as input a Boolean Sentence (P, Q, etc.)

- Outputs a Boolean value (True, False)

Page 116: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: AND

116

AND(P,Q)

Outputs True if both P and Q are True.

Page 117: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: OR

117

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

Page 118: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: NOT

118

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

NOT(P)

Outputs True if P is False.

Page 119: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Example

119

‣ Suppose P is True, Q is False: which of the following are True?

1. AND(P,Q)

2. OR(P,Q)

3. NOT(P)

4. NOT(Q)

Page 120: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Example

120

‣ Suppose P is True, Q is False: which of the following are True?

1. AND(P,Q)

2. OR(P,Q)

3. NOT(P)

4. NOT(Q)

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

NOT(P)

Outputs True if P is False.

Page 121: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Example

121

‣ Suppose P is True, Q is False: which of the following are True?

1. AND(P,Q)

2. OR(P,Q)

3. NOT(P)

4. NOT(Q)

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

NOT(P)

Outputs True if P is False.

Page 122: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Example

122

‣ Suppose P is True, Q is False: which of the following are True?

1. AND(P,Q)

2. OR(P,Q)

3. NOT(P)

4. NOT(Q)

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

NOT(P)

Outputs True if P is False.

Page 123: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Example

123

‣ Suppose P is True, Q is False: which of the following are True?

1. AND(P,Q)

2. OR(P,Q)

3. NOT(P)

4. NOT(Q)

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

NOT(P)

Outputs True if P is False.

Page 124: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Example

124

‣ Suppose P is True, Q is False: which of the following are True?

1. AND(P,Q)

2. OR(P,Q)

3. NOT(P)

4. NOT(Q)

AND(P,Q)

Outputs True if both P and Q are True.

OR(P,Q)

Outputs True if at least one of P or Q is True.

NOT(P)

Outputs True if P is False.

Page 125: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

125

P NOT( P)

T

F

Truth Tables: NOT

Page 126: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

126

P NOT( P)

T T

F F

Truth Tables: NOT

Page 127: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

127

P NOT( P)

T F T

F T F

Truth Tables: NOT

Page 128: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

128

When P is True, NOT(P) is False

When P is False, NOT(P) is True

P NOT( P)

T F T

F T F

Truth Tables: NOT

Page 129: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

129

P Q AND( P Q)

T T

T F

F T

F F

Truth Tables: AND

Page 130: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Truth Tables: AND

130

P Q AND( P Q)

T T T T

T F T F

F T F T

F F F F

Page 131: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

131

P Q AND( P Q)

T T T T T

T F F T F

F T F F T

F F F F F

Truth Tables: AND

Page 132: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

132

P Q AND( P Q)

T T T T T

T F F T F

F T F F T

F F F F F

When P and Q are True, AND(P,Q) is

True

Otherwise, AND(P,Q) is False

Truth Tables: AND

Page 133: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

133

P Q OR( P Q)

T T T T

T F T F

F T F T

F F F F

Truth Tables: OR

Page 134: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

134

P Q OR( P Q)

T T T T T

T F T T F

F T T F T

F F F F F

Truth Tables: OR

Page 135: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

135

Inference With AND!

AND(P,Q)

Therefore, P

Therefore, Q

P

Q

Therefore, AND(P,Q)

Page 136: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Logic: Composition

136

‣ Boolean Sentences represented with a letter are called Atomic Sentences (e.g. P, Q, R, S, etc.)

‣ But since AND(-,-), OR(-,-), and NOT(-), also output Boolean Values, they are also Boolean Sentences.

‣ For example:

- AND(NOT(P),Q)

- OR(AND(P,Q),NOT(R))

Page 137: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

137

P Q OR( NOT( Q), P)

T T

T F

F T

F F

Truth Tables: Composite

Page 138: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

138

P Q OR( NOT( Q), P)

T T T T

T F F T

F T T F

F F F F

Truth Tables: Composite

Page 139: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

139

P Q OR( NOT( Q), P)

T T F T T

T F T F T

F T F T F

F F T F F

Truth Tables: Composite

Page 140: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

140

P Q OR( NOT( Q), P)

T T F T T

T F T F T

F T F T F

F F T F F

Truth Tables: Composite

Page 141: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

141

P Q OR( NOT( Q), P)

T T T F T T

T F T F T

F T F T F

F F T F F

Truth Tables: Composite

Page 142: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

142

P Q OR( NOT( Q), P)

T T T F T T

T F T T F T

F T F T F

F F T F F

Truth Tables: Composite

Page 143: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

143

P Q OR( NOT( Q), P)

T T T F T T

T F T T F T

F T F F T F

F F T F F

Truth Tables: Composite

Page 144: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

144

P Q OR( NOT( Q), P)

T T T F T T

T F T T F T

F T F F T F

F F T T F F

Truth Tables: Composite

Page 145: Unit 1: Logic & Gates - David Abel › teaching › cs8_2016 › logic1.pdf · Unit 1: Logic & Gates. Takeaway: Logic 2 (1) There is a notion of correct reasoning (Logic) (2) Computers

Reflection

145

‣ Physical Bits!

‣ Ambiguity of Regular Languages

‣ Logical Inference

‣ Logical Functions: AND, OR, NOT

‣ Truth TablesIf P, then Q P Therefore Q.P NOT( P)

T F T

F T F