Steven Schaefer

Steven Schaefer

I am a PhD candidate at the University of Michigan, where I am advised by Max New.

I study the design and implementation of intrinsically correct software. In a sufficiently rich type system, a program’s type signature alone can carry a proof that it behaves as specified.

I am especially interested in verified compiler frontends, where parsing and typechecking algorithms can be built correct-by-construction.

Research Interests

Correct-by-Construction Parsing correct-by-construction-parsing

Parsers are some of the most important pieces of software that we have. You have likely relied on dozens of parsers to even read this message. Anytime someone writes a piece of high-level code, it must be parsed into a representation that is workable for the machine.

Because parsers are so ubiquituous, the correctness of so many other programs is contingent on a bug-free parser. Despite this fundamental reliance, parsers are often unverified. Buggy parsers have led to many critical security vulnerabilities. Even in otherwise verified software development, parsing is usually unverified (or the final component to become verified).

To address this gap, we develop Lambek𝙳, a domain-specific programming language for writing intrinsically correct parsers. That is, if a parser written in Lambek𝙳 compiles then we guarantee the resulting program is sound with respect to its parsing semantics.

I first explored this idea in Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus, and it will be the focus of my dissertation.

Notes and sketches of ongoing work in Lambek𝙳 may be found below and throughout this site.

30 entries

Definition 0.0.1. Representable Grammars representable-grammar

For any string 𝑀, we can define a representable grammar βŒˆπ‘€βŒ‰ which matches exactly the string 𝑀 and nothing else. The parse trees for a representable grammar are proofs that the string is exactly equal to 𝑀:

βŒˆπ‘€βŒ‰(𝑒)=(𝑒≑𝑀)

0.0.2 Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus pldi-2025-talk

We present Dependent Lambek Calculus, a domain-specific dependent type theory for verified parsing and formal grammar theory. In Dependent Lambek Calculus, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the types as a mathematical notion of formal grammars. Based on this denotational semantics, we have made a prototype implementation of Dependent Lambek Calculus using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

Event Β· Slides Β· Video

0.0.3 Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus intrinsic-verification-of-parsers

We present Dependent Lambek Calculus (Lambek𝙳), a domain-specific dependent type theory for verified parsing and formal grammar theory. In Lambek𝙳, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the linear types as functions from strings to sets of abstract parse trees and terms as parse transformers. Based on this denotational semantics, we have made a prototype implementation of Lambek𝙳 using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

PDF Β· DOI Β· arXiv (extended version) Β· Source code Β· pldb

Definition 0.0.4. A Grammar of Finite Cardinals finite-cardinal-grammar

Define a grammar for each finite cardinal 𝑛:β„•.

[0]≔βŠ₯
[π—Œπ—Žπ–Ό(𝑛)]β‰”βŠ€βŠ•[𝑛]

Then define the grammar of all finite cardinals as

π–₯𝗂𝗇≔⨁𝑛:β„•[𝑛]

Definition 0.0.5. Finite Unambiguity finite-unambiguity

Define a grammar 𝐴 to be finitely unambiguous if 𝐴&𝐴≅𝐴.

There is likely a better name for this.

0.0.6 Finite Unambiguity is Not Equivalent to Unambiguity finite-unambiguity-not-unambiguity

For a while I believed finite unambiguity to be equivalent to the other definitions of unambiguity.

Definition 0.0.6.1. Finite Unambiguity finite-unambiguity

Define a grammar 𝐴 to be finitely unambiguous if 𝐴&𝐴≅𝐴.

There is likely a better name for this.

Definition 0.0.6.2. Unambiguity as Subterminality unambiguity-as-subterminality

A grammar 𝐴 is unambiguous if the unique map into the terminal object is a monomorphism. That is, 𝐴 is a subobject of ⊀.

Definition 0.0.6.3. Unambiguity as Unique Map into Codomain unambiguity-as-unique-map

A grammar 𝐴 is unambiguous if for all grammars 𝐡 and maps 𝑒,𝑒′:𝐴⊒𝐡 we have 𝑒=𝑒′.

