betaFeedback

WorksComputer Science

Typechecking without Minimum Types: Finite Bases and Backward Checking for F<:⊤F_{<:}^{\top}

Abstract

System F<:⊤F_{<:}^{\top} has decidable subtyping but lacks minimum types. We prove that typechecking is decidable for arbitrary explicitly annotated terms with unrestricted subsumption. The difficulty is that type abstraction uses a variable's declared bound to type its body, while quantified subtyping forgets that bound. We construct finite covers that preserve all required subtype comparisons across this change of context. These covers yield a compositional finite typing basis and a decision procedure. We then derive a backward checker that propagates acceptable targets without constructing the complete typing basis. Rectangularity of typing families gives a uniform elimination domain while retaining every result type, even when the canonical type is not least. Finite inverse families transport targets through type substitution. The same inverse specification recovers bound forgetting and yields finite type-avoidance families. Both typechecking procedures are total Rocq functions proved equivalent to the original typing judgment. For a separate symbolic word-RAM realization, we prove a quartic worst-case work bound. We measure family representation sizes and comparison storage in independent OCaml prototypes on synthetic checking judgments.

CCS Concepts: • Theory of computation → Type theory.

Additional Key Words and Phrases: bounded quantification, subtyping, decidability, finite type bases, inverse substitution, type avoidance

Introduction

Decidable subtyping does not by itself provide a typechecking algorithm. A subtype checker compares two given types. Typechecking must also choose types for intermediate expressions, even when all parameter types and type arguments are explicit. Subsumption permits replacing an assigned type by a supertype before the next typing rule is applied. A computable minimum type, an assignable type below every other assignable type, controls these choices: compute that type, then compare it with the target [10].

For System F<:F_{<:}, Castagna and Pierce establish decidable subtyping, but their corrigendum exhibits terms without a minimum type and leaves general typechecking open [6, 7]. Laird later proves decidability for β\beta-normal terms of the original system [18 Corollary 8.6]. A normal form may have a type that the original term lacks, so normalizing the input does not extend this result to arbitrary terms § 9.1.

We prove that typechecking is decidable for arbitrary explicitly annotated terms of the original F<:TF^{\mathrm{T}}_{<:} calculus. We compute a finite collection of assignable types such that every assignable target is above at least one member. We then derive a backward checker that uses the requested target to avoid constructing the complete collection.

Why one type is not enough. In F<:TF^{\mathrm{T}}_{<:}, a type abstraction’s body can use the declared bound of its type variable. Comparing two quantified types instead treats that variable as having bound T\mathrm{T}. To see what this changes, take an outer variable β<:T\beta<: \mathrm{T} and the term

Λα<:β. λx:α. x:α.x.\Lambda\alpha<: \beta.\ \lambda x:\alpha.\ x:\alpha.x.

The inner function can return xx at type α\alpha or, using the bound α<:β\alpha<: \beta, at type β\beta. Thus the term has both types ∀α<:β.α→α\forall\alpha<: \beta.\alpha\to\alpha and ∀α<:β.α→β\forall\alpha<: \beta.\alpha\to\beta. Comparing these quantified types forgets the bound that related their bodies. Ghelli’s example rules out a common subtype of the two types in the outer context [7], so no minimum type can cover both. § 2.2 gives the inversion argument.

Decidability from finite representatives. Keeping both body types preserves the two typings in this example. For a general abstraction, we need enough assignable body types that, after its bound is forgotten for comparison, every type of the abstraction remains above one of the resulting quantified candidates. The corrigendum suggests using finite sets of minimal types; what is needed is a construction that covers all the choices subsumption permits.

We prove that the required finite covers can be computed for every well-formed type and context. They preserve the necessary comparisons after bound forgetting. For instance, to cover a variable’s supertypes, we retain the variable and representatives obtained from its bound. The full construction combines these alternatives according to the type constructors. Applying it at type abstraction lets us compute a finite collection for each term from the collections for its subterms. We call the result a typing basis. Write Δ\Delta for type-variable bounds and Γ\Gamma for term-variable typings. For a term ss in these contexts, the computed basis satisfies

Δ;Γ⊢s:T⟺∃B∈BΔ;Γ(s). Δ⊢B<:T.(1)\Delta;\Gamma\vdash s:T \quad\Longleftrightarrow\quad\exists B \in\mathcal{B}_{\Delta;\Gamma}(s).\ \Delta\vdash B <: T. \tag*{(1)}

Every candidate is assignable to ss, and an empty basis records failure to type the term. Checking a requested target therefore requires only finitely many subtype tests. The candidates need not be minimal.

Checking from a target. A finite basis establishes decidability, but its construction must retain enough candidates to cover every assignable type. Constructing and combining these candidates can require substantial work, even when a checking request asks about only one target. This motivates a backward checker that uses the requested target to determine which requirements to pass to subterms, without first constructing the complete basis.

At an application f uf\ u, the target TT specifies the required result type but leaves the parameter type undetermined. We must choose a type AA such that ff can be checked at A→TA \to T and uu at AA. The challenge is to make this choice without losing any valid typing.

We show that whenever ff can be used as a function, one computable parameter type is sufficient. It is a supertype of every admissible parameter type. Any result type available at one of those parameter types remains available at the chosen one. The checker can therefore fix the argument check while leaving all result choices available. We call this separation rectangularity. It holds even for functions without a minimum type. At type application, a corresponding property fixes the bound against which to check the explicit type argument.

At a type application, the desired result constrains the body of the function’s quantified type: after the explicit type argument is substituted, that body must be a subtype of the target. We represent these acceptable body types by a finite cover, allowing the requirement to be passed back to the function. We call this operation finite inverse substitution. Together, the fixed parameter types and these finite covers give a complete checker by recursion on the original term.

The inverse construction also recovers the bound-forgetting covers used in the decidability proof. Applied to a change of variable scope, it computes finite covers of the supertypes and subtypes expressible without a local type variable. § 8 develops this type-avoidance result and the requirements for transferring the method to another calculus.

The contributions are:

  • Decidable typechecking without minimum types. We construct effective finite covers under bound forgetting and use them to compute a complete typing basis. This decides the original judgment for arbitrary explicitly annotated terms, including β\beta-redexes and unrestricted subsumption (§ 3 and § 4).

  • Complete backward checking by inverse substitution. We prove rectangularity of typing families and exact finite inverse substitution, yielding a complete checker that propagates targets without constructing the full typing basis (§ 5). Shared representations support queries without enumeration (§ 6); a separate word-RAM realization has a quartic charged-work bound (Appendix § 15).

The two semantic checkers are total Rocq functions proved equivalent to the original declarative judgment. § 7 describes their verification and evaluates handwritten OCaml prototypes on complete synthetic checking judgments. The experiments examine symbolic family sizes and comparison storage.

The System F-sub-top Calculus

Syntax and rules

We use the subtype rules of § 2 and the typing rules of Appendix § 12.§ 1 of Castagna and Pierce’s extended version dated January 10, 1994 [6], with All-Top as the quantified subtyping rule. We use lowercase Greek letters α\alpha, β\beta, γ\gamma for type variables, Latin capitals AA, BB, CC for arbitrary types, and lowercase Latin letters xx, yy, zz for term variables. The syntax is

A,B::=α∣⊤∣A→B∣∀α<:A. B,s,t::=x∣Top⁡∣λx:A. s∣s t∣Λα<:A. s∣s{A}.\begin{aligned} A, B &::= \alpha\mid\top\mid A \to B \mid\forall\alpha<: A.\,B,\\ s, t &::= x \mid\operatorname{Top} \mid\lambda x : A.\,s \mid s\,t \mid\Lambda\alpha<: A.\,s \mid s\{A\}. \end{aligned}

Type and term contexts are

Δ::=∅∣Δ,α<:A,Γ::=∅∣Γ,x:A.\Delta::= \varnothing\mid\Delta, \alpha<: A,\qquad\Gamma::= \varnothing\mid\Gamma, x : A.

Contexts use distinct names; bounds in Δ\Delta refer only to earlier entries, and types in Γ\Gamma are scoped over Δ\Delta. Type formation is structural and depends only on scope. We use standard lookup notation, α\alpha-equivalence and capture-avoiding substitution B[R/α]B[R/\alpha]. Weakening of named types and term contexts is implicit. All rules below operate on well-formed contexts and types. We abbreviate Δ⊢A<:B\Delta\vdash A <: B by A<:ΔBA <:_\Delta B when convenient.

Figures Figure 1 and Figure 2 define the judgment to be decided. Subsumption may occur at any point in a derivation. The checker receives Δ\Delta, Γ\Gamma, ss, TT and decides whether Δ;Γ⊢s:T\Delta;\Gamma\vdash s : T holds. Type inference for unannotated terms is outside this specification. A raw term follows the displayed grammar but may contain unbound variables or ill-scoped annotations.

Δ⊢A<:AΔ⊢A<:A Refl⁡\frac{\phantom{\Delta\vdash A <: A}}{\Delta\vdash A <: A}\ \operatorname{Refl}
Δ⊢A<:BΔ⊢B<:CΔ⊢A<:C Trans⁡\frac{\Delta\vdash A <: B \qquad\Delta\vdash B <: C}{\Delta\vdash A <: C}\ \operatorname{Trans}
α<:A∈ΔΔ⊢α<:A Bound⁡\frac{\alpha<: A \in\Delta}{\Delta\vdash\alpha<: A}\ \operatorname{Bound}
Δ⊢A<:⊤Δ⊢A<:⊤ Top⁡\frac{\Delta\vdash A <: \top}{\Delta\vdash A <: \top}\ \operatorname{Top}
Δ⊢C<:AΔ⊢B<:DΔ⊢A→B<:C→D Arrow⁡\frac{\Delta\vdash C <: A \qquad\Delta\vdash B <: D}{\Delta\vdash A \to B <: C \to D}\ \operatorname{Arrow}
Δ⊢C<:AΔ,α<:⊤⊢B<:DΔ⊢∀α<:A. B<:∀α<:C. D All-Top⁡\frac{\Delta\vdash C <: A \qquad\Delta,\alpha<: \top\vdash B <: D}{\Delta\vdash\forall\alpha<: A.\,B <: \forall\alpha<: C.\,D}\ \operatorname{All\text{-}Top}

Figure 1. Declarative subtyping. Formation of all displayed judgments is implicit.

Typing rules for unrestricted subsumption

Figure 2. Typing with unrestricted subsumption. Type-Abs uses the actual annotation AA, whereas All-Top compares bodies with bound ⊤\top.

Failure of minimum typing

Return to Ghelli’s example from § 1 [7]. With Δ=(β<:⊤)\Delta= (\beta<: \top), write

e=Λα<:β. λx:α. x.e = \Lambda\alpha<: \beta.\ \lambda x : \alpha.\ x.

Denote the two types from the introduction by

T1=∀α<:β. α→α,T2=∀α<:β. α→β.T_1 = \forall\alpha<: \beta.\ \alpha\to\alpha,\qquad T_2 = \forall\alpha<: \beta.\ \alpha\to\beta.

A minimum, or least, type for ee would have to be a common subtype of T1T_1 and T2T_2. Subtype inversion (§ 2.3) rules out ⊤\top and arrows as subtypes of a universal. The only free type variable, β\beta, cannot be one either, because its bound is ⊤\top. A common subtype must therefore be universal. Comparing its body with both target bodies uses β<:⊤\beta<: \top, α<:⊤\alpha<: \top; inversion then forces an arrow body whose result lies below both α\alpha and β\beta. But the only subtype of α\alpha in that context is α\alpha, and the only subtype of β\beta is β\beta. Hence no common subtype exists, and ee has no minimum type.

For checking, the obstruction is the order of Sub and Type-Abs. A derivation of T2T_2 first applies subsumption to the body λx:α. x\lambda x : \alpha.\ x, using the actual bound:

Δ,α<:β⊢α→α<:α→β.\Delta, \alpha<: \beta\vdash\alpha\to\alpha<: \alpha\to\beta.

The body therefore has type α→β\alpha\to\beta. Applying Type-Abs then gives Δ;∅⊢e:T2\Delta; \varnothing\vdash e : T_2. Alternatively, apply Type-Abs directly to the body’s type α→α\alpha\to\alpha, obtaining Δ;∅⊢e:T1\Delta; \varnothing\vdash e : T_1. A final use of Sub could reach T2T_2 only if Δ⊢T1<:T2\Delta\vdash T_1 <: T_2. All-Top compares the bodies under α<:⊤\alpha<: \top, where

Δ,α<:⊤⊬α→α<:α→β.\Delta, \alpha<: \top\nvdash\alpha\to\alpha<: \alpha\to\beta.

This comparison would require α<:β\alpha<: \beta, which is unavailable in that context. Thus the second route fails: subsumption inside the body cannot always be postponed until after type abstraction.

The abstraction step must therefore account for typings obtained under the actual bound before using the weaker comparison context. Keeping both body types α→α\alpha\to\alpha and α→β\alpha\to\beta repairs this example. For a general abstraction, each retained body type needs finite alternatives that are assignable under the actual bound and cover its supertypes under the comparison context with bound ⊤\top. § 3 formulates these two requirements and constructs finite families satisfying them.

Decidable subtyping and exposure

We decide subtype comparisons using Castagna and Pierce’s algorithmic relation [6 Section 4.1], written Δ⊢aA<:B\Delta\vdash_{\mathrm{a}} A <: B. Figure 3 gives its five rules in our notation.

Algorithmic subtyping rules

Figure 3. Algorithmic subtyping, following Castagna and Pierce [6 Section 4.1]. All judgments are well formed, and the binder in A-All-Top is fresh.

Δ⊢aA<:⊤A-TopΔ⊢aα<:αA-Reflα<:A∈ΔΔ⊢aA<:BΔ⊢aα<:BA-PromoteΔ⊢aC<:AΔ⊢aB<:DΔ⊢aA→B<:C→DA-ArrowΔ⊢aC<:AΔ,α<:⊤⊢aB<:DΔ⊢a∀α<:A. B<:∀α<:C. DA-All-Top\begin{aligned} &\Delta\vdash_a A <: \top&& \text{A-Top}\\ &\Delta\vdash_a \alpha<: \alpha&& \text{A-Refl}\\ &\frac{\alpha<: A \in\Delta\qquad\Delta\vdash_a A <: B}{\Delta\vdash_a \alpha<: B} && \text{A-Promote}\\ &\frac{\Delta\vdash_a C <: A \qquad\Delta\vdash_a B <: D}{\Delta\vdash_a A \to B <: C \to D} && \text{A-Arrow}\\ &\frac{\Delta\vdash_a C <: A \qquad\Delta,\alpha<: \top\vdash_a B <: D}{\Delta\vdash_a \forall\alpha<: A.\,B <: \forall\alpha<: C.\,D} && \text{A-All-Top} \end{aligned}

Compared with Figure 1, reflexivity is restricted to variables and general transitivity is absent. A-Promote combines Bound with a Trans step whose intermediate type is fixed by the context. The premises of Arrow and All-Top are unchanged. To execute the rules, first test A-Top and A-Refl. Otherwise, promote a left variable or decompose matching constructors. If no rule applies, the comparison fails.

The difference from the algorithm for full F<:\mathrm{F}_{<:} is confined to the quantified body. For source ∀α<:A. B\forall\alpha<: A.\,B and target ∀α<:C. D\forall\alpha<: C.\,D, both algorithms compare CC with AA. They compare the bodies BB and DD in the respective contexts

full F<:Δ,α<:CF<:TΔ,α<:⊤\begin{aligned} \text{full } \mathrm{F}_{<:}&\qquad\Delta,\alpha<: C\\ \mathrm{F}^{\mathsf{T}}_{<:}&\qquad\Delta,\alpha<: \top \end{aligned}

In particular, A-All-Top uses neither quantifier’s declared bound in the body comparison.

In the cited extended version, Castagna and Pierce prove soundness and completeness [6 Theorem 4.4]: for well-formed inputs,

Δ⊢aA<:B⟺Δ⊢A<:B.(2)\Delta\vdash_a A <: B \Longleftrightarrow\Delta\vdash A <: B. \tag*{(2)}

Their termination result [6 Theorem 4.7 and Corollary 4.8] makes this a decision procedure.

Exposure. Application requires an arrow head, and type application requires a universal head. A type variable can provide either through its bound. We use the standard bound-following operation, also described by Laird [18 Lemma 6.3]. For well-formed Δ\Delta, AA, write AΔ♯A^\sharp_\Delta for the resulting type in the same scope, whose root is ⊤\top, an arrow, or a universal:

αΔ♯=Δ(α)Δ♯⊤Δ♯=⊤,(A→B)Δ♯=A→B,(∀α<:A. B)Δ♯=∀α<:A. B.\begin{aligned} \alpha^\sharp_\Delta&= \Delta(\alpha)^\sharp_\Delta\\ \top^\sharp_\Delta&= \top,\\ (A \to B)^\sharp_\Delta&= A \to B,\\ (\forall\alpha<: A.\,B)^\sharp_\Delta&= \forall\alpha<: A.\,B. \end{aligned}

It stops as soon as the outer constructor is known, without traversing its components. Ordered bounds make the variable case terminate. For example, if Δ=β<:⊤→⊤,α<:β\Delta= \beta<: \top\to\top,\alpha<: \beta, then αΔ♯=⊤→⊤\alpha^\sharp_\Delta= \top\to\top.

Exposure is deterministic and satisfies Δ⊢M<:MΔ♯\Delta\vdash M <: M^\sharp_\Delta. For compound targets, algorithmic inversion gives the interfaces used at elimination:

M<:ΔC→D⟺∃A0,B0. MΔ♯=A0→B0∧C<:ΔA0∧B0<:ΔD(3)M <:_{\Delta} C \to D \Longleftrightarrow\exists A_0,B_0.\ M^\sharp_\Delta= A_0 \to B_0 \land C <:_{\Delta} A_0 \land B_0 <:_{\Delta} D \tag*{(3)}
M<:Δ∀α<:C. D⟺∃A0,B0. MΔ♯=∀α<:A0. B0∧C<:ΔA0∧B0<:Δ,α<:⊤D.(4)M <:_{\Delta} \forall\alpha<: C.\,D \Longleftrightarrow\exists A_0,B_0.\ M^\sharp_\Delta= \forall\alpha<: A_0.\,B_0 \land C <:_{\Delta} A_0 \land B_0 <:_{\Delta,\alpha<:\top} D. \tag*{(4)}

Thus an exposed arrow or universal retains every comparison needed by its elimination rule, even when the original type is a variable. Type abstraction still requires a way to retain all body typings when the comparison context changes from α<:A\alpha<: A to α<:⊤\alpha<: \top.

Finite Covers under Bound Forgetting

Subsumption inside a type abstraction cannot always be postponed until after the abstraction (§ 2.2). We construct a finite set of alternatives for one assignable body type that covers its supertypes after bound forgetting. § 4 uses this construction to compute complete typing bases by recursion on terms.

Coverage at type abstraction

For a fresh binder α\alpha, we use the following abbreviations throughout:

ΔA=Δ, α<:A,Δ⊤=Δ, α<:⊤.\Delta_{A} = \Delta, \ \alpha<: A,\qquad\Delta_{\top} = \Delta, \ \alpha<: \top.

The surrounding expression determines the binder α\alpha. Consider Λα<:A. s\Lambda\alpha<: A.\ s whose body has a type

ΔA; Γ⊢s:B.\Delta_{A};\ \Gamma\vdash s : B.

Here BB is one assignable type, with no assumption that it is least. For any RR satisfying B<: ⁣ΔARB <:\!_{\Delta_{A}} R, Sub assigns RR to the body, and Type-Abs gives the abstraction type ∀α<:A. R\forall\alpha<: A.\ R. If we apply Type-Abs at BB first, reaching that same target by subsumption requires B<: ⁣Δ⊤RB <:\!_{\Delta_{\top}} R. As § 2.2 shows, the known comparison under ΔA\Delta_{A} does not imply this comparison under Δ⊤\Delta_{\top}.

To account for all such RR, we seek a finite set FBF_{B} of types CC, computed from ΔA\Delta_{A} and the single type BB, independently of RR. Each member must be well scoped in ΔA\Delta_{A}, and the set must satisfy two requirements:

C∈FB⇒B<: ⁣ΔAC,(5)C \in F_{B} \mathbin{\Rightarrow} B <:\!_{\Delta_{A}} C, \tag*{(5)}
B<: ⁣ΔAR⇒∃C∈FB. C<: ⁣Δ⊤R.(6)B <:\!_{\Delta_{A}} R \mathbin{\Rightarrow} \exists C \in F_{B}.\ C <:\!_{\Delta_{\top}} R. \tag*{(6)}

The first requirement makes every CC assignable to the body by Sub. Applying Type-Abs to each choice gives finitely many types ∀α<:A. C\forall\alpha<: A.\ C. The second requirement ensures that, for every RR above BB in ΔA\Delta_{A}, one of these quantified types lies below ∀α<:A. R\forall\alpha<: A.\ R by All-Top. Any subsequent subsumption on the quantified type remains available. We call such a set an upper cover of BB across the change from ΔA\Delta_{A} to Δ⊤\Delta_{\top}. The requirements involve only types and bounds, so we can construct this operation independently of the body term.

For Ghelli’s example, Δ=β<:⊤\Delta= \beta<: \top, A=βA = \beta, and the body λx:α. x\lambda x : \alpha.\ x has type B=α→αB = \alpha\to\alpha. Take

FB={α→α, α→β}.F_{B} = \{\alpha\to\alpha,\ \alpha\to\beta\}.

