From Symmetric Pattern-Matching to Quantum Control

. One perspective on quantum algorithms is that they are classical algorithms having access to a special kind of memory with exotic properties. This perspective suggests that, even in the case of quantum algorithms, the control ﬂow notions of sequencing, conditionals, loops, and recursion are entirely classical. There is however, another notion of control ﬂow, that is itself quantum. The notion of quantum conditional expression is reasonably well-understood: the execution of the two expressions becomes itself a superposition of executions. The quantum counterpart of loops and recursion is however not believed to be meaningful in its most general form. In this paper, we argue that, under the right circumstances, a reasonable notion of quantum loops and recursion is possible. To this aim, we ﬁrst propose a classical, typed, reversible language with lists and ﬁxpoints. We then extend this language to the closed quantum domain (without measurements) by allowing linear combinations of terms and restricting ﬁxpoints to structurally recursive ﬁxpoints whose termination proofs match the proofs of convergence of sequences in inﬁnite-dimensional Hilbert spaces. We additionally give an operational semantics for the quantum language in the spirit of algebraic lambda-calculi and illustrate its expressiveness by modeling several common unitary operations.


Introduction
The control flow of a program describes how its elementary operations are organized along the execution.Usual primitive control mechanisms are sequences, tests, iteration and recursion.Elementary operations placed in sequence are executed in order.Tests allow conditionally executing a group of operations and changing the course of the execution of the program.Finally, iteration gives the possibility to iterate a process an arbitrary number of times and recursion generalizes iteration to automatically manage the history of the operations performed during iteration.The structure of control flow for conventional (classical) computation is well-understood.In the case of quantum computation, control flow is still subject to debate.This paper proposes a working notion of quantum control in closed quantum systems, shedding new light on the problem, and clarifying several of the previous concerns.
Quantum computation.A good starting point for understanding quantum computation is to consider classical circuits over bits but replacing the bits with qubits, which are intuitively superpositions of bits weighed by complex number amplitudes.Computationally, a qubit is an abstract data type governed by the laws of quantum physics, whose values are normalized vectors of complex numbers in the Hilbert space C 2 (modulo a global phase).By choosing an orthonormal basis, say the classical bits tt and ff, a qubit can be regarded as a complex linear combination, α tt + β ff, where α and β are complex numbers such that |α| 2 + |β| 2 = 1.This generalizes naturally to multiple qubits: the state of a system of n qubits is a vector in the Hilbert space (C 2 ) ⊗n .
The operations one can perform on a quantum memory are of two kinds: quantum gates and measurements.Quantum gates are unitary operations that are "purely quantum" in the sense that they modify the quantum memory without giving any feedback to the outside world: the quantum memory is viewed as a closed system.A customary graphical representation for these operations is the quantum circuit, akin to conventional boolean circuits: wires represent qubits while boxes represents operations to perform on them.One of the peculiar aspects of quantum computation is that the state of a qubit is non-duplicable [1], a result known as the no-cloning theorem.A corollary is that a quantum circuit is a very simple kind of circuit: wires neither split nor merge.
Measurement is a fundamentally different kind of operation: it queries the state of the quantum memory and returns a classical result.Measuring the state of a quantum bit is a probabilistic and destructive operation: it produces a classical answer with a probability that depends on the amplitudes α, β in the state of the qubit while projecting this state onto tt or ff, based on the result.
For a more detailed introduction to quantum computation, we refer the reader to recent textbooks (e.g., [2]).
Control flow in quantum computation.In the context of quantum programming languages, there is a well-understood notion of control flow: the so-called classical control flow.A quantum program can be seen as the construction, manipulation and evaluation of quantum circuits [3,4].In this setting, circuits are simply considered as special kinds of data without much computational content, and programs are ruled by regular classical control.
One can however consider the circuit being manipulated as a program in its own right: a particular sequence of execution on the quantum memory is then seen as a closed system.One can then try to derive a notion of quantum control [5], with "quantum tests" and "quantum loops".Quantum tests are a bit tricky to perform [5,6] but they essentially correspond to well-understood controlled operations.The situation with quantum loops is more subtle [6,7].First, a hypothetical quantum loop must terminate.Indeed, a non-terminating quantum loop would entail an infinite quantum circuit, and this concept has so far no meaning.Second, the interaction of quantum loops with measurement is problematic: it is known that the canonical model of open quantum computation based on superoperators [8,9] is incompatible with such quantum control [6].Finally, the mathematical operator corresponding to a quantum loop would need to act on an infinite-dimensional Hilbert space and the question of mixing programming languages with infinitary Hilbert spaces is still an unresolved issue.
Our contribution.In this paper, we offer a novel solution to the question of quantum control: we define a purely quantum language, inspired by Theseus [10], featuring tests and fixpoints in the presence of lists.More precisely, we propose (1) a typed, reversible language, extensible to linear combinations of terms, with a reduction strategy akin to algebraic lambda-calculi [11][12][13]; (2) a model for the language based on unitary operators over infinite-dimensional Hilbert spaces, simplifying the Fock space model of Ying [7].This model captures lists, tests, and structurally recursive fixpoints.We therefore settle two longstanding issues.(1) We offer a solution to the problem of quantum loops, with the use of terminating, structurally recursive, purely quantum fixpoints.We dodge previously noted concerns (e.g., [6]) by staying in the closed quantum setting and answer the problem of the external system of quantum "coins" [7] with the use of lists.
(2) By using a linear language based on patterns and clauses, we give an extensible framework for reconciling algebraic calculi with quantum computation [16,12,11].
In the remainder of the paper, we first introduce the key idea underlying our classical reversible language in a simple first-order setting.We then generalize the setting to allow second-order functions, recursive types (e.g., lists), and fixpoints.After illustrating the expressiveness of this classical language, we adapt it to the quantum domain and give a semantics to the resulting quantum language in infinite-dimensional Hilbert spaces.Technical material that would interrupt the flow or that is somewhat complementary has been relegated to an extended version of the paper [17].

