Stage 04 · Step 19 of 50
For every input.
01The idea
A rule for every locker applies to locker three too. A universally quantified claim must cover every input.
You can also specialize such a claim to one input.
02In maths
Every natural number equals itself. A property holding for every natural number holds at three.
Picture it
Swipe sideways to see the whole picture.
intro n hands you a mystery number n that you know nothing about, so your proof works for every choice. Once you have a “for all” rule, you can use it at any number you like: specialize h 3 turns h into a fact about 3.03In Lean
This code comes directly from the file checked by Lean.
example : ∀ n : Nat, n = n := by
intro n
rfl
example (P : Nat → Prop) (h : ∀ n, P n) : P 3 := by
specialize h 3
exact h
The symbol ∀ means “for all.” Type it with \forall. It is the universal quantifier.
Introducing its variable gives you an arbitrary input. You cannot assume special properties that were not stated.
The tactic specialize applies an available universal hypothesis to a chosen argument, replacing that hypothesis with the specialized result.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
⊢ ∀ (n : Nat), n = n
After line 1: example : ∀ n : Nat, n = n := by
⊢ ∀ (n : Nat), n = n
After line 2: intro n
n : Nat ⊢ n = n
After line 3: rfl
no goals
After line 5: example (P : Nat → Prop) (h : ∀ n, P n) : P 3 := by
P : Nat → Prop h : ∀ (n : Nat), P n ⊢ P 3
After line 6: specialize h 3
P : Nat → Prop h : P 3 ⊢ P 3
After line 7: exact h
no goals
05Lean says
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 (P : Nat → Prop) (h : ∀ n, P n) : P 0 := by
specialize h "zero"
exact h
Application type mismatch: The argument "zero" has type String but is expected to have type Nat in the application h "zero"
The universal hypothesis expects a natural-number argument, not text.
The fix: Specialize it at the natural number zero.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Prove that every natural number plus zero equals itself.
Show a hint
Introduce an arbitrary natural number.
One more hint
Addition by zero on the right computes directly.
- A little stretch
Use one universal hypothesis to prove the property at two and at five.
Show a hint
Apply the hypothesis to each number.
One more hint
Package the resulting proofs into a conjunction.
example : ∀ n : Nat, n + 0 = n := by
sorry
example (P : Nat → Prop) (h : ∀ n, P n) : P 2 ∧ P 5 := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example : ∀ n : Nat, n + 0 = n := by
intro n
rfl
example (P : Nat → Prop) (h : ∀ n, P n) : P 2 ∧ P 5 := by
exact ⟨h 2, h 5⟩
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.