Lectures onType Theory
Chapter 168
Chapter 168Optional

Reversible Classical Computation

Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.

Three requirements are easy to confuse.

The function n2n 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 λx.case x of injyyinjrzz : AAA uses its argument exactly once and duplicates nothing. It is not injective: inja and injra both produce a. 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.

A language of partial isomorphisms

Definition 168.1 — Types and terms

Fix the grammar A,B::=1ABABμX.AXT::=ABT1T2v::=()xinjvinjrv(v1,v2)foldvt::=vinjtinjrt(t1,t2)foldtωtlet p=t1 in t2ω::={v1e1vnen}φλφ.ωω1ω2fixφ.ω where p ranges over tuples of distinct variables and e over terms. Terms are typed by Ψ;Δt:A with Δ a linear context of term variables and Ψ a context of iso variables; isos are typed by Ψωω:T.

Definition 168.2 — Typing

Ψ;():1
Unit
Ψ;x:Ax:A
Var
Ψ;Δt:A
Ψ;Δinjt:AB
InL
Ψ;Δt:B
Ψ;Δinjrt:AB
InR
Ψ;Δ1t1:AΨ;Δ2t2:B
Ψ;Δ1,Δ2(t1,t2):AB
Pair
Ψ;Δt:A[μX.A/X]
Ψ;Δfoldt:μX.A
Fold
Ψωω:ABΨ;Δt:A
Ψ;Δωt:B
App
Ψ;Δ1t1:A1AnΨ;Δ2,x1:A1,,xn:Ant2:B
Ψ;Δ1,Δ2let (x1,,xn)=t1 in t2:B
Let
Ψ,φ:Tωφ:T
IVar
Ψ,φ:Tωω:T
Ψωfixφ.ω:T
IFix
Ψ,φ:T1ωω:T2
Ψωλφ.ω:T1T2
ILam
Ψωω2:T1T2Ψωω1:T1
Ψωω2ω1:T2
IApp
Ψ;Δivi:AΨ;Δiei:Bvivj (ij)eiej (ij)
Ψω{v1e1vnen}:AB
Clauses

Definition 168.3 — Orthogonality

The relation t1t2 is the least relation closed under injt1injrt2,injrt1injt2,t1t2C[t1]C[t2], where the contexts are C::=[]injCinjrC(C,t)(t,C)foldClet p=t in C.

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.

Definition 168.4 — Forward evaluation

A substitution σ maps variables to terms; σ(t) is the capture-avoiding replacement. Evaluation contexts are E::=[]injEinjrEωElet p=E in t(E,v)(v,E)foldE, and is generated by fixφ.ωω[fixφ.ω/φ],(λφ.ω1)ω2ω1[ω2/φ],σ(vi)=v{v1e1vnen}vσ(ei),σ(p)=vlet p=v in tσ(t),t1t2Et1Et2,ωωωtωt. Write for the reflexive-transitive closure.

Lemma 168.5 — Preservation and determinism

If Ψ;Δt:A and tt then Ψ;Δt:A. Moreover is deterministic.

Proof of Lemma 168.5 — Preservation and determinism

Proof. Preservation. By induction on the derivation of tt. 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 Ψ;Δivi:A and Ψ;Δiei:B with the same Δi; a matching substitution σ assigns to each variable of Δi a value of its type, so σ(ei) has type B. For let, 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 Et0 with t0 a redex, since the grammar of E fixes which subterm is evaluated first and values are not redexes. At a clause application, at most one vi matches v: two matching clauses would give vivj 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 {injxinjx} applied to injrv is stuck: no clause matches. The language denotes partial injections, and an exhaustiveness requirement would be a separate condition.

Convention 168.6 — Exhaustive isos

An iso {viei}i of type AB is exhaustive when every closed value of type A matches some vi, and co-exhaustive when every closed value of type B matches some ei.

Proposition 168.7 — Progress for exhaustive isos

Let ωω:AB be built from exhaustive clause sets only, with no fix, and let v:A be a closed value. Then ωvw for a closed value w:B.

Proof of Proposition 168.7 — Progress for exhaustive isos

Proof. By induction on the structure of ω and, inside a clause set, on the value v. For a clause set, exhaustiveness gives an i and a σ with σ(vi)=v, so the clause rule fires and produces σ(ei); by lemma 168.5 it has type B, and every let and every iso application inside ei 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 fix excluded, the induction is well founded. ◻

Inversion

Definition 168.8 — Syntactic inversion

