Lectures onType Theory
Chapter 130
Chapter 130Optional

Dependent Multi-Stage Type Theory

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

A generator for vectors should return code whose type records the generated length. If a present-stage natural n occurs in the future type Vec An, ordinary modal code rejects it as an ordinary free variable. Allowing the occurrence without changing substitution is worse: substituting for n can change a type across a quotation boundary while leaving the term unchanged. Dependent staging needs one calculus whose stages, types, substitutions, and reductions agree.

The published card and its inversion-stable correction

A stage is a finite word A of stage variables; append is written Aα. Kinds and the selected source calculus have the grammars K::=Πx:τ.K,τ,σ::=XΠx:τ.στMατα.τ,M,N::=cxλx:τ.MMNMααMΛα.MMA%αM. A signature declares type constants and term constants. A context entry x:τ@A makes x available exactly at stage A. Judgments include ΓM:τ@A, Γτ::K@A, and ΓK kind@A. The empty signature is well formed; X::K may be added when K is a kind at the empty stage, and c:τ may be added when τ:: at the empty stage. A context may append fresh x:τ@A when τ::@A.

Kinds and types use these complete formation and checking rule families.

Γ kind@A
MD-Kind-Star
Γτ::@AΓ,x:τ@AK kind@A
ΓΠx:τ.K kind@A
MD-Kind-Pi
X::KΣ
ΓX::K@A
MD-TConst
Γσ::Πx:τ.K@AΓM:τ@A
ΓσM::K[M/x]@A
MD-TApp
Γτ::@Aα
Γατ::@A
MD-TCode
Γτ::K@AαFTV(Γ)FTV(A)
Γα.τ::K@A
MD-TForall
Γτ::@A
Γτ::@Aα
MD-TCSP
Γτ::K@AΓKJ@A
Γτ::J@A
MD-TConv

The rule MD-Pi below is the remaining type-formation family. There is no kind above . Thus a proposed derivation of Γ::@A fails: MD-Kind-Star forms a kind and no kinding rule has as its subject.

Dependent functions use formation, introduction, elimination, and beta conversion in the usual order, with every premise at the same stage:

Γτ::@AΓ,x:τ@Aσ::@A
ΓΠx:τ.σ::@A
MD-Pi
Γτ::@AΓ,x:τ@AM:σ@A
Γλx:τ.M:Πx:τ.σ@A
MD-Abs
ΓM:Πx:τ.σ@AΓN:τ@A
ΓMN:σ[N/x]@A
MD-App

Variables require an exact stage match:

c:τΣ
Γc:τ@A
MD-Const
x:τ@AΓ
Γx:τ@A
MD-Var
ΓM:τ@AΓτσ::@A
ΓM:σ@A
MD-Conv

Thus x:τ@A does not justify x:τ@Aα. The failed inference is the first-stage error in the naive vector generator. More explicitly, the only possible variable leaf would be n:Nat@εΓΓn:Nat@αMDVar, but the premise required by MD-Var is instead n:Nat@αΓ. The displayed tree is therefore not a derivation. The same failed lookup occurs when the future result type is Vec An.

Quotation and escape move in opposite directions.

ΓM:τ@Aα
ΓMα:ατ@A
MD-Quote
ΓM:ατ@A
ΓαM:τ@Aα
MD-Escape

Stage abstraction and application quantify the stage name.

ΓM:τ@AαFTV(Γ)FTV(A)
ΓΛα.M:α.τ@A
MD-SAbs
ΓM:α.τ@A
ΓMB:τ[B/α]@A
MD-SApp

Finally, cross-stage persistence is the source rule

ΓM:τ@A
Γ%αM:τ@Aα
MD-CSP

It persists a term syntactically; it is not the unrestricted persistence of references in an effectful host.

The displayed rules form the published λMD card. Its unrestricted type-equivalence CSP rule MD-QT-CSP does not preserve code-body inversion when stage words are noncommutative: from a body at Aα, lifting the code equality to Aβ does not produce a body equality at Aβα. The metatheorems below therefore use the inversion-stable fragment λisMD, which deletes MD-QT-CSP and changes no typing, term-equivalence, or reduction rule. The source rule remains displayed to make the delta auditable; no theorem below silently applies it. This corrected book-local system is a strict subsystem of the published typing/equality card, not the exact published calculus. The source’s preservation, normalization, confluence, and progress statements are therefore historical proof guides, not exact-signature imports. Each theorem below is proved for the corrected system from explicitly named source lemmas or local arguments.

The three mutually defined equivalence judgments are ΓKJ@A, Γτσ::K@A, and ΓMN:τ@A. Kind equivalence has five rules:

Γτσ::@AΓ,x:τ@AKJ@A
ΓΠx:τ.KΠx:σ.J@A
MD-QK-Pi
ΓKJ@A
ΓKJ@Aα
MD-QK-CSP
ΓK kind@A
ΓKK@A
MD-QK-Refl
ΓKJ@A
ΓJK@A
MD-QK-Sym
ΓKJ@AΓJI@A
ΓKI@A
MD-QK-Trans

Type equivalence is the least equivalence closed by every type constructor and implicit type-level CSP:

