Announcements Quiz 10: on Canvas. Due 6/18, noon. CPSC 121: Models - - PowerPoint PPT Presentation

announcements
SMART_READER_LITE
LIVE PREVIEW

Announcements Quiz 10: on Canvas. Due 6/18, noon. CPSC 121: Models - - PowerPoint PPT Presentation

Announcements Quiz 10: on Canvas. Due 6/18, noon. CPSC 121: Models of Computation HW5: available 6/14, due 6/21. 2018 Summer Term 1 Exam2 recap Intro to Induction Final exam: 6/25, 8:30a Tutorials will meet 6/21 all are welcome. Cinda


slide-1
SLIDE 1

CPSC 121: Models of Computation 2018 Summer Term 1

Intro to Induction Cinda Heeren, based on notes by Steve Wolfman, Patrice Belleville and others

1

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

Announcements

Quiz 10: on Canvas. Due 6/18, noon. HW5: available 6/14, due 6/21. Exam2 recap Final exam: 6/25, 8:30a

Tutorials will meet 6/21 – all are welcome. Lots of exam prep support—see piazza.

2

H

Outline

  • Prereqs and Learning Goals
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

3

Learning Goals: Pre-Class

By the start of class, you should be able to:

– Given a theorem to prove and the insight into how to break the problem down in terms of smaller problems, write out the skeleton of an inductive proof including: the base case(s) that need to be proven, the induction hypothesis, and the inductive step that needs to be proven.

4

slide-2
SLIDE 2

Learning Goals: In-Class

By the end of this unit, you should be able to:

– Formally prove properties of the non-negative integers (or a subset like integers larger than 3) that have appropriate self-referential structure— including both equalities and inequalities—using either weak or strong induction as needed. – Critique formal inductive proofs to determine whether they are valid and where the error(s) lie if they are invalid.

5

Outline

  • Prereqs and Learning Goals
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

6

Worked Problem: How Many Introductions?

Problem: n people would like to introduce themselves to each other. How many introductions does it take? For 2 people? For 3 people? For 4 people? For 5 people? … For n people?

Sound familiar? Let’s prove it.

7

Worked Problem: How Many Introductions?

Def’n: When two people meet each other, that counts as two intros. Let’s do a few steps concretely to find insight… For 1 person? Given the number for 1, for 2? Given the number for 2, for 3?

8

slide-3
SLIDE 3

Worked Problem: Self-referential structure?

It’s usually good to name things! Let’s let I(n) be the number of introductions required for a group of n people… I(1)? 0 introductions. Given I(k-1), what’s I(k)?

  • a. I(k-1) + 1
  • b. I(k-1) * (k-1)
  • c. I(k-1) + 2(k – 1)
  • d. I(k-1) + 2k
  • e. None of these

9

My turn!

Once we have this, we’re ready for our pattern!

A Pattern for Induction

  • 1. Identify the recursive structure in the problem.
  • 2. Circle each recursive appearance of the

structure inside its definition.

  • 3. Divide the cases into: those without recursive

appearances (“base cases”) and those with (“recursive” or “inductive” cases)

  • 4. Write a predicate P(a) describing what you

want to say about the structure.

  • 5. Write your theorem "aÎ?,P(a)
  • 6. Complete the proof template.

10

A Pattern for Induction

  • 1. Identify the recursive structure in the problem.
  • 2. Circle each recursive appearance of the

structure inside its definition.

  • 3. Divide the cases into: those without recursive

appearances (“base cases”) and those with (“recursive” or “inductive” cases)

  • 4. Write a predicate P(a) describing what you

want to say about the structure.

  • 5. Write your theorem "aÎ?,P(a)
  • 6. Complete the proof template.

11

I(k) I(k-1) “0” base case, “> 0” inductive case I(k) = k(k-1)

12

P(a) ≡ [fill in predicate definition] Theorem: For all [recursive structure] a, P(a) holds. Proof by structural induction: Consider an arbitrary [recursive structure] a. Base case: [For each non-recursive case, prove the theorem holds for that

  • case. End by showing your theorem true for the base case structure!]

