MINGSHENG YING, University of Technology Sydney, Australia
ZHICHENG ZHANG, Griffith University, Australia
KEAN CHEN, University of Pennsylvania, USA
In this paper, we introduce a notion of abstract quantum data type within the framework of universal algebra. This notion provides an algebraic foundation for describing data abstraction in quantum programming. We formally define a quantisation of classical data types and show that their equational specifications can be soundly lifted to the quantum setting. Two standard quantisation methods for classical functions, namely the bit oracle and the phase oracle, arise as special cases of this general construction. We illustrate the framework with applications to quantum arrays and quantum error-correcting codes, showing how they can be understood through the lens of data-type quantisation. We further establish conditions under which quantisation preserves structural relationships and constructions of classical data types, including embeddings, isomorphisms, and products.
CCS Concepts: • Software and its engineering → Abstract data types; • Theory of computation → Quantum computation theory.
Additional Key Words and Phrases: Quantum programming, abstract data types, universal algebra, quantisation, inheritance.
Quantum programming research has been conducted for more than 30 years, beginning with Knill's proposal of a set of conventions for writing quantum pseudocode [23], and it has become increasingly active in recent years [18, 39]. The majority of this research has focused on the algorithmic aspect of quantum programs. However, programming methodology must also study the structures, representations, and operations of data involved in large and complex programs [38]. To date, the data aspect of quantum programming has been less investigated.
1.1 Data types and data structures in quantum programming
Several basic quantum data types that abstract qubits and quantum registers are widely used in practical quantum programming languages, e.g. Qiskit [19], Q# [35], Cirq [6], Quipper [14], Guppy [24], Silq [3], Qrisp [32] and isQ [16]. Some more advanced quantum data types have been defined in theoretical research on quantum programming; for example, inductive quantum data types were introduced by Péchoux, Perdrix, Rennela and Zamdzhiev [31]. On the other hand, from the viewpoint of developer-friendly programming, a quantum programming language, Rhyme, with richer data types—including quantum extensions of floats, characters, arrays, and strings—was proposed by Varga, Aragonés-Soria and Oriol [36].
Various quantum data structures have been introduced for the design of quantum algorithms (see e.g. [1, 20, 21, 28, 37]). Yuan and Carbin's Tower [40] provides the first programming language support for data structures in quantum superposition, including using random-access memory and
Authors' addresses: Mingsheng Ying, Centre for Quantum Software and Information, University of Technology Sydney, Sydney, Australia, Mingsheng.Ying@uts.edu.au; Zhicheng Zhang, School of Information and Communication Technology, Griffith University, Brisbane, Australia, iszczhang@gmail.com; Kean Chen, Department of Computer and Information Science, University of Pennsylvania, Philadelphia, USA, keanchen.gan@gmail.com.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
recursive definitions of operations. A library of quantisations of data structures lists, stacks, queues, strings, and sets is programmed in Tower.
1.2 Data abstraction: from classical to quantum programming
Data abstraction is a foundational concept in classical programming that allows a programmer to focus on what an object does rather than how it does it. It is the process of hiding complex implementation details while exposing only the essential features of an object or data type. Thus, it allows developers to work with abstract data types (e.g. integers, arrays, or linked lists) without worrying about memory layout or hardware details [25, 26].
We believe that data abstraction will play an even more critical role in quantum programming [8, 30] for at least the following two reasons:
(1) Concepts such as superposition, entanglement, and measurement impose physical constraints that quantum data must respect but programmers may overlook or ignore. Therefore, data abstraction is essential for writing correct and scalable quantum software.
(2) Hardware independence is essential in quantum programming because quantum hardware is evolving rapidly. High-level abstractions allow quantum algorithms to be expressed without being tied to a specific quantum device or gate set. Compilers then map these abstract representations onto real hardware, optimising for noise, connectivity, and error rates.
Building upon previous work on quantum data structures [40] and quantum data types [36], we then naturally ask the following:
Question 1. How can we realise data abstraction in quantum programming?
1.3 Abstract data types
The introduction of abstract data types (ADTs) is a key way of realising data abstraction [17]. An ADT specifies a data type by focusing on what it does rather than how it is implemented, and thus the internal representation is hidden from the user. ADTs are defined from a user's viewpoint. In contrast, data structures are defined from an implementer's viewpoint as concrete representations of data. ADTs encourage programmers to think at a higher level of abstraction. The main advantages of ADTs include:
By separating the interface from the implementation, programmers can change how an ADT is implemented without affecting the rest of the program. For example, a stack ADT is defined by operations such as push, pop, and peek, regardless of whether it is implemented using an array or a linked list. This makes code easier to maintain, understand, and reuse.
ADTs support modularity so that users interact only through well-defined operations. This can significantly improve software reliability because errors caused by directly manipulating data are reduced.
Turning to the realm of quantum programming, Question 1 should be concretised to the following:
Question 2. How can we define abstract quantum data types? Is there a principled way to lift classical data types to the quantum setting—what one might call the quantisation of data types?
1.4 Contributions of this paper
The aim of this paper is to introduce a method for the quantisation of data types that supports data abstraction in quantum programming. The main difference between our work and previous studies [36, 40] is that our approach operates at the level of abstract data types, whereas [36, 40] focus on less abstract levels, such as data structures and concrete data types. The technical contributions of this paper are threefold:
(1) We formally define the notion of an abstract quantum data type within a universal-algebraic framework.
(2) We introduce a quantisation of classical ADTs and prove that their equational specifications can be soundly lifted to the quantum setting. This notion includes generalisations of two basic quantisation methods for classical functions as important special cases.
(3) We identify conditions ensuring that quantisation is compatible with structural relationships and constructions of classical data types, including embeddings, isomorphisms, and products.
We complement these results with illustrative applications to quantum arrays and quantum error correction.
We hope that the introduction of abstract quantum data types will help programmers design clean, flexible, and robust software systems for quantum computers. In particular, inheritance is a fundamental feature of object-oriented programming [5, 12], playing a crucial role in managing software complexity through mechanisms such as code reuse and hierarchical classification. The embedding result in Contribution (3) shows that certain algebraic inheritance relationships between classical data types can, under suitable conditions, be preserved under quantisation and transferred to their quantum counterparts.
1.5 Organisation of the paper
For the convenience of the reader, the basic concepts of ADTs are reviewed in Section 2. The notion of a quantum data type is introduced in Section 3, where several simple examples are also given to illustrate how quantum ADTs can be used in quantum programming. Section 4 develops a quantisation of classical ADTs and shows how equational specifications can be lifted to the quantum setting. It also presents two standard quantisation methods as special cases and explains their relationship through phase kickback. The framework is then illustrated through quantum arrays in Section 5 and quantum error correction in Section 6. Sections 7 and 8 investigate the structural properties of quantisation through embeddings and products, respectively. The paper concludes with a summary of the results and a brief discussion about topics for further research. The proofs of the main theorems and propositions are deferred to Appendix A.
2 ADTS IN CLASSICAL COMPUTING
In this section, we briefly review the basics of ADTs, following the textbook [9]. For more details, the reader can consult related chapters of [9].
A data type is a collection of data domains, designated basic data items, and operations on these domains. However, a programmer may not be interested in the concrete representation of a data type but only in its properties at an abstract level. Thus, the notion of ADT is introduced to specify the kinds of data that can be stored, the operations that can be performed on that data, and the rules those operations satisfy, independently of their concrete representation.
2.1 Basics of Universal Algebra
ADTs can be properly formalised in the mathematical language of universal algebra. A signature specifies the interface of an ADT. Formally, we have:
Definition 2.1 (Signatures). A signature is a pair Sig=(S,OP), where:
(1) S is a set of sorts;
(2) OP is a set of operation symbols. Each symbol O∈OP is assigned input sorts in(O)∈S∗ (the set of strings of elements in S, including the empty string ϵ) and an output sort out(O)∈S.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
We often write O:s1,…,sn→s for in(O)=s1,…,sn and out(O)=s. In particular, a constant symbol is an operation symbol c:↦s where the input sort in(c)=ϵ is empty.
Mathematically, a data type can then be modelled as an algebra as defined as follows:
Definition 2.2 (Algebras). An algebra A of a signature Sig=(S,OP), or a Sig-algebra for short, consists of:
(1) for each s∈S, As is a nonempty set, called the domain of sort s;
(2) for each O∈OP with O:s1,…,sn→s, OA is a mapping As1×⋯×Asn→As, called an operation. In particular, for each constant symbol c:↦s, cA is an element of As.
Throughout this paper, we only consider finite domains. The rules that the operations of an ADT must follow are usually specified as a family of equations. To define them, for each s∈S, we assume a set Xs of variables of sort s. The variable sets Xs are required to be pairwise disjoint and also disjoint from the operation symbols OP. Then we can introduce the following definition.
Definition 2.3 (Terms). The terms are recursively defined as follows:
(1) every constant symbol c:↦s and every variable x∈Xs are terms of sort s;
(2) if t1,…,tn are terms of sorts s1,…,sn, respectively, and O:s1,…,sn→s∈OP, then O(t1,…,tn) is a term of sort s.
A term without variables is called a ground term. The semantic interpretation of terms in a given algebra is presented through the notion of evaluation defined in the following:
Definition 2.4 (Evaluation). Let A be an Sig-algebra and σ an assignment in A that maps each variable x∈Xs to an element σ(x)∈As for every sort s. Then the evaluation evalσ(t) of a term t in assignment σ is recursively defined as follows:
(1) if t is a variable x, then evalσ(t)=σ(x), and if t is a constant c, then evalσ(t)=cA;
(2) if t=O(t1,…,tn), then evalσ(t)=OA(evalσ(t1),…,evalσ(tn)).
As noted above, a large class of the rules for the operations in an ADT can be described by equations between terms. The notion of equations can be formally defined in the following:
Definition 2.5 (Equations and Validity).
(1) Let t1 and t2 be two terms of the same sort s. If all variables occurring in t1 and t2 are among x1,…,xn, then
e=(∀x1:s1,…,xn:sn)(t1=t2)(1)
is called an equation, where xi is a variable of sort si for every i=1,…,n.
(2) The equation e is valid in an algebra A, or A satisfies e, written A⊨e, if for any assignment σ in A, we have evalσ(t1)=evalσ(t2).
It is easy to see that the validity of equation e only depends on the values σ(xi) (i=1,…,n) of assignments σ. In the specifications of ADTs in practical applications, universal quantifiers (∀x1:s1,…,xn:sn) in Equation (1) are often omitted (see Example 2.7).
If both t1 and t2 are ground terms, then e is called a ground equation. The validity of a ground equation e in an algebra does not depend on any assignment σ in A.
2.2 Specification of ADTs
Now we can use the algebraic framework defined in the previous subsection to specify ADTs.
Definition 2.6 (Specifications).
(1) A specification is a triple Spec=(S,OP,E), where Sig=(S,OP) is a signature, and E is a set of equations over the signature Sig.
(2) An algebra of the specification Spec, or Spec-algebra for short, is an algebra A of signature Sig such that A⊨e for every e∈E.
Besides the equational specifications defined above, there are more sophisticated classes of ADT specifications, such as Horn specifications. In this paper, we mainly consider equational specifications.
For a better understanding of the notions introduced above, let us see the following simple example:
Example 2.7 (Abstract data type of strings). A string is a sequence of basic data items from a given domain, called the alphabet. Let c1,…,cn be constant symbols denoting the basic data items. The most useful operations of strings in practical applications are:
make: it converts each basic data item into a string of length 1;
concat: it concatenates two strings;
ladd, radd: they add a basic data item to the left and right ends of a string, respectively.
Let Aalphabet={a1,…,an} be a domain for the alphabet. Let Astring=(Aalphabet)∗ be the set of strings of elements in Aalphabet, including the empty string ϵ.
For constant symbols, define ciA=ai for i=1,…,n and emptyA=ϵ.
For nonconstant operation symbols, define
(1) makeA:Aalphabet→Astring,makeA(a)=a for all a∈Aalphabet;
(2) concatA:Astring×Astring→Astring,concatA(u,v)=uv for all u,v∈Astring;
(3) laddA:Aalphabet×Astring→Astring,laddA(a,u)=au for all a∈Aalphabet and u∈Astring;
(4) raddA:Astring×Aalphabet→Astring,raddA(u,a)=ua for all a∈Aalphabet and u∈Astring.
It is easy to check that the above operations satisfy the equations in STRING, and hence A is a STRING-algebra.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
3 QUANTUM DATA TYPES
From now on, we generalise the algebraic specification techniques for classical ADTs into quantum computing. In this section, we formally define quantum data types in the universal-algebraic framework, analogously to their classical counterparts in Section 2, and illustrate it with some simple examples.
3.1 Basic Definitions
Let us first introduce the notion of a quantum signature as the quantum counterpart of Definition 2.1:
Definition 3.1 (Quantum Signatures). A quantum signature is a triple QSig=(Sq,K,U), where:
(1) Sq is a set of quantum sorts;
(2) K is a set of quantum state symbols. Each symbol ∣ψ⟩∈K is assigned sort sort(∣ψ⟩)∈Sq+ (the set of nonempty strings of elements in Sq);
(3) U is a set of quantum gate symbols. Each symbol U∈U is assigned sort sort(U)∈Sq+;
Roughly speaking, K and U correspond to the constant symbols and operation symbols in Definition 2.1, respectively. But there are some subtle differences between them and their classical counterparts. For a classical constant symbol c:→s, its input sort is empty and its output sort is a single sort s∈S. However, for a quantum state symbol ∣ψ⟩, it is possible that sort(∣ψ⟩)=s1,…,sn∈Sq+ with n>1. The reason is that ∣ψ⟩ may denote an entangled state between n subsystems, which cannot be decomposed into a string of the states of individual subsystems. We often write ∣ψ⟩:s1,…,sn for sort(∣ψ⟩)=s1,…,sn. Moreover, for a classical operation symbol O:s1,…,sn→s, the input sorts s1,…,sn and the output sort s need not coincide. In contrast, the input and output sorts of a quantum gate symbol U must be the same because it denotes a unitary operator. We write U:s1,…,sn for sort(U)=s1,…,sn. Indeed, sort(U) is both the input sort and output sort of U.
As the quantum counterparts of algebras described in Definition 2.2, quantum algebras are then defined by taking the domains of sorts to be Hilbert spaces and interpreting quantum state symbols and quantum gate symbols as pure quantum states and unitary operators, respectively.
Definition 3.2 (Quantum Algebras). A quantum algebra A of signature QSig=(Sq,K,U) consists of:
(1) for each s∈Sq, HsA is a Hilbert space, called the quantum domain of sort s (the superscript A of HsA is often omitted for simplicity);
(2) for each quantum state symbol ∣ψ⟩∈K with sort(∣ψ⟩)=s1,…,sn, ∣ψ⟩A is a unit vector (i.e. a pure quantum state) in Hs1⊗⋯⊗Hsn; and
(3) for each quantum gate symbol U∈U with sort(U)=s1,…,sn, UA is a unitary operator (i.e. a quantum gate) on Hs1⊗⋯⊗Hsn.
In this paper, we only consider quantum algebras where state symbols are interpreted as pure states and gate symbols as unitary operators. Of course, Definition 3.2 can be generalized such that state symbols are interpreted as mixed states (i.e. density operators) and gate symbols as noisy quantum gates (i.e. quantum channels) when needed in applications.
Given a quantum signature QSig, we assume a set Q of quantum variables. Each q∈Q is assigned a sort sort(q)∈Sq. For a string qˉ=q1,…,qn of quantum variables, we define sort(qˉ)=sˉ=s1,…,sn, where si=sort(qi). When the context is clear, we also use qˉ to denote the set {q1,…,qn}. Then the notion of term is generalised to the quantum case as follows:
Definition 3.3 (Quantum Circuit Formulas and Terms).
(1) Quantum circuit formulas C and their quantum variables qv(C) are inductively defined as follows:
(a) if U:s1,…,sn is a quantum gate symbol and q=q1,…,qn is a string of distinct quantum variables with sort(qi)=si for i=1,…,n, then C=U[q] is a quantum circuit formula, and qv(C)=q;
(b) if C1 and C2 are quantum circuit formulas, then C=C1;C2 is a quantum circuit formula, and qv(C)=qv(C1)∪qv(C2).
(2) Suppose C is a quantum circuit formula. For i=1,…,n, let ∣ψi⟩:si be a quantum state symbol and qi be a string of distinct quantum variables with sort(qi)=si and qi∩qj=∅ for i=j. Then τ=C∣ψ1⟩q1…∣ψn⟩qn is a quantum term, and qv(τ)=q1∪…∪qn∪qv(C). When the context is clear, ∣ψ⟩q may be used to denote the string ∣ψ1⟩q1…∣ψn⟩qn of quantum state symbols, where q=q1,…,qn. Define the set of free variables in quantum term τ to be fv(τ)=qv(τ)∖q.
The definition of quantum terms above differs slightly from its classical counterpart in Definition 2.3. Obviously, a quantum circuit formula C stands for a (combinational) quantum circuit constructed from quantum gates denoted by elements of U applied to quantum variables in Q. Furthermore, a quantum term C∣ψ1⟩q1…∣ψn⟩qn stands for a quantum circuit formula C with quantum variables q=q1,…,qn initialised in the state ∣ψ1⟩…∣ψn⟩, where each ∣ψi⟩ can be entangled. Conversely, a quantum circuit formula C can be seen as a quantum term with q=∅. A string of quantum state symbols ∣ψ⟩q=∣ψ1⟩q1…∣ψn⟩qn can also be seen as a quantum term with empty C.
Given an algebra A of a quantum signature QSig, for any subset Q′⊆Q of quantum variables, we write:
HQ′=q∈Q′⨂Hsort(q)
for the Hilbert space of the composite system Q′. Then an assignment of quantum variables in Q′ can be understood as a quantum state ∣φ⟩∈HQ′, although there is a basic difference between it and an assignment of classical variables; that is, the values of two classical variables are independent, but ∣φ⟩ could contain entanglement. Furthermore, the notion of evaluation can be generalised straightforwardly to the quantum case. As usual, for a unitary operator U, we implicitly identify it with its extension U⊗1 by censoring with an identity operator 1.
Definition 3.4 (Evaluation).
(1) Let C be a quantum circuit formula. Then its evaluation eval(C) in algebra A is a unitary operator on Hqv(C) recursively defined as follows:
(a) if C=U[q] for some U∈U, then eval(C)=UqA (unitary operator UA acting on the quantum system denoted by q);
(b) if C=C1;C2, then eval(C1;C2)=eval(C2)∘eval(C1) is a composition of unitary operators.
(2) Let τ=C∣ψ1⟩q1…∣ψn⟩qn be a quantum term. Suppose q=q1,…,qn and r is a string of quantum variables such that r⊇fv(τ) and r∩q=∅. Let ∣φ⟩ be a quantum state in Hr. Then the evaluation of τ in state ∣φ⟩ is defined as the quantum state:
The notion of equation can be smoothly generalised to the quantum setting too:
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
Definition 3.5 (Equations). Let τ1=C1∣ψ1⟩q1 and τ2=C2∣ψ2⟩q2 be two quantum terms that satisfy q1∩fν(τ2)=q2∩fν(τ1)=∅. Suppose r=fν(τ1)∪fν(τ2) and sort(r)=s. Then, for p⊆qν(τ1)∩qν(τ2),
e=(∀r:s)(τ1=τ2)⇓p(3)
is called an equation, and p are called the principal variables of e. In particular, if p=qν(τ1)∩qν(τ2), then ⇓p can be dropped from Equation (3).
Similar to the case of classical equations, universal quantifiers ( ∀r:s) in Equation (3) are often omitted in practical specifications of quantum ADTs (see Example 3.8 and Proposition 5.1).
It is worth examining carefully the differences between classical Equation (1) and quantum Equation (3). First, we notice that in terms τ1 and τ2, quantum variables q1 and q2 are already initialised, but r are not. Thus, Equation (3) means that the equality between τ1 and τ2 is valid for all possible input states of r. Second, an input state ∣φ⟩r of r=r1,…,rn may be entangled. Third, the evaluation of τ1 (resp. τ2) gives an output state ∣ψ1⟩ (resp. ∣ψ2⟩) of multiple quantum variables, but one may only be interested in a subset p of them. Thus, the variables in p are designated as the principal variables. Consequently, to define the validity of equations in a quantum algebra, we need the notion of a reduced density operator. For a quantum state ∣ψ⟩ in Hilbert space Hp⊗Hp, the restriction of ∣ψ⟩ onto p is defined as the reduced density operator
∣ψ⟩↓p=trp′(∣ψ⟩⟨ψ∣)
where trp′ stands for the partial trace over subsystem p′ (see Section 2.4.3 of [29] for its precise definition). Intuitively, ∣ψ⟩↓p describes the state of subsystem p when the whole system p⊎p′ is in state ∣ψ⟩. With this preparation, we are able to introduce:
Definition 3.6 (Validity). The equation e given in Equation (3) is valid in algebra A, written A⊨e, if for any quantum state ∣φ⟩∈Hr, we have:
eval∣φ⟩(τ1)↓p=eval∣φ⟩(τ2)↓p.
3.2 Specification of Quantum Data Types
As one may expect, the algebraic framework developed in the previous subsection can be used to specify ADTs in quantum computing. The following definition is a straightforward generalisation of Definition 2.6.
Definition 3.7 (Quantum Specification).
(1) A quantum specification is a quadruple QSpec=(Sq,K,U,E), where QSig=(Sq,K,U) is a quantum signature, and E is a set of equations of the form in Equation (3).
(2) A QSpec-algebra is a quantum algebra A of signature QSig such that A⊨e for every e∈E.
For a better understanding of quantum ADTs, let us first see the following simple example:
Example 3.8 (Abstract data type of qubits). Consider the following quantum specification:
Let HqbitA=H2 be the 2-dimensional Hilbert space.
For quantum state symbols, define ∣b⟩A=∣b⟩ for b∈{0,1},∣±⟩A=21(∣0⟩±∣1⟩), and ∣βab⟩A=21(∣0⟩∣b⟩+(−1)a∣1⟩∣1−b⟩) for a,b∈{0,1}.
• For quantum gate symbols, define
NOTA=X,HA=H,CNOTA=CNOT,
where X, H, and CNOT are the Pauli X, Hadamard, and controlled-NOT gates, respectively. It is easy to check that A satisfies all equations in QBIT, and hence A is a QBIT-algebra.
3.3 A Simple Application Example: Programming Quantum Query Algorithms
Quantum query algorithms. To further understand the role of ADTs in quantum computing, let us consider a large class of quantum algorithms, namely quantum query algorithms. Let qw and qo be two disjoint strings of qubits of lengths lw and lo, called the work qubits and output qubits, respectively. Suppose we are given a quantum oracle O, which is a black-box unitary operator. Then a quantum query algorithm [2] with queries to O is usually described as a quantum circuit:
C=UTOUT−1⋯U2OU1OU0
where Ut (t=0,1,…,T) are quantum gates independent of O. The circuit C is initialised in state ∣0⟩qw∣0⟩qo. Then the algorithm outputs x (a bit string) with probability
Prob(x)=∥⟨x∣qoC∣0⟩qw∣0⟩qo∥2.
Oracles as ADTs. Oracle synthesis functionality has already been integrated into quantum programming platforms like Qiskit [19] and Q# [35]. Ideally, a programmer does not need to know the implementation details of the oracle O when programming the quantum query algorithm. Instead, it can be viewed through the lens of ADTs. Consider a quantum specification (Sq,K,U,E), where qbit∈Sq,O∈U, and sort(O)=qbit,…,qbit. The equations in E may specify properties that
the oracle O should satisfy without fixing its implementation details. In this way, the quantum
where q=qw∪qo and M is the measurement in the computational basis of qo.
4 QUANTISATION OF DATA TYPES
The abstract notion of quantum ADTs was introduced in Section 3. In practical applications, a quantum ADT does not stand alone; rather, it often arises as an extension of a corresponding classical ADT. An application scenario is that, when developing a quantum program, the programmer realises that they need to apply a function, or more generally an ADT, that does not comply with certain constraints (e.g., non-unitarity) imposed by quantum mechanics. In such cases, the function or ADT must be quantised, and what the programmer actually invokes in the program is its quantisation. A typical example is a quantum oracle (see Section 3.3), which is often lifted from a black-box classical function. So, in this section, we consider how a classical data type defined in Section 2 can be extended to a quantum data type introduced in Section 3. We call this extension process quantisation.
In this section, we make the following conventions. Given a classical signature, for each sort s, we assume a designated constant symbol 0s:=s. Given a quantum signature, for any sort s, we assume a designated quantum state symbol ∣0s⟩:s. For a string s=s1,…,sn of sorts, the quantum state ∣0s⟩A in a given algebra A is then ∣0s1⟩A⊗…⊗∣0sn⟩A. When the context is clear, we omit the subscript s and use ∣0⟩ to abbreviate ∣0⟩…∣0⟩. These designated symbols are implicitly assumed to be included in the signatures discussed below. Given an algebra A of a signature, for each sort s, we assume that As is finite and there is a designated bijection
ksA:As→Z∣As∣,ksA(0sA)=0(4)
where for a positive integer m, Zm={0,1,...,m−1}. Intuitively, bijection ks(a) gives the default integer label for every element a∈As; that is, we use ks to enumerate all elements of As.
Let us first consider how a classical signature can be quantised to a quantum signature.
Definition 4.1 (Quantisation of signature). Let Sig=(S,OP) be a signature and QSig=(Sq,K,U) a quantum signature. A quantisation from Sig to QSig is a mapping η such that
(1) each sort s∈S is mapped to sq=η(s);
(2) each constant symbol c:→s is mapped to a quantum state symbol ∣ψc⟩=η(c) of sort sq. We additionally require η(0s)=∣0sq⟩; and
(3) each nonconstant operation symbol O:s1,…,sn→s is mapped to a triple of quantum gate symbols (UO,preO,postO)=η(O), where sort(UO)=sort(preO)=sort(postO)∈Sq+ is a string of sorts in one of the following forms:
• (in-place) s1q,…,snq,sa for some sa∈Sq∗, with sq=siq for some i;
• (out-of-place) s1q,…,snq,sq,sa for some sa∈Sq∗.
(4) In the above, the mappings s↦sq, c↦∣ψc⟩, and O↦UO are injective.
We need to carefully explain the above condition (3). For a nonconstant operation O, it is natural to expect its quantisation lifts its behaviour on classical data to the quantum setting. However, there are multiple ways to represent classical data as quantum data, e.g., encoding into computational-basis quantum states, encoding into relative phases, encoding into quantum amplitudes. Concrete examples can be found in Sections 4.1, 4.2, 5 and 6. Therefore, the quantum gate symbols preO and postO in η(O) serve for the representation of classical data in the quantum world, while UO serves for the lifted O in the quantum world. In particular, the quantum gate symbol preO (resp. postO) corresponds to how classical data is preprocessed into (resp. postprocessed from) quantum data. Then, UO corresponds to the quantisation of O that has quantum input and output. Their concrete interpretations in an algebra is given later. The injectivity of O↦UO in condition (4) means UO is unique for each O, but preO and postO can be the same for different O.
For convenience, if an operation symbol O is quantised in the in-place form, we assume the index i for sq=siq is implicitly fixed and used consistently in the other quantisation notions. The string sa of sorts represents ancilla sorts needed for the quantised operation.
Next, we consider how an algebra can be quantised along the quantisation of the signature.
Definition 4.2 (Quantisation of algebra). Let η be a quantisation from Sig to QSig. Then a quantum algebra A of signature QSig is a quantisation of an algebra A of signature Sig along η if:
(1) for each sort s∈S, {∣a⟩∣a∈As} forms an orthonormal basis of HsqA;
(2) for each constant symbol c↦s, ∣ψc⟩A=∣cA⟩. In particular, ∣0sq⟩A=∣0sA⟩; and
(3) for each nonconstant operation symbol O:s1,…,sn→s, and for all a1∈As1,…,an∈Asn, we have:
Here, the subsystems involved in quantum states and gates are implicitly assumed to be ordered according to sort (UO). In particular,
(in-place) ∣0⟩ denotes ∣0sa⟩A, and ∣OA(a1,…,an)⟩ is a state in HsiqA, where i is the fixed index in Definition 4.1; and
(out-of-place) ∣0⟩ denotes ∣0sq,sa⟩A, and ∣OA(a1,…,an)⟩ is a state in HsqA.
Intuitively, in Equation (5), preOA converts a computational-basis input (the default quantum representation of classical data) into a quantum input for UOA, and postOA converts the quantum output of UOA into a computational-basis output. The condition in Equation (5) says that, under the preprocessing preOA and postprocessing postOA, the behaviour of UOA agrees with OA on all classical inputs (with probability 1), so UOA quantises OA. In Sections 4.1, 4.2, 5 and 6, we will present illustrative examples, where the utility of the preprocessing preO and postprocessing postO becomes more concrete.
It remains to consider how a classical specification can be quantised. To this end, we need to introduce a quantisation of classical terms.
Definition 4.3 (Quantisation of terms). Let η be a quantisation from Sig to QSig. Suppose QSig contains a quantum gate symbol SUMs:sq,sq for each sort s in Sig, where sq=η(s). Let t be a term in Sig. For each variable x:s occurring in t, designate a distinct quantum variable qx:sq.
The quantisation η(t) is defined recursively as follows:
(1) If t=c↦s is a constant symbol, choose a fresh variable p:sq as the principal variable and define η(t)=∣ψc⟩p, where ∣ψc⟩=η(c);
(2) If t=x is a variable of sort s, choose a fresh variable q:sq as the principal variable and define η(t)=SUMs[qx,q]∣0⟩q; and
(3) Suppose t=O(t1,…,tn) is a term of sort s and η(ti)=Ci∣ψi⟩ for i=1,…,n, where each η(tj) has principal variable pj of sort sjq. Let p=p1,…,pn. By renaming variables
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
if necessary, assume that, apart from the designated qx, all other quantum variables in η(t1),…,η(tn) are distinct.
(in-place) sort( r) = sa and pi is chosen to be the principal variable, where i is the fixed index in Definition 4.1;
(out-of-place) sort( r) = sq,sa and r=r0,ra, where r0 is chosen to be the principal variable.
In Definition 4.3, note that the same qx is used for every occurrence of variable x in t. In clause (2) of this definition, the design η(t)=SUMs[qx,q]∣0⟩q is subtle and needs to be carefully explained. Intuitively, if the gate symbol SUM is interpreted properly in an algebra, SUMs[qx,q]∣0⟩q copies the computational-basis state of quantum variable qx to q, which is initialised in state ∣0⟩q. It has two purposes. First, copying in the computational basis reversibly handles the multiple occurrences of variable x in term t, where qx is used to store the input of x and each fresh q corresponds to a single occurrence of x. Second, since qx are not chosen to be principal variables, tracing out qx at the end “dephases” each corresponding q in the computational basis. This is important for the correctness of Theorem 4.5, when we transition from a classical equation with a universal quantifier (∀x) over classical inputs to a quantum equation with quantifier (∀q) over quantum inputs.
With quantisations of classical terms, we can further define quantisations of equations in a classical specification.
Definition 4.4 (Quantisation of equations). Let η be a quantisation from Sig to QSig, and let e=(x:s)(t1=t2) be a classical equation, where x=x1,…,xn is a string of all variables occurring in t1 or t2. We assume that the designated variables q=qx1,…,qxn (see Definition 4.3) in t1 and t2 are aligned, and η(t1) and η(t2) have the same principal variable, say p. Then, the quantisation η(e) of e along η is defined as follows:
η(e)=(∀q:sq)(η(t1)=η(t2))⇓p,
where sq is the quantisation of s.
With the above preparation, we are able to present the main result of this section, which describes a way of deriving a specification of a quantised ADT by lifting from the classical specification. To describe this lifting, for a,b∈As, we define
a⊕sAb=(ksA)−1(ksA(a)+ksA(b)mod∣As∣)(6)
where ksA is given in equation (4). Intuitively, the operator ⊕sA naturally extends the binary XOR ⊕ operator up to the bijection ksA. In particular, in Equation (6), the inputs a,b are mapped to the integer domain Z∣As∣, added in Z∣As∣, and then mapped back to the domain As. It is easy to verify that a⊕s0sA=0sA⊕sAa=a for any a. When the algebra A is clear, we simply write ks and ⊕s for ksA and ⊕sA, respectively.
THEOREM 4.5 (LIFTING OF SPECIFICATION). Let Spec=(Sig,E) be a classical specification, and let η be a quantisation from Sig to QSig. Suppose QSig contains a quantum gate symbol SUMs:sq,sq for each sort s in Sig, where sq=η(s). We define QSpec=(QSig,η(E)), where η(E)={η(e)∣equatione∈E}. If
(1) A is an algebra of Spec; and
(2) A is a quantisation of A along η and SUMsA:∣a⟩∣b⟩↦∣a⟩∣a⊕sb⟩ for any sort s and any a,b∈As,
then A is a quantum algebra of QSpec.
Here, corresponding to the discussion below Definition 4.3, the unitary operator SUMsA:∣a⟩∣b⟩↦∣a⟩∣a⊕sb⟩ is a canonical way to realise the copying in the computational basis when b=0. The proof of Theorem 4.5 is deferred to Appendix A.
The above definitions of quantisation are general. In the following subsections, we examine two specific quantisation methods that appear commonly in quantum algorithm design.
4.1 Bit Oracle Quantisation
The first quantisation method is bit oracle quantisation (BO-quantisation for short). The BO-quantisation of a classical algebra is defined as follows.
Definition 4.6 (BO-quantisation). Let η be a quantisation from Sig to QSig and A be a Sig-algebra. Then, a quantisation A of A along η is a BO-quantisation if for each nonconstant operation symbol O:s1,…,sn→s:
It is easy to check that UOA defined in equation (7) indeed satisfies the condition (5). When QSig includes the gate symbol SUMs for each sort s, the BO-quantisation of terms and equations can be naturally induced by Definition 4.6, according to Definitions 4.1 and 4.4.
Definition 4.6 naturally yields the common bit oracle in quantum algorithms as follows, where the designated kbit is the identity and ⊕bit reduces to XOR.
Example 4.7. Consider the following
• Signature Sig = (S, OP) with S={bit} and OP={0bit,f}, where 0bit:=bit and f:bitbit,…,bit→bit.
• Algebra A of signature Sig with Abit={0,1} and 0bitA=0, where fA:{0,1}n→{0,1} is a n-ary Boolean function.
Then the following gives a BO-quantisation of A:
• Signature QSig=(Sq,K,U) with Sq={qbit}, K={∣0qbit⟩}, and U={Uf,pref,postf}, where ∣0qbit⟩:qbit and Uf,pref,postf:qbit,…,qbit.
• Algebra A of signature QSig: HqbitA=C2,∣0qbit⟩A=∣0⟩, prefA=postfA=1, and
UfA∣x,b⟩=∣x,b⊕fA(x)⟩(8)
for any x∈{0,1}n and b∈{0,1}.
In this example, the unitary operator UfA is often known as the bit oracle or standard oracle used by a quantum algorithm to query a black-box function f. The bit oracle has been employed in the design of many quantum algorithms, e.g., the Deutsch-Jozsa algorithm [7] and the modular exponentiation subroutine of Shor's algorithm [34]. It should be noted that on the RHS of Equation (8),
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
the first n qubits are used to record the input x, and the last qubit is used to store the computational outcome f(x). In this way, Uf is made invertible and thus a unitary operator.
4.2 Phase Oracle Quantisation
The second quantisation method is phase oracle quantisation (PO-quantisation for short). The PO-quantisation of a classical algebra is defined as follows.
Definition 4.8 (PO-quantisation). Let η be a quantisation from Sig to QSig and A be a Sig-algebra. Then, a quantisation A of A along η is a PO-quantisation if for each nonconstant operation symbol O:s1,…,sn→s:
(1) UO is out-of-place with sa=∅.
(2) preOA=1s1q,…,snq⊗QFT∣As∣ and postOA=1s1q,…,snq⊗QFT∣As∣†, where QFT∣As∣ is the quantum Fourier transform on Z∣As∣ defined by
It is also easy to check that UOA defined in equation (9) satisfies the condition (5). When QSig includes the gate symbol SUMs for each sort s, the PO-quantisation of terms and equations can be naturally induced by Definition 4.8, according to Definitions 4.1 and 4.4.
Definition 4.8 naturally yields the common phase oracle (or more accurately, the controlled version of the common phase oracle) in quantum algorithms, where the designated kbit is the identity, ω=−1 and QFT2=H is the Hadamard operator.
Example 4.9. Consider the same signature Sig and algebra A as in Example 4.7. Then, the following gives a PO-quantisation of A:
• Signature QSig=(Sq,K,U): Sq={qbit}, K={∣0qbit⟩}, and U={Uf,pref,postf}, where ∣0qbit⟩: qbit and Uf,pref,postf: n+1qbit,…,qbit
• Algebra A of signature QSig: HqbitA=C2,∣0qbit⟩A=∣0⟩, prefA=postfA=1n⊗H, and
UfA∣x,b⟩=(−1)b⋅fA(x)∣x,b⟩
for any x∈{0,1}n and b∈{0,1}.
In this example, Uf is often known as the (controlled) phase oracle for a quantum algorithm to query a black-box function f. The phase oracle has been applied in Grover's search [15], amplitude amplification [4], and several other quantum algorithms.
4.3 Phase Kickback Trick
In quantum algorithms, the phase kickback trick provides a useful connection between a bit oracle and a phase oracle, and now we can view it through the lens of ADTs. For example, in the Deutsch-Jozsa algorithm that decides whether a given Boolean function f:{0,1}n→{0,1} is constant or balanced, the bit oracle Uf is defined by
Uf∣x,y⟩=∣x,y⊕f(x)⟩
for any x∈{0,1}n and y∈{0,1}. A key idea in this algorithm is that the target register is initialised in the superposition ∣¬⟩=21(∣0⟩−∣1⟩). We observe:
Uf∣x,−⟩=∣x⟩⊗(−1)f(x)∣−⟩=(−1)f(x)∣x⟩⊗∣−⟩.(10)
In the final expression above, the phase (−1)f(x) appears in front of the quantum state. On the other hand, if the target register is initialised in ∣+⟩=21(∣0⟩+∣1⟩), then
Uf∣x,+⟩=∣x⟩⊗∣+⟩.(11)
Combining Equations (10) and (11) gives
(1n⊗H)Uf(1n⊗H)∣x,b⟩=(−1)b⋅f(x)∣x,b⟩.(12)
More generally, the phase kickback implies a correspondence between BO-quantisation and PO-quantisation. Suppose η is a quantisation from Sig to QSig. Let A and B be BO- and PO-quantisations of the same algebra A along η, respectively. For each sort s in Sig, suppose that A and B have the same quantum domain
HsqA=HsqB=span{∣a⟩:a∈As}.
Then, analogous to Equation (12), for any operation O:s1,…,sn→s, we have:
This means that BO-quantisation and PO-quantisation can be related by changing how classical data are encoded into quantum data through preO and postO.
5 ILLUSTRATIVE APPLICATION I: QUANTUM ARRAYS
Arrays are a fundamental data type widely used in classical programming. To illustrate the framework developed in Sections 3 and 4, we show how quantum arrays can be defined via the quantisation of classical arrays. In particular, this approach offers a new perspective for understanding Quantum Random Access Memories (QRAMs) [10, 11].
5.1 Classical Arrays
For convenience of the reader, let us recall the basic theory of arrays. First, we describe the signature Sig=(S,OP) of the ADT of arrays. Let I be a set of index sorts and V a set of value sorts, so that S=I∪V. The value sorts and their dimensions are generated as follows:
(1) val∈V is a primitive value sort, and dim(val)=0;
(2) if I∈I and τ∈V, then array(I,τ)∈V, and dim(array(I,τ))=dim(τ)+1.
A canonical algebra A of Sig gives the following interpretation. For every I∈I and τ∈V, define
Aarray(I,τ)=AI→Aτ.
Consequently, if
τ=array(I1,array(I2,…,array(In,val)…)),
then
Aτ=AI1→(AI2→⋯→(AIn→Aval)⋯).
Equivalently, Aτ=(AI1×⋯×AIn)→Aval.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
For the operation symbols, let OP contain two classes of symbols:
where I∈I and τ∈V. They are also called selector and store operations, respectively. For simplicity, the subscripts I,τ of readI,τ and writeI,τ will often be omitted. In the canonical algebra A, they are interpreted as follows:
readI,τA:(a,j)↦a[j]writeI,τA:(a,j,v)↦a′(15)
for a∈Aarray(I,τ), j∈AI, and v∈Aτ, where a′[i]=a[i] if i=j and a′[j]=v. Intuitively, read(a,j) denotes the value stored in array a at index j, and write(a,j,v) denotes the array obtained by updating a with value v stored at index j.
We assume countably many variables and constants of each sort. The terms are constructed from variables and constants using operation symbols, and their sorts are defined in the usual way. A basic theory of arrays was first introduced by McCarthy [27], where the functions read and write are characterised by the following axioms. For every I∈I and τ∈V:
It should be pointed out that, essentially, the above two axioms do not constitute an equational specification as in Definition 2.6. Instead, they are formulated in a first-order logical language. However, they are easy to understand for our purposes.
5.2 Quantum Arrays
Now let us examine quantum arrays through the lens of the quantisation of the classical ADT of arrays (see Section 4). Suppose QSig=(Sq,K,U) is the quantum signature obtained from a quantisation η of the classical signature for arrays. For I∈I and τ∈V, write
Iq=η(I),τq=η(τ),qarray(Iq,τq)=η(array(I,τ)).
In particular, write qval=η(val). Then
Sq=Iq∪Vq,Iq={η(I):I∈I},Vq={η(τ):τ∈V}.
Let A be the canonical algebra for the signature of classical arrays considered previously. We consider the following quantised algebra A of A along η. We define:
(1) HqvalA=span{∣v⟩:v∈Aval};
(2) for every I∈I, HIqA=span{∣j⟩:j∈AI}; and
(3) for every τ∈V, HτqA=span{∣t⟩:t∈Aτ}. Furthermore, for every I∈I and τ∈V,
(16) where we denote ∣a⟩=⨂j∈AI∣a[j]⟩, and the indices j are ordered by keeping the designated kI(j) increasing (see Section 4). By expanding the RHS of Equation (16) recursively, if
τ=array(I1,array(I2,…,array(In,val)…)),
then
HτqA=(j1,…,jn)∈AI1×⋯×AIn⨂HqvalA.
Next, we explain how the read and write symbols in OP are quantised to gate symbols in U. As in Section 4, for each I∈I and τ∈V, we assume that the designated 0 satisfies 0array(I,τ)A[j]=0τA for any j∈AI. Let kI and kτ be the designated bijections for AI and Aτ, respectively. We recursively choose the designated bijection for the corresponding array sort to be
karray(I,τ)(a)=j∈AI∑∣Aτ∣kI(j)⋅kτ(a[j]).(17)
For the concrete one-dimensional QRAM examples below, fix an index sort idx∈I and write
Quantum read. The operation readI,τA can be quantised in the same way as the BO-quantisation in Definition 4.6:
(1) Uread, preread, and postread have the sort qarray (Iq,τq), Iq,τq.
(2) prereadA=postreadA=1.
(3) UreadA∣a⟩∣j⟩∣v⟩=∣a⟩∣j⟩∣v⊕τa[j]⟩ for any a∈Aarray(I,τ), j∈AI, and v∈Aτ.
We simply use qread to denote the gate Uread for convenience.
What qreadA effectively implements is a QRAM read operation. Consider the case when Aidx=ZN, Aval=ZM, and their designated bijections are the identity maps. Then, an array a of sort array stores N classical values a[0], a[1], …, a[N−1] from Aval at addresses 0,1,…,N−1. In classical computing, RAM (Random Access Memory) allows one to access a memory cell by providing an address. In QRAM (Quantum Random Access Memory), the key idea is that the address itself can be in a quantum superposition. This means one can query many memory locations simultaneously in superposition. A QRAM read implements the following transformation:
which is an instantiation of qreadA. So, in one operation, we can “load” data from multiple addresses coherently.
Quantum write. The operation writeI,τA can be quantised in-place as follows:
• Uwrite, prewrite, and postwrite have the sort qarray (Iq,τq), Iq,τq.
• prewriteA=postwriteA=1.
• UwriteA∣a⟩∣j⟩∣v⟩=∣a′⟩∣j⟩∣a[j]⟩ for any a∈Aarray(I,τ), j∈AI, and v∈Aτ, where a′[i]=a[i] if i=j and a′[j]=v.
We simply use qwrite to denote the gate Uwrite for convenience.
What qwriteA effectively implements is a QRAM swap operation. Again, consider the case when Aidx=ZN, Aval=ZM, and their designated bijections are the identity maps. Then, an array a of
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
sort array stores N classical values a[0],a[1],…,a[N−1] from Aval at addresses 0,1,…,N−1. A QRAM swap implements the following transformation:
Therefore, in one operation, qwrite can “write” data to multiple addresses coherently.
According to Theorem 4.5, by properly reexpressing Axiom 1 and Axiom 2 using equations we can derive specifications for the ADT of quantum arrays. Beyond that, quantum arrays actually satisfy extra properties. The following proposition shows that quantum array operations qread and qwrite satisfy an equation similar to the first part of the Axiom 1 for classical array operations read and write. This property is specified as a quantum equation (see Definition 3.5). Suppose that for each sort s in Sig, SUMs:sq,sq is a gate symbol in QSig and SUMsR∣a⟩∣b⟩=∣a⟩∣a⊕sb⟩ for any a,b∈As.
PROPOSITION 5.1. The algebra of quantum arrays with gates qread and qwrite satisfies the following specification:
However, a natural quantum analogue of Axiom 2 is not true. Let us consider the simplest case when Aidx=Aval=Z2. Even if we restrict attention to the principal variable, the equation
(qread[qa,qi,qv]∣Φ⟩=qread[qa,qi,qv]∣Ψ⟩)⇓qv
does not imply ∣Φ⟩=∣Ψ⟩, because the state of a composite quantum system is not uniquely determined by the states of its subsystems, which is indeed one of the fundamental differences between classical and quantum systems.
Quantum error correction is fundamental to fault-tolerant quantum computing [13, 22]. To further illustrate the framework developed in Sections 3 and 4, we show how a quantum error-correcting code can be described as a quantisation of a classical error-correcting code. In particular, we first consider the quantisation of a classical 3-bit repetition code and then show how its 9-bit extension gives rise to the Shor code.
6.1 Classical Repetition Code
We first describe a classical repetition code as an ADT. Consider the signature Sig=(S,OP), where S={lbit,pbit,idx,array}, lbit and pbit denote sorts of logical bits and physical bits, respectively. Following Section 5.1, idx is an index sort, and array=array(idx,pbit) is the sort for an array of physical bits. For simplicity, consider the canonical algebra A of Sig for the 3-bit repetition code. It gives:
where a′[j]=a[j] if j=i and a′[i]=a[i]⊕1. Intuitively, enc(x) is the code word that encodes x by repeating it three times, flip(a,i) flips the physical bit a[i] in the array a, and corr(a) produces a code word by replacing every entry of a with maj(a). Then, the algebra A satisfies the following equations:
The first equation states that corr leaves a code word unchanged. The second equation states that it recovers the code word after a bit flip on any physical bit.
6.2 Quantum Repetition Code
Now let us show the 3-qubit repetition code as a quantisation of the classical 3-bit repetition code. Suppose QSig=(Sq,K,U) is the quantum signature obtained from a quantisation η of the classical signature Sig in Section 6.1. Let
Here, ∣⊥⟩ is the designated ∣0qsyn⟩, which is a computational-basis state orthogonal to ∣0⟩, ∣1⟩, ∣2⟩. As in Section 5, we denote ∣a⟩=∣a[0],a[1],a[2]⟩. In particular, the designated ∣0qarray⟩=∣0,0,0⟩. We choose the designated functions k1bit, kpbit, and kidx to be identity functions, and define karray as in Equation (17).
Next, we explain how the operation symbols enc, flip, and corr are quantised to gate symbols in U.
Quantum encoding. The operation encA can be quantised out-of-place as follows:
(1) Uenc,preenc, and postenc have sort lqbit, qarray.
(2) preencA=postencA=1.
(3) UencA∣x⟩∣0,0,0⟩=∣0⟩∣x,x,x⟩ for any x∈Abit.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
We simply use qenc to denote the gate Uenc for convenience.
Compared with the classical enc in Section 6.1, the gate qenc encodes ∣x⟩ as ∣x,x,x⟩ in the computational basis and resets the logical bit to ∣0⟩. Note that when the logical qubit is initially in superposition, the physical qubits become entangled.
Quantum flip. The operation flipA can be quantised in-place as follows:
(1) Uflip, preflip, and postflip have sort qarray, qidx.
(2) preflipA=postflipA=1.
(3) UflipA∣a⟩∣i⟩=∣flipA(a,i)⟩∣i⟩ for any a∈Aarray and i∈Aidx.
As usual, we simply use qflip to denote the gate Uflip for convenience.
Note that qflip implements the classical operation flip in the computational basis. It leaves the index unchanged and applies a Pauli X gate to the physical qubit indexed by i.
Quantum correction. The operation corrA can be quantised in-place as follows:
(1) Ucorr, precorr, and postcorr have sort qarray, qsyn.
(2) precorrA=postcorrA=1.
(3) UcorrA∣a⟩∣⊥⟩=∣corrA(a)⟩∣syn(a)⟩ for any a∈Aarray, where
As usual, we simply use qcorr to denote the gate Ucorr for convenience.
Intuitively, qcorr implements the classical corr in the computational basis and produces the syndrome syn(a). In the computational basis, when a is a code word, the syndrome is ⊥; otherwise, it is the index of the unique physical bit that differs from maj(a), which is the error location when a is obtained from a bit-flip on a code word. Note that qcorr coherently performs the syndrome extraction and error correction together.
According to Theorem 4.5, the equations in Equation (21) can be lifted to a specification of the quantum repetition code. Here, we give a direct specification that the quantum repetition code corrects a single Pauli X error.
PROPOSITION 6.1. The quantum algebra A with gates qenc, qflip, and qcorr satisfies the following specification:
The first equation states that qcorr leaves a quantum code word unchanged. The second equation states that it recovers the quantum code word after qflip introduces a Pauli X error on any physical qubit. In both equations, qa is the only principal variable.
6.3 Shor Code
The 3-qubit quantum repetition code in Section 6.2 can only correct a Pauli X error. Inspired by the repetition code, the Shor code [33] is the first quantum error-correcting code that can correct an arbitrary single-qubit error. Let us examine the 9-qubit Shor code as a quantisation of a 9-bit repetition code. We reuse the classical signature Sig in Section 6.1 with slight modifications: the operation symbol flip in Section 6.1 is replaced by two operation symbols flipX, flipZ : array, idx → array of the same sort.
Consider the canonical algebra B for a 9-bit repetition code. It gives
Intuitively, the 9 physical bits of a are split into three groups, where the rth group consists of a[3r],a[3r+1],a[3r+2]. The value m(a)[r] is the majority of the rth group, while maj(a) is the majority of m(a)[0],m(a)[1],m(a)[2].
In the algebra B, the operations are interpreted as
where x∈Blbit, a∈Barray, and i,j∈Bidx. Here, although both flipX and flipZ are interpreted as a bit flip error in algebra B, their quantisations will correspond to different quantum errors later.
Similar to the algebra A for the 3-bit repetition code (see Section 6.1), the algebra B satisfies
As usual, we denote ∣a⟩=∣a[0],…,a[8]⟩. In particular, the designated state ∣0qarray⟩=∣0⟩⊗9. For a single-qubit unitary operator U, let Ui=1⊗i⊗U⊗1⊗(8−i), which applies U on the qubit indexed by i. The designated functions kbit, kpbit, kidx, and karray are chosen as in Section 6.2.
Next, we explain how the operation symbols enc, flipX, flipZ, and corr are quantised to gate symbols in U.
Quantum encoding. For x∈{0,1}, let
∣Ψx⟩=(2∣000⟩+(−1)x∣111⟩)⊗3.(26)
The operation encB can be quantised out-of-place as follows:
(1) Uenc, preenc, and postenc have sort lqbit, qarray.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
(2) preencB=1, and postencB∣0⟩∣Ψx⟩=∣0⟩∣encB(x)⟩ for any x∈B1bit.
(3) UencB∣x⟩∣0⟩⊗9=∣0⟩∣Ψx⟩ for any x∈B1bit.
We simply use qenc to denote the gate Uenc for convenience.
Compared with Section 6.2, the gate qenc here encodes the computational-basis ∣x⟩ into a Shor code word ∣Ψx⟩. If the logical qubit is initially in superposition, the physical qubits are in the corresponding superposition of ∣Ψ0⟩ and ∣Ψ1⟩.
Quantum flip. The operations flip XB and flip ZB can be quantised in-place as follows:
(1) UflipX,UflipZ,preflipX,preflipZ,postflipX,andpostflipZ have sort qarray, qidx.
(2) preflipXB=postflipXB=1 and preflipZB=postflipZB=(∏i=08Hi)⊗1,
(3) UflipXB=∑i=08Xi⊗∣i⟩⟨i∣ and UflipZB=∑i=08Zi⊗∣i⟩⟨i∣.
We simply use qflipX and qflipZ to denote the gates UflipX and UflipZ, respectively, for convenience.
The gates qflipX and qflipZ leave the index ∣i⟩ unchanged and apply Pauli X and Z gates, respectively, on the physical qubit indexed by i. Thus, they introduce the corresponding Pauli errors.
Quantum correction. For a∈Barray, we define syn(a)∈{0,1,2,⊥}4 as follows. For r∈{0,1,2},
Intuitively, syn(a) is the syndrome produced for an arbitrary a. For each r∈{0,1,2}, if there is an entry in the rth group of a that differs from m(a)[r], then syn(a)[r] records the index of this entry; otherwise, it records ⊥. Similarly, if an entry m(a)[r] differs from maj(a), then syn(a)[3] records the index r; otherwise, it records ⊥. Consequently, it is easy to check that a↦(maj(a),syn(a)) is a bijection.
For P∈{1,X,Y,Z}, i=3r+t, and k∈{0,1,2,3}, where r,t∈{0,1,2}, let us define σ(P,i)∈{0,1,2,⊥}4 by
Intuitively, σ(P,i) is the syndrome needed to correct the Pauli error Pi. Suppose we start with a Shor code word. A Pauli X error changes one physical qubit, so its syndrome records the information about i=3r+t. A Pauli Z error on any of the three physical qubits in the same group r has the same effect, so its syndrome only records the r. A Pauli Y error combines X and Z, so its syndrome contains both kinds of information.
Let {∣Φx,s⟩:x∈{0,1},s∈{0,1,2,⊥}4} be an orthonormal basis of HqarrayB such that
Φx,σ(P,i)⟩=Pi∣Ψx⟩(28)
for x∈B1bit, P∈{1,X,Y,Z}, and i∈Bidx. The existence of such a basis is proved in Lemma A.2. Here, in ∣Φx,s⟩, x records the logical bit and s records the syndrome.
The operation corrB can be quantised in-place as follows:
(1) Ucorr, precorr, and postcorr have sort qarray, qsyn.
We simply use qcorr to denote the gate Ucorr for convenience.
Intuitively, precorr implements the bijection a↦(maj(a),syn(a)) by mapping ∣a⟩ to ∣Φmaj(a),syn(a)⟩, while leaving the initial syndrome in qs unchanged. The quantum gate qcorr maps ∣Φx,s⟩ to the corrected Shor code word ∣Ψx⟩ and records the syndrome in qs. Finally, postcorr maps ∣Ψx⟩ to the computational-basis repetition code word ∣encB(x)⟩.
As in Section 5, we can derive specifications for the Shor code by lifting Equation (21) using Theorem 4.5. Beyond that, the Shor code actually satisfies stronger error-correction properties. The following equations specify that the Shor code corrects a single Pauli X, Z, or Y error.
PROPOSITION 6.2. The quantum algebra B with gates qenc, qflipX, qflipZ, and qcorr satisfies the following specification:
The first equation states that qcorr leaves an error-free Shor code word unchanged. The second and third equations state that qcorr recovers the code word after a Pauli X or Z error, respectively. The fourth equation covers a Pauli Y error through sequential application of qflipX and qflipZ. In all equations, qa is the only principal variable. Following the standard quantum error-correction argument, being able to correct Pauli X, Y, Z errors means that the Shor code corrects an arbitrary single-qubit error.
7 EMBEDDINGS OF QUANTUM DATA TYPES
So far, we have only considered the quantisation of individual ADTs. In classical computing, various relationships between different ADTs have been exploited for practical applications in software engineering. In particular, an embedding allows values of one ADT to be represented as values of another while preserving the relevant operations and semantics. Consequently, embeddings between ADTs can be used for applications such as data refinement and software component reuse. To enable these kinds of applications for quantum ADTs, in this section we ask under what conditions quantisation preserves structural relationships between algebras. In classical universal algebra, an embedding faithfully maps one algebra into another while preserving all operations. This section investigates when such an embedding lifts to an embedding between the corresponding quantum algebras.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
Definition 7.1 (Homomorphisms of algebras). Let A and A′ be two algebras of signature Sig=(S,OP). Then:
(1) A homomorphism from A to A′ is a family g=(gs)s∈S of mappings gs:As→As′ such that for each operation symbol O:s1,…,sn→s, and for all a1∈As1,…,an∈Asn, it holds that
(2) If all gs are injective, then g is called an embedding.
(3) If all gs are bijective, then g is called an isomorphism.
Let H and H′ be two Hilbert spaces. A linear operator T:H→H′ is called an isometric embedding if
⟨T(x)∣T(y)⟩H′=⟨x∣y⟩H
for all x,y∈H, where ⟨⋅∣⋅⟩H, ⟨⋅∣⋅⟩H′ denote the inner products in H and H′, respectively. It is easy to see that T is injective and norm-preserving:
∥T(x)∥H′=∥x∥H
for every x∈H, and the image T(H) is a closed subspace of H′.
Definition 7.2 (Embeddings between quantum algebras). Let A and A′ be two quantum algebras of signature Sigq=(Sq,K,U). Then an embedding from A to A′ is a family G=(Gs)s∈Sq of isometric embeddings Gs:Hs→Hs′ such that
(1) for each quantum state symbol ∣ψ⟩∈K of sort s1,…,sn, it holds that
(Gs1⊗⋯⊗Gsn)(∣ψ⟩A)=∣ψ⟩A′;(33)
(2) for each quantum gate symbol U∈U of sort s1,…,sn, and for any ∣φ⟩∈⨂i=1nHsi,
Since Gs1,…,Gsn are all isometric embeddings, H′=△(Gs1⊗⋯⊗Gsn)(⨂i=1nHsi) is a closed subspace of ⨂i=1nHsi′. Moreover, Gs1⊗⋯⊗Gsn:⨂i=1nHsi→H′ and its inverse (Gs1⊗⋯⊗Gsn)†:H′→⨂i=1nHsi are unitary operators. Thus, the condition in Equation (34) can be rewritten as:
UA=(Gs1⊗⋯⊗Gsn)†∘UA′∘(Gs1⊗⋯⊗Gsn)
. If all Gs are unitary operators, then G is called an isomorphism. In this case, Gs(Hs)=Hs′ for every s∈Sq, and H′=⨂i=1nHsi′.
In the remainder of this section, we give conditions under which an embedding of algebras induces an embedding of their quantisations.
7.1 Embeddings of Quantisations
Let A and A′ be two algebras of the same signature Sig=(S,OP), and let g=(gs)s∈S:A→A′ be an embedding. Let η be a quantisation from Sig to QSig=(Sq,K,U) that satisfies Sq=η(S). Let A and A′ be quantisations of A and A′ along η, respectively.
Recall that the quantisation of s∈S is sq∈Sq along η. For each s∈S, we define Gsq:HsqA→HsqA′ to be the linear operator that satisfies the following condition:
Gsq(∣a⟩)=∣gs(a)⟩foreverya∈As.(35)
We call G=(Gsq)s∈S the quantisation of g=(gs)s∈S along η. Since each gs is injective, {∣gs(a)⟩:a∈As} is an orthonormal set, which means each Gsq is an isometric embedding. If g is further an isomorphism, then each Gsq is a unitary.
For concreteness, we consider BO- and PO-quantisations in Section 4. For each s∈S, let ksA:As→Z∣As∣ and ksA′:As′→Z∣As′∣ be the two designated bijections as in Section 4, and let ⊕sA and ⊕sA′ be defined as in Section 4.
We first examine when a BO-quantisation can be embedded into another.
PROPOSITION 7.3 (EMBEDDINGS OF BO-QUANTISATIONS). Suppose that every state symbol in K is introduced by η, and that every gate symbol in U is introduced by η. Let A and A′ be BO-quantisations of A and A′, respectively, along η. If for each s∈S and a,b∈As,
gs(a⊕sAb)=gs(a)⊕sA′gs(b),
or equivalently, the following diagram commutes:
As×As⊕sAAsgs×gs↓↓gsAs′×As′⊕sA′As′
then G in Equation (35) is an embedding from A to A′.
Next, we examine when a PO-quantisation is isomorphic to another. Unlike the BO-quantisations, compatibility with the quantum Fourier transform in Definition 4.8 forces every gs to be surjective. Consequently, the corresponding result for PO-quantisations is stated only for isomorphisms.
PROPOSITION 7.4 (ISOMORPHISMS OF PO-QUANTISATIONS). Suppose that every state symbol in K is introduced by η, and that every gate symbol in U is introduced by η. Suppose g is an isomorphism. Let A and A′ be PO-quantisations of A and A′, respectively, along η. If for each s∈S,
ksA′∘gs=ksA,
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
or equivalently, the following diagram commutes (noting that ∣As∣=∣As′∣):
AsksAZ∣As∣↓As′ksA′Z∣As′∣
then G in Equation (35) is an isomorphism from A to A′.
8 PRODUCTS OF QUANTUM DATA TYPES
Embeddings discussed in the last section describe one of the simplest structural relationships between quantum ADTs. We now turn to how to construct a new quantum ADT from simpler ones. In classical computing, products of ADTs enable us to compose independently specified abstractions while preserving their interfaces and invariants, and they find applications in composite data structures, modular software composition, and other settings. To introduce the same capability into quantum software engineering, in this section we define the notion of the product of ADTs. At the classical level, the domains of two algebras are combined using Cartesian products. At the quantum level, the corresponding quantum domains are combined using tensor products. Furthermore, we present the conditions under which these products are compatible with the quantisations of ADTs.
Definition 8.1. Let A and B be two algebras of signature Sig=(S,OP). Then their product is defined as the algebra C=A×B of the same signature Sig satisfying the following conditions:
(1) for each sort s∈S, Cs=As×Bs (Cartesian product);
(2) for each operation symbol O:s1,…,sn→s, OC is defined as follows: for any ai∈Asi and bi∈Bsi ( i=1,…,n),
for any ∣αi⟩∈HsiA and ∣βi⟩∈HsiB ( i=1,…,n) together with linear extension.
Definition 8.2. Let A and B be two quantum algebras of signature QSig=(Sq,K,U). Then their product is defined as the quantum algebra C=A⊗B of the same signature QSig satisfying the following conditions:
(1) for each sort s∈Sq, HsC=HsA⊗HsB (tensor product);
(2) for each quantum state symbol ∣ψ⟩∈K of sort s1,…,sn, ∣ψ⟩C=Ts1,…,sn−1(∣ψ⟩A⊗∣ψ⟩B);
(3) for each quantum gate symbol U∈U of sort s1,…,sn,
UC=Ts1,…,sn−1∘(UA⊗UB)∘Ts1,…,sn
(38) is a unitary operator on ⨂i=1nHsiC=⨂i=1n(HsiA⊗HsiB), where UA⊗UB is defined by
for any ∣αi⟩∈HsiA and ∣βi⟩∈HsiB ( i=1,…,n) and extending linearly. Equivalently, Equation (38) can be expressed by the following commutative diagram:
Let A and B be two algebras of the same signature Sig=(S,OP), and let C=A×B. Suppose η is a quantisation from Sig to QSig that satisfies Sq=η(S). Suppose that A,B, and C are quantisations of A,B, and C, respectively, along η.
Recall that the quantisation of s∈S is sq∈Sq along η. For each s∈S, we define Jsq:HsqC→HsqA⊗HsqB to be a linear operator that satisfies the following condition:
Jsq∣(a,b)⟩=∣a⟩⊗∣b⟩(40)
for every a∈As and b∈Bs. Note that Jsq is a unitary. Let J=(Jsq)s∈S.
For concreteness, we consider when a BO-quantisation (and PO-quantisation) is compatible with products. For each D∈{A,B,C} and s∈S, let ksD:Ds→Z∣Ds∣ be the designated bijection, and let ⊕sD be defined as in Section 4.
PROPOSITION 8.3 (PRODUCTS OF BO-QUANTISATIONS). Suppose that every state symbol in K is introduced by η, and that every gate symbol in U is introduced by η. Let A,B, and C be BO-quantisations of A,B, and C=A×B, respectively, along the same quantisation η. If
(a,b)⊕sC(a′,b′)=(a⊕sAa′,b⊕sBb′)(41)
for any s∈S, a,a′∈As, and b,b′∈Bs, then J in Equation (40) is an isomorphism from C to A⊗B.
PROPOSITION 8.4 (PRODUCTS OF PO-QUANTISATIONS). Suppose that every state symbol in K is introduced by η, and that every gate symbol in U is introduced by η. Let A,B, and C be PO-quantisations of A,B, and C=A×B, respectively, along the same quantisation η. If
for any s∈S, a,a′∈As, and b,b′∈Bs, then J is an isomorphism from C to A⊗B.
9 CONCLUSION
This paper developed a universal-algebraic framework for data abstraction in quantum programming. We formally defined the notion of abstract quantum data types and a quantisation of classical data types and proved that their equational specifications can be soundly lifted to their quantisations. Generalised bit-oracle and phase-oracle quantisations arise as instances of this construction and are related through phase kickback. Further, the examples of quantum arrays, the three-qubit
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
repetition code, and the nine-qubit Shor code illustrate how quantum data and operations can be organised and specified within the framework. We also established conditions under which data type quantisation preserves embeddings, isomorphisms, and products.
As a first step toward introducing data abstraction into quantum programming, in this paper, we examine only two typical forms of quantisation, namely bit oracles and phase oracles. One can expect that more forms of quantisation will emerge in the development of future quantum algorithms and programs. We also consider only purely quantum abstract data types in this paper. In practical applications, quantum and classical data are often involved in the same program, and measurement outcomes of quantum data are stored as classical data that subsequently participate in classical computations. This observation suggests another interesting topic for future research: classical-quantum hybrid abstract data types.
We can expect that data abstraction in quantum programming enables programmers to reason about complex quantum behaviour in a manageable way as in classical programming. By hiding mathematical and physical complexity while enforcing quantum constraints, abstraction makes quantum software development more accessible, safer, and more scalable. As quantum computing matures, well-designed abstractions will be crucial for bridging the gap between theoretical algorithms and practical implementations.
ACKNOWLEDGMENTS
This work was supported in part by the Australian Research Council under Grant DP250102952.
REFERENCES
[1] Andris Ambainis. 2007. Quantum walk algorithm for element distinctness. SIAM J. Comput. 37 (2007), 210–239.
[2] Andris Ambainis. 2018. Understanding quantum algorithms via query complexity. In Proceedings of the International Congress of Mathematicians (ICM). 3265–3285.
[3] Benjamin Bichsel, Maximilian Baader, Timon Gehr, and Martin Vechev. 2020. Silq: a high-level quantum language with safe uncomputation and intuitive semantics. In Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). 286–300.
[4] Gilles Brassard, Peter Høyer, Michele Mosca, and Alain Tapp. 2002. Quantum amplitude amplification and estimation. In Quantum Computation and Information. Contemporary Mathematics, Vol. 305. 53–74.
[5] Luca Cardelli and Peter Wegner. 1985. On understanding types, data abstraction, and polymorphism. Comput. Surveys 17, 4 (1985), 471–523.
[7] David Deutsch and Richard Jozsa. 1992. Rapid solution of problems by quantum computation. Proceedings of the Royal Society of London A 439 (1992), 553–558.
[8] Olivia Di Matteo. 2025. The art of abstraction in quantum software. In 2025 IEEE/ACM International Workshop on Quantum Software Engineering (Q-SE). 25–26.
[9] Hartmut Ehrig and Bernd Mahr. 1985. Fundamentals of Algebraic Specification 1: Equations and Initial Semantics. Springer.
[10] Vittorio Giovannetti, Seth Lloyd, and Lorenzo Maccone. 2008. Architectures for a quantum random access memory. Physical Review A 78, Article 052310 (2008).
[11] Vittorio Giovannetti, Seth Lloyd, and Lorenzo Maccone. 2008. Quantum random access memory. Physical Review Letters 100, Article 160501 (2008).
[12] Joseph A. Goguen and José Meseguer. 1992. Order-sorted algebra I: equational deduction for multiple inheritance, overloading, exceptions and partial operations. Theoretical Computer Science 105 (1992), 217–273.
[13] Daniel Gottesman. 2024. Surviving as a quantum computer in a classical world. Textbook manuscript preprint.
[14] Alexander S. Green, Peter LeFanu Lumsdaine, Neil J. Ross, Peter Selinger, and Benoit Valiron. 2013. Quipper: a scalable quantum programming language. In Proceedings of the 34th ACM Conference on Programming Language Design and Implementation (PLDI). 333–342.
[15] 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.
[16] Jingzhe Guo, Huazhe Lou, Jintao Yu, Riling Li, Wang Fang, Junyi Liu, Peixun Long, Shenggang Ying, and Mingsheng Ying. 2023. isQ: An Integrated Software Stack for Quantum Programming. IEEE Transactions on Quantum Engineering
4, Article 2500116 (2023), 16 pages.
[17] John V. Guttag. 1977. Abstract data types and the development of data structures. Commun. ACM 20, 6 (1977), 396–404.
[18] Bettina Heim, Mathias Soeken, Sarah Marshall, Chris Granade, Martin Roetteler, Alan Geller, Matthias Troyer, and Krysta Svore. 2020. Quantum programming languages. Nature Reviews Physics 2 (2020), 709–722.
[19] Ali Javadi-Abhari, Matthew Treinish, Kevin Krsulich, Christopher J. Wood, Jake Lishman, Julien Gacon, Simon Martiel, Paul D. Nation, Lev S. Bishop, Andrew W. Cross, Blake R. Johnson, and Jay M. Gambetta. 2024. Quantum computing with Qiskit. arXiv:2405.08810 [quant-ph]
[20] Stacey Jeffery, Robin Kothari, and Frédéric Magniez. 2013. Nested quantum walks with quantum data structures. In Proceedings of the 24th Annual ACM-SIAM symposium on Discrete algorithms (SODA). 1474–1485.
[21] Ce Jin and Jakob Nogler. 2023. Quantum speed-ups for string synchronizing sets, longest common substring, and k-mismatch matching. In Proceedings of the 34th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA). 5090–5121.
[22] Emanuel Knill and Raymond Laflamme. 1997. Theory of quantum error-correcting codes. Physical Review A 55 (1997), 900–911.
[23] Emanuel H. Knill. 1996. Conventions for quantum pseudo-code. Technical Report. Los Alamos National Laboratory.
[24] Mark Koch, Alan Lawrence, Kartik Singhal, Seyon Sivarajah, and Ross Duncan. 2025. GUPPY: Pythonic quantum-classical programming. arXiv:2510.12582
[25] Barbara Liskov. 1987. Data abstraction and hierarchy. ACM SIGPLAN Notices 23, 5 (1987), 17–34.
[26] Barbara Liskov and Stephen Zilles. 1974. Programming with abstract data types. ACM SIGPLAN Notices 9, 4 (1974), 50–59.
[27] John McCarthy. 1962. Towards a mathematical science of computation. In IFIP Congress 62.
[28] Aran Nayebi, Scott Aaronson, Aleksandrs Belovs, and Luca Trevisan. 2015. Quantum lower bound for inverting a permutation with advice. Quantum Information & Computation 15 (2015), 901–913.
[29] Michael A. Nielsen and Isaac L. Chuang. 2000. Quantum Computation and Quantum Information. Cambridge University Press.
[30] Santiago Núñez-Corrales, Olivia Di Matteo, John Dumbell, Marcus Edwards, Edoardo Giusto, Scott Pakin, and Vlad Stirbu. 2025. Productive quantum programming needs better abstract machines. In 2025 IEEE International Conference on Quantum Computing and Engineering (QCE). 816–826.
[31] Romain Péchoux, Simon Perdrix, Mathys Rennela, and Vladimir Zamdzhiev. 2020. Quantum programming with inductive datatypes: causality and affine type theory. In Proceedings of the 23rd International Conference on Foundations of Software Science and Computation Structures (FoSSaCS). 562–581.
[32] Raphael Seidel, Sebastian Bock, René Zander, Matic Petrič, Niklas Steinmann, Nikolay Tcholtchev, and Manfred Hauswirth. 2024. Qrisp: a framework for compilable high-level programming of gate-based quantum computers. arXiv:2406.14792
[33] Peter W. Shor. 1995. Scheme for reducing decoherence in quantum computer memory. Physical Review A 52 (1995), R2493–R2496.
[34] Peter W. Shor. 1997. Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM J. Comput. 26 (1997), 1484–1509.
[35] Krysta Svore, Alan Geller, Matthias Troyer, John Azariah, Christopher Granade, Bettina Heim, Vadym Kliuchnikov, Mariia Mykhailova, Andres Paz, and Martin Roetteler. 2018. Q#: enabling scalable quantum computing and development with a high-level DSL. In Proceedings of the Real World Domain Specific Languages Workshop (RWSDL). Article 7, 10 pages.
[36] Tamás Varga, Yaiza Aragonés-Soria, and Manuel Oriol. 2024. Quantum types: going beyond qubits and quantum gates. In Proceedings of the 5th ACM/IEEE International Workshop on Quantum Software Engineering (Q-SE). 49–52.
[37] Qisheng Wang, Zhean Xu, and Zhicheng Zhang. 2026. Quantum data structure for range minimum query. J. Comput. System Sci. 157, Article 103756 (2026).
[39] Mingsheng Ying. 2024. Foundations of Quantum Programming (second ed.). Morgan Kaufmann.
[40] Charles Yuan and Michael Carbin. 2022. Tower: data structures in quantum superposition. Proceedings of the ACM on Programming Languages 6, OOPSLA2, Article 134 (2022), 259–288 pages.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
A DEFERRED PROOFS
All of the theorems and propositions in the main text of this paper were presented without proofs. In this appendix, we give all of these proofs. We first prove the following lemma, which is useful for proving Theorem 4.5.
LEMMA A.1. Let A and A be as in Theorem 4.5. Let t be a classical term involving classical variables x1:s1,…,xn:sn and p be the principal variable of η(t). We use q=q1,…,qn to denote the designated variables qx1,…,qxn as in Definition 4.3. Denote a=a1,…,an∈As1,…,Asn. Define σa to be an assignment of classical variables with σa(xi)=ai for i=1,…,n. For any quantum state
where eval on the LHS is defined in the quantum algebra A, and eval on the RHS is defined in the classical algebra A.
PROOF. We first consider the lemma for the computational-basis states; that is, ∣φ⟩=∣a⟩ for some a. This case can be proved by induction on the length of t with the following induction hypothesis:
IH: Let o denote the variables involved in the quantisation η(t) but not in p,q. For any classical assignment σ of x, let ai=σ(xi) and a=a1,…,an. There exists a quantum state ∣γ⟩ such that:
eval∣a⟩(η(t))=∣a⟩q∣evalσ(t)⟩p∣γ⟩o.(43)
There are three cases:
• If t=c, then η(t)=∣ψc⟩p and ∣ψc⟩A=∣cA⟩. Thus, Equation (43) holds.
• If t=x, then η(x)=SUMs[qx,q]∣0⟩q. Since ks(0sA)=0 and a⊕s0sA=a, we have
where each η(ti)=Ci∣ψi⟩ has principal variable pi. Note that in the in-place case, p=pi for the designated index i in Definition 4.1; in the out-of-place case, p is the first variable in r. By the IH for t1,…,tm, there exists a ∣Γ⟩ such that
for some ∣γ′⟩. Combining Equations (44) and (45), we obtain
eval∣a⟩(η(t))=∣a⟩q∣evalσ(t)⟩p(∣Γ⟩∣γ′⟩)o,
and Equation (43) holds.
Since all ∣a⟩q are orthogonal, by linearity and the tracing out of q, it is easy to prove the lemma for any quantum state ∣φ⟩.
PROOF OF THEOREM 4.5. Since A is already a quantum algebra of QSig, it suffices to show that A satisfies every equation in η(E). Consider any equation in E:
e=(∀x1:s1,…,xn:sn)(t1=t2).
We use q=q1,…,qn to denote the designated variables qx1,…,qxn corresponding to x1,…,xn, as in Definition 4.3.
Let p be the common principal variable of η(t1) and η(t2), as in Definition 4.4. Consider an arbitrary quantum state
∣φ⟩q=a∑βa∣a⟩q.
Since A is an algebra of Spec and e∈E, we have A⊨e. Therefore, for every a∈As1×⋯×Asn,
evalσa(t1)=evalσa(t2).(46)
Applying Lemma A.1 to t1 and t2, and using Equation (46), we obtain
eval∣φ⟩(η(t1))↓p=eval∣φ⟩(η(t2))↓p,
which is essentially A⊨η(e) by the validity of equations (see Definition 3.6). The conclusion then follows.
PROOF OF PROPOSITION 5.1. Note that in Equation (20), all variables are principal variables. To show that the equation is valid in algebra A, by linearity, it suffices to consider any computational-basis state of variables qa,qi,qv,qu:
∣φ⟩=∣a⟩qa∣j⟩qi∣v⟩qv∣u⟩qu.
Let a′ be an array with a′[i]=a[i] for i=j and a′[j]=u. By evaluating the LHS of Equation (20), we have
for any quantum state ∣φ⟩, and the conclusion follows.
□
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
PROOF OF PROPOSITION 6.1. Note that in Equations (23) and (24), qa is the only principal variable. By Equations (21) and (22) and the definition of qcorr, for every x∈{0,1} and i∈{0,1,2}, we have
From Equation (27), σ(1,i)=(⊥,⊥,⊥,⊥) for every i∈Bidx, and 1i∣Ψx⟩=∣Ψx⟩. Apart from the case P=P′=1, σ(P,i)=σ(P′,i′) for distinct pairs (P,i)=(P′,i′) only if P=P′=Z and i,i′∈{3r,3r+1,3r+2} for some r∈{0,1,2}. Moreover, for every x∈Bbit and r∈{0,1,2}, we have
Z3r∣Ψx⟩=Z3r+1∣Ψx⟩=Z3r+2∣Ψx⟩.
Thus, for every x∈Bbit, P,P′∈{1,X,Y,Z}, and i,i′∈Bidx,
σ(P,i)=σ(P′,i′)⇒Pi∣Ψx⟩=Pi′′∣Ψx⟩.
By Equations (27), (49) and (50), for every x,x′∈Bbit, P,P′∈{1,X,Y,Z}, and i,i′∈Bidx, it is easy to verify that
Therefore, Equation (28) is well-defined and these ∣Φx,σ(P,i)⟩ can be extended to an orthonormal basis of HqarrayB.
PROOF OF PROPOSITION 6.2. Note that in Equations (29) to (32), qa is the only principal variable. By Equations (27) and (28) and the definition of qcorr, for every x∈Bbit, we have
Since qa is the principal variable, we trace out ql,qi,qs. Both sides of Equations (30) to (32) give
i=0∑8x,x′∈{0,1}∑αx,iαx′,i∣Ψx⟩⟨Ψx′∣qa.
Therefore, Equations (30) to (32) are valid. The conclusion immediately follows.
PROOF OF PROPOSITION 7.3. As observed after Equation (35), every Gsq is an isometric embedding. It suffices to verify the two conditions in Definition 7.2.
(1) Let ∣ψ⟩∈K be a quantum state symbol. Then, there is a constant symbol c:→s such that ∣ψ⟩=η(c). Since g is a homomorphism, gs(cA)=cA′, which means
Gsq∣ψ⟩A=GsqcA⟩=cA′⟩=∣ψ⟩A′.
Consequently, Equation (33) holds.
(2) Let U∈U be a quantum gate symbol. It suffices to consider the following cases.
Suppose U=preO or U=postO for some nonconstant operation symbol O. This case is trivial because preOB=postOB=1 for B∈{A,A′}.
Suppose U=UO for some nonconstant operation symbol O:s1,…,sn→s. Write siq=η(si) and sq=η(s). For ai∈Asi and a∈As, we have
The second equality follows from the condition about ⊕sA and ⊕sA′ and the fact that g is a homomorphism.
By linearity, Equation (34) holds.
Thus, G satisfies Definition 7.2 and is an embedding from A to A′.
PROOF OF PROPOSITION 7.4. As observed after Equation (35), every Gsq is unitary. It suffices to verify the two conditions in Definition 7.2. For each s∈S, let Ns=∣As∣=∣As′∣ and ωs=e2πi/Ns.
(1) Let ∣ψ⟩∈K be a quantum state symbol. Similar to the proof of Proposition 7.3, Gsq∣ψ⟩A=∣ψ⟩A′ and therefore Equation (33) holds.
(2) Let U∈U be a quantum gate symbol. It suffices to consider the following cases.
Suppose U=preO or postO for some nonconstant operation symbol O:s1,…,sn→s. For any a∈As, since gs is bijective,
Here, the second equality uses ksA=ksA′∘gs. Tensoring Equation (53) with ⨂i=1nGsiq followed by linearity leads to Equation (34) for U=preO. Taking the adjoints proves it for U=postO.
Suppose U=UO for some nonconstant operation symbol O:s1,…,sn→s. For ai∈Asi and a∈As, Equation (9) gives
The second equality follows from ksA′∘gs=ksA and the fact that g is a homomorphism. By linearity, Equation (34) holds.
Thus, G satisfies Definition 7.2 and is an isomorphism from A to A′.
PROOF OF PROPOSITION 8.3. As observed after Equation (40), every Jsq is unitary. It suffices to verify the two conditions in Definition 7.2.
Mingsheng Ying, Zhicheng Zhang, and Kean Chen
(1) Let ∣ψ⟩∈K be a quantum state symbol, so ∣ψ⟩=η(c) for a constant symbol c:→s. Since ∣ψ⟩ has the single sort sq, Tsq=1. Then
Jsq∣ψ⟩C=Jsq(cA,cB)⟩=cA⟩⊗cB⟩=∣ψ⟩A⊗B.
Consequently, Equation (33) holds.
(2) Let U∈U be a quantum gate symbol. It suffices to consider the following cases.
Suppose U=preO or U=postO for some nonconstant operation symbol O. This case is trivial because preOD=postOD=1 for D∈{A,B,C}, and Equation (38) further implies that preOA⊗B=postOA⊗B=1. Therefore, Equation (34) holds in both cases.
Suppose U=UO for some nonconstant operation symbol O:s1,…,sn→s. Let us denote a=a1,…,an, b=b1,…,bn, and (a,b)=(a1,b1),…,(an,bn). For ai∈Asi, bi∈Bsi, a∈As, and b∈Bs, we have
Here, the first equality follows from Equation (7); the second follows from Equations (36), (40) and (41); the third follows from Equations (7) and (37); and the last follows from Equations (37) and (38).
By linearity, Equation (34) holds.
Thus, J satisfies Definition 7.2 and is an isomorphism from C to A⊗B.
PROOF OF PROPOSITION 8.4. As shown in the proof of Proposition 8.3, Equation (33) holds. It remains to verify Equation (34) for every U∈U through the following cases.
Suppose that U=preO or U=postO for some nonconstant operation symbol O:s1,…,sn→s. Equation (42) implies that for each sort s∈S,
where the second equality uses Equation (54), the third follows from Equation (37), and the final follows from Equation (38). Combining the above together, Equation (34) holds for U=preO. Taking adjoints proves it for U=postO.
Suppose U=UO for some nonconstant operation symbol O:s1,…,sn→s. Write a=a1,…,an,b=b1,…,bn, and (a,b)=(a1,b1),…,(an,bn). For ai∈Asi, bi∈Bsi, a∈As, and b∈Bs, let a′=OA(a) and b′=OB(b). By Equation (36), OC((a,b))=(a′,b′). Then we have
Here, the first equality follows from Equation (9); the second follows from Equation (42); and the last follows from Equations (9) and (38). By linearity, Equation (34) holds.
Thus, J satisfies Definition 7.2 and is an isomorphism from C to A⊗B.