The type ∏𝐴:𝗉𝗋𝗈𝗉𝖽𝖾𝖽𝐴 is well formed in the PTS 𝜆𝑃 of definition 60.5, extended by 𝗉𝗋𝗈𝗉 : ∗ and 𝖽𝖾𝖽 :∏𝐴:𝗉𝗋𝗈𝗉 ∗. This fact says nothing about whether an inhabitant of 𝖽𝖾𝖽 𝐴 denotes a derivation of the object proposition 𝐴. A framework must supply a representation in both directions and prove that canonical framework objects contain neither missing derivations nor exotic inhabitants. We begin with the smallest logic for which a binder is unavoidable.
LF and canonical objects
The Edinburgh Logical Framework, abbreviated LF, is a dependent lambda calculus used to represent the syntax, judgments, and derivations of another deductive system. Its four syntactic classes are 𝐾::=𝗍𝗒𝗉𝖾∣∏𝑥:𝐴𝐾,𝐴,𝐵::=𝑎∣𝐴𝑀∣∏𝑥:𝐴𝐵,𝑀,𝑁::=𝑐∣𝑥∣𝑀𝑁∣𝜆(𝑥:𝐴).𝑀,Σ::=⋅∣Σ,𝑎:𝐾∣Σ,𝑐:𝐴. Kinds classify LF families, LF families classify LF objects, and an LF signature Σ declares family constants 𝑎 and object constants 𝑐. The framework judgments Σ 𝗌𝗂𝗀,Γ 𝖼𝗍𝗑Σ,Γ⊢Σ𝐴:𝐾,Γ⊢Σ𝑀:𝐴 are distinct from every encoded object judgment introduced below.
LF has the structural, product, abstraction, application, and conversion rules of the PTS in definition 60.3, restricted as follows. Its conversion rule uses LF beta-eta equality in place of PTS beta equality. ⋅⊢Σ𝗍𝗒𝗉𝖾 𝗄𝗂𝗇𝖽,𝑎:𝐾∈ΣΓ⊢Σ𝑎:𝐾Fam,𝑐:𝐴∈ΣΓ⊢Σ𝑐:𝐴Con. In kinds and families alike, the product domain is a family and the bound variable is an object variable; no product binds a family variable. The LF kernel has no recursion, pattern matching, induction, or user-defined rewriting.
Referenced from 3 locations
The restriction keeps type checking decidable and makes the head of every closed normal object visible in its signature. Adding a case operator for an encoded syntax would permit a meta-function to inspect an object variable; such a function need not represent object-language binding.
An atomic LF object is a variable or object constant applied to zero or more canonical arguments. A canonical LF object at a product type ∏𝑥:𝐴𝐵 has the form 𝜆(𝑥 :𝐴). 𝑀, where 𝑀 is canonical at 𝐵; a canonical object at an atomic family has atomic form. Thus canonical objects are beta-normal and eta-long. We write Γ⊢Σ𝑀 𝖼𝖺𝗇:𝐴 for the resulting mutually inductive canonical and atomic judgments.
Referenced from 3 locations
Let 𝑓 :∏𝑥:𝐴𝐵 be an LF variable. The object 𝑓 is beta-normal, but its canonical form is 𝜆(𝑥:𝐴).𝑓𝑥. Adequacy is stated for the latter form. Otherwise one object-language constructor with a binding argument could be represented both by a lambda and by an unapplied function variable.
Referenced from 2 locations
Proof of Theorem 61.4 — Canonical forms for LF
Proof. The theorem is imported for the exact LF calculus of definition 61.1. Pfenning’s conversion procedure returns a unique canonical object at the given type and characterizes definitional equality by equality of those results [Pfe01]. The same presentation proves decidability of every LF judgment [Pfe01]. Harper, Honsell, and Plotkin give the fully-applied-head characterization that the adequacy proofs use [HHP93]. These imports include LF beta-eta conversion, dependent products, signatures, and contexts, but no rewrite extension. ◻
★☆☆ In the context 𝑓 :∏𝑥:𝐴∏𝑦:𝐵𝐶, write the eta-long canonical form of 𝑓. Then beta-reduce its application to canonical 𝑀 :𝐴 and 𝑁 :𝐵[𝑀/𝑥] and mark the two contraction steps, including the substituted annotation on the inner lambda. (Four lines.)
Referenced from 3 locations
Natural deduction as canonical LF data
Fix a finite set P0 of object propositional atoms. Let object propositions and labeled natural deductions be 𝑃,𝑄::=𝑝∣𝑃⊃𝑄(𝑝∈P0),𝐷,𝐸::=𝑢∣𝗌𝗎𝗉𝖨(𝑢.𝐷)∣𝗌𝗎𝗉𝖤(𝐷,𝐸). The object judgment Δ ⊢⊃𝐷 :𝑃 is generated by the three rules 𝑢:𝑃∈ΔΔ⊢⊃𝑢:𝑃Sup−AssmΔ,𝑢:𝑃⊢⊃𝐷:𝑄𝑢∉dom(Δ)Δ⊢⊃𝗌𝗎𝗉𝖨(𝑢.𝐷):𝑃⊃𝑄Sup−I Δ⊢⊃𝐷:𝑃⊃𝑄Δ⊢⊃𝐸:𝑃Δ⊢⊃𝗌𝗎𝗉𝖤(𝐷,𝐸):𝑄Sup−E. It is not an LF judgment. Object contexts are finite lists with pairwise distinct labels.
The signature Σ⊃ contains 𝗉𝗋𝗈𝗉:𝗍𝗒𝗉𝖾,𝗂𝗆𝗉:𝗉𝗋𝗈𝗉→𝗉𝗋𝗈𝗉→𝗉𝗋𝗈𝗉,𝖽𝖾𝖽:𝗉𝗋𝗈𝗉→𝗍𝗒𝗉𝖾,𝗌𝗎𝗉𝖨:∏𝑃:𝗉𝗋𝗈𝗉∏𝑄:𝗉𝗋𝗈𝗉(𝖽𝖾𝖽𝑃→𝖽𝖾𝖽𝑄)→𝖽𝖾𝖽(𝗂𝗆𝗉𝑃𝑄),𝗌𝗎𝗉𝖤:∏𝑃:𝗉𝗋𝗈𝗉∏𝑄:𝗉𝗋𝗈𝗉𝖽𝖾𝖽(𝗂𝗆𝗉𝑃𝑄)→𝖽𝖾𝖽𝑃→𝖽𝖾𝖽𝑄. and a declaration 𝑝 :𝗉𝗋𝗈𝗉 for every 𝑝 ∈P0. The judgments-as-types representation maps an object judgment Δ ⊢⊃𝑃 to the LF family 𝖽𝖾𝖽 ⌜𝑃⌝. The representation ⌜ −⌝ is defined compositionally by ⌜𝑝⌝:=𝑝,⌜𝑃⊃𝑄⌝:=𝗂𝗆𝗉⌜𝑃⌝⌜𝑄⌝. The derivation clauses are ⌜𝑢⌝:=𝑢,⌜𝗌𝗎𝗉𝖨(𝑢.𝐷)⌝:=𝗌𝗎𝗉𝖨⌜𝑃⌝⌜𝑄⌝(𝜆(𝑢:𝖽𝖾𝖽⌜𝑃⌝).⌜𝐷⌝),⌜𝗌𝗎𝗉𝖤(𝐷,𝐸)⌝:=𝗌𝗎𝗉𝖤⌜𝑃⌝⌜𝑄⌝⌜𝐷⌝⌜𝐸⌝. In the final two clauses, 𝑃,𝑄 are determined by the object derivation. An object context 𝑢1 :𝑃1,…,𝑢𝑛 :𝑃𝑛 maps to the LF context 𝑢1 :𝖽𝖾𝖽 ⌜𝑃1⌝,…,𝑢𝑛 :𝖽𝖾𝖽 ⌜𝑃𝑛⌝.
Referenced from 3 locations
Let Γ =⌜Δ⌝ be a represented derivation context, so every declaration of Γ has family 𝖽𝖾𝖽 ⌜𝑄⌝. If Γ ⊢Σ⊃𝑀 𝖼𝖺𝗇 :𝗉𝗋𝗈𝗉, then there is a unique object proposition 𝑃 such that 𝑀 =⌜𝑃⌝.
Referenced from 3 locations
Proof of Lemma 61.6 — Proposition-code inversion
Proof. The family 𝗉𝗋𝗈𝗉 is atomic, so 𝑀 is atomic. Its head is either a declared atom 𝑝 :𝗉𝗋𝗈𝗉 with no arguments or 𝗂𝗆𝗉 fully applied to two canonical objects of family 𝗉𝗋𝗈𝗉. In the first case decode 𝑝; in the second, apply the two induction hypotheses and decode 𝗂𝗆𝗉 ⌜𝑃⌝ ⌜𝑄⌝ as 𝑃 ⊃𝑄. No context variable has family 𝗉𝗋𝗈𝗉 in a represented derivation context. Constructor disjointness and the two induction hypotheses give uniqueness. ◻
The representation of implication introduction uses higher-order abstract syntax, abbreviated HOAS: the LF binder represents the object derivation’s discharged assumption. Object substitution is therefore implemented by LF beta-reduction when a represented hypothetical derivation is applied to the substituting derivation. This fact does not add a computation rule between the constants 𝗌𝗎𝗉𝖨 and 𝗌𝗎𝗉𝖤.
The object derivation of 𝑃 ⊃(𝑄 ⊃𝑃) is represented by 𝗌𝗎𝗉𝖨⌜𝑃⌝⌜𝑄⊃𝑃⌝(𝜆(𝑢:𝖽𝖾𝖽⌜𝑃⌝).𝗌𝗎𝗉𝖨⌜𝑄⌝⌜𝑃⌝(𝜆(𝑣:𝖽𝖾𝖽⌜𝑄⌝).𝑢)). The LF type is 𝖽𝖾𝖽 ⌜𝑃 ⊃(𝑄 ⊃𝑃)⌝. The two LF lambdas bind exactly the two object assumptions; the inner body may use 𝑢 but does not use 𝑣.
Referenced from 2 locations
A representation ⌜ −⌝ is compositional when it commutes with every object substitution. For derivation substitution this means ⌜𝐷[𝐸/𝑢]⌝=𝛽⌜𝐷⌝[⌜𝐸⌝/𝑢]. It is adequate for a judgment when, for each object context whose labels are pairwise distinct and each conclusion generated from the declared object atoms, it is a bijection between object derivations modulo alpha-equivalence and canonical LF objects of the represented family in the represented context.
Referenced from 2 locations
For every object derivation 𝐷, derivation 𝐸, and label 𝑢 for which 𝐷[𝐸/𝑢] is defined, ⌜𝐷[𝐸/𝑢]⌝=𝛽⌜𝐷⌝[⌜𝐸⌝/𝑢].
Referenced from 4 locations
Proof of Lemma 61.9 — Compositionality of the implication encoding
Proof. Induct on 𝐷. The assumption cases are ⌜𝑢[𝐸/𝑢]⌝=⌜𝐸⌝𝑠𝑢𝑏𝑠𝑡𝑖𝑡𝑢𝑡𝑖𝑜𝑛𝑎𝑡𝑢=𝑢[⌜𝐸⌝/𝑢],⌜𝑣[𝐸/𝑢]⌝=𝑣𝑣≠𝑢=𝑣[⌜𝐸⌝/𝑢]. For elimination, the induction hypotheses apply to both subderivations and the constructor is unchanged. For 𝐷 =𝗌𝗎𝗉𝖨(𝑣.𝐷0), choose the representative with 𝑣∉FV(𝐸)∪{𝑢}. Then ⌜𝗌𝗎𝗉𝖨(𝑣.𝐷0)[𝐸/𝑢]⌝=𝗌𝗎𝗉𝖨⌜𝑃⌝⌜𝑄⌝(𝜆(𝑣:𝖽𝖾𝖽⌜𝑃⌝).⌜𝐷0[𝐸/𝑢]⌝)𝐼𝐻=𝗌𝗎𝗉𝖨⌜𝑃⌝⌜𝑄⌝(𝜆(𝑣:𝖽𝖾𝖽⌜𝑃⌝).⌜𝐷0⌝[⌜𝐸⌝/𝑢])=⌜𝗌𝗎𝗉𝖨(𝑣.𝐷0)⌝[⌜𝐸⌝/𝑢]. These are all object derivation constructors. ◻
Let Δ =𝑢1 :𝑃1,…,𝑢𝑛 :𝑃𝑛, where the labels 𝑢𝑖 are pairwise distinct and every atom occurring in 𝑃1,…,𝑃𝑛,𝑃 belongs to P0. The representation ⌜ −⌝ is a compositional bijection {𝐷∣Δ⊢⊃𝐷:𝑃}/=𝛼 ⟷ {𝑀∣⌜Δ⌝⊢Σ⊃𝑀 𝖼𝖺𝗇:𝖽𝖾𝖽⌜𝑃⌝}/=𝛼.
Referenced from 4 locations
Proof of Theorem 61.10 — Adequacy for implicational natural deduction
Proof. Soundness. Induct on Δ ⊢⊃𝐷 :𝑃. An assumption maps to the corresponding LF variable. For implication introduction, the induction hypothesis gives ⌜Δ⌝,𝑢:𝖽𝖾𝖽⌜𝑃⌝⊢Σ⊃⌜𝐷⌝ 𝖼𝖺𝗇:𝖽𝖾𝖽⌜𝑄⌝. LF abstraction and the constant 𝗌𝗎𝗉𝖨 give a canonical object of 𝖽𝖾𝖽 ⌜𝑃 ⊃𝑄⌝. For implication elimination, the two induction hypotheses have the two argument families of 𝗌𝗎𝗉𝖤, so canonical application gives the represented conclusion.
Completeness. Define an inverse by induction on the canonical-object derivation. Since 𝖽𝖾𝖽 ⌜𝑃⌝ is atomic, the object is atomic. Its head is one of:
a context variable 𝑢𝑖, whose declared family forces 𝑃 =𝑃𝑖 and which maps to the assumption derivation;
𝗌𝗎𝗉𝖨 fully applied to two proposition codes and a canonical function; eta-longness forces the function to be 𝜆(𝑢 :𝖽𝖾𝖽 ⌜𝑅⌝). 𝑀0. Apply the induction hypothesis to 𝑀0 in the extended context and return implication introduction;
𝗌𝗎𝗉𝖤 fully applied to two proposition codes and two canonical derivation objects. Apply the two induction hypotheses and return implication elimination.
The arguments headed by 𝗉𝗋𝗈𝗉 decode uniquely by lemma 61.6. No other signature constant returns a family headed by 𝖽𝖾𝖽. Hence the inverse is total and excludes exotic inhabitants.
Inverse equations. Induction on object derivations shows that decoding ⌜𝐷⌝ returns 𝐷. Induction on canonical forms shows that encoding the decoded form returns the same variable or the same fully applied constructor; in the introduction case the two LF lambdas agree up to alpha-equivalence. Thus the maps are inverse. Compositionality is lemma 61.9. ◻
★★☆ Specialize to 𝐷 =𝑢 and to an assumption derivation 𝑒 :𝑃 independent of 𝑢. Encode the object proof reduction 𝗌𝗎𝗉𝖤(𝗌𝗎𝗉𝖨(𝑢.𝑢),𝑒):𝑃 ⟶cut 𝑒:𝑃. Show that the left encoding is already LF beta-normal: 𝗌𝗎𝗉𝖤 has no rewrite rule for a 𝗌𝗎𝗉𝖨 argument. State why the two encodings are not LF beta-eta equal. Then give the general equation ⌜𝐷[𝐸/𝑢]⌝ =𝛽𝜂⌜𝐷⌝[⌜𝐸⌝/𝑢] from lemma 61.9 and explain why neither calculation proves completeness. (Three quarters of a page.)
Referenced from 3 locations
A binding-rich typed encoding
The first encoding represented a binder in derivations. The next encoding represents the binder in the syntax of the simply typed lambda calculus itself. Object types, terms, and typing judgments are 𝐴,𝐵::=𝜄∣𝐴→𝐵,𝑡,𝑢::=𝑥∣𝜆(𝑥:𝐴).𝑡∣𝑡𝑢,Γ⊢𝗌𝗍𝑡:𝐴. The subscript 𝗌𝗍 keeps this object typing judgment separate from LF typing.
The LF signature Σ𝗌𝗍 contains 𝗍𝗉:𝗍𝗒𝗉𝖾,𝗂:𝗍𝗉,𝖺𝗋𝗋:𝗍𝗉→𝗍𝗉→𝗍𝗉,𝗍𝗆:𝗍𝗉→𝗍𝗒𝗉𝖾,𝗅𝖺𝗆:∏𝐴:𝗍𝗉∏𝐵:𝗍𝗉(𝗍𝗆𝐴→𝗍𝗆𝐵)→𝗍𝗆(𝖺𝗋𝗋𝐴𝐵),𝖺𝗉𝗉:∏𝐴:𝗍𝗉∏𝐵:𝗍𝗉𝗍𝗆(𝖺𝗋𝗋𝐴𝐵)→𝗍𝗆𝐴→𝗍𝗆𝐵. The type representation and term representation are ⌜𝜄⌝:=𝗂,⌜𝐴→𝐵⌝:=𝖺𝗋𝗋⌜𝐴⌝⌜𝐵⌝,⌜𝑥⌝:=𝑥,⌜𝜆(𝑥:𝐴).𝑡⌝:=𝗅𝖺𝗆⌜𝐴⌝⌜𝐵⌝(𝜆(𝑥:𝗍𝗆⌜𝐴⌝).⌜𝑡⌝),⌜𝑡𝑢⌝:=𝖺𝗉𝗉⌜𝐴⌝⌜𝐵⌝⌜𝑡⌝⌜𝑢⌝. The object typing derivation determines the implicit types 𝐴,𝐵 in the last two clauses. The object context 𝑥1 :𝐴1,…,𝑥𝑛 :𝐴𝑛 maps to 𝑥1 :𝗍𝗆 ⌜𝐴1⌝,…,𝑥𝑛 :𝗍𝗆 ⌜𝐴𝑛⌝.
Referenced from 3 locations
The object term 𝜆(𝑓 :𝐴 →𝐵). 𝜆(𝑥 :𝐴). 𝑓 𝑥 maps to B(𝑓):=𝗅𝖺𝗆⌜𝐴⌝⌜𝐵⌝(𝜆(𝑥:𝗍𝗆⌜𝐴⌝).𝖺𝗉𝗉⌜𝐴⌝⌜𝐵⌝𝑓𝑥). Consequently its complete representation is 𝗅𝖺𝗆⌜𝐴→𝐵⌝⌜𝐴→𝐵⌝(𝜆(𝑓:𝗍𝗆⌜𝐴→𝐵⌝).B(𝑓)). Substituting a represented function 𝑔 into the HOAS body contracts one LF redex and produces the representation of 𝜆(𝑥 :𝐴). 𝑔 𝑥. By contrast, the encoding of the object application has head 𝖺𝗉𝗉 and does not contract: 𝗅𝖺𝗆 and 𝖺𝗉𝗉 are representation constants, not LF computation rules. No definition of capture-avoiding substitution is added to the signature.
Referenced from 2 locations
If Γ,𝑥 :𝐴,Δ ⊢𝗌𝗍𝑡 :𝐵 and Γ ⊢𝗌𝗍𝑢 :𝐴, then ⌜𝑡[𝑢/𝑥]⌝=𝛽⌜𝑡⌝[⌜𝑢⌝/𝑥].
Referenced from 2 locations
Proof of Lemma 61.13 — STLC representation commutes with substitution
Proof. Induct on 𝑡. Variables give the two defining substitution equations. Application uses both induction hypotheses. For 𝑡 =𝜆(𝑦 :𝐶). 𝑡0, choose the alpha-equivalent representative with 𝑦∉FV(𝑢)∪{𝑥}∪dom(Γ,Δ). Then the object substitution enters the body, and the LF substitution enters the body of the representing LF lambda. The induction hypothesis gives ⌜𝑡0[𝑢/𝑥]⌝ =𝛽⌜𝑡0⌝[⌜𝑢⌝/𝑥]. These are all term constructors. ◻
Let ⌜Γ⌝ contain only declarations 𝑥 :𝗍𝗆 ⌜𝐴⌝. If ⌜Γ⌝ ⊢Σ𝗌𝗍𝑇 𝖼𝖺𝗇 :𝗍𝗉, then there is a unique STLC type 𝐴 with 𝑇 =⌜𝐴⌝.
Referenced from 3 locations
Proof of Lemma 61.14 — STLC type-code inversion
Proof. The canonical object is atomic. No variable in ⌜Γ⌝ has family 𝗍𝗉, and the only signature heads returning that family are 𝗂 and the fully applied 𝖺𝗋𝗋. Decode the first as 𝜄; in the second case recursively decode the two canonical 𝗍𝗉 arguments. Constructor disjointness and the two induction hypotheses give uniqueness. ◻
Let ⌜Γ⌝ contain only declarations 𝑥 :𝗍𝗆 ⌜𝐴⌝. Every canonical LF object ⌜Γ⌝⊢Σ𝗌𝗍𝑀 𝖼𝖺𝗇:𝗍𝗆⌜𝐵⌝ has exactly one of the forms 𝑥,𝖺𝗉𝗉⌜𝐴⌝⌜𝐵⌝𝑀1𝑀2,𝗅𝖺𝗆⌜𝐴1⌝⌜𝐵1⌝(𝜆(𝑥:𝗍𝗆⌜𝐴1⌝).𝑀0), with canonical subobjects at the displayed families. In the second form, 𝐴 is an arbitrary object type and the result type is 𝐵. The third form occurs only when 𝐵 =𝐴1 →𝐵1; its body has family 𝗍𝗆 ⌜𝐵1⌝ in the context extended by 𝑥 :𝗍𝗆 ⌜𝐴1⌝.
Referenced from 4 locations
Proof of Lemma 61.15 — No exotic STLC inhabitants
Proof. The target family is atomic, so 𝑀 is atomic. Its head is a variable or a constant. A variable in ⌜Γ⌝ has the first form. Among the constants of Σ𝗌𝗍, only 𝖺𝗉𝗉 and 𝗅𝖺𝗆 return a family headed by 𝗍𝗆. Eta-longness forces each constant to be fully applied. Their explicit 𝗍𝗉 arguments are uniquely object-type codes by lemma 61.14. In the 𝗅𝖺𝗆 case, the final argument has function type, so canonicality forces an LF lambda and extends the context by 𝑥 :𝗍𝗆 ⌜𝐴1⌝. There is no constant that eliminates, compares, or branches on an object of family 𝗍𝗆 ⌜𝐴1⌝; hence these cases exhaust the canonical inhabitants. ◻
For every object context Γ and object type 𝐴, representation is a compositional bijection {𝑡∣Γ⊢𝗌𝗍𝑡:𝐴}/=𝛼 ⟷ {𝑀∣⌜Γ⌝⊢Σ𝗌𝗍𝑀 𝖼𝖺𝗇:𝗍𝗆⌜𝐴⌝}/=𝛼.
Referenced from 4 locations
Proof of Theorem 61.16 — Adequacy for intrinsically typed STLC
Proof. Soundness is rule induction on object typing. The variable case selects its LF context declaration. The application and abstraction cases apply the corresponding LF signature constant; in the abstraction case, the induction hypothesis is used under the LF variable that represents the object binder.
For completeness, recursively invert the three forms of lemma 61.15. A variable maps to the object variable with the type recorded by its context declaration. An 𝖺𝗉𝗉 head yields canonical subobjects at 𝗍𝗆(𝖺𝗋𝗋 ⌜𝐴⌝ ⌜𝐵⌝) and 𝗍𝗆 ⌜𝐴⌝; decode them and apply the object application rule. An 𝗅𝖺𝗆 head forces the target type to be 𝐴1 →𝐵1 and yields a canonical body at 𝗍𝗆 ⌜𝐵1⌝ in the context extended by 𝑥 :𝗍𝗆 ⌜𝐴1⌝; decode the body and apply the object abstraction rule.
Induction on object terms proves decode-after-encode is the identity. Induction on canonical objects proves encode-after-decode is the identity, with alpha-equivalence in the binder case. The preceding substitution lemma supplies compositionality. ◻
The phrase intrinsically typed names what the index of 𝗍𝗆 does: ill-typed object terms have no representation. This encoding is not an adequacy theorem for raw terms plus a separate typing relation. Such an encoding would use an unindexed family 𝗍𝖾𝗋𝗆 and another family 𝗈𝖿 :𝗍𝖾𝗋𝗆 →𝗍𝗉 →𝗍𝗒𝗉𝖾, and would require a new canonical-forms proof.
Kernel checking and adequacy are distinct obligations; the following extension witnesses the gap. Extend Σ𝗌𝗍 by 𝗂𝗇𝗌𝗉𝖾𝖼𝗍:∏𝐴:𝗍𝗉𝗍𝗆𝐴→𝗍𝗆𝐴. For canonical 𝑀 :𝗍𝗆 ⌜𝐴⌝, the fully applied object 𝗂𝗇𝗌𝗉𝖾𝖼𝗍 ⌜𝐴⌝ 𝑀 is well typed and canonical. Its head is not a variable, 𝗅𝖺𝗆, or 𝖺𝗉𝗉, so the STLC inverse has no case for it. Kernel checking and canonicalization survive this extension while adequacy does not.
★★☆ Reconstruct the 𝗂𝗇𝗌𝗉𝖾𝖼𝗍 counterexample above from the extended signature. Exhibit the new canonical form that appears in lemma 61.15. Explain why no STLC constructor decodes it and therefore why sound typing of the LF constant does not preserve adequacy. (Half a page.)
Referenced from 3 locations
For an LF signature Σ and representation ⌜ −⌝, the following obligations are logically distinct:
the LF kernel checks Γ ⊢Σ𝑀 :𝐴;
canonicalization computes the unique 𝑀∘ of theorem 61.4;
an adequacy theorem proves that 𝑀∘ decodes to exactly one object of the represented judgment;
any framework program that searches for or transforms 𝑀 preserves the checked LF family.
None of the first, second, or fourth obligations implies the third.
Referenced from 2 locations
Proof of Proposition 61.17 — Framework trust and adequacy obligations
Proof. The first two concern only LF. The third quantifies over a separate object syntax and its representation inverse, data absent from LF typing. The preceding 𝗂𝗇𝗌𝗉𝖾𝖼𝗍 extension satisfies LF typing and canonicalization while making the completeness inverse partial; equivalently, the encoding is no longer surjective onto canonical LF inhabitants. The fourth concerns an algorithm external to the kernel; even a type-preserving identity transformation proves no inverse equation for ⌜ −⌝. ◻
User-defined rewriting is therefore excluded from the LF kernel in this chapter. A rewrite-enhanced framework needs confluence, subject reduction, normalization or a terminating conversion procedure, and a fresh adequacy proof for each encoding. A PTS classification or the LF theorem above cannot donate those results.
A controlled comparison of binding representations
Fix the same intrinsically typed STLC as above. Every representation in this section must support three operations and the same theorem: 𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑡),𝑡[𝜎],Γ⊢𝗌𝗍𝑡:𝐴⟹Δ⊢𝗌𝗍𝑡[𝜎]:𝐴 whenever 𝜎 maps each variable declared by Γ to a term of the same type in Δ. Comparing this one obligation prevents a convenient notation from being mistaken for a transferred theorem.
De Bruijn substitutions
Let a typed context be a list with its newest declaration at the left. A typed de Bruijn variable 𝑖 :𝐴 ∈Γ is generated by 𝑋0:𝐴∈(𝐴,Γ)Zero𝑖:𝐴∈Γ𝑖+1:𝐴∈(𝐵,Γ)Succ. Terms are variables 𝑖, applications, and annotated abstractions 𝜆𝐴𝑡. A de Bruijn renaming 𝜌 :Γ →Δ maps each derivation 𝑖 :𝐴 ∈Γ to a derivation 𝜌(𝑖) :𝐴 ∈Δ. A de Bruijn substitution 𝜎 :Γ →Δ maps it to a term Δ ⊢𝗌𝗍𝜎(𝑖) :𝐴.
Under a binder, define 𝜌↑(0):=0,𝜌↑(𝑖+1):=𝜌(𝑖)+1,𝜎↑(0):=0,𝜎↑(𝑖+1):=𝗋𝖾𝗇𝖺𝗆𝖾(+1)(𝜎(𝑖)). The actions are structural: 𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑖):=𝜌(𝑖),𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑡𝑢):=𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑡)𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑢),𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝜆𝐴𝑡):=𝜆𝐴𝗋𝖾𝗇𝖺𝗆𝖾𝜌↑(𝑡), and substitution is defined separately by 𝑖[𝜎]:=𝜎(𝑖),(𝑡𝑢)[𝜎]:=𝑡[𝜎]𝑢[𝜎],(𝜆𝐴𝑡)[𝜎]:=𝜆𝐴(𝑡[𝜎↑]).
If Δ ⊢𝗌𝗍𝑠 :𝐵 and 𝜏 :Δ →Ξ, then 𝗋𝖾𝗇𝖺𝗆𝖾(+1)(𝑠[𝜏])=(𝗋𝖾𝗇𝖺𝗆𝖾(+1)𝑠)[𝜏↑]. Both sides are terms of type 𝐵 in the context obtained by adding the same newest declaration to Ξ.
Referenced from 2 locations
Proof of Lemma 61.18 — Weakening commutes with de Bruijn substitution
Proof. Prove the statement after 𝑘 enclosing binders simultaneously for every 𝑘 ≥0. The weakening renaming is then the 𝑘-fold lift ( +1)↑𝑘, and the substitution is 𝜏↑𝑘. Induct on 𝑠. For a variable 𝑖, the two sides are 𝗋𝖾𝗇𝖺𝗆𝖾(+1)↑𝑘(𝜏↑𝑘(𝑖))and((+1)↑𝑘(𝑖))[𝜏↑(𝑘+1)]; the zero and successor clauses of lifting make them identical. Application uses the two induction hypotheses. Under 𝜆𝐴, the defining clauses lift both the weakening and the substitution once, so the body equation is the induction hypothesis at 𝑘 +1. Taking 𝑘 =0 gives the displayed law. ◻
Given substitutions 𝜎 :Γ →Δ and 𝜏 :Δ →Ξ, define their pointwise composite by (𝜎;𝜏)(𝑖):=𝜎(𝑖)[𝜏]. This is initially a raw term map. The typing clause of the following lemma shows that each component has the type declared for 𝑖 in Γ.
For typed substitutions of the displayed domains, 𝑡[𝗂𝖽]=𝑡,𝑡[𝜎][𝜏]=𝑡[𝜎;𝜏],𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑡)=𝑡[𝗏𝖺𝗋∘𝜌]. If Γ ⊢𝗌𝗍𝑡 :𝐴 and 𝜎 :Γ →Δ, then Δ ⊢𝗌𝗍𝑡[𝜎] :𝐴.
Referenced from 6 locations
Proof of Lemma 61.19 — De Bruijn substitution laws
Proof. The three equations are inductions on 𝑡. In the abstraction case, the defining equations give (𝜎;𝜏)↑=𝜎↑;𝜏↑,𝗂𝖽↑=𝗂𝖽; the identity equation is proved on variables by the zero and successor cases. For composition, the zero case is reflexive, while the successor case is (𝜎↑;𝜏↑)(𝑖+1)=(𝗋𝖾𝗇𝖺𝗆𝖾(+1)𝜎(𝑖))[𝜏↑]𝑙𝑒𝑚𝑚𝑎61.18=𝗋𝖾𝗇𝖺𝗆𝖾(+1)(𝜎(𝑖)[𝜏])=(𝜎;𝜏)↑(𝑖+1). For typing, induct on Γ ⊢𝗌𝗍𝑡 :𝐴. The variable case is the defining property of 𝜎. Application uses both induction hypotheses. Abstraction uses 𝜎↑ :(𝐴,Γ) →(𝐴,Δ); its zero branch is typed by Zero, and its successor branch is typed by weakening the corresponding component of 𝜎. The object abstraction rule then gives the conclusion. ◻
Cofinite locally nameless syntax
A locally nameless term uses atoms 𝑥 for free variables and indices 𝑖―― for bound variables: 𝑡::=𝑥∣𝑖――∣𝑡𝑢∣𝜆𝐴𝑡. Opening 𝑡 at depth 𝑘 with 𝑢, written 𝑡[𝑘↦𝑢], replaces 𝑘―― by 𝑢 and increments the depth under a binder. Put 𝑡𝑢:=𝑡[0↦𝑢]. A term is locally closed when every bound index is captured by an enclosing lambda.
The cofinite abstraction rule is 𝐿⊆fin𝔸∀𝑥∉𝐿. Γ,𝑥:𝐴⊢𝗅𝗇𝑡𝑥:𝐵Γ⊢𝗅𝗇𝜆𝐴𝑡:𝐴→𝐵LN−Lam. Free-variable substitution 𝑡[𝑢/𝑥] ignores bound indices and enters 𝜆𝐴𝑡 without lifting.
If 𝑢 is locally closed and 𝑦 ∉FV(𝑢) ∪{𝑥}, then (𝑡𝑦)[𝑢/𝑥]=(𝑡[𝑢/𝑥])𝑦.
Referenced from 3 locations
Proof of Lemma 61.20 — Opening commutes with free substitution
Proof. Generalize opening from depth 0 to an arbitrary depth 𝑘 and induct on 𝑡. At the free atom 𝑥, the right side opens the inserted 𝑢 and local closure gives 𝑢[𝑘↦𝑦] =𝑢; a different free atom uses 𝑦 ≠𝑥. A bound index follows from the definition of opening. Application uses both induction hypotheses, and the abstraction case applies the body hypothesis at depth 𝑘 +1. ◻
If Γ,𝑥 :𝐴,Δ ⊢𝗅𝗇𝑡 :𝐵 and Γ ⊢𝗅𝗇𝑢 :𝐴, then Γ,Δ⊢𝗅𝗇𝑡[𝑢/𝑥]:𝐵. Consequently, free renaming and preservation are admissible for locally nameless typing.
Referenced from 4 locations
Proof of Lemma 61.21 — Locally nameless substitution
Proof. Induct on the typing derivation. Variables and application use the corresponding substitution clauses. In the abstraction case, let 𝐿 be the finite exclusion set in LN-Lam. Put 𝐿′:=𝐿∪FV(𝑢)∪dom(Γ,Δ)∪{𝑥}. Let 𝑦 ∉𝐿′ be arbitrary. The cofinite premise at this particular 𝑦 gives Γ,𝑥 :𝐴,Δ,𝑦 :𝐶 ⊢𝗅𝗇𝑡𝑦0 :𝐷. The induction hypothesis therefore gives Γ,Δ,𝑦:𝐶⊢𝗅𝗇(𝑡𝑦0)[𝑢/𝑥]:𝐷. Rule induction on the typing derivation of 𝑢 shows that 𝑢 is locally closed. Because 𝑦 ∉FV(𝑢) ∪{𝑥}, lemma 61.20 gives (𝑡𝑦0)[𝑢/𝑥]=(𝑡0[𝑢/𝑥])𝑦. Since 𝑦 was arbitrary outside 𝐿′, rule LN-Lam closes the abstraction with exclusion set 𝐿′. Free renaming is substitution by a variable; preservation is the statement proved above. ◻
For a finite typed simultaneous substitution 𝜎 =(𝑢1/𝑥1,…,𝑢𝑛/𝑥𝑛) :Γ ⇒Δ, where the 𝑥𝑖 are pairwise distinct, define 𝑡[𝜎] in one structural traversal: the atom 𝑥𝑖 maps to 𝑢𝑖, every other atom and every bound index is unchanged, application is componentwise, and the operation enters a lambda without lifting. If, in addition, 𝑥𝑖 ∉FV(𝑢𝑗) whenever 𝑖 ≠𝑗, this direct operation is equal to the right-to-left iteration 𝑡[𝜎]:=(⋯(𝑡[𝑢𝑛/𝑥𝑛])⋯)[𝑢1/𝑥1]. Every component 𝑢𝑗 of a typed substitution is locally closed. Induction on the typing derivation, using the variable lookup clause and the same cofinite binder argument as lemma 61.21, proves Δ⊢𝗅𝗇𝑡[𝜎]:𝐵wheneverΓ⊢𝗅𝗇𝑡:𝐵 and Δ⊢𝗅𝗇𝜎:Γ. Induction on 𝑡, using the same enlarged cofinite set in the abstraction case, gives 𝑡[𝗂𝖽] =𝑡 and 𝑡[𝜎][𝜏] =𝑡[𝜎;𝜏]. Thus the simultaneous operation invoked in theorem 61.26 is derived rather than silently identified with the one-variable lemma.
The finite set in LN-Lam is load-bearing. An existential rule choosing one atom would not support the fresh choice required after substituting a term whose free variables include that atom.
Parametric higher-order syntax
For a family 𝑉 indexed by object types, define the intrinsically indexed constructors 𝗏𝖺𝗋:𝑉(𝐴)→𝖳𝖾𝗋𝗆(𝑉,𝐴),𝖺𝗉𝗉:𝖳𝖾𝗋𝗆(𝑉,𝐴→𝐵)×𝖳𝖾𝗋𝗆(𝑉,𝐴)→𝖳𝖾𝗋𝗆(𝑉,𝐵),𝖺𝖻𝗌:(𝑉(𝐴)→𝖳𝖾𝗋𝗆(𝑉,𝐵))→𝖳𝖾𝗋𝗆(𝑉,𝐴→𝐵). For a typed object context, put 𝖤𝗇𝗏(𝑉,⋅):=𝟏,𝖤𝗇𝗏(𝑉,𝐴,Γ):=𝑉(𝐴)×𝖤𝗇𝗏(𝑉,Γ),𝖯𝖳𝖾𝗋𝗆(Γ,𝐴):=∏𝑉:𝖳𝗒→𝖲𝖾𝗍𝖤𝗇𝗏(𝑉,Γ)→𝖳𝖾𝗋𝗆(𝑉,𝐴). An inhabitant of 𝖯𝖳𝖾𝗋𝗆(Γ,𝐴) is an open parametric higher-order abstract syntax term, abbreviated PHOAS term; closed terms use Γ = ⋅. The quantifier alone is not the promised invariant. We state the relational condition that the host language must enforce or the representation theorem must assume.
Let 𝑅𝐴 ⊆𝑉(𝐴) ×𝑊(𝐴) be a relation family. Its Kripke lifting 𝖳𝖾𝗋𝗆𝖱𝖾𝗅(𝑅) relates variables by 𝑅, applications componentwise, and abstractions 𝑓,𝑔 when, for every extension 𝑅′ ⊇𝑅, ∀𝑣:𝑉(𝐴),𝑤:𝑊(𝐴).𝑅′𝐴(𝑣,𝑤)⟹𝖳𝖾𝗋𝗆𝖱𝖾𝗅(𝑅′)𝐵(𝑓(𝑣),𝑔(𝑤)). Extend 𝑅 componentwise to 𝖤𝗇𝗏𝖱𝖾𝗅(𝑅) ⊆𝖤𝗇𝗏(𝑉,Γ) ×𝖤𝗇𝗏(𝑊,Γ). A polymorphic 𝑝 :𝖯𝖳𝖾𝗋𝗆(Γ,𝐴) is parametric when 𝖤𝗇𝗏𝖱𝖾𝗅(𝑅)(𝛾,𝛿)⟹𝖳𝖾𝗋𝗆𝖱𝖾𝗅(𝑅)𝐴(𝑝(𝑉)(𝛾),𝑝(𝑊)(𝛿)) for every 𝑉,𝑊,𝑅,𝛾,𝛿.
Referenced from 6 locations
Fix an object type 𝐴. Suppose a non-parametric host supplies a polymorphic test 𝗂𝗇𝗌𝗉𝖾𝖼𝗍𝑉:𝑉(𝐴→𝐴)→𝖡𝗈𝗈𝗅 that, at the constant family 𝑉0(𝑋):=ℕ, tests whether its argument is zero. In the one-variable context Γ =(𝐴 →𝐴) define 𝑝𝖻𝖺𝖽(𝑉)(𝑣,∗):={𝗏𝖺𝗋(𝑣)𝗂𝗇𝗌𝗉𝖾𝖼𝗍𝑉(𝑣)=𝗍𝗋𝗎𝖾,𝖺𝖻𝗌(𝜆𝑤.𝗏𝖺𝗋(𝑤))𝗂𝗇𝗌𝗉𝖾𝖼𝗍𝑉(𝑣)=𝖿𝖺𝗅𝗌𝖾. Both branches have type 𝖳𝖾𝗋𝗆(𝑉,𝐴 →𝐴), so 𝑝𝖻𝖺𝖽 :𝖯𝖳𝖾𝗋𝗆(Γ,𝐴 →𝐴). Let 𝑅𝐴→𝐴 relate 0 to 1 at 𝑉0 and take the corresponding related environments. The first output has head 𝗏𝖺𝗋 and the second has head 𝖺𝖻𝗌, so no 𝖳𝖾𝗋𝗆𝖱𝖾𝗅(𝑅) derivation relates them. Thus 𝑝𝖻𝖺𝖽 violates definition 61.22. The universal quantifier excludes this inhabitant only in a host whose polymorphism enforces the relational condition; a host with the displayed inspection primitive does not.
Referenced from 3 locations
Let 𝑝 :𝖯𝖳𝖾𝗋𝗆(Γ,𝐵) satisfy definition 61.22. Let a typed renaming 𝜌 :Γ ⇒Δ provide, naturally in 𝑉, maps 𝜌𝑉:𝖤𝗇𝗏(𝑉,Δ)→𝖤𝗇𝗏(𝑉,Γ) that select a variable of the same object type for every declaration of Γ. Let a typed substitution 𝜃 :Γ ⇒𝑇Δ provide 𝜃𝑉:𝖤𝗇𝗏(𝑉,Δ)→𝖤𝗇𝗏(𝖳𝖾𝗋𝗆(𝑉,−),Γ) naturally and parametrically. Then:
For every relation family 𝑅 and every pair of 𝖤𝗇𝗏𝖱𝖾𝗅(𝑅)-related environments 𝛾,𝛿, the outputs 𝑝(𝑉)(𝛾) and 𝑝(𝑊)(𝛿) are 𝖳𝖾𝗋𝗆𝖱𝖾𝗅(𝑅)-related. In particular, their head constructors are equal.
renaming and simultaneous substitution have the type-preserving maps 𝗋𝖾𝗇𝖺𝗆𝖾𝜌:𝖯𝖳𝖾𝗋𝗆(Γ,𝐵)→𝖯𝖳𝖾𝗋𝗆(Δ,𝐵),𝖲𝗎𝖻𝗌𝗍𝜃:𝖯𝖳𝖾𝗋𝗆(Γ,𝐵)→𝖯𝖳𝖾𝗋𝗆(Δ,𝐵).
both operations preserve parametricity, and identity and composition hold extensionally at every 𝑉 and environment.
The equality in clause 3 is extensional HOAS equality: two abstraction fields are equal when they return equal bodies at every host argument. A host that expresses this equality by its intensional identity type must supply function extensionality.
Referenced from 3 locations
Proof of Theorem 61.24 — PHOAS renaming, substitution, and preservation
Proof. The obstruction in the proof is that 𝖳𝖾𝗋𝗆(𝑉, −) has no general functorial action on maps of variable families: 𝑉 occurs to the left of an arrow in 𝖺𝖻𝗌. Substitution instead instantiates the polymorphic term at the nested family 𝖳𝖾𝗋𝗆(𝑉, −) and uses graph-relation free theorems to justify flattening, identity, and composition.
Suppose a polymorphic test selected different constructors for two related environment entries 𝑣0,𝑣1. Relate them by 𝑅𝐴 and use equality on constructor tags as the result relation. Parametricity requires the two outputs to have related, hence equal, tags, a contradiction. The same argument applies beneath a binder because definition 61.22 quantifies over extensions 𝑅′ that add the fresh pair of bound variables.
Renaming is precomposition: 𝗋𝖾𝗇𝖺𝗆𝖾𝜌(𝑝)(𝑉)(𝛿):=𝑝(𝑉)(𝜌𝑉(𝛿)). Every component selected by 𝜌 has its declaration’s object type, so the result retains index 𝐵. Naturality of 𝜌 and parametricity of 𝑝 prove parametricity of the result.
For substitution, define the structural flattening function 𝖿𝗅𝖺𝗍(𝗏𝖺𝗋(𝑡)):=𝑡,𝖿𝗅𝖺𝗍(𝖺𝗉𝗉(𝑡,𝑢)):=𝖺𝗉𝗉(𝖿𝗅𝖺𝗍(𝑡),𝖿𝗅𝖺𝗍(𝑢)),𝖿𝗅𝖺𝗍(𝖺𝖻𝗌(𝑓)):=𝖺𝖻𝗌(𝜆𝑣.𝖿𝗅𝖺𝗍(𝑓(𝗏𝖺𝗋(𝑣)))) from 𝖳𝖾𝗋𝗆(𝖳𝖾𝗋𝗆(𝑉, −),𝐵) to 𝖳𝖾𝗋𝗆(𝑉,𝐵). The abstraction clause injects the target bound variable before passing it to the source body; every recursive call is on a constructor subterm. Put 𝖲𝗎𝖻𝗌𝗍𝜃(𝑝)(𝑉)(𝛿):=𝖿𝗅𝖺𝗍(𝑝(𝖳𝖾𝗋𝗆(𝑉,−))(𝜃𝑉(𝛿))). Every constructor in the definition carries its object type, so induction on the input proves that 𝖿𝗅𝖺𝗍 preserves the index 𝐵. Relational induction shows that flattening preserves related terms; together with parametricity of 𝑝 and 𝜃, this proves parametricity of the result.
The identity law uses the free theorem, not merely an induction on an arbitrary host function. Let 𝗆𝖺𝗉𝖵𝖺𝗋𝑉 :𝖤𝗇𝗏(𝑉,Γ) →𝖤𝗇𝗏(𝖳𝖾𝗋𝗆(𝑉, −),Γ) inject every environment component. Instantiate parametricity of 𝑝 with the graph of 𝗏𝖺𝗋. It gives 𝖳𝖾𝗋𝗆𝖱𝖾𝗅(graph(𝗏𝖺𝗋))(𝑝(𝑉)(𝛾),𝑝(𝖳𝖾𝗋𝗆(𝑉,−))(𝗆𝖺𝗉𝖵𝖺𝗋𝑉(𝛾))). Induction on that relational derivation proves that flattening its right-hand term returns its left-hand term; its abstraction case uses the extensional HOAS equality stated in the theorem. This is 𝖲𝗎𝖻𝗌𝗍𝗂𝖽(𝑝)(𝑉)(𝛾) =𝑝(𝑉)(𝛾).
For composition, let 𝜃 :Γ ⇒𝑇Δ and 𝜙 :Δ ⇒𝑇Ξ. Define their composite componentwise by (𝜃;𝜙)𝑉(𝜉):=𝖿𝗅𝖺𝗍𝖤𝗇𝗏(𝜃𝖳𝖾𝗋𝗆(𝑉,−)(𝜙𝑉(𝜉))), where 𝖿𝗅𝖺𝗍𝖤𝗇𝗏 applies 𝖿𝗅𝖺𝗍 to every environment component. By the componentwise definition of 𝖤𝗇𝗏𝖱𝖾𝗅, the graph of 𝖿𝗅𝖺𝗍 relates this nested environment to its 𝖿𝗅𝖺𝗍𝖤𝗇𝗏 image. Naturality and parametricity of 𝜃 and 𝜙 separately prove that the displayed composite is a natural, parametric substitution family. Instantiate parametricity of 𝑝 with that graph relation. It relates 𝑝(𝖳𝖾𝗋𝗆(𝖳𝖾𝗋𝗆(𝑉,−),−))(𝜃𝖳𝖾𝗋𝗆(𝑉,−)(𝜙𝑉(𝜉))) to 𝑝(𝖳𝖾𝗋𝗆(𝑉,−))((𝜃;𝜙)𝑉(𝜉)). Induction on this 𝖳𝖾𝗋𝗆𝖱𝖾𝗅(graph(𝖿𝗅𝖺𝗍)) derivation proves that flattening the left twice equals flattening the right once; the Kripke-related abstraction case again uses extensional HOAS equality. Unfolding the two substitution definitions therefore gives the exact pointwise equation 𝖲𝗎𝖻𝗌𝗍𝜙(𝖲𝗎𝖻𝗌𝗍𝜃(𝑝))(𝑉)(𝜉)=𝖲𝗎𝖻𝗌𝗍𝜃;𝜙(𝑝)(𝑉)(𝜉). This argument uses no functorial action of 𝖳𝖾𝗋𝗆 on variable-family maps; the negative occurrence of the variable family in 𝖺𝖻𝗌 supplies no such general action. Renaming identity and composition are ordinary precomposition. Thus free-variable renaming uses 𝜌, while beta-substitution uses the environment substitution 𝜃; neither operation requires an ill-typed closed “variable injection.” ◻
Contextual syntax
A contextual object [Γ ⊢𝐴] is an intrinsically typed term paired with the exact context of variables it may use. A contextual substitution 𝜎:[Δ⊢Γ] assigns to each declaration 𝑥 :𝐴 of Γ an object [Δ ⊢𝐴]. Its action is defined by variable lookup, componentwise application, and lifting beneath a lambda. Thus contextual syntax packages the domain and codomain that were external indices on de Bruijn substitutions.
If 𝑡 :[Γ ⊢𝐴] and 𝜎 :[Δ ⊢Γ], then 𝑡[𝜎] :[Δ ⊢𝐴]. Identity and composition satisfy 𝑡[𝗂𝖽Γ]=𝑡,𝑡[𝜎][𝜏]=𝑡[𝜎;𝜏]. For a fixed ordered typed context Γ and a chosen naming of its declarations, erasing names induces a bijection from contextual objects modulo alpha-renaming to typed de Bruijn terms. This bijection commutes with substitution.
Referenced from 3 locations
Proof of Proposition 61.25 — Contextual substitution
Proof. Induct on 𝑡. Variable lookup has the family declared by 𝜎. Application uses both induction hypotheses. Under an abstraction, extend 𝜎 by the new variable and weaken its old components; this is exactly the lifted substitution 𝜎↑ of lemma 61.19. The identity and composition equations follow by the same induction, with the abstraction case reduced to the corresponding lifted equations. Relative to the fixed ordered Γ, erasure maps the 𝑖th contextual variable to index 𝑖; its inverse selects the chosen name of the 𝑖th declaration. Changing that naming changes the inverse only by simultaneous alpha-renaming. Induction on terms proves both inverse equations modulo alpha and the substitution square. ◻
De Bruijn, cofinite locally nameless, parametric HOAS, and contextual syntax each admit capture-avoiding substitution and prove preservation for the fixed intrinsically typed STLC.
Referenced from 4 locations
Proof of Theorem 61.26 — One obligation, four proofs
Proof. The four preservation results are lemma 61.19, lemma 61.21, theorem 61.24, proposition 61.25. Each cited statement constructs substitution in its representation and proves the displayed typing implication of this section. ◻
★★★ Represent (𝜆(𝑥 :𝐴). 𝜆(𝑦 :𝐵). 𝑥) 𝑢 in all four representations. Perform the beta-substitution, naming the lifted substitution, fresh atom, relation family, or contextual substitution used in the binder case. Verify that all four results translate to the de Bruijn term 𝜆𝐵(𝗋𝖾𝗇𝖺𝗆𝖾(+1)𝑢). (Two pages.)
Referenced from 5 locations
The boundary of an encoding theorem
The adequacy theorems theorem 61.10, theorem 61.16 hold only for their displayed LF signatures, represented contexts, canonical forms, and object judgments. They do not imply adequacy for:
an extension of either signature by a constant returning 𝖽𝖾𝖽 𝑃 or 𝗍𝗆 𝐴;
raw STLC syntax with a separate typing family;
a framework with user-defined conversion rules;
nominal unification, contextual modal systems other than the displayed calculus, or a proof assistant’s full kernel.
Referenced from 3 locations
Proof of Proposition 61.28 — Adequacy is signature-relative
Proof. Completeness in both adequacy proofs inverts the finite list of possible heads in the displayed signature. An added result constant creates a new canonical head. Raw syntax changes the represented family and the inverse relation. User-defined conversion changes canonical forms. Nominal unification, different contextual calculi, and proof-assistant kernels have constructors and conversion rules absent from the two signatures. Thus every listed extension invalidates at least one premise of the canonical-head inversion. ◻
Generalized framework signatures can package declarations and proof-assistant kernels can check their elaborated terms. The trust obligation is kernel soundness for those declarations. The adequacy obligation remains a separate pair of inverse maps for each encoded judgment. Neither a successful kernel check nor a framework feature list proves those maps inverse.
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 61.5, then complete exercise 61.8.
★★☆ Choose a canonical LF object of family 𝖽𝖾𝖽 ⌜(𝑃 ⊃𝑄) ⊃(𝑃 ⊃𝑄)⌝ and run the inverse from theorem 61.10 constructor by constructor. Re-encode the object derivation and prove that the result is alpha-equivalent to the chosen LF object.
Referenced from 4 locations
★★☆ Add one constant 𝑘 :𝗍𝗆(𝖺𝗋𝗋 𝗂 𝗂) to Σ𝗌𝗍. Show that LF type checking and canonicalization still succeed for 𝑘, but the completeness inverse of theorem 61.16 has no case. State the weakest extension of the object syntax that would restore a bijection and prove the new head case.
Referenced from 3 locations
★★★ For the two-binder redex of exercise 61.4, remove one load-bearing binder condition in turn: de Bruijn lifting, the cofinite exclusion set, PHOAS relation extension, and the exact contextual domain. For each representation, give a concrete substitution whose result is ill-scoped, captured, non-parametric, or assigned the wrong contextual type. Then restore the condition and compute the corrected result. (Two pages.)
Referenced from 3 locations
★★★ Practical project.lf-adequacy-checker Implement in Agda or Kappa a canonical-form checker and decoder for the intrinsically typed LF signature Σ𝗌𝗍. Preserve the invariant that every accepted atomic object has a head declared in the input LF signature and is fully applied to canonical arguments. The program must decode the represented identity and application terms, reject an underapplied 𝗅𝖺𝗆, and report an exotic result head after the test signature adds 𝗂𝗇𝗌𝗉𝖾𝖼𝗍. Print either the decoded STLC term and type or the first failed canonical-head condition. Those four outcomes are the decidable acceptance test.
Referenced from 6 locations
Sources. The LF calculus and its metatheory originate with Harper, Honsell, and Plotkin [HHP93]. Canonical representations, judgments-as-types, and conversion are developed in [Pfe01]. The cofinite abstraction rule and its substitution proof follow [Cha12]. The PHOAS relation follows the representation discipline of [Chl08]; the theorem printed here states explicitly the parametricity hypothesis that the source identifies as essential.