How do proofs look, about natural numbers? For example, here are two functions which process natural numbers; how can we prove that they are equivalent (that is, that they return the same result for all inputs, regardless of how they happen to compute that result)?
; Recall: ; Def'n of NatNum: ; - 0 ; - add1(k), where k is a NatNum. ; ; ; How do programs look, which use this def'n? ;; sumA: NatNum -> NatNum ;; Return the sum of the natNums in [0,n]. ;; (define (sumA n) (cond [(zero? n) 0] [(positive? n) (+ n (sumA (sub1 n)))])) ; ; Calling sumA(4) calls sumA(3) calls sumA(2) ... calls sumA(0). ;; sumB: NatNum -> NatNum ;; Return the sum of the natNums in [0,n]. ;; (define (sumB n) (* n (add1 n) 1/2)) ; See test cases in lect15-sum-test.ss ; Clearly sumB is a better solution than sumA -- ; but is it correct? Can we prove it correct? ; (Are there some implicit assumptions? If so, what?)
We want to prove these two functions are equivalent. We start by making a parameterized statement:
Let P(n) be the statement "(sumA n) = (sumB n)."
Here's the battle plan of proofs by induction:
Proof of &forall n.P(n), by induction:
Inductive step: For all k∈N, P(k) → P(k+1):
We need to show that (sumA k+1) = (sumB k+1).
One tool we'll have at hand is our inductive hypothesis P(k):
(sumA k) = (sumB k).
Okay, here goes: For k≥0,
(sumA k+1) = (+ k+1 (sumA (sub1 k+1))) [by code of sumA] = (k+1) + (sumA k) [by language's-implementation-of-arithmetic] = (k+1) + (sumB k) [by inductive hypothesis P(k)] = (k+1) + (* k (add1 k) 1/2) [by code of sumB] = (k+1) + k(k+1)/2 [by langauge's-implementation-of-arithmetic] = (k+1)*(1 + k/2) = (k+1)*(2/2 + k/2) = (k+1)*(k+2)/2 = (* k+1 (add1 k+1) 1/2) = (sumB k+1)Following that entire chain of equalities, we see that we have P(k+1).
Really, this is a new inference rule (particular to N):
If you know… Then you can conclude… P(0) } forall k. (P(k) → P(k+1)) } forall n.P(n)Read Rosen for more number examples.
By the way, a note on ∑k=1n (k) = n(n+1)/2:
***** **** *** ** *This is the picture of ∑k=15 (k).
S = 1 + 2 + … + n-1 + n, S = n + n-1 + … + 2 + 1 ------------------------------------------ add both equations 2S = (n+1) + (n+1) + … + (n+1) + (n+1) (n copies)Note: For arithmetic progression: Sum is (first-term + last-term) ⋅ number-of-terms / 2. My mantra: ``first plus last times n over two.''
board tiling, from Rosen.
P(n) = "A checkerboard 2n x 2n with one corner removed,
can be exactly tiled by L-shaped tri-ominoes."
A homework exercise:
• Show: &sumk=1n 2k
= 2k+1-1.
• Show: &sumk=1n bk
= (bk+1-1)/(b-1).
E.g., when b=10, we have 1+10+100+1000 = 1111 = 9999/9.
…[do the proof in lecture]…
Reflection on this sum:
S = 1 + b + b2 + … + bk bS = b + b2 + … + bk + bk+1 ------------------------------------------------------- S-bS = 1 - bk+1You think "Aw man, why'd we have to do this roundabout induction method, when we just could have written that?" Aside from the fact that it's the induction we're trying to teach (and not so much the proof of this particular equation), another way to view it is to say that induction is taking the inherent fuzziness of the ``…'' out of the the algebraic sleight-of-hand. Note that this fuzziness is still there even if you use the summation notation — it's just absorbed into the notation.
Note that induction doesn't provide us with any hint as to what our sums should look like, but if we have some guess then it gives us a method to prove that guess correct. The book has the formulas for (say) the sum-of-squares and sum-of-cubes. What about ∑k=1nk17, if we really needed a nice expression for this? We could guess that the answer is an 18th-degree polynomial, set up a generic polynomial with coefficients a18,…a0, and then (by plugging in 19 different values for n) come up with 19 linear equations in the 19 unknowns a18,…a0. We then solve for these coefficients. Finally, to wrap it off entirely, we could use induction to prove the formula correct (since it was intuition that an 18th-degree polynomial really would provide a solution).
(Got to here 2005.Mar.02, after covering sums and other review.)
Example 4, an inequality:
Harmonic series (in Rosen p.243, Example #6):
H2k ≥ 1+(k/2).
Note that this can be re-stated as,
Hn ≥ 1+lg(n)/2,
though suddenly we'd want to show this for all n (not just powers-of-2).
If all cities connected in one direction or the other, then there is some city which is connected to all others in either one or two steps.
After some work, I found I was using the same phrases over and over, like "a city connected to all cities within one or two steps". Some select definitions make the problem not only more concise, but also more understandable:
Given a semi-connected graph G, choose an arbitrary vertex v.
Note that G-{v} is semi-connected. [Aside: Def'n of G-{v} ?]
Let h0 be "old" hub of G-{v}.
What's wrong with this inductive proof: P(n) is "n > 1000".
(After all, it's easy to show P(k) → P(k+1).)
Okay, we'll patch that problem;
what's wrong with the induction proof of: P(n) is "n>1000 or n=0".
False proof: All horses are the same color.
Proof by induction for n>1.
let P(n) be "for a set of n horses, they all have the same color".
P(k) → P(k+1), ∀ k ≥ 1:
We need to show P(k+1). Start with any set of k+1 horses; we'll show
every member of H = { h1, …, hk, hk+1 } has the same color as h1.
First, h1 through hk all have the same color as h1
(by inductive hypothesis regarding the set H - {hk+1}).
It only remains to show that hk+1 is the same color.
But again by applying P(k) to the k-element set
H-{hk} = {h1, …, hk-1, hk+1 },
all have the same color as h1 (which includes hk+1).
Since "has the same color as" is transitive, all elements of H are the same color as h1. Q.E.D.
The question is, what is wrong with the proof? (We know the conclusion is wrong; we are asking, why is this proof not really following the rule of induction. If it were, then we'd have an example that induction isn't actually a valid rule of inference!)
A: For inequalities you can state "B ≤ C" as obvious when the right-hand-side C is:
Thus like in today's class example with the harmonic-number sum:
1 + 1/2 + 1/3 + … + 1/2k + 1/(2k+1) + 1/(2k+2) + … + 1/(2k+2k) ≥ 1 + 1/2 + 1/3 + … + 1/2k + 1/2k+1 + 1/2k+1 + … + 1/2k+1is fine, with the explanation "Replacing some terms by larger ones". Also, indenting can go a long way in making it clear how you're doing the replacement.
Similarly, it's fine to say
blah ≤ blah + (a² - 1)(in this case, need to take care that a²-1 is non-negative, which means you might need to mention why a isn't zero.)
Tip: when using < vs ≤, use the strongest statement possible — e.g. use < when the inequality really is strict. (So in the harmonic example above, is the "<" actually true for k=0?)