Stage 05 · Step 21 of 50
Numbers from zero and steps.
01The idea
A staircase starts at the ground and adds one step at a time. Natural numbers have the same structure.
Zero starts the sequence, and successor adds one.
02In maths
The natural numbers are built from zero and repeated applications of successor.
Picture it
Swipe sideways to see the whole picture.
Nat.zero, then climb one step at a time with Nat.succ. Two climbs land on step 2, which is why #eval prints 2. There is no step below the ground, so Nat has no negative numbers. One step up from any n is just n + 1, and rfl confirms it.03In Lean
This code comes directly from the file checked by Lean.
#check Nat.zero
#check Nat.succ
#eval Nat.succ (Nat.succ Nat.zero)
example (n : Nat) : Nat.succ n = n + 1 := by
rfl
Nat.zero and Nat.succ are the constructors of Nat. An inductive type is specified by constructors that build its values.
Zero is the starting constructor. The successor constructor accepts a natural number and produces another.
This construction supports induction: check zero, then show that a proof for one number extends to its successor.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
n : Nat ⊢ n.succ = n + 1
After line 5: example (n : Nat) : Nat.succ n = n + 1 := by
n : Nat ⊢ n.succ = n + 1
After line 6: rfl
no goals
05Lean says
Nat.zero : Nat Nat.succ (n : Nat) : Nat 2 no goals
A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.
06A common slip
Lean is telling us something useful here.
example : Nat.succ 2 = 2 := by
rfl
Tactic `rfl` failed: The left-hand side Nat.succ 2 is not definitionally equal to the right-hand side 2 ⊢ Nat.succ 2 = 2
The successor of two is three.
The fix: Count the successor step and correct the target.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Show that two successor steps from zero give two.
Show a hint
Start at zero and count two steps.
One more hint
The equality computes directly.
- A little stretch
Show that two successor steps from n give n plus two.
Show a hint
Addition by a concrete number on the right follows the constructors.
One more hint
Definitional equality checks this equation.
example : Nat.succ (Nat.succ Nat.zero) = 2 := by
sorry
example (n : Nat) : Nat.succ (Nat.succ n) = n + 2 := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example : Nat.succ (Nat.succ Nat.zero) = 2 := by
rfl
example (n : Nat) : Nat.succ (Nat.succ n) = n + 2 := by
rfl
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.