Mathematical induction and invariants
Connect a base case to a uniform successor step and recognize the same structure in maintained program properties.
On this page
The question for today
What you’ll understand
- Write a base case and a correctly quantified induction step.
- Use the induction hypothesis without assuming the next case.
- Relate an induction invariant to initialization and preservation.
Checking a formula at the first hundred integers gives evidence but leaves infinitely many cases untouched. Induction replaces that finite sampling with a mechanism that moves from any established case to its successor. A base case starts the mechanism. Invariants use the same reasoning to describe what remains true as a computation evolves. Learning to state the maintained property precisely matters more than memorizing a familiar summation formula.
The base and the step do different jobs
Let P(n) be a property for integers n at least a declared starting value. Induction asks for a proof of P at that starting value and a proof that for every allowed k, P(k) implies P(k + 1). The base establishes one actual truth. The step establishes a conditional rule for arbitrary k; it does not independently assert that P(k) is true. Together they propagate truth to every later integer, by the induction principle for natural numbers.
A missing base leaves the propagation rule with nothing to propagate. A missing step leaves isolated checked instances. The start need not be zero or one: an inequality might hold only from four onward, and then four is the appropriate base. Explicitly state that boundary because the formula for the step may divide by an expression or use an inequality that fails earlier. Extra tested cases are useful for debugging but do not substitute for either required component.
Use the hypothesis at exactly its scope
For a sum formula, write the sum through k plus one as the sum through k followed by its new term. The induction hypothesis can replace only the part already covered by k. After that substitution, algebra must reach the formula with k plus one in place of n. Starting with the desired next-case equality and silently invoking it during simplification is circular. You can explore backward, but present a justified implication from the known k-case.
An overly weak claim can make the successor step difficult because it forgets useful information. In a process with several stored quantities, the right invariant may relate all of them rather than constrain just the final output. Strengthening an induction statement adds a proof obligation, yet can make preservation easier by retaining the relationship needed by the update rule. Conversely, an overly strong assertion may be false at initialization. Testing the first few states helps identify a plausible property before proving it.
An invariant explains a whole run
An invariant is a property true initially and preserved by each allowed transition. If a loop maintains accumulator s and counter k while adding successive integers, a useful property relates s to the sum of the first k integers. Initialization establishes it before the loop, preservation follows from the update equations, and the stopping condition turns it into the desired output claim. Correctness also needs termination when a result is promised; an invariant alone permits a process that runs forever.
The deterministic gradient-descent lab provides another exact recurrence: the next position is one minus the step size times the current position. For a fixed step size strictly between zero and two, the absolute multiplier is less than one. Thus an initially bounded absolute position remains bounded after each update. That invariant is weaker than convergence to zero, which needs an additional geometric-decay argument. Separate the property preserved at every step from the limiting claim about infinitely many steps.
Work it through
Sum the first n odd numbers
Prove that 1 + 3 + ··· + (2n − 1) = n² for every positive integer n.
At n = 1 the sum is 1, equal to 1². This verifies the base case in the actual domain of the claim, without needing an interpretation of an empty sum.
Fix an arbitrary positive integer k and assume the sum of the first k odd numbers equals k². The next odd term is 2(k + 1) − 1 = 2k + 1.
Adding the next term gives k² + 2k + 1 = (k + 1)². This proves the required successor implication, so induction establishes the formula for every positive integer n.
The sum of the first n positive odd integers is n²; the proof covers all positive n through a uniform step.
The living notebook
Explore the model
Interactive lab · optimization
Prove a maintained bound
Choose step size η between 0 and 2 and initial position x₀. Before stepping, predict the bound , then inspect successive positions. Compare η greater than 2, where the multiplier’s magnitude exceeds one. The lab implements only descent on ; the invariant does not automatically apply to other objectives.
- Position x0
- 2
- Objective x²/2
- 2
- Iteration behavior
- Stable step
Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forInitialization plus preservation proves a property at every finite update.
Pause & reason
Check your understanding
Your turn
Try it yourself
Prove by induction that 3 divides 4ⁿ − 1 for every integer n ≥ 0.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
For the step write 4^(k+1) − 1 as 4(4^k − 1) + 3.
Compare with the solution
At n = 0, 4⁰ − 1 = 0, divisible by three with quotient zero. Suppose at some arbitrary k ≥ 0 that 4^k − 1 = 3r for an integer r. Then 4^(k+1) − 1 = 4(4^k − 1) + 3 = 12r + 3 = 3(4r + 1). The new quotient is an integer. This proves preservation, and induction gives divisibility at every n ≥ 0.
Keep the idea
Take it with you
- Induction needs an actual base and a uniform successor implication.
- The induction hypothesis covers the previous case, not the case being proved.
- An invariant proves maintained safety; termination and limiting behavior may need separate arguments.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.