Lectures onType Theory
Chapter 100
Chapter 100Optional

Graded Modal Dependent Type Theory

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

A context annotation tells how an open term uses each assumption. It does not produce a first-class value that may be stored now and opened later at a specified grade. For example, knowing that a pair projection ignores its second component does not let the pair type itself record that local fact. Repeated projection and substitution must rediscover the usage from the whole derivation.

A graded modality internalizes the demand. The type sA packages an A-value for later use at grade s. Dependency creates a second demand: an assumption may occur in the subject and independently in the subject’s type. Both demands remain visible below.

Three layers of grades

Definition 100.1 — Grade semiring

Fix a semiring (R,+,0,,1). Context addition and scalar multiplication use its operations pointwise. The paper calculus has no grade approximation rule: extending it to preordered semirings is an implementation extension and is outside the normalization theorem imported below.

Definition 100.2 — Graded typing judgment

A context has the form Γ=x1:A1,,xn:An. A vector σRn assigns a grade to each declaration. The context grade vector Δ has, at one-based position i, a row of length i1. That row records how earlier assumptions form Ai. The typing judgment is (Δσsσt)Γt:A. The vector σs grades occurrences in the subject t; the vector σt grades occurrences in the subject’s type A. All four vectors and contexts have the lengths forced by Γ.

Universe and variable typing make the three vectors concrete:

ΔΓ
(Δ00)ΓTypel:Typesucl
G-Type
Δ1,σ,Δ2Γ1,x:A,Γ2|Δ1|=|Γ1|
(Δ1,σ,Δ20|Δ1|,1,0σ,0,0)Γ1,x:A,Γ2x:A
G-Var

For a:Type0,x:a,y:ax:a, the subject grades are (0,1,0): only x occurs in the term. The subject-type grades are (1,0,0): only a occurs in the classifier. The last row of Δ is (1,0), since a forms the type of y and x does not. Collapsing these three vectors into one loses which occurrence belongs to the term, its type, or a later declaration.

This supplies a counterexample to a direct translation into the QTT judgment of definition 99.2. The independent GrTT classifier vector cannot be recovered after subject and classifier demands have been collapsed into one QTT usage vector. Conversely, QTT tensor elimination assigns quantities σπ and σ to the two components, whereas G-Let below assigns one common subject grade. Neither rule card is obtained by erasing annotations from the other, and no translation theorem is claimed.

Definition 100.3 — Core syntax

The core terms and types are t,A,B::=xTypel(x:(s,r)A)Bλx.ttu(x:rA)B(t,u)let(x,y)=tinusAboxtletboxx=tinu. In a function binder, s is the use of x in the function body and r its use in B. A tensor binder needs only r, since x is bound in the second component’s type rather than in a stored body.

The frozen paper core has its universe hierarchy and the displayed formers. The Gerty prototype adds a singleton unit type, preordered-semiring support, and other conveniences. Neither a unit nor a natural-number type former is silently added to the source signature used for preservation and normalization.

Exercise 100.1

★☆☆ For a:Type0,x:a,y:ay:a, compute the subject and subject-type vectors and the three rows of Δ. Change the subject to x and identify exactly one vector component that changes.

Functions, tensors, and modality

Definition 100.4 — Function rule card

Suppressing length equalities, the function rules have the grade equations

(Δσ10)ΓA:Typel1(Δ,σ1σ2,r0)Γ,x:AB:Typel2
(Δσ1+σ20)Γ(x:(s,r)A)B:Typel1l2
G-Π-F
(Δ,σ1σ3,r0)Γ,x:AB:Typel(Δ,σ1σ2,sσ3,r)Γ,x:At:B
(Δσ2σ1+σ3)Γλx.t:(x:(s,r)A)B
G-Lam

Application scales the argument’s subject use by s and its contribution to the result type by r:

(Δ,σ1σ3,r0)Γ,x:AB:Typel(Δσ2σ1+σ3)Γf:(x:(s,r)A)B(Δσ4σ1)Γu:A
(Δσ2+sσ4σ3+rσ4)Γfu:B[u/x]
G-App

