Synthetic Guarded Domain Theory and Step-Indexed Semantics
Prerequisites. Direct starred prerequisites: Chapter 50, Chapter 58. No later core chapter depends on this route.
A single mutable cell holding a function of type ℕ→ℕ is enough to write a divergent program in a language whose pure fragment has no recursion at all. Store the function 𝜆𝑥.(𝗀𝖾𝗍)𝑥 into the cell, then apply the cell’s contents to 𝟢: the application reads the cell, obtains the same function, and applies it again.
The obstacle this raises is not the divergence but its denotation. A meaning for the cell’s contents is a function whose meaning mentions the heap, because the body performs 𝗀𝖾𝗍; and a meaning for the heap is a meaning for the cell’s contents. Writing H for the object of heap meanings and 𝖬 for the effect that reading and writing produce, the requirement is H≅(ℕ→𝖬ℕ),𝖬𝑋=H→(resultsin𝑋withanewH), in which H occurs on both sides and, inside 𝖬, in a negative position. A set-theoretic solution of (163.1) does not exist: the right-hand side has strictly larger cardinality than H as soon as H has more than one element.
Chapter 58 produced unique solutions of equations whose recursive occurrence sits under the later modality. This chapter inserts that modality where the operational semantics already spends a step — at the read — and then carries the consequences through to a computational adequacy theorem and to a statement about contextual equivalence.
Write S for the presheaf category [𝜔op,𝐒𝐞𝐭] over the poset 1≤2≤⋯ of positive integers. An object 𝑋 is a family of sets 𝑋𝑛 with restriction maps 𝑟𝑋𝑛:𝑋𝑛+1⟶𝑋𝑛; a map is a family 𝑓𝑛 commuting with them. The later functor is (▸𝑋)1={∗},(▸𝑋)𝑛+1=𝑋𝑛,(next𝑋)1=!,(next𝑋)𝑛+1=𝑟𝑋𝑛, and Δ(𝑆) denotes the constant object with Δ(𝑆)𝑛=𝑆 and identity restrictions. Chapter 58 proves that ▸ preserves finite limits and that every map 𝑔:▸𝑋⇒𝑋 has exactly one global element 𝑥 with 𝑥1=𝑔1(∗) and 𝑥𝑛+1=𝑔𝑛+1(𝑥𝑛).
For objects 𝐴,𝐵 of S, (𝐵𝐴)𝑛={(𝑓𝑚)𝑚≤𝑛∣𝑓𝑚:𝐴𝑚⟶𝐵𝑚,𝑟𝐵𝑚∘𝑓𝑚+1=𝑓𝑚∘𝑟𝐴𝑚(𝑚<𝑛)}, with restriction deleting the last component. Consequently (𝐵𝐴)𝑛 depends only on the sets 𝐴𝑚, 𝐵𝑚 and the restriction maps between them for 𝑚≤𝑛.
Proof. By the presheaf exponential, (𝐵𝐴)𝑛=Nat(y(𝑛)×𝐴,𝐵). Since y(𝑛)𝑚 is a one-point set for 𝑚≤𝑛 and empty otherwise, such a natural transformation is exactly a family 𝑓𝑚:𝐴𝑚⟶𝐵𝑚 for 𝑚≤𝑛 subject to the displayed naturality squares. Restriction along 𝑛+1≥𝑛 deletes 𝑓𝑛+1. The displayed description mentions no datum at a level above 𝑛. ◻
Lemma 163.2 is the fact that makes (163.1) tractable: a level-𝑛 function space is determined by levels 1 through 𝑛 of its domain and codomain, so an equation whose right-hand side puts every occurrence of the unknown under one ▸ can be solved by recursion on the level.
A predicate𝑃 on an object 𝑋 of S is a family of subsets 𝑃𝑛⊆𝑋𝑛 closed under restriction: if 𝛼∈𝑃𝑛+1 then 𝑟𝑋𝑛(𝛼)∈𝑃𝑛. Predicates are ordered by inclusion at every level. The later operator on predicates is (⊳𝑃)1:=𝑋1,(⊳𝑃)𝑛+1:={𝛼∈𝑋𝑛+1∣𝑟𝑋𝑛(𝛼)∈𝑃𝑛}. Read 𝛼∈𝑃𝑛 as “𝑃 holds of 𝛼 after 𝑛 steps of observation”.
Proof of Proposition 163.4 — The later operator is a predicate former
Proof. Closure under restriction at the step from level 2 to level 1 is the inclusion into 𝑋1, which holds because (⊳𝑃)1=𝑋1. For the step from 𝑛+2 to 𝑛+1, let 𝛼∈(⊳𝑃)𝑛+2, so 𝑟𝑋𝑛+1(𝛼)∈𝑃𝑛+1; since 𝑃 is closed under restriction, 𝑟𝑋𝑛(𝑟𝑋𝑛+1(𝛼))∈𝑃𝑛, which says 𝑟𝑋𝑛+1(𝛼)∈(⊳𝑃)𝑛+1.
For the inclusion, 𝑃1⊆𝑋1=(⊳𝑃)1; and if 𝛼∈𝑃𝑛+1 then 𝑟𝑋𝑛(𝛼)∈𝑃𝑛 by closure, that is 𝛼∈(⊳𝑃)𝑛+1. ◻
Stage 𝑛+1. Let 𝛼∈𝑋𝑛+1. The induction hypothesis gives 𝑃𝑛=𝑋𝑛, so 𝑟𝑋𝑛(𝛼)∈𝑃𝑛, that is 𝛼∈(⊳𝑃)𝑛+1; the hypothesis ⊳𝑃⊆𝑃 then gives 𝛼∈𝑃𝑛+1. ◻
Theorem 163.5 is the proof principle used for every statement below whose subject matter is defined by guarded recursion. It is not a disguised induction on a syntactic measure: the object 𝑋 is arbitrary, and the induction is on the stage of the model. Its hypothesis is the exact counterpart of the typing rule Fix of chapter 58: a proof of 𝑃 from ⊳𝑃.
For 𝑋 in S define 𝖫𝑋 by recursion on the level: (𝖫𝑋)1:=𝑋1⊎{⊥},(𝖫𝑋)𝑛+1:=𝑋𝑛+1⊎(𝖫𝑋)𝑛, with restriction 𝑟𝑛 acting as 𝑟𝑋𝑛 on the left summand and as the identity inclusion (𝖫𝑋)𝑛⊆(𝖫𝑋)𝑛 on the right. Write 𝜂:𝑋⇒𝖫𝑋 for the left injection and 𝜃:▸𝖫𝑋⇒𝖫𝑋 for the right injection, using (▸𝖫𝑋)𝑛+1=(𝖫𝑋)𝑛 and (▸𝖫𝑋)1={∗} with 𝜃1(∗):=⊥.
Proof of Proposition 163.7 — L solves its equation, uniquely
Proof. The isomorphism is the identity on the displayed disjoint unions, using (▸𝖫𝑋)1={∗} and (▸𝖫𝑋)𝑛+1=(𝖫𝑋)𝑛. The normal form follows by induction on 𝑛: at level 1 an element is in 𝑋1 or is ⊥; at level 𝑛+1 it is in 𝑋𝑛+1, or lies in (𝖫𝑋)𝑛 and has the stated form by the induction hypothesis, and in the second case one further 𝜃 is prefixed. Uniqueness of 𝑌: 𝑌1≅𝑋1⊎{∗}, and if 𝑌𝑛≅(𝖫𝑋)𝑛 then 𝑌𝑛+1≅𝑋𝑛+1⊎𝑌𝑛≅(𝖫𝑋)𝑛+1; these bijections commute with restriction because the isomorphism 𝑌≅𝑋+▸𝑌 does. ◻
Let ⊥𝑋 be the global element of 𝖫𝑋 with (⊥𝑋)𝑛=𝜃𝑛(⊥); it is the unique fixed point of 𝜃 supplied by convention 163.1. For 𝑓:𝑋⇒𝖫𝑌 define 𝑓†:𝖫𝑋⇒𝖫𝑌 by recursion on the level, 𝑓†(𝜂(𝑎)):=𝑓(𝑎),𝑓†(𝜃(𝑡)):=𝜃(▸(𝑓†)(𝑡)),𝑓†1(⊥):=⊥.
Proof. The middle equation is the first clause of definition 163.8. The other two are proved by induction on the level, using proposition 163.7 to split an element as 𝜂(𝑎), as 𝜃(𝑡) with 𝑡 at a strictly smaller level, or as ⊥ at level 1. In the 𝜃 case both sides are 𝜃 applied to the corresponding equation one level down, which is the induction hypothesis; in the 𝜂 case both sides reduce by the middle equation; at level 1 both sides are ⊥. ◻
A recursive domain equation for one higher-order cell
Define objects H and, for each 𝑋, 𝖬𝑋 by 𝖬𝑋:=𝖫(𝑋×H)H,H1:={∗},H𝑛+1:=(𝖬Δ(ℕ)Δ(ℕ))𝑛, with 𝑟H1:=! and 𝑟H𝑛+1 the restriction of the exponential of lemma 163.2.
The definition is not circular. By lemma 163.2 the level-𝑛 component of an exponential depends only on levels 1,…,𝑛 of its domain and codomain, and the level-𝑛 component of 𝖫 depends only on levels 1,…,𝑛 of its argument; so H𝑛+1 is determined by H1,…,H𝑛.
Proof of Theorem 163.11 — Solution of the equation
Proof.The isomorphism. By the description of ▸ in convention 163.1, (▸F)1={∗}=H1 and (▸F)𝑛+1=F𝑛=H𝑛+1 by definition 163.10. The restriction maps agree by construction.
Uniqueness. Let H′ satisfy the same isomorphism. At level 1 both are one-point sets. Suppose a family of bijections H′𝑚→H𝑚 commuting with restriction has been given for 𝑚≤𝑛. By lemma 163.2 and definition 163.6, the set F𝑛 is built from H1,…,H𝑛 by disjoint unions, products and function sets, so those bijections induce a bijection F′𝑛→F𝑛; composing with the two isomorphisms gives a bijection H′𝑛+1→H𝑛+1, and it commutes with restriction because the isomorphisms do. ◻
Unfold definition 163.10 twice. At level 1 the heap object is a one-point set: after one step of observation, nothing about the stored function is visible. At level 2, H2=F1=(functionsℕ⟶(𝖬Δ(ℕ))1),(𝖬Δ(ℕ))1=(functionsH1⟶(𝖫(Δ(ℕ)×H))1)=(ℕ×{∗})⊎{⊥}, so H2 is the set of functions ℕ⟶ℕ⊎{⊥}. A stage-2 heap is therefore a function on numbers that may either return a number or fail to return. That this is exactly the information available after two steps of observation is what the whole construction is for.
★★☆ Compute H3 explicitly as a set built from ℕ, disjoint unions and function sets, showing every step. Then exhibit the restriction map H3⟶H2 and check that it agrees with lemma 163.2. Finally, state what a stage-3 heap records that a stage-2 heap does not.
★★☆ Delete the ▸ from theorem 163.11, so that the equation reads H≅F with F as displayed.
Show that the level-1 component of the right-hand side is then the set of functions ℕ⟶(H1⟶(ℕ×H1)⊎{⊥}), and conclude that the recursion on levels no longer terminates.
In sets, show that no set 𝑆 with more than one element satisfies 𝑆≅(𝑆→(ℕ×𝑆)⊎{⊥})ℕ, by a cardinality argument. Name the position of the occurrence of 𝑆 that makes the argument work.
Types and terms are 𝜏,𝜎::=ℕ∣𝜏→𝜎,𝑒::=𝑥∣𝑛――∣𝗌𝗎𝖼𝑒∣𝜆𝑥:𝜏.𝑒∣𝑒1𝑒2∣𝗀𝖾𝗍∣𝗌𝖾𝗍(𝑒1;𝑒2), with 𝑛―― a numeral for each 𝑛∈ℕ. Write 𝐹:=ℕ→ℕ for the type of the cell’s contents. The typing rules are those of the simply typed calculus of chapter 2 together with
Γ𝖼𝗍𝗑
Γ⊢𝗀𝖾𝗍:𝐹
Get
Γ⊢𝑒1:𝐹Γ⊢𝑒2:𝜏
Γ⊢𝗌𝖾𝗍(𝑒1;𝑒2):𝜏
Set
Values and evaluation contexts are 𝑣::=𝑛――∣𝜆𝑥:𝜏.𝑒,𝐸::=[]∣𝐸𝑒∣𝑣𝐸∣𝗌𝗎𝖼𝐸∣𝗌𝖾𝗍(𝐸;𝑒). A configuration⟨ℎ∣𝑒⟩ consists of a closed value ℎ with ⋅⊢ℎ:𝐹, the contents of the cell, and a term 𝑒. The transitions are ⟨ℎ∣𝐸⟨(𝜆𝑥:𝜏.𝑒)𝑣⟩⟩⟶Beta⟨ℎ∣𝐸⟨𝑒[𝑣/𝑥]⟩⟩,⟨ℎ∣𝐸⟨𝗌𝗎𝖼𝑛――⟩⟩⟶Succ⟨ℎ∣𝐸⟨𝑛+1――――⟩⟩,⟨ℎ∣𝐸⟨𝗀𝖾𝗍⟩⟩⟶Read⟨ℎ∣𝐸⟨ℎ⟩⟩,⟨ℎ∣𝐸⟨𝗌𝖾𝗍(𝑣;𝑒)⟩⟩⟶Write⟨𝑣∣𝐸⟨𝑒⟩⟩. Write ⟼ for the union of the four relations and ⟼∗ for its reflexive-transitive closure. A configuration converges to 𝑣, written ⟨ℎ∣𝑒⟩⇓𝑣, when ⟨ℎ∣𝑒⟩⟼∗⟨ℎ′∣𝑣⟩ for some ℎ′.
Let ℎ∗:=𝜆𝑥:ℕ.𝗀𝖾𝗍𝑥 and 𝑒∗:=𝗀𝖾𝗍0――. Then ⟨ℎ∗∣𝑒∗⟩⟶Read⟨ℎ∗∣ℎ∗0――⟩⟶Beta⟨ℎ∗∣𝗀𝖾𝗍0――⟩=⟨ℎ∗∣𝑒∗⟩, so the configuration returns to itself after two steps, one of which is a Read. The pure fragment of Λ𝖼𝖾𝗅𝗅 has no recursion operator; all of this program’s recursion passes through the cell.
Proof of Proposition 163.15 — Every divergence reads the cell
Proof. Suppose a transition sequence from ⟨ℎ∣𝑒⟩ performs no Read step. Replace 𝗀𝖾𝗍 everywhere by a fresh variable 𝑔:𝐹 and 𝗌𝖾𝗍(𝑒1;𝑒2) by (𝜆𝑧:𝐹.𝑒2)𝑒1 with 𝑧 not free in 𝑒2. This translation sends every Beta step to a Beta step, every Succ step to a Succ step and every Write step to a Beta step of the simply typed calculus, and it sends well-typed terms of Λ𝖼𝖾𝗅𝗅 to well-typed terms of the simply typed calculus over the context 𝑔:𝐹. By the normalization theorem of chapter 2 that calculus has no infinite reduction sequence from a well-typed term, so the original sequence is finite.
Hence a transition sequence with only finitely many Read steps decomposes into finitely many Read-free segments, each finite, and is therefore finite itself. ◻
Proposition 163.15 identifies the exact operational event that the later modality will account for. The interpretation below spends one ▸ at each Read step and none at the other three.
Set [[ℕ]]:=Δ(ℕ),[[𝜏→𝜎]]:=(𝖬[[𝜎]])[[𝜏]],[[𝑥1:𝜏1,…,𝑥𝑘:𝜏𝑘]]:=[[𝜏1]]×⋯×[[𝜏𝑘]], so that [[𝐹]]=F and, by theorem 163.11, H≅▸[[𝐹]]. A derivation of Γ⊢𝑒:𝜏 is interpreted as a map [[𝑒]]:[[Γ]]⇒𝖬[[𝜏]] by the clauses [[𝑥𝑖]]𝜌ℏ:=𝜂(𝜌𝑖,ℏ),[[𝑛――]]𝜌ℏ:=𝜂(𝑛,ℏ),[[𝗌𝗎𝖼𝑒]]𝜌ℏ:=(𝜆(𝑎,ℏ′).𝜂(𝑎+1,ℏ′))†([[𝑒]]𝜌ℏ),[[𝜆𝑥:𝜏.𝑒]]𝜌ℏ:=𝜂(𝜆𝑎.[[𝑒]](𝜌,𝑎),ℏ),[[𝑒1𝑒2]]𝜌ℏ:=(𝜆(𝜑,ℏ1).(𝜆(𝑎,ℏ2).𝜑𝑎ℏ2)†([[𝑒2]]𝜌ℏ1))†([[𝑒1]]𝜌ℏ),[[𝗀𝖾𝗍]]𝜌ℏ:=𝜃(▸(𝜆𝜑.𝜂(𝜑,ℏ))(ℏ)),[[𝗌𝖾𝗍(𝑒1;𝑒2)]]𝜌ℏ:=(𝜆(𝜑,ℏ1).[[𝑒2]]𝜌(next𝜑))†([[𝑒1]]𝜌ℏ). For a closed value ℎ of type 𝐹 write [[ℎ]]H:=next(𝜑ℎ), where 𝜑ℎ is the function component of [[ℎ]](∗)(ℏ)=𝜂(𝜑ℎ,ℏ); the clause for abstraction shows that this does not depend on ℏ.
The clause for 𝗀𝖾𝗍 is the only one that produces a 𝜃. It must: the heap ℏ is an element of ▸[[𝐹]], so the stored function is not available now, and the only way to use it is to apply the functorial action of ▸ and then re-enter 𝖫 through 𝜃. The clause for 𝗌𝖾𝗍 is dual: it stores next𝜑, which is available later, and spends no step.
Proof. By induction on 𝐸. For 𝐸=[] take 𝐾[](𝜌,𝑎,ℏ′):=𝜂(𝑎,ℏ′); the equation is then 𝜂†([[𝑒]]𝜌ℏ)=[[𝑒]]𝜌ℏ, which is proposition 163.9. For each other case the corresponding clause of definition 163.16 is already of the displayed form with the inductively given 𝐾 substituted into the outer continuation; associativity of (−)†, again from proposition 163.9, merges the two continuations into one. We display the case 𝐸=𝐸′𝑒2: the clause for application gives [[𝐸′⟨𝑒⟩𝑒2]]𝜌ℏ=(𝜆(𝜑,ℏ1).𝑐(𝜑,ℏ1))†([[𝐸′⟨𝑒⟩]]𝜌ℏ)=(𝜆(𝑎,ℏ′).(𝜆(𝜑,ℏ1).𝑐(𝜑,ℏ1))†𝐾𝐸′(𝜌,𝑎,ℏ′))†([[𝑒]]𝜌ℏ), where 𝑐 is the continuation of the application clause; the second equality is the induction hypothesis followed by associativity, and the bracketed map is 𝐾𝐸′𝑒2. The remaining three cases are the same computation with 𝑐 replaced by the continuation of the clause for 𝑣[], for 𝗌𝗎𝖼, and for 𝗌𝖾𝗍. ◻
Let Γ,𝑥:𝜏⊢𝑒:𝜎 and let 𝑣 be a closed value of type 𝜏 with value component [[𝑣]]v, meaning the first component of [[𝑣]]𝜌ℏ=𝜂([[𝑣]]v,ℏ). Then [[𝑒[𝑣/𝑥]]]𝜌=[[𝑒]](𝜌,[[𝑣]]v).
Proof. By induction on the derivation of Γ,𝑥:𝜏⊢𝑒:𝜎. We display the two cases in which the variable is consumed or captured; the remaining four clauses of definition 163.16 are composites of the subterm interpretations with maps not mentioning 𝜌, so each is the induction hypothesis applied componentwise.
Variable case. If 𝑒=𝑥 then 𝑒[𝑣/𝑥]=𝑣 and [[𝑣]]𝜌ℏ=𝜂([[𝑣]]v,ℏ)=[[𝑥]](𝜌,[[𝑣]]v)ℏ by the clause for variables. If 𝑒=𝑦 with 𝑦 distinct from 𝑥, both sides are 𝜂(𝜌𝑦,ℏ).
Binder case. If 𝑒=𝜆𝑦:𝜎1.𝑒1 with 𝑦∉FV(𝑣)∪{𝑥}, then [[𝜆𝑦:𝜎1.𝑒1[𝑣/𝑥]]]𝜌ℏ𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛163.16=𝜂(𝜆𝑎.[[𝑒1[𝑣/𝑥]]](𝜌,𝑎),ℏ)𝐼𝐻=𝜂(𝜆𝑎.[[𝑒1]](𝜌,[[𝑣]]v,𝑎),ℏ), and the right-hand side is [[𝜆𝑦:𝜎1.𝑒1]](𝜌,[[𝑣]]v)ℏ after exchanging the last two components of the environment, which is legal because the two variables are distinct. ◻
Let ⋅⊢𝑒:𝜏 and let ℎ be a closed value of type 𝐹. Write [[⟨ℎ∣𝑒⟩]]:=[[𝑒]](∗)[[ℎ]]H. Then ⟨ℎ∣𝑒⟩⟶Beta⟨ℎ∣𝑒′⟩,⟨ℎ∣𝑒⟩⟶Succ⟨ℎ∣𝑒′⟩,or⟨ℎ∣𝑒⟩⟶Write⟨ℎ′∣𝑒′⟩ implies [[⟨ℎ∣𝑒⟩]]=[[⟨ℎ′∣𝑒′⟩]], and ⟨ℎ∣𝑒⟩⟶Read⟨ℎ∣𝐸⟨ℎ⟩⟩implies[[⟨ℎ∣𝑒⟩]]=𝜃(next[[⟨ℎ∣𝐸⟨ℎ⟩⟩]]).
Proof of Theorem 163.19 — Soundness of the interpretation
Proof. By lemma 163.17 it suffices to treat the redex, since both sides are the same continuation applied to the interpretation of the redex.
Beta. Unfolding the clauses for application and abstraction, [[(𝜆𝑥:𝜏.𝑒)𝑣]]𝜌ℏ𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛163.16=(𝜆𝑎.[[𝑒]](𝜌,𝑎))[[𝑣]]vℏ𝑙𝑒𝑚𝑚𝑎163.18=[[𝑒[𝑣/𝑥]]]𝜌ℏ, where [[𝑣]]v is the value component of [[𝑣]]𝜌ℏ.
Succ. Both sides are 𝜂(𝑛+1,ℏ).
Write. The clause for 𝗌𝖾𝗍 evaluates 𝑒1 to a value 𝑣 with function component 𝜑𝑣 and continues with [[𝑒2]]𝜌(next𝜑𝑣), and next𝜑𝑣=[[𝑣]]H by definition 163.16. No 𝜃 is produced.
Read. Write ℏ=[[ℎ]]H=next(𝜑ℎ). Then [[𝗀𝖾𝗍]]𝜌ℏ𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛163.16=𝜃(▸(𝜆𝜑.𝜂(𝜑,ℏ))(next𝜑ℎ))𝑛𝑎𝑡.=𝜃(next(𝜂(𝜑ℎ,ℏ)))𝑑𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛163.16=𝜃(next([[ℎ]]𝜌ℏ)), the middle step by naturality of next. Applying lemma 163.17 to both sides and using that (−)† commutes with 𝜃 by definition 163.8 gives the displayed equation. ◻
Proof of Corollary 163.20 — Reading is the only step the model counts
Proof. Induction on the length of the transition sequence, applying the appropriate clause of theorem 163.19 at each step; the Read clause contributes one 𝜃 and the other three contribute none. At the end the configuration is a value, and the clauses of definition 163.16 for numerals and abstractions give the displayed 𝜂. ◻
Take ℎ∗ and 𝑒∗ from example 163.14. By example 163.14 the configuration performs one Read in every two steps and never converges, so corollary 163.20 applies with every 𝑘 and gives [[⟨ℎ∗∣𝑒∗⟩]]=𝜃𝑘([[⟨ℎ∗∣𝑒∗⟩]])forevery𝑘≥1. By proposition 163.7 an element of (𝖫(Δ(ℕ)×H))𝑛 with 𝑛 leading 𝜃’s is 𝜃𝑛(⊥), so [[⟨ℎ∗∣𝑒∗⟩]]=⊥.
The stored function is computed by the same unfolding. By example 163.12, [[ℎ∗]]H at stage 2 is the function ℕ⟶ℕ⊎{⊥} obtained from [[𝗀𝖾𝗍𝑥]] at stage 1; the clause for 𝗀𝖾𝗍 places a 𝜃 there, and 𝜃1(∗)=⊥ by definition 163.6. Hence the stage-2 stored function is constantly ⊥: after two steps of observation, the knot’s contents already return nothing on every input.
Corollary 163.20 runs from the operational semantics to the model. The converse direction — from a denotation to a run — is the content of computational adequacy, and it needs a relation between the two. At the type ℕ the relation can be avoided, as theorem 163.23 below shows; at a function type it cannot, because the denotation of a function is not a run but a family of maps, one at each stage.
Proof. Every closed well-typed term is a value or decomposes uniquely as 𝐸⟨𝑒0⟩ with 𝑒0 one of (𝜆𝑥:𝜏.𝑒)𝑣, 𝗌𝗎𝖼𝑛――, 𝗀𝖾𝗍, 𝗌𝖾𝗍(𝑣;𝑒); the decomposition is unique because the grammar of 𝐸 in definition 163.13 fixes, at each constructor, which subterm is evaluated first, and the value grammar determines when to move on. Exactly one transition applies to each of the four redexes. For progress, a closed well-typed non-value term has such a decomposition by induction on its typing derivation: at an application 𝑒1𝑒2 either 𝑒1 is not a value, and the induction hypothesis gives a decomposition inside 𝐸𝑒2, or 𝑒1 is a value of function type, hence an abstraction by inspection of the value grammar, and the same argument applies to 𝑒2. ◻
Let ⋅⊢𝑒:ℕ and let ℎ be a closed value of type 𝐹. Then ⟨ℎ∣𝑒⟩⇓𝑚――withexactly𝑘Readsteps⟺[[⟨ℎ∣𝑒⟩]]=𝜃𝑘(𝜂(𝑚,ℏ′))forsomeℏ′, and ⟨ℎ∣𝑒⟩ has an infinite transition sequence if and only if [[⟨ℎ∣𝑒⟩]]=⊥.
Proof. By lemma 163.22 exactly one of two things happens: the transition sequence from ⟨ℎ∣𝑒⟩ is finite and ends in a value, or it is infinite.
Convergent case.Corollary 163.20 gives the displayed right-hand side, with 𝑚 the value of the numeral reached.
Divergent case. By proposition 163.15 the sequence contains infinitely many Read steps. Fix 𝑛 and take a prefix containing 𝑛Read steps, ending at ⟨ℎ𝑛∣𝑒𝑛⟩. Applying theorem 163.19 along that prefix gives [[⟨ℎ∣𝑒⟩]]=𝜃𝑛(𝑢) for some 𝑢. By proposition 163.7 the only element of (𝖫(Δ(ℕ)×H))𝑛 with 𝑛 leading 𝜃’s is 𝜃𝑛(⊥), so [[⟨ℎ∣𝑒⟩]]𝑛=(⊥)𝑛. As 𝑛 was arbitrary, [[⟨ℎ∣𝑒⟩]]=⊥.
The two right-hand sides are distinct, since 𝜃𝑘(𝜂(𝑚,ℏ′)) at stage 𝑘+1 is not 𝜃𝑘+1(⊥); so each direction of the stated equivalences follows from the other case. ◻
Theorem 163.23 says nothing about a closed term of type 𝐹: its denotation is an element of F, and there is no numeral to compare. The relation defined next repairs that, and the heap relation is where the later operator does its work.
Write Val𝜏 for the set of closed values of type 𝜏 and Cfg𝜏 for the set of configurations ⟨ℎ∣𝑒⟩ with ⋅⊢𝑒:𝜏. Define predicates V𝜏onΔ(Val𝜏)×[[𝜏]],C𝜏onΔ(Cfg𝜏)×𝖫([[𝜏]]×H),WonΔ(Val𝐹)×H, simultaneously, by recursion on the stage and, at each stage, by induction on the type.
W1:=Δ(Val𝐹)×H1, and for 𝑛≥1, W𝑛+1:={(ℎ,ℏ)∣(ℎ,ℏ)∈(V𝐹)𝑛}, using H𝑛+1=[[𝐹]]𝑛 from theorem 163.11.
(Vℕ)𝑛:={(𝑚――,𝑚)∣𝑚∈ℕ}.
(V𝜏→𝜎)𝑛 is the set of pairs (𝜆𝑥:𝜏.𝑒,𝜑) such that for every 𝑚≤𝑛, every (𝑣,𝑎)∈(V𝜏)𝑚 and every (ℎ,ℏ)∈W𝑚, (⟨ℎ∣𝑒[𝑣/𝑥]⟩,𝜑𝑚(𝑎)(ℏ))∈(C𝜎)𝑚.
(C𝜏)𝑛 is defined by cases on the normal form of its second argument, using proposition 163.7:
(⟨ℎ∣𝑒⟩,𝜂(𝑎,ℏ))∈(C𝜏)𝑛 when ⟨ℎ∣𝑒⟩⟼∗⟨ℎ′∣𝑣⟩ by a sequence with no Read step, and (𝑣,𝑎)∈(V𝜏)𝑛 and (ℎ′,ℏ)∈W𝑛;
(⟨ℎ∣𝑒⟩,𝜃(𝑡))∈(C𝜏)𝑛+1 when ⟨ℎ∣𝑒⟩⟼∗⟨ℎ′∣𝐸⟨𝗀𝖾𝗍⟩⟩ by a sequence with no Read step and (⟨ℎ′∣𝐸⟨ℎ′⟩⟩,𝑡)∈(C𝜏)𝑛;
The recursion is well founded: clause 1 at stage 𝑛+1 mentions V𝐹 at stage 𝑛; clause 4 at stage 𝑛+1 mentions C𝜏 at stage 𝑛; clause 3 at stage 𝑛 mentions C𝜎 at stages at most 𝑛 and types smaller than 𝜏→𝜎. Clause 1 is the later operator of definition 163.3 applied to V𝐹 and transported along H≅▸[[𝐹]]: a heap and its denotation are related now exactly when the stored value and its denotation are related later.
Proof of Lemma 163.25 — The relations are predicates
Proof. For Vℕ the level plays no role. For V𝜏→𝜎 the defining condition quantifies over all 𝑚≤𝑛, so it is inherited at 𝑛−1; and restriction of 𝜑 from level 𝑛 to level 𝑛−1 deletes its top component by lemma 163.2, leaving the components at 𝑚≤𝑛−1 unchanged. For W: an element of W𝑛+2 is a pair in (V𝐹)𝑛+1, which restricts into (V𝐹)𝑛, that is into W𝑛+1; and every pair lies in W1. For C𝜏, restriction of 𝜃(𝑡) from level 𝑛+1 is 𝜃(𝑟(𝑡)) or, at 𝑛=1, the element ⊥; the first case is the induction hypothesis and the second is unconditional. Restriction of 𝜂(𝑎,ℏ) is 𝜂(𝑟(𝑎),𝑟(ℏ)), and the operational conditions do not mention the level. ◻
Proof. By induction on the derivation of Γ⊢𝑒:𝜏. We write 𝜌 for (𝑎1,…,𝑎𝑘) and 𝛾𝑒 for 𝑒[⃗𝑣/⃗𝑥].
Variable and numeral.[[𝑥𝑖]]𝜌ℏ=𝜂(𝑎𝑖,ℏ) and 𝛾𝑥𝑖=𝑣𝑖 is already a value, so the first clause of definition 163.24(4) applies with the empty transition sequence, using (𝑣𝑖,𝑎𝑖)∈(V𝜏𝑖)𝑛 and (ℎ,ℏ)∈W𝑛. The numeral case is the same with (𝑚――,𝑚)∈Vℕ.
Abstraction.[[𝜆𝑥:𝜏0.𝑒0]]𝜌ℏ=𝜂(𝜆𝑎.[[𝑒0]](𝜌,𝑎),ℏ), and 𝛾(𝜆𝑥:𝜏0.𝑒0) is a value; so it suffices to show that the pair lies in (V𝜏0→𝜎)𝑛. Let 𝑚≤𝑛, let (𝑣,𝑎)∈(V𝜏0)𝑚 and let (ℎ1,ℏ1)∈W𝑚. By lemma 163.25 the pairs (𝑣𝑖,𝑎𝑖) lie in (V𝜏𝑖)𝑚, so the induction hypothesis for 𝑒0 at stage 𝑚 gives (⟨ℎ1∣𝛾𝑒0[𝑣/𝑥]⟩,[[𝑒0]](𝜌,𝑎)ℏ1)∈(C𝜎)𝑚, which is the required condition.
Application. Let 𝑒=𝑒1𝑒2. The induction hypothesis for 𝑒1 places (⟨ℎ∣𝛾𝑒1⟩,[[𝑒1]]𝜌ℏ) in (C𝜏0→𝜏)𝑛. We argue by induction on the number of leading 𝜃’s of [[𝑒1]]𝜌ℏ. If there are none, the clause for 𝜂 gives a Read-free run ⟨ℎ∣𝛾𝑒1⟩⟼∗⟨ℎ1∣𝑤⟩ with (𝑤,𝜑)∈(V𝜏0→𝜏)𝑛 and (ℎ1,ℏ1)∈W𝑛; applying the induction hypothesis for 𝑒2 at (ℎ1,ℏ1) and then the defining condition of V𝜏0→𝜏 at 𝑚=𝑛 yields the claim, because lemma 163.17 identifies the denotation of the whole application with the corresponding continuation applied to these pieces. If there is at least one leading 𝜃, the clause for 𝜃 gives a Read step after a Read-free run, and the same decomposition at stage 𝑛−1 is the inner induction hypothesis.
Successor and 𝗌𝖾𝗍. As in the application case, with the continuation of the corresponding clause of definition 163.16; for 𝗌𝖾𝗍 the new heap is next𝜑𝑣, and (𝑣,𝜑𝑣)∈(V𝐹)𝑛 from the induction hypothesis gives (𝑣,next𝜑𝑣)∈W𝑛+1 by definition 163.24(1), hence membership in W𝑛 by lemma 163.25.
𝗀𝖾𝗍. At stage 1 the second clause of definition 163.24(4) is unconditional, since [[𝗀𝖾𝗍]]𝜌ℏ has a leading 𝜃 and 𝜃1(∗)=⊥. At stage 𝑛+1, the computation in the Read case of theorem 163.19 gives [[𝗀𝖾𝗍]]𝜌ℏ=𝜃(𝜂(ℏ,𝑟𝑛ℏ)), so the 𝜃 clause requires (⟨ℎ∣ℎ⟩,𝜂(ℏ,𝑟𝑛ℏ))∈(C𝐹)𝑛. The term ℎ is a value, so the empty run discharges the operational condition, and two memberships remain: (ℎ,ℏ)∈(V𝐹)𝑛and(ℎ,𝑟𝑛ℏ)∈W𝑛. The first is the hypothesis (ℎ,ℏ)∈W𝑛+1 read through definition 163.24(1). The second follows from the first by lemma 163.25 and the same clause one stage down. ◻
Proof of Corollary 163.27 — Adequacy at every type
Proof. Apply theorem 163.26 at stage 𝑛 and unfold the 𝜃 clause of definition 163.24(4) 𝑘 times; each unfolding produces one Read step preceded by a Read-free run, and the remaining datum is 𝜂(𝑎,ℏ′), whose clause supplies the value 𝑣 together with (𝑣,𝑎)∈(V𝜏)𝑛−𝑘. Since this holds for every 𝑛, the membership holds at every stage. ◻
Let ⋅⊢𝑒1:𝜏 and ⋅⊢𝑒2:𝜏 with [[𝑒1]]=[[𝑒2]]. Then for every context 𝐶 with ⋅⊢𝐶⟨𝑒𝑖⟩:ℕ, every closed value ℎ of type 𝐹 and every numeral 𝑚――, ⟨ℎ∣𝐶⟨𝑒1⟩⟩⇓𝑚――⟺⟨ℎ∣𝐶⟨𝑒2⟩⟩⇓𝑚――.
Proof of Theorem 163.28 — Denotational equality implies contextual equivalence
Proof. Every clause of definition 163.16 defines the denotation of a term from the denotations of its immediate subterms, so [[𝐶⟨𝑒⟩]] is a function of [[𝑒]]; hence [[𝐶⟨𝑒1⟩]]=[[𝐶⟨𝑒2⟩]]. Apply theorem 163.23 to each side: the left converges to 𝑚―― if and only if the common denotation is 𝜃𝑘(𝜂(𝑚,ℏ′)), and likewise for the right. ◻
Show [[Ω]](∗)ℏ=⊥ for every ℏ, by computing the Write step and then applying example 163.21.
Conclude from theorem 163.28 that Ω is contextually equivalent to every closed term of type ℕ whose denotation is ⊥, and exhibit one such term that contains no 𝗌𝖾𝗍.
State why the converse of theorem 163.28 is not established by these results, naming the property of the interpretation that would be required.
Two other step-indexed models, at their own signatures
Theorem 163.11 solved the equation for one cell of one fixed type. A language with allocation needs worlds: a world records, for each allocated location, the semantic type of its contents, and the recursion is then between worlds and semantic types. Two published models make different choices about that recursion, and neither theorem is a consequence of section 163.3–section 163.6.
Predicative references and universe-indexed worlds. Koronkevich and Bowman, Type Universes as Kripke Worlds, remove the recursion instead of solving it. Their calculus 𝜆PR kinds the type of an allocated term by a universe level, and a world at level 𝑖 records only allocations at levels below 𝑖; a function that closes over a level-𝑖 reference has a type at level 𝑖+1. The semantic worlds are then stratified by the universe hierarchy, and the type-world circularity does not arise. Their Theorem 3.3 is the fundamental lemma: if Γ⊢𝑒:𝜏 and 𝜏::Type𝑖, then for every 𝛾 in the context relation at a world 𝑊, the substituted term 𝛾(𝑒) lies in the expression relation E[[𝜏]]𝑖(𝑊), whose membership condition includes termination. Their language is therefore terminating, and Landin’s knot is not well typed in it: writing 𝜆𝑥.(𝗀𝖾𝗍)𝑥 into the cell would require the stored function to close over the very level at which the cell is allocated. The earlier workshop note One Weird Trick to Untie Landin’s Knot states a language and a termination claim that were conjectural and owns no theorem; only the later paper’s theorems are used here.
Substructural state with explicit step indices. Ahmed, Fluet and Morrisett give a step-indexed model of a substructural polymorphic 𝜆-calculus with four kinds of mutable reference — unrestricted, relevant, affine and linear — supporting deallocation and type-varying update. Their semantic types are indexed by an explicit natural-number step count and by a local store description, related to actual stores by a judgment 𝑠:𝑘𝜓 asserting that the store 𝑠 satisfies the description 𝜓 for 𝑘 steps, and their Theorem 1 is a soundness theorem for that calculus from which type safety follows. The index there is a number carried in the definition; in definition 163.24 it is the stage of the model and never appears in a formula. The two are related by the translation of chapter 58: an explicitly indexed family is a presheaf on 𝜔, and a decrement of the index is an application of ▸. That translation is a change of presentation; it does not transport their theorem to the language of definition 163.13, whose store discipline is unrestricted and whose type system has no substructural qualifiers.
General store with polymorphism. Sterling, Gratzer and Birkedal build a model of a dependent type theory with general reference types and recursive types by combining guarded recursion with impredicative polymorphism. Their higher-order state monad is (𝖳𝐴)𝑤:=∏𝑤′≥𝑤𝐻𝑤′→𝖫(∐𝑤″≥𝑤′𝐻𝑤″×𝐴𝑤″), and their semantic reference type is (𝗋𝖾𝖿𝐴)𝑤={𝑙∈|𝑤|∣next𝐴=𝑤𝑙}: a world assigns to each location a delayed semantic type, which is where guardedness enters. Their Theorem 2.5 states that 𝖳 is a strong monad each of whose values is a guarded domain, and Theorem 2.6 lists the equations of state that the model validates. Their worlds need not be syntactically definable, which is what makes the model compatible with relational reasoning about stateful abstract data types. Definition 163.10 is the degenerate case of a single location of a fixed type, where the world is constant and only the delay survives.
Comparison with a synthetic domain model
The guarded model produces fixed points without any order. The older synthetic route produces them from an order, and the two theorems are about disjoint classes of maps.
An 𝜔-cpo is a partially ordered set in which every increasing sequence 𝑑0≤𝑑1≤⋯ has a least upper bound; it is pointed when it has a least element ⊥. A map 𝑓:𝐷⟶𝐸 of 𝜔-cpos is continuous when it is monotone and 𝑓(⋁𝑖𝑑𝑖)=⋁𝑖𝑓(𝑑𝑖) for every increasing sequence.
Proof. Monotonicity and ⊥≤𝑓(⊥) give 𝑓𝑖(⊥)≤𝑓𝑖+1(⊥) by induction on 𝑖, so the sequence is increasing and its join exists. Then 𝑓(⋁𝑖𝑓𝑖(⊥))𝑐𝑜𝑛𝑡.=⋁𝑖𝑓𝑖+1(⊥)⊥≤𝑓(⊥)=⋁𝑖𝑓𝑖(⊥). If 𝑓(𝑑)≤𝑑 then 𝑓𝑖(⊥)≤𝑑 by induction on 𝑖, using ⊥≤𝑑 and monotonicity, so the join is below 𝑑. ◻
Theorem 163.30 and the guarded fixed-point theorem of convention 163.1 apply to different maps and produce different objects.
The identity map on a pointed 𝜔-cpo with at least two elements is continuous and has every element as a fixed point; theorem 163.30 selects ⊥. The identity on an object of S is not of the form 𝑔∘next unless the object is trivial, so the guarded theorem does not apply to it, and there is nothing for it to select.
Conversely, the map 𝜃:▸𝖫𝑋⇒𝖫𝑋 of definition 163.6 has exactly one fixed point, ⊥, by convention 163.1, and the object 𝖫𝑋 carries no order in which that could be described as least.
The two induction principles have incomparable hypotheses. Proposition 163.31 requires ⊥∈𝑃 and closure under joins; theorem 163.5 requires ⊳𝑃⊆𝑃. A predicate on 𝖫𝑋 that holds of 𝜂(𝑎) for every 𝑎 and fails at ⊥ satisfies neither, and a predicate that holds only at ⊥ satisfies the first but not the second.
Fiore and Rosolini construct a Grothendieck topos in which the category of 𝜔-cpos and continuous maps sits as a reflective exponential ideal, and show that with the dominance induced by the two-element chain it is a model of Hyland’s axioms for synthetic domain theory; the fixed-point property there is that the canonical map from the initial algebra of the lifting functor to its final coalgebra is an isomorphism, which is proved by exhibiting the colimit and the limit of the same diagram. Their second model, built from 𝜔-complete posets and stable maps, satisfies all of those axioms except two, and the failures are exactly that such categories are not closed under adding a top element and that unions of stable open subsets need not be stable open. Neither model validates theorem 163.5, and definition 163.10 does not solve its equation in either.
★★☆ Let 𝐷 be the pointed 𝜔-cpo {⊥≤0≤1≤⋯}∪{⊤} of the natural numbers with a top element adjoined, and let 𝑓(𝑑):=𝑑+1 with 𝑓(⊤)=⊤.
Compute fix(𝑓) by theorem 163.30 and identify all fixed points of 𝑓.
Exhibit the corresponding object of S whose stage-𝑛 set is {0,…,𝑛−1}∪{⊥} and a map out of its later object whose unique fixed point is the family (⊥)𝑛, and say which of the fixed points found in part 1 it corresponds to.
State which of theorem 163.30, theorem 163.5 proves that no other fixed point exists in its setting, and why the other cannot.
Guarded productivity is not general recursion. Every ▸ in definition 163.16 corresponds to a Read step, and proposition 163.15 shows that no other source of divergence exists in Λ𝖼𝖾𝗅𝗅. A language whose pure fragment diverges requires a further guarded clause, and proposition 163.15 then fails as stated.
Allocation is not modelled.Definition 163.10 fixes one cell of one type. A language with 𝗇𝖾𝗐 requires worlds, and with them a second recursion, between worlds and semantic types; section 163.7 records three published resolutions of that recursion and their exact theorems.
The contextual result is one-directional.Theorem 163.28 sends denotational equality to contextual equivalence. Full abstraction is the converse, and nothing above establishes it; the interpretation of a function type in definition 163.16 is a full function space, which by the argument of chapter 158 contains elements that no term denotes.
No order is available.Remark 163.32 shows that neither fixed-point principle implies the other, so a proof that uses proposition 163.31 does not transport into S, and a proof that uses theorem 163.5 does not transport into a category of domains.
★★★ Extend Λ𝖼𝖾𝗅𝗅 to two cells, both of type 𝐹, with 𝗀𝖾𝗍1,𝗀𝖾𝗍2 and 𝗌𝖾𝗍1,𝗌𝖾𝗍2.
Write the recursive domain equation for the pair-of-cells object H2 and solve it by the level recursion of definition 163.10, computing H21 and H22 explicitly.
Write the two-cell version of Landin’s knot in which the first cell calls the second and the second calls the first, and compute its denotation at stages 1, 2 and 3.
Now allow the second cell to hold a value of type ℕ rather than 𝐹, and state precisely which part of the level recursion still works and which part becomes unnecessary.
★★★Theorem 163.26 was proved by induction on the typing derivation, with the stage bookkeeping visible only in the 𝗀𝖾𝗍 case.
Write out the application case in full, displaying the continuation 𝐾 supplied by lemma 163.17 and the exact instance of definition 163.24(3) used.
Give a second proof of the 𝗀𝖾𝗍 case by Löb induction (theorem 163.5) on the predicate “for all ℎ and ℏ related at this stage, the configuration and the denotation are related”, and state which hypothesis of theorem 163.5 the heap clause definition 163.24(1) supplies.
Show that definition 163.24(3) becomes false if the quantifier “for every 𝑚≤𝑛” is replaced by “for 𝑚=𝑛”, by exhibiting a pair that would then fail to be closed under restriction.
★★★Practical project.guarded-store-adequacy Implement, in Kappa, a stage-indexed interpreter for Λ𝖼𝖾𝗅𝗅 and an operational machine for it, and use them to check adequacy on named programs.
Calculus to implement. The syntax, typing and transitions of definition 163.13, with de Bruijn indices and capture-avoiding substitution. Two executables are required: an operational machine that runs a configuration for a bounded number of transitions and reports the value, the number of Read steps, or a timeout; and a stage-𝑛 evaluator that computes [[⟨ℎ∣𝑒⟩]]𝑛 as an element of (𝖫(Δ(ℕ)×H))𝑛 in the normal form 𝜃𝑘(𝜂(𝑚,ℏ)) or 𝜃𝑛(⊥) of proposition 163.7, representing a stage-𝑛 heap by the finite datum computed in example 163.12 and exercise 163.1.
Invariant. The evaluator must consume exactly one stage at each 𝗀𝖾𝗍 and none at the other three transitions, and it must satisfy the restriction equation 𝑟𝑛([[⟨ℎ∣𝑒⟩]]𝑛+1)=[[⟨ℎ∣𝑒⟩]]𝑛 for every evaluated configuration; the program must check that equation and report a failure when it does not hold. This is the executable form of theorem 163.19.
Concrete result. For a configuration and a stage bound 𝑁, a report giving the machine’s outcome, the evaluator’s normal form at each stage 1,…,𝑁, and a verdict recording whether the two agree in the sense of theorem 163.23: convergence with 𝑘Read steps must match 𝜃𝑘(𝜂(𝑚,−)) for every stage above 𝑘, and a timeout at stage bound 𝑁 must match 𝜃𝑁(⊥).
Acceptance test. With 𝑁=6 the verdict must be agreement on: ⟨𝜆𝑥:ℕ.𝑥∣𝗀𝖾𝗍3――⟩, converging to 3―― with one Read; ⟨𝜆𝑥:ℕ.𝑥∣𝗌𝗎𝖼(𝗌𝗎𝖼1――)⟩, converging to 3―― with no Read; ⟨𝜆𝑥:ℕ.𝑥∣𝗌𝖾𝗍(𝜆𝑦:ℕ.𝗌𝗎𝖼𝑦;𝗀𝖾𝗍1――)⟩, converging to 2―― with one Read; and the knot ⟨ℎ∗∣𝑒∗⟩ of example 163.14, for which the evaluator must return 𝜃𝑛(⊥) at every stage 𝑛≤6 and the machine must time out. The program must also print the stage-2 stored function of example 163.21 and check that it is constantly ⊥. Produce three mutations that still run — spend a stage at 𝗌𝖾𝗍 instead of 𝗀𝖾𝗍, spend no stage at 𝗀𝖾𝗍, and drop the restriction check — and confirm that each makes at least one named case disagree. State explicitly that the program illustrates theorem 163.23 on finitely many configurations and finitely many stages, and does not prove it.