Γτσ::@AΓ,x:τ@Aρπ::@A
ΓΠx:τ.ρΠx:σ.π::@A
MD-QT-Pi
Γτσ::Πx:ρ.K@AΓMN:ρ@A
ΓτMσN::K[M/x]@A
MD-QT-App
Γτσ::@Aα
Γατασ::@A
MD-QT-Code
Γτσ::@AαFTV(Γ)FTV(A)
Γα.τα.σ::@A
MD-QT-Forall
Γτσ::@A
Γτσ::@Aα
MD-QT-CSP
Γτ::K@A
Γττ::K@A
MD-QT-Refl
Γτσ::K@A
Γστ::K@A
MD-QT-Sym
Γτσ::K@AΓσρ::K@A
Γτρ::K@A
MD-QT-Trans

Term congruence follows every term constructor:

Γτσ::@AΓ,x:τ@AMN:ρ@A
Γλx:τ.Mλx:σ.N:Πx:τ.ρ@A
MD-Q-Abs
ΓML:Πx:σ.τ@AΓNO:σ@A
ΓMNLO:τ[N/x]@A
MD-Q-App
ΓMN:τ@Aα
ΓMαNα:ατ@A
MD-Q-Quote
ΓMN:ατ@A
ΓαMαN:τ@Aα
MD-Q-Escape
ΓMN:τ@AαFTV(Γ)FTV(A)
ΓΛα.MΛα.N:α.τ@A
MD-Q-SAbs
ΓMN:α.τ@A
ΓMBNB:τ[B/α]@A
MD-Q-SApp
ΓMN:τ@A
Γ%αM%αN:τ@Aα
MD-Q-CSP
ΓM:τ@A
ΓMM:τ@A
MD-Q-Refl
ΓMN:τ@A
ΓNM:τ@A
MD-Q-Sym
ΓMN:τ@AΓNL:τ@A
ΓML:τ@A
MD-Q-Trans

Its four computational axioms are:

Γ,x:σ@AM:τ@AΓN:σ@A
Γ(λx:σ.M)NM[N/x]:τ[N/x]@A
MD-Q-Beta
ΓMN:τ@Aα
ΓαMαN:τ@Aα
MD-Q-Splice
ΓΛα.M:α.τ@A
Γ(Λα.M)BM[B/α]:τ[B/α]@A
MD-Q-StageBeta
ΓM:τ@AαΓM:τ@A
Γ%αMM:τ@Aα
MD-Q-Percent

The general stage word B in MD-Q-StageBeta follows the full-rule appendix of the cited source. Its main-text Q-Λ display restricts the same equation to the empty word; this chapter uses the appendix card consistently. The last axiom removes CSP only when the same term checks at both stages. For a constant c, MD-Const supplies both premises. For a variable declared only at A, the first premise fails. This side condition is why definitional equality is larger than the compatible closure of full reduction.

For an immediate calculation, let f:Πx:Nat.Nat@A and n:Nat@A. Rule MD-Q-Beta gives (λx:Nat.fx)nfn:Nat@A. Rule MD-Q-Quote transports this equality to code at the preceding stage, and MD-Q-Splice contracts the matching escape–quotation pair. In contrast, MD-QT-CSP applied to αρατ::@A yields an equality at Aβ while its bodies remain related at Aα, not Aβα. This concrete stage-order mismatch is the counterexample that forces the inversion-stable delta recorded above.

For a type constant Nat::, the dependent identity has the full derivation ΓNat::@Ax:Nat@AΓ,x:Nat@AΓ,x:Nat@Ax:Nat@AMDVarΓλx:Nat.x:Πx:Nat.Nat@AMDAbs. If f:Πx:Nat.Nat@A is a variable, then fc is a well-typed neutral application. No full-reduction rule fires at its head.

For n:Nat@ε, rule MD-CSP gives %αn:Nat@α. Hence a quoted vector constructor may have type α(Vec A(%αn)) at the empty stage. Omitting %α fails at MD-Var; placing it around a term already at Aα fails the premise of MD-CSP.

Fix a type constant A:: and signature constants nil:Vec A0,cons:Πn:Nat.AVec AnVec A(sucn), and a0,a1:A. Repeated MD-CSP and MD-App at stage α derive Γcons1(%αa1)(cons0(%αa0)nil):Vec A2@α. Rule MD-Quote therefore gives code of Vec A2 at the empty stage. Since MD-Const types a0,a1 at every stage, their CSP markers are redundant for typing and removable by MD-Q-Percent; they nevertheless make the intended persistence operation explicit. A context variable declared only at ε still requires CSP, as the preceding n-example shows. The closed constants make this seminar generator a staged value under the grammar used below.

Lemma 130.1 — Code-head inversion for type equivalence

In the inversion-stable fragment, if Γαρσ::@A and Γρ::@Aα, then σ is syntactically ατ for some τ, and Γρτ::@Aα. If instead Γσαρ::@A and Γρ::@Aα, then σ is syntactically ατ and Γτρ::@Aα for some τ.

Proof of Lemma 130.1 — Code-head inversion for type equivalence

Proof. First, induction on a type-equivalence derivation proves regularity: both endpoint types check at the displayed kind and stage. Constructor congruences rebuild their formation rules, reflexivity has formation as a premise, symmetry exchanges endpoints, and transitivity composes the two induction hypotheses. The corrected system has no MD-QT-CSP case.

Prove both orientations simultaneously by induction on the displayed type-equivalence derivation. In MD-QT-Code, the conclusion has the required head and its premise is the required body equality. In reflexivity, the additional body-formation hypothesis supplies body reflexivity at Aα. Symmetry exchanges the two induction statements.

