Library Before Proof: Making LLM-Generated Rocq Usable by Mathematicians

Guillaume Baudart, Marc LelargeAI4Research @ ICML 2026

TL;DR

While LLMs have become surprisingly good at "closing goals" in formal proof assistants like Rocq and Lean, they often produce unreadable "spaghetti code" that mathematicians can't audit or reuse. This paper proposes a three-artifact "recipe"—style-guided code, interactive blueprints, and verification PDFs—to transform LLM-generated proofs into structured, usable mathematical libraries.

What Problem Does This Paper Address?

In the world of formal verification, mathematicians use languages like Rocq (formerly Coq) or Lean to write proofs that a computer can 100% guarantee are correct. Recently, autonomous AI systems have successfully tackled high-level competition math (like the International Mathematical Olympiad).

However, there is a catch: the code these AIs produce is typically a "single-purpose proof script." It might prove the theorem, but it’s often a mess of thousands of lines of tactics that no human can read, let alone build upon. For a mathematician, a proof is only useful if they can audit it, understand the dependencies, and reuse the lemmas. The authors argue that the bottleneck in AI formalization has shifted from "can the AI prove this?" to "can a human use the library the AI just built?"

Methods

The authors introduce a "three-artifact recipe" to ensure LLM-generated code meets the standards of a professional mathematical library:

  1. Mathcomp-style Rocq: Instead of letting the LLM write arbitrary code, they use a "coding-style skill" (a set of prompts and guides) to force the LLM to follow the Mathematical Components (mathcomp) style. This style is terse, follows strict naming conventions, and is the gold standard for human-readable Rocq code.
  2. The Blueprint: Borrowing a tradition from the Lean community, they generate a hyperlinked HTML/PDF document. This "blueprint" states the math informally (in plain English/LaTeX) and provides direct links to the formal code, along with a visual dependency graph of all lemmas.
  3. The Verification PDF: For high-level results, they create a side-by-side document where every formal Rocq definition is paired with its informal textbook counterpart. This allows a mathematician to verify that the AI actually formalized the correct statement without needing to be a Rocq expert.

To produce these, they used Claude 3 Opus driving the Rocq prover through a Model Context Protocol (MCP) server, which allows the LLM to interact with the proof state step-by-step, just like a human would in an IDE.

Datasets

The researchers evaluated their method on two significant case studies:

  • Library E (Eulerian): A formalization of chapters from Richard Stanley’s Enumerative Combinatorics. It includes 22,500 lines of code and 889 named results.
  • Library Q (Quasi-Borel Spaces): A formalization of advanced probability theory (QBS), consisting of nearly 9,000 lines and 412 proofs.

These weren't just toy examples; Library E was used to solve Putnam 2025 Problem A5, a notoriously difficult combinatorics exercise.

Key Insights and Ideas

  • Style is a "Skill": You don't need a new model to get better code; you need better "tooling." By providing the LLM with a machine-checkable style guide, the generated code landed within the same "expansion ratio" (lines of code per mathematical statement) as human-authored libraries.
  • The Scaling Trade-off: The "Verification PDF" (side-by-side audit) is fantastic for a few dozen headline theorems (Library E), but it becomes "busywork" when you have 400+ proofs (Library Q). At that scale, the Blueprint and its dependency graph become the primary tools for human navigation.
  • Library-First Proving: The authors show that by building a structured library first, the final proof of a hard problem (like Putnam A5) becomes trivial—only 214 lines of code compared to over 2,000 lines in a previous "bespoke" AI attempt.

Key Results

  • Zero "Admitted": Both libraries were completed with zero Admitted (skipped) proofs and zero custom axioms, ensuring total formal correctness.
  • Efficiency: The AI-generated proof for Putnam A5 was an order of magnitude shorter than previous autonomous attempts because it sat on top of a well-structured library.
  • Tooling Contributions: The authors contributed five new features back to the open-source Rocq-MCP server, including better error capture and "stateless" query tools that allow the LLM to "look before it leaps" during the proving process.

Limitations and Future Work

The authors acknowledge that the Verification PDF is currently a flat document and needs to evolve into a richer, searchable, and hyperlinked interface to remain useful at scale. Additionally, some results in Library Q were stated in slightly weaker forms than their textbook versions (e.g., laws holding "up to equivalence" rather than "on the nose"), a limitation inherited from previous manual formalizations in other languages.

The next step is making these artifacts even more interactive, moving toward a world where a mathematician can "browse" an AI-generated library as easily as they read a textbook.

Summary updated

BibTeX
@inproceedings{baudart2026library,
  author = {Guillaume Baudart and Marc Lelarge},
  title = {{Library Before Proof: Making LLM-Generated Rocq Usable by Mathematicians}},
  booktitle = {AI4Research @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=uHPxM9N0Il},
}
Figure