The first premise exposes the grades forming the codomain. The argument’s subject vector σ4 is scaled once for computational use and once for its substitution into that codomain; its own type vector σ1 is the domain-formation vector already accounted for by the other premises.

For λx.λy.x, the inner binder has subject grade zero and type grade zero. Applying the function to any second argument therefore scales that argument’s subject and subject-type vectors by zero. This is a derivable statement about the term, not an operational erasure theorem.

Definition 100.5 — Dependent tensors

The strong dependent tensor (x:rA)B permits B to depend on its first component at grade r. Its complete rule card is

(Δσ10)ΓA:Typel(Δ,σ1σ2,r0)Γ,x:AB:Typel
(Δσ1+σ20)Γ(x:rA)B:Typel
G-⊗-F
(Δ,σ1σ3,r0)Γ,x:AB:Typel(Δσ2σ1)Γt1:A(Δσ4σ3+rσ2)Γt2:B[t1/x]
(Δσ2+σ4σ1+σ3)Γ(t1,t2):(x:rA)B
G-Pair
(Δσ3σ1+σ2)Γt1:(x:rA)B(Δ,σ1+σ2σ5,r0)Γ,z:(x:rA)BC:Typel(Δ,σ1,(σ2,r)σ4,s,sσ5,r,r)Γ,x:A,y:Bt2:C[(x,y)/z]
(Δσ4+sσ3σ5+rσ3)Γlet(x,y)=t1int2:C[t1/z]
G-Let

The common grade s on the two body binders is required because an arbitrary semiring sum cannot be inverted to recover separate component uses. Computation contracts let(x,y)=(t,u)invβv[t/x,u/y]. For closed A,B, choosing r=r=0 and s=1 derives let(x,y)=pin(x,y):(x:0A)B: the body vector assigns grade one to both binders, and G-Let adds the scrutinee vector once. Replacing p by a neutral variable leaves this eliminator stuck. The selected core contains the beta root above and no tensor eta rule.

Suppose the grade semiring is quantitative in the source’s sense: grade zero enforces that a subject is unused. Under this semantic hypothesis, the weak product A×B is the special case (x:0A)B with xFV(B). We do not make this product identification for an arbitrary semiring. The calculus retains only G-Let; a first-projection term may still be underivable because that rule assigns one common inspection grade to both components. The graded modality below supplies the local zero-use fact needed for the projection example.

Definition 100.6 — Graded modality rules

Formation, introduction, and elimination are

(Δσ0)ΓA:Typel
(Δσ0)ΓsA:Typel
G-Box-F
(Δσ1σ2)Γt:A
(Δsσ1σ2)Γboxt:sA
G-Box-I
(Δ,σ2σ4,r0)Γ,z:sAB:Typel(Δσ1σ2)Γt1:sA(Δ,σ2σ3,sσ4,sr)Γ,x:At2:B[boxx/z]
(Δσ1+σ3σ4+rσ1)Γletboxx=t1int2:B[t1/z]
G-Box-E

The body uses the unboxed x at subject grade s; the result type uses the scrutinee at grade r. These contributions occupy different vectors. The source prints the body’s classifier as B[x/z]. Since z:sA and x:A, the displayed B[boxx/z] is the type-correct reading of that source rule. Computation is letboxx=boxtinuβu[t/x]. For s=1, r=0, and closed A, the premises derive p:1Aletboxx=pinx:A with one subject use and zero subject-type use. A neutral p makes the eliminator stuck. The selected core includes this beta root and no box eta equation.

With the natural-number semiring, 2A packages an A-value for two uses. A lattice semiring can instead read grades as security labels. These instantiations share semiring equations, but their intended observations differ; the calculus adds no implicit order-based approximation.

Exercise 100.2

★★☆ Assume 2Δboxt:2A is obtained by G-Box-I. Calculate the demand on Δ when one elimination uses the unboxed value twice. Repeat at grade zero and explain why the result is a typing calculation rather than proof that a compiler deletes t.

