Stage 05 · Step 21 of 50

Numbers from zero and steps.

Core Lean8 minutesLean 4.36.0

01The idea

A staircase starts at the ground and adds one step at a time. Natural numbers have the same structure.

Indy · Your guide for this idea
Indy pointing

Zero starts the sequence, and successor adds one.

02In maths

The natural numbers are built from zero and repeated applications of successor.

Picture it

Natural numbers: start on the ground, climb one step at a timeA staircase standing on the ground. The ground is the number 0, labelled Nat.zero. Three steps rise from it, numbered 1, 2 and 3, and every climb from one step to the next is labelled succ. A dashed fourth step shows that the stairs keep going forever. Nothing lies below the ground. A note in the corner says that #eval Nat.succ (Nat.succ Nat.zero) prints 2, and points at step 2: two climbs up from the ground.Nat.zerothe ground1 step up2 steps up3 steps up…and so onsuccsuccsucc0123#eval Nat.succ (Nat.succ Nat.zero)prints 2: two climbs from the ground

Swipe sideways to see the whole picture.

Every natural number is built the same way: start on the ground with 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.

E21.leanTry it live (opens official Lean editor)
#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.

After line 5
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

Captured from Lean 4.36.0
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.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Show that two successor steps from zero give two.

  2. A little stretch

    Show that two successor steps from n give n plus two.

Exercises/E21.leanTry it live (opens official Lean editor)
example : Nat.succ (Nat.succ Nat.zero) = 2 := by
  sorry

example (n : Nat) : Nat.succ (Nat.succ n) = n + 2 := by
  sorry

08A quick check

1. What does Nat.succ do?

Read the answer and explanation

Adds one. Successor moves from a natural number to the next one.

2. Does Nat include negative integers?

Read the answer and explanation

No. Nat consists of zero and its successors. Int includes negative integers.

One more idea in your toolkit.

Take your time. Progress is yours to mark.