Inductive Step: a is recursively defined. Induction Hypothesis: Assume the theorem holds for [each recursive appearance of the structure in this case]. We now show the theorem holds for a. [And then do so! You should: 1) END by showing that your theorem holds for a. 2) USE the “Induction Hypothesis” assumption(s) you made. 3) NEVER take a recursive appearance and use the recursive definition to break it down further, like this BAD example: “each subtree is a binary tree that can have subtrees and so on until we reach an empty tree.”]

It helps to write out what you want to prove rather than just “show the theorem holds for a”. (Even though neither one is strictly necessary.)

slide-4
SLIDE 4

13

P(k) ≡ I(k) = k(k-1) Theorem: For all natural numbers k, P(k) holds. Proof by structural induction: Consider an arbitrary non-zero natural number k. Base case (k=0): We know I(0) = 0. 0(0-1) = 0(-1) = 0, as expected. P Inductive Step: (k>0) Induction Hypothesis: Assume the theorem holds for any j < k: that is, I(j) = j*(j-1). We now show the theorem holds for k. That is, I(k) = k(k-1). I(k) = I(k-1) + 2(k-1) by definition = (k-1)((k-1)-1) + 2(k-1) by the IH = (k-1)(k-2) + 2k – 2 = k^2 – 3k + 2 + 2k – 2 = k^2 – k = k(k-1) as expected P QED

If the recursive structure is parameterized by something, we use that thing inside P(?).

Outline

  • Prereqs and Learning Goals
  • Induction as a Formal Argument Form
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

14

Historical Problem: Sum of Odd Numbers

Problem: What is the sum of the first n odd numbers? First, find the pattern. Then, prove it’s correct. The first 1 odd number? The first 2 odd numbers? The first 3 odd numbers? The first n odd numbers?

Historical note: Francesco Maurolico made the first recorded use of induction in 1575 to prove this theorem!

15

Sum of Odd Numbers: Recursive Structure Problem: Prove that the sum of the first n

  • dd numbers is n2.

How can we break the sum of the first, second, …, nth odd number up in terms of a simpler sum of odd numbers?

16

slide-5
SLIDE 5

Sum of Odd Numbers: Recursive Structure Problem: Prove that the sum of the first n

  • dd numbers is n2.

The sum of the first n odd numbers is the sum of the first n-1 odd numbers plus the nth odd number.

(See our recursive formulation of S from the last slides!)

17

A Pattern for Induction

  • 1. Identify the recursive structure in the problem.
  • 2. Circle each recursive appearance of the

structure inside its definition.

  • 3. Divide the cases into: those without recursive

appearances (“base cases”) and those with (“recursive” or “inductive” cases)

  • 4. Write a predicate P(a) describing what you

want to say about the structure.

  • 5. Write your theorem "aÎ?,P(a)
  • 6. Complete the proof template.

18 19

P(a) ≡ [fill in predicate definition] Theorem: For all [recursive structure] a, P(a) holds. Proof by induction: Consider an arbitrary [recursive structure] a. Base case: [For each non-recursive case, prove the theorem holds for that

  • case. End by showing your theorem true for the base case structure!]

Inductive Step: a is recursively defined. Induction Hypothesis: Assume the theorem holds for [each recursive appearance of the structure in this case]. We now show the theorem holds for a. [And then do so! You should: 1) END by showing that your theorem holds for a. 2) USE the “Induction Hypothesis” assumption(s) you made. 3) NEVER take a recursive appearance and use the recursive definition to break it down further, like this BAD example: “each subtree is a binary tree that can have subtrees and so on until we reach an empty tree.”]

It helps to write out what you want to prove rather than just “show the theorem holds for a”. (Even though neither one is strictly necessary.)

Historical Problem: Sum of Odd Numbers

Theorem: For all positive integers n, the sum of the first n

  • dd natural numbers is n2.

C Base Case (n= ___): Induction Hypothesis: Assume... Inductive Step:

20

H

slide-6
SLIDE 6

21

(by the IH)

Historical Problem: Sum of Odd Numbers

Outline

  • Prereqs and Learning Goals
  • Induction as a Formal Argument Form
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

22

Problem: Proof Critique

Theorem: All horses are the same colour. See handout. Problem: Critique the proof.

23

H

Problem: Proof Critique

Theorem: All horses are the same colour. See handout. Proof critique: Is the proof valid?

  • a. Yes, because each step follows irrefutably