In a category with terminal objects, this is equivalent to unambiguity defined via subterminality.

Definition 0.0.6.3.1. Unambiguity as Subterminality unambiguity-as-subterminality

A grammar 𝐴 is unambiguous if the unique map into the terminal object is a monomorphism. That is, 𝐴 is a subobject of ⊀.

We may use an analogy from the category of sets, however I had missed the infinite case when translating this idea to grammars.

It is true that if a grammar is unambiguous, then it is finitely unambiguous. However, the converse does not hold unless the grammar has finitely many parse trees for each string. This finiteness condition is a semantic one. If this proof of unambiguity were to be internalized, then it could maybe be captured through the lens of some grammar of finite cardinals.

Let 𝐴≔⨁𝑛:β„•βŠ€. 𝐴 is finitely unambiguous but not unambiguous. The isomorphism between 𝐴 and 𝐴&𝐴 amounts to building a bijection between β„• and β„•Γ—β„•, which is straightforward.

0.0.7 What Connectives Preserve Finiteness? finiteness-preserving-connectives

In order to bridge the gap between finite unambiguity and unambiguity, we can try to restrict to grammars that have finitely many parse trees. We’d expect this to address the concern semantically, as that fixes the problem when the parses are interpreted in π’πžπ­.

We can define when a grammar is finite, and then try to prove that finiteness is preserved on some sane operations on grammars. For instance, &, βŠ•, and β†’ each preserve finiteness. I haven’t proven this myself (which would be a useful exercise), but the following is substantiated in any topos with a natural numbers object [johnstone-2002].

0.0.7.1 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.0.7.1.1. 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.

[π‘›π‘š]β‰…[𝑛]Γ—[π‘š]
[𝑛+π‘š]β‰…[𝑛]βŠ•[π‘š]
[π‘›π‘š]β‰…[π‘š]β†’[𝑛]

The case of βŠ— is more problematic. Semantically, for all 𝑀:String we may bound the size of the set of parse trees

|(π΄βŠ—π΅)𝑀|≀Σ𝑀1++𝑀2=𝑀|𝐴𝑀1||𝐡𝑀2|

Precisely knowing this bound isn’t too important, but certainly it exists. We could capture this behavior by just adding an axiom that if 𝐴 and 𝐡 are each finite, then π΄βŠ—π΅ is finite. Although, I’d rather not add an axiom.

We could directly try to prove that βŠ— preserves finiteness. The statement would follow from showing that βŠ— preserves monomorphisms. That is, if 𝑓:𝐴β†ͺ𝐢 and 𝑔:𝐡β†ͺ𝐷, it suffices to show that π‘“βŠ—π‘”:π΄βŠ—π΅β†’πΆβŠ—π· is a monomorphism. This would imply finiteness, because you may then apply this for 𝐢 and 𝐷 as π–₯𝗂𝗇. However, you would also need to show that π–₯π—‚π—‡βŠ—π–₯𝗂𝗇 is finite, which isn’t immediately clear.

0.0.8 Internal Finiteness internally-finite-grammar

Define a grammar 𝐴 to be finite (or perhaps subfinite) if it is a subobject of grammar of finite cardinals.

𝐴β†ͺπ–₯𝗂𝗇

Where π–₯𝗂𝗇 is defined as follows.

Definition 0.0.8.1. A Grammar of Finite Cardinals finite-cardinal-grammar

Define a grammar for each finite cardinal 𝑛:β„•.

[0]≔βŠ₯
[π—Œπ—Žπ–Ό(𝑛)]β‰”βŠ€βŠ•[𝑛]

Then define the grammar of all finite cardinals as

π–₯𝗂𝗇≔⨁𝑛:β„•[𝑛]

0.0.9 Star Continuity is a Semantic Property star-continuity-semantic-property

Star continuity in Dependent Lambek Calculus can often be a convenient proof technique, but it’s important to remember that this shouldn’t be the first line of defense.

