Your first step on the trail · New to proofs? Warm up at Step 0 first.
Stage 01 · Step 1 of 50
Meet your new calculator.
01The idea
A calculator follows rules in a fixed order. Lean does too.
Ask it to evaluate an expression, then compare what changes when you add parentheses.
02In maths
Multiplication is evaluated before addition. Parentheses can change the order of calculation.
Picture it
Swipe sideways to see the whole picture.
2 + 3 * 4 the multiplication is lower in the tree, so it happens first: 12, then 14. Parentheses rebuild the tree, so (2 + 3) * 4 adds first and gives 20.03In Lean
This code comes directly from the file checked by Lean.
#eval 2 + 3 * 4
#eval (2 + 3) * 4
#eval (17 : Nat) / 5
example : (2 + 3 * 4 : Nat) = 14 := by
rfl
#eval asks Lean to compute a value. An expression is a piece of code that describes a value.
Here the numbers are natural numbers: zero and the positive whole numbers. Division of natural numbers gives a whole-number quotient. It does not produce a fraction.
For practice, sorry marks a hole. Replace that word with your expression. You will learn how to name values in Example 3.
The last two lines turn the first calculation into a claim. Read them as “two plus three times four equals fourteen, because both sides compute to the same number.” Lean calls that check rfl.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
⊢ 2 + 3 * 4 = 14
After line 5: example : (2 + 3 * 4 : Nat) = 14 := by
⊢ 2 + 3 * 4 = 14
After line 6: rfl
no goals
05Lean says
14 20 3 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.
#eval 2 +
unexpected end of input
An operand is missing after the addition sign.
The fix: Complete the arithmetic expression before asking Lean to evaluate it.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Set firstTotal to the sum of three and four.
Show a hint
Replace the placeholder with an arithmetic expression.
One more hint
Use the addition symbol between the two numbers.
- A little stretch
Set secondTotal to twice the sum of three and four.
Show a hint
Calculate the sum before multiplying.
One more hint
Put parentheses around the addition.
def firstTotal : Nat := sorry
def secondTotal : Nat := sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
def firstTotal : Nat := 3 + 4
#eval firstTotal
def secondTotal : Nat := (3 + 4) * 2
#eval secondTotal
7 14
08A quick check
09New words & tools
Take your time. Progress is yours to mark.