from the previous steps.

  • b. Yes, because the premises are false.
  • c. Yes, but not for the reasons listed here.
  • d. No, because the inductive step fails for n=2.
  • e. No, but not for the reasons listed here.

24

slide-7
SLIDE 7

Problem: Proof Critique

Theorem: All horses are the same colour. See handout. Proof critique: Can the proof be fixed?

25

Ask yourself this question if you see a flaw in a proof… especially if it’s in your proof!

Outline

  • Prereqs and Learning Goals
  • Induction as a Formal Argument Form
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

26

Induction and Computer Science

How important is induction? Is it just for proving things about N? Induction forms the basis of…

– proofs of correctness and efficiency for many algorithms: e.g., How long does it take to detect duplicates in a list of n inputs? Does binary search work? – “recursive” algorithms: e.g., “merge sort” – “recursive data structures”: e.g., How big can a “tree”

  • f height n be?

27

Problem: Detecting Duplicates

Problem: How long does it take to detect duplicates in a list of n Inputs? Let’s assume the amount of “time” taken is proportional to the number of comparisons we make between numbers. We could compare each element to each

  • ther element and see if they’re the same.

Sound familiar? We already know how long this takes!

Note: this isn’t the fastest algorithm!

28

slide-8
SLIDE 8

Problem: Binary Search Works

Problem: Prove that binary search works. Binary search is when we search a sorted list by checking the middle element. If it’s what we’re looking for, we’re done. Otherwise, we “throw out” the part of the list we don’t need (e.g., the left half if the element we looked at was too small) and start over on what remains.

29

Sorting by “Merging”

Problem: sort a list of names. Algorithm:

  • 1. If the list is of length 1, it’s sorted.
  • 2. Otherwise:

a) Divide the list in half (or as close as possible). b) Sort each half using this algorithm. c) Merge the sorted lists back together.

30

The Merge Step

Problem: given two lists of names in sorted

  • rder, merge them into a single sorted list.

Merge(a,b):

  • 1. If a is empty, return b
  • 2. If b is empty, return a
  • 3. Otherwise, if the first element of b comes before

the first element of a, return a list with the first element of b at the front and the result of Merge(a, rest of b) as the rest

  • 4. Otherwise, return a list with the first element of

a at the front and the result of Merge(rest of a, b) as the rest.

31

Problem: Prove Merge works

32

H

slide-9
SLIDE 9

A Pattern for Induction

  • 1. Identify the recursive structure in the problem.
  • 2. Circle each recursive appearance of the

structure inside its definition.

  • 3. Divide the cases into: those without recursive

appearances (“base cases”) and those with (“recursive” or “inductive” cases)

  • 4. Write a predicate P(a) describing what you

want to say about the structure.

  • 5. Write your theorem "aÎ?,P(a)
  • 6. Complete the proof template.

33 34

P(a) ≡ [fill in predicate definition] Theorem: For all [recursive structure] a, P(a) holds. Proof by induction: Consider an arbitrary [recursive structure] a. Base case: [For each non-recursive case, prove the theorem holds for that

  • case. End by showing your theorem true for the base case structure!]

Inductive Step: a is recursively defined. Induction Hypothesis: Assume the theorem holds for [each recursive appearance of the structure in this case]. We now show the theorem holds for a. [And then do so! You should: 1) END by showing that your theorem holds for a. 2) USE the “Induction Hypothesis” assumption(s) you made. 3) NEVER take a recursive appearance and use the recursive definition to break it down further, like this BAD example: “each subtree is a binary tree that can have subtrees and so on until we reach an empty tree.”]

It helps to write out what you want to prove rather than just “show the theorem holds for a”. (Even though neither one is strictly necessary.)

Outline

  • Prereqs and Learning Goals
  • Induction as a Formal Argument Form
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

35

Problem: Prove that 2n < n!

Problem: prove that 2n < n!?

Note: is 2n < n!?

36

H

slide-10
SLIDE 10

A Pattern for Induction

  • 1. Identify the recursive structure in the problem.
  • 2. Circle each recursive appearance of the

structure inside its definition.

  • 3. Divide the cases into: those without recursive

appearances (“base cases”) and those with (“recursive” or “inductive” cases)

  • 4. Write a predicate P(a) describing what you

want to say about the structure.

  • 5. Write your theorem "aÎ?,P(a)
  • 6. Complete the proof template.