Both members are assignable under α<:β\alpha<: \beta. Applying Type-Abs to them gives the two quantified types of § 2.2. Each retained body matches its corresponding target by reflexivity under α<:⊤\alpha<: \top. § 5 returns to the same target through an explicit type application. There the inverse construction uses a finite family to answer one query, rather than computing the abstraction’s whole basis.

Principal and finite covers

Type abstraction changes only the new variable’s bound. For a uniform recursive construction, we first solve the stronger problem of forgetting all ambient bounds. For any context Θ\Theta, let Θ∘\Theta^{\circ} replace its bounds by ⊤\top, preserving the variable domain and leaving bounds inside types unchanged.

Restoring forgotten bounds preserves subtype comparisons. A use of α<:⊤\alpha<: \top can always be justified in the restored context, and All-Top extends both comparison contexts with the same fresh variable bounded by ⊤\top. Induction on a subtype derivation therefore gives, in particular,

ΔA∘⊢S<:T⟹Δ⊤⊢S<:T⟹ΔA⊢S<:T.(7)\Delta_{A}^{\circ} \vdash S <: T \Longrightarrow\Delta_{\top} \vdash S <: T \Longrightarrow\Delta_{A} \vdash S <: T. \tag*{(7)}

A family that provides coverage in ΔA∘\Delta_{A}^{\circ} consequently provides coverage in Δ⊤\Delta_{\top} as well. We can construct it by full forgetting and then restore the outer bounds that type abstraction retains.

For a well-formed context Δ\Delta, its well-scoped types form a preorder PΔP_{\Delta} under subtyping. The principal upper and lower cones of a type AA are

↑ΔA={T:A<:ΔT},↓ΔA={S:S<:ΔA}.\uparrow_{\Delta} A = \{T : A <:_\Delta T\}, \qquad\downarrow_{\Delta} A = \{S : S <:_\Delta A\}.

For a set SS of types, extend these operations by union:

↑ΔS=⋃A∈S↑ΔA,↓ΔS=⋃A∈S↓ΔA.\uparrow_{\Delta} S = \bigcup_{A \in S} \uparrow_{\Delta} A, \qquad\downarrow_{\Delta} S = \bigcup_{A \in S} \downarrow_{\Delta} A.

Thus ↑Δ{A}=↑ΔA\uparrow_{\Delta} \{A\} = \uparrow_{\Delta} A, and similarly for lower cones. When SS is finite, these sets are finitely generated; the sets themselves may be infinite. An upper cover expresses an old upper cone as a finite union of upper cones in the weaker context.

For Δ=β<:⊤\Delta= \beta<: \top and A=βA = \beta as above, the supertypes of α→α\alpha\to\alpha in ΔA\Delta_A are exactly ⊤\top, α→α\alpha\to\alpha, α→β\alpha\to\beta, and α→⊤\alpha\to\top. The arrow rules give

↑ΔA(α→α)=↑Δ⊤{α→α,α→β}.\uparrow_{\Delta_A}(\alpha\to\alpha) = \uparrow_{\Delta_{\top}}\{\alpha\to\alpha, \alpha\to\beta\}.

In Figure 4, the types form a chain under the actual bound. In Δ⊤\Delta_{\top}, α→α\alpha\to\alpha and α→β\alpha\to\beta become incomparable, while both remain below α→⊤\alpha\to\top.

Principal upper cone of $\alpha \to \alpha$ under $\alpha <: \beta$ and its finite cover under $\alpha <: \top$

Figure 4. The principal upper cone of α→α\alpha\to\alpha under α<:β\alpha<: \beta and its finite cover under α<:⊤\alpha<: \top, with Δ=(β<:⊤)\Delta= (\beta<: \top). Arrows point toward immediate supertypes. The outlined nodes generate the same four-element upper set in their respective contexts: one generator on the left, two on the right.

The left side is principal in ΔA\Delta_A. It has no single generator in Δ⊤\Delta_{\top}, where α→α\alpha\to\alpha and α→β\alpha\to\beta have no common subtype by the inversion argument of § 2.2.

Upper covers solve the obligation at type abstraction. Their construction also needs lower covers: an arrow comparison A→B<:C→DA \to B <: C \to D requires C<:AC <: A in its contravariant domain. We therefore establish both directions together.

Theorem 3.1 (Effective finite cone covers). For each well-formed Δ\Delta, AA, one can compute finite families UΔ(A)U_{\Delta}(A) and DΔ(A)D_{\Delta}(A) of types well formed in Δ\Delta such that

↑ΔA=↑Δ∘UΔ(A),(8)\uparrow_{\Delta} A = \uparrow_{\Delta} \circ U_{\Delta}(A), \tag*{(8)}
↓ΔA=↓Δ∘DΔ(A).(9)\downarrow_{\Delta} A = \downarrow_{\Delta} \circ D_{\Delta}(A). \tag*{(9)}

These equalities imply representative soundness. For u∈UΔ(A)u \in U_{\Delta}(A), reflexivity gives u∈↑Δ∘UΔ(A)=↑ΔAu \in\uparrow_{\Delta} \circ U_{\Delta}(A) = \uparrow_{\Delta} A, so A<:ΔuA <:_\Delta u. Dually, every d∈DΔ(A)d \in D_{\Delta}(A) satisfies d<:ΔAd <:_\Delta A.

The singleton {A}\{A\} would suffice if both sides used Δ\Delta. The finite families need not be minimal.

Restoring the outer bounds gives coverage in the comparison context used by type abstraction.

Corollary 3.2 (Restoring only the outer bounds). For well-formed Δ\Delta, AA and types BB, TT in the scope of ΔA\Delta_A,

ΔA⊢B<:T⟺∃u∈UΔA(B). Δ⊤⊢u<:T.\Delta_A \vdash B <: T \Longleftrightarrow\exists u \in U_{\Delta_A}(B). \ \Delta_{\top} \vdash u <: T.

Proof. Forward coverage holds first in ΔA∘\Delta_A^\circ. By (7), restore the outer bounds to obtain the comparison in Δ⊤\Delta_{\top}. Conversely, restore α\alpha’s bound to AA and compose with representative soundness.

Taking FB=UΔA(B)F_B = U_{\Delta_A}(B) now satisfies (5) by representative soundness and (6) by this corollary.

Constructing upper and lower covers

Given a well-formed Δ\Delta and type AA in its scope, the variable-source operation returns the finite set of declared variables below AA:

VΔ(A)={α∈dom⁡(Δ):Δ⊢α<:A}.V_{\Delta}(A) = \{\alpha\in\operatorname{dom}(\Delta) : \Delta\vdash\alpha<: A\}.

Subtyping decides membership. With C=Δ(α)C = \Delta(\alpha), the base cases are

UΔ(⊤)={⊤},DΔ(⊤)={⊤},UΔ(α)={α}∪UΔ(C),DΔ(α)=VΔ(α).\begin{aligned} U_{\Delta}(\top) &= \{\top\}, & D_{\Delta}(\top) &= \{\top\},\\ U_{\Delta}(\alpha) &= \{\alpha\} \cup U_{\Delta}(C), & D_{\Delta}(\alpha) &= V_{\Delta}(\alpha). \end{aligned}

A variable can either remain itself or use its upper bound. There are no compound subtypes of a variable, which accounts for the lower variable case.

For arrows, contravariance exchanges the two recursive constructions:

UΔ(A→B)={⊤}∪{a→b:a∈DΔ(A), b∈UΔ(B)},DΔ(A→B)=VΔ(A→B)∪{a→b:a∈UΔ(A), b∈DΔ(B)}.\begin{aligned} U_{\Delta}(A \to B) &= \{\top\} \cup\{a \to b : a \in D_{\Delta}(A),\ b \in U_{\Delta}(B)\},\\ D_{\Delta}(A \to B) &= V_{\Delta}(A \to B) \cup\{a \to b : a \in U_{\Delta}(A),\ b \in D_{\Delta}(B)\}. \end{aligned}

The lower variable-source component cannot be omitted: a variable with a function bound may be below an arrow without having arrow syntax.

Universal types follow the same variance:

UΔ(∀α<:A. B)={⊤}∪{∀α<:a. b:a∈DΔ(A), b∈UΔ⊤(B)},DΔ(∀α<:A. B)=VΔ(∀α<:A. B)∪{∀α<:a. b:a∈UΔ(A), b∈DΔ⊤(B)}.\begin{aligned} U_{\Delta}(\forall\alpha<: A.\ B) &= \{\top\} \cup\{\forall\alpha<: a.\ b : a \in D_{\Delta}(A),\ b \in U_{\Delta_{\top}}(B)\},\\ D_{\Delta}(\forall\alpha<: A.\ B) &= V_{\Delta}(\forall\alpha<: A.\ B) \cup\{\forall\alpha<: a.\ b : a \in U_{\Delta}(A),\ b \in D_{\Delta_{\top}}(B)\}. \end{aligned}

All-Top makes Δ⊤\Delta_{\top} independent of the bound aa of a generated type, so one recursive body cover suffices for every candidate bound.

Termination

A variable bound may be larger than the variable’s syntax, so plain type size does not justify recursion. As in Castagna and Pierce’s termination argument [6 Section 4.1.2], we measure types relative to their bounds. Our universal case gives the body variable bound ⊤\top, matching the cone recursion. Build a weight environment ρ\rho in the order of Δ\Delta. On declaring α<:A\alpha<: A, set ρ(α)=1+wρ(A)\rho(\alpha) = 1+w_{\rho}(A), where

wρ(α)=ρ(α),wρ(⊤)=1,wρ(A→B)=1+wρ(A)+wρ(B),wρ(∀α<:A. B)=1+wρ(A)+wρ[α↦2](B).\begin{aligned} w_{\rho}(\alpha) &= \rho(\alpha), & w_{\rho}(\top) &= 1,\\ w_{\rho}(A \to B) &= 1 + w_{\rho}(A) + w_{\rho}(B), & w_{\rho}(\forall\alpha<: A.\ B) &= 1 + w_{\rho}(A) + w_{\rho[\alpha\mapsto2]}(B). \end{aligned}

The weight 2 is the weight of a variable with bound ⊤\top. Earlier weights are available when a bound is measured, because contexts are ordered. ρ[α↦2]\rho[\alpha\mapsto2] extends the weight assignment with the fresh variable α\alpha. Write wΔ(A)w_{\Delta}(A) for the resulting type weight.

Extending the context by a fresh variable preserves the weights of old variables. Consequently, for a type TT well scoped in Δ\Delta,

wΔ,α<:A(T)=wΔ(T).w_{\Delta,\alpha<:A}(T)=w_{\Delta}(T).

Thus a variable α\alpha with declared bound CC satisfies wΔ(C)<wΔ(α)w_{\Delta}(C)<w_{\Delta}(\alpha). Every cone call therefore decreases weight: it either follows a bound, selects an arrow component, or selects a universal component with the stipulated extension by α<:⊤\alpha<:\top. Variable-source tests use the terminating subtype checker, whose recursive calls decrease the sum of the two endpoint weights. Exposure decreases the source weight. These measures establish termination without bounding the number or size of generated representatives by a polynomial.

Soundness and completeness

Proof sketch for Theorem 3.1. Induct on the weight, proving well-formedness and representative soundness together with both coverage equalities. A variable either remains itself or follows its bound; lower covers also retain all qualifying variable sources. Arrow inversion exchanges upper and lower coverage in the domain.

For a universal comparison ∀α<:A.B<:Δ∀α<:C.D\forall\alpha<:A.B<:_{\Delta}\forall\alpha<:C.D, inversion gives C<:ΔAC<:_{\Delta}A and B<:Δ⊤DB<:_{\Delta_{\top}}D. Choose a∈DΔ(A)a\in D_{\Delta}(A) and b∈UΔ⊤(B)b\in U_{\Delta_{\top}}(B) with C<:Δ∘aC<:_{\Delta^{\circ}}a and b<:Δ⊤∘Db<:_{\Delta_{\top}^{\circ}}D. All-Top then gives

Δ∘⊢∀α<:a.b<:∀α<:C.D.\Delta^{\circ}\vdash\forall\alpha<:a.b<:\forall\alpha<:C.D.

The representative is sound because a<:ΔAa<:_{\Delta}A and B<:Δ⊤bB<:_{\Delta_{\top}}b. The same body context Δ⊤\Delta_{\top} works for every generated bound. Lower coverage reverses the recursive choices and retains variable sources. Appendix § 12.§ 3 gives the full induction. □

Decidable Typechecking from Finite Bases

We compute typing bases by recursion on the original term. The cone cover of Corollary 3.2 handles bound forgetting at type abstraction; the remaining constructors use exposure and subtype tests.

Constructing typing bases

Theorem 4.1 (Effective finite typing bases). For every well-formed Δ;Γ\Delta;\Gamma and raw term ss, a finite family BΔ;Γ(s)B_{\Delta;\Gamma}(s) satisfying (1) is computable. Every family member is an assignable type of ss.

Figure 5 collects the finite-basis checker in rule form. The judgment Δ;Γ⊢bs⇒F\Delta;\Gamma\vdash_b s\Rightarrow F computes the finite set F=BΔ;Γ(s)F=B_{\Delta;\Gamma}(s), which may be empty; Δ;Γ⊢bs⇐T\Delta;\Gamma\vdash_b s\Leftarrow T accepts the requested target exactly when some B∈FB\in F satisfies Δ⊢aB<:T\Delta\vdash_a B<:T. The rules display the well-scoped cases with well-formed annotations.

Finite-basis synthesis and checking

Figure 5. Finite-basis synthesis and checking.

Each recursive basis supplies assignable candidates for the enclosing typing rule. Ordinary abstraction preserves coverage through covariance in the result type. At eliminations, exposure allows a candidate with a variable head to supply an arrow or universal. The tests in B-App and B-Type-App establish the premises needed to use that exposed type. For ordinary application, one argument candidate below the exposed domain suffices by subsumption. Type application checks the explicit type argument against the exposed bound.

B-Type-Abs is where the cone cover is needed. A body representative covers its supertypes under the actual bound in ΔA\Delta_A. Directly quantifying that representative can lose coverage, since All-Top compares bodies in Δ⊤\Delta_{\top}. The rule first takes its upper cover and then quantifies each retained body under the written bound AA. Representative soundness makes each candidate assignable; coverage after forgetting preserves every typing of the abstraction. This discharges the obligation from § 3.1.

A missing variable, malformed annotation or malformed type argument yields the empty basis, as does an elimination with no surviving candidate.

Soundness and completeness

Proof sketch for Theorem 4.1. Induct on ss. Every recursive call is on a proper subterm, and every auxiliary construction terminates by § 3.4. Typing inversion exposes the rule for that term constructor followed by a possible final subsumption.

At type abstraction, let inversion give a body type RR and a comparison ∀α<:A. R<:ΔT\forall\alpha<: A.\ R <:\Delta T. Choose a body representative BB with B<:ΔARB <:\Delta_A R. Corollary 3.2 gives C∈UΔA(B)C \in U_{\Delta_A}(B) with

Δ,α<:⊤⊢C<:R.\Delta, \alpha<: \top\vdash C <: R.

Hence All-Top gives ∀α<:A. C<:Δ∀α<:A. R\forall\alpha<: A.\ C <:\Delta\forall\alpha<: A.\ R and then ∀α<:A. C<:ΔT\forall\alpha<: A.\ C <:\Delta T. Soundness uses B<:ΔACB <:\Delta_A C to type the body before applying Type-Abs. Cone coverage thus accounts for the subsumption before type abstraction in § 2.2.

At a type application, inversion gives f:∀α<:U. Vf : \forall\alpha<: U.\ V, R<:ΔUR <:\Delta U, and V[R/α]<:ΔTV[R/\alpha] <:\Delta T. By (4), a function representative exposes as ∀α<:A. B\forall\alpha<: A.\ B with U<:ΔAU <:\Delta A and B<:Δ,α<:⊤VB <:\Delta,\alpha<:\top V. The bound test R<:ΔAR <:\Delta A succeeds. Preservation of subtyping by substitution from Δ⊤\Delta_{\top} gives B[R/α]<:ΔV[R/α]B[R/\alpha] <:\Delta V[R/\alpha], so the retained type covers TT. Soundness follows from exposure, Type-App, and the successful bound test. All these arguments retain the final subsumption supplied by inversion. Appendix § 12.§ 4 gives the full induction over term constructors. □

Corollary 4.2 (Decidability of the original judgment). Typechecking for arbitrary explicitly annotated F<:_{\mathsf{<:}} terms is decidable. There is a total procedure that accepts a raw input (Δ,Γ,s,T)(\Delta, \Gamma, s, T) exactly when Δ;Γ⊢s:T\Delta; \Gamma\vdash s : T holds.

Proof. Reject malformed environments and targets. Otherwise compute the finite basis and ask whether a member is below TT. Representative soundness and complete coverage prove the equivalence. Malformed inputs admit no typing derivation, so the wrapper needs no well-formedness premise on its caller. □\square

The cost of finite bases

The finite-basis theorem establishes a terminating construction but gives no polynomial bound on its cost. Shared representations can compress some very large finite families (Appendix § 13.§ 2). Such compression alone does not bound the cost of general construction or queries.

Backward Checking by Inverse Substitution

The finite-basis procedure summarizes all assignable types before comparing with a target. To decide a single judgment, we instead propagate acceptable targets through the term. Application requires a domain for the argument check; type application requires body targets before substitution. We introduce rectangularity to address the first problem, while finite inverse coverage addresses the second.

A canonical interface for elimination

Exposing a canonical type must recognize every available elimination shape and supply a domain or bound that preserves all result choices, including after substitution.

The rules below define Δ;Γ⊢cs⇒C\Delta; \Gamma\vdash_{\mathrm{c}} s \Rightarrow C on well-formed contexts and annotations, using the original typing judgment for argument checks. § 5.3 implements this relation.

Γ(x)=AΔ;Γ⊢cx⇒AΔ;Γ⊢cTop⇒⊤\frac{\Gamma(x)=A}{\Delta;\Gamma\vdash_{\mathrm{c}}x\Rightarrow A} \qquad \frac{}{ \Delta;\Gamma\vdash_{\mathrm{c}}\mathop{\mathrm{Top}}\Rightarrow\top}
Δ;Γ,x:A⊢cs⇒BΔ;Γ⊢cλx:A.s⇒A→BΔ,α<:A;Γ⊢cs⇒BΔ;Γ⊢cΛα<:A.s⇒∀α<:A.B\frac{\Delta;\Gamma,x:A\vdash_{\mathrm{c}}s\Rightarrow B}{\Delta;\Gamma\vdash_{\mathrm{c}}\lambda x:A.s\Rightarrow A\to B} \qquad \frac{\Delta,\alpha<:A;\Gamma\vdash_{\mathrm{c}}s\Rightarrow B}{\Delta;\Gamma\vdash_{\mathrm{c}}\Lambda\alpha<:A.s\Rightarrow\forall\alpha<:A.B}
Δ;Γ⊢cf⇒CC=A→BΔ;Γ⊢u:AΔ;Γ⊢cfu⇒BΔ;Γ⊢cf⇒CC=∀α<:A.BR<: ⁣ΔAΔ;Γ⊢cf{R}⇒B[R/α]\frac{\Delta;\Gamma\vdash_{\mathrm{c}}f\Rightarrow C \quad C=A\to B \qquad\Delta;\Gamma\vdash u:A}{\Delta;\Gamma\vdash_{\mathrm{c}}fu\Rightarrow B} \qquad \frac{\Delta;\Gamma\vdash_{\mathrm{c}}f\Rightarrow C \quad C=\forall\alpha<:A.B \qquad R<:\!_{\Delta}A}{\Delta;\Gamma\vdash_{\mathrm{c}}f\{R\}\Rightarrow B[R/\alpha]}

The proof tracks the pair formed by a term’s complete typing family and its canonical type. These semantic families may be infinite and are used only in the proof.

A substitution σ:Δ→Θ\sigma:\Delta\to\Theta is typed when its images are well formed and each source variable α\alpha satisfies σ(α)<: ⁣ΘΔ(α)[σ]\sigma(\alpha)<:\!_{\Theta}\Delta(\alpha)[\sigma]. Such substitutions preserve subtyping. For a type set SS, write S[σ]={B[σ]:B∈S}S[\sigma]=\{B[\sigma]:B\in S\}.

Definition 5.1 (Structured families). A pair (S,C)(S,C) is structured in Δ\Delta iff it is generated by the following clauses. All types are well formed in their indicated contexts.

  1. Singleton. ({C},C)({\{C\}},C) is structured in Δ\Delta.

  2. Constructors. From (S,B)(S,B) structured in Δ\Delta, form ({A→V:V∈S},A→B)({\{A\to V:V\in S\}},A\to B) in Δ\Delta. From (S,B)(S,B) structured in Δ\Delta, α<:A\alpha<:A, form ({∀α<:A.V:V∈S},∀α<:A.B)({\{\forall\alpha<:A.V:V\in S\}},\forall\alpha<:A.B) in Δ\Delta.

  3. Closure replacement. Replace SS by any family containing CC with the same upward closure in Δ\Delta.

  4. Typed image. Along a typed σ:Δ→Θ\sigma:\Delta\to\Theta, form (S[σ],C[σ])(S[\sigma],C[\sigma]) in Θ\Theta.

Singletons account for variables and the constant; constructors account for introductions. Closure replacement accounts for subsumption, and typed images account for type application. Every structured family contains its distinguished member, so it may be replaced by its upward closure. The next lemma shows that elimination also returns a structured family, allowing the invariant to be used again.

Lemma 5.2 (Rectangularity under typed substitution). Let (S,C)(S,C) be structured in Δ\Delta and σ:Δ→Θ\sigma: \Delta\to\Theta be typed. If C[σ]Θ♯=A0→B0C[\sigma]^{\sharp}_{\Theta} = A_{0} \to B_{0}, there is a structured pair (R,B0)(R,B_{0}) in Θ\Theta such that, for all well-scoped U,VU,V,

