Manuscript Offprint

arXiv:2610.35595

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

Per Kristian Lehre

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

LLMs now prove hard theorems in Lean. Can they also design algorithms and prove their correctness and efficiency? LLM-guided design of optimisation heuristics (such as AlphaEvolve) is purely empirical. Automated theorem provers with LLMs prove given statements. So far, there has been little evidence that LLMs can do both: design an algorithm and guarantee its efficiency by a mathematical proof. We present a staged pipeline modelled after research methodology in design and analysis of evolutionary algorithms. The agent proposes black-box optimisation algorithms, and Lean guards filter out flawed designs. The agent then defines a potential function and proves drift bounds that guarantee an expected runtime improvement over the baseline algorithm. At no point in the pipeline are the algorithms compared empirically. The agent generates a black-box optimisation algorithm with expected runtime O(n2)O(n^2) on a CYCLEUNCOVER problem, where the classical (1+1)(1+1) EA needs runtime eΩ(n)e^{\Omega(n)}. The pipeline also designs and analyses a black-box optimisation algorithm for integer-valued submodular minimisation with expected runtime O(n2+2c)O(n^{2+2c}), and it matches the optimal order O(n2)O(n^2) on LEADINGONES. Across 8 problem classes, 12 of 15 runs with frontier models complete the pipeline with a machine-checked expected-runtime bound. In 9 of them the bound is polynomial without relying on offline computation, which the black-box model does not charge. An ablation study shows that removing the staging and asking the agent to zero-shot an algorithmic design with a runtime guarantee leads to a copy of the seeded baseline algorithm (random search) or to incomplete proofs. Open-weight models (Goedel-Prover-V2-32B and Gemma 4) did not complete the pipeline. Our study suggests that machine-checked specifications in Lean can replace empirical evaluation in open-ended algorithm discovery. To the best of our knowledge, this is the first example of an automated pipeline that designs efficient black-box optimisation algorithms with machine-checked runtime bounds in Lean.

1 INTRODUCTION

From the perspective of theoretical computer science, algorithm design must produce two artefacts: First, the algorithm itself, a finite sequence of instructions that when executed in a computational model transforms within a finite number of steps any problem instance (the input) into an output (the solution) (Knuth, 1997). Secondly, the analysis of the algorithm, a mathematical proof that the algorithm produces the correct output on every problem instance, and a guarantee for the amount of computational resources required by the algorithm to produce that output (its complexity). In the context of machine learning, analysis also involves guaranteeing additional algorithmic properties, such as convergence rates, and regret and/or generalisation bounds. Inventing new and better algorithms involves an iterative developmental process between the two artefacts: a new candidate design drives the analysis in a certain direction, and obstacles in completion of the analysis can lead to insights into problem structure which motivate alterations to the algorithm design. The high cost and deep expertise needed for traditional algorithmic design have motivated research into automated design of heuristics. Recent LLM-based heuristic design approaches evaluate a candidate pool of heuristics on benchmark functions, and well-performing heuristics are varied through LLM-prompts to produce better ones. While this has been successful in many domains, the methodology is highly empirical and does not lead to any guarantees on the correctness or performance of the heuristics produced.

It is a significant open problem whether AI agents can carry out algorithmic design as seen from theoretical computer science. It has been argued that automated theorem proving (ATP) is challenging for AI, because proofs are either correct or incorrect, not in-between. Furthermore, the space of proofs is infinitely large (Buzzard, 2024). Formal algorithmic design goes beyond ATP, because it requires both navigating a space of algorithmic designs and automatically proving properties about these. Yet, the improvement in mathematical capability of frontier AI models over the last years has been remarkable. Long-standing conjectures have been closed using publicly available reasoning models with Lean-checked proof certificates (Sothanaphan, 2026). The time and cost needed to rigorously prove non-trivial mathematical statements have fallen significantly.

