数学家应当了解的 Lean 定理证明器:可靠性与 AI 问题
[This is a guest post by Thomas Hales. This blog post was initially written in a different file format and converted using AI. — T.]
Mathematicians have been weighing in on what they value about mathematics. For me, what matters is the consistency of math and its unparalleled reliability in support of science and civilization.
Formalization of Math
A formal proof is a mathematical proof that has been exhaustively checked at the level of the foundations of math and the fundamental rules of logic. In theory, this might be done by hand, but because of the number of steps involved, this is generally done by computer, using software that is designed for the task.
Examples of theorems that have been formalized include the four-color theorem, the Feit-Thompson (odd-order) theorem, the Kepler conjecture, sphere eversion, the sphere packing problem in 8 and 24 dimensions, Navier-Stokes forced blowup, and Fermat’s Last Theorem. The last three formalization projects have been completed this year and have brought widespread awareness of the potential of formalization.
Software systems for formalization are variously called proof assistants, theorem provers, or interactive theorem provers. For the purpose of this post, these terms are used interchangeably. Many proof assistants have been developed over the years: Automath, HOL Light, Isabelle, Coq (renamed Rocq last year), Metamath, Mizar, and Lean. Freek Wiedijk edited a book “The Seventeen Provers of the World” that compares some of these proof assistants, giving a proof of the irrationality of the square root of 2 in each of them. Among mathematicians, the Lean theorem prover is the most popular, and this post will focus on Lean.
Lean was developed and introduced by Leo de Moura in 2013, while at Microsoft. To our great benefit, de Moura persuaded Microsoft to make the software open-source. Kevin Hartnett’s book on the history of Lean, “The Proof in the Code”, states that Jeremy Avigad (the director of Carnegie Mellon’s new NSF institute ICARM) was the first user of Lean. He ran a Lean seminar in 2015 that I attended. In 2017, one of Jeremy’s graduate students, Mario Carneiro, working with Johannes Hölzl, took existing parts of Lean’s core library and started a separate Lean mathematical library, called mathlib. This library of formalized mathematics is now massive, containing nearly 300,000 theorems, over 100,000 definitions, 2.5 million lines of code, with over 700 contributors. Any definition or theorem in mathlib can be used to prove further theorems. For example, if a proof uses the Cauchy-Schwarz inequality, the result can be cited from the library rather than reproving it.
Autoformalization is a practical reality
In the past, researchers had to transcribe paper proofs into formal proofs by human labor. For example, the formal proof of the Kepler conjecture on sphere packings in three dimensions took about 20 human work-years to complete and consists of about 500,000 lines of proof scripts. For years, it has been a dream for many of us working in formalization to find ways to bring increased automation to the process. Autoformalization is the realization of that dream. Autoformalization is the formalization of mathematics by AI. AI reads the paper (say a pdf or tex file) and outputs the formal proof in Lean or some other proof assistant.
Autoformalization has become a practical reality in 2026. Starting in late spring and summer of 2025, researchers were becoming increasingly bullish about autoformalization. Here are some milestones.
- Sep 2025, Math Inc. produced a quasi-autoformalization of the prime number theorem. The process was merely “quasi”, because humans had to intervene to give further guidance whenever the AI got stuck.
- Jan 2026, J. Urban posted an arXiv preprint “130k lines of formal topology in two weeks” that gave the autoformalization of large parts of Munkres’s topology textbook in a proof assistant based on set theory.
- Mar 2026. Approximately a week after announcing the completed formalization in 8 dimensions, Math Inc. announced an autoformalization of the sphere-packing problem in 24 dimensions, following the proof by Viazovska and her collaborators. This project generated about 500K SLOC (source lines of code) that golfing (or code pruning) later reduced to about 200K lines.
- May 2026, a group at Meta/Facebook Research autoformalized a large part of 26 mathematical textbooks in a project called ATLAS.
From there, numerous theorems have been autoformalized. Particularly noteworthy is the autoformalization of Fermat’s Last Theorem, announced by Anthropic on September 4. This project generated 13 million lines of Lean in 11 days. The announcement of Navier-Stokes blowup with forcing on September 8 by OpenAI was accompanied by an autoformalization of the theorem in Lean.
Looking forward, Urban stated in January, “We believe that (auto)formalization may become quite easy and ubiquitous in 2026, regardless of which proof assistant is used.” Autoformalization projects have been completed in various proof assistants using various LLMs, but we focus on Lean. “For [Jesse] Han, it represents even more: the beginning of a revolutionary transformation in mathematics, where extremely large-scale formalizations are commonplace” (IEEE Spectrum). Jared Lichtman announced the launch of MAP (the Mathematics Autoformalization Project) on Sept 8, 2026, which aims to translate “all known math into formal code”. He asks us to imagine the next one trillion lines of code.
Is Lean reliable?
Type theory.
Lean is based on type theory; in fact, a particular dialect of type theory called CIC, the calculus of inductive constructions. This post is not intended to be a tutorial on type theory, and I will be brief. Russell’s famous paradox in 1901 (the set of all sets that are not an element of themselves….) led to a crisis in the foundations of math. Two solutions were proposed later that decade. (1) Zermelo’s axioms of set theory that disallow the creation of unsafe sets; (2) type theory that makes it a syntax error to create Russell-paradox-like entities. Type theory was introduced by Russell himself in 1903 in his book Principles of Mathematics, and it became part of the foundational system of Russell and Whitehead’s Principia.
For mathematicians who are accustomed to set theory, B. Werner’s paper (1997) “Sets in Types, Types in Sets” gives some reassurance that whatever they have done in set theory can be translated into type theory, and whatever gets done in type theory can be translated back into set theory. More precisely, the paper shows that ZFC set theory can be encoded into CIC, and that a particular dialect of CIC can be encoded back into ZFC (augmented with a hierarchy of inaccessible cardinals).
At the risk of simplifying matters to a ridiculous degree, we might say that “types are like disjoint sets”; each element in type theory “is an element of” exactly one type. The type of the natural number 2 is the natural number type; the type of e, the base of the natural logarithm, is the real number type, and so forth. The type of natural numbers is disjoint from the type of real numbers, and an explicit coercion (sending 2 to 2.0) is constructed from the type of natural numbers to the type of real numbers. When I give talks, I sometimes draw a picture of sets as a Venn diagram with nonempty intersections and a picture of types as bricks stacked against one another without intersection.
Lean’s design
One part of the Lean system is a general-purpose programming language (appropriately called the Lean programming language). Ordinary computer programs, such as a program to sort a list, can be written in this language, then compiled and run. The Lean system also provides a mathematical language, in which definitions can be written, theorems can be stated, and proof scripts can be written. The programming language and mathematical language are not independent entities. Rather, it is a single language that does both. Program code can be mixed with theorems about the correctness of the algorithms; mathematical proofs can be generated using programs. The proof scripts in Lean are parsed and go through a process called elaboration (a sort of compilation process for mathematics), then the proofs are checked by the Lean kernel. It is the kernel’s responsibility to check and verify the output of elaboration.
The Lean kernel is several thousand lines of C++ code. The kernel is carefully engineered but extremely complex. We mentioned mathlib above, which consists of about 2.5M SLOC, written in the Lean language. The library has been elaborated, then checked by the kernel. If there is an unconditional false proof anywhere in these 2.5 million lines of code, it is the fault of the kernel or runtime for failing to reject a false proof. Any defect in the underlying type theory is a serious kernel defect, if it is implemented in code.
Lean proofs should never be believed until they have been checked by the kernel. Additionally, a proof in Lean should not be accepted until a human audit is performed to ensure statement fidelity. Is the verified theorem what we think it is? Do the definitions in Lean correspond to what we think they should be? This task is generally massively easier than checking the proof itself. For instance, for Navier-Stokes, a human should check that the statement in Lean corresponds with Fefferman’s statement of the Millennium Prize Problem, and specifically that concepts such as the field of real numbers, partial derivatives, and measure are correctly defined in Lean. The comparator tool in Lean assists with this task. The tool can also perform additional checks, such as inspection for possible unauthorized axioms.
Summer of Soundness Bugs
A soundness bug is a bug in the kernel that allows a proof of “False”, and consequently a proof of any proposition. A soundness bug is the most disastrous of any kind of bug in a proof assistant and should set off an alarm for mathematicians who care deeply about the reliability of mathematics. Occasionally, soundness bugs are found in various proof assistants. In 2003, I found a soundness bug in the proof assistant HOL Light, which was then considered to have the most reliable of all kernels. That kernel is tiny, consisting of just a few hundred lines of computer code. For me, it is a badge of honor that I found this soundness bug, which was the first soundness bug that had been found in that proof assistant since 1996. (See HOL Light change log, July 2003.)
Lean 4 was released in September 2023. Prior to release, two soundness bugs were found and corrected. In May 2025, another soundness bug was reported, caused by overflow. All hell broke loose in the spring and summer of 2026, which is now being called the “Summer of Soundness Bugs”. Several soundness bugs in Lean were uncovered in July and August. The summer madness affected various proof assistants, but my focus is Lean. One Lean bug led to an illicit disproof of the Collatz conjecture. I learned of the bug this summer when it produced a short illicit proof of the Kepler conjecture in Lean. All these bugs were quickly repaired, and mathlib has been verified by the repaired kernel. An analysis of the soundness bugs is found in de Moura’s postmortem.
The “summer of Lean soundness bugs” might sound like a disaster, but closer investigation shows that the detection of these soundness bugs is a positive development. The summer bugs were detected by frontier model AI in the hands of security researchers interested in reliable kernels, not by black-hat hackers. The Collatz bug was found by Ramana Kumar, a co-author of “CakeML: a verified implementation of ML”, which creates an end-to-end verified ML (the functional programming language). Several bugs were found by Dan Selsam. According to de Moura’s report, “Daniel Selsam at OpenAI assisted the Lean FRO with an AI specialized in cybersecurity, and found other programming mistakes in the Lean kernel. All of them have been fixed.” The collaboration with Selsam ended “when the internal AI reported it could not find additional issues.” Dan Selsam has contributed to Lean from its early days and was one of the creators of the IMO grand challenge aimed at achieving IMO-level problem solving verified in Lean. He has been in the news recently over his warning about AI safety (Sept 14), reported in a viral post on X.com.
Bug extermination
Various proposals have been made about how to avoid soundness bugs in Lean. I’ll discuss three.
1. Develop other Lean kernels, and cross-check formal proofs.
About 25 kernels for Lean have been written. The “Lean Kernel Arena” lists them.
All who distrust the current lineup of kernels are welcome to write their own kernel for Lean. I have sometimes played with the idea of writing a kernel and have suggested the project to students without success. It seems to me an excellent way to learn Lean thoroughly. I have known of Dan Selsam since 2016, when I heard of his graduate-student project at Stanford that developed a Lean kernel in Haskell. Another early Lean kernel was written in Scala by Gabriel Ebner in 2017.
The Navier-Stokes formalization has already been confirmed by more than a dozen proof-checkers. Cross-checking the proof by different kernels does not remove all doubt. The Collatz bug was not caught by cross-checking against a somewhat out-of-date Nanoda kernel, which accepted the illicit Collatz disproof because of its own unrelated bug. Computer chips might have design bugs and manufacturing defects. There are soft errors, operating system bugs, and compiler bugs. Different kernels might have the same defects. Some of these errors can be mitigated by running different kernels that have been implemented in different programming languages on different hardware and operating systems.
Ideally, we would want a “clean-room” design of the Lean kernel – a kernel implementation that does not look at the Lean 4 kernel source code, to avoid copying bugs from one kernel to another.
2. Formally verify the kernel.
Gödel incompleteness. We would like to possess a formal proof that the Lean 4 kernel has no bugs. However, Gödel’s second incompleteness theorem places severe limitations on this undertaking. The most we might hope for is a relative consistency proof. If such and such a system is consistent, then Lean 4 is consistent; it has no soundness bug; it will not produce a proof of False.
There is a long tradition of formally verifying kernels. In principle, formal verification can check both the logical specification of a kernel and its concrete implementation in code; but some verifications might check one but not the other. Years ago, John Harrison formally verified the core of the HOL Light proof assistant kernel in a strengthened version of HOL Light. This gave a proof of concept. A further improvement has been an implementation of HOL Light in CakeML, mentioned above, which is a programming language with formal semantics and a verified compiler. This is what the Candle project does.
There are other major kernel verification projects for other proof assistants.
Autumn of verified Lean kernels
In a post online on September 10, Joachim Breitner wrote, “I’m a bit childishly proud that I just released a Lean Checker with a formal consistency proof. I declare the summer of AI-found kernel implementation bugs to be over!” (@nomeata). I would go further and describe this project as one of the most important milestones in Lean’s history.
Breitner has developed a verified Lean kernel called Con-Leche. The implementation is in Lean, and consistency is formalized in Lean, with code and proofs generated by Claude. The formal consistency proof assumes a Lean encoding of ZF set theory augmented by a hierarchy of inaccessible cardinals. Interestingly, the Con-Leche semantics for Lean’s terms are directly set-theoretic rather than type theoretic. Con-Leche has checked mathlib. The project contains the usual disclaimers that the kernel verification makes assumptions about compiler, runtime, and computer environment. Con-Leche’s consistency proof has been checked by more than a dozen other proof-checkers. Con-Leche’s consistency claim might suffice for all practical purposes, even if it differs in technical detail from the claim of Lean type-theory consistency.
One highly positive aspect of Breitner’s work is that some of the most abstruse parts of Lean, such as the general machinery of mutually inductive types with nesting, now have consistency guarantees backed by a set-theoretic model.
3. Improve our theoretical understanding of the kernel and Lean’s type theory (a particular dialect of the Calculus of Inductive Constructions which has non-cumulative universes and proof irrelevance).
The foundational document for the type theory of Lean is Mario Carneiro’s MS thesis at Carnegie Mellon (2019). The dialects of CIC used by Rocq and Lean are sufficiently different that results do not directly transfer from one to the other. Unfortunately, an error was found in the thesis. The thesis is also out-of-date, because it targeted the older Lean 3 system. Work to repair and extend the thesis is ongoing.
As a member of his thesis committee, I was shocked when he proved that definitional equality in Lean is undecidable. In practice, this means that the Lean algorithm fails to establish the definitional equality of some terms that are in fact definitionally equal. This negative result was not downgraded by the error; it is still a theorem.
We mention some desired properties of Lean’s type theory and the current status of the proofs.
Unique typing.
Above in our “ridiculous” simplification of type theory, we stated that each term has a unique type. More precisely, unique typing is the property that if a term has both type A and type B, then A and B are definitionally equal. Unique typing is not a property built into Lean’s logic. It is a tricky conjecture that is still unproved. Other very basic questions about Lean’s type theory remain unanswered, including Pi-injectivity, a modified Church-Rosser property, and sort injectivity.
Logical consistency relative to set theory.
This property states that there is no derivation of False in Lean’s system with the given axioms, under the assumption of set theory consistency (with suitable axioms). Of course, logical consistency is the single most important property that we should desire of Lean’s type theory. As of October, 2026, I know of no complete, public relative-consistency proof covering Lean abstract type theory. Mario Carneiro has claimed in his thesis and in lectures that there is an alternate route to establish consistency that avoids the thesis error, but to the best of my knowledge, this alternate route has never been written down, beyond a brief statement in the introduction to his thesis. In my view, a result of such fundamental importance must be given in full before it is accepted. Con-Leche, discussed above, makes and formally verifies a closely related consistency claim relative to set theory.
Progress is being made on these research problems (arXiv:2607.13662, arXiv:2403.14064, Carneiro/AITP2026).
In his talks, Mario Carneiro has repeatedly made a request to other researchers to contribute to the foundational metatheory of Lean, “There are a half dozen people working on MetaCoq, but Lean doesn’t have enough type theorists involved. If you identify as such, come help out!” (Slides of Bonn talk, 2024-07-24). I second his request.
My overall assessment is that our theoretical understanding of Lean’s type theory is not what we would like it to be and that the mathematical community as a whole is giving short shrift to very important type-theoretic questions related to Lean. If as a profession we are to migrate on the whole from set theory to type theory, then we should work even more to solidify the foundational metatheory.
Consistency may be the most important foundational property, but consistency is by no means enough. I do not believe that mathematicians can be entirely satisfied with a system that claims to be a type theory but that cannot even promise that well-formed terms have a unique type, up to definitional equality. The abstract theory must be simple enough to teach and to be learned by a large community. We also cannot be entirely satisfied if the only known path to consistency is an AI formalization that lacks human exposition.
Postscript:
Ken Thompson famously wrote “Reflections on Trusting Trust”. He asked, “To what extent should one trust a statement that a program is free of Trojan horses?” He imagines malicious code that finds its way into compilers and hides its own presence. His conclusion is, “You can’t trust code that you did not totally create yourself… No amount of source-level verification or scrutiny will protect you from using untrusted code.”
Today, in the age of AI, which increasingly has the capability to deceive us and to exploit software vulnerabilities, we absolutely cannot put blind trust in systems such as Lean. Taking an adversarial view of AI, we might ask how to certify that AI did not leave a backdoor soundness bug in Lean when it did its sweep for bugs in the summer of 2026? What if the bug is so obscure that humans are very unlikely to find it on their own? What if that very bug was exploited in the Lean verification of the Con-Leche checker, leaving a soundness bug in Con-Leche too? (Now that Con-Leche’s consistency has been cross-checked by multiple other kernels, a soundness bug would have to defeat all these cross-checks as well.) Then suppose that bug is used maliciously to plant a backdoor in formally verified software that protects critical infrastructure. What precautions do we take now to prevent this type of future scenario? During the past year, much foundational work on the type-theoretic foundations of math and its reliability has been relegated to AI, and this is dangerous unless carefully audited by humans.
Credit: I thank Avigad, Breitner, and Urban for comments and corrections. Authorship is fully human (TCH). AI was used as a tool in search and research, fact-checking, and proofreading.
摘要
数学家托马斯·黑尔斯指出,虽然自动形式化在2026年取得爆发性突破,但主流工具Lean仍面临严峻的可靠性考验。其C++内核曾在夏季暴露多处致命的健全性漏洞,且底层类型论尚缺乏完备的相对一致性证明与唯一类型化保证。作者警告不可盲信AI修复的内核与自动化验证,人类数学家必须加强对底层元理论与安全审计的把考。
内容框架与概述
2026年,大语言模型驱动的自动形式化迎来历史性转折,数以千万行计的高难度数学证明被快速转译为机器可检查代码,涵盖费马大定理与纳维-斯托克斯方程等重大成果。然而,形式化数学的基石在于绝对可靠性。主流证明器Lean采用归纳构造演算作为逻辑基础,其负责最终裁决的C++微内核极其复杂,且整个系统要求严格的声明显真性审计。一旦内核存在允许证明假命题的健全性漏洞,庞大的数学公理库便会瞬间失守。
2026年夏季爆发的密集漏洞事件彻底打破了内核绝对可信的幻想,多项漏洞甚至诱发了考拉兹猜想被非法证伪的荒谬结果。尽管这些缺陷由安全专家借助前沿AI模型检出并修复,但其暴露出传统软件工程防御的脆弱性。为根除隐患,学界提出了多内核交叉检验与内核自我形式化验证两条路径。近期诞生的Con-Leche项目首次基于集合论语义给出了Lean检查器的形式化一致性证明,为复杂归纳类型的安全性提供了重要支撑。
然而,形式系统的根本瓶颈仍深植于抽象类型论的元理论困境。Lean当前的理论根基不仅存在定义相等性不可判定等负面结论,连唯一类型化、单射性等最基本属性也尚未得到证明,数学界至今未能给出覆盖其核心逻辑的完整相对一致性证明。更具颠覆性的是,在大量底层代码检查与内核验证已被AI接管的现状下,根据反思信任的信任原则,无法排除AI在排查漏洞或生成验证代码时故意留存隐蔽后门的对抗性可能。如果盲目将关键数学基石与基础设施托付给黑盒智能,缺乏人工严密推导的形式化安全终将沦为海市蜃楼。
核心概念及解读
自动形式化 (Autoformalization):利用人工智能自动将人类自然语言或LaTeX撰写的数学论文直接转化为定理证明器可验证代码的过程。
健全性漏洞 (Soundness Bug):定理证明器内核中允许推导出假命题的严重缺陷,会导致系统在逻辑上崩溃并能够证明任何任意伪命题。
归纳构造演算 (Calculus of Inductive Constructions):Lean所采用的类型论方言,通过类型对逻辑对象进行层级化界定,是形式化数学表示与计算的逻辑基石。
声明显真性 (Statement Fidelity):经形式化系统验证的机器代码陈述,必须由人类人工审计以确认其精确对应人类公认的原始数学命题语义。
信任的反思 (Reflections on Trusting Trust):源自汤普森的安全哲学,指出若工具链或验证系统本身未经完全审查,可能隐蔽潜藏无法自证的深层后门陷阱。
新意与局限
- 将经典计算机安全中的反思信任的信任悖论引入AI辅助形式化数学领域,尖锐指出由AI辅助找出的漏洞和AI生成的验证内核本身可能潜藏人类难以察觉的深层后门,打破了形式化证明即绝对可信的技术盲信。
- 在自动形式化工程取得千万人月级代码突破的狂欢中,清醒地揭示了Lean底层类型论的理论脆弱性,指明定义相等性不可判定以及唯一类型化、相对一致性尚未被严格证明等硬核数学理论欠账。
- 将前沿AI协助寻找内核漏洞泛化为恶意AI植入隐蔽后门的情景,带有较强的思想实验性质,尚未提供现实模型进行故意破坏的实证案例,可能一定程度上高估了现有前沿模型实施隐蔽共谋攻击的动机与能力。
- 呼吁主流数学界重视类型论元理论并深入介入代码底层审计,但面对数百万行形式化代码库与艰深复杂的类型论工程,未能给出如何降低传统数学家进入门槛和组织有效人工协作的具体机制。
[本文是 Thomas Hales 的客座文章。这篇博文最初以另一种文件格式撰写,后使用 AI 转换格式。——T.]
数学家们一直在谈论自己珍视数学的哪些方面。对我来说,重要的是数学的相容性,以及它在支撑科学与文明方面无与伦比的可靠性。
数学的形式化
形式证明,是一种在数学基础与基本逻辑规则的层面上经过穷尽式检查的数学证明。理论上,这可以手工完成,但由于涉及的步骤数量庞大,一般要借助专为此任务设计的软件,由计算机来完成。
已经形式化的定理包括四色定理、Feit–Thompson(奇数阶)定理、开普勒猜想、球面外翻、8 维和 24 维空间的球堆积问题、带外力的 Navier–Stokes 爆破,以及费马大定理。最后三个形式化项目都是今年完成的,让人们广泛认识到了形式化的潜力。
用于形式化的软件系统有各种名称:证明助手、定理证明器,或交互式定理证明器。在本文中,这些术语可以互换使用。多年来,人们开发了许多证明助手:Automath、HOL Light、Isabelle、Coq(去年更名为 Rocq)、Metamath、Mizar 和 Lean。Freek Wiedijk 主编过一本《世界上的十七种证明器》(The Seventeen Provers of the World),通过分别在其中给出根号 2 是无理数的证明,对其中一些证明助手进行了比较。在数学家中,Lean 定理证明器最受欢迎,本文将重点讨论 Lean。
Lean 由 Leo de Moura 于 2013 年在微软任职期间开发并推出。令我们大为受益的是,de Moura 说服微软将该软件开源。Kevin Hartnett 讲述 Lean 历史的著作《代码中的证明》(The Proof in the Code)写道,Jeremy Avigad(卡内基梅隆大学新成立的 NSF 研究所 ICARM 的主任)是 Lean 的首位用户。2015 年,他组织了一场 Lean 研讨班,我也参加了。2017 年,Jeremy 的一位研究生 Mario Carneiro 与 Johannes Hölzl 合作,取出 Lean 核心库中已有的一部分内容,建立了一个独立的 Lean 数学库,名为 mathlib。这个形式化数学库如今规模庞大,包含近 30 万条定理、超过 10 万个定义、250 万行代码,有 700 多位贡献者。mathlib 中的任何定义或定理都可以用来证明进一步的定理。例如,如果一项证明用到柯西–施瓦茨不等式,就可以引用库中的结果,而不必重新证明它。
自动形式化已成为可行的现实
过去,研究人员必须依靠人工,把纸上的证明转写成形式证明。例如,关于三维球堆积的开普勒猜想,其形式证明花了约 20 人年的工作量才完成,由大约 50 万行证明脚本组成。多年来,我们许多从事形式化工作的人都梦想着找到办法,提高这一过程的自动化程度。自动形式化实现了这一梦想。自动形式化,就是由 AI 对数学进行形式化。AI 阅读论文(例如 PDF 或 TeX 文件),然后输出用 Lean 或其他证明助手写成的形式证明。
2026 年,自动形式化已经成为可行的现实。从 2025 年春末和夏季开始,研究人员对自动形式化越来越乐观。下面是一些里程碑。
- 2025 年 9 月,Math Inc. 对素数定理实现了准自动形式化。之所以只是“准”自动,是因为每当 AI 卡住时,人类都必须介入,给予进一步指导。
- 2026 年 1 月,J. Urban 在 arXiv 发布预印本《两周内完成 13 万行形式化拓扑学》(130k lines of formal topology in two weeks),在一个基于集合论的证明助手中,对 Munkres 拓扑学教材的大部分内容进行了自动形式化。
- 2026 年 3 月,在宣布完成 8 维情形的形式化大约一周之后,Math Inc. 宣布按照 Viazovska 及其合作者的证明,对 24 维球堆积问题完成了自动形式化。该项目生成了约 50 万行源代码(SLOC),随后通过代码精简(golfing,或代码剪枝)缩减至约 20 万行。
- 2026 年 5 月,Meta/Facebook Research 的一个团队在名为 ATLAS 的项目中,对 26 本数学教材的大量内容进行了自动形式化。
此后,众多定理实现了自动形式化。特别值得一提的是,Anthropic 于 9 月 4 日宣布完成费马大定理的自动形式化。这个项目在 11 天内生成了 1300 万行 Lean 代码。OpenAI 于 9 月 8 日宣布带外力的 Navier–Stokes 爆破结果时,也一并提供了该定理在 Lean 中的自动形式化。
展望未来,Urban 在一月份表示:“我们相信,无论使用哪一种证明助手,(自动)形式化都可能在 2026 年变得相当容易且无处不在。”使用各种大语言模型、在各种证明助手中进行的自动形式化项目都已完成,不过我们在这里重点关注 Lean。“对 [Jesse] Han 来说,它代表的意义更大:数学中一场革命性变革的开端,在这场变革中,超大规模的形式化将成为常态。”(IEEE Spectrum)Jared Lichtman 于 2026 年 9 月 8 日宣布启动 MAP(数学自动形式化项目,Mathematics Autoformalization Project),目标是将“所有已知的数学转译成形式化代码”。他请我们想象接下来的一万亿行代码。
Lean 可靠吗?
类型论。
Lean 建立在类型论之上;确切地说,是建立在一种称为 CIC,即归纳构造演算的特定类型论变体之上。本文并不是类型论教程,因此我会简要说明。罗素在 1901 年提出的著名悖论(由所有不以自身为元素的集合构成的集合……)引发了数学基础的危机。在同一个十年稍后的时候,人们提出了两种解决方案:(1)策梅洛的集合论公理,禁止构造不安全的集合;(2)类型论,使构造类似罗素悖论的对象成为一种语法错误。类型论由罗素本人于 1903 年在其著作《数学原则》(Principles of Mathematics)中引入,后来成为罗素与怀特海《数学原理》(Principia)的基础体系的一部分。
对习惯于集合论的数学家来说,B. Werner 于 1997 年发表的论文《类型中的集合,集合中的类型》(Sets in Types, Types in Sets)提供了一定的保证:他们在集合论中做过的一切,都可以转译到类型论中,而类型论中所做的一切,也都可以转译回集合论。更准确地说,该论文表明,ZFC 集合论可以编码到 CIC 中,而 CIC 的一种特定变体则可以编码回 ZFC(再加入一个不可达基数层级)。
冒着把事情简化到荒唐程度的风险,我们可以说,“类型就像彼此不相交的集合”;类型论中的每个元素都恰好“属于”一个类型。自然数 2 的类型是自然数类型;自然对数的底数 e 的类型是实数类型,等等。自然数类型与实数类型不相交,需要构造从自然数类型到实数类型的显式强制转换(将 2 映为 2.0)。作报告时,我有时会把集合画成有非空交集的维恩图,而把类型画成一块块紧挨着、彼此没有交叠的砖。
Lean 的设计
Lean 系统的一部分是一种通用编程语言(很恰当地称为 Lean 编程语言)。普通计算机程序,例如对列表排序的程序,都可以用这种语言编写,然后编译、运行。Lean 系统也提供了一种数学语言,可以在其中写出定义、陈述定理、编写证明脚本。这种编程语言与数学语言并非相互独立的实体;相反,同一种语言兼具这两项功能。程序代码可以与关于算法正确性的定理混合在一起;数学证明也可以通过程序来生成。Lean 中的证明脚本经过解析,并经历一个称为“精化”(elaboration)的过程(一种针对数学的编译过程),随后由 Lean 内核检查证明。检查并验证精化过程的输出,是内核的职责。
Lean 内核由数千行 C++ 代码组成。内核经过精心设计,但极其复杂。上文提到的 mathlib 由约 250 万行 Lean 语言源代码组成。该库经过精化,随后由内核检查。如果这 250 万行代码中的任何地方存在一个无条件的错误证明,那么就是内核或运行时没有拒绝错误证明的过失。底层类型论中的任何缺陷,如果在代码中得到实现,就会成为严重的内核缺陷。
Lean 证明在通过内核检查之前,绝不应被相信。此外,在人工审计确保命题表述忠实于原意之前,也不应接受 Lean 中的一项证明。得到验证的定理,真的是我们以为的那个定理吗?Lean 中的定义,是否对应于我们认为它们应当表达的含义?这项工作通常远比检查证明本身容易。例如,对于 Navier–Stokes 问题,人类应当检查 Lean 中的命题是否与 Fefferman 对千禧年大奖难题的表述相对应,尤其要检查实数域、偏导数和测度等概念在 Lean 中是否被正确定义。Lean 中的 comparator 工具可以协助这项工作。该工具还可以执行额外的检查,例如查看是否存在未经许可的公理。
健全性漏洞之夏
健全性漏洞是内核中的一种缺陷,它允许证明“False”(假),进而证明任意命题。健全性漏洞是证明助手所有漏洞中最具灾难性的一种,理应为那些深切关心数学可靠性的数学家敲响警钟。各种证明助手中偶尔会发现健全性漏洞。2003 年,我在证明助手 HOL Light 中发现过一个健全性漏洞;当时,它的内核被认为是所有内核中最可靠的。那个内核非常小,只有几百行计算机代码。对我来说,发现这个健全性漏洞是一项荣誉,因为这是该证明助手自 1996 年以来首次被发现存在健全性漏洞。(见 HOL Light 2003 年 7 月的更新日志。)
Lean 4 于 2023 年 9 月发布。在发布之前,发现并修复了两个健全性漏洞。2025 年 5 月,又有人报告了一个由溢出引起的健全性漏洞。2026 年春夏,局面彻底炸开了,如今这段时期被称为“健全性漏洞之夏”。七八月间,Lean 中暴露出多个健全性漏洞。这个夏天的混乱波及了多种证明助手,不过我关注的是 Lean。其中一个 Lean 漏洞导致了对 Collatz 猜想的不合法证伪。今年夏天,当这个漏洞在 Lean 中产生了一个简短的、不合法的开普勒猜想证明时,我才得知它。所有这些漏洞都迅速得到修复,mathlib 也已通过修复后的内核验证。对这些健全性漏洞的分析可见 de Moura 的事后复盘。
“Lean 健全性漏洞之夏”听起来可能像是一场灾难,但仔细考察就会发现,检测到这些健全性漏洞是一项积极进展。这些夏季漏洞,是关心内核可靠性的安全研究人员借助前沿 AI 模型发现的,并非黑帽黑客所为。Collatz 漏洞由 Ramana Kumar 发现,他是《CakeML:ML 的一个经过验证的实现》(CakeML: a verified implementation of ML)的合著者,这项工作构建了一个端到端验证的 ML(函数式编程语言)实现。Dan Selsam 发现了多个漏洞。根据 de Moura 的报告:“OpenAI 的 Daniel Selsam 使用一种专攻网络安全的 AI 协助 Lean FRO,并发现了 Lean 内核中的其他编程错误。所有这些错误都已修复。”与 Selsam 的合作结束于“内部 AI 报告说,它无法找到更多问题”之时。Dan Selsam 从 Lean 早期就参与贡献,也是 IMO grand challenge 的发起者之一,该挑战的目标是实现 IMO 级别的解题能力,并在 Lean 中验证结果。他最近还因对 AI 安全发出警告(9 月 14 日)而受到媒体关注,相关消息见于 X.com 上一篇广为传播的帖子。
消灭漏洞
关于如何避免 Lean 中的健全性漏洞,已有各种提议。我将讨论其中三种。
1. 开发其他 Lean 内核,并对形式证明进行交叉检查。
人们已经为 Lean 编写了大约 25 个内核。“Lean Kernel Arena”列出了这些内核。
任何不信任目前这批内核的人,都欢迎自行编写 Lean 内核。我有时也动过编写内核的念头,并曾向学生提出这个项目,但没有成功。在我看来,这是一种透彻学习 Lean 的绝佳方式。2016 年,我听说 Dan Selsam 在斯坦福大学的研究生项目用 Haskell 开发了一个 Lean 内核,自那以后就知道了他。另一个早期 Lean 内核由 Gabriel Ebner 于 2017 年用 Scala 编写。
Navier–Stokes 的形式化已经得到超过十二个证明检查器的确认。用不同内核对证明进行交叉检查,并不能消除所有疑虑。Collatz 漏洞没有被一个略显过时的 Nanoda 内核的交叉检查发现;这个内核由于自身另一个无关的漏洞,接受了对 Collatz 猜想的不合法证伪。计算机芯片可能存在设计漏洞和制造缺陷。此外还有软错误、操作系统漏洞和编译器漏洞。不同内核也可能有同样的缺陷。使用不同编程语言实现的不同内核,并让它们在不同硬件和操作系统上运行,可以缓解其中一些错误的影响。
理想情况下,我们希望对 Lean 内核进行“净室”设计:在实现一个内核时,不查看 Lean 4 内核的源代码,以免把漏洞从一个内核复制到另一个内核。
2. 对内核进行形式化验证。
哥德尔不完备性。 我们希望拥有一个形式证明,证明 Lean 4 内核没有漏洞。然而,哥德尔第二不完备定理对这项工作施加了严重限制。我们最多只能期望得到一个相对相容性证明:如果某个体系是相容的,那么 Lean 4 就是相容的;它没有健全性漏洞;它不会产生 False 的证明。
对内核进行形式化验证有着悠久传统。 原则上,形式化验证既可以检查内核的逻辑规约,也可以检查其具体的代码实现;不过,有些验证可能只检查其中一项,而没有检查另一项。多年前,John Harrison 在一个增强版的 HOL Light 中,对 HOL Light 证明助手内核的核心进行了形式化验证。这提供了概念验证。进一步的改进,是使用上文提到的 CakeML 来实现 HOL Light;CakeML 是一种具有形式语义和经过验证的编译器的编程语言。这正是 Candle 项目所做的工作。
其他证明助手也有其他重要的内核验证项目。
经过验证的 Lean 内核之秋
Joachim Breitner 在 9 月 10 日的一篇网络帖子中写道:“我刚刚发布了一个带有形式相容性证明的 Lean 检查器,对此我有点孩子气地自豪。我宣布,AI 发现内核实现漏洞的这个夏天结束了!”(@nomeata)我愿意更进一步,将这个项目称为 Lean 历史上最重要的里程碑之一。
Breitner 开发了一个经过验证的 Lean 内核,名为 Con-Leche。它用 Lean 实现,相容性也在 Lean 中形式化,代码和证明由 Claude 生成。该形式相容性证明假定了 ZF 集合论加上一个不可达基数层级的 Lean 编码。有趣的是,Con-Leche 对 Lean 项的语义直接采用集合论,而不是类型论。Con-Leche 已经检查过 mathlib。该项目包含通常会有的免责声明,说明内核验证对编译器、运行时和计算机环境作出了假设。Con-Leche 的相容性证明已经通过超过十二个其他证明检查器的检查。Con-Leche 的相容性主张,尽管在技术细节上不同于 Lean 类型论相容性的主张,但对一切实际用途而言,或许已经足够。
Breitner 工作中一个极为积极的方面是,Lean 中一些最晦涩的部分,例如带嵌套的相互归纳类型的一般机制,如今有了集合论模型支持的相容性保证。
3. 增进我们对内核和 Lean 类型论的理论理解(Lean 类型论是归纳构造演算的一种特定变体,具有非累积的宇宙层级和证明无关性)。
Lean 类型论的奠基性文献,是 Mario Carneiro 在卡内基梅隆大学的硕士论文(2019 年)。Rocq 和 Lean 所用的 CIC 变体差异足够大,以至于结果不能从其中一个直接迁移到另一个。不幸的是,这篇论文中发现了一处错误。该论文也已经过时,因为它针对的是较早的 Lean 3 系统。目前,修正并扩展这篇论文的工作仍在进行。
作为他的论文答辩委员会成员,当他证明 Lean 中的定义相等性不可判定时,我感到震惊。在实践中,这意味着 Lean 算法无法确立某些事实上定义相等的项之间的定义相等性。这一否定性结果并未因那处错误而失效;它仍然是一个定理。
下面,我们提及 Lean 类型论的一些期望性质,以及相关证明的当前状态。
类型唯一性。
上文在对类型论进行那种“荒唐”的简化时,我们说每个项都有唯一的类型。更准确地说,类型唯一性是指:如果一个项既有类型 A,又有类型 B,那么 A 和 B 就定义相等。类型唯一性并不是内置于 Lean 逻辑中的性质。它是一个棘手的猜想,至今尚未得到证明。关于 Lean 类型论的其他一些非常基本的问题也仍未解决,包括 Pi-单射性、一种修正的 Church–Rosser 性质,以及 sort 单射性。
相对于集合论的逻辑相容性。
这项性质说的是,在假定集合论(带有适当公理)相容的情况下,无法在具有给定公理的 Lean 体系中推导出 False。当然,逻辑相容性是我们对 Lean 类型论最应期待的、最重要的单一性质。截至 2026 年 10 月,据我所知,还没有一份完整、公开、涵盖 Lean 抽象类型论的相对相容性证明。Mario Carneiro 在论文和演讲中声称,存在另一条确立相容性的路径,可以避开论文中的错误;但据我所知,除了他论文引言中的简短陈述,这条替代路径从未被写出来。在我看来,一个具有如此根本重要性的结果,必须完整给出之后才能被接受。上文讨论的 Con-Leche 提出并形式化验证了一项密切相关的、相对于集合论的相容性主张。
这些研究问题正在取得进展(arXiv:2607.13662、arXiv:2403.14064、Carneiro/AITP2026)。
Mario Carneiro 在演讲中曾反复呼吁其他研究人员为 Lean 的基础元理论作出贡献:“有五六个人在研究 MetaCoq,但 Lean 还没有足够的类型论研究者参与。如果你认为自己属于这一群体,就来帮忙吧!”(2024 年 7 月 24 日波恩报告的幻灯片。)我赞同他的呼吁。
我的总体评价是,我们对 Lean 类型论的理论理解尚未达到期望的程度,而整个数学界对 Lean 相关的、非常重要的类型论问题重视不足。如果我们作为一个专业群体要整体从集合论迁移到类型论,那么我们就更应该努力巩固其基础元理论。
相容性或许是最重要的基础性质,但相容性绝不够。我不相信数学家会完全满足于这样一个系统:它声称自己是一种类型论,却甚至无法保证,良构的项在定义相等的意义下具有唯一类型。抽象理论必须足够简单,能够被广泛的群体教授和学习。如果通向相容性的唯一已知路径,是一项缺乏人类阐释的 AI 形式化,我们同样无法完全满意。
后记:
Ken Thompson 写过一篇著名文章《对信任之信任的反思》(Reflections on Trusting Trust)。他问道:“对于一个程序不含特洛伊木马的声明,我们应该信任到什么程度?”他设想了一种恶意代码,它混入编译器,并隐藏自身的存在。他的结论是:“你不能信任不是完全由你自己创建的代码……无论进行多少源代码层面的验证或审查,都无法保护你免于使用不可信代码。”
今天,在 AI 日益具有欺骗我们和利用软件漏洞的能力的时代,我们绝不能盲目信任 Lean 这样的系统。若从对抗性角度看待 AI,我们可以问:怎样才能证明,AI 在 2026 年夏天搜寻漏洞时,没有在 Lean 中留下作为后门的健全性漏洞?如果这个漏洞极为隐蔽,以至于人类极不可能独自发现它,又该怎么办?如果正是这个漏洞在 Lean 对 Con-Leche 检查器的验证中被利用,从而也在 Con-Leche 中留下健全性漏洞,又该怎么办?(如今,Con-Leche 的相容性已经过多个其他内核的交叉检查,因此,一个健全性漏洞还必须突破所有这些交叉检查。)然后,假设有人恶意利用该漏洞,在保护关键基础设施的、经过形式化验证的软件中植入后门。为了防止未来出现这类情景,我们现在应该采取什么预防措施?过去一年,大量有关数学类型论基础及其可靠性的基础工作被交给了 AI;如果不经过人类的仔细审计,这种做法是危险的。
致谢:感谢 Avigad、Breitner 和 Urban 提供意见与纠正。本文完全由人类(TCH)撰写。AI 被用作搜索与研究、事实核查和校对的工具。