proof by induction
why it works
what it is
To prove a claim for every whole number, prove it for the first, then show that whenever it holds (is true) for one number, it holds for the next.
A claim about every whole number cannot be checked one number at a time, since the numbers never run out. The page on doubling sums adds terms each twice the one before: 1 + 2 + 4 + 8 is 15, one less than the next term, 16. The last term is 2 to the power , so for 1 + 2 + 4 + 8, is 3. After 8, 2 to the power 3, comes 16, 2 to the power 4, so one less than the next term is . Is that true for every ?
Climb it like a ladder. The start: check by hand the first number the claim covers, 0 here. The step: show that whenever one rung holds, so does the next. Then the claim holds at 0 by the start, at 1 by the step, then at 2, and on. This is proof by induction. Books call the start the base case, and the step the inductive step.
In the step you suppose the claim holds one size down, at (for 3, at 2), then show it holds at . At 3: if 1 + 2 + 4 is 8 less 1, then 1 + 2 + 4 + 8 is 7 + 8, which is 16 less 1. Books call the supposing the inductive hypothesis.
Sometimes one rung down is not enough to stand on. Count the halvings from 13 to 1, rounding down: one halving to 6, then 6's own count. 6 is far below 12, one size down. So suppose the claim for every smaller number, since each is reached before . This is strong induction.
where the formulas come from
Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about , or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.
the move: check the first case
the line:why it is allowed: At as 0 the last term is 2 to the power 0, which is 1, so the sum is the one term 1. 2 to the power 1, less 1, is 1 too. This is the start.
the move: name the sum
the line:why it is allowed: Let be the sum. as 0 is the start, line 1; the step needs to be 0 or more, so it covers 1, 2, 3 and on. For 3, is 1 + 2 + 4 + 8.
guess it, thenthe move: split off the last term
the line:the sum one size down the new term, the total, 1 1 2 3 3 2 3 4 7 7 3 7 8 15 15 4 15 16 31 31 Line 3 for from 1 to 4. Each total matches the formula. why it is allowed: The bracket is the same sum one size down, in place of . At as 1 the bracket is just 1; for 3 it is 1 + 2 + 4, so the line reads 7 + 8.
guess it, thenthe move: suppose it holds one size down
the line:why it is allowed: The step. Suppose the claim holds at : it is the claim with in place of , so the bracket is 2 to the power , less 1. For 3, at 2: 2 to the power 3 (that is, 2 + 1) is 8, and 8 less 1 is 7.
guess it, thenthe move: tidy the power
the line:why it is allowed: is . So the sum one size down is , one less than the new term. For 3, 7 is 8 less 1.
guess it, thenthe move: collect the two
the line:why it is allowed: Two lots of , less 1. For 3, 16 less 1.
guess it, thenthe move: twice a power of 2 is the next
the line:why it is allowed: One more 2 multiplied. For 3, 2 × 8 is 16, which is 2 to the power 4, so 15, as line 2 adds up.
guess it, thenthe move: read it
the line:why it is allowed: Line 1 is the start. Lines 3 to 7 are the step, carrying the claim from to for any from 1.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
the move: check the first gap
the line:Shell sort on 8, 5, 2, 6, 1, 7: the gap 4 pass compares 8 with 1 and 5 with 7, and trades 8 and 1. Then gap 1 finishes. why it is allowed: Shell sort first sorts numbers a gap apart, then a smaller gap, down to 1, as the picture shows. Gap number 1 is 1, and 2 to the power 0 is 1, so it is at least that. This is the start.
the move: a gap from the one before
the line:- the gaps
The gaps and the powers of 2 for gap numbers 1 to 5. The gaps pull away. why it is allowed: Each gap is three times the one before, plus 1, as the question says. Let be gap number , from 2, since gap number 1 is the start, and the gap before it. For as 3, 3 × 4 + 1 is 13.
guess it, thenthe move: suppose it holds one gap down
the line:why it is allowed: The step. reads is at least. Suppose the claim holds for gap number , which is : it is the claim with in place of . For 3, gap number 2 is 4, at least 2.
guess it, thenthe move: tidy the power
the line:why it is allowed: is , as is .
guess it, thenthe move: three times both sides of line 4
the line:why it is allowed: Multiplying both sides by 3, a positive number, keeps the at least. For 3, 12 is at least 6.
guess it, thenthe move: add 1 to both sides
the line:why it is allowed: Adding the same to both sides keeps the at least. For 3, 13 is at least 7.
guess it, thenthe move: put line 2 in
the line:gap number line 7 gives at least 2 4 4 2 3 13 7 4 4 40 13 8 5 121 25 16 Each gap, the least value line 7 allows it, and , for from 2 to 5. Each is at least the one to its right. why it is allowed: Line 2 says is . For 3, 13 is at least 7.
guess it, thenthe move: drop the 1
the line:why it is allowed: Taking 1 off the right side makes it smaller, so is still at least it. For 3, 13 is at least 6.
guess it, thenthe move: two lots are no more than three
the line:why it is allowed: is positive, so two lots are no more than three. For 3, 13 is at least 6, and 6 at least 4.
guess it, thenthe move: twice a power of 2
the line:why it is allowed: Two times is one more 2 multiplied. For 3, 2 × 2 is 4.
guess it, thenthe move: read it
the line:why it is allowed: Line 1 is the start. Lines 2 to 10 are the step, carrying the claim from each gap to the next. An at least passes along a step just as an equals does. So gap number 11 is at least 1,024. Shell sort uses only gaps smaller than the row, and the gaps only grow, so a row of 1,000 needs at most 10 gaps. It uses 6: 1, 4, 13, 40, 121 and 364.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
the move: check the first case
the line:number 2s multiplied log to base 2 1 none 0 2 2 1 4 2 × 2 2 8 2 × 2 × 2 3 16 2 × 2 × 2 × 2 4 The powers of 2 up to 16, each with its log. 13 sits between 8 and 16. why it is allowed: The log to base 2 of a number counts the 2s multiplied to make it, as the table shows. 13 lies between 8 and 16, so its log is between 3 and 4 (about 3.70), and rounded down, 3. The log of 1 is 0. This is the start.
the move: count the halvings
the line:why it is allowed: Let be that count, for from 2, since 1 is the start. For 13, the halvings go 6, 3, 1, so 3.
guess it, thenthe move: halve once
the line:13 halves, rounding down, to 6, 3 and 1. Each tick to the right doubles the number and adds 1 to its log. Under each, in blue, its log rounded down: 3, 2, 1 and 0, so each halving takes off 1. why it is allowed: The first halving gives , half of rounded down. The rest is the same job on that. For 13, one halving to 6, then 2 more.
guess it, thenthe move: suppose it holds for every smaller number
the line:half, rounded down halvings to 1 log rounded down 13 6 3 3 6 3 2 2 3 1 1 1 1 none 0 0 13, and below it the numbers line 4 supposes the claim for. In every row the two counts match. why it is allowed: The step. is a whole number from 1, and below . Suppose the claim holds for every number below , so for that one. For 13, 6 needs 2 halvings, its log rounded down.
guess it, thenthe move: halving takes 1 off the log
the line:13 lies between 8 and 16, and 6 between 4 and 8, one band lower, so its log rounded down is 1 less. why it is allowed: This is line 18 of question 2 of the page halving and logarithms; the fold at line 6 opens that proof, if you want it.
guess it, thenthe move: put line 5 in
the line:where does this come from?
question 2 of the page halving and logarithmsHalve , rounding down each time. How many halvings reach 1? the move: name the log rounded down
the line:Rounding down, 11 halves to 5, 2 and 1. In blue, each log rounded down: 3, 2, 1, 0, one less at each halving. why it is allowed: Here is the number halved, from 2 up; for 11, is 3.
the move: rounding down never adds
the line:why it is allowed: For 11, 3 is at most 3.46.
the move: rounding down takes off less than 1
the line:why it is allowed: For 11, 4 is above 3.46.
the move: raise 2 to each side of line 2
the line:why it is allowed: 2 raised to a bigger power gives a bigger number. For 11, 8 is at most about 11.
the move: 2 to the log of n is n
the line:why it is allowed: By what a log is. For 11, 8 is at most 11.
the move: raise 2 to each side of line 3
the line:why it is allowed: As in line 4. For 11, about 11 is below 16.
the move: 2 to the log of n is n
the line:why it is allowed: As in line 5. For 11, 11 is below 16.
the move: halve both sides of line 5
the line:why it is allowed: For 11, 4 is at most 5.5, which is not whole.
the move: write the half as a power
the line:why it is allowed: Half a power of 2 has one 2 fewer. Half of 8 is 4.
the move: round the half down
the line:why it is allowed: is the half rounded down, 5 for 11. A whole number at most 5.5 is at most 5. The left side, 4 for 11, is whole, as is at least 1 for from 2 up.
the move: halve both sides of line 7
the line:why it is allowed: For 11, 5.5 is below 8.
the move: write the half as a power
the line:why it is allowed: As in line 9. Half of 16 is 8.
the move: round the half down
the line:why it is allowed: Rounding down never adds. For 11, 5 is below 8.
the move: take the log of line 10
the line:why it is allowed: A bigger number has a bigger log. For 11, the log of 4 is at most the log of 5.
the move: the log of a power of 2 is the power
the line:why it is allowed: For 11, the log of 4 is 2, at most about 2.32.
the move: take the log of line 13
the line:why it is allowed: As in line 14. For 11, the log of 5 is below the log of 8.
the move: the log of a power of 2 is the power
the line:why it is allowed: For 11, about 2.32 is below 3.
the move: round the log down
the line:the number at least below its log rounded down 11 8 16 3 5 4 8 2 2 2 4 1 1 1 2 0 Each halving takes 1 off the log rounded down. why it is allowed: By lines 15 and 17, the log of the half is at least one less than and below , so it rounds down to one less. For 11, about 2.32 rounds down to 2.
the move: use line 18 again and again
the line:why it is allowed: While the log rounded down is 1 or more, the number is at least 2 to the power 1, which is 2. So line 18 takes 1 off each halving, down to 0 after . For 11, 3, 2, 1, 0.
the move: a log rounded down to 0 belongs to 1
the line:why it is allowed: Such a log is at least 0 and below 1, so its number is at least 1 and below 2. It is 1.
why it is allowed: Line 5 takes the place of the log of the half.
guess it, thenthe move: tidy
the line:why it is allowed: 1 less 1 is nothing. For 13, 3, as line 2 counts.
guess it, thenthe move: read it
the line:why it is allowed: Line 1 is the start. Lines 3 to 7 carry the claim to from a smaller number.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
a worked example
If each number is at least its left neighbour, then each is at least every number to its left. Try it on 2, 4, 4, 7, 9.
- The claim for each place: the number there is at least every number before it.
- The start, place 1: no number stands before it, so the claim holds. Place 2 is the step used once: 4 is at least 2.
- The step: the next number is at least its neighbour, and the neighbour is at least every number before it, by the claim. So the next number is at least them all.
- On 2, 4, 4, 7, 9: 7 is at least its neighbour 4, which is at least 4 and 2. So 7 is at least 4, 4 and 2.
- By the start and the step every place holds, so every pair is in order.
- Bubble sort walks the row, swapping neighbours out of order. A walk with no swap finds every pair it compares in order. The numbers past its end are already in place, as each earlier walk carried the biggest left to the end. So the whole row is in order, and bubble sort may stop.
| place | number | at least every number before it | pairs with those |
|---|---|---|---|
| 1 | 2 | nothing before it | 0 |
| 2 | 4 | 2 | 1 |
| 3 | 4 | 4, 2 | 2 |
| 4 | 7 | 4, 4, 2 | 3 |
| 5 | 9 | 7, 4, 4, 2 | 4 |
the trap
check yourself
1 + 2 + 4 and on up to 64 adds to 127. Take the step of question 1 once more. What does 1 + 2 + 4 and on up to 128 add to?
the answer
Add the next term to 127. 127 + 128 is 255, one less than 256, as question 1 says for as 7.
Shell sort's gap number 6 is 364. What does question 2 say it is at least?
the answer
2 to the power 5, which is 32. 364 is well above it.
Halve 150 again and again, rounding down. How many halvings reach 1?
the answer
75, 37, 18, 9, 4, 2, 1, so seven. 150 lies between 128 and 256, so its log rounded down is 7, as question 3 says.