Volume P1 · Proof, induction and invariants
Mathematical induction
Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.
Read first
The principle of induction
Statement
The natural numbers are , and every natural number is reached from by adding some number of times. Induction uses this fact. A property that holds for and passes from each number to the next holds for all of them.
Theorem P1.4.1 (the principle of induction). Let be a statement about the natural number . If is true, and for every natural number the statement is true, then is true for every natural number .
Lean: Nat.rec is the principle, the tactic induction n with | zero => ... | succ k ih => ... is the way to use it, and Nat.le_induction is the form with a base (Lean core and Mathlib).
The principle is an axiom of the natural numbers in most treatments (the axiom of Peano), and Chapter 5 shows that it is equivalent to the well-ordering principle. A proof by induction has three parts.
- The statement: say what is, in a sentence that does not use the proof.
- The base case: prove , or for the first number of the claim.
- The step: let be a natural number (with ) and assume , the induction hypothesis. Prove .
Definition P1.4.2 (the form with a base ). If is true, and for every , then is true for every . The form with base follows from the form with base applied to the statement .
Example P1.4.3 (the odd numbers). Claim: for , . Base: for both sides equal . Step: assume . Then . This is the claim for . For the sum is .
Example P1.4.4 (the sum of the first numbers). Claim: for , . Base: for both sides are . Step: assume the formula for . Then the sum up to is , which is the formula for .
Lean: Finset.sum_range_succ is the lemma that peels the last term of a sum over Finset.range; with induction n and simp [Finset.sum_range_succ] it is the usual route to such a formula.
Example P1.4.5 (the geometric sum). Claim: for and , . Base: gives . Step: the sum up to is . For and the sum is .
Example P1.4.6 (a divisibility). Claim: for , . Base: . Step: if , then .
Example P1.4.7 (an inequality with a base other than ). Claim: for , . Base: . Step: assume with . Then , and since for . So . The claim is false for (where , , ), so the base cannot be moved down to , and the inequality is true again for and .
Example P1.4.8 (Bernoulli's inequality). Claim: for a real and , . Base: . Step: . The first inequality multiplies the hypothesis by .
Proof
Proof of the principle from the definition of . Suppose and all hold, and suppose fails for some . The proof is by the well-ordering principle of Chapter 5: let be the least with false. Then , so for a natural number , and is true since . The step gives , a contradiction.
This proof uses the well-ordering principle, so it is not a proof from nothing. In a development from the axioms, one of the two is an axiom. Both are true, and each follows from the other (Chapter 5, Section 2).
The step of an induction is an implication, and the proof of an implication assumes the hypothesis. The induction hypothesis is assumed, not proved, in the step. This is not a circle: the proof of the step is valid for the general , and the base case makes it a chain, as a row of dominoes falls when the first one is pushed and each one pushes the next.
Examples
Example P1.4.9 (sum of cubes). Claim: for . Base: . Step: the sum up to is . The sum of the first cubes is the square of the sum of the first numbers. For : .
Example P1.4.10 (a divisibility by cases of the step). Claim: for , is divisible by . Base: . Step: , which is the sum of the number and the multiple of . A check of by a computer finds no failure.
Example P1.4.11 (a recurrence). Let and . Then . Base: . Step: . The sequence begins .
Pitfalls
An induction proof can fail in four places, and each gives a false proof of a false claim or an incomplete proof of a true one.
A missing base case. Let be " is even". The step is true: is even if is. But is false, since is odd, and the claim is false for every , since is even and is odd. The step alone proves nothing.
A step that fails at the first value. The claim "all horses have the same color" of Chapter 3 has a step that fails from to . The step must hold for every , including the smallest.
A hypothesis that is used for the wrong . The step may use and not . A proof of that uses is a circle.
A claim with an unbound variable. In " is even for ", the statement is about one . A claim with two variables, such as " for all and ", needs a decision: the induction runs over one of them, and the other is held fixed.
Exercises
- [10] Prove by induction that for , and use it to find .
- [10] Prove that for .
- [12] Prove that for and that for .
- [12] Prove that for , and use it to find the number of nodes in a complete binary tree with levels (levels to ).
- [14] Prove that for , and that for .
- [15] Prove that for .
- [M18] Prove that for .
- [M20] Prove that for and that for by induction on .
- [M20] Prove Bernoulli's inequality for real and , and show that the condition cannot be dropped.
- [M24] Find the error in this proof of " for all ": base ; step , "which is less than ". Find the first for which the claim fails.
Lean
The tactic induction n with | zero => _ | succ k ih => _ gives the base goal and the step goal with the hypothesis ih. For a base other than , Nat.le_induction gives goals for n = a and for n + 1 with a ≤ n. A sum over Finset.range n obeys Finset.sum_range_succ, which splits off the last term, and simp [Finset.sum_range_succ] followed by ring closes many formulas of this section.
Notes and history
The method is old: it has forms in Pascal's treatise of 1654 on the arithmetic triangle, and in the work of Fermat on the method of descent, and the name mathematical induction is due to De Morgan in the nineteenth century. The axioms of Peano of 1889 take the principle as one of the axioms. TAOCP Section 1.2.1 states the principle and uses it for the first formulas of that section; the step from the formula to its proof is the part this chapter trains, and the next section shows what to do when the formula must first be found.
Stronger claims and recurrences
Statement
The step of an induction must prove from alone. Sometimes says too little for this, and the claim cannot be proved as it stands. A remedy that seems wrong at first is to prove more: a stronger claim with has a stronger hypothesis in the step, and the step may then go through.
Definition P1.4.12 (a stronger claim). A statement is stronger than if for every . A proof of for all proves for all .
Example (the sum of ). Claim : . A step from to would need from , and the last term may take the sum over for all that the hypothesis says. The stronger claim : the sum equals . Base: . Step: the sum up to is . Then gives , since .
Example P1.4.13 (the sum of ). Claim : . The stronger claim : the sum is at most . Base: . Step: , since . For the sum is about , below .
The two examples show a rule of thumb. The hypothesis must carry exactly the information that the step needs, and it is often a statement of how much below the bound the sum is. The right is found by examining what the step lacks, or by computing the first values and guessing the formula.
Definition P1.4.14 (the Fibonacci numbers). The Fibonacci numbers are , and for . The first values are .
Lean: Nat.fib with Nat.fib_add_two : fib (n + 2) = fib n + fib (n + 1) (Mathlib).
Definition P1.4.15 (induction with two base cases). If a statement is derived from and , the proof needs the base cases and , and the step: let , assume and , and prove . This is the principle of induction applied to the statement .
Example P1.4.16 (a bound for ). Claim: for . Base cases: and . Step: . For : , much smaller than . A better bound is next.
Theorem P1.4.17 (bounds for ). Let , so that . Then for .
Lean: the proof is a statement about Nat.fib and real powers; the key step is the identity , which nlinarith or ring_nf reaches after Real.sq_sqrt.
Proof. Base cases and : , and , true since . Step: let and assume both bounds for and for . Then . The lower bound is the same with the inequalities reversed: .
A two-step recurrence usually needs this double hypothesis. A proof that assumes only in the step has no information about and fails.
Example P1.4.18 (a sum of Fibonacci numbers). Claim: for . Base: . Step: the sum up to is . For the sum is .
Example P1.4.19 (a sum of squares). Claim: for . Base: . Step: .
Theorem P1.4.20 (a formula for a recurrence). Let , , and . Then for .
Proof. Base: and . Step: assume and . Then .
Proof
To use a stronger claim, follow these steps. First, write the step as a table: what is known (the hypothesis) and what is to be shown. Second, find what is missing: an inequality with a gap that is lost in the step, or a value of an expression that is not determined. Third, add this to the claim, and prove the new claim from the start with its own base case. The new base case may be harder, and the new step is easier.
The stronger claim often holds for a whole family of quantities, such as the three values , and in the last example below, and gives the step the information that it needs.
Examples
Example P1.4.21 (a closed form found by computation). Let , , . The values are . They are close to : the guess is . Base: and . Step: , and , so this is the guess for . A computer check of the first twenty values agrees.
Example P1.4.22 (the identity of Cassini). Claim: for . Base: . Step: . For : .
Example P1.4.23 (every third Fibonacci number is even). Claim: is even for . The recurrence relates to and , not to , so the hypothesis " is even" alone does not give the step. The stronger claim : is even, and and are odd. Base: . Step: is odd plus odd, so even; is even plus odd, so odd; is odd plus even, so odd. The values are .
Exercises
- [10] Compute and , and check against Cassini's identity.
- [12] Prove that for , and find the value for .
- [14] Prove that for .
- [14] Prove that for .
- [15] Prove the sharper bound for .
- [M18] Let , and . Find by computing four values and guessing, then prove it.
- [M20] Prove Cassini's identity for , and use it to show that consecutive Fibonacci numbers have no common divisor larger than .
- [M20] Prove that for and , by induction on .
- [M22] Prove that for , and explain why the claim "the sum is less than " cannot be proved by induction as it stands.
- [M25] Prove that is even for with a stronger claim. Prove that , and use it to show that for .
Lean
Nat.fib is the function, Nat.fib_add_two is the recurrence, and Nat.fib_pos gives positivity. A proof of a statement about Nat.fib by two-step induction can use Nat.twoStepInduction, which gives the two base cases and the double hypothesis. The shape of its arguments has changed between versions of Mathlib, so check it in the version that you use.
Notes and history
The sequence is from the Liber abaci of Leonardo of Pisa (1202), in a problem on rabbits, and the name Fibonacci was given in the nineteenth century. Cassini's identity is from 1680. TAOCP treats the Fibonacci numbers in Section 1.2.8, and the proofs by induction of that section have the form of this one. The bound of the theorem is a step toward the closed form of Section 1.2.8.
Induction on other quantities
Statement
The index of the principle is a natural number, but the natural number need not be an index in the statement. A claim about finite sets can be proved by induction on the number of elements, a claim about boards by induction on the side, and a claim about a loop by induction on the number of passes. The method is the same: choose a size that is a natural number, prove the claim for the smallest size, and prove it for size from size .
Definition P1.4.24 (induction on a size). Let be a class of objects, each with a size . To prove that every object of has a property, prove for each the statement : every object of size has the property. The proof by induction on has a base case, usually or , and a step that builds an object of size from one of size , or takes one apart.
A step that takes an object of size apart and applies the hypothesis to a smaller piece is correct only if every object of size has such a piece. The proof must say why.
Example P1.4.25 (the number of subsets). Claim: a set with elements has subsets. Base: the empty set has one subset, itself, and . Step: let have elements and choose . The subsets of are of two kinds, those that do not contain and those that do. The first kind are the subsets of , which has elements, so there are of them. The second kind correspond one-to-one with the first kind: a subset that contains goes to . So there are of them too, and in all. For a computer count gives .
Lean: Finset.card_powerset : (Finset.powerset s).card = 2 ^ s.card (Mathlib).
Example P1.4.26 (the handshakes). Claim: among people, if each two shake hands once, there are handshakes. Base: has . Step: add a person to a group of . The new person shakes hands with each of the , so there are new handshakes, and . For the count is , and for it is .
Example P1.4.27 (the regions of the plane). Claim: lines in the plane, no two parallel and no three through a point, divide the plane into regions. Base: gives region. Step: add a line to lines. The line meets each of the lines in a point, and these points are different, since no three lines are concurrent. They divide into pieces, and each piece divides a region of the old picture in two. So the number of regions grows by : . The numbers for are .
Theorem P1.4.28 (tiling). For every , a square board of side with one cell removed can be covered without overlap by L-shaped pieces of three cells. The number of pieces is .
Proof. Base: . The board has one cell, which is removed, and no piece is needed. Step: take a board of side with one cell removed. Cut it into four boards of side . One quarter contains the removed cell. Place one L-piece at the center of the board so that it covers one cell of each of the three other quarters, the cell next to the center. Now each quarter is a board of side with one cell removed (the removed cell or the cell of the piece). By the hypothesis each can be tiled. The number of pieces is .
The counting formula is a check, since is divisible by (Section 1). The side cannot be replaced by any side: for the side , the board has cells after the removal, which is not a multiple of , and for the side the board has cells, but a computer search finds that only of the cells give a tileable board.
Definition P1.4.29 (a loop's passes). A pass of a loop is one execution of its body. A claim about the state after passes is proved by induction on : the base is the state before the first pass, and the step shows that one more pass takes a state with the property to a state with the property.
Example P1.4.30 (the loop for the squares). Consider the loop, with , at the start, whose body is: ; . Claim: after passes, and . Base: , , . Step: if and before a pass, then after it and . After passes and . The loop gives the squares by additions only, and it is the loop form of the first example of Section 1.
Example P1.4.31 (the product by additions). Let a loop start with , , and let its body be ; , repeated while . Claim: after passes and . The proof is the same. When the loop stops, , so . This is the first instance of the method of invariants of Chapter 8: a statement that holds after every pass, and with the exit test gives the result.
Proof
For an induction on a size, the data of the proof are the class, the size and the decomposition. The decomposition is the step. In the examples above it is: remove an element of a set, remove a person from a group, remove a line, cut a board in four, or take one pass of a loop. A decomposition must be total: every object of size must have it. For the lines it is the removal of any line, and the picture of the remaining lines still satisfies the assumptions (no two parallel, no three concurrent). For the board it is the cutting in four equal parts, which needs the side to be even.
A mistake in the choice of the class is the usual source of false proofs. A proof for lines that adds a line to a picture of lines must be sure that every picture of lines can be obtained in this way, and the order in which the lines are added must not matter.
Examples
Example P1.4.32 (a false proof: all points are on one line). Claim: any points in the plane lie on one line. Base: and are true. Step: take points, with the hypothesis for . The first lie on a line and the last lie on a line . The two lines share points, so they are equal if , and all the points are on one line. The error is at , with three points: the two lines share only one point, so they need not be equal. The proof has a gap at the first step beyond the base , and the claim is false for three points that are not collinear.
Example P1.4.33 (the colored map). Claim: the regions into which lines divide the plane can be colored with two colors so that regions that share a side have different colors. Base: no line, one region. Step: add a line to a picture that is colored. Reverse all the colors on one side of . A side that lies on now separates regions of different colors (they had the same color before, as they were one region), and a side not on separates two regions on the same side of , whose colors were different and are still different (both reversed or both kept).
Example P1.4.34 (the sum of the digits). Claim: a number written in base is congruent to the sum of its digits modulo . Take the size to be the number of digits . Base: a number of one digit is its own digit sum. Step: a number with digits has the form with of digits and a digit. Since , , and is congruent to its digit sum. For : and .
Exercises
- [10] Prove by induction on that a set with elements has subsets, and find the number of subsets of that have an even number of elements.
- [12] Prove that among people there are pairs, by induction on , and find the number of diagonals of a convex polygon with sides, .
- [14] Run by hand the loop of the example for the squares for passes and give and after each pass.
- [15] A loop starts with and does in each pass. Prove that after passes . Change the body to and prove again.
- [15] Prove that lines in general position divide the plane into regions, and find the greatest number of regions for lines.
- [M18] Prove that the number of integers of digits in base (the first digit not ) is for , by induction on .
- [M20] Prove that every number of digits in base is congruent modulo to its digit sum. Use it to show that , and to find the remainder of modulo .
- [M22] Prove that a knockout tournament of players ends with exactly matches, by induction on (each match removes one player).
- [M24] Show that the tiling theorem does not hold for a board with one cell removed of side or , by counting cells. Describe the placement of the five pieces that tile a board of side with one corner cell removed.
- [M25] Find the error in the following proof that every set of people have the same age: base ; step: remove one person, apply the hypothesis; remove another person, apply it; the two groups of share people, so all have the same age. At which does the step fail?
Lean
For a claim about a finite set, Finset.induction_on is the principle on the number of elements: it gives the case of the empty set and the case of insert a s with a ∉ s. The statement Finset.card_powerset gives the number of subsets, and Finset.card_insert_of_not_mem gives the size of an insertion (the name has changed to Finset.card_insert_of_notMem in recent versions; check which one your version has). The tiling theorem is a statement that the project does not formalize.
Notes and history
The count of regions of the plane by lines is the first case of a family of results in the geometry of arrangements, and the tiling by L-pieces of a board with one cell removed is due to Golomb (1954), who used the problem to show how a proof by induction can give a construction. The false proof that all people have the same age is a variant of the horses of Chapter 3. Chapter 8 returns to the induction on the number of passes of a loop, which is the form that TAOCP Section 1.2.1 uses for its proofs of algorithms.
Induction is the method of proof for a statement about every natural number. It is the one method that a reader of Section 1.2.1 of TAOCP must have under control, because that section, and most of Chapter 1 of Volume 1 after it, proves its formulas by this method.
Section 1 states the principle in its forms for a base , a base and a general base, gives the pattern of an induction proof (statement, base, step), and works the first examples: sums, divisibility and inequalities. It ends with the usual errors. Section 2 treats the case where the claim as stated is too weak for the step and must be made stronger, with the Fibonacci numbers as the main example, and the proof of a formula for a recurrence. Section 3 treats induction on a quantity other than an index: the size of a finite set, the size of a board, the number of lines, and the number of passes of a loop.
The chapter assumes Chapters 1 to 3. The spine texts are Velleman, How to Prove It, Chapter 6, and Lehman, Leighton and Meyer, Mathematics for Computer Science, Chapter 6. Chapter 5 goes on to strong induction and well ordering, and Chapter 8 turns the method of a loop's passes of Section 3 into the method of invariants.
The source of this page. Something is wrong? Report it.