Lean Theorem Prover: Lean 4 and Mathlib Explained

Quick answer: Lean is a free, open-source programming language and proof assistant used to write and check mathematical proofs. You express a statement and its proof in Lean’s formal language, and its small kernel checks that the proof follows from the permitted assumptions. Lean 4 is the current major version, and Mathlib is its community library of mathematical definitions, theorems and proofs.

A calculator can confirm that \(7 + 0 = 7\). Lean can check a proof that \(n + 0 = n\) for every natural number \(n\). That is the difference between testing a case and proving a statement: a calculation checks one input, while a proof covers every case its assumptions allow.

What Is Lean?

Lean is an open-source proof assistant and programming language. Leonardo de Moura started it in 2013 at Microsoft Research; the current version, Lean 4, is developed by the nonprofit Lean FRO, which de Moura co-founded with Sebastian Ullrich. You write definitions, statements and proofs in Lean’s formal language. Tactics and other code build a formal proof object, and Lean’s small trusted kernel checks it.

ComponentRole
Lean 4The language and system for writing programs and formal proofs
MathlibA shared library of mathematical definitions and proved results
TacticA command that helps build a proof or transform the current goal
KernelThe core checker that validates the finished proof

Lean is not an AI system (though AI tools can write Lean), not a calculator (it proves general statements), and not like LaTeX (which only displays math; Lean checks it).

A Tiny Example

Here is a complete Lean proof that adding zero to a natural number changes nothing:

theorem add_zero_example (n : Nat) : n + 0 = n := by
  simp
CodeMeaning
theorem add_zero_exampleGive the theorem a name
(n : Nat)Let \(n\) be any natural number, including 0
: n + 0 = nThe claim to prove
:= byBegin a proof written with tactics
simpSimplify using a database of established rewriting rules

This proves the statement for every natural number, not for a list of tested values. Longer proofs combine tactics, named lemmas from the library and intermediate steps. You can paste this example into the free online Lean editor at live.lean-lang.org and watch the goal disappear.

What Is Mathlib?

Mathlib is Lean’s community library, a separate project from the Lean language itself. It covers many areas of undergraduate mathematics and a growing collection of research results, written and reviewed by hundreds of contributors. You load it with import Mathlib, and the practical benefit is reuse: you can build on established definitions and proved results instead of rebuilding them for every project.

Lean in the 2026 Headlines

DateResultScope of the Lean formalization
January 2026Erdős Problem 728Kevin Barreto used GPT-5.2 Pro and Harmonic’s Aristotle to produce a Lean proof of the intended statement
September 2026Fermat’s Last Theorem, complete formal proofA formalization of the existing proof: Anthropic reported that Claude agents wrote about 13 million lines of Lean in 11 days, following the Darmon–Diamond–Taylor account; Kevin Buzzard compiled it and ran the standard checker
September 2026Navier–Stokes blow-up (forced case)OpenAI released a writeup and a Lean formalization for the forced case, with a smooth external force
October 2026Unit distance exponent about 1.043The manuscript claims 1.043171; the Lean file proves the slightly weaker 1.04315, conditional on one numerical inequality checked outside Lean

What Lean Does and Does Not Guarantee

  • Compiling is not enough. Lean allows the placeholder sorry for unfinished steps, and a theorem can depend on extra axioms. The command #print axioms shows what a theorem really relies on. Before trusting a result, check that it and its dependencies contain no sorry or unintended axioms.
  • It guarantees, once those checks pass, that the formal statement follows from the axioms and the library, assuming Lean’s small kernel is correct.
  • It does not guarantee that the formal statement says what the human statement says. A typo in a definition can make a “proof” of the wrong thing. This is why reviewers check statements carefully.
  • It does not guarantee novelty. A checked proof can still be of something already known.
  • It does not make a proof readable. Kevin Buzzard noted that the 13-million-line Fermat formalization faithfully follows the earlier literature. Its main achievement is large-scale formal verification of existing mathematics.

How to Start

The free Natural Number Game teaches Lean in a web browser by proving facts about addition and multiplication. After that, the book Mathematics in Lean walks through real undergraduate topics.

Common Misconceptions

“Lean finds proofs by itself.” Lean checks proofs. Tactics and AI systems can help find them, but Lean is the referee.

“A Lean proof can never be wrong.” The logic is checked, but the statement must still be checked by people.

Watch: Lean in Video

If you learn better by watching, these videos are worth your time.

Creator of Lean: Handwritten Math Will Change Dramatically (Ryan Peterman). Leonardo de Moura on why Lean was built and where it is heading.
How to learn Lean programming language (Lex Clips). Terence Tao on using Lean as a working mathematician.
10 minute Lean tutorial: proving logical propositions (Xena Project). Kevin Buzzard’s quick hands-on introduction (uses an older Lean version).

Check Your Understanding

Five quick questions to see how much of this has stuck. Pick an answer and press Submit; you will see a short explanation either way.

Answer each question and press Submit to see your result right away.

1. Does a Lean file that compiles always contain a complete proof?
Found a bug? Let us know!
2. In the example, what does (n : Nat) mean?
Found a bug? Let us know!
3. What is Mathlib?
Found a bug? Let us know!
4. What can a Lean proof NOT guarantee?
Found a bug? Let us know!
5. About how many lines of Lean did the 2026 Fermat formalization contain?
Found a bug? Let us know!

Frequently Asked Questions

What is the Lean theorem prover?

Lean is an open-source proof assistant and programming language in which mathematical statements and proofs are written formally so a computer can check every step. It was created by Leonardo de Moura and is now developed by the Lean FRO.

Is Fermat’s Last Theorem proved in Lean?

Yes. In September 2026, Anthropic announced a complete Lean proof written largely autonomously by Claude agents over 11 days, about 13 million lines long. Kevin Buzzard compiled and checked it, noting it follows the early literature on Wiles’s proof.

Can a Lean proof be wrong?

The kernel checks the logic, so errors there are very unlikely. But a file can compile while using sorry or extra axioms, and the formal statement might not match the intended mathematics, so both must be checked.

What is the difference between Lean and Mathlib?

Lean 4 is the language and proof checker. Mathlib is a separate community library of mathematics written in Lean that you import to reuse definitions and theorems.

How do I learn Lean?

Start with the free Natural Number Game in your browser, then read Mathematics in Lean. Both are free online.

Keep Exploring

Sources and Further Reading

Related to This Article

What people say about "Lean Theorem Prover: Lean 4 and Mathlib Explained - Effortless Math"?

No one replied yet.

Leave a Reply