Manuscript Offprint
arXiv:2610.17708QEDIA: Quantum Program Verification in Lean
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
YUANJIE (COLLIN) REN*, Massachusetts Institute of Technology, USA and Atomic Inference Inc, USA
ZHICHENG ZHANG*, Griffith University, Australia
JUNYI LIU*, University of Maryland, USA
JINZHENG LI, Northeastern University, USA
YIDI QI, Harvard University, USA
MINGSHENG YING, University of Technology Sydney, Australia
Practical quantum programs interleave quantum and classical computation: classical data shape the quantum operations that are performed, and measurement outcomes shape the classical computation that follows. Formal verification of such programs in a proof assistant requires mechanizing a program logic that handles this interplay consistently at every level, from the mathematics of quantum mechanics, through program syntax and semantics, to specifications and proof rules. Such mechanizations, along with the program proofs built on them, typically require substantial manual effort.
We present QEDIA, a framework for verifying quantum programs with classical variables in Lean 4. At its foundation is an open library that formalizes the quantum Hoare logic QHL across all these levels and proves the logic sound for both partial and total correctness. We construct the library and the program proofs, under human supervision, using an LLM-based prover agent, whose general-purpose core we extend for quantum program verification. We illustrate QEDIA with verified programs including the quantum Fourier transform, phase estimation, repeat-until-success circuits, and Hamiltonian simulation.
CONTENTS
Abstract 1
Contents 1
1 Introduction 2
2 Motivating Examples 4
3 Preliminaries: QHL 7
3.1 Classical and Quantum Variables 7
3.2 Syntax and Semantics of qWhile 7
3.3 Formal Quantum States and Assertions 9
3.4 Proof System 10
4 Formalization in Lean and Library Organization 11
4.1 State Spaces and Programs 12
4.2 Execution Paths 13
4.3 Assertions and Validity 13
4.4 Proof Systems and Soundness 14
4.5 Code Metrics 14
5 The Prover Agent: Building the Library and Verifying Programs 15
5.1 Core Agent 15
5.2 Quantum Extension 16
These authors contributed equally to this work.
Authors' Contact Information: Yuanjie (Collin) Ren, Massachusetts Institute of Technology, Cambridge, MA, USA and Atomic Inference Inc, Cambridge, MA, USA, yuanjie@mit.edu; Zhicheng Zhang, School of Information and Communication Technology, Griffith University, Brisbane, Australia, iszczhang@gmail.com; Junyi Liu, Joint Center for Quantum Information and Computer Science, University of Maryland, College Park, MD, USA; Jinzheng Li, Department of Physics, Northeastern University, Boston, MA, USA; Yidi Qi, Harvard University, Cambridge, MA, USA; Mingsheng Ying, Centre for Quantum Software and Information, University of Technology Sydney, Sydney, Australia, Mingsheng.Ying@uts.edu.au.
Ren et al.
6 Verified Program Examples 17
6.1 Overview 17
6.2 Quantum Fourier Transform 18
6.3 Repeat-Until-Success 20
6.4 The Trotter Product-Formula Circuit 22
7 Related Work 23
8 Conclusion and Future Work 24
Acknowledgments 25
References 25
A Details of the Formalization 27
A.1 Deriving the Original Measurement Axiom 27
A.2 The RUS Program and Specification in Lean 28
B Further Verified Examples 29
B.1 The QFT on Arbitrary Inputs 29
B.2 Bell-State Preparation 29
B.3 Parallel Hadamard 30
B.4 Inverse QFT 30
B.5 Quantum Phase Estimation 31
B.6 Cluster-State Preparation 32
B.7 Building Blocks for Fermi-Hubbard Simulation 33
The same physics that constrains testing and debugging also reshapes the semantics a verifier must formalize. The programs considered here combine classical and quantum variables and operations. The classical–quantum interplay in such programs runs in both directions: classical variables determine the control flow, the gates applied, the qubits they act on, and their parameters; conversely, a measurement writes its outcome into the classical state, where it can influence the rest of the computation. Reasoning about such programs is the subject of a substantial body of work on quantum program verification [Chareton et al. 2021; Feng and Ying 2021; Hietala et al. 2021; Li et al. 2024; Liu et al. 2019; Ying 2011; Zhou et al. 2023].
Hoare logic is a cornerstone of classical program verification. Quantum Hoare logic [Ying 2011] was developed for purely quantum programs and later formalized in Isabelle/HOL [Liu et al. 2019] and Coq [Zhou et al. 2023]; a subsequent extension [Feng and Ying 2021] added classical variables. QHL [Ying 2026] extends this line of work with the features needed in practice: quantum arrays, parameterized gates, richer predicate syntax, and additional proof rules for reasoning about hybrid classical–quantum control. Specifications take the form of quantum Hoare triples , where the precondition and the postcondition each pair a classical formula with a quantum predicate that may depend on classical variables.
To use QHL for machine-checked program verification, we formalize it in the Lean 4 proof assistant [de Moura and Ullrich 2021]. The formalization spans the mathematics of quantum mechanics, program syntax and semantics, and the proof rules, which we prove sound. Mechanized verification of quantum programs, from the underlying libraries to the program proofs, typically requires substantial manual effort, as reflected in mature frameworks such as CoqQ [Zhou et al. 2023] and Qbricks [Chareton et al. 2021] and in the certified end-to-end verification of Shor's algorithm [Peng et al. 2023]. Mechanizing QHL is more demanding still, since the classical–quantum interplay must be handled consistently at each level of the formalization, as the examples in Section 2 illustrate.
This proof-writing effort motivates our use of theorem-proving agents that combine large language models (LLMs) with feedback from proof assistants [Baba et al. 2026; Breen et al. 2026; Li et al. 2026; Liu et al. 2026; Ren et al. 2026; Varambally et al. 2026]. The general approach is to generate candidate formal proofs and revise them using the proof assistant's diagnostics. In our work, LLM agents working under human supervision formalize the quantum program logic, build its supporting library, and construct the example proofs, all checked by Lean's kernel. To our knowledge, this is the first mechanized quantum program logic built by LLM agents.
This Paper and Its Contributions
This paper presents QEDIA, a framework for verifying quantum programs with classical variables in Lean 4, based on QHL and built on Mathlib [The mathlib Community 2020]. Its contributions are:
• A formalized quantum Hoare logic with proved soundness. QEDIA formalizes QHL for quantum while-programs with classical variables, quantum arrays, and parameterized gates. Its proof system is proved sound in Lean for both partial and total correctness. The formalization handles the classical–quantum interplay consistently at every level, from the mathematics of quantum mechanics to the proof system (Section 4).
• An agent-based proof-writing framework. A general-purpose core agent coordinates LLM agents to construct and review formal proofs, combining Lean checks with review of the intended mathematics. Its quantum extension supports applying QHL rules and adds quantum-specific checks (Section 5). We expect this workflow to be useful for future AI-assisted formal verification of quantum programs.
• A series of verified program examples. We illustrate QEDIA with eleven verified programs: preparation of the Bell state and a 1D cluster state; parallel Hadamard; the quantum Fourier transform and its inverse; quantum phase estimation; a repeat-until-success circuit; Hamiltonian simulation of the transverse-field Ising model by a Trotter product formula; and the Bravyi-Kitaev encoding, block encoding, and quantum signal processing for the Fermi–Hubbard model (Section 6 and Appendix B). To the best of our knowledge, some of these examples cannot be directly handled by existing quantum program verifiers, since they involve the classical–quantum interplay at both the program and specification levels.
The remainder of the paper is organized as follows. Section 2 uses three motivating examples to identify the levels at which the classical–quantum interplay must be handled. Section 3 provides background on QHL : its programs, assertions, and proof rules. Section 4 presents the Lean formalization of QHL and shows how it handles this interplay at each level. Section 5 describes the
https://github.com/qedia/quantum-formal-verification.
Ren et al.
i := 0; while i < n do H[q[i]]; j := 0; while j < n - 1 - i do cR(2π/2^{j+2})[q[i], q[i + 1 + j]]; j := j + 1 od; i := i + 1 od; i := 0; while i < [n/2] do SWAP[q[i], q[n - 1 - i]]; i := i + 1 od. (a) RUS (b) i := 0; while i < N do j := 0; while j < n do R_x(2a[j]δ)[q[j]]; j := j + 1 od; j := 0; while j < n - 1 do R_zz(2b[j]δ)[q[j], q[j + 1]]; j := j + 1 od; i := i + 1 od. (c) Trotter_n
Fig. 1. The three motivating programs. Classical variables include loop counters, measurement outcomes, and inputs; q is a quantum array, and a quantum operation acts on the qubits named in brackets.
prover agent that constructs the library and the program proofs. Section 6 is devoted to the verified program examples, with detailed derivations for the examples of Section 2. Section 7 discusses related work, and Section 8 concludes. Appendix A gives further details of the formalization, and Appendix B presents the remaining verified examples.
2 Motivating Examples
We now make the classical–quantum interplay described in Section 1 concrete. Through the three programs in Figure 1, we illustrate the capabilities that a verifier needs in order to handle this interplay at different levels.
Example 2.1 (Repeat-Until-Success). Our first example is a repeat-until-success (RUS) circuit. Such circuits use mid-circuit measurements and classical feedback, in contrast to ordinary unitary synthesis, to reduce the number of expensive T gates in implementing certain non-Clifford unitary gates [Bocharov et al. 2015; Paetznick and Svore 2014].
The program in Figure 1(a) presents an RUS implementation of the single-qubit unitary gate , using a two-qubit gate that is easier to construct from a few T gates [Paetznick and Svore 2014, Fig. 8]. Here, d is a data qubit, a is an ancilla qubit, and N is a classical input bounding the number of attempts. The variables N, k are natural numbers, and the measurement outcome m has type . The main component of the program is a while loop: in each iteration we reset the ancilla qubit a to , apply gate , measure a by the computational basis measurement , and assign the measurement outcome to the classical variable m. Given the specific , each iteration applies to data qubit d with probability 3/4 (indicated by m = 0) and leaves d unchanged with probability 1/4 (indicated by m = 1). The loop stops when m = 0 or the number of attempts reaches N.
The correctness of the RUS program in Figure 1(a) consists of two parts: the program terminates after applying to d or exhausting the N attempts, and it applies with probability bounded below in terms of N. Using the QHL framework, these two correctness conditions can be conveniently formalized as the following two Hoare triples:
and
Here, is an arbitrary initial state of d,
We omit a classical precondition or postcondition when it is true.
Intuitively, the first Hoare triple (1) guarantees that, with initially in , the program will terminate and it either applies successfully or exhausts the attempts and leaves in . The second Hoare triple (2) guarantees that the overall success probability in implementing the desired is at least .
Through the above example, we can see the classical–quantum interplay at both the program and specification levels. For the program, the classical variable m controls the while loop, yet its value in each iteration is set by measuring a. For the specification, in Hoare triples (1) and (2), the same classical variable m selects the successful branch and parameterizes the quantum predicate .
Example 2.2 (Quantum Fourier Transform). Our second example is the quantum Fourier transform (QFT). The QFT is a key subroutine of Shor's factoring algorithm [Shor 1997] and, through its inverse, the readout stage of quantum phase estimation [Cleve et al. 1998; Kitaev 1995].
The program in Figure 1(b) presents a standard QFT implementation [Coppersmith 1994] on a quantum array of qubits. Here, is the -th qubit of array , and we define the controlled phase gate for .
The main component of the program is a nested while loop: for each , we first apply the Hadamard gate to qubit . Then, for each , we apply to qubits , where both the qubit indices and the phase are parameterized by classical variables and . After these produce the Fourier phases, a final loop of SWAP gates reverses the qubit order.
The correctness of the QFT program in Figure 1(b) states that, for each fixed , the program terminates and maps computational basis states to the corresponding Fourier basis states. This can be formalized as the following Hoare triple:
\models_{t o t}\left\{\left|x\right\rangle\langle x\right|\right\}Q F T_{n}\left\{\left|\chi(n,x)\right\rangle\langle\chi(n,x)\right|\right\}. \tag{4}Here, the classical input is an array of bits representing the integer in binary, , and
is the Fourier basis state.
Intuitively, the Hoare triple (4) guarantees that, with initially in an arbitrary computational basis state , the program will terminate and leave in the corresponding Fourier basis state . We further verify the QFT on arbitrary inputs in Section 6.2.
The above example also illustrates the classical–quantum interplay at the program and specification levels. For the program, the classical variables determine both the qubit indices and the phase of the controlled phase gate. For the specification, the quantum predicates and both depend on the array .
Example 2.3 (The Trotter Product-Formula Circuit). Our third example is a Trotter product-formula circuit for Hamiltonian simulation. Such circuits approximate the quantum evolution generated by a sum of Hamiltonians [Lloyd 1996; Trotter 1959].
Ren et al.
The program in Figure 1(c) presents a first-order Trotter implementation of the evolution governed by the transverse-field Ising Hamiltonian
Here, is fixed, while the coefficient arrays , evolution time , and number of Trotter steps are classical inputs. The operators , are the Pauli operators on qubit . The main component of the program is a while loop: each iteration applies the single-qubit gate , with and , to every qubit . It then applies the two-qubit gate , with , to every , . The loop runs iterations.
The correctness of the Trotter program in Figure 1(c) is an approximation guarantee: the program terminates, and its output approximates applied to the input up to a target error. This correctness condition can be formalized as the following Hoare triple:
Here, is an arbitrary input state of , the classical input is the target error, , and is the operator norm. The classical precondition requires and that be at least the first-order Trotter error bound [Childs et al. 2021].
Intuitively, the Hoare triple (5) guarantees that, for every satisfying the classical precondition, the program will terminate and produce an output state with fidelity at least with the target state under the desired evolution .
Through the above example, we can see that the classical–quantum interplay enables us to express a correctness condition involving approximation. Showing exact implementation of the product formula alone does not establish the approximation guarantee of the Trotter circuit. Instead, in the Hoare triple (5), the classical variable represents the target error, and the quantum predicates are parameterized by .
To sum up, these motivating examples illustrate the intricacy in handling the classical–quantum interplay at the following two levels:
• (L1) Program syntax and semantics. Quantum programs contain both classical and quantum variables. Classical states can affect quantum states by the guards of control flow, indices for arrays, or parameters for gates and measurements. Quantum states can affect classical states by the outcomes of measurements. A program may also be parameterized, as and are by n.
• (L2) Specification and proof system. Building on (L1), the specification of program correctness contains both classical and quantum parts. Quantum predicates can depend on classical variables. Consequently, the proof system has to deal with the classical–quantum interplay as well.
Existing quantum verifiers such as [Chareton et al. 2021; Hietala et al. 2021; Li et al. 2024; Liu et al. 2019; Rand et al. 2018; Unruh 2019; Wu et al. 2025; Zhou et al. 2023] do not directly support the classical–quantum interplay at both levels: they admit the classical and quantum components only in a restricted combination, and none of them directly accommodates all of the specifications (1)–(5). A detailed comparison is presented in Section 7. QHL combines classical and quantum components as follows: classical variables, expressions, control flow, and classical formulas in specifications keep the same roles as in classical programs, and the quantum components are built around them. However, mechanizing such a framework as a Lean library requires more than encoding the proof rules. We further need to handle the classical–quantum interplay at the following level:
• (L0) Mathematics and quantum mechanics. Formalizing the semantics of quantum programs requires supporting structures from mathematics and quantum mechanics, including Hilbert spaces, states, linear operators, tensor products, probabilities, variables, gates, and measurements. While some of these can build on the existing Mathlib in Lean, one also needs to account for new requirements imposed by the classical–quantum interplay at higher levels (L1) and (L2). Conversely, the design choices at this level determine how conveniently the higher levels can be expressed.
A good mechanization must therefore handle the classical–quantum interplay at all three levels together. Section 4 describes how QEDIA does so.
3 Preliminaries: QHL
In this section, we briefly introduce the background on QHL [Ying 2026]. This includes quantum programs, their correctness specification, and its proof system.
3.1 Classical and Quantum Variables
Classical variables. A classical variable has a type, such as integers or booleans. A classical state assigns to each classical variable a value of the corresponding type. Evaluating a classical expression gives its value . We use to denote that the classical formula holds in .
Simple quantum variables. A simple quantum variable has a Hilbert space as its quantum type. The state space of a set of several quantum variables is the tensor product of their Hilbert spaces, denoted by . The joint state space of all quantum variables is denoted by . An operator on a subsystem acts on a larger system by tensoring it with the identity on the remaining quantum variables.
Quantum arrays and subscripted quantum variables. An array quantum variable of type consists of quantum variables indexed by a classical type , each with state space . Its joint state space is . If is a classical expression of type , the subscripted quantum variable denotes the quantum variable in classical state . We write . For a simple quantum variable, .
For example, the Trotter circuit (Example 2.3) applies gates to and , where the indices are parameterized by the classical variable . For a sequence of quantum variables, an operation acting on it should require
For example, requires .
3.2 Syntax and Semantics of qWhile
Syntax. Figure 2 gives the syntax of qWhile . Most components are self-explanatory. Here, we emphasize the interplay between classical and quantum parts. As usual, the guards in if and while statements are classical. In , the parameters and indices for subscripted quantum variables in are also classical. In the other direction, a measurement assigns its outcome value to a classical variable. That value can enter subsequent expressions: in the RUS program of Example 2.1, the outcome appears in the loop condition . We write for .
Ren et al.
Fig. 2. Syntax of qWhile . Here, x is a classical variable, e and are classical expressions, b is a classical boolean expression, q is a quantum variable, is a sequence of quantum variables, is a unitary gate parameterized by , and M is a measurement.
Fig. 3. Operational transition rules of qWhile . Here, the update is defined as if , and if . The unitary operator represents acting on . Each measurement operator corresponds to an outcome and also acts on . The initialization is defined as . The condition Dist is as defined in (6).
Operational semantics. We define a classical–quantum state, or cq-state, to be a pair , where is a classical state and is a partial density operator, that is, and . The quantity is the probability carried by this cq-state. This treatment makes it convenient to describe measurements in the operational semantics.
A configuration is , where is a remaining program to be executed or the termination symbol . The operational semantics of programs in Figure 3 defines rules for the transition between configurations.
Denotational semantics and termination. For an input cq-state , the denotational semantics can be defined directly via the operational semantics:
where is the reflexive transitive closure of and denotes a multiset. Here, a multiset is used because there may be transitions from different sequences of measurement outcomes terminating in the same final cq-state. The total probability of terminating outputs satisfies
The non-termination probability starting from the cq-state is then
Fig. 4. Syntax and signatures of formal quantum states. Here, is a quantum variable of type , is a classical expression of type , and are complex-valued classical expressions. The unitary gate is as defined in Figure 2.
Fig. 5. Interpretation of formal quantum states in a classical state . The unitary operator is as defined in Figure 3. The condition Dist is as defined in (6).
Fig. 6. Syntax and signatures of quantum predicate formulas. Here, K denotes a family of quantum predicates, and F denotes a finite family of operators. Both are parameterized by and act on .
3.3 Formal Quantum States and Assertions
Formal quantum states. In Section 2, we have seen Hoare triples parameterized by classical variables. For example, depends on the array for fixed in Example 2.2. To describe quantum states like , we need the notion of formal (pure) quantum states. Figure 4 gives the syntax and signature of a formal quantum state, where the signature records the quantum variables it involves and is recursively defined. Figure 5 specifies how formal quantum states are interpreted in a classical state.
Quantum predicate formulas. A quantum predicate is a Hermitian operator satisfying , where is the Löwner order. On a partial density operator , its expectation satisfies . Quantum predicate formulas have the syntax in Figure 6. Here, is an atomic formula with classical parameters , interpreted in a classical state as the quantum predicate on . We also use the atomic formula , where is a formal quantum state. There are three connectives for quantum predicate formulas: negation , tensor product , and a family of Kraus operators acting on .
Figure 7 specifies how quantum predicate formulas are interpreted in a classical state. We write if is well-defined. Most of the interpretations are self-explanatory. The connective can express the following transformations on quantum predicates: (1) reset, by taking ; (2) unitary, by taking ; (3) measurement, by taking
Ren et al.
Fig. 7. Interpretation of quantum predicate formulas in a classical state . Here, the condition Dist is as defined in (6). The Kraus operators satisfy . Each clause also requires its subformulas to be well-defined; otherwise is not well-defined.
for a measurement ; and (4) masking, by taking if is true and otherwise. We write for with .
Classical–quantum assertions. A cq-assertion is a pair , where is a classical first-order formula and is a quantum predicate formula. For a cq-state with , the expectation of is . We define the entailment by
Let us use to denote the substitution of for in . For every classical state , we define .
3.4 Proof System
The previous ingredients now fit together in a Hoare triple , with pre- and post-conditions being cq-assertions. The validity of Hoare triples is then defined as follows, providing formal meanings to the specifications (1)–(5) in Section 2.
Definition 3.1 (validity in QHL ). A Hoare triple is valid for total correctness, denoted as , if for every input cq-state with ,
The partial correctness is defined similarly, except for adding a term (accounting for non-termination) to the right-hand side of (7).
Proof rules. Table 1 shows the proof rules of QHL for deriving Hoare triples. Here, free( ) is the set of free classical variables of the classical formula , and var( ) is the set of classical variables in . We use cv(A), cv( ) to denote the sets of classical variables in the quantum predicate formula A and quantum variables , respectively. For a program P, qv(P) is the set of quantum variables in P, and change(P) consists of classical variables that P can modify.
Most axioms and rules are self-explanatory. In (Axiom-Meas), each outcome sets to and contributes to the precondition, and requires for every outcome. (Rule-Mask) moves the masking condition in the quantum predicate into the classical postcondition. For example, for a fresh variable , taking to be allows one to select a single measurement outcome. We can derive the measurement axiom of [Ying 2026] by applying (Axiom-Meas) to , followed by (Rule-Mask) and (Rule-Conseq), provided (see Appendix A.1). In (Rule-Accum1), contains Kraus operators and contains one, all of the same quantum type. Both (Rule-Accum1) and (Rule-Accum2) require . The notation is defined such that for any classical state , holds if for every and density operator on this quantum type,
(Rule-Accum1) combines mutually exclusive classical postconditions by disjunction, while (Rule-Accum2) combines quantum preconditions and postconditions using a Kraus operator.
(a) Partial correctness (QHL )
(Axiom-Ski) skip
(Axiom-Ass)
(Axiom-Init)
(Axiom-Uni)
(Axiom-Meas)
(Rule-Seq)
(Rule-Cond)
(Rule-Loop-par)
(Rule-Mask)
(Rule-Conseq)
for every ,
(Rule-Accum1)
for every
(Rule-Accum2)
(b) Total correctness (QHL ): replace (Rule-Loop-par) by
(Rule-Loop-tot)
Table 1. The QHL proof rules [Ying 2026], with a variant of (Axiom-Meas) and the added (Rule-Mask). Here, , , , and the mask are the instances of defined above. In (Rule-Accum1) and (Rule-Accum2), i indexes the Kraus operators of F. In (Rule-Loop-tot), the bound function t is an integer expression and z is a fresh integer variable, as usual for loops [Apt et al. 2009].
4 Formalization in Lean and Library Organization
We now describe how QEDIA handles the classical–quantum interplay consistently at the three levels of Section 2. The library follows these levels, each building on those below it.
This consistency comes from the way QHL combines classical and quantum components. Classical components keep their roles from classical programs, and quantum components are built around them. The formalization follows this combination at every level. The classical components are expressed directly in Lean, and the library builds the quantum components on them. At (L0), quantum variables are names from a finite set, and each set of names determines the Hilbert space of those variables. Classical data, such as array indices, can therefore select the quantum variables, and hence the space, on which an operation acts. At (L1), classical expressions and guards are Lean functions on classical states. Classical expressions also supply the indices of subscripted quantum variables and the parameters of gates. Proving the condition Dist( ) of (6) thus reduces to classical reasoning about indices. At (L2), the classical formula of a cq-assertion is a Lean predicate on classical states, and its quantum predicate is parameterized by classical variables. Classical reasoning about specifications therefore takes place directly in Lean’s logic.
Ren et al.
Table 2. Lean counterparts of the notions of Section 3. Types are simplified and parameters are omitted; for a Lean type, the third column gives the type it stands for. denotes the linear operators on , and values of Assn are quantum predicates.
| Section 3 | Lean | Type |
|---|---|---|
| classical-state type | Type | |
| space of | HS D S | |
| expression of type , guard | Lean functions | |
| sequence | RegExpr | |
| program | Prog | inductive type for the syntax of Figure 2 |
| quantum predicate formula | Assn | |
| cq-assertion | SourceAssertion | |
| masking by | toAssn | SourceAssertion Assn |
| validPar, validTot | Assn Prog Assn Prop | |
| SourceDerivPar, SourceDerivTot | SourceAssertion Prog SourceAssertion Prop |
Table 2 lists the Lean counterparts of the notions of Section 3, with their types. Sections 4.1 and 4.2 formalize (L0) and (L1): state spaces, programs, and their execution paths. Sections 4.3 and 4.4 formalize (L2): assertions and validity, and the proof systems with their soundness. Section 4.5 reports the size of the library and the examples.
4.1 State Spaces and Programs
At (L0), we use, on top of Mathlib, the labeled Hilbert spaces and Dirac notation of [Zhou et al. 2023]. Each quantum variable in a finite set of variable names has a finite, nonempty set of basis labels. A set has the Hilbert space
with . An operator on acts on through its cylindrical extension , where is the identity on the variables in . Thus, whichever quantum variables the classical state selects, every quantum operation becomes an operator on , on which quantum states and quantum predicates are also defined.
At (L1), programs are deeply embedded [Boulton et al. 1992], since the operational semantics and the proof rules are defined by cases on program syntax. Programs form the inductive type Prog for the syntax of Figure 2. For simplicity, classical expressions are shallowly embedded. Lean represents a classical expression by its evaluation , a function on the type of classical states. A guard thus has type , and proofs about classical computations use Lean's arithmetic.
Classical expressions also select quantum variables. A sequence may contain subscripted quantum variables such as , so the quantum variables it refers to depend on the classical state. We represent by a function (RegExpr in Table 2) with . Then holds if and only if is injective. Lean represents a quantum array by an injective map from its indices into . The condition therefore reduces to conditions on index values, which Lean proves with its arithmetic.
The Prog constructors for assignments, initializations, gates, and measurements take a classical update, a quantum operation, or both. The constructor for takes the update . The constructor for initialization takes a finite set of quantum variables, all reset to at once, as in . The constructor for takes and, in each classical state , the operator
on . This space is identified with when holds. The constructor for takes both: and the measurement operators in each , and an update for each outcome , such as . Since these operators depend on , Lean checks, when a program is written, that for every classical state each gate is unitary and each measurement satisfies the completeness relation.
4.2 Execution Paths
Lean represents the denotational semantics of Section 3 by execution paths, on which the soundness proofs of Section 4.4 rely. An execution path of a configuration is a finite sequence of transitions of Figure 3 starting from . Let be the finite set of execution paths of length that end in a terminal configuration. We write for the terminal configuration of a path . Each such path contributes to . Sums over this multiset, such as the one in (7), thus become sums over paths: for every nonnegative function on cq-states,
For , the partial sums of the right-hand side of (8) are bounded by . The series therefore converges. Partial correctness uses the resulting non-termination probability .
4.3 Assertions and Validity
At (L2), Lean keeps the classical and quantum parts of a cq-assertion apart. Like classical expressions, quantum predicate formulas are shallowly embedded. Lean represents a formula A by its interpretation (Figure 7), a function of type Assn. As a total function, the interpretation does not record where A is well-defined, so the well-definedness condition WD(A) is kept as a separate component. A cq-assertion is thus represented by a SourceAssertion with three components: and WD(A) as predicates on , and the interpretation of A. The entailment of Section 3 uses these components separately. Its first two conditions, and , become implications between Lean predicates. The third, , compares the interpretations in the states satisfying .
Definition 3.1 uses a cq-assertion only through the expectation for classical states . The function toAssn therefore represents by a single quantum predicate, which is for these states and 0 for the others. This is the masking of Section 3, with the formula in place of .
With toAssn, validity is stated for single quantum predicates and of type Assn. The proposition validTot states that, for every classical state and positive operator ,
The proposition validPar adds NT(P)(σ, ρ) to the right-hand side. For and , (9) is equivalent to the validity of Definition 3.1. By (8), its right-hand side is a sum over , as in (7). In this sum, masking makes every term with zero. This matches the condition on the sum in (7). On the left-hand side, masking gives zero when , so such states impose no condition. Finally, both sides of (9) are linear in . Quantifying over positive operators is therefore equivalent to quantifying over the partial density operators of Definition 3.1.
Ren et al.
4.4 Proof Systems and Soundness
The inductive propositions SourceDerivPar and SourceDerivTot have one constructor for each axiom and rule of Table 1, and the constructor for (Rule-Conseq) uses the entailment of Section 4.3.
For the axioms, Lean computes the precondition from the postcondition . As for the constructors of Section 4.1, classical updates and quantum operations are treated separately. A classical update is handled by evaluation. For , the precondition evaluates , , and the interpretation of in . This is the substitution of (Axiom-Ass), as defined in Section 3. A quantum operation is handled by its transformation. For initialization and gates, the precondition applies or in each classical state. A measurement combines both. In a classical state , the quantum predicate of its precondition is interpreted as
This is of (Axiom-Meas), with generalized to . As in (Axiom-Meas), and must hold after every update . Since is interpreted after the update, it can depend on the outcome, as the invariant of Example 2.1 does.
Since classical expressions and quantum predicate formulas are shallowly embedded, side conditions about their variables are stated semantically. In (Rule-Loop-tot), the fresh variable becomes an integer quantified outside the program, so the loop body cannot modify it. In (Rule-Accum1) and (Rule-Accum2), the conditions on change(P) and become the following: every transition of preserves the values of and , and acts on no quantum variable in . These systems satisfy the following soundness theorem.
THEOREM 4.1 (SOUNDNESS). For all cq-assertions , and programs ,
SourceDerivPar ,
SourceDerivTot .
The proof is by induction on the derivation, with one semantic lemma per constructor. For the axioms, the lemmas follow directly from the preconditions above. For (Rule-Mask), the lemma is immediate, since masking twice combines the conditions: toAssn . For sequential composition, each execution path of splits into an execution path of followed by one of . The lemma thus combines the validity of the two premises through the intermediate assertion. For loops, induction on the length of execution paths gives the partial-correctness bound. Induction on the initial value of the bound function gives the total-correctness bound. The soundness theorem uses only Lean's standard axioms propext, Classical. choice, and Quot. sound.
4.5 Code Metrics
Tables 3 and 4 report the size of the library and example files, including integration tests. Table 3 groups the library components by level. Excluding blank lines, the Spec column counts lines outside proofs and comments, and the Proof column counts lines strictly inside proof bodies.
At the declaration level, the library contains 2,475 theorem/lemma declarations and 673 definitions. The examples contain 1,117 such declarations and 575 definitions.
Table 3. Code metrics of the library by level and component: upper bounds on line counts.
| Component | Spec | Proof |
|---|---|---|
| (L0) Mathematics and quantum mechanics | ||
| Foundations | <250 | <200 |
Table 3 (continued)
| Component | Spec | Proof |
|---|---|---|
| Hilbert spaces and operators | <1,100 | <1,100 |
| Multi-qubit states and operators | <2,500 | <3,800 |
| Gates | <900 | <650 |
| Dirac notation | <950 | <600 |
| Superoperators | <450 | <400 |
| (L1) Program syntax and semantics | ||
| Programs | <500 | <250 |
| Semantics | <700 | <750 |
| (L2) Specification and proof system | ||
| Logic | <5,600 | <5,000 |
| Tactics | <100 | <50 |
| Total | <13,000 | <13,000 |
Table 4. Code metrics of the program examples: upper bounds on line counts.
| Example | Spec | Proof |
|---|---|---|
| Bell-state preparation | <100 | <50 |
| Parallel Hadamard | <150 | <300 |
| Quantum Fourier transform | <750 | <1,150 |
| Inverse QFT | <350 | <600 |
| Quantum phase estimation | <500 | <800 |
| Cluster-state preparation | <100 | <100 |
| Repeat-until-success | <150 | <100 |
| Trotter product formula (TFIM) | <550 | <550 |
| Bravyi-Kitaev transformation | <350 | <400 |
| Fermi-Hubbard LCU block encoding | <1,150 | <1,700 |
| Fermi-Hubbard QSP | <1,450 | <1,900 |
| Other examples and integration tests | <1,100 | <950 |
| Total | <6,500 | <8,500 |
5 The Prover Agent: Building the Library and Verifying Programs
We construct the library of Section 4 and the program proofs of Section 6 with a prover agent. It consists of a general-purpose core agent (Section 5.1) and a quantum extension (Section 5.2). The agent first builds the library, formalizing QHL and the mathematics it relies on, and then uses the library to verify programs. Throughout, the workflow separates fixing what is proved from proving it. A leader fixes the statements, subagents prove them, and the leader accepts a proof only if it proves the fixed statements. Figure 8 summarizes the workflow.
5.1 Core Agent
The core agent follows the approach of recent LLM-based theorem-proving agents [Breen et al. 2026; Li et al. 2026; Liu et al. 2026]. Given a mathematical statement or source, it produces Lean declarations in three stages: task definition, proof construction, and acceptance. The leader coordinates proof-writing subagents, and both are LLM agents. Human reviewers supervise the process
Ren et al.
and review the statements, the library, and the proofs. All agents use Mathlib and the library. They follow shared guidelines: preserve the target statement and its assumptions, search for existing results before proving new ones, and place reusable lemmas in the library.
Task definition. The leader reads the source and the library and writes a task specification: the target statements, their permitted assumptions, the required declarations, and the permitted changes. It reviews whether the specification expresses the intended mathematics and gives a meaningful guarantee. It then assigns the task to a subagent once its prerequisites are completed.
Proof construction. A subagent constructs each proof with Lean tools. These tools report proof goals and diagnostics, build files, and search Mathlib and the library. The subagent first tries existing lemmas and automation, and then edits and repairs the proof with Lean's feedback. It also checks axioms and inspects its own source locally, and reviews the proof against the guidelines, so failures can be repaired before submission.
Acceptance. The leader runs five checks on the combined changes of all subagents, returns failed changes for repair, and repeats the affected checks after any later change. Checks 1 and 5 relate the submitted declarations to the task specification. Checks 2–4 ensure that the proofs are complete and checked by Lean’s kernel with only the standard axioms.
(1) Faithful statements (Lean, LLM review). The leader reviews whether the required declarations, and the definitions they depend on, express the mathematics fixed in the task specification. When a task verifies a program, Lean also checks that its validity theorem has the type of the target Hoare triple fixed there.
(2) Clean build (Lean, Python). The library, including all submitted modules, builds without errors under the required settings.
(3) Axiom dependencies (Lean, Python). For each required theorem, Lean reports the axioms it uses. A script checks that they are exactly propext, Classical. choice, and Quot. sound.
(4) Kernel-checked proofs (Lean, LLM review). The leader inspects the submitted source for sorry, admit, native_decide, and options that bypass kernel checking. Lean checks the proofs under the required settings.
(5) Protected statements and definitions (LLM review). The leader compares the submitted changes with the approved baseline. It reviews whether they stay within the permitted changes and preserve the target statements and protected definitions. When a task extends the library, the leader also reviews new or changed definitions against their mathematical sources.
5.2 Quantum Extension
The quantum extension supports applying QHL rules and adds quantum-specific checks. In program verification, a task consists of a quantum program and a target Hoare triple. Its required declarations are the program as a Prog term, the precondition and postcondition, a SourceDerivTot or SourceDerivPar derivation, and the validity theorem. The agents construct the derivation, and the leader obtains the validity theorem from it by Theorem 4.1. Program proofs thus reason about assertions rather than execution paths (Section 4.2).
Verification conditions. Applying a rule turns its premises into Lean proof goals. For the axioms, Lean computes the precondition from the postcondition (Section 4.4). For the other rules, the agents choose what the conclusion leaves open, such as intermediate assertions, loop invariants, and bound functions. The resulting verification conditions split into classical and quantum conditions, as in Section 4. Classical conditions include the classical parts of entailments, , and the nonnegativity of a bound function. They are goals about Lean predicates on classical states, proved with Lean's logic and arithmetic. Quantum conditions include in the Löwner order and the conditions and of the accumulation rules. They are proved with library results about operators and quantum variables.
Quantum-specific checks. When a task verifies a program, the review in check 1 also examines whether the program implements the intended algorithm, with each gate defined by an explicit unitary in the library and each reused component a verified subprogram (Section 6.1). For each example, Lean verifies that the precondition has positive expectation on some input cq-state. This excludes preconditions with zero expectation on every input, for which the left-hand side of (7) vanishes and the Hoare triple holds for every program. For program tasks, the statements and definitions protected by check 5 include the program, the target Hoare triple, the proof systems, and the soundness proofs.
6 Verified Program Examples
We present eleven verified program examples, constructed using the prover agent (Section 5).
6.1 Overview
Table 5 summarizes the language features, verified properties, and subprogram reuse of these examples. Examples marked S reuse the verified derivations of the subprograms in the Reuse column. Each such subprogram is placed in the larger program by renaming its quantum variables with an injection and relating its classical state to that of the larger program. All Hoare triples are verified for total correctness, which accounts for termination.
Table 5. Overview of program examples. They illustrate the following program features: L (loop), NL (nested loops), A (quantum arrays), P (classical inputs), C (conditionals), M (measurement-controlled flow), and S (subprogram reuse).
| Example | Features | Verified property | Reuse |
|---|---|---|---|
| Bell state | - | prepares from | - |
| Parallel Hadamard | L, A | prepares for | - |
| QFT | NL, A, P | implements the Fourier transform for | - |
| Inverse QFT | NL, A, P | carries to | - |
| QPE | NL, A, P, S | recovers the -bit eigenphase of exactly | Parallel Hadamard, inverse QFT |
| Cluster state | L, A | prepares the 1D cluster state for | - |
| RUS | L, M, P | applies with probability at least | - |
| Trotter | NL, A, P | for and , every input has output fidelity at least with | - |
| Bravyi-Kitaev | NL, A, C | implements | - |
| Fermi-Hubbard LCU | NL, A, P | for , block-encodes with success probability | - |
| Fermi-Hubbard QSP | NL, A, P, C, S | for , block-encodes | Bravyi-Kitaev, Fermi-Hubbard LCU |
In the following, we present the verification for the QFT, RUS, and Trotter programs introduced in Section 2. Appendix B presents the remaining eight program examples, with the three building blocks for simulating the 1D spinless Fermi–Hubbard model grouped in Appendix B.7.
Ren et al.