Substitution and preservation

Substitution must update the triangular context vector as well as the two judgment vectors. If x occurs in later declaration types, removing its column without redistributing the substituend’s dependencies loses precisely the information Δ was introduced to retain.

Definition 100.7 — Discard, choose, and scale

For a triangular context vector Δ and a zero-based column index j, Δ\j removes column j from each later row, while Δ/j collects the removed entries. Thus a declaration at one-based position j+1 is removed at column index j. If σ is the grade vector used to construct a substituend, then Δ\j+(Δ/j)σ removes the old dependency on x and adds the dependencies of the substituend, each scaled by the former use of x. Short rows are padded on the right with zero before addition.

For a later type that uses x twice, substituting a term with subject vector (0,1) replaces the removed entry 2 by 2(0,1)=(0,2). Merely deleting the entry would falsely declare the later type independent of the substituted term.

Theorem 100.8 — Graded substitution

Suppose (Δτsτt)Γ1t:A and (Δ,τt,Δσ1,s,σ2ρ1,r,ρ2)Γ1,x:A,Γ2u:B. Assume the prefix vectors have length |Γ1|. Define j=|Γ1|=|Δ|, the zero-based column occupied by x in every later row, and Δ^=Δ,Δ\j+(Δ/j)τs,σ^=σ1+sτs,σ2,ρ^=ρ1+rτs,ρ2. Then (Δ^σ^ρ^)Γ1,Γ2[t/x]u[t/x]:B[t/x].

Proof of Theorem 100.8 — Graded substitution

Proof. Induct on the typing derivation of u. The selected-variable case returns the premise derivation for t; its subject and subject-type vectors are scaled by the grades at the removed position. Another variable uses the corresponding row after discard, and choose inserts the dependencies of t into its declared type.

In G-App, apply the induction hypotheses to the function and argument. The subject calculation uses distributivity: (σ1+sτs)+q(σ2+sτs)=σ1+qσ2+(s+qs)τs. The subject-type vector has the same equation with its independent binder grade. Substitution composition aligns B[v/y][t/x] with B[t/x][v[t/x]/y]. The lambda case extends the triangular vector by one row and uses alpha-renaming. Tensor introduction and elimination use the same two vector equations, with the dependent-result substitution visible in the latter. Box introduction uses associativity of scalar multiplication; box elimination additionally uses the discard/choose equation for its dependent result type. Universes are closed and variables cover the base cases. Thus every rule reconstructs the displayed conclusion. ◻

Lemma 100.9 — Reduction gives typed equality

If (Δσsσt)Γt:A and tβt, then (Δσsσt)Γt=t:A.

Proof of Lemma 100.9 — Reduction gives typed equality

Proof. For function beta, use theorem 100.8 to type the contractum and apply the function beta-equality rule. Tensor and box beta use the same substitution theorem, once for each bound component. A compatible reduction uses the corresponding equality congruence. These are all beta roots of definition 100.3. ◻

Theorem 100.10 — Type preservation

If (Δσsσt)Γt:A and tβt, then (Δσsσt)Γt:A.

Proof of Theorem 100.10 — Type preservation

Proof. By lemma 100.9, the two terms are equal at A under the original three grade components. Equality inversion returns a typing judgment for each endpoint, hence the required judgment for t. ◻

Exercise 100.3

★★☆ Prove the root box-beta case of theorem 100.10. Display the two scaled vectors in the elimination premise and identify their occurrences in the conclusion of theorem 100.8.

The exact normalization boundary

Definition 100.11 — The fragment GrTT^0,1

The fragment GrTT0,1 has exactly the two universe levels Type0 and Type1, and its contexts contain no variables whose type is Type1. Its reduction relation is beta reduction for functions, tensors, and boxes. Eta equality is not part of this reduction relation.