For transitivity in the first orientation, the first induction hypothesis writes the middle type as ατ and gives ρτ at Aα. Regularity of that equality supplies the formation premise needed by the second induction hypothesis. The second hypothesis writes the final type as αυ and gives τυ; transitivity at Aα completes the case. The reverse orientation exchanges the two induction statements. The Pi, application, and stage-quantifier congruences cannot have a code constructor on the displayed side. These are every type-equivalence rule in the corrected system.

The published proof’s simultaneous-inversion architecture motivates this induction , but its exact signature also has MD-QT-CSP. That missing case is not imported: at a code head it gives the noncommutative stage-order counterexample above. The explicit body-formation premise is necessary because published type-level CSP can form a code-headed type at a later word without furnishing code-formation inversion at that word. ◻

Lemma 130.2 — Quotation and escape inversion

In the inversion-stable fragment, if ΓMα:σ@A, then σ is syntactically ατ for some τ, and ΓM:τ@Aα. If ΓαM:τ@Aα, then there is a ρ such that ΓM:αρ@A and either ρ is syntactically τ, or Γρτ::@Aα.

Proof of Lemma 130.2 — Quotation and escape inversion

Proof. The source’s printed quotation-inversion premise uses @A; the quotation conclusion and MD-Quote force @Aα. We use that corrected stage annotation, which is also forced by the simultaneous inversion induction. Induct upward through trailing uses of MD-Conv. The first non-conversion rule is respectively MD-Quote or MD-Escape. In the quote case, regularity of the direct quote premise supplies the body-formation hypothesis of lemma 130.1; that lemma transports the body premise through every trailing type conversion and preserves the syntactic code head. In the escape case, retain the body type ρ from MD-Escape. With no trailing conversion it is syntactically the conclusion type. Otherwise the trailing conversions compose to Γρτ::@Aα. These cases establish exactly the stated alternatives without assuming code-formation inversion for a type introduced only by published type-level CSP. ◻

Exercise 130.1

★☆☆ With context variables n:Nat@ε and v:Vec An@ε, derive the type of %αvα. Identify the exact failed premise after removing %α.

Two substitutions cross the stage boundary

