cornell math proof
cornell math proof
One way of proving things is by induction. Theorem n is odd iff (in and only if) n2 is odd, for
• That’s coming next. n ∈ Z.
1 2
√
Theorem: 2 is irrational. This is perhaps the most important technique we’ll learn
√ for proving things.
Proof: By contradiction. Suppose 2 is rational. Then
√
2 = a/b for some a, b ∈ N +. We can assume that a/b Idea: To prove that a statement is true for all natural
is in lowest terms. numbers, show that it is true for 1 (base case or basis
• Therefore, a and b can’t both be even. step) and show that if it is true for n, it is also true for
n + 1 (inductive step).
Squaring both sides, we get
• The base case does not have to be 1; it could be 0, 2,
2 = a2/b2 3, . . .
Thus, a2 = 2b2, so a2 is even. This means that a must • If the base case is k, then you are proving the state-
be even. ment for all n ≥ k.
Suppose a = 2c. Then a2 = 4c2.
It is sometimes quite difficult to formulate the statement
Thus, 4c2 = 2b2, so b2 = 2c2. This means that b2 is even, to prove.
and hence so is b.
IN THIS COURSE, I WILL BE VERY FUSSY ABOUT
Contradiction!
√ THE FORMULATION OF THE STATEMENT TO PROVE.
Thus, 2 must be irrational. YOU MUST STATE IT VERY CLEARLY. I WILL ALSO
BE PICKY ABOUT THE FORM OF THE INDUC-
TIVE PROOF.
3 4
Writing Up a Proof by Induction A Simple Example
(1 + x)n+1 = (1 + x)n(1 + x)
≥ (1 + nx)(1 + x)[Induction hypothesis]
= 1 + nx + x + nx2
= 1 + (n + 1)x + nx2
≥ 1 + (n + 1)x
• Why does this argument fail if x < −1?
7 8
Towers of Hanoi Solution
• Move top n − 1 rings from pole 1 to pole 3 (we can
do this by assumption)
◦ Pretend largest ring isn’t there at all
• Move largest ring from pole 1 to pole 2
• Move top n − 1 rings from pole 3 to pole 2 (we can
do this by assumption)
◦ Again, pretend largest ring isn’t there
This solution translates to a recursive algorithm:
• Suppose robot(r → s) is a command to a robot to
move the top ring on pole r to pole s
Problem: Move all the rings from pole 1 and pole 2, • Note that if r, s ∈ {1, 2, 3}, then 6 − r − s is the other
moving one ring at a time, and never having a larger ring number in the set
on top of a smaller one.
How do we solve this? procedure H(n, r, s) [Move n disks from r to s]
if n = 1 then robot(r → s)
• Think recursively! else H(n − 1, r, 6 − r − s)
• Suppose you could solve it for n − 1 rings? How could robot(r → s)
you do it for n? H(n − 1, 6 − r − s, s)
endif
return
endpro
9 10
Theorem: It takes 2n − 1 moves to perform H(n, r, s), Theorem: Any algorithm to move n rings from pole r
for all positive n, and all r, s ∈ {1, 2, 3}. to pole s requires at least 2n − 1 steps.
Proof: Let P (n) be the statement “It takes 2n −1 moves Proof: By induction, taking the statement of the theo-
to perform H(n, r, s) and all r, s ∈ {1, 2, 3}.” rem to be P (n).
• Note that “for all positive n” is not part of P (n)! Basis: Easy: Clearly it requires (at least) 1 step to move
• P (n) is a statement about a particular n. 1 ring from pole r to pole s.
• If it were part of P (n), what would P (1) be? Inductive step: Assume P (n). Suppose you have a se-
quence of steps to move n + 1 rings from r to s. There’s
Basis: P (1) is immediate: robot(r → s) is the only move a first time and a last time you move ring n + 1:
in H(1, r, s), and 21 − 1 = 1. • Let k be the first time
Inductive step: Assume P (n). To perform H(n+1, r, s), • Let k 0 be the last time.
we first do H(n, r, 6 − r − s), then robot(r → s), then
H(n, 6 − r − s, s). Altogether, this takes 2n − 1 + 1 + • Possibly k = k 0 (if you only move ring n + 1 once)
2n − 1 = 2n+1 − 1 steps. Suppose at step k, you move ring n + 1 from pole r to
pole s0.
• You can’t assume that s0 = s, although this is opti-
mal.
11 12
Key point: Strong Induction
0
• The top n rings have to be on the third pole, 6−r −s
• Otherwise, you couldn’t move ring n + 1 from r to s0. Sometimes when you’re proving P (n + 1), you want to
By P (n), it took at least 2n − 1 moves to get the top n be able to use P (j) for j ≤ n, not just P (n). You can
rings to pole 6 − r − s0. do this with strong induction.
At step k 0, the last time you moved ring n + 1, suppose 1. Let P (n) be the statement . . . [some statement involv-
you moved it from pole r0 to s (it has to end up at s). ing n]
• the other n rings must be on pole 6 − r0 − s. 2. The basis step
n
• By P (n), it takes at least 2 − 1 moves to get them • P (k) holds because . . . [where k is the base case,
to ring s (where they have to end up). usually 0 or 1]
So, altogether, there are at least 2(2n − 1) + 1 = 2n+1 − 1 3. Inductive step
moves in your sequence:
• Assume P (k), . . . , P (n) holds. We show
• at least 2n − 1 moves before step k P (n + 1) holds as follows . . .
• at least 2n − 1 moves after step k 0 Although strong induction looks stronger than induction,
• step k itself. it’s not. Anything you can do with strong induction,
you can also do with regular induction, by appropriately
If course, if k 6= k 0 (that is, if you move ring n + 1 more
modifying the induction hypothesis.
than once) there are even more moves in your sequence.
• If P (n) is the statement you’re trying to prove by
strong induction, let P 0(n) be the statement P (1), . . . , P (n)
hold. Proving P 0(n) by regular induction is the same
as proving P (n) by strong induction.
13 14
Theorem: Any item costing n > 7 kopecks can be Suppose we wanted to sort n items. Here’s one way to
bought using only 3-kopeck and 5-kopeck coins. do it:
Proof: Using strong induction. Let P (n) be the state- Input n [number of items to be sorted]
ment that n kopecks can be paid using 3-kopeck and 5- w1, . . . , wn [items]
kopeck coins, for n ≥ 8.
Algorithm BubbleSort
Basis: P (8) is clearly true since 8 = 3 + 5.
for i = 1 to n − 1
Inductive step: Assume P (8), . . . , P (n) is true. We for j = 1 to n − i
want to show P (n + 1). If n + 1 is 9 or 10, then it’s if wj > wj+1 then switch(wj , wj+1) endif
easy to see that there’s no problem (P (9) is true since endfor
9 = 3 + 3 + 3, and P (10) is true since 10 = 5 + 5). endfor
Otherwise, note that (n + 1) − 3 = n − 2 ≥ 8. Thus,
P (n − 2) is true, using the induction hypothesis. This Why is this right:
means we can use 3- and 5-kopeck coins to pay for some-
• Intuitively, because largest elements “bubble up” to
thing costing n−2 kopecks. One more 3-kopeck coin pays
the top
for something costing n + 1 kopecks.
How many comparisons?
• Best case, worst case, average case all the same:
◦ (n − 1) + (n − 2) + · · · + 1 = n(n − 1)/2
15 16
Proving Bubble Sort Correct Inductive step: Suppose that Q(l) is true. If l+1 ≥ n−1,
then Q(l + 1) is vacuously true. If l + 1 < n, by Q(l), we
know that wl+1 > wj , for j = 1, . . . , l after l iterations.
We want to show that the algorithm is correct by induc- The (l + 1)st iteration of the inner loop compares wl+1
tion. What’s the statement of the induction? and wl+2. After the (l + 1)st iteration, the bigger one is
Could take P (n) to be the statement: the algorithm wl+2. Thus, wl+2 > wl+1. By the induction hypothesis,
works correctly for n inputs. wl+2 > wj , for j + 1, . . . , l.
• That turns out to be a tough induction statement to That completes the nested induction. Thus, Q(l) holds
work with. for all l. Q(n−1) says that wn > wj for j = 1, . . . , n−1.
That’s just what P (1) says. So we’re done with the base
• Suppose P (1) is true. How do you prove P (2)?
case of the main induction.
A better choice: [Note: For a really careful proof, we need better notation
• P (k) is the statement that, if there are n inputs and (for value of wl before and after the switch).]
k ≤ n − 1, then after k iterations of the outer loop,
Inductive step (for main induction): Assume P (k).
wn−k+1, . . . , wn are the k largest items, sorted in the
Thus, wk+1, . . . , wn are the k largest items. To prove
right order.
P (k + 1), we use nested induction again:
◦ Note that P (k) is vacuously true if k ≥ n.
• Now Q(l) says “if i = k + 1, then if l ≤ n − (k + 1),
Basis: How do we prove P (1)? By a nested induction! after l iterations of the inner loop, wl+1 > wj , for
j = 1, . . . , l.”
This time, take Q(l) to be the statement that, if l ≤ n−1,
then after l iterations of the inner loop, wl+1 > wj , for • Almost the same as before, except that instead of say-
j = 1, . . . , l. ing “if l ≤ n − 1”, we say “if l ≤ n − (k + 1).”
Basis: Q(1) holds because after the first iteration of the ◦ If i = k + 1, we go through the inner loop only
inner loop, w2 > w1 (thanks to the switch statement). n − (k + 1) times.
17 18
Q(n − k − 1) says that, after the (k + 1)st iteration of the How to Guess What to Prove
inner loop, wn−k > wj for j = 1, . . . , k. P (k) says that
the top k elements are wn−k+1, . . . , wn, in that order.
Thus, the top k + 1 elements must be wn−k , . . . wn, in Sometimes formulating P (n) is straightforward; some-
that order. This proves P (k + 1). times it’s not. This is what to do:
Note that P (n − 1) says that after n − 1 iterations of the • Compute the result in some specific cases
outer loop (which is all there are), the top n − 1 elements • Conjecture a generalization based on these cases
are w2, . . . , wn. So w1 has to be the smallest element,
and w1, w2, . . . , wn is a sorted list. • Prove the correctness of your conjecture (by induc-
tion)
19 20
Example
21