Skip to main content
QUICK REVIEW

[論文レビュー] Lean4Lean: Verifying a Typechecker for Lean, in Lean

Mario Carneiro|arXiv (Cornell University)|Mar 21, 2024
Manufacturing Process and OptimizationEngineering被引用数 6
ひとこと要約

Lean4Lean は Lean 4 向けに Lean で外部実装された検証器であり、Lean のカーネル、展開器、コンパイラ、Std、Mathlib を検査でき、形式的なメタ理論の基礎づくりとカーネル正確性に向けた部分証明を含む。

ABSTRACT

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 自身で書かれた外部検証器を Motivates と実装する。
  • Lean の型理論のメタ理論を formally specify し、核となる型付けと定義的等価性の性質を確立する。
  • Lean の内部 Expr 表現を検証用の検証済み抽象構文(VExpr)へ翻訳し関連付ける。
  • 形式化された理論に対して Lean のカーネルを検証し、部分的なメタ理論の結果を報告することで検証の実現性を示す。

提案手法

  • VExpr を Lean の型理論の De Bruijn ベースの抽象構文として定義し、型付け判定と定義的等価性判断(IsDefEq)を形式化する。
  • VExpr を Lean の Expr へ関連付ける翻訳メカニズムを、環境と宇宙情報をパラメータとする TrExpr 判定によって駆動する。
  • Lean4Lean を Lean で実装し、C++ Lean カーネルを模したカーネルとして Lean のコンパイラ・パッケージ、Std、Mathlib を検証する。
  • 検証ルーチンの終結性と部分性を管理する燃料ベースの RecM モナドを用い、深い再帰制限を固定する。
  • グローバル環境(Environment)と主操作(add, mkEmptyEnvironment)を記述し、検証のための宣言を結びつける。

実験結果

リサーチクエスチョン

  • RQ1Lean のカーネルを Lean 定義のメタ理論に対して外部検証器で formally verification できるか。
  • RQ2外部検証器内で Lean の型理論に関するコアな型付けと定義的等価性の性質をどの程度確立できるか。
  • RQ3内部 Expr 表現を忠実にモデル化し、検証目的の検証済み抽象構文(VExpr)へ関連付ける方法は。
  • RQ4Lean 実装の外部検証器と元の C++ カーネルとの性能トレードオフはどの程度で、全 Mathlib の検証が実現可能か。
  • RQ5UniqueTyping や Definitional Inversion のような partial なメタ理論結果はどの程度形式化でき、どこまでが仮説として残るべきか。

主な発見

  • Lean で実装された外部検証器 Lean4Lean は Lean 4 のカーネル、コンパイラパッケージ、Std、Mathlib を検証でき、元のカーネルより 20%–50% 遅い性能となる。
  • 本プロジェクトは検証されたカーネルの基本的な型付け判断と、正規性・不変条件といった性質を含む形式化作業を提供する。
  • 翻訳フレームワーク(TrExpr)と抽象構文(VExpr)を用いて Lean の内部 Expr を検証器と結びつけ、ローカルコンテキスト下での項に対する形式的推論を可能にする。
  • 検証は Lean 環境下での終結性を保証するために燃料ベースの RecM モナドを用い、基礎理論における非終端性と現実的な制約を認める。
  • いくつかの仮説的性質(例: UniqueTyping、Definitional Inversion)は微妙な証明エラーのため更なる証明が必要と識別されるが、真でありカーネル正確性を証明する上で essential と考えられる。
  • この研究は今後のカーネル変更を正式なメタ理論と検証結果で正当化するための基礎を築く。

この論文を読む

Nubintのビューアで原文を開き、読みながら気になる箇所をすぐに質問できます。

Nubintでこの論文を読む

このレビューはAIが論文の原文をもとに作成しました。引用する前に原文をご確認ください。