For iso types, (AB)1:=BA and (T1T2)1:=T11T21. For isos, φ1:=φ,(fixφ.ω)1:=fixφ.ω1,(ω1ω2)1:=ω11ω21,(λφ.ω)1:=λφ.ω1, and on a clause set, clause by clause, by (vlet p1=ω1p1 inlet pn=ωnpn in v)1:=(vlet pn=ωn1pn inlet p1=ω11p1 in v).

The clause case reverses the order of the let bindings and exchanges each pattern with the pattern it was computed from. That is the whole of inversion: no search and no new program.

Proposition 168.9 — Inversion is an involution

(ω1)1=ω for every iso ω.

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 let bindings and swaps the two sides; applying it twice reverses the order twice and swaps twice, and each ωk is replaced by (ωk1)1, which is ωk by the induction hypothesis. ◻

Lemma 168.10 — Inversion is well typed

If φ1:A1B1,,φn:AnBnωω:T then φ1:B1A1,,φn:BnAnωω1:T1.

Proof of Lemma 168.10 — Inversion is well typed

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 T structurally.

For Clauses, the premises are Ψ;Δivi:A, Ψ;Δiei:B, and the two orthogonality conditions. The inverted clause set has left-hand sides the vi appearing as the bodies of the ei and right-hand sides built from the vi. Its two orthogonality conditions are the two of the original exchanged, and the linear contexts are unchanged because reversing a chain of let bindings permutes the same bindings. The type of each ωk occurring in a body is inverted by the induction hypothesis, and the direction of each let is exchanged accordingly, so the inverted clause set is typed at BA by Clauses. ◻

Lemma 168.11 — Inversion commutes with evaluation

If ωω then ω1ω1.

Proof of Lemma 168.11 — Inversion commutes with evaluation

Proof. There are two iso reductions. For fixφ.ωω[fixφ.ω/φ], apply definition 168.8 to both sides: the iso (fixφ.ω)1, which is fixφ.ω1, reduces to ω1[fixφ.ω1/φ], and that is (ω[fixφ.ω/φ])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/φ]. ◻

Definition 168.12 — Backward evaluation

For a closed iso ω define the backward relation on terms by tbtifftt in the language of definition 168.4 with ω replaced by ω1 throughout.

Theorem 168.13 — The two directions agree

Let ωω:AB and let v:A be a closed value.

  1. If ωvw with w a value, then ω1wv.

  2. If ω1(ωv)v with v a value, then v=v.

Proof of Theorem 168.13 — The two directions agree

Proof. Proof idea. A forward run of a clause is a chain of let bindings executed left to right, each applying some ωk; the inverted clause is the same chain read right to left with each ωk 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 ωvw. 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 σ(vi)=v, and the run continues from σ(ei). Write ei as the chain let p1=ω1p1 in  in vi of definition 168.8. Each binding fires in turn, producing an extended substitution; let σk be the substitution after the kth binding, so that w=σn(vi).

Now run ω1 on w. By orthogonality of the right-hand sides, at most one inverted clause matches w, and vi does, with the substitution σn restricted to the variables of vi. The inverted body binds pn=ωn1pn first; by the induction hypothesis applied to the strictly shorter run of ωn, that binding recovers the value that pn had in the forward run. Repeating for k=n1,,1 recovers σ, and the body of the inverted clause is vi, so the result is σ(vi)=v.

Claim 2. If ωv does not reach a value, then ω1(ωv) does not either, by determinism (lemma 168.5), and the hypothesis is vacuous. Otherwise ωvw and Claim 1 gives ω1wv; determinism makes that the only run, so v=v. ◻

One program, inverted and run both ways

Definition 168.14 — Lists and a controlled negation

Write [A]:=μX.1(AX), with nil:=foldinj() and h::t:=foldinjr(h,t). Write 2:=11 with tt:=inj() and ff:=injr(). Define cnot:={(tt,tt)(tt,ff)(tt,ff)(tt,tt)(ff,y)(ff,y)} : 2222, map:=λψ.fixφ.{nilnilh::tlet h=ψh in let t=φt in h::t} of type (AB)([A][B]).

Proposition 168.15 — The example is well typed and self-inverse in one factor

cnot satisfies the two orthogonality conditions of Clauses; cnot1=cnot up to the order of clauses; and (mapψ)1=mapψ1.

Proof of Proposition 168.15 — The example is well typed and self-inverse in one factor

