It is commonly understood that factoring a general $n$-bit biprime via Shor's order finding algorithm requires $\widetilde{O}(n^3)$ gates by leveraging schoolbook integer arithmetics for addition and multiplication. Recent developments in quantum arithmetic circuits leveraging recursive Toom-Cook schemes have improved the cost scaling to $O(n^{2+ε})$. Here $ε>0$ depends on algorithm implementation details of the recursive multiplication steps, which allow for a vast number of design choices. The challenge in navigating such design space also presents an opportunity for demonstrating innovative practices in quantum software engineering in the era of open agentic science. We present a formally verified harness that ingests a design specification (namely a "policy" that describes a recursive circuit design scheme) from an external source, which may be an AI agent, and produces a set of formalized proofs covering mathematical correctness of the algorithm implementation, asymptotic scaling of the end-to-end gate cost, as well as the correctness of translating the verified algorithm to a detailed circuit implementation with an intermediate representation. The harness is published as an open challenge where human researchers and AI agents can search for more efficient factoring circuits while retaining machine-checked guarantees of correctness and end-to-end asymptotic complexity.
AI Summary
The paper addresses how to optimize recursive fast arithmetic for Shor’s order-finding algorithm while retaining machine-checked correctness and complexity guarantees. It presents ForShor, a Lean 4 harness accepting policies that specify Toom–Cook splitting arities, interpolation programs, and register-width thresholds. Policies must prove distinct interpolation points, correct evaluation checkpoints, exact shifts, and restoration of arithmetic registers.
For every valid policy, reusable proofs establish order-recovery success, approximation bounds, and semantics-preserving compilation from high-level circuits to a lower-level circuit language. If the policy’s highest-width table has arity $k$, the lowered gate count is $O(n^{1+\log_k(2k-1)})$; choosing sufficiently large fixed $k$ gives $O(n^{2+\epsilon})$ for every fixed $\epsilon>0$. This formalizes an existing fast-arithmetic construction rather than introducing its asymptotic speedup. The implementation combines recursive phase-product multiplication, a Cooley–Tukey QFT, and approximate modular multiplication requiring $O(\log n)$ additional precision qubits.
A symbolic intermediate representation supports Qualtran resource estimation. At 2048 bits, a variable-arity policy gives an estimated $1.685\times10^{12}$ T gates; the reported crossover against the Gidney–Ekerå factoring construction occurs around 3.8 million bits. An unformalized exact optimizer over independent recursion trees has claimed runtime $2^{O(K^4)}\operatorname{poly}(n)$, with table synthesis the bottleneck.
Formal verification stops before Qualtran translation and rotation synthesis; downstream estimates use numerical validation and mean synthesis costs. Other stated limitations include restricted policies, exact QFTs, ripple-carry adders, no physical-resource analysis, and highly extrapolated exact-search runtime projections.
Some signs of AI-generated textAI use disclosedOverclaimsUnclear writing
This preface was written by a human, and the subsequent sections with AI assistance and edited for clarity.
Error found: The fitting function stated for full order-finding resource curves omits the factor n required by the number of controlled modular multiplications, contradicting the paper's own full-algorithm exponent.
The main-text and Appendix B rotation-synthesis formulas correspond to inconsistent per-rotation error budgets, so their numerical T-count objectives are not identical as written.
The introduction mischaracterizes a search-specific runtime extrapolation involving an infeasible zero-charge relaxation as the cost of certifying the best-known feasible RSA-2048 policy.
Written by gpt-6.1-sol from the paper's full text. Automated: it can be wrong.
33 pages (13 pages of main text and the rest are appendices), 8 figures. Project website: https://forshor.ai , Lean formalization: https://verifiedqc.github.io/ForShor/
Formally verified harness for Shor's order finding algorithm with O(n2+ε) gate cost
It is commonly understood that factoring a general n-bit biprime via Shor's order finding algorithm requires O(n3) gates by leveraging schoolbook integer arithmetics for addition and multiplication. Recent developments in quantum arithmetic circuits leveraging recursive Toom-Cook schemes have improved the cost scaling to O(n2+ε). Here ε>0 depends on algorithm implementation details of the recursive multiplication steps, which allow for a vast number of design choices. The challenge in navigating such design space also presents an opportunity for demonstrating innovative practices in quantum software engineering in the era of open agentic science. We present a formally verified harness that ingests a design specification (namely a "policy" that describes a recursive circuit design scheme) from an external source, which may be an AI agent, and produces a set of formalized proofs covering mathematical correctness of the algorithm implementation, asymptotic scaling of the end-to-end gate cost, as well as the correctness of translating the verified algorithm to a detailed circuit implementation with an intermediate representation. The harness is published as an open challenge where human researchers and AI agents can search for more efficient factoring circuits while retaining machine-checked guarantees of correctness and end-to-end asymptotic complexity.
The paper addresses how to optimize recursive fast arithmetic for Shor’s order-finding algorithm while retaining machine-checked correctness and complexity guarantees. It presents ForShor, a Lean 4 harness accepting policies that specify Toom–Cook splitting arities, interpolation programs, and register-width thresholds. Policies must prove distinct interpolation points, correct evaluation checkpoints, exact shifts, and restoration of arithmetic registers.
For every valid policy, reusable proofs establish order-recovery success, approximation bounds, and semantics-preserving compilation from high-level circuits to a lower-level circuit language. If the policy’s highest-width table has arity k, the lowered gate count is O(n1+logk(2k−1)); choosing sufficiently large fixed k gives O(n2+ϵ) for every fixed ϵ>0. This formalizes an existing fast-arithmetic construction rather than introducing its asymptotic speedup. The implementation combines recursive phase-product multiplication, a Cooley–Tukey QFT, and approximate modular multiplication requiring O(logn) additional precision qubits.
A symbolic intermediate representation supports Qualtran resource estimation. At 2048 bits, a variable-arity policy gives an estimated 1.685×1012 T gates; the reported crossover against the Gidney–Ekerå factoring construction occurs around 3.8 million bits. An unformalized exact optimizer over independent recursion trees has claimed runtime 2O(K4)poly(n), with table synthesis the bottleneck.
Formal verification stops before Qualtran translation and rotation synthesis; downstream estimates use numerical validation and mean synthesis costs. Other stated limitations include restricted policies, exact QFTs, ripple-carry adders, no physical-resource analysis, and highly extrapolated exact-search runtime projections.
Large language models are increasingly assisting with demanding formal theorem-proving tasks, particularly when grounded in machine-checked libraries such as Lean. Agentic systems further amplify this process by searching, reusing, and extending existing formal developments to uncover new discoveries. In quantum computing, Shor's algorithm and its variants present such a demanding case for Lean formalization. In this work, we formalize this algorithm family in Lean through agentic formalization: software agents analyze sources, write Lean code and repair proofs, with human review of the scientific claims and machine checking of the resulting formal proofs. Our formalization develops the mathematical foundations for analyzing quantum attacks in two cryptographic settings: a 2048-bit modulus in the RSA-2048 and the standardized elliptic curve over a 256-bit prime field (P-256). To support these analyses, the formalization ranges from quantum algorithms for order finding to reversible quantum circuits for modular and elliptic-curve arithmetic. Based on [Quantum 5, 433] and [ASIACRYPT 2017, 241--270], we formalize the logical resource estimates for RSA-2048 and P-256, respectively, and provide additional estimates of classical operations. We expect the results pave the way for broader machine-checked quantum cryptanalysis and represent a step toward AI-assisted design and verification of quantum algorithms.
Compiling quantum algorithms for real devices involves hard optimization problems that can decide whether an algorithm runs at scale. We present a general method for solving such problems with AI agents, with every result certified. It builds on autoresearch loops, in which agents iteratively improve programs against a fixed evaluator and which have recently improved quantum cryptanalysis circuits, and adds two elements: a frozen, exact verifier certifies every result, and this verifier, together with the challenge around it, is built by an agent that formulates the problem with a researcher and validates the verifier against a solved case, deliberately broken solutions and published results before any solution exists. The method applies to any optimization problem whose solutions can be verified exactly and efficiently. We apply it to three compilation problems in quantum simulation, namely fermion-to-qubit encoding, Hamiltonian layout and unitary synthesis. In each, the agents improved substantially on published or standard constructions, reducing the cost being optimized by up to 73% at the largest sizes tested and outperforming a state-of-the-art optimizer for fermion-to-qubit encodings. Every submission is a program accompanied by its agent's notes, so the ideas behind each improvement are recorded in human-readable form; later agents built on them, and we describe them here. These results open the way to automated, certified discovery across quantum circuit design and beyond.
Quantum computing technology may soon deliver revolutionary improvements in algorithmic performance, but it is useful only if computed answers are correct. While hardware-level decoherence errors have garnered significant attention, a less recognized obstacle to correctness is that of human programming errors-"bugs." Techniques familiar to most programmers from the classical domain for avoiding, discovering, and diagnosing bugs do not easily transfer, at scale, to the quantum domain because of its unique characteristics. To address this problem, we have been working to adapt formal methods to quantum programming. With such methods, a programmer writes a mathematical specification alongside the program and semiautomatically proves the program correct with respect to it. The proof's validity is automatically confirmed-certified-by a "proof assistant." Formal methods have successfully yielded high-assurance classical software artifacts, and the underlying technology has produced certified proofs of major mathematical theorems. As a demonstration of the feasibility of applying formal methods to quantum programming, we present a formally certified end-to-end implementation of Shor's prime factorization algorithm, developed as part of a framework for applying the certified approach to general applications. By leveraging our framework, one can significantly reduce the effects of human errors and obtain a high-assurance implementation of large-scale quantum applications in a principled way.
We propose Open Autoresearch, a paradigm in which humans and AI agents publish evaluator-verified improvements to a public leaderboard. We instantiate it in ECDSA.Fail, optimizing reversible secp256k1 point-addition circuits, a bottleneck in Shor's algorithm for elliptic-curve cryptography. The benchmark minimizes the spacetime-inspired score S=Q×T, where Q is peak logical qubit width and T is average executed Toffoli count. Participants reduced S by 86.1%. At the data cutoff (26 July 2026), the best-scoring circuit uses 1,151 qubits and 1,299,453 average executed Toffoli gates, giving Q×T≈1.496 billion. This is more than 50% below Google's published point-addition score thresholds (arXiv:2603.28846), under different accounting conventions. Because the benchmark supplies one addend classically, we construct a coherent windowed-addition-compatible variant implementing the single-call interface required by windowed Shor. It uses 1,162 qubits and 1,684,161 average executed Toffoli gates. On 100,000 random inputs, its empirical success probability is p^=0.99809, giving Q×T/p^≈1.961 billion under an independently rerunnable per-call sensitivity model, not a full-Shor success estimate. Its qubit and Toffoli counts lie below Google's published thresholds and Schrottenloher's reported operating points (arXiv:2606.02235), although differing interfaces, accounting conventions, and validation scope preclude formal dominance. After the cutoff, the score was further reduced to 1.259 billion, while a separate low-width circuit reached 813 qubits. The public record shows AI agents complementing human judgment, providing evidence for open autoresearch on efficiently evaluable, machine-checkable objectives.
The timeline by which quantum computers can solve breakthrough problems in science depends on improved quantum algorithms as much as on better hardware. Such algorithmic advances are typically achieved through many years of expert human collaboration. In mathematics and computer science, large language models have accelerated progress through automated discovery loops. However, quantum algorithms can only be evaluated by classical computers on restricted or small instances. Here we demonstrate automated discovery of quantum programs beyond these regimes including order-of-magnitude improvements on scientific applications. To achieve this, we build a quantum program library in the Lean theorem prover in which Gemini 4 agents synthesize novel programs against formal problem specifications and verify their correctness and cost. Agent teams collaborate, sharing results and knowledge through wikis and discussing ideas at organized conferences. Our results improve on prior baselines for parallel search (up to 2.57x), quantum arithmetic (290x), and simulations relevant to fusion, photochemistry and drug-metabolism by 12x, 8x and 2.5x respectively. Combining human and artificial intelligence at scale, under the rigor of mathematical proof, lets researchers design algorithms that today's classical and quantum computers cannot test, shortening the path to practical quantum computation.
While recent progress in quantum hardware open the door for significant speedup in certain key areas, quantum algorithms are still hard to implement right, and the validation of such quantum programs is a challenge. Early attempts either suffer from the lack of automation or parametrized reasoning, or target high-level abstract algorithm description languages far from the current de facto consensus of circuit-building quantum programming languages. As a consequence, no significant quantum algorithm implementation has been currently verified in a scale-invariant manner. We propose Qbricks, the first formal verification environment for circuit-building quantum programs, featuring clear separation between code and proof, parametric specifications and proofs, high degree of proof automation and allowing to encode quantum programs in a natural way, i.e. close to textbook style. Qbricks builds on best practice of formal verification for the classical case and tailor them to the quantum case: we bring a new domain-specific circuit-building language for quantum programs, namely Qbricks-DSL, together with a new logical specification language Qbricks-Spec and a dedicated Hoare-style deductive verification rule named Hybrid Quantum Hoare Logic. Especially, we introduce and intensively build upon HOPS, a higher-order extension of the recent path-sum symbolic representation, used for both specification and automation. To illustrate the opportunity of Qbricks, we implement the first verified parametric implementations of several famous and non-trivial quantum algorithms, including the quantum part of Shor integer factoring (Order Finding - Shor-OF), quantum phase estimation (QPE) - a basic building block of many quantum algorithms, and Grover search. These breakthroughs were amply facilitated by the specification and automated deduction principles introduced within Qbricks.