自动教科书形式化
Automatic Textbook Formalization

原始链接: https://github.com/facebookresearch/repoprover

## RepoProver:数学教材的自动化形式化 RepoProver是一个多智能体系统,旨在将数学教材大规模形式化为Lean证明助手。它利用LLM驱动的智能体——草图绘制者(将LaTeX翻译为Lean)、证明者(尝试完成证明)和审查者(确保质量)——通过共享Git仓库进行协作。 该系统基于一个Lean项目,项目结构包含按章节组织的LaTeX源文件、定义形式化目标的`manifest.json`、用于项目文档的`CONTENTS.md`以及用于智能体协调的`issues/`目录。 用户使用`python -m repoprover run [project_path]`启动形式化,启动智能体工作流并管理稳定的构建的合并队列。通过SLURM启动器(`repoprover.stool`)支持分布式运行。系统提供跟踪token使用情况和智能体效率的工具。提供了一个玩具项目和示例配置,用于测试和指导。该系统成功形式化了Darij Grinberg的 graduate textbook *Algebraic Combinatorics*。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 自动教科书形式化 (github.com/facebookresearch) 7 分,由 tzury 发表于 50 分钟前 | 隐藏 | 过去 | 收藏 | 2 条评论 帮助 alex_be 发表于 8 分钟前 | 下一个 [–] 人工智能辅助数学研究的重大一步 回复 tzury 发表于 48 分钟前 | 上一个 [–] 更多细节:https://x.com/FabianGloeckle/status/2040082785851904401 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Paper PDF Formalization Blueprint Website Blueprint PDF

Code for Automatic Textbook Formalization (Gloeckle, Rammal, Arnal, Munos, Cabannes, Synnaeve, Hayat, 2026).

RepoProver is a multi-agent scaffold for large-scale formalization of mathematics textbooks in Lean. It orchestrates multiple LLM agents that collaborate on a shared git repository with the Lean project: sketcher agents translate definitions and theorem statements, prover agents fill in proofs, and reviewer agents enforce quality via pull request reviews. Coordination happens through a lightweight file-system-based issue tracker and a merge queue that ensures the main branch always builds.

This code produced an automatic formalization of the graduate textbook Algebraic Combinatorics by Darij Grinberg.

Requires Python 3.10+. Install in editable mode:

Preparing a formalization project

RepoProver operates on a Lean project repository. Before running, you need to set up:

  1. Create a Lean project with Mathlib and build it:

    lake init MyProject math
    lake update
    lake build
  2. Add LaTeX source files under a tex/ directory inside the project, organized by topic:

    MyProject/
    ├── lakefile.lean
    ├── lean-toolchain
    ├── lake-manifest.json
    ├── MyProject.lean           # root import file
    ├── MyProject/
    │   └── tex/                 # LaTeX source chapters
    │       ├── all.tex          # full textbook source (optional)
    │       ├── Topic1/
    │       │   ├── Chapter1.tex
    │       │   └── Chapter2.tex
    │       └── Topic2/
    │           └── ...
    ├── manifest.json            # chapter manifest (see below)
    ├── CONTENTS.md              # structure documentation (see below)
    └── issues/                  # issue tracker (see below)
    

    The tex files should be split by chapter/section so each can be assigned to a sketcher agent independently. An all.tex with the full source can be included for reference. Note that tex files are read-only — agents can read them but never modify source material.

  3. Create a CONTENTS.md at the project root documenting the structure of tex sources and corresponding Lean files. The coordinator generates an initial version from the manifest, and agents update it as the Lean codebase evolves. It serves as the central reference for project structure, proof status and architecture notes.

  4. Create a manifest.json at the project root listing the chapters to formalize and their target theorems/definitions. Each chapter entry has:

    • id: unique identifier for the chapter
    • title: human-readable chapter title
    • source_path: path to the LaTeX source file (relative to project root)
    • target_theorems: list of theorem/definition IDs to formalize from this chapter

    See configs/example_manifest.json for a full example from the algebraic combinatorics case study.

  5. Create an empty issues/ directory at the project root. Agents use this as a lightweight file-system-based issue tracker — they create short YAML files here to flag blockers, request refactorings, or coordinate work across chapters.

  6. Initialize git (with branch name main) in the project if not already done — RepoProver uses git for version control, branching and merging.

python -m repoprover run /path/to/lean/project --pool-size 10

This starts the main coordinator loop which launches sketcher, prover, maintainer and reviewer agents, manages the merge queue and tracks progress. The project state is saved in .repoprover/ inside the Lean project directory.

Use --clean to start from scratch, --verbose for debug logging.

For distributed runs across multiple machines, use the stool launcher:

python -m repoprover.stool --name myrun --project /path/to/lean/project

The stool launcher snapshots the repoprover code to a dump directory, symlinks the Lean project (avoiding slow copies of .lake/ and .git/) and submits a SLURM job. Rank 0 runs the coordinator in a background thread; all ranks (including rank 0) run as workers that pull tasks from the coordinator.

Options:

  • --launcher bash — run directly if already inside an salloc session
  • --pool-size N — number of Lean REPL instances per node (default: 10)
  • --nodes N — number of SLURM nodes (default: 1)
  • --agents-per-target N — max parallel agents per theorem/issue (default: 1)
  • --prs-to-issues — convert pending PRs to issues when resuming a run
  • --clean — wipe state and restart from scratch
  • --dirs-exists-ok — reuse an existing dump directory

See configs/example.yaml for an example configuration.

# Token usage breakdown by agent type and outcome
python scripts/count_tokens.py /path/to/lean/project

# Agent efficiency plots over time
python scripts/plot_agent_efficiency.py /path/to/lean/project --out ./plots

A toy project is included under examples/toy_project/ for quick testing. The setup script copies the files to a working directory, initializes git, fetches Mathlib and builds the project:

bash examples/toy_project/setup.sh /tmp/repoprover-toy-test

Then run repoprover on it:

source .venv/bin/activate
python -m repoprover run /tmp/repoprover-toy-test --pool-size 2 --verbose

The toy project has one chapter with 4 trivial targets (a definition and 3 theorems about doubling natural numbers).

To inspect agent trajectories from a run:

python -m repoprover.viewer --dir /path/to/lean/project/runs --port 8080

This project is licensed under the terms in LICENSE.

联系我们 contact @ memedata.com