Manuscript Offprint
arXiv:2610.34723Connecting Quantum Proof Systems and Hoare Logic
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
LIYI LI, Iowa State University, USA
ZOUKARNEINI DIFAIZI TAGBA, Iowa State University, USA
ALEX POTANIN, Australian National University, Australia
Verifying quantum programs today requires specialized proof systems built on interactive theorem provers such as Rocq, Lean, Isabelle, or Why3, and even modest quantum algorithms cost substantial human effort to verify. Because quantum programs cannot be effectively checked by runtime testing, formal verification is the only viable path to correctness, making the cost of these bespoke systems the chief barrier to scalable quantum software assurance. We show that verifying a quantum program should be no harder than verifying a classical array program, a paradigm commonly used in parallel programming: the Qafny quantum proof system translates into Hoare logic with array theory completely (every Qafny proof becomes a valid Hoare triple) and soundly (a valid translated triple certifies only true quantum specifications), and we mechanize the completeness direction in Rocq. The embedding determinizes quantum proof obligations and exposes the full machinery of classical automated verifiers (e.g. Dafny and SMT-based separation logic) to quantum code, removing the need for dedicated quantum proof system infrastructure. In particular, the embedding supplies the correctness argument that the existing compilation of Qafny into Dafny lacks.
1 Introduction
Quantum computers aim to solve highly complex problems by leveraging quantum superposition, which enables substantially faster algorithms, such as Shor's algorithm, than classical algorithms. Because of the exponential state space of quantum superpositions and the inherently probabilistic, nondeterministic nature of quantum systems, traditional validation techniques based on runtime testing are virtually impossible to develop for large quantum programs. Many frameworks have been proposed to verify quantum programs [Chareton et al. 2021; Hietala et al. 2021] using interactive theorem provers, such as Isabelle, Rocq, and Why3, while others have proposed some proof automation by creating proof systems [Cheng et al. 2025; Le et al. 2022; Li et al. 2024; Liu et al. 2019; Unruh 2019; Ying 2012; Zhou et al. 2021], but quantum program verification is still time-consuming.
While quantum computation might be more powerful than classical computation, an interesting question is whether verifying quantum programs is more difficult than verifying classical programs. The key is to establish an effective compilation from quantum program verification to a verification problem in a classical framework, thereby relating quantum and classical operations and providing a classical analogy for quantum programs.
In this paper, we propose a set of classical aggregate operations as the target for compiling quantum operations. Such operations are well-known in higher-order functional programming and are associated with a large and effective verification library. Based on these operations, we transform the Qafny quantum proof system to classical Hoare logic, and illustrate the same approach for Quantum Hoare Logic (QHL) [Feng and Ying 2021] to show its generality. While these classical operations might be computationally expensive, their verification might not be expensive, i.e., it suffices to verify correctness by examining a symbolic representative value of the quantum state after applying a quantum operation. When one applies a quantum operation to a quantum state that can be thought of as a set of classical state values, it cannot manipulate a singleton classical state value without affecting the others. In fact, the manipulation of the operation has a similar effect across different classical state values, which can be summarized by a symbolic state representing the quantum state.
Authors' Contact Information: Liyi Li, Iowa State University, USA, liyili2@iastate.edu; Zoukarneini Difaizi Tagba, Iowa State University, USA, difaizi@iastate.edu; Alex Potanin, Australian National University, Australia, alex.potanin@anu.edu.au.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin

Fig. 1. Two different kinds of soundness and completeness theorems (ours on the left).
To connect quantum and classical proof systems, we develop a new methodology for relating them. In verifying the transformation from quantum proof systems to classical Hoare logic, we develop soundness and completeness theorems based on such theorems in the compilation sense (Figure 1), rather than relying on the proof system soundness and relative completeness, which relate proof systems and their underlying language semantics. The right demonstrates the flow of what would happen by using proof system soundness and relative completeness for our transformation, which fails in place of utilizing the Hoare logic relative completeness to transform a semantic system back to logical assertions, because relative completeness cannot suggest the existence of an effective program verification via the transformation.
Essentially, the main issue arises at predicate transformation. Consider a simple quantum operation to add 3 on each basis-vector of a quantum state for , where is a superposition state . When performing verification, users also need to support a logical post-condition , where is an expression for describing the quantum state after the application, resulting in a quantum state . The post-condition transformation based on the right side of Figure 1 is listed below.
The first transformation above transforms the post-condition to a post-state, a map structure mapping from to a quantum state . Writing down the state can potentially be exponential. The next step is to transform the state by using some classical state structure (trans), e.g., lists or arrays. The last step turns the classical state structure back into a predicate, yielding a possibly exponential listing of different singleton states in the quantum superposition state .
To connect quantum and classical proof systems properly, as in the left of Figure 1, we develop completeness and soundness theorems for the translation itself, in the style of compiler correctness, to relate the validity of the two systems; i.e., the translation completeness theorem states that everything derivable in the quantum proof system is also derivable in Hoare logic, while the translation soundness theorem states that if the translated program is derivable in Hoare logic, then the quantum proof system also derives it, up to semantic equivalence of the assertions.
-
We invent an intermediate Hoare logic IR (HLIR) as the target language. We then develop a transformation from a quantum proof system to Hoare logic based on HLIR. We demonstrate the transformation by compiling the Qafny proof system to Hoare logic with array theory (HLIR), demonstrating that quantum program verification can be carried out via a classical Hoare logic proof system.
-
We prove translation completeness and translation soundness theorems for the compilation, establishing a theoretical foundation: every quantum program verification can be done effectively in Hoare logic, indicating that quantum program verification is no harder than classical program verification.
-
We also examine tensor-based separation conjunctions in Qafny as well as other proof systems [Le et al. 2022; Ying 2026]. We show that these quantum separation conjunctions are pure, in the sense that they can be replaced by classical conjunctions.
2 Background
Quantum Data. A quantum datum consists of one or more quantum bits (qubits), which can be expressed as a two-dimensional vector where the amplitudes and are complex numbers and . We frequently write the qubit vector as (the Dirac notation [Dirac 1939]), where and are computational basis-kets. When both and are non-zero, we can think of the qubit being “both 0 and 1 at once,” a.k.a. in a superposition [Nielsen and Chuang 2011], e.g., represents a superposition of and . Larger quantum data can be formed by composing smaller ones with the tensor product ( ) from linear algebra, e.g., the two-qubit datum (also written as ) corresponds to the vector . However, many multi-qubit data cannot be separated and expressed as the tensor product of smaller data; such inseparable data are called entangled, e.g. , known as a Bell pair, which can be rewritten to , where is a bit string consisting of two bits, each of which must be the same datum (i.e., or ). Each term is named a basis-ket [Nielsen and Chuang 2011], consisting of an amplitude and a basis vector .
Quantum Computation and Measurement. Computation on a quantum datum consists of a series of quantum operations, each acting on a subset of qubits in the quantum datum. In the standard form, quantum computations are expressed as circuits, as in Figure 2, which depicts a circuit that prepares the Greenberger-Horne-Zeilinger (GHZ) state [Greenberger et al. 1989] — an n-qubit entangled datum of the form: , where . In these circuits, each horizontal wire represents a qubit, and boxes on these wires indicate quantum operations, or gates. The circuit in Figure 2 uses n qubits and applies n gates: a Hadamard (H) gate and n-1 controlled-not (CNOT) gates. Applying a gate to a quantum datum evolves it. Its traditional semantics is expressed by multiplying the datum's vector form by the gate's corresponding matrix representation: n-qubit gates are -by- matrices. Except for measurement gates, a gate's matrix must be unitary and thus preserve appropriate invariants of quantum data's amplitudes. A measurement operation extracts classical information from a quantum datum. It collapses the datum to a basis state with a probability related to the datum's amplitudes (measurement probability), e.g., measuring collapses the datum to with probability , and likewise for , returning classical value 0 or 1, respectively. A more general form of quantum measurement is partial measurement, which measures a subset of qubits in a qubit array; such operations often have simultaneity effects due to entanglement, i.e., in
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
a Bell pair , measuring one qubit guarantees the same outcome for the other – if the first bit is measured as 0, the second bit is too.
High-level Operation Abstraction. Controlled quantum gates, such as controlled-not gates (CNOT), can be thought of as quantum versions of classical conditionals, called quantum conditionals, where we view a quantum datum as an array of basis-kets and apply an array map corresponding to the classical operation to each basis-ket. This is evident when using Dirac notation. For example, in preparing a two-qubit GHZ state (Figure 2, also a Bell pair) for qubit array x, the H gate evolves the datum to (same as ). The quantum conditional maps the classical conditional if onto the two basis-kets, where the operation acts as a modulo 2 addition to flip 's bit. Here, we do not flip the position in the first basis-ket due to , and we flip in the second basis-ket because of .
Another abstraction is quantum oracle operations. Quantum algorithms manipulate input information encoded in “oracles,” which are callable black-box circuits. Quantum oracles are usually quantum-reversible implementations of classical operations, especially arithmetic operations. The behavior of a quantum arithmetic operation resembles a high-order array map operation in Figure 3 line (7) over a single arithmetic operation applied to every basis-ket of a quantum datum. OQASM [Li et al. 2022] is a language that permits the definitions of quantum oracles.