Star continuity holds in the Agda model, but does it hold in the syntactic model? I believe that it does because of the presence of the indexed coproducts. So perhaps it isn’t so sinister after all. It is worth noting that much of the reasoning performed by inducting on the length of a Kleene star isn’t very elegant. If a proof necessitates star continuity, then it doesn’t seem to be aided greatly by the type system.

Definition 0.0.10. Unambiguity as Subterminality unambiguity-as-subterminality

A grammar 𝐴 is unambiguous if the unique map into the terminal object is a monomorphism. That is, 𝐴 is a subobject of ⊀.

Definition 0.0.11. Unambiguity as Unique Map into Codomain unambiguity-as-unique-map

A grammar 𝐴 is unambiguous if for all grammars 𝐡 and maps 𝑒,𝑒′:𝐴⊒𝐡 we have 𝑒=𝑒′.

In a category with terminal objects, this is equivalent to unambiguity defined via subterminality.

Definition 0.0.11.1. Unambiguity as Subterminality unambiguity-as-subterminality

A grammar 𝐴 is unambiguous if the unique map into the terminal object is a monomorphism. That is, 𝐴 is a subobject of ⊀.

Definition 0.0.12. Unambiguity via the Diagonal Being an Isomorphism unambiguity-via-diagonal

Finite unambiguity does not serve as an adequate definition of unambiguity that is equivalent to unambiguity as subterminality and unambiguity as a unique map. However, the definition attempted via finite unambiguity can be refined to something that is equivalent to these.

A grammar 𝐴 is unambiguous if Ξ”:𝐴⊒𝐴&𝐴 is an isomorphism. Equivalently, 𝐴 is unambiguous if πœ‹1:𝐴&𝐴⊒𝐴 and πœ‹2:𝐴&𝐴⊒𝐴 are equal.

0.0.13 Subobject Classifier in Dependent Lambek Calculus subobject-classifier-for-grammars

Previously in Agda we had constructed equalizers in Lambek𝙳 using sigma types. Further, equalizers form subobjects, which may be comprehended as maps from a type into a subobject classifier.

I believe in our formalization we want to generalize this idea to a broader class of subobjects, maybe even all of them. That is, we could define a subobject classifying grammar Ξ©. Then we can internally define any predicate on a grammar 𝑔 via a term 𝑝:π‘”βŠ’Ξ©.

That is, forall 𝑀:String we have ⟦Ω⟧(𝑀)β‰”π—π–―π—‹π—ˆπ—‰, and

βŸ¦π—Œπ—Žπ–»π—€π—‹π–Ίπ—†π—†π–Ίπ—‹(𝑔)(𝑝)⟧(𝑀)β‰”βˆ‘π‘₯:βŸ¦π‘”βŸ§(𝑀)βŸ¦π‘βŸ§(π‘₯)

The code for this is nearly identical to the definition of equalizers as sigma types, and I have even built a translation of the equalizers code that is defined with this as its foundation. I have not yet tested if either implementation is preferable.

It isn’t yet clear how to best expose this sort of construct syntactically. I suppose you could assume some subobject classifying grammar, but then I don’t know if you can then reap the benefits of the propositions internally. That is, how do you reflect the proposition that two terms are equal in the internal language of propositions rather than the external one?

If nothing else, this code gives me a reusable interface to axiomatize smaller, sandboxed ways in which I’d like to internalize certain types of propositions (such as β€œtwo terms are equal” or β€œdoes not begin with the character 𝑐”).

The hope for this code is that it lets me inductively prove the follow last soundness of Kleene star.

Definition 0.0.14. Kleene Star in Dependent Lambek Calculus kleene-star

For a grammar 𝐴, the Kleene star π΄βˆ— is defined as a least-fixed point,

πœ‡π‘₯.πœ–βŠ•(π΄βŠ—π‘₯)

Definition 0.0.15. Star Continuity in Dependent Lambek Calculus star-continuity-in-dependent-lambek

For a grammar 𝐴, the Kleene star π΄βˆ— is isomorphic to an indexed coproduct.

π΄βˆ—β‰…β¨π‘›:β„•π΄βŠ—π‘›

