Introduction
引言
A Lean proof is trusted because a small program checks it. However, lots of people have misconceptions on it or hold fixed viewpoints like the hallucination in a small, outdated LLM.
Lean 证明之所以可信,是因为有一个小程序会检查它。然而很多人对此存在误解,或者持有过时的看法,就像一个过时的小参数 LLM 的幻觉。
On 20 November 2026, Levent Alpöge released a Lean proof of the Riemann Hypothesis and of GRH for Dirichlet L-functions: about 17 million lines, written with Claude. One day later the Lean and Mathlib communities certified that both the statement and the proof are correct. Nobody can read 17 million lines in a day, so what exactly did they check?
2026 年 11 月 20 日,Levent Alpöge 发布了黎曼猜想以及狄利克雷 L 函数广义黎曼猜想的 Lean 证明:约 1700 万行,与 Claude 合作完成。一天后,Lean 和 Mathlib 社区认证了命题和证明都是正确的。没有人能在一天内读完 1700 万行,那他们到底检查了什么?
These are my learning notes. I knew almost no Lean when I started.
这是我的学习笔记。开始学之前,我几乎不懂 Lean。
Propositions are types, proofs are programs
命题即类型,证明即程序
In Lean, a proof is a value, and the statement it proves is its type. Here is the smallest useful example:
在 Lean 里,证明是一个值,它所证明的命题就是它的类型。下面是一个最小的有用例子:
theorem and_swap (p q : Prop) (h : p ∧ q) : q ∧ p :=
⟨h.2, h.1⟩
I read it as a C++ function. The colon means “has type”.
我把它当作一个 C++ 函数来读。冒号的意思是“的类型是”。
| Lean |
Meaning |
C++ analogy |
(p q : Prop) |
p and q are any two propositions |
template parameters |
(h : p ∧ q) |
h is a proof of “p and q” |
an argument of type pair<P, Q> |
: q ∧ p |
the statement I claim |
the return type |
:= ⟨h.2, h.1⟩ |
the proof |
return {h.second, h.first}; |
A proof of “p and q” is a pair: h.1 proves p, h.2 proves q, and ⟨a, b⟩ builds a new pair. So the theorem is a function that swaps a pair.
“p 且 q”的证明是一个二元组:h.1 证明 p,h.2 证明 q,⟨a, b⟩ 构造一个新的二元组。所以这个定理就是一个交换二元组两项的函数。
“If A then B” is a function type. These two lines are the same theorem:
“如果 A 那么 B”是一个函数类型。下面两行是同一个定理:
theorem take_left (p q : Prop) (h : p ∧ q) : p := h.1
theorem take_left' (p q : Prop) : p ∧ q → p := fun h => h.1
This is the Curry-Howard correspondence:
这就是柯里-霍华德对应:
| Logic |
Programming |
| proposition |
type |
| proof |
program or value |
| A and B |
pair (A, B) |
| if A then B |
function A → B |
| checking a proof |
type checking |
What “correct” means
“正确”指的是什么
“Correct” means only this: the body has the type that was promised. The kernel is a small type checker. It does not understand the math.
“正确”的意思仅仅是:函数体的类型与声明的类型一致。内核是一个小型类型检查器,它并不理解数学。
theorem bad (p q : Prop) (h : p ∧ q) : p := h.2 -- type mismatch
h.2 has type q, but I promised p. A wrong proof is a program that does not compile.
h.2 的类型是 q,但我声明的是 p。错误的证明就是编译不通过的程序。
This explains why reviewers can skip the bodies of the intermediate lemmas:
这解释了为什么审查者可以跳过中间引理的证明体:
- The kernel type-checks every body against its statement.
-
A caller sees only a lemma’s statement, never its body, like a function signature in a header file.
-
内核会把每个证明体与它的命题逐一做类型检查。
- 调用者只能看到引理的命题,看不到它的证明体,就像头文件里的函数签名。
So the human job shrinks to reading the final statement and the definitions it mentions. For the Riemann Hypothesis, the final theorem targets a definition that already lived in Mathlib.
所以人的工作缩减为:阅读最终命题以及它提到的定义。对黎曼猜想来说,最终定理指向的是 Mathlib 中早已存在的定义。
What we still have to trust
我们仍需信任的东西
Three things remain, and together they are the trusted computing base, TCB.
还剩下三样东西需要信任,它们合起来称为可信计算基(TCB)。
| What I trust |
How it is checked |
| The statement says what I think it says |
Humans read it, plus every definition it mentions |
| The axioms are acceptable |
#print axioms shows only the three standard ones |
| The kernel has no bug |
Re-check the proof with an independent checker |
The second row exists because Lean has legal ways to skip a proof:
之所以有第二行,是因为 Lean 有合法的方式跳过证明:
theorem fake : 1 = 2 := sorry -- placeholder, compiles with a warning
axiom magic : 1 = 2 -- declared true with no proof
Both pass type checking. #print axioms lists every unproved assumption a theorem depends on, transitively. If lemma A uses sorry, B calls A, and the final theorem calls B, then sorryAx appears in the final list even though nobody opened A or B.
两者都能通过类型检查。#print axioms 会列出一个定理依赖的全部未证明假设,而且是传递的。如果引理 A 用了 sorry,B 调用 A,最终定理调用 B,那么即使没人打开过 A 或 B,sorryAx 也会出现在最终的列表里。
Everything else is outside the TCB: 17 million lines of proof bodies, tactics, and AI-written code. It can be unreadable and it does not matter.
其余一切都在 TCB 之外:1700 万行证明体、策略(tactic),以及 AI 写的代码。它们可以完全不可读,这都无关紧要。
The weak point is the first row. If the statement is subtly wrong, Lean happily verifies a proof of the wrong thing.
薄弱环节是第一行。如果命题写得有细微偏差,Lean 会照样验证通过,只不过证明的是一个错误的命题。
The three standard axioms
三条标准公理
Bare Lean is stricter than everyday math, and each standard axiom restores one habit that mathematicians already have.
不加公理的 Lean 比日常数学更严格,每条标准公理恢复一个数学家本来就有的习惯。
| Human habit |
Without the axiom |
Axiom |
| “A iff B, so I can replace A by B anywhere” |
A ↔ B and A = B are different, so no substitution |
propext |
| “1/2 and 2/4 are the same number” |
They are different pairs; nothing makes them equal |
Quot.sound |
| “Either true or false”, proof by contradiction |
p ∨ ¬p is not provable for an arbitrary p |
Classical.choice |
Function extensionality (two functions with equal outputs are equal) is not a fourth axiom. Lean derives it from Quot.sound.
函数外延性(输出处处相同的两个函数相等)不是第四条公理,Lean 从 Quot.sound 推导出它。
They are “standard” for two reasons. Ordinary set-theoretic math already assumes all three habits. And they are the only axioms Mathlib uses, so “only the three standard axioms” means “the same assumptions as all of Mathlib”.
它们被称为“标准”公理有两个原因。普通的集合论数学本来就默认这三个习惯。而且它们是 Mathlib 唯一使用的公理,所以“只用了三条标准公理”就等于“和整个 Mathlib 的假设相同”。
Universes and inaccessible cardinals
宇宙层级与不可达基数
Lean is as consistent as ZFC plus the existence of inaccessible cardinals, which is slightly more than ZFC. The reason is the ladder of universes.
Lean 与“ZFC 加上存在不可达基数”等一致,这比 ZFC 稍强一点。原因在于宇宙的阶梯。
Types have types too:
类型也有自己的类型:
#check 3 -- Nat
#check Nat -- Type
#check Type -- Type 1
#check Type 1 -- Type 2, and so on forever
The ladder exists because Type : Type would let a type talk about itself. Self-reference plus negation gives a contradiction, as in the barber paradox: the barber who shaves exactly those who do not shave themselves. In type theory the actual construction is Girard’s paradox. Once False is provable, everything is provable, and “the kernel accepted it” means nothing.
之所以需要阶梯,是因为 Type : Type 会让一个类型谈论它自己。自我指涉加上否定就会产生矛盾,正如理发师悖论:理发师只给那些不给自己刮胡子的人刮胡子。在类型论中,真正推出矛盾的构造是吉拉尔悖论。一旦能证明 False,就能证明任何命题,“内核接受了它”也就毫无意义。
The ladder cuts the self-reference, the same way “the barber is not a villager” does: to talk about Type you must stand one level higher.
阶梯切断了自我指涉,作用和“理发师不算村民”一样:要谈论 Type,你必须站到更高一层。
To model one universe in set theory, you need a set so large that every ordinary operation done inside it stays inside it. Its size is an inaccessible cardinal. ZFC cannot prove such a set exists, because ZFC’s tools are exactly those ordinary operations. Lean has infinitely many universes, so it needs one for each level.
要在集合论中给一层宇宙建模,需要一个大到在其中做任何常规运算都不会跑出去的集合。它的大小就是一个不可达基数。ZFC 无法证明这种集合存在,因为 ZFC 的工具恰恰就是这些常规运算。Lean 有无穷多层宇宙,所以每一层都需要一个。
Mario Carneiro’s thesis shows the match is exact: Lean is equiconsistent with ZFC plus n inaccessible cardinals for every finite n. This is the weakest kind of large cardinal assumption and is widely accepted, but that is a consensus and not a theorem.
Mario Carneiro 的博士论文证明了这种对应是精确的:对任意有限的 n,Lean 与“ZFC 加上 n 个不可达基数”等一致。这是最弱的一类大基数假设,被广泛接受,但这是共识,不是定理。
Constructive versus classical
构造性与经典
A constructive proof hands you the answer, so it can run as a program. A classical proof only guarantees the answer exists.
构造性证明把答案交到你手上,所以可以作为程序运行。经典证明只保证答案存在。
-- constructive: the value carries its witness
def root : {n : Nat // n * n = 49} := ⟨7, rfl⟩
#eval root.val -- 7
-- classical: "some n exists, do not ask which"
theorem ex : ∃ n : Nat, n * n = 49 := ⟨7, rfl⟩
noncomputable def pick : Nat := Classical.choose ex
#eval pick -- error
root is a pair of a number and a proof, and rfl is the proof that both sides compute to the same value. pick is a Nat that nobody can name: the choice axiom produced it with no computation. It is like saying “I can prove a key exists in this building” without holding the key.
root 是一个由数字和证明组成的二元组,rfl 是“两边计算结果相同”的证明。pick 是一个没人说得出是几的 Nat:它由选择公理给出,没有任何计算过程。就像说“我能证明这栋楼里有一把钥匙”,手里却没有钥匙。
The vocabulary around this idea:
与这个思想相关的术语:
| Term |
Meaning |
| CIC, Calculus of Inductive Constructions |
The type theory under Lean and Rocq |
| Constructive |
To prove something exists, you must build it |
| Canonicity |
A closed, axiom-free term of type Nat computes to an actual numeral |
| Existence property |
If ∃ x, P x is provable, some concrete t with P t is provable |
| Disjunction property |
If A ∨ B is provable, then A is provable or B is provable |
| Program extraction |
Delete the logical parts of a proof and keep runnable code |
| Computable |
The definition can be executed |
Three Lean-specific details. Lean has no separate extraction tool; it compiles definitions and erases proofs. ∃ lives in Prop and hides its witness, which is why root uses the subtype {n // ...}. And only Classical.choice makes a definition non-computable, because the other two axioms produce only proofs, which are erased.
三个 Lean 特有的细节。Lean 没有单独的程序提取工具,它直接编译定义并擦除证明。∃ 位于 Prop 中,会隐藏它的见证,所以 root 用的是子类型 {n // ...}。另外,只有 Classical.choice 会让定义变得不可计算,因为另外两条公理只产生证明,而证明会被擦除。
Elevator pitch
一段话总结
In Lean, a proposition is a type and a proof is a program of that type, so checking a proof is type checking, done by a small kernel. To trust a theorem I only need to trust three things: the statement, the three standard axioms, and the kernel, and that is why a 17-million-line AI-written proof can be accepted without anyone reading its body. The remaining risk is the statement itself, because Lean verifies a proof of whatever was written, even if it is not what was meant.
在 Lean 中,命题是类型,证明是该类型的程序,所以检查证明就是类型检查,由一个小内核完成。要信任一个定理,我只需信任三样东西:命题、三条标准公理和内核,这就是为什么一个 1700 万行、由 AI 写成的证明,不需要任何人阅读证明体就能被接受。剩下的风险在命题本身,因为 Lean 会验证写下来的任何命题,即使它不是作者的本意。