Module contents
Lesson 5 of 22Core 90 min

Mathematical induction and the well-ordering principle

The three forms of induction (weak, strong and well-ordering), their equivalence, and the art of strengthening the hypothesis, exactly as when finding a loop invariant. A constructive inductive proof is a recursive algorithm.

After this lesson you can

  • Write weak and strong induction proofs with correct base cases
  • Prove the equivalence between induction and the well-ordering principle
  • Strengthen the induction hypothesis when the original statement is not inductive
  • Extract the recursive algorithm implicit in a constructive inductive proof
  • Identify typical mistakes in inductive proofs

Before you start

Motivation: a million cases are not a proof

Almost everything you program has the form “do something with the small case and combine it.” Mergesort sorts each half and merges them; binary search discards half the interval and starts again; a for loop updates an accumulator once per element. The question “is it correct?” always has the same structure: if the algorithm works on the smallest inputs, does it work on this one? Answering for all inputs requires an argument covering infinitely many cases in finitely many steps. That argument is induction, and without it there is no correctness proof for a recursive or iterative algorithm (you will see it in divide-and-conquer correctness and loop invariants).

Testing many cases does not suffice. Euler observed that n2+n+41n^2 + n + 41 is prime for n=0,1,…,39n = 0, 1, \dots, 39: forty consecutive cases. At n=40n = 40 it is 1681=4121681 = 41^2. Worse, Pólya conjectured in 1919 that, for every N≥2N \ge 2, at least half the integers from 11 to NN have an odd number of prime factors (counted with multiplicity). It was checked for decades; in 1958 Haselgrove proved it false without giving a counterexample, and in 1980 Tanaka found the smallest: N=906 150 257N = 906\,150\,257. No test suite would have gone so far. As you saw with refutation by counterexample, one failing case suffices to bring down a universal statement; now we need the opposite, a way to establish it without examining every case.

This lesson presents induction in three forms (weak, strong and the well-ordering principle), proves their equivalence and focuses on the genuinely difficult part: what to do when the claim you want to prove is not inductive and must be strengthened, exactly what you do when searching for a loop invariant. Along the way you will see that a constructive inductive proof is literally a recursive program.

Intuition: dominoes pushing one another

Imagine an infinite row of dominoes, one for each natural number. Domino nn represents the statement P(n)P(n), and “fallen” means “proved.” To topple them all, two things suffice: push the first (the base case) and ensure that each domino, upon falling, knocks down the next (the inductive step). Neither suffices alone, and the second has a subtlety: it does not say the dominoes fall, but that if one falls, the next falls.

InteractiveDominoes falling or stopping
P(0)P(1)P(2)P(3)P(4)P(5)P(6)P(7)P(8)P(9)P(10)P(11)P(12)P(13)
  • fallen domino: P(n)P(n) proved
  • step P(n)⇒P(n+1)P(n) \Rightarrow P(n+1) proved
  • unproved step
Scenario
t = 14
Falling dominoes9, from P(0) to P(8)
First unproved caseP(9)
The chain stops at P(8)P(8): there is no proof of P(9)P(9) or any subsequent case, even if it may be true. Checking many cases is not enough either: n2+n+41n^2 + n + 41 is prime for 0≤n≤390 \le n \le 39 and composite for n=40n = 40.
Each domino is a case P(n)P(n) and each aqua arc a proved step P(n)⇒P(n+1)P(n) \Rightarrow P(n+1). Play the fall: the chain stops at the first broken step. Click gaps to break or repair steps and disable the base case: does anything fall? Then switch to 2n>n22^n > n^2, where the step is proved only for n≥3n \ge 3 and the statement is false at n=2,3,4n = 2, 3, 4: find the smallest base case n0n_0 from which all dominoes fall.

The 2n>n22^n > n^2 scenario teaches the figure’s most useful lesson. The statement is true at n=0n = 0 and n=1n = 1 (1>01 > 0, 2>12 > 1), false at n=2,3,4n = 2, 3, 4 (4=44 = 4, 8<98 < 9, 16=1616 = 16) and true from n=5n = 5 onward. The step argument, which we will give shortly, works only for n≥3n \ge 3. With base case n0=0n_0 = 0 the first domino falls, but the first link is unproved; with n0=3n_0 = 3 the links are there, but the first domino does not stand. The whole chain needs both at once, first achieved at n0=5n_0 = 5.

Weak induction

Let us state the principle precisely. A predicate over the naturals is a formula P(n)P(n) with a free variable n∈N={0,1,2,… }n \in \N = \{0, 1, 2, \dots\}.

This scheme is weak induction or ordinary induction. Pay attention to each quantifier, where errors arise (review the quantifier laws if needed). The step does not assert ∀n P(n)\forall n\, P(n), which is what we want to prove. It asserts ∀n (P(n)⇒P(n+1))\forall n\,(P(n) \Rightarrow P(n+1)), and is proved like any universal: fix an arbitrary nn, assume P(n)P(n) (the induction hypothesis) and deduce P(n+1)P(n+1) with a direct proof. Assuming P(n)P(n) is not cheating: it is the premise of an implication.

Two immediate variants are used constantly. If the claim begins at n0n_0 instead of 0, the base is P(n0)P(n_0) and the step is proved for every n≥n0n \ge n_0; apply the principle to Q(m)=P(n0+m)Q(m) = P(n_0 + m). The principle is not a trick to justify every time: in Peano arithmetic it is an axiom (a schema, one per predicate), and in set theory a theorem, because N\N is defined as the smallest set containing 0 and closed under successor. Below we see it is equivalent to another property, well-ordering, which is often more intuitive.

The template

A well-written induction proof always has five parts, all worth writing even when they seem obvious:

  1. Statement P(n)P(n), with explicit induction variable and range (n≥n0n \ge n_0).
  2. Base case: check P(n0)P(n_0).
  3. Induction hypothesis: “let n≥n0n \ge n_0 and assume P(n)P(n).”
  4. Step: deduce P(n+1)P(n+1), identifying where the hypothesis is used. If unused, the proof is not inductive (and probably wrong).
  5. Conclusion: by induction, P(n)P(n) for every n≥n0n \ge n_0.

