← All papers
First page of P$^{3}$: Joint Program-and-Proof Planning for Verified Code Generation

P$^{3}$: Joint Program-and-Proof Planning for Verified Code Generation

Zenan Li, Ziran Yang, Peiyang Song, Zhaoyu Li, Kaiyu Yang

cs.AI Aug 10, 2026 · v1 cs.PL
An agentic LLM workflow jointly plans program and proof for verified code generation in Lean 4, with a repository-derived Lean benchmark.
Verified code generation asks a large language model (LLM) to generate both an executable program and a machine-checkable proof that the program meets a formal specification, promising software that is correct by construction. The de facto workflow decouples the two halves of the problem: first synthesize a program, then attempt to prove it correct. We observe that this sequential pipeline can be both ineffective and inefficient in practice. A program generated without anticipating its proof can be subtly incorrect or structurally difficult to verify, forcing the LLM into brittle repair loops that alternate between patching the code and patching the proof. Inspired by Dijkstra's view that a program and its correctness argument should be developed hand in hand, we propose $P^3$, an LLM-based agentic workflow that first derives a unified program-and-proof plan from the specification, then elaborates the implementation and proof scaffold under this shared plan. To evaluate verified code generation in realistic settings, we further introduce Lean4Commit0, a repository-derived, library-level benchmark built by extracting core APIs from real-world software repositories and translating their requirements, including relational specifications across APIs, into Lean tasks. Using four frontier LLM backends, we evaluate $P^3$ on Verina, AlgoVeri, and our Lean4Commit0 benchmark, where it achieves the highest solve rate in every benchmark–model setting. Compared with the stronger baseline, it improves solve rates by 4.6–11.2 percentage points and reduces per-task API cost by up to roughly 40% and wall-clock time by up to roughly 37% on the difficult subset of each benchmark. A targeted ablation further shows gains of 3.3–8.3 points over implementation-only planning, isolating the benefit of planning the program and proof jointly.

Verified code generation asks an LLM to produce a program plus a machine-checkable proof that it meets a formal specification. The de facto sequential program-then-proof pipeline often yields structurally hard-to-verify programs, forcing brittle repair loops that waste token and time budget.

P3 is an LLM agentic workflow that first derives a unified program-and-proof plan from the specification, recording contract, program decomposition, library functions/lemmas, and proof obligations. It then elaborates the implementation and a matching proof scaffold (induction principles, case splits, lemmas) under that shared plan, using Lean 4 feedback to repair at elaboration or plan level. The authors also build Lean4Commit0, a benchmark extracting Lean 4 verified-generation tasks (function signatures, postconditions, correctness theorems with sorry) from 108 real-world open-source libraries, including relational specifications across APIs.

Across Verina, AlgoVeri, and Lean4Commit0 with four frontier LLM backends, P3 achieves the highest solve rate in every setting, improving 4.6-11.2 points over the stronger baseline while cutting per-task API cost up to 40% and wall-clock time up to 37% on hard subsets. An ablation shows 3.3-8.3 point gains from joint program-and-proof planning over implementation-only planning.

BenchmarkModelPlainSeqP3Δ
VerinaGemini-3-Pro59.360.872.0+11.2
AlgoVeriClaude-Opus-4.739.040.348.1+7.8
Lean4Commit0Claude-Opus-4.713.917.622.2+4.6
Solve rates (%) across benchmarks and models: Plain, Seq (program-then-proof), and P3
BenchmarkPlainSeqPlan-SeqP3Δ
Verina68.868.369.874.6+4.8
AlgoVeri39.040.344.848.1+3.3
Lean4Commit013.917.613.922.2+8.3
Planning ablation: Plan-Seq vs P3 solve rates (%)