Manuscript Offprint

arXiv:2610.34264

Unit: a type checker for dependent type theory

Thierry Coquand

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We present UNIT, a type checker for a dependent type theory with Π\Pi, Σ\Sigma, records, data types with primitive recursion, an identity type and cumulative universes, and a module system in the tradition of AUTOMATH: a module is a list of declarations, its parameters are the declarations without a body, and an instance binds the parameters without copying the body. Definitions are treated uniformly. A definition keeps one identity wherever it is used; two uses are compared by their names and arguments before anything is unfolded; otherwise one definition is opened at the head of the comparison, the one declared last. There is no unification and no unfolding heuristic. A consequence is that the work of checking can be observed: UNIT reports, for each declaration, which definitions it opened, and this can be compared with the informal proof. The report exposes computational work whose mathematical justification or representational origin must be explained; it is a diagnostic, not a test of fidelity. We describe the system and this method, and report on four developments: a model of univalent type theory, synthetic algebraic geometry up to Châtelet's theorem, synthetic Stone duality and its cohomology. Together they show that a small, uniform system, about 5700 lines of Haskell, supports substantial mathematics, and they give concrete reasons to reconsider the complexity routinely accepted in proof assistants for mathematics.

1 Introduction

Large proofs are now checked in Lean, Rocq and Agda. The basic ideas of these systems go back to AUTOMATH: propositions as types, proofs as terms checked in a context, and definitions that are not expanded in the proof but expressed by convertibility. That definitions belong to the calculus, and are unfolded by a reduction of their own, is the point of de Bruijn's ΛΔ\Lambda\Delta [12], where a definition is a declaration of the same kind as an abstraction and can occur anywhere in a context. Here we investigate a particular combination: shared representations of definitions, a uniform conversion strategy, and reports of the definitions unfolded, compared with an accompanying mathematical proof.

These systems have also added to pure dependent type theory notions of their own: for instance unification and implicit arguments, type classes or instance search, coercions, tactics, impredicative propositions and definitional proof irrelevance. Each serves a purpose in large-scale formalisation, but they make the work of checking harder to relate to the proof being checked, which is what we want to study here, and they are not necessary for representing mathematical arguments: the developments of Section 4 were written without unification-based argument inference, instance search, coercions, tactics or a proof-irrelevant sort; omitted arguments are only filled by one-way matching (Section 2.4). We therefore work with a small dependent type theory with definitions, modules and records, in which nothing is guessed and every unfolding of a definition can be observed. In particular there are no tactics, as in Rocq and Lean: a proof is the term that is checked; and there are no placeholders to be refined interactively, as in Agda: a file is checked as it is written.

This paper presents such a system, UNIT (Section 2); the checker and all the developments are available at https://github.com/coquand/unit. Its type theory has Π\Pi, Σ\Sigma, records, data types with primitive recursion, an identity type, and cumulative universes indexed by level expressions. Its module system follows the segments of AUTOMATH: a theorem is stated in a context, and to use it one gives an instance of the context, the objects and the proofs of the hypotheses, in order; an instance only binds the parameters, and the body is neither copied nor checked again. Its treatment of definitions is uniform: a definition is a declaration like the others, it keeps one identity wherever it is used, and conversion tries to recognise two values by their names before it opens anything, and then opens one definition at a time.

This uniformity is not only a matter of simplicity. In [11] the author recalls translating the first lemmas of Frege's Begriffsschrift into AUTOMATH notation, and observes that “these notations represented rather faithfully what is going on when one is trying to understand a proof”. We ask whether this holds for the work done during checking too. We consider detailed, precise informal proofs that identify the named constructions and lemmas used and explain the necessary openings of definitions. Ordinary texts often leave such openings silent; making them explicit is part of the comparison, not an assumption about all mathematical reading. We make two hypotheses about these selected aspects of checking.

(H1) Checking can follow reading. On a proof accompanied by such a text, a checker can recognise repeated uses of named constructions without unfolding them, and its necessary openings of definitions can be accounted for by the text or by a stated representation convention. This concerns recognition and unfolding; substitution, universe constraints, scope checking and argument recovery remain additional work of the checker.

(H2) Cost is a diagnostic. When a step that is routine on paper is expensive to check, the report can help locate repeated decoding of a representation, a missing interface or intermediate statement, or unnecessary work in the checker. This is a heuristic, not an exhaustive diagnosis or a complexity bound: some proofs do compute.

For (H2) to be usable the checker must not hide the cost: a checker with clever unfolding heuristics can make a badly structured proof cheap, and so lose the information. A uniform checker makes its work observable. This should be relevant to the problem of proofs lost in translation [4]: a formal proof can be accepted without being the proof of the text it claims to translate. Unfolding reports supply evidence for investigating this correspondence. An unexplained opening may be representational work within the same mathematical argument; agreement of reports cannot exclude a different argument or an incorrectly translated statement.

The method (Section 3) uses this. It has three parts. (1) The checker reports, for each declaration, how its comparisons were settled and which definitions it opened. (2) The informal proof is written, and each step is classified by what a reader does: match names, open a definition the text cites, or nothing. The definitions the text cites can be given to the checker, which then reports the others. (3) For a declaration that costs more than its text suggests, the formal proof is split into the steps of the informal proof, each step is measured, and the expensive comparisons are traced to the part of the checker that asks for them. The method can be applied to an existing development, or while writing a new one.

The aim (Section 5) is that the structure of a formal proof be that of a detailed, precise informal proof: one definition for each notion, one declaration for each step, the intermediate claims written, “by definition” where a definition is opened, and the facts that a text states with a definition proved once by refl. Acceptance does not establish that a formal proof follows a given text [4]; the method supplies local evidence for examining this question.

The claim. UNIT demonstrates that a small, uniform system supports substantial mathematics. Its four developments, more than thirty thousand declarations, go from a model of univalent type theory to Châtelet's theorem and to the comparison of sheaf and Čech cohomology of compact Hausdorff spaces, with no unification, no instance search, no tactics and no unfolding heuristic, and each of them is checked in under a minute (Table 1). Each notion these systems add solves a real problem; the developments show that the problem can also be solved by writing, with named instances, explicit structures and stated lemmas, and in the cases we examined (Section 4) this brought the formal proof closer to its text. This is a concrete reason to reconsider the complexity routinely accepted in proof assistants for mathematics.

AI-assisted formalisation makes the question pressing. Much of that complexity exists to spare a human author from writing what can be inferred; when the formal text is written by a machine, writing explicitly costs little, and what matters is that the result can be checked simply and read against the mathematics. All the developments reported here were written in this way. Lean and Rocq remain valuable systems and libraries, but their architecture need not be the inevitable model for what comes next: it is a reason to reconsider which complexities are necessary in the proof language and in the checker.

Results (Section 4). The method found four places where the checker did more than a reader, and places where the informal proof leaves a step to the reader. Table 2 gives the effect on the model of univalent type theory.