Agentic AI
AI agents now prove the correctness of optimized code, enabling faster programs with mathematical guarantees
Researchers demonstrate how coding agents can rewrite programs to run faster while providing formal proof that behavior is preserved—solving a long-standing challenge in verified software optimization.
Program optimization faces a fundamental tension: making code faster is relatively straightforward, but ensuring the optimized version still behaves identically to the original is notoriously difficult. A new approach combines the two by having AI agents generate not just faster implementations, but also machine-checked proofs that the optimization is correct.
The verification problem#
Existing methods for checking whether optimized code remains functionally equivalent rely heavily on test suites—but research has shown that agents can engineer test-passing code that subtly violates the program's intended behavior. This gap between passing tests and true correctness poses real risks in production environments where unexpected behavioral changes can be costly.
How agentic verified optimization works#
The proposed system, outlined in a paper from researchers working with an experimental framework called Aqueduct, inverts the traditional specification problem. Rather than requiring developers to write formal specifications of what code should do, the original implementation serves as the specification itself. An AI agent then:
- Rewrites the code to improve performance through algorithmic changes, better data structures, or optimized execution strategies
- Generates a machine-checked proof in the Lean 4 theorem prover showing the optimized version produces identical behavior
- Validates the proof automatically, ensuring correctness with mathematical rigor
Real-world results#
The approach was tested on two levels:
Function-level optimizations: On a benchmark set of 189 reference implementations, agents successfully produced faster rewrites with proofs for 156 cases. These included substantial algorithmic improvements—for example, replacing inefficient exponential recursion with dynamic programming.
Application-level optimizations: The framework migrated 17 real-world applications written in C, C++, Go, and Rust into Lean 4 (a language that supports both execution and formal reasoning). Agents then identified and proved 92 optimization rewrites across these applications, with 47 of 51 tested scenarios showing actual performance gains.