Pattern-Matching Isomorphisms
The most elementary control structure in a programming language is the ability to conditionally execute one of several possible code fragments.Expressing such an abstraction using predicates and nested if -expressions makes it difficult for both humans and compilers to reason about the control flow structure.Instead, in modern functional languages, this control flow paradigm is elegantly expressed using pattern-matching.This approach yields code that is not only more concise and readable but also enables the compiler to easily verify two crucial properties: (i) non-overlapping patterns and (ii) exhaustive coverage of a datatype using a collection of patterns.Indeed most compilers for functional languages perform these checks, warning the user when they are violated.At a more fundamental level, e.g., in type theories and proof assistants, these properties are actually necessary for correct reasoning about programs.Our first insight, explained in this section, is that these properties, perhaps surprisingly, are sufficient to produce a simple and intuitive first-order reversible programming language.

An Example
We start with a small illustrative example, written in a Haskell-like syntax.Fig. 1 gives the skeleton of a function f that accepts a value of type Either Int Int; the patterns on the left-hand side exhaustively cover every possible incoming value and are non-overlapping.Similarly, Fig. 2 gives the skeleton for a function g that accepts a value of type (Bool,Int); again the patterns on the left-hand side exhaustively cover every possible incoming value and are non-overlapping.Now we claim that since the types Either Int Int and (Bool,Int) are isomorphic, we can combine the patterns of f and g into symmetric pattern-matching clauses to produce a reversible function between the types Either Int Int and (Bool,Int).Fig. 3 gives one such function; there, we suggestively use <-> to indicate that the function can be executed in either direction.This reversible function is obtained by simply combining the non-overlapping exhaustive patterns on the two sides of a clause.In order to be well-formed in either direction, these clauses are subject to the constraint that each variable occurring on one side must occur exactly once on the other side (and with the same type).Thus it is acceptable to swap the second and third right-hand sides of h but not the first and second ones.

