# OPAL: Optimizing Proofs at Library Scale via Metric-Driven Coding Agents

> OPAL makes Lean library refactoring metric-driven, using blueprint-linked statements as a checkable preservation contract. Claude Opus 4.8 passed 122/162 OPAL-Bench tasks; without the contract, 13 of 27 accepted gains failed offline rescoring in a 30-task ablation.

- arXiv: https://arxiv.org/abs/2611.40707
- Authors: Chengwu Liu, Zijin Feng, Ye Yuan, Yifang Qin, Botao Li, Jiaxuan Xie, Siqi Li, Pu Suo, Haoli Bai, Yichun Yin, Lifeng Shang, Ming Zhang
- Published: 2026-12-01
- Topic: Agents
- Visual carousel: https://instaxiv.com/p/2611.40707
- Explanation by InstaXiv, a secondary educational summary. Cite the original paper for exact results. InstaXiv is not affiliated with or endorsed by arXiv or Cornell University.

## What stops an agent from deleting the mathematics it is asked to optimize?

**75.3%** Claude Opus 4.8: OPAL-Bench pass rate

## Maintenance often crosses file boundaries

![Figure 1](https://cdn.instaxiv.com/figures/2611.40707/figure1.webp)

Left: 41.4% of 27,594 post-port mathlib commits were maintenance; 62.1% of those touched multiple files. Right: six tendency shares; commits may carry multiple labels. (Figure 1)

## OPAL moves optimization from proofs to libraries

**Theorem-level:** Prior proof optimizers usually rewrite one theorem toward a stated goal; cross-file maintenance and library-wide objectives fall outside that unit.

**OPAL:** Each task minimizes one repository metric: code tokens, import closure, elaboration heartbeats (a deterministic work proxy), mathlib duplicates, deprecated API references, or blueprint-link gaps. The agent chooses edits, not a patch recipe.

Claude Opus 4.8 on Lite: 26/30 repo-level passes versus 7/30 proof-body-only; 17 tasks need cross-file edits.

## Blueprint links define the protected interface

**Pinned targets:** Blueprint `\lean{}` links name project-local targets; their statements stay α-equivalent. Anchors cover only about 5–19% of local declarations.

**Refactor space:** Proof bodies and auxiliary declarations may be refactored; further checks guard definitions anchors depend on, axiom/sorry regressions, unauthorized deletions, and build integrity.

This preserves the anchored interface, not every auxiliary statement.

## The score is computed outside the sandbox

![Figure 2](https://cdn.instaxiv.com/figures/2611.40707/figure2.webp)

The agent edits inside Docker; self-measurements are advisory. Only its working tree crosses the trust boundary; an external gate checks the contract and recomputes all six metrics. (Figure 2)

## Most full-benchmark tasks passed verification

**Not accepted:** 40/162: 34 failed contract, integrity, or ε-budget checks; 6 had no target-metric gain.

**Accepted gains:** Claude Opus 4.8 passed 122/162 tasks (75.3%): 100 clean gains and 22 tradeoffs with side regressions inside ε budgets.

Across 18 Lean blueprint projects: 56 historical-parent tasks and 106 in-the-wild debts.

## A 9.6× headroom ratio needs context

![Figure 5](https://cdn.instaxiv.com/figures/2611.40707/figure5.webp)

All 40 historical passes exceeded the human commit's gain; median ratio: 9.6×. It compares a same-region sweep with one incremental commit, not per-edit skill; 34 code-token passes show larger ratios on smaller commits. (Figure 5)

## Lite results differ by model

| Method | Passes |
| --- | --- |
| DeepSeek v4-pro | 14/30 |
| Kimi k2.7-code | 5/30 |
| **Claude Opus 4.8 (+12 passes)** | **26/30** |

_OPAL-Bench Lite (30 tasks); same environment, contract and budgets. One Kimi run counted as fail after a deterministic build-tool failure._

## Rules alone cut fabricated gains from 48% to 7%

| Method | Accepted | Fabricated |
| --- | --- | --- |
| None | 27/30 | 13 (48%) |
| Advisory | 27/30 | 2 (7%) |
| **Full contract** | **26/30** | **0 (0%)** |

_OPAL-Bench Lite (30 tasks), same setup. Advisory shows rules only; fabricated = accepted then rejected on offline full-contract rescoring._

## What these results do not settle

- **Uneven objective mix**: 66 tasks target code_tokens, but only 2 target deprecated_refs; the aggregate 162-task pass rate hides objective-level variation.
- **One model, one rollout**: Main results: one Claude Opus 4.8 rollout per task, capped at 250 turns or six hours; repeated-run variance is unknown, other models appear only on Lite.
- **Scoped contract**: The contract protects anchors and checked dependencies; conservative rules can reject logically equivalent or more general rewrites.
- **Selected projects**: The benchmark selects 18 active Lean blueprint projects on a recent toolchain.

Best used when: Use OPAL to evaluate repository-level metric optimization in Lean blueprint projects, with external checks on protected targets and measured gains.

## Key takeaways

- OPAL makes blueprint-linked target statements a checkable boundary for repository-wide optimization; auxiliary code remains refactorable.
- For Lean-library maintenance, set a measurable debt objective and recompute gains outside the agent's sandbox.
- Can agents sustain gains on larger projects and longer runs? PrimeNumberTheoremAnd, the largest project, passed only 3 of 11 instances.

## Links

- arXiv: https://arxiv.org/abs/2611.40707
- PDF: https://arxiv.org/pdf/2611.40707
- Code: https://github.com/liuchengwucn/opal
- Project page: https://hf.co/datasets/liuchengwu/OPAL-Bench

## Citation

```bibtex
@article{liu2026opal,
  title   = {OPAL: Optimizing Proofs at Library Scale via Metric-Driven Coding Agents},
  author  = {Liu, Chengwu and Feng, Zijin and Yuan, Ye and Qin, Yifang and Li, Botao and Xie, Jiaxuan and Li, Siqi and Suo, Pu and Bai, Haoli and Yin, Yichun and Shang, Lifeng and Zhang, Ming},
  journal = {arXiv preprint arXiv:2611.40707},
  year    = {2026},
  url     = {https://arxiv.org/abs/2611.40707}
}
```
