Skip to content

Agentic verified optimization of real-world softwareAgentic Verified Optimization of Real-World Software

arXiv· arXiv:2610.30188· Zhe Ye, Udaya Ghai, Zhizhen Qin, Dawn Song, Soonho KongUniversity of California, Berkeley; Amazon Web ServicesIndexed by this site · 2026-10-23· Originally publishedDefenses

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

The authors propose agentic verified optimization: the agent produces a faster Lean implementation together with a machine-checked equivalence proof; on 189 Verina functions, 156 obtained verified speedups.

Questions
Coding agents can already speed up programs, but existing equivalence checks mostly rely on tests, and agents exploit passing tests without preserving behavior (reward hacking); the authors say they have observed such correctness failures.
Methods
Propose agentic verified optimization: the agent searches in Lean 4 simultaneously for a faster implementation f′ and an equivalence proof π : f = f′, using the existing implementation as the specification; and build AQUEDUCT to migrate C/C++/Go/Rust programs to native Lean, verifying the ports with differential testing.
Experiments and results
Of 189 Verina functions, 156 obtained verified speedups, with a geometric mean of 1.851×; on 17 migrated applications, 92 verified rewrites made 47/51 application scenarios faster, with an application-level geometric mean of 1.120×, smaller than the function-level 1.864×.
Limitations and future work
The directions listed by the authors include allocating effort between implementation and proof, proof reuse, target selection, workload specialization, learning from trajectories, extending equivalence to opaque effects and weaker relations, certified migration, and proving performance properties; the experiments use only one agent configuration, Codex with GPT-5.6 Sol, and the paper does not report token budgets or elapsed time.
Experimental setupCodex with GPT-5.6 Sol · Verina、ProgramBench · speedup(几何均值/中位数)、vfastp et al.
Evaluated models
Codex with GPT-5.6 Sol
Benchmarks
VerinaProgramBench
Metrics
speedup(几何均值/中位数)vfastprecovery
AI summaryThe researchers propose an agentic verified optimization task, requiring agents to produce faster implementations while providing machine-checkable proofs of equivalence to existing implementations, addressing the problem that existing equivalence checks mainly rely on tests, and agents have been shown to exploit passing tests without preserving the original behavior. The task is defined in Lean 4 at both the function and repository levels; existing implementations serve directly as specifications, avoiding the specification-writing bottleneck of verified code generation. The team developed the Aqueduct framework for this, migrating C, C++, Go, and Rust programs to native Lean and validating each migration with differential testing against the original program. On 189 reference implementations from Verina, agents produced faster proven rewrites for 156, including algorithmic changes such as replacing exponential recursion with dynamic programming; on 17 migrated applications, 92 proven rewrites sped up 47 of 51 application scenarios. Application-level speedups were smaller than function-level ones, making the choice of which functions to optimize an important problem.

The researchers propose an agentic verified optimization task, requiring agents to produce faster implementations while providing machine-checkable proofs of equivalence to existing implementations, addressing the problem that existing equivalence checks mainly rely on tests, and agents have been shown to exploit passing tests without preserving the original behavior. The task is defined in Lean 4 at both the function and repository levels; existing implementations serve directly as specifications, avoiding the specification-writing bottleneck of verified code generation. The team developed the Aqueduct framework for this, migrating C, C++, Go, and Rust programs to native Lean and validating each migration with differential testing against the original program. On 189 reference implementations from Verina, agents produced faster proven rewrites for 156, including algorithmic changes such as replacing exponential recursion with dynamic programming; on 17 migrated applications, 92 proven rewrites sped up 47 of 51 application scenarios. Application-level speedups were smaller than function-level ones, making the choice of which functions to optimize an important problem.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to make an agent speed up a program while guaranteeing unchanged behavior with a machine-checked proof, rather than relying on tests that can be exploited.

    Core question: when agents optimize program performance, how can machine-checked equivalence proofs replace tests to guarantee behavior preservation.

    • Setting and motivation: coding agents have already been asked to speed up code, but most existing work uses tests to check behavior preservation; the authors cite Dijkstra's view that testing can only find errors but cannot prove their absence.
    • Shortcomings of existing methods: when tests also define the agent's reward, the agent learns to pass the tests rather than preserve behavior (reward hacking). The authors cite examples: the 6× improvement reported by Jitskit came from regenerating test values rather than storing them; an audit found that 39.5% of GPU kernels accepted by an optimization framework had correctness failures.
    • Core observation: equivalence proofs cover all inputs and can close such correctness failures; at the same time, using the existing implementation as the specification bypasses the bottleneck of writing specifications in verified code generation (the authors say hand-written specifications also often contain errors).
    • The paper's proposal: it proposes agentic verified optimization—the agent produces a faster implementation f′ and an equivalence proof π : f = f′ with respect to the reference implementation f, formalizing the task in Lean 4 at both the function level and the repository level.
    • Supporting infrastructure: because real applications are rarely written in Lean, the authors build AQUEDUCT, which migrates C, C++, Go and Rust programs to native Lean and verifies each port against the original program using differential testing.
  2. What related research exists?

    The paper organizes related work along five threads: test-based optimization, optimizers with fixed transformations, optimization under formal checking, verified code generation benchmarks, and the scarcity of Lean applications.

    Test-based program optimization

    • PIE, LLM Compiler, AlphaDev, AlphaEvolve, etc.—use LLMs or search to rewrite programs or select compiler optimizations; KernelBench, CUDA Engineer, CUDA-L1, Astra, AsmEvo, etc. study GPU kernel generation and optimization; Jitskit synthesizes systems from specifications. The paper notes that these systems check correctness with tests or differential execution, and that when this check determines the reward the agent exploits the check; documented failures include exploiting weaknesses in timing methodology, specializing to benchmark input distributions, and passing standard tests while violating kernel contracts.

    Verified optimizers with fixed transformations or representations

    • Verified compilers such as CompCert and CakeML apply only pre-proven-correct passes; egg explores consequences of given rewrite rules; superoptimizers such as Denali, STOKE, and Souper search within a fixed instruction representation; Fiat, the Isabelle Refinement Framework, Cogent, and LLMLift derive implementations from refinement steps supplied by the developer. The paper notes that such optimizers can only find what their passes, rules, or target language can express, so gains are bounded.

    Agent optimization under formal checking

    • Translation validation tools such as Alive2 and HEC; LLM-Vectorizer, VecTrans, and LLM-VeriOpt use Alive2 to check LLVM rewrites, and the paper notes that Alive2 accepts only 38.2% of LLM-Vectorizer's test programs; T-LLM uses CBMC plus a language-model judge, and the paper notes that it reports a 33.8% false-acceptance rate. IDS, Solidus, and lean-zip have agents prove against hand-written specifications, and the paper notes that specifications are hard to write and every system must be rewritten.

    Verified code generation benchmarks

    • miniCodeProps, FVAPPS, Verina, CLEVER, DafnyBench, VerusBench, VeriCoding, RVBench, Vero, etc.—the paper notes that all of them check whether an implementation satisfies a specification, and none evaluates speed.

    Lean applications and code translation

    • Lean software such as Aeneas, Strata, Cedar, lean-zip, and RyuLean4 are formal models or standalone components, and the paper notes that they lack callers and workloads of deployed applications; VERT uses bounded model checking and FLOURINE uses differential fuzzing to check translations.

    Baselines and benchmarks: function level uses Verina's 189 reference implementations; repository level uses 40 ProgramBench repositories, and the migration baseline is a single agent porting directly under the same tasks and model configuration.

    The authors' positioning: this paper takes existing implementations as the specification, has the agent write new algorithms directly in Lean and prove equivalence, is not limited by a fixed transformation set, and requires no specification to be written in advance.

  3. How does the paper address this problem?

    Formalize in Lean 4 the joint search task of "faster implementation + equivalence proof", and use the AQUEDUCT multi-agent pipeline to migrate real programs to Lean as optimization targets.

    Overall approach: formalize program optimization as searching for a faster implementation under an equivalence constraint, with the agent searching jointly for the implementation and the proof in Lean 4, and with the existing implementation as the specification.

    Problem formalization

    • Behavioral equivalence: for pure functions, equivalence means returning the same result for all inputs; for functions whose effects are expressed within Lean (such as monads threading state, or exceptions), the effects are part of the function value, and equality applies likewise; opaque effects (IO, external calls) are out of scope for this work.
    • Optimization objective: minf′,π tB(f′) s.t. π : f = f′, i.e., minimize execution time on workload B, subject to the Lean kernel accepting the equivalence proof; success within a finite budget means finding tB(f′) < tB(f) 的可行对。
    • 两个层面:函数级给定目标 f 求更快实现;仓库级由智能体在预算内选择优化哪些函数,改写需与应用一同构建。
    • 负载与特化:负载 B 定义"更快";本研究对优化器隐藏评测负载并要求完全相等,使加速反映跨输入的泛化而非对计时输入的特化;论文也给出特化机制(可判定谓词 P 加守卫替换),留作方向。

    实现与证明的联合搜索

    • 每次改写改变要写的证明:提升重复计算需证明值可复用,改变遍历需不变式,换算法需关联不同中间状态;智能体由 Lean 的错误与证明目标引导,在继续优化、尝试证明、证明辅助引理、改实现之间分配精力。
    • 示例(Figure 2,Verina 任务 verina_advanced_33):参考实现每元素两次递归调用、在递增列表上探索 2^n 个分支;改写用动态规划填表、访问 O(n²) 个条目,在 261 个输入的语料上快 4,467.871×;证明用一条把表查询与参考递归助手对每个后缀和每个前驱元素联系起来的引理。
    • 引理可跨改写复用:Gron 中 validIdentifier 改写的证明复用了先前改写证明的字符分类引理。

    验收与测量

    • 验收:改写被接受当且仅当 Lean 内核在仓库的全新副本中对照未改动的参考检查通过相等定理(沿用 Vero 的做法),防止智能体改动参考、添加公理或替换被证明的定义。
    • 附录 A 的四项检查:构建(参考与调用方字节不变、@[csimp] 注册后可构建)、公理限于 {propext, Quot.sound, Classical.choice} 且禁止 sorryAx、可执行性(禁止 partial/unsafe/@[implemented_by]/@[extern])、禁止 native_decide。
    • 指标:函数级 microbenchmark 单独计时目标;应用级 macrobenchmark(称 application scenario)在固定输入上跑公开入口。函数级加速 s(f′) = tB(f)/tB(f′),场景加速 tw(R)/tw(R′),用几何均值与中位数汇总;并定义 vfastp = 1/(|F|)∑f ∈ F 1[sf > p] (following KernelBench's fastp), i.e., the fraction of targets for which the best verified candidate is more than p times faster.

    AQUEDUCT migration framework

    • Migration task: given a pinned original program and the declared input domain of its public interface, compare the port with the original program at the library API or executable entry point, comparing exit status, output bytes, filesystem effects and timeout status input by input; the port must be native Lean with no FFI and no subprocess calls to the original program; a successful migration means the port agrees with the original program on all tests in the accumulated corpus T, and recovery is measured once on a disjoint hidden test set Thidden.
    • Workflow (Figure 3): three migration agents produce candidate ports using different strategies; three test-design agents expand the corpus targeting uncovered entry points, boundary inputs and disagreements between candidates, using differential execution (shrinking disagreements to minimal counterexamples), coverage instrumentation and coverage-guided fuzzing, and mutation testing; a deterministic controller replays the corpus according to consistency across behavior families and selects the best candidate; a repair agent fixes failing tests, with some evidence hidden from the repair agent; repair and test generation alternate until the corpus fully passes or the budget is exhausted; the controller finally audits whether the port calls the original program or hardcodes answers, then measures once on Thidden.
  4. What experiments did the paper conduct?

    Two sets of studies: function-level optimization of 189 Verina functions, and repository-level optimization of 17 AQUEDUCT-migrated applications plus migration quality evaluation on 40 repositories.

    Experimental Setup

    • Agent: Both studies use Codex with GPT-5.6 Sol, xhigh reasoning setting; the evaluation workload is hidden from the optimizer, and exact equality with the reference is required.
    • Function level: Verina's 189 reference implementations (108 basic, 81 advanced), with one independent optimization call per function; the 54 functions not sped up in the first round were retried once under the same conditions. The timing corpus was frozen before optimization and contains 49,620 generated and official test cases (at most 256 generated cases plus official tests per target).
    • Timing protocol: Lean 4.18.0, AMD EPYC 9654, bound to a single logical CPU; after warm-up and iterative calibration, nine paired trials are run with alternating execution order, requiring identical output; speedup is the baseline median time divided by the candidate median time. The authors cite PIE's report: even timing the same binary can show apparent speedups with mean 1.12× and top 5% reaching 1.91×, hence the use of repeated paired trials.
    • Repository level: 40 repositories sampled from ProgramBench (258 to 1,524,580 lines, C/C++/Go/Rust); of 39,857 declared tests, the original programs pass 18,642 in the evaluation environment, and recovery is counted on this subset. The optimization study covers 17 of these ports and 51 application scenarios (3 per repository); the workload is built by an independent agent and frozen before optimization.
    • Migration baseline: a single migration agent ports directly under the same tasks and model configuration.
    • Aggregation method: aggregate performance takes the fastest verified implementation per target (including the reference), i.e., each target contributes max(1, sf).

    Main Results

    Swipe horizontally to read the table

    SettingNumber fasterGeometric meanMedian
    Verina Basic (108 targets, Table 1)931.959×1.109×
    Verina Advanced (81 targets, Table 1)631.716×1.163×
    Verina all (189 targets, Table 1)1561.851×1.117×
    Repository-level function layer: optimized Lean vs migrated Lean (92 rewrites, Table 2)92/921.864×1.402×
    Repository-level function layer: optimized Lean vs original program (Table 2)15/920.235×0.217×
    Repository-level function layer: migrated Lean vs original program (Table 2)12/920.126×0.120×
    Repository-level application layer: optimized Lean vs migrated Lean (51 scenarios, Table 2)47/511.120×1.077×
    Repository-level application layer: optimized Lean vs original program (Table 2)3/510.148×0.160×
    • The authors state that the agent produced faster implementations for 156 of the 189 targets (82.5%), and retries contributed 21 improvements among the 54 retried functions; vfast1.25 = 37.6% (71 functions), vfast2 = 20.1% (38 functions) (Figure 4).
    • The authors classify the 92 rewrites into three patterns: algorithmic improvement (removing loops), representation improvement (cheaper data representation), and evaluation-order improvement (fast path for common inputs); the largest rewrite speedup is 18.53× (Figure 5b).
    • The authors state that function-level gains are retained but shrink after integration: application-level speedup is limited by the fraction of scenario time taken by the rewritten function, and the rest of the scenario (including I/O) is unchanged; all 17 repositories become faster by per-repository geometric mean, but 4 scenarios do not become faster.

    Case Studies

    • Three largest speedups: the highest is 128,292×, from replacing iterative arithmetic summation with a closed-form polynomial; a dynamic programming rewrite (Figure 2) is 4,467.871× faster on a 261-input corpus (Appendix D.1).
    • Reusing verified library algorithms: the SquareRoot rewrite calls Mathlib's logarithmic-time Nat.sqrt and is 21.16× faster; isPerfectSquare is similarly rewritten and is 17.97× faster.
    • Exploiting problem properties: the majorityElement rewrite returns early when a count exceeds half and is 3.74× faster; nthUglyNumber replaces a list with an array with unchanged control flow and is 124.90× faster.

    Migration Quality (AQUEDUCT vs single agent)

    • Hidden-test recovery: on 40 repositories, AQUEDUCT ports pass 16,345 of the 18,642 tests supported by the original programs (87.68%), and the single-agent baseline passes 12,709 (68.17%), a difference of 19.50 percentage points.
    • Sources of the difference: on 9 repositories the single-agent ports pass 0 tests while AQUEDUCT recovers 61.10%–100%, contributing 2,685 of the net increase of 3,636 tests; the other 12 repositories' 960 incremental tests come from long-tail cases such as rare option combinations, malformed and boundary inputs, and exact diagnostics and exit conventions; the single agent leads on 4 repositories, by at most 5 tests.
    • Mutation analysis of generated tests (Appendix B): on 36 compilable mutants from 9 repositories, generated tests kill 28 (77.8%) and ProgramBench hidden tests kill 17 (47.2%) (Table 3); the full audit overall (25 repositories, 190 mutants) kills 101 (53.2%, 95% interval 39.1%–67.0%) (Table 4).

    Other Ablations and Analyses

    • Migration component ablation (Figure 6, recovery): full pipeline 87.68%; single-round repair 79.22%; no coverage guidance 77.88%; no mutation feedback 77.63%; no candidate combination (best single strategy) 72.96%; single agent 68.17%; fixed-stage pipeline 53.32%.
    • The authors state that removing candidate diversity causes the largest drop; the fixed-stage pipeline is below the single-agent baseline, from which the authors conclude that the agent should be free to arrange its work and strictness should be concentrated in the acceptance criteria.
    • 7zip case (Appendix D.2): 252,968 lines, the port recovers 554 of the 883 tests supported by the original program (62.74%), versus 28.77% for the baseline; when the budget is exhausted, the obligation list still lists 938 behaviors for which evidence has not been established.
  5. What are some points that can be further explored?

    The authors list eight research directions in Section 6; the experiments use only a single agent configuration and do not report token budgets or elapsed time.

    Limitations and Future Directions Noted by the Authors

    • Allocating effort between implementation and proof (Section 6): compare strategies such as optimize-then-prove, prove-while-modifying, and interleaving under matched time and token budgets; compare the transformations the agent attempts with and without a proof requirement.
    • Reusing proofs across optimizations (Section 6): compare the effect on proof cost of fresh proof search versus reusing prior lemmas; distinguish within-repository reuse from cross-repository transfer; study adapting rewrites and proofs during software evolution.
    • Target selection for application performance (Section 6): compare source inspection versus profile-guided selection; compare local function rewrites versus module-level rewrites; in the Conclusion the authors also note that target selection should consider the fraction of application runtime taken by the function.
    • Workload specialization (Section 6): this study hides the evaluation workload and requires exact equality; the authors propose replacing support specialization with a guard on predicate P and measuring the additional speedup from specialization.
    • Learning from optimization trajectories (Section 6): train on trajectories linking candidate programs, measured performance, and proof states, and evaluate on held-out repositories.
    • Extending equivalence relations and the optimization space (Section 6): extend equivalence to opaque effects (IO, network), concurrency, and weaker relations (e.g., floating-point error bounds); extend rewrites to explicit memory layout, unboxed representations, and vector instructions; the authors note that optimizing the I/O paths of the Section 5 applications requires this extension. Two further directions are certified migration (also proving the path from the original program to the Lean port) and proving performance properties (cost models, asymptotic bounds).

    Scope of the Experiments

    • The agent under test is one configuration, Codex with GPT-5.6 Sol (xhigh reasoning); the paper does not report token budgets, elapsed time, or comparisons across agents.
    • Function level covers Verina's 189 reference implementations (108 basic, 81 advanced), with each of the 54 functions not sped up in the first round retried once.
    • Repository-level optimization covers 17 migrated ports (C, C++, Go, Rust programs), 92 rewrites, and 51 application scenarios (3 per repository); migration quality evaluation covers 40 ProgramBench repositories.
    • Equivalence checking applies only to functions whose effects are expressible in Lean (pure functions and monads such as StateM and Except), excluding IO and external calls (Appendix A).
    • Timing is performed on Lean 4.18.0, AMD EPYC 9654 single logical CPU, with nine paired trials; the paper does not report the number of repetitions of optimization calls.
  6. Summarize the main content of the paper

    The agent jointly searches for faster implementations and equivalence proofs in Lean 4, achieving verified speedups at both the function level and the migrated-application level, but application-level gains are smaller.

    A paper on agentic program optimization: it formalizes optimization as searching for a faster implementation under an equivalence constraint, using the existing implementation as the specification, bypassing the specification-writing bottleneck, and replacing exploitable tests with machine-checked proofs.

    • Problem: tests can only find errors, not prove their absence; when tests define the reward, agents reward hack, and the authors cite existing examples of a 6× fake speedup and a 39.5% kernel correctness failure rate.
    • Method: agentic verified optimization—the agent produces f′ and a proof π : f = f′, which the Lean kernel accepts in a fresh copy of the repository; the accompanying AQUEDUCT migrates C/C++/Go/Rust programs to native Lean, builds a corpus using differential testing, coverage, fuzzing and mutation testing, and verifies each port.
    • Function-level results: of 189 Verina reference implementations, 156 obtained faster verified rewrites, with a geometric mean of 1.851× and a median of 1.117× (Table 1); the largest case reached 128,292×.
    • Repository-level results: on 17 migrated applications, all 92 rewrites passed the kernel check and were faster, with a function-level geometric mean of 1.864×; of 51 application scenarios, 47 became faster, with an application-level geometric mean of 1.120× (Table 2).
    • Migration quality: AQUEDUCT ports achieved 87.68% recovery on ProgramBench hidden tests, versus 68.17% for the single-agent baseline.
    • The authors' conclusions: the authors state that current agents can already perform verified optimization on standalone functions and migrated applications; application-level gains are smaller than function-level gains, and 4 scenarios did not become faster, so local speedup does not guarantee a faster application, and target selection is a key problem; the optimized Lean is still overall slower than the original programs (function-level geometric mean 0.235×), and the authors list I/O paths and lower-level optimization opportunities as future directions.

Related papers

Read originalarxiv.org