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.
The principal system in this chapter has raw level terms are 0, successor 𝑡+, and join 𝑡⊔𝑢. It has a type 𝖫𝖾𝗏𝖾𝗅:U0, universes U𝑡:U𝑡+, explicit types 𝖫𝗂𝖿𝗍𝑢𝐴, and terms 𝗅𝗂𝖿𝗍𝑎 and 𝗅𝗈𝗐𝖾𝗋𝑎. 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.
Besides the ordinary rules of dependent type theory, the principal system has
Γ𝖼𝗍𝗑
Γ⊢𝖫𝖾𝗏𝖾𝗅:U0
Level
Γ𝖼𝗍𝗑
Γ⊢0:𝖫𝖾𝗏𝖾𝗅
L-Zero
Γ⊢𝑡:𝖫𝖾𝗏𝖾𝗅
Γ⊢𝑡+:𝖫𝖾𝗏𝖾𝗅
L-Suc
Γ⊢𝑡:𝖫𝖾𝗏𝖾𝗅Γ⊢𝑢:𝖫𝖾𝗏𝖾𝗅
Γ⊢𝑡⊔𝑢:𝖫𝖾𝗏𝖾𝗅
L-Join
Γ⊢𝑡:𝖫𝖾𝗏𝖾𝗅
Γ⊢U𝑡:U𝑡+
L-Univ
Judgmental equality includes left identity, associativity, commutativity, and idempotence for ⊔, together with (𝑡⊔𝑢)+≡𝑡+⊔𝑢+ and 𝑡⊔𝑡+≡𝑡+. Define 𝖡𝖾𝗅𝗈𝗐(𝑡,𝑢) by 𝑡⊔𝑢≡𝑢.
The expression (0+⊔0)⊔0+ is judgmentally equal to 0+: identity removes 0, and idempotence contracts the two remaining copies. The equation 𝑡⊔𝑡+≡𝑡+ shows 𝖡𝖾𝗅𝗈𝗐(𝑡,𝑡+). The predicate 𝖡𝖾𝗅𝗈𝗐 is the level order, not a subtyping judgment.
Proof of Proposition 117.4 — Lift is an isomorphism on terms
Proof. For 𝑎:𝐴, Lift-𝛽 gives 𝗅𝗈𝗐𝖾𝗋(𝗅𝗂𝖿𝗍𝑎)≡𝑎, which is one inverse law.
For the other, fix 𝑏:𝖫𝗂𝖿𝗍𝑢𝐴 and apply Lift-𝜂 to the pair 𝗅𝗂𝖿𝗍(𝗅𝗈𝗐𝖾𝗋𝑏) and 𝑏. Both are terms of 𝖫𝗂𝖿𝗍𝑢𝐴 by Lift-I and Lift-E, and its third premise is discharged by Lift-𝛽 at 𝑎:=𝗅𝗈𝗐𝖾𝗋𝑏, which gives 𝗅𝗈𝗐𝖾𝗋(𝗅𝗂𝖿𝗍(𝗅𝗈𝗐𝖾𝗋𝑏))≡𝗅𝗈𝗐𝖾𝗋𝑏. The conclusion is 𝗅𝗂𝖿𝗍(𝗅𝗈𝗐𝖾𝗋𝑏)≡𝑏, the second inverse law. ◻
★★☆ Normalize (𝛼+⊔𝛽)⊔(𝛼⊔𝛽+) using the semilattice and successor equations. Then decide whether it is below 𝛼+⊔𝛽+ in 𝖡𝖾𝗅𝗈𝗐, giving the equality that witnesses the answer.
Level abstraction and application are ordinary dependent abstraction and application at the type 𝖫𝖾𝗏𝖾𝗅: 𝗂𝖽𝐿:=𝜆𝑡.𝜆𝐴.𝜆𝑥.𝑥:∏𝑡:𝖫𝖾𝗏𝖾𝗅∏𝐴:U𝑡𝐴→𝐴. 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 𝑡.
Define 𝗍𝗐𝗂𝖼𝖾𝖫𝖾𝗏𝖾𝗅:(∏𝑡:𝖫𝖾𝗏𝖾𝗅∏𝐴:U𝑡𝐴→𝐴)→(ℕ→ℕ)×(U0→U0) by applying its argument to (0,ℕ) 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.
Proof. Rule induction on the derivation of 𝐽. 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 U𝑡 to U𝑢 and its type to U𝑢+. For Lift-F, substitution commutes with 𝑡⊔𝑣 by the syntactic definition of substitution. Every level equality axiom is an equation schema and remains an instance after replacing 𝑡 by 𝑢. 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.
Let a generator be ⋆ or a level variable. Define 𝑁(0) to be the empty map and let 𝑁(𝑥) have the sole entry (𝑥,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 (⋆,𝑚) is removed when some variable entry has exponent at least 𝑚, because that variable iterate absorbs the constant iterate. Two level expressions are algorithmically equal when their resulting finite maps are equal.
Proof of Lemma 117.8 — Level normalization is sound
Proof. For a finite map 𝑀, let 𝑅(𝑀) be the ordered join of its indicated iterates, with 𝑅(∅)=0. We first prove 𝑣≡𝑅(𝑁(𝑣)) by structural induction on 𝑣. The zero and variable cases use the definition of 𝑅. 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, 0⊔𝑥≡𝑥; applying successor 𝑚 times and distributing it shows that a variable iterate with exponent at least 𝑚 absorbs the constant iterate (⋆,𝑚). Hence every deletion preserves equality to 𝑅(𝑁(𝑣)). If 𝑁(𝑡)=𝑁(𝑢)=𝑀, the two induction results give 𝑡≡𝑅(𝑀) and 𝑢≡𝑅(𝑀). Symmetry and transitivity yield 𝑡≡𝑢. ◻
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, [[𝑡+]]𝜎:=[[𝑡]]𝜎+1, and [[𝑡⊔𝑢]]𝜎:=max([[𝑡]]𝜎,[[𝑢]]𝜎). Each of the six equations of definition 117.2 is valid in (ℕ,max,0,+1): left identity because 0 is least, associativity, commutativity and idempotence because max is a semilattice operation, distribution because max(𝑚,𝑛)+1=max(𝑚+1,𝑛+1), and inflation because max(𝑚,𝑚+1)=𝑚+1. Hence 𝑡≡𝑢 implies [[𝑡]]𝜎=[[𝑢]]𝜎 for every 𝜎.
The proof of lemma 117.8 gives 𝑣≡𝑅(𝑁(𝑣)), so it also gives [[𝑣]]𝜎=[[𝑅(𝑁(𝑣))]]𝜎, and the latter is the maximum of 𝑚 over any constant entry (⋆,𝑚) together with 𝜎(𝑥)+𝑘 over the variable entries (𝑥,𝑘). It therefore suffices to separate two distinct maps produced by definition 117.7. Let 𝑀≠𝑀′ be two such maps.
Suppose first that their variable entries differ at some 𝑥. Take 𝜎(𝑥):=𝑛 and 𝜎(𝑦):=0 for every other variable. Every term of the maximum other than the one contributed by 𝑥 is bounded by a constant independent of 𝑛, while 𝑥 contributes 𝑛+𝑘 when (𝑥,𝑘)∈𝑀 and contributes nothing when 𝑥 is absent. For 𝑛 larger than every exponent occurring in 𝑀 or 𝑀′, the two maxima are 𝑛+𝑘 and 𝑛+𝑘′ with 𝑘≠𝑘′, or one is 𝑛+𝑘 and the other is bounded independently of 𝑛; in both cases they differ.
Otherwise the variable entries agree and the constant entries differ. Take 𝜎(𝑦):=0 for every variable. A map produced by definition 117.7 retains (⋆,𝑚) only when every variable entry has exponent strictly below 𝑚, so its maximum at this valuation is 𝑚 when a constant entry is present and is the largest variable exponent otherwise. If both maps carry constant entries 𝑚≠𝑚′, the maxima differ. If exactly one does, its maximum is 𝑚 and the other’s is the largest shared variable exponent, which is strictly below 𝑚. If neither does, the maps agree, contradicting 𝑀≠𝑀′.
So distinct maps have distinct interpretations at some valuation, and equal levels have equal maps. ◻
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.
For the exact syntax and rules fixed in convention 117.1, the source proves the following package.
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).
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).
Typing is decidable only for the checkable/inferable classes and checkable contexts stated in Theorem 4.5.
Theorem 5.1 has a narrower signature. Fix a source context Γ, a source term 𝑡, and strictness 𝑠. 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; Γ⊢𝑡:ℕ; and 0𝑐▹1𝑡. Under those hypotheses there is 𝑛∈ℕ such that the source reduces to the numeral 𝑛―― and both the strict and non-strict erasures reduce to 𝑛――, 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 ℓ∈ℕ∪{𝜔}. Define reducibility 𝖱𝖾𝖽ℓ(Γ;𝐽) 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,↑(𝑡+)=1+↑𝑡,↑(𝑡⊔𝑢)=max(↑𝑡,↑𝑢), and assign realizer 0 to an atomic neutral. Mutual induction on reducible levels and their equality proves 𝑡≡𝑢⟹↑𝑡=↑𝑢,𝑡⊔𝑢≡𝑢⟹↑𝑡≤↑𝑢. 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 U𝑡 is reducible at external level ℓ when 𝑡 is a reducible level and ↑𝑡<ℓ; an element of that universe is a type reducible at external level ↑𝑡. Neutral types, Level, Π, Σ, natural numbers, unit, empty, identity, and lifted types have their standard Kripke clauses. In the lift clause, 𝗅𝗂𝖿𝗍 and 𝗅𝗈𝗐𝖾𝗋 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 ↑𝑡<1+↑𝑡. 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; 𝗅𝗂𝖿𝗍 and 𝗅𝗈𝗐𝖾𝗋 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 𝑛; its source component gives reduction of 𝑡 to 𝑛――, and its target component gives reduction of either erasure to 𝑛――. 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 𝑛 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 𝖽𝗂𝗌𝗉𝑛, written (−)↑𝑛 in that source, which raises every universe level inside a closed term by a fixed natural number 𝑛. A user writes the apparently monomorphic 𝗂𝖽:∏𝐴:U0𝐴→𝐴 and recovers the instance needed at the next level after the fact: 𝖽𝗂𝗌𝗉1(𝗂𝖽):∏𝐴:U0+𝐴→𝐴, so that 𝖽𝗂𝗌𝗉1(𝗂𝖽)(U0):U0→U0 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 𝗍𝗐𝗂𝖼𝖾𝖫𝖾𝗏𝖾𝗅, 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 ↑𝑗𝑖 but make it a silent, judgmentally functorial coercion: the laws ↑𝑖𝑖𝑀=𝑀 and ↑𝑘𝑗↑𝑗𝑖𝑀=↑𝑘𝑖𝑀 hold judgmentally, and lifting commutes with the dependent function space. Under definition 117.3 none of that holds: 𝖫𝗂𝖿𝗍𝑢 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 𝖫𝖾𝗏𝖾𝗅, it has a family 𝖫𝖾𝗏𝖾𝗅<ℓ 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.
★★☆ Write the complete type of a function that receives 𝗂𝖽𝐿 and uses it at ℕ, U0, and 𝖫𝗂𝖿𝗍0+ℕ. Mark the product that does not inhabit any universe and derive all three applications.
★★☆ Formalize the lifting law 𝖫𝗂𝖿𝗍𝑢(𝖫𝗂𝖿𝗍𝑣𝐴) against 𝖫𝗂𝖿𝗍𝑢⊔𝑣𝐴: give the two functions between them built from 𝗅𝗂𝖿𝗍 and 𝗅𝗈𝗐𝖾𝗋, 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.
★★☆ 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.
★★☆ 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.
★★★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.