Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Contextual modal objects
An LF derivation under assumptions is not determined by its conclusion alone. For example, a derivation object for 𝑥 :𝐴 ⊢𝗌𝗍𝑥 :𝐴 may use 𝑥, whereas a closed object of the same object type may not. Reifying only the term loses this distinction. A contextual type records both the term’s type and the exact open context.
The simply typed contextual modal calculus has two variable levels: Ψ,Γ::=⋅∣Γ,𝑥:𝐴,Δ::=⋅∣Δ,𝑢::𝐴[Ψ],𝐴,𝐵::=𝑎∣𝐴→𝐵∣[Ψ⊢𝐴]. Ordinary variables 𝑥 are declared in Γ; meta-variables 𝑢 stand for open objects and are declared in the modal context Δ. Terms and explicit contextual substitutions are 𝑀,𝑁::=𝑥∣𝜆(𝑥:𝐴).𝑀∣𝑀𝑁∣𝖻𝗈𝗑(Ψ.𝑀)∣𝗅𝖾𝗍𝖻𝗈𝗑(𝑀,𝑢.𝑁)∣𝖼𝗅𝗈(𝑢,𝜎),𝜎::=⋅∣𝜎,𝑀/𝑥. The family [Ψ ⊢𝐴] is a contextual type: its elements are terms of type 𝐴 whose free ordinary variables are declared by Ψ.
Referenced from 6 locations
The ordinary STLC rules carry the two contexts Δ;Γ. The contextual rules are Δ;Ψ⊢𝑀:𝐴Δ;Γ⊢𝖻𝗈𝗑(Ψ.𝑀):[Ψ⊢𝐴]Ctx−I Δ;Γ⊢𝑀:[Ψ⊢𝐴]Δ,𝑢::𝐴[Ψ];Γ⊢𝑁:𝐶Δ;Γ⊢𝗅𝖾𝗍𝖻𝗈𝗑(𝑀,𝑢.𝑁):𝐶Ctx−E 𝑢::𝐴[Ψ]∈ΔΔ;Γ⊢𝜎:ΨΔ;Γ⊢𝖼𝗅𝗈(𝑢,𝜎):𝐴Meta. Rule Ctx-I discards the ambient ordinary context Γ: only declarations in Ψ may occur in the boxed body. Rule Meta restores an occurrence of the open object by giving one term for every declaration in Ψ.
If 𝑢 ::𝐴[𝑥 :𝐴], then Δ; 𝑦:𝐴⊢𝖻𝗈𝗑(𝑧:𝐴.𝖼𝗅𝗈(𝑢,𝑧/𝑥)):[𝑧:𝐴⊢𝐴]. The closure instantiates the formal variable 𝑥 of 𝑢 by the boxed variable 𝑧. The ambient 𝑦 is intentionally unavailable inside the box. Thus 𝖻𝗈𝗑(𝑧 :𝐴.𝑦) is rejected when 𝑦 belongs only to the ambient context: Ctx-I checks its body under 𝑧 :𝐴, not under 𝑦 :𝐴,𝑧 :𝐴.
Referenced from 2 locations
★☆☆ In the modal context 𝑢 ::𝐴[𝑥 :𝐴] and ambient ordinary context 𝑦 :𝐴, derive the type of 𝖻𝗈𝗑(𝑧 :𝐴.𝖼𝗅𝗈(𝑢,𝑧/𝑥)) rule by rule. Then replace the body by 𝑦 and identify the first premise that fails. (Eight lines.)
Referenced from 3 locations
The following operations preserve typing:
if Δ;Γ ⊢𝑀 :𝐴 and Δ;Γ,𝑥 :𝐴,Γ′ ⊢𝑁 :𝐶, then Δ;Γ,Γ′ ⊢𝑁[𝑀/𝑥] :𝐶;
if Δ;Ψ ⊢𝑀 :𝐴 and Δ,𝑢 ::𝐴[Ψ],Δ′;Γ ⊢𝑁 :𝐶, then Δ,Δ′;Γ ⊢𝑁[Ψ.𝑀/𝑢] :𝐶;
if Δ;Γ ⊢𝜎 :Ψ and Δ;Ψ ⊢𝑀 :𝐴, then Δ;Γ ⊢𝑀[𝜎] :𝐴.
In the second operation, 𝖼𝗅𝗈(𝑢,𝜏)[Ψ.𝑀/𝑢]:=𝑀[𝜏[Ψ.𝑀/𝑢]/Ψ]; the inner operation recursively substitutes in every component of 𝜏. Substitution for a meta-variable therefore performs the postponed contextual substitution with those transformed components rather than constructing an ill-formed expression 𝖼𝗅𝗈(𝑀,𝜏).
Referenced from 2 locations
Proof of Proposition 63.3 — Ordinary and contextual substitution
Proof. Each clause is an induction on the second displayed typing derivation. Ordinary substitution commutes with every constructor except 𝖻𝗈𝗑(Ψ.𝑁), whose body contains no free ambient ordinary variable; that form is unchanged. Simultaneous substitution extends beneath a lambda by the identity component for its bound variable.
For contextual substitution, the principal Meta case has head 𝑢. The substitution 𝜏 :Ψ is typed in the extended modal context Δ,𝑢 ::𝐴[Ψ],Δ′. The induction hypotheses applied to its components give 𝜏[Ψ.𝑀/𝑢] :Ψ in Δ,Δ′. Simultaneous substitution then derives 𝑀[𝜏[Ψ.𝑀/𝑢]/Ψ] :𝐴, exactly the required result. A different meta-variable rebuilds its closure after applying the induction hypotheses to its substitution components. In the Ctx-E case, choose the bound meta-variable outside the finite set of meta-variables in 𝑀 and reapply the rule. The remaining cases commute with the operation. These cases also prove the third clause componentwise. ◻
The two principal reductions and two commuting conversions are (𝜆(𝑥:𝐴).𝑀)𝑁⟶beta𝑀[𝑁/𝑥],𝗅𝖾𝗍𝖻𝗈𝗑(𝖻𝗈𝗑(Ψ.𝑀),𝑢.𝑁)⟶box𝑁[Ψ.𝑀/𝑢],𝗅𝖾𝗍𝖻𝗈𝗑(𝑀,𝑢.𝑁)𝑃⟶comm𝗅𝖾𝗍𝖻𝗈𝗑(𝑀,𝑢.𝑁𝑃),𝗅𝖾𝗍𝖻𝗈𝗑(𝗅𝖾𝗍𝖻𝗈𝗑(𝑀,𝑣.𝑁),𝑢.𝑃)⟶comm𝗅𝖾𝗍𝖻𝗈𝗑(𝑀,𝑣.𝗅𝖾𝗍𝖻𝗈𝗑(𝑁,𝑢.𝑃)), with the bound meta-variable in each commuting conversion chosen outside the free meta-variables of the moved term.
Proof of Theorem 63.4 — Simply typed CMTT metatheory
Proof. For subject reduction, invert the final typing rule at each principal redex. The beta case uses ordinary substitution; the box case uses contextual substitution; the commuting cases use weakening and rebuild Ctx-E.
For strong normalization, import Theorem 4.7(2) of Nanevski, Pfenning, and Pientka for the exact simply typed contextual modal syntax, typing judgments, principal reductions, and commuting conversions displayed here [NPP08]. Its interpretation theorem maps [Ψ ⊢𝐴] to two copies of the function type from the translations of Ψ to the translation of 𝐴, maps 𝖻𝗈𝗑 to a sum injection, and maps 𝗅𝖾𝗍𝖻𝗈𝗑 to sum elimination. Theorem 4.7(1) proves that every source principal or commuting step maps to one or more target steps; Theorem 4.7(2) concludes directly that their union is strongly normalizing on well-typed source terms. Its proof imports de Groote’s strong normalization theorem for the simply typed lambda calculus with binary sums, beta-reduction, and the two case-permutation conversions. We use the stated source theorem rather than treating that target result as a local lemma. The source theorem treats meta-level application of explicit substitutions as one operation; it does not establish strong normalization for an arbitrary explicit-substitution calculus. ◻
Canonical dependent contextual objects
Dependent LF needs unique canonical forms, whereas the commuting conversions above admit several syntactic placements of 𝗅𝖾𝗍𝖻𝗈𝗑. The canonical dependent calculus therefore has only normal and atomic terms and performs substitution hereditarily.
Extend canonical LF with contextual products ∏𝑢::𝐴[Ψ]𝐵 and with meta-variables declared 𝑢 ::𝐴[Ψ]. If Ψ =𝑥1 :𝐴1,…,𝑥𝑛 :𝐴𝑛, write ̂Ψ:=𝑥1,…,𝑥𝑛 for its list of variable names with the types erased. Normal terms include 𝗆𝗅𝖺𝗆(𝑢.𝑀); atomic terms include contextual application 𝗆𝖺𝗉𝗉(𝑅,̂Ψ.𝑁). Otherwise normal terms are ordinary lambdas or atomic terms, and atomic terms are headed by an ordinary variable, a constant, or a closure 𝖼𝗅𝗈(𝑢,𝜎). Typing is bidirectional: normal terms check against a given canonical family, while atomic terms synthesize a canonical family.
Hereditary substitution is written postfix using the global substitution notation: for example, (𝐵[̂Ψ.𝑁/𝑢])𝑎𝐴[Ψ] substitutes the contextual object ̂Ψ.𝑁 for 𝑢 in the type 𝐵, using 𝐴[Ψ] as termination index. The superscripts 𝑛, 𝑎, 𝛾, and 𝛿 key the mutually defined operations on normal terms, types, ordinary contexts, and modal contexts. For a simultaneous substitution 𝜎, the corresponding notation is (𝐵[𝜎])𝑎Ψ, with the same superscript keys.
The modal context, contextual product, meta-abstraction, and contextual application rules are ⊢Δ 𝗆𝖼𝗍𝗑Δ⊢Ψ 𝖼𝗍𝗑Δ;Ψ⊢𝐴⇐𝗍𝗒𝗉𝖾⊢Δ,𝑢::𝐴[Ψ] 𝗆𝖼𝗍𝗑MCtx Δ⊢Ψ 𝖼𝗍𝗑Δ;Ψ⊢𝐴⇐𝗍𝗒𝗉𝖾Δ,𝑢::𝐴[Ψ];Γ⊢𝐵⇐𝗍𝗒𝗉𝖾Δ;Γ⊢∏𝑢::𝐴[Ψ]𝐵⇐𝗍𝗒𝗉𝖾MPi Δ,𝑢::𝐴[Ψ];Γ⊢𝑀⇐𝐵Δ;Γ⊢𝗆𝗅𝖺𝗆(𝑢.𝑀)⇐∏𝑢::𝐴[Ψ]𝐵MLam Δ;Γ⊢𝑅⇒∏𝑢::𝐴[Ψ]𝐵Δ;Ψ⊢𝑁⇐𝐴Δ;Γ⊢𝗆𝖺𝗉𝗉(𝑅,̂Ψ.𝑁)⇒(𝐵[̂Ψ.𝑁/𝑢])𝑎𝐴[Ψ]MApp. Closures and simultaneous substitutions are checked by the following four rules; the second extension form records an atomic component with 𝑅//𝑥: Δ,𝑢::𝐴[Ψ],Δ′;Γ⊢𝜎⇐ΨΔ,𝑢::𝐴[Ψ],Δ′;Γ⊢𝖼𝗅𝗈(𝑢,𝜎)⇒(𝐴[𝜎])𝑎ΨMVar 𝑋Δ;Γ⊢⋅⇐⋅SNilΔ;Γ⊢𝜎⇐ΨΔ;Γ⊢𝑀⇐(𝐴[𝜎])𝑎ΨΔ;Γ⊢𝜎,𝑀/𝑥⇐Ψ,𝑥:𝐴SNorm Δ;Γ⊢𝜎⇐ΨΔ;Γ⊢𝑅⇒𝐴′𝐴′=(𝐴[𝜎])𝑎ΨΔ;Γ⊢𝜎,𝑅//𝑥⇐Ψ,𝑥:𝐴SAtom. The ordinary context-formation and ordinary bidirectional LF rules carry the same modal prefix Δ. Thus the hereditary operation in MApp is part of the typing rules whose decidability is stated below, rather than an untyped meta-operation.
Referenced from 5 locations
Ordinary substitution of a canonical lambda into a neutral application creates a beta-redex. A hereditary substitution contracts every such redex as it is created. Its termination index is the dependency-erasure 𝑎−:=𝑎,(∏𝑥:𝐴𝐵)−:=𝐴−→𝐵−,(∏𝑢::𝐴[Ψ]𝐵)−:=𝐴−[Ψ−]→𝐵−. For the characteristic ordinary application case, [𝑀/𝑥]𝛼(𝑅𝑁):={𝑅′𝑁′[𝑀/𝑥]𝛼𝑅=𝑅′ atomic,[𝑁′/𝑦]𝛼1𝑀′[𝑀/𝑥]𝛼𝑅=𝜆𝑦.𝑀′:𝛼1→𝛼2, where 𝑁′:=[𝑀/𝑥]𝛼𝑁 and 𝛼1 is a proper subexpression of 𝛼 in the second case. Contextual application has the same clause with a contextual approximation 𝛼1[𝜓] →𝛼2. The outer measure decreases when a created redex is contracted; otherwise the term structure decreases.
For the dependent canonical calculus of definition 63.5:
ordinary, simultaneous, and contextual hereditary substitutions terminate on every raw input, returning a result or finite failure;
all formation, checking, synthesis, and equality judgments are decidable.
Ordinary substitution preserves a normal-object judgment under the following exact existence premises. If Δ;Γ⊢𝑀⇐𝐴,Δ;Γ,𝑥:𝐴,Γ1⊢𝑁⇐𝐶, Γ′1 =(Γ1[𝑀/𝑥])𝛾𝐴 exists with Δ ⊢Γ,Γ′1 𝖼𝗍𝗑, and 𝐶′ =(𝐶[𝑀/𝑥])𝑎𝐴 exists with Δ;Γ,Γ′1 ⊢𝐶′ ⇐𝗍𝗒𝗉𝖾, then Δ;Γ,Γ′1⊢(𝑁[𝑀/𝑥])𝑛𝐴⇐𝐶′.
Modal substitution preserves a normal-object judgment if the substituted modal suffix, ordinary context, and result type all exist and are well formed. Explicitly, from Δ;Ψ⊢𝑀⇐𝐴,Δ,𝑢::𝐴[Ψ],Δ1;Γ⊢𝑁⇐𝐶, put Δ′1=(Δ1[̂Ψ.𝑀/𝑢])𝛿𝐴[Ψ],Γ′=(Γ[̂Ψ.𝑀/𝑢])𝛾𝐴[Ψ],𝐶′=(𝐶[̂Ψ.𝑀/𝑢])𝑎𝐴[Ψ]. If all three exist and ⊢Δ,Δ′1 𝗆𝖼𝗍𝗑, Δ,Δ′1 ⊢Γ′ 𝖼𝗍𝗑, and Δ,Δ′1;Γ′ ⊢𝐶′ ⇐𝗍𝗒𝗉𝖾, then Δ,Δ′1;Γ′⊢(𝑁[̂Ψ.𝑀/𝑢])𝑛𝐴[Ψ]⇐𝐶′.
Simultaneous substitution requires an underapproximation. Write Ψ− =(𝑥1 :𝛼1,…,𝑥𝑛 :𝛼𝑛) for dependency erasure. A context approximation 𝜓 underapproximates Ψ with respect to 𝜎 when it differs from Ψ− only by replacing a declaration 𝑥𝑖 :𝛼𝑖 with the untyped declaration 𝑥𝑖 :, and only when the corresponding component of 𝜎 is atomic, written 𝑅𝑖//𝑥𝑖. If Δ;Γ ⊢𝜎 ⇐Ψ, Δ;Ψ ⊢𝑁 ⇐𝐶, and 𝜓 is an underapproximation of Ψ with respect to 𝜎, then, whenever 𝐶′ =(𝐶[𝜎])𝑎𝜓 exists and Δ;Γ ⊢𝐶′ ⇐𝗍𝗒𝗉𝖾, Δ;Γ⊢(𝑁[𝜎])𝑛𝜓⇐𝐶′.
Referenced from 3 locations
Proof of Theorem 63.6 — Qualified hereditary substitution and decidability
Proof. For termination, order recursive calls lexicographically: first by the strict subexpression ordering on the erased approximation 𝛼, 𝛼[𝜓], or 𝜓, and second by the raw syntax. Compositional clauses retain the approximation and descend to a subterm. A clause that creates a redex may enter a larger body, but its new approximation is a proper subexpression, as in the displayed application clause. The ordering is well founded, so every operation returns or fails after finitely many calls.
For preservation, strengthen the claim mutually over normal terms, atomic terms, types, kinds, contexts, modal contexts, and substitutions. Induct first on the erased approximation and then on the typing derivation. The created-redex case uses the outer induction hypothesis at 𝛼1 <𝛼; compositional cases use the derivation induction hypotheses. The context, modal-context, and type existence premises in clauses 3–5 are required because the raw terminating operation is permitted to fail; they establish that the reconstructed target judgments are defined.
The bidirectional rules are syntax directed. Their only non-structural computations are the hereditary substitutions just proved terminating, so structural recursion decides every judgment. Clauses 1–2 are exactly Theorems 5.1–5.2 on pp. 30–31 of [NPP08]. The source’s Theorem 5.3 states the three corresponding type-formation principles; clauses 3–5 are the normal-object principles of its Appendix Theorem C.4, including that theorem’s existence, well-formedness, and underapproximation hypotheses. The proof above exhibits their common measure without strengthening those imported claims. ◻
★★☆ Let 𝑓 :𝐴 →𝐴 and 𝑦 :𝐴. Compute the hereditary substitution of the canonical object 𝜆(𝑧 :𝐴). 𝑧 for 𝑓 in the neutral application 𝑓 𝑦. Display the created beta-redex, its contraction, and the strict decrease from approximation 𝐴− →𝐴− to 𝐴−. (Half a page.)
Referenced from 3 locations
A context-preserving transformation
For a neutral STLC object 𝑅, define type-directed eta expansion by 𝜂𝜄(𝑅):=𝑅,𝜂𝐴→𝐵(𝑅):=𝜆(𝑥:𝐴).𝜂𝐵(𝑅𝜂𝐴(𝑥)), where 𝑥 is the ordinary variable introduced by the contextual binder. The recursive call 𝜂𝐴(𝑥) first expands the newly introduced neutral variable at its domain type, so the application to 𝑅 is well typed even when 𝐴 is itself a function type.
If 𝐷 is a contextual LF derivation of a neutral object [Ψ ⊢𝗌𝗍𝑅 ⇒𝐴], then the syntax-directed transformation 𝜂(𝐷) is a derivation [Ψ ⊢𝗌𝗍𝜂𝐴(𝑅) ⇐𝐴]. The output contains no ordinary variable outside Ψ.
Referenced from 2 locations
Proof of Proposition 63.7 — Context preservation of eta expansion
Proof. Induct on 𝐴. At 𝜄, the neutral-to-normal coercion returns 𝐷. At 𝐴 →𝐵, extend Ψ by 𝑥 :𝐴. The contextual variable rule synthesizes 𝑥 :𝐴, and the induction hypothesis at 𝐴 checks 𝜂𝐴(𝑥) :𝐴. Application therefore synthesizes 𝑅 𝜂𝐴(𝑥) :𝐵. The induction hypothesis at 𝐵 checks its eta expansion, and abstraction discharges 𝑥, returning to the exact context Ψ. Every introduced variable is discharged in this same recursive clause, so the free-variable set remains contained in dom(Ψ). ◻
This transformation internalizes open LF objects. It is not a universe of binding descriptions: its recursion is fixed to the displayed STLC syntax and its contextual type records one concrete LF context.
Beluga context schemas and recursive calls
Beluga programs manipulate contextual LF objects, so a recursive proof must preserve the shape of the open LF context as well as the conclusion family. For the type-uniqueness example, fix LF families 𝗍𝗉 :𝗍𝗒𝗉𝖾, 𝗍𝖾𝗋𝗆 :𝗍𝗒𝗉𝖾, and 𝗁𝖺𝗌𝗍𝗒𝗉𝖾 :𝗍𝖾𝗋𝗆 →𝗍𝗉 →𝗍𝗒𝗉𝖾.
The context schema 𝗑𝗍𝖦 generates contexts by repeating blocks 𝑏=(𝑥:𝗍𝖾𝗋𝗆, 𝑢:𝗁𝖺𝗌𝗍𝗒𝗉𝖾𝑥𝑇) for an LF object type 𝑇 :𝗍𝗉. A projection 𝑏.𝑥 denotes the term declaration and 𝑏.𝑢 denotes its paired typing derivation. Every use of 𝑏.𝑢 therefore has family 𝗁𝖺𝗌𝗍𝗒𝗉𝖾 (𝑏.𝑥) 𝑇 in the context extended by the whole block.
Referenced from 3 locations
In the lambda case of type uniqueness, the two premise derivations are opened under the same extended schema context 𝑔,𝑏 :𝗑𝗍𝖦. A recursive call must pass both projections because the body derivations mention the new term and require its typing assumption.
Let 𝑔 satisfy 𝗑𝗍𝖦 and let 𝑏 be a block of definition 63.8. A contextual object with family [𝑔,𝑏⊢𝗁𝖺𝗌𝗍𝗒𝗉𝖾(𝑏.𝑥)𝑇] may project 𝑏.𝑢. If a recursive call extends its contextual term argument by 𝑏.𝑥 but omits 𝑏.𝑢 from the corresponding derivation argument, that argument does not inhabit the displayed family.
Referenced from 2 locations
Proof of Proposition 63.9 — Paired-block scope invariant
Proof. Schema inversion gives exactly two declarations in 𝑏: the object 𝑏.𝑥 :𝗍𝖾𝗋𝗆 and 𝑏.𝑢 :𝗁𝖺𝗌𝗍𝗒𝗉𝖾 (𝑏.𝑥) 𝑇. The LF variable rule derives the displayed family from the second declaration. After omitting 𝑏.𝑢, no declaration in 𝑔,𝑏.𝑥 :𝗍𝖾𝗋𝗆 has that family. Canonical-head inversion therefore has no variable case for the required derivation object, so the recursive argument is out of scope. ◻
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 63.3, then complete exercise 63.5.
★★☆ Let Ψ =(𝑥 :𝐴,𝑦 :𝐵) and let a simultaneous substitution contain a normal component 𝑀/𝑥 and an atomic component 𝑅//𝑦. List every context approximation that underapproximates Ψ with respect to this substitution. Explain why erasing the type of 𝑥 is forbidden and why retaining the type of 𝑦 remains permitted. (Half a page.)
Referenced from 4 locations
★★☆ Compare the simply typed box redex with the dependent contextual application of a canonical meta-abstraction. Give one well-typed instance of each. Normalize both, and identify why the first calculus needs commuting conversions while the second performs hereditary substitution during typing. Do not transfer strong normalization from one calculus to the other.
Referenced from 3 locations
★★★ Practical project.beluga-context-scope Inspect the pinned Beluga file examples/literate_beluga/0Beginner/Type_Uniqueness.bel. Identify the schema block pairing an LF term variable with its typing assumption and the recursive call that extends that block under a lambda. In the Kappa companion, represent the paired declarations and check that both projected arguments refer to the same term and type. Then replace the typing projection by one for a different term. The accepted corpus must accept the source-shaped call and reject the altered call with the missing family [𝑔,𝑏 ⊢𝗁𝖺𝗌𝗍𝗒𝗉𝖾 (𝑏.𝑥) −]. This finite check does not execute Beluga and does not establish either theorem card printed in the preceding contextual-modal development.
Referenced from 6 locations
Sources. The simply typed interpretation is Theorem 4.6 of Nanevski, Pfenning, and Pientka; its strong-normalization boundary is Theorem 4.7 [NPP08]. The raw termination and decidability statements are Theorems 5.1–5.2 on pp. 30–31. The exact well-formedness, existence, and underapproximation premises for preservation are Theorem C.4 on Appendix pp. 11–12 (physical PDF pp. 59–60). Pientka’s tutorial prints the paired schema on physical pp. 60–64 and the lambda-case recursive call with both block projections on physical p. 72 [Pie15]. Those pages and the pinned Beluga source are source-shape evidence only; they do not supply an LF adequacy or CMTT normalization theorem [Bel25].