Induction is a powerful idea that can dramatically simplify some proofs that would otherwise be quite hairy.
Here we'll see how simple induction can unlock a not-so-simple task.
Task
Prove the following is true for every natural number
It is not immediately obvious how to do this in our head.
Maths
Let's introduce the idea of induction. To prove a proposition
- Base case:
is true for . - Inductive step:
true for implies true for .
The following illustrates how these two things together allow us to prove
For our task, let
The base case
The inductive step is the implication
- Let's start with
. - By assumption
, so . - Expanding
lets us see . This is because can't be negative. - Putting all this together, we have
.
In the inductive step, the assumption that
We have shown the base case
Let's write this out in a form that takes us towards a Lean proof.
Code
The following Lean program proves, by induction, that
-- 21 - Simple Induction
import Mathlib.Tactic
example {n : ℕ} : 2^n ≥ n + 1 := by
induction n with
| zero =>
norm_num
| succ n ih =>
calc
2^(n + 1) = 2 * 2^n := by ring
_ ≥ 2 * (n + 1) := by rel [ih]
_ = (n + 1) + 1 + n := by ring
_ ≥ (n + 1) + 1 := by norm_num
The proof header is as we'd expect, but the rest of the proof has a structure we've not seen before.
The induction is started using induction n with which tells Lean we want to do induction on the variable n. We need to specify the variable because some tasks may have more than one variable.
After that we have two sections, starting with | zero => for the base case, and | succ n ih => for the inductive step.
- The code indented under | zero => is the proof of the base case 2 ^ 0 ≥ 0 + 1, which here can be resolved by norm_num.
- The code indented under | succ n ih => is the proof of the inductive step 2 ^ (n + 1) ≥ n + 1 + 1, which here requires a calc section. The inductive hypothesis is established as ih.
Infoview
Placing the cursor before induction n with shows the original proof goal.
⊢ 2 ^ n ≥ n + 1
Moving the cursor to the start of the next line | zero => shows the goal for the base case.
⊢ 2 ^ 0 ≥ 0 + 1
Placing the curser just before | succ n ih => shows the goal for the inductive step, and also the inductive hypothesis ih.
ih : 2 ^ n ≥ n + 1
⊢ 2 ^ (n + 1) ≥ n + 1 + 1
Exercise
Write a Lean program to prove, by induction, that
for any natural number