strong induction cse 311 autumn 20 lecture 16Β Β· 2020. 12. 29.Β Β· strong induction that hypothesis...
TRANSCRIPT
Strong Induction CSE 311 Autumn 20
Lecture 16
Announcements
Hey, things are kinda crazyβ¦
If news is making it infeasible to do your work, send an email to Robbie/make a private post on Ed; we can talk about what to do.
In general, please talk to us. If youβre struggling (with personal issues or just because the course is moving quickly) we can find ways to help, but thereβs only so much we can do without you reaching out first.
Gumball
Says everything will be ok.
How do we know recursion works?
//Assume i is a nonnegative integer
//returns 2^i.
public int CalculatesTwoToTheI(int i){
if(i == 0)
return 1;
else
return 2*CaclulatesTwoToTheI(i-1);
}
Why does CalculatesTwoToTheI(4) calculate 2^4?
Convince the other people in your room
Making Induction Proofs Pretty
Let π(π) be βCalculatesTwoToTheI(i)β returns 2π.
Base Case (π = 0) Note that if the input π is 0, then the if-statement evaluates to true, and 1 = 2^0 is returned, so π(0) is true.
Inductive Hypothesis: Suppose π(π) holds for an arbitrary π β₯ 0.
Inductive Step: Since π β₯ 0, π β₯ 1, so the code goes to the recursive case. We will return 2 β CalculatesTwoToTheI(k). By Inductive Hypothesis,
CalculatesTwoToTheI(k)= 2π. Thus we return 2 β 2π = 2π+1.
So π(π + 1) holds.
Therefore π(π) holds for all π β₯ 0 by the principle of induction.
Making Induction Proofs Pretty
All of our induction proofs will come in 5 easy(?) steps!
1. Define π(π). State that your proof is by induction on π.
2. Base Case: Show π(0) i.e. show the base case
3. Inductive Hypothesis: Suppose π(π) for an arbitrary π.
4. Inductive Step: Show π π + 1 (i.e. get π π β π(π + 1))
5. Conclude by saying π π is true for all π by the principle of induction.
Some Other Notes
Always state where you use the inductive hypothesis when youβre using it in the inductive step.
Itβs usually the key step, and the reader really needs to focus on it.
Be careful about what values youβre assuming the Inductive Hypothesis for β the smallest possible value of π should assume the base case but nothing more.
The Principle of Induction (formally)
Informally: if you knock over one domino, and every domino knocks over the next one, then all your dominoes fell over.
π 0 ; βπ(π π β π π + 1 )
β΄ βπ(π π )
Principle of
Induction
More InductionInduction doesnβt only work for code!
Show that Οπ=0π 2π = 1 + 2 + 4 +β―+ 2π = 2π+1 β 1.
More InductionInduction doesnβt only work for code!
Show that Οπ=0π 2π = 1 + 2 + 4 +β―+ 2π = 2π+1 β 1.
Let π π =βΟπ=0π 2π = 2π+1 β 1.β
We show π(π) holds for all π by induction on π.
Base Case ( )
Inductive Hypothesis:
Inductive Step:
π(π) holds for all π β₯ 0 by the principle of induction.
More InductionInduction doesnβt only work for code!
Show that Οπ=0π 2π = 1 + 2 + 4 +β―+ 2π = 2π+1 β 1.
Let π π =βΟπ=0π 2π = 2π+1 β 1.β
We show π(π) holds for all π by induction on π.
Base Case (π = 0)Οπ=00 2π = 1 = 2 β 1 = 20+1 β 1.
Inductive Hypothesis: Suppose π(π) holds for an arbitrary π β₯ 0.
Inductive Step: We show π(π + 1). Consider the summationΟπ=0π+12π =
2k+1 + Οπ=0π 2π = 2π+1 + 2π+1 β 1 , where the last step is by IH.
Simplifying, we get: Οπ=0π+1 2π = 2π+1 + 2π+1 β 1 = 2 β 2π+1 β 1 =
2 π+1 +1 β 1.
π(π) holds for all π β₯ 0 by the principle of induction.
Letβs Try Another Induction Proof
Let π π = α2 if π = 2π(π β 1)2 + 3π π β 1 if π > 2
Prove π(π) is even for all π β₯ 2 by induction on π.
Letβs just set this one up, weβll leave the individual pieces as exercises.
Setup
Let π(π) be βπ(π) is even.β
HEY WAIT -- π(0) isnβt true π(0) isnβt even defined!
We can move the βstarting lineβ
Change the base case, and then update the IH to have the smallest value of π assume just the base case.
Setup
Let π(π) be βπ(π) is even.β
We show π π for all π β₯ 2 by induction on π.
Base Case (π = π): π π = 2 by definition. 2 is even, so we have π(2).
Inductive Hypothesis: Suppose π(π) holds for an arbitrary k β₯ 2.
Inductive Step: We show π(π + 1). Consider π(π + 1). By definition of π β , π π + 1 = π(π)2 + 3π π . By inductive hypothesis, π(π) is even, so it equals 2π for some integer π. Plugging in we have:
π π + 1 = 2π 2 + 3 2π = 2 2π2 + 2 3π = 2(2π2 + 3π).
Since π is an integer, 2π2 + 3π is also an integer, and π(π + 1) is even.
Therefore, π(π) holds for all π β₯ 2 by the principle of induction.
Making Induction Proofs Pretty
All of our induction proofs will come in 5 easy(?) steps!
1. Define π(π). State that your proof is by induction on π.
2. Base Case: Show π(π) i.e. show the base case
3. Inductive Hypothesis: Suppose π(π) for an arbitrary π β₯ π.
4. Inductive Step: Show π π + 1 (i.e. get π π β π(π + 1))
5. Conclude by saying π π is true for all π β₯ π by the principle of induction.
Letβs Try Another Induction Proof
Uniqueness is hard. Letβs just show existence.
I.e.
Claim: Every positive integer greater than 1 can be written as a product of primes.
Every positive integer greater than 1 has a unique
prime factorization.
Fundamental Theorem of Arithmetic
Induction on Primes.
Let π(π) be βπ can be written as a product of primes.β
We show π(π) for all π β₯ 2 by induction on π.
Base Case (π = π): 2 is a product of just itself. Since 2 is prime, it is written as a product of primes.
Inductive Hypothesis: Suppose π(π) holds for an arbitrary integer π β₯ 2.
Inductive Step: Case 1, π + 1 is prime: then π + 1 is automatically written as a product of primes.
Case 2, π + 1 is composite:
Therefore π(π + 1).
π(π) holds for all π β₯ 2 by the principle of induction.
Weβre Stuck
We can divide π + 1 up into smaller pieces (say π , π‘ such that π π‘ = π + 1with 2 β€ π < π + 1 and 2 β€ π‘ < π + 1
Is π(π ) true? Is π(π‘) true?
I meanβ¦it would beβ¦
But in the inductive step we donβt have itβ¦
Letβs add it to our inductive hypothesis.
Induction on Primes
Let π(π) be βπ can be written as a product of primes.β
We show π(π) for all π β₯ 2 by induction on π.
Base Case (π = π): 2 is a product of just itself. Since 2 is prime, it is written as a product of primes.
Inductive Hypothesis:
Inductive Step: Case 1, π + 1 is prime: then π + 1 is automatically written as a product of primes.
Case 2, π + 1 is composite:
Therefore π(π + 1).
π(π) holds for all π β₯ 2 by the principle of induction.
Induction on Primes
Let π(π) be βπ can be written as a product of primes.β
We show π(π) for all π β₯ 2 by induction on π.
Base Case (π = π): 2 is a product of just itself. Since 2 is prime, it is written as a product of primes.
Inductive Hypothesis: Suppose π 2 ,β¦ , π π hold for an arbitrary integer π β₯ 2.
Inductive Step: Case 1, π + 1 is prime: then π + 1 is automatically written as a product of primes.
Case 2, π + 1 is composite: We can write π + 1 = π π‘ for π , π‘ nontrivial divisors (i.e. 2 β€ π < π + 1 and 2 β€ π‘ < π + 1). By inductive hypothesis, we can write π as a product of primes π1 β β¦ ππ and π‘ as a product of primes π1β―πβ. Multiplying these representations, π + 1 = π1β―ππ β π1β―πβ, which is a product of primes.
Therefore π(π + 1).
π(π) holds for all π β₯ 2 by the principle of induction.
Strong Induction
That hypothesis where we assume π base case , β¦ , π(π) instead of just π(π) is called a strong inductive hypothesis.
Strong induction is the same fundamental idea as weak (βregularβ) induction.
π(0) is true.
And π 0 β π(1), so π 1 .And π 1 β π(2), so π 2 .And π 2 β π(3), so π 3 .And π 3 β π(4), so π 4 .β¦
π(0) is true.
And π 0 β π(1), so π 1 .And [P 0 β§ π 1 ] β π(2), so π 2 .And [P 0 β§ β―β§ π 2 ] β π(3), so π 3 .And[P 0 β§ β―β§ π 3 ] β π(4), so π 4 .β¦
Making Induction Proofs Pretty
All of our strong induction proofs will come in 5 easy(?) steps!
1. Define π(π). State that your proof is by induction on π.
2. Base Case: Show π(π) i.e. show the base case
3. Inductive Hypothesis: Suppose P b β§ β―β§ π(π) for an arbitrary π β₯ π.
4. Inductive Step: Show π π + 1 (i.e. get [P b β§ β―β§ π(π)] β π(π + 1))
5. Conclude by saying π π is true for all π β₯ π by the principle of induction.
Strong Induction vs. Weak Induction
Think of strong induction as βmy recursive call might be on LOTS of smaller valuesβ (like mergesort β you cut your array in half)
Think of weak induction as βmy recursive call is always on one step smaller.β
Practical advice:
A strong hypothesis isnβt wrong when you only need a weak one (but a weak one is wrong when you need a strong one). Some people just always write strong hypotheses. But itβs easier to typo a strong hypothesis.
Robbie leaves a blank spot where the IH is, and fills it in after the step.
Practical Advice
How many base cases do you need?Always at least one.
If youβre analyzing recursive code or a recursive function, at least one for each base case of the code/function.
If you always go back π steps, at least π consecutive base cases.
Enough to make sure every case is handled.
Letβs Try Another! Stamp Collecting
I have 4 cent stamps and 5 cent stamps (as many as I want of each). Prove that I can make exactly π cents worth of stamps for all π β₯ 12.
Try for a few values.
Then thinkβ¦how would the inductive step go?
Stamp Collection (attempt)
Define π(π) I can make π cents of stamps with just 4 and 5 cent stamps.
We prove π(π) is true for all π β₯ 12 by induction on π.
Base Case:
12 cents can be made with three 4 cent stamps.
Inductive Hypothesis Suppose [maybe some other stuff and] π(π), for an arbitrary π β₯ 12.
Inductive Step:
We want to make π + 1 cents of stamps. By IH we can make π β 3 cents exactly with stamps. Adding another 4 cent stamp gives exactly π + 1cents.
Stamp Collection
Is the proof right?
How do we know π(13)
Weβre not the base case, so our inductive hypothesis assumes π(12), and then we say if π 9 then π(13).
Wait a secondβ¦.
If you go back π steps every time, you need π base cases.
Or else the first few values arenβt proven.
Stamp Collection
Define π(π) I can make π cents of stamps with just 4 and 5 cent stamps.
We prove π(π) is true for all π β₯ 12 by induction on π.
Base Case:
12 cents can be made with three 4 cent stamps.13 cents can be made with two 4 cent stamps and one 5 cent stamp.14 cents can be made with one 4 cent stamp and two 5 cent stamps.15 cents can be made with three 5 cent stamps.
Inductive Hypothesis Suppose P 12 β§ π 13 β§ β―β§ π(π), for an arbitrary π β₯ 15.
Inductive Step:
We want to make π + 1 cents of stamps. By IH we can make π β 3 cents exactly with stamps. Adding another 4 cent stamp gives exactly π + 1 cents.
A good last check
After youβve finished writing an inductive proof, pause.
If your inductive step always goes back π steps, you need π base cases (otherwise π + 1 will go back before the base cases youβve shown). And make sure your inductive hypothesis is strong enough.
If your inductive step is going back a varying (unknown) number of steps, check the first few values above the base case, make sure your cases are really covered. And make sure your IH is strong.
Making Induction Proofs Pretty
All of our induction proofs will come in 5 easy(?) steps!
1. Define π(π). State that your proof is by induction on π.
2. Base Cases: Show π ππππ , π ππππ+1 β¦π(ππππ₯) i.e. show the base cases
3. Inductive Hypothesis: Suppose π ππππ β§ π ππππ + 1 β§ β―β§ π(π) for an arbitrary π β₯ ππππ₯ . (The smallest value of π assumes all bases cases, but nothing else)
4. Inductive Step: Show π π + 1 (i.e. get [P(bπππ β§ β―β§ π π ] β π(π + 1))
5. Conclude by saying π π is true for all π β₯ ππππ by the principle of induction.
Stamp Collection, Done Wrong
Define π(π) I can make π cents of stamps with just 4 and 5 cent stamps.
We prove π(π) is true for all π β₯ 12 by induction on π.
Base Case:
12 cents can be made with three 4 cent stamps.Inductive Hypothesis Suppose π(π), π β₯ 12.
Inductive Step:
We want to make π + 1 cents of stamps. By IH we can make π cents exactly with stamps. Replace one of the 4 cent stamps with a 5 cent stamp.
π(π) holds for all π by the principle of induction.
Stamp Collection, Done Wrong
What if the starting point doesnβt have any 4 cent stamps?
Like, say, 15 cents = 5+5+5.
Even more practice
Iβve got a bunch of these 3 piece tiles.
I want to fill a 2πx2π grid (π β₯ 1) with the pieces, except for a 1x1 spot in a corner.
Gridding
Base Case: π = 1
Inductive hypothesis: Suppose you can tile a 2πx2π grid, except for a corner.
Inductive step: 2π+1x2π+1, divide into quarters. By IH can tileβ¦