Terms and Types
We present a formalization of the ideas presented above using a simple typed first-order reversible language.The language is two-layered.The first layer contains values, which also play the role of patterns.These values are constructed from variables ranged over x and the introduction forms for the finite types a, b constructed from the unit type and sums and products of types.The second layer contains collections of pattern-matching clauses that denote isomorphisms of type a ↔ b.Computations are chained applications of isomorphisms to values: The typing rules are defined using two judgments: ∆ v v : a for typing values (or patterns) and terms; and ω ω : a ↔ b for typing collections of pattern-matching clauses denoting an isomorphism.As it is customary, we write The typing rules for values are the expected ones.The only subtlety is the fact that they are linear: because values act as patterns, we forbid the repetition of variables.A typing context ∆ is a set of typed variables x 1 : a 1 , . . ., x n : a n .A value typing judgment is valid if it can be derived from the following rules: The typing rule for term construction is simple and forces the term to be closed: The most interesting type rule is the one for isomorphisms.We present the rule and then explain it in detail: The rule relies on two auxiliary conditions as motivated in the beginning of the section.These conditions are (i) the orthogonality judgment v⊥v that formalizes that patterns must be non-overlapping and (ii) the condition dim(a) = n which formalizes that patterns are exhaustive.The rules for deriving orthogonality of values or patterns are: The idea is simply that the left and right injections are disjoint subspaces of values.To characterize that a set of patterns is exhaustive, we associate a dimension with each type.For finite types, this is just the number of elements in the type and is inductively defined as follows: dim For a given type a, if a set of non-overlapping clauses has cardinality dim(a), it is exhaustive.Conversely, any set of exhaustive clauses for a type a either has cardinality dim(a) or can be extended to an equivalent exhaustive set of clauses of cardinality dim(a).

Semantics
We equip our language with a simple operational semantics on terms, using the natural notion of matching.To formally define it, we first introduce the notion of variable assignation, or valuation, which is a partial map from a finite set of variables (the support) to a set of values.We denote the matching of a value w against a pattern v and its associated valuation σ as σ[v] = w and define it as follows: If σ is a valuation whose support contains the variables of v, we write σ(v) for the value where the variables of v have been replaced with the corresponding values in σ.
Given these definitions, we can define the reduction relation on terms.The redex Because of the conditions on patterns, a matching pattern exists by exhaustivity of coverage, and this pattern is unique by the non-overlapping condition.Congruence holds: ω t → ω t whenever t → t .As usual, we write s → t to say that s rewrites in one step to t and s → * t to say that s rewrites to t in 0 or more steps.
Because of the conditions set on patterns, the rewrite system is deterministic.More interestingly, we can swap the two sides of all pattern-matching clauses in an isomorphism ω to get ω −1 .The execution of ω −1 is the reverse execution of ω in the sense that ω −1 (ω t) → * t and ω(ω −1 t ) → * t .

Second-Order Functions, Lists, and Recursion
The first-order reversible language from the previous section embodies symmetric-pattern matching clauses as its core notion of control.Its expressiveness is limited, however.We now show that it is possible to extend it to have more in common with a conventional functional language.To that end, we extend the language with the ability to parametrically manipulate isomorphisms, with a recursive type (lists), and with recursion.

