Step 0 · Before the hike

Base Camp Gym

Every good climb starts with a warm-up. Work through six short stations, about 20 minutes in all. Then the trail makes sense from the very first step.

No installs and no accounts. Just read, look and think.

Step 0

Station 1

Where math came from

People did mathematics for thousands of years before anyone wrote a proof. Here is the whole story on one page.

  1. ~20,000 years agoTally marksNotches cut into bones, like the Ishango bone from central Africa, are some of the oldest signs of counting.
  2. ~1800 BCE · BabylonClay tabletsStudents practised multiplication tables and square roots. One tablet lists the sides of right triangles.
  3. ~1550 BCE · EgyptThe Rhind papyrusWorked problems on sharing bread, measuring fields and building pyramids. These are recipes: “do this, then this.”
  4. ~600–300 BCE · GreeceThe first proofsThales, and later Euclid, ask a new question: why must this be true? Euclid’s Elements builds geometry from a few starting rules, with a proof for every fact.
  5. 628 CE · IndiaRules for zeroBrahmagupta writes down how to add, subtract and multiply with zero and negative numbers.
  6. ~820 CE · BaghdadAlgebraAl-Khwārizmī’s book gives us the word algebra. His name gives us the word algorithm.
  7. 1600s–1900sCalculus, then logicCoordinates and calculus arrive. Later, mathematicians study logic itself, the rules that proofs follow.
  8. 1976 → todayComputers join inA computer helps prove the four color theorem. Programs that check proofs line by line grow from a research idea into everyday tools. That is where Lean fits.

The big shift: for a long time, math was mostly recipes that worked. The Greek idea was to accept a fact only when it follows from earlier facts, through reasons anyone can check.

Read the longer story of math and proof →

Station 2

What a proof really is

A proof is a chain of small steps. Each step must follow from something already accepted: a definition, a basic rule, or a theorem proved earlier. The last step is the claim. Picture crossing a river on stepping stones.

A proof is a path of stepping stonesOn the left bank are things we already know: definitions, rules of algebra and earlier theorems. On the right bank is the claim that a plus b is even. Four stones cross the river: a equals 2r because a is even; b equals 2s because b is even; a plus b equals 2r plus 2s by swapping in; which equals 2 times r plus s by factoring out 2.What weknowdefinitions,algebra rules,old theoremsThe claima + bis even1a = 2ra is even2b = 2sb is even3a + b = 2r + 2sswap in4= 2(r + s)factor out 2

Swipe sideways to see the whole picture.

Every stone must be solid. If one step doesn’t really follow, there’s a gap. A proof with a gap is not a proof yet, however convincing it sounds. Lean’s job is to test every stone.

Six words you will keep meeting

Claim
A sentence that is either true or false. “7 is odd.” Also called a statement or proposition.
Definition
The agreed meaning of a word. “Even means twice some whole number.”
Axiom
A starting rule we accept without proof, like “every number has a next number.”
Theorem
A claim that has been proved. Once proved, it can be used in later proofs.
Proof
The chain of steps showing a claim follows from definitions, axioms and theorems.
Counterexample
One case where a claim fails. One is enough to show an “always” claim is false.

Why examples are not enough

Put points on a circle and join every pair with a straight line. Count the pieces the circle is cut into.

A pattern that breaks at six pointsCircles with 1 to 6 points, every pair of points joined. The circle is cut into 1, 2, 4, 8, 16 and then 31 regions. The doubling pattern predicts 32 for six points, but the real answer is 31.1 point12 points23 points44 points85 points166 points31not 32!

Swipe sideways to see all six circles.

1, 2, 4, 8, 16… it looks like doubling. You would bet on 32 next. The real answer is 31. Five examples in a row fooled us. A pattern is a great guess, and a proof is what turns a guess into a fact.

A proof you can see

Add up odd numbers: 1, then 1 + 3, then 1 + 3 + 5… You always get a square number. Here is why.