Proof. Orthogonality. Left-hand sides: (tt,tt) and (tt,ff) differ in the second component by the choice of injection, so they are orthogonal by definition 168.3 with the context (tt,[]); each is orthogonal to (ff,y) 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 cnot has a body that is a value with no let, 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, (λψ.fixφ.ω)1=λψ.fixφ.ω1, and ω1 is {nilnilh::tlet t=φ1t in let h=ψ1h in h::t}, which is the body of map with ψ replaced by ψ1, up to the order of the two independent bindings. Since φ1=φ, the recursion variable is unchanged. ◻

Example 168.16 — A run in each direction

Let :=(tt,tt)::(ff,tt)::nil and let M:=mapcnot. Forward: M{}(unfolding fix and λ)let h=cnot(tt,tt) inlet t=M((ff,tt)::nil) in h::t(clause 2)let t=M((ff,tt)::nil) in (tt,ff)::t(clause 1 of cnot)(tt,ff)::(ff,tt)::nil(recursion, then clause 1). Write for the result. Backward, that is forward on M1=mapcnot1=mapcnot by proposition 168.15: M1let t=M1((ff,tt)::nil) in let h=cnot1(tt,ff) in h::t(tt,tt)::(ff,tt)::nil=, the two bindings firing in the reversed order prescribed by definition 168.8. This is theorem 168.13(1) at this instance.

Definition 168.17 — Ancillae and uncomputation

For a closed type A define the iso DupA:AAA by structural recursion on A: on 1 it is ()((),()); on A1A2 it sends injkx to (injkx1,injkx2) using DupAk on x; on A1A2 it is the two duplications followed by the evident exchange; and on μX.A it is fix applied to the unfolding. For a closed value v:B define erasev:ABA by the single clause (x,v)x.

DupA 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 DupA1 to a pair of different values is stuck. That is exactly what makes the following pattern available.

Proposition 168.18 — Uncomputation

Let ωω:AB and let A be closed. Set bennett(ω):={xlet (x1,x2)=DupAx inlet y=ωx1 in (y,x2)} : ABA. Then for every closed value v:A with ωvw, bennett(ω)v(w,v),bennett(ω)1(w,v)v.

Proof of Proposition 168.18 — Uncomputation

Proof. The forward run fires the single clause, then the two bindings in order: DupAv(v,v) by induction on A using definition 168.17, and ωvw by hypothesis, so the body evaluates to (w,v). For the backward run, definition 168.8 gives bennett(ω)1={(y,x2)let x1=ω1y in let x=DupA1(x1,x2) in x}, and on (w,v) the first binding gives x1=v by theorem 168.13(1), so the second is DupA1(v,v), which is v. 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. ◻

Exercise 168.1

★★☆ Definition 168.2 imposes orthogonality on both sides of a clause set.

  1. 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.

  2. 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.

  3. Show that the term (168.1) of the opening is rejected by Clauses, naming which condition it violates.

Building a trace

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.

Definition 168.19 — Partial injections

The category PInj has sets as objects and partial injections as morphisms: a morphism f:XY is a partial function whose restriction to dom(f) is injective. Composition is composition of partial functions, the identity is the total identity. Set XY:=XY, the disjoint union, and I:=; for f:XX and g:YY let fg act as f on the left summand and as g on the right, and let cX,Y:XYYX exchange the two summands.

Lemma 168.20 — PInj is symmetric monoidal

(PInj,,,c) satisfies the axioms of chapter 159.

Proof of Lemma 168.20 — PInj is symmetric monoidal

Proof. fg is a partial injection because the two summands are disjoint and each of f,g 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. ◻

Definition 168.21 — Trace, following Joyal, Street and Verity

A trace on a symmetric monoidal category V is a family of functions TrX,YU:V(XU, YU)V(X,Y) satisfying

Tight

(naturality in X and Y) TrU(f(gidU))=TrU(f)g and TrU((hidU)f)=hTrU(f);

Slide

(dinaturality in U) for g:UU, TrU((idYg)f)=TrU(f(idXg));

Vanish

TrI(f)=f and TrUV(g)=TrU(TrXU,YUV(g));

Super

TrU(f)g=TrU((idc1)(fg)(idc));

Yank

TrU(cU,U)=idU.

Construction 168.22 — The particle trace

