Trusted Kernels and Bidirectional Checking
Consider the input
The calculation exposes two algorithmic obligations. The checker must decide judgmental equality, and it must recover the arguments of a type constructor when an elimination rule demands them. The rest of the chapter makes those two obligations explicit in the kernel interface.
Proof assistants, judgmentally
Here a proof assistant is a partial function from unchecked syntax to derivations.
Remark 48.1 — Proof assistants are type-checkers¶
Stripped of definitions, implicit arguments, tactics, and libraries, a proof assistant in the style of Agda, Rocq, or Lean is a type-checker. Its kernel checks context formation, declarations, types, terms, and equalities; the closed query
Referenced from 2 locations
Production kernels optimize conversion and may use different universe or lift mechanisms. Whatever the representation, every accepted surface term must elaborate to a kernel term that a small trusted checker can recheck. The core used here is therefore a mathematical design point, not a literal description of Agda, Lean, or Rocq.
The five judgment forms of definition 26.13 classify well-formed objects, whereas a type-checker receives arbitrary syntax. Its input is therefore presyntax, syntax carrying no well-formedness guarantee, and its task is to produce a derivation—the process called elaboration.
Definition 48.2 — Presyntax¶
A preexpression is a binding tree with no well-formedness requirement. We write
Referenced from 3 locations
Definition 48.3 — Elaboration judgments¶
The judgment
Referenced from 2 locations
Here are the rules needed for the opening calculation. The base rules are
Example 110.4 — The first complete elaboration¶
Put
Referenced from 2 locations
Remark 48.5 — Where type-checking happens¶
In Pre-Lam the recursive calls merely translate presyntax; the checking is the final premise
Referenced from 2 locations
The untrusted elaborator may construct annotations by any method. The trusted rechecker traverses those annotations independently and accepts only when it reconstructs the claimed type and kernel term. This two-phase boundary goes back to de Bruijn’s Automath; the LCF architecture instead makes theorems values of an abstract type.
The projection example marks the same boundary in the fused calculus: projection from an unannotated pair is not synthesizable, and an expected type for the projection does not repair the missing synthesis premise. The elaboration rule must put an annotation on the pair itself or construct another synthesis-directed form.
Exercise 48.1¶
Extend definition 48.2 by the four constructors
Referenced from 3 locations
Lemma 48.6 — Effective enumeration of derivations¶
For a fixed recursive signature, derivations of each of the five judgments are recursively enumerable. Consequently derivability, including
Referenced from 3 locations
Proof of Lemma 48.6 — Effective enumeration of derivations
Proof. Encode variables, binding trees, finite contexts, rule names, and finite trees by natural numbers. Enumerate finite labeled trees. For each tree, check bottom-up that every node is an instance of its displayed rule: finite lists and freshness are elementary, while raw substitution and alpha-equivalence are decidable by convention 2.3, definition 26.6, definition 26.10. Output precisely the accepted trees. To semidecide a fixed judgment, run the enumeration until a tree with that root appears. If the judgment is derivable this happens after finitely many steps; otherwise the search continues. ◻
The metatheoretic demands
Equality checking and constructor inversion are algorithmic requirements; consistency and canonicity describe the judgments they accept. Their computability claims take finite derivation trees as inputs.
Remark 48.7 — Encoding¶
Computability-theoretic statements use ordinary deterministic Turing machines and a fixed effective Gödel coding of binding trees, contexts, rule names, and finite derivation trees by
Referenced from 4 locations
Definition 48.8 — Normalization structure¶
An effective conversion invariant consists of computable functions
Referenced from 6 locations
Proposition 48.9¶
A type theory with a recursive signature and effectively checkable rule instances admits an effective conversion invariant if and only if there is a decision procedure for its judgmental equality of types and of terms.
Referenced from 7 locations
Proof of Proposition 48.9
Proof. (
(
For a term input
Definition 48.10 — Injective and invertible Π -types¶
A type theory has injective
Referenced from 7 locations
Definition 48.11 — Consistency¶
A type theory is consistent if there is no closed term
Referenced from 2 locations
Consistency excludes a proof of the empty type, but it does not say what a closed datum computes to. A consistent theory could still contain a closed Boolean that is judgmentally equal to neither constructor. The stronger computational condition is therefore separate.
Definition 48.12 — Canonicity¶
A type theory enjoys canonicity if for every closed term
Referenced from 2 locations
Remark 48.13¶
Natural-number canonicity says more than head canonicity: every closed
Referenced from 2 locations
Remark 48.14 — The demand list¶
The four demands are:
an effective conversion invariant, for equality checking;
computably invertible type constructors, for syntax-directed elaboration;
consistency, for reading types as propositions; and
canonicity, for reading closed data as programs.
These are properties of a specified signature. No item follows merely from the words “dependent type theory.”
Referenced from 3 locations
Exercise 48.2¶
Spell out the computability details suppressed in the proof of proposition 48.9: define the enumeration of derivations, verify that the search is a partial recursive function, and verify totality on well-typed inputs, and prove that the term index is independent of a converted choice of classifier.
Referenced from 3 locations
Bidirectional elaboration
The annotated calculation works, but it repeats
Remark 48.15 — The bidirectional discipline¶
For some preterms the term fixes the type: the codomain of the synthesized type of
Referenced from 2 locations
Convention 110.16 — The Timpl kernel signature¶
The implementation signature
Every core
The auxiliary proof fragment
Proposition 110.17 — Exact rule delta from the proof fragment to Timpl¶
The full Timpl rule set is obtained from
The delta newly admits, for example, the fully annotated derivation
Since that hypothesis is what every checker theorem below rests on, name its content exactly. Totality of
Proof of Proposition 110.17 — Exact rule delta from the proof fragment to Timpl
Proof. Inspection of the three listed rule families proves the syntactic-delta claim. Applying Vec-intro
Definition 48.16 — Bidirectional elaboration¶
The algorithm ranges over the full Timpl signature of convention 110.16:
Its surface expressions are the unannotated raw expressions, with two exceptions. There is an annotation
The bidirectional elaboration judgments are the three modes that respectively check a type, check a term against an expected type, and synthesize a type together with a kernel term.
Assume total deterministic computable operations
Strict lift is deliberately a code-level former in this surface language:
The three judgments are
Remark 110.19 — Status for the named signatures¶
The assumptions and results do not have the same scope:
| Signature | Demands | Status |
|---|---|---|
| neither D1 nor D2 | the direct Tait proof supplies only closed-Boolean canonicity and separation | |
| Coquand’s |
D1 | a normalization-model construction at a cumulative universe-bearing signature that is none of the calculi in this book |
| D1–D2 | the six total operations are the explicit interface hypotheses of this chapter | |
| ETT with universes | D1; |
refuted by theorem 48.40, corollary 48.48 |
The cumulative construction remains at
Referenced from 2 locations
The type-checking rules are structural translations. A synthesized universe element provides the only bridge from a term mode to the type mode.
Rule Ty-El is that bridge: it first synthesizes a universe element and then returns the elaborated code as a type.
Dependent elimination synthesizes its result by substituting the elaborated scrutinee into the motive. Variables, fixed-type constructors, and annotations also synthesize.
The vector constructors and eliminator expose every parameter needed by the kernel rule. The bracketed lists below are stored certificate fields, not inferred surface arguments. Write
For Syn-VecInd, abbreviate the complete surface and core nodes by
Introduction forms check against a constructor recovered from the expected type; dedicated introduction and code rules take priority over the fallback that synthesizes a type and compares it with the expected type.
For Russell universes the expected universe supplies the level. These are term-checking rules: they are what permit a type expression to occur as a universe element.
The code rules use the formation and lift rules of definition 29.1 and definition 29.10. Equality is consulted only by the two comparison premises and inside the inversion operations. Everywhere else information flows structurally.
The rule cards are executed in the following total priority order. In type mode inspect the head in the order
Proposition 48.17 — Determinism and termination¶
Read with this priority, every full-Timpl elaboration query has at most one derivation and one output. Assuming the exact oracles of definition 48.16 total, every query terminates.
Referenced from 4 locations
Proof of Proposition 48.17 — Determinism and termination
Proof. For each mode and head constructor, exactly one clause is eligible. Its premises are evaluated in the fixed order stated by the algorithm; a failed premise returns failure. All outputs are determined by recursive outputs and the deterministic oracles. In particular, Ty-El uses the single output of
For termination, order calls lexicographically by the size of the surface subject and the mode order
The annotations in the source tree can serve as a certificate rather than as trusted elaborator state.
Remark 110.21 — The de Bruijn criterion¶
A proof assistant meets the de Bruijn criterion when it can export a proof object that a small, independent program checks against the stated formal rules. For Timpl the trust chain consists of the surface input, then the untrusted elaborator, then the certificate
Referenced from 2 locations
Definition 110.22 — Independent annotation recheck¶
A term certificate is a quintuple
| Function | recognized head, in order | defining clause |
|---|---|---|
| Ty-Pi; Ty-Sg; Ty-Id; Ty- |
||
| variable; application; first; second; |
Syn-Var; Syn-App; Syn-Fst; Syn-Snd; Syn- |
|
| lambda; pair; reflexivity; code |
Chk-Lam; Chk-Pair; Chk-Refl; Chk-Code- |
There is no implicit default: a head absent from its row fails. A recognized head whose selected clause fails is not retried as “other.” Binder freshening is deterministic up to alpha-equivalence. In particular, Syn-VecInd checks the motive in
To decide a certificate, first run
Referenced from 5 locations
Theorem 110.23 — Recheck soundness and round trip¶
Assume the full-Timpl conversion and constructor-inversion operations required in definition 48.16. Independent annotation recheck terminates. If it accepts
Referenced from 4 locations
Proof of Theorem 110.23 — Recheck soundness and round trip
Proof. Termination is the lexicographic argument of proposition 48.17; the table introduces no call not present in its rule. For soundness, simultaneously induct on the selected table entry. The type row applies, in order, the Timpl formation rule for
For the round trip, first induct on the successful type elaboration, which reconstructs
Corollary 110.24 — Kernel guarantee¶
Under the oracle contract of definition 48.16, an exported certificate accepted by an implementation of definition 110.22 denotes a derivable object-theory judgment, independently of how the elaborator constructed the certificate.
Referenced from 3 locations
Proof of Corollary 110.24 — Kernel guarantee
Proof. Acceptance and theorem 110.23 give
Example 110.25 — The annotation boundary¶
The bare application
Referenced from 2 locations
Lemma 110.26 — Formation generation for Timpl¶
In the economical presentation of Timpl, formation of a
Referenced from 3 locations
Proof of Lemma 110.26 — Formation generation for Timpl
Proof. Translate by theorem 26.43. The final nonstructural rule is either direct head formation, which has the claimed premises, or U-El, whose premise types a code for the same head in a universe. Invert that code-typing derivation at its last nonstructural rule; the corresponding universe-closure rule again exposes the same component formation premises. For each other head, inversion stops at its direct formation rule or at the matching universe-code rule and returns precisely that rule’s component premises. ◻
Theorem 48.19 — Soundness¶
Suppose
Proof of Theorem 48.19 — Soundness
Proof. Use simultaneous induction on the algorithmic derivation.
Type formers. In Ty-Pi, the induction hypotheses give
Application and projections. In Syn-App, synthesis gives
Introductions and switching. In Chk-Lam, inversion gives a display
Reflexivity. The premise gives
Booleans and vectors. The Boolean constructors use
Natural-number elimination. The induction hypotheses give the motive
For
Universe codes. For Chk-Code-Pi, the two checked premises are terms
Theorem 48.20 — Completeness up to annotation¶
For every judgment of Timpl:
if
, some annotation of its surface image checks as a type and returns ;if
, some annotation of its surface image checks against and returns ;under the same hypothesis, some annotation synthesizes
and returns .
The surface image erases a kernel abstraction’s domain annotation; rule Chk-Lam reconstructs it from
Proof of Theorem 48.20 — Completeness up to annotation
Proof. First translate the derivation to the economical structural presentation by theorem 26.43. The formers of Timpl satisfy the stability hypotheses there, so the translated derivation has no final weakening, substitution, equal-substitution, or context-conversion rule. The induction uses the following strengthened checking claim:
Types. Direct formation cases follow the corresponding Ty-* rules and the type induction hypotheses. Suppose instead that Russell decoding makes the code
Introductions. The economical generation rule exposes the constructor. For an abstraction, universal coherence of
Boolean introduction uses Syn-True or Syn-False. Boolean elimination retains its motive and recursively annotates its scrutinee and two branches, so Syn-BoolInd applies. For vector formation, choose the level already printed in its Timpl derivation and use Ty-Vec; vector introduction stores that level and element parameter and uses Syn-VNil or Syn-VCons. A final Vec-elim derivation already contains
Application. A final
Dependent eliminators. For natural-number elimination, first annotate the checked image of the scrutinee by
For
Variables and fixed constructors synthesize directly and then use Chk-Conv. An economical conversion ending needs no circular appeal: its proper typing premise is handled by (*) at the converted target. These cases prove (1) and the strengthened (2).
For (3), given
The local theorem has the same outward shape as two older checker results, but their inputs and conclusions do not match Timpl. Printing the three interfaces prevents a similarity of prose from becoming an illicit theorem transfer.
Convention 110.29 — Source checker interfaces¶
For Coquand’s closure machine, let
For the bidirectional-PCUIC source calculus, fix checker flags, a well-formed global environment
Referenced from 4 locations
Proposition 110.30 — Exact comparison boundary¶
Neither source theorem in convention 110.29 proves theorem 48.20. The bidirectional-PCUIC signatures restrict to the annotated
Referenced from 3 locations
Proof of Proposition 110.30 — Exact comparison boundary
Proof. For PCUIC, take an empty global environment, retain variables, stratified sorts, products, annotated abstractions, and applications, and specialize
For Coquand’s calculus, a total rule-preserving translation cannot send its single judgment
Exercise 48.3¶
Extend Timpl by coproducts and by a sound, complete, universally coherent operation
Referenced from 3 locations
Exercise 48.4¶
Work in the empty context with
Referenced from 3 locations
Elaborating definitions
A later declaration may compute with an earlier definition. Its elaboration context must therefore store both the declared type and the elaborated body.
Remark 48.21 — A definition is not a variable¶
Consider the script
Referenced from 2 locations
The kernel theory need not be extended. A defined elaboration context stores the definiens as typed metatheoretic data. The variable rule below retrieves that stored term; a checker may represent the retrieval by lazy
Definition 48.22 — Defined elaboration contexts¶
A defined elaboration context
Every judgment of definition 48.16 acquires the parameter
Here
Referenced from 2 locations
Remark 48.23 — The singleton alternative¶
One can instead extend the object theory by a singleton type
Referenced from 3 locations
[3]
Definition 48.24 — Elaboration of declaration lists¶
A declaration list is
A script is accepted when
Referenced from 2 locations
Example 110.35 — Elaborating the two declarations¶
The first declaration checks
Referenced from 2 locations
Exercise 48.5¶
Verify the singleton alternative of remark 48.23: define its introduction and projection, derive the defining equality by reflection, and derive eta using pair congruence, Eq-Uniq, and
Referenced from 3 locations
Exercise 48.6¶
Add the declaration
Referenced from 3 locations
The oracle boundary in ETT
The bidirectional rules are conditional on total conversion and inversion oracles. Equality reflection supplies an exact counterexample to treating that condition as automatic.
Theorem 48.40 — ETT lacks injective Π -types¶
Extensional type theory with
Referenced from 3 locations
Proof of Theorem 48.40 — ETT lacks injective Π -types
Proof. Put
The environment used in proposition 35.4 interprets both
Theorem 48.47 — Undecidability of extensional equality¶
For ETT with the Russell universes, no total Turing machine decides, from derivations of two well-typed terms in a common context and type, whether they are judgmentally equal.
Referenced from 4 locations
Proof of Theorem 48.47 — Undecidability of extensional equality
Proof. This is the judgmental-equality instance of theorem 35.49. Its fixed effective coding and machine model are convention 90.50; its reduction maps SK trees to typed terms in
Corollary 48.48¶
ETT with Russell universes admits no effective conversion invariant of definition 48.8. Moreover, no total algorithm decides all of its raw term-typing queries.
Referenced from 6 locations
Proof of Corollary 48.48
Proof. The first claim follows from proposition 48.9, theorem 48.47. The second is the typechecking instance of theorem 35.49. Concretely, the reduction sends typed endpoints
Remark 48.49 — The intensional contrast¶
The SK encoding uses equality reflection to turn the hypotheses
Referenced from 2 locations
Exercise 48.12¶
Using definition 35.45, lemma 35.46, reconstruct the reflected K equation and one application-congruence step. Identify which rules supply reflexivity, symmetry, transitivity, and congruence although
Referenced from 3 locations
Exercise 48.13¶
Write both directions of the typing reduction in corollary 48.48 as derivation trees. Use the annotated constructor
Referenced from 3 locations
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 110.9, then complete exercise 110.10.
Exercise 110.9¶
For application, the natural-number eliminator, and identity elimination, write the annotated term returned by synthesis and a separate checking derivation for that annotation. Mark precisely where normalization, constructor inversion, and context conversion enter.
Referenced from 4 locations
Exercise 110.10¶
Practical project.bidirectional-kernel-recheck Before implementing either pass, derive on paper the accepted annotated application, the accepted
Bibliographic notes.
Coquand’s source-checker interface and soundness theorem are in [Coq96]. The bidirectional PCUIC judgment and translations are in [LB22]; its smaller