Odd numbers build squaresA four by four square of tiles split into L-shaped layers of 1, 3, 5 and 7 tiles. So 1 plus 3 plus 5 plus 7 equals 16, which is 4 squared. Each new odd layer wraps around the last square to make the next square.1 = 1= 1×11 + 3 = 4= 2×21 + 3 + 5 = 9= 3×31 + 3 + 5 + 7 = 16= 4×4
Each odd number is an L-shaped layer. It wraps around a square to make the next bigger square: add one row, one column, and one corner tile, so 2n + 1 tiles. That reason works for every size of square, so it is a real proof, not a pattern. You will prove a similar staircase sum in Lean at Step 24.

Remember: examples help you guess. A proof explains why, for every case. A single counterexample can sink an “always” claim. You will use one in Step 45.

Station 3

Why mathematicians want a checker

Proofs are written by people, and people make mistakes. Usually other experts read a proof carefully to check it. That works most of the time. Here are three times it was hard.

  • Four colors for any map

    1879 → 1890 → 1976 → 2005Alfred Kempe published a proof that four colors are enough for any map. Experts accepted it for 11 years, until Percy Heawood found a mistake. A correct proof in 1976 needed a computer to check many cases. In 2005, the whole proof was checked by a proof assistant.

  • Fermat’s Last Theorem

    1637 → 1993 → 1995Fermat claimed a proof that “didn’t fit in the margin.” More than 350 years later, Andrew Wiles announced a proof. Checking found a gap. Wiles, with Richard Taylor, fixed it a year later. A team led by Kevin Buzzard is now checking it in Lean.

  • Stacking oranges

    1611 → 1998 → 2014Kepler guessed the grocer’s pyramid is the tightest way to stack balls. Thomas Hales’s 1998 proof was so long that, after years, the reviewers said they were “99% certain.” So Hales led a team that had computers check every step, finished in 2014.

The idea: a proof assistant is software that checks every step of a proof. Then nobody has to just trust that a long argument is right. Lean is a proof assistant.

Station 4

Where Lean came from

The dream of checking math by computer is old. In 1967, N. G. de Bruijn built Automath, one of the first proof checkers. Others followed, such as Mizar, Isabelle and Coq (now called Rocq). Lean builds on these ideas.

In 2013, Leonardo de Moura, a computer scientist at Microsoft Research, started Lean. He wanted a checker that was both trustworthy and pleasant to use. It has been rebuilt three times since.

Four versions of LeanA staircase: Lean 1 in 2013, Lean 2 in 2015, Lean 3 in 2017, the first stable version, when Mathlib began, and Lean 4 from 2021 to today, rebuilt and written mostly in Lean itself. This course uses Lean 4.36.Lean 12013Started at MicrosoftLean 22015Still experimentalLean 32017Mathlib beginsLean 42021–todayRebuilt, written in LeanYou are here: Lean 4.36

Swipe sideways to see every version.

Lean 4 is a full programming language and a proof checker in one. It is mostly written in Lean itself. This course uses Lean 4.36.
  1. 2017Mathlib beginsMathematicians start a shared library of checked definitions and theorems. Anyone can contribute.
  2. 2020–2022A test from the frontierFields Medal winner Peter Scholze asked whether Lean could check a hard new result of his. The Lean community did it. This was the Liquid Tensor Experiment.
  3. 2023Lean 4 grows upLean 4.0.0 is released and Mathlib moves to Lean 4. The Lean FRO, a non-profit organization, is set up to look after Lean.
  4. 2023Three weeksTerence Tao and a team check a brand-new proof in Lean in about three weeks.
  5. 2024AI writes LeanGoogle DeepMind’s AlphaProof writes Lean proofs for International Mathematical Olympiad problems. Lean checks them, so nobody has to trust the AI.

What is inside Lean 4

What is inside Lean 4Three nested rings. At the centre is the kernel, a small program that checks every proof. Around it is the Lean 4 language with its tactics. The outer ring is Mathlib, a huge shared library of definitions and theorems. Your proof sits on top and is checked by the kernel.kernelLean 4 languagetactics like rflMathlibshared libraryThe kernelA small program that checks everystep. Small, so experts can trust it.The languageWrite programs, claims and tactics.MathlibA huge library of checked theorems.Your proofUses all three. Only the kerneldecides if it is correct.
The key to trusting Lean: however clever the tactics or the AI that wrote a proof, the small kernel at the center checks the final result. In early lessons you use core Lean. From Step 26, you also use Mathlib.

Station 5

How to read Lean 4

