Stage 02 · Step 6 of 50
Your first proof.
01The idea
Imagine checking both sides of a balance. You can calculate each side and see that they match.
Lean can do this too. The tactic rfl closes an equality when both sides are definitionally equal.
02In maths
2 + 2 = 4. Both sides describe the same natural number.
Picture it
Swipe sideways to see the whole picture.
rfl works like a balance scale. It computes both sides and checks that they land on exactly the same value: 2 + 2 becomes 4, and 4 is already 4. When the scale is level, the proof is done and Lean says “no goals.”03In Lean
This code comes directly from the file checked by Lean.
example : 2 + 2 = 4 := by
rfl
An equality says that two expressions describe the same thing. A proof gives Lean a reason to accept a statement.
The word example starts an unnamed declaration. The colon introduces its statement. The text := by starts a tactic proof.
Read rfl as “check definitional equality.” Definitional equality means Lean can identify the two expressions by its computation rules.
Not every true equality works this way. Some need facts and additional proof steps. You will meet those in the next lessons.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
⊢ 2 + 2 = 4
After line 1: example : 2 + 2 = 4 := by
⊢ 2 + 2 = 4
After line 2: rfl
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 = 5 := by
rfl
Tactic `rfl` failed: The left-hand side 2 + 2 is not definitionally equal to the right-hand side 5 ⊢ 2 + 2 = 5
Lean calculates the left side as 4. It cannot identify 4 with 5, so this attempt fails.
The fix: Change the target back to 4. The compiled example above shows the corrected proof.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Easy: prove that three plus three equals six. Replace sorry with a tactic.
Show a hint
Both sides calculate to the same natural number.
One more hint
Use the same tactic as the worked example.
- A little stretch
Stretch: prove that the sum of two and three, multiplied by four, equals twenty.
Show a hint
Parentheses tell Lean which operation to calculate first.
One more hint
rfl can calculate several operations while checking this equality.
example : 3 + 3 = 6 := by
sorry
example : (2 + 3) * 4 = 20 := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example : 3 + 3 = 6 := by
rfl
example : (2 + 3) * 4 = 20 := by
rfl
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.