Stage 02 · Step 8 of 50
Give a proof a name.
01The idea
A saved recipe saves you work next time. A named theorem does the same for a proof.
Once checked, it becomes a fact you can reuse.
02In maths
A proof that two plus two equals four can be given a name and used again.
Picture it
Swipe sideways to see the whole picture.
theorem is a proof you hang on the wall with a label. You prove 2 + 2 = 4 once, and Lean files it as the tool two_plus_two. Later, when a goal says exactly the same thing, exact two_plus_two takes the tool down and finishes the job, with no need to prove it again.03In Lean
This code comes directly from the file checked by Lean.
theorem two_plus_two : 2 + 2 = 4 := by
rfl
example : 2 + 2 = 4 := by
exact two_plus_two
A theorem is a named proposition together with its checked proof. People often call a supporting theorem a lemma.
This core Lean module uses the keyword theorem for both roles. Main results and supporting lemmas use the same proof checking rules.
The tactic exact supplies a proof term of precisely the type the goal asks for.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
⊢ 2 + 2 = 4
After line 1: theorem two_plus_two : 2 + 2 = 4 := by
⊢ 2 + 2 = 4
After line 2: rfl
no goals
After line 4: example : 2 + 2 = 4 := by
⊢ 2 + 2 = 4
After line 5: exact two_plus_two
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 : 2 + 2 = 4 := by
exact two_plus_tow
Unknown identifier `two_plus_tow`
The name is not an available theorem.
The fix: Declare the theorem before using it and copy its exact name.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Use the supplied named theorem to finish the first example.
Show a hint
The theorem is already supplied in the practice file.
One more hint
Use exact followed by its name in the final proof.
- A little stretch
Reuse the named fact about four squared.
Show a hint
Look at the name of the preceding theorem.
One more hint
The named theorem is already a term of the type you need.
theorem three_plus_three : 3 + 3 = 6 := by
rfl
example : 3 + 3 = 6 := by
sorry
theorem four_squared : 4 * 4 = 16 := by
rfl
example : 4 * 4 = 16 := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
theorem three_plus_three : 3 + 3 = 6 := by
rfl
example : 3 + 3 = 6 := by
exact three_plus_three
theorem four_squared : 4 * 4 = 16 := by
rfl
example : 4 * 4 = 16 := by
exact four_squared
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.