You don’t need to write Lean yet. Learn to read it. Here are four ideas that cover almost everything on the trail.

A A claim, then its proof

This proof from Step 10 says: “if you already have a proof of P, then P is true.” Read it piece by piece.

example (P : Prop) (h : P) : P := byexact h1234
  1. (P : Prop) “Let P be any claim at all.” Prop is the type of claims.
  2. (h : P) “…and suppose we already have h, a proof of P.” This is a hypothesis: a fact you may use.
  3. : P “Then P is true.” This is the claim to prove.
  4. exact h “The proof is exactly h.” exact hands Lean something that matches the goal.
The first word, example, means “here is a claim”. := by means “and here is why”. Everything before the final colon sets the scene.

B The goal: what you have, and what you need

While you write a proof, Lean shows a goal state. It is your map on the trail. This is the real goal state Lean shows at the start of the proof above.

What you haveP : Proph : PWhat you must prove⊢ PAbove the linefacts and names youare allowed to useAfter ⊢ (“turnstile”)the goal: what is stillleft to prove
Facts you have are listed above the line, each with a name. The ⊢ symbol (say “turnstile”) marks the goal, what you still need to prove. Here the goal is P, and you already have h : P. Done.

C Tactics are moves

A tactic is one move in a proof. Each move changes the goal, usually making it simpler. When no goals are left, the proof is finished. These are the real before-and-after states Lean recorded.

BEFORE⊢ 2 + 2 = 4rflthe tactic (your move)AFTERno goals
BEFOREP : Proph : P⊢ Pexact hthe tactic (your move)AFTERno goals

Swipe sideways to see before and after.

On the trail you’ll collect more than 25 tactics, like tools in a backpack. The Toolkit lists them all.

D Everything has a type

In Lean, every value has a type: what kind of thing it is. Write 42 : Nat and read it as “42 has type Nat.” Lean checks types the way a lock checks a key: the wrong kind of thing simply doesn’t fit.

Everything in Lean has a typeFour bins. Nat holds whole numbers such as 42, 0 and 7. String holds text such as "hello" and "Lean". Bool holds true and false. Prop holds claims such as 2 + 2 = 4 and 2 + 2 = 5; a claim can be false and still be a claim.4207Natwhole numbers"hello""Lean"StringtexttruefalseBooltrue or false2 + 2 = 42 + 2 = 5Propclaims

Swipe sideways to see all four types.

Claims are things too: their type is Prop. A false claim like 2 + 2 = 5 is still a claim. You just can’t prove it. And proofs have types: h : P means “h is a proof of P.” Meet types at Step 2.

Symbols you will meet

Lean writes logic with a few symbols. You type each one with a backslash shortcut, like \to for →.

SymbolSay it asType itFirst used
⊢goal: still to prove\vdashStep 6
→implies / if … then\toStep 11
∧and\andStep 12
∨or\orStep 14
¬not\notStep 16
↔if and only if\iffStep 18
∀for every\forallStep 19
∃there exists\existsStep 20

All symbols are on the symbols page. To run Lean yourself, every lesson has a “Try it live” link, or see Get set up.

Station 6

Warm-up check

Three quick questions. They’re not graded, just a stretch before you start.

1. Your friend checks a claim for the first 1,000 whole numbers. It works every time. Is that a proof?

Read the answer and explanation

No. A proof must cover every case, not just the ones tested. Checks are evidence. The circle pattern worked five times in a row and then failed. A proof gives a reason that covers every case.

2. In Lean, what does “no goals” mean?

Read the answer and explanation

The proof is complete. Nothing is left to prove. Each tactic changes the goal. When none are left, every part of the claim has been proved.

3. In the goal state below, what is h?
h : P
⊢ P

Read the answer and explanation

A name for a fact you are allowed to use. Everything above the ⊢ line is something you have. h is the name of a proof of P, so exact h finishes the goal.

You’re ready for the trail.

Every lesson follows the same eight parts, so you always know where you are.

  1. The ideaan everyday picture
  2. In mathsthe exact claim
  3. In Leanchecked code
  4. Step by stepgoal after each line
  5. Lean saysthe real output
  6. A common slipa real error, explained
  7. Your turntwo tasks + hints
  8. Quick check2–3 questions