Fig. 2. GHZ Circuit
Hoare Logic with Array Theory. Hoare logic (also known as Floyd–Hoare
logic or Hoare rules) [Gordon 2012; Hoare 1969] is a formal system with a set of logical rules for reasoning rigorously about the correctness of computer programs. The central feature of Hoare logic is the Hoare triple. A triple describes how the execution of a piece of code changes the state of the computation. A Hoare triple is of the form where P and Q are assertions and C is a C-like program. Here, P is named the pre-condition and Q the post-condition. When the pre-condition is met, executing the command establishes the post-condition. Assertions are formulae in predicate logic.
The left-hand side shows the key assignment rule in Hoare logic, which establishes the relation between the post-condition and the pre-condition for the assignment operation . The variables and are not restricted to any particular data structure, as they certainly can represent array variables. To verify array assignments, we can define the operation , i.e., the index of the array is assigned to . As the proof rule on the right-hand above, starting from the post-condition , the pre-condition is a replacement of every array variable with the updated array , i.e., we assume the operation updates the position with in .
We assume some useful predicates and conventions to capture the properties of array indexing. First, we use to refer to an array of elements having type , range( ) refers to a list of ranges for some , and means . Second, the predicate ensures that , a multi-dimensional array, has lengths in different dimensions as , and we refer to that the arrays all have lengths . Third, we refer to that is a prefix of , i.e., if has terms and has terms, then .
The following lemma links a pointwise specification of an array-producing statement to the assignment rule: once a statement is known to fill with at every index, any post-condition can be pushed backwards through it by substituting the pointwise-updated array for
A', exactly as the assignment rule does for a scalar. It is the step that turns each HLIR primitive's loop into a single substitution in Section 7.
LEMMA 2.1 (POINTWISE UPDATE). Given , , and
we have
PROOF. By using the Hoare logic assignment rule, we have . With the assumption in the corollary, we result in the following post-condition,
, which is equivalent to P.
The predicate is widely used in various proofs in the paper, so we will sometimes assume it without explicit mention.
3 Overview
Here, we provide an overview of embedding quantum program proofs in Hoare logic. We utilize a running example based on the Deutsch–Jozsa algorithm in Figure 3: given a function that is either constant or balanced, represented as an oracle in the circuit, the algorithm determines whether is constant by outputting or another value. In the algorithm, we first use a length qubit array and an extra qubit , where and is in a uniform superposition by applying Hadamard gates in lines 2 and 5. The superposition state spans all possible values for the two-qubit arrays.
We then apply the oracle operation in line 7 to the locus , i.e., the list of qubit ranges, possibly entangled, that the operation acts on (loci are defined in Section 4.2), and Hadamard gates to in line 9. The oracle operation queries the function and stores the result in the qubit. The H gates associate the query results with the amplitudes, determining the probability of each basis-ket in the quantum state. Here, the state yields an amplitude 1 if is a constant function, and the measurement operation in line 11 outputs with probability .
Line 1 specifies the pre-condition: starts in the state and in the state. Line 12 specifies the post-condition to be verified: that the measurement result correctly indicates that the function is constant, with output probability . The other assertions are the step-wise post-conditions. The type information is specific to Qafny and is introduced in the next section.
Relating Quantum Operations with Classical Ones in a Proof Triple. Here, we provide an overview of viewing a quantum operation as a behavioral equivalence sequence of classical operations. The transformation does not introduce computational benefits, but these classical operations are well-known structures that can be effectively verified; thus, the transformation could provide benefits in verifying quantum programs.
We now highlight the key strategy by showing the transformation of the proof step for Figure 3 lines 6-8. We list the quantum triple with conditions in Qafny as an example. Such a triple captures the key features in many other quantum proof systems [Feng and Ying 2021; Li et al. 2024], where we discuss one of them next.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
1
2
3
4
5
6
7
8
9
10
11
12