LLM review
L∃VN Lean 4 checking
Python scripts
Fig. 8. The workflow of the core agent with the quantum extension. Icons show whether Lean, Python scripts, or LLM review performs each acceptance check of Section 5.1. Dotted arrows show where the agents use the guidelines and the quantum extension.
6.2 Quantum Fourier Transform
We first derive the Hoare triple (4) for the QFT program in Example 2.2. The QFT proof outline presents this derivation. In a proof outline [Apt et al. 2009; Owicki and Gries 1976], the program is annotated with assertions. Each program statement, together with the assertions before and after it, forms a Hoare triple. The right column gives the proof rules used in deriving each Hoare triple. (Rule-Seq) is used implicitly to sequentially combine Hoare triples. The target Hoare triple is formed by the first and last assertions in the proof outline.
We explain the notation as follows. For simplicity of presentation, we write a pure state for its projector in Hoare triples and write quantum predicates directly as operator expressions. The invariant names are local to each example unless explicitly reused. Let , and . Then, the final Fourier basis state can be written as
The key components of the QFT proof outline are the three loops at lines 2, 5, and 12, where we use (Rule-Loop-tot). The first loop invariant is , where
meaning the first quantum variables already carry their Fourier phases. The second loop invariant is , where
The third loop invariant is , where
| Quantum Fourier transform | |
|---|---|
| {true, |x>} | |
| 1 | i:=0(Axiom-Ass), (Rule-Conseq) |
| {i=0, J(i)}J(i): i iterations completed; J(0) = |x> | |
| 2 | while i < n do(Rule-Loop-tot), t = n - i |
| {i < n, J(i)} | |
| 3 | H[q[i]](Axiom-Uni) |
| {i < n, J'(i,0)} | |
| 4 | j:=0(Axiom-Ass), (Rule-Conseq) |
| {i < n ∧ j = 0, J'(i,j)} | |
| 5 | while j < n - 1 - i do(Rule-Loop-tot), t = (n - 1 - i) - j |
| {i < n ∧ j < n - 1 - i, J'(i,j)} | |
| 6 | cR(2π/2J+2)[q[i], q[i+1+j]](Axiom-Uni) |
| {i < n ∧ j < n - 1 - i, J'(i,j+1)} | |
| 7 | j:=j+1(Axiom-Ass), (Rule-Conseq) |
| {i < n ∧ j ≤ n - 1 - i, J'(i,j)} | |
| 8 | od |
| {i < n ∧ j = n - 1 - i, J'(i,j)} | |
| {i < n, J(i+1)} | |
| 9 | i:=i+1(Axiom-Ass), (Rule-Conseq) |
| {i ≤ n, J(i)} | |
| 10 | od |
| {i = n, J(n)} | |
| {true, ∏_{m=0}^{n-1} |ψ(θ(m))>} | |
| 11 | i:=0(Axiom-Ass), (Rule-Conseq) |
| {i = 0, J''(i)} | |
| 12 | while i < ⌊n/2⌋ do(Rule-Loop-tot), t = ⌊n/2⌋ - i |
| {i < ⌊n/2⌋, J''(i)} | |
| 13 | SWAP[q[i], q[n - 1 - i]](Axiom-Uni) |
Ren et al.
(continued)
{ i < [n/2], }
14
(Axiom-Ass), (Rule-Conseq)
{ i ≤ [n/2], }
15 od
{ i = [n/2], }
{ true, }
(Rule-Conseq)
At line 1, . The Hadamard gate at line 3 converts into , which is turned into by the second while loop. Inside the loop, at line 6, the controlled rotation adds the phase contributed by through . From , the first while loop ends at line 10 with . The third while loop reverses the qubit order by SWAP[q[i],q[n-1-i]] .
The Hoare triple (4) determines the output of each computational basis input up to a phase. To establish correctness on arbitrary inputs, we also derive the following Hoare triple for :
Appendix B.1 derives (11) and shows that (4) and (11) together determine the output on every input up to a common global phase.
6.3 Repeat-Until-Success
We next derive the Hoare triples (1) and (2) for the RUS program in Example 2.1. The RUS proof outline presents the derivation of (1).
We explain the notation as follows. The gate is explicitly given by [Paetznick and Svore 2014, Fig. 8]:
where is the phase- gate, and is the first tensor factor and the control of each CNOT. It satisfies, for all ,
where and . Let for . Then, , and (13) means .
The key component of the RUS proof outline is the while loop at line 3, where we use (Rule-Loop-tot). The loop invariant is , with defined in (3), meaning that the data qubit carries if and is unchanged if , so that each attempt restarts from .
Repeat-until-success
{ , }
1
(Axiom-Ass), (Rule-Conseq)
{ , }
2
(Axiom-Ass), (Rule-Conseq)
{ , }
3 while do
(Rule-Loop-tot),
{ , }
4
(Axiom-Init)
{ , }
(continued)
5 (Axiom-Uni) 6 (Axiom-Meas), (Rule-Conseq) 7 (Axiom-Ass), (Rule-Conseq) 8 od (Rule-Conseq)
At line 6, (Axiom-Meas) sums over both outcomes of measuring , which updates the classical variable controlling the loop. It converts the postcondition of line 6 into . The loop ends at line 8 with , which is the postcondition of (1).
We then derive the success bound (2) in the RUS success proof outline, using the loop invariant , where
For , is the probability of at least one success within the remaining attempts. At loop exit, the classical part excludes the exhausted branch , so only successful outputs are counted in (2).
Repeat-until-success: success probability
{ , }
1 (Axiom-Ass), (Rule-Conseq)
{ , }
2 (Axiom-Ass), (Rule-Conseq)
{ , }
3 while do { , } (Axiom-Init), (Rule-Conseq) { , } (Axiom-Uni) { , } (Axiom-Meas), (Rule-Mask), (Rule-Conseq) { , } (Axiom-Ass), (Rule-Conseq) { , } od { , } { , } (Rule-Conseq) }
The quantum invariant is preserved since for , that is, the probability of in the current attempt plus the probability of followed by a later success. At line 6, when , the outcome would violate . We therefore apply (Axiom-Meas) with the mask on , and the
Ren et al.
precondition is still the assertion after line 5 because . Then (Rule-Mask) converts the mask into the classical postcondition of line 6.
In both outlines, keeps the bound function nonnegative, and the loop body decreases it under .
6.4 The Trotter Product-Formula Circuit
We then derive the Hoare triple (5) for the Trotter program in Example 2.3. The Trotter proof outline presents this derivation.
We explain the notation as follows. Let and be the products of the first rotations applied by the second and third while loops, respectively:
Let and , which means and . Each iteration of the first while loop therefore applies . Let denote the classical precondition of (5). Define . Since , remains in every invariant and supplies the assumptions of the final (Rule-Conseq) step.
The key components of the Trotter proof outline are the three loops at lines 2, 4, and 9, where we use (Rule-Loop-tot). The first loop invariant is , where
meaning that the first iterations of the first while loop are completed. The second loop invariant is , where
meaning that the first rotations of the current iteration are applied. The third loop invariant is , where
meaning that all rotations and the first rotations of the current iteration are applied.
| Trotter product-formula circuit | |
|---|---|
| 1 | \{\Phi_{\varepsilon} \wedge i = 0, \mathcal{J}(i)\}$ |
| 2 | while do |
| 3 | \{\Phi_{\varepsilon} \wedge i < N \wedge j = 0, \mathcal{J}'(i,j)\}$ |
| 4 | while do |
| 5 | \{\Phi_{\varepsilon} \wedge i < N \wedge j < n, \mathcal{J}'(i,j+1)\}$ |
| 6 | \{\Phi_{\varepsilon} \wedge i < N \wedge j \leq n, \mathcal{J}'(i,j)\}$ |
| 7 | od |
(continued)
{ , { , } 8 { , } 9 while do { , } 10 { , } 11 { , } 12 od { , } { , } 13 { , } 14 od { , } { } { true, } }
(Rule-Conseq)
(Axiom-Ass), (Rule-Conseq)
(Rule-Loop-tot),
(Axiom-Uni)
(Axiom-Ass), (Rule-Conseq)
(Rule-Conseq)
(Axiom-Ass), (Rule-Conseq)
(Rule-Conseq)
(Rule-Conseq)
At line 1, . By (14), the rotation at line 5 converts into , and the rotation at line 10 converts into . From , we have , and the first while loop ends at line 14 with .
Only the last (Rule-Conseq) step uses the condition on in . It relies on the first-order Trotter error bound [Childs et al. 2021]
which sums the one-step error over the iterations. Under , (15) gives . Hence , since projectors onto unit vectors satisfy .
7 Related Work
Quantum Hoare logics. Quantum Hoare logic (QHL) [Ying 2011] provides sound and relatively complete proof systems for partial and total correctness of quantum while-programs without classical variables. The applied quantum Hoare logic [Zhou et al. 2019] restricts preconditions and postconditions to projections, which simplifies the proof rules for larger programs. For programs with classical variables, the logic of [Feng and Ying 2021] uses families of Hermitian operators indexed by classical states as preconditions and postconditions. QHL [Ying 2026] instead pairs a classical first-order formula with a single quantum predicate formula parameterized by classical variables. Specifications thus remain compact, and classical first-order reasoning applies directly to their classical parts. QHL also supports quantum arrays and gates whose indices and parameters are given by classical variables. Earlier quantum Hoare logics do not support these features [Ying 2026].
Mechanized quantum program logics. The QHL prover [Liu et al. 2019] formalizes a finite-dimensional partial-correctness fragment of QHL in Isabelle/HOL and proves it sound and
Ren et al.
complete. CoqQ [Zhou et al. 2023] verifies partial and total correctness of quantum while-programs in Coq, with a machine-checked soundness proof. Neither supports classical program variables. CoqQLR [Deng et al. 2024; Wu et al. 2025] formalizes in Coq a logic for local reasoning about probabilistic properties of classical–quantum programs, with soundness for trace-preserving programs. The qrhl-tool [Unruh 2019] supports quantum relational Hoare logic (qRHL) in Isabelle/HOL, with soundness proved on paper.
Verification of circuits and hybrid programs. QWIRE [Rand et al. 2018] embeds a typed circuit language in Coq with dynamic lifting of measurement results. SQIR/VOQC [Hietala et al. 2021] verifies circuit optimizations in Coq, and a certified implementation of Shor's algorithm [Peng et al. 2023] builds on SQIR. Qbricks [Chareton et al. 2021] verifies circuit-building programs in Why3. Qafny [Li et al. 2024] has a type-guided quantum proof system and automates verification by translation into Dafny. Table 10 summarizes these systems.
Table 10. Quantum program verification tools: QEDIA in context.
| Tool | Assistant | Program model | Classical data/control |
|---|---|---|---|
| CoqQ [Zhou et al. 2023] | Coq | quantum while | no classical variables |
| QHL prover [Liu et al. 2019] | Isabelle/HOL | quantum while | no classical variables |
| CoqQLR [Wu et al. 2025] | Coq | classical-quantum while | classical variables |
| qrhl-tool [Unruh 2019] | Isabelle/HOL | relational (program pairs) | classical variables |
| QWIRE [Rand et al. 2018] | Coq | circuits | classical wires, dynamic lifting |
| SQIR/VOQC [Hietala et al. 2021] | Coq | circuits | measurement branches |
| Qbricks [Chareton et al. 2021] | Why3 | circuit-building programs | circuit construction |
| Qafny [Li et al. 2024] | Coq/Dafny | quantum programs (via Dafny) | immutable bindings |
| QEDIA (this work) | Lean 4 | classical-quantum while | classical variables indexing qubits and gate parameters |
To our knowledge, QEDIA is the first mechanization of a quantum Hoare logic that supports quantum arrays and gates parameterized by classical program variables, with soundness proved for both partial and total correctness.
8 Conclusion and Future Work
Quantum programs interleave classical and quantum computation. Verifying them in a proof assistant requires handling this interplay consistently, from the mathematics of quantum mechanics to the proof rules. QEDIA does so for QHL in Lean 4 and proves the logic sound for both partial and total correctness. On this foundation, we verified programs ranging from the quantum Fourier transform and repeat-until-success circuits to Trotter-based Hamiltonian simulation and quantum signal processing for the Fermi–Hubbard model. LLM agents built the library and these proofs under human supervision, and Lean's kernel checks every proof.
In the following, we list a few topics for future work.
-
Quantum error correction. Quantum error correction underpins fault-tolerant quantum computation. Its syndrome measurement outcomes determine, through classical decoding, which corrections are applied. This makes it a natural next target for QEDIA.
-
Quantum recursion. Quantum recursive programs [Ying and Zhang 2026; Zhang and Ying 2025] combine quantum control flow with recursive procedure calls. Extending QEDIA to them
requires handling this combination, since qWhile has neither quantum control flow nor procedure calls.
• Parallel and distributed programs. Hoare-style logics have been developed for parallel [Ying et al. 2019] and distributed [Feng et al. 2022] quantum programs. Mechanizing them raises further challenges, such as entanglement between component programs and the intertwining of nondeterminism from measurements and from parallelism [Ying et al. 2019].
Acknowledgments
Use of AI. The Lean formalization and proofs were constructed by LLM agents under human supervision (Section 5), using OpenAI's GPT-5.5, GPT Sol (versions 5.6, 6, and 6.1), and GPT-6 Astra, as well as Anthropic's Claude Opus (versions 4.6, 4.8, and 5.5) and Claude Fable (versions 5 and 5.1). We also used AI assistance during the later stages of the project to organize data and improve the clarity and language of the manuscript. The formal proofs are checked by the Lean 4 kernel. The authors take responsibility for the specifications, interpretation of the results, and final content of the paper.
References
Krzysztof R. Apt, Frank S. de Boer, and Ernst-Rüdiger Olderog. 2009. Verification of Sequential and Concurrent Programs (3rd ed.). Springer. doi:10.1007/978-1-84882-745-5
Kaito Baba, Chaoran Liu, Shuhei Kurita, and Akiyoshi Sannai. 2026. Prover Agent: An Agent-Based Framework for Formal Mathematical Proofs. arXiv:2506.19923 [cs.AI] https://arxiv.org/abs/2506.19923
Charles H. Bennett, Gilles Brassard, Claude Crépeau, Richard Jozsa, Asher Peres, and William K. Wootters. 1993. Teleporting an unknown quantum state via dual classical and Einstein-Podolsky-Rosen channels. Physical Review Letters 70, 13 (1993), 1895–1899. doi:10.1103/PhysRevLett.70.1895
Charles H. Bennett and Stephen J. Wiesner. 1992. Communication via one- and two-particle operators on Einstein-Podolsky-Rosen states. Physical Review Letters 69, 20 (1992), 2881–2884. doi:10.1103/PhysRevLett.69.2881
Alex Bocharov, Martin Roetteler, and Krysta M. Svore. 2015. Efficient Synthesis of Universal Repeat-Until-Success Quantum Circuits. Physical Review Letters 114, 8 (2015), 080502. doi:10.1103/PhysRevLett.114.080502
Richard Boulton, Andrew Gordon, Mike Gordon, John Harrison, John Herbert, and John Van Tassel. 1992. Experience with Embedding Hardware Description Languages in HOL. In Theorem Provers in Circuit Design: Theory, Practice and Experience (IFIP Transactions A: Computer Science and Technology, Vol. A-10), Victoria Stavridou, Thomas F. Melham, and R. T. Boute (Eds.). North-Holland, Amsterdam, 129–156.
Benjamin Breen, Marco Del Tredici, Jacob McCarran, Javier Aspuru Mijares, Weichen Winston Yin, Kfir Sulimany, Jacob M. Taylor, Frank H. L. Koppens, and Dirk Englund. 2026. Ax-Prover: A Deep Reasoning Agentic Framework for Theorem Proving in Mathematics and Quantum Physics. arXiv:2510.12787 [cs.AI] https://arxiv.org/abs/2510.12787
Christophe Chareton, Sébastien Bardin, François Bobot, Valentin Perrelle, and Benoît Valiron. 2021. An Automated Deductive Verification Framework for Circuit-building Quantum Programs. In Programming Languages and Systems (ESOP) (Lecture Notes in Computer Science, Vol. 12648). Springer, 148–177. doi:10.1007/978-3-030-72019-3_6
Andrew M. Childs, Yuan Su, Minh C. Tran, Nathan Wiebe, and Shuchen Zhu. 2021. Theory of Trotter Error with Commutator Scaling. Physical Review X 11, 1 (2021), 011020. doi:10.1103/PhysRevX.11.011020
Isaac L. Chuang and M. A. Nielsen. 1997. Prescription for experimental determination of the dynamics of a quantum black box. Journal of Modern Optics 44, 11–12 (1997), 2455–2467. doi:10.1080/09500349708231894
Richard Cleve, Artur Ekert, Chiara Macchiavello, and Michele Mosca. 1998. Quantum Algorithms Revisited. Proceedings of the Royal Society A 454, 1969 (1998), 339–354. doi:10.1098/rspa.1998.0164
D. Coppersmith. 1994. An Approximate Fourier Transform Useful in Quantum Factoring. Research Report RC19642. IBM Research Division. arXiv:quant-ph/0201067 https://arxiv.org/abs/quant-ph/0201067
Leonardo de Moura and Sebastian Ullrich. 2021. The Lean 4 Theorem Prover and Programming Language. In Automated Deduction – CADE 28 (Lecture Notes in Computer Science, Vol. 12699). Springer, 625–635. doi:10.1007/978-3-030-79876-5_37
Yuxin Deng, Huiling Wu, and Ming Xu. 2024. Local Reasoning about Probabilistic Behaviour for Classical–Quantum Programs. In Verification, Model Checking, and Abstract Interpretation (VMCAI) (Lecture Notes in Computer Science, Vol. 14500). Springer, 163–184. doi:10.1007/978-3-031-50521-8_8
Dennis Dieks. 1982. Communication by EPR devices. Physics Letters A 92, 6 (1982), 271–272. doi:10.1016/0375-9601(82)90084-6
Ren et al.
Yuan Feng, Sanjiang Li, and Mingsheng Ying. 2022. Verification of Distributed Quantum Programs. ACM Transactions on Computational Logic 23, 3 (2022), 1–40. doi:10.1145/3517145
Yuan Feng and Mingsheng Ying. 2021. Quantum Hoare Logic with Classical Variables. ACM Transactions on Quantum Computing 2, 4 (2021), 1–43. doi:10.1145/3456877
András Gilyén, Yuan Su, Guang Hao Low, and Nathan Wiebe. 2019. Quantum Singular Value Transformation and Beyond: Exponential Improvements for Quantum Matrix Arithmetics. In Proceedings of the 51st Annual ACM SIGACT Symposium on Theory of Computing (STOC). 193–204. doi:10.1145/3313276.3316366
Lov K. Grover. 1996. A Fast Quantum Mechanical Algorithm for Database Search. In Proceedings of the 28th Annual ACM Symposium on Theory of Computing (STOC). 212–219. doi:10.1145/237814.237866
Kesha Hietala, Robert Rand, Shih-Han Hung, Xiaodi Wu, and Michael Hicks. 2021. A Verified Optimizer for Quantum Circuits. Proceedings of the ACM on Programming Languages 5, POPL (2021), 1–29. doi:10.1145/3434318
J. Hubbard. 1963. Electron correlations in narrow energy bands. Proceedings of the Royal Society of London. Series A 276, 1365 (1963), 238–257. doi:10.1098/rspa.1963.0204
A. Yu. Kitaev. 1995. Quantum measurements and the Abelian Stabilizer Problem. arXiv:quant-ph/9511026 [quant-ph] https://arxiv.org/abs/quant-ph/9511026
E. Knill, D. Leibfried, R. Reichle, J. Britton, R. B. Blakestad, J. D. Jost, C. Langer, R. Ozeri, S. Seidelin, and D. J. Wineland. 2008. Randomized Benchmarking of Quantum Gates. Physical Review A 77, 1 (2008), 012307. doi:10.1103/PhysRevA.77.012307
Jinzheng Li, Zeru Zhu, and Yuanjie Ren. 2026. MerLean-Prover: A Recursive Looping Harness for Lean 4 Theorem Proving. arXiv:2605.26959 [cs.LO] https://arxiv.org/abs/2605.26959
Liyi Li, Mingwei Zhu, Rance Cleaveland, Alexander Nicolellis, Yi Lee, Le Chang, and Xiaodi Wu. 2024. Qafny: A Quantum-Program Verifier. In 38th European Conference on Object-Oriented Programming (ECOOP) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 313). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 24:1–24:31. doi:10.4230/LIPIcs.ECOOP.2024.24
Junyi Liu, Bohua Zhan, Shuling Wang, Shenggang Ying, Tao Liu, Yangjia Li, Mingsheng Ying, and Naijun Zhan. 2019. Formal Verification of Quantum Algorithms Using Quantum Hoare Logic. In Computer Aided Verification (Lecture Notes in Computer Science, Vol. 11562), Isil Dillig and Serdar Tasiran (Eds.). Springer International Publishing, Cham, 187–207. doi:10.1007/978-3-030-25543-5_12
Junqi Liu, Zihao Zhou, Zekai Zhu, Marco Dos Santos, Weikun He, Jiawei Liu, Yunzhou Xie, Junqiao Zhao, Qiufeng Wang, Lihong Zhi, Jia Li, and Wenda Li. 2026. Numina-Lean-Agent: An Open and General Agentic Reasoning System for Formal Mathematics. In Proceedings of the 43rd International Conference on Machine Learning (Proceedings of Machine Learning Research, Vol. 306). PMLR, 80284–80297. https://proceedings.mlr.press/v306/liu26gp.html
Seth Lloyd. 1996. Universal Quantum Simulators. Science 273, 5278 (1996), 1073–1078. doi:10.1126/science.273.5278.1073
Guang Hao Low and Isaac L. Chuang. 2019. Hamiltonian Simulation by Qubitization. Quantum 3 (2019), 163. doi:10.22331/q-2019-07-12-163
M. Mohseni, A. T. Rezakhani, and D. A. Lidar. 2008. Quantum-Process Tomography: Resource Analysis of Different Strategies. Physical Review A 77, 3 (2008), 032322. doi:10.1103/PhysRevA.77.032322
Susan Owicki and David Gries. 1976. An axiomatic proof technique for parallel programs I. Acta Informatica 6, 4 (1976), 319–340. doi:10.1007/BF00268134
Adam Paetznick and Krysta M. Svore. 2014. Repeat-Until-Success: Non-deterministic Decomposition of Single-Qubit Unitaries. Quantum Information and Computation 14, 15–16 (2014), 1277–1301.
Yuxiang Peng, Kesha Hietala, Runzhou Tao, Liyi Li, Robert Rand, Michael Hicks, and Xiaodi Wu. 2023. A Formally Certified End-to-End Implementation of Shor's Factorization Algorithm. Proceedings of the National Academy of Sciences 120, 21 (2023), e2218775120. doi:10.1073/pnas.2218775120
Robert Rand, Jennifer Paykin, and Steve Zdancewic. 2018. QWIRE Practice: Formal Verification of Quantum Circuits in Coq. Electronic Proceedings in Theoretical Computer Science 266 (2018), 119–132. doi:10.4204/EPTCS.266.8
Robert Raussendorf and Hans J. Briegel. 2001. A One-Way Quantum Computer. Phys. Rev. Lett. 86 (May 2001), 5188–5191. Issue 22. doi:10.1103/PhysRevLett.86.5188
Yuanjie Ren, Jinzheng Li, and Yidi Qi. 2026. MerLean: An Agentic Framework for Autoformalization in Quantum Computation. arXiv:2602.16554 [cs.LO] https://arxiv.org/abs/2602.16554
Jacob T. Seeley, Martin J. Richard, and Peter J. Love. 2012. The Bravyi–Kitaev Transformation for Quantum Computation of Electronic Structure. The Journal of Chemical Physics 137, 22 (2012), 224109. doi:10.1063/1.4768229
Peter W. Shor. 1997. Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer. SIAM J. Comput. 26, 5 (1997), 1484–1509. doi:10.1137/S0097539795293172
The mathlib Community. 2020. The Lean Mathematical Library. In Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP). 367–381. doi:10.1145/3372885.3373824
Hale F. Trotter. 1959. On the Product of Semi-Groups of Operators. Proc. Amer. Math. Soc. 10, 4 (1959), 545–551. doi:10.1090/S0002-9939-1959-0108732-6
Dominique Unruh. 2019. Quantum Relational Hoare Logic. Proceedings of the ACM on Programming Languages 3, POPL (2019), 1–31. doi:10.1145/3290346
Sumanth Varambally, Thomas Voice, Yanchao Sun, Zhifeng Chen, Rose Yu, and Ke Ye. 2026. Hilbert: Recursively Building Formal Proofs with Informal Reasoning. In International Conference on Learning Representations (ICLR).
Dave Wecker, Matthew B. Hastings, Nathan Wiebe, Bryan K. Clark, Chetan Nayak, and Matthias Troyer. 2015. Solving Strongly Correlated Electron Models on a Quantum Computer. Physical Review A 92, 6 (2015), 062318. doi:10.1103/PhysRevA.92.062318
William K. Wootters and Wojciech H. Zurek. 1982. A single quantum cannot be cloned. Nature 299, 5886 (1982), 802–803. doi:10.1038/299802a0
Huiling Wu, Yuxin Deng, and Ming Xu. 2025. Local Reasoning about Probabilistic Behaviour for Classical-Quantum Programs. arXiv:2308.04741 [cs.PL] https://arxiv.org/abs/2308.04741v3
Mingsheng Ying. 2011. Floyd-Hoare Logic for Quantum Programs. ACM Transactions on Programming Languages and Systems 33, 6 (2011), 1–49. doi:10.1145/2049706.2049708
Mingsheng Ying. 2026. A Practical Quantum Hoare Logic with Classical Variables, I. Information and Computation 309 (2026), 105417. doi:10.1016/j.ic.2026.105417
Mingsheng Ying and Zhicheng Zhang. 2026. Verification of Recursively Defined Quantum Circuits. Proceedings of the ACM on Programming Languages 10, PLDI (2026), 656–680. doi:10.1145/3808273
Mingsheng Ying, Li Zhou, and Yangjia Li. 2019. Reasoning about Parallel Quantum Programs. arXiv:1810.11334 [cs.LO] https://arxiv.org/abs/1810.11334
Zhicheng Zhang and Mingsheng Ying. 2025. Quantum Register Machine: Efficient Implementation of Quantum Recursive Programs. Proceedings of the ACM on Programming Languages 9, PLDI (2025), 822–847. doi:10.1145/3729283
Li Zhou, Gilles Barthe, Pierre-Yves Strub, Junyi Liu, and Mingsheng Ying. 2023. CoqQ: Foundational Verification of Quantum Programs. Proceedings of the ACM on Programming Languages 7, POPL (2023), 833–865. doi:10.1145/3571222
Li Zhou, Nengkun Yu, and Mingsheng Ying. 2019. An Applied Quantum Hoare Logic. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). 1149–1162. doi:10.1145/3314221.3314584
A Details of the Formalization
A.1 Deriving the Original Measurement Axiom
We derive the measurement axiom of [Ying 2026], which treats one outcome at a time, from (Axiom-Meas) and (Rule-Mask). The axiom reads
Here, is a classical variable and . The following proof outline derives it, provided .
| Single-outcome measurement | ||
|---|---|---|
| 1 | (Axiom-Meas), (Rule-Conseq) (Rule-Mask) (Rule-Conseq) | |
At line 1, (Axiom-Meas) gives the precondition . Since is fresh, its classical part is equivalent to . In each classical state , the masks keep only the term for , so its quantum part has the same interpretation as . Since , both quantum parts are well-defined at the same classical states satisfying . (Rule-Conseq) then replaces one precondition by the other.
Ren et al.
A.2 The RUS Program and Specification in Lean
The following excerpts illustrate how the RUS program of Figure 1(a) and its success specification (2) are represented in Lean. Programs have type Prog (Section 4.1). The classical-state type Store (Σ in Table 2) represents , with Boolean values false and true encoding the outcomes 0 and 1. Surrounding namespace declarations and theorem proofs are omitted.
noncomputable def body (W : UnitaryOp (EuclideanSpace C (Bool × Bool))) : Prog Store D := .seq (.init fun _ => regA.sig) (.seq (.unitary 2 rAT (gateW W)) (.seq (.measure 2 1 rA measA updM) (.assign incK)))
noncomputable def prog (W : UnitaryOp (EuclideanSpace C (Bool × Bool))) : Prog Store D := .seq (.assign initM) (.seq (.assign initK) (.while guard (body W)))
Here, initM, initK, and incK implement , , and , and guard is . The expression regA.sig identifies the ancilla to reset; rA and rAT select a and . The operation gateW W applies W to that pair, measA is the computational-basis measurement, and updM writes its outcome to m. Thus the measurement outcome controls whether the loop executes again.
Here, wPS and vPS are and of Example 2.1.
noncomputable def boundedRusClassicalProg : Prog ClassicalInput.Store D := ClassicalInput.prog wPS
theorem boundedRusClassicalSuccessSourceValid (hψ₀ : ||ψ₀|| = 1) : validTot (ClassicalInput.preQ betaPS norm_betaPS_le_one ψ₀ hψ₀).toAssn boundedRusClassicalProg (ClassicalInput.postQ vPS ψ₀ hψ₀).toAssn := ...
To identify its precondition and postcondition, we use the following local names:
local notation "Pre" => ClassicalInput.preQ betaPS norm_betaPS_le_one h local notation "Post" => ClassicalInput.postQ vPS h
At a classical state , their components satisfy
(Pre).classical , (Post).classical , (Pre).defined , (Pre).quantum.op , (Post).quantum.op .
Here, is defined in (3). The coefficient in the precondition is established by classicalSuccessPreQ_op, using the proved failure-amplitude identity
theorem normSq_betaPS :
By the third line of the display, toAssn masks their quantum predicates only by the displayed classical conditions (Section 4.3). The validity theorem is (2); it follows from the corresponding SourceDerivTot derivation by Theorem 4.1. Its proof outline is in Section 6.3.
B Further Verified Examples
This appendix presents the remaining eight examples of Table 5, after extending the QFT example of Section 6.2 to arbitrary inputs. The proof outlines follow the conventions of Section 6.2.
B.1 The QFT on Arbitrary Inputs
We derive the Hoare triple (11) by the QFT proof outline, with the quantum parts of its three loop invariants replaced by , , and . At line 3, . At line 6, the controlled rotation fixes because is in . At line 13, the swap fixes . The first loop starts from and ends with .
Let be the unitary applied by . For an input state , we use the same outline with the loop invariants , , and taken to be the states obtained from by the gates of the outline up to the corresponding point. Then the verification conditions at lines 3, 6, and 13 hold by definition, and . This establishes
For every program P and states , , and ,
Indeed, for the input , the output expectations of and are both at least one, whereas and the total probability of termination is at most one. Hence .
Applying this fact to (16) and (4) gives with . Together with (11), it gives with . The Fourier sum in Example 2.2 yields . Since , linearity gives
The Fourier basis states are orthonormal, so for every . Thus, for every input state , . The common global phase does not change its projector, and (Rule-Conseq) applied to (16) establishes
B.2 Bell-State Preparation
The Bell state is the shared resource of quantum teleportation [Bennett et al. 1993] and superdense coding [Bennett and Wiesner 1992], and its preparation is the smallest entangling circuit. The program applies a Hadamard to and then a CNOT with control and target . Its Hoare triple is
| Bell-state preparation | |
|---|---|
| 1 | {true, |00>}H[q0](Axiom-Uni){true, |+> ⊗ |0>} |
| 2 | CNOT[q0, q1](Axiom-Uni) |
Ren et al.
(continued)
{ true, }
The verification conditions at lines 1 and 2 are the gate actions and .
B.3 Parallel Hadamard
Parallel Hadamard prepares the uniform superposition , the first step of algorithms such as Grover search [Grover 1996] and phase estimation. The program applies a Hadamard to each quantum variable of the quantum array , using the loop counter . Its Hoare triple is, for every ,
The key component of the parallel-Hadamard proof outline is the loop at line 2, where we use (Rule-Loop-tot). The loop invariant is , where
meaning that the first quantum variables carry .
| Parallel Hadamard | |
|---|---|
| {true, |0⟩⊗n} | |
| 1 | i := 0(Axiom-Ass), (Rule-Conseq) |
| {i = 0, J(i)} | |
| 2 | while i < n do(Rule-Loop-tot), t = max(n-i, 0) |
| {i < n, J(i)} | |
| 3 | H[q[i]](Axiom-Uni) |
| {i < n, J(i+1)} | |
| 4 | i := i + 1(Axiom-Ass), (Rule-Conseq) |
| {true, J(i)} | |
| 5 | od |
| {i ≥ n, J(i)} | |
At line 1, . At line 3, for . The loop ends at line 5 with , which gives .
B.4 Inverse QFT
The inverse QFT is the readout stage of quantum phase estimation: it carries the Fourier basis state back to . The program reverses the QFT circuit of Section 6.2, with the same classical variables: the loop counters and the classical input . It first runs the swap loop of the QFT in the same order, since the swaps act on disjoint pairs of quantum variables. It then runs the iterations of the first while loop of the QFT in reverse order with negated phase angles. Iteration of its second loop reverses iteration of the first loop of the QFT, and its third loop applies for , which reverses iteration of the second loop of the QFT. Its Hoare triple is
The derivation uses the three loops of the QFT proof outline in reverse order. The first loop, which performs the swaps, uses the loop invariant , where, in this example, , meaning that the first swaps are applied. It carries to . The second loop uses the loop invariant . In its iteration , the third loop uses : it starts from and ends at . The verification conditions are those of lines 3, 6, and 13 of the QFT proof outline, with each gate replaced by its inverse. Each iteration of the third loop removes one phase term by
The Hadamard then gives at , which yields . The second loop ends with .
B.5 Quantum Phase Estimation
Quantum phase estimation [Cleve et al. 1998; Kitaev 1995] estimates an eigenphase of a unitary and is the core subroutine of Shor's algorithm [Shor 1997]. This program writes an exactly representable eigenphase into the control qubits and preserves the target eigenstate. Fix , a single-qubit unitary , and a state . The classical input specifies the eigenphase through the classical precondition
where is as in Example 2.2. Thus requires to be an eigenstate of with eigenphase . The program acts on the control qubits and the target qubit . It prepares the control qubits by (Appendix B.3), then runs a loop whose iteration applies the controlled power to , and finally applies (Appendix B.4) to the control qubits. Its Hoare triple is
The key component of the QPE proof outline is the loop at line 3, where we use (Rule-Loop-tot). The loop invariant is , where
meaning that the first control qubits carry their phases.
| Quantum phase estimation | ||
|---|---|---|
| 1 | proved in Appendix B.3 | |
| 2 | (Axiom-Ass), (Rule-Conseq) | |
| 3 | while do | (Rule-Loop-tot), |
| 4 | (Axiom-Uni) | |
Ren et al.
(continued)
{ , } 5 { , } 6 od { , } { true, } 7 { true, }
(Axiom-Ass), (Rule-Conseq)
(Rule-Conseq)
proved in Appendix B.4
Lines 1 and 7 use the Hoare triples of Appendices B.3 and B.4 on the control qubits, which leave and the target qubit unchanged. At line 4, the control is in , and gives
(19)
The gate leaves the other control qubits unchanged, which establishes . The loop ends at line 6 with by (10).
B.6 Cluster-State Preparation
This example prepares the 1D cluster state, the resource state of measurement-based quantum computation [Raussendorf and Briegel 2001]. The program has one classical variable, the loop counter , which each of its two loops initializes. The first loop applies to , and the second applies to . Its Hoare triple is, for every ,
where
The key components of the cluster-state proof outline are the loops at lines 2 and 7, where we use (Rule-Loop-tot). The first loop uses the loop invariant , with the verification conditions of Appendix B.3. The second uses , where
meaning that the first CZ gates are applied.
| Cluster-state preparation | |
|---|---|
| {true, |0⟩⊗n} | |
| 1 | k := 0(Axiom-Ass), (Rule-Conseq){k = 0, J(k)}J(k) = |+⟩⊗k ⊗ |0⟩⊗(n-k); J(0) = |0⟩⊗n |
| 2 | while k < n do(Rule-Loop-tot), t = n-k{k < n, J(k)} |
| 3 | H[q[k]](Axiom-Uni){k < n, J(k+1)} |
| 4 | k := k + 1(Axiom-Ass), (Rule-Conseq){k ≤ n, J(k)} |
(continued)
5 od { k = n, } { true, } (Rule-Conseq) 6 k := 0 (Axiom-Ass), (Rule-Conseq) { k = 0, } : the first k CZ gates applied 7 while k < n - 1 do (Rule-Loop-tot), { k < n - 1, } 8 CZ[q[k], q[k+1]] (Axiom-Uni) { k < n - 1, } 9 k := k + 1 (Axiom-Ass), (Rule-Conseq) { k ≤ n - 1, } 10 od { k = n - 1, } { true, } (Rule-Conseq)
By definition, and . At line 8, CZ multiplies each computational basis state by , so for by linearity.
B.7 Building Blocks for Fermi–Hubbard Simulation
The Fermi–Hubbard model is a standard model of interacting electrons [Hubbard 1963] and a benchmark for quantum simulation [Wecker et al. 2015]. We consider its 1D spinless version on an open chain, with nearest-neighbor hopping and density interactions, and verify three building blocks for simulating it: (a) encode the fermionic states and Hamiltonian into qubits by the Bravyi–Kitaev (BK) transformation; (b) block-encode the encoded Hamiltonian by an LCU circuit; and (c) apply a QSP polynomial transformation to that encoding [Gilyén et al. 2019; Low and Chuang 2019]. The QSP program composes them: it runs the BK circuit on its input and calls the LCU circuit in each iteration.
B.7.1 The Bravyi–Kitaev Transformation. The Bravyi–Kitaev transformation maps fermionic operators to qubit operators acting on qubits, compared with for the Jordan–Wigner transformation [Seeley et al. 2012]. This example verifies the circuit of the Bravyi–Kitaev transformation, the invertible matrix over given by its block recursion:
where is zero except for its last row, which is all ones. The circuit computes in place [Seeley et al. 2012], level by level. The program has two classical variables, the level counter and the block counter . The first while loop runs over the levels, and the second runs over the blocks of one level. Each iteration of the second loop is a conditional. If block exists at level , that is, , it applies a CNOT with control and target , where and . Otherwise, it skips. Its Hoare triple is, for every and every input state of the qubits,
Here, is the computational basis state of the qubits for , and we also write for the unitary that maps each to .
The key components of the Bravyi–Kitaev proof outline are the loops at lines 2 and 4, where we use (Rule-Loop-tot). The first loop uses the loop invariant , where is the state
Ren et al.
obtained by applying the first levels of the circuit to . The second loop uses , where is obtained by applying the first iterations of level to .
Bravyi-Kitaev transformation
{ true, }
1 (Axiom-Ass), (Rule-Conseq) { , }
2 while do (Rule-Loop-tot), { , }
3 (Axiom-Ass), (Rule-Conseq) { , }
4 while do (Rule-Loop-tot), { , }
5 if (Rule-Cond) { , } first premise
6 then CNOT[q[ctl], q[tgt]] (Axiom-Uni) { , } { , } second premise
7 else skip (Axiom-Ski), (Rule-Conseq) { , } { , }
8 (Axiom-Ass), (Rule-Conseq) { , }
9 od { , } { , } (Rule-Conseq)
10 (Axiom-Ass), (Rule-Conseq) { true, }
11 od { , } { true, } (Rule-Conseq)
At line 6, the CNOT carries to . At line 7, block does not exist, so . The second loop ends with . After line 11, , and because no block exists at a level . Each CNOT updates one bit of a computational basis state, so the first levels map to , where is obtained from by the bit updates of the first levels. Finally, states that the levels compute , so by linearity.
B.7.2 The Fermi–Hubbard LCU Block Encoding. Block encoding by a linear combination of unitaries (LCU) embeds a Hamiltonian, scaled by , in a block of a unitary, and is the input model of quantum signal processing. This example block-encodes the Fermi–Hubbard Hamiltonian by a program with nested loops and classically computed angles and signs. The fermionic operators are linear combinations of Pauli strings under the BK encoding, and we prove that they satisfy the fermionic anticommutation relations. For , the Hamiltonian is
with Pauli strings , six per adjacent pair, and real coefficients computed from . Let
where is a fixed index, and let for and for . Let be the two-qubit rotation by in the subspace spanned by and ,
which acts as the identity on and . The sign gate on has matrix .
The program acts on system qubits and ancilla qubits , one per Hamiltonian term. We write for the basis state with ancilla qubit in and every other ancilla qubit in . The classical variables are the loop counters and the Hamiltonian coefficients .
The program begins with the ancilla initialization , where is the sequence of all ancilla qubits. It continues with the circuit LCU, which has the standard prepare–select–unprepare structure. Line 1 applies to , and the first while loop (lines 2–6) applies the rotations to , , which carries to the state with amplitude on each . The second loop (lines 7–12) runs over the ancilla qubits. Its iteration applies the sign gate to and then, controlled on , the single-qubit factors of to the system qubits, one factor per iteration of the third loop. The fourth loop (lines 13–17) applies the inverse rotations at the reversed positions, and line 18 applies to again.
The four loops use the loop invariants , and , where
Here, is the product of the first single-qubit factors of , is the factor acting on , and is the product of the first inverse rotations of the fourth loop. The invariant means that the ancilla amplitudes are prepared, and means that the signed Pauli strings of the first terms are applied. The LCU proof outline derives
for every and every input state of the system qubits.
| LCU block encoding | ||
|---|---|---|
| 1 | {true, |0···0⟩a ⊗ |ψ⟩}X[a[0]]{true, |10⟩a ⊗ |ψ⟩} | (Axiom-Uni) |
| 2 | j := 0{j = 0, J(0)(j)} | (Axiom-Ass), (Rule-Conseq)τ0 = 1 |
| 3 | while j < N-1 do{j < N-1, J(0)(j)} | (Rule-Loop-tot), t = (N-1)-j |
| 4 | G(θj(σ))[a[j], a[j+1]]{j < N-1, J(0)(j+1)} | (Axiom-Uni) |
| 5 | j := j + 1 | (Axiom-Ass), (Rule-Conseq) |
Ren et al.
(continued)
{ j ≤ N - 1, }
6 od { j = N - 1, }
{ true, }
7 l := 0 { l = 0, }
8 while l < N do { l < N, }
9 sg_l(σ)[a[l]] { l < N, }
10 s := 0; while s < n do c-(P_l)_s[a[l], q[s]]; s := s + 1 od { l < N, }
11 l := l + 1 { l ≤ N, }
12 od { l = N, }
{ true, }
13 j := 0 { j = 0, }
14 while j < N - 1 do { j < N - 1, }
15 G(- )[a[N-2-j], a[N-1-j]] { j < N - 1, }
16 j := j + 1 { j ≤ N - 1, }
17 od { j = N - 1, }
{ true, }
18 X[a[0]] { true, | }
(Rule-Conseq) (Axiom-Ass), (Rule-Conseq)
(Rule-Loop-tot), t = N - l
(Axiom-Uni)
(Rule-Loop-tot), t = n - s,
(Axiom-Ass), (Rule-Conseq)
(Rule-Conseq) (Axiom-Ass), (Rule-Conseq)
(Rule-Loop-tot), t = (N - 1) - j
(Axiom-Uni)
(Axiom-Ass), (Rule-Conseq)
(Rule-Conseq) (Axiom-Uni)
The verification condition for the rotation at line 4 is
which carries to . Since the fourth loop applies the inverses of the rotations of the first loop in reverse order, . Together with and , this gives, for , the block-encoding identity
For every quantum predicate K on the system qubits, , and every , we derive
(22)
We derive this Hoare triple backward from the postcondition . Each gate and the initialization use the precondition given by their axioms. A loop with bound uses the loop invariant , where is the quantum predicate required after the loop and is the unitary applied by its iterations , which is for . Its verification conditions are
where is the unitary applied by iteration . The third loop is derived in the same way. For an initialization or a circuit and a quantum predicate , we write for the precondition computed from by the axioms (Section 4.4) and these loop invariants. The Hoare triple (22) then follows from (Axiom-Init), the LCU proof outline with these loop invariants, and (Rule-Conseq), whose premise
holds with equality by the block-encoding identity (21). Hence the precondition of (22) equals . The same derivation applies to . Since the total output trace is at most the input trace, the expectation of in the output equals that of the precondition in the input. Taking gives the success probability . As ranges over all quantum predicates, the precondition determines the successful output .
B.7.3 The QSP Polynomial Transformation. Quantum signal processing (QSP) applies polynomial transformations to a block-encoded operator and underlies efficient Hamiltonian simulation [Gilyén et al. 2019; Low and Chuang 2019]. The QSP program alternates the LCU circuit of Appendix B.7.2 with phase gates and reflections on the ancilla qubit . After the ancilla initialization , the program applies (Appendix B.7.1) to the system qubits and then runs a loop of depth on the counter . Iteration applies the phase gate , with the angle given by the classical array , then LCU, then , and increments .
Let , and let , , and be the unitaries applied by LCU, , and ; the single-qubit matrix of is . Let [Gilyén et al. 2019], with the factor acting first. The QSP proof outline derives
for every , depth , and input state . The key component of the outline is the loop at line 3, where we use (Rule-Loop-tot). The loop invariant is , where .
QSP polynomial transformation
{ true, }
1 proved in Appendix B.7.1 { true, }
2 (Axiom-Ass), (Rule-Conseq) { , }
3 while do (Rule-Loop-tot), { , }
4 phase( )[a[0]] (Axiom-Uni) { , }
5 LCU as in the LCU proof outline { , }
6 (Axiom-Uni) { , }
7 (Axiom-Ass), (Rule-Conseq) { , }
8 od { , } { true, } (Rule-Conseq)
Line 1 uses the Hoare triple of Appendix B.7.1 on the system qubits, which leaves the ancilla qubits unchanged. At line 5, the loops of LCU use as loop invariants the states obtained by applying
Ren et al.
the gates of each loop up to the current iteration to . The verification conditions hold by the definition of : , each iteration maps to , and the loop ends with .
Let be an eigenstate with , and assume and . We prove that, on the states the loop reaches from , is the reflection about the subspace with all ancilla qubits in , and that the loop preserves a two-dimensional subspace containing [Gilyén et al. 2019]. In a basis of this subspace that starts with , the upper-left entry of is, with ,
with the k = 0 factor acting first, as in . Hence
For arbitrary inputs, assume and for every eigenvalue of , and define by for each eigenstate with . By linearity, the eigenstate identity extends to
Including the initial BK transformation, the block is therefore
Let denote these spectral hypotheses. They hold, for example, when and . For every quantum predicate on the system qubits, , we derive
(24)
We derive it in the same way as (22), with in place of and . Its loop invariant is , where , with the factor acting first, and the bound function is . The initial (Rule-Conseq) premise holds with equality:
Methods for choosing so that approximates a target polynomial are given in [Gilyén et al. 2019; Low and Chuang 2019].