Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
In every calculus so far, a value may be named, used twice, and discarded: 𝗅𝖾𝗍 𝑥 =𝑉 𝗂𝗇 ⟨𝑥,𝑥⟩ is a program. For a value that is a quantum bit, the first of those three operations is impossible. The impossibility is not a design decision about a language; it is a theorem about linear maps, proved in theorem 184.4 below, and any language whose values include quantum bits must either reject that program or be unsound with respect to the physics it claims to describe.
Rejecting it is not enough either. A quantum program measures, and measurement is probabilistic and changes the state that later computation reads; a term alone cannot carry that state, because two variables in different parts of a term may refer to entangled qubits whose joint state is not the pair of their separate states (lemma 184.3). So the calculus must be built on configurations that separate a classical term from a quantum store, its reduction must be probabilistic, and its type system must ensure that a well-typed configuration never asks for a duplicate of a stored qubit.
This chapter constructs the linear algebra that makes those requirements precise, fixes one calculus that meets them, and proves its safety theorem. The proof obligations are exactly two: that reduction preserves typing together with the store invariant, and that a well-typed configuration is never stuck in a way that would require an impossible physical operation. Both are proved. What is not proved — and is stated as such — is any claim that the categorical model developed at the end is adequate or fully abstract for this language.
The quantum minimum
Let ℂ2 have the standard basis written |0⟩,|1⟩ and the Hermitian inner product ⟨𝜙 ∣𝜓⟩:=∑𝑖――𝜙𝑖𝜓𝑖. A qubit state is a unit vector |𝜓⟩ =𝛼|0⟩ +𝛽|1⟩ with |𝛼|2 +|𝛽|2 =1. An 𝑛-qubit register state is a unit vector of ⨂𝑛−1𝑖=0ℂ2 ≅ℂ2𝑛, whose standard basis is written |𝑏0⋯𝑏𝑛−1⟩ for 𝑏𝑖 ∈{0,1}. A linear map 𝑈 on a finite-dimensional inner-product space is unitary when 𝑈†𝑈 =id, where the adjoint 𝑈† is the unique linear map with ⟨𝑈†𝜙 ∣𝜓⟩ =⟨𝜙 ∣𝑈𝜓⟩ for all 𝜙,𝜓.
Referenced from 3 locations
Two physical assumptions are used below and are not derived: an isolated system evolves by a unitary map, and a measurement in the standard basis returns outcome 𝑏 with probability given by the Born rule of definition 184.5. Everything else in this section is linear algebra.
Let 𝐻:=1√2(111−1) and let CNOT act on ℂ2 ⊗ℂ2 by |𝑏0𝑏1⟩ ↦|𝑏0 (𝑏0 ⊕𝑏1)⟩. Both are unitary: 𝐻† =𝐻 and 𝐻2 =id, while CNOT permutes an orthonormal basis. Then (𝐻⊗id)|00⟩=1√2(|0⟩+|1⟩)⊗|0⟩=1√2(|00⟩+|10⟩), and applying CNOT gives |Φ+⟩:=1√2(|00⟩ +|11⟩).
Referenced from 3 locations
There are no |𝜙⟩,|𝜒⟩ ∈ℂ2 with |Φ+⟩ =|𝜙⟩ ⊗|𝜒⟩.
Referenced from 5 locations
Proof of Lemma 184.3 — The Bell state is entangled
Proof. Write |𝜙⟩ =𝑎|0⟩ +𝑏|1⟩ and |𝜒⟩ =𝑐|0⟩ +𝑑|1⟩. Then |𝜙⟩ ⊗|𝜒⟩ =𝑎𝑐|00⟩ +𝑎𝑑|01⟩ +𝑏𝑐|10⟩ +𝑏𝑑|11⟩, so equality with |Φ+⟩ requires 𝑎𝑐=1√2,𝑎𝑑=0,𝑏𝑐=0,𝑏𝑑=1√2. From 𝑎𝑐 ≠0 we get 𝑎 ≠0 and 𝑐 ≠0; then 𝑎𝑑 =0 gives 𝑑 =0 and 𝑏𝑐 =0 gives 𝑏 =0, whence 𝑏𝑑 =0 ≠1√2. ◻
Lemma 184.3 is the reason a program state cannot store a qubit inside a term: the joint state of two qubits is not determined by two separate qubit expressions.
There is no linear map 𝑈 :ℂ2 ⊗ℂ2 →ℂ2 ⊗ℂ2 such that 𝑈(|𝜓⟩ ⊗|0⟩) =|𝜓⟩ ⊗|𝜓⟩ for every qubit state |𝜓⟩.
Referenced from 6 locations
Proof of Theorem 184.4 — No cloning
Proof. Suppose 𝑈 is such a map. Taking |𝜓⟩ =|0⟩ and |𝜓⟩ =|1⟩ gives 𝑈|00⟩ =|00⟩ and 𝑈|10⟩ =|11⟩. Taking | +⟩:=1√2(|0⟩ +|1⟩) and using linearity, 𝑈(|+⟩⊗|0⟩)=1√2(𝑈|00⟩+𝑈|10⟩)=1√2(|00⟩+|11⟩), whereas the assumed property requires | +⟩ ⊗| +⟩ =12(|00⟩ +|01⟩ +|10⟩ +|11⟩). The coefficient of |01⟩ is 0 in the first and 12 in the second. ◻
Only linearity was used: no unitarity, no norm, no physics. The theorem therefore constrains every calculus whose values may be arbitrary quantum states, independently of which gates it provides.
Let |𝑄⟩ be an 𝑛-qubit state and 0 ≤𝑖 <𝑛. Write |𝑄⟩ =𝛼|𝑄0⟩ +𝛽|𝑄1⟩, where |𝑄𝑏⟩ is a normalized state in which the 𝑖-th qubit is |𝑏⟩ and |𝛼|2 +|𝛽|2 =1; this decomposition exists and is unique up to phase. Measuring the 𝑖-th qubit in the standard basis yields outcome 0 with probability |𝛼|2 and leaves the register in state |𝑄0⟩, and outcome 1 with probability |𝛽|2, leaving |𝑄1⟩.
Referenced from 6 locations
A density matrix on a finite-dimensional space 𝑉 is a positive semidefinite linear map 𝜌 :𝑉 →𝑉 with tr 𝜌 =1; a pure state |𝜓⟩ corresponds to 𝜌 =|𝜓⟩⟨𝜓|. For a bipartite space 𝑉 ⊗𝑊, the partial trace tr𝑊 is the unique linear map with tr𝑊(𝐴 ⊗𝐵) =tr(𝐵) ⋅𝐴. A channel is a completely positive trace-preserving linear map on density matrices.
Referenced from 3 locations
Take |Φ+⟩ and discard the second qubit. With 𝜌 =|Φ+⟩⟨Φ+| =12(|00⟩⟨00| +|00⟩⟨11| +|11⟩⟨00| +|11⟩⟨11|), the partial trace over the second factor kills the two cross terms, since tr(|0⟩⟨1|) =0, and gives tr2𝜌=12|0⟩⟨0|+12|1⟩⟨1|=12id. The same matrix is obtained by measuring the first qubit of |Φ+⟩ and forgetting the outcome. Discarding a qubit is therefore a perfectly good operation — it is a channel — and it is not the operation forbidden by theorem 184.4. A type system for quantum data must forbid duplication; it need not forbid discarding, and the calculus fixed below does not.
Referenced from 8 locations
★☆☆ Verify that CNOT is unitary by exhibiting its matrix in the basis |00⟩,|01⟩,|10⟩,|11⟩ and computing CNOT†CNOT. Then compute (id ⊗𝐻)|Φ+⟩ and say whether the result is entangled.
Referenced from 2 locations
★★☆ Show that theorem 184.4 still holds if 𝑈 is only required to satisfy 𝑈(|𝜓⟩ ⊗|0⟩) =𝑒𝑖𝜃(𝜓)|𝜓⟩ ⊗|𝜓⟩ for some phase depending on |𝜓⟩. Then show that a map cloning the two basis states alone does exist, and identify exactly which hypothesis the clone of | +⟩ violates.
Referenced from 2 locations
★★☆ Measure the first qubit of |Φ+⟩ using definition 184.5: compute 𝛼, 𝛽, |𝑄0⟩, |𝑄1⟩, and the two probabilities, and then compute the state of the second qubit conditional on each outcome. Compare with example 184.7 and explain why the two calculations agree on the density matrix but differ in what an observer knows.
Referenced from 2 locations
A calculus with classical control
The calculus fixed for this chapter is that of Selinger and Valiron, A Lambda Calculus for Quantum Computation with Classical Control, arXiv cs/0404056. Its shape is forced by the previous section: a configuration carries a quantum register separately from the term, and the type system is affine linear.
Terms and values are 𝑀,𝑁 ::= 𝑥∣𝑀𝑁∣𝜆𝑥.𝑀∣⟨𝑀,𝑁⟩∣𝗅𝖾𝗍 ⟨𝑥1,𝑥2⟩=𝑀 𝗂𝗇 𝑁∣ 𝗂𝖿 𝑀 𝗍𝗁𝖾𝗇 𝑁 𝖾𝗅𝗌𝖾 𝑃∣0∣1∣∗∣𝗆𝖾𝖺𝗌∣𝗇𝖾𝗐∣𝑈,𝑉,𝑊 ::= 𝑥∣𝜆𝑥.𝑀∣0∣1∣∗∣𝗆𝖾𝖺𝗌∣𝗇𝖾𝗐∣𝑈∣⟨𝑉,𝑊⟩, where 𝑈 ranges over a set of built-in unitary gates, each with an arity. A program state is a triple [𝑄,𝐿,𝑀] in which 𝑄 is a normalized vector of ⨂𝑖<𝑛ℂ2 for some 𝑛 ≥0, 𝑀 is a term, and 𝐿 is an injective linking function from a set of variables containing FV(𝑀) to {0,…,𝑛 −1}. We write 𝑝𝑖 for the variable 𝑥 with 𝐿(𝑥) =𝑖 and abbreviate [𝑄,𝐿,𝑀] to [𝑄,𝑀].
Referenced from 5 locations
The linking function is the device that answers lemma 184.3: the term mentions names, the register holds one joint state, and the correspondence between them is explicit and injective.
Write [𝑄,𝑀] ⟶𝑝[𝑄′,𝑀′] for a step taken with probability 𝑝. The root rules are [𝑄,(𝜆𝑥.𝑀)𝑉]⟶1[𝑄,𝑀[𝑉/𝑥]],[𝑄,𝗅𝖾𝗍 ⟨𝑥1,𝑥2⟩=⟨𝑉1,𝑉2⟩ 𝗂𝗇 𝑁]⟶1[𝑄,𝑁[𝑉1/𝑥1,𝑉2/𝑥2]],[𝑄,𝗂𝖿 0 𝗍𝗁𝖾𝗇 𝑀 𝖾𝗅𝗌𝖾 𝑁]⟶1[𝑄,𝑁],[𝑄,𝗂𝖿 1 𝗍𝗁𝖾𝗇 𝑀 𝖾𝗅𝗌𝖾 𝑁]⟶1[𝑄,𝑀],[𝑄,𝑈⟨𝑝𝑗1,…,𝑝𝑗𝑛⟩]⟶1[𝑄′,⟨𝑝𝑗1,…,𝑝𝑗𝑛⟩],[𝑄,𝗇𝖾𝗐 𝑏]⟶1[𝑄⊗|𝑏⟩,𝑝𝑛],[𝛼𝑄0+𝛽𝑄1,𝗆𝖾𝖺𝗌 𝑝𝑖]⟶|𝛼|2[𝑄0,0],[𝛼𝑄0+𝛽𝑄1,𝗆𝖾𝖺𝗌 𝑝𝑖]⟶|𝛽|2[𝑄1,1], where in the gate rule the indices 𝑗1,…,𝑗𝑛 are pairwise distinct and 𝑄′ is obtained from 𝑄 by applying 𝑈 to those qubits, in the 𝗇𝖾𝗐 rule 𝑄 has 𝑛 qubits so that 𝑝𝑛 names the new one, and in the measurement rules 𝑄0,𝑄1 are the normalized states of definition 184.5 for the qubit named 𝑝𝑖. These rules are closed under the left-to-right call-by-value evaluation contexts for application, pairing, 𝗅𝖾𝗍, and 𝗂𝖿.
Referenced from 5 locations
Types are 𝐴,𝐵 ::= 𝛼∣𝑋∣ !𝐴∣(𝐴⊸𝐵)∣⊤∣(𝐴⊗𝐵), where 𝛼 ranges over the type constants 𝖻𝗂𝗍 and 𝗊𝖻𝗂𝗍 and 𝑋 over type variables; !𝐴 is the type of duplicable values. Subtyping 𝐴 <:𝐵 is generated by 𝛼<:𝛼,𝑋<:𝑋,⊤<:⊤, 𝐴<:𝐵!𝐴<:𝐵,!𝐴<:𝐵!𝐴<:!𝐵,𝐴<:𝐴′𝐵<:𝐵′𝐴′⊸𝐵<:𝐴⊸𝐵′, 𝐴1<:𝐵1𝐴2<:𝐵2𝐴1⊗𝐴2<:𝐵1⊗𝐵2.
Referenced from 4 locations
Judgments have the form Δ ⊢𝑀 :𝐵 with Δ a function from variables to types. Writing !Δ for a context all of whose types begin with !, the rules are 𝐴<:𝐵Δ,𝑥:𝐴⊢𝑥:𝐵,𝐴𝑐<:𝐵Δ⊢𝑐:𝐵, Γ1,!Δ⊢𝑀:𝐴⊸𝐵Γ2,!Δ⊢𝑁:𝐴Γ1,Γ2,!Δ⊢𝑀𝑁:𝐵, 𝑥:𝐴,Δ⊢𝑀:𝐵Δ⊢𝜆𝑥.𝑀:𝐴⊸𝐵,Γ,!Δ,𝑥:𝐴⊢𝑀:𝐵FV(𝑀)∩|Γ|=∅Γ,!Δ⊢𝜆𝑥.𝑀:!𝑛+1(𝐴⊸𝐵), !Δ,Γ1⊢𝑀1:!𝑛𝐴1!Δ,Γ2⊢𝑀2:!𝑛𝐴2!Δ,Γ1,Γ2⊢⟨𝑀1,𝑀2⟩:!𝑛(𝐴1⊗𝐴2),Δ⊢∗:!𝑛⊤, !Δ,Γ1⊢𝑀:!𝑛(𝐴1⊗𝐴2)!Δ,Γ2,𝑥1:!𝑛𝐴1,𝑥2:!𝑛𝐴2⊢𝑁:𝐴!Δ,Γ1,Γ2⊢𝗅𝖾𝗍 ⟨𝑥1,𝑥2⟩=𝑀 𝗂𝗇 𝑁:𝐴, Γ1,!Δ⊢𝑃:𝖻𝗂𝗍Γ2,!Δ⊢𝑀:𝐴Γ2,!Δ⊢𝑁:𝐴Γ1,Γ2,!Δ⊢𝗂𝖿 𝑃 𝗍𝗁𝖾𝗇 𝑀 𝖾𝗅𝗌𝖾 𝑁:𝐴, with the constants typed by 𝐴0=𝐴1=!𝖻𝗂𝗍,𝐴𝗇𝖾𝗐=!(𝖻𝗂𝗍⊸𝗊𝖻𝗂𝗍),𝐴𝗆𝖾𝖺𝗌=!(𝗊𝖻𝗂𝗍⊸!𝖻𝗂𝗍),𝐴𝑈=!(𝗊𝖻𝗂𝗍𝑛⊸𝗊𝖻𝗂𝗍𝑛). A program state [𝑄,𝐿,𝑀] is well typed of type 𝐵, written [𝑄,𝐿,𝑀] :𝐵, when Δ ⊢𝑀 :𝐵 is derivable for Δ ={𝑥 :𝗊𝖻𝗂𝗍 ∣𝑥 ∈FV(𝑀)}.
Referenced from 10 locations
Three features of definition 184.11 carry the whole discipline. Contexts are split in the binary rules, so a linear variable cannot be used twice. The duplicable part !Δ is shared rather than split, so a duplicable value may be used any number of times. And the axiom permits an unused Δ, so weakening is available: a value may be discarded, which by example 184.7 is the partial trace and not an error.
Let 𝑀 be the term 𝗅𝖾𝗍 ⟨𝑥,𝑦⟩=⟨𝗇𝖾𝗐 0,𝗇𝖾𝗐 0⟩ 𝗂𝗇 𝗅𝖾𝗍 ⟨𝑥′,𝑦′⟩=CNOT⟨𝐻𝑥,𝑦⟩ 𝗂𝗇 𝗆𝖾𝖺𝗌 𝑥′. Typing: 𝗇𝖾𝗐 0 has type 𝗊𝖻𝗂𝗍 by the constant rule and application; the pair has type 𝗊𝖻𝗂𝗍 ⊗𝗊𝖻𝗂𝗍 with 𝑛 =0; the gate has type 𝗊𝖻𝗂𝗍2 ⊸𝗊𝖻𝗂𝗍2 after one subtyping step; and 𝗆𝖾𝖺𝗌 𝑥′ has type !𝖻𝗂𝗍. The two halves of the pair are typed in disjoint contexts, which is what prevents writing ⟨𝑥,𝑥⟩.
Reduction from the empty register: two 𝗇𝖾𝗐 steps give [|00⟩,…] with 𝑥 =𝑝0, 𝑦 =𝑝1; the gate steps give [|Φ+⟩,…] by example 184.2; and the measurement step gives [|00⟩,0] with probability 12 and [|11⟩,1] with probability 12. The final configuration still holds one qubit, named by a variable that no longer occurs in the term; it has been discarded, and example 184.7 says what its state is.
Referenced from 3 locations
Safety
Two properties are to be proved. Reduction must preserve typing, so that the discipline of definition 184.11 still holds after a step; and a well-typed configuration must never be stuck at a term that would require an impossible operation — a gate applied to a duplicated qubit name, or a gate applied to a function.
A program state [𝑄,𝐿,𝑀] is an error state when 𝑀 is not a value and no reduction rule of definition 184.9 applies to it; the two cases to keep in mind are [𝑄,𝑈⟨𝑝𝑖,𝑝𝑖⟩], where the gate rule fails because the indices are not distinct, and [𝑄,𝐻(𝜆𝑥.𝑥)], where no rule applies because the argument is not a qubit name.
Referenced from 2 locations
If 𝑥 ∉FV(𝑀) and Δ,𝑥 :𝐴 ⊢𝑀 :𝐵, then Δ ⊢𝑀 :𝐵.
If 𝑉 is a value and Δ ⊢𝑉 :!𝐴, then for every 𝑥 ∈FV(𝑉) there is a type 𝐶 with 𝑥 :!𝐶 ∈Δ.
If 𝐴 <:!𝐵 then 𝐴 =!𝐶 for some 𝐶.
Referenced from 7 locations
Proof of Lemma 184.14 — Weakening and duplicable values
Proof. (iii) is an induction on the derivation of 𝐴 <:!𝐵: the only rules whose conclusion has a ! on the right are the two rules for !, and both have a ! on the left of the conclusion.
(i) Induction on the typing derivation. The context is only ever split or shared, never inspected, and every rule permits an arbitrary unused part of the context; the axiom permits it explicitly.
(ii) Induction on 𝑉. If 𝑉 =𝑥 then the axiom gives 𝐴′ <:!𝐴 for the declared type 𝐴′ of 𝑥, and (iii) gives 𝐴′ =!𝐶. If 𝑉 is an abstraction with type !𝐴, the only rule deriving a type beginning with ! for an abstraction is the second abstraction rule, whose conclusion requires all free variables of 𝑉 to be typed in !Δ. The constants have closed types, and for a pair the introduction rule with 𝑛 ≥1 types both components in contexts whose shared part is !Δ, so the induction hypothesis applies. ◻
Let 𝑉 be a value. If Γ1,!Δ,𝑥 :𝐴 ⊢𝑀 :𝐵 and Γ2,!Δ ⊢𝑉 :𝐴, then Γ1,Γ2,!Δ ⊢𝑀[𝑉/𝑥] :𝐵.
Referenced from 5 locations
Proof of Lemma 184.15 — Linear substitution
Proof. Induction on the derivation of Γ1,!Δ,𝑥 :𝐴 ⊢𝑀 :𝐵, with the contexts Γ1,Γ2 tracked explicitly.
Axiom. If 𝑀 =𝑥 then 𝑀[𝑉/𝑥] =𝑉 and 𝐴 <:𝐵, so the conclusion follows from the derivation of 𝑉 by the subtyping in the axiom of definition 184.11. If 𝑀 =𝑦 ≠𝑥 then 𝑀[𝑉/𝑥] =𝑦, and lemma 184.14(i) discards the unused hypothesis on 𝑥 and adds the unused Γ2.
Application. Let 𝑀 =𝑀1𝑀2, typed from Γ′1,!Δ ⊢𝑀1 :𝐴′ ⊸𝐵 and Γ″1,!Δ ⊢𝑀2 :𝐴′ with Γ1 =Γ′1,Γ″1. The variable 𝑥 occurs in exactly one of the two subcontexts, since contexts are split; say in Γ′1. The induction hypothesis substitutes into 𝑀1 using Γ2, and 𝑀2[𝑉/𝑥] =𝑀2 because 𝑥 ∉FV(𝑀2). Reassembling with the application rule gives the conclusion. If instead 𝑥 :𝐴 lies in the shared part, then 𝐴 =!𝐶; then 𝑉 is typed in Γ2,!Δ with Γ2 consisting of duplicable types by lemma 184.14(ii), so Γ2 may be shared between the two premises, and the induction hypothesis applies to both.
Abstraction. For the linear rule, the induction hypothesis applies to the body. For the duplicable rule, its side condition FV(𝑀) ∩|Γ| =∅ is preserved because FV(𝑀[𝑉/𝑥]) ⊆(FV(𝑀) ∖{𝑥}) ∪FV(𝑉) and the free variables of 𝑉 are duplicable by lemma 184.14(ii).
Pairing, 𝗅𝖾𝗍, and 𝗂𝖿. Each is a splitting rule and is treated exactly as the application case, with the same distinction between 𝑥 occurring in a split part and 𝑥 occurring in the shared duplicable part. ◻
If [𝑄,𝐿,𝑀] :𝐵 and [𝑄,𝐿,𝑀] ⟶𝑝[𝑄′,𝐿′,𝑀′] with 𝑝 >0, then [𝑄′,𝐿′,𝑀′] :𝐵.
Referenced from 7 locations
Proof of Theorem 184.16 — Subject reduction
Proof. Induction on the derivation of the reduction step. The contextual cases follow from the induction hypothesis, because each evaluation context is built by a typing rule whose other premises are unchanged. For the root rules:
Beta and 𝗅𝖾𝗍 use lemma 184.15, the substituted terms being values.
Conditional discards one branch; both branches were typed at 𝐵 in the same context, and lemma 184.14(i) discards the context used for the guard.
Gate. The term 𝑈⟨𝑝𝑗1,…,𝑝𝑗𝑛⟩ has type 𝗊𝖻𝗂𝗍𝑛, and so does the resulting tuple of names; the register changes but 𝐿 and the set of free variables do not, so the typing context Δ ={𝑥 :𝗊𝖻𝗂𝗍} is unchanged.
New. The term 𝗇𝖾𝗐 𝑏 has type 𝗊𝖻𝗂𝗍, and the result 𝑝𝑛 has type 𝗊𝖻𝗂𝗍 in the extended context; 𝐿′ extends 𝐿 injectively by 𝑝𝑛 ↦𝑛, so the invariant that free variables are linked injectively into the register is preserved.
Measurement. The term 𝗆𝖾𝖺𝗌 𝑝𝑖 has type !𝖻𝗂𝗍 and the results 0 and 1 have type !𝖻𝗂𝗍 by the constant rule. The variable 𝑝𝑖 disappears from the term, and 𝐿′ is 𝐿 restricted accordingly; the register loses no qubit, so the linking function remains injective into {0,…,𝑛 −1}. ◻
Let Δ =𝑥1 :𝗊𝖻𝗂𝗍,…,𝑥𝑛 :𝗊𝖻𝗂𝗍 and let 𝑉 be a value. If Δ ⊢𝑉 :𝐴 ⊸𝐵 then 𝑉 is 𝗇𝖾𝗐, 𝗆𝖾𝖺𝗌, a gate 𝑈, or an abstraction. If Δ ⊢𝑉 :𝐴 ⊗𝐵 then 𝑉 =⟨𝑉1,𝑉2⟩. If Δ ⊢𝑉 :𝖻𝗂𝗍 then 𝑉 ∈{0,1}.
Referenced from 6 locations
Proof of Lemma 184.17 — Shape of values
Proof. By inspection of the rules that can conclude a judgment for a value in such a context, together with definition 184.10: a variable in Δ has type 𝗊𝖻𝗂𝗍, and 𝗊𝖻𝗂𝗍 <:𝐴 ⊸𝐵, 𝗊𝖻𝗂𝗍 <:𝐴 ⊗𝐵, and 𝗊𝖻𝗂𝗍 <:𝖻𝗂𝗍 all fail, since subtyping relates a type constant only to itself. The remaining values are the listed ones. ◻
Let [𝑄,𝐿,𝑀] :𝐵. Then [𝑄,𝐿,𝑀] is not an error state. Either 𝑀 is a value, or there is a state [𝑄′,𝐿′,𝑀′] with [𝑄,𝐿,𝑀] ⟶𝑝[𝑄′,𝐿′,𝑀′]; and in the second case the probabilities of all single-step reductions from [𝑄,𝐿,𝑀] sum to 1.
Referenced from 12 locations
Proof of Theorem 184.18 — Progress and safety
Proof. Induction on 𝑀. If 𝑀 is a value there is nothing to prove. Otherwise 𝑀 has one of the forms 𝑃𝑁, 𝑁𝑉, ⟨𝑁,𝑃⟩, ⟨𝑉,𝑁⟩, 𝗂𝖿 𝑁 𝗍𝗁𝖾𝗇 𝑃 𝖾𝗅𝗌𝖾 𝑅, or 𝗅𝖾𝗍 ⟨𝑥,𝑦⟩ =𝑁 𝗂𝗇 𝑃 with 𝑁 not a value, in which case the induction hypothesis applies to 𝑁 — whose free variables are still all of type 𝗊𝖻𝗂𝗍 — and the corresponding evaluation-context rule lifts its reductions, preserving the total probability 1.
The remaining cases are redexes. For 𝑉𝑊 with both parts values, lemma 184.17 says that 𝑉 is 𝗇𝖾𝗐, 𝗆𝖾𝖺𝗌, a gate, or an abstraction. For an abstraction the beta rule applies with probability 1. For 𝗇𝖾𝗐 the argument has type 𝖻𝗂𝗍, so it is 0 or 1 by lemma 184.17, and the 𝗇𝖾𝗐 rule applies. For 𝗆𝖾𝖺𝗌 the argument has type 𝗊𝖻𝗂𝗍; a value of that type in this context is a variable, hence some 𝑝𝑖, and the two measurement rules apply with probabilities summing to |𝛼|2 +|𝛽|2 =1. For a gate 𝑈 of arity 𝑛 the argument has type 𝗊𝖻𝗂𝗍𝑛, so by lemma 184.17 it is a tuple of values of type 𝗊𝖻𝗂𝗍, hence a tuple of names 𝑝𝑗1,…,𝑝𝑗𝑛; these are pairwise distinct because the tuple was typed by the pairing rule, which splits the context, so no variable occurs in two components, and 𝐿 is injective. Hence the gate rule applies.
In every case a rule applies, so [𝑄,𝐿,𝑀] is not an error state. ◻
For a well-typed program state, no reduction sequence reaches a configuration in which a gate is applied to two occurrences of one qubit name or to a non-qubit, and every maximal reduction sequence either converges to a value or is infinite.
Referenced from 2 locations
Proof of Corollary 184.19 — What the type system establishes
Proof. The first claim is theorem 184.16 followed by theorem 184.18 at each step. The second is the same statement read as a dichotomy: by progress, a well-typed non-value always reduces. ◻
★☆☆ Show that 𝜆𝑥.⟨𝑥,𝑥⟩ has no type 𝗊𝖻𝗂𝗍 ⊸𝗊𝖻𝗂𝗍 ⊗𝗊𝖻𝗂𝗍, and that it does have the type !𝖻𝗂𝗍 ⊸!𝖻𝗂𝗍 ⊗!𝖻𝗂𝗍. Point at the exact premise of the pairing rule that distinguishes the two cases.
Referenced from 3 locations
★☆☆ Give a typing derivation for 𝜆𝑥. 0 at type 𝗊𝖻𝗂𝗍 ⊸!𝖻𝗂𝗍 and describe the channel that the corresponding program implements on a one-qubit register.
Referenced from 3 locations
★★☆ Delete the injectivity requirement on 𝐿 from definition 184.8. Exhibit a program state that is well typed in the sense of definition 184.11, reduces, and violates the conclusion of theorem 184.18; then identify the step of the proof of theorem 184.18 that used injectivity.
Referenced from 2 locations
Type inference by decoration
The term 𝑀:=𝜆𝑥.𝜆𝑦. 𝑥𝑦 has the types 𝑇1:=(𝐴 ⊸𝐵) ⊸(𝐴 ⊸𝐵) and 𝑇2:=!(𝐴 ⊸𝐵) ⊸!(𝐴 ⊸𝐵), and neither is a substitution instance or a subtype of the other; moreover the most general type of which both are substitution instances, namely 𝑋 ⊸𝑋, is not a type of 𝑀.
Referenced from 4 locations
Proof of Proposition 184.21 — No principal types
Proof. Both typings are derivable: 𝑇1 by the linear abstraction rule twice, and 𝑇2 by the duplicable abstraction rule, whose side condition is met because FV(𝑀) =∅. Neither is an instance of the other because substitution does not insert or delete a !; neither is a subtype of the other because definition 184.10 relates !𝐶 and 𝐶 only in the direction !𝐶 <:𝐶, and the two occurrences of the affected type in 𝑇1 and 𝑇2 appear in opposite variance positions. Finally 𝑋 ⊸𝑋 is not derivable for 𝑀, since the body 𝑥𝑦 requires the type of 𝑥 to be an arrow. ◻
Inference must therefore proceed differently: strip the exponentials, infer an ordinary simple type, and then search for a decoration.
Intuitionistic types are 𝑈,𝑉 ::=𝛼 ∣𝑋 ∣(𝑈 ⇒𝑉) ∣(𝑈 ×𝑉) ∣⊤. The skeleton map ( −)† deletes every !: (!𝑛𝛼)†=𝛼,(!𝑛𝑋)†=𝑋,(!𝑛⊤)†=⊤,(!𝑛(𝐴⊸𝐵))†=𝐴†⇒𝐵†,(!𝑛(𝐴⊗𝐵))†=𝐴†×𝐵†, and the lifting map ( −)♣ reads the clauses backwards, producing a quantum type with no !. A quantum derivation 𝜋 has a skeleton 𝜋†, obtained by applying ( −)† to every judgment in it; a decoration of an intuitionistic derivation 𝜌 is a quantum derivation 𝜋 with 𝜋† =𝜌.
Referenced from 2 locations
Let 𝑀 be a term.
(Soundness) If 𝜋 is a quantum derivation of Γ ⊢𝑀 :𝐴, then 𝜋† is an intuitionistic derivation of Γ† ⊢𝑀 :𝐴†.
(Completeness) If 𝑀 is quantum typable and 𝜌 is any intuitionistic derivation of Δ ⊢𝑀 :𝑈 with |Δ| =|Γ|, then 𝑀 has a quantum derivation whose skeleton is 𝜌.
(Decidability) Quantum typability is decidable: infer an intuitionistic derivation 𝜌, which is decidable, and search the finitely many decorations of 𝜌 that use no repeated exponential.
Referenced from 4 locations
Clause (i) is proved by induction on 𝜋: every quantum rule becomes the corresponding intuitionistic rule once the exponentials are deleted, the two abstraction rules both becoming the intuitionistic abstraction rule, and the context splittings becoming context sharing. Clause (ii) is Lemma 13 of the selected paper, and clause (iii) is the algorithm of its Section 5.3, using its Lemma 15 to bound the search to decorations without repeated exponentials. What is imported is the statement that a quantum typing exists whenever some decoration of the intuitionistic derivation is valid, together with the finiteness bound that makes the search terminate. The algorithm returns a type, not a description of all types; by proposition 184.21 no most general type exists.
The following terms are rejected, each for a different reason visible in the rules. The term 𝜆𝑥.⟨𝑥,𝑥⟩ at 𝗊𝖻𝗂𝗍 fails because the pairing rule splits the context (exercise 184.4). The term 𝜆𝑥. 𝗂𝖿 𝑥 𝗍𝗁𝖾𝗇 0 𝖾𝗅𝗌𝖾 1 at 𝗊𝖻𝗂𝗍 ⊸!𝖻𝗂𝗍 fails because the conditional requires the guard to have type 𝖻𝗂𝗍 and 𝗊𝖻𝗂𝗍 <:𝖻𝗂𝗍 is not derivable: a qubit cannot be inspected without measurement. The term 𝐻(𝜆𝑥.𝑥) fails because 𝐴𝐻 =!(𝗊𝖻𝗂𝗍 ⊸𝗊𝖻𝗂𝗍) forces the argument to have type 𝗊𝖻𝗂𝗍, and by lemma 184.17 an abstraction does not.
Referenced from 3 locations
★★☆ Infer the intuitionistic type of 𝜆𝑓.𝜆𝑥. 𝑓(𝑓𝑥), enumerate its decorations without repeated exponentials, and determine which are valid quantum derivations. Then explain what your answer says about applying a quantum gate twice to the same qubit.
Referenced from 2 locations
★★☆ Exhibit two quantum derivations with the same skeleton whose conclusions have incomparable types, and conclude that ( −)† is not injective on derivations. Relate this to proposition 184.21.
Referenced from 2 locations
A model with duals
The linear discipline of definition 184.11 suggests a model in which the tensor is not a categorical product. The pure unitary fragment — terms without 𝗆𝖾𝖺𝗌, 𝗇𝖾𝗐, and 𝗂𝖿, and with types built from 𝗊𝖻𝗂𝗍, ⊗, and ⊤ — is interpreted below in finite-dimensional Hilbert spaces, and the additional structure that this model carries beyond a monoidal category is exactly what the graphical calculus of section 184.6 uses.
A symmetric monoidal category is a category C (definition 141.8) with a functor ⊗ :C ×C →C, an object 𝐼, and natural isomorphisms 𝛼𝐴,𝐵,𝐶 :(𝐴 ⊗𝐵) ⊗𝐶 →𝐴 ⊗(𝐵 ⊗𝐶), 𝜆𝐴 :𝐼 ⊗𝐴 →𝐴, 𝜌𝐴 :𝐴 ⊗𝐼 →𝐴, and 𝜎𝐴,𝐵 :𝐴 ⊗𝐵 →𝐵 ⊗𝐴, subject to the pentagon and triangle coherence equations and to 𝜎𝐵,𝐴 ∘𝜎𝐴,𝐵 =id.
Referenced from 4 locations
Let 𝐅𝐝𝐇𝐢𝐥𝐛 have finite-dimensional complex inner-product spaces as objects and linear maps as morphisms, with ⊗ the tensor product and 𝐼 =ℂ. The structural isomorphisms are the usual ones, and 𝜎 exchanges tensor factors on basis vectors.
Referenced from 2 locations
A symmetric monoidal category is compact closed when every object 𝐴 has a dual: an object 𝐴∗ with morphisms 𝜂𝐴 :𝐼 →𝐴∗ ⊗𝐴 and 𝜀𝐴 :𝐴 ⊗𝐴∗ →𝐼 satisfying the snake equations 𝜌𝐴∘(id𝐴⊗𝜀𝜎𝐴)∘𝛼−1∘(𝜂𝜎𝐴⊗id𝐴)∘𝜆−1𝐴=id𝐴, and its mirror image for 𝐴∗, where the superscript 𝜎 marks the symmetry inserted to make the composite typecheck.
Referenced from 2 locations
Let 𝐴 have orthonormal basis 𝑒1,…,𝑒𝑛 and let 𝐴∗ be the dual space with dual basis 𝑒1,…,𝑒𝑛. Define 𝜂𝐴(1):=∑𝑖𝑒𝑖 ⊗𝑒𝑖 and 𝜀𝐴(𝑥 ⊗𝑓):=𝑓(𝑥). Then equation 184.1 holds, so 𝐅𝐝𝐇𝐢𝐥𝐛 is compact closed.
Referenced from 3 locations
Proof of Proposition 184.28 — Hilbert spaces are compact closed
Proof. Evaluate the composite on a basis vector 𝑒𝑗, suppressing the structural isomorphisms, which act as identities on these elements: 𝑒𝑗 ↦ (∑𝑖𝑒𝑖⊗𝑒𝑖)⊗𝑒𝑗 ↦ ∑𝑖𝑒𝑖⊗𝜀(𝑒𝑖⊗𝑒𝑗)𝜎=∑𝑖𝛿𝑖𝑗𝑒𝑖=𝑒𝑗, where the middle step applies 𝜀 to the second and third factors after the symmetry, giving 𝑒𝑖(𝑒𝑗) =𝛿𝑖𝑗. The mirror equation is the same calculation with the roles of 𝐴 and 𝐴∗ exchanged, using 𝑒𝑖(𝑒𝑗) =𝛿𝑖𝑗 again. ◻
A dagger on a category is an identity-on-objects contravariant functor ( −)† with 𝑓†† =𝑓. A dagger symmetric monoidal category is dagger compact when it is compact closed and 𝜀𝐴 =𝜂†𝐴 ∘𝜎𝐴,𝐴∗. In 𝐅𝐝𝐇𝐢𝐥𝐛 the dagger is the adjoint of definition 184.1, and the displayed equation holds by the calculation ⟨𝜂𝐴(1) ∣𝑓 ⊗𝑥⟩ =∑𝑖――――⟨𝑒𝑖∣𝑓⟩⟨𝑒𝑖 ∣𝑥⟩ =𝑓(𝑥) read as the definition of 𝜀𝐴 up to the symmetry.
Referenced from 2 locations
Interpret 𝗊𝖻𝗂𝗍 by ℂ2, ⊤ by ℂ, 𝐴 ⊗𝐵 by the tensor product, and a context Δ =𝑥1 :𝐴1,…,𝑥𝑛 :𝐴𝑛 by ⨂𝑖[[𝐴𝑖]]. Every derivation of Δ ⊢𝑀 :𝐵 in the unitary fragment determines a linear map [[𝑀]] :[[Δ]] →[[𝐵]], and the map is unitary when every gate constant occurring in 𝑀 is interpreted by a unitary.
Referenced from 3 locations
Proof of Proposition 184.30 — Typing soundness for the unitary fragment
Proof. Induction on the derivation. The axiom gives an identity or a structural isomorphism. Pairing gives a tensor of the two interpretations, which is defined because the contexts are disjoint — this is exactly where the splitting of contexts is used, and it is why the interpretation exists at all. The 𝗅𝖾𝗍 rule composes with the associativity isomorphism. A gate constant gives its matrix. Unitarity is preserved by tensor and composition, and the structural isomorphisms are unitary. ◻
Teleportation, twice
Let 𝖻𝖾𝗅𝗅 be the term 𝗅𝖾𝗍 ⟨𝑎,𝑏⟩=⟨𝗇𝖾𝗐 0,𝗇𝖾𝗐 0⟩ 𝗂𝗇 CNOT⟨𝐻𝑎,𝑏⟩ of type 𝗊𝖻𝗂𝗍 ⊗𝗊𝖻𝗂𝗍, and let 𝗍𝖾𝗅𝖾:=𝜆𝑞. 𝗅𝖾𝗍 ⟨𝑎,𝑏⟩=𝖻𝖾𝗅𝗅 𝗂𝗇𝗅𝖾𝗍 ⟨𝑥,𝑦⟩=CNOT⟨𝑞,𝑎⟩ 𝗂𝗇𝗅𝖾𝗍 𝑚1=𝗆𝖾𝖺𝗌(𝐻𝑥) 𝗂𝗇𝗅𝖾𝗍 𝑚2=𝗆𝖾𝖺𝗌𝑦 𝗂𝗇 𝐶𝑚1𝑚2𝑏, where 𝐶 𝑚1 𝑚2 𝑏 applies 𝑍 when 𝑚1 =1 and 𝑋 when 𝑚2 =1. Typing: 𝗍𝖾𝗅𝖾 has type 𝗊𝖻𝗂𝗍 ⊸𝗊𝖻𝗂𝗍. The variable 𝑞 is consumed by the gate; 𝑎 and 𝑦 are consumed by CNOT and 𝗆𝖾𝖺𝗌; 𝑏 is returned. Every context split is forced, and no rule would allow 𝑞 to appear twice.
Reduction: after 𝖻𝖾𝗅𝗅 the register is |𝜓⟩ ⊗|Φ+⟩ where |𝜓⟩ =𝛼|0⟩ +𝛽|1⟩ is the input qubit. Applying CNOT to the first two qubits and 𝐻 to the first rewrites the state as 12∑𝑚1,𝑚2∈{0,1}|𝑚1𝑚2⟩⊗𝑋𝑚2𝑍𝑚1|𝜓⟩, an identity checked by expanding both sides on the basis |0⟩,|1⟩ for |𝜓⟩. The two measurements therefore each return 0 or 1 with probability 12, and in the branch (𝑚1,𝑚2) the third qubit is 𝑋𝑚2𝑍𝑚1|𝜓⟩; the correction 𝐶 applies 𝑍𝑚1 and 𝑋𝑚2, which are self-inverse, leaving |𝜓⟩. Two classical bits were produced and consumed, and the linear typing shows that the input qubit no longer exists: the value of 𝑞 was consumed by a gate, and only 𝑏 is returned.
Referenced from 5 locations
Read equation 184.1 with 𝐴 =ℂ2. The composite (id ⊗𝜀) ∘(𝜂 ⊗id) sends a state |𝜓⟩ placed on the left wire to the same state on the right wire, having passed through the pair created by 𝜂; that is precisely the statement that a state can be moved along an entangled pair. In the graphical notation, in which a morphism is a box, composition is vertical, ⊗ is horizontal, and 𝜂,𝜀 are a cup and a cap, the equation says that a wire bent twice may be straightened.
The equation is not yet teleportation, and the difference is exactly the corrections in example 184.32: 𝜀 is a single morphism, while a measurement in the Bell basis produces one of four outcomes, each corresponding to 𝜀 ∘(id ⊗𝑈𝑚) for one of the four Pauli maps 𝑈𝑚. Teleportation is therefore the snake equation together with the fact that each 𝑈𝑚 is invertible and its inverse is applicable by a classically controlled gate. The graphical calculus makes the first half visible; the second half is classical control, which is definition 184.9 and not a property of the monoidal structure.
Referenced from 3 locations
Safe uncomputation, compared. A high-level quantum language may provide automatic uncomputation of temporary values. In Silq, a term marked 𝗊𝖿𝗋𝖾𝖾 is one whose action is a permutation of basis states, and the type system permits a temporary value produced by a 𝗊𝖿𝗋𝖾𝖾 computation to be discarded silently, inserting its inverse. The rule delta against definition 184.11 is: add an annotation 𝗊𝖿𝗋𝖾𝖾 on functions, and add a discard rule permitting Γ,𝑥 :𝐴 ⊢𝑀 :𝐵 to conclude Γ ⊢𝗅𝖾𝗍 𝑥 =𝑁 𝗂𝗇 𝑀 :𝐵 when 𝑁 is 𝗊𝖿𝗋𝖾𝖾 and 𝑥 is unused. In the calculus of this chapter that rule is unnecessary for typability, since weakening is already admissible; the difference is operational, because Silq’s rule promises that the discarded value leaves no entanglement, whereas example 184.7 shows that plain discarding may leave a mixed state. Neither Silq’s theorem nor its implementation is imported: the comparison is a rule delta and an example, and theorem 184.18 is unaffected by it.
★★☆ Verify equation 184.1 in 𝐅𝐝𝐇𝐢𝐥𝐛 for 𝐴 =ℂ2 by writing 𝜂(1) =𝑒1 ⊗𝑒1 +𝑒2 ⊗𝑒2 and evaluating the composite on 𝑒1 and on 𝑒2 separately. Then compute what the composite does if 𝜂(1) is replaced by 𝑒1 ⊗𝑒1 alone, and say which equation fails.
Referenced from 2 locations
★★☆ Complete the expansion asserted in example 184.32: expand |𝜓⟩ ⊗|Φ+⟩, apply CNOT to the first two qubits and 𝐻 to the first, and collect terms to obtain the displayed sum. Then write the correction 𝐶 as a term of the calculus and give its typing derivation.
Referenced from 2 locations
Boundary
The type system of definition 184.11 prevents the specified ill-formed uses of quantum data: duplication of a linear variable, application of a gate to a non-qubit, and inspection of a qubit without measurement (example 184.24). Theorem 184.18 is a statement about configurations of this calculus and about nothing else. In particular it does not establish that a physical device implements a gate, that a described process is unitary, that an algorithm has a claimed speedup, or that a compiled circuit is efficient. Quantum error correction, cryptographic security, and hardware compilation require their own theorems with their own hypotheses. Circuit generation — producing a reusable circuit value rather than executing a computation on a register — is a different problem with its own staging discipline, and it is not treated here.
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 184.11, then exercise 184.12; the implementation project exercise 184.15 may be attempted at any time.
★★☆ Write out the pairing case of lemma 184.15 in full, including the subcase in which 𝑥 :!𝐶 lies in the shared duplicable part of the context. State exactly where lemma 184.14(ii) is used and what would go wrong without it.
Referenced from 3 locations
★★☆ The following argument is wrong. “Subject reduction holds for the calculus without the injectivity condition on 𝐿, because the typing of a program state depends only on 𝑀, and theorem 184.16 only ever inspects 𝑀.” Identify the step of the proof of theorem 184.18 that fails under this hypothesis, exhibit the resulting error state, and state the invariant that the corrected argument must carry.
Referenced from 3 locations
★★★ Define, for finite-dimensional spaces 𝐴 and 𝐵, the set of completely positive maps from density matrices on 𝐴 to density matrices on 𝐵, and verify that the measurement of definition 184.5 followed by forgetting the outcome is such a map by exhibiting its Kraus operators. Then compute the map determined by 𝜆𝑥. 0 of exercise 184.5 and compare it with example 184.7.
Referenced from 2 locations
★★☆ Prove clause (i) of theorem 184.23 in full by induction on the quantum derivation, displaying the two abstraction cases separately. Then explain why the converse direction cannot be proved the same way, and which finiteness statement replaces it.
Referenced from 2 locations
Bibliographic notes
The calculus, its probabilistic reduction on program states, its affine linear type system with subtyping, and the safety and inference results of section 184.2, section 184.3, section 184.4 are those of Selinger and Valiron, A Lambda Calculus for Quantum Computation with Classical Control, arXiv cs/0404056: definition 184.8 is its Definition 1, lemma 184.15 its Lemma 10, theorem 184.16 its Theorem 1, theorem 184.18 its Theorem 2 with Corollary 2, and theorem 184.23 its Lemma 13 with the algorithm of its Section 5.3. The decoration technique for linear type inference is due to Danos, Joinet, and Schellinx. Valiron’s later author-released Haskell embedding, retained in the reference library, implements a related discipline with a QRAM simulator; it is implementation evidence, targets a historical compiler, and is not a release accompanying the paper.
The compact-closed and dagger structure of section 184.5 is that of Abramsky and Coecke’s categorical quantum mechanics, with the CPM construction for mixed states due to Selinger; proposition 184.28 is the standard verification in 𝐅𝐝𝐇𝐢𝐥𝐛, and the reading of teleportation as the snake equation together with classical corrections (example 184.33) is theirs. Vicary’s lecture notes and the Edinburgh course on quantum programming semantics are the recommended companions for the graphical calculus; de Wolf’s and Watrous’s texts supply the quantum-information background compressed into section 184.1, and Valiron’s current notes bridge from linear algebra to the calculus. The safe-uncomputation comparison of section 184.6 is the design problem solved by Silq, in Bichsel, Baader, Gehr, and Vechev, Silq: A High-Level Quantum Language with Safe Uncomputation and Intuitive Semantics, PLDI 2020; that paper and its artifact are retained in the reference library and own no statement above.