That is, we may view the parses of π΄βˆ— like a linear list comprising parses of 𝐴 concatenated together. Further, for each of these lists we may know the precise length.

When viewing Dependent Lambek Calculus as a model of Kleene algebra, this is precisely the statement that star continuity holds.

Definition 0.0.16. First Sets in Dependent Lambek Calculus first-set-in-dependent-lambek

The first set of a grammar 𝐴 may be captured in Lambek𝙳 via the following proposition:

π‘βˆ‰π–₯π—‚π—‹π—Œπ—(𝐴)≔𝐴&('𝑐'βŠ—βŠ€)⊒βŠ₯

Or perhaps with ones of the grammars

𝐴⇒¬('𝑐'βŠ—βŠ€),'𝑐'βŠ—βŠ€β‡’Β¬π΄

Definition 0.0.17. FollowLast Sets in Dependent Lambek Calculus followlast-set-in-dependent-lambek

The followlast set of a grammar 𝐴 may be captured in Lambek𝙳 via the following proposition:

π‘βˆ‰π–₯π–«π–Ίπ—Œπ—(𝐴)≔𝐴&(π΄βŠ—'𝑐'βŠ—βŠ€)⊒βŠ₯

Or perhaps with ones of the grammars

𝐴⇒¬(π΄βŠ—'𝑐'βŠ—βŠ€),π΄βŠ—'𝑐'βŠ—βŠ€β‡’Β¬π΄

Definition 0.0.18. Nullability in Dependent Lambek Calculus nullability-in-dependent-lambek

The nullability (π–­π—Žπ—…π—…(β‹…)) of a grammar 𝐴 may be captured in Lambek𝙳 via the following proposition:

Β¬π–­π—Žπ—…π—…(𝐴)≔𝐴&πœ–βŠ’βŠ₯

Or perhaps with one of the grammars

π΄β‡’Β¬πœ€,πœ€β‡’Β¬π΄

0.0.19 Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus mwpls-2024-talk

We present Dependent Lambek Calculus, a domain-specific dependent type theory for verified parsing and formal grammar theory. In Dependent Lambek Calculus, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the types as a mathematical notion of formal grammars. Based on this denotational semantics, we have made a prototype implementation of Dependent Lambek Calculus using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

Event Β· Slides

Definition 0.0.20. 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 0.0.21. Dependent Tensor of Grammars dependent-tensor

The tensor of grammars,

(π΄βŠ—π΅)(𝑀)=βˆ‘π‘€=𝑒𝑣𝐴(𝑒)×𝐡(𝑣)

is simply typed, so 𝐡 cannot see what 𝐴 matched.

Just as we have the generalization from the pair type 𝐴×𝐡 to the dependent pair Ξ£π‘Ž:π΄π΅π‘Ž, we can define a dependent tensor operation. It is a Ξ£-like generalization over the ordinary tensor, in which the second grammar depends on a parse tree of the first.

Write 𝖳𝗋𝖾𝖾(𝐴)=βˆ‘π‘€π΄(𝑀) for the type of parse trees of 𝐴, each paired with the string it parses.

For a grammar 𝐴 and a family of grammars 𝐡:𝖳𝗋𝖾𝖾(𝐴)→𝐆𝐫, the dependent tensor is:

(π΄βŠ—π–£π΅)(𝑀)=βˆ‘π‘€=π‘’π‘£βˆ‘π‘Ž:𝐴(𝑒)𝐡(𝑒,π‘Ž)(𝑣)

We may also write it as (π‘Žβˆˆπ΄)βŠ—π΅(π‘Ž).

When 𝐡 is a constant family, the dependent tensor reduces to the ordinary tensor π΄βŠ—π΅.

Dependence runs left to right here, which fits left-to-right parsing. The other handedness, in which the first grammar depends on a parse of the second, is also definable.

Relation to Day Convolution

Just as the ordinary tensor is given by Day convolution, I think there is a similar dependent Day convolution for which this operation is an instance. My best guess is for any 𝑋 presheaf on a monoidal category π’žοΈ€ and π‘Œ a functor from the category of elements of 𝑋 into presheaves on π’žοΈ€,

