← All papers
First page of FormalWeaver: Dependency-Aware Translation of Formal Repositories at Scale

FormalWeaver: Dependency-Aware Translation of Formal Repositories at Scale

Hantao Lou, Alok Singh

cs.LG Nov 30, 2026 · v1 cs.AI cs.PL
Uses LLM agents to translate the Coq library Flocq into Lean 4 and Mathlib, producing the sorry-free FloatSpec repository with compiler-guided repair.
AI agents are increasingly capable of generating formal code and proofs under given specifications, but repository construction requires coherence of specifications and proofs across dependencies, beyond isolated theorem completion. Existing evaluations largely focus on declaration-level success and therefore do not directly measure whether an agent can preserve source coverage, specification semantics, and proof correctness together while growing an integrated repository. We study this gap through formal repository translation, where the task is to translate formal source repositories into another formal language. We introduce FormalWeaver, a source-grounded pipeline that translates dependency-ready items against frozen upstream representations and interfaces, with compiler-guided repair scoped to the current item. Applied to Flocq, a Coq library for floating-point reasoning, the pipeline produces FloatSpec, a Lean port with 58 core files, 5,075 indexed items, and 194,704 lines of Lean code. We further conduct controlled experiments comparing FormalWeaver with different translation strategies on submodules of the Flocq translation task. We evaluate two aspects in sequence: whether a translation compiles and, for those that compile, whether it is semantically aligned with the source. Their conjunction defines translation accuracy. The results show that FormalWeaver substantially improves translation accuracy over simpler translation strategies.

LLM-based formal generation is usually evaluated one declaration at a time. Translating a whole formal repository between proof assistants instead requires specifications, interfaces and proofs to stay coherent across dependencies. Existing evaluations do not measure source coverage, semantic faithfulness and proof correctness together at repository scale.

FormalWeaver represents the source repository as a dependency graph and schedules dependency-ready items for translation. Each item is translated against frozen upstream representations and interfaces, with compiler-guided repair scoped to the current item. Downstream items are unlocked only after acceptance. Translation accuracy requires both that the Lean target compiles and that it is semantically aligned with its source.

Applied to Flocq (40 files, 2,164 items, 24,786 lines of Coq), the pipeline produced FloatSpec: 58 core files, 5,075 items and 194,704 lines of Lean 4/Mathlib, building without sorries. On 22 Flocq submodules, ablations show that dependency scheduling, interface stabilization and scoped repair each improve compile success and semantic faithfulness.

VariantCompile successSemantic faithfulnessTask completionCalls/item
Full FormalWeaver30.9%96.6%20.0%2.084
w/o scheduling22.6%87.7%0.0%3.287
w/o stabilization23.7%92.2%0.0%2.032
w/o scoped repair17.6%73.9%0.0%1.000
Ablation of FormalWeaver components on Flocq submodules