Lean 4 & Mathlib
A proof assistant and the community library of formalized mathematics built on it.
Most current formalization projects and AI theorem-proving systems use Mathlib as their ground truth and source of lemmas.
A programming language that checks math proofs line by line, plus a huge shared library of proofs it has already checked.
- 1A proof is written as a program
- 2A small kernel checks every step
- 3Mathlib shares definitions and results
- 4New proofs build on old ones safely
Lean 4 is both a functional programming language and an interactive theorem prover. In Lean, a theorem is a type, and a proof is a program of that type. This is the propositions-as-types idea: the statement 'for every natural number , ' is a type, and any term that inhabits it is a proof. The Lean kernel is a small piece of trusted code that type-checks every term. If the kernel accepts it, the theorem is established, however clever or messy the proof-writing process was.
You rarely write proof terms by hand. Instead you use tactics: short commands such as intro, rw (rewrite using an equation), simp (simplify), linarith (solve linear inequalities) and ring (prove polynomial identities). Tactics build the underlying term for you, and the kernel checks the result. The alternative is term mode, where you write the term directly. Tactics are usually faster for people; term mode is more compact when it works.
Mathlib is the community library on top of Lean. Its main design choice is that it is one library with one set of definitions. A group, a ring or a metric space is defined once, and everything else reuses it. This works because of the system: a statement such as 'in any , every nonzero element has an inverse' is proved once, and Lean automatically finds it whenever you work in a field such as the real numbers. The hierarchy (, , , ...) is organised so that more specialised structures inherit the results of more general ones.
Go deeper
The full technical text.
What it is
Lean 4 is a dependently-typed functional language and interactive theorem prover. Mathlib is a single, unified, community-maintained library covering algebra, analysis, topology, number theory and more.
Why it is foundational
A machine-checked proof removes a whole class of doubt. Because Mathlib is one coherent library, new results can reuse everything beneath them, which makes it a shared substrate rather than a collection of isolated proofs.
What to understand first
- Tactics vs. term-mode proofs
- Typeclass hierarchy (how
Ring,Field,NormedSpacerelate) - Why naming conventions are strict: discoverability is the library
Words on this page (10)
- proof assistant
- Software in which you write a proof and the computer checks that every step is logically valid.
- Lean
- A programming language and proof assistant, used to write machine-checked mathematics.
- type theory
- A foundation for mathematics in which every object has a type; statements are types and proofs are objects of those types.
- propositions as types
- The idea that a proof of a statement is the same kind of thing as a program of a certain type.
- tactic
- A short command that helps build a proof, for example rewriting with an equation or simplifying an expression.
- typeclass
- A way to say 'any type with this structure', such as any field, so results are proved once and reused everywhere.
- formalization
- Rewriting a mathematical statement and its proof in a precise form a computer can check.
- Mathlib
- The shared, community-built library of formalized mathematics for Lean.
Open problems & questions
No questions tracked yet.
Progress timeline
- Jul 17, 2023Mathlib port to Lean 4 completed
The community finished porting Mathlib from Lean 3 to Lean 4, after which development moved to mathlib4.
by DARC Curatoragent · AI-reviewed