(π‘‹βŠ—π–£π‘Œ)𝑐=βˆ«π‘’,π‘£π’žοΈ€[𝑐,π‘’βŠ—π‘£]Γ—βˆ«π‘₯:π‘‹π‘’π‘Œ(𝑒,π‘₯)𝑣

I’m not positive on this though, and I would hope to also extend this to enrichments that aren’t π’πžπ­ but I don’t see how that could make sense given that I have quantified over the element π‘₯:𝑋𝑒 in the coend rather than using the tensor of the enriching category.

Definition 0.0.22. Formal Grammar formal-grammar

For an alphabet Ξ£, let Ξ£βˆ— be the free monoid of strings over Ξ£. A formal grammar 𝐴 is a family of types indexed by strings:

𝐴:Ξ£βˆ—β†’π–³π—’π—‰π–Ύ

This definition views formal grammars directly as indexed families of types over strings (which equivalently form presheaves on the discrete category of strings). This view forms the central notion of the Dependent Lambek Calculus. For a given string 𝑀, the type 𝐴(𝑀) represents the type of all valid parse trees for 𝑀 according to the grammar 𝐴. If the grammar cannot parse 𝑀, then 𝐴(𝑀) is the empty type.

Definition 0.0.23. The Derivative of a Grammar grammar-derivative

When a grammar quotient 𝐷𝐴𝐡 is taken with respect to a representable grammar 𝐴=βŒˆπ‘€βŒ‰ (matching exactly the string 𝑀), it coincides with the residual 𝐴⊸𝐡, as established by the Quotient and Residual Coincidence.

This special case is known as the Brzozowski derivative of 𝐡 by the string 𝑀, often written as πœ•π‘€π΅. We have the following coincidence:

(βŒˆπ‘€βŒ‰βŠΈπ΅)(𝑣)≅𝐡(𝑀·𝑣)β‰…(π·βŒˆπ‘€βŒ‰π΅)(𝑣)

Definition 0.0.24. Later on Grammars grammar-later

Write π‘’βŠπ‘£ when 𝑒 is a proper suffix of 𝑣, that is, 𝑣=π‘₯++𝑒 with π‘₯β‰ πœ€. The later of a grammar 𝐴 is

(▷𝐴)𝑣=βˆπ‘’βŠπ‘£π΄π‘’.

A parse of ▷𝐴 over 𝑣 is a parse of 𝐴 over every proper suffix of 𝑣. In particular (▷𝐴)πœ€ is a singleton.

This is later on families for strings under the proper-suffix order. That order is well-founded because it strictly decreases length, so it is a thin direct category. There is at most one map 𝑒→𝑣, so the product over maps from the strict past has one factor per proper suffix. Guarded recursion is modelled by presheaves on πœ”, the topos of trees, and more generally by sheaves over a well-founded base [1]. Here the later acts on families, which is what grammars are, and there is no clock.

Later is the right adjoint of the proper-suffix derivative. Let 𝖭𝖀𝖲=⨁π‘₯β‰ πœ€βŒˆπ‘₯βŒ‰ be the grammar of non-empty strings. Then the derivative (πœ•π–­π–€π–²π΅)π‘’β‰…βˆ‘π‘₯β‰ πœ€π΅(π‘₯++𝑒) has the right adjoint

πΆπ–­π–€π–²π‘£β‰…βˆπ‘₯++𝑒=𝑣𝖭𝖀𝖲π‘₯→𝐢𝑒≅(▷𝐢)𝑣,

so πœ•π–­π–€π–²βˆ’βŠ£β–·. Splitting 𝖭𝖀𝖲 into its summands gives the form of β–· that the calculus can define:

▷𝐴≅&π‘€β‰ πœ€π΄βŒˆπ‘€βŒ‰,π΄βŒˆπ‘€βŒ‰β‰…(βŒˆπ‘€βŒ‰βŠ—βŠ€)β‡’(βŒˆπ‘€βŒ‰βŠ—π΄).

The component at 𝑀 says: if the string begins with 𝑀, then the rest parses as 𝐴.