Fig. 3. Running example for Deutsch–Jozsa algorithm when is constant; circuit on the right; the grayed out part is the Qafny state types; is an abbreviation of ; line 12 has several simplification and is actually equal to 1 after simplification; state in lines 6 to 12 are separable from , as .
In handling the oracle operation . , we pattern-match it with the ket structure of each basis-ket in the pre-condition state, and infer that the ket structure of each basis-ket in the post-condition state should be . In relating the quantum state predicates to a classical Hoare logic format, we think of a linear sum operator as a single dimension array concatenation; thus, the nested sum operator introduces a two dimensional array where each element property can be described by the expression . In our system, we can think of the number of sum operators in a quantum state predicate as being transformed into an -dimensional array capturing the predicate relation (this is the essence of the EN type). When , conceptually, we can think of the state as the array below.
Note that the locus for the above state is , meaning that the two ket structures, and , have different lengths if we think of and in their bitstring representations. The above simple transformation can be summarized by viewing a quantum state as a predicate over an array of the same dimension as the number of linear-sum terms. Although the state representation might be the right choice, such a simple transformation might not work for many cases. In the example above, if we bit-flip , using , we need to develop a way to locate the specific bit in the right ket structure. Additionally, one cannot assume the qubit order in a ket structure is always well-ordered; e.g., the range points to the ket above, but we cannot assume that must point to the first bit in 's bitstring and points to the last, i.e., the order depends on the layout of the array.
We compile the above operation and its proof to a sequence of classical operations, easily verifiable in Hoare logic, and develop a general procedure to verify the operation via the proof for the sequence. Assume that a set of loci partitions all quantum qubits in into separable regions, and the qubits in the EN(2) typed locus are stored in a two-dimensional array A. The operation produces a set of indices in A for the qubits in with the state being . The array A can have arbitrary dimensions, i.e., an EN(k) typed state is compiled to k-dimensional. Each element in A has the following record type.
Assuming that A is two-dimensional with two-level lengths and , we identify four consecutive operations to construct the Hoare logic proof for the oracle operation above, as follows.
Below are example transitions that apply the above operations to the state in Equation (1).
locateN(A, , ) shrinks high-dimensional element vectors to focus on the indices (e.g., ) representing the locus fragment in A, as we assign the result to a new array (same dimension as A), as . The vector operation accesses the vector but restricts it to the indices of the locus . For the state in Equation (1), and A are identical.
The mapN operation applies the function to each element in and assigns the result to a new array , where and refer to the element's amplitude and vector, respectively. In Figure 3, flips the result bit because it is constant, as the result after . assignN merges the vector in back to , i.e., each vector element is the concatenation of vector and vector , where is the locus fragment outside of . The function determines how we merge the amplitudes of the two arrays; we use 's amplitudes here. Finally, we assign back to .
The transformation is generalizable to other quantum proof systems. In Quantum Hoare Logic (QHL) [Feng and Ying 2021], a proof triple can be written as , where and are pre- and post-conditions for classical variables and and are quantum state predicates. For example, the above proof triple for the oracle operation can be expressed as follows.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
Here, there are no conditions for classical variables. In the quantum state predicates, we encode each range in the locus information in the corresponding basis-vector, e.g., Essentially, transforming the above triple is similar to the Qafny one, in which we still transform a state into a high-dimensional array. We illustrate the QHL case by examples here and in Section 5; a detailed discussion is in Section B and the full QHL translation is left to future work.
The main theorems. We first present the paper’s main result: quantum program verification can be effectively carried out within the classical Hoare logic proof system. We use Qafny as the example proof system for the main theorems in the paper. Given a Qafny proof triple, , there are three main theorems in the paper.
PROPOSITION 3.1 (TRANSLATION COMPLETENESS). Translating a derivable Qafny triple results in a valid Hoare logic triple .
PROPOSITION 3.2 (TRANSLATION SOUNDNESS). Let a well-typed Qafny program and well-typed conditions and translate to , , and . If the Hoare triple is valid, then Qafny derives a triple with and ; by the semantic soundness of Qafny, satisfies the specification .
PROPOSITION 3.3 (TRANSLATION SIZE). The translation produces at most eleven HLIR statements per Qafny statement, and the translated assertions and the Hoare proof skeleton for each statement have size polynomial in the size of the Qafny triple and the array dimension, measured in the symbolic array representation of Section 7.
Throughout, the ground truth is the quantum semantics. A Qafny triple is derived by the Qafny proof system, which is sound with respect to that semantics [Li et al. 2024]; the classical side never sees quantum states, only the translated program e and assertions P and Q. Our two theorems relate derivability in Qafny to validity of the translated Hoare triple in both directions, and we name them from the perspective of Hoare logic as the verifier. Translation completeness says that nothing Qafny can prove is lost in translation: Hoare logic with array theory is expressive enough. Translation soundness says that the classical verifier cannot certify a false quantum claim: a valid translated triple corresponds to a Qafny derivation with semantically equivalent conditions and hence, by Qafny's semantic soundness, to a true statement about the program. Both directions are needed for the claim in the abstract. The size bound shows that the translation is effective: the verification conditions it generates are polynomial in the input, so the classical verifier faces a problem no larger than the quantum one, up to its own proving power. The bound concerns the size of the conditions, not solver time.
We formally detail the compilation of this operation and others in the next section.
4 The Source Proof System: Qafny
We introduce a part of Qafny as an example quantum proof system for demonstrating the compilation procedure.
4.1 Qafny Syntax and A Running Example
Figure 4 shows Qafny’s syntax, which is imperative and designed with high-level quantum programming operations. A Qafny program consists of statements ( ), including control flow constructs (SKIP ( ), for-loops, and quantum conditionals), classical assignments ( ), computational basis quantum measurement ( ), and quantum heap mutations ( ). A measurement operation is a let-binding that measures the locus , stores the classical value of the result.
QHL names and as quantum variables, while Qafny names them as ranges in a locus.
OQASM Expr
Arith Expr
Bool Expr
Quantum Expr op
Statement
Fig. 4. Qafny syntax. We focus on the operations marked in black, and the red ones are essentially classical.
in with the probability , and uses the result in . A heap mutation applies a quantum operation – such as state preparation operations (Hadamard gate H and quantum Fourier transformation gate QFT), and a quantum arithmetic oracle operation ()-to a locus ; such behavior is analogous to mutating a qubit heap array by applying the operation to each basis-ket element in the array.
Quantum reversible Boolean guards are implemented as OQASM oracle operations, expressed by one of , and , which intuitively amounts to computing , and false respectively as and storing the result of as a binary in qubit In both conditionals and loops, guards are used to represent the qubits being controlled.
4.2 Quantum State Predicates and Qafny Triples
Quantum program proofs are based on the Qafny triples , meaning that a quantum program verification for is valid if we start with a pre-condition and the execution of satisfies the post-condition , where is the typed environment for and . Here, and are syntactic logical forms representing quantum states, e.g., the one in Figure 5; such quantum state predicates are generic to different quantum proof systems.
A program verification in Qafny can be expressed as a separation logic triple . Qafny verifies such a triple by constructing a proof tree, as in Li et al. [2024]. We explain below how Qafny state representations are organized, and discuss the program syntax and proof translation in the following subsections. As in Figure 5, the states in Qafny triples are syntactic entities that represent quantum states and program transitions. A state describes program variable behavior, where variables are partitioned into two different kinds: C for classical scalar values, such as natural numbers or reals, and for a physical -length qubit array conceptually residing in a quantum heap. We permit users to write scalar types, e.g., nat and real, in a Qafny program, recognized as C-kind.
In Qafny, we abstract a quantum state as a predicate that represents a heap structure, with qubits corresponding to physical heap locations. A state predicate is expressed as , meaning that a group of possibly entangled qubits maps to a quantum datum of type . Elements in a quantum state predicate are separated by the operation, conceptually equivalent to the tensor operator . Similar to the separation conjunction in separation logic, it enables modular reasoning about the quantum state predicate and ensures that different unentangled qubit groups are disjoint. Before we explain the types and loci, we show an example of expressing a Qafny triple from the Deutsch–Jozsa algorithm in Figure 3 (left). Line 1 is the pre-state predicate before any operation is executed, with EN(0) typed data (abbreviation of ) for the separable qubit group . Applying the Hadamard operation to in line 2 turns 's state to a EN(1) typed datum in line 3. The pre- and post-conditions and the operation form a Qafny triple as follows.
can define all quantum arithmetic operations, e.g., Figure 3 line 7. See [Li et al. 2022].
and can possibly apply to a range, like , in an entangled locus.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
Basic Terms:
Nat. Num Complex Amplitude Real Phase
Variable Function Variable Bit/Bool Bitstring
Modes, Kinds, Types, and Classical/Quantum Values:
Classical Scalar Value
Kind
Basis Vector
Basic Ket
Quantum Type
Quantum Data
Quantum Loci and States
Qubit Array Range
Locus
concatenated op
Type Environment
concatenated op
Typed Quantum State Predicate
concatenated op
Syntax Abbreviations and Basis/Locus Equations
Fig. 5. State syntax. The part marked in red is specific to Qafny, while the other part is generic across different quantum proof systems. A range in a locus is the interval in a qubit array . Loci are finite lists; states are finite sets. Natural-number literals are ranged over by ; range bounds are arithmetic expressions and may mention program variables, such as in . The ops after "concatenated op" are concatenations.
Qafny utilizes types to classify quantum data, allowing quantum program verification managed in different views of a quantum state, e.g., every Qafny triple comes with a type environment , where its well-typedness is defined as for all . We use to track changes across different quantum state types, leading to distinct verification strategies, as captured in the proof translation in Section 6.
As mentioned above, many entangled quantum data are not expressible as tensor compositions of individual qubits. Instead, they can be expressed in the basis-ket view, i.e., the quantum datum, classified as type in Qafny, can be viewed as a linear sum (array) of basis-kets , each representing a possible outcome for measuring the qubits. The flag represents the number of summation operations in a quantum state representation syntactically. For example, we merge two qubit groups and into the entangled datum in line 4, as the locus . Here, the whole datum has possible basis-ket states, for , i.e., the basis-vector fragment for is represented as while the basis-vector fragment for is .
The EN(0) typed datum, e.g., 's state in line 1, represents a non-superposition state, since it contains only a singleton basis-ket. A single qubit state could be in superposition but not entangled, e.g., the state in Figure 3 line 3 can be represented as -length qubit array , each of which is a EN(1) superposition state , for the range ; the state is not entangled.
As a state predicate, physical qubit locations might be hard to track, e.g., the entangled qubit information in line 8 is spread into different basis-kets. Therefore, we develop a locus structure to indicate that the two ranges and are possibly entangled. It is also an information location indicator, i.e., the range points to the first bits in each basis-ket and points to the last bit .
5 Embedding Separation Conjunction and the Frame Rule
Here, we discuss the translation of the frame rule in Qafny and QHL, and separation conjunctions, and present our first discovery: tensor-based quantum separation conjunctions are pure, a key contribution of the paper.
In separation logic, an assertion is pure when its truth depends only on the store and not on the heap. When an assertion is pure, a separation conjunction (*) is equivalent to an ordinary conjunction (∧). Here, we generalize the pureness as follows. Given , for any program operation, if we can show that modifying the operation in Q will never affect the evaluation of P, there is pureness on the particular separation conjunction, and is equivalent to .
A non-purity scenario is based on a predicate , where is a memory heap location pointing to . Even though might not mention , a variable in could alias , so modifying might affect the value in . This scenario cannot arise in Qafny: there is no qubit reference type, loci are ranges of named qubit arrays, and the type environment keeps the loci of a state disjoint, so two names never denote the same physical qubit. In a language with qubit references, or under a reference semantics, the disjointness assumption must be discharged separately, which is what a separating conjunction provides there.
Example 5.1 (Pureness Example). As an example of showing pureness, the separation conjunction in the proof lines 1-3 in Figure 3 can be replaced by a normal conjunction.
If we have the example in QHL, the same separation conjunction can also be rewritten as a normal conjunction. Here, can be viewed as a predicate , e.g., means .
In the above example, we replace the tensor operators connecting different unentangled qubit regions with normal conjunctions. In quantum operations, if we know that the operation, e.g., , does not mention a qubit region , the operation will not affect the region. This is different from the need for separation conjunction, where a point operation might affect a memory field even if the operation does not explicitly mention the field. We have the following theorem.
THEOREM 5.2 (PURENESS). Given , , , and , where and describe disjoint sets of qubits and , we have the following in QHL.
as well as the following in Qafny.
Here, means that is valid if and only if is valid. We also require , , , and : the loci of and are disjoint, which the Qafny
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
type environment enforces and which the translated frame rule below turns into the classical side condition .
The proof of the above theorem for the Qafny version relies on its type system, and the proof for QHL relies on a clear separation for distinguishing qubit locus regions and demonstrates that the execution of does not affect . The Qafny locus type system purely separates two state conditions if they mention disjoint loci, as we have a stronger result for Qafny below.
THEOREM 5.3 (QAFNY PURENESS). Given and , such that and , there exists such that and .
PROOF. The proof utilizes the Qafny proof system soundness [Li et al. 2024] , as we inductively show that for any e, if a state can be partitioned into and based on disjoint loci in and and e only operates on , then is never affected.
Theorem 5.2 suggests that separation conjunctions can be replaced by ordinary ones if the two pieces describe disjoint loci. It indicates that the separation conjunctions in the Qafny and QHL frame rule – where the Qafny one is listed on the left above – can be rewritten to a formula containing only ordinary conjunctions; thus, translating the two quantum proof systems to Hoare logic will not require adding separation conjunctions. Here, represents the translated Hoare logic program for , , , and are the translated predicates for , , and . The details of these translated functions are given in Section 7.
In fact, the above result is general for all the tensor ( ) based quantum separation conjunctions [Le et al. 2022; Zhou et al. 2021]: once the disjointness of the two qubit regions is tracked, as the Qafny type environment does, these separation conjunctions are pure, i.e., they can be treated as normal conjunctions.
6 The Intermediate Representation Language based on Hoare Logic
We describe HLIR based on Hoare logic, where every operation is definable and provable as a composition of operations in the classical Hoare logic language with array assignments. Mainly, we discuss the syntax (Figure 6), the informal meaning, and array-state representations. We detail HLIR with proof examples, along with our translation proof from Qafny to HLIR in the next section.
Index Function ::=
Array Element ::= element {amp = z, vector = c}
Function ::=
Statement ::=
Fig. 6. HLIR Syntax
This is Qafny’s soundness with respect to the quantum semantics, not one of the translation theorems of this paper.
HLIR State Representation. As we mentioned, for an EN(n)-typed quantum state, loci partition the state into disjoint qubit regions, where every fragment in a locus is disjoint from other fragments in the locus. We model the EN(n)-typed state in Hoare logic as an n-dimensional array, containing elements , modeled as a record in Figure 6. The array indexing operation can be abbreviated as , which represents a basis-ket state; the array can be thought of as a linear sum of basis-kets. In each element, one can access the amplitude via amp and the vector via vector. The two functions up and up update the amp of an element and the positions of its vector, respectively.
Essentially, vector is a bit sequence. We maintain a map from the qubits in the locus fragment to the indices in the bit sequence, to record the index positions. As an instance, Equation (1) is an array representation of a quantum state, pointed to by the locus , where , with being the state in Equation (1), points to the index position 0, while points to the index position 1. We have the following lemma for ind.
LEMMA 6.1 (DISJOINTNESS PRESERVATION). Given a locus , an EN(n) typed state , and a locus map ind, where indices(A) = ind and for every , we have , and for every locus fragment , s.t. and indices(A') = ind , for , vector(A' [j_0, ..., j_{n-1}]) vector(A[j_0, ..., j_{n-1}]).
The above lemma has a hidden assumption when applied to Qafny: we assume we can always refer to a finite global universe containing all qubits in the state . Such a statement is valid in Qafny as well as many other quantum proof systems. We present the following lemma, which states that the resulting quantum state after executing a Qafny program is always a subset of the input state. Thus, for any program, there is a quantum state that acts as its universe.
LEMMA 6.2 (QUANTUM STATE SHRINKING). Given a state , a Qafny program , and a type environment , such that , , and (the Qafny program is evaluated to by the input state ), we have .
Briefing the HLIR Operation Syntax. The functions and statements in Figure 6 are used in the translation proof in Section 7. We provide informal descriptions below.
We have a set of helper functions to define small array properties. The operations range( ) and are described in Section 2. enumerates numbers from 0 to , merge( , , ) creates a new vector by replacing 's indices with , and vector( ) shrinks vector to .
We divide the statements into two sets: a set (marked black) of essential operations and a set (marked blue) of compositional operations definable in terms of the essential set. Most of the operations in the essential set are standard functional programming operations. mapN is a high-order map operation mapping the function to every element in the array , filterN filters out elements in an array that do not satisfy the boolean function , concat concatenates two arrays if they have the same dimensions, produces the array lengths, which can be high-dimensional, and sqrtSum computes the square root of the sum of the squared amplitude norms over all array elements, as it can be built on top of a higher-order folding function. assignN is an update function that updates with 's element amplitudes and vectors (the shrunk fragments), assuming , where defines how to combine the amplitudes of and 's elements.
The set of compositional operations is definable by the essential set. We examine them in Section 7 and briefly describe them here. locateN creates a new array by shrinking the vectors in every element to the indices . copyN( , ind ) and enumN( , ind ) are special case of mapN. The former creates an dimensional array if is dimensional, by replacing each element with a list of copies of that element. If the inner dimension has length , enumN creates an array by copying but differing in terms of the vectors, where vector( , ind ) = i
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
and vector multiplies and 's element amplitudes. upDim upgrades 's dimensions to , assuming that (defined in Section 2). The operation fills the new dimensions by copying the elements in the original .
7 Translating Qafny Operations to HLIR
This section describes the translation proof from Qafny to HLIR. The translation of Qafny to HLIR turns Qafny proof triples to Hoare logic triples , including two pieces: translating the Qafny program to an IR code and, respectively, translating the pre- and post-conditions and to and . The two pieces can be described by two judgments: and . The former extends the Qafny type system and the latter extends the well-typed quantum state . In Sections 7.1 to 7.5, we discuss translations for different Qafny operations, along with validity arguments, the completeness direction: for any derivable Qafny triple for an operation, we show that its translated Hoare triple is valid. Finally, we state the translation completeness, translation soundness, and translation size theorems in Section 7.6.
The translations are organized by the effect of an operation on the array representation. (1) Operations that create superposition add a dimension: H and QFT (and, in the same way, rotations that create superposition) translate to copyN, enumN, and ampN (Section 7.2); the amplitudes need not be uniform, since ampN multiplies by an arbitrary function of the old and new basis vectors, of which the uniform Hadamard amplitude is one instance. (2) Operations that map elements in place, i.e., basis permutations and phases such as X, RZ, and the arithmetic oracles , translate to locateN, mapN, and assignN (Section 7.1). (3) Controlled operations, i.e., quantum conditionals, split the array with filterN, translate the body, and reassemble it with concat (Section 7.3). (4) Measurement filters and renormalizes (Section 7.4), and classical statements are translated structurally (Section 7.5). Any gate given by its action on basis kets falls into class (1) or (2), possibly under a control of class (3).
7.1 Translating Oracle Operations
Here, we discuss the transformation of the oracle operation proof rule below to HLIR.
This rule relies on a frame rule to focus state predicates to the locus . Because the Qafny separation conjunction is pure, it is no different from a normal conjunction. We can rewrite the above Qafny proof rule to the version below, which relates a general post-condition to a pre-condition, in a style similar to the Hoare logic array assignment rule.
To translate the proof rule to Hoare logic, we construct a composition of classical operations representing the effect of the operation , including three components: the operations locateN, mapN, and assignN, mentioned in Section 3. One example is given in Section 3.
Validity Proof. We state the translated Hoare triple as a lemma below, showing its validity.
LEMMA 7.1 (VALID ORACLE APPLICATION TRANSFORMATION). Given a quantum state and an operation in the locus , with the -typed quantum datum , transformed to an dimensional array having the collection of indices , where , we have the following valid Hoare triple.
Here, refers to where and are expanded to and ; and are defined as follows, where (Figure 6) replaces the positions of with the bits , with .
Proof. The validity proof utilizes Lemmas 7.2 and 7.3. Its mechanized proof is in Rocq.
We define and prove below the three operations locateN, mapN, and assignN. Essentially, locateN and mapN are similar, where the former is a special case of the latter, described below
We now show the proof for mapN. For all the proofs, we assume the array length axioms , stating that the -dimensional arrays have -dimensional lengths .
LEMMA 7.2 (THE VALID MAPN DEFINITION). Given dimensional arrays and , with , and a function , we have the valid Hoare triple for :
where is defined as:
Proof. By Lemma 2.1, it is enough to show the validity of the following triple.
The proof-tree derivation, with loop invariants at each level, is given in Section A.1.
assignN(A, , , , ) updates 's element amplitudes with the combination of and 's amplitudes via , as well as updates 's bit-vectors, only for the part, with 's. We now show the validity lemma for assignN.
LEMMA 7.3 (THE VALID ASSIGNN DEFINITION). Given dimensional arrays , , and (assuming that is pre-initialized to an dimensional array with bounds ), with , we have the following valid Hoare triple.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
Proof. By Lemma 2.1, it is enough to show the validity of the following triple.
The rest of the proof derives a Hoare logic proof tree and has a procedure as the one in Lemma 7.2, except that we update with . The proof-tree derivation is given in Section A.2.
7.2 Translating Hadamard and QFT Operations
The translations of Hadamard and QFT operations to HLIR are similar; it suffices to demonstrate the Hadamard operation translation. We list the proof rule below.
Similar to the oracle function case above, we develop the translation based on a generalized version connecting the pre- and post-conditions P, listed below.
We first show the effect of the operation. The operation’s Qafny type rule, , indicates that a Hadamard operation lifts an dimensional array to dimensional. An example is to apply to a typed state with the locus . The quantum datum is shown on the left below, with its one-dimensional array view on the right.
To construct a proof in Hoare logic, we can split the operation into three steps, (copyN, enumN, and ampN), on the first two bits, corresponding to the locus fragment . Below are their transitions.
The copyN step turns each array element into an array of (4) elements by copying the original element, i.e., for the element , we make an array of 4 copied elements. This step also turns the array dimension from one (typed EN(1)) to two (typed EN(2)). For the first two bits of each element vector in the inner array, enumN enumerates from 0 to in binary. As shown above, we change the first two bits at each basis-vector position to 00 (integer 0), 10 (1), 01
(2), and 11 (3) for each inner array. ampN multiplies each amplitude position by two pieces. We first multiply by , and then by a phase , where old and new refer to the first two bits of element vectors before and after applying enumN, respectively, and is the dot product. QFTs are similar to Hadamard operations, with the addition of phase multiplication.
Validity Proof. Below, we present the valid Hoare triple definition as a lemma for Hadamard operations, followed by the proofs for individual operations.
LEMMA 7.4 (VALID HADAMARD APPLICATION). Given a quantum state , an operation in the locus with the -typed quantum datum , transformed to an -dimensional array , with and , the result array has dimension, with the inner array bound . The valid Hoare logic triple is given as follows.
\begin{aligned}let E&:=[\forall k\in[0,2^{|\eta|}).up^{a}(up^{b}(A[\overline{j}],k,ind^{\varphi}(\eta)),(-1)^{k\cdot vector(A[\overline{j}])[ind^{\varphi}(\eta)])]in\\&\left\{P[A\{\forall\overline{j}\in range(\overline{m}).\overline{j}\mapsto E\}/A]\wedge Q_{len}(A,\overline{m})\wedge Q_{len}(A\{\forall\overline{j}\in range(\overline{m}).\overline{j}\mapsto E\},(\overline{m},2^{|\eta|}))\right\}\\&\quad A_{1}:=copyN(A,\overline{m},ind^{\varphi}(\eta));A_{2}:=enumN(A_{1},\overline{m},ind^{\varphi}(\eta));A_{3}:=ampN(A_{1},A_{2},\overline{m},ind^{\varphi}(\eta));A:=A_{3}\\&\left\{P\wedge Q_{len}(A,\overline{m})\wedge Q_{len}(A\{\forall\overline{j}\in range(\overline{m}).\overline{j}\mapsto E\},(\overline{m},2^{|\eta|}))\right\}\end{aligned}Proof. The validity proof below comprises the results for copyN, enumN, and ampN. Its mechanized proof is in Rocq.
We now demonstrate the definitions and proofs for the three key IR operations. We first show the valid Hoare triple for copyN.
LEMMA 7.5 (THE VALID COPYN HOARE TRIPLE). Given a locus , an dimensional array , with the bounds , and the valid Hoare triple of copyN( , ) is listed below with its implementation. We assume that the result array is initialized to have dimensions, with the additional dimension bounded by .
where copyN(A, , ind ) is defined as: mapN(A, , .copy(2 , (x, y))); copy(N, v) is a function to generate an array of N copies of the element v.
Proof. By Lemma 2.1, it is enough to show the validity of the following triple.
The proof is given by deriving a proof tree and using a single operation mapN. Its details are mechanized in Rocq.
We now present the proof of enumN below, where we construct an dimensional array based on , by replacing the vector in the locus with the enumeration from 0 to .
LEMMA 7.6 (THE VALID ENUMN HOARE TRIPLE). Given a locus , an dimensional array , with the bounds , the valid Hoare triple of is listed below with its implementation. The result array is initialized as an dimensional array. has the first indices and the most inner index .
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
where enumN is defined as follows; enum(2^|η|) produces an array listing all numbers in [0, 2^|η|).
Proof. By Lemma 2.1, it is enough to show the validity of the following triple.
The proof-tree derivation is given in Section A.3.
We now demonstrate the validity of the Hoare triple for ampN, and it suffices to show the n-dimensional case. Here, we generate an n-dimensional array , having the same basis-vectors as , but multiplying its amp elements by a phase relating the amp elements of and .
LEMMA 7.7 (THE AMPN PROOF). Given a locus , two dimensional arrays and , with the bounds of each dimension to be , and the valid Hoare triple of the function is listed below. The result array is initialized to be -dimensional with bounds .
\begin{aligned}&\left\{\begin{array}{l}P[A_{3}\{\forall\overline{j}\in\mathrm{range}(\overline{m}).\overline{j}\mapsto\mathrm{up}^{a}(\mathrm{up}^{b}(A_{1}[\overline{j}],\mathrm{vector}(A_{2}[\overline{j}])[\mathrm{ind}^{\varphi}(\eta)],\mathrm{ind}^{\varphi}(\eta)),\\ \quad(-1)^{\mathrm{vector}(A_{1}[\overline{j}])[\mathrm{ind}^{\varphi}(\eta)]\cdot\mathrm{vector}(A_{2}[\overline{j}])[\mathrm{ind}^{\varphi}(\eta)])\}/A_{3}]\wedge Q_{\mathrm{len}}(A_{1},A_{2},A_{3},(\overline{m},2^{|\eta|}))\end{array}\right\}\\ &A_{3}:=\mathrm{ampN}(A_{1},A_{2},\overline{m},\mathrm{ind}^{\varphi}(\eta))\\ &\left\{P\wedge Q_{\mathrm{len}}(A_{1},A_{2},A_{3},(\overline{m},2^{|\eta|}))\right\}\\ \end{aligned}where is defined as:
Proof. The proof is given as deriving a proof tree and building on top of assignN. The detail is mechanized in Rocq.
7.3 Translating Quantum Conditionals
We now present the translation of a quantum conditional, whose proof and type rules in Qafny are given below and contain two predicate transformers, and .
\begin{aligned}\frac{\mathrm{P-If}}{\frac{FV(b)=\eta\qquad\left\{\eta^{\prime}:\mathrm{EN}(n)\right\}\vdash\left\{\varphi\left[\mathcal{F}(b,\eta,\eta^{\prime})/\eta\boxplus\eta^{\prime}\right]\right\}\mu\left\{\varphi^{\prime}\right\}}{\left\{\eta\boxplus\eta^{\prime}:\mathrm{EN}(n)\right\}\vdash\left\{\varphi\right\}\mathrm{if}(b)\mu\left\{\varphi\left[\mathcal{U}(\neg b,\eta,\eta\boxplus\eta^{\prime})/\eta\boxplus\eta^{\prime}\right]*\varphi^{\prime}\left[\mathcal{U}(b,\eta,\eta\boxplus\eta^{\prime})/\eta^{\prime}\right]\right\}}\\ \frac{\mathrm{T-If}}{FV(b)=\eta\qquad FV(e)\subseteq\eta^{\prime}\qquad\sigma\uplus\left\{\eta^{\prime}:\mathrm{EN}(n)\right\}\vdash e\triangleright\sigma\uplus\left\{\eta^{\prime}:\mathrm{EN}(n^{\prime})\right\}}\\ \frac{\sigma\uplus\left\{\eta\boxplus\eta^{\prime}:\mathrm{EN}(n)\right\}\vdash\mathrm{if}(b)e\triangleright\sigma\uplus\left\{\eta\boxplus\eta^{\prime}:\mathrm{EN}(n^{\prime})\right\}}\end{aligned}In Rule P-If, the bottom layer selects basis-kets w, where is true and trims the basis-ket states to the locus region . With the shrunk basis-ket states, the top level applies the operation. We first demonstrate the Qafny proof via the Bell pair example.
Example 7.8 (The Quantum Conditional Example in Bell Pair). The Bell pair circuit (Section 2) applies a Hadamard to qubit followed by a controlled-not on guarded by , and . With pre- and post-conditions, the Qafny triple is:
The pre-condition is an EN(1) typed entangled state for . The upper-level pre-condition checks 's basis-ket fragment , masks the case, and leaves the case of , where we hide 's basis-vector since it is not mentioned in the locus domain. Finally, we assemble the upper level post-condition with and .
The key to embedding the proof rule is to connect the upper- and bottom-level (pre- and post-) conditions. To do so, we can think of two program points • and ○ around the translated expression e, where we prepare inserted predicates before • to transform P to the right form of the upper-level pre-condition and transform ○, representing the upper-level post-condition, to the bottom-level post-condition Q. We manage the translation as follows.
LEMMA 7.9 (THE QUANTUM CONDITIONAL TRANSFORMATION). Given if (b) , where we do expression translation for , and pre- and post-condition translations, as and ; without losing generality, we assume the locus is translated to an dimensional array , such that , we express the valid Hoare logic triple as follows. and represent the lengths for an and (> ) dimensional arrays, respectively, where extends with additional dimensions with length 1 in each dimension; adds the lengths in each dimensions.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
;
;
;
;
;
, , );
;
In the lemma, filterN collects all the elements in A satisfying b on the vector-bits corresponding to , updates 's dimension from to , and creates a new array by concatenating to the end of .
As an example of compiling Example 7.8, we name all the compiled operations in Lemma 7.9 as if_h(e), where the Qafny triple in Example 7.8 is translated to the Hoare triple below.
We examine the step-by-step effect of the operation below. By applying the filterN functions to A for Boolean expressions b and , we assign and , with both lengths being for and for ). We list the post-condition after applying the first four operations below.
We then apply locateN to and assign to be . By applying pre-condition strengthening, we reach the pre-condition on the top level above.
In Example 7.8, the upper level is a translation of given by the oracle operation compilation in Lemma 7.1. We list the translated version below.
After applying the expression , we reach the upper level post-condition , with the length . Since 's dimension is not modified in the upper-level computation, i.e., 's dimension is the same as 's, the first upDim operation sets to be the same as . The same situation applies to the second upDim. We list below the post-condition, including only , , and after the two upDim operations.
The assignN operation assigns to with 's amplitude as well as the basis-vector bit shrunk to the second position 's position), where is assigned as . Then, we concatenate and and assign back to A. Finally, we reach the bottom-level post-condition listed in the Hoare triple above.
Validity Proof. The validity proof is based on the Qafny proof rule for quantum conditionals, with generalized pre- and post-conditions, where we set the bottom-level pre- and post-conditions to be arbitrary P and Q in P-If. In Lemma 7.9, the operations before • transform P to the precondition of the upper level (P-If) and the operations after ○ transform the post-condition in the upper level to Q, i.e., the pre- and post-conditions around e can be thought of as , where • and ○ represent the translated upper-level pre- and post-conditions. We outline the proof below.
Proof. The proof requires deriving a Hoare logic proof tree, including the array-length axioms for and to . We assume that defines the length for dimensional array, where defines the lengths for dimensions and the remaining dimensions have length 1. The proof relies on the axiom that concat(filterN(A, b), filterN(A, -b)) gives back , i.e., if we partition into two subsets and merge them back, it will produce the same . This is valid in quantum states since they do not care about ordering. The proof-tree derivation is given in Section A.4.
We now present the proofs for some of the functions involved above. The filter (filterN), array concatenation (concat), and array length (|A|) are well known, as many previous works [Wang and Appel 2023] discuss their Hoare logic proofs. Their mechanized proof is in Rocq and has a similar style to Lemma 7.2. We mainly focus on upDim(A, , ), which updates A's dimension from to , provided that , i.e., is a prefix of as .
LEMMA 7.10 (THE VALID UPDIM HOARE TRIPLE). Given a locus , an dimensional array , with the bounds and a length list , and the valid Hoare triple of upDim( ) is listed below with its implementation. We assume that the result array is initialized to dimension with the additional dimension bounds .
where upDim(A, , ) is defined as: mapN(A, , .copy( , )); copy( , v) is a generalized version of the copy function in Lemma 7.5 to produce a dimensional array of elements v.
PROOF. The proof is given by deriving a proof tree using a single operation mapN, and it follows a similar style to the proof of Lemma 7.5. Its detail is mechanized in Rocq.
7.4 Translating Quantum Measurement
Below is the Qafny proof rule for quantum measurements, containing a predicate transformer M.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
The predicate transformer performs two tasks: 1) trim down the locus to be since is measured away, and 2) assign the measurement result, both measurement output bits and probability value, to the binding variables and , respectively. The operation is similar to a series of array assignments, as in the quantum oracle operation, except that the measurement result is nondeterministic. If we view a quantum state as an array representing a linear sum, we can always assume the existence of the index to be picked; thus, , if refers to the sub-array of , and the probability value is the sum of the squares of all amplitudes in (for all ), such that . We define the following valid Hoare triple for quantum measurement.
LEMMA 7.11 (THE MEASUREMENT VALID TRIPLE). Given a quantum state , an operation in the locus with the -typed quantum datum , transformed to an dimensional array , where the collection of indices . Assuming that the index is picked for , the valid Hoare triple is listed as follows, where .
Following the Bell pair example in Example 7.8, assume that we are given the task of verifying whether 0 and are the valid outputs after measuring the first qubit, and the state before the measurement is represented as an array . When applying the proof sequence in Lemma 7.11 to the example, we first pick 0 as the output index, as , where we assign to vector , and we assign and to be and with . Finally, is assigned to where we assign to be by dividing the element amplitude by .
Measurement need not be the last step of a program: binds the outcome and its probability for use in the continuation. Because the outcome index is chosen once and the remaining array is a function of the pre-state and that choice, the continuation sees as an ordinary classical variable; feed-forward control on measurement outcomes, as in teleportation or repeat-until-success loops, therefore translates to ordinary classical control in Hoare logic, and no black-box probability distribution is involved.
Validity Proof. We show the proof of Lemma 7.11 below.
Proof. The proof derives a Hoare logic proof tree by combining the proof results for the filterN, locateN, sqrtSum, and other functions. For simplicity, we omit the judgments. The proof-tree derivation is given in Section A.5.
For the functions involved in the proof, aside from sqrtSum, the others have been discussed above. We now present the proof of the sqrtSum function below, which is essentially the same as the proof for a classical sum function.
LEMMA 7.12 (THE SQRTSUM HOARE TRIPLE). Given a locus , an -dimensional array with bounds , the valid Hoare triple for the function is listed below.
where is defined as:
PROOF. The proof is given by deriving a proof tree with a structure similar to the proofs of the classical sum function and of Lemma 7.2.
7.5 Translating Classical Operations
The Qafny proof system contains some proof rules for classical operations, where we list two below for sequencing and for-loop operations.
Except for the Qafny typing, the proof rules are similar to the sequencing and for-loop rules in Hoare logic. These rule transformations are natural, i.e., we transform the sub-terms and simply transform these operations to the proof rules for similar operations in Hoare logic. Sequencing is compositional: the translation of ; is the sequence of the two translations, and P-SEQ becomes the Hoare sequencing rule. A for-loop is a classical loop whose body is translated as above, so P-Loop becomes the Hoare loop rule with the translated invariant. The only non-trivial step is the invariant itself: its locus typically grows with the loop index, as does in a loop that entangles one more qubit per iteration, so the invariant is translated with the index map and the array bounds parameterised by . The translated invariant is then an ordinary Hoare invariant, and its preservation over one iteration is the translation of the loop body from to .
7.6 Translation Completeness and Soundness
This section presents the two translation theorems; translation completeness (Theorem 7.13) and its component lemmas are mechanized in Rocq, while translation soundness (Theorem 7.14) is proved on paper. Based on the individual component proofs in Section 7, we express the combined theorem below.
THEOREM 7.13 (TRANSLATION COMPLETENESS). Given a Qafny proof , let , , and ; thus, .
PROOF. The proof is based on induction on the Qafny type system and a combination of the proofs for the cases in Lemmas 7.1, 7.4, 7.9 and 7.11. The proof of the for-loop and a Hoare logic
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
loop are the same except that we need to translate the loop invariant, since the for-loop operation is classical in Qafny.
The above theorem is the completeness direction: as we translate the program , pre-condition , and post-condition to a Hoare logic program and conditions and , the triple is valid in Hoare logic, so nothing Qafny can prove is lost in translation. Since the translation is guided by the Qafny type system , the converse direction, translation soundness, must be shown separately: when a translated is valid, Qafny derives a triple for with semantically equivalent conditions, so the classical verifier cannot certify a false quantum claim. This is the direction that makes a classical verdict about a quantum program trustworthy. In the following theorem, is the semantic interpretation of the quantum state .
THEOREM 7.14 (TRANSLATION SOUNDNESS). Given a Qafny program , with the typed translation where , two conditions and , such that and , if , there exists and , such that , , and .
Proof. The proof is based on induction on the Qafny typing rules . Note that the expression is translated from via fixed translation functions. If the three entities can construct a valid Hoare triple, , we can find conditions and to construct a valid Qafny triple . When we translate to , we translate an individual quantum operation to a composition of HLIR operations. If we can construct a Hoare triple for the HLIR operations, we can also construct a Qafny triple for .
Now, we need to construct the relations between and and between and . When we translate to , we restrict their types to ; these types are based on the locus structures. Given , we can show that the types for and are also and , respectively. With the same program , we are able to show that and are semantically equivalent, as and .
Finally, we bound the size of the translation. Sizes are measured in the symbolic array representation used throughout Section 7: a dimension of length is a single bound expression and assertions quantify over index vectors, so a Hadamard operation on qubits adds one dimension (copyN, enumN, ampN) rather than elements.
THEOREM 7.15 (TRANSLATION SIZE). Let , , and , and let be the largest array dimension (the largest in an type) occurring in and . Then (i) contains at most eleven HLIR statements per Qafny statement of , so is linear in ; (ii) and are polynomial in and , respectively; (iii) for each HLIR statement, the Hoare proof-tree skeleton of Section 7 and Section A has size polynomial in the size of its pre- and post-conditions and in .
The theorem bounds the size of the generated verification conditions; it says nothing about the time a classical verifier needs to discharge them.
Proof. By cases on the translation of each Qafny statement. For (i), an oracle application translates to four statements (Lemma 7.1: locateN, mapN, assignN, and an assignment), a Hadamard or QFT application to four (Lemma 7.4), a quantum conditional to eleven plus the translation of its body (Lemma 7.9), and a measurement to seven (Lemma 7.11); sequencing and for-loops add no statements beyond those of their sub-statements (Section 7.5). For (ii), the translation of a state predicate maps each locus to one k-dimensional array, a quantifier over its index vector, and the basis-ket expression of q, whose size is linear in plus ; each predicate transformer in Section 7 substitutes one array expression of that size per occurrence of the array variable, so the translated assertions remain polynomial. For (iii), the skeleton of each primitive (Lemma 7.2 and Section A) consists of one loop per dimension whose invariant repeats the post-condition with a bounded index prefix, that is, copies of an assertion of polynomial size; copyN, enumN, ampN, locateN, and upDim are instances of mapN or assignN, sqrtSum is a classical sum, and the conditional and measurement skeletons compose a constant number of such steps.
8 Related Work
We discuss the related work below.
Quantum Proof Systems. Quantum proof systems include Qafny [Cheng et al. 2025; Li et al. 2024], QBricks [Chareton et al. 2021] based on the path-sum method [Amy 2019; Chareton et al. 2026], Quantum Hoare Logic (QHL) [Feng and Ying 2021; Liu et al. 2019; Ying 2012, 2019; Ying and Zhang 2026; Yu et al. 2026], quantum separation logic (QSL) [Le et al. 2022; Zhou et al. 2021], quantum relational logic [Li and Unruh 2021; Unruh 2019], and probabilistic Hoare logic for quantum programs [Kakutani 2009]. These proof systems are developed based on quantum program semantics and states, such as interpreting superoperators [Ying 2012] or Dirac notation [Chareton et al. 2021] as program-state syntax, whereas our work demonstrates the translation of a quantum proof system to the classical Hoare logic system.
The key difference between the quantum proof systems and our work is that we develop translation completeness and soundness theorems to show that quantum verification can be effectively done in Hoare logic, i.e., we compile proof rules in a quantum proof system to Hoare logic directly, and show the soundness and completeness based on the compilation. Moreover, the compilation is not specific to Qafny; we illustrate it for QHL as well. As mentioned in Section 5, there are also quantum separation logic proof systems [Le et al. 2022; Zhou et al. 2021] that view tensor products as a kind of separation conjunction, and we show that these separation conjunctions are pure.
Qafny in Dafny. Qafny [Cheng et al. 2025] compiles Qafny verification conditions into Dafny sequences and verifies 37 quantum programs with the Dafny verifier, but proves nothing about the compilation itself. Our translation targets an idealized Hoare logic with array theory, of which Dafny is one instance, and Theorems 7.13 and 7.14 are what justify trusting a Dafny verdict about a quantum program: nothing Qafny can prove is lost, and nothing false is certified. Beyond that foundation, this paper contains results that Qafny does not: the pureness of tensor-based separating conjunction (Section 5), the representation of an EN(n) state as an n-dimensional array with the index map ind (Section 6), the filter-and-renormalize treatment of measurement (Section 7.4), and the size bound (Theorem 7.15).
Symbolic Execution of Quantum Programs. Fang and Ying [2024] and Chareton et al. [2026] execute quantum programs symbolically, the former with symbolic stabilizer states for error-correction programs and the latter with hybrid path-sums for hybrid quantum programs, and decide properties of the symbolic state of a given program. These are engines; our contribution is meta-theoretic: a translation between two proof systems with guarantees in both directions (Theorems 7.13 and 7.14), with the completeness direction mechanized in Rocq, together with the pureness result of Section 5. We share the engine-level view that superposition should be represented symbolically. What the translation adds, and what a symbolic execution engine does not imply, is that the classical Hoare rules for arrays already suffice, and why: separating conjunction is pure, dynamic locus reordering is handled by an index map, and measurement is filter-and-renormalize. Classical Proof Systems. We are informed by Hoare and separation logic, as articulated in the classic paper [Gordon 2012; Reynolds 2002], and other papers as well [Itzhaky et al. 2021; Löding et al. 2017; Neider et al. 2018; Sammler et al. 2021; Ta et al. 2016; Zhan 2018]. Primarily, we show a compilation from Qafny to Hoare logic with array operators [Gordon 2012].
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
9 Conclusion, Future Work, and Limitations
We have shown that verifying a quantum program need be no harder than verifying a classical program, e.g., a parallel program: the Qafny proof system translates into Hoare logic with array theory completely and soundly, and the completeness direction is mechanized in Rocq. Three observations make the embedding tractable. First, Qafny's separation conjunctions over disjoint loci are pure and reduce to ordinary conjunctions. Second, an EN(n)-typed quantum state admits a faithful representation as an n-dimensional array of basis-kets. Third, the semantics of quantum operations, applied to that representation, factor through a small set of array-aggregate primitives, packaged here as the Hoare-logic intermediate representation HLIR. We also bound the size of the translation: in the symbolic array representation, the generated verification conditions are polynomial in the size of the Qafny triple and the array dimension.
The embedding is constructive: every Qafny proof rule maps to an explicit HLIR derivation, and every HLIR primitive is realized by a proof-tree skeleton in Hoare logic with array theory. Quantum proof obligations therefore become deterministic and can be discharged by classical automated verifiers (e.g. Dafny, SMT-based separation logic, natural-proof engines) with no quantum-specific infrastructure. Future work includes extending the embedding to richer quantum types (such as oracle and Hadamard variants), connecting HLIR to a concrete automated back-end for end-to-end verified quantum software, and investigating whether the same determination technique generalizes to other hybrid classical/quantum proof systems.
Our compilation only shows that quantum program verification is no harder than classical program verification, i.e., we do not claim that all quantum program verification is easy, as many quantum programs based on statistical methods, such as quantum machine learning [Biamonte et al. 2017], are hard to verify. However, we believe the same holds for classical program verification, as many classical AI and machine-learning-based programs are also hard to verify.
References
Matthew Amy. 2019. Towards Large-scale Functional Verification of Universal Quantum Circuits. Electronic Proceedings in Theoretical Computer Science 287 (Jan. 2019), 1–21. doi:10.4204/eptcs.287.1
Jacob Biamonte, Peter Wittek, Nicola Pancotti, Patrick Rebentrost, Nathan Wiebe, and Seth Lloyd. 2017. Quantum machine learning. Nature 549, 7671 (01 Sep 2017), 195–202. doi:10.1038/nature23474
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 - 30th European Symposium on Programming, ESOP 2021, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2021, Luxembourg City, Luxembourg, March 27 - April 1, 2021, Proceedings (Lecture Notes in Computer Science, Vol. 12648), Nobuko Yoshida (Ed.). Springer, 148–177. doi:10.1007/978-3-030-72019-3_6
Christophe Chareton, Jad Issa, Mathieu Nguyen, Nicolas Blanco, and Sébastien Bardin. 2026. Hybrid Path-Sums for Hybrid Quantum Programs. Proc. ACM Program. Lang. 10, PLDI, Article 236 (June 2026), 27 pages. doi:10.1145/3808314
Feifei Cheng, Sushen Vangeepuram, Henry Allard, Seyed Mohammad Reza Jafari, Alex Potanin, and Liyi Li. 2025. Embedding Quantum Program Verification into Dafny. Proc. ACM Program. Lang. 9, OOPSLA2, Article 379 (Oct. 2025), 27 pages. doi:10.1145/3763157
Paul Adrien Maurice Dirac. 1939. A new notation for quantum mechanics. Mathematical Proceedings of the Cambridge Philosophical Society 35 (1939), 416 – 418.
Wang Fang and Mingsheng Ying. 2024. Symbolic Execution for Quantum Error Correction Programs. Proc. ACM Program. Lang. 8, PLDI, Article 189 (June 2024), 26 pages. doi:10.1145/3656419
Yuan Feng and Mingsheng Ying. 2021. Quantum Hoare Logic with Classical Variables. ACM Transactions on Quantum Computing 2, 4, Article 16 (dec 2021), 43 pages. doi:10.1145/3456877
Mike Gordon. 2012. Background reading on Hoare Logic. https://www.cl.cam.ac.uk/archive/mjcg/HL/Notes/Notes.pdf
Daniel M. Greenberger, Michael A. Horne, and Anton Zeilinger. 1989. Going beyond Bell's Theorem. Springer Netherlands, Dordrecht, 69–72. doi:10.1007/978-94-017-0849-4_10
Kesha Hietala, Robert Rand, Shih-Han Hung, Xiaodi Wu, and Michael Hicks. 2021. A Verified Optimizer for Quantum Circuits. In Proceedings of the ACM Conference on Principles of Programming Languages (POPL).
C. A. R. Hoare. 1969. An axiomatic basis for computer programming. Commun. ACM 12, 10 (Oct. 1969), 576–580. doi:10.1145/363235.363259
Shachar Itzhaky, Hila Peleg, Nadia Polikarpova, Reuben N. S. Rowe, and Ilya Sergey. 2021. Cyclic Program Synthesis. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation (Virtual, Canada) (PLDI 2021). Association for Computing Machinery, New York, NY, USA, 944–959. doi:10.1145/3453483.3454087
Yoshihiko Kakutani. 2009. A Logic for Formal Verification of Quantum Programs. In Advances in Computer Science - ASIAN 2009. Information Security and Privacy, Anupam Datta (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 79–93.
Xuan-Bach Le, Shang-Wei Lin, Jun Sun, and David Sanan. 2022. A Quantum Interpretation of Separating Conjunction for Local Reasoning of Quantum Programs Based on Separation Logic. Proc. ACM Program. Lang. 6, POPL, Article 36 (jan 2022), 27 pages. doi:10.1145/3498697
Liyi Li, Finn Voichick, Kesha Hietala, Yuxiang Peng, Xiaodi Wu, and Michael Hicks. 2022. Verified Compilation of Quantum Oracles. In OOPSLA 2022. doi:10.48550/ARXIV.2112.06700
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 2024) (Leibniz International Proceedings in Informatics (LIPics), Vol. 313), Jonathan Aldrich and Guido Salvaneschi (Eds.). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 24:1–24:31. doi:10.4230/LIPics.ECOOP.2024.24
Yangjia Li and Dominique Unruh. 2021. Quantum Relational Hoare Logic with Expectations. In 48th International Colloquium on Automata, Languages, and Programming (ICALP 2021) (Leibniz International Proceedings in Informatics (LIPics), Vol. 198), Nikhil Bansal, Emanuela Merelli, and James Worrell (Eds.). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 136:1–136:20. doi:10.4230/LIPics.ICALP.2021.136
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, Isil Dillig and Serdar Tasiran (Eds.). Springer International Publishing, Cham, 187–207.
Christof Löding, P. Madhusudan, and Lucas Peña. 2017. Foundations for Natural Proofs and Quantifier Instantiation. Proc. ACM Program. Lang. 2, POPL, Article 10 (dec 2017), 30 pages. doi:10.1145/3158098
Daniel Neider, Pranav Garg, P. Madhusudan, Shambwaditya Saha, and Daejun Park. 2018. Invariant Synthesis for Incomplete Verification Engines. In Tools and Algorithms for the Construction and Analysis of Systems, Dirk Beyer and Marieke Huisman (Eds.). Springer International Publishing, Cham, 232–250.
Michael A. Nielsen and Isaac L. Chuang. 2011. Quantum Computation and Quantum Information (10th anniversary ed.). Cambridge University Press, USA.
J.C. Reynolds. 2002. Separation logic: a logic for shared mutable data structures. In Proceedings 17th Annual IEEE Symposium on Logic in Computer Science. 55–74. doi:10.1109/LICS.2002.1029817
Michael Sammler, Rodolphe Lepigre, Robbert Krebbers, Kayvan Memarian, Derek Dreyer, and Deepak Garg. 2021. RefinedC: Automating the Foundational Verification of C Code with Refined Ownership Types. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation (Virtual, Canada) (PLDI 2021). Association for Computing Machinery, New York, NY, USA, 158–174. doi:10.1145/3453483.3454036
Quang-Trung Ta, Ton Chanh Le, Siau-Cheng Khoo, and Wei-Ngan Chin. 2016. Automated Mutual Explicit Induction Proof in Separation Logic. doi:10.48550/ARXIV.1609.00919
Dominique Unruh. 2019. Quantum Relational Hoare Logic. Proc. ACM Program. Lang. 3, POPL, Article 33 (jan 2019), 31 pages. doi:10.1145/3290346
Qinshi Wang and Andrew W. Appel. 2023. A Solver for Arrays with Concatenation. J. Autom. Reason. 67, 1 (Jan. 2023), 31 pages. doi:10.1007/s10817-022-09654-y
Mingsheng Ying. 2012. Floyd–Hoare Logic for Quantum Programs. ACM Trans. Program. Lang. Syst. 33, 6, Article 19 (Jan. 2012), 49 pages. doi:10.1145/2049706.2049708
Mingsheng Ying. 2019. Toward Automatic Verification of Quantum Programs. Form. Asp. Comput. 31, 1 (feb 2019), 3–25. doi:10.1007/s00165-018-0465-3
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. 2024. Verification of Recursively Defined Quantum Circuits. arXiv:2404.05934 [quant-ph] https://arxiv.org/abs/2404.05934
Mingsheng Ying and Zhicheng Zhang. 2026. Verification of Recursively Defined Quantum Circuits. Proc. ACM Program. Lang. 10, PLDI, Article 195 (June 2026), 25 pages. doi:10.1145/3808273
Nengkun Yu, Jens Palsberg, and Thomas Reps. 2026. SAQR-QC: A Logic for Scalable but Approximate Quantitative Reasoning about Quantum Circuits. Proc. ACM Program. Lang. 10, PLDI, Article 206 (June 2026), 25 pages. doi:10.1145/3808284
Bohua Zhan. 2018. Efficient Verification of Imperative Programs Using Auto2. In Tools and Algorithms for the Construction and Analysis of Systems, Dirk Beyer and Marieke Huisman (Eds.). Springer International Publishing, Cham, 23–40.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
Li Zhou, Gilles Barthe, Justin Hsu, Mingsheng Ying, and Nengkun Yu. 2021. A Quantum Interpretation of Bunched Logic and Quantum Separation Logic. In Proceedings of the 36th Annual ACM/IEEE Symposium on Logic in Computer Science (Rome, Italy) (LICS '21). Association for Computing Machinery, New York, NY, USA, Article 75, 14 pages. doi:10.1109/LICS52264.2021.9470673
A Proof-Tree Derivations for the Translation Lemmas
This appendix collects the Hoare logic proof-tree derivations for the lemmas in Section 7; the main text keeps each lemma, its translated triple, and the reduction step, and points here for the derivation. In every derivation, the right-hand column names the Hoare rule applied at each step.
A.1 Proof Tree for mapN
We continue the proof of Lemma 7.2 (Section 7.1), showing the validity of the triple for obtained there via Lemma 2.1.
We expand to . The proof requires deriving a Hoare logic proof tree. We demonstrate the simplified proof sequences with loop invariants at each level. The right-hand side indicates the Hoare rules to apply.
Assign
Pre-Strength
while
While
Invariant
while
Invariant
}
...
}
}
Post-Weakening
A.2 Proof Tree for assignN
We demonstrate the proof-tree derivation for Lemma 7.3 (assignN) below, for the instance in which the amplitude is taken from ; the general case replaces by throughout.
PROOF. The proof requires a derivation of a Hoare logic proof tree, having a simplified proof sequence as follows. Mainly, we implement the assignN function as the program with assertions
We plan to upload a complete technical report to arXiv in lieu of appendices.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
below. Here, inserts 's bits into 's vector at the indices (via merge), and its proof is given in the Rocq mechanization.
Assign Pre-Strength while While Invariant { ... while Invariant { ; } ... } } Post-Weakening
A.3 Proof Tree for enumN
We continue the proof of Lemma 7.6 (Section 7.2), showing the validity of the triple obtained there via Lemma 2.1.
The proof tree is shown below. The pre-condition strengthening rules utilize the axioms for , , , , , , and , as they all have the same bounds .
let ;
There is a single enum function above. We show the enum function proof below.
LEMMA A.1 (A SINGLE ENUMERATION FUNCTION). Given a length n, we define a single enumeration function to generate an array A as the following valid Hoare triple.
Proof. The proof of the valid Hoare triple is given as follows.
We show the proof for a single ampMult function below.
☐
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
LEMMA A.2 (A SINGLE AMPLITUDE MULTIPLICATION FUNCTION). Given two bitstring arrays and , a collection of indices , and a complex number , we define a single amplitude multiplication function to compute a complex number below. is a dot product.
PROOF. We implement to be the program .
□
A.4 Proof Tree for Quantum Conditionals
We continue the proof of Lemma 7.9 (Section 7.3), using the array-length axioms and the concat/filterN axiom stated there.
let
; ; ; ; ; ; ; ;
Pre-Strength FilterN, Len FilterN, Len Pre-Strength LocateN Upper Pre-Strength Len, UpDim UpDim AssignN Concat Assign
A.5 Proof Tree for Quantum Measurement
We continue the proof of Lemma 7.11 (Section 7.4); as there, the judgments are omitted.
let and
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
Indexing
Indexing
FilterN
Pre-Strength
Len
LocateN
SqrtSum
MapN
Assign
B Transformation for QHL
We show below the transformation for quantum Hoare logic (QHL) augmented with classical variables. A chain of QHL work [Feng and Ying 2021; Ying 2026; Ying and Zhang 2024, 2026] combines classical variables with quantum data in a QHL proof rule. In this paper, we call this chain CQHL, and we describe the proof rule as follows.
The rule suggests that the execution of the program under a state described by the pre-condition results in a post-state described by the post-condition , where and are pre- and post-conditions on the classical state, while and are quantum data predicates written in the Dirac notation of a quantum datum.
CQHL distinguishes classical variables from quantum variables . Quantum variables can be single-qubit variables or quantum array variables . A quantum array variable can be written in the form where and are two indices in the array , i.e., we have and . Quantum array variables are indexed like classical arrays.
CQHL labels kets with quantum variable subscripts, e.g., refers to a basis-ket state in the qubit position and refers to a quantum datum in the quantum array .
We show an example proof triple for lines 1-3, based on the proof rule for quantum unitary operation above.
The triple applies a Hadamard operation. Here, we utilize the CQHL consequence rule to rewrite the bottom pre-condition to the upper one, where the inverse of H gate (H†) is H itself, and applying the H gate to yields .
Classical Arithmetic Expression
Boolean Expression
Unitary Operations
Program Expression
Fig. 7. CQHL Syntax.
The CQHL syntax is in Figure 7: skip ({}), quantum unitary application , sequencing, classical conditional (if then else fi), quantum conditional (qif fiq), classical assignment ( ), and function call ( ). In the language, and refer to classical arithmetic and Boolean expressions, respectively. Boolean expressions ( ) consist of Boolean values (true and false), equality ( ), negation ( ), and other operations.
A unitary operation is either a single-qubit gate (H or X) or a quantum oracle , which maps a quantum datum on to .
We define a valid program to have no free classical variables, , i.e., classical variables are all bound by a let-binding (let in ). In CQHL, a quantum variable refers to a single qubit and a quantum array to a group of qubits. The range of the array is written , where and are classical expressions.
To transform CQHL to classical Hoare logic, we first translate CQHL to Qafny and then apply the translation of Section 7 to the result.
We first translate a CQHL predicate to a Qafny state predicate. Here, is a classical predicate, which translates directly. In CQHL, the quantum predicate is written in Dirac notation as , where the qubit array variable gives the qubit locations of the state. We translate the predicate as follows.
To translate a CQHL program to Qafny, note that classical assignments, classical conditionals, function calls, and sequencing are classical operations and map directly to their Qafny counterparts. Only the two quantum operations, and qif fiq, need care.
The translation of depends on . If is an oracle operation, we translate it to the oracle operation of Qafny; if is the Hadamard gate , we translate it to the Hadamard operation of Qafny. Since together with oracle operations is universal, any other gate can be decomposed into a sequence of these two operations.
A CQHL quantum conditional qif fiq translates to a sequence of two Qafny quantum conditionals, as shown below.
Liyi Li, Zoukarneini Difaizi Tagba, and Alex Potanin
This completes the translation of CQHL to Qafny; the translation of Section 7 then takes the resulting Qafny triple to classical Hoare logic.