Lectures onType Theory
Chapter 117
Chapter 117Optional

First-Class Universe Levels and Level Polymorphism

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

Ordinary universe polymorphism permits a declaration to have implicit level parameters at its outer boundary. It does not type a function that receives another level-polymorphic function and instantiates that argument twice at different levels. The obstruction is rank: the quantified level must occur inside an argument type. Making levels terms removes that obstruction, but also puts level computation inside substitution, conversion, normalization, and erasure.

Convention 117.1 — Principal first-class-level system

The principal system in this chapter has raw level terms are 0, successor t+, and join tu. It has a type Level:U0, universes Ut:Ut+, explicit types LiftuA, and terms lifta and lowera. The hierarchy is noncumulative; dependent products that inhabit a universe are homogeneous in their level. The type of a higher-rank level-polymorphic function may be well formed without inhabiting any universe. Judgmental level equality presents a join-semilattice with least element and an inflationary join-preserving successor. The source proves normalization, consistency, canonicity, injectivity, decidable equality, decidable typing for its stated checkable fragment, and safe erasure for its graded extraction signature. No theorem in this card applies to the bounded calculus later in the chapter.

Level algebra and lifts

Definition 117.2 — First-class level rules

Besides the ordinary rules of dependent type theory, the principal system has

Γ ctx
ΓLevel:U0
Level
Γ ctx
Γ0:Level
L-Zero
Γt:Level
Γt+:Level
L-Suc
Γt:LevelΓu:Level
Γtu:Level
L-Join
Γt:Level
ΓUt:Ut+
L-Univ

Judgmental equality includes left identity, associativity, commutativity, and idempotence for , together with (tu)+t+u+ and tt+t+. Define Below(t,u) by tuu.

The expression (0+0)0+ is judgmentally equal to 0+: identity removes 0, and idempotence contracts the two remaining copies. The equation tt+t+ shows Below(t,t+). The predicate Below is the level order, not a subtyping judgment.

Definition 117.3 — Lift rules

For Γt:Level, Γu:Level, and ΓA:Ut, the rules are

ΓA:Ut
ΓLiftuA:Utu
Lift-F
Γa:A
Γlifta:LiftuA
Lift-I
Γb:LiftuA
Γlowerb:A
Lift-E

Their equality rules are

Γa:A
Γlower(lifta)a:A
Lift-β
Γb:LiftuAΓb:LiftuAΓlowerblowerb:A
Γbb:LiftuA
Lift-η

The source states uniqueness in this extensional form rather than as an expansion equation; lift(lowerb)b is derived from it in proposition 117.4.

The explicit lift replaces cumulativity. From A:Ut and Below(t,u), one obtains LiftuA:Uu after level conversion. One does not infer A:Uu.

Proposition 117.4 — Lift is an isomorphism on terms

For fixed A:Ut and level u, the functions lift:ALiftuA and lower:LiftuAA are mutually inverse by judgmental equality.

Proof of Proposition 117.4 — Lift is an isomorphism on terms

Proof. For a:A, Lift-β gives lower(lifta)a, which is one inverse law.

For the other, fix b:LiftuA and apply Lift-η to the pair lift(lowerb) and b. Both are terms of LiftuA by Lift-I and Lift-E, and its third premise is discharged by Lift-β at a:=lowerb, which gives lower(lift(lowerb))lowerb. The conclusion is lift(lowerb)b, the second inverse law. ◻

Exercise 117.1

★★☆ Normalize (α+β)(αβ+) using the semilattice and successor equations. Then decide whether it is below α+β+ in Below, giving the equality that witnesses the answer.

Higher-rank level abstraction

Definition 117.5 — Level abstraction

Level abstraction and application are ordinary dependent abstraction and application at the type Level: idL:=λt.λA.λx.x:t:LevelA:UtAA. The outer product is formed by the unrestricted well-formed-type rule. It need not inhabit a universe, because the universe level of the codomain depends nontrivially on t.

Define twiceLevel:(t:LevelA:UtAA)(NN)×(U0U0) by applying its argument to (0,N) and to (0+,U0). A prenex declaration can quantify the level of the outer declaration, but it cannot give the function argument a polymorphic type that is instantiated at both levels. First-class level abstraction types both applications.

Lemma 117.6 — Level substitution

If Γ,t:Level,ΔJ and Γu:Level, then Γ,Δ[u/t]J[u/t].

Proof of Lemma 117.6 — Level substitution

Proof. Rule induction on the derivation of J. Variable and binder cases are the ordinary substitution cases. For L-Suc and L-Join, apply the induction hypotheses to their level premises and rebuild the rule. For L-Univ, substitution changes Ut to Uu and its type to Uu+. For Lift-F, substitution commutes with tv by the syntactic definition of substitution. Every level equality axiom is an equation schema and remains an instance after replacing t by u. The remaining type-former, conversion, and computation cases are the corresponding ordinary substitution rules. ◻