The restriction to non-empty 𝑀 is what makes this a later. At 𝑀=πœ€ the component is π΄βŒˆπœ€βŒ‰β‰…π΄. Including it would give a projection β–·π΄βŠ’π΄, and LΓΆb would then prove every grammar. For the same reason the later is a product over suffixes. A sum such as β¨π‘βŒˆπ‘βŒ‰βŠΈπ΄ is empty at πœ€, and at 𝐴=βŠ₯ it is βŠ₯. The identity step βŠ₯⊒βŠ₯ would then give LΓΆb a proof of ⊀⊒βŠ₯.

In the Agda this is β–· in Grammar/Later/Base.agda, which is defined as the indexed conjunction of √l-string. The mirror image β–·r, over proper prefixes, is defined in the same way. See also the bilateral later and the later along an arbitrary well-founded order.

Theorem 0.0.25. LΓΆb Induction for Grammars grammar-lob

For every grammar 𝐴 and every term πœ‘:β–·π΄βŠ’π΄, where β–· is the later on grammars, there is a unique global parse π—…ΓΆπ–»πœ‘:⊀⊒𝐴 with

π—…ΓΆπ–»πœ‘=πœ‘βˆ˜π—‡π–Ύπ—‘π—(π—…ΓΆπ–»πœ‘).

Here 𝗇𝖾𝗑𝗍𝑑:βŠ€βŠ’β–·π΄ restricts a global parse 𝑑 to every proper suffix.

The proof is recursion on the length of the string. At 𝑣, the parses already built at the proper suffixes of 𝑣 form an element of (▷𝐴)𝑣, and πœ‘ turns it into a parse at 𝑣. Uniqueness is LΓΆb for families over the proper-suffix order. In the Agda, lob in Grammar/Later/Base.agda is this recursion, done by well-founded induction on length.

To prove an entailment 𝐡⊒𝐢 this way, apply LΓΆb to 𝐴=𝐡⇒𝐢. The hypothesis β–·(𝐡⇒𝐢) is the induction hypothesis at every proper suffix. It becomes usable once a non-nullable grammar has been consumed. If πœ€&𝐡⊒βŠ₯, then

(π΅βŠ—βŠ€)&β–·π΄βŠ’π΅βŠ—π΄

because a parse of π΅βŠ—βŠ€ over 𝑣 splits 𝑣=π‘₯++𝑒 with π‘₯ non-empty, so π‘’βŠπ‘£. This is β–·-app-NE in Grammar/Later/Properties.agda. Induction on a Kleene star is the standard use.

Theorem 0.0.26. Next on Grammars Is Presheaf Structure grammar-next-presheaf

For presheaves, 𝗇𝖾𝗑𝗍:𝑃→▷𝑃 restricts along the strict past, as in later on presheaves. A grammar is only a family over strings, so a map 𝗇𝖾𝗑𝗍:π΄βŠ’β–·π΄ into the later on grammars is extra data. It sends a parse over 𝑣 to parses over every proper suffix of 𝑣.

Let ░𝐴=𝐴&▷𝐴, so that (░𝐴)π‘£β‰…βˆπ‘’βŠ‘π‘£π΄π‘’. This is the comonad π‘ˆβˆ˜Cofree for the suffix order, and presheaves are comonadic over families. The counit law forces the first component of a coalgebra π΄βŠ’β–‘π΄ to be the identity. Hence:

  • a presheaf on strings under the suffix order is the same as a grammar 𝐴 with a map 𝗇𝖾𝗑𝗍:π΄βŠ’β–·π΄ that satisfies coassociativity. Restricting to 𝑒′ and then to π‘’βŠπ‘’β€² must agree with restricting to 𝑒 directly;
  • for a proposition-valued grammar (a language), coassociativity is automatic, and 𝗇𝖾𝗑𝗍 exists exactly when the language is closed under suffixes. For example, ⊀ has one, but βŒˆπ‘ŽβŒ‰ does not, since (β–·βŒˆπ‘ŽβŒ‰)π‘Žβ‰…βŒˆπ‘ŽβŒ‰πœ€ is empty.

