Quantum Programming with Inductive Datatypes: Causality and Affine Type Theory

Inductive datatypes in programming languages allow users to define useful data structures such as natural numbers, lists, trees, and others. In this paper we show how inductive datatypes may be added to the quantum programming language QPL. We construct a sound categorical model for the language and by doing so we provide the first detailed semantic treatment of user-defined inductive datatypes in quantum programming. We also show our denotational interpretation is invariant with respect to big-step reduction, thereby establishing another novel result for quantum programming. Compared to classical programming, this property is considerably more difficult to prove and we demonstrate its usefulness by showing how it immediately implies computational adequacy at all types. To further cement our results, our semantics is entirely based on a physically natural model of von Neumann algebras, which are mathematical structures used by physicists to study quantum mechanics.


Introduction
Quantum computing is a computational paradigm which takes advantage of quantum mechanical phenomena to perform computation.Much of the interest in quantum computing is due to impressive algorithms, such as Shor's polynomialtime algorithm for integer factorisation [23], Grover's O( √ n) algorithm for unsorted database search [7] and others [15].Of course, in order to implement these algorithms it is necessary to also develop appropriate quantum programming languages.The present paper is concerned with this issue and makes several theoretical contributions towards the design and denotational semantics of quantum programming languages.
Our development is based around the quantum programming language QPL [22] which we extend with inductive datatypes.Our paper is the first to construct a denotational semantics for user-defined inductive datatypes in quantum programming.In the spirit of the original QPL, our type system is affine (discarding of arbitrary variables is allowed, but copying is restricted).We also extend QPL with a copy operation for classical data, because this is an admissible operation in quantum mechanics which improves programming convenience.The addition of inductive datatypes requires a departure from the original denotational semantics of QPL, which are based on finite-dimensional quantum structures, and we consider instead (possibly infinite-dimensional) quantum structures based on W*-algebras (also known as von Neumann algebras), which have been used by physicists in the study of quantum foundations [24].As such, our semantic treatment is physically natural and our model is more accessible to physicists and experts in quantum computing compared to most other denotational models.
QPL is a first-order programming language which has procedures, but it does not have lambda abstractions.Thus, there is no use for a !-modality and we show how to model the copy operation by describing the canonical comonoid structure of all classical types (including the inductive ones).
An important notion in quantum mechanics is the idea of causality which has been formulated in a variety of different ways.In this paper, we consider a simple operational interpretation of causality: if the output of a physical process is discarded, then it does not matter which process occurred [9].In a symmetric monoidal category C with tensor unit I, this can be understood as requiring that for any morphism (process) f : A 1 → A 2 , it must be the case that ⋄ A2 • f = ⋄ A1 , where ⋄ Ai : A i → I is the discarding map (process) at the given objects.This notion ties in very nicely with our affine language, because we have to show that the interpretation of values is causal, i.e., values are always discardable.
A major contribution of this paper is that we prove the denotational semantics is invariant with respect to both small-step reduction and big-step reduction.The latter is quite difficult in quantum programming and our paper is the first to demonstrate such a result.Combining this with the causal properties of values, we obtain (as a corollary) computational adequacy at all types.

Syntax of QPL
The syntax of QPL (including our extensions) is summarised in Figure 1.A well-formed type context, denoted ⊢ Θ, is simply a list of distinct type variables.A type A is well-formed in type context Θ, denoted Θ ⊢ A, if the judgement can be derived according to the following rules: Note that nested type induction is allowed.Henceforth, we implicitly assume that all types we are dealing with are well-formed.
Example 1.The type of natural numbers is defined as Nat ≡ µX.I + X. Lists of a closed type • ⊢ A are defined as List(A) ≡ µY.I + A ⊗ Y.
Notice that our type system is not equipped with a !-modality.Indeed, in the absence of function types, there is no reason to introduce it.Instead, we specify the subset of types where copying is an admissible operation.The classical types are a subset of our types defined in Figure 1 (unit) Π ⊢ Γ new unit u Γ, u : I (discard) Π ⊢ Γ, x : A discard x Γ P is a classical type (copy) Π ⊢ Γ, x : P y = copy x Γ, x : P, y : S is a unitary of arity n (unitary) Π ⊢ Γ, q1 : qbit, . . ., qn : qbit q1, . . ., qn * = S Γ, q1 : qbit, . . ., qn : qbit property that variables of classical types may be copied, whereas variables of non-classical types may not be copied (see (copy) rule in Figure 2).
We use small latin letters (e.g.x, y, u, q, b) to range over term variables.More specifically, q ranges over variables of type qbit, u over variables of unit type I, b over variables of type bit := I + I and x, y range over variables of arbitrary type.We use Γ and Σ to range over variable contexts.A variable context is a function from term variables to closed types, which we write as Γ = x 1 : A 1 , . . ., x n : A n .
We use f, g to range over procedure names.Every procedure name f has an input type A and an output type B, denoted f : A → B, where A and B are closed types.We use Π to range over procedure contexts.A procedure context is a function from procedure names to pairs of procedure input-output types, denoted Remark 2. Unlike lambda abstractions, procedures cannot be passed to other procedures as input arguments, nor can they be returned as output.
A term judgement has the form Π ⊢ Γ M Σ (see Figure 2) and indicates that term M is well-formed in procedure context Π with input variable context Γ and output variable context Σ.All types occurring within it are closed.
The intended interpretation of the quantum rules are as follows.The (qbit) rule prepares a new qubit q in state |0 0|.The (unitary) rule applies a unitary operator S to a sequence of qubits in the standard way.The (measure) rule performs a quantum measurement on qubit q and stores the measurement outcome in bit b.The measured qubit is destroyed in the process.
The no-cloning theorem of quantum mechanics [27] shows that arbitrary qubits cannot be copied.Because of this, copying is restricted only to classical types, as indicated by the (copy) rule, and this allows us to avoid runtime errors.Like the original QPL [22], our type system is also affine and the (discard) rule allows any variable to be discarded.