Normalization, checking, and erasure

Open level expressions are semilattice polynomials in variables and their iterated successors. A finite normal form records the greatest successor exponent of each variable and of the positive constant iterates.

Definition 117.7 — Level polynomial normal form

Let a generator be or a level variable. Define N(0) to be the empty map and let N(x) have the sole entry (x,0). Join takes pointwise maxima. Successor adds one to every present exponent, except that the successor of the empty map has the sole entry (,1). A constant entry (,m) is removed when some variable entry has exponent at least m, because that variable iterate absorbs the constant iterate. Two level expressions are algorithmically equal when their resulting finite maps are equal.

Lemma 117.8 — Level normalization is sound

If N(t)=N(u), then the level equations of definition 117.2 derive tu.

Proof of Lemma 117.8 — Level normalization is sound

Proof. For a finite map M, let R(M) be the ordered join of its indicated iterates, with R()=0. We first prove vR(N(v)) by structural induction on v. The zero and variable cases use the definition of R. The join case uses the two induction hypotheses; associativity, commutativity, and idempotence then implement pointwise maximum. In the successor case, the distribution equation moves successor through the ordered join. The empty join becomes the constant iterate (,1), as required.

It remains to justify entries deleted during join. Inflation removes an iterate below a larger iterate of the same variable. Moreover, 0xx; applying successor m times and distributing it shows that a variable iterate with exponent at least m absorbs the constant iterate (,m). Hence every deletion preserves equality to R(N(v)). If N(t)=N(u)=M, the two induction results give tR(M) and uR(M). Symmetry and transitivity yield tu. ◻

Lemma 117.9 — Level normalization is complete

If the level equations of definition 117.2 derive tu, then N(t)=N(u).

Proof of Lemma 117.9 — Level normalization is complete

Proof. Interpret levels in the natural numbers. A valuation σ assigns a natural number to each level variable; extend it by [[0]]σ:=0, [[t+]]σ:=[[t]]σ+1, and [[tu]]σ:=max([[t]]σ,[[u]]σ). Each of the six equations of definition 117.2 is valid in (N,max,0,+1): left identity because 0 is least, associativity, commutativity and idempotence because max is a semilattice operation, distribution because max(m,n)+1=max(m+1,n+1), and inflation because max(m,m+1)=m+1. Hence tu implies [[t]]σ=[[u]]σ for every σ.

The proof of lemma 117.8 gives vR(N(v)), so it also gives [[v]]σ=[[R(N(v))]]σ, and the latter is the maximum of m over any constant entry (,m) together with σ(x)+k over the variable entries (x,k). It therefore suffices to separate two distinct maps produced by definition 117.7. Let MM be two such maps.

Suppose first that their variable entries differ at some x. Take σ(x):=n and σ(y):=0 for every other variable. Every term of the maximum other than the one contributed by x is bounded by a constant independent of n, while x contributes n+k when (x,k)M and contributes nothing when x is absent. For n larger than every exponent occurring in M or M, the two maxima are n+k and n+k with kk, or one is n+k and the other is bounded independently of n; in both cases they differ.

Otherwise the variable entries agree and the constant entries differ. Take σ(y):=0 for every variable. A map produced by definition 117.7 retains (,m) only when every variable entry has exponent strictly below m, so its maximum at this valuation is m when a constant entry is present and is the largest variable exponent otherwise. If both maps carry constant entries mm, the maxima differ. If exactly one does, its maximum is m and the other’s is the largest shared variable exponent, which is strictly below m. If neither does, the maps agree, contradicting MM.

So distinct maps have distinct interpretations at some valuation, and equal levels have equal maps. ◻

Corollary 117.10 — Level equality is decidable

Judgmental equality of level expressions built from 0, successor and join is decided by comparing the finite maps of definition 117.7.

Proof of Corollary 117.10 — Level equality is decidable

Proof. The maps are finite and computed by structural recursion, so equality of maps is decidable. lemma 117.8 gives one implication and lemma 117.9 the other. ◻

This decides the level fragment only, and by a procedure owned by this chapter. The source decides equality for the whole theory by a different route, comparing partially canonical level views inside its bidirectional conversion algorithm; theorem 117.11 records that source theorem, and neither procedure is used to justify the other.

Theorem 117.11 — Metatheory of the principal system