37 38

P(a) ≡ [fill in predicate definition] Theorem: For all [recursive structure] a, P(a) holds. Proof by induction: Consider an arbitrary [recursive structure] a. Base case: [For each non-recursive case, prove the theorem holds for that

  • case. End by showing your theorem true for the base case structure!]

Inductive Step: a is recursively defined. Induction Hypothesis: Assume the theorem holds for [each recursive appearance of the structure in this case]. We now show the theorem holds for a. [And then do so! You should: 1) END by showing that your theorem holds for a. 2) USE the “Induction Hypothesis” assumption(s) you made. 3) NEVER take a recursive appearance and use the recursive definition to break it down further, like this BAD example: “each subtree is a binary tree that can have subtrees and so on until we reach an empty tree.”]

It helps to write out what you want to prove rather than just “show the theorem holds for a”. (Even though neither one is strictly necessary.)

Online Quiz Notes: New Problem

Imagine that your country's postal system

  • nly issues 3 cent and 7 cent stamps. Prove

by induction that it is possible to pay for postage using only these stamps for any amount n cents, where n is at least 12. We will use n=12 as one of our base cases. (“We pay 12 cents with four 3 cent stamps”.)

39

Extra Base Cases?

Our inductive step says that for “sufficiently large” n, we can make n cents of postage by making n-3 cents of postage and then using a three cent stamp. What additional base case (if any) do we need?

  • a. n = 6
  • b. n = 13
  • c. n = n-3
  • d. no additional base cases
  • e. more than one additional base case

40

slide-11
SLIDE 11

n ³ ?

Our inductive step says that for “sufficiently large” n, we can make n cents of postage by making n-3 cents of postage and then using a three cent stamp. We use n=12, n=13, and n=14 as base cases. How large must n be for the inductive step?

  • a. n ³ 12
  • b. n ³ 13
  • c. n ³ 14
  • d. n ³ 15
  • e. none of these

41

Extra Base Cases? Version 2

Our inductive step says that for “sufficiently large” n, we can make n cents of postage by making n-1 cents of postage and then doing one of: take out two 7c stamps and add five 3c stamps or (if there are fewer than two 7c stamps), take out two 3c stamps and add a 7c stamp. What additional base case (if any) do we need?

  • a. n = 6
  • b. n = 13
  • c. n = n-1
  • d. no additional base cases
  • e. more than one additional base case

42

n ³ ? Version 2

Our inductive step says that for “sufficiently large” n, we can make n cents of postage by making n-1 cents of postage and then doing one of: take out two 7c stamps and add five 3c stamps or (if there are fewer than two 7c stamps), take out two 3c stamps and add a 7c stamp. We use n=12 as our only base case. How large must n be for the inductive step?

  • a. n ³ 12
  • b. n ³ 13
  • c. n ³ 14
  • d. n ³ 15
  • e. none of these

43

Bonus DFA-Circuit example

Convert this DFA to a sequential circuit: First step: what does it do?

44

slide-12
SLIDE 12

Bonus DFA-Circuit example

Goals: Preliminary work – draw the high level view

  • f the circuit you’re building

45

H

Bonus DFA-Circuit example

Convert this DFA to a sequential circuit: Second step: articulate the logic via a TT

46

H

Bonus DFA-Circuit example

Third step: build logic for each Current state

47

Bonus DFA-Circuit example

Fourth step: build logic for each accepting state

48

slide-13
SLIDE 13

Bonus DFA-Circuit example

Admire your work:

49

Outline

  • Prereqs and Learning Goals
  • Induction as a Formal Argument Form
  • Problems and Discussion

– Introductions – Odd Numbers – Horse Colours – CS Induction: Duplicate Detection, Binary Search, MergeSort – More examples

  • Next Lecture Notes

50

Learning Goals: In-Class

By the end of this unit, you should be able to:

– Formally prove properties of the non-negative integers (or a subset like integers larger than 3) that have appropriate self-referential structure— including both equalities and inequalities—using either weak or strong induction as needed. – Critique formal inductive proofs to determine whether they are valid and where the error(s) lie if they are invalid.

51

Lecture Prerequisites

In the “Textbook and References” section of the course website:

– Read the “Sets and functions” sections.

Complete the open-book, untimed, online quiz that is due before class.

52