We take inspiration from the field of runtime analysis of evolutionary algorithms which has a well-defined approach to design and analysis. The field requires that algorithms fit in a black-box optimisation framework (Droste et al., 2006) (more often called the query model in TCS) where optimisation is formulated as an interaction between an oracle which knows the function to be optimised, and an algorithm which queries the oracle for fitness values. The field has developed a small number of highly generic mathematical tools that aid in the analysis. In particular, we build on drift analysis (Hajek, 1982; He & Yao, 2001) which measures the progress of the algorithm with a potential function. The potential function, which is introduced for the purpose of the analysis and is not part of the algorithm itself, maps the state of the algorithm into a potential value. Bounds on the runtime can be obtained from properties of the distribution of the drift (change in potential per oracle query). The black-box model allows for an enormous variety of algorithms, most of which are useless. To constrain algorithm search, we use Lean guards to filter out provably flawed designs. We only allow algorithms that are able to visit all parts of the search space, that use randomness, and that take into account fitness responses from the oracle. The full staged pipeline is shown in Figure 2. The pipeline is seeded with a problem card that provides the definition of the problem, its problem instances, and basic properties. Additionally, the pipeline is seeded with an initial algorithmic design with a stated runtime bound. In all the experiments described here, we use uniform random search as the initial algorithm, with expected runtime O(2n)O(2^n). The staged pipeline consists of some informal stages where an informal model produces one or more prose descriptions of designs. There are also formal stages where the agent needs to synthesise a definition or a proof that is then verified by Lean. In case Lean reports a failure, the formal stage is repeated, until it backtracks (determined by a Luby sequence (Luby et al., 1993)), or the formal stage passes. Some formal stages are gates to filter out flawed designs, others collect definitions that are used later, e.g., the definition of the algorithm or the potential. If a run reaches the end of the pipeline, it obtains an algorithm Ai+1A^{i+1} with a guaranteed improved runtime compared to algorithm AiA^i. The pipeline can be looped, e.g., producing an algorithm Ai+2A^{i+2} which beats Ai+1A^{i+1}, and so on. In most of the experiments described here, we make one iteration of the loop; two runs iterate it for three and five generations.

Contributions. To our knowledge, we propose the first automated system for formal design and analysis of black-box algorithms for pseudo-Boolean optimisation. The system does not involve any empirical evaluation or comparison of algorithms. The entire design process is driven by informal algorithm proposals followed by mathematical formalisation and analysis in Lean. Our contributions are:

• We formalise the human process of designing and analysing black-box optimisation algorithms through a staged pipeline which combines LLMs with Lean.

• We demonstrate that an agent using the staged pipeline is able to design efficient black-box algorithms with associated machine-checked runtime bounds in Lean for a range of problems. On CYCLEUNCOVER, the constructed algorithm has expected polynomial runtime, whereas the classical (1+1)(1+1) EA has exponential runtime. The agent is able to exploit structure in anonymised problem classes.

• We show through ablation studies that without the staged pipeline, the agent fails to construct efficient algorithms.

Table 1: Overview of some related work in automating the design and formal analysis of algorithms. The first group machine-checks analyses of human-designed algorithms. The second group produces machine-checked proofs, but of a theorem or specification given to it. The third group discovers algorithms, but validates them only empirically. This work lies at the intersection: the algorithm is proposed by an LLM, its analysis is produced by an LLM, and the property machine-checked is the expected runtime of a stochastic process.

WorkAlgorithmic artefactProcessDesigned byAnalysed byMachine-checked property
Li et al. (2024)first-order convex methodsdeterministichumanhumanconvergence rate
Vajjha et al. (2021)value / policy iterationstochastic (MDP)humanhumanconvergence
Schäffeler & Abdulaziz (2025)approximate policy iterationstochastic (MDP)humanhumanconvergence
Ospanov et al. (2025); Varambally et al. (2025); Li et al. (2026)(proof / code search)n/an/aLLMgiven theorem or code specification
Romera-Paredes et al. (2024); Novikov et al. (2025); Lange et al. (2025)heuristics, constructions—LLM—none (empirical validation)
van Stein & Bäck (2025)black-box optimisation algorithms (metaheuristics)stochasticLLM—none (empirical benchmarking)
This workblack-box optimisation algorithmsstochasticLLMLLMcorrectness & expected runtime

References (63)