For the exact syntax and rules fixed in convention 117.1, the source proves the following package.

  1. Every well-typed object is reducible (Lemma 3.3 and Corollary 3.8); hence consistency, natural-number canonicity, weak-head normalization, and injectivity/nonconfusion follow (Corollaries 3.9–3.12).

  2. Algorithmic equality is complete (Theorem 4.2); hence judgmental equality is decidable (Corollary 4.3), and well-formed types and terms have eta-long normal forms (Corollary 4.4).

  3. Typing is decidable only for the checkable/inferable classes and checkable contexts stated in Theorem 4.5.

  4. Theorem 5.1 has a narrower signature. Fix a source context Γ, a source term t, and strictness s. Its four hypotheses are exactly: whenever erased matches for the empty type are allowed, Γ is consistent; either Γ=, or erased matches are disallowed for weak-Σ and unit types; Γt:N; and 0c1t. Under those hypotheses there is nN such that the source reduces to the numeral n and both the strict and non-strict erasures reduce to n, as stated by the paper’s source and target closure relations.

Proof of Theorem 117.11 — Metatheory of the principal system

Proof. We construct the logical relation and derive each consequence. Use external indices N{ω}. Define reducibility Red(Γ;J) by well-founded induction on , with type reducibility inductive and reducible type and term equality recursive in a type-reducibility witness. The relation is parameterized by generic type, term, and atomic-neutral equality relations that are partial equivalence relations, stable under weakening, conversion, and weak-head expansion, and contained in judgmental equality.

The first-class level clause is independent of . A reducible level weak-head reduces to 0, a successor of a reducible level, or a neutral built from an atomic neutral and joins. Define its external realizer by 0=0,(t+)=1+t,(tu)=max(t,u), and assign realizer 0 to an atomic neutral. Mutual induction on reducible levels and their equality proves tu⟹↑t=↑u,tuu⟹↑t≤↑u. The zero, successor, and atomic-neutral cases are immediate. In the join case use the induction hypotheses and the corresponding equality of maxima. Associativity, commutativity, idempotence, and absorption are the same laws for maximum; the rule relating a neutral join to a successor uses the second displayed implication. This covers every level-equality generator.

A universe Ut is reducible at external level when t is a reducible level and t<; an element of that universe is a type reducible at external level t. Neutral types, Level, Π, Σ, natural numbers, unit, empty, identity, and lifted types have their standard Kripke clauses. In the lift clause, lift and lower transport the underlying reducible term, and Lift-β and Lift-η make those transports inverse. The strict inequality in the universe clause makes recursive calls well founded.

Prove the fundamental lemma simultaneously for context formation, typing, type equality, and term equality. Variables use the reducible substitution. The structural, Π, Σ, natural-number, unit, empty, and identity cases are the ordinary Kripke cases. L-Zero, L-Suc, and L-Join use the level construction above; every semilattice equality uses the corresponding realizer equality. L-Univ uses t<1+t. Lift-F, Lift-I, and Lift-E use the lift clause, and the two lift equalities use its inverse laws. Substitution uses weakening of the relation and its Kripke quantification. Conversion uses irrelevance of reducibility witnesses. These cases exhaust the system card, so every well-typed object is reducible.

Instantiate the generic equality by judgmental equality. A closed reducible natural weak-head reduces to zero or a successor chain, because the neutral case is impossible in the empty context; this proves canonicity. A closed term of the empty type would have to reduce to a neutral, also impossible, so the theory is consistent. Every reducible object has a weak-head normal form. Comparing the outer clauses of two reducibly equal types gives injectivity and nonconfusion.

For algorithmic equality, normalize levels to finite views consisting of a natural offset together with atomic neutral summands. Join is computed by maximum on offsets and union-with-domination on summands. Structural induction proves that view computation is deterministic and validates all semilattice equations; equality of finite views is decidable. Extend the usual mutually defined weak-head, type, term, and neutral comparisons by this level comparison and by congruence for universes and lifts. The resulting relations satisfy the generic-equality interface: weakening and conversion are inductions on comparison, weak-head expansion follows from determinism, and the level equations follow from the view calculation. Applying the fundamental lemma again proves completeness. Soundness is an induction on the comparison derivation. On well-formed inputs, decide judgmental equality by running the finite comparison; recursively reading its witnesses produces eta-long normal forms.

Typing is decided by mutual recursion only for the stated syntactic classes. In a context of checkable types, check a checkable term against a checkable type using decidable conversion. For an inferable term, recurse on syntax. A product first infers a universe for its domain and then checks its codomain in the extended context; a lift without its level annotation is not inferable. Every recursive call is on a proper subterm, proving termination and item 3. No rule handles arbitrary raw terms.

For item 4, define erasure structurally. All level expressions, universes, and type formers erase; lift and lower erase to their arguments. Relevant lambdas and applications erase homomorphically. In the non-strict translation an erased application drops its argument and an erased lambda substitutes a fixed looping term for its binder; in the strict translation the erased argument becomes a value placeholder. Prove by induction on the source reduction that erasure simulates each step in the appropriate target closure. The new level steps erase on both sides. Lift beta erases to reflexivity, and lift eta changes no runtime term. The ordinary beta, constructor, pair, and eliminator cases use the substitution–erasure lemma, proved by structural induction.