Operational Semantics of QPL
In this section we describe the operational semantics of QPL.The central notion is that of a program configuration which provides a complete description of the current state of program execution.It consists of four components that must satisfy some coherence properties: (1) the term which remains to be executed; (2) a value assignment, which is a function that assigns formal expressions to variables as a result of execution; (3) a procedure store which keeps track of what procedures have been defined so far and (4) the quantum state computed so far.
Value Assignments.A value is an expression defined by the following grammar: where n ranges over the natural numbers.Think of * as representing the unique value of unit type I and of n as representing a pointer to the n-th qubit of a quantum state ρ.Specific values of interest are ff := left I,I * and tt := right I,I * which correspond to false and true respectively.
A qubit pointer context is a set Q of natural numbers.A value v of type A is well-formed in qubit pointer context Q, denoted Q ⊢ v : A, if the judgement is derivable from the following rules: If v is well-formed, then its type and qubit pointer context are uniquely determined.If Q ⊢ v : P with P classical, then we say v is a classical value.
A value assignment is a function from term variables to values, which we write as V = {x 1 = v 1 , . . ., x n = v n }, where x i are variables and v i are values.A value assignment is well-formed in qubit pointer context Q and variable context Γ , denoted Q; Γ ⊢ V, if V has exactly the same variables as Γ and exists, and some of the Q i may be empty.
Procedure Stores.A procedure store is a set of procedure definitions, written as: A procedure store is well-formed in procedure context Π, written Π ⊢ Ω, if the judgement is derivable via the following rules: where M is a term, V is a value assignment, Ω is a procedure store and ρ ∈ C 2 n ×2 n is a finite-dimensional density matrix with 0 ≤ tr(ρ) ≤ 1.The density matrix ρ represents a (mixed) quantum state and its trace may be smaller than one because we also use it to encode probability information (see Remark 4).We write dim(ρ) = n to indicate that the dimension of ρ is n.
A well-formed program configuration is a configuration to indicate this situation.The formation rules enforce that the qubits of ρ and the qubit pointers from V are in a 1-1 correspondence.
The small step semantics is defined for configurations (M | V | Ω | ρ) by induction on M in Figure 3 and we now explain the notations used therein.
Fig. 3: Small Step Operational semantics of QPL.
In the (discard) rule, we use two functions that depend on a value v.They are tr v , which modifies the quantum state ρ by tracing out all of its qubits which are used in v, and r v which simply reindexes the value assignment, so that the pointers within r v (V ) correctly point to the corresponding qubits of tr v (ρ), which is potentially of smaller dimension than ρ.Formally, for a wellformed value v, let Q and A be the unique qubit pointer context and type, such that Q ⊢ v : A. Then tr v (ρ) is the quantum state obtained from ρ by tracing out all qubits specified by Q.Given a value assignment , where: In the (unitary) rule, the superoperator S #" m applies the unitary S to the vector of qubits specified by #" m.In the (measure0) and (measure1) rules, the m-th qubit of ρ is measured in the computational basis, the measured qubit is destroyed in the process and the measurement outcome is stored in the bit b.More specifically, |i m = I 2 m−1 ⊗ |i ⊗ I 2 n−m and m i| is its adjoint, for i ∈ {0, 1}, and where I n is the identity matrix in C n×n .Remark 4. Because of the way we decided to handle measurements, reduction (− −) is a nondeterministic operation, where we encode the probabilities of reduction within the trace of our density matrices in a similar way to [8].Equivalently, we may see the reduction relation as probabilistic provided that we normalise all density matrices and decorate the reductions with the appropriate probability information as specified by the Born rule of quantum mechanics.The nondeterministic view leads to a more concise and clear presentation and because of this we have chosen it over the probabilistic view.
In the (while) rule, the term The (proc) rule simply defines a procedure which is added to the procedure store and the (call) rule is used to call already defined procedures.In the (call) rule, the term M α is α-equivalent to M and is obtained from it by renaming the input x 2 to x 1 , renaming the output y 2 to y 1 and renaming all other variables within M to some fresh names, so as to avoid conflicts with the input, output and the rest of the variables within V .