Terms and Types
Formally, the language is now defined as follows.
Table 1.Typing rules for terms and values (Products) We use variables f to span a set of iso-variables and variables x to span a set of term-variables.We extend the layer of isos so that it can be parameterized by a fixed number of other isos, i.e., we now allow higher-order manipulation of isos using λf.ω, iso-variables, and applications.Isos can now be used inside the definition of other isos with a let-notation.These let-constructs are however restricted to products of term-variables: they essentially serve as syntactic sugar for composition of isos.An extended value is then a value where some of its free variables are substituted with the result of the application of one or several isos.Given an extended value e, we define its bottom value, denoted with Val(e) as the value "at the end" of the let-chain: Val(v) = v, and Val(let p = ωp in e) = Val(e).The orthogonality of extended values is simply the orthogonality of their bottom value.
As usual, the type of lists [a] of elements of type a is a recursive type and is equivalent to 1 ⊕ (a × [a]).We build the value [] (empty list) as inj l () and the term t 1 : t 2 (cons of t 1 and t 2 ) as inj r t 1 , t 2 .In addition, to take full advantage of recursive datatypes, it is natural to consider recursion.Modulo a termination guarantee it is possible to add a fixpoint to the language: we extend isos with the fixpoint constructor µf.ω.Some reversible languages allow infinite loops and must work with partial isomorphisms instead.Since we plan on using our language as a foundation for a quantum language we insist of termination.
Since the language features two kinds of variables, there are typing contexts (written ∆) consisting of base-level typed variables of the form x : a, and typing context (written Ψ ) consisting of typed iso-variables of the form f : T .As terms and values contain both base-level and iso-variables, one needs two typing contexts.Typing judgments are therefore written respectively as ∆; Ψ v t : a.The updated rules for ( v ) are found in Tab. 1.As the only possible free variables µf.ω terminates in any finite context Table 2. Typing rules for isos in isos are iso-variables, their typing judgments only need one context and are written as Ψ ω ω : T .The rules for typing derivations of isos are in Tab. 2. It is worthwhile mentioning that isos are treated in a usual, non-linear way: this is the purpose of the typing context separation.The intuition is that an iso is the description of a closed computation with respect to inputs: remark that isos cannot accept value-types.As computations, they can be erased or duplicated without issues.On the other hand, value-types still need to be treated linearly.
In the typing rule for recursion, the condition "µf.ω terminates in any finite context" formally refers to the following requirement.A well-typed fixpoint µf.ω of type is terminating in a 0-context if for all closed isos ω i : a i ↔ b i not using fixpoints and for every closed value v of type a, the term ((µf.ω)ω 1 . . .ω n )v terminates.We say that the fixpoint is terminating in an (n + 1)-context if for all closed isos ω i : a i ↔ b i terminating in n-contexts, and for every closed value v of type a, the term ((µf.ω)ω 1 . . .ω n )v terminates.Finally, we say that the fixpoint is terminating in any finitary context if for all n it is terminating in any n-context.
With the addition of lists, the non-overlapping and exhaustivity conditions need to be modified.The main problem is that we can no longer define the dimension of types using natural numbers: [a] is in essence an infinite sum, and would have an "infinite" dimension.Instead, we combine the two conditions into the concept of orthogonal decomposition.Formally, given a type a, we say that a set S of patterns is an orthogonal decomposition, written OD a (S), when these patterns are pairwise orthogonal and when they cover the whole type.We formally define OD a (S) as follows.For all types a, OD a {x} is valid.For the unit type, OD 1 {()} is valid.If OD a (S) and OD b (T ), then where FV(t) stands for the set of free value-variables in t.We then extend the notion of orthogonal decomposition to extended values as follows.If S is a set of extended values, OD ext a (S) is true whenever OD a {Val(e) | e ∈ S}.With this new characterization, the typing rule of iso in Eq. 1 still holds, and then can be re-written using this notion of orthogonal decomposition as shown in Tab. 2.
The rewriting system satisfies the usual properties for well-typed terms: it is terminating, well-typed closed terms have a unique normal value-form, and it preserves typing.
Theorem 1.The inversion operation is well-typed, in the sense that if f 1 : Thanks to the fact that the language is terminating, we also recover the operational result of Sec.2.3.