Let f:XUYU in PInj. For xX define a finite or infinite sequence by z0:=x and, as long as f(zi) is defined and lies in U, zi+1:=f(zi). Set TrU(f)(x):={f(zn)if the sequence stops at zn with f(zn)Y,undefinedotherwise.

Lemma 168.23 — The particle trace is a partial injection

TrU(f) is a partial injection XY.

Proof of Lemma 168.23 — The particle trace is a partial injection

Proof. Suppose TrU(f)(x)=TrU(f)(x)=y, with traversal sequences z0,,zn and z0,,zm. Then f(zn)=y=f(zm), so zn=zm by injectivity of f. Suppose n,m1. Then f(zn1)=zn=zm=f(zm1), so zn1=zm1 by injectivity again; iterating, the two sequences agree from the end backwards. They must run out together: if say n>m then after m steps backwards we reach znm=z0=xX, contradicting ziU for i1. Hence n=m and x=z0=z0=x. ◻

Theorem 168.24 — The particle trace satisfies the trace laws

Tr of construction 168.22 is a trace on PInj in the sense of definition 168.21.

Proof of Theorem 168.24 — The particle trace satisfies the trace laws

Proof. Throughout, “the run of f from x” means the sequence of construction 168.22. Each law is proved by comparing two runs element by element.

Tight, first equation. Let g:XX. The run of f(gidU) from xX begins by applying g and then proceeds exactly as the run of f from g(x), since on the U summand gidU is the identity. Both sides are therefore defined at x precisely when g is defined at x and TrU(f) at g(x), with the same value.

Tight, second equation. Let h:YY. The run of (hidU)f from x visits the same elements of U as the run of f, because hidU is the identity on U; it exits when f exits, and then applies h.

Slide. Let g:UU. Write f:XUYU. The run of (idYg)f from x has the form x f u1 g u1 f u2 g u2 , and the run of f(idXg) from x has the form x f u1 g u1 f u2 , the two sequences differing only in whether the last recorded state is taken before or after the application of g. Both exit at the same application of f into Y, and with the same value; and one is defined exactly when the other is.

Vanish, first equation. U=, so no run has a step: the sequence stops at z0=x and the value is f(x).

Vanish, second equation. Let g:XUVYUV. The run of g from x visits a sequence of elements of UV. The inner trace TrV(g) collapses each maximal stretch of consecutive elements of V into a single step, and the outer trace then iterates over the elements of U. The composite therefore visits exactly the same elements of U in the same order and exits at the same application, so the two sides agree; and the composite is defined at x exactly when the run of g leaves UV, since an infinite run either has infinitely many U-states, when the outer trace diverges, or a final infinite V-stretch, when the inner trace diverges.

Super. Write the right-hand side as TrU(k) with k:=(idc1)(fg)(idc), a morphism (XX)U(YY)U. On the summand XU the two symmetries cancel and k acts as f; on X it acts as g and lands in Y at once. Hence the run of k from an element of X is the run of f, giving TrU(f), and the run from an element of X has length zero, giving g. That is TrU(f)g.

Yank. Here f=cU,U:UUUU exchanges the two summands, with X=Y=U the first summand. For x in the first summand, cU,U(x) is the copy of x in the second summand, which is the traced summand, so z1 is that copy; applying cU,U again returns the copy in the first summand, which is in Y. The run stops after one step with value x. Hence TrU(cU,U)=idU. ◻

Remark 168.25 — The trace is not part of the symmetric monoidal interface

Theorem 168.24 is a theorem about PInj, not about symmetric monoidal categories. The category of finite sets and total bijections is symmetric monoidal under disjoint union and admits no trace at U: taking X=Y= and f=idU, the run from no element is vacuous, but Vanish and Yank force TrU(idU):, whereas TrU(cU,U)=idU requires the trace to see a nonempty run; the two are consistent only because PInj 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.

Interpretation and its two theorems

Definition 168.26 — Interpretation in PInj

Interpret types by [[1]]:={},[[AB]]:=[[A]][[B]],[[AB]]:=[[A]]×[[B]], and [[μX.A]] 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 ωω:AB by a partial injection [[ω]]:[[A]][[B]]: a clause set is the union of the partial injections determined by its clauses, a let chain is the composite of the interpretations of its bindings, and fix 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.

Lemma 168.27 — Clause sets denote partial injections

If ω{viei}i:AB then the union of the clause interpretations is a partial injection.

Proof of Lemma 168.27 — Clause sets denote partial injections

Proof. Each clause determines a partial injection: matching vi against a value determines the substitution uniquely, and building ei from it is a composite of injections by induction on ei. For the union, two clauses have disjoint domains because vivj and orthogonal patterns have no common instance, by definition 168.3; and they have disjoint images because eiej, 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. ◻

Theorem 168.28 — Inversion denotes inversion

For every closed iso ωω:AB, [[ω1]]=[[ω]]1, the converse 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 let 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 fixφ.ω to fixφ.ω1, so it suffices that the trace commutes with converse: for f:XUYU, TrU(f1)=TrU(f)1. That is the calculation in lemma 168.23: the run of f1 from y is the reversal of the run of f that ends at y, which the proof there constructs by stepping backwards through the injectivity of f. ◻

Theorem 168.29 — Soundness

Let ωω:AB and v:A. If ωvw with w a value then [[ω]]([[v]])=[[w]].

Proof of Theorem 168.29 — Soundness

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: fix 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 vi. The let rule is composition of partial injections. ◻

Theorem 168.30 — Adequacy; imported

Fix an interpretation of the language of definition 168.1definition 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 t:A, the term t reduces to a value if and only if [[t:A]]0[[A]].

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.5proposition 168.18 are proved locally.

Definition 168.26 is not a join inverse rig category on the nose: PInj is one, but the interpretation given there handles only the fragment without nested fix 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.

Compact closure, and a refuted claim

Convention 168.31 — The negative and fractional card

Chen and Sabry extend a first-order reversible language of type isomorphisms with a dual to sums, a negative type A, and a dual to products, a fractional type 1/A. Operationally, a negative type is a computational effect that reverses the direction of execution, so that a value flowing into A emerges as a value flowing out of A; 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.

Remark 168.32 — The erratum, and what is not used

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 h:=ε+id there are two combinators h1=idη+ and h2=(idη+)α, with α the associativity-and-exchange combinator A+[B+C]=C+[B+A], both of which satisfy the inverse conditions for h and are not equal. Uniqueness of inverses therefore fails, and the category is not an inverse category.

Nothing in section 168.1section 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 PInj, 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 TrU(f)=(idε)(fid)(idη), but theorem 168.24 constructs a trace on PInj without any dual objects, and no adequacy theorem for the language of definition 168.1 follows from compact closure alone.

Boundary

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 PInj 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.4section 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.

Suggested first pass.

Problems exercise 168.2, exercise 168.3, and exercise 168.5 form the suggested first pass. None of these problems is a prerequisite for a later chapter.

Exercise 168.2

★★★ Theorem 168.24 proved the five laws by comparing runs.

  1. Write the proof of Vanish, second equation, as an explicit bijection between the run of g and the pair of runs of the iterated trace, and check the two divergence cases separately.

  2. Show that TrU is not injective, by exhibiting two distinct f,f with the same trace, and say which law would fail if it were required to be.

  3. Prove that the trace of construction 168.22 satisfies TrU(f1)=TrU(f)1, filling in the backward-stepping argument sketched in theorem 168.28.

Exercise 168.3

★★★ A reversible Turing machine is a tuple (Q,Σ,δ,b,qs,qf) whose transition relation is a partial injection on configurations (q,(l,s,r)) consisting of a state and a tape split at the head.

  1. Give a closed type C of definition 168.1 whose values are the configurations, using μ for the two tape halves.

  2. Write an iso step:CC from a finite δ, and check both orthogonality conditions of Clauses against the two conditions that make δ reversible.

  3. Write the iterating iso using fix, and say which of proposition 168.7 and theorem 168.30 applies to it and why the other does not.

  4. Use proposition 168.18 to turn a machine computing f into an iso of type CCC, and state what the second component holds.

Exercise 168.4

★★☆ Proposition 168.18 discharges an ancilla with DupA1.

  1. Show that DupA1(v,w) is stuck when vw, and identify the clause of definition 168.17 at which the match fails for A=2.

  2. Show that DupA is not exhaustive as an iso AAA in the other direction, and conclude that proposition 168.7 does not apply to it.

  3. Give a program that leaves an ancilla undischarged, and compute the denotation of its inverse to see what the leftover records.

Exercise 168.5

★★★ Practical project.reversible-inverter Implement, in Kappa, an evaluator and a syntactic inverter for the language of definition 168.1definition 168.4, and run programs in both directions.

Calculus to implement. Types 1, , 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 cnot and map of definition 168.14 with the list of example 168.16, the forward result must be (tt,ff)::(ff,tt)::nil and the backward result must be , with the backward clause-index trace the reverse of the forward one. On bennett(cnot) of proposition 168.18 with input (tt,tt), the forward result must be ((tt,ff),(tt,tt)) and the backward result (tt,tt). The following must be rejected by the checker: the clause set {injyyinjrzz} of (168.1), for violating right-hand orthogonality; and a clause set repeating a linear variable. The following must be reported as stuck: Dup21(tt,ff), and {injxinjx} applied to injr(). Produce three mutations that still run — drop the right-hand orthogonality check, invert a clause without reversing the let 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.

Search the book

Type to search the local edition.