Theorem 5 (Subject reduction). If
), for some (necessarily unique) contexts Π ′ , Γ ′ , Q ′ and where Σ is invariant.Assumption 6.From now on we assume all configurations are well-formed.A configuration Program execution finishes at terminal configurations, which are characterised by the property that they do not reduce any further.We will use calligraphic letters (C, D, . ..) to range over configurations and we will use T to range over terminal configurations.For a configuration C = (M | V | Ω | ρ), we write for brevity tr(C) := tr(ρ) and we shall say C is normalised whenever tr(C) = 1.We say that a configuration C is impossible if tr(C) = 0 and we say it is possible otherwise.proc GHZnext :: l : ListQ -> l : ListQ { new qbit q; case l of nil -> q*=H; l = q :: nil | q' :: l' -> q',q *= CNOT; l = q :: q' :: l' } proc GHZ : Example 9.The GHZ n state is defined as γ n := (|0 ⊗n +|1 ⊗n )( 0| ⊗n + 1| ⊗n )/2.In Figure 5, we define a procedure GHZ, which given a natural number n, generates the state γ n , which is represented as a list of qubits of length n.The procedure (5a) uses an auxiliary procedure GHZnext, which given a list of qubits representing the state γ n , returns the state γ n+1 again represented as a list of qubits.The two procedures make use of some (hopefully obvious) syntactic sugar.In 5b, we also present the last few steps of a reduction sequence which produces , where Ω contains the above mentioned procedures.In the reduction sequence we only show the term in evaluating position and we omit some intermediate steps.The type ListQ is a shorthand for List(qbit) from Example 1.

W*-algebras
In this section we describe our denotational model.It is based on W*-algebras, which are algebras of observables (i.e.physical entities), with interesting domain-theoretic properties.We recall some background on W*-algebras and their categorical structure.We refer the reader to [24] for an encyclopaedic account on W*-algebras.Domain-theoretic preliminaries.Recall that a directed subset of a poset P is a non-empty subset X ⊆ P in which every pair of elements of X has an upper bound in X.A poset P is a directed-complete partial order (dcpo) if each directed subset has a supremum.A poset P is pointed if it has a least element, usually denoted by ⊥.A monotone map f : P → Q between posets is Scott-continuous if it preserves suprema of directed subsets.If P and Q are pointed and f preserves the least element, then we say f is strict.We write DCPO (DCPO ⊥! ) for the category of (pointed) dcpo's and (strict) Scott-continuous maps between them.
Definition of W*-algebras.A complex algebra is a complex vector space V equipped with a bilinear multiplication (− • −) : V × V → V , which we write as juxtaposition.A Banach algebra A is a complex algebra A equipped with a submultiplicative norm − : A → R ≥0 , i.e. ∀x, y ∈ A : xy ≤ x y .A * -algebra A is a complex algebra A with an involution (−) An element x ∈ A of a C*-algebra A is called positive if ∃y ∈ A : x = y * y.The poset of positive elements of A is denoted A + and its order is given by Let f : A → B be a linear map between C*-algebras A and B. We say that f is positive if it preserves positive elements.We say that f is completely positive if it is n-positive for every n ∈ N, i.e. the map M n (f ) : ,j≤n is positive.The map f is called multiplicative, involutive, unital if it preserves multiplication, involution, and the unit, respectively.The map f is called subunital whenever the inequalities 0 ≤ f (1) ≤ 1 hold.A state on a C*-algebra A is a completely positive unital map s : A → C.
Although W*-algebras are commonly defined in topological terms (as C*algebras closed under several operator topologies) or equivalently in algebraic terms (as C*-algebras which are their own bicommutant), one can also equivalently define them in domain-theoretic terms [18], as we do next.
A completely positive map between C*-algebras is normal if its restriction to the unit interval is Scott-continuous [18,Proposition A.3].A W*-algebra is a C*-algebra A such that the unit interval [0, 1] A is a dcpo, and A has a separating set of normal states: for every x ∈ A + , if x = 0, then there is a normal state s : A → C such that s(x) = 0 [24, Theorem III.3.16].
A linear map f : A → B between W*-algebras A and B is called an NCPSUmap if f is normal, completely positive and subunital.The map f is called an NMIU-map if f is normal, multiplicative, involutive and unital.We note that every NMIU-map is necessarily an NCPSU-map and that W*-algebras are closed under formation of matrix algebras as in Example 10.
Categorical Structure.Let W * NCPSU be the category of W*-algebras and NCPSUmaps and let W * NMIU be its full-on-objects subcategory of NMIU-maps.Throughout the rest of the paper let C := (W * NCPSU ) op and let V := (W * NMIU ) op .QPL types are interpreted as functors Θ ⊢ A : V |Θ| → V and closed QPL types as objects A ∈ Ob(V) = Ob(C).One should think of V as the category of values, because the interpretation of our values from §3 are indeed V-morphisms.General QPL terms are interpreted as morphisms of C, so one should think of C as the category of computations.We now describe the categorical structure of V and C and later we justify our choice for working in the opposite categories.
Both C and V have a symmetric monoidal structure when equipped with the spacial tensor product, denoted here by (− ⊗ −), and tensor unit I := C [10, Section 10].Moreover, V is symmetric monoidal closed and also complete and cocomplete [10].C and V have finite coproducts, given by direct sums of W*algebras [1, Proposition 4. The categories V, C and Set are related by symmetric monoidal adjunctions: [25, pp. 11] and the subcategory inclusion J preserves coproducts and tensors up to equality.
Interpreting QPL within C and V is not an ad hoc trick.In physical terms, this corresponds to adopting the Heisenberg picture of quantum mechanics and this is usually done when working with infinite-dimensional W*-algebras (like we do).Semantically, this is necessary, because (1) our type system has conditional branching and we need to interpret QPL terms within a category with finite coproducts; (2) we have to be able to compute parameterised initial algebras to interpret inductive datatypes.The category W * NCPSU has finite products, but it does not have coproducts, so by interpreting QPL terms within C = (W * NCPSU ) op we solve problem (1).For (2), the monoidal closure of V = (W * NMIU ) op is crucial, because it implies the tensor product preserves ω-colimits.Convex sums.In both C and W * NCPSU , morphisms are closed under convex sums, which are defined pointwise, as usual.More specifically, given NCPSUmaps f 1 , . . ., f n : A → B and real numbers p i ∈ [0, 1] with i p i ≤ 1, then the map i p i f i : A → B is also an NCPSU-map.
DCPO ⊥! -enrichment.For W*-algebras A and B, we define a partial order on C(A, B) by : f ≤ g iff g − f is a completely positive map.Equipped with this order, our category C is DCPO ⊥! -enriched [2, Theorem 4.3].The least element in C(A, B) is also a zero morphism and is given by the map 0 : A → B, defined by 0(x) = 0. Also, the coproduct structure and the symmetric monoidal structure are both DCPO ⊥! -enriched [1, Corollary 4.9.15][2, Theorem 4.5].
Quantum Operations.For convenience, our operational semantics adopts the Schrödinger picture of quantum mechanics, which is the picture most experts in quantum computing are familiar with.However, as we have just explained, our denotational semantics has to adopt the Heisenberg picture.The two pictures are equivalent in finite dimensions and we will now show how to translate from one to the other.By doing so, we provide an explicit description (in both pictures) of the required quantum maps that we need to interpret QPL.
Consider the maps in Figure 6.The map tr is used to trace out (or discard) parts of quantum states.Density matrices ρ are in 1-1 correspondence with the maps new ρ , which we use in our semantics to describe (mixed) quantum states.The meas map simply measures a qubit in the computational basis and returns a bit as measurement outcome.The unitary S map is used for application of a unitary S.These maps work as described in the Schrödinger picture of quantum mechanics, i.e., the category W * NCPSU .For every map f : A → B among those mentioned, f † : B → A indicates its Hermitian adjoint3 .In the Heisenberg picture, composition of maps is done in the opposite way, so we simply write f ‡ := (f † ) op ∈ C(A, B) for the Hermitian adjoint of f when seen as a morphism in (W * NCPSU ) op = C. Thus, the mapping (−) ‡ translates the above operations from the Schrödinger picture (the category W * NCPSU ) to the Heisenberg picture (the category C) of quantum mechanics.
Parameterised initial algebras.In order to interpret inductive datatypes, we need to be able to compute parameterised initial algebras for the functors induced by our type expressions.V is ideal for this, because it is cocomplete and monoidal closed and so all type expressions induce functors on V which preserve ω-colimits.

Denotational Semantics of QPL
In this section we describe the denotational semantics of QPL.

Interpretation of types
The interpretation of a type Θ ⊢ A is a functor Θ ⊢ A : V |Θ| → V, defined by induction on the derivation of Θ ⊢ A in Figure 7.As usual, one has to prove this assignment is well-defined by showing the required initial algebras exist.
Proposition 13.The assignment in Figure 7 is well-defined.
Proof.By induction, every Θ ⊢ A is an ω-cocontinuous functor and thus it has a parameterised initial algebra by Proposition 12.

⊓ ⊔
For simplicity, the interpretation of terms is only defined on closed types and so we introduce more concise notation for them.For any closed type • ⊢ A we write for convenience A := • ⊢ A ( * ) ∈ Ob(V), where * is the unique object of the terminal category 1.Notice also that A ∈ Ob(C) = Ob(V).
Definition 15.Given a closed type • ⊢ µX.A, we define an isomorphism (in V): where the equality is Lemma 14 and the iso is the initial algebra structure.
Fig. 7: Interpretations of types.K A is the constant-A-functor.

Copying and Discarding
Our type system is affine, so we have to construct discarding maps at all types.The tensor unit I is a terminal object in V (but not in C) which leads us to the next definition.
Definition 17 (Discarding map).For any W*-algebra A, let ⋄ A : A → I be the unique morphism of V with the indicated domain and codomain.
We will see that all values admit an interpretation as V-morphisms and are therefore discardable.In physical terms, this means values are causal (in the sense mentioned in the introduction).Of course, this is not true for the interpretation of general terms (which correspond to C-morphisms).
Our language is equipped with a copy operation on classical data, so we have to explain how to copy classical values.In the absence of a !-modality, we do this by constructing a copy map defined at all classical types.
, one can define a copy map △ P : P → P ⊗ P for every classical type • ⊢ P , such that the triple P , △ P , ⋄ P forms a cocommutative comonoid in V.
Proof.The proof requires some effort and is presented in Appendix A.

⊓ ⊔
We shall later see that the interpretations of our classical values are comonoid homomorphisms (w.r.t.Proposition 18) and therefore they may be copied.

Interpretation of terms
Given a variable context Γ = x 1 : A 1 , . . ., x n : A n , we interpet it as the object ) defined by induction on the derivation of Π ⊢ Γ M Σ in Figure 9.For brevity, we often write M := Π ⊢ Γ M Σ , when the contexts are clear or unimportant.We now explain some of the notation used in Figure 9.The rules for manipulating qubits use the morphisms new ‡ |0 0| , meas ‡ and unitary ‡ S which are defined in §4.For the interpretation of while loops, given an arbitrary morphism f : A ⊗ bit → A ⊗ bit of C, we define a Scott-continuous endofunction where the isomorphism d A,I,I : A ⊗ (I + I) → (A ⊗ I) + (A ⊗ I) is explained in §4.For any pointed dcpo D and Scott-continuous function h : D → D, its least fixpoint is lfp(h) := ∞ i=0 h i (⊥), where ⊥ is the least element of D. Remark 19.The term semantics for defining and calling procedures does not involve any fixpoint computations.The required fixpoint computations are done when interpreting procedure stores, as we shall see next.

Interpretation of configurations
Before we may interpret program configurations, we first have to describe how to interpret values and procedure stores.
which we abbreviate as v if Q and A are clear from context.It is defined by induction on the derivation of Q ⊢ v : A in Figure 8.
For the next theorem, recall that if Theorem 20.Let Q ⊢ v : A be a value.Then: Proof.In Appendix A.

⊓ ⊔
We see that, as promised, interpretations of values may always be discarded and interpretations of classical values may also be copied.Next, we explain how to interpret value contexts.For a value context Q; Γ ⊢ V , its interpretation is the morphism: Some of the Q i can be empty and this is the reason why the definition depends on a coherent natural isomorphism.We write V as a shorthand for Q; Γ ⊢ V .Obviously, V is also causal thanks to Theorem 20.
Interpretation of procedure stores.The interpretation of a well-formed procedure store Π ⊢ Ω is an element of Π , i.e. a |Π|-tuple of morphisms from C. It is defined by induction on Π ⊢ Ω :

Using this observation, we can now define the interpretation of a configuration
For brevity, we simply write (M | V | Ω | ρ) or even just C to refer to the above morphism.

Soundness, Adequacy and Big-step Invariance
Since our operational semantics allows for branching, soundness is showing that the interpretation of configurations is equal to the sum of small-step reducts.
Theorem 21 (Soundness).For any non-terminal configuration C : Proof.By induction on the shape of the term component of C. ⊓ ⊔ Remark 22.The above sum and all sums that follow are well-defined convex sums of NCPSU-maps where the probability weights p i have been encoded in the density matrices.
A natural question to ask is whether C is also equal to the (potentially infinite) sum of all terminal configurations that C reduces to.In other words, is the interpretation of configurations also invariant with respect to big-step reduction.This is indeed the case and proving this requires considerable effort.
Theorem 23 (Big-step Invariance).For any configuration C, we have: The above theorem is the main result of our paper.This is a powerful result, because with big-step invariance in place, computational adequacy at all types is now a simple consequence of the causal properties of our interpretation.Observe that for any configuration C, we have a subunital map ⋄ • C : C → C and evaluating it at 1 yields a real number Theorem 24 (Adequacy).For any normalised C : If C is not normalised, then adequacy can be recovered simply by normalising: (⋄ • C ) (1) = tr(C)Halt(C), for any possible configuration C. The adequacy formulation of [17] and [4] is now a special case of our more general formulation.
Proof.By Theorem 24 and because ⋄ I = id.

Conclusion and Related Work
There are many quantum programming languages described in the literature.For a survey see [6] and [16, pp. 129].Circuit programming languages, such as Proto-Quipper [20,21] and ECLNL [14], generate quantum circuits, but these languages do not support executing quantum measurements.Here we focus on quantum languages which support measurement and which have either inductive datatypes or some computational adequacy result.
Our work is the first to present a detailed semantic treatment of user-defined inductive datatypes for quantum programming.In [17] and [4], the authors show how to interpret a quantum lambda calculus extended with a datatype for lists, but their syntax does not support any other inductive datatypes.These languages are equipped with lambda abstractions, whereas our language has only support for procedures.Lambda abstractions are modelled using constructions from quantitative semantics of linear logic in [17] and techniques from game semantics in [4].We believe our model is simpler and certainly more physically natural, because we work only with mathematical structures used by physicists in their study of quantum mechanics.Both [17] and [4] prove an adequacy result for programs of unit type.In [19], the authors discuss potential categorical models for inductive datatypes in quantum programming, but there is no detailed semantic treatment provided and there is no adequacy result, because the language lacks recursion.
Other quantum programming languages without inductive datatypes, but which prove computational adequacy results include [8,11].A simple quantum language described in [28] is equipped with a denotational semantics which is defined in terms of its operational semantics in such a way that soundness and adequacy trivially hold by definition (and are indeed not stated).
A model based on W*-algebras for a quantum lambda calculus without recursion or inductive datatypes was described in a recent manuscript [3].In that model, it appears that currying is not a Scott-continuous operation, and if so, the addition of recursion renders the model neither sound, nor adequate.For this reason, we use procedures and not lambda abstractions in our language.
To conclude, we presented two novel results in quantum programming: (1) we provided a denotational semantics for a quantum programming language with inductive datatypes; (2) we proved that our denotational semantics is invariant with respect to big-step reduction.We also showed that the latter result is quite powerful by demonstrating how it immediately implies computational adequacy.
Our denotational model is based on W*-algebras, which are used by physicists to study quantum foundations.We hope this would make it useful for developing static analysis methods based on abstract interpretation and we plan on investigating this as part of future work.

A Comonoid Structure of Classical Types
In this appendix we describe the comonoid structure of classical types within our category V (and therefore also in C).Our methods are based on those of [13], but there are some small differences compared to that work.In particular, we have less structure to work with, but our type expressions are also simpler.Nevertheless, the main idea is the same: we present an additional (classical) type interpretation for classical types within a cartesian category (in our case Set) which then allows us to carry the comonoid structure into V via a symmetric monoidal adjunction.In our case, the adjunction is denoted Set it is defined in [3], but here we only use the categorical properties mentioned in §4, so we omit the definition of the adjunction.

A.1 Classical Interpretation of Classical Types
The classical interpretation of a classical type Θ ⊢ P is given by a functor Θ ⊢ P : Set |Θ| → Set, defined by induction on the derivation of Θ ⊢ P in the following way: where × is the categorical product in Set and where ∐ is the categorical coproduct in Set.This assignment is well-defined, because every Θ ⊢ P is an ωcocontinuous functor on Set and thus it has a parameterised initial algebra [13, §4.3].For any closed classical type • ⊢ P , we write P := • ⊢ P ( * ) ∈ Ob(Set).
Our next proposition shows that the standard and classical type interpretations are strongly related via a natural isomorphism, which is crucial for defining the comonoid structure.
Proposition 26.For any classical type Θ ⊢ P there exists a natural isomorphism 10), defined by induction on the derivation of Θ ⊢ P. Therefore, in the special case when Θ = •, there exists an isomorphism ι P : P ∼ = F P given by ι P := ι •⊢P * .
Proof.The definition of ι Θ⊢P and the proof of the theorem is essentially the same as [13, Theorem 6.1.2]and it is presented in detail in [12, A.8]. ⊓ ⊔ Fig. 10: Relationship between type interpretations.