The proof separates syntax into four disjoint stages. With all displayed judgments restricted to GrTT0,1, define Kind={AΔ,σ,Γ. (Δσ0)ΓA:Type1},Type={AΔ,σ,Γ. (Δσ0)ΓA:Type0},Con={tΔ,σs,σt,Γ,A.(Δσsσt)Γt:A, (Δσt0)ΓA:Type1},Term={tΔ,σs,σt,Γ,A.(Δσsσt)Γt:A, (Δσt0)ΓA:Type0}. These stage definitions are source Definition C.1, and the imported classification result is source Lemma C.2. It gives KindType= and ConTerm=.

Definition 100.12 — Base terms, key redex, and saturation

Let SN be the set of terms admitting no infinite beta-reduction sequence. The base set B is the least set satisfying these eight clauses: variables, Type0, and Type1 lie in B; if t1B and t2SN, then t1t2B; if t2B and t1SN, each tensor let and box let with scrutinee t1 and body t2 lies in B; if their constituents are strongly normalizing, dependent function types, dependent tensor types, and box types lie in B.

A term’s key redex is the term itself when it is a beta redex; it is otherwise the unique key redex of the operator in an application or of the scrutinee in a tensor let or box let. Write redk(t) for its contraction. A set X is saturated when XSN,BX,redk(t)X  tSNtX. The collection SAT of saturated sets interprets Type0 at the kind stage; Type1 has type interpretation SN, while [[Type0]]ε is the constant family XSATSN. Dependent functions use the corresponding candidate function space and tensors use Cartesian products. The interpretation erases box constructors because grades do not occur in beta reduction. This definition reproduces source Definitions C.3, C.4, and C.6, source Lemma C.7, and the universe clauses of Definitions C.8 and C.10 [MIO21].

The erasure in this proof is a device for proving membership in SN. It is not a compiler semantics and does not establish that erasing boxes preserves observations, costs, or run-time access counts.

The proof mechanism is a saturated-set interpretation. Its valuation judgments must be stated before the theorem. A type valuation starts empty. For a declaration x:A with A:Type1, it extends ε by xX for an arbitrary XK[[A]]; for A:Type0, it extends the context without changing ε. A valid term valuation starts empty. At a Type1-classified declaration it extends ρ by xt with t[[A]]ε(ε(x)); at a Type0-classified declaration it instead requires t[[A]]ε. Write these judgments as ΔΓε and ΔΓερ, respectively. The term ((t))ρ is ρ(t) with tensor lets translated to substitutions and graded boxes erased. These are inductive judgments on the same triangular context Δ, not an informal class of closing maps. The remaining kind-, type-, and term-interpretation clauses are imported at the signatures below, where RawTerm is the set of raw terms generated by definition 100.3: K[[]]:KindSet,[[]]ε:KindTypeConSet,(())ρ:KindTypeConTermRawTerm. from Definitions C.8–C.12 [MIO21]. Their supplied consequence is Lemma C.16: interpreted constructors inhabit the corresponding kind interpretation and interpreted types yield saturated candidates.

The source semantic judgment (Δσsσt)Γt:A has two clauses. If A:Type1, every valid (ε,ρ) satisfies ((t))ρ[[A]]ε([[t]]ε). If A:Type0, every such valuation satisfies ((t))ρ[[A]]ε. This is Definition C.13 of the source at its exact restricted signature; the load-bearing induction occupies its Theorem C.17.

Theorem 100.13 — Imported semantic typing

For every derivation (Δσsσt)Γt:A in GrTT0,1, the semantic judgment (Δσsσt)Γt:A above holds.

Proof of Theorem 100.13 — Imported semantic typing

Proof. This is Theorem 3 of Moon–Eades–Orchard, with its complete induction in their Appendix C, Theorem C.17 [MIO21]. Their Δ, subject vector, and subject-type vector are exactly those of definition 100.2; their function and tensor cases are the rules of definition 100.4, definition 100.5. Their box cases are the rules of definition 100.6 under the type-correct reading of G-Box-E recorded after that rule. The import is restricted exactly as in definition 100.11. In particular, it imports neither arbitrary universe levels nor variables of type Type1. Those identifications instantiate every premise and give the stated conclusion. ◻

