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.

Core Lean5 minutesLean 4.36.0

01The idea

A calculator follows rules in a fixed order. Lean does too.

Lemmi · Your guide for this idea
Lemmi pointing

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

Order of operations drawn as two calculation treesLeft tree for 2 + 3 * 4: the plus sign is at the top, with 2 on one branch and a times sign on the other branch, joining 3 and 4. The times sign is worked out first, giving 12, then the plus gives 14. Right tree for (2 + 3) * 4: the times sign is at the top, with a plus sign joining 2 and 3 on one branch and 4 on the other. The plus is worked out first, giving 5, then the times gives 20. Lean's #eval reports 14 and 20.2 + 3 * 4+*234142nd121st* comes before +, so it sits lower(2 + 3) * 4*+423202nd51stparentheses pull + down to go first

Swipe sideways to see the whole picture.

Lean reads a calculation like a tree and works from the bottom up. In 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.

E01.leanTry it live (opens official Lean editor)
#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.

After line 5
⊢ 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

Captured from Lean 4.36.0
14
20
3
no goals

A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Set firstTotal to the sum of three and four.

  2. A little stretch

    Set secondTotal to twice the sum of three and four.

Exercises/E01.leanTry it live (opens official Lean editor)
def firstTotal : Nat := sorry

def secondTotal : Nat := sorry

08A quick check

1. Which operation happens first in the first calculation?

Read the answer and explanation

Multiplication. Multiplication has higher precedence than addition.

2. What does #eval ask Lean to do?

Read the answer and explanation

Compute a value. Evaluation runs a computation and reports its result.

One more idea in your toolkit.

Take your time. Progress is yours to mark.