A.2 Constructing the copy map
Using ι P , we can define a copy map on the interpretation of closed classical types.
Definition 27.For any closed classical type • ⊢ P we define a copy morphism: Proposition 28.P , △ P , ⋄ P is a cocommutative comonoid in V.
Proof.First, observe that ⋄ P = P The rest of the proof is then identical to [13,Proposition 6.3.3].
⊓ ⊔ Next, we identify the comonoid homomorphisms with respect to the above comonoid structure.
Definition 29.Given closed classical types P and R, we say that a morphism Proposition 30.For every classical morphism f : P → R , we have: Therefore, f is a comonoid homomorphism with respect to Proposition 28.

A.3 Folding and Unfolding of Classical Types
In order to prove soundness of our semantics, we have to be able to copy all classical values.Thus, we have to show that folding and unfolding of classical inductive types are classical morphisms in the sense of Definition 29.This is the purpose of the present subsection.Lemma 31 (Type Substitution).Let Θ, X ⊢ P and Θ ⊢ R be classical types.Then (see Figure 12): Proof.Special case of [13,Lemma 6.1.5],where γ = id.Detailed proof is available in [12, A.9].

⊓ ⊔
We may now define folding and unfolding for the classical interpretation of classical inductive types.
Definition 32.Given a closed classical type • ⊢ µX.P, we define an isomorphism: fold µX.P : P [µX.P/X] = X ⊢ P µX.P ∼ = µX.P : unfold µX.P Like in the standard type interpretation, substitution holds up to equality, so the above folding/unfolding is given simply by the initial algebra structure of the indicated functors.We conclude the subsection with a proposition showing how the different folds/unfolds relate to one another.
Proof.This is simply a special case of [13,Theorem 6.1.7].

