Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Three requirements are easy to confuse.
The function 𝑛↦2𝑛 on the natural numbers is injective. A program computing it is a program for doubling, and no syntactic operation on that program text produces a program for halving: to invert it one must write a new program, and the new program is partial, since it is undefined on odd arguments. Injectivity of a function is therefore not executable inversion of a program.
Linear use is not injectivity either. In a linear calculus the term 𝜆𝑥.𝖼𝖺𝗌𝖾𝑥𝗈𝖿𝗂𝗇𝗃ℓ𝑦↦𝑦∣𝗂𝗇𝗃𝑟𝑧↦𝑧:𝐴⊕𝐴⊸𝐴 uses its argument exactly once and duplicates nothing. It is not injective: 𝗂𝗇𝗃ℓ𝑎 and 𝗂𝗇𝗃𝑟𝑎 both produce 𝑎. What has been discarded is not a value but the record of which branch was taken.
Both failures have the same repair, and it is a condition on the clauses of a definition rather than on its variables: the left-hand sides must be pairwise non-overlapping, and so must the right-hand sides. A definition satisfying both conditions can be inverted by exchanging the two sides of every clause, and (168.1) fails the second condition, its two right-hand sides being the same variable.
Fix the grammar 𝐴,𝐵::=𝟏∣𝐴⊕𝐵∣𝐴⊗𝐵∣𝜇𝑋.𝐴∣𝑋𝑇::=𝐴↔𝐵∣𝑇1→𝑇2𝑣::=()∣𝑥∣𝗂𝗇𝗃ℓ𝑣∣𝗂𝗇𝗃𝑟𝑣∣(𝑣1,𝑣2)∣𝖿𝗈𝗅𝖽𝑣𝑡::=𝑣∣𝗂𝗇𝗃ℓ𝑡∣𝗂𝗇𝗃𝑟𝑡∣(𝑡1,𝑡2)∣𝖿𝗈𝗅𝖽𝑡∣𝜔𝑡∣𝗅𝖾𝗍𝑝=𝑡1𝗂𝗇𝑡2𝜔::={𝑣1↔𝑒1∣⋯∣𝑣𝑛↔𝑒𝑛}∣𝜑∣𝜆𝜑.𝜔∣𝜔1𝜔2∣𝖿𝗂𝗑𝜑.𝜔 where 𝑝 ranges over tuples of distinct variables and 𝑒 over terms. Terms are typed by Ψ;Δ⊢𝑡:𝐴 with Δ a linear context of term variables and Ψ a context of iso variables; isos are typed by Ψ⊢𝜔𝜔:𝑇.
The relation 𝑡1⟂𝑡2 is the least relation closed under 𝗂𝗇𝗃ℓ𝑡1⟂𝗂𝗇𝗃𝑟𝑡2,𝗂𝗇𝗃𝑟𝑡1⟂𝗂𝗇𝗃ℓ𝑡2,𝑡1⟂𝑡2𝐶[𝑡1]⟂𝐶[𝑡2], where the contexts are 𝐶::=[−]∣𝗂𝗇𝗃ℓ𝐶∣𝗂𝗇𝗃𝑟𝐶∣(𝐶,𝑡)∣(𝑡,𝐶)∣𝖿𝗈𝗅𝖽𝐶∣𝗅𝖾𝗍𝑝=𝑡𝗂𝗇𝐶.
Orthogonality is a syntactic separation: two orthogonal terms differ at some position by a choice of injection, so no value matches both. Requiring it on the right-hand sides of Clauses is what (168.1) violates, and it is the condition that makes inversion well typed.
A substitution𝜎 maps variables to terms; 𝜎(𝑡) is the capture-avoiding replacement. Evaluation contexts are 𝐸::=[−]∣𝗂𝗇𝗃ℓ𝐸∣𝗂𝗇𝗃𝑟𝐸∣𝜔𝐸∣𝗅𝖾𝗍𝑝=𝐸𝗂𝗇𝑡∣(𝐸,𝑣)∣(𝑣,𝐸)∣𝖿𝗈𝗅𝖽𝐸, and ⟶ is generated by 𝖿𝗂𝗑𝜑.𝜔⟶𝜔[𝖿𝗂𝗑𝜑.𝜔/𝜑],(𝜆𝜑.𝜔1)𝜔2⟶𝜔1[𝜔2/𝜑],𝜎(𝑣𝑖)=𝑣′{𝑣1↔𝑒1∣⋯∣𝑣𝑛↔𝑒𝑛}𝑣′⟶𝜎(𝑒𝑖),𝜎(𝑝)=𝑣𝗅𝖾𝗍𝑝=𝑣𝗂𝗇𝑡⟶𝜎(𝑡),𝑡1⟶𝑡2𝐸⟨𝑡1⟩⟶𝐸⟨𝑡2⟩,𝜔⟶𝜔′𝜔𝑡⟶𝜔′𝑡. Write ⟶∗ for the reflexive-transitive closure.
Proof of Lemma 168.5 — Preservation and determinism
Proof.Preservation. By induction on the derivation of 𝑡⟶𝑡′. The two iso rules replace an iso variable by an iso of the same type, which is typed by IFix and ILam respectively. For the clause rule, Clauses gives Ψ;Δ𝑖⊢𝑣𝑖:𝐴 and Ψ;Δ𝑖⊢𝑒𝑖:𝐵 with the same Δ𝑖; a matching substitution 𝜎 assigns to each variable of Δ𝑖 a value of its type, so 𝜎(𝑒𝑖) has type 𝐵. For 𝗅𝖾𝗍, Let makes the types of the pattern variables the components of the tuple. The two context rules are the induction hypothesis.
Determinism. Each term has at most one decomposition 𝐸⟨𝑡0⟩ with 𝑡0 a redex, since the grammar of 𝐸 fixes which subterm is evaluated first and values are not redexes. At a clause application, at most one 𝑣𝑖 matches 𝑣′: two matching clauses would give 𝑣𝑖⟂𝑣𝑗 with a common instance, and by definition 168.3 orthogonal terms differ by a choice of injection at some position, so no value instantiates both. ◻
Progress fails, and deliberately. The iso {𝗂𝗇𝗃ℓ𝑥↔𝗂𝗇𝗃ℓ𝑥} applied to 𝗂𝗇𝗃𝑟𝑣 is stuck: no clause matches. The language denotes partial injections, and an exhaustiveness requirement would be a separate condition.
An iso {𝑣𝑖↔𝑒𝑖}𝑖 of type 𝐴↔𝐵 is exhaustive when every closed value of type 𝐴 matches some 𝑣𝑖, and co-exhaustive when every closed value of type 𝐵 matches some 𝑒𝑖.
Proof of Proposition 168.7 — Progress for exhaustive isos
Proof. By induction on the structure of 𝜔 and, inside a clause set, on the value 𝑣. For a clause set, exhaustiveness gives an 𝑖 and a 𝜎 with 𝜎(𝑣𝑖)=𝑣, so the clause rule fires and produces 𝜎(𝑒𝑖); by lemma 168.5 it has type 𝐵, and every 𝗅𝖾𝗍 and every iso application inside 𝑒𝑖 is handled by the induction hypothesis for the smaller isos occurring in it. For 𝜆𝜑.𝜔 and 𝜔1𝜔2 the two iso rules of definition 168.4 reduce to a smaller iso. With 𝖿𝗂𝗑 excluded, the induction is well founded. ◻
For iso types, (𝐴↔𝐵)−1:=𝐵↔𝐴 and (𝑇1→𝑇2)−1:=𝑇−11→𝑇−12. For isos, 𝜑−1:=𝜑,(𝖿𝗂𝗑𝜑.𝜔)−1:=𝖿𝗂𝗑𝜑.𝜔−1,(𝜔1𝜔2)−1:=𝜔−11𝜔−12,(𝜆𝜑.𝜔)−1:=𝜆𝜑.𝜔−1, and on a clause set, clause by clause, by (𝑣↔𝗅𝖾𝗍𝑝1=𝜔1𝑝′1𝗂𝗇⋯𝗅𝖾𝗍𝑝𝑛=𝜔𝑛𝑝′𝑛𝗂𝗇𝑣′)−1:=(𝑣′↔𝗅𝖾𝗍𝑝′𝑛=𝜔−1𝑛𝑝𝑛𝗂𝗇⋯𝗅𝖾𝗍𝑝′1=𝜔−11𝑝1𝗂𝗇𝑣).
The clause case reverses the order of the 𝗅𝖾𝗍 bindings and exchanges each pattern with the pattern it was computed from. That is the whole of inversion: no search and no new program.
Proof of Proposition 168.9 — Inversion is an involution
Proof. By induction on 𝜔. The four non-clause cases are immediate from definition 168.8. For a clause set, the inner definition reverses the order of the 𝗅𝖾𝗍 bindings and swaps the two sides; applying it twice reverses the order twice and swaps twice, and each 𝜔𝑘 is replaced by (𝜔−1𝑘)−1, which is 𝜔𝑘 by the induction hypothesis. ◻
Proof. By induction on the typing derivation. The rules IVar, IFix, ILam and IApp each produce a derivation of the same shape with every iso type inverted, because definition 168.8 inverts 𝑇 structurally.
For Clauses, the premises are Ψ;Δ𝑖⊢𝑣𝑖:𝐴, Ψ;Δ𝑖⊢𝑒𝑖:𝐵, and the two orthogonality conditions. The inverted clause set has left-hand sides the 𝑣′𝑖 appearing as the bodies of the 𝑒𝑖 and right-hand sides built from the 𝑣𝑖. Its two orthogonality conditions are the two of the original exchanged, and the linear contexts are unchanged because reversing a chain of 𝗅𝖾𝗍 bindings permutes the same bindings. The type of each 𝜔𝑘 occurring in a body is inverted by the induction hypothesis, and the direction of each 𝗅𝖾𝗍 is exchanged accordingly, so the inverted clause set is typed at 𝐵↔𝐴 by Clauses. ◻
Proof of Lemma 168.11 — Inversion commutes with evaluation
Proof. There are two iso reductions. For 𝖿𝗂𝗑𝜑.𝜔⟶𝜔[𝖿𝗂𝗑𝜑.𝜔/𝜑], apply definition 168.8 to both sides: the iso (𝖿𝗂𝗑𝜑.𝜔)−1, which is 𝖿𝗂𝗑𝜑.𝜔−1, reduces to 𝜔−1[𝖿𝗂𝗑𝜑.𝜔−1/𝜑], and that is (𝜔[𝖿𝗂𝗑𝜑.𝜔/𝜑])−1 because inversion commutes with substitution of an iso for an iso variable, which is an induction on 𝜔 using 𝜑−1=𝜑. The same two steps apply to (𝜆𝜑.𝜔1)𝜔2⟶𝜔1[𝜔2/𝜑]. ◻
Proof of Theorem 168.13 — The two directions agree
Proof.Proof idea. A forward run of a clause is a chain of 𝗅𝖾𝗍 bindings executed left to right, each applying some 𝜔𝑘; the inverted clause is the same chain read right to left with each 𝜔𝑘 inverted, so a backward run replays the bindings in reverse. The induction is on the length of the forward run, with the clause case carried by the orthogonality of the right-hand sides.
Claim 1. Induct on the length of 𝜔𝑣⟶∗𝑤. If the first step is an iso reduction, lemma 168.11 gives the corresponding step for 𝜔−1 and the induction hypothesis applies. Otherwise the first step is the clause rule: some 𝜎 has 𝜎(𝑣𝑖)=𝑣, and the run continues from 𝜎(𝑒𝑖). Write 𝑒𝑖 as the chain 𝗅𝖾𝗍𝑝1=𝜔1𝑝′1𝗂𝗇⋯𝗂𝗇𝑣′𝑖 of definition 168.8. Each binding fires in turn, producing an extended substitution; let 𝜎𝑘 be the substitution after the 𝑘th binding, so that 𝑤=𝜎𝑛(𝑣′𝑖).
Now run 𝜔−1 on 𝑤. By orthogonality of the right-hand sides, at most one inverted clause matches 𝑤, and 𝑣′𝑖 does, with the substitution 𝜎𝑛 restricted to the variables of 𝑣′𝑖. The inverted body binds 𝑝′𝑛=𝜔−1𝑛𝑝𝑛 first; by the induction hypothesis applied to the strictly shorter run of 𝜔𝑛, that binding recovers the value that 𝑝′𝑛 had in the forward run. Repeating for 𝑘=𝑛−1,…,1 recovers 𝜎, and the body of the inverted clause is 𝑣𝑖, so the result is 𝜎(𝑣𝑖)=𝑣.
Claim 2. If 𝜔𝑣 does not reach a value, then 𝜔−1(𝜔𝑣) does not either, by determinism (lemma 168.5), and the hypothesis is vacuous. Otherwise 𝜔𝑣⟶∗𝑤 and Claim 1 gives 𝜔−1𝑤⟶∗𝑣; determinism makes that the only run, so 𝑣′=𝑣. ◻
Write [𝐴]:=𝜇𝑋.𝟏⊕(𝐴⊗𝑋), with 𝗇𝗂𝗅:=𝖿𝗈𝗅𝖽𝗂𝗇𝗃ℓ() and ℎ::𝑡:=𝖿𝗈𝗅𝖽𝗂𝗇𝗃𝑟(ℎ,𝑡). Write 𝟐:=𝟏⊕𝟏 with 𝗍𝗍:=𝗂𝗇𝗃ℓ() and 𝖿𝖿:=𝗂𝗇𝗃𝑟(). Define 𝖼𝗇𝗈𝗍:={(𝗍𝗍,𝗍𝗍)↔(𝗍𝗍,𝖿𝖿)∣(𝗍𝗍,𝖿𝖿)↔(𝗍𝗍,𝗍𝗍)∣(𝖿𝖿,𝑦)↔(𝖿𝖿,𝑦)}:𝟐⊗𝟐↔𝟐⊗𝟐,𝗆𝖺𝗉:=𝜆𝜓.𝖿𝗂𝗑𝜑.{𝗇𝗂𝗅↔𝗇𝗂𝗅∣ℎ::𝑡↔𝗅𝖾𝗍ℎ′=𝜓ℎ𝗂𝗇𝗅𝖾𝗍𝑡′=𝜑𝑡𝗂𝗇ℎ′::𝑡′} of type (𝐴↔𝐵)→([𝐴]↔[𝐵]).
Proof of Proposition 168.15 — The example is well typed and self-inverse in one factor
Proof.Orthogonality. Left-hand sides: (𝗍𝗍,𝗍𝗍) and (𝗍𝗍,𝖿𝖿) differ in the second component by the choice of injection, so they are orthogonal by definition 168.3 with the context (𝗍𝗍,[−]); each is orthogonal to (𝖿𝖿,𝑦) by the first component with the context ([−],−). Right-hand sides: the same three pairs in a different order, so the same argument applies.
Self-inversion. Each clause of 𝖼𝗇𝗈𝗍 has a body that is a value with no 𝗅𝖾𝗍, so definition 168.8 simply exchanges the two sides; the resulting clause set is the original one with the first two clauses exchanged.
Map. By definition 168.8, (𝜆𝜓.𝖿𝗂𝗑𝜑.𝜔)−1=𝜆𝜓.𝖿𝗂𝗑𝜑.𝜔−1, and 𝜔−1 is {𝗇𝗂𝗅↔𝗇𝗂𝗅∣ℎ′::𝑡′↔𝗅𝖾𝗍𝑡=𝜑−1𝑡′𝗂𝗇𝗅𝖾𝗍ℎ=𝜓−1ℎ′𝗂𝗇ℎ::𝑡}, which is the body of 𝗆𝖺𝗉 with 𝜓 replaced by 𝜓−1, up to the order of the two independent bindings. Since 𝜑−1=𝜑, the recursion variable is unchanged. ◻
Let ℓ:=(𝗍𝗍,𝗍𝗍)::(𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅 and let 𝑀:=𝗆𝖺𝗉𝖼𝗇𝗈𝗍. Forward: 𝑀ℓ⟶{…}ℓ(unfolding𝖿𝗂𝗑and𝜆)⟶𝗅𝖾𝗍ℎ′=𝖼𝗇𝗈𝗍(𝗍𝗍,𝗍𝗍)𝗂𝗇𝗅𝖾𝗍𝑡′=𝑀((𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅)𝗂𝗇ℎ′::𝑡′(clause2)⟶∗𝗅𝖾𝗍𝑡′=𝑀((𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅)𝗂𝗇(𝗍𝗍,𝖿𝖿)::𝑡′(clause1of𝖼𝗇𝗈𝗍)⟶∗(𝗍𝗍,𝖿𝖿)::(𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅(recursion,thenclause1). Write ℓ′ for the result. Backward, that is forward on 𝑀−1=𝗆𝖺𝗉𝖼𝗇𝗈𝗍−1=𝗆𝖺𝗉𝖼𝗇𝗈𝗍 by proposition 168.15: 𝑀−1ℓ′⟶𝗅𝖾𝗍𝑡=𝑀−1((𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅)𝗂𝗇𝗅𝖾𝗍ℎ=𝖼𝗇𝗈𝗍−1(𝗍𝗍,𝖿𝖿)𝗂𝗇ℎ::𝑡⟶∗(𝗍𝗍,𝗍𝗍)::(𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅=ℓ, the two bindings firing in the reversed order prescribed by definition 168.8. This is theorem 168.13(1) at this instance.
For a closed type 𝐴 define the iso 𝖣𝗎𝗉𝐴:𝐴↔𝐴⊗𝐴 by structural recursion on 𝐴: on 𝟏 it is ()↔((),()); on 𝐴1⊕𝐴2 it sends 𝗂𝗇𝗃𝑘𝑥 to (𝗂𝗇𝗃𝑘𝑥1,𝗂𝗇𝗃𝑘𝑥2) using 𝖣𝗎𝗉𝐴𝑘 on 𝑥; on 𝐴1⊗𝐴2 it is the two duplications followed by the evident exchange; and on 𝜇𝑋.𝐴 it is 𝖿𝗂𝗑 applied to the unfolding. For a closed value 𝑣:𝐵 define 𝖾𝗋𝖺𝗌𝖾𝑣:𝐴⊗𝐵↔𝐴 by the single clause (𝑥,𝑣)↔𝑥.
𝖣𝗎𝗉𝐴 is not a duplication of an arbitrary value into two independent copies; it is an iso, so its inverse is defined only on pairs whose two components agree, and applying 𝖣𝗎𝗉−1𝐴 to a pair of different values is stuck. That is exactly what makes the following pattern available.
Let ⊢𝜔𝜔:𝐴↔𝐵 and let 𝐴 be closed. Set 𝖻𝖾𝗇𝗇𝖾𝗍𝗍(𝜔):={𝑥↔𝗅𝖾𝗍(𝑥1,𝑥2)=𝖣𝗎𝗉𝐴𝑥𝗂𝗇𝗅𝖾𝗍𝑦=𝜔𝑥1𝗂𝗇(𝑦,𝑥2)}:𝐴↔𝐵⊗𝐴. Then for every closed value 𝑣:𝐴 with 𝜔𝑣⟶∗𝑤, 𝖻𝖾𝗇𝗇𝖾𝗍𝗍(𝜔)𝑣⟶∗(𝑤,𝑣),𝖻𝖾𝗇𝗇𝖾𝗍𝗍(𝜔)−1(𝑤,𝑣)⟶∗𝑣.
Proof. The forward run fires the single clause, then the two bindings in order: 𝖣𝗎𝗉𝐴𝑣⟶∗(𝑣,𝑣) by induction on 𝐴 using definition 168.17, and 𝜔𝑣⟶∗𝑤 by hypothesis, so the body evaluates to (𝑤,𝑣). For the backward run, definition 168.8 gives 𝖻𝖾𝗇𝗇𝖾𝗍𝗍(𝜔)−1={(𝑦,𝑥2)↔𝗅𝖾𝗍𝑥1=𝜔−1𝑦𝗂𝗇𝗅𝖾𝗍𝑥=𝖣𝗎𝗉−1𝐴(𝑥1,𝑥2)𝗂𝗇𝑥}, and on (𝑤,𝑣) the first binding gives 𝑥1=𝑣 by theorem 168.13(1), so the second is 𝖣𝗎𝗉−1𝐴(𝑣,𝑣), which is 𝑣. The second binding is where the ancilla is discharged: it is defined only because the two components agree, and that is what uncomputation means here. ◻
★★☆Definition 168.2 imposes orthogonality on both sides of a clause set.
Exhibit a clause set satisfying the left condition but not the right, and show that lemma 168.10 fails for it by displaying the ill-formed inverted clause set.
Exhibit a clause set satisfying the right condition but not the left, and show that lemma 168.5 fails for it, by exhibiting a value with two reducts.
Show that the term (168.1) of the opening is rejected by Clauses, naming which condition it violates.
Chapter 159 supplies a symmetric monoidal category: objects, a tensor, a unit, and a symmetry, with the coherence equations. It supplies no feedback operation, and the recursion of definition 168.14 needs one. This section constructs it for the category that will interpret the language and proves the laws that a feedback operation must satisfy.
The category 𝐏𝐈𝐧𝐣 has sets as objects and partial injections as morphisms: a morphism 𝑓:𝑋→𝑌 is a partial function whose restriction to dom(𝑓) is injective. Composition is composition of partial functions, the identity is the total identity. Set 𝑋⊗𝑌:=𝑋⊔𝑌, the disjoint union, and 𝐼:=∅; for 𝑓:𝑋→𝑋′ and 𝑔:𝑌→𝑌′ let 𝑓⊗𝑔 act as 𝑓 on the left summand and as 𝑔 on the right, and let 𝑐𝑋,𝑌:𝑋⊔𝑌→𝑌⊔𝑋 exchange the two summands.
Proof of Lemma 168.20 — PInj is symmetric monoidal
Proof.𝑓⊗𝑔 is a partial injection because the two summands are disjoint and each of 𝑓,𝑔 is one; functoriality of ⊗ is the corresponding fact for disjoint unions of partial functions. The associator, unitors and symmetry are total bijections, hence partial injections, and every coherence equation is an equation between bijections of finite disjoint unions, checked by following an element through both sides. ◻
Let 𝑓:𝑋⊔𝑈→𝑌⊔𝑈 in 𝐏𝐈𝐧𝐣. For 𝑥∈𝑋 define a finite or infinite sequence by 𝑧0:=𝑥 and, as long as 𝑓(𝑧𝑖) is defined and lies in 𝑈, 𝑧𝑖+1:=𝑓(𝑧𝑖). Set Tr𝑈(𝑓)(𝑥):={𝑓(𝑧𝑛)ifthesequencestopsat𝑧𝑛with𝑓(𝑧𝑛)∈𝑌,undefinedotherwise.
Proof of Lemma 168.23 — The particle trace is a partial injection
Proof. Suppose Tr𝑈(𝑓)(𝑥)=Tr𝑈(𝑓)(𝑥′)=𝑦, with traversal sequences 𝑧0,…,𝑧𝑛 and 𝑧′0,…,𝑧′𝑚. Then 𝑓(𝑧𝑛)=𝑦=𝑓(𝑧′𝑚), so 𝑧𝑛=𝑧′𝑚 by injectivity of 𝑓. Suppose 𝑛,𝑚≥1. Then 𝑓(𝑧𝑛−1)=𝑧𝑛=𝑧′𝑚=𝑓(𝑧′𝑚−1), so 𝑧𝑛−1=𝑧′𝑚−1 by injectivity again; iterating, the two sequences agree from the end backwards. They must run out together: if say 𝑛>𝑚 then after 𝑚 steps backwards we reach 𝑧𝑛−𝑚=𝑧′0=𝑥′∈𝑋, contradicting 𝑧𝑖∈𝑈 for 𝑖≥1. Hence 𝑛=𝑚 and 𝑥=𝑧0=𝑧′0=𝑥′. ◻
Proof of Theorem 168.24 — The particle trace satisfies the trace laws
Proof. Throughout, “the run of 𝑓 from 𝑥” means the sequence of construction 168.22. Each law is proved by comparing two runs element by element.
Tight, first equation. Let 𝑔:𝑋′→𝑋. The run of 𝑓∘(𝑔⊗id𝑈) from 𝑥′∈𝑋′ begins by applying 𝑔 and then proceeds exactly as the run of 𝑓 from 𝑔(𝑥′), since on the 𝑈 summand 𝑔⊗id𝑈 is the identity. Both sides are therefore defined at 𝑥′ precisely when 𝑔 is defined at 𝑥′ and Tr𝑈(𝑓) at 𝑔(𝑥′), with the same value.
Tight, second equation. Let ℎ:𝑌→𝑌′. The run of (ℎ⊗id𝑈)∘𝑓 from 𝑥 visits the same elements of 𝑈 as the run of 𝑓, because ℎ⊗id𝑈 is the identity on 𝑈; it exits when 𝑓 exits, and then applies ℎ.
Slide. Let 𝑔:𝑈→𝑈′. Write 𝑓:𝑋⊔𝑈→𝑌⊔𝑈′. The run of (id𝑌⊗𝑔)∘𝑓 from 𝑥 has the form 𝑥𝑓⟼𝑢′1𝑔⟼𝑢1𝑓⟼𝑢′2𝑔⟼𝑢2⋯, and the run of 𝑓∘(id𝑋⊗𝑔) from 𝑥 has the form 𝑥𝑓⟼𝑢′1𝑔⟼𝑢1𝑓⟼𝑢′2⋯, the two sequences differing only in whether the last recorded state is taken before or after the application of 𝑔. Both exit at the same application of 𝑓 into 𝑌, and with the same value; and one is defined exactly when the other is.
Vanish, first equation.𝑈=∅, so no run has a step: the sequence stops at 𝑧0=𝑥 and the value is 𝑓(𝑥).
Vanish, second equation. Let 𝑔:𝑋⊔𝑈⊔𝑉→𝑌⊔𝑈⊔𝑉. The run of 𝑔 from 𝑥 visits a sequence of elements of 𝑈⊔𝑉. The inner trace Tr𝑉(𝑔) collapses each maximal stretch of consecutive elements of 𝑉 into a single step, and the outer trace then iterates over the elements of 𝑈. The composite therefore visits exactly the same elements of 𝑈 in the same order and exits at the same application, so the two sides agree; and the composite is defined at 𝑥 exactly when the run of 𝑔 leaves 𝑈⊔𝑉, since an infinite run either has infinitely many 𝑈-states, when the outer trace diverges, or a final infinite 𝑉-stretch, when the inner trace diverges.
Super. Write the right-hand side as Tr𝑈(𝑘) with 𝑘:=(id⊗𝑐−1)∘(𝑓⊗𝑔)∘(id⊗𝑐), a morphism (𝑋⊔𝑋′)⊔𝑈→(𝑌⊔𝑌′)⊔𝑈. On the summand 𝑋⊔𝑈 the two symmetries cancel and 𝑘 acts as 𝑓; on 𝑋′ it acts as 𝑔 and lands in 𝑌′ at once. Hence the run of 𝑘 from an element of 𝑋 is the run of 𝑓, giving Tr𝑈(𝑓), and the run from an element of 𝑋′ has length zero, giving 𝑔. That is Tr𝑈(𝑓)⊗𝑔.
Yank. Here 𝑓=𝑐𝑈,𝑈:𝑈⊔𝑈→𝑈⊔𝑈 exchanges the two summands, with 𝑋=𝑌=𝑈 the first summand. For 𝑥 in the first summand, 𝑐𝑈,𝑈(𝑥) is the copy of 𝑥 in the second summand, which is the traced summand, so 𝑧1 is that copy; applying 𝑐𝑈,𝑈 again returns the copy in the first summand, which is in 𝑌. The run stops after one step with value 𝑥. Hence Tr𝑈(𝑐𝑈,𝑈)=id𝑈. ◻
Theorem 168.24 is a theorem about 𝐏𝐈𝐧𝐣, not about symmetric monoidal categories. The category of finite sets and total bijections is symmetric monoidal under disjoint union and admits no trace at 𝑈≠∅: taking 𝑋=𝑌=∅ and 𝑓=id𝑈, the run from no element is vacuous, but Vanish and Yank force Tr𝑈(id𝑈):∅→∅, whereas Tr𝑈(𝑐𝑈,𝑈)=id𝑈 requires the trace to see a nonempty run; the two are consistent only because 𝐏𝐈𝐧𝐣 admits the empty partial map, which the category of bijections does not. Partiality is therefore not an accident of construction 168.22: it is what makes feedback available.
Interpret types by [[𝟏]]:={∗},[[𝐴⊕𝐵]]:=[[𝐴]]⊔[[𝐵]],[[𝐴⊗𝐵]]:=[[𝐴]]×[[𝐵]], and [[𝜇𝑋.𝐴]] by the least fixed point of the induced operator on sets, which exists because the grammar of definition 168.1 makes the operator monotone. Interpret a closed iso ⊢𝜔𝜔:𝐴↔𝐵 by a partial injection [[𝜔]]:[[𝐴]]→[[𝐵]]: a clause set is the union of the partial injections determined by its clauses, a 𝗅𝖾𝗍 chain is the composite of the interpretations of its bindings, and 𝖿𝗂𝗑 is interpreted by the trace of construction 168.22 applied to the interpretation of the body with its recursive occurrence routed through the traced summand.
Proof of Lemma 168.27 — Clause sets denote partial injections
Proof. Each clause determines a partial injection: matching 𝑣𝑖 against a value determines the substitution uniquely, and building 𝑒𝑖 from it is a composite of injections by induction on 𝑒𝑖. For the union, two clauses have disjoint domains because 𝑣𝑖⟂𝑣𝑗 and orthogonal patterns have no common instance, by definition 168.3; and they have disjoint images because 𝑒𝑖⟂𝑒𝑗, by the same argument applied to the right-hand sides. A union of partial injections with pairwise disjoint domains and pairwise disjoint images is a partial injection. ◻
Proof of Theorem 168.28 — Inversion denotes inversion
Proof. By induction on 𝜔.
Clause set. By lemma 168.27 the denotation is a disjoint union of clause denotations. Definition 168.8 exchanges the two sides of each clause and reverses the chain of 𝗅𝖾𝗍 bindings, so the denotation of the inverted clause is the composite of the converses in reverse order, which is the converse of the composite; and the union of the converses is the converse of the union, the domains and images being disjoint.
Abstraction and application.Definition 168.8 inverts both components, and the induction hypothesis applies to each.
Fixed point. Inversion sends 𝖿𝗂𝗑𝜑.𝜔 to 𝖿𝗂𝗑𝜑.𝜔−1, so it suffices that the trace commutes with converse: for 𝑓:𝑋⊔𝑈→𝑌⊔𝑈, Tr𝑈(𝑓−1)=Tr𝑈(𝑓)−1. That is the calculation in lemma 168.23: the run of 𝑓−1 from 𝑦 is the reversal of the run of 𝑓 that ends at 𝑦, which the proof there constructs by stepping backwards through the injectivity of 𝑓. ◻
Proof. By induction on the length of the run, using lemma 168.5 for the typing at each step. The two iso reductions do not change the denotation: 𝖿𝗂𝗑 unfolds to a term whose denotation is the same trace by the fixed-point property of construction 168.22, and 𝛽 for iso abstraction is substitution, which the interpretation of definition 168.26 respects. The clause rule selects the unique matching clause, whose denotation is by lemma 168.27 the restriction of [[𝜔]] to the values matching 𝑣𝑖. The 𝗅𝖾𝗍 rule is composition of partial injections. ◻
Fix an interpretation of the language of definition 168.1–definition 168.4 in a join inverse rig category C that is enriched over directed-complete partial orders and whose objects 0 and 1 are distinct. For every closed term ⊢𝑡:𝐴, the term 𝑡 reduces to a value if and only if [[⊢𝑡:𝐴]]≠0[[𝐴]].
The statement imported is the adequacy theorem of Chardonnet, Lemonnier and Valiron, Semantics for a Turing-complete Reversible Programming Language with Inductive Types, Theorem 41, at the hypotheses displayed above; their proof passes through a finitary sublanguage with bounded fixed points, proves the statement there by strong normalization, and transfers it. The same paper proves, as its Theorem 43, that every computable partial injection between the interpretations of two closed types is the denotation of some iso. What the import supplies here is the converse direction of theorem 168.29; the forward direction, the inversion theorem theorem 168.28, the trace and its laws theorem 168.24, and the operational results of lemma 168.5–proposition 168.18 are proved locally.
Definition 168.26 is not a join inverse rig category on the nose: 𝐏𝐈𝐧𝐣 is one, but the interpretation given there handles only the fragment without nested 𝖿𝗂𝗑 under an iso abstraction. The imported theorem is stated at the source’s own signature and is not applied to definition 168.26 beyond that fragment.
Chen and Sabry extend a first-order reversible language of type isomorphisms with a dual to sums, a negative type −𝐴, and a dual to products, a fractional type 1/𝐴. Operationally, a negative type is a computational effect that reverses the direction of execution, so that a value flowing into −𝐴 emerges as a value flowing out of 𝐴; a fractional type is an effect that discards a designated value or raises an exception. Each extension is given its own abstract machine, and each is proved to form a compact closed category; the two machines are combined by the standard pairing of backtracking with exceptions.
The original publication stated, as its Theorem 25, that the category constructed from the combined language is an inverse category. That statement is withdrawn. The published erratum records that the proof omits the uniqueness of inverses, and gives a counterexample: for ℎ:=𝜀+⊕id there are two combinators ℎ1=id⊕𝜂+ and ℎ2=(id⊕𝜂+)∘𝛼, with 𝛼 the associativity-and-exchange combinator 𝐴+[𝐵+𝐶]=𝐶+[𝐵+𝐴], both of which satisfy the inverse conditions for ℎ and are not equal. Uniqueness of inverses therefore fails, and the category is not an inverse category.
Nothing in section 168.1–section 168.5 uses that claim. The inversion of definition 168.8 is a syntactic operation with proposition 168.9 proved directly, and theorem 168.28 identifies its denotation with the converse in 𝐏𝐈𝐧𝐣, where inverses are unique because a partial injection has at most one converse. Compact closure is a different structure from a trace: a compact closed category has a trace, by Tr𝑈(𝑓)=(id⊗𝜀)∘(𝑓⊗id)∘(id⊗𝜂), but theorem 168.24 constructs a trace on 𝐏𝐈𝐧𝐣 without any dual objects, and no adequacy theorem for the language of definition 168.1 follows from compact closure alone.
Reversible classical computation is not quantum computation, and the gap is exactly two features.
Linear structure. A quantum program is a linear map on a complex Hilbert space, and superposition means that a state is a linear combination of basis states. Definition 168.19 has no addition: a morphism of 𝐏𝐈𝐧𝐣 sends a point to at most one point, and the coproduct ⊔ is a disjoint union of possibilities, not a sum of amplitudes. Every theorem of section 168.4–section 168.5 is a statement about points.
Unitarity and measurement. A quantum evolution is unitary, hence total and invertible; a partial injection is invertible only on its domain, and proposition 168.7 needs exhaustiveness to make an iso total. In the other direction, measurement is not reversible at all, so a quantum language containing it is not a reversible language.
The only bridge between the two used later is the one proved here: the category of definition 168.19 with the trace of theorem 168.24, and the syntactic inversion of definition 168.8 with theorem 168.13. A quantum chapter that needs more must construct it.
★★★Theorem 168.24 proved the five laws by comparing runs.
Write the proof of Vanish, second equation, as an explicit bijection between the run of 𝑔 and the pair of runs of the iterated trace, and check the two divergence cases separately.
Show that Tr𝑈 is not injective, by exhibiting two distinct 𝑓,𝑓′ with the same trace, and say which law would fail if it were required to be.
Prove that the trace of construction 168.22 satisfies Tr𝑈(𝑓−1)=Tr𝑈(𝑓)−1, filling in the backward-stepping argument sketched in theorem 168.28.
★★★ A reversible Turing machine is a tuple (𝑄,Σ,𝛿,𝑏,𝑞𝑠,𝑞𝑓) whose transition relation is a partial injection on configurations (𝑞,(𝑙,𝑠,𝑟)) consisting of a state and a tape split at the head.
Give a closed type 𝐶 of definition 168.1 whose values are the configurations, using 𝜇 for the two tape halves.
Write an iso 𝗌𝗍𝖾𝗉:𝐶↔𝐶 from a finite 𝛿, and check both orthogonality conditions of Clauses against the two conditions that make 𝛿 reversible.
Write the iterating iso using 𝖿𝗂𝗑, and say which of proposition 168.7 and theorem 168.30 applies to it and why the other does not.
Use proposition 168.18 to turn a machine computing 𝑓 into an iso of type 𝐶↔𝐶⊗𝐶, and state what the second component holds.
★★★Practical project.reversible-inverter Implement, in Kappa, an evaluator and a syntactic inverter for the language of definition 168.1–definition 168.4, and run programs in both directions.
Calculus to implement. Types 𝟏, ⊕, ⊗ and 𝜇; terms and isos of definition 168.1; the orthogonality check of definition 168.3; the typing rules of definition 168.2, including the linearity of Δ; the evaluation relation of definition 168.4 with a step bound; and the inversion of definition 168.8. Represent terms with named variables and implement capture-avoiding substitution; matching a value against a pattern must produce the unique substitution or fail.
Invariant. The type checker must reject any clause set violating either orthogonality condition, and must reject any term using a linear variable other than exactly once. The evaluator must fire at most one clause at each application, and must report the clause index; the recorded sequence of clause indices for a run is its trace. For every accepted iso 𝜔 the program must check (𝜔−1)−1=𝜔 syntactically, which is proposition 168.9.
Concrete result. For a named iso and input value: the forward run with its clause-index trace and result; the inverted iso printed in full; and the backward run with its trace and result.
Acceptance test. On 𝖼𝗇𝗈𝗍 and 𝗆𝖺𝗉 of definition 168.14 with the list ℓ of example 168.16, the forward result must be (𝗍𝗍,𝖿𝖿)::(𝖿𝖿,𝗍𝗍)::𝗇𝗂𝗅 and the backward result must be ℓ, with the backward clause-index trace the reverse of the forward one. On 𝖻𝖾𝗇𝗇𝖾𝗍𝗍(𝖼𝗇𝗈𝗍) of proposition 168.18 with input (𝗍𝗍,𝗍𝗍), the forward result must be ((𝗍𝗍,𝖿𝖿),(𝗍𝗍,𝗍𝗍)) and the backward result (𝗍𝗍,𝗍𝗍). The following must be rejected by the checker: the clause set {𝗂𝗇𝗃ℓ𝑦↔𝑦∣𝗂𝗇𝗃𝑟𝑧↔𝑧} of (168.1), for violating right-hand orthogonality; and a clause set repeating a linear variable. The following must be reported as stuck: 𝖣𝗎𝗉−1𝟐(𝗍𝗍,𝖿𝖿), and {𝗂𝗇𝗃ℓ𝑥↔𝗂𝗇𝗃ℓ𝑥} applied to 𝗂𝗇𝗃𝑟(). Produce three mutations that still run — drop the right-hand orthogonality check, invert a clause without reversing the 𝗅𝖾𝗍 order, and allow two clauses to match — and confirm that each makes a named backward run disagree with its forward run. State explicitly that the program illustrates theorem 168.13 on finitely many inputs and proves neither it nor theorem 168.30.