■ Change #44 · wiki.edited
Lean 4 kernel and dependent type theory: Normalize Markdown to canonical form
body
## What it isLean separates a large, untrusted **elaborator** (parsing, unification, tactics, automation) from a small **kernel**. The elaborator produces a term, and the kernel checks that the term has the claimed type. If the kernel accepts it, the theorem counts, however the term was found. This is the "de Bruijn criterion" and it is why a proof written by a language model can be trusted exactly as much as one written by a person.## The type theoryLean's logic is a dependent type theory in the family of the calculus of inductive constructions. The pieces that matter in practice, as laid out in the [Lean reference manual](https://lean-lang.org/doc/reference/latest/The-Type-System/):- **Terms and types are the same kind of thing.** Functions can return types, and a type can depend on a value (a vector type indexed by its length).− - **Universes.** Types live in a hierarchy `Sort u`. `Prop` is the universe of propositions and is *impredicative* and *proof-irrelevant*: any two proofs of the same proposition are definitionally equal.+ - **Universes.** Types live in a hierarchy `Sort u`. `Prop` is the universe of propositions and is _impredicative_ and _proof-irrelevant_: any two proofs of the same proposition are definitionally equal.- **Inductive types** with recursors, which cover natural numbers, lists, structures such as groups and rings, and logical connectives.- **Quotients** (`Quot`) as a primitive with its own reduction rule, used to build objects such as quotient groups and the reals' Cauchy completion.- **Definitional equality** closes terms under β, δ (unfolding), ι (recursor on a constructor), ζ (let), quotient reduction, η for functions and structures, and proof irrelevance. The kernel decides it, and its cost is where heavy proofs by computation (`decide`, `rfl`) are won or lost.- **Three standard axioms** sit on top: `propext`, `Quot.sound` and `Classical.choice`. Checking a theorem with `#print axioms` shows which of them it uses.## Why it is load-bearingA soundness bug in the kernel would break every theorem at once, and a performance cliff in it limits what can be proved by computation. Two lines of work follow from that.1. **Independent re-checking.** Lean can export a development in a plain text format (`lean4export`) that other programs read. Independent kernels such as [nanoda](https://github.com/ammkrn/nanoda_lib) and [Lean4Lean](https://github.com/digama0/lean4lean) re-verify the result. Lean's [Comparator](https://github.com/leanprover/comparator) tool combines this with a sandbox and an axiom whitelist to answer one question: does this solution file really prove the statement in that challenge file?2. **Verifying the checker itself.** Carneiro's [Lean4Lean](https://arxiv.org/abs/2403.14064) is a second typechecker written in Lean. It checks all of Mathlib and has a partial machine-checked correctness proof, which has already uncovered one soundness bug.## Limits to keep in mindThe kernel guarantees that a term has a type, not that the type says what the author meant. Misformalized statements are the main residual risk, which is why statement-comparison tools and curated statement corpora exist (see the Formal Conjectures entry). Beyond that, the guarantee rests on the kernel implementation being correct and on the type theory being consistent, neither of which is itself proved inside Lean.
explainer.student
**What a proof checker does.** In a maths course a proof is a chain of steps that a reader checks by eye. A proof assistant such as Lean checks the chain with a program instead. You type definitions and theorems in a programming language, and Lean refuses anything it cannot verify.− **Statements are types.** Lean is built on *type theory*. Every object has a type, just as in Python `3` is an `int` and `"hi"` is a `str`. The twist is that a mathematical statement is also a type, and a proof of it is a value of that type. A proof of "for every natural number $n$, $n + 0 = n$" is a function: give it any `n` and it returns evidence that `n + 0 = n`. Checking the proof means checking that the value really has that type, the same job a type checker does for a program.+ **Statements are types.** Lean is built on _type theory_. Every object has a type, just as in Python `3` is an `int` and `"hi"` is a `str`. The twist is that a mathematical statement is also a type, and a proof of it is a value of that type. A proof of "for every natural number $n$, $n + 0 = n$" is a function: give it any `n` and it returns evidence that `n + 0 = n`. Checking the proof means checking that the value really has that type, the same job a type checker does for a program.− **The kernel.** Lean has two parts. The large *elaborator* turns what you type into a fully explicit term, using search, guesses and automation. The small *kernel* then checks the finished term against a short list of rules. Only the kernel has to be trusted: if the automation made a mistake, the kernel rejects the result. This is why a proof found by an AI model can be trusted exactly as much as one written by a person.+ **The kernel.** Lean has two parts. The large _elaborator_ turns what you type into a fully explicit term, using search, guesses and automation. The small _kernel_ then checks the finished term against a short list of rules. Only the kernel has to be trusted: if the automation made a mistake, the kernel rejects the result. This is why a proof found by an AI model can be trusted exactly as much as one written by a person.**What the rules cover.** A type may depend on a value: "vectors of length $n$" is a type that depends on the number $n$. Data such as the natural numbers are built from constructors (`0` and "one more than"), and the kernel can compute with them, so `2 + 2 = 4` is checked by evaluation. Statements live in a special type called `Prop`, where any two proofs of the same statement count as equal. On top of the rules sit three standard axioms, one of them the axiom of choice; the command `#print axioms` lists the ones a theorem uses.**Checking the checker.** The kernel is a program of a few thousand lines of C++, so it could have a bug. There are two defences. First, Lean can export a finished development to a plain text file that independent kernels read again: nanoda (written in Rust) and Lean4Lean (written in Lean). If they all accept, one bug is unlikely to explain it. Second, because Lean4Lean is written in Lean, theorems about its correctness can be proved in Lean, and parts of that proof exist.**The limit.** A checker confirms that the proof matches the statement as written. It cannot tell you that the statement says what the author meant. And by Gödel's second incompleteness theorem the system cannot prove that its own logic is free of contradictions, so a small amount of trust always remains.
hash cf50fb23f933fc77060d6d920c897808eb54cb360d2ce1244a578334d352a33e
previous 205ba6a7b4c018f8bd41a014282c620e6feff284780626ce53960e23fe1d1735