⊓ ⊔
This shows that folding/unfolding of classical types is a classical isomorphism (Definition 29) and may thus be copied.
Fig. 12: The commuting diagram of natural isomorphisms for Lemma 31.

A.4 Copying of Classical Values
Finally, we may state the main theorem from this appendix.
Theorem 34.The interpretation of a classical value is a classical morphism (see Definition 29) and may thus be copied.
Proof.The proof is essentially the same as [13,Proposition 6.3.7].Recall that by Lemma 3, if Q ⊢ v : P is a classical value, then Q = •.The proof proceeds by defining for every classical value • ⊢ v : P a classical value interpretation • ⊢ v : P : 1 → P in Set.It is defined by induction on the derivation of • ⊢ v : P in the following way: where inl and inr are the coproduct injections in Set; f, g is the unique map induced by the product in Set and fold is defined in Definition 32.To finish the proof, one has to show The fold case follows by Proposition 33 and the remaining cases follow easily from the axioms of symmetric monoidal adjunctions.

B Proof of Theorem 23
For brevity, we define End(r) .
Note, that the sequence r∈TerSeq ≤n (C) End(r) n∈N is an increasing chain in our order and thus we may take its supremum, as we did above.
To show Theorem 23 is to show: As a simple consequence of Soundness (Theorem 21), we get the following.
Corollary 35.For any configuration C, we have C ≥ C ⇓ .
Proof.We have C ≥ r∈TerSeq ≤n (C) End(r) which follows by induction on n using Theorem 21.The corollary follows by taking the supremum over n.