U→V∈↑ΘS[σ]⟺U< ⁣: ⁣ΘA0∧V∈R.U \to V \in\uparrow_{\Theta} S[\sigma] \Longleftrightarrow U <\!:\!_{\Theta} A_{0} \land V \in R.

If C[σ]Θ♯=∀α< ⁣: ⁣A0.B0C[\sigma]^{\sharp}_{\Theta} = \forall\alpha<\!:\! A_{0}. B_{0}, there is a structured pair (R,B0)(R,B_{0}) in Θ\Theta, α< ⁣: ⁣A0\alpha<\!:\! A_{0} such that

∀α< ⁣: ⁣U.V∈↑ΘS[σ]⟺U< ⁣: ⁣ΘA0∧V∈R,\forall\alpha<\!:\! U.V \in\uparrow_{\Theta} S[\sigma] \Longleftrightarrow U <\!:\!_{\Theta} A_{0} \land V \in R,

where VV has the extended variable scope. Conversely, an arrow in ↑ΘS[σ]\uparrow_{\Theta} S[\sigma] forces C[σ]C[\sigma] to expose an arrow, and a universal forces it to expose a universal.

Proof sketch. Induct on the structured-family clauses, generalizing over Θ\Theta and σ\sigma. Singleton families use exposure and subtype inversion. Constructor families keep the domain independent of the body choices. In the universal case, ALL-TOP takes the body’s upward closure under bound ⊤\top, but the body family must remain structured under the actual bound AA. For a family SS in ΔA\Delta_{A}, bound restoration and transitivity give

↑ΔA(↑Δ⊤S)=↑ΔAS.(10)\uparrow_{\Delta_{A}}\left(\uparrow_{\Delta_{\top}} S\right) = \uparrow_{\Delta_{A}} S. \tag*{(10)}

Thus closure replacement preserves the structured pair under the actual bound, also after substitution. Subtype preservation transports closure replacement through σ\sigma; the typed-image case uses composition of typed substitutions. Appendix § 12.§ 1 gives the full induction. □

Corollary 5.3 (Canonical elimination interface). In well-formed contexts Δ;Γ\Delta;\Gamma, the canonical relation satisfies:

  1. Typability and assignability. A term ss is typable exactly when there is a CC with Δ;Γ⊢fcs⇒C\Delta;\Gamma\vdash_{\mathrm{fc}} s \Rightarrow C. This CC is unique and Δ;Γ⊢s:C\Delta;\Gamma\vdash s : C.

  1. Shape completeness. For such a CC, ss has an assignable arrow type exactly when CΔ♯C^{\sharp}_{\Delta} is an arrow, and an assignable universal type exactly when it is a universal.

  1. Rectangularity. If CΔ♯=A→BC^{\sharp}_{\Delta} = A \to B or CΔ♯=∀α< ⁣: ⁣A.BC^{\sharp}_{\Delta} = \forall\alpha<\!:\! A.B, respectively, then

Δ;Γ⊢s:U→V⟺U< ⁣: ⁣ΔA∧Δ;Γ⊢s:A→V,(11)\Delta;\Gamma\vdash s : U \to V \Longleftrightarrow U <\!:\!_{\Delta} A \land\Delta;\Gamma\vdash s : A \to V, \tag*{(11)}
Δ;Γ⊢s:∀α< ⁣: ⁣U.V⟺U< ⁣: ⁣ΔA∧Δ;Γ⊢s:∀α< ⁣: ⁣A.V.(12)\Delta;\Gamma\vdash s : \forall\alpha<\!:\! U.V \Longleftrightarrow U <\!:\!_{\Delta} A \land\Delta;\Gamma\vdash s : \forall\alpha<\!:\! A.V. \tag*{(12)}

Components range over their respective variable scopes, with universal bodies in the extended scope.

  1. Substitution stability. The pair ({T:Δ;Γ⊢s:T},C)(\{T : \Delta;\Gamma\vdash s : T\},C) is structured. Its image under every typed substitution remains structured and satisfies Lemma 5.2, including the structured result and body families needed for subsequent eliminations.

Proof sketch. Induction on typing constructs a canonical derivation and its structured typing family together. Variables and introductions use the corresponding structured-family clauses and upward closure. At application, Lemma 5.2 supplies an exposed arrow, permits subsuming the argument to its domain, and returns a structured result family.

At type application, it supplies a structured body pair (R,B)(R,B) under the actual bound AA. The bound test R< ⁣: ⁣ΔAR <\!:\!_{\Delta} A makes [R/α]:(Δ,α< ⁣: ⁣A)→Δ[R/\alpha] : (\Delta,\alpha<\!:\! A) \to\Delta typed. The complete result family is

{T:Δ;Γ⊢f{R}:T}=↑ΔR[R/α],\{T : \Delta;\Gamma\vdash f\{R\} : T\} = \uparrow_{\Delta} R[R/\alpha],

structured with member B[R/α]B[R/\alpha] by typed image and closure replacement. This preserves the invariant when the result is eliminated again. Induction on canonical derivations gives assignability and uniqueness; Lemma A.1 gives the detailed typing induction. Finally, apply Lemma 5.2 with identity substitution to the upward-closed typing family. Its exposed heads give shape completeness, and reflexivity at AA gives the two rectangularity equations with the same VV.

The same VV occurs on both sides of each equation: possible domains are exactly the types below AA, independently of the possible results. This is the rectangularity of the complete typing family. An arbitrary finite family of arrows can still correlate domains and results.

For an example of successive eliminations, let i=Λα<:⊤.λx:α.xi = \Lambda\alpha<: \top.\lambda x:\alpha.x, R=⊤→⊤R = \top\to\top, and u=λz:⊤.zu = \lambda z:\top.z. The canonical rules give

∅;∅⊢ci{R}⇒R→R,\varnothing;\varnothing\vdash_{\mathrm{c}} i\{R\} \Rightarrow R \to R,
∅;∅⊢ci{R} u⇒R.\varnothing;\varnothing\vdash_{\mathrm{c}} i\{R\}\,u \Rightarrow R.

The result can now be applied to Top. Before substitution, the corresponding result type was the variable α\alpha; its arrow head comes from RR. Typed images and structured result families allow the same shape and domain properties to justify this next elimination.

Corollary 5.4 (Canonical elimination equations). With AA the exposed canonical domain or bound, respectively,

Δ;Γ⊢f u:T⟺Δ;Γ⊢u:A∧Δ;Γ⊢f:A→T,(13)\Delta;\Gamma\vdash f\,u:T \Longleftrightarrow\Delta;\Gamma\vdash u:A \land\Delta;\Gamma\vdash f:A \to T, \tag*{(13)}
Δ;Γ⊢f{R}:T⟺R<ΔA∧∃V. Δ;Γ⊢f:∀α<:A.V∧V[R/α]<ΔT.(14)\Delta;\Gamma\vdash f\{R\}:T \Longleftrightarrow R <_{\Delta} A \land\exists V.\ \Delta;\Gamma\vdash f:\forall\alpha<: A.V \land V[R/\alpha] <_{\Delta} T. \tag*{(14)}

Proof. Inversion supplies f:U→Vf:U \to V, u:Uu:U, and V<:TV <: T. By (11), U<:AU <: A and f:A→Vf:A \to V, hence u:Au:A and f:A→Tf:A \to T. Type application uses (12) with the same body VV. Both converses follow by elimination and subsumption.

Finite inverse substitution

Equation (13) determines the next target for ff. Equation (14) still quantifies over an unknown VV, constrained by its substituted form V[R/α]V[R/\alpha]. We need a finite description of acceptable bodies before that substitution. Subsequent checking steps must be able to transform this whole description again.

Consider a type application of Ghelli’s example. Fix Δ=(β<:⊤)\Delta= (\beta<: \top) and an empty term context, and write

f=Λγ<:β.Λα<:γ.λx:α.x,s=f{β},T=∀α<:β.α→β.(15)f = \Lambda\gamma<: \beta.\Lambda\alpha<: \gamma.\lambda x:\alpha.x,\quad s = f\{\beta\},\quad T = \forall\alpha<: \beta.\alpha\to\beta. \tag*{(15)}

The reduct of ss is the term from § 2.2. Its canonical type is ∀α<:β.α→α\forall\alpha<: \beta.\alpha\to\alpha, which is not below TT. One body target before substitution is

W=∀α<:γ.α→γ,W[β/γ]=T.(16)W = \forall\alpha<: \gamma.\alpha\to\gamma,\quad W[\beta/\gamma] = T. \tag*{(16)}

Assigning ∀γ<:β.W\forall\gamma<: \beta.W to ff suffices to check ss at TT. The inverse construction computes a finite family covering all acceptable bodies, including this choice. § 5.4 follows it through the complete check.

For the general construction, fix well-formed contexts Δ,Θ\Delta,\Theta, a typed substitution σ:Δ→Θ\sigma:\Delta\to\Theta, and a target TT well formed in Θ\Theta. We seek finite families L(T)\mathcal{L}(T) and I+(T)\mathcal{I}^{+}(T) and I−(T)\mathcal{I}^{-}(T) in the context Δ\Delta. Writing L(F)\mathcal{L}(F) for the set of types represented by a family FF, their specifications are, for every BB well formed in Δ\Delta,

B[σ]<ΘT⟺∃V∈L(Iσ−(T)). B<ΔV,(17)B[\sigma] <_{\Theta} T \Longleftrightarrow\exists V \in\mathcal{L}(\mathcal{I}^{-}_{\sigma}(T)).\ B <_{\Delta} V, \tag*{(17)}
T<ΘB[σ]⟺∃V∈L(Iσ+(T)). V<ΔB.(18)T <_{\Theta} B[\sigma] \Longleftrightarrow\exists V \in\mathcal{L}(\mathcal{I}^{+}_{\sigma}(T)).\ V <_{\Delta} B. \tag*{(18)}

The lower family generates exactly the source types whose substituted forms lie below TT. An acceptable body may be any subtype of a retained representative. The upper family has the dual specification and is needed when recursion enters a contravariant domain.

To propagate several acceptable targets and share their constructor structure, we represent finite families by the grammar

F,G::=∅∣{A}∣F∪G∣Arr(F,G)∣All(F,G).F,G ::= \varnothing\mid\{A\} \mid F \cup G \mid\mathrm{Arr}(F,G) \mid\mathrm{All}(F,G).

The denotation L\mathcal{L} respects empty families, singletons and choice: L(∅)=∅\mathcal{L}(\varnothing) = \varnothing, L({A})={A}\mathcal{L}(\{A\}) = \{A\}, and L(F∪G)=L(F)∪L(G)\mathcal{L}(F \cup G) = \mathcal{L}(F) \cup\mathcal{L}(G). The arrow constructor takes two families in Δ\Delta and returns a family in Δ\Delta. The universal constructor takes a domain family in Δ\Delta and a body family in the extended variable scope, returning a family in Δ\Delta. Choose a fresh α\alpha bound in the body family GG but not in FF. These scope requirements concern variable declarations only. The product denotations are

L(Arr(F,G))={A→B:A∈L(F), B∈L(G)},\mathcal{L}(\mathrm{Arr}(F,G)) = \{A \to B : A \in\mathcal{L}(F),\ B \in\mathcal{L}(G)\},
L(All(F,G))={∀α<:A. B:A∈L(F), B∈L(G)}.\mathcal{L}(\mathrm{All}(F,G)) = \{\forall\alpha<: A.\ B : A \in\mathcal{L}(F),\ B \in\mathcal{L}(G)\}.

A finite set written as a family abbreviates a choice of singletons. In a family argument position, a type TT stands for {T}\{T\}. Membership in a family means membership in its denotation. Choices retain their own children. Replacing {A→B,C→D}\{A \to B, C \to D\} by Arr({A,C},{B,D})\mathrm{Arr}(\{A,C\}, \{B,D\}) can introduce the additional types A→DA \to D and C→BC \to B. A product permits independent choices on its two sides, including when the same family occurs in both positions.

For fixed well-formed Δ;Γ\Delta; \Gamma, the backward judgment checks a term ss against a finite target representation FF in Δ\Delta. It holds when some represented target is assignable to the term:

Δ;Γ⊢bws⇐F⟺∃T∈L(F). Δ;Γ⊢s:T.(19)\Delta; \Gamma\vdash_{\mathrm{bw}} s \Leftarrow F \Longleftrightarrow\exists T \in\mathcal{L}(F).\ \Delta; \Gamma\vdash s : T. \tag*{(19)}

Here FF describes acceptable targets; BΔ;Γ(s)\mathcal{B}_{\Delta;\Gamma}(s) summarizes all assignable types. The initial query has F={T}F = \{T\}. Later queries may contain several alternatives even though the original request has only one target.

The signed subtype predicates take a finite family FF and a type QQ, both in the displayed comparison context Θ\Theta, and express existence of a subtype or supertype witness:

EΘ+(F,Q)⟺∃A∈L(F). A<:ΘQ,EΘ−(F,Q)⟺∃A∈L(F). Q<:ΘA.E_{\Theta}^{+}(F,Q) \Longleftrightarrow\exists A \in\mathcal{L}(F).\ A <:_{\Theta} Q,\qquad E_{\Theta}^{-}(F,Q) \Longleftrightarrow\exists A \in\mathcal{L}(F).\ Q <:_{\Theta} A.

The sign records which side of subtyping contains the family: the subtype for ++ and the supertype for −-. The single-target specifications extend to finite target families as follows.

Theorem 5.5 (Finite inverse families). For well-formed Δ,Θ\Delta,\Theta, a typed σ:Δ→Θ\sigma: \Delta\to\Theta, and a finite family FF well scoped in Θ\Theta, finite families Iσp(F)I_{\sigma}^{p}(F) are computable in Δ\Delta for p∈{−,+}p \in\{-,+\}. For every QQ well formed in the source context Δ\Delta,

EΔp(Iσp(F),Q)⟺EΘp(F,Q[σ]).(20)E_{\Delta}^{p}(I_{\sigma}^{p}(F),Q) \Longleftrightarrow E_{\Theta}^{p}(F,Q[\sigma]). \tag*{(20)}

Every generated representative is well scoped and substitutes below (minus) or above (plus) some member of FF.

Construction and proof. Construct both signs simultaneously by induction on the singleton target’s weight from § 3.4, ranging over source contexts and typed substitutions. A source variable α\alpha qualifies for a variable guard precisely when σ(α)<:ΘT\sigma(\alpha) <:_{\Theta} T for the lower inverse, or T<:Θσ(α)T <:_{\Theta} \sigma(\alpha) for the upper inverse. These finitely many decidable tests cover all variable candidates. For an arrow candidate and target, inversion gives

(B1→B2)[σ]<:ΘC→D⟺C<:ΘB1[σ]∧B2[σ]<:ΘD.(B_1 \to B_2)[\sigma] <:_{\Theta} C \to D \Longleftrightarrow C <:_{\Theta} B_1[\sigma] \land B_2[\sigma] <:_{\Theta} D.

Upper coverage of CC supplies aa with a<:ΔB1a <:_{\Delta} B_1. Lower coverage of DD supplies bb with B2<:ΔbB_2 <:_{\Delta} b. Their arrow a→ba \to b covers the candidate B1→B2B_1 \to B_2 from above. The corresponding equation for the reference construction is

Iσˉ(C→D)={α∈dom⁡(Δ):σ(α)<:ΘC→D}∪Arr⁡(Iσ+(C),Iσ−(D)).(21)I_{\bar{\sigma}}(C \to D) = \{\alpha\in\operatorname{dom}(\Delta) : \sigma(\alpha) <:_{\Theta} C \to D\} \cup\operatorname{Arr}(I_{\sigma}^{+}(C), I_{\sigma}^{-}(D)). \tag*{(21)}

Representative soundness gives (a→b)[σ]<:ΘC→D(a \to b)[\sigma] <:_{\Theta} C \to D. The reversed comparison exchanges the two recursive signs. Universal bodies use the lifted substitution under a binder with bound ⊤\top on both sides, independently of the chosen bound. A positive target variable follows its bound, decreasing the weight. The cases for ⊤\top follow by subtype inversion.

Soundness follows from the guards and constructor rules. Inversion gives recursive witnesses for completeness. Extend the construction to choice by union and to independent products by combining their child witnesses with the appropriate signs. An empty target family has empty inverses in both directions. In particular, a product with an empty child contributes no representatives. Subtype preservation by typed substitution and representative soundness give the reverse implications. Appendix § 12.§ 2 gives all construction equations and the simultaneous soundness and coverage induction. □

Taking σ=id⁡:Δ∘→Δ\sigma= \operatorname{id} : \Delta^{\circ} \to\Delta recovers the cone specifications (9) and (8), together with member soundness. This identity is typed because its source bounds are all ⊤\top. The syntax of a type is unchanged, but its two comparison contexts differ. The specifications coincide, without requiring identical representative lists.

The comparison bound ⊤\top. The checker needs σ=[R/α]:(Δ,α<:⊤)→Δ\sigma= [R/\alpha] : (\Delta, \alpha<: \top) \to\Delta, lifted under local binders. Combining its lower inverse with (14) gives

Δ;Γ⊢f{R}:T⟺R<:ΔA∧∃W∈L(I[R/α]−(T)). Δ;Γ⊢f:∀α<:A.W.(22)\Delta; \Gamma\vdash f\{R\} : T \Longleftrightarrow R <:_{\Delta} A \land\exists W \in\mathcal{L}(I_{[R/\alpha]}^{-}(T)).\ \Delta; \Gamma\vdash f : \forall\alpha<: A.W. \tag*{(22)}

Inverse completeness gives V<:Δ,α<:⊤WV <:_{\Delta,\alpha<:\top} W. All-Top lifts this comparison to quantified types, assigning ff the type ∀α<:A.W\forall\alpha<: A.W. Conversely, inverse soundness gives W[R/α]<:TW[R/\alpha] <: T, so Type-App followed by subsumption proves the required typing. The source bound α<:⊤\alpha<: \top is necessary for this argument: a comparison derived only under the actual bound AA would not justify the All-Top step.

Checking equations

The partial synthesis function CΔ;Γ(s)C_{\Delta;\Gamma}(s) implements the canonical rules of § 5.1. It evaluates canonical premises recursively and subtype premises by the subtyping decider. At application, it implements the declarative guard Δ;Γ⊢u:A\Delta; \Gamma\vdash u : A by the family check Δ;Γ⊢bwu⇐{A}\Delta; \Gamma\vdash_{\mathrm{bw}} u \Leftarrow\{A\} defined below. Failed lookup, ill-formed annotations or type arguments, wrong exposed heads, and failed guards reject. Theorem 5.6 proves synthesis and checking correct together.

Checking λx:A.s\lambda x : A.s against C→DC \to D requires C<:ΔAC <:_{\Delta} A and a body check at DD. For a finite target family FF, filtered projections PΔ,A→P^{\to}_{\Delta,A} and PΔ,A∀P^{\forall}_{\Delta,A} retain the complete body families of qualifying branches. These families are the targets passed to the abstraction’s body. With AA well formed in Δ\Delta, the arrow projection stays in Δ\Delta; the universal projection returns a family in Δ,α<:A\Delta,\alpha<: A, renaming target binders to the abstraction’s fresh α\alpha:

L(PΔ,A→(F))={D:∃C. C→D∈L(F)∧C<:ΔA},\mathcal{L}(P^{\to}_{\Delta,A}(F)) = \{D : \exists C.\ C \to D \in\mathcal{L}(F) \land C <:_{\Delta} A\},
L(PΔ,A∀(F))={D:∃C. ∀α<:C.D∈L(F)∧C<:ΔA}.\mathcal{L}(P^{\forall}_{\Delta,A}(F)) = \{D : \exists C.\ \forall\alpha<: C.D \in\mathcal{L}(F) \land C <:_{\Delta} A\}.

Both domain tests use the displayed outer context Δ\Delta. The projections distribute over choice and inspect singleton types. For a matching product, retain its body child exactly when the positive query on its domain child and AA succeeds. Domain and result choices therefore remain within the same branch.

Each checking call first runs canonical synthesis and rejects on failure or an empty target family. Success establishes typability, supplies elimination domains, and discharges the guards u:Au : A and R<: ⁣ΔAR <:\!_{\Delta} A. If ⊤∈L(F)\top\in L(F), accept. Otherwise use the equations below. In the final two lines, AA is the domain or bound exposed from CΔ;Γ(f)C_{\Delta;\Gamma}(f). The last line uses the inverse of (22), with source context Δ⊤\Delta_{\top}:

Δ;Γ⊢bwx⇐F⟺EΔ(F,Γ(x)),\Delta;\Gamma\vdash_{\mathrm{bw}} x \Leftarrow F \Longleftrightarrow E_{\Delta}(F,\Gamma(x)),
Δ;Γ⊢bwλx:A. s⇐F⟺Δ;Γ,x:A⊢bws⇐PΔ,A▽(F),\Delta;\Gamma\vdash_{\mathrm{bw}} \lambda x : A.\,s \Leftarrow F \Longleftrightarrow\Delta;\Gamma,x:A \vdash_{\mathrm{bw}} s \Leftarrow P^{\triangledown}_{\Delta,A}(F),
Δ;Γ⊢bwΛα<:A. s⇐F⟺ΔA;Γ⊢bws⇐PΔ,A▽(F),\Delta;\Gamma\vdash_{\mathrm{bw}} \Lambda\alpha<:A.\,s \Leftarrow F \Longleftrightarrow\Delta_A;\Gamma\vdash_{\mathrm{bw}} s \Leftarrow P^{\triangledown}_{\Delta,A}(F),
Δ;Γ⊢bwf u⇐F⟺Δ;Γ⊢bwf⇐Arr⁡({A},F),\Delta;\Gamma\vdash_{\mathrm{bw}} f\,u \Leftarrow F \Longleftrightarrow\Delta;\Gamma\vdash_{\mathrm{bw}} f \Leftarrow\operatorname{Arr}(\{A\},F),
Δ;Γ⊢bwf{R}⇐F⟺Δ;Γ⊢bwf⇐All⁡({A},I[R/α](F)).\Delta;\Gamma\vdash_{\mathrm{bw}} f\{R\} \Leftarrow F \Longleftrightarrow\Delta;\Gamma\vdash_{\mathrm{bw}} f \Leftarrow\operatorname{All}(\{A\},I_{[R/\alpha]}(F)).