Examples
In the previous sections, we developed a novel classical reversible language with a familiar syntax based on pattern-matching.The language includes a limited notion of higher-order functions and (terminating) recursive functions.We illustrate the expressiveness of the language with a few examples and motivate the changes and extensions needed to adapt the language to the quantum domain.
We encode booleans as follows: B = 1 ⊕ 1, tt = inj l (), and ff = inj r ().One of the easiest function to define is not : B ↔ B which flips a boolean.The controlled-not gate which flips the second bit when the first is true can also be expressed: All the patterns in the previous two functions are orthogonal decompositions which guarantee reversibility as desired.By using the abstraction facilities in the language, we can define higherorder operations that build complex reversible functions from simpler ones.For example, we can define a conditional expression parameterized by the functions used in the two branches: Using if and the obvious definition for the identity function id, we can define ctrl :: (a ↔ a) → (B ⊗ a ↔ B ⊗ a) as ctrl f = if f id and recover an alternative definition of cnot as ctrl not.We can then define the controlledcontrolled-not gate (aka the Toffoli gate) by writing ctrl cnot.We can even iterate this construction using fixpoints to produce an n-controlled-not function that takes a list of n control bits and a target bit and flips the target bit iff all the control bits are tt: The language is also expressible enough to write conventional recursive (and higher-order) programs.We illustrate this expressiveness using the usual map operation and an accumulating variant mapAccu: The three examples cnot*, map and mapAccu uses fixpoints which are clearly terminating in any finite context.Indeed, the functions are structurally recursive.
A formal definition of this notion for the reversible language is as follows.
where a is a structurally recursive type.We say that µf.ω is structurally recursive provided that for each i ∈ I, the value v i is either of the form [], p 1 , . . .p n or of the form h : t, p 1 , . . .p n .In the former case, e i does not contain f as a free variable.In the latter case, e i is of the form This definition will be critical for quantum loops in the next section.

From Reversible Isos to Quantum Control
In the language presented so far, an iso ω : a ↔ b describes a bijection between the set B a of closed values of type a and the set B b of closed values of type b.If one regards B a and B b as the basis elements of some vector space a and b , the iso ω becomes a 0/1 matrix.
As an example, consider an iso ω defined using three clauses of the form From the exhaustivity and non-overlapping conditions derives the fact that the space a can be split into the direct sum of the three subspaces a vi (i = 1, 2, 3) generated by v i .Similarly, b is split into the direct sum of the subspaces b v i generated by v i .One can therefore represent ω as the matrix ω in Fig. 4: The "1" in each column v i indicates to which subspace b v j an element of a vi is sent to.In Sec.2.2 we discussed the fact that v i ⊥v j when i = j.This notation hints at the fact that a and b could be seen as Hilbert spaces and the mapping ω as a unitary map from a to b .The purpose of this section is to extend and formalize precisely the correspondence between isos and unitary maps.
The definition of clauses is extended following this idea of seeing isos as unitaries, and not only bijections on basis elements of the input space.We therefore essentially propose to generalize the clauses to complex, linear combinations of values on the right-hand-side, such as shown on the left, with the side conditions on that the matrix of Fig. 5 is unitary.We define in Sec.5.1 how this extends to second-order.