⊓ ⊔
In the remainder of this appendix, we will show that the converse inequality also holds, thereby finishing the proof of Theorem 23.

B.1 Proof Strategy
Our proof strategy is based on that of [17] where the authors establish computational adequacy at unit type.
In §B.2 we extend the QPL language with finitary (or bounded) primitives for recursion and we update the operational and denotational semantics in an appropriate way, so that the established language properties continue to hold (Theorem 36).In §B.3 we prove adequacy via the following steps: we show that any finitary configuration is strongly normalising (Lemma 37) which then allows us to prove invariance of the interpretation for finitary configurations with respect to big-step reduction (Corollary 38); we show that the finitary configurations approximate the ordinary configurations both operationally (Lemma 40) and denotationally (Lemma 42); using these results we prove invariance of the denotational semantics with respect to big-step reduction for the ordinary QPL language (Theorem 23).

B.2 Language Extension
We extend the syntax of QPL by adding indexed procedure names.We use f n , g n with n ∈ N to range over indexed procedure names.An indexed procedure name f n can be used at most n times in the operational semantics (see below), whereas an (ordinary) procedure name f may be used any number of times.We write f n : A → B to indicate that the indexed procedure name has input type A and output type B. Procedure contexts are now also allowed to contain indexed procedure names, in addition to standard procedure names.Procedure contexts which contain a procedure name f n cannot contain the unindexed procedure name f or any other other indexed procedure names f m with m = n.
The term language is extended by adding new terms, some of which are indexed by natural numbers n ≥ 0. These terms are governed by the following formation rules: The formation rules for procedure stores are extended by adding a rule for indexed procedures: The notion of a well-formed configuration is defined in the same way as before provided one uses the updated notions of well-formed terms and well-formed procedure stores.The operational semantics is extended by adding the rules: where in the last rule, Ω α is the procedure store obtained from Ω by renaming f n+1 to f n within all procedure bodies contained in Ω.Similarly, M α2 is the result of renaming f n+1 to f n within M .The term M α1 is obtained from M by also renaming f n+1 to f n and then doing the same term variable renamings as in the unindexed (call) rule (see §3).
We extend the denotational semantics by adding interpretations for the newly added terms: Notice that the interpretations of the indexed (proc) and (call) term rules contain no fixpoint calculations, just like their unindexed counterparts.Similarly to the unindexed case, the non-trivial calculations take place in the interpretation of the procedure store rules.The newly added rule for formation of procedure stores is interpreted in the following way: The interpretation of configurations is now defined in the same way as before, but also using the newly added rules and updated notions.Finally, the notion of terminal configuration is also updated to include configurations of the form With this in place, all language properties stated in the previous sections also hold true for the extended language.
Theorem 36.Subject Reduction (Theorem 5), Progress (Theorem 7) and Soundness (Theorem 21) also hold true for the extended language (using the updated language notions).

