Foundations of mathematics
Formal proof with proof assistants (Lean)
A proof assistant like Lean checks a mathematical proof the way a compiler checks a program: it reduces "is this proof correct?" to "does this typing judgment reduce", verified by a small trusted kernel.
IntuitionWhy trust a proof you cannot fully read?
Mathlib, the Lean 4 mathematical library, now has millions of lines of proof — far more than any one person can read line by line. Yet mathematicians trust it, for the same reason we trust an elevator inspector's stamp rather than personally re-welding every cable: a small, fixed checking procedure (the kernel) has verified every single step, and the kernel itself is short enough to audit by hand.
UndergraduateThe Calculus of Inductive Constructions
Definition: Terms, types, and the typing judgment
Lean's core logic is the Calculus of Inductive Constructions (CIC): a dependent type theory where types can depend on values (dependent function type , read "for every , a value of type "), and new types are built by inductive declarations (natural numbers, lists, the propositional equality type). Every object is classified by the typing judgment : "in context , the term has type ".
Under the Curry–Howard correspondence, a proposition is itself a type, and a proof of is a term of that type — proving is programming. This is why type-checking, an algorithm that already had to exist to compile programs, is enough to check proofs.
| Layer | Job | Trust |
|---|---|---|
| Elaborator / tactics | Search for a proof term from high-level tactic scripts | Untrusted: bugs here only waste time |
| Kernel | Re-check that really has type | Trusted: this is the de Bruijn criterion |
AdvancedThe de Bruijn criterion and equality via Eq.rec
The de Bruijn criterion says a proof assistant is trustworthy when a small, independently-auditable kernel checks every proof term, so : soundness rests on a few hundred lines of code, not on the tactic engine that produced the term. Inductive equality is itself defined by one constructor , and its eliminator (the J-rule) is the single primitive the kernel needs to derive every other property of equality.
There is a term built only from and ; symmetry is a theorem of CIC, not an extra axiom.
Why is it true?
If equality needed a separate axiom for symmetry, transitivity, congruence, and so on, the trusted kernel would grow with every new fact about . Deriving them all from one eliminator keeps the kernel tiny.
Proof
Fix . We want a function taking (for arbitrary ) to a proof of . Apply with the motive — a family of propositions indexed by the point and the proof connecting to .
The eliminator asks for a proof of the base case , i.e. of ; supply itself. This is legal because the base case is always indexed by at the starting point .
then returns, for every and every , a proof of . Instantiate : we obtain exactly a proof of .
Packaging this as gives the term of type . The kernel accepts it purely by matching this application against the type signature of — no reasoning about "symmetry" as a concept is needed at the kernel level.
There is a term built only from .
Why is it true?
Chaining equalities ( therefore ) is used in essentially every proof; if it were an axiom instead of a derived term, the kernel would have to trust that axiom rather than verify it by computation.
Proof
Fix and . Given for arbitrary , we want a proof of . Apply to with motive , indexed by the point and the proof connecting to .
The base case required is , i.e. — exactly . So is the base-case proof supplied to .
then delivers, for every and every , a proof of , which is what we wanted.
So has type . Notice the pattern shared with symmetry: both proofs "transport" a fact along an equality by choosing the right motive , then let the kernel's fixed reduction rule for on do the actual work.
UndergraduateReal-world applications: from compilers to number theory
Formal proof is no longer a laboratory curiosity. CompCert, a C compiler formally verified in Coq, has a machine-checked proof that its generated assembly always behaves like the source program — a guarantee no test suite can give. AWS and Signal use formally verified cryptographic code (in tools like AWS's s2n TLS library, HACL and F) to remove entire classes of memory-safety and side-channel bugs. And in pure mathematics, Lean's Liquid Tensor Experiment (2020–2022) formalized a hard theorem of Peter Scholze in condensed mathematics, and Terence Tao's team formalized the Polynomial Freiman–Ruzsa (PFR) conjecture's proof in Lean within months of the human proof appearing in 2023.
Example: Type-checking a proof of
Show, at the level of the kernel, why the term built by induction for is accepted.
Solution
Addition on is defined by recursion on the second argument: and . So the base case of the goal reduces by computation to , which is — the kernel accepts it with no logical work at all, just unfolding a definition.
For a general theorem this base case is trivial by the definition above, so no induction is even needed for this particular statement (unlike , which does need induction since recursion is on the second argument).
The kernel's role is simply to unfold according to its recursive definition on the literal term , arrive at , and then check that the two sides of the goal are definitionally equal — reducing "is this proof correct" to a terminating computation, exactly the de Bruijn criterion in action.
Example: Verified compilation as a typed equality
CompCert states its correctness theorem as a semantic preservation property. Explain what "the proof is a term of that type" buys engineers over ordinary compiler testing.
Solution
CompCert's theorem has the shape "for every source program that compiles to assembly , every observable behavior of is a behavior of " — a universally quantified statement over all source programs, not just the ones in a test suite.
A test suite checks finitely many pairs and can never rule out a miscompilation on program #4,000,001. A Coq proof term of the universally quantified statement is instead type-checked once, for the whole quantifier, by the kernel — the same kernel used for every other CompCert lemma, so no new trust is introduced per test case.
Because the proof term is total and the theorem is about the compiler's actual Coq source code (extracted to OCaml), any change to the compiler that breaks the guarantee simply fails to type-check, catching regressions that a finite regression-test suite would miss entirely — this is precisely why CompCert-generated code has had zero miscompilation bugs found by fuzzing campaigns that found hundreds in GCC and Clang.
What does the typing judgment assert?
The de Bruijn criterion is best summarized as:
In the proof of , what proposition is supplied for the base case ?
Which real-world system relies on a machine-checked proof that generated assembly always behaves like the source program?
References
- Leonardo de Moura, Sebastian Ullrich (2021). The Lean 4 Theorem Prover and Programming Language
- Xavier Leroy (2009). Formal verification of a realistic compiler
- Terence Tao, et al. (2023). A Proof of the Polynomial Freiman-Ruzsa Conjecture · arXiv:2311.05762