[论文解读] Lean4Lean: Verifying a Typechecker for Lean, in Lean
Lean4Lean 是一个用 Lean 编写的外部验证器,用于 Lean 4,能够检查 Lean 的内核、展开器、编译器、Std 和 Mathlib,具有正式的元理论基础和朝着内核正确性的部分证明。
In this paper we present a new "external checker" for the Lean theorem prover, written in Lean itself. This is the first complete typechecker for Lean 4 other than the reference implementation in C++ used by Lean itself, and our new checker is competitive with the original, running between 20% and 50% slower and usable to verify all of Lean's mathlib library, forming an additional step in Lean's aim to self-host the full elaborator and compiler. Moreover, because the checker is written in a language which admits formal verification, it is possible to state and prove properties about the kernel itself, and we report on progress to formalize the Lean type theory abstractly and prove some theorems about it. Finally, we combine these to get a proof of correctness of parts of the kernel. We plan to use this project to help justify any future changes to the kernel and type theory and ensure unsoundness does not sneak in through either the abstract theory or implementation bugs. The verification is already paying off, as one soundness bug has been spotted and fixed as a result of this work.
研究动机与目标
- 激励并实现一个用 Lean 自身编写的 Lean 4 外部验证器。
- 形式化地给出 Lean 的类型理论的元理论,并确立核心类型化与定义性相等性质。
- 将 Lean 的内部 Expr 表示转换并关联到用于验证的经验证的抽象语法(VExpr)。
- 通过将 Lean 的内核与形式化理论进行检查来演示验证的可行性,并报告部分元理论结果。
提出的方法
- 将 VExpr 定义为 Lean 的类型理论的基于 de Bruijn 的抽象语法,并形式化类型判定与定义等价判断(IsDefEq)。
- 通过由环境和宇宙信息参数化的 TrExpr 判断驱动的翻译机制,将 VExpr 与 Lean 的 Expr 相关联。
- 在 Lean 中实现 Lean4Lean,使其内核镜像 C++ Lean 内核,以验证 Lean 的编译包、Std 和 Mathlib。
- 在验证例程中使用基于燃料的 RecM 单子来管理终止性和偏性,设定固定的深递归限制。
- 描述全局环境(Environment)和核心操作(add、mkEmptyEnvironment),以将用于验证的声明联系在一起。
实验结果
研究问题
- RQ1是否可以使用一个用 Lean 实现的外部验证器,将 Lean 定义的元理论对 Lean 的内核进行形式化验证?
- RQ2在外部验证器中可以就 Lean 的类型理论建立哪些核心的类型化与定义性相等性质?
- RQ3如何对内部的 Expr 表示进行真实可信的建模,并将其与经验证的抽象语法(VExpr)相关联,以用于验证?
- RQ4与原始的 C++ 内核相比,Lean 实现的外部验证器的性能权衡如何,是否可行对 Mathlib 进行全面验证?
- RQ5哪些部分元理论结果(例如唯一类型、反演性质)可以形式化,哪些仍然是猜想?
主要发现
- Lean4Lean 外部验证器,用 Lean 实现,能够验证 Lean 4 的内核、编译包、Std 和 Mathlib,性能比原内核慢 20%–50%。
- 该项目提供了围绕基本类型判断及如规则性和在验证内核中的不变量等性质的形式化工作。
- 一个翻译框架(TrExpr)和一个抽象语法(VExpr)将 Lean 的内部 Expr 与验证器连接起来,使在局部上下文下对项进行形式化推理成为可能。
- 验证使用基于燃料的 RecM 单子,以确保在 Lean 环境中的终止性,承认底层理论和实践约束下的不可终止性。
- 一些猜想性质(例如 UniqueTyping、Definitional Inversion)被确定需要进一步证明,原因是存在一个微妙的证明错误,但被认为是真实且对证明内核正确性至关重要。
- 这项工作为未来对内核的变更提供了通过形式化元理论和验证结果来证明的基础。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。