NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Verified Proof Refactoring with Codex and Qwen

Lazar Milikic, Gordan Đurić, Viktor KunčakarXiv 2026

TL;DR

Getting a mathematical proof to compile in a formal theorem prover like Lean is hard enough, but making that proof short, fast to verify, and compatible across software updates is an entirely different beast. This paper shows how to pair off-the-shelf, open-weights language models with a clever software-engineering tool loop and a strict compiler harness to automatically refactor existing proofs. The result? Faster, leaner, verified code that took first place in a major open-source AI refactoring competition—all without fine-tuning a single weight.

What Problem Does This Paper Address?

Imagine writing a complex piece of software that works, only to realize it takes forever to compile, spans way too many lines of code, and breaks the moment you update your dependencies. Mathematical proofs written in Lean 4—a programming language and interactive theorem prover—suffer from the exact same headaches.

Two formally verified proofs of the exact same mathematical theorem can look wildly different under the hood. One might be bloated and burn massive compute cycles (measured in Lean as "heartbeats") every time the compiler checks it, while another breezes through. Furthermore, Lean evolves rapidly; a proof written for one toolchain version might fail in the next. The authors tackle verified proof refactoring: taking an existing, working Lean 4 proof and shrinking its token length and checking cost, while strictly preserving the exact theorem statement and ensuring it compiles across multiple required Lean versions.

Methods

Instead of training a specialized model from scratch, the authors treat proof optimization like an agentic software engineering task. They connect a locally served, off-the-shelf Qwen3.8-Flash-Next-FP8 model to a modified version of the open-source Codex CLI terminal interface.

Figure 1: The agent proposes and tests replacements within each problem’s deadline. The host retains verified improvements during search and cleanup.

The workflow breaks down into a tightly controlled pipeline:

  1. The Sandboxed Agent Loop: The Qwen agent is given a problem deadline (nearly 8 hours per proof) and eleven custom command-line tools. It can inspect intermediate proof goals, profile which steps are burning the most compiler heartbeats, search local project files (using BM25 and vector embeddings via Qwen3-Embedding-0.6B), and even browse DuckDuckGo for documentation.
  2. Strict Host Verification: Whenever the agent proposes a refactored proof, an isolated host system steps in. It verifies that the theorem statement hasn't been sneakily altered, prevents circular logic, and runs the candidate against every required Lean version. A new proof only dethrones the reigning champion (the "incumbent") if it passes all versions and beats the previous combined score—an average of token savings, heartbeat savings, and version compatibility—by more than 0.02 points.
  3. Deterministic CPU Cleanup: Once the 48-hour GPU budget for model search is up, the LLMs are shut down. A pure-CPU worker pool runs a fixed 16-pass deterministic "code golf" schedule on the winning proofs—pruning unused lemmas, deleting redundant local facts, and merging adjacent rewrites—only keeping changes that pass the same strict multi-version verifier.

Under the hood, they squeeze impressive throughput out of four 80GB A100 GPUs using vLLM, prefix caching, and Qwen’s built-in multi-token speculative decoding to serve ten concurrent agent workers.

Datasets

  • Training Datasets: None. Both the Qwen generator and embedding models use publicly released weights with zero fine-tuning.
  • Evaluation Dataset: The system is evaluated on Lean Refactor Arena, an established benchmark consisting of 60 proof-refactoring problems. Across those 60 tasks, there are 127 total proof–version compatibility checks that must be satisfied. For local semantic code search, the system queries a frozen LeanExplore index.

Key Insights and Ideas

  • Tooling and harness design beat custom training: While prior systems like ImProver 2 rely on iterative training to teach models how to optimize proofs, this work shows that a strong, frozen reasoning model (xhigh effort) armed with compiler profilers, search tools, and a rock-solid refactoring prompt ("strategy cards") is extraordinarily competitive right out of the box.
  • Never trust the agent with the scoreboard: By keeping the check ledger, source environments, and evaluator state strictly outside the model's writable workspace, it becomes mathematically impossible for the agent to hallucinate success or accidentally corrupt the theorem it is trying to prove.
  • Synergy between neural intuition and symbolic polish: LLMs are great at big structural shifts—like changing representations or finding a better library abstraction—while deterministic scripts excel at tedious syntax minification (like pruning unused list items in tactics). Combining both yields free performance gains.

Key Results

  • Competition Victory: The system placed first in the open-source LLM track of the Lean Refactor Arena at the NeurIPS 2026 VeriCodeGen Workshop.
  • High Optimization Scores: Across all 60 benchmark problems, the 48-hour LLM search achieved a mean combined score of 82.07.
  • Effective CPU Polish: Running the 2.2-hour deterministic CPU cleanup improved 28 of the 60 proofs, nudging the final mean score up to 82.18.
  • 100% Reliability: Every single final proof passed all 127 required proof–version checks.
  • Inference Efficiency: Using speculative decoding on four A100 GPUs, the vLLM server accepted roughly 50% of draft tokens and sustained ~883 tokens/second across active agent loops.

Limitations and Future Work

Not discussed in the paper. (Note: Because this is a concise competition system report, the authors focus entirely on architecture, compute accounting, and reproducibility rather than a formal discussion of limitations or future directions—though the steep wall-clock budget of ~48 hours on 4xA100 GPUs for just 60 proofs stands out as an implicit practical constraint.)

Summary updated

BibTeX
@misc{milikic2026verified,
  author = {Lazar Milikic and Gordan Đurić and Viktor Kunčak},
  title = {{Verified Proof Refactoring with Codex and Qwen}},
  year = {2026},
  eprint = {2611.31762},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.31762},
}
Figure