Stage 04 · Step 20 of 50
Find one witness.
01The idea
To show that a treasure exists, showing one treasure is enough. An existence proof supplies a witness.
It also proves that the witness has the requested property.
02In maths
There exists a natural number n such that n + 1 = 4.
Picture it
Swipe sideways to see the whole picture.
exists 3 names 3 as the witness, and Lean checks 3 + 1 = 4 by computing it. Pointing at the wrong number, like 2, would leave you stuck proving 2 + 1 = 4, which is false.03In Lean
This code comes directly from the file checked by Lean.
example : ∃ n : Nat, n + 1 = 4 := by
exists 3
The symbol ∃ means “there exists.” Type it with \exists. It is the existential quantifier.
A witness is the value you choose. The rest of the proof checks its property.
The tactic exists supplies a witness and tries to finish by definitional equality. If that is not enough, the property remains as a goal.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
⊢ ∃ n, n + 1 = 4
After line 1: example : ∃ n : Nat, n + 1 = 4 := by
⊢ ∃ n, n + 1 = 4
After line 2: exists 3
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 : ∃ n : Nat, n + 1 = 4 := by
exists 2
unsolved goals ⊢ 2 + 1 = 4
The chosen witness leaves an unproved and false equality.
The fix: Choose three and verify its property.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Find a natural number whose double is ten.
Show a hint
Try five as the witness.
One more hint
An anonymous constructor packages the witness and its equality proof.
- A little stretch
Find one number satisfying both supplied equations.
Show a hint
Both equations must use the same witness.
One more hint
Use three, then provide both arithmetic proofs.
example : ∃ n : Nat, n * 2 = 10 := by
sorry
example : ∃ n : Nat, n + 1 = 4 ∧ n * 2 = 6 := 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 * 2 = 10 := by
exact ⟨5, rfl⟩
example : ∃ n : Nat, n + 1 = 4 ∧ n * 2 = 6 := by
exact ⟨3, rfl, rfl⟩
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.