Extending the Language to Linear Combinations of Terms
The quantum unitary language extends the reversible language from the previous section by closing extended values and terms under complex, finite linear combinations.For example, if v 1 and v 2 are values and α and β are complex numbers, α • v 1 + β • v 2 is now an extended value.
Several approaches exist for performing such an extension.One can update the reduction strategy to be able to reduce these sums and scalar multiplications to normal forms [12,18], or one can instead consider terms modulo the usual algebraic equalities [13,18]: this is the strategy we follow for this paper.
When extending a language to linear combination of terms in a naive way, this added structure might generate inconsistencies in the presence of unconstrained fixpoints [13,12,18].The weak condition on termination we imposed on fixpoints in the classical language was enough to guarantee reversibility.With the presence of linear combinations, we want the much stronger guarantee of unitarity.For this reason, we instead impose fixpoints to be structurally recursive.
The quantum unitary language is defined by allowing sums of terms and values and multiplications by complex numbers: if t and t are terms, so is α • t + t .Terms and values are taken modulo the equational theory of modules.We furthermore consider the value and term constructs −, − , let p = − in −, inj l (−), inj r (−) distributive over sum and scalar multiplication.We do not however take iso-constructions as distributive over sum and scalar multiplication: . This is in the spirit of Lineal [12,11].
The typing rules for terms and extended values are updated as follows.We only allow linear combinations of terms and values of the same type and of the same free variables.Fixpoints are now required to be structurally recursive, as introduced in Def. 1. Finally, an iso is now not only performing an "identity" as in Fig. 4 The reduction relation is updated in a way that it remains deterministic in this extended setting.It is split into two parts: the reduction of pure terms, i.e. non-extended terms or values, and linear combinations thereof.Pure terms and values reduce using the reduction rules found in Tab. 3. We do not extend applicative contexts to linear combinations.For linear combinations of pure terms, we simply ask that all pure terms that are not normal forms in the combination are reduced.This makes the extended reduction relation deterministic.
Example 1.This allows one to define an iso behaving as the Hadamard gate, or a slightly more complex iso conditionally applying another iso, whose behavior as a matrix is shown in Fig. 6.
With this extension to linear combinations of terms, one can characterize normal forms as follows.
Lemma 1 (Structure of the normal forms).Let ω be such that ω ω : a ↔ b.For all closed values v of type a, the term ω v rewrites to a normal form N i=1 α i • w i where N < ∞, each w i is a closed value of type b and i |α i | = 1.Proof.The fact that ω v converges to a normal form is a corollary of the fact that we impose structural recursion on fixpoints.The property of the structure of the normal form is then proven by induction on the maximal number of steps it takes to reach it.It uses the restriction on the introduction of sums in the typing rule for clauses in isos and the determinism of the reduction.
In the classical setting, isos describe bijections between sets of closed values: it was proven by considering the behavior of an iso against its inverse.In the presence of linear combinations of terms, we claim that isos describe more than bijections: they describe unitary maps.In the next section, we discuss how types can be understood as Hilbert spaces (Sec.5.2) and isos as unitary maps (Secs 5.3 and 5.4).

