Prerequisites. Direct starred prerequisites: Chapter 184. No later core chapter depends on this route.
A program of the quantum lambda calculus of chapter 184 owns quantum data. Its configuration [𝑄,𝐿,𝑀] contains a register, and reducing the term changes that register. Suppose instead we want a program that describes a circuit: a value that can be stored, printed, applied twice, or transformed, without executing anything. The first attempt is to write a function that produces a term, but the calculus of chapter 184 has no type of circuits. The only way to apply a gate there is to reduce a configuration, and the result is a changed register rather than a description.
The obstruction sharpens once the description is parameterized. Consider the family rep𝑛 := “apply the gate 𝐻 to the wire 𝑛 times”, whose size is selected by a classical natural number. Two facts must hold simultaneously: 𝑛 may be inspected, duplicated, and compared, since it controls a recursion; and the wire may not be duplicated, by theorem 184.4. A single linear context cannot carry both. Typing 𝑛 linearly forbids the recursion that reads it twice — once for the test and once for the recursive call — while typing the wire duplicably reintroduces cloning.
The calculus of this chapter resolves this by splitting the judgment: one context of parameters, available at circuit-generation time and freely duplicable, and one context of states, the wires, which are linear. The splitting is not a convention imposed on the programmer; it is forced by the two requirements just displayed, and every construct of the language is placed on one side of it.
Parameters and states
Fix a set of wire type constants 𝛼. The types of Proto-Quipper-M are 𝐴,𝐵 ::= 𝛼∣0∣𝐴+𝐵∣𝐼∣𝐴⊗𝐵∣𝐴⊸𝐵::= ∣ !𝐴∣𝗇𝖺𝗍∣𝗅𝗂𝗌𝗍𝐴∣Circ(𝑇,𝑈),𝑃,𝑅 ::= 0∣𝑃+𝑅∣𝐼∣𝑃⊗𝑅∣ !𝐴::= ∣𝗇𝖺𝗍∣𝗅𝗂𝗌𝗍𝑃∣Circ(𝑇,𝑈),𝑇,𝑈 ::= 𝛼∣𝐼∣𝑇⊗𝑈. The 𝑃,𝑅 are the parameter types, a subgrammar of the types; the 𝑇,𝑈 are the simple types, which describe wire bundles. Note what each grammar omits: a parameter type never contains a bare wire constant 𝛼 or a linear function, and a simple type contains no !, no sum, and no circuit.
Referenced from 7 locations
The three grammars encode the split. A value of parameter type exists at generation time and may be duplicated; a value of simple type is a bundle of wires in the circuit being built; and Circ(𝑇,𝑈), itself a parameter type, is the type of a completed circuit from interface 𝑇 to interface 𝑈 — a description, duplicable precisely because it is not a wire.
Terms and values are 𝑀,𝑁 ::= 𝑥∣ℓ∣𝑐∣𝗅𝖾𝗍 𝑥=𝑀 𝗂𝗇 𝑁∣𝗅𝖾𝖿𝗍𝐴,𝐵𝑀∣𝗋𝗂𝗀𝗁𝗍𝐴,𝐵𝑀∣ 𝖼𝖺𝗌𝖾 𝑀 𝗈𝖿 {𝗅𝖾𝖿𝗍 𝑥→𝑁∣𝗋𝗂𝗀𝗁𝗍 𝑦→𝑃}∣∗∣𝑀;𝑁∣⟨𝑀,𝑁⟩∣ 𝗅𝖾𝗍 ⟨𝑥,𝑦⟩=𝑀 𝗂𝗇 𝑁∣𝜆𝑥𝐴.𝑀∣𝑀𝑁∣𝗅𝗂𝖿𝗍 𝑀∣𝖿𝗈𝗋𝖼𝖾 𝑀∣ 𝖻𝗈𝗑𝑇𝑀∣𝖺𝗉𝗉𝗅𝗒(𝑀,𝑁)∣(⃗ℓ,𝐶,⃗ℓ′),𝑉,𝑊 ::= 𝑥∣ℓ∣𝑐∣𝗅𝖾𝖿𝗍𝐴,𝐵𝑉∣𝗋𝗂𝗀𝗁𝗍𝐴,𝐵𝑉∣∗∣⟨𝑉,𝑊⟩∣ 𝜆𝑥𝐴.𝑀∣𝗅𝗂𝖿𝗍 𝑀∣(⃗ℓ,𝐶,⃗ℓ′), where ℓ ranges over labels, the names of wires, and (⃗ℓ,𝐶,⃗ℓ′) is a boxed circuit: a circuit 𝐶 together with its input and output label tuples. A label context 𝑄 assigns a wire type constant to each of finitely many labels. A configuration is a pair (𝐶,𝑀) of a circuit under construction and a term. Typing judgments have the form Φ;𝑄 ⊢𝑀 :𝐴, with Φ a context of parameter types and 𝑄 a label context.
Referenced from 4 locations
Let M be a symmetric monoidal category (definition 184.25) together with an interpretation [[ −]] of wire type constants as objects, extended to label contexts by [[𝑄]]:=⨂ℓ∈𝑄[[𝑄(ℓ)]]. The category ML of labelled circuits has label contexts as objects and, as morphisms 𝑄 →𝑄′, the morphisms [[𝑄]] →[[𝑄′]] of M. Identities and composition are those of M, and the symmetric monoidal structure is the unique one making [[ −]] :ML →M symmetric monoidal; for label contexts with disjoint domains, 𝑄 ⊗𝑄′ ≅𝑄 ∪𝑄′.
Referenced from 3 locations
Nothing about quantum mechanics has been used. M is an arbitrary symmetric monoidal category, and a “circuit” is a morphism in it; the quantum instance is one choice among many, and it is deferred to section 185.4 so that the theorems below are visibly independent of it.
Boxing and unboxing
The phase distinction determines two operations. A circuit is built by running a function on fresh wires and recording what happened; that is boxing. A recorded circuit is inserted into the circuit under construction; that is application.
The typing rules for the two circuit constructs are Φ;∅⊢𝑀:!(𝑇⊸𝑈)Φ;∅⊢𝖻𝗈𝗑𝑇𝑀:Circ(𝑇,𝑈), Φ;𝑄1⊢𝑀:Circ(𝑇,𝑈)Φ;𝑄2⊢𝑁:𝑇Φ;𝑄1,𝑄2⊢𝖺𝗉𝗉𝗅𝗒(𝑀,𝑁):𝑈, together with the rules for the modality, Φ;∅⊢𝑀:𝐴Φ;∅⊢𝗅𝗂𝖿𝗍 𝑀:!𝐴,Φ;𝑄⊢𝑀:!𝐴Φ;𝑄⊢𝖿𝗈𝗋𝖼𝖾 𝑀:𝐴.
Referenced from 6 locations
Three side conditions carry the discipline, and each is visible in the rules. The argument of 𝖻𝗈𝗑 is typed in an empty label context, so a circuit description may not capture a wire of the surrounding circuit; that is the exact prohibition that makes Circ(𝑇,𝑈) a parameter type. The argument is also duplicable, of type !(𝑇 ⊸𝑈), so that boxing may run it on freshly generated labels. And 𝖺𝗉𝗉𝗅𝗒 splits the label context, so that the wires fed to a circuit are not also used elsewhere.
Evaluation is a big-step relation (𝐶,𝑀) ⇓(𝐶′,𝑉) on configurations. The rule for boxing is (id𝑄, (𝖿𝗈𝗋𝖼𝖾 𝑀)⃗ℓ)⇓(𝐷,𝑉)(𝐶,𝖻𝗈𝗑𝑇𝑀)⇓(𝐶,(⃗ℓ,𝐷,𝑉)), where 𝑄 is a fresh label context of shape 𝑇 and ⃗ℓ its labels: the body is run on a separate circuit that starts as the identity, and the resulting circuit 𝐷 is packaged as a value. The rule for application appends the recorded circuit to the circuit under construction, renaming its labels to the supplied ones. The remaining rules are the call-by-value rules for the functional constructs, leaving 𝐶 untouched.
Referenced from 3 locations
Let 𝛼 be a wire constant and let 𝑔 :!(𝛼 ⊸𝛼) be a gate. Define, by recursion on a parameter of type 𝗇𝖺𝗍, rep:=𝜆𝑛𝗇𝖺𝗍. 𝗅𝗂𝖿𝗍 (𝜆𝑤𝛼. 𝖼𝖺𝗌𝖾 𝑛 𝗈𝖿 {0→𝑤 ∣ 𝑚+1→(𝖿𝗈𝗋𝖼𝖾 𝑔)𝑤′}),𝑤′:=(𝖿𝗈𝗋𝖼𝖾(rep 𝑚))𝑤, so that rep :𝗇𝖺𝗍 → !(𝛼 ⊸𝛼), and put repbox:=𝜆𝑛𝗇𝖺𝗍. 𝖻𝗈𝗑𝛼(rep 𝑛) of type 𝗇𝖺𝗍 →Circ(𝛼,𝛼).
The variable 𝑛 is used twice in the body — in the test and in the recursive call — which is permitted because 𝗇𝖺𝗍 is a parameter type and 𝑛 is declared in Φ. The variable 𝑤 is used once, which is enforced because 𝛼 is a wire type and 𝑤 is declared in the label context. This is the split announced in the chapter opening, now visible in a single derivation.
Evaluating repbox 3 generates a fresh label ℓ0 of type 𝛼, runs the body on it, and records the three gate applications: 𝐷 = ℓ0 𝑔 ⟶ℓ1 𝑔 ⟶ℓ2 𝑔 ⟶ℓ3, so that the value is the boxed circuit (ℓ0,𝐷,ℓ3) of type Circ(𝛼,𝛼). Its typed interface is one input wire of type 𝛼 and one output wire of type 𝛼, independently of 𝑛; the number 3 is visible in the size of 𝐷 and not in its type. A type that recorded the width would have to mention a term, and no type of definition 185.1 does.
Referenced from 6 locations
The term 𝜆𝑤𝛼. 𝖻𝗈𝗑𝛼(𝗅𝗂𝖿𝗍 (𝜆𝑣𝛼. 𝑤)) is not typable. The body of the 𝖻𝗈𝗑 must be typed in the empty label context by definition 185.4, but it mentions 𝑤, which is in the label context. The rejection is exactly right: the boxed circuit would be a description that secretly refers to a wire of the surrounding circuit, and applying it twice would use that wire twice.
Referenced from 4 locations
★☆☆ Compute the type and the generated circuit of repbox 0 and repbox 1, and state which part of the answer depends on 𝑛 and which does not.
Referenced from 2 locations
★★☆ For each of the following terms, say whether it is typable and name the premise that decides the question: (a) 𝜆𝑛𝗇𝖺𝗍.⟨𝑛,𝑛⟩;(b) 𝜆𝑤𝛼.⟨𝑤,𝑤⟩; (c) 𝜆𝑐Circ(𝛼,𝛼).⟨𝑐,𝑐⟩;(d) 𝜆𝑤𝛼.𝖺𝗉𝗉𝗅𝗒(repbox 2,𝑤).
Referenced from 2 locations
Safety and soundness
Let 𝑄,𝑄′ be label contexts. A configuration (𝐶,𝑀) is well typed with input labels 𝑄, output labels 𝑄′, and type 𝐴, written 𝑄 ⊢(𝐶,𝑀) :𝐴;𝑄′, when there is a label context 𝑄″ disjoint from 𝑄′ with 𝐶 :𝑄 →𝑄″ ∪𝑄′ in ML and ∅;𝑄″ ⊢𝑀 :𝐴.
Referenced from 3 locations
The definition says exactly which wires belong to whom: the circuit built so far consumes the input labels and produces 𝑄″ ∪𝑄′, of which the term owns 𝑄″ and the environment owns 𝑄′.
Let 𝑄 ⊢(𝐶,𝑀) :𝐴;𝑄′ be well typed.
(Subject reduction) If (𝐶,𝑀) ⇓(𝐶′,𝑉) then 𝑄 ⊢(𝐶′,𝑉) :𝐴;𝑄′.
(Error freeness) (𝐶,𝑀) ⇓̸Error.
(Termination) There are 𝐶′ and 𝑉 with (𝐶,𝑀) ⇓(𝐶′,𝑉).
(Soundness) Interpreting a well-typed configuration by [[(𝐶,𝑀)]] := [[𝑄]] 𝐶 ⟶[[𝑄″∪𝑄′]] ≅ ⟶[[𝑄″]]⊗[[𝑄′]] [[𝑀]]⊗id ←←←←←←←←←←←←←←←→[[𝐴]]⊗[[𝑄′]], we have [[(𝐶,𝑀)]] =[[(𝐶′,𝑉)]] whenever (𝐶,𝑀) ⇓(𝐶′,𝑉).
(Computational adequacy) At the observable types, equality of denotations implies that the two configurations evaluate to the same boxed circuit.
Referenced from 10 locations
Clauses (i)–(v) are Propositions 5.2, 5.3, 5.4, 5.6, and 5.7 of Rios and Selinger, A Categorical Model for a Quantum Circuit Description Language, arXiv:1706.02630, which states them and omits their proofs. The proofs are in Rios’s thesis, On a Categorically Sound Quantum Programming Language for Circuit Description, Dalhousie University, 2021, where subject reduction is Theorem 6.4.2, error freeness is Theorem 6.5.1, and soundness is Theorem 9.2.1, the last proved by rule induction over the evaluation relation with the cases grouped as axioms, inductive rules, substitution rules, and circuit rules. This book imports the five statements at exactly the signature displayed above, with the thesis as the proof owner; the extended abstract alone does not discharge them, and no statement here is inferred from the implementations named in section 185.4.
Let ∅;∅ ⊢𝑀 :!(𝑇 ⊸𝑈) and suppose (id𝑄,(𝖿𝗈𝗋𝖼𝖾 𝑀) ⃗ℓ ) ⇓(𝐷,𝑉) for a fresh label context 𝑄 of shape 𝑇. Then [[(𝐶,𝖻𝗈𝗑𝑇𝑀)]] =[[(𝐶,(⃗ℓ,𝐷,𝑉))]].
Referenced from 3 locations
Proof of Lemma 185.10 — The boxing case of soundness
Proof. Both sides have the form [[𝐶]] followed by [[𝑁]] ⊗id for the respective terms 𝑁, and 𝐶 is unchanged by the boxing rule, so it suffices to prove [[𝖻𝗈𝗑𝑇𝑀]] =[[(⃗ℓ,𝐷,𝑉)]] as morphisms 𝐼 →[[Circ(𝑇,𝑈)]]. By definition 185.4 the left side is the name in ML of the morphism [[𝑇]] →[[𝑈]] determined by 𝑀; by definition 185.5 the right side is the name of the morphism recorded by 𝐷 together with the output labels named by 𝑉. The hypothesis (id𝑄,(𝖿𝗈𝗋𝖼𝖾 𝑀)⃗ℓ) ⇓(𝐷,𝑉) and clause (iv) of theorem 185.9 applied to that smaller configuration — whose starting circuit is the identity — give [[(id𝑄,(𝖿𝗈𝗋𝖼𝖾 𝑀)⃗ℓ)]] =[[(𝐷,𝑉)]], and the left side of that equation is exactly the morphism named by [[𝖻𝗈𝗑𝑇𝑀]]. Taking names of equal morphisms gives the claim. ◻
Lemma 185.10 is not an independent proof of clause (iv): it uses that clause at a smaller configuration. It is written out because it exhibits the mechanism — boxing is the name of a morphism, and generation computes that morphism — which the statement of the theorem does not display.
The generic theorem and its quantum instance
Every statement above holds for an arbitrary symmetric monoidal category M with a chosen interpretation of wire constants. The quantum instance is obtained by choosing M to be a category of quantum circuits: objects are finite tensors of wire types, and morphisms are circuits built from a fixed gate set, composed and tensored, taken up to the equations of the chosen circuit formalism. Nothing in theorem 185.9 changes; what changes is what a generated value means.
Implementations, and what they show. A native prototype implementation of Proto-Quipper-M exists, and a full-scale circuit-description language, Quipper, exists with worked developments of teleportation, the quantum Fourier transform, and arithmetic. Both are execution evidence: they show that circuits of the expected shape are produced on the expected inputs. Neither establishes any clause of theorem 185.9, and the prototype’s constructor and tooling coverage is incomplete. An independent mechanized treatment of a related Proto-Quipper core exists in a Hybrid/Coq development, and a separate circuit language, QWIRE, is mechanized in Coq; those developments prove statements about their own systems, and the trust boundary of a host proof assistant is part of what they prove. A modern Proto-Quipper variant adds reversing, control, and a 𝗐𝗂𝗍𝗁-𝖼𝗈𝗆𝗉𝗎𝗍𝖾𝖽 construct; it is a bounded comparison and does not strengthen the endpoints imported here.
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 185.3, then exercise 185.4; the implementation project exercise 185.6 may be attempted at any time.
★★☆ Let swapbox:=𝖻𝗈𝗑𝛼⊗𝛼(𝗅𝗂𝖿𝗍(𝜆𝑝𝛼⊗𝛼.𝗅𝖾𝗍 ⟨𝑢,𝑣⟩=𝑝 𝗂𝗇 ⟨𝑣,𝑢⟩)). Derive its type, compute the generated circuit and its labelled interface, and then compute the circuit generated by the term that applies swapbox twice to a pair 𝑝. State which equation of definition 184.25 makes the second circuit equal to the identity in M, and whether the two generated circuits are equal as data.
Referenced from 4 locations
★★☆ Locate the parameter/state violation in each of the three terms 𝖻𝗈𝗑𝛼(𝗅𝗂𝖿𝗍(𝜆𝑤𝛼.⟨𝑤,𝑤⟩)),𝜆𝑤𝛼.𝗅𝗂𝖿𝗍 𝑤,𝜆𝑛𝗇𝖺𝗍.𝖺𝗉𝗉𝗅𝗒(𝑛,𝑛), naming for each the rule of definition 185.4 or definition 185.1 that fails.
Referenced from 3 locations
★★☆ Compare repbox 3 of example 185.6 with the term of chapter 184 that applies 𝐻 three times to a qubit of a register. Say precisely what each one produces, what each one consumes, and why the first may be used twice while the second may not.
Referenced from 2 locations
Bibliographic notes
The calculus, the parameter/state distinction, the boxing and application constructs, the category ML of labelled circuits, and the five statements of theorem 185.9 are from Rios and Selinger, A Categorical Model for a Quantum Circuit Description Language, arXiv:1706.02630, whose Table 1 and Table 2 are the source of definition 185.1, definition 185.2 and whose Definition 4.2 is definition 185.3. That paper is an extended abstract and omits the proofs; the proof-complete development is Rios’s thesis, cited at theorem 185.9 with its theorem numbers. The comparison with an executing quantum term is the calculus of chapter 184.
Selinger’s survey of graphical languages for monoidal categories is the reference for the diagrammatic reading of a generated circuit, and Vicary’s notes for the categorical background. The Quipper tutorial [GLR^+13] contains the worked teleportation, Fourier transform, and addition developments that motivate circuit description at scale; the pinned Quipper release, the native Proto-Quipper-M prototype, the QWIRE development, and the Hybrid/Coq formalization of a Proto-Quipper core are retained in the reference library as implementation and comparison evidence. The modern Proto-Quipper with reversing and control [FKRS26] is a bounded comparison whose own conclusion leaves the combined dependent and modal semantics open.