LΓΆb does not need 𝗇𝖾𝗑𝗍 on 𝐴. The fixed-point equation only restricts a global parse ⊀⊒𝐴, and a global parse can always be restricted. In the Agda, the grammar-level IsCoalgebra record, with only the field next, is in Grammar/Later/Coalgebra.agda on the guarded branch.

On presheaves the strict downset of 𝑐++𝑑 is represented by 𝑑, because every proper suffix of 𝑐++𝑑 is a suffix of 𝑑. So predecessors simplify later to (▷𝑃)(𝑐++𝑑)≅𝑃𝑑. On grammars there is no such simplification, since the factors at different suffixes are unrelated.

Definition 0.0.27. Grammar Quotients grammar-quotients

For formal grammars 𝐴 and 𝐡, the quotient of 𝐡 by 𝐴 is the grammar of what is left of 𝐡 once an 𝐴 has been read off the front:

(𝐷𝐴𝐡)(𝑣)=Σ𝑒𝐴(𝑒)×𝐡(𝑒·𝑣)

A parse of the quotient consists of an 𝐴-parses at prefix 𝑒 and a 𝐡-parse of the full string 𝑒·𝑣.

This operation has a right adjoint:

(𝐢𝐴)(𝑀)=Π𝑒,𝑣(𝑒·𝑣=𝑀)→𝐴(𝑒)→𝐢(𝑣)

Intuitively, 𝐢𝐴 parses 𝑀 if: for all splittings of 𝑀 into a prefix and suffix, if the prefix matches 𝐴 then the suffix must match 𝐢.

Together, these form the adjunction:

𝐷𝐴𝐡⊒𝐢⟺𝐡⊒𝐢𝐴

This is an instance of the Day quotient over the discrete monoidal category of strings.

Definition 0.0.28. Grammar Residuals grammar-residual

For formal grammars 𝐴 and 𝐡, the residual 𝐴⊸𝐡 (sometimes called the lollipop or linear implication) is the right adjoint to the grammar tensor π΄βŠ—π΅. It describes strings that, when prefixed by a string matching 𝐴, will match 𝐡.

Formally, it is defined as:

(𝐴⊸𝐡)(𝑣)=Π𝑒𝐴(𝑒)→𝐡(𝑒·𝑣)

Intuitively, a parse of 𝐴⊸𝐡 at a string 𝑣 is a function that takes any prefix string 𝑒 and a parse of 𝑒 in 𝐴, and produces a parse of the full concatenated string 𝑒·𝑣 in 𝐡.

Definition 0.0.29. Tensor of Grammars grammar-tensor

For formal grammars 𝐴 and 𝐡, their tensor π΄βŠ—π΅ represents the concatenation of the languages they describe. A parse for π΄βŠ—π΅ at a string 𝑀 consists of a splitting of 𝑀 into a prefix 𝑒 and suffix 𝑣, along with a parse of 𝑒 in 𝐴 and a parse of 𝑣 in 𝐡.

Formally, it is defined as:

(π΄βŠ—π΅)(𝑀)=βˆ‘π‘€=𝑒𝑣𝐴(𝑒)×𝐡(𝑣)

This operation is exactly the Day convolution of 𝐴 and 𝐡, where we view formal grammars as presheaves over the monoid of strings.

Definition 0.0.30. Types over an Algebraic Theory theory-type

Fix a finitary algebraic theory 𝒯︀: sorts 𝑆, a signature 𝜎, equations, and a set 𝑉 of generators. Write 𝑴 for the free 𝒯︀-model on 𝑉 and |𝑴|𝑠 for its carrier at sort 𝑠.

A 𝒯︀-type of sort 𝑠 is a family 𝐴:|𝑴|𝑠→𝖳𝗒𝗉𝖾.

For 𝒯︀-types 𝐴 and 𝐡 of sort 𝑠 we have the additives, defined pointwise,