Corollary 100.14 — Beta strong normalization

Every GrTT0,1-typable term is beta-strongly normalizing.

Proof of Corollary 100.14 — Beta strong normalization

Proof. This is the source’s Strong Normalization Corollary immediately after Theorem 3, imported with its open-term conclusion [MIO21]. The source defines canonical elements of K[[A]] and a valid term valuation, then invokes semantic typing. Its corollary asserts tSN for the source term itself even though the displayed semantic judgment constrains ((t))ρ; that transfer is inherited from the source’s corollary and is not reproved here. ◻

The two-universe restriction and exclusion of Type1-typed variables are substantive hypotheses of this proof. Removing them invalidates the well-founded stage analysis; no stronger theorem is claimed here. Strong normalization alone is neither decidability of conversion without a decidable one-step system and confluence proof, nor logical consistency without the remaining canonical-forms argument.

Exercise 100.4

★★☆ List the exact hypotheses of corollary 100.14. For each of the following conclusions—eta normalization, full-GrTT normalization, conversion decidability, and erasure soundness—name a missing premise or a signature mismatch that prevents it from following from the corollary.

A modal program

Fix a quantitative grade semiring. Let Pair0(A,B) abbreviate the weak product (x:0A)B, and package the second component at grade zero: first:Pair0(A,0B)A. The program is λp. let(x,y)=pinletboxz=yinx. Rule G-Let binds x:A and y:0B at the same inspection grade, namely one. The zero is introduced earlier: G-Box-I gives the packaged second component subject vector 0β=0. Thus an input pair constructed from component-demand vectors α and β has vector α+0β, and the common grade of G-Let yields 1(α+0β)=α. Without 0, the strong tensor eliminator assigns the same inspection grade to both components and cannot derive this projection for every semiring. The modality is therefore doing type-theoretic work: it packages the local zero-use fact.

The calculation does not promise that a concrete run time skips construction of the second component. Such a result needs an operational erasure map and an observational-equivalence proof. The saturated-set proof of corollary 100.14 erases modalities for a different purpose.

Exercise 100.5

★★☆ Give all three grade components Δ,σs,σt for first in a context containing A:Type0, B:Type0, and the input pair. Identify the zero generated by the weak product and the zero generated by 0; they occupy different positions.

Suggested first pass.

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

Exercise 100.6

★★☆ Reconstruct graded substitution for a box elimination whose result type depends on the scrutinee at grade r. Compute the subject and subject-type vectors separately, then compute the discard/choose update to the triangular context vector.

Exercise 100.7

★★★ Instantiate the rule card once with natural-number grades and once with the Boolean information-flow lattice semiring. Give one semiring calculation valid in both instances and one observational reading meaningful in only one instance. Identify the additional approximation rule that would be required to use the lattice order, and explain why the imported normalization theorem does not cover that extension.

Exercise 100.8

★★★ Practical project.grtt-modal-grade-calculator Implement in Agda or Kappa subject, subject-type, and triangular context grade vectors over natural numbers. Implement application scaling and the discard/choose substitution operation while maintaining the invariant that one-based row i of the triangular vector has length i1. On the named cases modal-first, substitute-twice, and bad-row-length, print respectively subject demand (1,0), substituted dependency (0,2), and bad-row-length rejected: shape. Store the subject and subject-type vectors in one judgment record. A mutation that copies the subject vector into the subject-type field must fail the named separation oracle. The program checks finite grade equations; it does not prove preservation or strong normalization.

Sources. The three-vector judgment, graded function and tensor binders, modality, substitution operations, and preservation proof follow Moon, Eades, and Orchard [MIO21]. The exact strong-normalization boundary is stated before their proof and its conclusion is Corollary 1 on p. 21 of the pinned paper: beta reduction in the two-universe GrTT0,1 fragment with no variables of Type1. Gerty v0.1.0 supplies implementation evidence only; its unit, natural-number, implicit-grade, and solver features are not silently added to that theorem’s signature.

Search the book

Type to search the local edition.