Generalized Algebraic Theories
Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
A many-sorted signature declares a set of sorts and, for each operation symbol, a list of argument sorts and a result sort. Try to declare a category. There are two sorts,
What the mathematics wants is one sort for each pair of objects,
A signature that cannot be sorted into three lists
Example 147.1 — An equation must precede a sort¶
Declare, in this order,
Referenced from 5 locations
An ordering of the three kinds of declaration therefore cannot be imposed in advance: a sort may depend on an operation, an operation on an equation, and an equation on a sort. A presentation must be a single sequence in which each entry is checked against everything before it. That is the shape of definition 147.4, and it is why the definition proceeds by induction on the length of the sequence rather than by describing three sets.
Two further decisions are forced. First, “everything before it” must be made precise without a syntax, since a syntax is what the theory is supposed to generate; the device is to interpret a partial presentation as a category of models and each declaration as an operation available uniformly in every model. Second, the ambient notion of model must already support contexts, dependent types, terms and substitution. That is exactly a category with families (definition 54.16), and the strict morphisms of definition 54.26 are what “uniformly” will mean.
Convention 147.2 — Ambient CwFs and size¶
Fix Grothendieck universes as in convention 116.37 and write
Referenced from 2 locations
Uniform families and presentations
Definition 147.3 — Uniform family¶
Let
A uniform family of contexts over
is a family with a context of for each object , such that for every .Given such a
, a uniform family of types over is a family with and for every .Given
and , a uniform family of terms is a family with and for every .
Referenced from 3 locations
Uniformity is a condition on the whole category of models at once. It replaces the syntactic notion “an expression in the vocabulary declared so far”: an expression would give such a family by interpretation, and the definition takes the families themselves as primitive so that no syntax has to exist yet.
Definition 147.4 — Presentation¶
A presentation
Empty. The unique presentation of length
is , and .Sort. Let
be a uniform family of contexts over . Then is a presentation. An object of is a pair with an object of and ; a morphism is a morphism with .Operator. Let
be a uniform family of contexts and a uniform family of types over . Then is a presentation. An object of is a pair with ; a morphism is an with .Equation. Let
be as above and let be uniform families of terms in . Then is a presentation, and is the full subcategory of on those with .
Referenced from 19 locations
This is Definition 4 of Bezem, Coquand, Dybjer and Escardó, On generalized algebraic theories and categories with families, physical page 6 of the journal version. The definition is independent of any syntax: nothing in it mentions an expression.
Lemma 147.5 — Extensions carry uniform families forward¶
Let
Referenced from 4 locations
Proof of Lemma 147.5 — Extensions carry uniform families forward
Proof. Let
Lemma 147.5 is what makes definition 147.4 well founded: the family used to justify entry
Example 147.6 — Monoids, step by step¶
The one-sorted theory of monoids is
Referenced from 9 locations
Example 147.7 — Categories¶
The declaration that failed in the opening is now legitimate:
Referenced from 3 locations
Remark 147.8 — Why the presentation is large, and why that is harmless¶
A uniform family is indexed by the objects of
Referenced from 3 locations
Exercise 147.1¶
Write the presentation of preorders — one sort
Referenced from 2 locations
Exercise 147.2¶
Definition 147.4 has no clause adding an equation between types. Show that the theory of categories can nevertheless be presented, by checking that every equation used in example 147.7 is an equation between terms. Then explain what would go wrong in example 147.1 if the equation
Referenced from 2 locations
The initial model
Definition 147.4 specifies a category of models without producing one. The syntactic construction produces the initial one, and it must be carried out entry by entry: theorem 54.27 builds the initial bare CwF, and each added sort, operator or equation changes the raw grammar, the inference rules and the quotient, so nothing about the extended theory follows from the bare statement.
Theorem 147.9 — Initiality¶
For every presentation
Referenced from 9 locations
Proof of Theorem 147.9 — Initiality
Proof. Induction on the length of
Base. For
Adding a sort
Adding an operator
Adding an equation
At each stage the added item was checked against the four requirements, so the induction is complete. ◻
Uniqueness at each stage used only one fact about the added entry: that a morphism of
Corollary 147.10 — Uniform families are contexts of the initial model¶
For each presentation
Referenced from 9 locations
Proof of Corollary 147.10 — Uniform families are contexts of the initial model
Proof. A context
Corollary 147.10 removes the largeness recorded in remark 147.8: a presentation may be rewritten so that each entry names a context, type and terms of the initial model constructed so far, and it then becomes a small syntactic object.
Theorem 147.11 — Structural induction¶
Let
Referenced from 7 locations
Proof of Theorem 147.11 — Structural induction
Proof. The inclusion
The hypotheses of theorem 147.11 are exactly the clauses of definition 54.16, definition 147.4; there is one closure condition per constructor of the raw syntax and one per declared symbol, and no condition for the declared equations, which hold automatically in a subclass of a model.
Example 147.12 — A CwF with Π and as a presentation¶
Take the presentation whose sorts are
Referenced from 3 locations
Exercise 147.3¶
Following the proof of theorem 147.9, write out the grammar and the added inference rules for the presentation of monoids of example 147.6, and identify the raw term whose class is
Referenced from 2 locations
Exercise 147.4¶
Instantiate theorem 147.11 at the monoid presentation built in example 147.6, and read off the induction principle it yields. State the principle as a claim about every term of type
Referenced from 2 locations
Exercise 147.5¶
In the equation step of theorem 147.9 the raw syntax does not change but the quotient does. Give a presentation
Referenced from 2 locations
Cartmell’s first-order syntax
Cartmell’s original definition proceeds through a syntax: raw expressions, judgment forms
Proposition 147.13 — Interpretation into the first-order account¶
Let
Referenced from 4 locations
Proof of Proposition 147.13 — Interpretation into the first-order account
Proof. Corollary 147.10 converts each uniform family into a datum of
Remark 147.14 — The boundary in both directions¶
Cartmell’s notion additionally permits declarations
Referenced from 4 locations
Optional route.
Second-order signatures with binding
Every entry of definition 147.4 declares an operation whose arguments are terms. A binder is not of that shape. Writing the untyped lambda calculus as a signature, one wants
The repair is to add contexts and substitutions explicitly, index the sort of terms by contexts, and turn the metatheoretic function into a term in an extended context. Applied to the display above it produces a first-order presentation in the sense of definition 147.4.
Definition 147.15 — The frozen second-order signature language¶
A second-order generalized algebraic signature declares sorts, possibly indexed by earlier sorts, and operations whose argument types may be second order, that is, of the form
Referenced from 3 locations
Example 147.16 — One binder-rich signature and its translation¶
The second-order signature of the untyped lambda calculus is Definition 3 of the source, physical page 5:
Referenced from 4 locations
Remark 147.17 — What the extension supplies and what it does not¶
The translated theory of example 147.16 is a presentation in the sense of definition 147.4: every entry declares a sort, an operation between declared sorts, or an equation between terms, and the uniform families are read off exactly as in example 147.6. Consequently theorem 147.9 and theorem 147.11 apply to it, and that is the only way results of this chapter reach a language with binders.
Three limits are recorded. First, the source’s own translation is generic and does not produce the smallest first-order presentation of a given second-order signature; simpler equivalent presentations of the lambda calculus exist, and no minimality is claimed. Second, the accompanying implementation is a partial deep embedding in Agda that computes the translation on examples; it is evidence that the construction is correct on those examples, not a mechanization of the semantic theorems stated in prose. Third, the metatheory of definition 147.15 is extensional with uniqueness of identity proofs, whereas section 147.2, section 147.3 used only convention 116.17; no theorem proved there is strengthened by the extension.
Referenced from 2 locations
Exercise 147.6¶
Write out the failed homomorphism condition for two second-order models
Referenced from 2 locations
Exercise 147.7¶
In the translated theory, define the de Bruijn variables
Referenced from 2 locations
Source. The second-order extension is A. Kaposi and Sz. Xie, Second-order generalised algebraic theories: signatures and first-order semantics, FSCD 2024, Definitions 3 and 4 on physical pp. 5–6 and the metatheory statement on physical p. 4; the related finitary presentation of inductive-inductive signatures is [KKL20].
Suggested first pass.
Begin with exercise 147.8 and exercise 147.9, then complete exercise 147.12.
Exercise 147.8¶
Write the presentation of reflexive graphs — one sort of vertices, one sort of edges indexed by two vertices, and one operation giving a loop at each vertex — and identify the uniform family of contexts used for the edge sort. Then say what an internal reflexive graph is in the CwF
Referenced from 3 locations
Exercise 147.9¶
Prove directly, without corollary 147.10, that the family assigning to each CwF its chosen terminal object is uniform, and that the family assigning to each CwF some chosen non-terminal context is not. Which clause of definition 54.26 is responsible?
Referenced from 3 locations
Exercise 147.10¶
Give a Cartmell-style theory with a declaration
Referenced from 2 locations
Exercise 147.11¶
Show that theorem 147.11 fails if the closure condition on comprehension is dropped: exhibit a presentation and a subclass of
Referenced from 2 locations
Exercise 147.12¶
Practical project.gat-presentation-checker Implement a checker for presentations in the small syntactic form supplied by corollary 147.10. The input is a finite list of entries. An entry is a sort declaration, an operator declaration, or an equation; in each case its context, type and terms are given as raw expressions over the CwF combinators of definition 54.16 extended by the symbols declared in earlier entries. The program processes the list in order and, for each entry, checks that its context is a derivable context, that its type is a derivable type over that context, and that its terms are derivable terms of that type, using only the rules generated by the entries already accepted.
Invariant. The program maintains, after entry
Concrete result. For each entry the program prints accepted together with two recorded indices — the last entry of any kind used, and the last equation used, or none — or rejected together with the reason: undeclared symbol, ill-typed argument, or an equation not yet available.
Acceptance test. Run it on the monoid presentation of example 147.6: all six entries must print accepted, and the last entry used by the left unit law must be the entry declaring rejected with the reason equation not yet available. A run that accepts the reordered list has failed to check the argument types of
Referenced from 3 locations
Sources. Definition 147.3, Definition 147.4, the monoid calculation of example 147.6, theorem 147.9, corollary 147.10 and the boundary of remark 147.14 follow M. Bezem, T. Coquand, P. Dybjer and M. Escardó, On generalized algebraic theories and categories with families, Mathematical Structures in Computer Science 31 (2021), 1006–1023 [BCDE21]: the interdependency example and Definition 4 on physical page 6, Theorem 1 and Remarks 2–4 on physical page 7, the four construction steps on physical page 9, and the monoid presentation and initial model on physical pages 10–11. The original first-order syntax and the contextual-category semantics are J. Cartmell, Generalised algebraic theories and contextual categories, PhD thesis, Oxford 1978, and the article of the same title, Annals of Pure and Applied Logic 32 (1986), 209–243 [Car78, Car86, Car18]. The initial CwF used as the base case is theorem 54.27, following Castellan, Clairambault and Dybjer [CCD21] and Dybjer [Dyb96].