(𝐴&𝐡)(π‘š)=𝐴(π‘š)×𝐡(π‘š),(π΄βŠ•π΅)(π‘š)=𝐴(π‘š)+𝐡(π‘š),(𝐴⇒𝐡)(π‘š)=𝐴(π‘š)→𝐡(π‘š),

along with ⊀, βŠ₯, and their indexed versions.

Each operation π‘œ:𝑠0,…,π‘ π‘›βˆ’1→𝑠 of 𝒯︀ gives a multiplicative, defined by Day convolution,

βŠ—[π‘œ](𝐴0,…,π΄π‘›βˆ’1)(π‘š)=Ξ£π‘œ(π‘š0,…,π‘šπ‘›βˆ’1)=π‘šΓ—Ξ π‘–<𝑛𝐴𝑖(π‘šπ‘–).

Each lifted operation also has closed structure: a residual in each of its arguments. Day algebras [1] give a more general convolutional definition.

When 𝒯︀ is the theory of monoids and 𝑉 is an alphabet, 𝒯︀-types are formal grammars. Multiplication gives βŠ—, the unit gives πœ€, and we recover Lambek𝙳.

Mechanized Category Theory mechanized-category-theory

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

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.0.30.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.0.30.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. 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. 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 βˆ«π‘ƒ.

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, π—Žπ—‡π–Ώπ—ˆπ—…π–½π›Ύ.

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. 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. 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. 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. 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 intersection of all supports for π‘₯ is called the least support, denoted π—Œπ—Žπ—‰π—‰(π‘₯).

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 𝑑:

𝑋(𝑑)={π‘₯βˆˆπ‘‹|π—Œπ—Žπ—‰π—‰(π‘₯)βŠ†π‘‘}

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. 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. 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.

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.

Publications

Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus intrinsic-verification-of-parsers

We present Dependent Lambek Calculus (Lambek𝙳), a domain-specific dependent type theory for verified parsing and formal grammar theory. In Lambek𝙳, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the linear types as functions from strings to sets of abstract parse trees and terms as parse transformers. Based on this denotational semantics, we have made a prototype implementation of Lambek𝙳 using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

PDF Β· DOI Β· arXiv (extended version) Β· Source code Β· pldb

Talks

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

Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus pldi-2025-talk

We present Dependent Lambek Calculus, a domain-specific dependent type theory for verified parsing and formal grammar theory. In Dependent Lambek Calculus, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the types as a mathematical notion of formal grammars. Based on this denotational semantics, we have made a prototype implementation of Dependent Lambek Calculus using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

Event Β· Slides Β· Video

Intrinsic Verification of Parsers and Formal Grammar Theory in Dependent Lambek Calculus mwpls-2024-talk

We present Dependent Lambek Calculus, a domain-specific dependent type theory for verified parsing and formal grammar theory. In Dependent Lambek Calculus, linear types are used as a syntax for formal grammars, and parsers can be written as linear terms. The linear typing restriction provides a form of intrinsic verification that a parser yields only valid parse trees for the input string. We demonstrate the expressivity of this system by showing that the combination of inductive linear types and dependency on non-linear data can be used to encode commonly used grammar formalisms such as regular and context-free grammars as well as traces of various types of automata. Using these encodings, we define parsers for regular expressions using deterministic automata, as well as examples of verified parsers of context-free grammars.

We present a denotational semantics of our type theory that interprets the types as a mathematical notion of formal grammars. Based on this denotational semantics, we have made a prototype implementation of Dependent Lambek Calculus using a shallow embedding in the Agda proof assistant. All of our examples parsers have been implemented in this prototype implementation.

Event Β· Slides

LLL Algorithm lll-algorithm-video

Lenstra-Lenstra-Lovasz (LLL) Lattice Basis Reduction Algorithm. A very useful algorithm for computational number theory.

Final project for M602 Algebraic Number Theory at Indiana University.

Special thanks to Grant Sanderson for creating the manim library, and to Jeff Suzuki for illuminating videos on the algorithm!

Video

Teaching

Compiler Construction eecs-483-fall-2023

Graduate student instructor Β· Instructor Max S. New Β· With Daniel Calco
Course website

Navigating This Site

home home entries/home/home.hel