Ordinary substitution [N/x] replaces terms and dependent occurrences in types. Stage substitution [B/α] replaces stage variables in stage words, quotation labels, escapes, CSP, and types; it alpha-renames a bound stage variable before crossing Λ. Representative defining equations are (λx:τ.M)[B/α]=λx:τ[B/α].M[B/α],(MC)[B/α]=M[B/α]C[B/α],Mβ[B/α]=M[B/α]β[B/α],(βM)[B/α]=β[B/α]M[B/α],(%βM)[B/α]=%β[B/α]M[B/α],(βC)[B/α]={β(C[B/α]),βα,B(C[B/α]),β=α. Primitive quotation, escape, and CSP nodes carry one stage variable. For a word α1αn, the source’s derived notation denotes iteration in source order for quotation and in reverse order for escape and CSP. At the empty word all three operations are the identity. Consequently, stage substitution can expand one primitive occurrence into n nodes when it replaces its label by a word of length n. It introduces no stage abstraction or stage-application node. These conventions determine the quote, escape, and CSP cases below; they are part of the syntax definition.

Let J range over the six judgment shapes K kind@C,τ::K@C,M:τ@C,KJ@C,τσ::K@C,ML:τ@C. Substitution acts on every term, type, kind, stage annotation, and context entry displayed in a judgment.

Lemma 130.3 — Simultaneous structural and substitution package

Well-formed contexts and all six judgments admit weakening and exchange of independent entries. Moreover, capture-avoiding substitution satisfies both of the following schemas. Γ,x:ξ@B,ΓJ,ΓN:ξ@BΓ,Γ[N/x]J[N/x],ΓJΓ[D/α]J[D/α]. The same implications hold with the judgment conclusion replaced by context well-formedness. For every expression E, where E may be a context, kind, type, or term, the two substitutions commute up to alpha-equivalence: E[N/x][D/α]αE[D/α][N[D/α]/x]. Choose term binders outside the free term names of E and N, and choose stage binders outside the free stage names of E and D. If a fixed deterministic convention selects among those names, the two representatives are syntactically equal.

Proof of Lemma 130.3 — Simultaneous structural and substitution package

Proof. Prove weakening, exchange, ordinary substitution, and stage substitution simultaneously for context well-formedness and the six judgment families. Context extension uses the type-kinding induction hypothesis for the declared type. In MD-Var, ordinary substitution uses the premise ΓN:ξ@B when the selected variable is x, and otherwise rebuilds membership in the substituted context. The variable case of stage substitution changes both the declaration and its exact stage annotation.

For MD-Kind-Pi, MD-Pi, MD-Abs, and every dependent congruence, alpha-rename the term binder away from N, apply the induction hypotheses to the domain and binder-extended premise, and rebuild the rule. MD-TApp, MD-App, and MD-Q-App additionally use the structural composition law for dependent substitution in their result kind or type. The constructor rules for code, quotation, escape, and CSP apply the induction hypothesis at the premise stage and then rebuild the derived word-labelled rule determined by the substituted annotation.

For MD-TForall, MD-SAbs, MD-QT-Forall, and MD-Q-SAbs, alpha-rename the bound stage variable outside the free stage variables of the substituting word D and the substituted expressions. The freshness premise is then preserved. Stage application substitutes in its result type as well as its term premise. Reflexivity, symmetry, and transitivity use the corresponding formation or equality induction hypotheses. The conversion rules MD-TConv and MD-Conv use, respectively, the simultaneously proved kind- and type-equivalence clauses; this is why a typing-only induction would be insufficient. Each computational equality axiom uses the typing clauses for its premises and the substitution composition law for its contractum. These cases exhaust context formation, kind formation, type kinding, term typing, and the three equivalence families.

Finally, prove the interaction equation by structural induction on E. Constructor cases commute componentwise. At a term or stage binder, rename the binder outside the free names of N, N[D/α], and D, then use the induction hypothesis for the body. The resulting representatives differ only by those bound-name choices, which proves alpha-equivalence and the stated deterministic-representative corollary. ◻

Full reduction and staged execution differ

Let C range over arbitrary finite stage words. Full reduction contracts terms only. Its one-hole full contexts are F::=[]λx:τ.FFMMFFααFΛα.FFB%αF. In particular, no full context enters a binder annotation, a type, a kind, or a stage word. This makes precise the source’s phrase “least compatible relations on terms”: compatibility stays within the term syntactic category. The relation contains exactly three root contractions: (λx:τ.M)NM[N/x],αMαM,(Λα.M)CM[C/α]. If RR is one of these root contractions, then F[R]F[R]. These are all full-reduction rules. There is no CSP contraction. Substituting the empty stage for α erases %α syntactically; MD-Q-Percent is instead a typed equivalence axiom with two premises.

The term-only boundary exposes a failure in the source’s exact syntactic confluence claim.

Proposition 130.4 — Dependent annotations obstruct exact confluence

Full reduction on well-typed terms is not syntactically confluent. This failure already occurs without staging constructs and without MD-QT-CSP.

Proof of Proposition 130.4 — Dependent annotations obstruct exact confluence

Proof. Take a signature containing Nat::,F::Πn:Nat.,c:Nat, and put L=(λz:Nat.z)c,T=(λx:Nat.λy:Fx.y)L. Rules MD-TApp, MD-Abs, and MD-App derive L:Nat@ε and T:(Πy:FL.FL)@ε. Contracting the outer redex gives TU=λy:FL.y. Reducing the argument first and then contracting the outer redex gives T(λx:Nat.λy:Fx.y)cV=λy:Fc.y. Rule MD-Q-Beta, followed by MD-QT-App and dependent-product congruence, gives Πy:FL.FLΠy:Fc.Fc::@ε, so conversion types both arms at the original result type. The only redex in U occurs inside its binder annotation. No displayed full context reaches it; hence U and V are distinct full normal forms. They have no common reduct. ◻

Extending compatibility into annotations would make UV, but that is a different mutually sorted reduction. It would also invalidate the nonempty simple-erasure simulation below because (FL)=F=(Fc). The corrected local card therefore retains term-only reduction, strong normalization for that relation, and the annotation-erased confluence theorem proved below. It does not repeat the published exact-confluence claim [KI19a].

Staged reduction s is deterministic, left-to-right, and indexed by stages. Constant-headed neutral spines hA and values VA are defined mutually by hε::=chεvεhεB,hA::=cxhAvAhABαhε(A=α),vε::=hελx:τ.MvααΛα.vε,vA::=hAλx:τ.vAvAvAvAααΛα.vAvABαvA(A=Aα, Aε)%αvA(A=Aα). The source omits term constants from its value grammar although MD-Const types them at every stage. The displayed book-local delta closes constant heads under ordinary and stage application. At a nonempty stage it also classifies an escape whose empty-stage operand is a neutral constant spine; a quoted operand remains a splice redex. Thus cv, cB, and α(cB) are final forms, while αvα is not. These productions enable no reduction and leave preservation, full normalization, and annotation-erased confluence unchanged. Let D be either ε or one stage variable. The hole of EDA is at stage D, while the whole context is at stage A: EDε::=[] (D=ε)EDεMvεEDεEDααΛα.EDεEDεC,EDA::=[] (A=D)λx:τ.EDAEDAMvAEDAEDAαααEDA (Aα=A)Λα.EDAEDAC%αEDA (Aα=A). The redexes are Rε::=(λx:τ.M)vε(Λα.vε)C,Rα::=αvαα. The staged relation consists of these three rule schemas: EεA[(λx:τ.M)vε]sEεA[M[vε/x]],EεA[(Λα.vε)C]sEεA[vε[C/α]],EαA[αvαα]sEαA[vα]. The source prints C=ε in one redex grammar but admits an arbitrary stage word in the contraction schema. The card uses the contraction schema: C is unrestricted in the stage-beta redex, while D records only the stage at which a redex is selected. Thus the grammar and decomposition theorem quantify over the same redex. In particular, (Λα.c)(βγ) is an empty-stage redex, not a stuck nonvalue, and the stage-beta rule gives the calculation (Λα.c)(βγ)sc. The staged relation does not normalize arbitrary code bodies at the generation stage. Thus (λx:τ.x)cα reduces under full reduction but is a code value for empty-stage execution.

Theorem 130.5 — Preservation

For the inversion-stable fragment, if ΓM:τ@A and MN, then ΓN:τ@A. The same conclusion holds for one staged step MsN at stage A.

Proof of Theorem 130.5 — Preservation

Proof. Induct on the reduction derivation. For full beta, invert trailing MD-Conv rules, then invert MD-App and MD-Abs. Ordinary substitution from lemma 130.3 types the contractum at the dependent result type; reapply the inverted conversions. Quote–escape inversion uses lemma 130.2: escape inversion produces a body type ρ, while quote inversion types the contractum at ρ@Aα. If ρ is syntactically τ, this is already the required judgment; otherwise escape inversion supplies Γρτ::@Aα, and MD-Conv gives it. Stage beta first inverts MD-SApp and MD-SAbs; stage substitution types M[C/α] at τ[C/α]@A, and alpha-renaming preserves the freshness premise.

For compatibility in the displayed full contexts beneath an ordinary abstraction, application, quotation, escape, stage abstraction, or stage application, apply the induction hypothesis to the selected premise and rebuild respectively MD-Abs, MD-App, MD-Quote, MD-Escape, MD-SAbs, or MD-SApp. The quotation case changes the premise stage to Aα; the escape case changes it back to A. A step beneath CSP is typed by the induction hypothesis at A and rebuilt by MD-CSP at Aα. A trailing MD-Conv reuses its unchanged type-equivalence premise after applying the induction hypothesis to the term premise. These are every compatible term constructor and conversion. There is no compatibility case for a binder annotation or another type expression. Each staged evaluation context selects one of these cases, so the staged assertion follows from the same derivation. ◻

The erasure used for normalization is defined locally. On terms it is homomorphic for variables, constants, ordinary abstraction, and application, and it deletes staging constructors: Mα=(αM)=(Λα.M)=(MB)=(%αM)=M. On types, X=X,(Πx:τ.σ)=τσ,(τM)=τ,(ατ)=τ,(α.τ)=τ. Erase every kind to the one simple kind. Signature erasure retains each type constant as a simple type constant and changes each declaration c:τ to c:τ. Context erasure keeps term declarations and drops their stages: =,(Γ,x:τ@A)=Γ,x:τ. The published translation prints an additional type-variable-context clause on physical page 30, but the published context grammar on physical page 6 has no such entry. The local translation therefore has no unreachable clause. These equations extend the source translation. The source omits clauses for constants and CSP and prints type application only at a variable argument; the local total translation adds c=c, deletes CSP, and treats an arbitrary type-level term argument uniformly . The simulation statement below is proved for the corrected rule signature.

Lemma 130.6 — Simple erasure and full-step simulation

If ΓM:τ@A in λisMD, then the simply typed judgment ΓM:τ holds. Moreover, an ordinary-beta full step maps to a nonempty simply typed beta sequence, whereas a stage-beta or splice full step leaves erasure syntactically equal. The same classification holds under every displayed full context F.

Proof of Lemma 130.6 — Simple erasure and full-step simulation

Proof. Prove erasure of kinding, typing, and the three equivalence judgments simultaneously. Kind and type constants use their erased signature entries. Dependent product formation, ordinary abstraction, and ordinary application become the simple arrow rules. Erasure commutes with dependent result substitution: (σ[N/x])=σ. Code, quotation, escape, stage abstraction/application, and CSP erase to their premises. Conversion uses the simultaneous assertion τστ=σ. Constructor congruences preserve that equality, and each computational equality has identical erasure or one simple beta equality. Reflexivity, symmetry, and transitivity preserve it. These cases cover every retained rule; the corrected system has no MD-QT-CSP case.

For reduction, ordinary beta uses (M[N/x])=M[N/x], proved by structural induction on M, and contracts the erased beta redex. Stage substitution changes only stage annotations and their derived staging nodes; erasure deletes both, so stage beta has equal erasures. Quote and escape are both erased, so splice also has equal erasures. An induction on the full-context derivation transports the corresponding beta sequence or syntactic equality through the erased context. These are all three root contractions and every term-only compatibility family. The qualification is essential: a hypothetical beta step inside a type annotation would erase to equality, as proposition 130.4 demonstrates. ◻

Theorem 130.7 — Strong normalization of full reduction

In the inversion-stable fragment, if ΓM:τ@A, no infinite sequence M=M0M1 exists.

Proof of Theorem 130.7 — Strong normalization of full reduction

Proof. By lemma 130.6, M is simply typed. An ordinary beta step gives a nonempty target beta reduction; splice and stage beta leave the translation equal. Let s(M) count stage-abstraction and stage-application nodes, and let q(M) count quotation and escape nodes. Order (s(M),q(M)) lexicographically. A stage-beta contraction strictly decreases the first component. It may expand derived word-labelled quotation, escape, or CSP notation, but it cannot change the first component; quote and escape expansion may increase the second. A splice preserves the first component and strictly decreases the second. Stage substitution introduces no stage abstraction or stage-application node. Ordinary beta may increase both components, but an infinite source reduction with infinitely many ordinary-beta steps would give an infinite simply typed beta reduction. If it had only finitely many, its tail would strictly decrease the displayed lexicographic pair at every step, also impossible. This lexicographic argument repairs the published proof’s insufficient raw-size sentence. Only strong normalization of the simply typed target is imported; the source-to-target simulation is the local lemma above. Classifying constant-headed spines as final forms does not add a full-reduction step. ◻

Exact confluence fails only because ordinary substitution changes dependent binder annotations that full reduction deliberately freezes. Remove those annotations while retaining every computational and staging constructor. The binder-annotation erasure has target grammar u,v::=cxλx.uuvuααuΛα.uuB%αu and is defined by ca=c,xa=x,λx:τ.Ma=λx.Ma,MNa=MaNa,Mαa=Maα,αMa=αMa,Λα.Ma=Λα.Ma,MBa=MaB,%αMa=%αMa. Alpha-equivalent target terms are identified. This erasure differs from (): it deletes only ordinary binder types and retains quotation, escape, stage abstraction/application, and CSP.

Put the three root contractions and the term-compatible closure above on the annotation-free grammar, and write the resulting relation as a. A primitive splice can become a tower of splices after stage substitution, so ordinary one-layer parallel reduction is insufficient. For a word B=β1βn, define the derived shells qB(u)=uβnβ1,eB(u)=βnβ1u,pB(u)=%βn%β1u. All three shells are the identity at B=ε. These equations are the iteration convention of section 130.2; for example, (αcα)[βγ/α]=γ(βcγβ). Contracting only the inner β-splice exposes a γ-splice, so this term does not reduce to c in one ordinary parallel step.

Define word-parallel reduction w by the rules

uwu
WP-Refl
u1wv1ukwvk
H(u1,,uk)wH(v1,,vk)
WP-Cong

where H ranges over the seven constructor schemas λx.(), ()(), α, α(), Λα.(), C, and %α(). Constants and variables use reflexivity, and stage words are unchanged. Add ordinary beta, stage beta for every finite word C, and one word-splice rule for every nonempty finite word B:

uwuvwv
(λx.u)vwu[v/x]
WP-Beta
uwuBε
eB(qB(u))wu
WP-Splice
uwu
(Λα.u)Cwu[C/α]
WP-StageBeta

Rule WP-Splice contracts the entire derived splice tower in one word-parallel step. At B=α it is the primitive splice rule. The other two root rules are WP-Beta and WP-StageBeta.

Lemma 130.8 — Substitution compatibility of word-parallel reduction

For annotation-free terms u,u,v,v, a term variable x, a stage variable α, and an arbitrary finite stage word C, uwu,vwvu[v/x]wu[v/x],uwuu[C/α]wu[C/α].

Proof of Lemma 130.8 — Substitution compatibility of word-parallel reduction

Proof. Prove the two assertions simultaneously by induction on the displayed word-parallel derivation. Alpha-rename term and stage binders outside the free names of the substituting expression or word before applying an induction hypothesis. At an ordinary-beta root, let y be its term binder and let a,a be its annotation-free argument endpoints. Ordinary beta uses the ordinary-substitution assertion twice and the substitution-composition equation. After alpha-renaming yx outside the free variables of v, the decisive equation is u[a/y][v/x]αu[v/x][a[v/x]/y]. At a stage-beta root, let D be its finite stage-word argument. Stage beta uses the stage-substitution assertion on its body. After renaming the bound stage variable δ outside C, its composition equation is u[D/δ][C/α]αu[C/α][D[C/α]/δ].

For a word-splice root with shell word B, ordinary substitution leaves the shell unchanged and the body induction hypothesis supplies the premise of the same root rule. Stage substitution changes its shell word to B[C/α]. If this word is nonempty, apply the word-splice rule to the body induction hypothesis. If it is empty, both shells erase by definition and that induction hypothesis is already the required conclusion. A primitive quotation, escape, or CSP congruence whose label is α expands to a shell indexed by C; induction on the length of C rebuilds the required single congruence derivation. The other constructor congruences rebuild directly. These cases exhaust the three root rules and the seven congruence schemas. ◻

Lemma 130.9 — Word-parallel diamond

If uwv1 and uwv2, then there is an annotation-free term z with v1wz and v2wz.

Proof of Lemma 130.9 — Word-parallel diamond

Proof. Define the complete development u recursively. A term has at most one outer word-splice shell: reading its consecutive outer escape labels and then the immediately following quotation labels determines the nonempty word B. At that shell and at the other two root-redex shapes set ((λx.u)v)=u[v/x],(eB(qB(u)))=u(Bε),((Λα.u)C)=u[C/α], and otherwise rebuild the outer constructor from the complete developments of its term children.

First prove uwu by structural induction. At a root redex, apply the corresponding word-parallel root rule to the induction hypotheses for its term children. Otherwise apply congruence. Next induct on uwv. The root cases use lemma 130.8; the word-splice case uses the induction hypothesis for its body. A congruence derivation either rebuilds a nonredex constructor or retains one of the three root shapes. Ordinary beta and stage beta then use their root rules on the induction hypotheses for the children.

The remaining overlap is a congruence derivation from an outer shell eB(qB(u)). A congruence derivation cannot contract the outermost escape. Induction on |B| therefore gives exactly two possibilities. Either every shell constructor remains, or an inner word-splice step removes a prefix of B. In both cases the reduct has the form eC(qC(v)),Cε,uwv, where C is respectively B or the unique nonempty suffix left after the contracted prefix. For B=βγ, contracting the inner β-shell leaves eγ(qγ(v)). The induction hypothesis gives vwu, and the word-splice root rule sends the retained C-shell to u in one step. This treats the congruence-versus-generalized-root overlap. Thus the induction proves the triangle property uwvvwu. Both reducts in the statement therefore reduce to u. ◻

Proposition 130.10 — Confluence of annotation-free reduction

The relation a is confluent on annotation-free terms.

Proof of Proposition 130.10 — Confluence of annotation-free reduction

Proof. Every a step is a word-parallel step. Conversely, induction on a word-parallel derivation expands it to a: congruence interleaves the finite child sequences; ordinary and stage beta contribute one root contraction after the child sequences; and a word-splice root indexed by B contributes exactly |B| primitive splice contractions after the body sequence. By lemma 130.9, the word-parallel relation has the diamond property. The two inclusions imply (a)=(w). Induction on the length of one word-parallel path, with an inner induction that moves its first step across the other path one diamond at a time, proves confluence of its reflexive-transitive closure. The displayed equality therefore gives confluence of a. ◻

Theorem 130.11 — Confluence modulo binder annotations

In the inversion-stable fragment, suppose ΓM:τ@A, MM, and MM. There are terms N,N and an annotation-free term u such that MN,MN,Na=u=Na. No claim that N=N is made.

Proof of Theorem 130.11 — Confluence modulo binder annotations

Proof. Structural induction on terms and on the displayed full contexts gives both directions needed for lifting: PQPaaQa,PaauQ. PQ  Qa=u. For ordinary beta these statements use P[Q/x]a=Pa[Qa/x]; for stage beta they use the exact equation P[B/α]a=Pa[B/α], where B is the substituted stage word. Splice is homomorphic. No annotation case occurs because neither relation reduces there.

Project the two reductions from M to the annotation-free relation. By proposition 130.10, their erasures have a common target u. Lift the two joining sequences back one step at a time. The lifted endpoints are the required N and N. The counterpeak of proposition 130.4 shows why the conclusion cannot in general be strengthened to N=N. ◻

Corollary 130.12 — Unique full normal forms modulo annotations

If two full normal forms are reachable from one well-typed term in the inversion-stable fragment, their binder-annotation erasures are alpha-equivalent.

Proof of Corollary 130.12 — Unique full normal forms modulo annotations

Proof. Apply theorem 130.11. Normality makes both joining sequences empty, so the theorem’s final annotation-free terms are equal. ◻

Lemma 130.13 — Type-constructor head separation

In the inversion-stable fragment, suppose Γτσ::@A. If either endpoint has outer constructor Π, α, or , then the other endpoint has the same outer constructor. In the code case the stage label is the same α.

Proof of Lemma 130.13 — Type-constructor head separation

Proof. Prove both orientations simultaneously by induction on the type-equivalence derivation. Rules MD-QT-Pi, MD-QT-Code, and MD-QT-Forall preserve the displayed outer constructor, and MD-QT-Refl preserves it syntactically. Rule MD-QT-App has a type application at both endpoints, so none of the three hypotheses can hold in that case. Symmetry exchanges the two induction statements. In a transitivity derivation, the first induction hypothesis gives the same head for the middle type and the second gives that head for the final type. The inversion-stable fragment has no MD-QT-CSP case. These are all type-equivalence rules. ◻

Lemma 130.14 — Empty-stage value heads

Suppose Γ has no variable declared at stage ε, vVε, and Γv:τ@ε.

  1. If τ=Πx:ρ.σ, then either v=λx:ρ.M for some ρ,M, or vhε.

  2. If τ=αρ, then either v=wα for some wVα, or vhε.

  3. If τ=α.ρ, then either v=Λα.w for some wVε, or vhε.

Proof of Lemma 130.14 — Empty-stage value heads

Proof. Inspect the four productions of vε. A neutral constant-headed spine gives the stated neutral alternative. In the other three productions, invert trailing uses of MD-Conv. The first non-conversion rule is respectively MD-Abs, MD-Quote, or MD-SAbs, so its result type is headed respectively by Π, β, or . Every trailing conversion preserves that head by lemma 130.13; in the code case it also preserves β. Hence exactly the production named in each clause can remain besides the neutral alternative. The empty-stage context hypothesis excludes a variable head through the exact-stage premise of MD-Var. ◻

Theorem 130.15 — Unique staged decomposition

In the inversion-stable fragment, suppose Γ has no variable declared at stage ε and ΓM:τ@A. Write VA for the grammar vA above. Either MVA, or there are a unique redex stage D{ε}{αα is a stage variable}, a unique context EDA, and a unique redex RD such that M=EDA[RD]. The stage word C in a stage-beta redex is unrestricted.

Proof of Theorem 130.15 — Unique staged decomposition

Proof. Induct on the final typing rule. The induction hypothesis includes uniqueness for each premise to which staged evaluation descends.

For MD-Const, the term belongs to hA. In MD-Var, the exact stage premise contradicts the context hypothesis when A=ε; at a nonempty stage the variable belongs to hA.

For MD-Abs, an abstraction at ε is a value because its body is not selected there. At a nonempty stage, apply the induction hypothesis to the body under Γ,x:τ@A. The added declaration is not at ε. A body value gives the abstraction-value production; a body decomposition is lifted by the unique λx:τ.EDA context production.

For MD-App, first apply the induction hypothesis to the function. Its decomposition lifts uniquely to EDAN. If the function is a value, apply the induction hypothesis to the argument; its decomposition lifts uniquely to vAEDA. If both are values and Aε, the production vAvA makes the whole application a value. If A=ε, the function has dependent-product type, so clause 1 of lemma 130.14 leaves two cases. A lambda head gives the unique ordinary-beta redex; a head in hε extends uniquely to the final spine hεvε. Quotation and stage- abstraction heads are excluded by the cited lemma.

For MD-Quote, apply the induction hypothesis to its premise at Aα. A body value gives vAαα; a body decomposition lifts uniquely through EDAαα.

For MD-Escape, write the conclusion stage as Aα and apply the induction hypothesis to the operand at A. An operand decomposition lifts through αEDA. If the operand is a value and Aε, the production αvAVAα applies. If A=ε, the operand has code type. Clause 2 of lemma 130.14 says that it is either vαα, which exposes the unique splice redex at stage α, or hε, which gives the final neutral αhεhα. Ordinary and stage abstractions are excluded by the same clause.

For MD-SAbs, apply the induction hypothesis to the body at A. A body value gives Λα.vA; a body decomposition lifts through the unique Λα.EDA production. For MD-SApp, first decompose its function. A decomposition lifts through EDAC. If the function is a value and Aε, the production vAC gives a value. If A=ε, the function has stage-quantifier type, so clause 3 of lemma 130.14 leaves a Λ-head, which gives the unique stage-beta redex for the unrestricted word C, or a neutral head, which extends to hεC. Lambda and quotation heads are excluded by the cited lemma.

For MD-CSP, decompose its premise at A. A value gives %αvAVAα; a decomposition lifts through the unique %αEDA production. A trailing MD-Conv changes neither term nor stage and therefore reuses the induction result for its term premise. These cases cover constants, variables, and all seven term constructors, plus conversion.

At each binary constructor the context grammar first selects the left premise unless it is a value and then selects the right premise; the two choices are disjoint. The remaining context productions have distinct outer constructors. At an empty-stage root, lemma 130.14 makes the redex-head and neutral-head cases disjoint, and the three redex schemas have distinct outer shapes. Combining these syntactic facts with uniqueness in the induction hypotheses proves uniqueness of D, EDA, and RD. ◻

Corollary 130.16 — Staged progress and type safety

Under the hypotheses of theorem 130.15, either MVA or there exists N with MsN. Consequently a closed, well-typed staged evaluation never reaches a nonvalue with no staged step.

Proof of Corollary 130.16 — Staged progress and type safety

Proof. Apply theorem 130.15. In its second alternative, the displayed staged rule for the unique redex gives N. Preservation from theorem 130.5 retains the hypothesis after every step, so a finite evaluation cannot end at an untyped stuck term. ◻

Exercise 130.2

★★☆ Prove the MD-SApp beta case of theorem 130.5, including the stage-word annotation and freshness renaming. Then show why omitting stage substitution from the result type makes the conclusion ill formed.

Exercise 130.3

★★☆ In the inversion-stable fragment, let one full-reduction step contract an outer stage-beta redex and a second step contract a redex strictly inside its body. Draw the one-step peak. Use stage-substitution compatibility to construct a common reduct by zero or more steps, naming every copied or erased residual redex. Repeat for an outer splice and an inner ordinary-beta redex.

Limits and seminar

The published rules are source-bounded to Kawata–Igarashi’s pure λMD [KI19b]. The theorems in this chapter are instead local theorems about the corrected card introduced above. That card deletes published rule MD-QT-CSP, requires the body-formation premise in code-head inversion, and extends the published staged-value grammar by constant-headed spines. Its full reduction is explicitly term-compatible and freezes binder annotations; exact syntactic confluence is replaced by theorem 130.11 after the counterexample proposition 130.4. The published proofs supply named proof architectures and comparison points; none is cited as an exact-signature theorem for the corrected card. There is no general inference procedure, reference semantics, or compiler-correctness theorem attached to either card. Unrestricted CSP for references can preserve a dead cell; adding effects also invalidates the annotation-free reduction permutations used by theorem 130.11. MetaOCaml, multilevel contextual type theory, Mœbius, and Cocon have separate contexts and observations; a quotation glyph is not a translation. The boundaries are concrete on the open-code judgment x:τ@αxβ.

MetaML.

A stage-indexed environment may admit CSP for selected values, but a persisted reference gives future code a cell whose allocation stage has ended; λisMD has neither stores nor that rule.

Multilevel contextual type theory.

Open code carries an explicit environment classifier or contextual type recording x; the λisMD card records availability by @A and supplies no contextual-code elimination.

Mœbius.

Type and term contexts are layered and code may abstract over context variables; no such context abstraction appears in λisMD.

Cocon.

Contextual objects and LF substitutions make the open context an explicit index. That supports hereditary substitution judgments absent here and does not validate MD-CSP for effects.

These four cards vary the representation of the open context, so none supplies a translation theorem for the displayed example.

[4]

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 130.4, then complete exercise 130.6.

Exercise 130.4

★★☆ Type a generator for a two-element vector whose result type contains the literal index two. Calculate staged evaluation to a code value and verify the body type at the extended stage.

Exercise 130.5

★★★ Extend the empty-stage language with RefNat, locations , allocation newn, and dereference !. A store is a finite map from locations to naturals; allocation chooses the least unused location. A generation boundary evaluates its generator, returns the generated code, and then discards every location allocated during that generation. Add unrestricted CSP for locations. Generate code for dereferencing a freshly allocated cell, then give two later evaluations: before each, allocate a new cell initialized respectively to zero and one. Calculate both stores and results, and identify the store-independence premise in canonical forms or local confluence that the extension invalidates.

Exercise 130.6 — Practical: dependent stage checker

★★★ Practical project.dependent-stage-checker Complete project dependent-stage-checker. Implement stage-depth checking for the one-name finite corpus, quotation, escape, CSP, and splice evaluation. Replay the stage-match mutant and connect its changed decision to the MD-Var case above. The named cases print vector-index: Vec(1), quote-dependent: Code(Vec(1)), and raw-crossing: rejected. The finite checker is independent evidence; it does not implement stage abstraction/application or mechanize confluence or strong normalization.

Search the book

Type to search the local edition.