B.3 The Proof
A term in the extended language is called finitary if it does not contain any unindexed procedure names or while loops.A term is called ordinary if it does not contain any indexed procedure names, indexed while loops or 0 Γ,Σ subterms.
In other words, an ordinary term is simply a term in the base QPL language as described in §2.Similarly, a finitary (ordinary) procedure store Ω is a procedure store where each procedure name of Ω is indexed (unindexed) and such that its procedure body is a finitary (ordinary) term.A finitary (ordinary) configuration is a configuration (M | V | Ω | ρ) where M and Ω are finitary (ordinary).A finitary configuration is true to its name, because all of its reduction sequences terminate in a finite number of steps.In other words, the above lemma shows that lockstep execution occurs between any ordinary reduction sequence and any one of its approximating finitary reduction sequences, provided the latter terminates in the ordinary sense.This allows us to establish the following corollary.from which the corollary follows by taking suprema.Let r ′ ∈ TerSeq ≤n (C ′ ) be arbitrary.If End(r ′ ) is a 0-configuration, then End(r ′ ) = 0 and thus it contributes nothing to the sum and may be ignored.Otherwise End(r ′ ) is a skip-configuration and by Lemma 40, there exists a unique r ∈ TerSeq ≤n (C), such that r ′ ⊏ r.In this case End(r ′ ) ⊏ End(r) and since both of them are skip-configurations, it follows End(r ′ ) = End(r) .Moreover, if r ′ 1 , r ′ 2 ∈ TerSeq ≤n (C ′ ) and also r 1 ⊐ r ′ 1 = r ′ 2 ⊏ r 2 , then r 1 = r 2 (to see this, observe that r ′ 1 and r ′ 2 must differ due to branching from a quantum measurement and thus so do r 1 and r 2 ).Both sums are finite and we showed that for all non-trivial summands on the left there exist corresponding summands on the right which are equal to them, thus the required inequality holds.

⊓ ⊔
The next lemma shows that ordinary configurations are also approximated by finitary configurations in a denotational sense.
Lemma 42.For any ordinary term M , procedure store Ω and configuration C:

Fig. 4 :
Fig. 4: Example of a term and of a reduction graph.

