Proof by Induction


Recursion has much in common with the mathematical technique of proof by induction.
Theorem: The sum of the first n odd integers is n2.

Proof:

Base case (n=1, stop condition): 12 = 1

Inductive assumption (leap of faith): 1 + 3 + 5 + ... + (2k-1) = k2.

Inductive step (using the procedure as its own helper): We wish to prove that:
1 + 3 + 5 + ... + (2k-1) + (2k+1) = (k + 1)2.

We have assumed that 1 + 3 + 5 + ... + (2k-1) = k2.

By replacing 1 + 3 + 5 + ... + (2k-1) by k2 in the left hand side of the equation we wish to prove, we get:
k2 + (2k+1) = (k + 1)2.

But k2 + (2k+1) = k2 + 2k + 1 = (k+1)2.

Therefore, 1 + 3 + 5 + ... + (2k-1) + (2k+1) = (k + 1)2.

The principle of mathematical induction says that since we proved that the sum of the first 1 odd integers is 12, and that we know that when it's true for the first k odd integers it's also true for the first k+1 odd integers, then it must be true for all postive integers k. We conclude that the sum of the first k odd integers is k2.//