arXiv:2611.08277cs.AINov 2026

Manuscript Offprint

arXiv:2611.08277

LeanContext: Disentangling Mathematical Resources from Local Formal Context in Lean Whole-Proof Generation

Hang Zhang, Qihao Ye, Litong Liu, Yunbei Zhang, Yugyung Lee, Yue Zhou, Bowen Liu, Emily First, Cheng Han, Qiao Zhuang

Abstract

Neural theorem proving increasingly uses retrieved premises and project context to support proof generation. Evaluating these resources requires measuring the advantage of target-selected declarations over comparable alternatives and how this advantage depends on training. We introduce LEANCONTEXT, a benchmark of 129,826 Lean whole-proof generation problems, to investigate these questions. We group selected complete preceding mathematical declarations as Mathematical Context (MC) and the remaining selected local source commands as Environment Context (EC). Four aligned input views support crossed training and inference evaluations with shared targets and original Lean verification environments. For both diffusion- and autoregressive-based models, selected declarations outperform comparable alternatives by a larger margin when training includes MC. Final-input audits identify omitted declarations referenced by the target. Prioritizing these dependencies improves Pass@32 by 1.40% and 1.70% for LLaDA and Llama, respectively, on 2,000 targets. The selection experiment operates without access to target reference proofs and holds checkpoints, EC, and inference budgets constant. The code and dataset are available at https://github.com/haaardcvZ/LeanContext.

1 Introduction

Neural theorem proving increasingly uses retrieved premises and project source context to generate proofs (Yang et al., 2023; Hu et al., 2025). This development reflects the cumulative nature of formal mathematics, where definitions introduce objects and subsequent lemmas establish properties that later proofs reuse (The mathlib Community, 2020). A proof about a newly defined object may combine its definition, an earlier lemma, and an instance required to apply that lemma. Supporting such proof

construction requires models to use the mathematical declarations supplied by the current project.

Existing work has examined several forms of information that support this process. LeanDojo studies retrieval-augmented proving with accessible premises (Yang et al., 2023). Passport examines identifier representations, while Rango retrieves relevant premises and proof examples (Sanchez-Stern et al., 2023; Thompson et al., 2025). miniCTX extends evaluation to project source context and analyzes the contributions of environment information, definitions, lemma statements, proofs, and comments (Hu et al., 2025). These studies establish that different information components can help proof generation. We examine the advantage of target-selected declarations over comparable replacements and how training with declarations changes this advantage when accompanying source commands are held fixed.

Answering this question calls for a common unit of comparison across mathematical resources. Definitions, lemmas, structures, classes, and instances serve different functions, but subsequent proofs can reuse them as declarations. Treating a complete declaration as the resource unit allows its identity to be tracked through selection, replacement, and dependency analysis. The comparison must also preserve other visible source commands, such as variable, namespace, and notation, when the declaration set changes. This motivates organizing declaration resources separately from the commands that accompany them. Declarations matched for kind, scope, and length can differ in their usefulness for proving a given target. Comparing these alternatives with the accompanying source commands held fixed makes the advantage of the selected content measurable. Verified proof success provides a common criterion for evaluating this advantage across different valid proof strategies.

We introduce LEANCONTEXT, a benchmark of 129,826 Lean whole-proof generation problems

*Equal contribution. †Corresponding authors

Figure

Figure 1: Overview of LEANCONTEXT. (Left) A complete mathematical declaration (MC) and accompanying source commands (EC) precede a proof target. (Right) Four aligned views support crossed training, inference evaluations, and matched replacement. Input comparisons retain the target and original Lean verification environment. Matched replacement also keeps EC unchanged.

from a fixed Mathlib4 snapshot. Mathematical Context (MC) comprises selected complete preceding mathematical declarations, while Environment Context (EC) comprises the remaining selected local source commands. The MC/EC partition supports comparisons of selected mathematical declarations with matched alternatives and enables us to examine how their advantage changes across training conditions. Four aligned input views supply neither category, MC alone, EC alone, or both (Full). They support crossed training and inference evaluations, as well as declaration replacements with EC held constant. Generated proofs are verified at the original target location in the complete Lean environment. Figure 1 illustrates the context partition and these comparisons.

To examine training-dependent declaration benefits under both diffusion and autoregressive generation, we evaluate LLaDA (Nie et al., 2025) and Llama (Llama Team, AI @ Meta, 2024), respectively. With checkpoints trained on both context categories, adding MC to EC improves Pass@32 by 7.1% and 8.5%, respectively. On the same 11,064 test targets, the corresponding gains are 0.4% and 0.8% after EC-only training. Comparisons with alternatives matched for kind, scope, and length further show a larger advantage for selected declarations when training includes MC. Dependency audits then identify declarations omitted from final inputs. Prioritizing these dependencies without accessing target reference proofs improves verified

success under fixed checkpoints, EC, and budgets, while revealing resource tradeoffs.

Our main contributions are as follows:

  • A benchmark for controlled context comparisons. We provide four aligned input views for 129,826 Lean proof problems, supporting comparisons of declaration visibility under fixed targets and verification environments.
  • Evidence on training-dependent declaration benefits. Crossed evaluations and matched replacements show larger declaration gains and selected-content advantages after training with MC than after EC-only training in both evaluated backbones.
  • Dependency diagnostics that guide selection. We audit declaration visibility in final inputs and use these diagnostics to test a dependency-priority policy that improves verified proof success.

References (94)