Theorem 7 (
Progress).If C is a configuration, then either C is terminal or there exists a configuration D, such that C D. Moreover, if C is not terminal, then tr(C) = C D tr(D) and there are at most two such configurations D. In the above situation, the probability of reduction is Pr(C D) := tr(D)/tr(C), for any possible C (see Remark 4) and Theorem 7 shows the total probability of all single-step reductions is 1.If C is impossible, then C occurs with probability 0 and subsequent reductions are also impossible.Probability of Termination Given configurations C and D let Seq n (C, D) := {C 0 • • • C n | C 0 = C and C n = D}, and let Seq ≤n (C, D) = n i=0 Seq n (C, D).Finally, let TerSeq ≤n (C) := T terminal Seq ≤n (C, T ).In other words, TerSeq ≤n (C) is the set of all reduction sequences from C which terminate in at most n steps (including 0 if C is terminal).For every terminating reduction sequence r = (C • • • T ), let End(r) := T , i.e.End(r) is simply the (terminal) endpoint of the sequence.For any configuration C, the sequence r∈TerSeq ≤n (C) tr(End(r)) n∈N is increasing with upper bound tr(C) (follows from Theorem 7).For any possible C, we define: Halt(C) := ∞ n=0 r∈TerSeq ≤n (C) tr(End(r))/tr(C) which is exactly the probability of termination of C.This is justified, because Halt(T ) = 1, for any terminal (and possible) configuration T and Halt(C) = C D D possible Pr(C D)Halt(D).We write * for the transitive closure of .

Fig. 5 :Example 8 .
Fig. 5: Example with lists of qubits and a recursive procedure.
xy) * = y * x * and (λx) * = λx * , for x, y ∈ A and λ ∈ C. A C*-algebra is a Banach * -algebra A which satisfies the C*-identity, i.e. x * x = x 2 for all x ∈ A. A C*-algebra A is unital if it has an element 1 ∈ A, such that for every x ∈ A : x1 = 1x = x.All C*-algebras in this paper are unital and for brevity we regard unitality as part of their definition.Example 10.The algebra M n (C) of n × n complex matrices is a C*-algebra.In particular, the set of complex numbers C has a C*-algebra structure since M 1 (C) = C.More generally, the n × n matrices valued in a C*-algebra A also form a C*-algebra M n (A).The C*-algebra of qubits is qbit := M 2 (C).
7.3].The coproduct of objects A and B is denoted by A + B and the coproduct injections are denoted left A,B : A → A + B and right A,B : B → A + B. Given morphisms f : A → C and g : B → C, we write [f, g] : A + B → C for the unique cocone morphism induced by the coproduct.Moreover, coproducts distribute over tensor products [1, §4.6].More specifically, there exists a natural isomorphism d A,B,C : A ⊗ (B + C) → (A ⊗ B) + (A ⊗ C) which satisfies the usual coherence conditions.The initial object in C is moreover a zero object and is denoted 0. The W*-algebra of bits is bit := I + I = C ⊕ C.

Example 16 .
The interpretation of the types from Example 1 are Nat = ω i=0 C and List

Corollary 25 .
Let M be a closed program of unit type, i.e. • ⊢ • M • .Then:

Lemma 37 .
(Finitary Strong Normalisation) For any finitary configuration C, there exists n ∈ N, such that the length of every reduction sequence from C is at most n.Corollary 38.For any finitary configuration C, we have C = C ⇓ .Proof.Using Lemma 37, let n ∈ N be the smallest number such that the length of every reduction sequence from C is at most n.It follows thatC = r∈TerSeq ≤n (C) End(r) ,which can be easily shown by induction on n using Theorem 36.The proof concludes by recognising that r∈TerSeq ≤n (C) define an approximation relation (− ⊏ −) between finitary configurations and ordinary configurations.It is defined to be the smallest relation satisfying the following rule:M ′ ◭ M Ω ′ ⊳ Ω (M ′ | V | Ω ′ | ρ) ⊏ (M | V | Ω | ρ) Remark 39.By definition, if (M ′ | V | Ω ′ | ρ) ⊏ (M | V | Ω | ρ), then M and M ′ do not contain any 0 subterms, nor do Ω and Ω ′ in any of their procedure bodies.We proceed with a lemma which shows the relation (− ⊏ −) approximates the ordinary operational semantics.But first, we introduce two new notions.Every terminal finitary configuration T is either of the form(skip | V | Ω | ρ) or (0 | V | Ω | ρ).In the former case we say T is a skip-configuration and in the latter case we say T is a 0-configuration.Lemma 40.Let C 0 be an ordinary configuration and C ′ 0 a finitary configuration withC ′ 0 ⊏ C 0 .Let r ′ = (C ′ 0 • • • C ′ n )be a terminal reduction sequence, where C ′ n is a skip-configuration.Then there exists a unique terminal reduction sequence r = (C 0• • • C n ) such that C ′ i ⊏ C i ,which we will henceforth abbreviate by writing r ′ ⊏ r.Proof.Let C ′ 0 = (M ′ | V ′ | Ω ′ | ρ ′ ).The proof follows by induction on n.The base case n = 0 is trivial and the step case follows by case distinction on M ′ .⊓ ⊔

Proof.
Straightforward induction.⊓ ⊔ Finally, we can prove Theorem 23.Proof of Theorem 23.By Corollary 35, it suffices to show C ≤ C ⇓ .We have: