Abstract. Since the seminal work of Selinger and Valiron, the standard design for quantum lambda calculi has kept the quantum state outside the program: terms manipulate pointers to an external register. This is largely due to the difficulty of eliminating tensor products. For example, the calculus λρ∘ embeds density matrices directly within terms, where terms carry the entire computation state, a feature particularly appealing for program verification. However, lacking a tensor elimination construct, it can neither access the individual qubits of a compound state nor discard them. Borgna showed that this inability to discard qubits makes the calculus strictly less expressive than the quantum lambda calculus of Selinger and Valiron.
In this paper we show that tensor elimination is possible in this setting. The key observation is that the Pauli decomposition, combined with the spectral decomposition of the Pauli matrices, allows any n-qubit density matrix to be expressed as a real linear combination of tensor products of single-qubit density matrices. Exploiting this fact, we extend λρ∘ with a construct let x⊗n=ρ in t, which binds each xi to a single-qubit density matrix arising from the decomposition of ρ.
We equip the extended calculus with a rewrite system, a type system, and a denotational semantics, and prove Subject Reduction, Progress, Strong Normalisation, Soundness, and Adequacy. The new construct also recovers the missing ability to discard qubits, thereby restoring expressiveness. Moreover, we show that this is achieved in a physically principled way: a variable unused in t is interpreted exactly as being partial-traced out, as dictated by the no-deleting theorem. We illustrate the resulting compositionality through quantum teleportation and the three-qubit bit-flip code.
Quantum programming languages provide a hardware-independent, high-level description of quantum algorithms. Since the seminal work of Selinger and Valiron [13], the standard design for higher-order quantum languages has followed
∗ This paper is based on the second's author Master's thesis [10].
A. Díaz-Caro and T. Miguez
the quantum data / classical control paradigm: the quantum state is kept in an external register, while terms manipulate names (pointers) to the qubits stored in it. This design sidesteps the problem of decomposing entangled compound states within the language itself. By contrast, calculi that represent quantum states directly as terms must confront this problem explicitly.
Another line of quantum lambda calculi takes a different route, embedding the computation state directly as a constant within terms, instead of keeping it in an external store. Reasoning in such calculi more directly reflects the evolution of the computation state, which makes them especially appealing for program verification [2]: since a term carries its entire computation state, program equivalences can be established by reasoning within the calculus itself, rather than about configurations of an external store. One such calculus is λρ∘ [5], which uses density matrices to represent states as part of terms.
This internal-state approach has recently been used as the basis for an expectation-based analysis of higher-order quantum programs [2]. That work considers a derivative calculus using vectors instead of density matrices and adding recursion, among other extensions, and exploits its similarities with a probabilistic classical language [1]. In that setting, the calculus serves as an intermediate language: a higher-order quantum program can be compiled into it, and the analysis can then be performed there.
The need for such an intermediate-language role is partly due to a limitation of λρ∘ and its derivative calculi: they lack a tensor elimination construct, or let-tensor. As a consequence, although compound quantum states can be represented, they cannot be decomposed within the language itself. The difficulty is not specific to λρ∘: being unable to split the state of a multi-qubit system into its components, precisely because of entanglement, is a limitation shared by other calculi for quantum computation, such as those of Hasuo and Hoshino [8] and Delbecque [4]. This affects compositionality. A single quantum computation can still be expressed by encoding operations directly at the matrix level, so the language can still serve its purpose as an intermediate language. However, the individual qubits of a compound state cannot be addressed independently.
Consider a concrete scenario: given a two-qubit state ρ, suppose that we want to apply a function f to the first qubit and a function g to the second qubit independently. In λρ∘, there is no way to express this as f(x1) and g(x2), where x1 and x2 are the individual qubits of ρ. One must instead encode the operation at the matrix level, using an operator such as Uf⊗Ug applied to the whole state, losing the modularity that lambda calculi are designed to provide.
This limitation also has an expressiveness-level counterpart. Since λρ∘ provides no mechanism for decomposing a state, it also provides no mechanism for discarding qubits. Borgna [3] showed that, as a consequence, some quantum computations cannot be directly encoded in it.
In this paper we present an extension of λρ∘ that addresses both concerns. It provides compositional access to the individual qubits of a state and, through affine discard (an affine type system being one that admits weakening but not contraction), recovers the ability to discard qubits, thereby restoring expres-siveness. Moreover, the resulting notion of discard is shown to coincide exactly with the partial trace, yielding a physically meaningful interpretation of affine weakening.
The key observation is that combining the Pauli decomposition of density matrices with the spectral decomposition of the Pauli matrices [11] allows any n-qubit density matrix to be expressed as a real linear combination of tensor products of single-qubit density matrices. We exploit this fact to extend λρ∘ with a construct let x⊗n=ρ in t that binds the individual qubit components of a compound state within a body, so that programs may operate on them in an algebraically coherent way.
Contributions. We make the following contributions.
A compositional let construct. We extend λρ∘ with a construct let x⊗n=ρ in t that binds the variables x1,…,xn to the single-qubit density matrices arising from the decomposition of ρ within the body t. The decomposition is obtained by combining the Pauli decomposition with the spectral decomposition of the Pauli matrices: the state ρ is expressed as a weighted sum of tensor products of single-qubit density matrices, and the body t is evaluated for each such tensor product, weighted accordingly.
A denotational semantics. We provide a denotational semantics for the extended calculus, interpreting the new let construct through the corresponding decomposition of density matrices.
Metatheoretical properties. We prove Subject Reduction, Progress, Strong Normalisation, Soundness, and Adequacy for the extended calculus. We also prove the central result specific to this extension: discard coincides with partial trace. This establishes that the let construct is faithful to the no-deleting theorem.
Illustrative examples. We implement quantum teleportation and the three-qubit bit-flip error correction code in the extended calculus. Both examples demonstrate how the let construct enables compositional programming over multi-qubit states, including the separation of roles in teleportation and ancilla management in error correction. Throughout the paper, we also use the Bell state as a running example: we exhibit its Pauli and combined decompositions and use it to show how discarding a qubit computes the partial trace.
2 Preliminaries
We briefly recall quantum computing in the density matrix formalism and the base calculus λρ∘. We refer to [11] for a comprehensive introduction to the former.
2.1 Quantum Computing with Density Matrices
While a pure state can be described by a unit vector in a Hilbert space, this representation cannot capture situations in which our knowledge of the system
A. Díaz-Caro and T. Miguez
is incomplete, for instance after a measurement whose outcome is unknown. The density matrix formalism encompasses both pure and mixed states.
Definition 2.1 (Density matrix). A density matrix (or density operator) is a positive semidefinite matrix ρ with tr(ρ)=1, where tr denotes the trace. For an n-qubit system, ρ is a 2n×2n matrix. We write Dn for the set of density matrices of n-qubit systems.
A pure state ∣ψ⟩ corresponds to the density matrix ρ=∣ψ⟩⟨ψ∣. A mixed state, representing a statistical ensemble in which the system is in state ρi with probability pi (where ∑ipi=1), is described by ρ=∑ipiρi.
The four postulates of quantum mechanics can be formulated entirely in terms of density matrices. The evolution of a closed system is described by a unitary operator U, which transforms a state ρ into UρU†. A measurement is described by a family of operators {πi}i satisfying ∑iπi†πi=I. If the system is in state ρ, the probability of outcome i is pi=tr(πi†πiρ) and, when pi>0, the corresponding post-measurement state is πiρπi†/pi. Finally, composite systems are represented by tensor products: if systems A and B are respectively in states ρA and ρB, then their joint state is ρA⊗ρB.
Example 2.1 (Bell state). The Bell state ∣β00⟩=21(∣00⟩+∣11⟩) has density matrix
β00=21(∣00⟩⟨00∣+∣00⟩⟨11∣+∣11⟩⟨00∣+∣11⟩⟨11∣).
This state cannot be written as ρA⊗ρB for any single-qubit density matrices ρA and ρB. It will serve as a running example throughout the paper.
Two physical principles constrain any language manipulating quantum data. Quantum information cannot be freely duplicated (the no-cloning theorem [14]), which motivates the affine type system of λρ∘. Likewise, quantum information cannot be freely deleted (the no-deleting theorem [12]). We return to this point in Section 5.1, where we show that discard corresponds exactly to partial trace.
2.2 The Calculus λρ∘
The calculus λρ∘ [5] is a quantum extension of the lambda calculus in which quantum data is represented by density matrices. Following the quantum data / classical control paradigm, measurements are handled through deterministic rewriting with probabilistic control: a measurement does not reduce to a single outcome but rather to a probabilistic mixture containing all possible outcomes.
The grammar of terms (Table 1) contains the usual lambda calculus constructs together with terms corresponding to the quantum operations described in the previous section and constructs for probabilistic control. In ρn, the superscript n denotes the number of qubits. The term Umt applies a unitary transformation, πmt performs a measurement, and t⊗r forms a composite system. The term ∑ipiti represents a probabilistic mixture. Finally, letcase∘ eliminates a measurement result by producing the weighted sum of all possible branches.
t:=x∣λx.t∣tt
(Standard lambda calculus)
∣ρn∣Unt∣πnt∣t⊗t
(Quantum postulates)
∣i=1∑npiti∣letcase∘x=tin{t,…,t}
(Probabilistic control)
where pi∈(0,1], ∑i=1npi=1, and ∑ is considered modulo associativity and commutativity.
Table 1. Grammar of terms of λρ∘.
Although λρ∘ provides a constructor for composite systems through ⊗, it provides no corresponding elimination construct. This absence prevents the individual components of a compound state from being manipulated independently and is precisely the limitation addressed in the present work.
To state Progress, we distinguish values from reducible terms. Since measurements are evaluated through letcase°, a term πmρn is considered a value.
Definition 2.2 (Values). A value is a term v defined by the following grammar
w^:=λx.t∣πmρn∣i∑piw^iv:=w^∣ρn
where ∀i=j,w^i=w^j. This condition is to be read syntactically: the summands must be pairwise distinct as terms (up to renaming of bound variables); in particular, two λ-abstractions are identified only when they are the same term, regardless of the function they denote.
The rewrite system (Table 2) uses a deterministic relation →. We write t[r/x] for the usual capture-avoiding substitution of r for the free occurrences of x in t, following Barendregt's variable convention. Since density matrices are themselves terms, several rewrite rules relate the syntactic layer to the underlying mathematical model. To keep the two apart, within the rewrite rules we write ⊗^ and ∑ for the tensor product and the linear combination of matrices, the usual operations of linear algebra, reserving ⊗ and ∑ for the homonymous term constructors. The overline notation extends an operator to the dimension of the state to which it is applied. For instance, when applying a two-qubit unitary U2 to a three-qubit state, U2=U2⊗^I1. Notably, measurement does not reduce by itself; it only reduces when it is the argument of a letcase°, producing a weighted sum over all possible outcomes. We include a distributivity rule for letcase° over probabilistic mixtures. This rule is needed to formulate Progress using the notion of value above. We write t↓r when there exists a term u such that t→∗u and r→∗u.
A. Díaz-Caro and T. Miguez
(λx.t)r→t[r/x]
letcase° x=πmρn in {t0,…,t2m−1}→∑ipiti[ρin/x]
with {ρin=piπiρnπi†pi=tr(πi†πipiρn)
Umρn→ρ′n
with UmρnUm†=ρ′n
ρ⊗ρ′→ρ′′
with ρ′′=ρ⊗ρ′
∑ipiρi→ρ′
with ρ′=∑ipiρi
∑ipit→t
(∑ipiti)r→∑ipi(tir)
letcase° x=∑ipiw^i in {t0,…,t2m−1}→∑ipiletcase∘x=w^i in {t0,…,t2m−1}
The type system (Table 3) is affine: variables can be used at most once, preventing the duplication of quantum states (respecting the no-cloning theorem). In rules that combine two contexts Γ and Δ (namely ¬o and ⊗), the two contexts are required to be disjoint, which is what enforces linearity. The type n denotes an n-qubit density matrix, the type (m,n) denotes the result of measuring m out of n qubits and A¬B is the linear function type. While composite systems can be introduced through the ⊗ rule, there is no corresponding elimination rule.
3 The Compositional Extension
We first develop the Pauli spectral decomposition machinery needed for the new construct, then present the extended calculus.
3.1 Pauli and Spectral Decompositions
The extension relies on combining the Pauli decomposition of density matrices with the spectral decomposition of the Pauli operators. We begin by recalling both constructions. The Pauli matrices, together with the identity, form a basis for the space of 2×2 Hermitian matrices [11, §2.1.3]:
I=(1001),X=(0110),Y=(0i−i0),Z=(100−1).
Definition 3.1 (Pauli operator basis). Let n∈N∗. The Pauli operator basis of size n is the set Pn={⨂i=1nMi∣Mi∈{I,X,Y,Z}}.
The set Pn contains 4n elements and forms an orthogonal basis of C2n×2n with respect to the Hilbert–Schmidt inner product ⟨A,B⟩=tr(A†B) [9]. Hence any density matrix ρ can be written as
ρ=Pi∈Pn∑αiPi,αi=2n1tr(Piρ),(1)
with αi∈R (real because ρ and each Pi are Hermitian).
Example 3.1 (Pauli decomposition of the Bell state). Since n=2, the Pauli basis P2 has 16 elements M1⊗M2. The only non-zero coefficients are
αII=41,αXX=41,αYY=−41,αZZ=41.(2)
The corresponding Pauli decomposition is therefore
β00=41(I⊗I+X⊗X−Y⊗Y+Z⊗Z).(3)
To obtain a decomposition into tensor products of single-qubit density matrices, we must further decompose the Pauli operators appearing in Equation (1). For this purpose we use the spectral decomposition theorem.
Theorem 3.1 (Spectral decomposition). Let A be a normal matrix of dimension d×d. Then A=∑i=1dλi∣vi⟩⟨vi∣, where λ1,…,λd are the eigenvalues of A (with multiplicity) and ∣v1⟩,…,∣vd⟩ form an orthonormal basis of eigenvectors.
3.2 Spectral Decomposition of the Pauli Matrices
By Theorem 3.1, each Pauli matrix can be written as a linear combination of its eigenprojectors. For the Pauli matrices, these decompositions are
where αi is the coefficient of the i-th Pauli operator Pi=Mi1⊗⋯⊗Min in the Pauli decomposition (1) of ρ, and λiklk and ρiklk are, respectively, the eigenvalues in {−1,+1} and the corresponding rank-one eigenprojectors of the k-th factor Mik of Pi, as given in Section 3.2. In particular, each ρiklk∈D1 is a single-qubit density matrix.
Proof. Let
Pi=Mi1⊗⋯⊗Min
be an element of the Pauli basis. By the spectral decomposition of each factor,
Mik=λik1ρik1+λik2ρik2.
Expanding the tensor product and substituting the resulting expression into Equation (1) yields the claimed decomposition.
The coefficients pil are not necessarily non-negative, so Equation (4) is generally not a convex combination. Nevertheless, evaluating the trace of Equation (4) yields
i,l∑pil=tr(ρ)=1.
Indeed, each tensor product ⊗kρiklk has trace one. The individual terms ⊗kρiklk are genuine density matrices; the non-classical behaviour of entangled states is encoded in the coefficients, which may be negative.
The decomposition into single-qubit density matrices is the key mathematical tool underlying our let construct. It provides a canonical way to represent any multi-qubit state as a real linear combination of tensor products of single-qubit density matrices, allowing the individual components to be manipulated independently within a program.
Example 3.2 (combined decomposition of the Bell state). Continuing from Example 3.1, only the four pairs II, XX, YY, ZZ carry non-zero αi (Equation (2)), so the sum has 4×4=16 non-zero terms. Expanding each, the full combined decomposition is
Some tensor products appear more than once in the expansion because they arise from different Pauli terms. We deliberately keep the decomposition in its expanded form to make the contribution of each Pauli component explicit.
Observe that all terms are tensor products of single-qubit density matrices, while the correlations of β00 are reflected in the pattern of positive and negative coefficients.
Remark 3.1 (Size of the decomposition). The sum in Equation (4) may, in the worst case, contain up to 8n summands, although only those Pauli strings Pi with non-zero coefficient αi contribute — for the Bell state, only 4 of the 16 Pauli pairs are non-zero, giving the 16 terms of Example 3.2. This exponential growth is not introduced by the let construct: an n-qubit density matrix is already represented by a 2n×2n matrix, and the decomposition merely re-expresses this existing information as a sum over single-qubit components rather than as the entries of a single 2n×2n matrix. This behaviour is therefore inherent to the representation of quantum states rather than a consequence of the let construct itself. λρ∘ is intended as a calculus for reasoning about and verifying quantum programs, where a term carries its computation state for the purposes of equational and denotational reasoning, rather than as an executable model for efficient classical simulation; a faithful classical representation of an entangled n-qubit state may incur an exponential cost, with or without the let construct.
3.4 Extended Grammar, Rewrite System, and Type System
We now introduce the construct enabled by the decomposition developed in the previous subsections. We extend the grammar of λρ∘ with a new term let x⊗n=ρ in t, which binds n variables x1,…,xn, each of type 1 (single-qubit density matrix), within the body t. The superscript ⊗n in x⊗n indicates that x is being decomposed into n tensor components.
where ρ=∑i=14n∑l∈{1,2}npil⊗k=1nρiklk as in Proposition 3.1.
Table 4. Rewrite rules for the let construct.
We also generalise the construct ∑ipiti from probabilistic mixtures to finite real linear combinations whose coefficients sum to one, but are not required to be positive. This extension is necessary because the decomposition of Proposition 3.1 may involve negative coefficients.
The new reduction rules for the let construct are given in Table 4.
The reduction works as follows: when the source term is a density matrix ρn, its decomposition given by Proposition 3.1 is computed. Each tensor product ⊗kρiklk induces a simultaneous substitution of the components ρiklk for the variables xk in the body. The results are then recombined according to the coefficients pil.
The type system is extended with a single new rule:
Γ,Δ⊢letx⊗n=tins:AΓ⊢t:nΔ,x1:1,…,xn:1⊢s:Alet
The rule requires that t has type n, and types the body s under assumptions corresponding to the n single-qubit components of the decomposition. The contexts Γ and Δ are split, maintaining the affine discipline.
4 Denotational Semantics
A completely positive map (CPM) is a linear map between spaces of operators that preserves positivity under extension by arbitrary ancillary systems. CPMs are the standard model for physically realisable quantum operations [11, Ch. 8]. We write CPM(Dn,Dm) for the set of CPMs from Dn to Dm. Types are interpreted as
[n]=Dn[(m,n)]=Dn[A⊸B]=CPM([A],[B]).
The interpretation is defined relative to a typing judgement Γ⊢t:A and a valuation θ⊨Γ, that is, θ(x)∈[A] for every assumption x:A∈Γ. Given such a valuation, the interpretation of λρ∘ terms is
where, for the interpretation of the let construct, [t]θ is decomposed as in Proposition 3.1 as
[t]θ=i=1∑4nl∈{1,2}n∑pilk=1⨂nρiklk
This interpretation is well defined, since every density matrix admits such a decomposition.
5 Properties
We show that discarding a qubit through the affine type system with the let construct is equivalent to tracing it out, and that the extended calculus preserves the fundamental properties of Subject Reduction, Progress, Strong Normalisation, Soundness, and Adequacy. Full proofs are given in the appendix.
5.1 Discard as Partial Trace
We first recall the partial trace, the physical operation of discarding a subsystem. The partial trace over A is the unique linear map trA defined on product operators by trA(∣a1⟩⟨a2∣⊗∣b1⟩⟨b2∣)=⟨a2∣a1⟩∣b1⟩⟨b2∣; the partial trace over subsystem k acts as tr on the k-th tensor factor and as the identity on all others [11, §2.4.3]. On product states trA(ρA⊗ρB)=ρB, but for entangled states it produces a mixed state even when the global state is pure.
Example 5.1 (partial trace of the Bell state). Tracing out the first qubit of the Bell state β00 gives the maximally mixed state, reflecting that no information about the second qubit can be obtained without access to the first:
The relevance of the partial trace here is physical. Just as quantum information cannot be cloned, it cannot be deleted [12].
Any operation that appears to delete a qubit must, in reality, hide its information somewhere else (e.g. in the environment); the physical operation corresponding to ignoring a subsystem is precisely the partial trace, which marginalises over it. A language construct that “discards” a qubit must therefore, for physical faithfulness, denote a partial trace rather than a literal deletion. We now show that the let construct does exactly this: ignoring a component in the body (permitted by the affine type system) is not merely a syntactic convenience, but is computationally equivalent to first computing the reduced density matrix of the remaining qubits via the partial trace, and then decomposing that reduced state.
Proposition 5.1 (Discard as Partial Trace). Let ρn be an n-qubit density matrix with n≥2, and let s be a term with x2:1,…,xn:1⊢s:A (so, by affinity, x1∈/FV(s)). Then
The same holds for discarding any other qubit position k by relabeling.
Proof. (Sketch.) Let ρ=∑i,lpil⊗k=1ρiklk be the decomposition into single-qubit density matrices given by Proposition 3.1. Applying the main let rule and using x1∈/FV(s), the left-hand side reduces to
On the other hand, by linearity of tr1 and tr(ρi1l1)=1,
tr1(ρn)=i,l2,…,ln∑(l1∑pil)⊗k=2nρiklk,
which is precisely the combined decomposition of tr1(ρn). Reducing the right-hand side with this decomposition yields the same sum. Both sides reduce to a common term.
Remark 5.1. This connects affine variable discard to the no-deleting theorem: when a variable xk is not mentioned in the body of a let, the reduction silently sums out its contribution exactly as the partial trace does in quantum mechanics. The affine type system thus enforces the quantum-mechanical principle that ignoring a subsystem is equivalent to computing its reduced state.
In particular, affine discard is not merely admissible but has the exact physical interpretation prescribed by quantum mechanics.
The property generalises to the simultaneous discard of any subset of qubits, since partial traces over disjoint subsystems commute.
Example 5.2 (discard computes the partial trace). Consider let x⊗2=β00 in x2. Since x1∈/FV(x2), the first qubit variable is discarded by the affine type system, so we expect the result to be tr1(β00). Applying the let rule with the combined decomposition (5) and keeping only the second tensor factor, the terms from X⊗X, Y⊗Y, and Z⊗Z cancel pairwise; only I⊗I contributes, so
coinciding with Example 5.1, as guaranteed by Proposition 5.1.
5.2 Subject Reduction, Progress, and Strong Normalisation
Theorem 5.1 (Subject Reduction). If Γ⊢t:A and t→r, then Γ⊢r:A.
The proof is by induction on the derivation of t→r; the cases for the original constructs follow [5]. For the main let reduction, inversion gives Γ⊢ρn:n and Δ,x1:1,…,xn:1⊢s:A; each ρiklk is a single-qubit density matrix, so repeated use of the substitution lemma gives Δ⊢s[ρi1l1/x1,⋯]:A, and Proposition 3.1 ensures that ∑i,lpil=1, so the rule + yields the result.
The let construct is not a value. Indeed, if its source term is a density matrix the main reduction rule applies; otherwise, any reduction of the source term propagates through the contextual rule.
Theorem 5.2 (Progress). If ⊢t:A then either t is a value or there exists r such that t→r.
One proves a stronger statement for open terms: if Γ⊢t:A, then t is a value, reduces, or contains a free variable and does not rewrite. For the new case Γ,Δ⊢let x⊗n=t in s:A: if t is a density matrix ρn the main rule fires; if t reduces, the contextual rule applies; otherwise t has a free variable and so does the whole term.
Theorem 5.3 (Strong Normalisation). Every closed, well-typed term ⊢t:A is strongly normalising.
The proof uses Girard's reducibility candidates [7]. Following Díaz-Caro and Dowek [6], we extend the reduction with projection rules ∑ipiti→tj to handle the distributivity rule without duplication, and define typed reducibility sets SN(A) with SN(n)=SN((m,n))=SN and SN(A→B)={t∈SN∣t→∗λx.u⇒∀v∈SN(A),u[v/x]∈SN(B)}. The key new per-construct lemma states that if t∈SN(n) and s[ρ1/x1,…,ρn/xn]∈SN(A) for all single-qubit ρk∈SN(1), then let x⊗n=t in s∈SN(A). A fundamental substitution lemma concludes strong normalisation for every closed well-typed term.
Remark 5.2. One may wonder whether Theorem 5.3 could be obtained by a simpler argument, showing that some measure on terms decreases along reduction: after all, the calculus is affine, so no variable is ever duplicated by substitution. Such an argument may well be possible, but it is not immediately obvious,
A. Díaz-Caro and T. Miguez
because the terms of a linear combination can be repeated. The main let rule replaces its body s by one copy of s per summand of the decomposition, and both the letcase∘ rule and the distributivity rule (∑ipiti)r→∑ipi(tir) replicate whole subterms across the summands. Along these reductions a term therefore typically grows rather than shrinks, and no obvious measure decreases.
5.3 Soundness and Adequacy
Theorem 5.4 (Soundness). If Γ⊢t:A, θ⊨Γ, and t→r, then [t]θ=[r]θ.
The proof is by induction on the derivation of t→r. The key insight behind the let case is that the operational semantics (the reduction rule for let) and the denotational semantics (the interpretation of let) are defined from the same decomposition given by Proposition 3.1. Soundness then reduces to an application of the semantic substitution lemma ( [t[s/x]]θ=[t]θ,x↦[s]θ) together with linearity of the interpretation.
Soundness tells us the interpretation is invariant under reduction, but invariance alone does not imply it carries useful information. Full completeness (denotationally equal closed terms reduce to a common value) is too strong for function types: the terms r=λf.f and t=λf.λx.f(x) are distinct normal forms with the same denotation (the identity CPM on A→A) and no common reduct. We therefore characterise semantic equality by observational equivalence.
Definition 5.1 (Context, observational equivalence). A context C is a term with a single hole [⋅] such that [⋅]:A⊢C:n for some type A and n∈N. Two closed terms ⊢t:A and ⊢r:A are observationally equivalent, written t≡r, if for every context C with hole type A there exists a density matrix ρ such that C[t]→∗ρ and C[r]→∗ρ.
Theorem 5.5 (Adequacy). If ⊢t:A,⊢r:A, and [t]θ=[r]θ, then t≡r.
Proof. (Sketch.) Let C be a context with hole type A and output type n. By compositionality of the interpretation, [t]θ=[r]θ implies [C[t]]θ=[C[r]]θ. By Theorems 5.1, 5.2, and 5.3, the closed ground-type terms C[t] and C[r] reduce to density matrices ρ1 and ρ2. By Soundness, ρ1=[C[t]]θ=[C[r]]θ=ρ2. Hence both reduce to a common ρ, so t≡r.
Adequacy shows that semantic equality implies observational equivalence: no ground-type experiment can distinguish two denotationally equal programs.
6 Examples
6.1 Teleportation
In λρ∘, quantum teleportation can be written as the single term [5]
where Z3=I⊗I⊗Z and X3=I⊗I⊗X operate on the global 3-qubit state. This formulation conflates Alice's and Bob's roles: Alice prepares and measures, while Bob corrects, yet the term treats the entire protocol as a monolithic operation. Moreover, the type of T is 1−∘3, since the branches return the full 3-qubit post-measurement state, even though the teleported qubit is only the third one. This reflects an artefact of the encoding rather than the intended behaviour of the protocol.
Using the let construct, we can cleanly separate the two roles. The key observation is that since the type system is affine, Bob can bind all three qubit variables via let but only use q3, his qubit, discarding Alice's qubits q1 and q2. Alice takes the input qubit, composes it with her half of the Bell pair, applies the CNOT and Hadamard gates, and measures her two qubits. Bob then analyses the resulting measurement term and, in each branch, decomposes the corresponding 3-qubit post-measurement state, applies the appropriate Pauli correction to his qubit, and returns only that qubit:
The correction Z1q3 applies Z to a single-qubit variable, rather than the global operator Z3=I⊗I⊗Z. The type of teleport is 1−∘1: it takes a single-qubit density matrix and returns a single-qubit density matrix. This type accurately reflects the physical protocol, where Alice's qubits are discarded after the correction step and only Bob's corrected qubit remains.
To illustrate the role of the new typing rule, the derivation of a typical Bob branch is
y:3⊢letq⊗n=yinZ1q3:1y:3⊢y:3axaxulet
where q1 and q2 appear in the context but are unused: this is precisely how Alice’s qubits are discarded, and by Proposition 5.1 this discard computes the partial trace over them.
6.2 Bit-Flip Error Correction
The three-qubit bit-flip code [11, §10.1.1] protects a single logical qubit against a single bit-flip (X) error by encoding it into three physical qubits, using two ancilla qubits during syndrome extraction. This example illustrates how the let construct enables clean ancilla management, qubit extraction, and a more faithful typing of the protocol.
In the original calculus, each branch of the correction must apply the correction as a global five-qubit operator and the ancilla qubits cannot be discarded,
A. Díaz-Caro and T. Miguez
so the correction has type 3 —∞ 5 and, after decoding, the full protocol has type bitflip₀ : 1 —∞ 5: there is no mechanism to discard the ancilla qubits or extract the logical qubit, and the ancillas are carried as irremovable overhead. With the let construct, each branch decomposes the five-qubit post-measurement state, applies the correction to only the affected code qubit, and recombines only the three code qubits, discarding the ancillas; decoding then extracts the first qubit. Writing β = |0⟩⟨0| for the ancilla state and Enc³, Synd⁵, Dec³ = (Enc³)† for the encoding, syndrome-extraction and decoding circuits, after syndrome extraction the first two qubits are ancillas carrying the syndrome information, while the last three qubits contain the encoded state. Accordingly, the correction step discards the ancillas and acts only on the three code qubits:
The corrections are manifestly local: b1 applies X1 to a single-qubit variable q3, rather than the global operator X35=I⊗I⊗X⊗I⊗I. The type 1→1 accurately reflects the physical reality of the protocol: a single qubit is encoded, protected, and recovered. Contrast this with bitflip0:1→5 in the original calculus.
7 Conclusion
We have shown that a multi-qubit state embedded inside a term can, after all, be split into individual qubits: the Pauli decomposition together with the spectral decomposition of the Pauli matrices expresses any n-qubit density matrix as a real linear combination of tensor products of single-qubit states. Exploiting this, we extended λρ∘ with a compositional let construct, gave it a rewrite system, an affine type system, and a denotational semantics based on completely positive maps, and proved Subject Reduction, Progress, Strong Normalisation, Soundness, and Adequacy. The construct is physically principled: discarding an unused qubit computes exactly the partial trace, in accordance with the no-deleting theorem. The teleportation and bit-flip examples show that programs over states-as-constants can be written compositionally, with types that reflect the underlying physical protocol. This supports the broader thesis that keeping the quantum state as a constant of the language—rather than in an external register—is a viable design, well suited to reasoning about programs.
Acknowledgments. This work was partially funded by the European Union through the Horizon-Europe MSCA-SE project QCOMICAL (101182520), the PEPR integrated project EPiQ (ANR-22-PETQ-0007), the ANII Fondo Clemente Estable project FCE-1-2025-1-186751, and the STIC-AmSud project QUASAR.
Disclosure of Interests. The authors have no competing interests to declare that are relevant to the content of this article.
References
Avanzini, M., Barthe, G., Dal Lago, U.: On continuation-passing transformations and expected cost analysis. In: Proc. ACM Program. Lang. vol. 5, pp. 1–30 (2021)
Avanzini, M., Díaz-Caro, A., Hainry, E., Péchoux, R.: Expectation-based analysis of higher-order quantum programs. Draft at arXiv:2504.18441 (2025)
Borgna, A.: Simulación del lambda cálculo de matrices de densidad en el lambda cálculo cuántico de Selinger y Valiron. Master's thesis, Universidad de Buenos Aires (2019)
Delbecque, Y.: Game semantics for quantum data. In: Quantum Physics and Logic / Developments in Computational Models (QPL/DCM@ICALP 2008). pp. 41–57 (2008)
Díaz-Caro, A.: A lambda calculus for density matrices with classical and probabilistic controls. In: Programming Languages and Systems (APLAS 2017). LNCS, vol. 10695, pp. 448–467. Springer (2017), arXiv:1705.00097
Díaz-Caro, A., Dowek, G.: A linear linear lambda-calculus. Mathematical Structures in Computer Science 34(10), 1103–1137 (2024)
Girard, J.Y., Lafont, Y., Taylor, P.: Proofs and Types. No. 7 in Cambridge Tracts in Theoretical Computer Science, Cambridge University Press (1989)
Hasuo, I., Hoshino, N.: Semantics of higher-order quantum computation via geometry of interaction. Annals of Pure and Applied Logic 168(2), 404–469 (2017)
Koska, O., Baboulin, M., Gazda, A.: A tree-approach Pauli decomposition algorithm with application to quantum computing. In: IEEE International Conference on Quantum Computing and Engineering (QCE) (2024), arXiv:2403.11644
Miguez, T.: A compositional extension of λρ∘ via Pauli decomposition. Master's thesis, Universidad de Buenos Aires (2026)
Nielsen, M.A., Chuang, I.L.: Quantum Computation and Quantum Information. Cambridge University Press, 10th anniversary edition edn. (2010)
Pati, A.K., Braunstein, S.L.: Impossibility of deleting an unknown quantum state. Nature 404(6774), 164–165 (2000)
Selinger, P., Valiron, B.: A lambda calculus for quantum computation with classical control. Mathematical Structures in Computer Science 16(3), 527–552 (2006)
Wootters, W., Zurek, W.: A single quantum cannot be cloned. Nature 299(5886), 802–803 (1982)
A. Díaz-Caro and T. Miguez
A Spectral Decomposition of the Pauli Matrices
We compute the spectral decomposition of each of the four Pauli matrices explicitly. In each case, we find the eigenvalues and an orthonormal basis of eigenvectors, and verify that M=∑iλi∣vi⟩⟨vi∣.
Identity I. The identity matrix I=(1001) has eigenvalue λ=1 with multiplicity 2. The standard basis vectors ∣0⟩ and ∣1⟩ are eigenvectors, so:
I=1⋅∣0⟩⟨0∣+1⋅∣1⟩⟨1∣.
Pauli Z. The matrix Z=(100−1) is already diagonal, with eigenvalue λ1=+1 for eigenvector ∣0⟩ and λ2=−1 for eigenvector ∣1⟩. The characteristic polynomial is det(Z−λI)=(1−λ)(−1−λ)=0, giving λ=±1. The spectral decomposition is:
Pauli X. The matrix X=(0110) has characteristic polynomial det(X−λI)=λ2−1=0, giving eigenvalues λ=±1. For λ1=+1, solving (X−I)v=0 gives v1=v2, so the normalized eigenvector is ∣+⟩=21(11). For λ2=−1, solving (X+I)v=0 gives v1=−v2, so the normalized eigenvector is ∣−⟩=21(1−1).
Pauli Y. The matrix Y=(0i−i0) has characteristic polynomial det(Y−λI)=λ2−1=0, giving eigenvalues λ=±1. For λ1=+1, solving (Y−I)v=0 gives v1=−iv2; absorbing the global phase, the normalized eigenvector is conventionally written ∣i⟩=21(∣0⟩+i∣1⟩), so ∣i⟩⟨i∣=21(1i−i1). For λ2=−1, solving (Y+I)v=0 gives v1=iv2, and with ∣−i⟩=21(∣0⟩−i∣1⟩) we have ∣−i⟩⟨−i∣=21(1−ii1).
so the result is 21∣0⟩⟨0∣+21∣1⟩⟨1∣=2I=tr1(β00).
C Detailed Proofs
Throughout, we assume standard weakening and strengthening properties for the affine type system.
C.1 Substitution Lemma
Lemma C.1 (Substitution). If Γ,x:A⊢t:B and Δ⊢r:A, then Γ,Δ⊢t[r/x]:B.
Proof. By induction on t.
– Let t=x. Then B=A. By weakening, Γ,Δ⊢r:A. Notice that t[r/x]=r.
– Let t=y. Then, by weakening and strengthening, Γ,Δ⊢y:B. Notice that t[r/x]=y.
– Let t=λy.s. Then B=C→D and, by inversion, Γ,x:A,y:C⊢s:D. Then, by the induction hypothesis, Γ,y:C,Δ⊢s[r/x]:D, so, by rule −∘i, Γ,Δ⊢λy.(s[r/x]):C→D. Notice that λy.(s[r/x])=(λy.s)[r/x].
– Let t=t1t2. Then Γ,x:A=Γ1,Γ2, with Γ1⊢t1:C→B and Γ2⊢t2:C.
If x:A∈Γ1, then, by the induction hypothesis Γ1∖{x:A}, Δ⊢t1[r/x]:C→B, so by rule −∘e, Γ1∖{x:A}, Γ2, Δ⊢t1[r/x]t2:B. Notice that Γ1∖{x:A}, Γ2=Γ and t1[r/x]t2=(t1t2)[r/x].
If x:A∈Γ2, then, by the induction hypothesis Γ2∖{x:A}, Δ⊢t2[r/x]:C, so by rule −∘e, Γ1, Γ2∖{x:A}, Δ⊢t1(t2[r/x]):B. Notice that Γ1, Γ2∖{x:A}=Γ and t1(t2[r/x])=(t1t2)[r/x].
– Let t=ρn. Then B=n. By weakening and strengthening, Γ,Δ⊢ρn:n.
Notice that t[r/x]=ρn.
– Let t=Ums. Then B=n and Γ,x:A⊢s:n. Then, by the induction hypothesis, Γ,Δ⊢s[r/x]:n. So, by rule u,Γ,Δ⊢Um(s[r/x]):n. Notice that Um(s[r/x])=(Ums)[r/x].
– Let t=πms. Then B=(m,n) and Γ,x:A⊢s:n. Then, by the induction hypothesis, Γ,Δ⊢s[r/x]:n. So, by rule m, Γ,Δ⊢πm(s[r/x]):(m,n). Notice that πm(s[r/x])=(πms)[r/x].
A. Díaz-Caro and T. Miguez
Let t=t1⊗t2. Then B=n1+n2, Γ,x:A=Γ1,Γ2 with Γi⊢ti:ni for i=1,2. Let x:A∈Γi for some i=1,2. Then, by the induction hypothesis, Γi∖{x:A}, Δ⊢ti[r/x], so by rule ⊗, either Γ,Δ⊢t1[r/x]⊗t2:n1+n2, or Γ,Δ⊢t1⊗t2[r/x]:n1+n2. In the first case, notice that t1[r/x]⊗t2=(t1⊗t2)[r/x], and in the second, t1⊗t2[r/x]=(t1⊗t2)[r/x].
Let t=∑ipiti. Then Γ,x:A⊢ti:B and so, by the induction hypothesis, Γ,Δ⊢ti[r/x]:B. Therefore, by rule +, Γ,Δ⊢∑ipiti[r/x]:B. Notice that ∑ipiti[r/x]=(∑ipiti)[r/x].
Let t=letcase∘y=s in {t0,…,t2m−1}. y:n⊢ti:B, for i=0,…,2m−1, and, Γ⊢s:(m,n). By the induction hypothesis, Γ,Δ⊢s[r/x]:(m,n). So, by rule lc, Γ,Δ⊢letcase∘y=s[r/x] in {t0,…,t2m−1}: B. Notice that (letcase∘y=s in {t0,…,t2m−1})[r/x]=letcase∘y=s[r/x] in {t0,…,t2m−1}.
Let t=let y⊗n=s in u. Then Γ,x:A=Γ1,Γ2 with Γ1⊢s:n and Γ2,y1:1,…,yn:1⊢u:B.
If x:A∈Γ1, then by the induction hypothesis, Γ1∖{x:A}, Δ⊢s[r/x]:n. Since x∈/FV(u), we have u[r/x]=u. By rule let, Γ1∖{x:A}, Γ2, Δ⊢let y⊗n=s[r/x] in u:B.
If x:A∈Γ2, then by the induction hypothesis, Γ2∖{x:A}, Δ,y1:1,…,yn:1⊢u[r/x]:B. Since x∈/FV(s), we have s[r/x]=s. By rule let, Γ1,Γ2∖{x:A}, Δ⊢let y⊗n=s in u[r/x]:B.
C.2 Subject Reduction (Theorem 5.1)
Proof.
Let t=(λx.t′)s, r=t′[s/x]. Then Γ⊢(λx.t′)s:A, so, Γ1⊢λx.t′:B→A and Γ2⊢s:B, with Γ=Γ1,Γ2. Hence, Γ1,x:B⊢t′:A, and so, by Lemma C.1, Γ⊢t′[s/x]:A.
Let t=Umρn, r=ρ′n, with ρ′n=UmρnUm†. Then A=n. By rule axρ, Γ⊢ρ′n:n.
Let t=ρ1n⊗ρ2m and r=ρ, with ρ=ρ1n⊗ρ2m. Then, A=n+m, with ⊢ρ1n:n and ⊢ρ2m:m. Since ρ is a density matrix of (n+m)-qubits, ⊢ρ:n+m.
Let t=letcase∘x=πmρn in {t0,…,t2m−1} and r=∑ipiti[ρin/x], with ρin=piπiρnπi† and pi=tr(πi†πiρn). Then Γ⊢πmρn:(m,n) and x:n⊢ti:A. By Lemma C.1, Γ⊢ti[ρin/x]:A, then, by rule +, Γ⊢∑ipiti[ρin/x]:A.
Let t=letcase∘x=∑jqjw^j in {s0,…,s2m−1} and r=∑jqjletcase∘x=w^j in {s0,…,s2m−1}. By inversion of rule lc, Γ⊢∑jqjw^j:(m,n) and x:n⊢si:A for each i. By rule +, each w^j:(m,n). Applying rule lc to each w^j gives Γ⊢letcase∘x=w^j in {s0,…,s2m−1}:A, and then rule + gives Γ⊢r:A.
Let t=∑ipiρi and r=ρ′, with ρ′=∑ipiρi. Then, Γ⊢∑ipiρi:n, and by rule axρ, Γ⊢ρ′:n.
Let t=∑ipir. Then, Γ⊢r:A.
Let t=(∑ipiti)r and ∑ipi(tir). Then, Γ=Γ1,Γ2,Γ1⊢ti:B→A and Γ2⊢r:B. Therefore, by rule −∘e,Γ1,Γ2⊢tir:A, and by rule +, Γ1,Γ2⊢∑ipi(tir):A.
Let t=let x⊗n=ρn in s and r=∑i=14n∑l∈{1,2}npils[ρi1l1/x1,⋯,ρinln/xn], where pil are the combined decomposition coefficients. We have Γ,Δ⊢let x⊗n=ρn in s:A. By inversion, Γ⊢ρn:n and Δ,x1:1,…,xn:1⊢s:A. As each ρiklk is a 1-qubit density matrix by construction, by rule axρ we have ⊢ρiklk:1. Then, by repeated application of Lemma C.1, we have that Δ⊢s[ρi1l1/x1,⋯,ρinln/xn]:A. Since the Pauli decomposition preserves trace, we have that ∑i=14n∑l∈{1,2}npil=1. Then, by rule +, we have Γ,Δ⊢∑i=14n∑l∈{1,2}npils[ρi1l1/x1,⋯,ρinln/xn]:A.
Contextual cases: Let s→s′, then
Consider t=t′s and r=t′s′. Then Γ=Γ1,Γ2, with Γ1⊢t′:B→A and Γ2⊢s:B. By the induction hypothesis, Γ2⊢s′:B, so by rule ¬e, Γ⊢t′s′:A.
Consider t=st′ and r=s′t′. Then Γ=Γ1,Γ2, with Γ1⊢s:B→A and Γ2⊢t′:B. By the induction hypothesis, Γ1⊢s′:B→A, so by rule ¬e, Γ⊢s′t′:A.
Consider t=Ums and r=Ums′. Then A=n and Γ⊢s:n. By the induction hypothesis Γ⊢s′:n, so by rule u, Γ⊢Ums′:n.
Consider t=πms and r=πms′. Then A=(m,n) and Γ⊢s:n. By the induction hypothesis Γ⊢s′:n, so by rule m, Γ⊢πms′:(m,n).
Consider t=t′⊗s and r=t′⊗s′. Then A=n+m and Γ=Γ1,Γ2, with Γ1⊢t′:n and Γ2⊢s:m. By the induction hypothesis Γ2⊢s′:m, so by rule ⊗, Γ⊢t′⊗s′:n+m.
Consider t=s⊗t′ and r=s′⊗t′. Then A=n+m and Γ=Γ1,Γ2, with Γ1⊢s:n and Γ2⊢t′:m. By the induction hypothesis Γ1⊢s′:n, so by rule ⊗, Γ⊢s′⊗t′:n+m.
Consider t=letcase∘x=s in {t0,…,t2m−1} and r=letcase∘x=s′ in {t0,…,t2m−1}. Then x:n⊢ti:A for i=0,…,2m−1, and Γ⊢s:(m,n). By the induction hypothesis, Γ⊢s′:(m,n) and by rule lc, Γ⊢letcase∘x=s′ in {t0,…,t2m−1}:A.
Consider t=∑ipiti and r=∑ipiri, with tj→rj, and ∀i=j, ti=ri. By inversion, Γ⊢ti:A. By the induction hypothesis, ∀i, Γ⊢ri:A. Then, by rule +, Γ⊢∑ipiri:A.
Consider t=let y⊗n=s in u and r=let y⊗n=s′ in u. Then Γ=Γ1,Γ2, with Γ1⊢s:n and Γ2,y1:1,…,yn:1⊢u:A. By the induction hypothesis Γ1⊢s′:n, so by rule let,Γ⊢let y⊗n=s′ in u:A.
C.3 Progress (Theorem 5.2)
Proof. We relax the hypotheses and prove the theorem for open terms as well. That is: if Γ⊢t:A, then either t is a value, there exists r such that t→r, or t contains a free variable, and t does not rewrite.
– Let Γ,x:A⊢x:A as a consequence of rule ax. Then, we are done since x is a free variable and does not rewrite.
A. Díaz-Caro and T. Miguez
– Let Γ⊢λx.t:A→B as a consequence of Γ,x:A⊢t:B and rule −∘i. Since reduction under λ is not part of the rewrite system, λx.t is always a value by Definition 2.2.
– Let Γ,Δ⊢tr:B as a consequence of Γ⊢t:A→B, Δ⊢r:A and rule −∘e. Then, by the induction hypothesis, one of the following cases happens:
• There exists t′ such that t→t′, in which case tr→t′r.
• There exists r′ such that r→r′, in which case tr→tr′.
t is a value and r does not rewrite. The only values which can be typed by A→B are:
t=x, in which case xr contains a free variable and does not rewrite.
t=λx.v, in which case (λx.v)r→v[r/x].
t=∑ipiti, where Γ⊢ti:A→B. Then, tr→∑ipi(tir).
t is not a value, contains a free variable, and does not rewrite, and r does not rewrite, in which case, if t is not a sum, tr contains a free variable and does not rewrite. If t=∑ipiti is a sum, tr→∑ipi(tir).
– Let Γ⊢ρn:n as a consequence of rule axρ. Then, we are done since ρn is a value.
– Let Γ⊢Umt:n as a consequence of Γ⊢t:n and rule u. Then, by the induction hypothesis, one of the following cases happens:
t is a value. Since λx.v cannot be typed by n, the only values that can be typed by n are either ρn, or they contain free variables:
Let t=ρn, then Umρn→ρ′, with ρ′=UmρnUm†.
Let t contain a free variable. Notice that it can only be either a free variable by itself, a tensor of values containing free variables, or a linear combination of different values containing free variables. In any case, t contains a free variable and does not rewrite. Hence, Umt contains a free variable and does not rewrite.
• There exists r such that t→r, in which case Umt→Umr;
t contains a free variable and does not rewrite, in which case the same is true for Umt.
– Let Γ⊢πmt:(m,n) as a consequence of Γ⊢t:n and rule m. Then, by the induction hypothesis, one of the following cases happens:
• t is a value. Then πmt is also a value and does not rewrite.
t contains a free variable and does not rewrite, in which case the same is true for πmt.
– Let Γ,Δ,⊢t⊗r:n+m as a consequence of Γ⊢t:n, Δ⊢r:m and rule ⊗. Then, by the induction hypothesis, one of the following happens:
• There exists t′ such that t→t′, in which case t⊗r→t′⊗r.
• There exists r′ such that r→r′, in which case t⊗r→t⊗r′.
t is a value and r does not rewrite. The only values that can be typed by n are either ρn, or they contain free variables.
Let t=ρn, then:
• If r=ρm, t⊗r→ρ′, with ρ′=ρn⊗ρm.
• If r contains a free variable and does not rewrite, then the same is true for t⊗r.
Let t contain a free variable. Then t⊗r contains a free variable and does not rewrite.
t contains a free variable and does not rewrite, and r does not rewrite, in which case t⊗r contains a free variable and does not rewrite.
– Let Γ⊢letcase∘x=r in {t0,…,t2m−1}:A as a consequence of x:n⊢ti:A for i=0,…,2m−1, Γ⊢r:(m,n), and rule lc. By the induction hypothesis, the possible cases for r are:
r=πmρn (a measurement value on a concrete density matrix). Then the main letcase ∘ rule fires:
letcase∘x=πmρnin{t0,…,t2m−1}→i∑piti[ρin/x].
r=∑jqjwj is a closed non-trivial linear combination of values wj:(m,n) (necessarily each wj=πmρjn). Then the distributing rule fires:
– Let Γ⊢∑ipiti:A as a consequence of Γ⊢ti:A, ∑ipi=1, and rule +. If ∑ipiti is a value, then we are done. If it is not a value, then one of the following cases is true:
tj=tk for some j=k, in which case ∑ipiti→(∑i=j,kpiti)+(pj+pk)tj.
At least one ti is not a value. By the induction hypothesis, if ti is not a value, either it rewrites, or it contains a free variable and does not rewrite. If at least one ti rewrites, then ∑ipiti rewrites. If none of these rewrites and at least one contains a free variable, then ∑ipiti does not rewrite and contain a free variable.
– Let Γ,Δ⊢let x⊗n=t in s:A as a consequence of Γ⊢t:n,Δ,x1:1,…,xn:1⊢s:A and rule let. By induction, the possible cases for t are:
t is a value. Since λx.v cannot be typed by n, the only values that can be typed by n are either ρn, or they contain free variables:
Let t contain a free variable. Notice that it can only be either a free variable by itself, a tensor of values containing free variables, or a linear combination of different values containing free variables. In any case, t contains a free variable and does not rewrite. Hence, let x⊗n=t in s contains a free variable and does not rewrite.
There exists t′ such that t→t′, in which case let x⊗n=t in s→ let x⊗n=t′ in s.
t contains a free variable and does not rewrite, in which case the same is true for let x⊗n=t in s.
C.4 Strong Normalisation (Theorem 5.3)
The proof uses Girard's reducibility candidates method [7]: strong normalisation is established by defining typed reducibility sets SN(A), proving a forward-closure lemma (Lemma C.3), establishing per-construct closure lemmas, and concluding by a fundamental substitution lemma.
Extended reduction relation. Following Díaz-Caro and Dowek [6], we augment the reduction relation with the following projection rules:
i∑piti→tjforanyindexj.
These rules are not part of the operational semantics of the calculus; they are added solely for the purpose of the strong normalisation argument. Since the original reduction relation is a subset of the extended one, strong normalisation for the extended relation implies strong normalisation for the original.
The sets SN and SN(A). Let SN denote the set of all terms that are strongly normalising under the extended relation. The length ℓ(t) of a term t∈SN is the maximal length of any reduction sequence from t. We define, by induction on the type A, a set SN(A) of reducible terms of type A:
Lemma C.2 (SN is closed under sums). If t1,…,tk∈SN then ∑ipiti∈SN.
Proof. By induction on ∑iℓ(ti) and then on the size of the term. Any one-step reduct of ∑ipiti either reduces one summand (covered by the induction hypothesis on ℓ), applies a sum-collapse rule to produce a density matrix or a single term t (both in SN), or fires a projection rule to produce some tj (in SN by assumption). In each case the reduct is in SN, so ∑ipiti∈SN.
Definition C.1 (Neutral terms). A term t is neutral if it is not a λ-abstraction and not a probabilistic sum.
Lemma C.3 (CR3: forward closure for neutral terms). Let t be neutral of type A. If every one-step reduct of t belongs to SN(A), then t∈SN(A).
Proof. Since every one-step reduct of t is in SN(A)⊆SN, every reduction sequence from t is finite, so t∈SN. For ground and measurement types A∈{n,(m,n)}, membership in SN(A) is just membership in SN, which we just established. For A=B→C: suppose t→∗λx. u. Since t is neutral, the first step of this sequence goes t→t′ for some reduct t′, and t′→∗λx. u. By hypothesis, t′∈SN(B→C), so for any v∈SN(B) we have u[v/x]∈SN(C). Hence t∈SN(B→C).
Per-construct closure lemmas.
Lemma C.4 (Closed under sums in SN(A)). If t1,…,tk∈SN(A) then ∑ipiti∈SN(A).
Proof. By Lemma C.2, ∑ipiti∈SN. It remains to check the additional condition for function types. Suppose A=B→C and ∑ipiti→∗λx. u. By the projection rules, some tj satisfies tj→∗λx. u (since the only reduction that produces a λ from a sum is via a summand). Since tj∈SN(B→C), for any v∈SN(B) we get u[v/x]∈SN(C). Hence ∑ipiti∈SN(B→C).
Lemma C.5 (Closed under λ-abstraction). If for all v∈SN(A), t[v/x]∈SN(B), then λx.t∈SN(A→B).
Proof. We check the two conditions in the definition of SN(A→B). λx.t∈SN: since the calculus has no body reduction rule, λx.t is a normal form and hence trivially in SN. Body condition: since there is no body reduction rule, λx.t→∗λx.u implies u=t. So the condition reduces to: for all v∈SN(A), t[v/x]∈SN(B), which is exactly the hypothesis.
Lemma C.6 (Closed under application). If t∈SN(A→B) and s∈SN(A), then ts∈SN(B).
Proof. By induction on ℓ(t)+ℓ(s) and Lemma C.3. The term t is neutral. We show every one-step reduct of t is in SN(B), then conclude by CR3. Reduction inside t or s: if t→t′ then t′∈SN(A→B) (since SN(A→B) is downward closed) and ℓ(t′)<ℓ(t), so the induction hypothesis gives t′s∈SN(B); symmetrically if s→s′. Both values, t=λx.u: the rule (λx.u)s→u[s/x] fires; since t→∗λx.u (zero steps) and s∈SN(A), the body condition of t∈SN(A→B) gives u[s/x]∈SN(B). Both values, t=∑ipiti: the distribution rule (∑ipiti)s→∑ipi(tis) fires; by the projection rules, t→ti in the extended relation, so ℓ(ti)<ℓ(t) and ti∈SN(A→B) (by downward closure). The induction hypothesis gives each tis∈SN(B), and Lemma C.4 then gives ∑ipi(tis)∈SN(B). In every case the one-step reduct is in SN(B), so CR3 gives ts∈SN(B).
Lemma C.7 (Closed under unitary operation and measurement). If t∈SN(n) then Umt∈SN(n) and πmt∈SN((m,n)).
A. Díaz-Caro and T. Miguez
Proof. Both Umt and πmt are neutral. Any reduction either applies inside t (giving a reduct in SN by the induction hypothesis on ℓ(t)) or fires the outermost rule: Umρn→ρ′n∈SN(n); and πmt has no outermost rule at all (it only participates in a reduction as the argument of letcase∘, not by itself), so the first case always applies. By Lemma C.3, both terms are in the appropriate SN set.
Lemma C.8 (Closed under tensor). If t∈SN(m) and s∈SN(n), then t⊗s∈SN(m+n).
Proof. The term t⊗s is neutral. Reductions apply inside t or s (both stay in SN by induction), or fire the collapse rule ρ1m⊗ρ2n→ρm+n (a density matrix, hence in SN(m+n)). Lemma C.3 gives the result.
Lemma C.9 (Closed under letcase°). If r∈SN((m,n)) and, for all density matrices ρn∈SN(n), si[ρn/x]∈SN(A) for each i, then letcase° x=r in {s0,…,s2m−1}∈SN(A).
Proof. By induction on ℓ(r) and Lemma C.3. The term is neutral. If a reduction applies inside r, the induction hypothesis applies. If r is a closed value of type (m,n), there are two sub-cases ( λ-abstractions cannot have measurement types):
r=πmρn: the main letcase° rule fires, giving ∑ipisi[ρin/x]. Each ρin∈SN(n); by hypothesis each si[ρin/x]∈SN(A); by Lemma C.4 the sum is in SN(A).
r=∑jqj(πmρjn): the distributing rule fires, giving ∑jqjletcase∘x=πmρjn in {s0,…,s2m−1}. Each πmρjn has smaller ℓ(r), so by the previous sub-case each summand is in SN(A); by Lemma C.4 the sum is in SN(A).
Lemma C.3 concludes.
Lemma C.10 (Closed under let). If t∈SN(n) and, for all density matrices ρk∈SN(1) ( k=1,…,n), s[ρ1/x1,…,ρn/xn]∈SN(A), then let x⊗n=t in s∈SN(A).
Proof. By induction on ℓ(t) and Lemma C.3. The term is neutral. If a reduction applies inside t, the induction hypothesis applies (the reduct t′ still satisfies t′∈SN(n) as a reduct of a strongly normalising term). If t is a value of ground type n, it must be a density matrix ρn (no λ- or π-value has type n). The main let rule fires:
Each ρiklk is a density matrix, hence in SN(1). By the hypothesis, each substituted body s[ρi1l1/x1,…,ρinln/xn] belongs to SN(A). By Lemma C.4 the entire sum belongs to SN(A). Lemma C.3 concludes.
Fundamental lemma. A substitution θ is valid for Γ, written θ⊨Γ, if θ(x)∈SN(A) for every x:A∈Γ.
Lemma C.11 (Fundamental lemma). If Γ⊢t:A and θ⊨Γ, then θ(t)∈SN(A).
Proof. By induction on the typing derivation of Γ⊢t:A.
– Variable x:A∈Γ. Then θ(x)∈SN(A) by hypothesis.
– Density matrix ρn. Then θ(ρn)=ρn, which is a normal form, hence in SN=SN(n).
λ-abstraction λx. u of type A→B. Let v∈SN(A). Define θ′=(θ,x↦v); then θ′⊨Γ,x:A. By the induction hypothesis on u, θ′(u)=(θ(u))[v/x]∈SN(B). By Lemma C.5, θ(λx.u)=λx.θ(u)∈SN(A→B).
– Application t1t2. By the induction hypotheses, θ(t1)∈SN(A→B) and θ(t2)∈SN(A). Lemma C.6 gives θ(t1t2)∈SN(B).
– Unitary Umt. By induction, θ(t)∈SN(n). Lemma C.7 gives Umθ(t)∈SN(n).
– Tensor t1⊗t2. By induction, θ(t1)∈SN(m) and θ(t2)∈SN(n). Lemma C.8 gives θ(t1)⊗θ(t2)∈SN(m+n).
– Probabilistic sum ∑ipiui. By induction, each θ(ui)∈SN(A). Lemma C.4 gives θ(∑ipiui)=∑ipiθ(ui)∈SN(A).
– Letcase letcase° x=r in {s0,…,s2m−1}. By induction, θ(r)∈SN((m,n)). For any density matrix ρn∈SN(n), define θ′′=(θ,x↦ρn); then θ′′⊨Γ,x:n, and the induction hypothesis gives each θ(si)[ρn/x]=θ′′(si)∈SN(A). Lemma C.9 gives the result.
– Let let x⊗n=u in s with Γ⊢u:n and Δ,x1:1,…,xn:1⊢s:A. By induction, θ(u)∈SN(n). For any density matrices ρk∈SN(1) ( k=1,…,n), define θ′′=(θ∣Δ,x1↦ρ1,…,xn↦ρn); then θ′′⊨Δ,x1:1,…,xn:1, and by the induction hypothesis θ′′(s)=θ(s)[ρ1/x1,…,ρn/xn]∈SN(A). Lemma C.10 gives let x⊗n=θ(u) in θ(s)∈SN(A).
Taking θ to be the empty substitution (valid for any closed term), the Fundamental Lemma C.11 gives: for every closed ⊢t:A, we have t∈SN(A)⊆SN. Hence every closed well-typed term is strongly normalising under the extended relation, and therefore also under the original relation.
C.5 Semantic Substitution Lemma
Lemma C.12 (Semantic Substitution). Let Γ,x:A⊢t:B, Δ⊢s:A, and θ⊨Γ,Δ. Then [[t[s/x]]]θ=[[t]]θ,x↦[[s]]θ.
Proof. By induction on t.
Let t=x. Then t[s/x]=s, and [[x]]θ,x↦[[s]]θ=[[s]]θ, so both sides equal [[s]]θ.
Let t=y with y=x. Then t[s/x]=y, and [[y]]θ,x↦[[s]]θ=θ(y)=[[y]]θ.
A. Díaz-Caro and T. Miguez
Let t=λy.u. Then t[s/x]=λy.(u[s/x]) (assuming y=x and y∈/FV(s) by renaming). By definition of the interpretation and the induction hypothesis on u:
Let t=letcase∘y=r in {t0,…,t2m−1}, with Γ′⊢r:(m,n) and y:n⊢ti:B. Since the ti are typed in y:n alone, x∈/FV(ti), so t[s/x]=letcase∘y=r[s/x] in {t0,…,t2m−1}. By the induction hypothesis on r, [r[s/x]]θ=[r]θ,x↦[s]θ, so the post-measurement states ρi and probabilities pi are the same on both sides: [t[s/x]]θ=∑ipi[ti]θ,y↦ρi=[t]θ,x↦[s]θ.
Let t=let y⊗n=u in v, with Γ,x:A=Γ1,Γ2,Γ1⊢u:n and Γ2,y1:1,…,yn:1⊢v:B (with yk=x by α-renaming).
If x:A∈Γ1, then t[s/x]=let y⊗n=u[s/x] in v, since x∈/FV(v). By the induction hypothesis on u, [u[s/x]]θ=[u]θ,x↦[s]θ, so the combined decomposition coefficients αi are the same on both sides:
If x:A∈Γ2, then t[s/x]=let y⊗n=u in v[s/x], since x∈/FV(u). The combined decomposition coefficients of [u]θ are unchanged. By the induction hypothesis on v:
Let t=letcase∘x=∑jqjwj in {t0,…,t2m−1} and r=∑jqjletcase∘x=wj in {t0,…,t2m−1}. Write Fi(ρ):=[ti]θ,x↦ρ; this is linear in ρ because the type system is affine ( x appears at most once in ti). Let ρ=[∑jqjwj]θ=∑jqj[wj]θ, and define pi=tr(πi†πiρ) and ρi=πiρπi†/pi as in the semantics. Note that piρi=πiρπi†, so by linearity of Fi, pi⋅Fi(ρi)=Fi(πiρπi†). Therefore, substituting ρ=∑jqj[wj]θ and using linearity:
Hence [t]θ=∑jqj[letcase∘x=wj in {t0,…,t2m−1}]θ=[r]θ.
A. Díaz-Caro and T. Miguez
Let t=let x⊗n=ρn in s, r=∑i,lpils[ρi1l1/x1,…,ρinln/xn], where pil=αi(ρn)∏kλiklk. Unfolding the interpretation of let and applying Lemma C.12 n times:
• Let t=su, r=s′u. By the induction hypothesis [s]θ=[s′]θ, so [su]θ=[s]θ([u]θ)=[s′]θ([u]θ)=[s′u]θ.
• Let t=us, r=us′. By the induction hypothesis [s]θ=[s′]θ, so [us]θ=[u]θ([s]θ)=[u]θ([s′]θ)=[us′]θ.
• Let t=Ums, r=Ums′. [Ums]θ=Um[s]θUm†=Um[s′]θUm†=[Ums′]θ.
• Let t=πms, r=πms′. [πms]θ=∑iπi[s]θπi†=∑iπi[s′]θπi†=[πms′]θ.
• Let t=s⊗u, r=s′⊗u. [s⊗u]θ=[s]θ⊗[u]θ=[s′]θ⊗[u]θ=[s′⊗u]θ. The case t=u⊗s is analogous.
• Let t=∑jpjuj, r=∑jpjvj where uk→vk and uj=vj for j=k. By the induction hypothesis [uk]θ=[vk]θ, so [∑jpjuj]θ=∑jpj[uj]θ=∑jpj[vj]θ=[∑jpjvj]θ.
• Let t=letcase∘x=s in {u0,…,u2m−1}, r=letcase∘x=s′ in {u0,…,u2m−1}. By the induction hypothesis [s]θ=[s′]θ, so the post-measurement states and probabilities are the same, giving [t]θ=[r]θ.
• Let t=let x⊗n=s in u,r=let x⊗n=s′ in u. By the induction hypothesis [s]θ=[s′]θ, so αi([s]θ)=αi([s′]θ) for all i, and the two interpretations agree term by term.
C.7 Compositionality and Adequacy
Lemma C.13 (Compositionality). Let C be a context with hole type A and output type B, and let θ be any valuation of the free variables of C (those not contributed by the hole). For any closed terms ⊢t:A and ⊢r:A, [t]θ=[r]θ implies [C[t]]θ=[C[r]]θ.
Proof. We prove the lemma by structural induction on the context C. In each case we write t and r for the two closed terms with [t]θ=[r]θ, and θ for any fixed valuation of the free variables of C.
Let C=[⋅]. C[t]=t and C[r]=r, so [C[t]]θ=[t]θ=[r]θ=[C[r]]θ directly from the hypothesis.
Let C=λx.C′. For any v in the domain of x, by the induction hypothesis applied to C′ with valuation θ′=(θ,x↦v), [C′[t]]θ′=[C′[r]]θ′. Hence the two functions v↦[C′[t]]θ′ and v↦[C′[r]]θ′ agree pointwise, giving [λx.C′[t]]θ=[λx.C′[r]]θ.
Let C=C′s. [C′[t]s]θ=[C′[t]]θ([s]θ), and by the induction hypothesis [C′[t]]θ=[C′[r]]θ, so the two are equal. The case C=sC′ is symmetric.
Let C=UmC′. [UmC′[t]]θ=Um[C′[t]]θUm†=Um[C′[r]]θUm†=[UmC′[r]]θ, using the induction hypothesis.
Let C=πmC′. [πmC′[t]]θ=∑iπi[C′[t]]θπi†=∑iπi[C′[r]]θπi†=[πmC′[r]]θ.
Let C=C′⊗s. [C′[t]⊗s]θ=[C′[t]]θ⊗[s]θ=[C′[r]]θ⊗[s]θ=[C′[r]⊗s]θ.
The case C=s⊗C′ is symmetric.
Let C=∑ipisi with the hole in sj. Then [∑ipisi]θ=∑i=jpi[si]θ+pj[C′[t]]θ, and by the induction hypothesis [C′[t]]θ=[C′[r]]θ, so the sum is unchanged.
Let C=letcase∘x=C′ in {t0,…,t2m−1}. Let σ=[C′[t]]θ and σ′=[C′[r]]θ. By the induction hypothesis σ=σ′. The probabilities pi=tr(πi†πiσ) and post-measurement states σi=πiσπi†/pi depend only on σ, so they are the same for C′[t] and C′[r]. Hence [letcase∘x=C′[t] in {t0,…,t2m−1}]θ=∑ipi[ti]θ,x↦σi=[letcase∘x=C′[r] in {t0,…,t2m−1}]θ.
Let C=letcase∘x=s in {t0,…,C′,…,t2m−1}. The probabilities pi and post-measurement states σi of s are independent of the hole. For the j-th branch, by the induction hypothesis (with valuation θ,x↦σj), [C′[t]]θ,x↦σj=[C′[r]]θ,x↦σj. All other branches are unchanged, so the total expression is unchanged.
Let C=let x⊗n=C′ in s. The combined decomposition of let x⊗n=C′[t] in s is computed from [C′[t]]θ. By the induction hypothesis, [C′[t]]θ=[C′[r]]θ, so the Pauli coefficients αi and hence the weights pil and eigenprojectors ρiklk are identical for both sides. Therefore [let x⊗n=C′[t] in s]θ=∑i,lpil[s]θ,x1↦ρi1l1,…,xn↦ρinln=[let x⊗n=C′[r] in s]θ.
Let C=let x⊗n=s in C′. The combined decomposition of s is fixed. For each index pair (i,l), let θil=θ,x1↦ρi1l1,…,xn↦ρinln. By the induction hypothesis applied to C′ with valuation θil, [C′[t]]θil=[C′[r]]θil. Multiplying by pil and summing over all (i,l) gives [let x⊗n=s in C′[t]]θ=[let x⊗n=s in C′[r]]θ.
In every case [C[t]]θ=[C[r]]θ, completing the induction.
Lemma C.14 (Normalisation). If ⊢t:n is a closed well-typed term of type n, then there exists a density matrix ρn such that t→∗ρn.
Proof. By Theorem 5.3 (Strong Normalisation), t is strongly normalising. By Theorem 5.2 (Progress) and Theorem 5.1 (Subject Reduction), every closed well-typed term either is a value or reduces, with type preserved. Since t has type n, its normal form must be a value of type n, which can only be a density matrix ρn.
Proof (of Theorem 5.5 (Adequacy)). The argument is assembled directly from the two lemmas and soundness. Let C be any context with hole type A and output type n (so ⊢C[t]:n and ⊢C[r]:n are closed). We exhibit a density matrix ρ such that C[t]→∗ρ and C[r]→∗ρ.
Step 1 (Compositionality). By Lemma C.13 applied with the empty valuation and the hypothesis [t]θ=[r]θ,[C[t]]θ=[C[r]]θ.
A. Díaz-Caro and T. Miguez
Step 2 (Normalisation). By Lemma C.14, since ⊢C[t]:n and ⊢C[r]:n are closed ground-type terms, there exist density matrices ρ1 and ρ2 with C[t]→∗ρ1 and C[r]→∗ρ2.
Step 3 (Soundness, iterated). Writing the first sequence as C[t]=s0→s1→⋯→sk=ρ1, Theorem 5.4 (Soundness) applied at each step gives [s0]θ=⋯=[sk]θ, so [C[t]]θ=[ρ1]θ=ρ1. Likewise [C[r]]θ=ρ2.
Step 4 (Identification). ρ1=[ρ1]θ=[C[t]]θ=[C[r]]θ=[ρ2]θ=ρ2. Setting ρ:=ρ1=ρ2, we have C[t]→∗ρ and C[r]→∗ρ. Since C was an arbitrary context with output type n, Definition 5.1 gives t≡r.