The proof has a geometric reading: an n×nn \times n square of points becomes an (n+1)×(n+1)(n+1)\times(n+1) square by adding an L-shaped border of 2n+12n + 1 points. The inductive step is exactly that addition.

The assumption x≥−1x \ge -1 is used in one place, when multiplying (the last step needs only nx2≥0nx^2 \ge 0), and without it the result is false: with x=−3x = -3 and n=5n = 5, (1+x)5=−32<−14=1+5x(1 + x)^5 = -32 < -14 = 1 + 5x. Finding where each assumption enters distinguishes a proof you understand from one you copied. This inequality returns in sequence limits: for example, it gives an→∞a^n \to \infty if a>1a > 1, because an=(1+(a−1))n≥1+n(a−1)a^n = (1 + (a - 1))^n \ge 1 + n(a-1).

Notice the order: first the step, to find from which nn it works, then the base case, which must lie within that range. This is what you did with the figure.

Strong induction

Sometimes P(n+1)P(n+1) follows not from P(n)P(n) but from earlier, more distant cases. When factoring n=a⋅bn = a\cdot b, the factors aa and bb may be any pair smaller than nn; knowing that n−1n - 1 is a product of primes does not help.

This is strong induction or complete induction: in the step you may assume all earlier cases, not only the immediately preceding one. Formally there is no separate base case. For n=0n = 0 the hypothesis “∀k<0, P(k)\forall k < 0,\ P(k)” is empty, so the step requires proving P(0)P(0) without help. In practice the step splits into cases: small values of nn with nothing earlier to use (the base cases, possibly several) and the general case.

Proof

It follows from weak induction by a trick that will recur: prove something stronger. Let Q(n)Q(n) be “P(k)P(k) for every k<nk < n.” Q(0)Q(0) holds vacuously. If Q(n)Q(n) holds, the theorem’s hypothesis gives P(n)P(n), and since k<n+1k < n+1 means k<nk < n or k=nk = n, we have Q(n+1)Q(n+1). By weak induction Q(n)Q(n) holds for all nn; in particular Q(n+1)Q(n+1) gives P(n)P(n).

∎

Notice that the case “nn prime” acts as a base case, although it does not occur only at the beginning: 2,3,5,7,…2, 3, 5, 7, \dots are proved without the hypothesis. Uniqueness of factorization is more delicate and you will handle it in the exercises using well-ordering.

Several base cases: the postage-stamp problem

You have only 4-cent and 7-cent stamps. Which amounts can you pay exactly? A little trial shows 1717 cannot be paid (neither 1717, nor 17−7=1017 - 7 = 10, nor 17−14=317 - 14 = 3 is a multiple of 4), but 18=4+7+718 = 4 + 7 + 7, 19=4⋅3+719 = 4\cdot 3 + 7, 20=4⋅520 = 4\cdot 5 and 21=7⋅321 = 7\cdot 3.

Statement. Every n≥18n \ge 18 can be paid with 4- and 7-cent stamps.

Proof. By strong induction. The cases n=18,19,20,21n = 18, 19, 20, 21 are the four above. If n≥22n \ge 22, then n−4≥18n - 4 \ge 18 and by hypothesis n−4n - 4 can be paid; adding a 4-cent stamp pays nn.

Why four base cases? The step uses P(n−4)P(n - 4), and for n−4n - 4 to lie in the proved range we need n≥22n \ge 22. The four values 18,…,2118, \dots, 21 have no earlier case to appeal to within the range and must be done by hand. With one base case the proof would show P(18),P(22),P(26),…P(18), P(22), P(26), \dots and nothing more.

InteractiveStamps and strong induction
012345678910111213141516171819202122232425262728293031remainder 0remainder 1remainder 2remainder 3
  • base case
  • proved by the step
  • first payable in its column (multiple of 7)
4 c
7 c
Largest impossible amount17 = 4·7 − 4 − 7
Base cases18, 19, 20, 21
Payment30 = 4·4 + 7·2
Chain30 ← 26 ← 22 ← 18
Each column is a residue class modulo 4. Its first payable cell is a multiple of 7 (magenta dot); from there, adding a stamp of 4 moves down one row. The largest impossible amount is just above the latest multiple of 7, 7⋅3=217\cdot3 = 21.
Amounts are arranged in rows with as many cells as the value of the smaller stamp, so the inductive step P(n−p)⇒P(n)P(n - p) \Rightarrow P(n) is ‘the cell above’. Crossed-out amounts cannot be paid. Click an amount to see the proof chain back to a base case. Notice how each column (amounts with the same remainder modulo pp) becomes payable as soon as a multiple of the larger stamp appears. Try other pairs: what formula gives the largest impossible amount? What happens with 4 and 6?

The figure suggests the general proof. With stamps p<qp < q and gcd⁡(p,q)=1\gcd(p, q) = 1, the multiples 0,q,2q,…,(p−1)q0, q, 2q, \dots, (p-1)q have distinct remainders modulo pp (if iq≡jqiq \equiv jq, then pp divides (i−j)q(i - j)q and, since it shares no factor with qq, divides i−ji - j). Thus each column becomes payable at one of them and remains so thereafter. The last starts at (p−1)q(p-1)q, and the amount just above, (p−1)q−p=pq−p−q(p-1)q - p = pq - p - q, is the largest impossible one. This is a result of J. J. Sylvester (1884). The general case, finding the largest impossible amount with kk stamps that are collectively coprime, is the Frobenius problem, and for three or more stamps has no general closed formula (F. Curtis proved in 1990 that none of polynomial type can exist).

The well-ordering principle

There is a third way to say the same thing without mentioning steps or hypotheses.

This is the well-ordering principle. It seems trivial, but depends entirely on the structure of N\N. It fails in Z\Z (the negative integers have no least element), in Q≥0\Q_{\ge 0} (the set {1/n:n≥1}\{1/n : n \ge 1\} has no minimum), and in R≥0\R_{\ge 0} (nor does the interval (0,1)(0, 1)). What makes N\N special is the absence of infinite strictly decreasing sequences: from any nn one can descend only finitely many times. That idea, Fermat’s infinite descent, guarantees that a loop terminates when its variant function is a natural number decreasing on each iteration.