The term Top⁡\operatorname{Top} is rejected when ⊤∉L(F)\top\notin L(F). The last two lines follow from the elimination and inverse equations. Appendix § 15 implements these equations by producing candidates along a whole checking spine and saving its elimination domains and scoped obligations. Discharging these obligations once supplies the canonical premises for subsequent checks on that spine, whose changing target families do not require synthesis to be repeated.

Theorem 5.6 (Backward checking correctness). Canonical synthesis and family checking terminate. For well-formed contexts, synthesis returns CC exactly when Δ;Γ⊢cs⇒C\Delta;\Gamma\vdash_{\mathrm{c}} s \Rightarrow C holds, and checking any well-scoped finite family satisfies (19). With malformed inputs rejected, the procedure accepts a raw input (Δ,Γ,s,T)(\Delta,\Gamma,s,T) exactly when Δ;Γ⊢s:T\Delta;\Gamma\vdash s:T holds. It consequently agrees with the finite-basis checker.

Proof. Use strong induction on term size, generalizing over well-formed contexts and finite target families. At each size, first prove that synthesis terminates and returns exactly the types related by ⊢c\vdash_{\mathrm{c}}; then prove termination and correctness of family checking at that size.

Synthesis recurses only on proper subterms. By the synthesis induction hypothesis, its recursive results coincide with the canonical premises. For an application f uf\,u, the checking induction hypothesis for the smaller term uu makes the test at {A}\{A\} equivalent to the declarative guard u:Au:A. Subtype decidability supplies the type-application guard; lookup, formation and exposure tests implement the remaining premises. Thus synthesis succeeds exactly when the canonical relation holds. Lemma A.1 then gives an assignable result on success and excludes every typing on failure.

Family checking at the current size uses this already established synthesis result. An empty family rejects. When ⊤∈L(F)\top\in L(F), checking succeeds exactly when synthesis does. All remaining recursive checks occur on a proper body or function child, so the checking induction hypothesis applies to their transformed target families. Projections and signed queries terminate, and finite inverse operations terminate independently by Theorem 5.5.

Variables and introductions follow inversion and branch selection. For type abstraction, restore body comparisons from Δ⊤\Delta_{\top} to ΔA\Delta_A. Conversely, a selected body type can be used in TYPE-ABS. Reflexivity in Δ\Delta and the successful domain test justify final subsumption. Equations (13) and (22) prove elimination. The wrapper rejects malformed environments and targets. Synthesis rejects invalid annotations and type arguments; typing formation excludes a derivation in each case. □\square

Only inverse exactness enters the type-application argument. Any total inverse construction satisfying that interface gives the same checking answers: each computes the target-family judgment (19). The general construction and the single-hole specialization of § 6.1 are instances of this result.

Beyond the canonical upper cone

For the query in (15), the canonical subtype test fails, but the target family has an accepting branch. The canonical bound of ff is β\beta, so its type-argument guard succeeds. The lower inverse contains the body WW of (16). The positive guard on the quantified domain and the negative guard on the arrow result both test β<:β\beta<: \beta and permit the fresh γ\gamma; the arrow domain retains α\alpha. Equations (22) and the body projections then give:

Current termSelected targetSuccessful test or choice
f{β}f\{\beta\}TTβ<:β\beta<: \beta; inverse member WW
ff∀γ<:β. W\forall\gamma<: \beta.\, Wβ<:β\beta<: \beta; retain body WW
Λα<:γ.λx:α.x\Lambda\alpha<: \gamma.\lambda x:\alpha.xWWγ<:γ\gamma<: \gamma; retain α→γ\alpha\to\gamma
λx:α.x\lambda x:\alpha.xα→γ\alpha\to\gammaα<:α\alpha<: \alpha; retain γ\gamma
xxγ\gammaΓ(x)=α\Gamma(x)=\alpha, α<:γ\alpha<: \gamma

Table 3.

The recursive checks enter the actual contexts γ<:β\gamma<: \beta and then α<:γ\alpha<: \gamma, where the last variable test succeeds. The complete inverse and body families retain their other branches.

Symbolic Implementation

The backward checker consumes finite families through signed queries, body selection and inverse substitution. The specification does not require enumerating their denotations. We specialize the inverse to the substitutions generated by type application, then share the resulting family structure and its comparison queries.

Single-hole inverse specialization

For a type-application substitution, old source variables need no separate guards: retaining the original targets already covers them.

Fix a comparison context Θ\Theta, a replacement RR well formed there, and a fresh hole α\alpha. The typed substitution [R/α]:(Θ,α<:⊤)→Θ[R/\alpha] : (\Theta,\alpha<: \top) \to\Theta maps the new source scope back to the target scope. Input families are in Θ\Theta, and inverse families are in Θ,α<:⊤\Theta,\alpha<: \top. Let ι:Θ↪Θ,α<:⊤\iota: \Theta\hookrightarrow\Theta,\alpha<: \top be the scope inclusion, fixing each old variable. For every type TT in Θ\Theta,

(T[ι])[R/α]=T.(T[\iota])[R/\alpha] = T .

Substitution therefore retracts this embedding. The recursive rules below retain every old target member in the extended scope. These copies cover the old-variable alternatives tested by the general inverse.

For example, let β\beta be an old variable and TT a member of the target family. In the lower inverse, the general construction adds β\beta when β<: ⁣ΘT\beta<:\!_{\Theta} T. Weakening preserves that comparison:

β<: ⁣ΘT⟹β<: ⁣Θ,α<:⊤T.\beta<:\!_{\Theta} T \quad\Longrightarrow\quad\beta<:\!_{\Theta,\alpha<:\top} T .

The retained TT covers β\beta and, by transitivity, every source type below β\beta. Omitting the separate β\beta alternative therefore preserves all lower-inverse queries. Dually, if T<: ⁣ΘβT <:\!_{\Theta} \beta, the retained TT lies below β\beta and covers its upper-inverse alternative. For the fresh hole α\alpha, substitution instead produces RR, so its eligibility is decided by comparing RR with the target family.

Write Ip(F)I^p(F) for the specialized inverse below. It has the coverage specification of I[R/α]p(F)I^p_{[R/\alpha]}(F), but need not return the same representatives. For a family FF in the fixed target context Θ\Theta, the fresh-hole guard returns either the singleton {α}\{\alpha\} or the empty family in the extended source scope:

JP(F)={{α},EΘP(F,R),∅,otherwise.J^{P}(F)= \begin{cases} \{\alpha\}, & E^{P}_{\Theta}(F,R),\\ \varnothing, & \text{otherwise.} \end{cases}

With this scope convention, the pruned rules are

I−(∅)=I+(∅)=∅,I−(⊤)={⊤},I−(β)={β}∪J−({β}),I−(Arr⁡(F,G))=Arr⁡(I+(F),I−(G))∪J−(Arr⁡(F,G)),I+(⊤)={⊤}∪J+({⊤}),I+(β)={β}∪J+({β})∪I+(Θ(β)),I+(Arr⁡(F,G))=Arr⁡(I−(F),I+(G))∪J+(Arr⁡(F,G)).\begin{aligned} I^{-}(\varnothing)&=I^{+}(\varnothing)=\varnothing,\\ I^{-}(\top)&=\{\top\},\\ I^{-}(\beta)&=\{\beta\}\cup J^{-}(\{\beta\}),\\ I^{-}(\operatorname{Arr}(F,G))&=\operatorname{Arr}(I^{+}(F),I^{-}(G))\cup J^{-}(\operatorname{Arr}(F,G)),\\ I^{+}(\top)&=\{\top\}\cup J^{+}(\{\top\}),\\ I^{+}(\beta)&=\{\beta\}\cup J^{+}(\{\beta\})\cup I^{+}(\Theta(\beta)),\\ I^{+}(\operatorname{Arr}(F,G))&=\operatorname{Arr}(I^{-}(F),I^{+}(G))\cup J^{+}(\operatorname{Arr}(F,G)). \end{aligned}

Both operations distribute over choice. Universals have the same variance, with lifted substitution and a body context with bound ⊤\top. Under local binders chosen fresh for RR, the lifted substitution fixes their variables and all old variables, and maps the hole α\alpha to RR viewed in the extended scope. Empty products are removed. An inhabited positive structural branch already covers ⊤\top.

Induction over the construction shows that every old target member is retained in the extended scope. Retraction makes each such member sound after substitution. The old-variable argument above, the fresh-hole tests and constructor inversion establish the inverse specifications.

Sharing family structure

A family expression can be stored as an acyclic graph, with repeated child expressions sharing a node. For the specialized inverse above, take R=⊤→⊤R=\top\to\top:

I−(R→R)=Arr⁡({R,α},{R,α}).I^{-}(R\to R)=\operatorname{Arr}(\{R,\alpha\},\{R,\alpha\}).

The two occurrences of {R,α}\{R,\alpha\} share one child node while allowing independent choices, so the graph represents all four arrows. Choice nodes retain their own children, preserving the branch correlations of § 5.2.

Signed queries can use that structure directly. For an arrow target, subtype inversion separates the two component tests:

EΘ+(Arr⁡(F,G),C→D)⟺EΘ−(F,C)∧EΘ+(G,D),EΘ−(Arr⁡(F,G),C→D)⟺EΘ+(F,C)∧EΘ−(G,D).\begin{aligned} E^{+}_{\Theta}(\operatorname{Arr}(F,G),C\to D)&\Longleftrightarrow E^{-}_{\Theta}(F,C)\land E^{+}_{\Theta}(G,D),\\ E^{-}_{\Theta}(\operatorname{Arr}(F,G),C\to D)&\Longleftrightarrow E^{+}_{\Theta}(F,C)\land E^{-}_{\Theta}(G,D). \end{aligned}

Each conjunction chooses witnesses from the two children of the same product. A choice node uses disjunction over its branches. Nonemptiness is also structural: a product needs both children, a choice needs one, and a singleton is inhabited. The test ⊤∈L(F)\top\in L(F) inspects singleton and choice roots; constructor products contribute no ⊤\top member. These operations supply the empty-product and ⊤\top-membership tests without materializing the represented types.

The single-hole inverse creates transformed constructor nodes and guarded hole alternatives. Reusing a transformed child avoids repeating the same inverse calculation. Appendix § 13.§ 2 exhibits a generator family with double-exponential cardinality and a linear shared representation. Its members form an antichain, so dominance pruning retains them all while sharing avoids their enumeration.

Queries depend on the comparison context

A query EΘP(F,Q)E^{P}_{\Theta}(F,Q) depends on the live family graph and ordered bound assignments, together called a snapshot. Replacing a variable’s bound ⊤\top by its actual bound may change the answer. Inverse substitution imports copies of variable bounds and their constructor components at successive checking steps. A group fixes the scoped source type, captured variable identities, scope cursor and query direction. The cursor identifies a scope prefix; birth slots remain fixed on retirement. Within one fixed snapshot and at a fixed endpoint, successes on live slots form a prefix: older matching copies retain the alternatives of later ones. A cutoff records the first failure or an all-success marker.

Inverse guards are evaluated in the old snapshot before insertion mutates the graph. Insertion and bound activation discard the prototypes’ snapshot-local comparison tables. Ordinary comparisons between variable-free types remain valid across snapshots. Body selection retains its child family and retires unneeded material without renumbering births.

For example, two inverse steps with replacement R=⊤→⊤R = \top\to\top and successive fresh holes α,γ\alpha,\gamma with bound ⊤\top can give an earlier copy F0={R,α,γ}F_0 = \{R,\alpha,\gamma\} and a later copy F1={R,γ}F_1 = \{R,\gamma\}. The negative query at endpoint α\alpha succeeds for F0F_0 and fails for F1F_1, so the cutoff is one. Theorem 5.6 uses the exact signed-query interface independently of this cache representation.

The evaluated variants differ in storage allocation. Dense initializes scope-local comparison tables; shared allocates entries on demand and also shares ordinary comparisons between variable-free types across scopes. Both store the canonical domains attached to application targets as family nodes.

Mechanization and Evaluation

Mechanization

The finite-family and backward checkers are terminating Rocq functions, proved equivalent to the original typing judgments, including rejection of malformed inputs. The backward checker is verified with both the general inverse of § 5.2 and the single-hole specialization of § 6.1. Both satisfy the exact-inverse interface, although they may produce different representatives. We reuse the type syntax and substitution lemmas from the POPLmark [1] example distributed with Autosubst [22]. Autosubst uses functional extensionality.

An independent, axiom-free Rocq development verifies the execution model in Appendix § 15 on parsed inputs: totality, unique answers and charged work, equivalence to the original typing judgment, and a quartic work bound. Decoding and the concrete representation of numeric fields are analyzed on paper. The measured OCaml prototypes are independent implementations; the cost certificate applies to the specified model.

LLM Assistance. All mathematical arguments and proof strategies were developed by the authors. In the Rocq formalization, we used OpenAI Codex solely to assist with completing proof scripts for selected lemmas. Rocq mechanically checked the resulting proofs, and the authors reviewed the formalized statements.

Prototype evaluation

We examine the distribution of symbolic family sizes and comparison storage across complete checking judgments. Studies of Union–Find-based inference likewise examine representation growth and query structure [19, 20].

Three native OCaml checkers use machine integers and shared type nodes. The finite-family reference synthesizes a correlated symbolic family and compares it with the target. The dense and shared backward prototypes use the same scoped-cutoff procedure from § 6, with the storage policies described there. The separate cost realization also uses producer-lineage transport and persistent storage, which these prototypes do not implement.

Workloads and protocol. The fixed synthetic corpus combines call, composition and callback templates, witness-carrying typed random generation, and stress families varying spine, bound-chain and type depth. A nonminimum typing family exercises introductions, dependent instantiations and mixed redexes. Scales are k=2,4,8,16,32k = 2, 4, 8, 16, 32. After target deduplication, 130 programs give 582 distinct judgments: 294 accepted and 288 rejected. These include 16 accepted targets outside the canonical upper cone and 129 rejections preserving the exposed constructor. All generated programs are typable; rejected judgments test target incompatibility. The reference assigns labels; an extracted certified Rocq checker agrees on 231 judgments at scales two and four.

Input size nn counts the complete tuple (Δ,Γ,s,T)(\Delta, \Gamma, s, T) in a tree encoding, including repeated occurrences despite implementation sharing. The corpus spans 40–1805 bits. Each complete query starts with empty caches. Family-node counts cover all symbolic family nodes created during the check, including those later retired. All 12222 uninstrumented checks and 1746 separate counter runs complete and agree with the labels. Appendix § 14 gives the encoding, generators, separate regression checks, protocol and full results.

Structural cost distribution. In Figure 6(a), templates occupy an increasing band, typed-random queries mostly use small families, and stress includes both small representations and the largest families. At 149 input bits, family counts range from 3 to 64. Both backward variants intern identical counts on all 582 judgments, with a maximum of 1250.

Figure 6. Structural cost across all 582 distinct judgments. (a) Shared backward’s interned family nodes against complete encoded input size; dense has identical family counts on all judgments. (b) Paired dense/shared comparison entries; the dotted line denotes equality. Each point is one judgment, colored by workload family. Count axes retain zeros. Filled/hollow markers denote accepted/rejected targets.

Storage and runtime. Shared uses fewer entries on 260 judgments; the remaining 322 allocate none in either variant (Figure 6(b)). Dense counts include unused initialized cells; shared counts include scoped and variable-free entries.

On the depth-32 staircase witness, both variants intern 1,250 family nodes, while sharing reduces comparison entries from 28,569 to 2,081. Median CPU time rises from 10.5 to 11.9 ms and allocation volume from 10.2 to 11.4 MB. The reference has a lower CPU median than shared on 530 of 582 queries. For the depth-32 dependent-instantiation program, the median of its five query medians is 119.2 ms for reference and 1.5 ms for shared.

Appendix C reports comparison entries by input size and further measurements for the same prototypes.

Consequences and Scope

The inverse theorem applies to any fixed typed substitution. Identity between different comparison contexts gives bound forgetting (§ 5.2); weakening gives a second application, finite type avoidance. Its use in another calculus requires that calculus’s own coverage and typing arguments.

Finite type avoidance

The inverse construction also computes types expressible after a local name leaves scope, an avoidance problem studied for bounded existentials [15] and module signatures [8]. Let BB be well scoped in ΔA\Delta_A, and write ι:Δ↪ΔA\iota: \Delta\hookrightarrow\Delta_A for the scope inclusion.

Corollary 8.1 (Effective finite type avoidance). For well-formed Δ\Delta, AA and BB well scoped in ΔA\Delta_A, one can compute finite families F,GF,G in Δ\Delta such that every well-scoped TT in Δ\Delta satisfies

B< ⁣: ⁣ΔAT⟺∃V∈L(F). V< ⁣: ⁣ΔT,(23)B <\!:\!_{\Delta_A} T \Longleftrightarrow\exists V \in\mathcal{L}(F).\ V <\!:\!_{\Delta} T, \tag*{(23)}
T< ⁣: ⁣ΔAB⟺∃V∈L(G). T< ⁣: ⁣ΔV.(24)T <\!:\!_{\Delta_A} B \Longleftrightarrow\exists V \in\mathcal{L}(G).\ T <\!:\!_{\Delta} V. \tag*{(24)}

Proof. Weakening preserves the old variable-bound comparisons, so ι\iota is typed. Take F=Iι+(B)F = I_{\iota}^{+}(B) and G=Iι−(B)G = I_{\iota}^{-}(B) in Theorem 5.5. □

All representatives avoid the local variable because they are well scoped in Δ\Delta. Equation (23) covers every outer type that can serve as a supertype of BB, without assuming a single best choice. The lower family may be empty.

For example, take Δ=β< ⁣:⊤\Delta= \beta<\!: \top, A=βA = \beta, and B=αB = \alpha. An exact upper cover is F={β}F = \{\beta\}: every outer supertype of α\alpha is reachable through its bound β\beta. An exact lower cover is empty, since no type in the outer scope is below the fresh variable α\alpha.

This corollary concerns subtype comparisons in F≤F_{\leq}. A language with local abstract types would need a typing rule that uses these families.

Generalization requirements

To transfer the decidability method to another calculus, one must establish decidable subtyping on well-formed inputs, effective finite covers for its context changes, and complete compositional operations for its term rules. Transferring the backward algorithm requires a complete elimination interface and finite inverse families for its substitutions. Runtime bounds require a separate analysis of the chosen realization. Finite coverage alone imposes no polynomial size bound.

All-Top makes the body comparison context independent of candidate bounds. We use this independence in both cone construction and the inverse substitution step at type application. These properties must be reconsidered when the quantified subtype rule changes.

Implicit instantiation introduces a further quantifier: the substitution itself must be chosen. Greedy implicit bounded quantification provides a decidable approach for a variant of kernel F≤F_{\leq} [9]. Our inverse theorem concerns each fixed typed substitution. Taking the union of its solution sets over infinitely many possible substitutions need not preserve finite generation. Extending the method to implicit instantiation therefore requires a finite representation of those choices and a complete procedure for querying it.

Related Work

Bounded quantification

Bounded quantification combines parametric polymorphism and subtyping in Fun [5] and System F<:F_{<:} [4]. Pierce proves undecidability of full subtyping and typechecking [21]. Curien and Ghelli [10] establish minimum typing and a deterministic checking procedure through normalization of typing derivations. Deterministic rule selection does not imply that its subtyping calls terminate. In F<:TF^{\mathsf{T}}_{<:}, subtype checking terminates, but minimum typing fails [6, 7].

The corrigendum proposes finite minimal-type families as a possible route to checking. Our finite construction maintains coverage through bound forgetting.

Laird’s extended system recovers minimum typing using two quantifiers [18]. Typechecking of F<:TF^{\mathsf{T}}_{<:} inputs in that extension is decidable (Proposition 8.5). Agreement on normal terms (Proposition 7.3) gives decidability for the original normal fragment (Corollary 8.6). Proposition 7.1 separates the original and extended judgments on arbitrary terms.

Checking a normal form can accept a target that the original term lacks, as Laird’s counterexample shows. Take Δ=β<:⊤\Delta= \beta<: \top, an empty term context, and T=∀α<:β. α→βT = \forall\alpha<: \beta.\ \alpha\to\beta. The type-β\beta redex

r=(Λγ<:⊤. Λα<:β. λx:γ. x){β}⟶βr′,r = (\Lambda\gamma<: \top.\ \Lambda\alpha<: \beta.\ \lambda x : \gamma.\ x)\{\beta\} \longrightarrow_{\beta} r',
r′=Λα<:β. λx:β. xr' = \Lambda\alpha<: \beta.\ \lambda x : \beta.\ x

satisfies

Δ;∅⊢r′:T,Δ;∅⊬r:Tin F<:T.\Delta; \varnothing\vdash r' : T,\qquad\Delta; \varnothing\not\vdash r : T \qquad\text{in } F^{\mathsf{T}}_{<:}.

The positive judgment uses α<:β\alpha<: \beta inside r′r' to assign α→β\alpha\to\beta to λx:β. x\lambda x : \beta.\ x before type abstraction. The negative judgment is Laird’s separating example. This failure of subject expansion prevents direct reuse of the normal-form checker. Our algorithms decide the original judgment on the unreduced input.

Barthe and Frade use finite minimal-type families for constructor subtyping, where finiteness comes from a constructor’s finite declarations [2 Section 4, Proposition 4]. In our construction, representatives must cover the effects of bounds that body typing can use but quantified subtyping discards. The generic finite-family checking pattern is prior work. We establish effective completeness across the change of comparison context.

Kernel F<:F_{<:} compares universal types with equal bounds [5, 18]. Strong Kernel F<:F_{<:} uses two contexts that retain the compared types’ respective bounds. Hu and Lhoták establish decidable subtyping for it [16 Section 7]. Zhou et al. combine bounded quantification with iso-recursive types, with decidable subtyping in their kernel variant and undecidable subtyping in their full variant [23]. These choices change the subtype relation. Our theorems concern the single-context All-Top\mathsf{All\text{-}Top} rule, which our checking procedures retain.

Target propagation and compact representations

Bidirectional typing organizes synthesis and checking around the available type information [12]. The backward equations use this organization. Completeness in our calculus needs the uniform elimination domains of Corollary 5.4 and finite inverse substitution. In particular, checking an argument against a canonical domain cannot be replaced by comparing its canonical type with that domain.

MLsub combines ML-style inference and subtyping using a polar separation and compact principal types, with simplification related to regular-language algebra [11]. Our signed families also preserve variance and shared structure. Their meaning is a finite collection of ordinary F<:TF^{\mathsf{T}}_{<:} types, and checking queries that collection under changing scoped bounds. Their use requires the exact inverse-coverage theorem of § 5.2. A small representation alone does not establish that property for a different type algebra.

Ghelli and Pierce [15] address avoidance in Kernel Fun with bounded existentials by computing a least variable-free supertype and, when one exists, a greatest variable-free subtype. Module calculi also address avoidance through existential signatures [8] or ZipML’s floating fields, represented by zippers [3]. Our Corollary 8.1 instead gives finite covers of the outer-scope supertypes and subtypes already expressible in F≺⊤F_{\prec}^{\top}.

Conclusion

Finite covers under bound forgetting make typing bases compositional for F≺⊤F_{\prec}^{\top} and establish decidability for arbitrary original terms. Backward checking uses rectangularity to fix elimination domains while preserving every result type. Finite inverse substitution then transports acceptable targets through type application. Both procedures are proved equivalent to the original typing judgment in Rocq.

The inverse specification unifies bound forgetting and finite type avoidance. Its exactness also permits different symbolic implementations. Our experiments measure symbolic family sizes across synthetic checking judgments and show how sharing reduces comparison entries.

Future work

Local abstract types. The closest extension is a calculus with explicitly annotated bounded packages, where unpacking introduces a hidden type name that must not escape in the result type. Bounded existentials already expose this avoidance problem [15]. Corollary 8.1 suggests a compositional rule: replace each member of the body’s typing basis by its finite family of outer-scope supertypes, then take their union. This would cover every exportable result type without requiring a least avoiding type. A conservative first language would keep package signatures separate from the current grammar of ordinary types. Its new proof obligations are package typing, substitution, and completeness of the scope-exit rule. First-class existential types would additionally require new subtyping and inverse-coverage cases. Extending the approach to ML signatures [3, 8] would also require coverage results for paths and sharing constraints.

Type schemes and correlated alternatives. Union and intersection types test both our finite-basis representation and our rectangularity invariant. In a system with intersection introduction, a nonempty finite sound complete basis would itself yield a minimum type: the intersection of its members is assignable and lies below every assignable type. Systems that still lack minima therefore need a richer representation. Semantic subtyping provides such a precedent: type schemes support decidable checking despite the failure of minimum typing [14 Sections 5.4 and 6.12]. For backward checking, an overloaded type such as (A→B)∧(C→D)(A \to B) \land(C \to D) also ties different results to different domains; one uniform domain need not preserve all results. The finite arrow decomposition of Frisch et al. [14 Lemma 6.37] can be distributed into a finite union of rectangles, providing a candidate replacement invariant. The next question is whether symbolic schemes with these correlations admit exact inverse queries under scoped substitutions. An explicitly annotated, nonrecursive fragment would let us study closure and termination before adding bounded quantification.

Implicit bounded instantiation. Greedy implicit bounded quantification [9] and higher-rank checking with unions and intersections [17] offer concrete calculi with carefully restricted instantiation rules. Our inverse theorem handles a fixed substitution. Even for one candidate quantified type ∀α<:A.B\forall\alpha<: A.B, implicit instantiation must find an RR satisfying both R<:AR <: A and B[R/α]<:ΔTB[R/\alpha] <:_\Delta T. A complete solver must preserve both the alternatives for BB and shared choices for RR.

References

Supporting Proofs for Typechecking

Proofs of the canonical elimination interface

Definition 5.1 and Lemma 5.2 state the structured-family invariant used by Corollary 5.3. We give its full proof and the typing induction establishing the invariant for canonical types.

Typed substitutions. For σ:Δ→Θ\sigma: \Delta\to\Theta, the lift under a fresh binder α\alpha has source Δ,α<:A\Delta, \alpha<: A and target Θ,α<:A[σ]\Theta, \alpha<: A[\sigma]. Subtype preservation follows by induction on the derivation: the bound condition handles variables, and lifted substitutions handle the fresh variable with bound ⊤\top in All-Top.

Universal body closure. For (S,B)(S, B) structured in ΔA\Delta_A, reflexivity and bound restoration give S⊆↑Δ⊤S⊆↑ΔASS \subseteq\uparrow_{\Delta_\top} S \subseteq\uparrow_{\Delta_A} S; transitivity then proves (10). Since B∈SB \in S, closure replacement makes (↑Δ⊤S,B)(\uparrow_{\Delta_\top} S, B) structured under the actual bound. The same argument applies after substitution, with actual bound A[σ]A[\sigma].

Proof of Lemma 5.2. Induct on the structured-family clauses, quantifying over every target context Θ\Theta and typed σ\sigma. For a singleton, exposure and subtype inversion give the equivalences. The result family is the upper cone of the exposed body, using Θ\Theta for arrows and Θ,α<:⊤\Theta, \alpha<: \top for universals. These families are structured by the singleton and closure-replacement clauses, with (10) handling the universal case.

For an arrow family, substitution preserves its fixed domain and maps the body family independently. Arrow inversion gives the result family as the upward closure of that image, which is structured by the typed-image and closure-replacement clauses. For a universal family, lift σ\sigma under its actual bound AA. The image body family is structured in Θ,α<:A[σ]\Theta, \alpha<: A[\sigma]. All-Top separates the candidate bound from the upward closure of this family in Θ,α<:⊤\Theta, \alpha<: \top. (10) makes that closure structured under the actual bound, with the substituted body as distinguished member. Constructor inversion also rules out the other exposed head in each case.

For closure replacement, every member of either source family lies above a member of the other. Subtype preservation transports these witnesses through σ\sigma, so the images have equal upward closures as well. The induction hypothesis transfers the factorization and exposed heads. For a typed image, apply it to the composite typed substitution. □

Lemma A.1 (Canonical typing families). A term ss in well-formed contexts is typable exactly when there is a CC such that Δ;Γ⊢cs⇒C\Delta; \Gamma\vdash_{\mathrm{c}} s \Rightarrow C. This CC is unique and assignable, and the pair

({T:Δ;Γ⊢s:T},C)(\{T : \Delta; \Gamma\vdash s : T\}, C)

is structured in Δ\Delta.

Proof. First, induction on a canonical derivation proves assignability. Exposure soundness types the function at its exposed type, and the declarative argument guard justifies application. The other cases follow their typing rules, with subsumption after exposure at type application.

For the converse, induct on a typing derivation, constructing both a canonical derivation and the structured pair. Variables and the constant use singletons followed by upward closure; introductions wrap the body family with the annotated constructor and take upward closure for subsumption.

At application, the derivation supplies f:U→Vf : U \to V and u:Uu : U. Apply Lemma 5.2 with identity substitution to the function family structured by induction. It gives an exposed arrow A0→B0A_0 \to B_0, a structured result family (R,B0)(\mathcal{R}, B_0), and U<:A0U <: A_0, so subsumption gives u:A0u : A_0. Together with the canonical derivation for ff, this is precisely the application rule’s declarative guard and gives Δ;Γ⊢cf u⇒B0\Delta; \Gamma\vdash_{\mathrm{c}} f\,u \Rightarrow B_0. Each V∈RV \in\mathcal{R} is a result of ff at domain A0A_0; inversion places every application typing above such a VV. Hence the complete typing family is ↑ΔR\uparrow_\Delta\mathcal{R}, structured with member B0B_0 by closure replacement.

At type application, the same lemma gives an exposed universal ∀α<:A0.B0\forall\alpha<: A_0. B_0. Factorization and the derivation’s bound test give R<:A0R <: A_0, satisfying the canonical type-argument guard and deriving Δ;Γ⊢cf{R}⇒B0[R/α]\Delta; \Gamma\vdash_c f\{R\} \Rightarrow B_0[R/\alpha]. The body family (R,B0)(\mathcal{R}, B_0) is structured in Δ,α<:A0\Delta, \alpha<: A_0, so [R/α]:(Δ,α<:A0)→Δ[R/\alpha] : (\Delta, \alpha<: A_0) \to\Delta is typed. Each V∈RV \in\mathcal{R} yields V[R/α]V[R/\alpha] by Type-App at A0A_0; factorization retains the same VV from any type-application derivation. Thus inversion and subsumption give the complete result family ↑ΔR[R/α]\uparrow_{\Delta}\mathcal{R}[R/\alpha], structured with member B0[R/α]B_0[R/\alpha] by typed image and closure replacement. A final subsumption preserves the canonical derivation and leaves the complete typing family unchanged.

Induction on canonical derivations gives uniqueness: lookup fixes variable types, introductions wrap the unique canonical body type, and eliminations use the unique canonical function type and deterministic exposure. Consequently the structured pair constructed from any typing derivation has the same distinguished CC as every canonical derivation. □

Construction of general inverse families

Fix a typed σ:Δ→Θ\sigma: \Delta\to\Theta between well-formed contexts. For a family FF well scoped in Θ\Theta, define the source-variable guards

vars⁡σp(F)={α∈dom⁡(Δ):EΘp(F,σ(α))}.\operatorname{vars}^{p}_{\sigma}(F) = \{\alpha\in\operatorname{dom}(\Delta) : E^{p}_{\Theta}(F, \sigma(\alpha))\}.

The guards are decidable by finite-family queries and subtype decidability.

Singleton targets. Construct both signs together. The cases for ⊤\top and variables are

Iσ−(⊤)={⊤},I^{-}_{\sigma}(\top) = \{\top\},
Iσ+(⊤)={⊤}∪vars⁡σ+(⊤),I^{+}_{\sigma}(\top) = \{\top\} \cup\operatorname{vars}^{+}_{\sigma}(\top),
Iσ−(β)=vars⁡σ−(β),I^{-}_{\sigma}(\beta) = \operatorname{vars}^{-}_{\sigma}(\beta),
Iσ+(β)=vars⁡σ+(β)∪Iσ+(Θ(β)).I^{+}_{\sigma}(\beta) = \operatorname{vars}^{+}_{\sigma}(\beta) \cup I^{+}_{\sigma}(\Theta(\beta)).

For arrows, reverse the sign at the domain:

Iσ−(A→B)=vars⁡σ−(A→B)∪Arr⁡(Iσ+(A),Iσ−(B)),I^{-}_{\sigma}(A \to B) = \operatorname{vars}^{-}_{\sigma}(A \to B) \cup\operatorname{Arr}(I^{+}_{\sigma}(A), I^{-}_{\sigma}(B)),
Iσ+(A→B)={⊤}∪vars⁡σ+(A→B)∪Arr⁡(Iσ−(A),Iσ+(B)).I^{+}_{\sigma}(A \to B) = \{\top\} \cup\operatorname{vars}^{+}_{\sigma}(A \to B) \cup\operatorname{Arr}(I^{-}_{\sigma}(A), I^{+}_{\sigma}(B)).

For a universal target, choose its binder α\alpha fresh for both contexts and the images of σ\sigma. Write up⁡(σ)\operatorname{up}(\sigma) for the typed lift

up⁡(σ):(Δ,α<:⊤)⟶(Θ,α<:⊤),\operatorname{up}(\sigma) : (\Delta, \alpha<: \top) \longrightarrow(\Theta, \alpha<: \top),

which fixes α\alpha and applies σ\sigma to old variables. The equations are

Iσ−(∀α<:A.B)=vars⁡σ−(∀α<:A.B)∪All⁡(Iσ−(A),Iup⁡(σ)−(B)),\begin{aligned} I^{-}_{\sigma}(\forall\alpha<: A. B) &= \operatorname{vars}^{-}_{\sigma}(\forall\alpha<: A. B) \\ &\quad\cup\operatorname{All}(I^{-}_{\sigma}(A), I^{-}_{\operatorname{up}(\sigma)}(B)), \end{aligned}
Iσ+(∀α<:A.B)={⊤}∪vars⁡σ+(∀α<:A.B)∪All⁡(Iσ+(A),Iup⁡(σ)+(B)).\begin{aligned} I^{+}_{\sigma}(\forall\alpha<: A. B) &= \{\top\} \cup\operatorname{vars}^{+}_{\sigma}(\forall\alpha<: A. B) \\ &\quad\cup\operatorname{All}(I^{+}_{\sigma}(A), I^{+}_{\operatorname{up}(\sigma)}(B)). \end{aligned}

The universal products bind the same fresh α\alpha in their body child. Formation depends on variable scope, so a body formed with bound ⊤\top is also formed under any generated bound.

Singleton recursion decreases wΘ(T)w_{\Theta}(T) (see § 3.4): following a variable bound or a constructor child decreases weight, with an extension by α<:⊤\alpha<: \top for universal bodies. Each guard makes finitely many terminating subtype tests.

Target-family expressions. The empty and choice cases are

Iσp(∅)=∅,Iσp(F∪G)=Iσp(F)∪Iσp(G).I^p_{\sigma}(\varnothing) = \varnothing,\qquad I^p_{\sigma}(F \cup G) = I^p_{\sigma}(F) \cup I^p_{\sigma}(G).

A singleton uses the preceding construction. For an arrow or universal product, first test whether both child languages are nonempty. If either is empty, return the empty family for both signs. Otherwise use

Iσ−(Arr⁡(F,G))=vars⁡σ−(Arr⁡(F,G))∪Arr⁡(Iσ+(F),Iσ−(G)),I^-_{\sigma}(\operatorname{Arr}(F,G)) = \operatorname{vars}^-_{\sigma}(\operatorname{Arr}(F,G)) \cup\operatorname{Arr}(I^+_{\sigma}(F), I^-_{\sigma}(G)),
Iσ+(Arr⁡(F,G))={⊤}∪vars⁡σ+(Arr⁡(F,G))∪Arr⁡(Iσ−(F),Iσ+(G)),I^+_{\sigma}(\operatorname{Arr}(F,G)) = \{\top\} \cup\operatorname{vars}^+_{\sigma}(\operatorname{Arr}(F,G)) \cup\operatorname{Arr}(I^-_{\sigma}(F), I^+_{\sigma}(G)),
Iσ−(All⁡(F,G))=vars⁡σ−(All⁡(F,G))∪All⁡(Iσ+(F),Iup⁡(σ)−(G)),\begin{aligned} I^-_{\sigma}(\operatorname{All}(F,G)) &= \operatorname{vars}^-_{\sigma}(\operatorname{All}(F,G)) \\ &\quad\cup\operatorname{All}(I^+_{\sigma}(F), I^-_{\operatorname{up}(\sigma)}(G)), \end{aligned}
Iσ+(All⁡(F,G))={⊤}∪vars⁡σ+(All⁡(F,G))∪All⁡(Iσ−(F),Iup⁡(σ)+(G)).\begin{aligned} I^+_{\sigma}(\operatorname{All}(F,G)) &= \{\top\} \cup\operatorname{vars}^+_{\sigma}(\operatorname{All}(F,G)) \\ &\quad\cup\operatorname{All}(I^-_{\sigma}(F), I^+_{\operatorname{up}(\sigma)}(G)). \end{aligned}

In the universal equations, FF has scope Θ\Theta and GG has scope Θ\Theta, α<:⊤\alpha<: \top; the result body has scope Δ\Delta, α<:⊤\alpha<: \top. Nonemptiness is structural: choice uses disjunction, products use conjunction, and a singleton is nonempty. Recursion follows the finite expression, using the singleton construction at its leaves.

Proof of Theorem 5.5. Prove formation, soundness and coverage simultaneously. For every VV in the constructed lower family, there is T∈L(F)T \in L(F) with V[σ]<:ΘTV[\sigma] <:_{\Theta} T; for every such TT and well-formed QQ with Q[σ]<:ΘTQ[\sigma] <:_{\Theta} T, there is a lower representative VV with Q<:ΔVQ <:_{\Delta} V. For the upper family, reverse both comparisons: members satisfy T<:ΘV[σ]T <:_{\Theta} V[\sigma] for some target TT, and T<:ΘQ[σ]T <:_{\Theta} Q[\sigma] supplies a representative V<:ΔQV <:_{\Delta} Q.

For singleton targets, induct on target weight over both contexts and every typed substitution. Guards are sound by their tests and cover qualifying source variables by reflexivity. Substitution preserves compound roots.

At target ⊤\top, every source type is below the lower representative ⊤\top. For the upper direction, subtype inversion forces a nonvariable QQ whose image is above ⊤\top to be ⊤\top. The ⊤\top and guard branches cover these cases.

At a target variable β\beta, only source variables can have an image below β\beta, giving lower coverage. For upper coverage of a nonvariable QQ, algorithmic inversion of β<:ΘQ[σ]\beta<:_{\Theta} Q[\sigma] gives Θ(β)<:ΘQ[σ]\Theta(\beta) <:_{\Theta} Q[\sigma], and the induction hypothesis for the bound supplies a representative below QQ. Its soundness follows from β<:ΘΘ(β)\beta<:_{\Theta} \Theta(\beta) and transitivity.

For target A→BA \to B, a nonvariable source below the target must be an arrow Q=C→DQ = C \to D. Inversion gives A<:ΘC[σ]A <:_{\Theta} C[\sigma] and D[σ]<:ΘBD[\sigma] <:_{\Theta} B. Upper coverage of AA supplies a<:ΔCa <:_{\Delta} C; lower coverage of BB supplies D<:ΔbD <:_{\Delta} b. Hence C→D<:Δa→bC \to D <:_{\Delta} a \to b, with a→ba \to b in the lower construction. For the upper direction, an arrow source satisfies C[σ]<:ΘAC[\sigma] <:_{\Theta} A and B<:ΘD[σ]B <:_{\Theta} D[\sigma]. The opposite child inverses supply C<:ΔaC <:_{\Delta} a and b<:ΔDb <:_{\Delta} D, so a→b<:ΔC→Da \to b <:_{\Delta} C \to D. The arrow rule combines child soundness in both directions.

For target ∀α<:A.B\forall\alpha<: A.B, the compound source must be ∀α<:C.D\forall\alpha<: C.D. Inversion separates the bound comparison in Θ\Theta from the body comparison in Θ,α<:⊤\Theta,\alpha<: \top. In the lower direction, child coverage gives a<:ΔCa <:_{\Delta} C and D<:Δ,α<:⊤bD <:_{\Delta,\alpha<:\top} b; in the upper direction it gives C<:ΔaC <:_{\Delta} a and b<:Δ,α<:⊤Db <:_{\Delta,\alpha<:\top} D. The typed lift permits the body induction hypothesis in each case. Applying \textsc{All-Top} yields the required covering universal. The same rule combines child soundness. In both constructor cases, guards cover source variables, the upper ⊤\top branches cover ⊤\top, and mismatched compound roots are impossible. Child formation gives formation of the products; replacing the bound ⊤\top preserves body scope.

Induct next on the family expression. Empty families and empty products have no witnesses; singleton leaves use the result above. Choices take soundness and coverage from the branch containing the witness. For inhabited products, child coverage supplies representatives as in the constructor cases. Child soundness supplies independent target witnesses whose combination belongs to the original product. Universal bodies use the typed lift and All-Top. Inhabitation justifies the positive ⊤\top branch. Formation of an inhabited product ensures formation of each child’s members; guards test source variables against the whole product.

Coverage gives one direction of (20); soundness, subtype preservation under σ\sigma, and transitivity give the other.

Soundness and completeness of cone covers

Proof of Theorem 3.1. Induct on the weight, proving well-formedness and representative soundness together with both equalities. Soundness and restoration place each right-hand set in (8) and (9) inside its left-hand set by transitivity. For the reverse inclusions, expand membership in the left-hand cone and cover the resulting subtype comparison.

For ⊤\top, the upper comparison forces the target to be ⊤\top. The lower comparison is covered by ⊤\top itself. For a variable α\alpha, algorithmic inversion of α<:T\alpha<: T either gives T=αT = \alpha or a comparison from its bound CC to TT. The retained α\alpha covers the first case and the induction hypothesis for CC covers the second. A subtype of α\alpha must be a variable, so the lower variable-source family contains the source itself.

For A→B<:TA \to B <: T, either T=⊤T = \top or T=C→DT = C \to D with C<:AC <: A and B<:DB <: D. In the latter case lower coverage gives a∈DΔ(A)a \in D_{\Delta}(A) with C<:aC <: a in Δ∘\Delta^\circ, and upper coverage gives b∈UΔ(B)b \in U_{\Delta}(B) with b<:Db <: D there. Hence the generated a→ba \to b is below C→DC \to D in the forgotten context. For S<:A→BS <: A \to B, a variable SS is retained explicitly. Otherwise S=C→DS = C \to D, with A<:CA <: C and D<:BD <: B. Upper coverage of AA and lower coverage of BB provide a<:Ca <: C and D<:bD <: b in the forgotten context, so C→D<:a→bC \to D <: a \to b as required. The component soundness statements also give soundness of each generated arrow in the original context.

For ∀α<:A. B<:T\forall\alpha<: A.\, B <: T, the case T=⊤T = \top is explicit. Otherwise inversion gives T=∀α<:C. DT = \forall\alpha<: C.\, D with C<: ⁣ΔAC <:\!_{\Delta} A and B<: ⁣Δ⊤DB <:\!_{\Delta_{\top}} D. Choose a∈DΔ(A)a \in D_{\Delta}(A) and b∈UΔ⊤(B)b \in U_{\Delta_{\top}}(B) with C<: ⁣Δ∘aC <:\!_{\Delta^\circ} a and b<: ⁣Δ⊤∘Db <:\!_{\Delta_{\top}^\circ} D. All-Top then gives

Δ∘⊢∀α<:a. b<:∀α<:C. D.\Delta^\circ\vdash\forall\alpha<: a.\, b <: \forall\alpha<: C.\, D.

The representative is sound because a<: ⁣ΔAa <:\!_{\Delta} A and B<: ⁣Δ⊤bB <:\!_{\Delta_{\top}} b. Lower coverage treats variable sources explicitly. For a universal source, the induction hypotheses give an upper bound representative and a lower body representative. Applying All-Top again gives the required comparison. All representatives are well formed by component formation. Changing a bound does not change its variable scope.

Soundness and completeness of typing bases

Proof of Theorem 4.1. Induct on ss, generalizing over well-formed contexts Δ;Γ\Delta; \Gamma. If variable lookup fails, an abstraction annotation is ill formed, or a type argument is ill formed, the construction returns the empty family. Typing inversion excludes every assignable type in these cases, so both soundness and coverage hold. Otherwise all context extensions used for recursive calls are well formed. If a recursive basis is empty, the induction hypothesis excludes a typing for that subterm; inversion excludes one for the enclosing term, whose basis is also empty. Every recursive call is on a proper subterm, and every auxiliary construction terminates by § 3.4. Typing inversion exposes the rule for that term constructor followed by a possible final subsumption. Variables and the constant use their declared types. At an arrow introduction, the induction hypothesis gives a body representative below the body type from inversion. Arrow covariance lifts that comparison, and final subsumption reaches the requested target. Each generated arrow is sound by the introduction rule.

At type abstraction, let inversion give a body type RR and a comparison ∀α<:A. R<:ΔT\forall\alpha<: A.\ R <:_\Delta T. Choose a body representative BB with B<:ΔARB <:_\Delta A R. Corollary 3.2 gives C∈UΔA(B)C \in U_{\Delta_A}(B) with

Δ,α<:⊤⊢C<:R\Delta, \alpha<: \top\vdash C <: R

Hence All-Top gives ∀α<:A. C<:Δ∀α<:A. R\forall\alpha<: A.\ C <:_\Delta\forall\alpha<: A.\ R and then ∀α<:A. C<:ΔT\forall\alpha<: A.\ C <:_\Delta T. Soundness uses B<:ΔACB <:_\Delta A C to type the body before applying Type-Abs. Cone coverage thus accounts for the subsumption before type abstraction in § 2.2.

At an application, inversion gives f:U→Vf : U \to V, u:Uu : U, and V<:ΔTV <:_\Delta T. Choose a function representative C<:ΔU→VC <:_\Delta U \to V. Equation (3) gives C=A→BC = A \to B, U<:ΔAU <:_\Delta A, and B<:ΔVB <:_\Delta V. An argument representative D<:ΔUD <:_\Delta U therefore passes the test D<:ΔAD <:_\Delta A, and the retained BB is below TT. Conversely, exposure is sound, and an argument representative passing that test makes the application rule applicable with result BB.

At a type application, inversion gives f:∀α<:U. Vf : \forall\alpha<: U.\ V, R<:ΔUR <:_\Delta U, and V[R/α]<:ΔTV[R/\alpha] <:_\Delta T. By (4), a function representative exposes as ∀α<:A. B\forall\alpha<: A.\ B with U<:ΔAU <:_\Delta A and B<:Δ,α<:⊤VB <:_ {\Delta,\alpha<:\top} V. The bound test R<:ΔAR <:_\Delta A succeeds. Preservation of subtyping by substitution from Δ⊤\Delta_\top gives B[R/α]<:ΔV[R/α]B[R/\alpha] <:_\Delta V[R/\alpha], so the retained type covers TT. Soundness follows from exposure, Type-App, and the successful bound test. All these arguments retain the final subsumption supplied by inversion. □

Refinements of Finite Covers

Minimal typing classes

Fix a term ss and well-formed contexts Δ;Γ\Delta;\Gamma in this subsection. An assignable type MM is minimal when every assignable T<:MT <: M also satisfies M<:TM <: T. Incremental insertion into a finite basis rejects a candidate already covered by an existing member; otherwise it removes members covered by the candidate and inserts it. Validity and coverage are preserved, with one representative per mutual-subtyping class in the resulting antichain.

Upper cone pruning uses subtyping in Δ∘\Delta^\circ and retains minimal representatives. Lower cone pruning reverses that order and retains maximal representatives. Term-basis pruning uses subtyping in Δ\Delta. Pruning an upper cone in the original context could delete a representative needed after forgetting, so these orders are part of the specification.

Theorem B.1 (Complete minimal classes). Every member of the computed term antichain is minimal, and every minimal assignable type is mutually a subtype of some member of that antichain.

Proof. Let BB be a member and let an assignable TT satisfy T<:BT <: B. Coverage gives a member A<:TA <: T, hence A<:BA <: B. The antichain property gives B<:AB <: A (the two members represent the same class), so B<:TB <: T. Conversely, a minimal TT has a member B<:TB <: T by coverage. Assignability of BB gives T<:BT <: B. □

A typable term has a minimum type exactly when its antichain has one equivalence class. Antichains can still be large (Section B.2).

Large antichains and shared representations

In successive contexts α0<:T,…,αi<:T\alpha_0 <: T,\ldots,\alpha_i <: T, define

A0={α0},Ai+1={αi+1}∪{(A→T)→B:A,B∈Ai}.\mathcal{A}_0 = \{\alpha_0\}, \qquad\mathcal{A}_{i+1} = \{\alpha_{i+1}\} \cup\{(A \to T) \to B : A,B \in\mathcal{A}_i\}.

These families are antichains. For the compound members, two reversals of domain variance give

(A→⊤)→B<:(A′→⊤)→B′⟺A<:A′∧B<:B′.(A \to\top) \to B <: (A' \to\top) \to B' \Longleftrightarrow A <: A' \land B <: B'.

A fresh variable bounded by ⊤\top is incomparable with every compound member. Induction therefore gives no duplicates and

c0=1,ci+1=1+ci2,ck+1≥22k,where ci=∣Ai∣.c_0 = 1,\qquad c_{i+1} = 1 + c_i^2,\qquad c_{k+1} \ge2^{2^k},\qquad\text{where } c_i = \lvert\mathcal{A}_i\rvert.

The family Ak\mathcal{A}_k has a direct shared representation with 4k+24k + 2 nodes, counting the initial α0\alpha_0 and one shared node for ⊤\top. Each step adds a variable, a choice, and two arrows, reusing the previous family.

This bound concerns the generator language; obtaining the same bound for a small term’s typing basis would require a realization proof.

Evaluation Details

Input encoding

The input is the complete tuple (Δ,Γ,s,T)(\Delta, \Gamma, s, T). Its size nn is the length of a tree encoding with separate de Bruijn indices for type and term variables, two-bit type tags, three-bit term tags, and Elias-gamma codes for j+1j + 1 for each natural field jj [13]. Context lengths precede their entries, followed by the term and target. Contexts use newest-first order, with each type-variable bound scoped over older entries. Repeated tree occurrences count separately even when their implementation uses shared nodes. Thus nn includes contexts, annotations, explicit type arguments and the target. The corpus spans 40 to 1805 bits; the generator parameter kk is not this encoding length.

Workload constructions

All families use scales k=2,4,8,16,32k = 2, 4, 8, 16, 32.

Templates. Templates start from s0=xs_0 = x, with x:Ax : A, and repeat a type-preserving step kk times. Call templates use si+1=f{A} sis_{i+1} = f\{A\}\,s_i, with f:∀β<:B. β→βf : \forall\beta<: B.\,\beta\to\beta and A<:ΔBA <:_\Delta B. Composition uses si+1=g(f si)s_{i+1} = g(f\,s_i), with f:A→(A→A)f : A \to(A \to A) and g:(A→A)→Ag : (A \to A) \to A. Callbacks use si+1=h f sis_{i+1} = h\,f\,s_i, with f:A→Af : A \to A and h:(A→A)→(A→A)h : (A \to A) \to(A \to A). In polymorphic calls, composition and callbacks, the context declares α<:⊤→⊤\alpha<: \top\to\top and AA ranges over α\alpha, α→α\alpha\to\alpha and ∀β<:⊤. β→β\forall\beta<: \top.\,\beta\to\beta; the polymorphic call bound is B=⊤B = \top. Bounded calls instead fix A=αA = \alpha and vary its declared bound BB over ⊤→⊤\top\to\top, ⊤→(⊤→⊤)\top\to(\top\to\top) and ∀β<:⊤. β→β\forall\beta<: \top.\,\beta\to\beta. The target witness is AA in each case. A checking spine follows abstraction bodies and function children; each application argument starts a new spine. Iteration increases the number of spines while each spine has length at most three.

Typed random. Typed random uses eight fixed seeds per kk, ordered contexts of one to four bindings, and type-generation fuel five. Witness-preserving choices cover abstractions, environment-headed applications/instantiations, and term/type redexes; unavailable environment choices fall back to redexes. The generator is xorshift64star-v1 with a recorded seed matrix; kk is the recursive expansion budget.

Stress. Long spines apply kk consecutive type arguments to a function with kk nested quantifiers with bound ⊤\top and innermost body αk→αk\alpha_k \to\alpha_k, then apply the result to x:⊤→⊤x : \top\to\top. Every type argument is ⊤→⊤\top\to\top; the longest stress spine has length 34. Bound chains fix C=⊤→(⊤→⊤)C = \top\to(\top\to\top) and declare α1<:C\alpha_1 <: C and αi+1<:αi\alpha_{i+1} <: \alpha_i; with x:αkx : \alpha_k and f:C→Cf : C \to C, they check f x:Cf\,x : C. Type staircases grow quantified and arrow depth. Define

T0=⊤,Ti+1=∀γ<:⊤. Ti,T_0 = \top,\qquad T_{i+1} = \forall\gamma<: \top.\,T_i,
S0(A)=⊤,Si+1(A)=∀γ<:⊤. A→Si(A),S_0(A) = \top,\qquad S_{i+1}(A) = \forall\gamma<: \top.\,A \to S_i(A),

with fresh binders. In Δ=(β<:Tk,α<:Tk)\Delta= (\beta<: T_k, \alpha<: T_k) and Γ=(x:Sk(α))\Gamma= (x : S_k(\alpha)), the staircase query checks (Λγ<:⊤.  T.x){Sk(β)}(\Lambda\gamma<: \top. \; T.x)\{S_k(\beta)\} at Sk(α)S_k(\alpha). Its term has one type application while the surrounding types grow with kk.

Nonminimum typing. In the context β<:⊤\beta<: \top, δ<:⊤\delta<: \top, let

gβ=Λα<:β.λx:α.x,Cβ=∀α<:β.α→α,Pβ=∀α<:β.α→β.g_{\beta} = \Lambda\alpha<: \beta.\lambda x : \alpha.x,\qquad C_{\beta} = \forall\alpha<: \beta.\alpha\to\alpha,\qquad P_{\beta} = \forall\alpha<: \beta.\alpha\to\beta.

The canonical type is CβC_{\beta}, yet gβg_{\beta} also has type PβP_{\beta}; the All-Top rule prevents Cβ<:ΔPβC_{\beta} <:\Delta P_{\beta}. Replacing the result β\beta in PβP_{\beta} by the unrelated δ\delta gives a rejected target with the same constructor skeleton. Three variants per kk preserve this positive/negative pair. Introductions wrap gβg_{\beta} in kk term abstractions with ⊤\top annotations, and wrap its targets in matching arrows. Instantiations add kk nested type abstractions, each bounded by the preceding variable (the outermost by β\beta), then instantiate all of them with β\beta. Mixed redexes additionally wrap the instantiated term in kk applications (λz:⊤.s)(\lambda z : \top. s) Top with unused zz. These 15 programs test the failure of canonical subtype checking through introduction and both elimination forms.

Targets and coverage. Programs contribute a witness, a distinct non-⊤\top structural supertype when available, a local perturbation and an outer-shape change. For the original families, a deterministic leaf search also retains the first rejected target preserving the witness’s exposed arrow or quantified head, when one exists; it visits codomains and bodies first. The nonminimum family instead supplies its explicit positive/negative pair. Duplicate targets within a program are merged, retaining all construction tags. The reference labels the resulting judgments before measurement; terms retain redexes. A separate ordinary-subtyping diagnostic records whether the canonical result is below each target. The corpus contains 129 same-head rejections and 16 accepted targets outside the canonical upper cone, including one from typed random generation. All generated programs are typable; rejected judgments test target incompatibility.

Separate Rocq regression proofs exercise nonminimum argument checking and rejection at ⊤\top of an abstraction with an untypable body. The OCaml regressions cover malformed inputs, failed type-argument bounds, and nested type abstractions and instantiations. These checks are outside the timed corpus.

Measurement protocol and records

The recorded run uses native OCaml 5.4.1 with -O2 on an Apple M4 with 32 GiB RAM. Seven uninstrumented repetitions run in fresh native workers with empty caches, sequentially with shuffled query and method order. Process CPU time covers the complete check, including validation, synthesis and enabled GC. Generation, target construction, startup, input registration, empty-engine construction and the preceding full collection are excluded. Input registration creates the common syntax pool. Empty-engine construction also creates method-specific empty hash tables and their initial bucket arrays: the reference’s five tables and the backward engine’s additional synthesis/checking tables. Spine construction, dense comparison arrays, on-demand shared entries and their subsequent initialization are performed inside the timed check.

A separate counter run must agree with the timed runs. A ten-second parent-enforced deadline includes untimed setup; each syntax or checker-node pool is limited to 250,000 nodes. Timeout, node-limit, mismatch, allocation, stack and worker failures remain explicit records. Medians require all seven repetitions and the counter run to succeed. The first and third quartiles linearly interpolate the sorted CPU samples at positions 0.25(r−1)0.25(r-1) and 0.75(r−1)0.75(r-1) for r=7r = 7. Table 2 separates accepted and rejected queries and reports the median relative interquartile range (IQR).

MethodAcceptedRejectedDispersion
Finite-family reference9.08.019.0%
Dense backward45.542.013.0%
Shared backward45.041.513.6%

Table 2. CPU medians across accepted and rejected queries, in μ\mus. Dispersion is the median per-query IQR divided by that query’s median over 7 repetitions.

Check-call allocation uses Gc.allocated_bytes, including probes; peak RSS covers the whole worker. Logical comparison counts include unused dense cells and on-demand shared entries.

The run archive contains the corpus, raw samples, counters and summary, with environment, compiler profile, limits, plotting versions and SHA-256 hashes of the corpus, sources and executable. The reporter checks corpus hashes and rejects duplicate rows, incomplete matrices and label mismatches. The README gives measurement and export commands.

Detailed measurements

WorkloadQueriesInput bitsReferenceDenseShared
Polymorphic calls6564–8228.0108.0112.0
Bounded calls6068–5418.0106.0111.0
Composition6586–7008.098.0100.0
Callbacks6586–7007.064.069.0
Typed random17881–3338.024.023.0
Long spines2063–46211.587.589.5
Bound chains2563–1968.020.020.0
Type staircases2594–180512.088.094.0
Nonminimum typing7940–77544.040.041.0

Table 1. Synthetic OCaml workloads. Times are medians across completed queries of their median CPU times, in μ\mus. Input lengths include both contexts and the target. Counts include accepted and rejected queries.

The reference has a lower CPU median on 531 of 582 queries against dense and 530 against shared. The largest per-query median is 131.2 ms. For the five targets of the depth-32 dependent-instantiation program, the median of the five per-query medians is 119.2 ms for reference and 1.5 ms for each backward variant.

On the depth-32 staircase witness, both variants intern 1,250 family nodes, while sharing reduces comparison entries from 28,569 to 2,081. Median CPU time increases from 10.5 to 11.9 ms and estimated allocation volume from 10.2 to 11.4 MB. Fewer logical comparison entries therefore need not reduce time or total allocation volume.

Figure 7. Logical comparison entries, including scoped ordinary and cohort queries. Dense counts include unused initialized cells; shared counts include on-demand scoped and variable-free entries. The symmetric logarithmic scale retains zeros. Filled/hollow markers denote accepted/rejected targets.

Figure 8. Median CPU time per judgment over seven uninstrumented checks in fresh workers; whiskers span the first and third quartiles. Filled/hollow markers denote accepted/rejected judgments.

Quartic Cost Bound

We analyze the checking equations of § 5.3 with the single-hole inverse of § 6.1.

Execution and charges

For I=(Δ,Γ,s,T)I = (\Delta, \Gamma, s, T), use the encoded length nn of Section C.1 and put m=n+1m = n + 1. Words have O(log⁡(n+2))O(\log(n + 2)) bits; primitive word operations cost one. Intern immutable descriptions in an ordered dictionary at logarithmic cost; subsequent accesses use handles.

A checking spine follows abstraction bodies and function children; application arguments start new spines. For spine lengths ℓi\ell_i and term-node count NsN_s,

∑iℓi=Ns≤n,M2(s)=∑iℓi2≤Ns2.(25)\sum_i \ell_i = N_s \le n,\qquad M_2(s) = \sum_i \ell_i^2 \le N_s^2. \tag*{(25)}

Below, ℓ\ell denotes one spine’s length; mm always refers to the original input, including in recursive argument checks.

Execution state. Each spine stores its current term occurrence, lexical context, saved elimination domains, and a pointer to the target family graph of § 6. A history FF is a mutable family record with a stable identity, sign, scope cursor, fixed head, full constructor children and root alternatives. Constructor frames retain the actual domain and body pointers. A cursor identifies a scope prefix; binder tokens and cursors keep their identities when insertion changes their numerical levels. Ordinary type endpoints retain their captured tokens. Imported histories start from ordinary types and attached producers from canonical types; these initial types are their seeds. Birth allocates a history and appends its slot to its source group. Retirement never renumbers these slots.

Driver and spine operations. Validate all parsed syntax, including both children and empty context tails. On success, build source indices and produce spine candidates with delayed substitutions, saving domains and ordered scoped obligations. Reject if candidate production fails. Otherwise discharge term arguments recursively at their saved domains and test type arguments against their saved bounds, in obligation order, stopping at the first failure. Only then initialize the spine: allocate its lexical tokens, reserve deeper scopes up to the target’s maximum binder depth plus 4m4m using fresh tokens with bound ⊤\top, and clone the target as a negative history. Its query cache and hole-event list start empty.

The current term and target root determine the next action. Acceptance when ⊤∈L(F)\top\in L(F) takes priority, as in § 5.3. Otherwise an application or matching introduction first reserves 4m4m further comparison cursors and tokens with bound ⊤\top. Prepare the source directories, child-map profiles and query tables for this snapshot, then perform the corresponding operation:

  1. At f uf\ u, attach the saved canonical domain AA as a positive family and make an arrow frame with this domain and the complete current family FF as its body. Continue at ff.

  2. At f{R}f\{R\}, freeze the inverse guards in the current context, including ordinary seed guards for imports needed in this pass. Insert the fresh token α\alpha with bound ⊤\top, update histories and imports in child-before-parent order, and append the alternatives selected by the frozen guards. Attach the saved canonical bound AA and form the universal frame with the complete inverse body [⊤R/α](F)[{\top}_{R/\alpha}](F). Continue at ff.

  3. At λx:A.s\lambda x : A.s, query the matching frame’s positive domain against AA in the current outer context. On success consume the frame, retain its full body family, extend Γ\Gamma by x:Ax : A, and continue at ss.

  4. At Λα<:A.s\Lambda\alpha<: A.s, make the same domain query in the outer context. On success consume the universal frame, activate its token by changing its bound from ⊤\top to AA at most once,

and continue at ss with its full body family in Δ\Delta, α<:A\alpha<: A. Retire material that requires the consumed binder’s bound to remain ⊤\top.

A failed domain guard terminates with rejection, reusing that query’s result; its reservation, preparation and query work have already occurred. The other terminal cases prepare their query tables without a further scope reservation: if ⊤∈L(F)\top\in\mathcal{L}(F), accept; otherwise a variable xx returns EΔ−(F,Γ(x))E_{\Delta}^{-}(F,\Gamma(x)), and a constant or an introduction without a matching frame rejects. Every successful update consumes one spine node.

Preparation scans the retained group and view arrays, including retired slots, to rebuild directories and select active rows, those containing a live history. It compiles profiles only for these rows, at shallow and deep cursors alike, scanning their parent slots and child threshold ranges a constant number of times. Import passes start from missing bound promotions of live histories and close under ordinary-source child and bound dependencies. Preparation also computes the core results needed by the operation’s queries, using Section D.3; these are available for prepared-result reuse. Queries read a fixed snapshot and evaluate dependencies before their parent, with domains before bodies. A miss evaluates all requests of its compiled equation in their stored order and caches the answer before the next request; a hit reuses it. Before publishing a successful update, seal all new birth records and, in the pre-update query snapshot, perform the seed comparisons used to certify reusable cutoffs. Publish the new root and eligible cache entries, then retire invalidated regions. Compiled profiles and snapshot-local query tables are rebuilt at the next preparation; deep comparison entries persist only under Lemma D.9.

A completed snapshot consists of the live graph and ordered bound assignments reached by this driver after initialization, comparison reservation, or a successful update, with birth records sealed and retirement finished. Reservation only adds deeper tokens with bound ⊤\top; it leaves existing histories and bounds unchanged. At cursor cc, write Θc\Theta_c for this snapshot’s comparison context. All histories in a query are interpreted in their current versions in that one snapshot, including the current bound assignments. Inverse guards use the snapshot before insertion; queries on the resulting families use the completed successor.

Lemma D.1 (Spine production). Production and discharge of the saved obligations succeed exactly when canonical synthesis succeeds at the spine root. On success, each saved domain comes from the canonical exposure at its original application occurrence, in that occurrence’s lexical context. Target propagation reuses these premises. Each term argument off the spine generates one recursive checking obligation, with its original context and the saved domain.

Proof. Induct on term size. Production follows abstraction bodies and function children, computing candidates on return. Lookup and introduction reproduce the canonical rules. At ff, expose the candidate for ff, save its domain AA, and append (Δ,Γ,u,A)(\Delta,\Gamma,u,A) to the obligations; the candidate is its codomain. At f{R}f\{R\}, save the exposed bound AA and the obligation R<: ⁣ΔAR <:\!_{\Delta} A, and apply the delayed substitution to the body. Thus production is canonical synthesis with precisely these premises left open. The induction hypothesis for the smaller argument terms makes their full checks at {A}\{A\} equivalent to the saved typing premises. Failure of production or an obligation therefore excludes canonical synthesis; success establishes it at every position on the spine.

Subsequent checking visits the same occurrences and lexical contexts: an introduction extends them by its written annotation, and an elimination moves to its function child. Only the target family changes. Hence the saved premises replace every repeated synthesis call in § 5.3, including the typability test before accepting when ⊤∈L(F)\top\in\mathcal{L}(F). Production emits each off-spine argument once and target propagation emits none. The executed spines are consequently a subset of the syntactic partition in (25). ▫

Definition D.2 (Concrete run and charged work). run(I,a,W)(I, a, W) holds when the driver above terminates with answer aa; WW sums validation visits, setup and the charges below along its executed operations, including recursive obligation checks. Caches start empty. Charge unused initialization, discarded allocations and work before rejection; invalid inputs incur only validation. Allocate one store per spine initialization or type-argument check, numbered from zero in driver order at three per store. Spines and type-argument checks cost one plus their reached operations; obligation traversal costs one per visited list node, including the empty tail.

Query keys are (row, cursor, sign, endpoint, mode); misses evaluate the equations of Section D.3, children first. Hits, prepared-result reuse and core insertion cost 1, 2, 4, plus compilation and recursive work. Shallow banks and shared columns retain their snapshot and bound versions. Column keys are (cursor, sign, endpoint); hits and output reads cost 3, 4. A miss queries rows in order, merges failures, traverses the forest and writes outputs for 11 plus primitive-query work and counts of rows, aggregation/indexing events and new cells.

Charge all retained slots visited during directory construction, and all parent slots, child thresholds and token/cap entries read or initialized while compiling active-row profiles. Directory capacity is 1+max⁡(#groups,#variable views)1 + \max(\#\mathrm{groups}, \#\mathrm{variable\ views}). Reserving 4m4m comparison cursors and tokens with bound ⊤\top costs 8m+4m(2t+d)+6m(4m−1)8m + 4m(2t + d) + 6m(4m - 1) for tt old tokens and dd deeper cursors. Each store initializes 16m2+116m^2 + 1 headers at two per header. Publication reads and inserts new cells, then retires regions; new-cell reads, writes, links and named-cell deletions cost 4, 3, 4, 8.

The mechanized model takes parsed syntax with abstract natural-number fields. For an input of bb bits, a decoder scans the encoding once, using b+1b + 1 as an overflow sentinel and rejecting oversized fields and malformed encodings. Valid indices and context lengths are at most bb, so this rejects no well-formed input. Successful complete decoding preserves n=bn = b and leaves fields that fit O(log⁡(b+2))O(\log(b + 2))-bit words. This linear decoding and numeric representation argument is on paper.

Coverage and source order

core(F)(F) keeps the fixed head and full children; positive base(F)(F) also keeps promotions. Lower inversion from a singleton retains at most one structural root, so a matching introduction consumes one frame and retains its full body after the domain test.

Application token α\alpha has saved guard Rα≺AαR_\alpha\prec A_\alpha and positive owning domain FαdomF_\alpha^{\mathrm{dom}} initially containing AαA_\alpha. Its complete evolding domain, weakened along the live owner’s scope-prefix inclusion to observer cc in Θc\Theta_c, is Dˉα,c\bar{D}_{\alpha,c}. Pending added tokens have bound ⊤\top; nonself excludes FF’s fixed variable head.

Lemma D.3 (Pending-owner preservation and root projection). In every completed snapshot reached after successful argument obligations, each pending nonself root α\alpha in a live positive FF at cc has a live owner and, for well-formed endpoints in Θc\Theta_c, satisfies

∀Q nonvariable.EΘc+(D^α,c,Q)⟹EΘc+(base⁡(F),Q).(26)\forall Q\ \text{nonvariable.}\quad E^{+}_{\Theta_c}(\widehat{D}_{\alpha,c}, Q) \Longrightarrow E^{+}_{\Theta_c}(\operatorname{base}(F), Q). \tag*{(26)}
∀Q.EΘc+(D^α,c,Q)⟹EΘc+(F,Q).(27)\forall Q.\quad E^{+}_{\Theta_c}(\widehat{D}_{\alpha,c}, Q) \Longrightarrow E^{+}_{\Theta_c}(F, Q). \tag*{(27)}

These hold also inside live positive owning domains and survive birth, common inverse, activation after a successful domain test, and retirement. For nonvariable QQ, live positive histories satisfy EΘc+(F,Q)⟺EΘc+(base⁡(F),Q)E^{+}_{\Theta_c}(F, Q) \Longleftrightarrow E^{+}_{\Theta_c}(\operatorname{base}(F), Q), and negative histories satisfy EΘc−(F,Q)⟺EΘc−(core⁡(F),Q)E^{-}_{\Theta_c}(F, Q) \Longleftrightarrow E^{-}_{\Theta_c}(\operatorname{core}(F), Q).

Proof. Induct jointly on histories and owners. At birth, U≺Rα≺AαU \prec R_\alpha\prec A_\alpha and upper-inverse completeness give structural or promotion witnesses for nonvariable QQ, and inhabitation for Q=⊤Q = \top. Inverse exactness and weakening by declarations with bound ⊤\top preserve them. Close strictly outward owner dependencies transitively by depth before publication. At activation, V∈L(Fαdom)V \in\mathcal{L}(F_\alpha^{\mathrm{dom}}) and V<:AV <: A preserve the implications by weakening and composition, both at observers and inside domains. Retain fixed literal and promotion branches and original target roots; inner pending bounds stay ⊤\top. Activated tokens leave the invariant; retirement deletes dependent regions. The implications and subtype inversion give the projections. □\square

Source cohorts key imports by descriptor, cursor, captured tokens and sign, and producers additionally by occurrence, role and exposure generation. Annotation and declaration roles differ. Labels include inserted arguments; exposure starts at the original bound. NCN_C counts allocated slots, including retired births. Here an occurrence is a position in the original type syntax or a term-introduction wrapper. Substitution keeps surviving constructor labels and labels inserted syntax by its explicit argument occurrence. Projection selects a labelled child; exposure starts a new generation at the original bound’s root. Each attachment records the actual children, captured tokens and owning wrapper. Its domain records retire when that wrapper is consumed; the separate body continues.

Lemma D.4 (Source order). Fix a completed snapshot and a cursor with comparison context Θ\Theta. Let FiF_i be the current history at birth slot ii in one source cohort or attached producer group CC. All live FiF_i use this same snapshot’s bound assignments. Their successes form a prefix at every well-formed QQ in Θ\Theta:

EΘp(Fi,Q)⟺i<κCp(Q)E_{\Theta}^{p}(F_i,Q) \Longleftrightarrow i < \kappa_C^p(Q)

for live ii.

This holds for whole families and cores.

Proof. Imports retain their named seeds. A new copy of a seed is therefore covered by an older matching history; applying the same exact inverse to both preserves this implication. For producers, replay the result-contributing synthesis path with its saved substitutions. Two live checkpoints of one occurrence and generation satisfy Sbσb,b′=SbS_b \sigma_{b,b'} = S_b for b<b′b < b', where σb,b′\sigma_{b,b'} erases the intervening restored slots. This identity holds separately for each actual constructor child, with opposite sign on domains and a lifted substitution in universal bodies. Inverse completeness at each child supplies a witness in the older core, and hence whole-family coverage as well. Labels and captured placements select the actual substitution sequence.

While an owning wrapper is live, its seed binders have not been crossed. Erasing later application tokens by their saved replacements remains typed at activation: the saved argument guard and the successful domain test give the substituted bound condition, also in pending owners by Lemma D.3. Substitution reflects an answer back to the checkpoint, and narrowing preserves the converse. Fixed-head comparisons use the same bound version on both sides. Retirement removes positions without renumbering them, preserving the prefix on live slots. □\square

A newly computed cutoff is the first live failure or current capacity; only ∞\infty certifies success at all future births. Deep reuse follows Lemma D.9.

Lemma D.5 (Canonical and producer grouping). Canonical and exposed types have O(m)O(m) height and absolute scope, with scoped DAGs of O(m2)O(m^2) nodes, O(m)O(m) per level. At each snapshot, attached records form O(m)O(m) ordered producer groups per cursor and O(m2)O(m^2) in total, with O(m2ℓ)O(m^2\ell) records cumulatively per spine.

Proof. For one candidate, follow its result path through bodies and function children. Introduction adds a wrapper; substitution increases height by at most the explicit argument’s height. An argument term’s synthesized type is never inserted. Exposure resets the root to an original lexical bound, so only the segment after the last reset contributes. Written annotations, replacements and wrappers on that segment have total size at most nn. Height and lexical depth are therefore O(m)O(m). Memoization is local to this forward computation. During one substitution, an old scoped node has one output. An inserted source occurrence is keyed by its insertion level: its free tokens are fixed by the argument’s lexical capture, its local tokens by that placement. All copies undergo the same remaining substitutions on the result path, so the key determines the resulting scoped node. At final level jj, an occurrence of intrinsic depth dd was inserted at j−dj-d; it contributes at most one node there. Summing original occurrences gives O(m)O(m) nodes per level and O(m2)O(m^2) per candidate. Distinct archived candidates retain their own records.

To count generations, consider two reloads of the same original bound on this path. Bounds point strictly outward, so projections and bound lookups alone cannot return to that occurrence. Let e,ie,i count the intervening type eliminations and introductions. Returning to a variable root consumes all ii introduced universal wrappers, and a return through a type source consumes at least one more universal. Hence e≥i+1e \ge i + 1. The restored root level changes by e−i>0e-i>0, and an occurrence at depth dd is restored at that level plus dd. Repeated live generations therefore occupy distinct cursors. If the lexical boundary crosses an earlier placement, it has consumed its owning wrapper and retired that domain’s records. The unexposed declaration copy adds only a separate constant role.

There are O(m)O(m) occurrence/role pairs and at most a constant number of live generations for each pair at a signed cursor. Canonical height and at most ℓ≤n\ell\le n subsequent insertions confine attachments to O(m)O(m) cursors. Each of at most ℓ\ell attachments contributes O(m2)O(m^2) records, giving the stated live and cumulative bounds. □

Compiled queries and termination

For parent group CC and a partial child-position map π\pi on live parent slots, define

pull⁡π(k)=min⁡{i∈dom⁡(π):π(i)≥k}∪{NC}.\operatorname{pull}_{\pi}(k)=\min\{i\in\operatorname{dom}(\pi):\pi(i)\ge k\}\cup\{N_C\}.

Compile thresholds in one parent-plus-child scan. Import maps πd,πb\pi_d,\pi_b are nondecreasing between fixed cohorts and defined on all live parents, so i<pull⁡π(k)i<\operatorname{pull}_{\pi}(k) iff π(i)<k\pi(i)<k for live ii. Constructor cutoffs are

κcore=min⁡(kd,kb),ks=pull⁡πs(κs)for imports.(28)\kappa_{\mathrm{core}}=\min(k_d,k_b),\qquad k_s=\operatorname{pull}_{\pi_s}(\kappa_s)\quad\text{for imports}. \tag*{(28)}

Reverse the domain sign. Producer variable children may span several rows.

Shared variable columns. A prepared row η\eta of variable producers has snapshot-local key (occurrence, role, exposure generation, cursor, sign); referring parent births share its birth array and fixed token zz. For column (c,p,Q)(c,p,Q) in comparison context Θ\Theta, Rz\mathcal{R}_z contains all such rows at cc with sign pp and head zz, even when their occurrence labels differ. View (C,s)(C,s) stores actual children Hs(i)H_s(i) and birth positions, masking nonvariable children and retired parents.

Number driver updates by their birth stamp jj; initialization has stamp zero and reservation does not advance the stamp. The logical birth phase is b(H)=3jb(H)=3j for ownerless old-side imports, 3j+23j+2 otherwise (including clones and owner-tagged imports); token insertion is tz=3j+1t_z=3j+1. Same-pass seed guards precede insertion even if their imports are physically allocated later: they query the ordinary seed in the pre-insertion context and the import receives that pass’s inverse. Clones are born from the restored source after the event. Prepared whole-family cutoffs give

τ(z)=min⁡{b(H):η∈Rz, H live in η, ¬EΘp(H,Q)}.\tau(z)=\min\{b(H):\eta\in\mathcal{R}_z,\ H\text{ live in }\eta,\ \neg E^\mathrm{p}_\Theta(H,Q)\}.

Empty minima use None, above current phases without certifying future births. Saved variable replacements form a forest of earlier-token parents; in token order compute

ϑ(z)={ϑ(y),if parent⁡(z)=y and ϑ(y)<tz,τ(z),otherwise.\vartheta(z)= \begin{cases} \vartheta(y), & \text{if }\operatorname{parent}(z)=y\text{ and }\vartheta(y)<t_z,\\ \tau(z), & \text{otherwise.} \end{cases}

Views map phases to the first live parent whose variable child reaches them; vs(Q)v_s(Q) reads the view at ϑ(z∗)\vartheta(z_*) for last live path token z∗z_*, returning capacity if none qualifies. Construction costs O(#tokens+#rows+#views)O(\#\text{tokens}+\#\text{rows}+\#\text{views}) numeric work plus primitive queries; prepared lookups cost O(1)O(1).

Lemma D.6 (Row and replay compatibility). Fix one completed snapshot and column (c,p,Q)(c,p,Q), with QQ well formed in Θ\Theta. Every live HH in RzR_z satisfies tz≤b(H)t_z \le b(H). For live histories in these rows,

b(H)≤b(H′)∧EΘp(H′,Q)⟹EΘp(H,Q).(29)b(H) \le b(H') \land E^{p}_{\Theta}(H',Q) \quad\Longrightarrow\quad E^{p}_{\Theta}(H,Q). \tag*{(29)}

Each live variable child in a producer view is an entry of exactly one prepared row. Its token lies on the replacement path ending at the view’s last live token. Its phase lies at or after its token’s insertion and strictly before the next insertion on this path, if any. Moreover, if parent⁡(z)=y\operatorname{parent}(z)=y, every live yy-history in the prepared rows born before tzt_z covers every live history in the prepared rows for zz or a descendant of zz, in the sense of the implication in (29).

Proof. Induct on updates, generalizing over well-formed endpoints. At birth a variable producer has singleton seed {z}\{z\}; its complete family, including promotions, has that seed’s signed cone. Every older live history with fixed head zz retains zz. Hence it covers the newborn, regardless of their occurrence labels. Two births in the same phase have the same singleton cone. Common inverse preserves this coverage by exactness; activation preserves it by the typed checkpoint erasure used in Lemma D.4. Induction on updates proves (29), including agreement at equal phases.

For the path assertion, restrict the saved-substitution replay to the actual child of a fixed parent occurrence. A surviving constructor keeps its label until replay restores a variable that supplied the whole child. Thereafter a change from yy to zz can only undo an application whose saved replacement is yy; this is precisely the edge parent⁡(z)=y\operatorname{parent}(z)=y. The replay segment consists of the actual updates between those attachment births, so this insertion lies strictly after the earlier birth and before the later clone. Further undoing fixes old tokens or restores a fresh one, and cannot return to an ancestor. Thus the observations follow one path, possibly skipping tokens with no live observation, and their intervals do not interleave. A child cannot contain zz before its admission, giving the lower endpoint of each interval. The child’s source key and permanent birth slot identify its row entry; different parents referring to it reuse this entry.

For the final assertion, an older fixed yy-history succeeds at the literal endpoint yy. At the insertion with replacement yy, inverse exactness makes it succeed at zz. This uses either the retained pre-event history or its frozen ordinary seed guard; the latter has phase 3j<tz3j < t_z even when materialized later. A new variable producer at zz has the singleton cone of zz, so transitivity gives coverage. Iterate this argument along saved-variable edges. Subsequent inverse and legal activation preserve it; retirement merely removes observations. Post-event clones have phase 3j+2>tz3j+2 > t_z and are not used as pre-event witnesses. □

Lemma D.7 (Producer route decomposition). Fix a reachable producer group CC, constructor side ss, child cursor, sign psp_s and endpoint QQ. Each live parent ii has live actual child Hs(i)H_s(i); reverse the domain sign and observe universal bodies at the shared cursor where the new binder has bound TT. Partition pointers by variable/nonvariable fixed heads, preserving parent positions. The nonvariable route has one source group DsD_s and map πs\pi_s defined on those live parent slots. The first variable-child failure is vs(Q)v_s(Q), giving

ks(Q)=min⁡(pull⁡πs(κDsp(Q)),vs(Q)).(30)k_s(Q)=\min\bigl(\operatorname{pull}_{\pi_s}(\kappa^p_{D_s}(Q)),v_s(Q)\bigr). \tag*{(30)}

Missing failures contribute NCN_C. After preparation, each side uses at most one structural request, one profile lookup and one column read.

Proof. Backward replay preserves a nonvariable child’s provenance until it restores the variable that supplied that entire child. Exposure and projection occur at the synthesis root, so cannot introduce another nonvariable source below this surviving parent. This gives DsD_s and πs\pi_s.

By Lemma D.6, merging row failures gives the first failing phase across RzR_z: a live zz-history succeeds exactly when its phase is below τ(z)\tau(z). In particular, a finite minimum has a live failing witness; None means all current entries succeed. Induct along a view’s replacement path. If ϑ(y)<tz\vartheta(y) < t_z, its failing witness is at yy or an ancestor whose failure already blocked the intervening edge. The lemma’s blocking implication makes all observations below zz fail. Retain that threshold. Otherwise all preceding path observations succeed, since their phases are below tzt_z; the new observations use τ(z)\tau(z), whose finite value is at least tzt_z. This proves

ηi∈Rzi,ηi[ai]=Hs(i),bi=b(Hs(i)),\eta_i \in R_{z_i},\quad\eta_i[a_i] = H_s(i),\quad b_i = b(H_s(i)),
EΘ+(Hs(i),Q)⟺bi<ϑ(z∗).(31)E^{+}_{\Theta}(H_s(i),Q) \Longleftrightarrow b_i < \vartheta(z_*). \tag*{(31)}

Here ηi\eta_i and aia_i are the actual child’s row and permanent birth slot. The strict order 3j<tz<3j+23j < t_z < 3j + 2 fixes the same-pass boundary. Every actual pointer occurs in one mask, so component and side minima give the first failing constructor, a prefix cutoff by Lemma D.4. □

Whole-family unions take cutoff maxima. Each positive variable head retains at most two promotion witnesses, one per bound version; compile their profiles from actual references and applicable versions.

Seal record⁡F(q)=EΘ+(F,Rq)\operatorname{record}_{F}(q) = E^{+}_{\Theta}(F,R_q) at application-token insertion, including same-pass guards; later or absent records are false. Inverse exactness, retraction and (27) preserve nonself answers. Nonself roots are application tokens, so histories with arrow, universal or ⊤\top heads use their record; fixed-variable histories use

EΘ+(Fz,q)⟺record⁡Fz(q)∨z<:Θq.E^{+}_{\Theta}(F_z,q) \Longleftrightarrow\operatorname{record}_{F_z}(q) \lor z \mathrel{<:\Theta} q.

Negative holes⁡(F)\operatorname{holes}(F) excludes the fixed head and retains old membership. anc⁡Θ(q)\operatorname{anc}_{\Theta}(q) contains qq and its variable-bound ancestors, stopping at a nonvariable bound. Inversion gives

EΘ−(F,q)⟺EΘ−(core⁡(F),q)∨(anc⁡Θ(q)∩holes⁡(F)≠∅).E^{-}_{\Theta}(F,q) \Longleftrightarrow E^{-}_{\Theta}(\operatorname{core}(F),q) \lor\left(\operatorname{anc}_{\Theta}(q) \cap\operatorname{holes}(F) \ne\varnothing\right).

Using y∈holes⁡(Fi)⟺i<μC(y)y \in\operatorname{holes}(F_i) \Longleftrightarrow i < \mu_C(y) on live births, the hole cutoff is max⁡y∈anc⁡Θ(q)μC(y)\max_{y \in\operatorname{anc}_{\Theta}(q)} \mu_C(y) (missing entries zero). Only the activated token’s row changes, since outer bounds cannot mention it and inner pending bounds are ⊤\top; each row has at most two versions.

For attached group CC, let aC(q)a_C(q) count births before qq’s insertion; transport RqR_q and Θ(q)\Theta(q) to the query scope. With χi(Q)=EΘ+(Fi,Q)\chi_i(Q) = E^{+}_{\Theta}(F_i,Q) and ψi(Q)=EΘ−(Fi,Q)\psi_i(Q) = E^{-}_{\Theta}(F_i,Q), use

χi(q)⟺seedvar⁡i(q)∨(i<aC(q)∧χi(Rq)),\chi_i(q) \Longleftrightarrow\operatorname{seedvar}_i(q) \lor\left(i < a_C(q) \land\chi_i(R_q)\right),
ψi(q)⟺ownvar⁡i(q)∨ψi(Θ(q))∨(i<aC(q)∧ψi(Rq)).\psi_i(q) \Longleftrightarrow\operatorname{ownvar}_i(q) \lor\psi_i(\Theta(q)) \lor\left(i < a_C(q) \land\psi_i(R_q)\right).

Here seedvar tests z<:qz <: q for fixed head zz, and ownvar tests equality; both are false for nonvariable heads. Omit absent replacements and zero caps. Inverse exactness at the live owner’s captured placement gives only earlier histories the replacement branch; negative inversion gives the bound branch. Compile caps by minimum and literal tests by greatest successful position plus one; the combined result is a prefix by source order.

Order tokens by admission, declarations before pending tokens. Bounds and replacements capture earlier tokens, so endpoint expansion along arrow children, universal domains, bounds, replacements and retained ⊤\top witnesses is acyclic when stopped at universal bodies. Let eC(Q)e_C(Q) be its height and H∗H_* the maximum level, including prepared sources. Set j=0,1,2j = 0, 1, 2 for imports, variable views and producer or checking rows; hsrc(η)=ec(Sη)h_{\mathrm{src}}(\eta)=e_c(S_\eta) for imported seed SηS_\eta, zero otherwise; and a=2,1,0a=2,1,0 for whole, fixed-variable helper and core modes. Use rank

r(η,Q)=(1,H∗−level⁡(c),ec(Q),j(η),hsrc(η),a)r(\eta,Q)=(1,H_*-\operatorname{level}(c),e_c(Q),j(\eta),h_{\mathrm{src}}(\eta),a)

and (0,0,wΘ(S)+wΘ(T),0,0,0)(0,0,w_{\Theta}(S)+w_{\Theta}(T),0,0,0) for ordinary subtyping, with the weights of § 3.4. Body calls decrease H∗−level⁡(c)H_*-\operatorname{level}(c), endpoint expansions ece_c, dispatch jj, imported promotion hsrch_{\mathrm{src}}, and whole-to-core calls aa. Ordinary calls decrease the leading tag and then weight. Earlier coordinates stay fixed. Rank induction proves termination and query exactness.

Cumulative work and the quartic bound

The source catalogue has an instruction for ⊤\top at rank zero and one instruction per original type occurrence, including annotations, explicit arguments, context declarations and the target. Compile older declarations first and each type in postorder; rank is the instruction’s catalogue index. Arrow and universal instructions point to their children; a variable records its written index, lexical depth and the earlier instruction for its bound. A variable opened for All-Top points to rank zero. Thus every dependency has smaller rank, and the catalogue size bcatb_{\mathrm{cat}} is at most mm. An imported instance retains its instruction, cursor, captured tokens and sign; the capture interprets free variables and the cursor supplies local binders. One pass memoizes this complete key.

Lemma D.8 (Source inventory and scope advance). The catalogue is closed under child and bound requests; saved replacements refer to its original argument instructions. A pass starting at maximum live level hh imports O(m(h+m))O(m(h+m)) heads, with O(m)O(m) per level. The 4m4m comparison cursors reserved by the driver suffice for its construction and queries. After jj spine updates, maximum live level is O(m(j+1))O(m(j+1)).

Proof. At an arrow, both children keep the cursor; at a universal, only the body advances it by one. Bound lookup keeps the comparison cursor and restores the bound’s recorded capture. Each transition decreases instruction rank. Consequently level⁡(c)+rank⁡(r)\operatorname{level}(c)+\operatorname{rank}(r) never increases along an import dependency, bounding imported levels by h+bcath+b_{\mathrm{cat}}. A replacement starts from an existing catalogue root at its saved capture.

At a fixed cursor, an instruction has one live captured placement in a pass. Its free tokens come from the saved source environment and its local tokens from that cursor’s prefix. A crossing of an old internal binder discards paths using that placement: imports are fresh, hole edges do not point back to an older import, and an imported constructor cannot become the retained negative checking frame. In the deeper scopes no lexical crossing occurs, so the placement stays fixed. Children, bound lookup and replacement imports preserve this property with the captures just specified. Thus the O(m)O(m) instructions give O(m)O(m) import keys per level, including both signs, and the stated per-pass count.

For reservation, an old-side import adds at most bcatb_{\mathrm{cat}} levels; insertion adds one. A canonical domain has binder depth at most nn, and completing its promotions adds at most bcatb_{\mathrm{cat}} more. Taking the maximum over old material and the new domain bounds the constructed levels by h+n+2+bcat≤h+2m+1h+n+2+b_{\mathrm{cat}}\le h+2m+1. An ordinary query from level cc descends at most 2n+1=2m−12n+1=2m-1 further levels: its endpoint syntax contributes at most n+1n+1, and the ordered lexical-bound catalogue contributes at most nn; local comparison binders have bound ⊤\top. Child requests decrease the remaining depth by one whenever they advance the cursor. Thus construction followed by query descent fits within h+4mh+4m. Initially the target depth and 4m4m padding give the same room; a terminal query uses the room left by the last update. Each step adds only O(m)O(m) levels, proving the height claim.

Call the original and canonical levels, padded by all remaining insertions, shallow. Lemma D.5 bounds this band by O(m)O(m); a cursor’s classification is fixed at admission. Deeper cursors contain only imports, whose source-local tokens remain beyond every future lexical boundary. Summing Lemma D.8 over the spine gives

#cursors and tokens=O(mℓ),#heads=O(m2ℓ2),#shallow heads=O(m2ℓ),#deep cohorts=O(m2ℓ).\begin{aligned} \#\text{cursors and tokens} &= O(m\ell), &\#\text{heads} &= O(m^2\ell^2),\\ \#\text{shallow heads} &= O(m^2\ell), &\#\text{deep cohorts} &= O(m^2\ell). \end{aligned}

The last count uses the O(m)O(m) fixed instruction/capture keys at each of O(mℓ)O(m\ell) deep cursors across all passes; further matching births append to those cohorts. Attach deep events [0,k)[0,k) at k−1k-1 in a birth chain reachable from earlier births: g≤ℓg \le\ell events use O(NC+g)O(N_C+g) storage. Shallow masks use one slot per head per stage. Links target live or fresh objects; retirement prevents resurrection. Each node and edge has one allocation and live interval, giving O(m2ℓ2)O(m^2\ell^2) amortized graph work by reference counting, including discarded records.

Lemma D.9 (Deep-cache preservation). Let a deep imported cohort have seed SS, current capacity BB, and an accurate cutoff for endpoint QQ in whole-family or core mode. A persistent key fixes the cohort, cursor, sign, mode, captured endpoint and applicable bound versions. Its source-local tokens remain beyond all future lexical boundaries, and its free lexical tokens have final bounds. Publication tests S⪯ΘcQS \preceq_{\Theta_c} Q for positive sign and Q⪯ΘcSQ \preceq_{\Theta_c} S for negative sign. If this seed test succeeds, the tag ∞\infty is valid for future births. If it fails, the current finite cutoff k≤Bk \le B remains valid. These tags survive reservation, common inverse, frame operations and activation while their cursor and captures satisfy the stated conditions. An all-success answer without a seed certificate is snapshot-local.

Proof. Transport SS and QQ by their stable captured tokens. Reservation only appends deeper binders with bound ⊤\top. At inverse, the retraction replacing the fresh token fixes these old endpoints; inverse exactness therefore preserves the answers of retained births. For core mode use the same identities at the actual constructor children; a negative core at a variable endpoint also retains that endpoint’s bound version. Frame operations leave retained imported histories unchanged. Activation cannot cross a deep source’s local binders or change a captured free bound. Later application tokens in the evolving family may activate; erase them by their saved replacements. The successful argument and domain guards make this erasure typed by Lemma D.3. Since it fixes SS and QQ, substitution reflects any new witness to the earlier query, while narrowing preserves the converse. Thus activation preserves both retained answers and the ordinary seed test.

Every new matching birth is a copy of SS, or its inverse in a pass whose fresh token is absent from the old QQ. Its answer at QQ is exactly the seed test, by inverse exactness (childwise for cores). If that test succeeds, every old birth retains the seed and every future birth succeeds, justifying ∞\infty. If it fails, each new position i≥B≥ki \ge B \ge k fails. Retained old positions keep their answers, so the same predicate i<ki < k remains exact. The predicate continues to hold when the first failing birth retires: slots are permanent, it concerns only live positions, and the seed certificate still determines future births.

Success at every current live position gives cutoff BB. Publication must perform the seed test: success certifies ∞\infty; failure makes BB a persistent finite cutoff whose future births fail. Without that test, current capacity or None cannot be reused after growth. Retirement removes entries whose cursor or capture is no longer admissible; a changed bound version has a different key. Such entries are never revived under a reused numerical level. Ordinary deep comparisons obey the same token and bound stability, without the birth cases. □\square

Lemma D.10 (Cumulative comparison capacity). Comparison regions initialize O(m3ℓ)O(m^3\ell) cells per spine; after profile and shared-column preparation, each consumer uses O(1)O(1) local work and makes O(1)O(1) recursive requests.

Proof. A shallow snapshot has O(m)O(m) cursors, O(m)O(m) groups and import rows per cursor, O(m2)O(m^2) frame and target rows and O(m)O(m) endpoints per cursor. Imports have one live captured placement; negative frames have no bound promotion. Source size, intrinsic depth and live owners bound closure under children, bounds and replacements. Over O(ℓ)O(\ell) snapshots this gives O(m3ℓ)O(m^3\ell) cells.

By Lemma D.9, each eligible deep cell is initialized and evaluated once across snapshots, even if its witnessing birth later retires. Lemma D.8 gives O(m)O(m) named endpoints per deep cursor, with fixed captures. Thus the O(m2ℓ)O(m^2\ell) deep cohorts have O(m)O(m) persistent columns each. Ordinary rectangles have O(m)O(m) sources on each side at O(mℓ)O(m\ell) cursors and obey the same bound. Constant modes, bound versions and reserves include unused cells and retired snapshots. Lemma D.7 bounds prepared work and branching; updates pay for repeated roots and hits. □

Every live import is reached by promotions and constructor edges from an initial history, checking frame or producer at level O(m)O(m) (Lemma D.5 and the input bound). Promotion keeps the cursor. Along imported dependencies, level plus catalogue rank cannot increase, and rank is at most mm (Lemma D.8). Hence live imports also have level O(m)O(m). With O(m)O(m) source keys per cursor and two child views per producer group, there are O(m2)O(m^2) active rows.

Closing missing promotions under these dependencies creates O(m2)O(m^2) imports per memoized pass. A constant number of passes, one canonical attachment and one frame add O(m2)O(m^2) records per update. After jj updates, the retained array has O(m2(j+1))O(m^2(j+1)) records, including retired ones. Each record contributes one group slot and each parent at most two child-view slots; nonempty directories obey the same bound. Radix grouping and directory construction scan fixed-length, polynomial-range keys for these slots in O(m2(j+1))O(m^2(j+1)) work per snapshot.

Each active row has O(j+1)O(j+1) parent slots and a constant number of child threshold ranges of that length: a pass contributes at most one birth per cohort, an attachment one per producer group. With O(m)O(m) token/cap entries per row, rebuilding profiles costs O(m2(j+1)+m3)O(m^2(j+1)+m^3) per snapshot, including deep rows. The cumulative directory and profile work is

O(∑j=0ℓ[m2(j+1)+m3])=O(m2ℓ2+m3ℓ).O\left(\sum_{j=0}^{\ell}\left[m^2(j+1)+m^3\right]\right)=O(m^2\ell^2+m^3\ell).

By Lemma D.6, the row key and permanent slot recover every actual variable child; referring parent births create no additional rows. Lemma D.5 therefore bounds these rows and the two views per parent group by O(m2)O(m^2) per snapshot, each assigned once to a cursor and sign. Token widths are O(m)O(m) per cursor (source-depth window, lexical tokens and ℓ\ell applications), O(m2)O(m^2) per snapshot. The O(m)O(m) endpoint columns cost O(m3ℓ)O(m^3\ell) numeric work; primitive requests use the counted cache cells.

Owner columns and twice-built ancestor rows across O(mℓ)O(m\ell) cursors cost O(m3ℓ)O(m^3\ell); remapping, scans and requests cost O(m2ℓ2)O(m^2\ell^2). Interning O(m2ℓ)O(m^2\ell) immutable descriptions costs O(m2ℓlog⁡(m+2))O(m^2\ell\log(m+2)); mutable copies reuse handles. Canonical production and type-argument setup cost O(m3ℓ)O(m^3\ell) per spine. Total spine work is O(m3ℓ+m2ℓ2)O(m^3\ell+m^2\ell^2).

Theorem D.11 (Quartic charged work and RAM realization). For every parsed II, the model relation run of Definition D.2 has a run with unique answer and charged work, accepting exactly when Δ;Γ⊢s:T\Delta;\Gamma\vdash s:T holds. One input-independent constant crunc_{\mathrm{run}} satisfies

ledger⁡(n,s)=n+(n+1)3Ns+(n+1)2M2(s),\operatorname{ledger}(n,s)=n+(n+1)^3N_s+(n+1)^2M_2(s),
W(I)≤crunledger⁡(n,s).(32)W(I)\le c_{\mathrm{run}}\operatorname{ledger}(n,s). \tag*{(32)}

Its charged work is O((n+1)4)O((n+1)^4). With the decoding and numeric representation argument of Section D.1, the word-RAM realization takes O((b+1)4)O((b+1)^4) time on a bit-string input of length bb.

Proof. Induct on term size for recursive obligations and on completed updates within each spine. Initialization establishes the history invariants and an empty cache. At an established snapshot, query-rank induction proves the current guards accurate. Use those witnesses to establish pending-owner coverage, replay compatibility and cache preservation at the successor. Reservation preserves the old state and supplies scope room by Lemma D.8. Thus every reached query and update terminates; fixed operations and consecutive stores give uniqueness. Lemma D.1 replaces repeated canonical calls, and exact queries and frames implement Theorem 5.6, giving typing equivalence. Summing spine work using (25), with validation and setup charged once, gives (32) and the quartic charged-work bound. Decoding adds O(b)O(b) work; on success n=bn=b, giving the stated word-RAM bound. □

References

  1. [1]Brian A. Avdemir, Aaron Bohannon, Matthew Fairbairn, J. Nathan Foster, Benjamin C. Pierce, Peter Sewell, Dimitrios Vytiniotis, Geoffrey Washburn, Stephanie Weirich, and Steve Zdancewic. 2005. Mechanized Metatheory for the Masses: The POPLmark Challenge. In Theorem Proving in Higher Order Logics (Lecture Notes in Computer Science, Vol. 3603). Springer, Berlin, Heidelberg, 50–65. doi:10.1007/11541868_4
  2. [2]Gilles Barthe and Maria João Frade. 1999. Constructor Subtyping. In Programming Languages and Systems (ESOP 1999) (Lecture Notes in Computer Science, Vol. 1576). Springer, Berlin, Heidelberg, 109–127. doi:10.1007/3-540-49099-X_8DOI
  3. [3]Clément Blaudeau, Didier Rémy, and Gabriel Radanne. 2025. Avoiding Signature Anomalies in ML Modules with Zippers. Proceedings of the ACM on Programming Languages 9, POPL, Article 66 (2025), 30 pages. doi:10.1145/3704902DOI
  4. [4]Luca Cardelli, Simone Martini, John C. Mitchell, and Andre Scedrov. 1994. An Extension of System F with Subtyping. Information and Computation 109, 1–2 (1994), 4–56. doi:10.1006/inco.1994.1013DOI
  5. [5]Luca Cardelli and Peter Wegner. 1985. On Understanding Types, Data Abstraction, and Polymorphism. Comput. Surveys 17, 4 (1985), 471–522. doi:10.1145/6041.6042DOI
  6. [6]Giuseppe Castagna and Benjamin C. Pierce. 1994. Decidable Bounded Quantification. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. Association for Computing Machinery, New York, NY, USA, 151–162. doi:10.1145/174675.178844 Extended version dated January 10, 1994.
  7. [7]Giuseppe Castagna and Benjamin C. Pierce. 1995. Corrigendum: Decidable Bounded Quantification. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. Association for Computing Machinery, New York, NY, USA, 408. doi:10.1145/199448.199539DOI
  8. [8]Karl Crary. 2020. A Focused Solution to the Avoidance Problem. Journal of Functional Programming 30, Article e24 (2020), 44 pages. doi:10.1017/S0956796820000222DOI
  9. [9]Chen Cui, Shengyi Jiang, and Bruno C. d. S. Oliveira. 2023. Greedy Implicit Bounded Quantification. Proceedings of the ACM on Programming Languages 7, OOPSLA2, Article 295 (2023), 29 pages. doi:10.1145/3622871
  10. [10]Pierre-Louis Curien and Giorgio Ghelli. 1992. Coherence of Subsumption, Minimum Typing and Type-Checking in F<:. Mathematical Structures in Computer Science 2, 1 (1992), 55–91. doi:10.1017/S0960129500001134DOI
  11. [11]Stephen Dolan and Alan Mycroft. 2017. Polymorphism, Subtyping, and Type Inference in MLsub. In Proceedings of the 44th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. Association for Computing Machinery, New York, NY, USA, 60–72. doi:10.1145/3009837.3009882
  12. [12]Jana Dunfield and Neel Krishnaswami. 2021. Bidirectional Typing. Comput. Surveys 54, 5, Article 98 (2021), 38 pages. doi:10.1145/3450952
  13. [13]Peter Elias. 1975. Universal Codeword Sets and Representations of the Integers. IEEE Transactions on Information Theory 21, 2 (1975), 194–203. doi:10.1109/TIT.1975.1055349DOI
  14. [14]Alain Frisch, Giuseppe Castagna, and Véronique Benzaken. 2008. Semantic Subtyping: Dealing Set-theoretically with Function, Union, Intersection, and Negation Types. J. ACM 55, 4, Article 19 (2008), 64 pages. doi:10.1145/1391289.1391293DOI
  15. [15]Giorgio Ghelli and Benjamin C. Pierce. 1998. Bounded Existentials and Minimal Typing. Theoretical Computer Science 193, 1–2 (1998), 75–96. doi:10.1016/S0304-3975(96)00300-3DOI
  16. [16]Jason Z. S. Hu and Ondřej Lhoták. 2020. Undecidability of D<: and Its Decidable Fragments. Proceedings of the ACM on Programming Languages 4, POPL, Article 9 (2020), 30 pages. doi:10.1145/3371077DOI
  17. [17]Shengyi Jiang, Chen Cui, and Bruno C. d. S. Oliveira. 2025. Bidirectional Higher-Rank Polymorphism with Intersection and Union Types. Proceedings of the ACM on Programming Languages 9, POPL, Article 71 (2025), 31 pages. doi:10.1145/3704907DOI
  18. [18]James Laird. 2023. Revisiting Decidable Bounded Quantification, via Dinaturality. Electronic Notes in Theoretical Informatics and Computer Science 1 (2023), 16 pages. doi:10.46298/entics.10474DOI
  19. [19]Magnus Madsen and Jaco van de Pol. 2020. Polymorphic Types and Effects with Boolean Unification. Proceedings of the ACM on Programming Languages 4, OOPSLA, Article 154 (2020), 29 pages. doi:10.1145/3428222DOI
  20. [20]Magnus Madsen, Jaco van de Pol, and Troels Henriksen. 2023. Fast and Efficient Boolean Unification for Hindley-Milner-Style Type and Effect Systems. Proceedings of the ACM on Programming Languages 7, OOPSLA2, Article 240 (2023), 28 pages. doi:10.1145/3622816DOI
  21. [21]Benjamin C. Pierce. 1994. Bounded Quantification Is Undecidable. Information and Computation 112, 1 (1994), 131–165. doi:10.1006/inco.1994.1055DOI
  22. [22]Steven Schäfer, Tobias Tebbi, and Gert Smolka. 2015. Autosubst: Reasoning with de Bruijn Terms and Parallel Substitutions. In Interactive Theorem Proving. Springer International Publishing, Cham, 359–374. doi:10.1007/978-3-319-22102-1_24DOI
  23. [23]Litao Zhou, Yaoda Zhou, Qianqiong Wan, and Bruno C. d. S. Oliveira. 2025. Recursive Subtyping for All. Journal of Functional Programming 35, Article e8 (2025), 55 pages. doi:10.1017/S0956796825000036DOI

Paper details

vlnc:W_5wapg73x
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 6

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents