Mechanized Category Theory

2026-10-01 · Steven Schaefer

Our research lab has a library of mechanized category theory in Agda that I help maintain, cubical-categorical-logic.

Cubical categorical logic

Lessons from Mechanizing Categorical Logic in Cubical Agda onpls-2026-talk

We present cubical-categorical-logic, a library of formalized category theory in Cubical Agda. The library’s core idea is to treat syntax as a free categorical structure whose dependent eliminator is stated via (displayed) universal properties. From the same reusable components we have proven canonicity and conservativity results across several type theories, as well as the coherence theorem for monoidal categories. In this talk, we discuss these applications and reflect on Cubical Agda as a host for mechanized metatheory, where it is sometimes a boon and sometimes a bane.
Slides

Further, there are plenty of notes and thoughts related to category theory more broadly. Although, these thoughts are often formalized, the formalization is currently not much represented in these notes. Instead, they just talk about math.

Category theory

Definition. Day Convolution day-convolution

Let 𝒱︀ be a symmetric monoidal closed category that is complete and cocomplete. Let (𝒞︀,⊗𝒞︀,𝐼) be a small monoidal 𝒱︀-enriched category. The Day convolution of 𝒱︀-enriched presheaves 𝐴,𝐵:𝒞︀op→𝒱︀ is the enriched presheaf

(𝐴⊗Day𝐵)𝑐=∫𝑢,𝑣𝒞︀(𝑐,𝑢⊗𝒞︀𝑣)⊗𝒱︀𝐴𝑢⊗𝒱︀𝐵𝑣,

with unit the representable 𝒞︀(−,𝐼).

Day convolution makes the enriched presheaf category [𝒞︀op,𝒱︀] a monoidal category, symmetric when 𝒞︀ is [1]. It is moreover closed.

Under the enriched Yoneda embedding the convolution of representables is representable, 𝒞︀(−,𝑥)⊗Day𝒞︀(−,𝑦)≅𝒞︀(−,𝑥⊗𝒞︀𝑦), so Day convolution is the cocontinuous extension of the tensor of 𝒞︀.

As a Kan Extension

Equivalently, 𝐴⊗Day𝐵 is the left Kan extension of (𝑢,𝑣)↦𝐴𝑢⊗𝒱︀𝐵𝑣 along ⊗𝒞︀op:𝒞︀op×𝒞︀op→𝒞︀op.

In 𝐒𝐞𝐭

When 𝒱︀=𝐒𝐞𝐭, we recover the ordinary Day convolution of presheaves 𝐴,𝐵:𝒞︀op→𝐒𝐞𝐭, where the formula simplifies to:

(𝐴⊗Day𝐵)𝑐=∫𝑢,𝑣𝒞︀[𝑐,𝑢⊗𝒞︀𝑣]×𝐴𝑢×𝐵𝑣.

Definition. The Quotient and its Right Adjoint in Day Convolution day-quotient

Let 𝐶 be a small monoidal category. Recall that for presheaves 𝐴,𝐵:𝐶op→𝐒𝐞𝐭, the Day convolution provides a closed monoidal structure:

(𝐴⊗𝐵)(𝑐)=∫𝑢,𝑣𝐶[𝑐,𝑢⊗𝑣]×𝐴(𝑢)×𝐵(𝑣)
(𝐴⊸𝐵)(𝑐)=∫𝑢𝐴(𝑢)→𝐵(𝑢⊗𝑐)

which forms an adjunction 𝐴⊗−⊣𝐴⊸−.

For covariant functors 𝐴:𝐶→𝐒𝐞𝐭 and presheaves 𝐵:𝐶op→𝐒𝐞𝐭, we can define the quotient and its right adjoint, each of which is a presheaf on 𝐶:

(𝐷𝐴𝐵)(𝑐)=∫𝑢𝐴(𝑢)×𝐵(𝑢⊗𝑐)
(𝐵𝐴)(𝑐)=∫𝑢,𝑣𝐶[𝑢⊗𝑣,𝑐]→(𝐴(𝑢)→𝐵(𝑣))

These form the adjunction 𝐷𝐴⊣−𝐴.

Definition. The Quotient and Residual Coincidence in Day Convolution day-quotient-coincidence

The Day quotient, 𝐷𝐴𝐵, takes 𝐴 to be a covariant functor and 𝐵 to be a contravariant one. While the residual 𝐴⊸𝐵 takes both to be contravariant.

This apparent variance mismatch disappears when we restrict to the groupoid core 𝐺=𝖼𝗈𝗋𝖾(𝐶), where variance is trivialized since 𝐺≅𝐺op.

For any functor 𝐹:𝐺→𝐒𝐞𝐭 on the core, we can freely extend it to both a presheaf and a covariant copresheaf on 𝐶 by left Kan extension along the respective inclusions 𝐺→𝐶op and 𝐺→𝐶:

𝗆𝗄𝖯𝗌𝗁(𝐹)(𝑐)=∫𝑠∈𝐺𝐶[𝑐,𝑠]×𝐹(𝑠)
𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝐹)(𝑐)=∫𝑠∈𝐺𝐶[𝑠,𝑐]×𝐹(𝑠)

By substituting these extensions into the definitions of the residual and the quotient, we obtain a general coincidence for any 𝐹:𝐺→𝐒𝐞𝐭 and 𝐵:𝐶op→𝐒𝐞𝐭:

𝗆𝗄𝖯𝗌𝗁(𝐹)⊸𝐵≅𝐷𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝐹)𝐵

This equivalence states that computing the residual against the presheaf extension of 𝐹 is perfectly isomorphic to taking the quotient by its covariant extension.

The Representable Case

Instantiating the above theorem at a representable functor on the core, 𝐹=𝐺[𝑥,−]: the co-Yoneda lemma says that the left Kan extensions compute to the representables on 𝐶:

𝗆𝗄𝖯𝗌𝗁(𝐺[𝑥,−])≅𝐶[−,𝑥]
𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝐺[𝑥,−])≅𝐶[𝑥,−]

Applying the general coincidence theorem, the left and right adjoints coincide precisely on (opposite-variance) representables:

(𝐶[−,𝑥]⊸𝐵)(𝑐)≅𝐵(𝑥⊗𝑐)≅(𝐷𝐶[𝑥,−]𝐵)(𝑐)

When 𝐶 is the discrete monoidal category of strings, this recovers the derivative of formal grammars.

In nominal sets, I suspect that this construction also describes name abstraction and the freshness quantifier, although I have not check all of the details of the proof.

Definition. Nominal Sets nominal-set

Fix a countably infinite set of names 𝔸. A nominal set [1] is a set 𝑋 equipped with an action by the group of finite permutations 𝖯𝖾𝗋𝗆(𝔸), such that every element 𝑥∈𝑋 has a finite support.

A finite set of names 𝑆⊆𝔸 supports 𝑥 if any permutation fixing 𝑆 pointwise also fixes 𝑥.

The category of nominal sets is equivalent to the Schanuel topos. Under this equivalence, a nominal set 𝑋 corresponds to a functor 𝕀→𝐒𝐞𝐭, where 𝕀 is the category of finite sets and injections, given by mapping a finite set of names 𝑡 to the set of elements supported by 𝑡:

𝑋(𝑡)={𝑥∈𝑋|𝑡supports𝑥}

Definition. Nominal Sets as Day Quotients nominal-sets-quotient

In the Schanuel topos, the underlying category for Day convolution is 𝐶=𝕀op, where 𝕀 is the category of finite sets and injections.

Given a nominal set 𝑋, its presheaf action describes elements supported by 𝑡:

𝑋(𝑡)={𝑥∈𝑋|𝗌𝗎𝗉𝗉(𝑥)⊆𝑡}

Instead of taking 𝑋 a priori as a presheaf, we can view it as a finitely- supported 𝖯𝖾𝗋𝗆(𝔸)-set. We can restrict our attention to the groupoid core 𝐺=𝖼𝗈𝗋𝖾(𝕀), asking for the support to be exactly the input:

𝑋𝑠={𝑥∈𝑋|𝗌𝗎𝗉𝗉(𝑥)=𝑠}

This family 𝑋•:𝐺→𝐒𝐞𝐭 is functorial on finite sets and bijections.

By extending this functor along the inclusions described in Quotient Coincidence, we can extend 𝑋• to both a presheaf 𝗆𝗄𝖯𝗌𝗁(𝑋•) and a copresheaf 𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝑋•) on 𝐶. This suggests the equivalence:

𝗆𝗄𝖯𝗌𝗁(𝑋•)⊸𝑌≅𝐷𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝑋•)𝑌

I suspect this allows us to describe name abstraction [𝑋]𝑌 [1] —which ordinarily looks like an operation on two presheaves of the same variance—as the quotient of 𝑌 by the induced copresheaf 𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝑋•).

Concretely, [𝑋]𝑌 is usually given by the quotient of the product by an equivalence relation:

[𝑋]𝑌≅𝑋×𝑌∼

where (𝑥,𝑦)∼(𝜋𝑥,𝜋𝑦) for permutations 𝜋 fixing 𝗌𝗎𝗉𝗉(𝑦)−𝗌𝗎𝗉𝗉(𝑥).

On the other hand, the Day quotient computes to a coend:

(𝐷𝗆𝗄𝖢𝗈𝗉𝗌𝗁(𝑋•)𝑌)(𝑐)=∫𝑠𝑋𝑠×𝑌(𝑠⊎𝑐)

A priori, a coend over 𝑠 of the product 𝑋𝑠×𝑌(𝑠⊎𝑐) is expressed as the quotient of a set of triples by an equivalence relation ≈:

{(𝑠,𝑥,𝑦)|𝑠=𝗌𝗎𝗉𝗉(𝑥),𝗌𝗎𝗉𝗉(𝑦)⊆𝑠⊎𝑐}/≈

However, because the comprehension formula fixes 𝑠=𝗌𝗎𝗉𝗉(𝑥), we reduce to a quotient of pairs:

{(𝑥,𝑦)|𝗌𝗎𝗉𝗉(𝑦)⊆𝗌𝗎𝗉𝗉(𝑥)⊎𝑐}/≈

I suspect that this quotient will equate to the one given by [𝑋]𝑌, thus resolving the apparent issues with variance. I further suspect that one will need the sheaf condition (pullback-preservation) of nominal sets to establish this equivalence.

Definition. The Schanuel Topos schanuel-topos

Let 𝕀 be the category of finite sets and injections. The Schanuel topos is the category of pullback-preserving functors 𝕀op→𝐒𝐞𝐭.

Equivalently, it is the category of nominal sets, which are sets equipped with an action by the group of permutations on a countable set of names 𝔸, such that every element has finite support.

Theorem. Day Convolution is Closed day-closed-structure

Let 𝒱︀ be a symmetric monoidal closed category that is complete and cocomplete. Let (𝒞︀,⊗𝒞︀,𝐼) be a small monoidal 𝒱︀-enriched category and 𝐴,𝐵 be 𝒱︀-enriched presheaves on 𝒞︀. Define

(𝐴⊸𝐵)𝑐=∫𝑢𝐴𝑢⊸𝒱︀𝐵(𝑢⊗𝒞︀𝑐).

Then, for Day convolution ⊗Day,

𝐴⊗Day−⊣𝐴⊸Day−.

Proof. Proof that Day Convolution is Closed day-closed-structure-proof

For 𝑋,𝐵:𝒞︀op→𝒱︀, the enriched hom in [𝒞︀op,𝒱︀] is given by the end:

∫𝑐((𝐴⊗Day𝑋)𝑐⊸𝒱︀𝐵𝑐)≅∫𝑐((∫𝑢,𝑣𝒞︀(𝑐,𝑢⊗𝒞︀𝑣)⊗𝒱︀𝐴𝑢⊗𝒱︀𝑋𝑣)⊸𝒱︀𝐵𝑐)≅∫𝑐∫𝑢,𝑣((𝒞︀(𝑐,𝑢⊗𝒞︀𝑣)⊗𝒱︀𝐴𝑢⊗𝒱︀𝑋𝑣)⊸𝒱︀𝐵𝑐)≅∫𝑢,𝑣((𝐴𝑢⊗𝒱︀𝑋𝑣)⊸𝒱︀∫𝑐(𝒞︀(𝑐,𝑢⊗𝒞︀𝑣)⊸𝒱︀𝐵𝑐))≅∫𝑢,𝑣((𝐴𝑢⊗𝒱︀𝑋𝑣)⊸𝒱︀𝐵(𝑢⊗𝒞︀𝑣))≅∫𝑣(𝑋𝑣⊸𝒱︀∫𝑢(𝐴𝑢⊸𝒱︀𝐵(𝑢⊗𝒞︀𝑣)))≅∫𝑣(𝑋𝑣⊸𝒱︀(𝐴⊸𝐵)𝑣).

∎

Symmetrically, (𝐵⟜𝐴)𝑐=∫𝑣𝐴𝑣⊸𝒱︀𝐵(𝑐⊗𝒞︀𝑣) and −⊗Day𝐴⊣−⟜𝐴, so the enriched presheaf category [𝒞︀op,𝒱︀] is biclosed [1].

Definition. The Bicategory of Categories bicategory-of-categories

The bicategory of categories 𝖢𝖠𝖳 has

  • as 0-cells, categories (at a fixed pair of universe levels, for objects and for morphisms);
  • as hom-category 𝖢𝖠𝖳(𝒞︀,𝒟︀), the functor category [𝒞︀,𝒟︀], so 1-cells are functors and 2-cells are natural transformations;
  • as identity 1-cell, the identity functor;
  • as composition, 𝐹⋆𝐺=𝐺∘𝐹 on functors. On natural transformations 𝛽:𝐹⇒𝐹′ and 𝛾:𝐺⇒𝐺′ the horizontal composite is given directly by its components

    (𝛽⋆𝛾)𝑐=𝐺(𝛽𝑐)⋆𝛾𝐹′𝑐.

Every component of the left unitor, the right unitor and the associator is an identity morphism, and their inverses are identities too. So the only content of the triangle and pentagon is that composites of identities are identities.

𝖢𝖠𝖳 is still a bicategory and not a strict 2-category: Id∘𝐹 and 𝐹 agree on objects and on morphisms, but in the formalization they are not the same functor definitionally. The structure cells are there to name that agreement.

A monad in 𝖢𝖠𝖳 is an ordinary monad on a category, and a prestack is a pseudofunctor into 𝖢𝖠𝖳.

Definition. Corecursive algebra corecursive-algebra

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. An algebra 𝛼:𝐹𝐵→𝐵 is corecursive when for every coalgebra 𝛾:𝑋→𝐹𝑋 there is exactly one hylomorphism from 𝛾 to 𝛼. Equivalently, the functor 𝖧𝗒𝗅𝗈(−,𝛼) of the hylomorphism profunctor is constantly a singleton. It is the dual of a recursive coalgebra: an 𝐹-algebra in 𝒞︀ is corecursive exactly when it is recursive as an 𝐹op-coalgebra in 𝒞︀op.

Example. If (𝜈𝐹,𝗈𝗎𝗍) is a terminal coalgebra, then 𝗈𝗎𝗍 is invertible and 𝗈𝗎𝗍−1:𝐹(𝜈𝐹)→𝜈𝐹 is a corecursive algebra: a solution of ℎ=𝛾⋆𝐹ℎ⋆𝗈𝗎𝗍−1 is the same thing as a solution of ℎ⋆𝗈𝗎𝗍=𝛾⋆𝐹ℎ, that is, a coalgebra map into the terminal coalgebra, and there is exactly one, 𝗎𝗇𝖿𝗈𝗅𝖽𝛾.

Definition. Hylomorphism hylomorphism

Fix an endofunctor 𝐹:𝒞︀→𝒞︀, a coalgebra 𝛾:𝑋→𝐹𝑋 and an algebra 𝛼:𝐹𝐵→𝐵. A hylomorphism (or coalgebra-to-algebra morphism) from 𝛾 to 𝛼 is a morphism ℎ:𝑋→𝐵 satisfying

ℎ=𝛾⋆𝐹ℎ⋆𝛼.

Definition. The hylomorphism profunctor hylomorphism-profunctor

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. Hylomorphisms form a profunctor from coalgebras to algebras,

𝖧𝗒𝗅𝗈:𝖢𝗈𝖺𝗅𝗀(𝐹)op×𝖠𝗅𝗀(𝐹)→𝐒𝐞𝐭,

where 𝖧𝗒𝗅𝗈((𝑋,𝛾),(𝐵,𝛼)) is the set of ℎ:𝑋→𝐵 with ℎ=𝛾⋆𝐹ℎ⋆𝛼.

The action is by composition. If 𝑔:(𝑌,𝛿)→(𝑋,𝛾) is a coalgebra morphism (𝑔⋆𝛾=𝛿⋆𝐹𝑔) and 𝑘:(𝐵,𝛼)→(𝐵′,𝛼′) is an algebra morphism (𝛼⋆𝑘=𝐹𝑘⋆𝛼′), then 𝑔⋆ℎ⋆𝑘 is again a hylomorphism:

𝛿⋆𝐹(𝑔⋆ℎ⋆𝑘)⋆𝛼′=𝛿⋆𝐹𝑔⋆𝐹ℎ⋆𝛼⋆𝑘=𝑔⋆𝛾⋆𝐹ℎ⋆𝛼⋆𝑘=𝑔⋆ℎ⋆𝑘.

In these terms, a coalgebra 𝛾 is recursive when 𝖧𝗒𝗅𝗈(𝛾,−) is the terminal functor, and an algebra 𝛼 is corecursive when 𝖧𝗒𝗅𝗈(−,𝛼) is. For the inverse of an initial algebra the profunctor is representable, 𝖧𝗒𝗅𝗈(𝗂𝗇−1,−)≅𝖠𝗅𝗀(𝐹)(𝗂𝗇,−), and dually 𝖧𝗒𝗅𝗈(−,𝗈𝗎𝗍−1)≅𝖢𝗈𝖺𝗅𝗀(𝐹)(−,𝗈𝗎𝗍) for a terminal coalgebra.

When every value of 𝖧𝗒𝗅𝗈 is a singleton, every divide-and-conquer specification over 𝐹 has exactly one solution. This is what local contractivity guarantees.

Definition. Lax Functor lax-functor

A lax functor 𝐹:ℬ︀→𝒞︀ between bicategories consists of

  1. a map on 0-cells, 𝑥↦𝐹𝑥;
  2. for all 𝑥,𝑦, a functor 𝐹𝑥,𝑦:ℬ︀(𝑥,𝑦)→𝒞︀(𝐹𝑥,𝐹𝑦), acting on 1-cells and 2-cells;
  3. a unit comparison, natural 2-cells 𝐹𝑥0:1𝐹𝑥⇒𝐹(1𝑥);
  4. a composition comparison, 2-cells 𝐹𝑓,𝑔2:𝐹𝑓⋆𝐹𝑔⇒𝐹(𝑓⋆𝑔) natural in 𝑓 and 𝑔;
  5. such that three coherence laws hold, one for each structure cell of ℬ︀:

    • left unit: (𝐹0▷𝐹𝑓)⋆𝐹1,𝑓2⋆𝐹(𝜆𝑓)=𝜆𝐹𝑓;
    • right unit: (𝐹𝑓◁𝐹0)⋆𝐹𝑓,12⋆𝐹(𝜌𝑓)=𝜌𝐹𝑓;
    • associativity: (𝐹𝑓,𝑔2▷𝐹ℎ)⋆𝐹𝑓⋆𝑔,ℎ2⋆𝐹(𝛼𝑓,𝑔,ℎ)=𝛼𝐹𝑓,𝐹𝑔,𝐹ℎ⋆(𝐹𝑓◁𝐹𝑔,ℎ2)⋆𝐹𝑓,𝑔⋆ℎ2.

Here ⋆ between 2-cells is vertical composition, and 𝜃▷ℎ and ℎ◁𝜃 are whiskerings.

Lax functors compose: (𝐺∘𝐹)0=𝐺0⋆𝐺(𝐹0) and (𝐺∘𝐹)𝑓,𝑔2=𝐺𝐹𝑓,𝐹𝑔2⋆𝐺(𝐹𝑓,𝑔2). The coherence laws of the composite follow from those of 𝐹 and 𝐺 and naturality of 𝐺2, without using the triangle or pentagon of any of the bicategories involved.

A lax functor whose comparison cells are invertible is a pseudofunctor.

Definition. Lax and Pseudonatural Transformations lax-natural-transformation

Let 𝐹,𝐺:ℬ︀→𝒞︀ be lax functors. A lax natural transformation 𝜎:𝐹⇒𝐺 consists of

  1. for each 0-cell 𝑥, a 1-cell 𝜎𝑥:𝐹𝑥→𝐺𝑥;
  2. for each 1-cell 𝑓:𝑥→𝑦, a 2-cell filling the naturality square,

    𝜎𝑓:𝐹𝑓⋆𝜎𝑦⇒𝜎𝑥⋆𝐺𝑓;
  3. such that 𝜎𝑓 is natural in 𝑓: for a 2-cell 𝜃:𝑓⇒𝑔, (𝐹𝜃▷𝜎𝑦)⋆𝜎𝑔=𝜎𝑓⋆(𝜎𝑥◁𝐺𝜃);
  4. and such that 𝜎 respects the comparison cells of 𝐹 and 𝐺: one law relating 𝜎1𝑥 to 𝐹0, 𝐺0 and the unitors, and one relating 𝜎𝑓⋆𝑔 to 𝜎𝑓, 𝜎𝑔, 𝐹2, 𝐺2 and the associators.

A lax natural transformation is pseudonatural when every 𝜎𝑓 is invertible. As with pseudofunctors, this is a property, so the pseudonatural transformations 𝐹⇒𝐺 are a full subcategory of the category of lax transformations and modifications.

Between prestacks the 1-cells are taken to be pseudonatural. The reason is biuniversality: a transformation whose components 𝜎𝑥 are all equivalences of categories is an equivalence of prestacks only if its naturality cells are invertible, and a biuniversal element should be exactly a representation of a prestack up to such an equivalence.

Definition. Locally Discrete Bicategory locally-discrete-bicategory

Every category 𝒞︀ is a bicategory 𝖫𝖣(𝒞︀) with only identity 2-cells. Its 0-cells are the objects of 𝒞︀, and the hom-category 𝖫𝖣(𝒞︀)(𝑥,𝑦) is the discrete category on the set 𝒞︀(𝑥,𝑦): a 2-cell 𝑓⇒𝑔 is a proof that 𝑓=𝑔. Composition and identities are those of 𝒞︀; the unitors and associator are the unit and associativity laws of 𝒞︀. Since the homs of 𝒞︀ are sets, any two parallel 2-cells are equal, so the triangle and pentagon hold trivially.

A functor 𝐹:𝒞︀→𝒟︀ gives a pseudofunctor 𝖫𝖣(𝐹):𝖫𝖣(𝒞︀)→𝖫𝖣(𝒟︀), whose comparison 2-cells are the functor laws of 𝐹.

The locally discrete bicategory is how ordinary indexed categories enter bicategorical language: a prestack on 𝖫𝖣(𝒞︀) is a pseudofunctor 𝒞︀op→𝖢𝖠𝖳, and its Grothendieck construction is a displayed category over 𝒞︀.

Definition. Opposite Bicategory opposite-bicategory

The opposite ℬ︀op of a bicategory ℬ︀ has the same 0-cells and reverses the 1-cells but not the 2-cells:

ℬ︀op(𝑥,𝑦)=ℬ︀(𝑦,𝑥).

Composition swaps its arguments, 𝑓⋆op𝑔=𝑔⋆𝑓. The left unitor of ℬ︀op is the right unitor of ℬ︀ and vice versa, and the associator of ℬ︀op is the inverse of the associator of ℬ︀, with its arguments reversed.

Since the 2-cells keep their direction, a lax functor 𝐹:ℬ︀→𝒞︀ induces a lax (not oplax) functor ℬ︀op→𝒞︀op with the same action on cells. Reversing the 2-cells instead gives the bicategory ℬ︀co, whose hom-categories are the opposites (ℬ︀(𝑥,𝑦))op.

Duality saves work: a coherence lemma about ℬ︀ can often be obtained by instantiating a companion lemma at ℬ︀op, which swaps left and right.

Definition. Pseudofunctor pseudofunctor

A pseudofunctor 𝐹:ℬ︀→𝒞︀ is a lax functor whose unit and composition comparisons

𝐹𝑥0:1𝐹𝑥⇒𝐹(1𝑥)𝐹𝑓,𝑔2:𝐹𝑓⋆𝐹𝑔⇒𝐹(𝑓⋆𝑔)

are invertible 2-cells. So 𝐹 preserves identities and composition up to coherent isomorphism.

Being pseudo is a property of a lax functor: invertibility of a 2-cell is a proposition, since inverses are unique. The data of a pseudofunctor is exactly the data of a lax functor, and everything proved about lax functors applies to pseudofunctors unchanged. Pseudofunctors are closed under composition and identities, as lax functors are, because invertible 2-cells are closed under composition and under the action of a functor on hom-categories.

The main examples here are prestacks, pseudofunctors ℬ︀op→𝖢𝖠𝖳. When ℬ︀ is locally discrete on a category 𝒞︀, these are the pseudofunctors 𝒞︀op→𝖢𝖠𝖳 of fibred category theory.

Definition. Recursive coalgebra recursive-coalgebra

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. A coalgebra 𝛾:𝑋→𝐹𝑋 is recursive when for every algebra 𝛼:𝐹𝐵→𝐵 there is exactly one hylomorphism ℎ:𝑋→𝐵 from 𝛾 to 𝛼, that is, exactly one solution of

ℎ=𝛾⋆𝐹ℎ⋆𝛼.

Equivalently, the functor 𝖧𝗒𝗅𝗈(𝛾,−) of the hylomorphism profunctor is constantly a singleton.

Recursiveness is a coalgebraic form of well-foundedness: 𝛾 decomposes each input into subproblems, and recursiveness says that every divide-and-conquer program built on this decomposition has a unique meaning, without mentioning an order on inputs. [1] use recursive coalgebras on categories of indexed families to obtain algorithms that are correct by the type of the map they compute.

Example. If (𝜇𝐹,𝗂𝗇) is an initial algebra, then 𝗂𝗇 is invertible (Lambek’s lemma) and 𝗂𝗇−1:𝜇𝐹→𝐹(𝜇𝐹) is a recursive coalgebra. Precomposing with the isomorphism 𝗂𝗇, the equation ℎ=𝗂𝗇−1⋆𝐹ℎ⋆𝛼 is equivalent to 𝗂𝗇⋆ℎ=𝐹ℎ⋆𝛼, which says ℎ is an algebra map out of the initial algebra; there is exactly one, 𝖿𝗈𝗅𝖽𝛼.

The dual notion is a corecursive algebra.

Definition. Total Bicategory total-bicategory

The total bicategory of a displayed bicategory over 𝒦︀ packages the base and the displayed data together, one dimension up from the total category of a displayed category.

  • Its 0-cells are pairs of a 0-cell of 𝒦︀ and a displayed 0-cell over it.
  • Its hom-category from to is the total category of the displayed hom-category . So a 1-cell is a pair and a 2-cell is a pair .
  • Identities, composition, unitors and associator are pairs of the base structure and the displayed structure over it, and the triangle and pentagon hold because they hold in the base and, over that, in the displayed bicategory.

Projecting to first components is a pseudofunctor whose unit and composition comparisons are identity 2-cells.

Predecessors simplify later predecessors-simplify-later

A predecessor of 𝑥 is a top element of its strict downset: a strict morphism 𝜌:𝑝→𝑥 through which every strict morphism into 𝑥 factors uniquely. Equivalently, 𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥)≅𝗒𝑝 — the downset is representable.

The Yoneda lemma then collapses later to evaluation:

⊳𝑃(𝑥)=𝖯𝗌𝗁𝒞︀(𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥),𝑃)≅𝖯𝗌𝗁𝒞︀(𝗒𝑝,𝑃)≅𝑃(𝑝),

with 𝗇𝖾𝗑𝗍 becoming restriction along 𝜌. The name is from the naturals: every strict map into 𝑛+1 factors through 𝑛→𝑛+1, so on 𝜔 — in the topos of trees — later is just the shift

⊳𝑃(0)≅⊤,⊳𝑃(𝑛+1)≅𝑃(𝑛),

and a Löb step is a base value together with a rule producing the value at 𝑛+1 from the value at 𝑛.

When this predecessor exists, we can give a simpler description of later, as in the topos of trees, but this may not be possible in all direct categories.

Algebras as a displayed category algebras-displayed

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. The 𝐹-algebras form a displayed category AlgStr(𝐹) over 𝒞︀.

Over an object 𝑥, a displayed object of AlgStr(𝐹) is a structure map

𝛼∈𝒞︀(𝐹𝑥,𝑥).

Over 𝑓:𝑥→𝑦, a displayed morphism from 𝛼 to 𝛽 is the proposition that 𝑓 is an algebra homomorphism:

𝛼⋆𝑓=𝐹𝑓⋆𝛽.

The total category Alg(𝐹)=∫AlgStr(𝐹) is the category of 𝐹-algebras.

The co-Eilenberg–Moore category as a displayed category co-eilenberg-moore-displayed

A comonad on 𝒞︀ is a monad 𝑊 on 𝒞︀op. Everything about its coalgebras is then inherited from the Eilenberg–Moore construction, instantiated at the opposite category — nothing is defined twice.

Algebras of 𝑊 over 𝒞︀op are coalgebras 𝛾∈𝒞︀(𝑥,𝑊𝑥) of the underlying endofunctor, and the monad algebra laws, read in 𝒞︀op, are the comonad coalgebra laws — the unit and multiplication of 𝑊, viewed in 𝒞︀, are the counit 𝜀 and comultiplication 𝛿:

𝛾⋆𝜀𝑥=𝗂𝖽𝑥𝛾⋆𝛿𝑥=𝛾⋆𝑊𝛾.

The co-Eilenberg–Moore category is the opposite of the total category:

coEM(𝑊)=(EM(𝑊))op.

Coalgebras as a displayed category coalgebras-displayed

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. Coalgebras require no new construction: a coalgebra is an algebra in the opposite category. Define

CoalgStr(𝐹)=AlgStr(𝐹op),

a displayed category over 𝒞︀op, where 𝐹op:𝒞︀op→𝒞︀op is 𝐹 acting on the opposite category.

Concretely, over an object 𝑥 a displayed object is a structure map

𝛾∈𝒞︀(𝑥,𝐹𝑥).

The category of coalgebras is the opposite of the total category:

Coalg(𝐹)=(∫CoalgStr(𝐹))op.

The outer opposite returns morphisms to the direction of 𝒞︀: a morphism (𝑥,𝛾)→(𝑦,𝛿) is a map 𝑓:𝑥→𝑦 with

𝑓⋆𝛿=𝛾⋆𝐹𝑓.

Definition. The comparison functor of an adjunction comparison-functor

An adjunction 𝐹⊣𝑈 with 𝐹:𝒞︀→𝒟︀ and 𝑈:𝒟︀→𝒞︀ induces a monad 𝑇=𝑈∘𝐹 on 𝒞︀. Write 𝜀:𝐹∘𝑈⇒𝖨𝖽 for the counit of the adjunction. Every object 𝑑 of 𝒟︀ then induces a 𝑇-algebra carried by the object 𝑈𝑑, witnessed by the map

𝑈𝜀𝑑:𝑈𝐹𝑈𝑑→𝑈𝑑.

This assignment extends to a functor into the Eilenberg–Moore category,

𝐾:𝒟︀→EM(𝑇),

the comparison functor of the adjunction.

Dually, an adjunction induces a comonad on the other side and a comparison into the co-Eilenberg–Moore category. When these comparisons are equivalences we say that the adjunction 𝐹⊣𝑈 is (co)monadic.

Definition. Direct categories direct-category

A well-founded order is a set 𝐷 with a proposition-valued transitive relation < admitting no infinite descent: every element is accessible. Write 𝑎≤𝑏 for (𝑎<𝑏)∨(𝑎=𝑏).

A direct structure on a category 𝒞︀ over (𝐷,<) is a functor

deg:𝒞︀→(𝐷,≤)

into the well-founded order viewed as a poset category. The functor organizes two pieces of data at once: an ordering on the objects, and the invariant that morphisms respect it — 𝑓:𝑥→𝑦 forces deg𝑥≤deg𝑦.

A direct structure equips the objects with a well-founded strict relation

𝑥≺𝑦⟺deg𝑥<deg𝑦.

Intuitively, direct categories are the right generalization of well-foundedness to the categorical setting: a direct category is essentially one whose underlying graph is a directed acyclic graph, layered by degree, so that data at an object may be defined by recursion from data at all objects strictly below it.

The degrees order the objects, while the morphisms of 𝒞︀ say how an object sits over its predecessors.

Definition. Earlier on presheaves earlier-presheaf

Later takes a limit over smaller indices. Dually, the earlier modality takes a colimit over larger indices: an element of ⊲𝑃 at 𝑥 is a 𝑃-element sitting at some object 𝑦 strictly above 𝑥, carried down along a chosen morphism 𝑥→𝑦.

Earlier is left adjoint to later:

⊲⊣⊳

Under this adjunction, 𝗇𝖾𝗑𝗍:𝑃→⊳𝑃 corresponds to

𝗉𝗋𝖾𝗏:⊲𝑃→𝑃,

.

The Eilenberg–Moore category as a displayed category eilenberg-moore-displayed

Fix a monad (𝑇,𝜂,𝜇) on 𝒞︀. Its Eilenberg–Moore category arises in two displayed layers. The first layer is the displayed category of algebras AlgStr(𝑇) of the underlying endofunctor.

The second layer, EMStr(𝑇), is displayed over the total category Alg(𝑇). Over an algebra (𝑥,𝛼) the displayed objects are the propositions that 𝛼 satisfies the monad algebra laws:

𝜂𝑥⋆𝛼=𝗂𝖽𝑥𝜇𝑥⋆𝛼=𝑇𝛼⋆𝛼.

The Eilenberg–Moore category is the total category of the tower:

EM(𝑇)=∫EMStr(𝑇).

Definition. Initial algebra initial-algebra

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. An initial 𝐹-algebra, written 𝜇𝐹, is an initial object of the category of algebras Alg(𝐹).

Unfolding the universal property: an initial algebra is an algebra (𝜇𝐹,in) such that every algebra (𝑥,𝛼) admits a unique morphism fold𝛼:𝜇𝐹→𝑥 satisfying

in⋆(fold𝛼)=𝐹(fold𝛼)⋆𝛼.

Definition. Later on families later-family

Conjugation with the adjunction between presheaves and families 𝑈⊣Cofree lets us induce a later construction on families from the one on presheaves,

⊳Fam=𝑈∘⊳∘Cofree:Fam(𝒞︀)→Fam(𝒞︀).

Concretely, later on families evaluates to

⊳Fam𝐴(𝑥)≅∏𝑦≺𝑥 ∏𝑓:𝑦→𝑥𝐴(𝑦)

Definition. Later on presheaves later-presheaf

The later modality for presheaves on a direct category is given by the presheaf of natural transformations

out of the strict downset.

(⊳𝑃)(𝑥)=𝖯𝗌𝗁𝒞︀(𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥),𝑃).

An element of ⊳𝑃 at 𝑥 is a coherent choice of 𝑃-elements at all objects strictly smaller than 𝑥.

Restriction in ⊳𝑃 along 𝑓:𝑦→𝑥 precomposes with the induced map 𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑦)→𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥). At an object of minimal degree the strict downset is empty, so ⊳𝑃 is trivial there.

Via functoriality, every presheaf restricts to smaller indices. Thus we may define the map

𝗇𝖾𝗑𝗍:𝑃→⊳𝑃

that sends an element 𝑝 over 𝑥 to the family of all its restrictions along morphisms from strictly lower objects.

Theorem. Löb induction on families lob-family

Like later on families, the recursion principle for families is inherited from that on presheaves. Given a family 𝐴 and a step

𝜑𝑥:⊳Fam𝐴(𝑥)→𝐴(𝑥)for each 𝑥,

the construction is a chain of transpositions with Löb for presheaves used in the middle:

Just as for presheaves, the fixed point constructed above is unique: the two transpositions are bijections, and the presheaf-level fixed point is already unique.

Theorem. Löb induction for presheaves on a direct category lob-presheaf

Let 𝒞︀ be a direct category and 𝑃 a presheaf on it. Every map

𝜑:⊳𝑃→𝑃

has a fixed point: a global element 𝗅ö𝖻𝜑:⊤→𝑃 with

𝗅ö𝖻𝜑=𝗅ö𝖻𝜑⋆𝗇𝖾𝗑𝗍⋆𝜑,

and this fixed point is unique.

The hypothesis says: the value of 𝑃 at any object is determined by its values over the strict past — 𝜑 turns a coherent family over the strict downset of 𝑥 into a value at 𝑥. The proof is recursion along the well-founded ≺: at each 𝑥, the section already constructed over the past assembles into an element of (⊳𝑃)(𝑥), and 𝜑 extends it to 𝑥.

Definition. Locally contractive endofunctors locally-contractive-functor

Write 𝑋⇒𝑌 for the presheaf of morphisms 𝑋→𝑌. An endofunctor 𝐹 on presheaves is locally contractive when its action on morphisms factors through later: there is a map

𝐹𝛿:⊳(𝑋⇒𝑌)→(𝐹𝑋⇒𝐹𝑌)

Definition. Monadicity and comonadicity monadicity-comonadicity

An adjunction 𝐹⊣𝑈 with 𝐹:𝒞︀→𝒟︀ and 𝑈:𝒟︀→𝒞︀ induces a monad 𝑇=𝑈∘𝐹 on 𝒞︀, and a comparison functor

𝐾:𝒟︀→EM(𝑇)

sending each object of 𝒟︀ to the 𝑇-algebra it carries.

The functor 𝑈 is monadic when 𝐾 is an equivalence: the adjunction exhibits 𝒟︀ as objects of 𝒞︀ equipped with algebraic structure for 𝑇, the Eilenberg–Moore category.

Comonadicity is monadicity in the opposite category: a left adjoint 𝐿:𝒟︀→𝒞︀ with right adjoint 𝑅 induces a comonad 𝑊=𝐿∘𝑅 on 𝒞︀, a comparison 𝒟︀→coEM(𝑊) into the co-Eilenberg–Moore category, and 𝐿 is comonadic when this comparison is an equivalence.

The adjoint triple between presheaves and families presheaf-family-adjoint-triple

A family over 𝒞︀ is a set 𝐴(𝑥) for each object 𝑥, with no action of morphisms. Families form a category Fam(𝒞︀): a morphism 𝐴→𝐵 is a function 𝐴(𝑥)→𝐵(𝑥) for each 𝑥.

Forgetting the restriction maps of a presheaf gives a functor

𝑈:𝖯𝗌𝗁𝒞︀→Fam(𝒞︀).

It has both a left and a right adjoint,

Free⊣𝑈⊣Cofree.

The two adjoints demonstrate different means of forcing a family to be functorial. The right adjoint universally quantifies over morphisms in,

Cofree(𝐴)(𝑥)=∏𝑦𝒞︀(𝑦,𝑥)→𝐴(𝑦),

with restriction along 𝑓 given by precomposition. The left adjoint instead existentially quantifiers over morphisms out:

Free(𝐴)(𝑥)=∑𝑦𝒞︀(𝑥,𝑦)×𝐴(𝑦),

with restriction acting on the first component. (For Free we ask that 𝒞︀ have a set of objects, so that this sum is a set and thus Free defines a presheaf.)

Theorem. Presheaves are monadic and comonadic over families presheaves-monadic-comonadic-over-families

The adjoint triple Free⊣𝑈⊣Cofree induces a monad 𝑇=𝑈∘Free and a comonad 𝑊=𝑈∘Cofree on Fam(𝒞︀).

Both comparison functors are equivalences: presheaves are the Eilenberg–Moore algebras of 𝑇 and the co-Eilenberg–Moore coalgebras of 𝑊,

𝖯𝗌𝗁𝒞︀≃EM(𝑇)𝖯𝗌𝗁𝒞︀≃coEM(𝑊).

So presheaves are both monadic and comonadic over families.

Reading the algebra structure concretely: a 𝑇-algebra on a family 𝐴 is a map ∑𝑦𝒞︀(𝑥,𝑦)×𝐴(𝑦)→𝐴(𝑥) for each 𝑥, subject to the monad algebra laws — that is, exactly a functorial action of restriction.

The comonadic reading is the same structure seen from the element’s side: a 𝑊-coalgebra is a map 𝐴(𝑥)→∏𝑦𝒞︀(𝑦,𝑥)→𝐴(𝑦), giving each value its restriction along every morphism into 𝑥. Where the monad says restriction acts on values, the comonad says a value already carries all of its restrictions — and the coalgebra laws say it does so coherently.

Definition. Proper and maximal sieves proper-maximal-sieve

The representable 𝗒𝑥 is itself a sieve on 𝑥. A sieve on 𝑥 is proper when it is not equal to the representable.

Say that a proper sieve is maximal when it contains all other proper sieves as a sub-sieve.

Definition. Sieves sieve

A sieve on an object 𝑥 of 𝒞︀ is a subobject of the representable presheaf 𝗒𝑥: a presheaf 𝑆 with a monic morphism 𝑆↣𝗒𝑥. Sieves are a generalization from the notion of ideal found in ring theory to category theory.

A morphism 𝑓:𝑦→𝑥 belongs to 𝑆, written 𝑆∋𝑓, when 𝑓 lies in the image of the inclusion at 𝑦. Because 𝑆 is a presheaf and the inclusion is natural, membership is closed under precomposition:

𝑆∋𝑓⇒𝑆∋𝑔⋆𝑓for every 𝑔:𝑧→𝑦.

A sieve is thus a “downward closed” collection of morphisms into 𝑥.

Sieves on 𝑥 are ordered by refinement: 𝑆⊆𝑇 when every morphism belonging to 𝑆 belongs to 𝑇.

Theorem. Maximality of the strict downset among proper sieves strict-downset-maximal

Call a direct structure reflecting when every morphism between objects of equal degree is a split epimorphism. In a reflecting direct category, every non-invertible-in-degree morphism strictly raises degree, and the strict downset is as large as a proper sieve can be:

If the direct structure is reflecting, then every proper sieve 𝑆 on 𝑥 refines into the strict downset:

𝑆⊆𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥).

Suppose 𝑓∈𝑆 with 𝑓:𝑦→𝑥 of equal degree. By reflection 𝑓 has a section 𝑠, and closure under precomposition gives 𝑠⋆𝑓=𝗂𝖽𝑥∈𝑆, contradicting properness.

So every morphism in 𝑆 strictly raises degree. That is, every morphism in 𝑆 is also a member of 𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥).

Definition. The strict downset sieve of a direct category strict-downset-sieve

Let 𝒞︀ carry a direct structure. The strict downset 𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥) of an object 𝑥 is the presheaf of morphisms into 𝑥 from strictly lower objects:

𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥)(𝑦)={𝑓:𝑦→𝑥∣𝑦≺𝑥},

with restriction by precomposition — well defined since degrees are non-decreasing, so precomposing can only stay strictly below.

The evident inclusion 𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥)↣よ𝑥 makes 𝖲𝗍𝗋𝗂𝖼𝗍𝖣𝗈𝗐𝗇(𝑥) a sieve on 𝑥. It is moreover a proper sieve, as it exlcudes the identity.

Definition. Terminal coalgebra terminal-coalgebra

Fix an endofunctor 𝐹:𝒞︀→𝒞︀. A terminal 𝐹-coalgebra, written 𝜈𝐹, is a terminal object of the category of coalgebras Coalg(𝐹) — equivalently, an initial algebra for 𝐹op.

Unfolding the universal property: a terminal coalgebra is a coalgebra (𝜈𝐹,out) such that every coalgebra (𝑥,𝛾) admits a unique morphism unfold𝛾:𝑥→𝜈𝐹 satisfying

(unfold𝛾)⋆out=𝛾⋆𝐹(unfold𝛾).

Well-founded posets are thin direct categories well-founded-poset-as-thin

Every poset forms a thin category. Similarly, if the poset is well-founded then it induces a thin direct category.

Definition. Category category

A category 𝒞︀ consists of

  1. A type of objects 𝒞︀0
  2. For each pair of objects 𝑥,𝑦:𝒞︀0 a set of morphisms 𝒞︀(𝑥,𝑦). We may simply write a morphism with an arrow, denote 𝑓:𝒞︀(𝑥,𝑦) as 𝑓:𝑥→𝑦 or 𝑥→𝑓𝑦 or similar
  3. A composition operation on morphisms. For 𝑓:𝑥→𝑦 and 𝑔:𝑦→𝑧, there is a morphism 𝑓⋆𝑔:𝑥→𝑧
  4. For each 𝑥:𝒞︀0, an identity morphism 𝗂𝖽𝑥:𝑥→𝑥
  5. Left-unitality of composition: for all 𝑓:𝑥→𝑦, an equality

    𝗂𝖽𝖫𝑓:𝗂𝖽𝑥⋆𝑓=𝑓
  6. Right-unitality of composition: for all 𝑓:𝑥→𝑦, an equality

    𝗂𝖽𝖱𝑓:𝑓⋆𝗂𝖽𝑦=𝑓
  7. Associativity of composition: for all 𝑓:𝑥→𝑦, 𝑔:𝑦→𝑧, ℎ:𝑧→𝑤, an equality

    𝖺𝗌𝗌𝗈𝖼𝑓,𝑔,ℎ:(𝑓⋆𝑔)⋆ℎ=𝑓⋆(𝑔⋆ℎ)

Concretely, the definition above is meant to model the one used in the Cubical standard library [1].

However, the notion of category is flexible. Depending on the context, we may be talking of small, locally small, wild, or any other kind of category that may augment which things we require to be (homotopy) sets, which things we require to be small types, etc. For the most part, the same idea of a category will apply across all of these settings.

Definition. Bicategory bicategory

A bicategory is a notion of weak 2-category that arises as a category weakly enriched in categories. That is, instead of having hom sets, between any two objects a bicategory has hom categories such that the enriched category laws hold up to invertible 2-cell rather than strictly.

A bicategory 𝒦︀ consists of

  1. A type of objects 𝒦︀0, or 0-cells
  2. For all 𝑥,𝑦:𝒦︀0, a category 𝒦︀1(𝑥,𝑦). We may elide the subscript and simply write this as 𝒦︀(𝑥,𝑦). Refer to the objects of 𝒦︀(𝑥,𝑦) as 1-cells between 𝑥 and 𝑦, and we may write 𝑓:𝒦︀(𝑥,𝑦) as 𝑓:𝑥→𝑦 or 𝑥→𝑓𝑦. For 𝑓,𝑔:𝒦︀(𝑥,𝑦), refer to the morphisms in 𝒦︀(𝑥,𝑦) between 𝑓 and 𝑔 as 2-cells and write the morphism 𝛼:(𝒦︀(𝑥,𝑦))(𝑓,𝑔) as 𝛼:𝑓⇒𝑔 or 𝑓⇒𝛼𝑔
  3. For each 𝑥:𝒦︀0, an identity 1-cell 1𝑥:𝒦︀(𝑥,𝑥)
  4. For all 𝑥,𝑦,𝑧:𝒦︀0, a composition functor 𝒦︀⋆𝑥,𝑦,𝑧:𝒦︀(𝑥,𝑦)×𝒦︀(𝑦,𝑧)→𝒦︀(𝑥,𝑧). For 1-cells 𝑓:𝑥→𝑦 and 𝑔:𝑦→𝑧, write their composite as 𝑓⋆𝑔:𝑥→𝑧
  5. For all 𝑤,𝑥,𝑦,𝑧:𝒦︀0, a natural isomorphism, the associator 𝛼 between the two composite functors 𝒦︀(𝑤,𝑥)×𝒦︀(𝑥,𝑦)×𝒦︀(𝑦,𝑧)→𝒦︀(𝑤,𝑧) that compose the leftmost, respectively rightmost, pair first:

    𝒦︀⋆𝑤,𝑦,𝑧∘(𝒦︀⋆𝑤,𝑥,𝑦×id)⇒𝒦︀⋆𝑤,𝑥,𝑧∘(id×𝒦︀⋆𝑥,𝑦,𝑧)

    Its component at 1-cells 𝑓,𝑔,ℎ is the invertible 2-cell

    𝛼𝑓,𝑔,ℎ:(𝑓⋆𝑔)⋆ℎ⇒𝑓⋆(𝑔⋆ℎ)
  6. For all 𝑥,𝑦:𝒦︀0, natural isomorphisms, the left unitor 𝜆 and right unitor 𝜌, each between an endofunctor of 𝒦︀(𝑥,𝑦) and the identity functor:

    𝒦︀⋆𝑥,𝑥,𝑦∘⟨1𝑥,id⟩⇒id𝒦︀⋆𝑥,𝑦,𝑦∘⟨id,1𝑦⟩⇒id

    where 1𝑥 and 1𝑦 in the pairings ⟨−,−⟩ denote the constant functors at the identity 1-cells. The components at a 1-cell 𝑓:𝒦︀(𝑥,𝑦) are the invertible 2-cells

    𝜆𝑓:1𝑥⋆𝑓⇒𝑓𝜌𝑓:𝑓⋆1𝑦⇒𝑓
  7. such that for all 𝑓:𝒦︀(𝑥,𝑦) and 𝑔:𝒦︀(𝑦,𝑧) the triangle below commutes in 𝒦︀(𝑥,𝑧):

  8. and such that for all composable 1-cells 𝑓,𝑔,ℎ,𝑘 the pentagon below commutes:

Definition. Monad in a bicategory monad-in-a-bicategory

Fix a bicategory 𝒦︀, with composition ⋆, identity 1-cells 1𝑥, associator 𝛼, and unitors 𝜆,𝜌. A monad in 𝒦︀ internalises the usual notion of monad: it is an endo-1-cell carrying a multiplication and a unit that satisfy the monoid laws up to the coherence cells of the bicategory.

A monad in 𝒦︀ consists of

  1. a 0-cell 𝑥, the object the monad acts on;
  2. an endo-1-cell 𝑡:𝒦︀(𝑥,𝑥);
  3. a multiplication 2-cell 𝜇:𝑡⋆𝑡⇒𝑡;
  4. a unit 2-cell 𝜂:1𝑥⇒𝑡;
  5. such that 𝜇 is associative: the following diagram of 2-cells commutes in 𝒦︀(𝑥,𝑥), where the top map is the associator that rebrackets the threefold composite:

  6. and such that 𝜇 and 𝜂 satisfy the unit laws: the following two diagrams commute in 𝒦︀(𝑥,𝑥), where the hypotenuses are the left and right unitors:

Taking 𝒦︀ to be the bicategory of categories, functors, and natural transformations recovers an ordinary monad on a category: 𝑡 is the endofunctor, 𝜇 the multiplication, and 𝜂 the unit, with the coherence cells all identities.

Definition. Free Monoidal Category over a Set free-monoidal-category

Fix a set 𝑋. The objects of the free monoidal category over 𝑋, 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋), are generated inductively by the elements of 𝑋 and a unit element 𝐼 over a binary operation ⊗. The morphisms are given by a quotient-inductive type. They are generated by associators, unitors, and identity over composition and parallel action over ⊗ then quotiented by associativity and composition equation to satisfy the category laws, equations constraining the associators/unitors to be natural isomorphisms, and pentagon/triangle equations to satiate the axioms of a monoidal category.

Definition 0.1. Global Elimination Principle for the Free Monoidal Category free-monoidal-category-elimination

Given any displayed monoidal category 𝑀𝙳 over 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋) with an interpretation 𝜄:𝑋⇝𝑀𝙳, we may construct a global section 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋)→𝑀𝙳. We refer to this as the global elimination principle of 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋).

Definition. Global Elimination Principle for the Free Monoidal Category free-monoidal-category-elimination

Given any displayed monoidal category 𝑀𝙳 over 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋) with an interpretation 𝜄:𝑋⇝𝑀𝙳, we may construct a global section 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋)→𝑀𝙳. We refer to this as the global elimination principle of 𝖥𝗋𝖾𝖾𝖬𝗈𝗇(𝑋).

Products of Categories as Total Categories product-as-total-category

Given categories 𝒞︀ and 𝒟︀, 𝒞︀×𝒟︀ is equivalent to the total category of weakening.

Definition. Quiver quiver

A quiver is just a directed graph presented via a type of objects, a type of edges, and two projection functions that pick out source and target of an edge.

Definition. Thin Category thin-category

A category 𝐶 is thin if there is at most one morphism between any two objects.

Definition. Element of a Presheaf element-of-presheaf

An element of a presheaf 𝑃 at an object 𝑐 is an element 𝑥 of the set 𝑃𝑐.

Definition. Universal Element of a Presheaf universal-element

A universal element of a presheaf 𝑃 on a category 𝐶 is an element 𝑥∈𝑃𝑐, where 𝑐 is some object of 𝐶, demonstrating that 𝑃 is representable by 𝑐.

𝑃≅よ𝑐

(Slightly) more concretely, a universal element is captured by the following three pieces of data

  • An object 𝑐 of 𝐶
  • An element 𝑥∈𝑃𝑐
  • A proof that the map sending a morphism 𝑓:𝑏→𝑐 to (𝑃𝑓)(𝑥) is an equivalence

This third point states that morphisms from 𝑏 into 𝑐 are uniquely determined by an element of 𝑃 at the domain 𝑏.

Or equivalently, universal elements are terminal in the category of elements.

What is a universal property, really? universal-property

Universal properties are a convenient method for defining an object in a category up to isomorphism. Rather than giving a concrete, bottom-up construction of an object, we can instead uniquely specify its behavior.

Consider the example of products in a category 𝐶. We say that the product of 𝑐 and 𝑑 is any object 𝑝 of 𝐶 such that the following diagram commutes.

We say that 𝑝 satisfies the universal property of the product of 𝑐 and 𝑑.

Surely this matches our set-based intuition of what a product should behave like. Similarly, we can sketch out constructions of other universal properties like initial objects, terminal objects, exponentials, etc. However, what is precisely meant by the term universal property?

The notion of a universal property is made precise by the notion of a universal element of a presheaf. That is, an object satisfies a universal property if we can build a universal element of the appropriate presheaf at that object.

Let’s look at the universal element characterization of the products example. Note that a map into a product is determined by a map into each component. To map into 𝑐×𝑑, we need both a map into 𝑐 and a map into 𝑑, as in the above diagram. That is, to build a map 𝑏→𝑐×𝑑, we must simultaneously provide elements of よ𝑐 and よ𝑑 at 𝑏.

Using the product of presheaves, this means we are providing a single element of the presheaf (よ𝑐)×(よ𝑑). Quite nicely, the universal element of this presheaf provides the object of 𝐶 that is the product of 𝑐 and 𝑑. The universal element, provided that it exists, contains the following data:

  • An object 𝑝
  • An element 𝑥∈(よ𝑐×よ𝑑)𝑝
  • A proof that the map sending 𝑓:𝑏→𝑝 to a pair of maps 𝑓1:𝑏→𝑐, 𝑓2:𝑏→𝑑 is an equivalence. Therefore, any element of よ𝑐×よ𝑑 factors through 𝑥

Recall that the product of presheaves is computed pointwise in the category of sets, so if we expand the type of the element 𝑥 above we find that 𝑥 is a pair of maps 𝑝→𝑐 and 𝑝→𝑑.

(よ𝑐×よ𝑑)𝑝≅(よ𝑐𝑝)×(よ𝑑𝑝)

The first part of this pair is precisely 𝜋1. Correspondingly, the second part of this pair is 𝜋2. Finally, the universality of the element 𝑥 (i.e. the proof that any other element factors through 𝑥) captures our commutative diagram from above.

This is a very rough sketch of what a universal property is, and has elided for now an important application of the Yoneda lemma. In any case, all a universal property is really saying is that a particular presheaf is representable; and, rather elegantly, a universal element of a presheaf is convenient packaging of that representability proof.

In summary, universal properties are not as ad-hoc as they may initially seem, and the language of presheaves provides a reusable and precise definition that can be instantiated to describe a very large class of properties.

Definition. Constant Presheaf constant-presheaf

The constant presheaf of a set 𝑋 on a category 𝐶 is a functor Δ(𝑋):𝐶𝑜𝑝→𝐒𝐞𝐭 such that

Δ(𝑋)𝑐≔𝑋

I often call this the discrete presheaf for 𝑋, but I don’t know if that’s standard.

Finite Cardinal Arithmetic in a Topos finite-cardinal-arithmetic-topos

In a topos with a natural numbers object (𝑁,𝑧,𝑠), you can define finite cardinals as objects that arise as the pullback along a morphism 𝑝:⊤→𝑁 of the generic finite cardinal. Write [𝑝] for the cardinal corresponding to 𝑝.

The above characterization is a little obtuse and does warrant some more explanation. One way to make it more concrete is that [𝑧]=⊥ and [𝑠∘𝑛]=⊤⊕[𝑛], and that finite cardinals warrant a nice induction principle. If 𝑃 is a property expressible in the internal language such that ⊥ satisfies 𝑃, and that whenever 𝐴 satisfies 𝑃 then ⊤⊕𝐴 satisfies 𝑃; then every finite cardinal satisfies 𝑃. That is, 𝑃 forms a (𝑧,𝑠)-closed subobject of 𝑁 and thus 𝑃 is all of 𝑁.

My working mental model is in a presheaf topos, where the natural numbers object can be defined explicitly as Δ(ℕ).

Definition 0.2. Constant Presheaf constant-presheaf

The constant presheaf of a set 𝑋 on a category 𝐶 is a functor Δ(𝑋):𝐶𝑜𝑝→𝐒𝐞𝐭 such that

Δ(𝑋)𝑐≔𝑋

I often call this the discrete presheaf for 𝑋, but I don’t know if that’s standard.

The finite cardinals with respect to Δ(ℕ) can be characterized then as,

[0]≔⊥
[𝗌𝗎𝖼(𝑛)]≔⊤⊕[𝑛]

These obey nice algebraic properties.

[𝑛𝑚]≅[𝑛]×[𝑚]
[𝑛+𝑚]≅[𝑛]⊕[𝑚]
[𝑛𝑚]≅[𝑚]→[𝑛]

Definition. Subobject subobject

In a category 𝒞︀, a subobject of 𝑐 is an isomorphism class of monomorphisms into 𝑐.

Definition. Terminal Object terminal-object

An object 𝑐 in a category 𝒞︀ is terminal if there is a unique morphism from any other object into it.

Because terminal objects are unique up to unique isomorphism (as are all universal objects) we often just write ⊤ to refer to the terminal object. Likewise, !:𝑑→⊤ refers to the unique morphism into ⊤.

Definition. Equalizer equalizer

Let 𝑐 and 𝑑 be objects in a category 𝒞︀ with two parallel morphisms 𝑓,𝑔:𝑐→𝑑. The equalizer of 𝑓 and 𝑔, if it exists, is the universal object 𝖾𝗊 with the following property:

  • There is a morphism 𝜋:𝖾𝗊→𝑐
  • 𝑓∘𝜋=𝑔∘𝜋

Constructing Equalizers in Type Theory equalizers-in-type-theory

In the presence of Σ-types, one may construct all equalizers. Given types 𝐴 and 𝐵 with functions 𝑓,𝑔:𝐴→𝐵, the equalizer may be constructed as

𝖾𝗊𝑓,𝑔≔∑𝑎:𝐴(𝑓(𝑎)=𝑔(𝑎))

Definition. Subobject Classifier subobject-classifier

Subsets 𝐴 of a set 𝑋 may classically be identified with a characteristic map 𝜒𝐴:𝑋→𝖻𝗈𝗈𝗅. Intuitively, for every 𝑥:𝑋, 𝜒𝐴 gives a truth value to the statement “𝑥 is in the subset 𝐴”. In this manner, the domain of the characteristic map, 𝖻𝗈𝗈𝗅, classifies the subsets of 𝑋.

Generalizing over this principle, in a category 𝒞︀ an object Ω is a subobject classifier if maps into it from some object 𝑐 likewise uniquely identify a subobject of 𝑐.

We can understand Ω to behave like an object of truth values that are not necessarily boolean valued. A morphism 𝑝:𝑐→Ω can be thought of like a predicate on 𝑐. If 𝑐 were a set, this would precisely be the characteristic function on it. However, this idea can generalize beyond sets. For instance in the category of graphs, Ω is a cleverly constructed graph such that any graph homomorphism 𝑔→Ω into it picks out a unique subgraph of 𝑔.

There are always two (suggestively named) disjoint “points” of Ω, thought of as morphisms out of the terminal object 𝗍𝗋𝗎𝖾,𝖿𝖺𝗅𝗌𝖾:⊤→Ω. I think if we’re being careful, 𝗍𝗋𝗎𝖾 may properly be the “subobject classifier” but I always use the term to refer to Ω itself.

A subobject 𝜙:𝑑↪𝑐 induces a unique characteristic morphism 𝑝𝜙:𝑐→Ω such that

𝑝𝜙∘𝜙=𝗍𝗋𝗎𝖾∘!𝑑

Moreover, the appropriate square must be a pullback.

Definition. Closed Monoidal Structure closed-monoidal-category

A monoidal category is left closed if for each 𝑌∈𝐶, the functor −⊗𝑌:𝐶→𝐶 has a right adjoint 𝑌⊸−:𝐶→𝐶 forming the left internal-hom out of 𝑌.

That is, for all 𝑋,𝑌,𝑍, there is a natural isomorphism 𝐶[𝑋⊗𝑌,𝑍]≅𝐶[𝑋,[𝑌,𝑍]]

There is an obvious right-handed variant 𝑌⟜− that is right adjoint to 𝑌⊗−.

If 𝐶 is both right and left closed, the monoidal category is simply called closed (or perhaps biclosed).

Definition. Monoidal Category monoidal-category

A monoidal category is a category 𝒞︀ together with

  1. a functor ⊗:𝒞︀×𝒞︀→𝒞︀, the tensor product;
  2. an object 𝐼 of 𝒞︀, the unit;
  3. natural isomorphisms

    𝛼𝑥,𝑦,𝑧:(𝑥⊗𝑦)⊗𝑧→𝑥⊗(𝑦⊗𝑧)𝜆𝑥:𝐼⊗𝑥→𝑥𝜌𝑥:𝑥⊗𝐼→𝑥

    the associator, left unitor and right unitor;

such that the triangle and the pentagon below commute for all objects 𝑤,𝑥,𝑦,𝑧.

Definition. Category of Elements category-of-elements

Let 𝑃 be a presheaf on a category 𝒞︀. The category of elements of 𝑃 is the displayed category over 𝒞︀ whose displayed objects over 𝑐 are the elements 𝑝∈𝑃𝑐, and whose displayed morphisms over 𝑓:𝑐→𝑑 from 𝑝 to 𝑞 are proofs that (𝑃𝑓)(𝑞)=𝑝.

Since 𝑃𝑐 is a set, there is at most one displayed morphism over each 𝑓 between given elements: a morphism of elements is a morphism of 𝒞︀ that happens to carry 𝑞 back to 𝑝. Its total category is the classical category of elements ∫𝑃, and a universal element of 𝑃 is exactly a terminal object of ∫𝑃.

mechanized-category-theory note entries/home/mechanized-category-theory.hel