Proof

(1) ⇒ (2) is the strong induction proof you have seen. Two implications remain.

(3) ⇒ (1). Assume P(0)P(0) and ∀n (P(n)⇒P(n+1))\forall n\,(P(n) \Rightarrow P(n+1)), and suppose, for contradiction, that the set of counterexamples C={n∈N:¬P(n)}C = \{n \in \N : \neg P(n)\} is nonempty. By well-ordering it has a least element mm. It cannot be m=0m = 0, since P(0)P(0) is true; thus m=k+1m = k + 1 for some kk. Since k<mk < m and mm is the least counterexample, P(k)P(k) is true, and the step gives P(k+1)=P(m)P(k + 1) = P(m). Contradiction.

(2) ⇒ (3). By contraposition: let A⊆NA \subseteq \N have no least element and show A=∅A = \varnothing. Let P(n)P(n) be “n∉An \notin A.” Assume P(k)P(k) holds for every k<nk < n, meaning no number smaller than nn is in AA. If nn were in AA, it would be its least element, which does not exist; hence n∉An \notin A, which is P(n)P(n). By strong induction no nn is in AA.

∎

“Equivalent” has a precise meaning here: each principle follows from either other one plus the basic properties in the statement, which do not imply any of the three by themselves. There is no sense asking which is “the true one”; each is more convenient for a type of proof. Induction builds upward; well-ordering reasons about the first failure.

Minimal-counterexample proofs

The proof of (3) ⇒ (1) is a method in itself. To prove ∀n P(n)\forall n\, P(n):

  1. Assume there are counterexamples and take the least, mm (the minimal counterexample).
  2. Use the fact that P(k)P(k) holds for every k<mk < m to construct a counterexample smaller than mm (or reach another contradiction).

This is strong induction written backward, and often the most natural form when the argument “descends” from one case to a smaller one.

This is the same argument as in the previous lesson, but well-ordering makes explicit why descent cannot continue forever. Another application needed in the exercises: every n≥2n \ge 2 has a prime divisor. Otherwise let mm be the least counterexample. mm is not prime (it would be its own prime divisor), so m=abm = ab with 1<a<m1 < a < m; by minimality aa has a prime divisor, which also divides mm. Contradiction.

Strengthening the hypothesis

Until now the statement could be proved as given. The lesson’s most important phenomenon is that often it cannot, even when true.

Start with a minimal example. Statement: the sum of the first nn odd numbers is a perfect square. Try the step: you know 1+3+⋯+(2n−1)1 + 3 + \cdots + (2n - 1) is some square m2m^2 and want m2+2n+1m^2 + 2n + 1 to be a square. Without knowing mm, you cannot: m2+2n+1m^2 + 2n + 1 with m=3m = 3 and n=2n = 2 is 1414. The hypothesis is too weak to feed the step. The solution is to prove something stronger, that the sum is exactly n2n^2, and then the step works, as you saw. The paradox is only apparent: strengthening the statement also strengthens the induction hypothesis used in the step. Pólya called this the inventor’s paradox: the more ambitious plan may be more likely to succeed.

We must clarify what “cannot” means, because logic has a trap. If P(n)P(n) holds for all nn, the implication P(n)⇒P(n+1)P(n) \Rightarrow P(n+1) is true outright, because its conclusion is true. What fails is not the implication, but the possibility of deducing it knowing only what P(n)P(n) says about nn, the situation of the person proving it. In the case most relevant here, a recursively defined quantity (a partial sum, a loop state), this is formalized by separating value from property.

“Every value xx,” not just the actual value xnx_n, makes the notion demanding. In the odd-number example, xn=1+3+⋯+(2n−1)x_n = 1 + 3 + \cdots + (2n-1) and f(n,x)=x+2n+1f(n, x) = x + 2n + 1. The property “xx is a square” is not inductive (the earlier 1414: n=2n = 2, x=9x = 9), although it holds for every xnx_n; “x=n2x = n^2” is inductive and implies the first.

That move is strengthening the induction hypothesis. A series is the canonical example.

Why ∑1/k2<2\sum 1/k^2 < 2 is not inductive

Let S(n)=∑k=1n1/k2S(n) = \sum_{k=1}^{n} 1/k^2. We want to show S(n)<2S(n) < 2 for every n≥1n \ge 1. It is true (the limit is π2/6≈1.645\pi^2/6 \approx 1.645), yet the direct step is impossible. If all you know is S(n)<2S(n) < 2, then

S(n+1)=S(n)+1(n+1)2<2+1(n+1)2,S(n+1) = S(n) + \frac{1}{(n+1)^2} < 2 + \frac{1}{(n+1)^2},

which is not <2< 2. The problem is not algebraic skill: the hypothesis allows S(n)S(n) arbitrarily close to 2, and then any positive term pushes it over. In the definition’s language, f(n,x)=x+1(n+1)2f(n, x) = x + \frac{1}{(n+1)^2} and x<2x < 2 is not inductive: with n=1n = 1 and x=1.9x = 1.9 we get 2.152.15. We need to know how much margin remains.

Proof

Base: S(1)=1=2−1/1S(1) = 1 = 2 - 1/1. Step: assume S(n)≤2−1/nS(n) \le 2 - 1/n. Then

S(n+1)≤2−1n+1(n+1)2,S(n+1) \le 2 - \frac{1}{n} + \frac{1}{(n+1)^2},

and this is ≤2−1n+1\le 2 - \frac{1}{n+1} if and only if 1(n+1)2≤1n−1n+1=1n(n+1)\frac{1}{(n+1)^2} \le \frac{1}{n} - \frac{1}{n+1} = \frac{1}{n(n+1)}, which holds because n(n+1)<(n+1)2n(n+1) < (n+1)^2.

∎

The strengthened claim says more (it gives a bound improving with nn), and precisely for that reason is provable: the hypothesis supplies a cushion of 1/n1/n, of which the step spends only part. Since S(n)S(n) is increasing and bounded, the bound also proves the series converges (by completeness of the reals), without calculating its sum.

How do we find such a bound? Regard the step as a budget. If the hypothesis is S(n)≤B(n)S(n) \le B(n), the step closes using only the hypothesis if the bound rises at least as much as the sum:

B(n+1)−B(n) ≥ 1(n+1)2.B(n+1) - B(n) \ \ge\ \frac{1}{(n+1)^2}.

With B(n)=2B(n) = 2 the bound does not rise and the step always fails. With B(n)=2−c/nB(n) = 2 - c/n it rises by c/(n(n+1))c/(n(n+1)), and the condition becomes c(n+1)≥nc(n+1) \ge n for every nn, that is, c≥1c \ge 1. But the base case S(1)=1≤2−cS(1) = 1 \le 2 - c requires c≤1c \le 1. The value c=1c = 1 is the only one that works with base n=1n = 1: the bound was not found by inspiration, but by solving both constraints.

InteractiveStrengthened-hypothesis lab
What is true: S(n) and the bound B(n)1.001.251.501.752.00π²/6 ≈ 1.645baseThe step: increase in bound / new term 1/(n+1)²012151015202530n
  • S(n)=∑k≤n1/k2S(n) = \sum_{k \le n} 1/k^2
  • candidate bound B(n)B(n)
  • step closes
  • step open
Candidate hypothesis
1
H(n): S(n)<2H(n):\ S(n) < 2
Base caseS(1) = 1.000 < 2
Inductive stepfails at n = 1
Step margin (increase in the bound minus the new term):
−1(n+1)2<0-\frac{1}{(n+1)^2} < 0
The hypothesis S(n)<2S(n) < 2 allows S(n)S(n) to be arbitrarily close to 2, so adding 1(n+1)2\frac{1}{(n+1)^2} may exceed 2. The step does not close for any nn, even though the statement is true.
Above, what is true: partial sums S(n)S(n) and candidate bound B(n)B(n). Below, the step as a budget: each bar is (B(n+1)−B(n)) / 1(n+1)2\big(B(n+1) - B(n)\big)\,/\,\frac{1}{(n+1)^2}, the bound's increase divided by the new term. The step closes where the bar reaches the dashed line at 1. Start with the original hypothesis and notice all bars are zero. Switch to 2−c/n2 - c/n and lower cc below 1: the step begins to fail at progressively smaller nn. Raise it above 1: the base case fails unless delayed. Finally, with a−1n+1/2a - \frac{1}{n + 1/2}, find the smallest aa that works with n0=1n_0 = 1 and see how close it gets to π2/6\pi^2/6 by delaying the base.

The lab’s third family shows there is room for refinement. Since (n+12)(n+32)=(n+1)2−14<(n+1)2(n + \tfrac12)(n + \tfrac32) = (n+1)^2 - \tfrac14 < (n+1)^2, we have 1(n+1)2<1n+1/2−1n+3/2\frac{1}{(n+1)^2} < \frac{1}{n + 1/2} - \frac{1}{n + 3/2}, so B(n)=a−1n+1/2B(n) = a - \frac{1}{n + 1/2} closes the step for any aa, with margin. The base case S(1)=1≤a−23S(1) = 1 \le a - \tfrac{2}{3} gives a≥5/3a \ge 5/3: a five-line induction proof establishes ∑1/k2<5/3≈1.667\sum 1/k^2 < 5/3 \approx 1.667, only 0.0220.022 from the exact value. Delaying the base to n0=4n_0 = 4 (and checking n≤3n \le 3 by hand) gives a=S(4)+14.5≈1.6458a = S(4) + \tfrac{1}{4.5} \approx 1.6458, with three correct digits of π2/6\pi^2/6.

The same move in a program

Consider a loop computing S(n)S(n) and the assertion to verify at the end:

s = 0.0
for k in range(1, n + 1):
    s += 1 / k**2
    assert s < 2          # cierto, pero no se puede demostrar iteración a iteración

A checker (or you, reasoning) can use at each iteration only what it knows from the previous one. Knowing s < 2 does not guarantee s + 1/(k+1)**2 < 2. What is preserved is s <= 2 - 1/k: a loop invariant, a property true on entry and preserved by every iteration. An invariant is, word for word, an induction hypothesis over the number of iterations, and almost never matches the desired postcondition: it must be strengthened. Finding invariants is the creative part of loop verification in lesson 8, and tools such as Dafny or proof assistants ask for exactly that: an inductive invariant, not merely a true one.

Induction as recursion

A 2n×2n2^n \times 2^n board missing one square has 4n−14^n - 1 squares, a multiple of 3 (because 4≡14 \equiv 1 modulo 3). Can it always be covered without overlaps by L-trominoes, three-square pieces occupying a 2×22\times 2 block minus one corner? Whatever square is missing, yes, and the proof (Solomon Golomb, 1954) is as short as a program.

Proof

Induct on nn. Base, n=0n = 0: the board is one square, hh; what remains is empty and is tiled by the empty set of pieces.

Step: assume the result for 2n×2n2^n \times 2^n with any hole, and take a 2n+1×2n+12^{n+1}\times 2^{n+1} board without square hh. Divide it into four 2n×2n2^n \times 2^n quadrants. One contains hh. Place a tromino at the board’s center covering, in each of the other three quadrants, the square touching the board’s center (the four squares around the center form a 2×22 \times 2 block, one per quadrant, so those three form an L). Each quadrant now has exactly one unavailable square (the hole hh, or the square just covered by the central tromino), so by the induction hypothesis each can be tiled. Combining the four tilings and central tromino tiles the board.

∎

The induction hypothesis applies to quadrants with holes in arbitrary positions: not the board nn with its hole hh, but four boards with four different holes. That is why the statement says “every square hh” and not “one fixed square”: the quantifier over hh must be inside predicate P(n)P(n) so the hypothesis inherits it. This is another form of strengthening: generalizing a parameter.

InteractiveTromino tiling: the proof is the algorithm
  • NW missing
  • NE missing
  • SW missing
  • SE missing
Board size 2n×2n2^n \times 2^n
piece 21 of 21
Piece colors
Trominoes placed21 of 21=43−1321 \text{ of } 21 = \tfrac{4^{3} - 1}{3}
Covered cells63 of 63
Current call2×2, depth 2
Hole for this callartificial (from parent)
Call stack: 8×8 → SE 4×4 → SE 2×2
Board complete: 21 trominoes cover the 63 cells, each exactly once.
Click any square to remove it and play the construction. Each step is a recursive call: the thick outline marks the current call's sub-board, the dashed cross divides its quadrants, and the highlighted tromino is the central one. When a sub-board does not contain the original hole, its ‘hole’ (dotted outline) is the square covered by the parent call's central tromino: thus each subproblem has the same form as the original. Color by depth to see the call tree and compare the number of pieces with (4n−1)/3(4^n - 1)/3.

Read the proof again as code and the correspondence is complete:

ProofProgram
statement P(n)P(n): “for every hole hh there is a tiling”signature teselar(n, h) returning a tiling
base case n=0n = 0recursion base: nothing to place
induction hypothesis applied to a quadrantrecursive call teselar(n - 1, h')
construction in the step (central tromino)local work of each call
induction is on nn, which decreasesrecursion terminates

A constructive inductive proof, which not only asserts existence but says how to obtain the object from smaller cases, is a recursive algorithm whose correctness is the proof itself. Prime factorization above is factorizar(n): if n is prime, return it; otherwise find a divisor and concatenate the two calls. The stamp problem is sellos(n) = sellos(n - 4) + [4] with four base cases in a table. This correspondence is no metaphor: in the module’s final lesson, the Curry–Howard correspondence turns it into a formal identity between proofs and programs.

The proof also gives the cost. If T(n)T(n) counts placed pieces, T(0)=0T(0) = 0 and T(n)=4 T(n−1)+1T(n) = 4\,T(n-1) + 1, a recurrence with solution T(n)=(4n−1)/3T(n) = (4^n - 1)/3: exactly the number of squares divided by three, as required. The algorithm does constant work per piece, so it is linear in board size, which is optimal.

Classic mistakes

All horses are the same color

Pólya popularized this “proof” that all horses in any finite set have the same color.

P(n)P(n): in every set of nn horses, all are the same color. Base: with one horse, obvious. Step: take n+1n + 1 horses numbered 1,…,n+11, \dots, n+1. The first nn, A={1,…,n}A = \{1, \dots, n\}, have the same color by hypothesis. The last nn, B={2,…,n+1}B = \{2, \dots, n+1\}, do too. Since the middle horses belong to both groups, the two colors agree and the n+1n + 1 horses all have the same color.

The statement is false, so something fails. The base case is correct. The flaw is in “the middle horses”: A∩B={2,…,n}A \cap B = \{2, \dots, n\} has n−1n - 1 elements, and when n+1=2n + 1 = 2 it is empty. With two horses, A={1}A = \{1\} and B={2}B = \{2\} share none and nothing relates their colors. The step P(n)⇒P(n+1)P(n) \Rightarrow P(n+1) is valid for every n≥2n \ge 2, but fails at n=1n = 1, precisely the link joining the base to everything else.

InteractiveThe missing link
P(1)P(2)P(3)P(4)P(5)P(6)P(7)P(8)P(9)P(10)P(11)P(12)P(13)P(14)A = {1}B = {2}12
  • fallen domino: P(n)P(n) proved
  • step P(n)⇒P(n+1)P(n) \Rightarrow P(n+1) proved
  • unproved step
  • A∩BA \cap B
Scenario
2
t = 14
Falling dominoesonly P(1)
First unproved caseP(2)
∣A∩B∣|A \cap B|0
With n+1=2n + 1 = 2, A={1}A = \{1\} and B={2}B = \{2\} share no horse: nothing forces horses 1 and 2 to have the same color. The link P(1)⇒P(2)P(1) \Rightarrow P(2) is false and the chain stops at P(1)P(1): no other domino falls.
The two brackets mark AA (the first nn horses) and BB (the last nn), and the aqua band marks A∩BA \cap B with the horses that would transmit the color between groups. Begin with two horses: there is no band. Increase to three or more: the argument works, but only if P(n)P(n) has already fallen, and the row of dominoes shows the chain broke at P(1)⇒P(2)P(1) \Rightarrow P(2).

Implementation: inductive proofs are programs

First, tromino tiling, translated line by line from the proof. Each piece receives a number; the hole stays 0. Verification is independent of the algorithm: it checks that each piece has three squares within a 2×22\times 2 block (three distinct squares in a 2×22 \times 2 block always form an L) and nothing remains uncovered.

[ ]Recursive tromino tilingBrowser
import numpy as np

def teselar(n, hueco):
    """Tesela el tablero 2^n x 2^n sin la casilla `hueco` = (fila, columna), siguiendo la demostración.
    Devuelve una matriz con 0 en el hueco y el número de pieza (1, 2, ...) en cada casilla."""
    lado = 2 ** n
    T = np.zeros((lado, lado), dtype=np.int32)
    siguiente = [0]

    def resolver(f0, c0, tam, hf, hc):
        if tam == 1:                       # caso base: un tablero 1x1 sin su única casilla está vacío
            return
        m = tam // 2
        qh = (hf >= f0 + m, hc >= c0 + m)  # cuadrante del hueco
        siguiente[0] += 1
        huecos = {}
        for df in (0, 1):
            for dc in (0, 1):
                if (df, dc) == qh:
                    huecos[(df, dc)] = (hf, hc)               # el hueco real se queda en su cuadrante
                else:
                    f, c = f0 + m - 1 + df, c0 + m - 1 + dc    # casilla de este cuadrante que toca el centro
                    T[f, c] = siguiente[0]                    # la cubre el triominó central
                    huecos[(df, dc)] = (f, c)                 # y pasa a ser su hueco «ficticio»
        for (df, dc), (f, c) in huecos.items():
            resolver(f0 + df * m, c0 + dc * m, m, f, c)       # hipótesis de inducción = llamada recursiva

    resolver(0, 0, lado, *hueco)
    return T

def es_teselado(T, hueco):
    """Comprueba que T cubre cada casilla salvo el hueco exactamente una vez con triominós en L."""
    if T[hueco] != 0 or (T == 0).sum() != 1:
        return False
    k = T.max()
    if not np.all(np.bincount(T.ravel(), minlength=k + 1)[1:] == 3):   # 3 casillas por pieza
        return False
    f, c = np.indices(T.shape)
    p, f, c = T.ravel(), f.ravel(), c.ravel()
    fmin = np.full(k + 1, T.shape[0]); fmax = np.full(k + 1, -1)
    cmin = fmin.copy(); cmax = fmax.copy()
    np.minimum.at(fmin, p, f); np.maximum.at(fmax, p, f)
    np.minimum.at(cmin, p, c); np.maximum.at(cmax, p, c)
    # cada pieza cabe en un bloque 2x2: sus filas y sus columnas abarcan exactamente 2 valores
    return bool(np.all(fmax[1:] - fmin[1:] == 1) and np.all(cmax[1:] - cmin[1:] == 1))

T = teselar(3, (1, 5))
print(T)
print("piezas:", T.max(), "  (4^3 - 1)/3 =", (4**3 - 1) // 3)

# todos los huecos posibles hasta 16x16
for n in range(0, 5):
    lado = 2 ** n
    assert all(es_teselado(teselar(n, (f, c)), (f, c)) for f in range(lado) for c in range(lado))
    donde = "su única casilla" if lado == 1 else f"cualquiera de sus {lado * lado} casillas"
    print(f"n = {n}: tablero {lado}x{lado}, hueco en {donde}: teselado válido")

# huecos aleatorios en tableros mayores, hasta 128x128
rng = np.random.default_rng(0)
for n in (5, 6, 7):
    lado = 2 ** n
    for _ in range(3):
        h = tuple(int(v) for v in rng.integers(0, lado, size=2))
        assert es_teselado(teselar(n, h), h)
    print(f"n = {n}: {lado}x{lado}, {(4**n - 1) // 3} triominós, 3 huecos aleatorios correctos")

The 8×88 \times 8 board matrix with the hole in row 1 and column 5 (counting from 0, as in the code) is the same construction as the figure: piece 1 is the central tromino, and pieces appear in depth-first order. The 341 exhaustive checks and those for large boards do not prove anything we did not already know; they catch translation errors between proof and code, where people make mistakes.

The lesson’s other two constructive proofs, written similarly. Strong induction appears in the recursive call not necessarily being on n−1n - 1.

[ ]Strong induction as codeBrowser
def factorizar(n):
    """Todo n >= 2 es producto de primos: la demostración por inducción fuerte, ejecutable."""
    assert n >= 2
    for d in range(2, int(n ** 0.5) + 1):
        if n % d == 0:                                  # n = d * (n // d) con 2 <= d, n // d < n
            return factorizar(d) + factorizar(n // d)   # hipótesis de inducción en dos valores menores
    return [n]                                          # sin divisores propios: n es primo

BASE = {18: [4, 7, 7], 19: [4, 4, 4, 7], 20: [4, 4, 4, 4, 4], 21: [7, 7, 7]}

def sellos(n):
    """Paga n >= 18 con sellos de 4 y 7, siguiendo la demostración por inducción fuerte."""
    if n in BASE:
        return BASE[n]                                  # los cuatro casos base
    assert n >= 22, "solo está demostrado para n >= 18"
    return sellos(n - 4) + [4]                          # paso: P(n - 4) implica P(n)

def sellos_iterativo(n):
    """La misma prueba, desenrollada: la hipótesis de inducción se convierte en invariante."""
    assert n >= 18, "solo está demostrado para n >= 18"
    k = 0
    while n not in BASE:      # invariante: n_original = n + 4k y n >= 18
        n, k = n - 4, k + 1
    return BASE[n] + [4] * k

for n in (360, 1001, 2**10, 9973, 600851475143):
    print(n, "=", " * ".join(map(str, factorizar(n))))

for n in (18, 25, 37, 100):
    s = sellos(n)
    assert sum(s) == n and s.count(4) * 4 + s.count(7) * 7 == n
    print(f"{n} = {s.count(4)}*4 + {s.count(7)}*7")
print("100000 en iterativo:", sum(sellos_iterativo(100000)) == 100000)

def pagable(n, a, b):
    return any((n - b * y) % a == 0 for y in range(n // b + 1))

for a, b in [(4, 7), (3, 5), (5, 8), (6, 11), (9, 13)]:
    F = max(n for n in range(500) if not pagable(n, a, b))
    print(f"sellos {a} y {b}: mayor imposible = {F},  ab - a - b = {a * b - a - b}")

sellos(100000) would fail in Python due to recursion depth (around 25,000 calls against the default limit of 1000). The iterative version has no such problem and illustrates a general point: linear recursion like this, with one call and work that can be accumulated (here, the counter kk of 4-cent stamps), is a loop, and the induction hypothesis justifying the call becomes the invariant justifying each iteration. Brute-force checking of Sylvester’s formula, ab−a−bab - a - b, agrees for all five pairs.

Checking inductive steps with sympy

For an identity of the form ∑k=n0nt(k)=F(n)\sum_{k=n_0}^{n} t(k) = F(n), the inductive step is mechanical: assuming the sum through nn is F(n)F(n), the sum through n+1n + 1 is F(n)+t(n+1)F(n) + t(n+1), and the step closes if and only if F(n)+t(n+1)−F(n+1)F(n) + t(n+1) - F(n+1) is identically zero. A computer algebra system checks it without sign errors.

[ ]Symbolic inductive stepsBrowser
import sympy as sp

n, c, a = sp.symbols("n c a", positive=True)

def comprobar_identidad(F, termino, n0=1):
    """¿Prueba la inducción que sum_{k=n0}^{n} termino(k) = F(n)? Devuelve (base, residuo del paso)."""
    base = sp.cancel(F.subs(n, n0) - termino.subs(n, n0))
    # paso: suponiendo F(n) = suma hasta n, la suma hasta n + 1 es F(n) + termino(n + 1)
    residuo = sp.cancel(F + termino.subs(n, n + 1) - F.subs(n, n + 1))
    return base, residuo

casos = {
    "1 + 3 + ... + (2n - 1) = n^2": (n**2, 2 * n - 1),
    "1 + 2 + ... + n = n(n + 1)/2": (n * (n + 1) / 2, n),
    "1^3 + ... + n^3 = (n(n + 1)/2)^2": ((n * (n + 1) / 2) ** 2, n**3),
    "1^2 + ... + n^2 = n^3/3 (falsa)": (n**3 / 3, n**2),
}
for nombre, (F, t) in casos.items():
    base, residuo = comprobar_identidad(F, t)
    print(f"{nombre:36s} base: {base}   residuo del paso: {sp.factor(residuo)}")

The three true identities give base 0 and residue 0. The false one, ∑k2=n3/3\sum k^2 = n^3/3, fails on both fronts, and its residue also says how far the step is wrong: the correct formula is n3/3+D(n)n^3/3 + D(n) with D(n)=n2/2+n/6D(n) = n^2/2 + n/6, and the residue (3n+2)/3(3n + 2)/3 is exactly the increment D(n+1)−D(n)D(n+1) - D(n) of what is missing.

For inequalities the calculation is the same, but we examine a sign. With hypothesis S(n)≤B(n)S(n) \le B(n), the step closes using only the hypothesis if and only if the margin B(n+1)−B(n)−1(n+1)2B(n+1) - B(n) - \frac{1}{(n+1)^2} is ≥0\ge 0 for every nn in range.

[ ]Margins of candidate boundsBrowser
def margen(B):
    return sp.factor(sp.cancel(B.subs(n, n + 1) - B - 1 / (n + 1) ** 2))

print("B(n) = 2:               margen =", margen(sp.Integer(2)))
print("B(n) = 2 - c/n:         margen =", margen(2 - c / n))
print("B(n) = 2 - 1/n:         margen =", margen(2 - 1 / n))
print("B(n) = a - 1/(n + 1/2): margen =", margen(a - 1 / (n + sp.Rational(1, 2))))

m09 = margen(2 - sp.Rational(9, 10) / n)
print("\nc = 9/10: margen =", m09)
print("primer n con margen < 0:", next(k for k in range(1, 100) if m09.subs(n, k) < 0))

The original bound gives an always negative margin, −1/(n+1)2-1/(n+1)^2; the 2−c/n2 - c/n family gives c(n+1)−nn(n+1)2\frac{c(n+1) - n}{n(n+1)^2}, which is ≥0\ge 0 for every nn precisely when c≥1c \ge 1; and the bound with n+12n + \tfrac12 leaves a positive margin of order 1/(4n4)1/(4n^4). With c=0.9c = 0.9 the step survives until n=9n = 9 and fails at n=10n = 10: the lab’s red bars.

Finally, turn well-ordering into search: if a statement about naturals is false, it has a least counterexample, and traversing n=0,1,2,…n = 0, 1, 2, \dots finds it (if within reach). This is the right tool to refute, and the wrong one to prove.

[ ]Searching for the smallest counterexampleBrowser
def menor_contraejemplo(P, desde=0, hasta=10**6):
    """El principio del buen orden convertido en búsqueda: el menor n del rango con P(n) falso."""
    return next((k for k in range(desde, hasta) if not P(k)), None)

def es_primo(m):
    return m >= 2 and all(m % d for d in range(2, int(m ** 0.5) + 1))

k = menor_contraejemplo(lambda k: es_primo(k * k + k + 41))
print("n^2 + n + 41 es primo para n <", k, " y en n =", k, "vale", k * k + k + 41, "= 41 * 41")
print("2^n > n^2 falla en:", [k for k in range(30) if not 2 ** k > k * k])

S = 0.0
print("\nmenor a con la que S(n) <= a - 1/(n + 1/2) se demuestra desde n0:")
for n0 in range(1, 7):
    S += 1 / n0**2
    print(f"  n0 = {n0}: a = S(n0) + 1/(n0 + 1/2) = {S + 1 / (n0 + 0.5):.6f}")
print("pi^2/6 =", round(3.141592653589793**2 / 6, 6))

The final table is the lab’s: with base n0=1n_0 = 1 we need a=5/3a = 5/3, and each delay brings the bound closer to π2/6=1.644934\pi^2/6 = 1.644934, below which no bound in this family can go, since S(n)→π2/6S(n) \to \pi^2/6 and 1n+1/2→0\frac{1}{n + 1/2} \to 0.

The library version

ToolWhat it doesWhen to use it
sympy.summation(t, (k, 1, n))closed symbolic sumfind the F(n)F(n) you then prove by induction
sympy.factorint(n)prime factorizationwhat factorizar does, with fast algorithms (including Pollard rho)
functools.cachememoizes a recursive functionstrong-induction recursions with repeated subproblems
Lean 4 (tactic induction)checks the whole proofwhen you need mechanical certainty, not just the step
[ ]sympy for finding what is then provedBrowser
import sympy as sp

k, n = sp.symbols("k n", integer=True, positive=True)
for t in (k, k**2, k**3, 2 * k - 1, 1 / (k * (k + 1))):
    print(f"sum_(k=1)^n {str(t):12s} = {sp.factor(sp.summation(t, (k, 1, n)))}")
print("sum 1/k^2 hasta infinito =", sp.summation(1 / k**2, (k, 1, sp.oo)))
print("factorint(600851475143) =", sp.factorint(600851475143))

summation finds the formula; induction certifies it. Notice ∑1/(k(k+1))=n/(n+1)=1−1n+1\sum 1/(k(k+1)) = n/(n+1) = 1 - \frac{1}{n+1}: this is the telescoping sum behind the strengthened bound, because 1(k+1)2≤1k(k+1)\frac{1}{(k+1)^2} \le \frac{1}{k(k+1)}.

In a proof assistant induction is a tactic, and the system checks that base and step have been proved (see proof assistants). This is Maurolico’s example in Lean 4 with Mathlib:

import Mathlib

theorem suma_impares (n : ℕ) : ∑ i ∈ Finset.range n, (2 * i + 1) = n ^ 2 := by
  induction n with
  | zero => simp                       -- caso base: la suma vacía es 0 = 0^2
  | succ n ih =>                       -- ih : ∑ i ∈ range n, (2i + 1) = n^2
    rw [Finset.sum_range_succ, ih]     -- separa el último término y usa la hipótesis
    ring                               -- n^2 + (2n + 1) = (n + 1)^2

The three lines of the step are the three lines of the paper proof. And if the statement is not inductive, Lean leaves you stuck at the same point: you must strengthen it before calling induction.

Exercises

ProofThe sum of cubes
Prove: For every n≥1n \ge 1, ∑k=1nk3=(n(n+1)2)2\displaystyle\sum_{k=1}^{n} k^3 = \left(\frac{n(n+1)}{2}\right)^2.
0
Let P(n)P(n) be the stated equality. Use weak induction from n0=1n_0 = 1.

Step 1 of 3. How do you check the base case?

ProofExistence and uniqueness of factorization
Prove: Every integer n≥2n \ge 2 is a product of primes, and that factorization is unique up to factor order.
0
You may use Euclid's lemma: if a prime pp divides a product a ba\,b, then it divides aa or bb (proved with Bézout's identity in lesson 8 and extended by induction to products of several factors).

Step 1 of 4. Which induction do you use for existence?

ProofThe series of reciprocal squares
Prove: For every n≥1n \ge 1, ∑k=1n1k2≤2−1n\displaystyle\sum_{k=1}^{n}\frac{1}{k^2} \le 2 - \frac{1}{n}, so the sum is less than 2.
0
Let S(n)=∑k=1n1/k2S(n) = \sum_{k=1}^{n} 1/k^2.

Step 1 of 3. First: why not prove S(n)<2S(n) < 2 directly by induction?

QuizWhere does the horse proof fail?
The ‘proof’ that all horses in any finite set have the same color uses base P(1)P(1) and the step: among n+1n+1 horses, the first nn have the same color, as do the last nn, and the middle ones belong to both groups. Where is the flaw?
QuizHow many base cases?
You want to prove by strong induction that an≤2na_n \le 2^n for the sequence an=an−1+2an−3a_n = a_{n-1} + 2a_{n-3}, whose step uses bounds for an−1a_{n-1} and an−3a_{n-3}. Which base cases do you need?
QuizWhat is well-ordered?
Which of these sets, with the indicated order, have a least element in every nonempty subset?

More than one answer may be correct.

QuizTwo parameters
You want to prove ∀m ∀n  P(m,n)\forall m\, \forall n\; P(m, n), and the step for (m,n)(m, n) uses P(m−1,n)P(m - 1, n) and P(m,n−1)P(m, n - 1). Cases with m=0m = 0 or n=0n = 0 are direct. Which induction works?
NumericThe largest impossible amount
You have only 4- and 7-cent stamps. What is the largest amount you cannot pay exactly? (Then prove by strong induction that all larger amounts can be paid.)
NumericHow many trominoes?
How many trominoes does the recursive construction place on a 64×6464 \times 64 board with one square removed?
NumericThe family's best bound
With hypothesis S(n)≤a−1n+1/2S(n) \le a - \frac{1}{n + 1/2}, where S(n)=∑k=1n1/k2S(n) = \sum_{k=1}^{n} 1/k^2, the inductive step closes for any aa. What is the smallest aa for which base case n0=1n_0 = 1 also holds?
CodeThe tromino tiler
Implement tile(n, hueco), returning an integer matrix of 2n×2n2^n \times 2^n with 0 at hueco = (fila, columna) and, elsewhere, the identifier (1, 2, 3...) of the tromino covering it, following the induction proof. Also implement verificar(T, hueco), returning True if and only if the hole is the only square with 0 and every identifier appears in exactly three squares forming an L (three squares in one 2×22\times 2 block). Your verificar must reject incorrect boards.
import numpy as np

def tile(n, hueco):
  lado = 2 ** n
  T = np.zeros((lado, lado), dtype=int)
  # tu código: divide en cuadrantes, coloca el triominó central y resuelve los cuatro cuadrantes
  return T

def verificar(T, hueco):
  # tu código: el hueco es la única casilla a 0 y cada pieza son 3 casillas en un bloque 2x2
  return False
Shift+Enter to run

Summary

Key idea
To prove something for every nn, a base case and a step transmitting truth from smaller cases to the next suffice; when the statement transmits too little, prove a stronger one that does, just as when finding a loop invariant.
  • Weak induction: P(n0)P(n_0) and ∀n≥n0 (P(n)⇒P(n+1))\forall n \ge n_0\,(P(n) \Rightarrow P(n+1)) give ∀n≥n0 P(n)\forall n \ge n_0\, P(n). The step is a universal proved assuming P(n)P(n) for arbitrary nn, and the base must be where the step already works.
  • Strong induction: the step assumes all earlier cases. If it uses P(n−1),…,P(n−m)P(n - 1), \dots, P(n - m), mm base cases are needed, like the four for 4- and 7-cent stamps.
  • Well-ordering: every nonempty subset of N\N has a minimum. Equivalent to both inductions, it gives the minimal-counterexample method, natural when the argument descends to a smaller case.
  • Strengthening the hypothesis: ∑1/k2<2\sum 1/k^2 < 2 is true but not inductive; ∑1/k2≤2−1/n\sum 1/k^2 \le 2 - 1/n is, because it carries the margin needed by the step. Find it by treating the step as a budget, B(n+1)−B(n)≥1/(n+1)2B(n+1) - B(n) \ge 1/(n+1)^2.
  • Induction and recursion: a constructive inductive proof is a recursive algorithm (tromino tiling, factorization, stamps), and its correctness is the proof itself; unrolled, the induction hypothesis becomes an invariant.
  • Typical errors: steps valid only from a certain nn (horses), missing or ill-fitting base cases, inducting on the wrong variable or fixing the other, and assuming what one wants to prove.