<<

Applying quantitative semantics to higher-order quantum computing

Michele Pagani Peter Selinger Benoˆıt Valiron Universite´ Paris 13, Sorbonne Paris Cite´ Dalhousie University University of Pennsylvania Villetaneuse, France Halifax, Canada Philadelphia, U.S.A. [email protected] [email protected] [email protected]

Abstract Not surprisingly, the resulting finitary language permitted a fully Finding a denotational semantics for higher order quantum com- abstract semantics in terms of finite dimensional spaces; this was putation is a long-standing problem in the semantics of quantum hardly an acceptable solution to the general problem. The second programming languages. Most past approaches to this problem fell approach [12] was to construct a semantics of higher-order quan- short in one way or another, either limiting the language to an un- tum computation by methods from theory; specifically, by usably small finitary fragment, or giving up important features of applying a presheaf construction to a model of first-order quantum quantum physics such as entanglement. In this paper, we propose a computation. This indeed succeeds in yielding a model of the full denotational semantics for a quantum lambda calculus with recur- quantum lambda calculus, albeit without recursion. The main draw- sion and an infinite data type, using constructions from quantitative back of presheaf models is the absence of recursion, and the fact semantics of linear logic. that such models are relatively difficult to reason about. The third approach [6] was based on the Geometry of Interaction. Starting from a traced monoidal category of basic quantum operations, Ha- 1. Introduction suo and Hoshino applied a sequence of categorical constructions, Type theory and denotational semantics have been successfully which eventually yielded a model of higher-order quantum com- used to model, design, and reason about programming languages putation. The problem with this approach is that the tensor prod- for almost half a century. The application of such methods to uct constructed from the geometry-of-interaction construction does quantum computing is much more recent, going back only about not coincide with the tensor product of the underlying physical 10 years [16]. data types. Therefore, the model drops the possibility of entangled An important problem in the semantics of quantum computing states, and thereby fails to model one of the defining features of is how to combine quantum computing with higher-order functions, quantum computation. or in other words, how to design a functional quantum program- Our contribution. In this paper, we give a novel denotational ming language. A syntactic answer to this question was arguably semantics of higher-order quantum computation, based on meth- given with the design of the quantum lambda calculus [18, 21]. The ods from quantitative semantics. Quantitative semantics refers to quantum lambda calculus has a well-defined syntax and operational a family of semantics of linear logic that interpret proofs as linear semantics, with a strong type system and a practical type inference mappings between vector spaces (or more generally, modules), and algorithm. However, the question of how to give a denotational se- standard lambda-terms as power series. The original idea comes mantics to the quantum lambda calculus turned out to be difficult, from Girard’s normal functor semantics [4]. More recently, quan- and has remained open for many years [17, 20]. One reason that titative semantics has been used to give a solid, denotational se- designing such a semantics is difficult is that quantum computation mantics for various algebraic extensions of lambda-calculus, such is inherently defined on finite dimensional Hilbert spaces, whereas as probabilistic and differential lambda calculi (e.g. [1], [2]). the semantics of higher-order functional programming languages, One feature of our model is that it can represent infinite di- including such features as infinite data types and recursion, is in- mensional structures, and is expressive enough to describe recur- herently infinitary. sive types, such as lists of qubits, and to model recursion. This is In recent years, a number of solutions have been proposed to achieved by providing an exponential structure a` la linear logic. the problem of finding a denotational semantics of higher-order Unlike the Hasuo-Hoshino model, our model permits general en- quantum computation, with varying degrees of success. The first tanglement. We interpret (a minor variant of) the quantum lambda approach [19] was to restrict the language to strict linearity, mean- calculus in this model. Our main result is the adequacy of the model ing that each function had to use each argument exactly once, in with respect to the operational semantics. the spirit of linear logic. In this way, all infinitary concepts (such Outline. In Section2, we briefly review some background. Sec- as infinite types and recursion) were eliminated from the language. tion3 presents the version of the quantum lambda calculus that we use in this paper, including its operational semantics. Section4 re- calls the completion of certain categories under infinite biproducts. In Section5, we apply this construction to a specific category of completely positive maps. Section6 presents the denotational se- mantics of the quantum lambda calculus and proves the adequacy theorem. Finally, Section7 concludes with some properties of the representable elements.

[Paper accepted to POPL 2014 – Unrevised draft.]

1 2013/10/2 qubit 1: |φi • H 2.2 Density matrices and completely positive maps If we identify |0i and |1i with the standard basis vectors  1  and M 0 (i) (ii)  0  x,y 1 , the state of a qubit can be expressed as a two-dimensional qubit 2: |0i H • ⊕  α  vector v = α|0i + β|1i = β . Similarly, the state of an n-qubit system can be expressed as an 2n-dimensional column location A vector. Often, it is necessary to consider probability distributions qubit 3: |0i ⊕ on quantum states; these are also known as mixed states. Consider location B a quantum system that is in one of several states v1, . . . , vk with probabilities p1, . . . , pk, respectively. The density of this Uxy |φi mixed state is defined to be (iii) X ∗ A = pivivi . i Figure 1: The quantum teleportation protocol. By a theorem of Von Neumann, the density matrix is a good repre- sentation of mixed states, in the following sense: two mixed states 2. Background are indistinguishable by any physical experiment if and only if they have the same density matrix [15]. Note that tr A = p1 + ... + pk. 2.1 Quantum computation in a nutshell For our purposes, it is often convenient to permit sub-probability distributions, so that p1 + ... + pk 6 1. Quantum computation is a computational paradigm based on the n×n Let us write C for the space of n × n-matrices. Recall laws of quantum physics. We briefly recall some basic notions; n×n ∗ that a matrix A ∈ C is called positive if v Av > 0 for all please see [15] for a more complete treatment. The basic unit of n n×n information in quantum computation is a quantum bit or qubit, v ∈ C . Given A, B ∈ C , we write A v B iff B − A is positive; this is the so-called Lowner¨ partial order. A linear whose state is given by a normalized vector in the two-dimensional n×n m×m 2 2 map F : → is called positive if A w 0 implies Hilbert space C . It is customary to write the canonical basis of C C C {|0i, |1i} F (A) w 0, and completely positive if F ⊗ idk is positive for as , and to identify these basis vectors with the booleans k×k false and true, respectively. The state of a qubit can therefore be all k, where idk is the identity function on C . If F moreover thought of as a complex linear combination of booleans α|0i + satisfies tr(F (A)) 6 tr A for all positive A, then it is called β|1i, called a quantum superposition. More generally, the state of a superoperator. The density matrices are precisely the positive 2 2 matrices A of trace 1. Moreover, the superoperators correspond n qubits is an element of the n-fold tensor product C ⊗ ... ⊗ C . 6 There are three kinds of basic operations on quantum data: ini- precisely to those functions from mixed states to mixed states that tializations, unitary maps and measurements. Initialization prepares are physically possible [15, 16]. a new qubit in state |0i or |1i. A unitary map, or gate, is an in- 2.3 The category CPM vertible linear map U such that U ∗ = U −1; here U ∗ denotes the complex conjugate transpose of U. Finally, the operation of mea- The category CPMs is defined as follows: the objects are natural surement consumes a qubit and returns a classical bit. If n qubits numbers, and a F : n → m is a completely positive n×n m×m are in state α|0i⊗φ0 +β|1i⊗φ1, where φ0 and φ1 are normalized map F : C → C . Let CPM be the free completion of states of n − 1 qubits, then measuring the leftmost qubit will yield CPMs under finite biproducts; specifically, the objects of CPM are 2 false with probability |α| , leaving the remaining qubits in state φ0, sequences ~n = (n1, . . . , nk) of natural numbers, and a morphism and true with probability |β|2, leaving the remaining qubits in state F : ~n → ~m is a matrix (Fij ) of Fij : nj → mi of φ1. CPMs. The categories CPMs and CPM are symmetric monoidal, and in fact, compact closed [16]. Example 1. A small algorithm is the simulation of an unbiased coin toss: initialize one quantum bit to |0i, apply the Hadamard gate 2.4 Limitations of CPM as a model sending |0i to √1 (|0i+|1i) and |1i to √1 (|0i−|1i), then measure. 2 2 The category CPM can serve as a fully abstract model for a simple, 1 1 The result is true with probability 2 and false with probability 2 . strictly linear, finitary quantum lambda calculus [19]. For example, the type bit is interpreted as (1, 1), and the type qubit is inter- Example 2. A slightly more involved algorithm is the quantum preted as (2). Measurement, as a map from qubit to bit, sends teleportation algorithm a b (see [15] for details). The procedure is ( c d ) to (a, d). The coin toss is a map (1) → (1, 1) sending (p) summarized in Figure1. Wires represent the path of quantum bits p p to ( 2 , 2 ). Function spaces are interpreted via the compact closed in the computation, and time flows from left to right. The gate H structure. • stands for an application of the Hadamard gate, whereas the gate ⊕ As mentioned in the introduction, the semantics of [19] is ex- is a controlled-not: it flips the bottom qubit if the upper one is in tremely limited, because it is completely finitary. Thus recursion, state |1i. The box M is a measurement. The unitaries Uxy are infinite data types, and non-linear functions (i.e., those that can use their argument more than once) had to be completely removed from U = ( 1 0 ) ,U = ( 0 1 ) ,U = ( 1 0 ) ,U = ( 0 1 ) . 00 0 1 01 1 0 10 0 -1 11 -1 0 the language in order to fit the model. For example, even the sim- The goal is to send a quantum bit in an unknown state |φi from ple squaring function f 7→ λx.f(f x) is not representable in CPM. Location A to Location B using two classical bits. The procedure Similarly, CPM cannot express infinite types, such as the type of can be reversed to send two classical bits using a quantum bit. In lists of qubits. this case it is called the dense coding algorithm [15]. The purpose of the present paper is to remove all of these The algorithm consists in three parts. In (i), two quantum bits restrictions. As an example, consider the following pseudo-code (qubits 2 and 3) are entangled in state √1 (|00i + |11i). In (ii), (in ML-style): 2 the input qubit 1 in state |φi is entangled with qubit 2, then both val qlist : qubit -> qubit list are measured. The result is sent over location B, where in (iii) an let rec qlist q = if (cointoss ()) then q correction Uxy is applied on qubit 3, setting it to state |φi. else let (x,y) = entangle q in x::(f y)

2 2013/10/2 By convention, is associative to the right, while application Terms M,N,P ::= ( and tensor are associative to the left. We use the notation A⊗n for A x λxA.M MN skip M;N tensored n times. The type A` denotes finite lists of type A. When ` A B doing structural induction on types, we assume that A is greater M ⊗ N let x ⊗ y = M in N ⊗n than A , for any n ∈ N. A B in` M inr M match P with (x : M|y : N) The set of terms and types is somewhat spartan; however it can be easily extended by introducing syntactic sugar. Note that, for splitA letrec f A(B x = M inN meas new U technical convenience, we have only allowed types of the form !A when A is an arrow type. However, for an arbitrary type A, the type Values V,W ::= !A can be simulated by using !(1 ( A) instead. A x c λx .M V ⊗ W in` V inr W Notation 3. We write bit = 1 ⊕ 1, tt = inr skip, ff = in` skip, nil = in` skip and M :: N = inr (M ⊗N). We write Types A, B, C ::= λskip.M for the term λz1.(z;M), where z is a fresh variable, and ` P M N P (x1 : N|y1 : M) qubit A(B !(A(B) 1 A⊗B A⊕B A . if then else for match with . A context ∆ is a function from a finite set of variables to types. Table 1: Grammars of terms, values and types. We denote the domain of ∆ by |∆|, and we write ∆ = x1 : A1, . . . , xn : An whenever |∆| = {x1, . . . , xn} and ∆(xi) = Ai. We call ∆ exponential (resp. linear) whenever all Ai are !- Here, the function cointoss is a fair coin toss, and the function types (resp. no Ai is a !-type). We write !∆ for a context which entangle sends α|0i + β|1i to α|00i + β|11i. is exponential. The notation Γ, Σ refers to the union of the two So if the function qlist is applied to a qubit α|0i + β|1i, contexts Γ and Σ and assumes that |Γ| and |Σ| are disjoint. 1 the output is α|0i + β|1i with probability 2 , α|00i + β|11i with A judgement is a triple Γ ` M : A of a context Γ, a term M 1 1 and a type A. A judgement is called valid if it can be inferred from probability 4 , α|000i + β|111i with probability 8 , and so on. Its semantics should be of type 2 → (2, 4, 8,...), mapping the typing rules in Figure2, using the convention that the contexts Γ and Σ are linear.   a 0 0 b   a b 1 a b 1 0 0 0 0 ( c d ) 7→ ( c d ) , 0 0 0 0 ,... . Proposition 4. There is at most one derivation inferring a given 2 4 c 0 0 d typing judgement Γ ` M : A. The category CPM is “almost” capable of handling this case, but not quite, because it cannot express infinite tuples of matrices. The Example 5. In Section 2.4, we wrote the informal program qlist. model we propose in this paper is essentially an extension of CPM Our language is expressive enough to represent it. The term to infinite biproducts, using methods developed in [5,9, 10, 14]. cointoss can be defined as meas(H(new tt)), and it has type qubit bit. The term entangle is λx .Nc(x ⊗ (new ff)), which has 3. A quantum lambda calculus type qubit ( qubit ⊗ qubit. Then, qlist is We define a typed quantum lambda calculus that is a variant of ` letrec f qubit(qubit q = the quantum lambda calculus previously defined in [20]. The main difference is that the language in this present paper is a true exten- if cointoss then q :: nil sion of linear logic (see the type assignment system of Table2). else let xqubit ⊗ yqubit = entangle q in x :: fy In particular, in contrast with [20], !(A ⊗ B) ( !A ⊗ !B is not ` provable and there is no need for a subtyping relation. The opera- which has type qubit ( qubit . In Examples9 and 30 we tional semantics implements a call-by-value strategy. An untyped discuss its operational and denotational semantics, respectively. call-by-name variant has been studied in [8]. The classes of terms, values and types are defined in Table1. Example 6. In Example2 and Figure1, we sketched the quantum The symbol c ranges over the set of term constants {skip, splitA, teleportation algorithm. We said that the algorithm can be decom- meas, new,U}. The constant U ranges over a set of elementary posed in 3 parts. Each of these parts can be described and typed in unitary transformations on quantum bits. In the examples below, the quantum lambda-calculus, yielding a higher-order term. This is we will be using the Hadamard gate H and the controlled-not gate an adaptation of an example provided in [18]. N , defined as follows [15]: c (i) generates an EPR pair of entangled quantum bits. Its type is  1 0 0 0  1 1 1  0 1 0 0 therefore 1 ( qubit ⊗ qubit. The corresponding term is H = √ 1 −1 Nc = 0 0 0 1 (1) 2 0 0 1 0 EPR = λskip.Nc(H(new ff)) ⊗ (new ff). Notice that bound variables are given in Church-style, i.e., with a type annotation. This allows Proposition4, and simplifies the se- (ii) performs a Bell measurement on two quantum bits and outputs mantic interpretation of the typed terms. We omit such annotations two classical bits x, y. Its type is thus qubit ( qubit ( in the sequel if uninteresting or obvious. bit ⊗ bit, and the term BellMeasure is defined as We have two kinds of arrows: the linear arrow A(B, and the  let x ⊗ y = N (q ⊗ q )  λq .λq . c 1 2 . intuitionistic arrow !(A ( B), which is obtained by the call-by- 1 2 in (meas (H x)) ⊗ (meas y) value translation of the intuitionistic implication into linear logic [3]. Intuitively, only the terms of type !(A ( B) represent func- (iii) performs a correction. It takes one quantum bit, two classical tions that can be iterated, whereas terms of type A(B must be bits, and outputs a quantum bit. It has a type of the form used at most once. A type of the form !A is called a !-type or non- qubit ( bit ⊗ bit ( qubit. The term is linear type, and all other types are called linear. The distinction between linear and non-linear types is crucial for allowing the type U = λq.λx ⊗ y.if x then (if y then U11 q else U10 q) system to enforce the no-cloning property of quantum physics. else (if y then U01 q else U00 q).

3 2013/10/2 A linear A linear !∆ ` V : AV value ax axd p 1I !∆, x : A ` x : A !∆, x :!A ` x : A !∆ ` V :!A !∆ ` skip : 1

∆, x : A ` M : B !∆, Γ ` M : A B !∆, Σ ` N : A !∆, Γ ` M : 1 !∆, Σ ` N : A I ( A ( (E 1E ∆ ` λx .M : A ( B !∆, Γ, Σ ` MN : B !∆, Γ, Σ ` M;N : A

!∆, Γ ` M : A !∆, Σ ` N : B !∆, Γ ` M : A ⊗ B !∆, Σ, x : A, y : B ` N : C ⊗ ⊗E !∆, Γ, Σ ` M ⊗ N : A ⊗ B I !∆, Γ, Σ ` let xA ⊗ yB = M in N : C

!∆, Σ, y : B ` N : C !∆, Γ ` P : A ⊕ B !∆, Σ, x : A ` M : C !∆, Γ ` M : A !∆, Γ ` M : B r ` ⊕E ⊕I ⊕I A B !∆, Γ ` in` M : A ⊕ B !∆, Γ ` inr M : A ⊕ B !∆, Γ, Σ ` match P with (x : M|y : N): C

!∆, Γ ` M : 1 ⊕ (A⊗A`) !∆, f : !(A B), x : A ` M : B !∆, Γ, f : !(A B) ` N : C ` split ( ( rec ` −I A ` ` A B !∆, Γ ` M : A !∆ ` split : A (1 ⊕ (A⊗A ) !∆, Γ ` letrec f ( x = M in N : C

U of arity n meas new ⊗n ⊗n U !∆ ` meas : qubit ( bit !∆ ` new : bit ( qubit !∆ ` U : qubit ( qubit

Table 2: Typing rules. The contexts Γ and Σ are assumed to be linear. In the p-rule A is assumed to be an arrow type.

We can now write the term x1 : qubit, . . . , xn : qubit ` M : A. In case ` = |x1, . . . , xni we can also write ` ` M : A. telep = λskip.let x ⊗ y = EPR skip in let f = BellMeasure x in The purpose of a quantum closure is to provide a mechanism let g = U y to talk about terms with embedded quantum data. The idea is that in f ⊗ g. a variable y ∈ FV(M) is bound in the closure [q, `, M] to qubit number `(y) of the quantum state q. So for example, the quantum It can then be shown that closure ` telep :!(1 (qubit bit⊗bit)⊗(bit⊗bit qubit)) 1 A ( ( ( [ √ (|00i + |11i), |x1, x2i, λy .yx1x2] 2 is a valid typing judgement. A In other words, the teleportation algorithm produces a pair of denotes a term λy .yx1x2 with two embedded qubits x1, x2 in the entangled state |x x i = √1 (|00i + |11i). entangled functions f : qubit → bit ⊗ bit and g : bit ⊗ bit → 1 2 2 qubit. These functions have the property that g(f(|φi)) = |φi Numbering of qubits in the state starts at 1. The notion of α- for all qubits |φi, and f(g(x ⊗ y)) = (x ⊗ y) for all booleans x equivalence extends naturally to quantum closures, for instance, the and y. These two functions are each other’s inverse, but because states [q, |xi, λyA.x] and [q, |zi, λyA.z] are equivalent. From now they contain an embedded qubit each, they can only be used once. on, we tacitly identify quantum closures up to renaming of bound They can be said to form a “single-use ” between the variables. (otherwise non-isomorphic) types qubit and bit ⊗ bit. However, The evaluation of a term is defined as a probabilistic rewriting the whole procedure is duplicable: one can generate as many one- procedure on quantum closures, using a call-by-value reduction p time-use isomorphism pairs as desired. strategy. We use the notation [q, `, M] → [q0, `0,M 0] to mean that the left-hand side closure reduces in one step to the right-hand side 3.1 Operational semantics with probability p ∈ [0, 1]. The operational semantics is defined in terms of an abstract ma- Definition 8. The reduction rules are shown in Table3. The rules chine simulating the behavior of Knill’s QRAM model. It is similar split into three categories: (a) rules handling the classical part of the to the semantics given in [20]. calculus; (b) rules dealing with quantum data; and (c) congruence Definition 7. A quantum closure is a triple [q, `, M] where rules for the call-by-value strategy. Note that in the statement of the rules, V and W refer to values. 2n • q is a normalized vector of C , for some integer n > 0. The In the rules in Table3(b), the quantum state q has size n. vector q is called the quantum state; The quantum state q0 in the first rule is obtained by applying the • M is a term, not necessarily closed; k-ary unitary gate U to the qubits `(x1), . . . , `(xk). Precisely, 0 −1 2n • ` is a one-to-one map from the set of free variables of M to the q = (σ ◦ U ⊗ id ◦σ )(q), where σ is the action on C of set {1, . . . , n}. It is called the linking function. any permutation over {1, . . . , n} such that σ(i) = `(xi) whenever We write |`| for the domain of `. By abuse of language we may i 6 k. In the rules about measurements, we assume that if q0 and call a closure [q, `, V ] a value when the term V is a value. We q1 are normalized quantum states of the form denote the set of quantum closures by Cl and the set of quantum P 0 0 P 1 1 j αj |φj i ⊗ |0i ⊗ |ψj i, j αj |φj i ⊗ |1i ⊗ |ψj i, (2) closures that are values by Val. We write `| for the linking M 0 0 function whose domain is restricted to the set of free variables of then q0 and q1 are respectively M. We say that the quantum closure [q, `, M] is total when |`| P 0 0 P 1 1 αj |φj i ⊗ |ψj i, αj |φj i ⊗ |ψj i, (3) has cardinality n, the size of the quantum state. In that case, if j j 0 1 |`| = {x1, . . . , xn} and `(xi) = i, we write ` as |x1, . . . , xni. where the vectors φj and φj have dimension `(x) − 1 (so that the A quantum closure [q, |x1, . . . , xni,M] has a type A, whenever measured qubit is `(x)).

4 2013/10/2 [q, `, (λxA.M) V ] →1 [q, `, M{V/x}][q, `, let xA ⊗ yB = V ⊗ W in N] →1 [q, `, N{V/x, W/y}] 1 A B 1 [q, `, skip;N] → [q, `, N][q, `, match (in` V ) with (x : M|y : N)] → [q, `, M{V/x}] 1 A B 1 [q, `, splitV ] → [q, `, V ][q, `, match (inr V ) with (x : M|y : N)] → [q, `, N{V/y}] [q, `, letrec f A(B x = M in N] →1 [q, `, N{(λxA.letrec f A(B x = M in M)/f}]

(a) Classical control.

1 0 [q, `, U(x1 ⊗ · · · ⊗ xk)] → [q , `, x1 ⊗ · · · ⊗ xk] 2 1 |β| 0 [q, ∅, new ff] → [q ⊗ |0i, {y 7→ n + 1}, y][αq0 + βq1, {x 7→ i}, meas x] −−→ [q1, ∅, tt] 2 1 |α| 0 [q, ∅, new tt] → [q ⊗ |1i, {y 7→ n + 1}, y][αq0 + βq1, {x 7→ i}, meas x] −−−→ [q0, ∅, ff] (b) Quantum data. The variable y is fresh.

p 0 0 0 p 0 0 0 p 0 0 0 [q, `, MN] → [q , ` ,M N][q, `, M ⊗ N] → [q , ` ,M ⊗ N][q, `, in` M] → [q , ` , in` M ] p 0 0 0 p 0 0 0 p 0 0 0 [q, `, V M] → [q , ` ,VM ][q, `, V ⊗ M] → [q , ` ,V ⊗ M ][q, `, inr M] → [q , ` , inr M ] p p [q, `, M;N] → [q0, `0,M 0;N][q, `, let xA ⊗ yB = M in N] → [q0, `0, let xA ⊗ yB = M 0 in N] p [q, `, match M with (xA : P |yB : N)] → [q0, `0, match M 0 with (xA : P |yB : N)]

0 0 p 0 0 0 (c) Congruence rules, under the hypothesis that for some `0 we have ` = `0 ] `|M , ` = `0 ] ` |M0 and [q, `|M ,M]→[q , ` |M0 ,M ].

Table 3: Reduction rules on closures.

p Note that the only probabilistic reduction step is the one cor- Proposition 11 (Subject reduction). When [q, |y1 . . . yni,M] → 0 0 responding to measurement. Also, we underline that the hypothe- [q , |x1 . . . xn0 i,M ] and y1 : qubit, . . . , yn : qubit ` M : A, p 0 0 0 0 sis associated with a congruence rule [q, `, C[M]]→[q , ` ,C[M ]] then x1 : qubit, . . . , xn0 : qubit ` M : A. takes into account the whole quantum states q and q0. In fact, be- cause of the entanglement, the evaluation of [q, `|M ,M] may have a side-effect on the state of the qubits pointed by the variables oc- Proof. The proof is done by structural induction on the reduction p 0 0 curring in the context C[]. [q, |y1 . . . yni,M] → [q , |x1 . . . xn0 i,M ], using Lemma 10 for The rules assume that the involved closures are well-defined. the cases where substitution occurs. p In particular, whenever [q, `, M] → [q, `, M 0], the two terms M and M 0 have the same free variables. For example, the closure [|00i, |yzi, (λx.y)z] cannot reduce and it represents an error. The Proposition 12 (Type safety). If [q, `, M] is typable then either M p type system will prevent such an error as proven in Proposition 12. is a value or there is a closure [q0, `0,M 0] such that [q, `, M] → 0 0 0 1 [q , ` ,M ]. Moreover, if M is not a value, the total probability of Example 9. Recall Example5. We have [|i, |i, cointoss] → all possible single-step reductions from [q, `, M] is 1. 1 [|1i, |xi, meas(Hx)] → [ √1 (|0i + |1i), |xi, meas x], the latter 2 reducing to either [|i, |i, tt] or [|i, |i, ff], with equal probability 1 Proof. By induction on a typing derivation of M. 2 . As for entangle, we have that [α|0i + β|1i, |xi, entangle x] p 0 0 0 1 Lemma 13 (Totality). If [q, `, M] → [q , ` ,M ] and [q, `, M] is → [α|0i + β|1i, |xi,N (x ⊗ (new ff))] c total, then [q0, `0,M 0] is total too. 1 → [α|00i + β|10i, |xyi,Nc(x ⊗ y)] 1 p → [α|00i + β|11i, |xyi, x ⊗ y]. Proof. By induction on a derivation of [q, `, M] → [q0, `0,M 0], Similarly, one can check that [α|0i + β|1i, |qi, qlist q] behaves one proves that as described in Section 2.4, reducing to [α|0i + β|1i, |qi, q :: nil] 0 0 1 0 0 dim(q ) = dim(q) + dim(` ) − dim(`) with probability 2 , to [α|00i + β|11i, |qq i, q :: q :: nil] with 1 probability 4 , etc. In particular, notice that in any single reduc- where dim(q) is the size of the quantum state q and dim(`) is the tion sequence the variable q has not been duplicated, as correctly cardinality of the domain set of the linking function `. Then, one asserted by the type of qlist. gets the statement, since [q, `, M] is total iff dim(q) = dim(`). Lemma 10 (Substitution). Suppose !∆, Γ, x : A ` M : B and !∆, Σ ` V : A, where Γ and Σ are linear contexts with disjoint domain. Then !∆, Γ, Σ ` M{V/x} : B. 3.2 Reduction system as a Markov chain The reduction relation → defines the probability that a closure Proof. By induction on the derivation of !∆, Γ, x : A ` M : B reduces to another one in a single step. In order to extend it to an (which is unique by Proposition4). arbitrary large (but finite) number of reduction steps, we present the reduction relation as a Markov process over the set of closures, following the spirit of [1].

5 2013/10/2 Definition 14. We define an infinite matrix Red ∈ [0, 1]Cl×Cl indexed sum over a homset C(A, B) as componentwise: X _ X f := ( f). (6)  p 0 0 0 F ⊆finS p if [q, `, M] → [q , ` ,M ], f∈S f∈F  0 0 0 1 if [q, `, M] = [q , ` ,M ] and ⊕ Red 0 0 0 := Definition 15. An object A of C is a pair (|A|, (Aa)a∈|A|) of [q,`,M],[q ,` ,M ] M is a value,  a (possibly infinite) set of indexes |A|, called the web of A, and 0 otherwise. a |A|-family of objects in C. The homset C⊕(A, B) is the set of the |A| × |B| matrices of morphisms φ = (φa,b)(a,b)∈|A|×|B| in Note that Red is well-defined: for any two quantum clo- ⊕ ⊕ 0 0 0 C. Given φ ∈ C (A, B) and ψ ∈ C (B, C), the (diagrammatic) sures [q, `, M] and [q , ` ,M ] there is at most one p such that P p 0 0 0 composition φ ; ψ is the matrix product: (φ ; ψ)a,c = b∈|B| φa,b ; [q, `, M] → [q , ` ,M ]. Red is a stochastic matrix: for all clo- 0 P ψb,c. The identity is the diagonal matrix ida,a0 := idAa if a = a , sures [q, `, M], 0 6 [q0,`0,M0]∈Cl Red[q,`,M],[q0,`0,M0] 6 1. 0 and ida,a0 := 0 if a 6= a . Intuitively, the value of Red[q,`,M],[q0,`0,M0] describes the prob- 0 0 0 ability of evolving from the state [q, `, M] to the state [q , ` ,M ] 4.1 The linear structure in one step. 4.1.1 Biproduct A closure [q, `, M] is absorbing whenever Red[q,`,M],[q,`,M] = 1: the absorbing states are those which are invariant under the The category C⊕ is the free biproduct completion of C. The bi- L ⊕ transition matrix. In particular, values are all absorbing. (Note that product i∈I Ai of a family (Ai)i∈I of objects in C is defined there are absorbing terms which are not values, such as [|i, |i, Ω], L S L  by | i∈I Ai| := i∈I {i} × |Ai| and i∈I Ai := (Aj )a. with Ω the total diverging term letrec f x = fx in f skip). (j,a) n The corresponding projections and injections are denoted respec- The n-th power Red of the matrix Red is a stochastic ma- j j tively by π and ι . The tupling hφiii∈I (resp. (co)-tupling [ψi]i∈I ) trix on Cl (in case n = 0, we have the identity matrix on Cl). ⊕ n of a family of morphisms φi elements of C (A, Bi) (resp. ψi ele- Intuitively, the value of Red[q,`,M],[q0,`0,M0] is the probability of ⊕ ments of C (Ai, B)) is defined by (hφiii∈I )a,(i,b) := (φi)a,b and evolving from the state [q, `, M] to the state [q0, `0,M 0] in exactly ([ψi]i∈I ) := (ψi)a,b. n steps. In particular, if [q0, `0,V ] is a value then the sequence (i,a),b n {Red[q,`,M],[q0,`0,V ]}n∈N is monotonically increasing. 4.1.2 Monoidal product ∞ Cl×Val We then can define the matrix Red in [0, 1] as follows: The bifunctor ⊗ : C⊕ × C⊕ → C⊕ is defined on objects A, B by ∞ ∞ n  |A ⊗ B| := |A| × |B| and (A ⊗ B)(a,b) := Aa ⊗ Bb, where the Red[q,`,M],[q0,`0,V ] := sup Red[q,`,M],[q0,`0,V ] . (4) n=0 ⊗ in the right-hand side of the second equation is that of the cate- ∞ gory C. The tensor unit is the singleton web space ({∗}, 1), where The element Red[q,`,M],[q0,`0,V ] is the probability that [q, `, M] 0 0 1 is the tensor unit of C. By abuse of notation we will also de- reaches a value [q , ` ,V ] in an arbitrary number of steps. Finally, note the unit of C⊕ by 1. The action of ⊗ on morphisms is defined we define the probability that [q, `, M] reduces to some value as componentwise, and similarly for the associativity, unit, and sym- A,B,C X ∞ metry . E.g., the associator is α 0 0 0 = Halt[q,`,M] := Red[q,`,M],[q0,`0,V ] . (5) ((a,b),c),(a ,(b ,c )) Aa,Bb,Cc Aa,Bb,Cc [q0,`0,V ]∈Val δa,a0 δb,b0 δc,c0 α , where α is the associator in C and δa,a0 is the Kronecker delta. Notice the n-fold tensor product A⊗n of an object A can be 4. Infinite biproduct completion ⊗n represented by |A | := {(a1, . . . , an) | ∀i 6 n, ai ∈ |A|} and ⊗n In this section, we recall the definition of the infinite biproduct A := Aa ⊗· · ·⊗Aa . The group Sn of permutations on ⊕ (a1,...,an) 1 n completion C of a symmetric monoidal closed linear continuous ⊗n {1, . . . , n} gives the n! symmetries of A , namely σ ∈ Sn can R-category C (Definition 15). We also recall how C gives (under be seen as the symmetry certain hypotheses) a Lafont category, which is a model of intu- Aa ,...,Aa itionistic linear logic (Proposition 18). This construction is known: σ 0 0 := δ 0 . . . δ 0 σ 1 n , (a1,...,an),(a1,...,an) a1,a an,a it was sketched in [5] and detailed in [9, 10, 13, 14]. In particular, σ(1) σ(n) Aa1 ,...,Aan [10] gives the definition of linear continuous R-category that we where σ is the symmetry in C between Aa1 ⊗· · ·⊗Aan use here. Our contribution is in applying such a construction to a and Aaσ(1) ⊗ · · · ⊗ Aaσ(n) . category useful for interpreting quantum data types (Section5). Tensor product distributes over biproducts. The isomorphism L L Consider a continuous commutative semiring R. This is a com- between ( i∈I Ai) ⊗ B and i∈I (Ai ⊗ B) is mutative semiring (|R|, 0, 1, +, ·) equipped with an order rela- Aa⊗Bb tion ≺ such that 0 is the minimum, any directed set D ⊆ |R| distr((i,a),b),(i0,(a0,b0)) := δi,i0 δa,a0 δb,b0 id . has a sup W, and + and · are continuous, i.e., monotone and W(r + D) = r + W D and W(r · D) = r · W D. The letters 4.1.3 Monoidal closure p, q, r range over |R|. The internal hom object is defined as |A ( B| := |A| × |B| and We say that a symmetric monoidal closed category C is a linear (A ( B)(a,b) := Aa ( Bb, where Aa ( Bb is the internal continuous R-category whenever: (i) every homset is endowed hom in C. For every pair of objects A, B, the evaluation morphism A,B ⊕ with a structure of module over the semiring R; (ii) composition Eval : C ((A ( B)⊗A, B) is defined componentwise, using 0 0 0 0 Aa,Bb and tensor are bilinear, that is (pf + p f );(qg + q g ) is equal to the evaluation morphism eval in C((Aa ( Bb) ⊗ Aa, Bb). ⊕ ⊕ 0 0 0 0 0 0 0 0 The isomorphism from C (C ⊗ A, B) to C (C, A B) is (p · q)(f ; g) + (p · q )(f ; g ) + (p · q)(f ; g) + (p · q )(f ; g ), ( denoted by Λ(−) and its inverse by App(−). and the same for ⊗; (iii) every homset is endowed with a structure Proposition 16. The category C⊕ endowed with the above struc- of complete partial order with 0 as the minimum and composition, ture is symmetric monoidal closed. ⊗, addition and scalar multiplication continuous. From now on, C denotes a symmetric monoidal closed linear Similarly, it is easy to check that C⊕ also inherits the ?-autono- continuous R-category. In that case, notice that we can define the mous (resp. compact closed) structure of C.

6 2013/10/2 Proposition 17.C ⊕ is a linear continuous R-category with the exactly one solution by the freeness of the exponential comonoid on pointwise R-module operations and order, e.g., (φ + ψ)a,b = B. Weakening gives the counit. The co-multiplication (also called ⊕ φa,b + ψa,b. digging) is the unique comonoid morphism dig ∈ C (!A, !!A) such that dig ; d = id. Finally, the last two morphisms which are 4.2 Exponential structure essential to interpret our calculus are Bierman’s m⊗ ∈ C⊕(!A ⊗ 1 ⊕ A symmetric monoidal closed category with finite products, such !B, !(A⊗B)) and m ∈ C (1, !1) which are the unique comonoid that each object has a corresponding free commutative comonoid, morphisms such that m⊗ ; d = d ⊗ d and m1 ; d = id1. is called a Lafont category, which is known to be a model of intuitionistic linear logic [7, 13]. n An 5. Completing CPM We say that the n-th (symmetric) power (A , eq ) of an ⊕ object A of a symmetric monoidal category is the equalizer of We want to apply the general construction C to a category C the n! symmetries of the n-ary tensor A⊗n, provided that such an which is useful for interpreting quantum data types. One natural n equalizer exists. That is, eqA is a morphism from An to A⊗n choice would be to consider the category CPM of completely pos- ⊗n itive maps [16]. However, CPM misses two essential requirements equalizing the symmetries of A (i.e., for every permutation σ ∈ ⊕ n n for producing CPM . First, CPM does not have the equalizers of S , eqA ; σ = eqA ), enjoying the following universal property: n the tensor symmetries. Second, the homsets of CPM are not con- for every object D and morphism f from D to A⊗n equalizing the tinuous with respect to the Lowner¨ order, i.e., not every directed symmetries of A⊗n, there exists a unique morphism f † such that n subset has a sup. f † ; eqA = f . We will therefore recast this category into CPMs, the category n σ eqA 1 of completely positive maps on positive matrices with symmetries An / A⊗n / A⊗n (7) and a ∞ morphism completing the Lowner¨ order on completely O < σ / f n! positive maps. unique f † 5.1 Complete positive maps with symmetries and top D n×n Any permutation g ∈ Sn gives rise to a matrix Pg ∈ C , defined n An Moreover, we say that (A , eq ) preserves the monoidal product by Pg(ei) = eg(i), where ei is the ith standard basis vector. We n An B n×n −1 whenever for every object B, the pair (A ⊗ B, eq ⊗ id ) is define an action of g on C by g ·A := PgAPg . Moreover, for 1 P the equalizer of the diagram obtained from the diagram equalized a subgroup G ⊆ Sn, we define G · A := g · A, where n #G g∈G by (An, eqA ) by replacing each object A with A ⊗ B and each #G is the number of elements of G. B arrow f by f ⊗ id . n×n Lemma 19. Given a subgroup G ⊆ Sn, its action on C is Proposition 18 (Folklore, cf. [5, 14]).C ⊕ is a Lafont category idempotent (i.e., G ; G = G) and completely positive. whenever the category C has the n-th power for every n ∈ N and object A, and this power preserves the monoidal product. Proof. For the idempotence, notice that for every g ∈ G, Gg = G, 1 P ⊕ n An therefore: G · G · A = Gg · A = G · A The complete Namely, one proves that C inherits the n-th powers (A , eq ) #G g∈G from C. Then, the free commutative comonoid !A of an object A is positivity of G is derived from the complete positivity of each defined as L An. element g ∈ G, when considered as a morphism. Indeed, any map n of the form A 7→ SAS−1 is completely positive, and therefore For later reference, we give a concrete presentation of !A: −1 so is A 7→ g · A = PgAPg . Moreover, non-negative linear O µ(a) |!A| := Mf (|A|), (!A)µ := Aa , (8) combination of completely positive maps is completely positive, 1 P a∈|µ| and therefore G = #G g∈G g is completely positive. where Mf (|A|) is the set of the finite multisets of |A|, µ(a) is the number of occurrences of a in µ, |µ| is the support of the multi- In the sequel, we use the notation G both for a subgroup of Sn µ(a) and for the completely positive map defined by it. set µ, i.e., |µ| := {a ∈ |A| ; µ(a) 6= 0}, the object Aa is N µ(a) We can now define the category CPMs which is essentially a the µ(a)-th power in C of Aa. Finally, the object Aa a∈|µ| sub-category of the Karoubi envelope of the completion of CPMs, µ(a) denotes the tensor of the spaces Aa . This is well-defined up to continuous with respect to the Lowner¨ ordering on positive matri- isomorphism; for example, it can be defined by arbitrarily fixing ces. In fact, the idea of using the Karoubi construction for getting an order on the elements of |A|. The counit, here called weak- the tensor powers follows [9]. ⊕ 1 1 ening w ∈ C (!A, 1), is wµ,∗ := δµ,[] id , where id is the identity of 1 in C. The co-multiplication, here called contraction Definition 20. The category CPMs of completely positive maps ⊕ µ0,µ00 with symmetries and top has as objects pairs (n, G) where n ∈ N c ∈ C (!A, !A ⊗ !A), is given by cµ,(µ0,µ00) = δµ,µ0+µ00 c , and G is a subgroup of Sn. A morphism f from (n, G) to (m, H) µ0,µ00 where c is the unique morphism in C satisfying the equa- is either a completely positive map from n×n to m×m such that 0 00 µ0 µ00 µ µ C C tion cµ ,µ ; eqA ⊗ eqA = eqA ;σ, with eqA be the equal- G ; f ; H = f, or the constant ∞. The identity of (n, G) is G N ⊗µ(a) N a and the composition is the functional composition on completely izer of the symmetries of a∈|µ| Aa of the shape a∈|µ| σ 0 00 positive maps, or is given by the equations ∞ ; g = ∞ = f ; ∞ if a Aµ Aµ with σ ∈ Sµ(a) (and similarly for eq and eq ). Notice that f, g 6= 0, and ∞ ; 0 = 0 = 0 ; ∞. + such equalizers exist by the hypothesis that the powers of C pre- Let R+ = R ∪ {∞} be the continuous completion of the ⊕ + serve the monoidal product. Last, the dereliction d ∈ C (!A, A) is semiring R with respect to the canonical ordering on reals, with Aa dµ,a := δµ,[a] id . 0 · ∞ = 0. Note that R+ is a continuous semiring. The linear exponential comonad is given as usual for Lafont categories. The functorial promotion maps an object A to !A and Remark 21. The category CPMs is a linear continuous R+- a morphism φ ∈ C⊕(A, B) to the unique comonoid morphism category, continuous with respect to the Lowner¨ order v on positive !φ ∈ C⊕(!A, !B) satisfying the equation d ; φ = !φ ; d, which has maps enriched with ∞ as the maximum element.

7 2013/10/2 Proposition 22. The category CPMs inherits the symmetric mono- N × N). In general, notice that all constructions of the Lafont cate- idal closed structure of CPM. gory preserve the underlined CPMs space (1, {id}) and act only at the level of webs. Proof. The object (n, G) ⊗ (m, H) is defined as (nm, G ⊗ H), For more involved examples, one should look for objects nm,nm n×m,n×m with larger dimensions, like qubit := {(2, {id})∗}. In fact, we where we use the isomorphism C = C obtained ⊗2 2 by the lexicographic order on the pairs (i, j) ∈ n × m, and G ⊗ H have qubit := {(4, {id})∗}, while the 2-power qubit is {(4, { , σ}) } 4 is intended to be the subgroup of Snm of the permutations of the id ∗ , where is represented as the lexicographically or- dered set {(0, 0), (0, 1), (1, 0), (1, 1)} and the permutation σ acts form g ⊗ h, with g ∈ G, h ∈ H acting as (i, j) 7→ (g(i), h(j)). 0 0 The tensor unit is 1 = (1, {id}). Symmetry, unit, and associativity on it by (b, b ) 7→ (b , b) (cf. the proof of Lemma 23). The group maps are obtained from those of CPM by pre-composing and of permutations {id, σ} shrinks the set of possible morphisms to 2 post-composing with the actions of the groups of the objects. The or from qubit . For example, the matrix Nc associated with the homset (n, G) (m, H) is equal to the tensor (nm, G ⊗ H) and controlled-not gate (Equation (1)) defines a complete positive endo- ( 4×4 ⊗2 the morphism eval is again inherited from CPM. Concretely, given map of C , which is an endo-morphism of qubit but not of n×m,n×m n×n 2 F ∈ C and N ∈ C , eval(F ⊗ N) is the matrix in qubit , because Nc is not invariant under the action of {id, σ}: m×m 0 C defined at the coordinate (j, j ) ∈ m × m by  2 0 0 0  1 1 0 1 0 1 {id, σ}(Nc) = (id(Nc) + σ(Nc)) = 0 0 1 1 6= Nc. 1 X X X 2 2 0 1 1 0 F 0 0 N 0 . #G#H (i,h(j)),(i ,h(j )) g(i),g(i ) g∈G h∈H (i,i0)∈n×n Concerning biproducts, the object qubit ⊕ qubit is given by 2 {(2, {id})tt, (2, {id})ff}, while its 2-power (qubit ⊕ qubit) is In fact, one can prove that CPMs inherits the compact closed {(4, {id, σ})[tt,tt], (4, {id})[tt,ff], (4, {id, σ})[ff,ff]}. Notice the structure of CPM. difference between the CPMs object (4, {id}) associated with Lemma 23. The category CPMs has the n-th powers for any [tt, ff] and the object (4, {id, σ}) associated with the two mul- tisets of singleton support. n ∈ N. Moreover, such powers preserve the monoidal product. ⊕ The description of the objects and the morphisms of CPMs ⊗n Proof. Notice that the group of the n! symmetries of (m, G) as indexed families is crucial for inferring the structure of a Lafont can be seen as a group H of permutations on mn, each element ⊕ n category from the more basic categories underlying CPMs . How- σ acting as follows on m seen as the set of n-tuples of ele- ⊕ ever, it is worthwhile to notice that CPMs can also be presented as ments in {1, . . . , m} lexicographically ordered: (i1, . . . , in) 7→ ⊗n a concrete and linear maps between modules. (iσ(1), . . . , iσ(n)). Let us denote by hG ∪ Hi the smallest sub- ⊗n The rest of the section sketches such an alternative presentation. group of Smn containing G ∪ H. Notice that all elements ⊕ ⊗n Let A be an object of CPMs . We define a module Pos(A) of hG ∪ Hi are of the form (g1, . . . , gn); σ for gi ∈ G + and σ ∈ H. In fact, such a permutation can also be expressed over R as follows. For every a in |A| consider the quotient na×na 0 σ ;(g , . . . , g ) C /∼Ga of the set of square matrices, where M ∼Ga M as σ(1) σ(n) . In particular, the morphism induced by 0 hG⊗n ∪ Hi is equal to G⊗n ; H. Define the equalizer of the whenever there exists g ∈ Ga such that g(M) = M . Notice that na×na symmetries of (m, G)⊗n by (m, G)n := (mn, hG⊗n ∪ Hi) with the image of C under the action of Ga yields a set Mat(a) ⊆ na×na na×na (m,G)n ⊗n of canonical representatives for /∼ . Let us eq := hG ∪ Hi. C C Ga write Pos(a) for its associated cone of positive matrices. This pos- + itive cone is an R -module. Since group actions are completely 5.2 The biproduct completion of CPMs. positive maps, complete positivity naturally extends to complex The category CPMs is a linear continuous R+-category (Re- linear maps f : Mat(a) → Mat(b): f can be regarded as the map na×na nb×nb mark 21), so we can apply the construction of Section4 to obtain Ga ; f : C → C . We define f to be completely pos- ⊕ its infinite biproduct completion CPMs . To sum up, the category itive if and only if Ga ; f is. Since the positive matrices span the ⊕ complex vector space of square matrices (of corresponding size), CPMs is given as follows. one can canonically extend the definition of complete positivity to + Objects are given by indexed families {(na,Ga)}a∈|A|, where the R -module homomorphisms Pos(a) → Pos(b). We then define: index set |A| is called the web of A and, for every a ∈ |A|, na is M Pos(A) := (Pos(a) ∪ {∞a}) (9) a natural non-negative integer and Ga a group of permutations a∈|A| over na.

Morphisms from {(na,Ga)}a∈|A| to {(mb,Hb)}b∈|B| are matri- The operations are defined pointwise, and ∞a is absorbing for ces φ indexed by |A| × |B| and such that φa,b is either a com- addition and scalar multiplication with respect to Pos(a), except n ×n m ×m pletely positive map from C a a to C b b invariant under for the rule 0 · ∞a = 0. The Lowner¨ order v on positive matrices the actions of Ga and Hb, or the top ∞. can be extended to Pos(A) componentwise: v v u if for all a ∈ |A|, va v ua or ua = ∞a. In particular, notice that Pos(A) From Propositions 18 and 22 and Lemma 23, we can conclude: is complete with respect to this order, where the maximum is the ⊕ vector whose value is ∞ in every a ∈ |A|, and the directed sup Corollary 24. The category CPMs is a Lafont category. a is defined componentwise. This makes Pos(A) into a continuous Example 25. The unit of the monoidal product ⊗ is given by module over R+: addition and scalar multiplication are continuous the singleton web object 1 = {(1, {id})∗}. The biproduct 1 ⊕ 1 operations with respect to the order. will be used to interpret the bit type and it is defined as the two- Example 26. Let us define the modules associated with the objects element family {(1, {id})tt, (1, {id})ff}. The free commutative + comonoids associated with 1 and 1⊕1 are infinite families that can discussed in Example 25. Clearly we have: Pos(1) = R , Pos(1⊕ 2 × + +N +N N be concretely defined as (see Equation8): !1 = {(1, {id})n}n∈N 1) = R , Pos(!1) = R and Pos(!(1 ⊕ 1)) = R . and !(1 ⊕ 1) = {(1, {id})(n,m)}n,m∈N, where we use the iso- Concerning the examples on qubit, we have that Pos(qubit) ⊗2 morphisms between Mf ({∗}) (resp. Mf ({tt, ff})) and N (resp. (resp. Pos(qubit ) is the cone of positive matrices of dimension

8 2013/10/2 2 × 2 (resp. 4 × 4) plus the top element ∞. More interestingly, the  2 a if ~m = []~ and b = ff, module associated with qubit is  meas !∆`qubit(bit = ( a b ) 7→ d ~m = []~ b =  a b b c   ~m,(∗,b) c d if and tt, d e f g J K  d f e g positive ; a, b, c, d, e, f, g, h, i, l ∈ C 0 otherwise. h i i l  ⊗2 ( a 0 ) if ~m = []~ and b = ff, which is a subcone of Pos(qubit ) of dimension 10. Finally,  0 0 2 2 !∆`bit(qubit 0 0 ~ Pos(qubit ⊕ qubit) is equal to the Pos(qubit ) ⊕ new ~m,(b,∗) = a 7→ ( 0 a ) if ~m = [] and b = tt, ⊗2 2 J K Pos(qubit ) ⊕ Pos(qubit ). 0 otherwise.

Let f : Pos(A) → Pos(B) be a continuous module homo- ( −1 ⊗n ⊗n UMU if ~m = []~ , A !∆`qubit (qubit morphism. We say that f is quantum-compatible if for all a ∈ | | U ~m,(~∗,~∗) = M 7→ a b 0 otherwise. and b ∈ |B|, fa,b = ι ; f ; π is either the map ∞ sending all J K non-zero elements to ∞b and 0 to 0, or a module homomorphism Pos(a) → Pos(b). We say that f is completely positive if all the Table 4: Interpretation of the quantum constants. U and M have the same 2n×2n module homomorphisms fa,b are completely positive maps. dimension C , U being unitary. Proposition 27. There is an isomorphism between the homset ⊕ ⊕ CPMs (A, B) and the continuous module homomorphisms from φn ∈ CPMs (!C, !A): Pos(A) to Pos(B) that are quantum compatible and completely w;!0 positive. φ0 := !C −−→ !A, (10) id ⊗φn φ φn+1 := !C −→c !C ⊗ !C −−−−→ !C ⊗ !A −→ !A. (11) ⊕ Proof. Take φ ∈ CPMs (A, B). We define the map fφ from Since φ can be regarded as a continuous module homomorphism P n Pos(A) to Pos(B) by fφ(v)b := a φa,b(va). Here, we set (in particular it is monotone), the set {φ } is directed complete. φa,b(va) = ∞b when φa,b = ∞ and va 6= 0, or when φa,b 6= 0 We define Y(φ) as its least upper bound. and va = ∞a. We set φa,b(va) = 0 when one of φa,b and va is The denotations of the constants meas, new and the unitary zero. In all other cases, φa,b(va) is a well-defined positive matrix transformations are given in Table4 nb×nb in the space C . The infinite sum in the definition of fφ(v)b Given a linking ` = |y , . . . , y i, we write ` ` M : A for the P 1 m converges since { a∈F φa,b(va) | F ⊆fin |A|} is directed. One judgement y1 : qubit, . . . , ym : qubit ` M : A. then proves that φ 7→ fφ is a bijection. Proposition 28 (Invariance of the interpretation). Let ` be the linking |y1, . . . , ymi and ` ` M : A. If M is not a value, then 2m 6. Interpretation of the quantum lambda calculus for all quantum states q ∈ C , ``A ∗ X `0`A 0 0∗ 6.1 Denotational semantics M (qq ) = p · N (q q ). (12) ⊕ J K p J K We interpret the quantum λ-calculus into CPMs , extending the [q,`,M]→[q0,`0,N] standard interpretation of intuitionistic linear logic to also include the quantum features of the calculus. Section7 will show that Proof. By hypothesis, [q, `, M] is a typable total closure, and so, the denotation of a quantum λ-term is a true family of complete by Proposition 11 and Lemma 13, any of its reduct [q0, `0,N] is a positive maps, not containing the ∞ morphism. `0`A 0 0∗ ⊕ typable total closure, so that N (q q ) is well-defined. The denotation A of a type A is an object of CPMs , i.e., Equation 12 is proven byJ cases,K depending on the rule applied an indexed sequenceJ K of objects of CPMs, defined by structural to [q, `, M]. The cases of Table3(a) follows from the fact that ⊕ induction on A, as follows. qubit is the singleton web ob- CPMs is a continuous model of linear logic. The quantum rules J K ject {(2, {id})∗}; 1 is the tensor unit 1 = {(1, {id})∗} of (Table3(b)) are trivial consequences of Table4, and the congruence ⊕ J K CPMs ; A ( B = A ⊗ B is the tensor product of A and rules of Table3(c) are done by induction on M, using the fact that ⊕ B ; A ⊕J B is theK biproductJ K of A and B ; !A isJ theK free the category CPMs is linear. commutativeJ K J K comonoid over A ; J AK` is theJ K infiniteJ K biproduct ∞ ⊗n J K J K `1 ⊕i=0 A . Corollary 29. We have M ∗ > Halt[| i,| i,M]. J K ∞ n ` Notice the difference between !A = ⊕i=0 A and A . J K J K J K J K `1 Recalling Notation3, we have that bit is defined as 1 ⊕ 1 = Proof. By induction on n, we can show that M ∗ is equal to `0`1 ∗ {(1, {id})ff, (1, {id})tt}. By abuseJ of notation,K we can omitJ theK P n 0 0 J K [q0,`0,N] Red[| i,| i,M],[q0,`0,N] N (q q ). Then the claim brackets, i.e., in the following, the simple letter A will denote bothJK J K ⊕ follows by taking the limit as n → ∞, and invoking the mono- n the type and its interpretation in CPMs . tonicity of {Red }n. Let Γ = x1 : A1, . . . , xn : An. We define the denotation of a typing judgement Γ ` M : A as a morphism M Γ`A in 6.2 Examples ⊕ N J K CPMs ( i Ai , A ). The definition is by structural induction In this section, we discuss the denotations of the two examples of on the uniqueJ typeK J derivationK π of Γ ` M : A (Proposition4). programs that we already encountered. In Table5, we recall the definition regarding the usual linear logic ` rules: the morphisms φ, ψ, φ , φ refer to the denotation of the Example 30. Recall the terms of Example5. The web of qubit A B ` n J ` K premises of the last rule of π, which are uniquely defined given is N, while qubit n = (2 , {id}). Notice that Pos( qubit ) J L K 2n×2n 2n×2n J K Γ ` M : A. is equivalent to n P (C ) where P (C ) is the cone of In the interpretation of the letrec constructor, the fixed 2n × 2n positive matrices. The denotation of the term qlist is ⊕ point operator Y is defined as follows. Let φ be a morphism in a morphism in CPMs (qubit, qubit`), that is, a map sending a ⊕ L 2n×2n CPMs (!C ⊗ !A, !A). By induction on n, we define the morphism 2 × 2 positive matrix onto n P (C ). The program qlist

9 2013/10/2 w⊗id w⊗d dig m !φ Λ(φ) !∆ ⊗ A / 1 ⊗ A ' A !∆ ⊗ !A / 1 ⊗ A ' A !∆ / !!∆ / !(!∆) / !A !∆ ⊗ Γ / A ( B A (a) !∆, x : A ` x : A (b) !∆, x :!A ` x : A (c) !∆, ` V :!A (d) !∆, Γ ` λx .M : A ( B

c⊗id φ⊗ψ eval w c⊗id φ⊗id ψ !∆ ⊗ Γ ⊗ Σ / !∆ ⊗ Γ ⊗ !∆ ⊗ Σ / A ⊗ A ( B / B !∆ / 1 !∆ ⊗ Γ ⊗ Σ / !∆ ⊗ Γ ⊗ !∆ ⊗ Σ / 1 ⊗ !∆ ⊗ Σ ' !∆ ⊗ Σ / A (e) !∆, Γ, Σ ` MN : B (f) !∆ ` skip : 1 (g) !∆, Γ, Σ ` M;N : A

c⊗id φ⊗ψ c⊗id φ⊗id ψ φ ι` !∆ ⊗ Γ ⊗ Σ / !∆ ⊗ Γ ⊗ !∆ ⊗ Σ / A ⊗ B !∆ ⊗ Γ ⊗ Σ / !∆ ⊗ Γ ⊗ !∆ ⊗ Σ / A ⊗ B ⊗ !∆ ⊗ Σ / C !∆ ⊗ Γ / A / A ⊕ B A B (h) !∆, Γ, Σ ` M ⊗ N : A ⊗ B (i) !∆, Γ, Σ ` let x ⊗ y = M in N : C (j) !∆, Γ ` in` M : A ⊕ B

r φ ι c⊗id ψ⊗id distr φA⊕φB !∆ ⊗ Γ / B / A ⊕ B !∆ ⊗ Γ ⊗ Σ / !∆ ⊗ Γ ⊗ !∆ ⊗ Σ / (A ⊕ B) ⊗ !∆ ⊗ Σ / (A ⊗ !∆ ⊗ Σ) ⊕ (B ⊗ !∆ ⊗ Σ) / C A B (k) !∆, Γ ` inr M : A ⊕ B (l) !∆, Γ, Σ ` match M with (x : N|y : L): C

c id ⊗ Y(dig;m;!(Λφ)) ψ φ ` id ⊕distr L∞ ⊗n ` !∆ ⊗ Γ −→ !∆ ⊗ Γ ⊗ !∆ −−−−−−−−−−−→ !∆ ⊗ Γ ⊗ !(A ( B) −→ C !∆ ⊗ Γ / 1 ⊕ (A ⊗ A ) / 1 ⊕ ( n=1 A ) = A (m) !∆, Γ ` M : A` (n) !∆, Γ ` letrec f x = M in N : C

Table 5: Sketch of the interpretation of the typing judgements. The morphisms φ, ψ, φA, φB refer to the denotation of the premises of the unique derivation concluding a typing judgement. In (c) and (n), the morphism m stands for m1 or the suitable sequence of m⊗, depending on the context !!∆. is defined using recursion: its semantics is the the limit of the mor- classical bits. This pair of bits (x, y) is picked probabilistically: a a b 1 1 phisms fn sending ( c d ) to (0, 2 e1,..., 2n en, 0, 0,...) where ei column was chosen by this choice. Now, in (iii), i.e. in the function i i is the 2 × 2 positive matrix of the form g, two bits are used to decide on the matrix Uxy that should be   used: this is the choice of a matrix in the column. This matrix a 0 ··· 0 b is the composition of these two operations, yielding a function 0 0 ··· 0 0  . . . . .  from qubit to qubit. The 4 matrices in the column record all  ...... .   g 0 0 ··· 0 0 the possible choices of inputs to . c 0 ··· 0 d The matrices on the diagonal corresponds to a run of the algo- rithm as it was intended: feeding g with the result from f. Since a b This limit is the map sending ( c d ) to the sequence of infinitely they are supposed to be the identity on qubit, we can therefore 1 1 increasing matrices (0, 2 e1,..., 2n en,...). Note that the first el- deduce that the matrices A00,00, A01,01, A10,10 and A11,11 are all 0  1 0 0 1  ement of the sequence is , as the program qlist never return the 0 0 0 0 empty list. Also note that all the positive matrices in the sequence equal to 0 0 0 0 . Since this matrix cannot be written as the ten- 1 0 0 1 represent entangled states of arbitrary sizes. Our semantics is the sor of two 2 × 2 matrices, we conclude that the denotation A of first one to be able to account for such a case: in [6], only fixed (teleport skip) is indeed entangled. sizes were allowed for entangled states. We can compute the other matrices Axy,zt using the same Example 31. We claim in the introduction that the model is ex- argument: in general, Axy,zt is a composition of f and g, except pressive enough to describe entanglement at higher-order types. As that instead of giving (x, y) to g, we feed it with (z, t). We therefore we discuss in Example6, the encoding of the quantum teleporta- get a function qubit → qubit constructed out of the U−− that might (if xy = zt) or might not be the identity. In general, tion algorithm produces two entangled, mutually inverse functions: ∗ f : qubit → bit ⊗ bit and g : bit ⊗ bit → qubit. the matrices Axy,zt is the denotation of the unitary UztUxy. The denotation A is given in full details in Table6. The term (teleport skip) of type (qubit ( bit ⊗ bit) ⊗ (bit ⊗ bit ( qubit) is one instance of such a pair of functions. Its denotation is a finite sequence of 16 square matrices of size 6.3 Adequacy ⊕ 4 × 4. Using a lexicographic convention, we can lay them out as In the following, we prove the adequacy of CPMs (Theorem 39). follows: This amounts to achieving the converse inequality of Corollary 29. 1 A = ( A00,00,A00,01,A00,10,A00,11, The proof uses a syntactic approach, following [6]. We introduce 4 n A01,00,A01,01,A01,10,A01,11, a bounded let-rec , which can be unfolded at most n times. A10,00,A10,01,A10,10,A10,11, On the one hand, the language allowing only bounded let-rec is A11,00,A11,01,A11,10,A11,11 ). strongly normalizing (Lemma 34), hence the adequacy for it can be easily achieved by induction on the longest reduction sequence of Because of the convention, morally each row corresponds to an el- a term (Corollary 35). On the other hand, the unbounded let-rec ement of type bit ⊗ bit ( qubit whereas each column corre- can be expressed as the supremum of its bounded approximants, sponds to an element of type qubit ( bit ⊗ bit. Picking a row, both semantically (Lemma 37) and syntactically (Lemma 38). We i.e. a choice of two left-sided booleans, amounts to choosing the then conclude the adequacy for the whole quantum λ-calculus by two booleans that will be fed to the function g. Picking a column, continuity. i.e. a choice of two right-sided booleans, amounts to deciding on the probabilistic result we get from the function f. The intersec- Definition 32. Let us extend the grammar of terms (Table1) by tion of a column and a row is therefore the representation of a map adding: (i) a new term ΩA; (ii) a family of new term constructs n A B qubit ( qubit. This map is a description of a possible path in letrec f ( x = M in N indexed by natural numbers n > 0. the control flow of the algorithm. The typing rules for these new constructs are Indeed, consider again Figure1. In (ii), i.e., in the function f, qubit 1 and qubit 2 are entangled and measured, generating two !∆ ` ΩA : A

10 2013/10/2   1 0 0 1   0 0 0 0   1 0 0 -1   0 0 0 0  0 0 0 0 0 1 1 0 0 0 0 0 0 1 -1 0 A = A00,00 = 0 0 0 0 ,A00,01 = 0 1 1 0 ,A00,10 = 0 0 0 0 ,A00,11 = 0 -1 1 0 , 1 0 0 1 0 0 0 0 -1 0 0 1 0 0 0 0  0 0 0 0   1 0 0 1   0 0 0 0   1 0 0 -1  0 1 1 0 0 0 0 0 0 1 -1 0 0 0 0 0 A01,00 = 0 1 1 0 ,A01,01 = 0 0 0 0 ,A01,10 = 0 -1 1 0 ,A01,11 = 0 0 0 0 , 0 0 0 0 1 0 0 1 0 0 0 0 -1 0 0 1  1 0 0 -1   0 0 0 0   1 0 0 1   0 0 0 0  0 0 0 0 0 1 -1 0 0 0 0 0 0 1 1 0 A10,00 = 0 0 0 0 ,A10,01 = 0 -1 1 0 ,A10,10 = 0 0 0 0 ,A10,11 = 0 1 1 0 , -1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0  0 0 0 0   1 0 0 -1   0 0 0 0   1 0 0 1   0 1 -1 0 0 0 0 0 0 1 1 0 0 0 0 0 A11,00 = 0 -1 1 0 ,A11,01 = 0 0 0 0 ,A11,10 = 0 1 1 0 ,A11,11 = 0 0 0 0 . 0 0 0 0 -1 0 0 1 0 0 0 0 1 0 0 1

Table 6: The denotation of the teleportation algorithm.

!∆, f : !(A ( B), x : A ` M : B In fact, by Lemma 34, there exists m ∈ N such that Halt[q,`,M] = !∆, Γ, f : !(A B) ` N : C P m ( [q0,`0,V ] Red[q,`,M],[q0,`0,V ]. The proof then follows by induction !∆, Γ ` letrecn f A(B x = M in N : C on m. Their denotations are given, respectively, by the map 0 and the Definition 36. Let / be a relation between finitary terms and family of maps general terms defined as the smallest congruence relation on terms 0 0 id ⊗(dig;m;!(Λφ))n ψ satisfying, for every M/M and N/N : !∆⊗Γ −→c !∆⊗Γ⊗!∆ −−−−−−−−−−→ !∆⊗Γ⊗!(A B) −→ C, ( A B 0 0 ⊕ N{(λx .Ω )/f} / (letrec f x = M in N ), where φ ∈ CPMs (!∆ ⊗ !(A ( B) ⊗ A, B) and ψ ∈ n 0 0 ⊕ (letrec f x = M in N) / (letrec f x = M in N ). CPMs (!∆ ⊗ Γ ⊗ !(A B),C) are the denotations of the ( Γ`A n ⊕ Γ`A W 0 premises and (dig; m; !(Λφ)) ∈ CPMs (!∆, !(A B)) is de- Lemma 37. If Γ ` M : A, then M = M0/M M . ( 0 fined as in Equations (10), (11). J K M finitary J K The reduction rules are updated as follows. Proof (Sketch). By induction on the derivation of Γ ` M : A. 0 A B 1 A B [q, `, letrec f ( x = M in N] −→ [q, `, N{(λx .Ω )/f}] 0 Lemma 38. If M/M , then Halt[q,`,M] 6 Halt[q,`,M0]. [q, `, letrecn+1 f A(B x = M in N] 1 A n A B Proof (Sketch). By induction on n, one proves the inequality: −→ [q, `, N{(λx .letrec f ( x = M in M)/f}]. P n P n [q0,`0,N] Red[q,`,M],[q0,`0,N] 6 [q0,`0,N0] Red[q,`,M0],[q0,`0,N0], The additions to the language do not modify the properties from which trivially follows the statement. of the language: subject reduction (Proposition 11) and totality (Lemma 13) hold as they are stated, while type safety (Proposi- Theorem 39. Let M be a program, i.e., a closed term of unit type. `1 tion 12) and soundness (Proposition 28) are satisfied, with the pro- Then M ∗ = Halt[| i,| i,M] . viso of considering the set of normal forms to consists of the set of J K `1 values and the set of terms containing Ω in evaluating position. Proof. By Corollary 29 we have M ∗ > Halt[| i,| i,M]. As for J`1 K W 0 `1 the converse: by Lemma 37, M = 0 M , which is Definition 33. A term is called finitary when it does not contain W ∗ M /M ∗ equal to Halt J0 byK Corollary 35J, whichK is less or any occurrence of the un-indexed let-rec construct. It can how- M0/M [| i,| i,M ] n equal to Halt by Lemma 38. ever contain Ω and any of the indexed let-rec . We call a closure [| i,| i,M] finitary when its term is finitary. 7. Structure of the sets of representable elements Lemma 34 (Strong normalization). If [q1, `1,M1] is finitary and typable, then every reduction sequence We conclude this paper by an analysis of some of the properties of the denotation of terms. p1 p2 p3 ⊕ [q1, `1,M1] −→ [q2, `2,M2] −→ [q3, `3,M3] −→· · · Recall that a morphism in CPMs is a indexed family of either is finite. a completely positive map, or the element ∞. We show that (1) all types have a non-zero inhabitant; (2) provided that the term Proof (Sketch). By reducing the quantum λ-calculus to a sim- constant U ranges over arbitrary unitary matrices, the representable ply typed non-deterministic language without quantum states, for elements of a given homset form a convex set including 0; and (3) which a standard proof technique can be used. The terms of this ∞ is not part of any representable element. language are the terms of the extended quantum λ-calculus, minus We first need two auxiliary definitions. the let-rec construct. The operational semantics is obtained from Definition 40. We define two type-indexed families of terms ωA Table3 and the rules for let-recn by replacing closures with the and ωA by mutual induction in Table7. The term c represents respective terms and the rules of Table 3b by dummy reduction the fair coin toss meas (H (new ff)) (recall Example1) and the rules: like U(• ⊗ · · · ⊗ •) → • ⊗ · · · ⊗ •, or new ff → •. The notation µfx.M stands for letrec f x = M in f. symbol • denotes a distinct term variable, which, by convention, it is never bound by an abstraction. Clearly, the strong normalization Lemma 41. For all types A, we have ` ωA : 1 ( A and `1(A of this language implies that of the typed quantum λ-calculus. ` ωA : A ( 1. Moreover, the morphisms ωA and `A(1 ωA , seen as indexed families, do not containJ theK zero-CPM. Corollary 35 (Finitary adequacy). Let M be a closed finitary term J K `1 Proof. The fact that their type is as specified in the lemma is a of unit type. Then M ∗ = Halt[| i,| i,M] . J K straightforward proof by structural induction on the term. Proof (Sketch). We prove that, for any total finitary quantum clo- The proof that for all A, the denotations of ωA and ωA do not ``1 ∗ sure of unit type [q, `, M] we have M (qq ) = Halt[q,`,M]. contain the zero-CPM is done by induction on A: For the types J K

11 2013/10/2 qubit ωqubit = λskip.new ff ωqubit = λx .if meas x then skip else skip A A(B ωA(B = λskip.λx .(ωA x);(ωB skip) ωA(B = λf .ωB (f (ωA skip)) A !(A(B) ω!(A(B) = λskip.λx .(ωA(B skip) x ω!(A(B) = µgf .if c then skip else (ωA(B f); (g f) ω1 = λskip.skip ω1 = λskip.skip A⊗B ωA⊗B = λskip.(ωA skip) ⊗ (ωB skip) ωA⊗B = λx .let z1 ⊗ z2 = x in (ωA z1);(ωB z2) A⊕B A B ωA⊕B = λskip.if c then (ωA skip) else (ωB skip) ωA⊕B = λx .match x with (z1 : ωA z1|z2 : ωB z2) A` ωA` = µfskip.if c then (skip) else (ωA skip) :: (f skip) ωA` = µfx .match split x with 1 A⊗A` ( z1 : z1 z2 : let y1 ⊗ y2 = z2 in (ωA y1);(f y2))

Table 7: Two mutually recursive families of terms qubit and 1, the result is immediate. For the types A ⊕ B and [4] J.-Y. Girard. Normal functors, power series and lambda-calculus. Ann. A⊗B, invoking the induction hypothesis is enough. The interesting Pure Appl. Logic, 37(2):129–177, 1988. ` types are A and !(A ( B). The cases ω!(A(B) and ωA` are [5] J.-Y. Girard. Coherent banach spaces: a continuous denotational se- mantics. Theoretical Computer Science, 227:297, 1999. straightforward. For the cases ωA` and ω!(A(B), one is careful to touch all possible instances: in the former, the term probabilistically [6] I. Hasuo and N. Hoshino. Semantics of higher-order quantum com- generates lists of all possible lengths whereas in the latter the term putation via geometry of interaction. In Proceedings of LICS, pages is probabilistically consuming all possible repetitions of a non-zero 237–246, 2011. input. [7] Y. Lafont. Logiques, categories´ et machines. PhD thesis, Universite´ Paris 7, 1988. Corollary 42. All types are inhabited by at least one closed value [8] U. D. Lago, A. Masini, and M. Zorzi. Confluence results for a quantum of non-null denotation. lambda calculus with measurements. Electr. Notes Theor. Comput. Sci., 270(2):251–261, 2011. Proof. Immediate with Lemma 41: for a given type A, choose the term (ω skip). [9] J. Laird, G. Manzonetto, and G. McCusker. Constructing differential A categories and deconstructing categories of games. Information and Proposition 43. Given a type A and a context Γ, the denotations Computation, 222:247–264, 2013. M Γ`A of valid typing judgements Γ ` M : A form a convex set [10] J. Laird, G. McCusker, G. Manzonetto, and M. Pagani. Weighted includingJ K 0. relational models of typed lambda-calculi. In LICS’13, 2013. [11] S. Mac Lane. Categories for the Working Mathematician. Springer, Proof. Suppose that Γ is x1 : A1, . . . , xn : An. A term M 2nd edition, Sept. 1998. mapping to 0 is (ωA1 x1; ... ; ωAn xn; Ω) where the term Ω is a [12] O. Malherbe. Categorical models of computation: partially traced shortcut for letrec f x = f x in f skip, of denotation 0. categories and presheaf models of quantum computation. PhD thesis, Γ`A Γ`A University of Ottawa, 2010. Now, suppose that f = M1 and g = M2 , and choose two non-negative realJ numbersK ρ1, ρ2 suchJ thatK ρ1 + [13] P.-A. Mellies.` Categorical semantics of linear logic. Panoramas et 2 ρ2 = 1. There exists an angle φ such that (cos φ) = ρ1 Syntheses` , 12, 2009. 2 and that (sin φ) = ρ2. As the term constant U ranges over [14] P.-A. Mellies,` N. Tabareau, and C. Tasson. An explicit formula for cos φ − sin φ ICALP’09 (2) arbitrary unitaries, the unitary matrix Vφ = ( ) is the free exponential modality of linear logic. In , pages sin φ cos φ 247–260, 2009. representable in the quantum lambda-calculus. The term c0 = [15] M. A. Nielsen and I. L. Chuang. Quantum Computation and Quantum meas (Vφ (new ff)) has denotation (ρ1, ρ2). We then conclude 0 Information. Cambridge University Press, 2002. that the term if c then M1 else M2 has the denotation ρ1f + ρ2g. [16] P. Selinger. Towards a quantum programming language. Mathematical Structures in Computer Science, 14(4):527–586, 2004. Proposition 44. If Γ ` M : A is valid, then ∞ is not part of the [17] P. Selinger. Towards a semantics for higher-order quantum computa- denotation M Γ`A of M. tion. In QPL’04, TUCS General Publication No 33, pages 127–143, J K 2004. Proof. Suppose that ∞ were to be found in the interpretation of [18] P. Selinger and B. Valiron. A lambda calculus for quantum compu- x1 : A1, . . . , xn : An ` M : A. Then the closed term tation with classical control. Mathematical Structures in Computer Science, 16(3):527–552, 2006. (λx1 . . . xn.ωA M)(ωA skip) ... (ωA skip) 1 n [19] P. Selinger and B. Valiron. On a fully abstract model for a quantum of type 1 has for denotation ∞, contradicting Theorem 39. linear functional language. In QPL’06, 2008. [20] P. Selinger and B. Valiron. Quantum lambda calculus. In S. Gay This last proposition indicates that the element ∞ is really an and I. Mackie, editors, Semantic Techniques in Quantum Computation, artifact only needed for the categorical construction. The repre- chapter 9, pages 135–172. Cambridge University Press, 2009. sentable elements in the model are only built out of families of [21] B. Valiron. Semantics for a higher-order functional programming completely positive maps. language for quantum computation. PhD thesis, University of Ottawa, 2008. References [1] V. Danos and T. Ehrhard. Probabilistic coherence spaces as a model of higher-order probabilistic computation. Inform. Comput., 2011. [2] T. Ehrhard. Finiteness spaces. MSCS, 15(4):615–646, 2005. [3] J.-Y. Girard. Linear logic. Th. Comp. Sc., 50:1–102, 1987.

12 2013/10/2 A. Appendix A.1.1 Linear structure In the following, ◦ denotes the functional composition, i.e., φ◦ψ = We recall how the structure defining a compact closed category ψ ; φ. is inherited by C⊕ from C. That means that C⊕ is symmet- ric monoidal and that it is a closed (resp. ?-autonomous, com- A.1 Infinite biproduct completion pact closed) whenever C is closed (resp. ?-autonomous, compact ⊕ It is known that, under certain hypothesis, the infinite biproduct closed). In addition, C has biproducts even if C does not. ⊕ completion C of a continuous commutative-monoid-enriched Biproduct The category C⊕ is the free biproduct completion of symmetrical monoidal category C gives a model of linear logic. L ⊕ ⊕ C. The biproduct i∈I Ai of a family (Ai)i∈I of objects in C is In particular, C denotes the exponential modality via the infi- defined by nite biproduct of the equalizers of the symmetries of the n-fold M [ M monoidal product of C (if it exists). This construction has been | A | := {i} × |A |, A  := (A ) , i i i (j,a) j a (14) mentioned in [14] and one can find specific instances in [9] (where i∈I i∈I i∈I the sum of the continuous commutative monoid structure of the C homsets is assumed to be idempotent) and in [10] (where the con- j j (π )(i,a),a0 := δi,j δa,a0 idAa , (ι )a,(i,a0) := δi,j δa,a0 idAa . struction is applied to a continuous semiring R seen as a continu- (15) ous commutative-monoid-enriched symmetrical monoidal category with a single object). In this section, we recall the construction of The tupling hφiii∈I (resp. (co)-tupling [φi]i∈I ) of a family of ⊕ ⊕ C⊕, and in Section5, we apply it to the category of completely morphisms φi ∈ C (A, Bi) (resp. ψi ∈ C (Ai, B)) is defined positive maps with symmetries. by:

(hφiii∈I )a,(i,b) := (φi)a,b ([ψi]i∈I )(i,a),b := (ψi)a,b (16) Definition 45. A continuous semiring R is defined to be a semiring L Proposition 49. The object i∈I Ai together with the projections (|R|, 0, 1, +, ·) equipped with an order relation ≺ such that 0 is i i ⊕ the minimum, any directed set D ⊆ |R| has a directed sup W, (π )i∈I and injections (π )i∈I is a biproduct of C . W W and + and · are continuous, i.e., (r + D) = r + D and The category ⊕ is the free biproduct completion W W Proposition 50. C (r · D) = r · D. of C, i.e., for every category D endowed with a biproduct of fami- lies, and every functor F : C → D, there exists a unique functor From now on R will denote a continuous commutative semir- † ⊕ ing. F : C → D commuting with biproducts.

Definition 46. A symmetric monoidal category C is a linear R- ⊕ † L Proof. For any object A of C , define F (A) = a∈|A| F (Aa), category when every homset is endowed with the structure of a ⊕ † module over the semiring R, the composition is bilinear and the and for every morphism φ ∈ C (A, B), define F (A) = tensor preserves the module structure over R on homsets, that is h[F (φa,b)]a∈|A|ib∈|B|. (f + f 0); g = f ; g + f 0 ; g, f ;(g + g0) = f ; g + f ; g0, g ;0 = 0 = 0;g, (g +f)⊗h = (g ⊗h)+(f ⊗h), and g ⊗0 = 0. Monoidal product The bifunctor ⊗ : C⊕ ×C⊕ → C⊕ is defined We moreover say that C is continuous when every homset on objects A, B by is endowed with the structure of a complete partial order and |A ⊗ B| := |A| × |B|, (A ⊗ B) := A ⊗ B , (17) composition, addition and scalar multiplication are continuous. (a,b) a b where the ⊗ in the right-hand side of the second equation is that Remark 47. We cannot use Selinger’s abstract cones [17], because of the category C. The action of ⊗ on morphisms is defined com- the cancellation law fails in CPMs with ∞. ponentwise; given φ ∈ C⊕(A, B) and ψ ∈ C⊕(C, D), we set for Lemma 48. If C is a linear continuous R-category, then we can (a, c) ∈ |A ⊗ C|, (b, d) ∈ |B ⊗ D|, define the indexed sum over a homset C(A, B) as (φ ⊗ ψ)(a,c),(b,d) := φa,b ⊗ ψc,d. (18) X _ X  f := f . The tensor unit is given by the space 1: F ⊆finS f∈S f∈F |1| := {∗}, 1∗ := 1, (19) where 1 is the tensor unit of C. P Proof. Just notice that { f | F ⊆fin S} is directed. f∈F Proposition 51. The operation ⊗ is a bifunctor endowing a sym- metric monoidal structure on C⊕ whose unit object is the space 1. From now on, we assume that C is a symmetric monoidal linear Moreover, C⊕ is a linear continuous R-category with addition and continuous R-category C. scalar multiplication defined componentwise. Reminder of Definition 15(C ⊕). An object of C⊕ is a pair A = (|A|, (Aa)a∈|A|) of a (possibly infinite) set of indexes |A|, Proof. The natural transformations α, λ, ρ, σ, proving the asso- called the web of A, and a |A|-family of objects in C. The hom- ⊕ ciativity, the neutrality of 1, and the symmetry of ⊗, are defined set C (A, B) is the set of the |A| × |B| matrices of morphisms componentwise from the corresponding isomorphisms in the cat- φ = (φa,b)(a,b)∈|A|×|B| in C. egory C. So, for example, the associator isomorphism is given by ⊕ ⊕ Given φ ∈ C (A, B) and ψ ∈ C (B, C), the composition A,B,C Aa,Bb,Cc Aa,Bb,Cc α 0 0 0 = δa,a0 δb,b0 δc,c0 α , where α φ ; ψ is the matrix product: ((a,b),c),(a ,(b ,c )) is the associativity isomorphism in C, and δa,a0 is the Kronecker X (φ ; ψ) = φ ; ψ (13) delta. The commutativity of the pentagonal diagram follows imme- a,c a,b b,c diately from its commutativity in C. b∈|B| Similarly, for the unit isomorphisms and the braiding σ. where the sum is defined by Lemma 48. The identity is the diagonal The axioms of the continuous R-module structure trivially fol- 0 0 matrix ida,a0 := idAa if a = a , and ida,a0 := 0 if a 6= a . low from those of C, except for the continuity of the composition,

13 2013/10/2 W Aa,Bb where one uses the commutativity of : the equation (ψc,(a,b) ⊗ Aa) ; eval = φ(c,a),b and hence _ X _ ψc,(a,b) = Λ(φc,(a,b)). (( φi); ψ)a,c = ((φi)a,b ; ψb,c) i i b As usual the universal property defined by diagram 23 induces _ X ⊕ ⊕ = ((φi)a,b ; ψb,c) an isomorphism from C (C ⊗ A, B) to C (C, A ( B), which i b we denote by Λ(−) and its inverse by App(−). _ = (φi ; ψ)a,c Dualizing object: The dualizing object ⊥ (if it exists) in C can be i seen as an object of C defined by:

|⊥| := {∗}, ⊥∗ :=⊥, (24) Notice that the associativity and unit isomorphisms allow us to Proposition 53. If C is ?-autonomous, then so it is C⊕ with the define the n-fold tensor product A⊗n of an object A by |A⊗n| := ⊗n dualizing object ⊥. Moreover, if C is compact closed, than so is {(a1, . . . , an) | ∀i n, ai ∈ |A|} and A := Aa ⊗· · ·⊗ ⊕ 6 (a1,...,an) 1 C . Aan . Notice also that the group of permutations Sn on {1, . . . , n} ⊗n A ⊕ gives the n! symmetries of A , namely σ ∈ Sn can be seen as the Proof. The isomorphism ∂ ∈ C (A, (A ( 1) ( 1)) is defined symmetry defined as: A Aa Aa as ∂a,((a0,∗),∗) = δa,a0 ∂ , where as usual ∂ is the correspond- ing isomorphism in C. σ 0 0 := (a1,...,an),(a1,...,an) n ! A ⊗···⊗A ,A ⊗···⊗A A.1.2 Exponential structure M a1 an aσ(1) aσ(n) δa ,a0 σ ⊕ σ(i) i We define the free exponential comonoid showing that C is a i=1 Lafont category [13]. Such a comonoid is the infinite biproduct of As usual on vector space based categories, the tensor product dis- the equalizers of the symmetries of the n-fold tensors, following L tributes over products. In fact, note that the web |( i∈I Ai) ⊗ B| the formula described in [14]. L ⊕ is in bijection with the web | i∈I (Ai ⊗ B)| via the mapping The next subsection shows how C inherits such equalizers ((i, a), b) 7→ (i, (a, b)). Moreover, the objects of C associated with (here called symmetric tensor powers) from C, and the subsection ((i, a), b) and (i, (a, b)) are the same. This induces an isomorphism after that gives the free exponential comonoid of C⊕. ⊕ L L distr in the homset C (( i∈I Ai)⊗B, i∈I (Ai⊗B)), defined by Symmetric Tensor Powers n Definition 54. The symmetric n-th power (An, eqA ) of an object distr((i,a),b),((i0,(a0,b0)) := δi,i0 δa,a0 δb,b0 idA ⊗B . (20) ia b A of a symmetric monoidal category C is the equalizer of the n! Hom-closure If C is closed, then C⊕ is also closed. The object symmetries of the n-ary tensor A⊗n. That is, An is an object of n of linear morphisms is defined as C, eqA is a morphism in C(An,A⊗n) equalizing the symmetries ⊗n An An of A (i.e., for every permutation σ ∈ Sn, eq ; σ = eq ) |A ( B| := |A| × |B|, (A ( B)(a,b) := Aa ( Bb, (21) enjoying the following universal property: for every object D and where the ( in the right-hand side of the second equation is the morphism f ∈ C(D,A⊗n) equalizing the symmetries of A⊗n, object of the homset C(Aa, Bb). For every pair of objects A, B, there exists a unique morphism f † such that the evaluation morphism EvalA,B : C⊕((A B) ⊗ A, B) is ( n σ defined componentwise: eqA 1 An / A⊗n / A⊗n. A,B A ,B / a b O < σn! Eval((a,b),a0),b0 := δa,a0 δb,b0 eval , (22) f unique f † Aa,Bb where eval is the evaluation morphism in C((Aa ( Bb) ⊗ Aa, Bb). D Proposition 52. If C has a left-closed structure, then the family of For C⊕ to inherit the powers of C, we need the additional A,B objects A ( B and morphisms Eval , for every A, B, endows hypothesis that such equalizers preserve the tensor product. C⊕ with a left closed structure. Definition 55. An equalizer (E, eq) preserves tensor products whenever for every object B the pair (E ⊗ B, eq ⊗ idB ) is the Proof. We must prove the universal property defining a left closed ⊕ equalizer of the diagram obtained from the diagram equalized by structure, i.e., for every morphism φ ∈ C (A ⊗ C, B), there is a (E, eq) by replacing each object A with A ⊗ B and each arrow f unique morphism Λ(φ) ∈ C⊕(C, A B) such that: ( by f ⊗ idB . n m C ⊗ A (23) Lemma 56. If (An, eqA ) and (Bm, eqB ) preserve tensor prod- n m An Bm φ ucts, then (A ⊗ B , eq ⊗ eq ) is the equalizer of the endo- Λ(φ)⊗A ⊗n ⊗m morphisms of A ⊗B of the shape σ⊗ρ, for σ ∈ Sn, ρ ∈ Sm.  EvalA,B Moreover, such an equalizer preserves tensor products. (A ( B) ⊗ A /( B. n m The definition of Λ(φ) is componentwise, using the same univer- Proof. Clearly, eqA ⊗ eqB equalizes the group of the n! × m! ⊗n ⊗m sal property for each C component of Eval, i.e., Λ(φ)c,(a,b) := symmetries of A ⊗ B which keep A’s copies separate Λ(φ(c,a),b)), where Λ(φ(c,a),b)) is the unique morphism such that from B’s copies. As for the universal property, one notices that An Bm An Bm Aa,Bb m (Λ(φc,(a,b)) ⊗ Aa) ; eval = φ(c,a),b. The commutativity of eq ⊗ eq = eq ⊗ idB ; idA⊗n ⊗ eq . Then, take a ⊗n ⊗m the diagram follows immediately from the definitions and this lat- morphism f ∈ C(D,A ⊗ B ) equalizing the permutations † ⊗n m ter equality. The uniqueness of Λ(φ) follows from the fact that for in Sn × Sm. We get a unique f ∈ C(D,A ⊗ B ) by apply- ⊕ Bm any morphism ψ ∈ C (C, A ( B), diagram (23) must satisfy ing the universal property to the equalizer idA⊗n ⊗ eq and from

14 2013/10/2 †† n m N ⊗p(a) that we get a unique f ∈ C(D,A ⊗B ) applying the universal for every i). Notice that φb,p4 ;α ∈ C(Bb, a∈|p| Aa ). Notice An m N property to the equalizer eq ⊗ idB . that φb,p4 ; α equalizes the symmetries of the form a∈|p| ρa, with ρa ∈ Sp(a). In fact, there exists a permutation ρ ∈ Sn N Lemma 57. If C has symmetric n-th powers for every n ∈ N pre- such that φb,p4 ; α ; a∈|p| ρa = φb,p4 ; ρ ; α and this last serving tensor products, then C⊕ also has symmetric n-th powers morphism is equal to φb,~ai ; α since by hypothesis φ equalizes all p(a) for every n ∈ N and they also preserve tensor products. In partic- N p(a) N Aa n permutations in Sn. Since ( a∈|p| Aa , a∈|p| eq ) is the ular, the object A can be defined by choosing an arbitrary order N on the elements of |A| and then setting equalizer of the permutations of the form a∈|p| ρa (Lemma 56), (φ ; α)† ∈ n n O p(a) we have that there exists a unique morphism b,p4 |A | := Mn(|A|), Ap := Aa , p(a) N p(a) † N Aa C(Bb, Aa ) such that (φ ; α) ; eq = a∈|p| a∈|p| b,p4 a∈|p| φb,p4 ; α. where the support |u| of a set of multisets u is |u| := S |p|, and † † p∈u Define φ := (φ ; α) . We have, for any b ∈ |B| and p(a) b,p b,p4 ⊗n the object Aa is the p(a)-th power in C of the Aa. Finally, the ~ai = (a1, . . . , an) ∈ |A |, writing p = [a1, . . . , an], N p(a) p(a) object a∈|p| Aa denotes the tensor of the spaces Aa along n p(a) † A † O Aa the order we have fixed on |A|. Different orders give isomorphic (φ ; eq )b,~ai = φb,p ; eq ;α ; ren~ai objects, all presenting the symmetric n-power, so we leave the order a∈|p| n A 0 implicit. The morphism (eq ) is 0 if p 6= [a1, . . . , an]; p,(a1,...,an) = φb,~a ; α ; α ; ren~ai otherwise it is equal to the following composition of morphisms σ(i) = φb,~aσ(i) ; ren~ai N A⊗p(a) a∈|p| a = φb,~ai p(a) : α;ren 0 N Aa (a1...an) 4 a∈|p| eq where σ is the permutation in Sn transforming ~ai into p and α 0 N ⊗p(a) the associator such that φb,p4 ; α ∈ C(Bb, a∈|p| Aa ). The N p(a) N$n 0 Aa Aa , passage from the second to the third line is the remark that α is a∈|p| i=1 i the inverse of α. The last line is achieved by the hypothesis that φ equalizes all permutations on Sn. where α ; ren(a1,...,an) is the composition of the associator and ⊗p(a) † † N The uniqueness of φ is inferred from that of φb,p. any symmetry mapping the object a∈|p| Aa to the object n Nn The fact that (An, eqA ) preserves tensor products can be easily Aai . i=1 achieved by checking that the whole proof continues to hold if we n Proof. Let us prove that the morphism eqA is well-defined, add the needed tensors. p(a) N Aa i.e., that the composition a∈|p| eq ; α ; ren~ai is indepen- Free Exponential Comonoid dent of the chosen symmetry ren~ai , for any sequence ~ai = ⊗n Lemma 58. If C has the symmetric n-th power of every object and (a1, . . . , an) ∈ |A |. In fact, for any σ ∈ Sn such that α ; σ if such a power preserves tensor products, then in C⊕ the object N ⊗p(a) Nn n maps Aa to Aa , there is a family {σa}a∈|p| of L a∈|p| i=1 i !A := n A is the free commutative comonoid generated by A, N A ⊕ permutations σa ∈ Sp(a) such that α ; σ = a∈|p| σa ; α ; ren~ai . the co-multiplication, here called contraction c ∈ C (!A, !A ⊗ A ⊕ Indeed, for i, j 6 p(a), define σa(i) = j whenever the i-th occur- !A), the counit, here called weakening w ∈ C (!A, 1), and the A ⊕ rence of a in (a1, . . . , an) becomes the j-th occurrence of a in the dereliction d ∈ C (!A, A) are given by sequence (aσ−1(1), . . . , aσ−1(n)). Then, wA := π0, dA := π1, p(a) p(a) O Aa O Aa A n+m n,m −1 −1 eq ;α ; σ = (eq ;σa); α ; ren~ai c := hhπ ; c im ; distr ; σin ; distr , a∈|p| a∈|p| where cn,m is the unique morphism commuting the diagram p(a) A N a α and the latter is equal to a∈|p| eq ; α ; ren~ai , since we have ⊗(n+m) ⊗n ⊗m p(a) p(a) A / A ⊗ A (25) Aa Aa O eq ; σa = eq for every a. O n n+m n m Let us now prove that (An, eqA ) is the equalizer of the n! eqA eqA ⊗ eqA ⊗n An An symmetries of A . We first prove that eq ; σ = eq , for cA,n,m An+m An ⊗ Am any symmetry σ ∈ Sn. The proof is componentwise: in case / ~ai = (a1, . . . an) is not an enumeration of a multiset p (i.e., n n which exists by applying the universal property to the equalizer p 6= [a , . . . , a ]), then both (eqA ;σ) and eqA are equal An Am 1 n p,~ai p,~ai eq ⊗ eq (see Lemma 56). n p(a) to 0. Otherwise, we have (eqA ;σ) = (N eqAa ); p,~ai a∈|p| Proof. The morphisms w and c give a structure of comonoid to An α ; σ~a ,~a , but the latter is equal to (eq ;σ)p,~a since we σ−1(i) i i !A. In fact by using the uniqueness of the morphism cn,m in proved that such a morphism is invariant under the symmetries with diagram (25) one can check the three equations Nn A as codomain. i=1 ai c ;(c ⊗ !A); α = c ; (!A ⊗ c), Now, let us take a morphism φ ∈ C⊕(B, A⊗n) equalizing the group of the n! symmetries of A⊗n and let us prove that φ has a c ; A ⊗ w ; ρ = A, c ; w ⊗ A ; λ = A. n unique decomposition into φ† ; eqA . The definition of φ† is given For example, by an easy computation one can reduce the first componentwise and depends on the order 4 on |A| assumed for equation to checking that, for every n, m, r ∈ , we have the n N giving a particular presentation of the object A . Let b ∈ |B|, equation : cn+m,r ; cn,m ⊗ idAr ;α = cn,m+r ; idAn ⊗cm,r. Then, n p ∈ |A |, and let p4 = (a1, . . . , an) be the unique sequence which by using diagram (25), such an equation is reduced to proving the is an enumeration of p increasing with respect to 4 (i.e., ai 4 ai+1 equality of a composition of the associator morphisms mapping the

15 2013/10/2 space A⊗(n+m+r) into A⊗n ⊗ (A⊗m ⊗ A⊗r). Such a composition = µ ; µn ⊗ µm ; α ; ⊗(n+m) ; α by (27) is always unique by the Monoidal Coherence Theorem [11]. = µ ;(µn ; ⊗n) ⊗ (µm ; ⊗m) The comonoid is moreover commutative. In fact, the equation n m c = c ; σ is equivalent to proving, for every pair of numbers m, n, = µ ; n ⊗ m ; eqA ⊗ eqA by (25) that cn,m = cm,n ; σ. The claim follows similarly to the previous m n The uniqueness easily follows using the uniqueness of diagram 28. cases. In fact from the naturality of σ one gets σ ; eqA ⊗ eqA = n m eqA ⊗ eqA ;σ. Finally, let us prove that the comonoid is free. Let B, µ ∈ C⊕(B, B ⊗ B), ν ∈ C⊕(B, 1) be a commutative comonoid and A ?-autonomous category such that each object has a free  ∈ C⊕(B, A). We prove that there exists a unique comonoid comonoid is usually called a Lafont category, which is known morphism † such that to be a model of linear logic [13]. In particular, the linear expo- nential comonad is given by the functorial promotion mapping an d ⊕ !A / A. (26) object A to !A and a morphism φ ∈ C (A, B) to the unique O > comonoid morphism !φ ∈ C⊕(!A, !B) satisfying the equation  † d ; φ = !φ ; d, which has exactly one solution by the freeness of the exponential comonoid on B. Weakening gives the counit and B the co-multiplication (also called digging) is the unique comonoid morphism dig ∈ C⊕(!A, !!A) such that dig ; d = id. Finally, n µn ∈ C⊕(B, B⊗n) We define the -ary diagonal as follows: the last morphism which is essential to interpret our calculus is ⊕ µ0 := ν, µn+1 := µ ; µn ⊗ id . m ∈ C (!A ⊗ !B, !(A ⊗ B)) which is the unique comonoid mor- phism such that m ; d = d ⊗ d. By induction on n one can prove that µn+m = µ ; µn ⊗ µm ; αλ. (27) A.2 Proof of the compact closure of CPMs. The tensor ⊗ is defined on objects by Then, we define n as the unique morphism making this diagram commute: (n, G) ⊗ (m, H) := (nm, G ⊗ H), n eqA where we use the isomorphism nm,nm = n×m,n×m obtained An / A⊗n. (28) C C O 4 by the lexicographic order on the pairs (i, j) ∈ n × m, and G ⊗ H ⊗n ⊗n unique n B  is intended to be the subgroup of Snm of the permutations of the 4 n form g ⊗ h, with g ∈ G, h ∈ H acting as (i, j) 7→ (g(i), h(j)). B µ 0 0 Notice that whenever f is in CPMs((n, G), (n ,G )) and h ∈ Such a morphism is well-defined since by the commutativity of CPMs((m, H), (m0,H0)), then the usual tensor product f ⊗ h µ the morphism µn ; ⊗n equalizes the A⊗n symmetries and by (with in addition the equalities ∞ ⊗ h = f ⊗ ∞ = ∞) enjoys the n Lemma 57, (An, eqA ) is the equalizer of such symmetries. We condition G⊗G0 ;f ⊗h;H⊗H0 = (G;f ;G0)⊗(H;g;H0) = f ⊗h. † n then set  := h in. The tensor unit is I = (1, {id}). Symmetries, unit, and asso- The morphism † makes the diagram (26) commute, namely ciativity maps are obtained from those of CPM by pre-composing † ; d = 1 = . We also have † ; w = 0 = ν. The last equation and post-composing with the actions of the groups of the objects. we need to check is † ; c = µ ; † ⊗ †. First, notice that proving For example, the two symmetries of (n, G) ⊗ (m, H) are G ⊗ H such an equation is equivalent to proving the commutativity of the (which is the identity in this category) and G ⊗ H ; σ ; H ⊗ G, where σ is the symmetry in CPM of n ⊗ m. The idempotence of following, for every n, m ∈ N: G and H ensures that the two morphisms are in CPMs and one can ⊗n ⊗m An Am A ⊗ A An Am check that they give a symmetric monoidal structure to CPMs. eq ⊗ eq 3 k eq ⊗ eq The compact closure is given by (n, G)∗ := (n, G); the unit n m n m ∗ A ⊗ A A ⊗ A . η(n,G) ∈ CPMs(I, (n, G) ⊗ (n, G)) (resp. co-unit (n,G) ∈ ∗ i n+m n 4 m CPMs((n, G) ⊗ (n, G) ,I)) is the composition (resp. precompo- cn,m A B ⊗ B  ⊗ j 4 sition) of the unit (resp. co-unit) of CPM with G ⊗ G. In other n+m µ  B words, writing Ei,j for the matrix having 0 everywhere, except 1 In fact, the right-hand side (as well as the left-hand side) of the at (i, j): ⊗n X diagram equalizes the group of n! × m! permutations of A ⊗ η (1) := G(E ) ⊗ G(E ) ⊗m An Am (n,G) i,j i,j A . So by the universal property of eq ⊗ eq (which are the i,j equalizers of such permutations, since tensor equalizers preserve X 1 0 0 0 0 0 0 tensors by Lemma 57), we have that there is a unique morphism (n,G)(Ei,j ⊗ Ei ,j ) := 2 δg(i),g (i )δg(j),g (j ) An Am #G that composed with eq ⊗ eq gives that side of the diagram. g,g0∈G n+m The commutativity of the diagram then implies  ; cn,m = µ ; n ⊗ m. From this then follows that for every b ∈ |B|, p, q ∈ |!A| such that the cardinality of p (resp. of q) is n (resp. These maps are completely positive: † † † m), we have ( ; c)b,(p,q) = (µ ;  ⊗  )b,(p,q). The claim follows • P The unit is completely positive because i,j Ei,j is a positive since the diagram commutes for every n, m ∈ N. matrix, and because G ⊗ G is completely positive: This makes So let us prove such a diagram. We have: η(1) positive. Therefore, for any positive matrix A, (η ⊗id)(A) n+m An Am  ; cn,m ;(eq ) ⊗ (eq ) is simply (η(1)) ⊗ A which is positive. n+m An+m • Let f be the map sending Ei,j ⊗ Ei0,j0 to δi,i0 δj,j0 . This map is =  ; eq ;α by (25) P completely positive as its characteristic matrix i,j Ei,j ⊗Ei,j = µn+m ; ⊗(n+m) ; α by (28) is positive.

16 2013/10/2   1 P 0 Proof. We only have to check for three additional cases to extend Since the counit can be written as 2 0 (g ⊗ g ) ◦ f, #G g,g the proof. it is completely positive. We have to prove that • The case M = Ω is satisfied, as Ω does not reduce, and its denotation is 0. ρ−1 ; id ⊗η ; α ;  ⊗ id ;λ = G (n,G) (n,G) (n,G) (n,G) (n,G) (n,G) • In the case letrecn+1 f x = M in N, the equation becomes and its dual starting with λ−1 . Let us denote the elements of (n,G)∗ n+1 ``A ∗ n×n letrec f x = M in N (qq ) = the base of C by {eh}h∈n×n and the action of g ∈ G on eh J n K `0`A 0 0∗ by eg(h). By an easy computation, we have that the left-hand side N{(λx.letrec f x = M in M)/f} (q q ), morphism applied to eh is equal to: J K which is valid because of the definition of the operation ()n X X 1 δ 0 G(e ) (29) (Equations (10) and (11)). Indeed, if φ is the denotation of M, (#G)2 g (h),g(k) k k∈n×n g,g0∈G !∆ ` λx.letrecn f x = M in M = X X 1 = δ −1 0 G(e ) (30) J n K (#G)2 g g (h),k k c id ⊗(dig;m;!(Λφ)) !(Λφ) k∈n×n g,g0∈G !∆ −→ !∆⊗!∆ −−−−−−−−−→ !∆⊗!(A(B) −→ !(A(B), X X X 1 whereas, provided that ψ is the denotation of N, = δ 0 G(e ) (31) (#G)2 g (h),k k k∈n×n g∈G g0∈g−1G !∆, Γ ` letrecn+1 f x = M in N = X X X 1 J K = δ 0 G(e ) (32) (#G)2 g (h),k k !∆ ⊗ Γ !(A(B) k∈n×n g∈G 0 g ∈G c ψ O X X 1  id ⊗(dig;m;!(Λφ))n+1 = δ 0 G(ek) (33) !∆ ⊗ Γ ⊗ !∆ / !∆ ⊗ Γ ⊗ !(A B), #G g (h),k ( k∈n×n g0∈G which is precisely N{(λx.letrecn f x = M in M)/f} , X 1 J K = G(eg0(k)) (34) by noticing that 0 #G g ∈G (dig; m; !(Λφ))n+1 = !∆ ` λx.letrecn f x = M in M . = G ; G(ek) = G(ek) (35) J K • The last case is letrec0 f x = M in N, using the fact that the The same holds for the dual. denotation of Ω is 0. A.3 Complete proof of Adequacy Reminder of Definition 33. finitary From now on, we consider the language extended with the Ω and A term is called when it does n not contain any occurrence of the un-indexed construct. the bounded let-rec constructor, as in Definition 32. let-rec It can however contain Ω and any of the indexed let-recn. We Lemma 59. Together with the new constructs, the language still call a closure finitary when its term is finitary. enjoys subject reduction (Proposition 11) and totality (Lemma 13). Lemma 63. A finitary closure only reduces to finitary closures. Proof. Subject reduction. The proof uses the substitution lemma (Lemma 10), still valid with the two additional constructs. Proof. The only rewrite rule creating a term with an un-indexed Totality. The two new rewrite rules add two cases to the induction: let-rec construct already has a term with an un-indexed let-rec since they do not modify the quantum state, the proof carries construct as redex. through. Reminder of Lemma 34. If [q1, `1,M1] is finitary, then every Definition 60. A Ω-term is a term generated by the following rewrite sequence grammar: p p p [q , ` ,M ] −→1 [q , ` ,M ] −→2 [q , ` ,M ] −→·3 · · O ::= Ω | ΩM | V Ω | Ω;N | Ω ⊗ N | V ⊗ Ω | 1 1 1 2 2 2 3 3 3 A B is finite. Moreover, a normal form of such a sequence is a closure let x ⊗ y = Ω in N | in` Ω | inr Ω | having as term either a value or an Ω-term. match Ω with (xA : N|yB : N 0). Lemma 61. If [q, `, M] is typable then either M is a value, or Proof. The first claim of the lemma is proved by showing that the p language is strongly normalizing. The second claim follows from a Ω-term, or there is a closure [q0, `0,M 0] such that [q, `, M] → 0 0 0 Lemma 61. [q , ` ,M ]. Moreover, if M is neither a value nor a Ω-term, the to- Strong normalization of the language is proved by reducing it to tal probability of all possible single-step reductions from [q, `, M] a non-deterministic language without quantum states, for which a is 1. standard proof technique can be used. Proof. The proof by induction on the typing derivation of M carries Let us define the language AUX whose terms are the terms through with the added constructs. of the extended quantum lambda-calculus, minus the let-rec construct, and whose operational semantics is given in Table8. Lemma 62 (Invariance of the interpretation). Let ` = |y1, . . . , ymi The operational semantics is obtained from Table3 and the rules and ` ` M : A. If M is not a value, nor an Ω-term, then for all for let-recn by replacing closures with the respective terms and 2m quantum states q ∈ C , the rules of Table 3b by dummy reduction rules: ``A ∗ X `0`A 0 0∗ M (qq ) = p · N (q q ). U(• ⊗ · · · ⊗ •) → • ⊗ · · · ⊗ • new ff → • new tt → • J K p J K [q,`,M]→[q0,`0,N] meas • −→ tt meas • −→ ff

17 2013/10/2 where • denotes a distinct term variable, which, by convention, it Reminder of Lemma 37. For every typing judgement Γ ` M : A, is never bound by an abstraction. Intuitively, • corresponds to the we have: variables pointing to the quantum state. Γ`A _ 0 Γ`A M = M0/M M . The type system of the language AUX is a simple type system J K M0 finitary J K with function types, pairs, , lists, and a base type qubit: A, B, C ::= qubit A → B 1 A × B A ⊕ B A`. Proof. By structural induction on the derivation of Γ ` M : A, one proves that: (i) Γ ` M 0 : A is derivable for every M 0 /M; (ii) The typing rules are found in Table9. Note that we treat the { M 0 Γ`A ; M 0 /M} is directed; (iii) the equation in the state- distinctive term variable • as a term constant, with its own typing mentJ holds.K All cases are trivial consequences of the induction hy- rule. pothesis and the continuity of all the categorical constructs. In the The language AUX satisfies subject reduction, and can be shown rec rule case, one notices that by definition Y(dig; m; !(Λφ)) = to be strongly normalizing using a standard technique (e.g. using W∞ (dig; m; !(Λφ))n. reducibility candidates). n=0 p One can map a finitary program from the quantum lambda Lemma 65. Let M/M 0, and let [q, `, M] −→ [q0, `0,N]. Then calculus to the language AUX as follows: p there exists a unique N 0 such that N/N 0 and [q, `, M 0] −→ [q, `, M] 7−→ M [q0, `0,N 0]. where M is M where all the variables of ` have been replaced Reminder of Lemma 38. For every M/M 0, we have that with •. It is straightforward to check that M is well-typed, then so Halt[q,`,M] 6 Halt[q,`,M0]. is M, and that if p Proof. We prove by induction on n the inequality: [q, `, M] −→ [q0, `0,M 0] X n X n Red 0 0 Red 0 0 0 0 . then [q,`,M],[q ,` ,N] 6 [q,`,M ],[q ,` ,N ] [q0,`0,N] [q0,`0,N0] M → M 0. from which trivially follows the statement. This concludes the proof of the lemma: if there were an infinite The case n = 0 is trivial, as both sides are equal to 1. Suppose reduction sequence in the quantum lambda-calculus starting with a that the result is true for n, and consider the value finitary program, it would generate an infinite rewrite sequence in AUX , which is not possible. X n+1 Red[q,`,M],[q0,`0,N] = [q0,`0,N] Corollary 64. For any finitary closure [q, `, M], there exists a X X n Red 00 00 Red 00 00 0 0 = number m ∈ N such that: [q,`,M],[q ,` ,P ] [q ,` ,P ],[q ,` ,N] [q0,`0,N] [q00,`00,P ] X m Halt[q,`,M] = Red[q,`,M],[q0,`0,V ] . X X n 00 00 00 00 0 0 [q0,`0,V ] Red[q,`,M],[q ,` ,P ] Red[q ,` ,P ],[q ,` ,N] . [q00,`00,P ] [q0,`0,N] Proof. By Konig’s¨ Lemma and Lemma 34, the reduction tree (36) with root [q, `, M] is finite. Let m be its height. We have that From Lemma 65, we deduce that for every P there exists a unique 0 0 0 m0 0 for every m > m, and every [q , ` ,V ], Red[q,`,M],[q0,`0,V ] = P such that Red[q,`,M],[q00,`00,P ] = Red[q,`,M0],[q00,`00,P 0] and m 0 Red[q,`,M],[q0,`0,V ]. We conclude by the definition of Halt (Equa- such that P/P . Remark that, independently from the rewrites tion (5)). P of M, there might exist other terms P 0 such that we have Red[q,`,M0],[q00,`00,P 0] 6= 0. For example, if M were Ω, although 0 Reminder of Corollary 35. Let M be a closed finitary term of unit there would be no such P there would still be one P . `1 Now, from induction hypothesis, we infer that for all of the pairs type. Then M ∗ = Halt[| i,| i,M] . J K (P,P 0),

Proof. We prove that, for any total finitary quantum closure of unit X n Red 00 00 0 0 type [q, `, M]: [q ,` ,P ],[q ,` ,N] 6 [q0,`0,N] ``1 ∗ M (qq ) = Halt[q,`,M] . X n J K Red[q00,`00,P 0],[q0,`0,N0] . (37) In fact, by Corollary 64, there exists m ∈ N such that Halt[q,`,M] = [q0,`0,N0] P m Red 0 0 . The proof is by induction on m. If [q0,`0,V ] [q,`,M],[q ,` ,V ] Using Equations (36) and (37) we deduce that m = 0, then either M = skip and Halt[q,`,M] = 1 or a M is an Ω-term and Halt[q,`,M] = 0. Notice that in both cases, being the X n+1 Red[q,`,M],[q0,`0,N] 6 closure total, we have that q and ` are empty. We conclude trivially [q0,`0,N] by the definition of skip and the fact that the semantics of an Ω- X X n term is the zero matrix.J TheK induction step follows by the induction Red[q,`,M],[q00,`00,P 0] Red[q00,`00,P 0],[q0,`0,N0] = hypothesis and Lemma 62. [q00,`00,P 0] [q0,`0,N0] X n+1 Red 0 0 0 0 . (38) / [q,`,M ],[q ,` ,N ] Reminder of Definition 36. Let be a relation between finitary 0 0 0 terms and general terms defined as the smallest congruence relation [q ,` ,N ] on terms satisfying, for every M/M 0 and N/N 0: This finishes the proof of the lemma. N{(λxA.ΩB )/f} / (letrec f x = M 0 in N 0) (letrecn f x = M in N) / (letrec f x = M 0 in N 0)

18 2013/10/2 (λxA.M) V → M{V/x} let xA ⊗ yB = V ⊗ W in N → N{V/x, W/y} A B skip;N → N match (in` V ) with (x : M|y : N) → M{V/x} A B splitV → V match (inr V ) with (x : M|y : N) → N{V/y} letrec0 f A(B x = M in N → N{(λxA.ΩB )/f} letrecn+1 f A(B x = M in N → N{(λxA.letrecn f A(B x = M in M)/f}

(a) Classical control.

U(• ⊗ · · · ⊗ •) → • ⊗ · · · ⊗ • new ff → • new tt → • meas • −→ tt meas • −→ ff

(b) What used to refer to quantum data.

0 0 0 0 0 0 MN → M NM ⊗ N → M ⊗ N in` M → in` M VM → VM V ⊗ M → V ⊗ M inr M → inr M M;N → M 0;N let xA ⊗ yB = M in N → let xA ⊗ yB = M 0 in N match M with (xA : P |yB : N) → match M 0 with (xA : P |yB : N)

(c) Congruence rules, under the hypothesis that M → M 0.

Table 8: Rewrite system for the language AUX of Lemma 34.

ax 1I Ω • ∆, x : A ` x : A ∆ ` skip : 1 ∆ ` Ω: A ` • : qubit

∆, x : A ` M : B ∆ ` M : A → B ∆ ` N : A ∆ ` M : 1 ∆ ` N : A →I →E 1 ∆ ` λxA.M : A → B ∆ ` MN : B ∆ ` M;N : A E

∆ ` M : A ∆ ` N : B ∆ ` M : A × B ∆, x : A, y : B ` N : C × ×E ∆ ` M ⊗ N : A × B I ∆ ` let xA × yB = M in N : C

∆, y : B ` N : C ∆ ` P : A ⊕ B ∆, x : A ` M : C ∆ ` M : A ∆ ` M : B r ` ⊕E ⊕I ⊕I A B ∆ ` in` M : A ⊕ B ∆ ` inr M : A ⊕ B ∆ ` match P with (x : M|y : N): C

∆ ` M : 1 ⊕ (A×A`) ∆, f :(A B), x : A ` M : B ∆, f :(A B) ` N : C ` ( ( −I split rec ∆, Γ ` M : A` ∆ ` splitA : A`→1 ⊕ (A×A`) ∆ ` letrecn+1 f A(B x = M in N : C

U of arity n meas new U ∆ ` meas : qubit → bit ∆ ` new : bit → qubit ∆ ` U : qubit×n → qubit×n

Table 9: Typing rules for the language AUX .

19 2013/10/2