Agentic Algorithm Design: LLMs that Propose, Formalise, and Prove Runtime Bounds for Evolutionary Algorithms in Lean

Summary (Overview)

  • Novel pipeline: The paper presents a staged pipeline that combines LLMs with the Lean theorem prover to automatically design black-box optimisation algorithms and prove their expected runtime bounds—with no empirical evaluation whatsoever.

  • Key results: Across 8 problem classes, 12 of 15 runs with frontier models completed the pipeline with machine-checked runtime bounds. The agent designed an O(n2)O(n^2) algorithm for a novel CYCLEUNCOVER problem where the classical (1+1) EA requires eΩ(n)e^{\Omega(n)} runtime, and achieved the classical O(n2)O(n^2) runtime on LEADINGONES.

  • Ablation findings: Removing the staging and asking for zero-shot algorithmic design leads to copies of the seeded baseline algorithm (random search) or incomplete proofs. Open-weight models (Goedel-Prover-V2-32B, Gemma 4) failed to complete the pipeline.

  • Submodular minimisation: Over five generations of the pipeline, the agent rediscovered projected subgradient descent on the Lovász extension for integer-valued submodular minimisation, improving the runtime bound from O(n3+2c)O(n^{3+2c}) to O(n2+2c)O(n^{2+2c}).

  • First of its kind: To the authors' knowledge, this is the first automated pipeline that designs efficient black-box optimisation algorithms with machine-checked runtime bounds in Lean.

Introduction and Theoretical Foundation

Background and Motivation

From a theoretical computer science perspective, algorithm design requires two artefacts: (1) the algorithm itself—a finite sequence of instructions, and (2) the analysis—a mathematical proof of correctness and complexity guarantees. Traditional algorithmic design is costly and requires deep expertise, motivating research into automated design of heuristics.

Recent LLM-based heuristic design approaches (e.g., AlphaEvolve, ShinkaEvolve, LLaMEA) evaluate candidate heuristics empirically on benchmark functions. While successful, these methods provide no guarantees on correctness or performance. The paper addresses the open problem of whether AI agents can carry out algorithmic design as understood in theoretical computer science—producing both algorithms and rigorous proofs of their efficiency.

Black-Box Optimisation Framework

The paper adopts the black-box optimisation scenario (also called the query model) from the theory of evolutionary algorithms:

  • An adversary picks a fitness function f∈Ff \in F, f:X→Rf: \mathcal{X} \to \mathbb{R}
  • The algorithm queries search points xtx_t and receives fitness values f(xt)f(x_t)
  • Runtime TA,fT_{A,f} is the number of queries until the algorithm queries an optimal search point
  • An algorithm is a tuple A=(Y,init,query,step)A = (\mathcal{Y}, \text{init}, \text{query}, \text{step})

The worst-case expected runtime over a function class is TA,F=max⁡f∈FE[TA,f]T_{A,F} = \max_{f \in F} \mathbb{E}[T_{A,f}].

Drift Analysis

The pipeline builds on drift analysis (Hajek, 1982; He & Yao, 2001), which measures algorithm progress via a potential function Φ:Y→R\Phi: \mathcal{Y} \to \mathbb{R}. The drift is the change in potential per time step: Zt+1−ZtZ_{t+1} - Z_t where Zt=Φ(yt)Z_t = \Phi(y_t).

The paper introduces a simplified drift theorem (Corollary 3.1) that avoids measure-theoretic complications. For all t∈Nt \in \mathbb{N}, with Xt∈[0,1]X_t \in [0,1]:

(1)1{t<T}p≤E[1{t<T}1{Xt+1≤Xt−ε}∣Gt](1) \quad \mathbb{1}_{\{t < T\}} p \leq \mathbb{E}\left[\mathbb{1}_{\{t < T\}} \mathbb{1}_{\{X_{t+1} \leq X_t - \varepsilon\}} \mid \mathscr{G}_t\right] E[1{t<T}1{Xt<Xt+1}∣Gt]≤1{t<T}p/2,(2)\mathbb{E}\left[\mathbb{1}_{\{t < T\}} \mathbb{1}_{\{X_t < X_{t+1}\}} \mid \mathscr{G}_t\right] \leq \mathbb{1}_{\{t < T\}} p/2, \tag{2} E[1{t<T}1{Xt+ε<Xt+1}∣Gt]≤1{t<T}εp/4.(3)\mathbb{E}\left[\mathbb{1}_{\{t < T\}} \mathbb{1}_{\{X_t + \varepsilon < X_{t+1}\}} \mid \mathcal{G}_t\right] \leq \mathbb{1}_{\{t < T\}} \varepsilon p/4. \tag{3}

These conditions together yield the runtime bound E[TA]≤4/(εp)\mathbb{E}[T_A] \leq 4/(\varepsilon p).

Methodology

The Staged Pipeline

The pipeline (Figure 2 in the paper) is seeded with a problem card and an initial algorithm (uniform random search with expected runtime O(2n)O(2^n)). It consists of informal stages (prose descriptions) and formal stages (Lean definitions/proofs verified by the prover). Stages are repeated upon Lean failure, with backtracking determined by a Luby sequence.

Algorithm Design Stages (0–8):

  • Stage 0 (DesignLock): Agent proposes informal algorithm design with justification
  • Stage 1 (ConstructAlgorithmComponents): Formalise the algorithm as tuple A=(V,init,step,query)A = (\mathcal{V}, \text{init}, \text{step}, \text{query})
  • Stage 2 (Completeness): Algorithm must be able to query any search point from any reachable state
  • Stage 3 (NonAbsorbing): Algorithm must use randomness
  • Stage 4 (NotRandomSearch): Algorithm must differ from uniform random search
  • Stage 5 (Adaptiveness): State update must depend on fitness responses
  • Stage 6 (QueryNonInjectivity): State must carry information beyond the current query

Potential Function Stages (9a–9f):

  • Agent proposes candidate potential functions with a "drift story"
  • Potential must be in [0,1][0,1], measurable, and zero iff the state queries an optimum
  • Guard against two-valued potentials (0 and 1 only)

Drift Certificates and Runtime Bound (10a–10j):

  • Define sets Good(y), Worsen(y), BigWorsen(y) for each state y
  • Prove drift conditions (1)–(3) of Corollary 3.1
  • Prove jump probability lower bound pjumpp_{\text{jump}}
  • Final stage applies the runtime bound E[TA]≤4/(εp)\mathbb{E}[T_A] \leq 4/(\varepsilon p)

Models and Implementation

  • Frontier models: Claude Opus 5, Opus 5.5, Fable 5.1 (CLI backend)
  • Open-weight models: Goedel-Prover-V2-32B (formal stages, pass@256) + Gemma 4 26B-A4B (prose stages) via vLLM backend
  • Two backends: CLI and vLLM, with the Kimina Lean server

Empirical Validation / Results

Benchmark Functions

#ProblemModelAlgorithmRuntime Bound
1ONEMAXOpus 5(1+1) EA, rate 1/(n+1)1/(n+1)O(n3)O(n^3)
2LEADINGONESOpus 5.5fitness-dependent rate 1/(LO+2)1/(LO+2)O(n3)O(n^3)
3LEADINGONES, e−1e^{-1} lemmaOpus 5.5fitness-dependent rate 1/(LO+2)1/(LO+2)O(n2)O(n^2)
4JUMPk_kOpus 5.5(1+1) EA, rate 1/(n+1)1/(n+1)O(nk+2)O(n^{k+2})
5JUMPk_k, e−1e^{-1} lemmaOpus 5.5rate cycling with learned phase bitO(nk+1)O(n^{k+1})
6CYCLEUNCOVERFable 5.1cycle walk (learn-then-solve)O(n2)O(n^2)
7WELLCOVEREDVCFable 5.1fitness-directed asym. mutationO(n4)O(n^4)
9WELLCOVEREDVC, anonymisedOpus 5.5regime-switching asym. mutationO(n4)O(n^4)
10VERTEXCOVER, flat fitnessFable 5.1edge probing + exact solveO(n3)O(n^3)
11BANDWIDTHVC, flat fitnessFable 5.1window probing + exact solveO(kn)O(kn)
14BANDWIDTHVCOpus 5.5window-repair random searchΘ(2n)\Theta(2^n)
15SUBMODULARMINOpus 5.5Lovász subgradient descentO(n2+2c)O(n^{2+2c})

CYCLEUNCOVER: A Novel Problem

The agent designed a fundamentally different algorithm from evolutionary approaches:

  1. Build a two-colouring of the cycle graph by walking along it
  2. Sample uniformly random vertices until finding an uncoloured neighbour of current vertex uu
  3. Colour it oppositely to uu and make it the new current vertex
  4. After O(n)O(n) steps, query the optimum (all vertices of one colour)

The algorithm needs O(n)O(n) queries per step in expectation (probability Ω(1/n)\Omega(1/n) of finding the single uncoloured neighbour), giving total runtime O(n2)O(n^2). This contrasts with the classical result:

Theorem 5.1: The expected runtime of the (1+1) EA on CYCLEUNCOVER is eΩ(n)e^{\Omega(n)}.

Submodular Minimisation Over Generations

The pipeline was looped for 5 generations on integer-valued submodular minimisation:

GenerationRuntime Bound
112nB2(2n+4)(n+1)=O(n3+2c)12nB^2(2n+4)(n+1) = O(n^{3+2c})
216n2B2(n+2)=O(n3+2c)16n^2B^2(n+2) = O(n^{3+2c})
332nB2(n+1)=O(n2B2)32nB^2(n+1) = O(n^2B^2)
5≈8.13⋅B2(n+1)2\approx 8.13 \cdot B^2(n+1)^2

The final bound O(n2+2c)O(n^{2+2c}) matches the asymptotic complexity of the classical Fujishige-Wolfe algorithm.

Ablation Studies

  • Zero-shot ablation: Without staging, the agent reproduced the seeded random search algorithm for CYCLEUNCOVER, or failed to produce a runtime bound (BANDWIDTHVC)
  • Weaker models: Claude Sonnet passed Stages 0–10g but failed at the mass bound (Stage 10h); open-weight models stopped much earlier (Stages 3–9d) and generated 25–124M output tokens per run

Theoretical and Practical Implications

On the Role of Formal Verification

The paper demonstrates that machine-checked specifications in Lean can replace empirical evaluation in open-ended algorithm discovery. This is significant because:

  1. It provides rigorous guarantees that empirical benchmarking cannot
  2. It eliminates the risk of overfitting to benchmark functions
  3. It enables verification of stochastic algorithms (not just deterministic ones)

On Algorithm Discovery

The pipeline discovered algorithms that differ qualitatively from standard evolutionary approaches:

  • CYCLEUNCOVER: A learn-then-solve strategy exploiting graph structure
  • VERTEXCOVER (flat fitness): An edge-probing strategy that "cheats" by exploiting the black-box model's free offline computation
  • Submodular minimisation: Rediscovery of Lovász subgradient descent, a classical convex optimisation technique

Limitations and Caveats

  • Runtime bounds are often not tight (e.g., O(n3)O(n^3) vs true O(nlog⁡n)O(n\log n) for ONEMAX)
  • The simplified drift theorem (Corollary 3.1) prevents multiplicative drift analysis
  • Only frontier models completed the pipeline; open-weight models failed
  • The black-box model does not charge for offline computation, enabling "cheating" strategies

Conclusion

The paper presents the first automated pipeline that designs efficient black-box optimisation algorithms with machine-checked runtime bounds in Lean. Key takeaways:

  1. Staging is essential: Breaking the design-and-analysis task into stages with formal guards is crucial for success; zero-shot attempts fail
  2. Formal verification works: Lean guards effectively filter out flawed designs and enable rigorous runtime guarantees
  3. LLMs can do theoretical computer science: The agent discovered novel algorithms for new problems (CYCLEUNCOVER) and rediscovered classical results (Lovász subgradient descent)

Future directions identified by the authors:

  • Richer drift theorems for tighter bounds
  • More iterations of the design loop
  • Extension to continuous search spaces
  • More comprehensive experimental design with statistical analysis

The authors acknowledge limitations: only frontier models completed the pipeline, the simplified drift theorem leads to non-tight bounds, and the search space is restricted to bitstrings. Nevertheless, this work establishes that automated formal algorithm design is feasible, potentially transforming how optimisation algorithms are discovered and verified.

Related papers