The graded fundamental lemma, by induction on the typing and usage derivations, says that a well-resourced source natural is related to its erasure. At natural numbers the relation exposes a numeral n; its source component gives reduction of t to n, and its target component gives reduction of either erasure to n. The empty and weak-Σ/unit match cases are exactly where the first two hypotheses of item 4 discharge otherwise stuck erased eliminations. The typing and usage hypotheses supply the remaining two premises. Therefore the claimed n exists for both strictnesses.

The construction is noncumulative, uses homogeneous products, and restricts typing to the stated classes. The proof therefore yields none of the three excluded extensions. ◻

Two neighbouring designs

Level expressions are not the only way to make a hierarchy usable, and two comparisons fix what the principal calculus is being measured against. Both are expressiveness and engineering comparisons; neither supplies a theorem for convention 117.1.

Displacement instead of quantification. Hou (Favonia), Angiuli and Mullanix’s order-theoretic analysis replaces level variables by a displacement operation dispn, written ()n in that source, which raises every universe level inside a closed term by a fixed natural number n. A user writes the apparently monomorphic id:A:U0AA and recovers the instance needed at the next level after the fact: disp1(id):A:U0+AA, so that disp1(id)(U0):U0U0 typechecks. The comparison with definition 117.5 is exact and it is a comparison of expressiveness, not of theorems: displacement acts on closed terms only, so it cannot type twiceLevel, whose argument must be instantiated at two levels inside its own type. Conversely first-class levels put level computation inside conversion, which displacement avoids.

Cumulativity instead of explicit lifts. Sterbac and Sterling’s fuss-free cumulative universes keep an explicit lift ij but make it a silent, judgmentally functorial coercion: the laws iiM=M and jkijM= ikM hold judgmentally, and lifting commutes with the dependent function space. Under definition 117.3 none of that holds: Liftu is a type former whose introduction and elimination must be written, and proposition 117.4 gives an isomorphism, not an identity.

Bounded first-class levels. The bounded calculus is a complete extension in a different direction: instead of a single type Level, it has a family Level< of levels bounded by , so that a level variable carries its own upper bound and the universe formation rule can quantify over exactly the levels below a given one. Bounds are part of the typing relation rather than a separate predicate, which is what lets the system satisfy subject reduction where an unbounded presentation of the same idea does not.

At this signature, Chan and Weirich prove subject reduction, type safety, consistency, and canonicity; consistency and canonicity are obtained from a syntactic logical relation through a fundamental soundness theorem. Normalization of open terms and decidability of checking are stated there as open.

Therefore theorem 117.11 does not transfer. Its items 1 and 2 are proved by a reducibility argument for the unbounded syntax of convention 117.1; adding bounds changes the typing relation those items quantify over, and the bounded source does not reprove them. A shared example with the same printed type is not evidence either way, because the two systems assign it types in different relations.

Sources

The principal calculus and its metatheory follow Danielsson, Favier, and Kubánek [DFK26]. The bounded comparison follows Chan and Weirich [CW25].

Suggested first pass.

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

Exercise 117.2

★★☆ Write the complete type of a function that receives idL and uses it at N, U0, and Lift0+N. Mark the product that does not inhabit any universe and derive all three applications.

Exercise 117.3

★★☆ Formalize the lifting law Liftu(LiftvA) against LiftuvA: give the two functions between them built from lift and lower, derive both universe memberships from Lift-F, and prove the two composites judgmentally equal to the identity using only Lift-β, Lift-η, and the level equations. State which step would fail if the levels were compared by syntactic identity rather than by corollary 117.10.

Exercise 117.4

★★☆ Compare the principal first-class-level calculus, the bounded-level calculus, and displacement polymorphism at their printed signatures. For each system, state its level syntax, the judgment in which levels occur, and one theorem established by the cited source. Then name one claim that does not transfer to either of the other two systems, and identify the missing rule or hypothesis.

Exercise 117.5

★★☆ Make a table with one row for normalization, canonicity, subject reduction, decidable equality, and decidable checking. Fill the proved cells separately for the principal and bounded calculi, and cite the exact theorem location named in this chapter for every filled cell.

Exercise 117.6

★★★ Practical project.first-class-level-normalizer Implement in Agda or Kappa the finite-map normal form from definition 117.7. Preserve the invariant that each generator occurs once with its greatest exponent. On join-idem, successor-distributes, and strict-bound, print equal, equal, and not-below. A mutation that uses minimum rather than maximum for join must fail strict-bound. The program decides the displayed level algebra; it is not a typechecker for either first-class-level calculus.

Search the book

Type to search the local edition.