Recursive Domain Semantics and Computational Adequacy
Prerequisites. Direct starred prerequisites: none. Chapter 12 supplies domains, continuity and least fixed points; chapter 22 supplies monads, algebraic operations and their equations. No later core chapter depends on this route.
A recursive definition denotes a least fixed point, and a nonterminating program denotes ⊥. That much is a definition, not a theorem. The theorem one wants is the converse direction: if the denotation is not ⊥, the program does something. Write Ω:=𝖱𝖾𝖼(𝑓:𝜄→𝜄,𝑥:𝜄.𝑓𝑥)0,𝑃:=𝖱𝖾𝖼(𝑓:𝜄→𝜄,𝑥:𝜄.𝑥)0. Both are closed terms of type 𝜄; the first runs forever and the second returns 0. Their denotations are ⊥ and 𝜂(0). Nothing proved so far excludes a third term whose denotation is 𝜂(0) but which runs forever, and if such a term existed the semantics would be useless for reasoning about programs.
With effects the question sharpens further. A computation that may print, or choose, or fail, does not merely terminate or diverge: it produces a tree of possible behaviours, and the tree may be infinite. An adequacy theorem must therefore compare the denotation of a term with the denotation of the tree the operational semantics builds — and to have such a tree at all, one must first solve a recursive domain equation.
Fix a signature Σ of operation symbols 𝑓 with arities ar(𝑓)∈ℕ; symbols of arity 0 are written 𝑎 and called constants. Types are 𝜎,𝜏::=𝜄∣𝑜∣𝟏∣𝜎×𝜏∣𝜎→𝜏, and terms are 𝑀,𝑁::=𝑥∣0∣𝗌𝗎𝖼𝖼(𝑀)∣𝗉𝗋𝖾𝖽(𝑀)∣𝗓𝖾𝗋𝗈(𝑀)∣𝗍𝗍∣𝖿𝖿∣𝗂𝖿𝑀𝗍𝗁𝖾𝗇𝑁𝖾𝗅𝗌𝖾𝐿∣⋆∣⟨𝑀,𝑁⟩∣𝗉𝗋1(𝑀)∣𝗉𝗋2(𝑀)∣𝜆(𝑥:𝜎).𝑀∣𝑀𝑁∣𝑓(𝑀1,…,𝑀𝑛)∣𝖱𝖾𝖼(𝑓:𝜎→𝜏,𝑥:𝜎.𝑀), with 𝑛=ar(𝑓) in the operation clause. Typing is the evident simply typed discipline, with Γ⊢𝑓(𝑀1,…,𝑀𝑛):𝜎 when every Γ⊢𝑀𝑖:𝜎, and Γ⊢𝖱𝖾𝖼(𝑓:𝜎→𝜏,𝑥:𝜎.𝑀):𝜎→𝜏 when Γ,𝑓:𝜎→𝜏,𝑥:𝜎⊢𝑀:𝜏. Call 𝖯𝖢𝖥−Σ the fragment without 𝖱𝖾𝖼 and 𝖯𝖢𝖥Σ the whole language.
The operation symbols are the only source of effects, and an operation is not a function on values: 𝑓(𝑀1,…,𝑀𝑛) offers 𝑛 continuations and the semantics chooses among them.
Closed values are 𝑉::=0∣𝗌𝗎𝖼𝖼(𝑉)∣𝗍𝗍∣𝖿𝖿∣⋆∣⟨𝑉,𝑉′⟩∣𝜆(𝑥:𝜎).𝑀, with 𝑛――:=𝗌𝗎𝖼𝖼𝑛(0), and closed evaluation contexts are 𝐸::=[]∣𝗌𝗎𝖼𝖼(𝐸)∣𝗓𝖾𝗋𝗈(𝐸)∣𝗉𝗋𝖾𝖽(𝐸)∣𝗂𝖿𝐸𝗍𝗁𝖾𝗇𝑀𝖾𝗅𝗌𝖾𝑁∣⟨𝐸,𝑀⟩∣⟨𝑉,𝐸⟩∣𝗉𝗋𝑖(𝐸)∣𝐸𝑀∣𝑉𝐸. The redex transitions are 𝗓𝖾𝗋𝗈(0)⟶𝗍𝗍,𝗓𝖾𝗋𝗈(𝑛+1―――)⟶𝖿𝖿,𝗉𝗋𝖾𝖽(0)⟶0,𝗉𝗋𝖾𝖽(𝑛+1―――)⟶𝑛――,𝗉𝗋1⟨𝑉,𝑉′⟩⟶𝑉,𝗉𝗋2⟨𝑉,𝑉′⟩⟶𝑉′,(𝜆(𝑥:𝜎).𝑀)𝑉⟶𝑀[𝑉/𝑥],𝗂𝖿𝗍𝗍𝗍𝗁𝖾𝗇𝑀𝖾𝗅𝗌𝖾𝑁⟶𝑀,𝗂𝖿𝖿𝖿𝗍𝗁𝖾𝗇𝑀𝖾𝗅𝗌𝖾𝑁⟶𝑁, together with the labelled redex transition 𝑓(𝑀1,…,𝑀𝑛)𝑓𝑖⟶𝑀𝑖 for 1≤𝑖≤𝑛=ar(𝑓) and the predicate 𝑎()↓𝑎 for constants. These are closed under evaluation contexts: 𝑅⟶𝑁𝐸⟨𝑅⟩⟶𝐸⟨𝑁⟩,𝑅𝑓𝑖⟶𝑁𝐸⟨𝑅⟩𝑓𝑖⟶𝐸⟨𝑁⟩,𝐸⟨𝑎()⟩↓𝑎. For 𝖯𝖢𝖥Σ add the redex transition 𝖱𝖾𝖼(𝑓:𝜎→𝜏,𝑥:𝜎.𝑀)⟶𝜆(𝑥:𝜎).𝑀[𝖱𝖾𝖼(𝑓:𝜎→𝜏,𝑥:𝜎.𝑀)/𝑓].
Every closed well-typed term is either a value, or of the form 𝐸⟨𝑅⟩ for a unique evaluation context 𝐸 and redex 𝑅, or of the form 𝐸⟨𝑎()⟩ for a unique 𝐸 and constant 𝑎. Consequently a closed well-typed non-value 𝑀 satisfies exactly one of: 𝑀⟶𝑁 for a unique 𝑁; 𝑀𝑓𝑖⟶𝑁𝑖 for a unique 𝑓 and determined 𝑁1,…,𝑁ar(𝑓); or 𝑀↓𝑎 for a unique 𝑎. In each case the results have the same type as 𝑀.
Proof. Induction on the typing derivation of 𝑀. For each term former, the grammar of 𝐸 contains exactly one clause with a hole in the position that the transition rules inspect, and the side conditions (𝑉 before 𝐸 in ⟨𝑉,𝐸⟩ and 𝑉𝐸) make the decomposition deterministic. If the inspected subterm is already a value, the term itself is a redex or a value, which is the base case; if it is not, the induction hypothesis decomposes it and the surrounding former extends the context. Type preservation is checked clause by clause: each redex transition replaces a term by one of the same type, substitution preserves typing, and the operation clause returns an argument of the same type as the whole. ◻
Effect values and the tree a program builds
For 𝖯𝖢𝖥−Σ the tree is finite, and this is worth proving before the infinitary machinery is built.
The effect values of type 𝜎 are generated by 𝑡::=𝑉∣𝑓(𝑡1,…,𝑡𝑛) with 𝑉 a closed value of type 𝜎 and 𝑛=ar(𝑓). For a closed term 𝑀 with no infinite ⟶-chain, define |𝑀|:=⎧{
{
{
{⎨{
{
{
{⎩𝑀if𝑀isavalue,|𝑁|if𝑀⟶𝑁,𝑓(|𝑁1|,…,|𝑁𝑛|)if𝑀𝑓𝑖⟶𝑁𝑖,𝑛=ar(𝑓),𝑎()if𝑀↓𝑎.
Every closed well-typed term of 𝖯𝖢𝖥−Σ has no infinite ⟶-chain, and every branch of its transition tree ends in a value or in a constant; hence |𝑀| is defined.
Proof of Theorem 154.5 — Termination for the recursion-free fragment
Proof. Define computability predicates on closed terms by induction on types. A value of type 𝜄, 𝑜 or 𝟏 is computable. A value ⟨𝑉,𝑉′⟩ is computable when 𝑉 and 𝑉′ are. A value 𝜆(𝑥:𝜎).𝑀 is computable when 𝑀[𝑉/𝑥] is computable for every computable value 𝑉:𝜎. A closed term is computable when every transition sequence from it terminates in a computable value or in a term 𝐸⟨𝑎()⟩.
Two facts are proved simultaneously by induction on typing derivations: every closed well-typed term is computable, and every well-typed term with free variables is computable under substitution of computable values. The cases for 0, 𝗍𝗍, ⋆ and pairs are immediate. For 𝗌𝗎𝖼𝖼, 𝗉𝗋𝖾𝖽, 𝗓𝖾𝗋𝗈, 𝗉𝗋𝑖 and the conditional, the induction hypothesis gives that the scrutinee’s transition sequences terminate; by lemma 154.3 the surrounding context then exposes a redex whose transition is one of the displayed clauses, and the result is again computable, in the conditional case by the induction hypothesis for the chosen branch. For application, the induction hypothesis makes the function’s sequences terminate at a computable 𝜆(𝑥:𝜎).𝑀 and the argument’s at a computable 𝑉, and computability of the abstraction gives computability of 𝑀[𝑉/𝑥]. For 𝑓(𝑀1,…,𝑀𝑛), the term is already a redex: each labelled transition leads to some 𝑀𝑖, computable by hypothesis, and the branching is finite because ar(𝑓) is. Since every branch is finite and branching is finite, König’s lemma gives that the whole tree is finite. ◻
Proof of Proposition 154.6 — Two descriptions of |M| agree
Proof.(⇒) Induction on the finite transition tree of 𝑀, whose finiteness is theorem 154.5; each clause of definition 154.4 matches one rule. (⇐) Induction on the derivation of 𝑀⇓𝑡: each rule has strictly smaller subderivations for the continuations, and the second rule reduces the term, so the derivation exhibits a finite tree and the value it computes is exactly |𝑀|. Determinacy of the first two cases is lemma 154.3. ◻
The recursive domain equation for effect trees
With 𝖱𝖾𝖼 the transition tree can be infinite, and |𝑀| must be an infinite tree. Infinite trees are not generated by any grammar; they are the solution of a domain equation, and this section solves it.
A dcpo is a poset with least upper bounds of directed subsets; a dcppo is a dcpo with a least element ⊥. A function is continuous when it is monotone and preserves directed suprema, and strict when it preserves ⊥. We write 𝑥⊑𝖣𝑦 for the order. A continuous Σ-algebra is a dcppo 𝐷 with a continuous 𝑓𝐷:𝐷ar(𝑓)→𝐷 for each 𝑓∈Σ; morphisms are strict continuous functions commuting with the operations.
For a set 𝑋 define a chain of posets 𝑇0⊑𝖣𝑇1⊑𝖣⋯ by 𝑇0:={⊥},𝑇𝑘+1:={⊥}∪𝑋∪{𝑓(⃗𝑡)∣𝑓∈Σ,𝑡𝑖∈𝑇𝑘(𝑖≤ar(𝑓))}, ordered by: ⊥ least; distinct elements of 𝑋 incomparable and maximal in their level; and 𝑓(⃗𝑡)⊑𝖣𝑔(⃗𝑢) iff 𝑓=𝑔 and 𝑡𝑖⊑𝖣𝑢𝑖 for all 𝑖. Let 𝑒𝑘:𝑇𝑘→𝑇𝑘+1 be the inclusion and 𝑝𝑘:𝑇𝑘+1→𝑇𝑘 the truncation replacing every subtree at depth 𝑘 by ⊥. Define CTΣ(𝑋):={(𝑡𝑘)𝑘∈ℕ∣𝑡𝑘∈𝑇𝑘,𝑝𝑘(𝑡𝑘+1)=𝑡𝑘}, ordered componentwise.
Proof. Monotonicity of 𝑒𝑘 is immediate. For 𝑝𝑘, truncation is defined by recursion on depth and preserves the three order clauses. The first equation holds because truncating at depth 𝑘 an element already of depth at most 𝑘 changes nothing. For the inequality, truncation only replaces subtrees by ⊥, which is smaller. ◻
CTΣ(𝑋) is a dcppo; the map Θ:{⊥}∪𝑋∪∐𝑓∈ΣCTΣ(𝑋)ar(𝑓)→CTΣ(𝑋) sending ⊥ to the constantly-⊥ sequence, 𝑥∈𝑋 to the sequence (⊥,𝑥,𝑥,…), and 𝑓(⃗𝑢) to the sequence whose (𝑘+1)st component is 𝑓(𝑢1𝑘,…,𝑢𝑛𝑘), is an order isomorphism onto its image and makes CTΣ(𝑋) the free continuous Σ-algebra on 𝑋: for every continuous Σ-algebra 𝐷 and every function ℎ:𝑋→𝐷 there is a unique strict continuous Σ-homomorphism ˆℎ:CTΣ(𝑋)→𝐷 with ˆℎ∘𝜂=ℎ, where 𝜂(𝑥):=Θ(𝑥).
Proof of Theorem 154.10 — The tree domain solves its equation
Proof.Dcppo. A directed set of sequences has componentwise suprema, and each 𝑇𝑘 is a finite-height poset in which every directed subset with a common shape has a supremum: two elements of 𝑇𝑘 with an upper bound have the same head, so a directed subset is either {⊥}-cofinal or has a common head, and the supremum is computed headwise by induction on 𝑘. Compatibility with 𝑝𝑘 is preserved by suprema because 𝑝𝑘 is monotone and, being defined by truncation, preserves the headwise suprema just described. The constantly-⊥ sequence is least.
Isomorphism. A compatible sequence (𝑡𝑘) has 𝑡0=⊥ and, if 𝑡1≠⊥, a determined head that is either an element of 𝑋 — in which case every later component is that element — or an operation symbol 𝑓, in which case the components of the 𝑛 argument sequences are 𝑡𝑘+1’s arguments and are themselves compatible. This is exactly the inverse of Θ, and both directions are monotone.
Freeness. Given ℎ:𝑋→𝐷 define ˆℎ(𝑡):=⨆𝑘ℎ𝑘(𝑡𝑘) where ℎ𝑘:𝑇𝑘→𝐷 is defined by ℎ0(⊥)=⊥, ℎ𝑘+1(⊥)=⊥, ℎ𝑘+1(𝑥)=ℎ(𝑥) and ℎ𝑘+1(𝑓(⃗𝑡))=𝑓𝐷(ℎ𝑘(𝑡1),…,ℎ𝑘(𝑡𝑛)). Each ℎ𝑘 is monotone and ℎ𝑘=ℎ𝑘+1∘𝑒𝑘, so the family is increasing along the sequence and the supremum exists. Strictness and preservation of the operations are read off from the clauses, and continuity holds because directed suprema in CTΣ(𝑋) are computed componentwise and each 𝑓𝐷 is continuous. Uniqueness: a strict continuous homomorphism 𝑔 with 𝑔∘𝜂=ℎ agrees with ˆℎ on every element of finite depth by induction on that depth, and every 𝑡 is the directed supremum ⨆𝑘Θ-image of its truncations, so continuity forces 𝑔=ˆℎ. ◻
Write 𝑀⇓𝑉 for 𝑀⟶∗𝑉 with 𝑉 a value, 𝑀⇓𝑓𝑖𝑁 when 𝑀⟶∗𝐿𝑓𝑖⟶𝑁 for some 𝐿, 𝑀⇓𝑎 when 𝑀⟶∗𝐿↓𝑎, and 𝑀↑ when there is an infinite ⟶-chain from 𝑀. For a closed term 𝑀:𝜎 define |𝑀|∈CTΣ(Val𝜎) by its approximants |𝑀|(0):=⊥ and |𝑀|(𝑘+1):=⎧{
{
{
{⎨{
{
{
{⎩𝑉if𝑀⇓𝑉,𝑓(|𝑁1|(𝑘),…,|𝑁𝑛|(𝑘))if𝑀⇓𝑓𝑖𝑁𝑖,𝑛=ar(𝑓),𝑎()if𝑀⇓𝑎,⊥if𝑀↑.
The four cases of definition 154.11 are exhaustive and mutually exclusive, the family (|𝑀|(𝑘))𝑘 is compatible, and |𝑀|=⎧{
{
{
{⎨{
{
{
{⎩𝑉𝑀=𝑉,|𝑁|𝑀⟶𝑁,𝑓(|𝑁1|,…,|𝑁𝑛|)𝑀𝑓𝑖⟶𝑁𝑖,𝑎()𝑀=𝐸⟨𝑎()⟩. Moreover |−| is the least function satisfying that equation in the pointwise order.
Proof of Lemma 154.12 — | | is well defined and satisfies its equation
Proof. Exhaustiveness and exclusivity: by lemma 154.3 the ⟶-chain from 𝑀 is deterministic, so it is either infinite — the fourth case — or ends in a value, a labelled redex, or a constant, which are the first three. Compatibility: truncating |𝑀|(𝑘+1) at depth 𝑘 gives |𝑀|(𝑘) by induction on 𝑘, since each clause applies the same case analysis one level down. The displayed equation is the case analysis read at the level of the whole tree, using that unlabelled steps do not change the medium-step behaviour. Leastness: let 𝑔 be any solution of the displayed equation. Then |𝑀|(𝑘)⊑𝖣𝑔(𝑀) for every 𝑘, by induction on 𝑘: at 𝑘=0 because ⊥ is least, and at 𝑘+1 because the clause defining |𝑀|(𝑘+1) and the clause of the equation for 𝑔 have the same head, with the induction hypothesis applied to the arguments. Hence |𝑀|=⨆𝑘|𝑀|(𝑘)⊑𝖣𝑔(𝑀). ◻
Let C be a cartesian closed category that is 𝐃𝐜𝐩𝐨-enriched, let 𝑇 be a strong monad on C whose Kleisli category C𝑇 is 𝐃𝐜𝐩𝐩𝐨-enriched with strict strength, and assume C has a natural numbers object 10⟶𝑁𝑠⟶𝑁 and the coproduct 𝕋:=1+1. For each 𝑓∈Σ assume a family 𝑓𝑥:𝑇(𝑥)ar(𝑓)→𝑇(𝑥)(𝑥∈C) that is algebraic: natural with respect to Kleisli maps, that is 𝑔†∘𝑓𝑥=𝑓𝑦∘(𝑔†)ar(𝑓) for every 𝑔:𝑥→𝑇(𝑦). Write 𝜂 and (−)† for the unit and Kleisli extension.
Put [[𝜄]]:=𝑁, [[𝑜]]:=𝕋, [[𝟏]]:=1, [[𝜎×𝜏]]:=[[𝜎]]×[[𝜏]] and [[𝜎→𝜏]]:=[[𝜎]]⇒𝑇[[𝜏]], and interpret a context by the product of its types. Terms receive [[𝑀]]:[[Γ]]→𝑇[[𝜎]] by the standard call-by-value clauses, with [[𝑓(𝑀1,…,𝑀𝑛)]]:=𝑓[[𝜎]]∘⟨[[𝑀1]],…,[[𝑀𝑛]]⟩,[[𝗂𝖿𝐿𝗍𝗁𝖾𝗇𝑀𝖾𝗅𝗌𝖾𝑁]]:=cond†[[𝜎]]∘⟨⟨[[𝑀]],[[𝑁]]⟩,[[𝐿]]⟩, where cond𝑧:𝑇(𝑧)2×𝕋→𝑧 in C𝑇 corresponds to the pair of projections under the isomorphisms C𝑇(𝑦,𝑧)2≅C(1,𝑦⇒𝑧)2≅C(𝕋,𝑦⇒𝑧)≅C𝑇(𝑦×𝕋,𝑧), and with [[𝖱𝖾𝖼(𝑓:𝜎→𝜏,𝑥:𝜎.𝑀)]]:=𝑌(𝑔↦𝜆𝑇[[𝑀]]∘⟨id[[Γ]],𝑔⟩),𝑌(𝐺):=⨆𝑛≥0𝐺𝑛(⊥).
Proof. Induction on 𝑉. The constants 0, 𝗍𝗍, 𝖿𝖿, ⋆ are interpreted by 𝜂 after a map into the corresponding object. 𝗌𝗎𝖼𝖼(𝑉) is 𝜂∘𝑠 applied to the factorization for 𝑉. A pair is the pairing of two factorizations followed by 𝜂, using that 𝜂 is monoidal for the strength. An abstraction is interpreted by 𝜂 after currying, since currying produces a C-map into the exponential. No clause introduces (−)†, and 𝑓𝑥 occurs in no value. ◻
Let the equational theory contain the 𝛽-equations of definition 154.2 read as equations, the algebraicity schema 𝐸⟨𝑓(𝑀1,…,𝑀𝑛)⟩=𝑓(𝐸⟨𝑀1⟩,…,𝐸⟨𝑀𝑛⟩), and, for 𝖯𝖢𝖥Σ, the unfolding equation for 𝖱𝖾𝖼. Then Γ⊢𝑀≡𝑁:𝜎 implies [[𝑀]]=[[𝑁]].
Proof. Each 𝛽-equation is verified by unfolding the clauses of definition 154.14 and using the monad laws; lemma 154.15 is what makes the substitution 𝑀[𝑉/𝑥] correspond to precomposition rather than to a Kleisli extension. The algebraicity schema is exactly the naturality assumption of convention 154.13: interpreting an evaluation context yields a Kleisli map 𝑔, and the schema becomes 𝑔†∘𝑓=𝑓∘(𝑔†)𝑛. The unfolding equation holds because 𝑌(𝐺)=𝐺(𝑌(𝐺)) for the least fixed point of a continuous 𝐺, and 𝐺 is continuous since composition and currying are continuous in the enrichment. ◻
Proof of Theorem 154.17 — Adequacy, recursion-free
Proof. By theorem 154.5 and proposition 154.6, 𝑀⇓|𝑀|. An induction on that derivation, using the corresponding equations of lemma 154.16 at each rule, gives ⊢𝑀=|𝑀|:𝜎 in the equational theory; and lemma 154.16 turns that into [[𝑀]]=[[|𝑀|]]. ◻
Adequacy with recursion
Recursion breaks the argument of theorem 154.17: there is no finite derivation of 𝑀⇓|𝑀| to induct on. One inequality survives; the other is obtained by approximating the recursion syntactically.
Proof of Lemma 154.18 — Interpretation of infinitary effect values
Proof.C𝑇(1,[[𝜎]]) is a dcppo by convention 154.13 and carries a continuous ar(𝑓)-ary operation for each 𝑓, induced by 𝑓[[𝜎]]; so it is a continuous Σ-algebra. Apply the freeness clause of theorem 154.10 to ℎ(𝑉):=[[𝑉]]. ◻
Proof. Induction on 𝑘. For 𝑘=0 the left side is ⊥. For 𝑘+1 examine the four cases of definition 154.11. If 𝑀⇓𝑉 then 𝑀⟶∗𝑉, and each unlabelled step is an instance of an equation of lemma 154.16, so [[𝑀]]=[[𝑉]]. If 𝑀⇓𝑓𝑖𝑁𝑖 then likewise [[𝑀]]=[[𝑓(𝑁1,…,𝑁𝑛)]]=𝑓[[𝜎]]([[𝑁1]],…,[[𝑁𝑛]]), and the induction hypothesis together with monotonicity of 𝑓[[𝜎]] gives the claim. If 𝑀⇓𝑎 then [[𝑀]]=[[𝑎()]]. If 𝑀↑ the left side is ⊥. The final statement follows because [[−]] is continuous by lemma 154.18 and |𝑀|=⨆𝑘|𝑀|(𝑘). ◻
Let A extend 𝖯𝖢𝖥−Σ by constants Ω𝜎:𝜎 and by 𝖱𝖾𝖼𝑛(𝑓:𝜎→𝜏,𝑥:𝜎.𝑀):𝜎→𝜏 for 𝑛∈ℕ, with redex transitions 𝖱𝖾𝖼𝑛+1(𝑓,𝑥.𝑀)⟶𝜆(𝑥:𝜎).𝑀[𝖱𝖾𝖼𝑛(𝑓,𝑥.𝑀)/𝑓],𝖱𝖾𝖼0(𝑓,𝑥.𝑀)⟶𝜆(𝑥:𝜎).Ω𝜏, and with [[Ω𝜎]]:=⊥ and [[𝖱𝖾𝖼𝑛]] the 𝑛th approximant 𝐺𝑛(⊥) of definition 154.14. Define 𝑀′≺𝑀, for 𝑀′ a term of A and 𝑀 a term of 𝖯𝖢𝖥Σ of the same type, to be the compatible closure of: Ω𝜎≺𝑀 for every 𝑀:𝜎, and 𝖱𝖾𝖼𝑛(𝑓,𝑥.𝑀′)≺𝖱𝖾𝖼(𝑓,𝑥.𝑀) whenever 𝑀′≺𝑀.
Proof. Repeat the computability argument of theorem 154.5, saying now that a closed term is computable when every transition sequence from it terminates in a computable value or in a term 𝐸⟨𝑎()⟩ or 𝐸⟨Ω𝜏⟩. The only new cases are the two 𝖱𝖾𝖼𝑛 clauses. For 𝖱𝖾𝖼0 the reduct is an abstraction whose body is Ω𝜏, computable because every sequence from Ω𝜏 is already stuck in the required form. For 𝖱𝖾𝖼𝑛+1 the reduct is an abstraction whose body mentions 𝖱𝖾𝖼𝑛, computable by an inner induction on 𝑛. ◻
if 𝑀′ is a value then so is 𝑀, and their immediate subterms are again related;
if 𝑀′=𝐸′⟨𝑅′⟩ for a redex 𝑅′ that is not Ω𝜏, then 𝑀=𝐸⟨𝑅⟩ with 𝐸′≺𝐸 and 𝑅′≺𝑅, and 𝑅′⟶𝑁′ implies 𝑅⟶𝑁 with 𝑁′≺𝑁, and similarly for labelled transitions and for ↓𝑎.
Proof. Induction on the derivation of 𝑀′≺𝑀. The relation is defined by compatible closure, so a value on the left forces the same outermost former on the right except in the two base cases, and Ω is not a value. For the second clause, the grammar of evaluation contexts is the same in both languages, so the unique decomposition of lemma 154.3 on the left is matched on the right former by former. The transition clauses are checked one by one; the only interesting one is 𝖱𝖾𝖼𝑛+1(𝑓,𝑥.𝑀′)⟶𝜆(𝑥:𝜎).𝑀′[𝖱𝖾𝖼𝑛/𝑓], whose right-hand counterpart unfolds 𝖱𝖾𝖼 once, and 𝖱𝖾𝖼𝑛≺𝖱𝖾𝖼 holds by definition, so the substituted bodies remain related because ≺ is closed under substitution of related terms. ◻
If 𝑀′≺𝑀 with 𝑀′ closed then |𝑀′|⊑𝖣|𝑀| in CTΣ(Val𝜎), where |𝑀′| is computed in A with |𝐸⟨Ω𝜏⟩|:=⊥. Moreover |𝑀|=⨆{|𝑀′|∣𝑀′≺𝑀,𝑀′closed}, and the set on the right is directed.
Proof of Proposition 154.23 — Approximants of the tree
Proof. The inequality is proved by induction on the length of the terminating A-sequence supplied by lemma 154.21, using lemma 154.22 at each step: a value on the left forces the same value on the right; a stuck Ω contributes ⊥; and a labelled step is matched, so the heads agree and the induction hypothesis applies to the arguments. Directedness: given 𝑀′1,𝑀′2≺𝑀, replace every 𝖱𝖾𝖼𝑛𝑖 by 𝖱𝖾𝖼max(𝑛1,𝑛2) and every Ω by the corresponding subterm of the other approximant where it is not Ω; the result is an upper bound below 𝑀. For the supremum, it suffices to produce, for each 𝑘, an 𝑀′≺𝑀 with |𝑀|(𝑘)⊑𝖣|𝑀′|; take 𝑀′ to be 𝑀 with every 𝖱𝖾𝖼 replaced by 𝖱𝖾𝖼𝑘, which by lemma 154.22 matches the first 𝑘 levels of the transition tree. ◻
Proof.[[|𝑀|]]⊑𝖣[[𝑀]] is lemma 154.19. For the converse, definition 154.14 interprets each 𝖱𝖾𝖼 by a directed supremum of its approximants, and composition, pairing, currying and (−)† are continuous in the enrichment of convention 154.13; hence [[𝑀]]=⨆{[[𝑀′]]∣𝑀′≺𝑀closed}. Each 𝑀′ is a term of A, which is recursion-free by lemma 154.21, so theorem 154.17 applies verbatim with the extra clause [[Ω𝜎]]=⊥=[[|Ω𝜎|]] and gives [[𝑀′]]=[[|𝑀′|]]. By proposition 154.23 the family {|𝑀′|} is directed with supremum |𝑀|, and [[−]] on trees is continuous by lemma 154.18. Combining, [[𝑀]]=⨆𝑀′≺𝑀[[𝑀′]]=⨆𝑀′≺𝑀[[|𝑀′|]]=[[⨆𝑀′≺𝑀|𝑀′|]]=[[|𝑀|]]. ◻
Two instances, and the theorem one expected
Theorem 154.24 equates two denotations. The statement usually called adequacy compares a denotation with an observation, and it follows.
Take C=𝐒𝐞𝐭, 𝑇 the nonempty finite powerset monad F+ with Σ={𝗈𝗋} of arity 2 and 𝗈𝗋𝑋 binary union. Then F+(𝑋) is the free semilattice on 𝑋, and 𝗈𝗋 is algebraic in the sense of convention 154.13. Define the usual nondeterministic evaluation 𝑀⇓𝗇𝑉 by replacing the labelled clause with 𝑀1𝗈𝗋𝑀2⟶𝗇𝑀𝑖. Assigning to each finite effect value the set ℎ(𝑉):={𝑉}, ℎ(𝑡𝗈𝗋𝑡′):=ℎ(𝑡)∪ℎ(𝑡′), one has 𝑀⇓𝗇𝑢 if and only if 𝑢=ℎ(𝑡) for the 𝑡 with 𝑀⇓𝑡.
Proof of Corollary 154.26 — Adequacy for nondeterminism
Proof.[[𝑀]](∗)=[[|𝑀|]](∗) by theorem 154.17. Since [[−]] on effect values is the unique Σ-homomorphism and 𝗈𝗋 is union, [[𝑡]](∗)=⋃𝑉∈ℎ(𝑡)[[𝑉]](∗) by induction on 𝑡. Finally ℎ(|𝑀|)={𝑉∣𝑀⇓𝗇𝑉} by example 154.25. ◻
Let 𝜎 be 𝜄 or 𝑜 and let 𝑀:𝜎 be closed in 𝖯𝖢𝖥Σ. In the nondeterministic instance extended with recursion, 𝑥∈[[𝑀]](∗) if and only if 𝑀 can evaluate to the value denoting 𝑥. In particular [[𝑀]](∗)=∅ if and only if every computation from 𝑀 diverges.
Proof of Corollary 154.27 — The ground-type statement
Proof. At a ground type distinct values have distinct denotations and every element of the interpreting set is the denotation of exactly one value, so the Σ-homomorphism of lemma 154.18 sends a tree to the set of values labelling its leaves, with ⊥ contributing nothing. Now apply theorem 154.24 and read off both directions. ◻
★★☆ Show by an explicit counterexample that lemma 154.16 fails if the naturality requirement on 𝑓𝑥 in convention 154.13 is dropped: give a monad, an operation family that is natural in C but not with respect to Kleisli maps, and an evaluation context for which the algebraicity schema is unsound.
★★☆ Prove that the truncation maps 𝑝𝑘 of construction 154.8 are continuous, and that CTΣ(𝑋) with 𝑋 a singleton and Σ a single unary symbol is order-isomorphic to ℕ∪{∞} with its usual order. Which clause of theorem 154.10 does the second part illustrate?
★★☆ Show that the inequality of lemma 154.19 can be strict before the supremum is taken, by exhibiting 𝑀 and 𝑘 with [[|𝑀|(𝑘)]] strictly below [[𝑀]]. Then explain why no single 𝑘 suffices, and locate the step of theorem 154.24 that repairs this.
The theorem proved is theorem 154.24: the denotation of a term equals the denotation of the effect tree its operational semantics builds. Four restrictions are part of the statement and none may be dropped silently. The signature Σ is fixed and its operations are algebraic (convention 154.13); handlers, which are not algebraic, are outside the theorem. The semantic setting is fixed: a 𝐃𝐜𝐩𝐨-enriched cartesian closed category with a strong monad whose Kleisli category is 𝐃𝐜𝐩𝐩𝐨-enriched with strict strength; without strictness of the strength the interpretation of 𝖱𝖾𝖼 is not the least fixed point computed above. The observation is fixed: corollary 154.27 is stated at ground types, and at higher types the equality of theorem 154.24 is an equality of denotations, not a statement about contexts. And the language is simply typed: nothing here concerns dependent families, whose reindexing over equality evidence is a separate construction with its own hypotheses and which donates no theorem to this chapter and receives none from it.
The proof base is Plotkin and Power’s account of adequacy for algebraic effects, whose language, effect values, tree domain, approximation language and two adequacy theorems are followed above; the domain-theoretic prerequisites are standard [AJ94], the operational background is [Har16, Plo77], and the algebraic view of effects with its equational presentations is [PP03, PP13]. The handler material in the last of these is cited for context only; no handler is interpreted here.
★★★ Instantiate convention 154.13 with C=𝐒𝐞𝐭 and 𝑇 the finite probability distribution monad, Σ containing one binary symbol 𝖼𝗁𝗈𝗈𝗌𝖾 interpreted as the fair convex combination. Verify algebraicity, define the analogue of ℎ from example 154.25, and state and prove the analogue of corollary 154.26. Then explain why the recursion-free restriction matters for your proof and what would have to change to remove it.
★★★ Give a strong monad on 𝐃𝐜𝐩𝐨 and an operation family for which the conclusion of theorem 154.24 fails, by violating exactly one clause of convention 154.13. Identify the first step of the proof that breaks and show the resulting counterexample term.
★★☆Lemma 154.12 asserts that |−| is the least solution of its equation. Exhibit a second, strictly larger solution for a signature with one constant, and say which operational fact rules it out as a description of evaluation.
★★★Practical project.effect-tree-evaluator Implement, for a fixed finite signature Σ with one binary symbol and one constant, the small-step machine of definition 154.2 for 𝖯𝖢𝖥Σ together with the fuel-bounded computation of the approximants |𝑀|(𝑘) of definition 154.11. The invariant the program must maintain is that the printed tree of depth 𝑘 is exactly |𝑀|(𝑘): every unlabelled step is silent, every labelled step branches, a stuck constant is a leaf, and exhausted fuel prints ⊥. The program must print, for each named input, the decomposition 𝐸⟨𝑅⟩ found at the first step, the approximant tree at a requested depth, and the finite set of value leaves. The acceptance test is: the term 𝑃 of the chapter opening prints the one-leaf tree 0 at every depth 𝑘≥1; the term Ω prints ⊥ at every depth; the term 𝗈𝗋(0,𝗌𝗎𝖼𝖼(0)) prints a two-leaf tree whose leaf set is {0,1――}, matching corollary 154.26; and a term whose recursion is guarded by an operation prints strictly growing trees as 𝑘 increases, matching the directedness in proposition 154.23. A fuel-bounded evaluator computes approximants only; it does not compute |𝑀|, and it proves neither theorem 154.24 nor corollary 154.27.