Modeling Types as Hilbert Spaces
By allowing complex linear combinations of terms, closed normal forms of finite types such as B or B ⊗ B can be regarded as complex vector spaces with basis consisting of closed values.For example, B is associated with We can consider this space as a complex Hilbert space where the scalar product is defined on basis elements in the obvious way: v|v = 1 and v|w = 0 if v = w.The map Had of Ex. 1 is then effectively a unitary map on the space B .
The problem comes from lists: the type [1] is inhabited by an infinite number of closed values: [], [()], [(), ()], [(), (), ()],. . .To account for this case, we need to consider infinitely dimensional complex Hilbert spaces.In general, a complex Hilbert space [19] is a complex vector space endowed with a scalar product that is complete with respect the distance induced by the scalar product.The completeness requirement implies for example that the infinite linear combination [] + 1  2 • [()] + 1 4 [(), ()] + 1 8 [(), (), ()] + • • • needs to be an element of [B] .To account for these limit elements, we propose to use the standard [19] Hilbert space 2 of infinite sequences.Definition 2. Let a be a value type.As before, we write B a for the set of closed values of type a, that is, B a = {v | v v : a}.The span of a is defined as the Hilbert space a = 2 (B a ) consisting of sequences (φ v ) v∈Ba of complex numbers indexed by B a such that v∈Ba |φ v | 2 < ∞.The scalar product on this space is defined as ( We shall use the following conventions.A closed value v of a is identified with the sequence (δ v,v ) v ∈Ba where δ v,v = 1 and δ v,v = 0 if v = v .An element (φ v ) v∈Ba of a is also written as the infinite, formal sum v∈Ba φ v • v.

Modeling Isos as Bounded Linear Maps
We can now define what is the linear map associated to an iso.Definition 3.For each closed iso ω ω : a ↔ b we define ω as the linear map from a to b sending the closed value v : a to the normal form of ω v : b under the rewrite system.
In general, the fact that ω is well-defined is not trivial.If it is formally stated in Theorem 3, we can first try to understand what could go wrong.The problem comes from the fact that the space a is not finite in general.Consider the iso map Had : This is an infinite sum of sums of complex numbers: we need to make sure that it is well-defined: this is the purpose of the next result.Because of the constraints on the language, we can even show that it is a bounded linear map.
In the case of the map map Had, we can understand why it works as follows.The space [B] can be decomposed as the direct sum ∞ i=0 E i , where E i is generated with all the lists in B of size i.The map map Had is acting locally on each finitely-dimensional subspace E i .It is therefore well-defined.Because of the unitarity constraint on the linear combinations appearing in Had, the operation performed by map Had sends elements of norm 1 to elements of norm 1.This idea can be formalized and yield the following theorem.Theorem 3.For each closed iso ω ω : a ↔ b the linear map ω : a → b is well-defined and bounded.

Modeling Isos as Unitary Maps
In this section, we show that not only closed isos can be modeled as bounded linear maps, but that these linear maps are in fact unitary maps.The problem comes from fixpoints.We first consider the case of isos written without fixpoints, and then the case with fixpoints.
Without recursion.The case without recursion is relatively easy to treat, as the linear map modeling the iso can be compositionally constructed out of elementary unitary maps.
Theorem 4. Given a closed iso ω ω : a ↔ b defined without the use of recursion, the linear map π : a → b is unitary.
The proof of the theorem relies on the fact that to each closed iso ω ω : a ↔ b one can associate an operationally equivalent iso ω ω : a ↔ b that does not use iso-variables nor lambda-abstractions.We can define a notion of depth of an iso as the number of nested isos.The proof is done by induction on this depth of the iso ω: it is possible to construct a unitary map for ω using the unitary maps for each ω ij as elementary building blocks.
As an illustration, the semantics of Gate of Example 1 is given in Figure 6.
Isos with structural recursion.When considering fixpoints, we cannot rely anymore on this finite compositional construction: the space a cannot anymore be regarded as a finite sum of subspaces described by each clause.
We therefore need to rely on the formal definition of unitary maps in general, infinite Hilbert spaces.On top of being bounded linear, a map ω : a → b is unitary if (1) it preserves the scalar product: ω (e)| ω (f ) = e|f for all e and f in a and (2) it is surjective.
Theorem 5. Given a closed iso ω ω : a ↔ b that can use structural recursion, the linear map π : a → b is unitary.
The proof uses the idea highlighted in Sec.5.4: for a structurally recursive iso of type [a] ⊗ b ↔ c, the Hilbert space [a] ⊗ b can be split into a canonical decomposition E 0 ⊕ E 1 ⊕ E 2 ⊕ • • • , where E i contains only the values of the form [x 1 . . .x i ], y , containing the lists of size i.On each E i , the iso is equivalent to an iso without structural recursion.

Conclusion
In this paper, we proposed a reversible language amenable to quantum superpositions of values.The language features a weak form of higher-order that is nonetheless expressible enough to get interesting maps such as generalized Toffoli operators.We sketched how this language effectively encodes bijections in the classical case and unitary operations in the quantum case.It would be interesting to see how this relates to join inverse categories [14,15].
In the vectorial extension of the language we have the same control as in the classical, reversible language.Tests are captured by clauses, and naturally yield quantum tests: this is similar to what can be found in QML [5,6], yet more general since the QML approach is restricted to if-then-else constructs.The novel aspect of quantum control that we are able to capture here is a notion of quantum loops.These loops were believed to be hard, if not impossible.What makes it work in our approach is the fact that we are firmly within a closed quantum system, without measurements.This makes it possible to only consider unitary maps and frees us from the Löwer order on positive matrices [6].As we restrict fixpoints to structural recursion, valid isos are regular enough to capture unitarity.Ying [7] also proposes a framework for quantum while-loops that is similar in spirit to our approach at the level of denotations: in his approach the control part of the loops is modeled using an external systems of "coins" which, in our case, correspond to conventional lists.Reducing the manipulation of this external coin system to iteration on lists allowed us to give a simple operational semantics for the language.

Table 3 .
Reduction rules