0% found this document useful (0 votes)
5 views53 pages

CL and TT v2

This document is a draft titled 'A Gentle Introduction to Categorical Logic and Type Theory' by Eric Schmid, which aims to provide an introduction to category theory, its application in logical systems, and type theory. It covers fundamental concepts such as categories, functors, and natural transformations, as well as their connections to algebraic theories and propositional logic. The text includes examples, exercises, and proofs to facilitate understanding for readers with a background in set theory, algebra, and logic.

Uploaded by

ayman.892010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views53 pages

CL and TT v2

This document is a draft titled 'A Gentle Introduction to Categorical Logic and Type Theory' by Eric Schmid, which aims to provide an introduction to category theory, its application in logical systems, and type theory. It covers fundamental concepts such as categories, functors, and natural transformations, as well as their connections to algebraic theories and propositional logic. The text includes examples, exercises, and proofs to facilitate understanding for readers with a background in set theory, algebra, and logic.

Uploaded by

ayman.892010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

A Gentle Introduction to Categorical Logic and Type Theory

Eric Schmid
DRAFT: March 6, 2025
Version 2
ii
Contents

1 Basic Category Theory 5


1.1 From Elements to Arrows: The Categorical Approach . . . . . . . . . . . . 5
1.2 Definition of Categories and Basic Examples . . . . . . . . . . . . . . . . . . 6
1.3 Functors and Natural Transformations . . . . . . . . . . . . . . . . . . . . . 13
1.4 Universal Constructions: Initial Objects, Products, and Limits . . . . . . . 18

2 Algebraic Theories and Propositional Logic 23


2.1 Algebraic Theories and Functorial Semantics . . . . . . . . . . . . . . . . . 23
2.1.1 Syntax and Theories as Categories . . . . . . . . . . . . . . . . . . . 24
2.1.2 Examples of Algebraic Categories and Functors . . . . . . . . . . . . 27
2.2 Boolean Algebras and Classical Propositional Logic . . . . . . . . . . . . . . 28
2.2.1 Heyting Algebras and Frames: Intuitionistic Propositional Logic . . 33

3 First-Order Logic in Categories 37


3.1 Categorical Semantics of Type Theory . . . . . . . . . . . . . . . . . . . . . 42

A Further Reading 47

iii
iv CONTENTS
Preface

Category theory provides a unifying language to study mathematical structures in terms


of their relationships (morphisms) rather than just their elements. Categorical logic uses
category theory to study logical systems, offering a structural perspective on syntax and
semantics, while type theory provides a framework connecting logic with computation via
the Curry–Howard correspondence. These notes aim to introduce the basics of category
theory and show how categories provide semantics for logic and type theories. We assume
the reader has some familiarity with elementary set theory, algebra, and logic (propositional
and first-order), but we proceed from first principles and include many examples and
exercises for self-study.
These notes draw on several texts. The structure of presentation follows Abramsky and
Tzevelekos’s Introduction to Categories and Categorical Logic 1 , while expanding on topics
with material from Awodey’s lecture notes on categorical logic2 and Jacobs’s comprehensive
textbook Categorical Logic and Type Theory 3 .
Chapter 1 introduces basic category theory: the language of objects and arrows, functors
between categories, natural transformations, and fundamental categorical constructions
(products, coproducts, limits, etc.). We emphasize how many familiar mathematical con-
cepts can be reformulated in terms of arrows rather than elements, leading to a shift in
perspective that underlies categorical logic.

Chapter 2 covers propositional logic and algebraic theories from a categorical perspec-
tive. We explain how algebraic structures (like groups, rings, etc.) can be described as
categories with finite products (Lawvere theories), and how their models are functors to
1
Samson Abramsky and Nikos Tzevelekos, ”Introduction to Categories and Categorical Logic,”
arXiv:1102.1313 (2011), which provides a succinct introduction to category theory and its connections
to logic.
2
Steve Awodey (with input from Andrej Bauer), Categorical Logic, Autumn School on Proof and Compu-
tation, Fischbachau 2022 and the draft Introduction to Categorical Logic (September 15, 2024). These texts
develop the idea of algebraic theories, propositional logic, and Stone duality in a categorical framework.
3
Bart Jacobs, Categorical Logic and Type Theory, Studies in Logic and the Foundations of Mathematics
141, Elsevier, 1999. Jacobs’s book systematically develops logic and type theory using category theory (in
particular, fibrations) and serves as a reference for advanced topics beyond the scope of these introductory
notes.

1
2 CONTENTS

Set. We prove soundness and completeness for equational logic categorically. We then
treat propositional logic: Boolean algebras and their dual Stone spaces provide semantics
for classical propositional calculus, culminating in Stone’s duality theorem. We also discuss
intuitionistic propositional logic via Heyting algebras, introducing frames and locales as
categorical generalizations of topological spaces.

Chapter 3 deals with first-order logic in categorical terms. We develop the notion of a
cartesian or finite limit logic (also called coherent or regular logic for certain fragments)
and show how quantifiers can be characterized as adjoint functors. The concept of a clas-
sifying category (or classifying topos in more advanced settings) for a first-order theory
is introduced, providing a categorical semantics where models of the theory correspond
to functors from this category. We define key properties of categories that capture logi-
cal axioms: regular categories (for ∃), coherent categories (for ∨), Heyting categories (for
intuitionistic logic), and Boolean categories (for classical logic). We outline the internal
logic of categories and give a glimpse of Kripke–Joyal semantics for logical formulas in a
category (as used in topos theory).

Chapter 4 introduces type theory and its categorical semantics. We start with the simply-
typed λ-calculus as a formal system of types and terms. We define Cartesian closed cat-
egories (CCC) and explain the Curry–Howard–Lambek correspondence: how CCCs are
equivalent (as models) to the simply-typed lambda calculus. In particular, we show how
a CCC provides a sound and complete semantics for propositional logic with implication
(and how adding product types corresponds to conjunction). We then extend to depen-
dent types and discuss how categories with additional structure (such as locally Cartesian
closed categories and categories with families) provide semantics for dependent type theo-
ries (which correspond to first-order logic internally). Finally, we touch on polymorphism
and universe types, connecting to advanced type theory: a universe in a category is in-
troduced as an object that can be thought of as a type of all (small) types, allowing the
interpretation of type-theoretic universes categorically.

Throughout, we include full proofs of propositions and theorems to make this text self-
contained. In places where proofs are beyond the scope of an introduction (for example,
Gödel’s completeness theorem for first-order logic or a full proof of Stone’s theorem), we
give sketches or references for further reading.

It is our hope that this expanded textbook will serve students and researchers from
both computer science and mathematics who are interested in the beautiful connections
between category theory, logic, and type theory. The exercises should help the reader gain
a working proficiency in these concepts. We encourage attempting the exercises, as many
important ideas appear there.
CONTENTS 3

Acknowledgments. We thank the authors of the original notes and textbooks. All
mistakes or omissions in these notes are our own.
4 CONTENTS
Chapter 1

Basic Category Theory

1.1 From Elements to Arrows: The Categorical Approach


Mathematics traditionally speaks in terms of elements: for example, we say a function
f : X → Y is injective if “for all x1 , x2 ∈ X, f (x1 ) = f (x2 ) implies x1 = x2 .” In category
theory, we shift focus from elements to arrows. Instead of quantifying over elements, we
express properties via composition of arrows. For instance, the injectivity of f can be cap-
tured by the condition: whenever two arrows g, h : Z → X satisfy f ◦ g = f ◦ h, then g = h.
In categorical terms, this says f : X → Y is a monomorphism if f ◦ g = f ◦ h =⇒ g = h.
Dually, f is a epimorphism if g ◦ f = h ◦ f =⇒ g = h (cancellable on the right).

This arrow-centric viewpoint reveals deep structural similarities across different math-
ematical contexts. A classic example: the concept of a “homomorphism” (structure-
preserving map) between algebraic structures can be seen as a special case of a categorical
morphism (arrow). By abstracting properties of these arrows (composition, identity, etc.),
category theory provides a unifying framework to discuss disparate areas of math in a
common language.

In category theory, we do not require that arrows are functions or that objects are
sets; they can be any abstract entities as long as they satisfy certain axioms. This level
of generality is powerful: for example, a partially ordered set (poset) can be viewed as
a special category (with at most one arrow between any two objects), and a group can
be viewed as a category with a single object (all group elements being arrows from that
object to itself). These perspectives might seem unusual at first, but they allow us to apply
categorical reasoning (like “universal properties”) to a wide range of situations.

In summary, category theory encourages thinking about mathematical structures in


terms of their relationships (morphisms) rather than just their constituents. This shift will

5
6 CHAPTER 1. BASIC CATEGORY THEORY

enable us to later describe logical systems and type systems in terms of categories, where
logical formulas and types correspond to objects, and proofs and programs correspond to
arrows.

1.2 Definition of Categories and Basic Examples


We begin with the formal definition of a category. Informally, a category C consists of a
collection of objects and, for each pair of objects (A, B), a collection of arrows (also called
morphisms) from A to B. These arrows can be composed, and there are identity arrows
for each object, such that composition is associative and identities act as neutral elements.
Let us state this precisely.

Definition 1.1 (Category). A category C consists of:

• A class Ob(C) of objects, denoted A, B, C, . . .

• For every ordered pair of objects (A, B), a class C(A, B) of morphisms (or arrows)
from A to B. If f is a morphism in C(A, B), we write f : A → B.

These data satisfy the following axioms:

• (Composition) For any f : A → B and g : B → C, there is a morphism g◦f : A → C


called their composite. Composition is associative: if f : A → B, g : B → C, and
h : C → D, then h ◦ (g ◦ f ) = (h ◦ g) ◦ f .

• (Identity) For every object A, there is a morphism idA : A → A, called the identity
on A, such that for every f : A → B, we have f ◦ idA = f , and for every g : C → A,
idA ◦ g = g. In other words, idA acts as a two-sided identity for composition.

We often denote the class of morphisms from A to B as homC (A, B) or simply C(A, B). If
a morphism f : A → B is an isomorphism (defined below), we may write A ∼ = B.
Proof. This definition is standard. Note that we allow the collections of objects and mor-
phisms to be proper classes (not necessarily sets), but in practice many categories of interest
are locally small, meaning C(A, B) is a set for all A, B.

In the definition above, we used the word “class” to allow for the possibility that the
collection of all objects or morphisms might be too large to be a set (for example, the cat-
egory of all sets has a proper class of objects). A category is called small if its objects and
morphisms form sets (rather than proper classes), and locally small if for each A, B, the
hom-class C(A, B) is a set. Unless stated otherwise, we will not worry about set-theoretic
size issues and will assume categories are locally small.
1.2. DEFINITION OF CATEGORIES AND BASIC EXAMPLES 7

Let us unravel the definition with some immediate consequences and simple examples:

f
• Composition being associative means that given a composable triple of arrows A −→
g h
B→− C− → D, it doesn’t matter how we parenthesize the composite h ◦ g ◦ f . We can
thus unambiguously write h ◦ g ◦ f : A → D.

• Identities are unique for each object (because if u : A → A is any morphism with the
identity property, u = u ◦ idA = idA ◦ u = idA ). Often, we simply write 1A for idA
when context is clear.

• The definition does not require that Ob(C) or C(A, B) are non-empty. It is perfectly
valid (though not very interesting) to have a category with no objects (and hence no
arrows), or a category with objects but no arrows between some pairs of objects. For
instance, the empty category has no objects at all, and the discrete category on
a set of objects has only identity arrows and no others.

Now we present a variety of examples. These illustrate how diverse categories can be,
and how familiar structures fit into this abstract framework.

Example 1.2 (Sets and Functions). Perhaps the most fundamental example is the cate-
gory Set, whose objects are all (small) sets and whose morphisms are all functions between
sets. Composition is the usual composition of functions, and identity morphisms are iden-
tity functions. It is straightforward to verify that Set satisfies the category axioms. This
category plays a special role as the typical setting for the semantics of many theories (since
models of theories are often sets with structure). We will often denote it by Set.

Other categories of mathematical structures and structure-preserving functions include:


- Grp: objects are groups, morphisms are group homomorphisms.
- Mon: monoids and monoid homomorphisms.
- Ring: rings (with unity) and ring homomorphisms.
- Top: topological spaces and continuous functions.
- Vectk : vector spaces over a field k and linear transformations.
In general, any class of structures with a suitable notion of homomorphism forms a category.
Composition of morphisms is just composition of functions that respect the structures, and
identities are the identity functions.
Example 1.3 (Posets as Categories). A partially ordered set (poset) (P, ≤) can be
viewed as a category C where:
8 CHAPTER 1. BASIC CATEGORY THEORY

- The objects are the elements of P .


- There is a unique morphism a → b in C if and only if a ≤ b in the poset, and no morphism
otherwise.

In this category interpretation, composition corresponds to transitivity of the order,


and identity morphisms correspond to reflexivity (a ≤ a). Associativity holds because if
a ≤ b and b ≤ c and c ≤ d, then a ≤ d (transitivity handles any way of associating the
inequalities).

It’s easy to see that verifying the category axioms reduces to checking that ≤ is reflexive
and transitive (which is given). Anti-symmetry (the condition a ≤ b and b ≤ a implies
a = b) means that the only isomorphisms in this category are identity morphisms; such a
category is called skeletal (isomorphic objects are equal).

As a specific instance, consider any topological space X. Its open sets O(X) form a
poset under inclusion (U ≤ V iff U ⊆ V ). Thus O(X) can be regarded as a category: an
arrow U → V exists iff U ⊆ V . This example will be important later when we discuss
frames and locales in logic (since O(X) is a frame, an example of a complete Heyting
algebra).

Example 1.4 (Groups and Monoids as One-Object Categories). Any group (G, ·, e) can
be seen as a category with a single object ∗. Define Ob(C) = {∗}. Let C(∗, ∗) = G, i.e. each
element g ∈ G is considered a morphism ∗ → ∗. Composition of morphisms in C is given by
the group operation: the composite of f : ∗ → ∗ and g : ∗ → ∗ is defined to be g ◦ f := g · f
(note the order: first f , then g). The group identity e serves as the identity morphism id∗ .
The group axioms (associativity of · and identity e) exactly ensure the category axioms
hold. Every arrow in this category is invertible (with f −1 as the inverse of f ), reflecting
the fact that all morphisms are isomorphisms.

More generally, any monoid (a set with an associative binary operation and a unit,
but not necessarily inverses) can be viewed as a category with one object. A monoid ele-
ment m is a morphism ∗ → ∗; composition is given by the monoid operation g ◦ f = g · f .
The lack of inverses in a monoid means that some arrows in the category will not have
two-sided inverses (so it’s not a “groupoid”, which would be the category analog of group
where every arrow is invertible).

This perspective “a category with one object is a monoid” is a correspondence: cate-


gory theorists thus see monoids as very simple categories. It also suggests that studying
properties of monoids can be done with categorical language if desired. For instance, a
monoid homomorphism h : M → N is the same as a functor between the corresponding
1.2. DEFINITION OF CATEGORIES AND BASIC EXAMPLES 9

one-object categories (more on functors soon).


Example 1.5 (The Zero and Unit Categories). The empty category 0 has no objects
(and hence no morphisms). It vacuously satisfies the category axioms. The empty category
is the initial object in the category of (small) categories, meaning there is a unique functor
from 0 to any category C (since to define a functor you have to specify images of objects
and morphisms, but 0 has none to specify, so there’s exactly one choice).

The unit category 1 (also sometimes denoted 1 or ∗) has a single object ∗ and only
its identity morphism 1∗ . In 1, for the single object ∗, hom(∗, ∗) = {1∗ }. This is indeed a
category (trivially satisfying axioms). The unit category serves as a terminal object in the
category of categories: there is a unique functor from any category C to 1 (by sending all
objects to ∗ and all morphisms to 1∗ ). We will later see that terminal objects in categories
are an important notion and that 1 is a terminal category.

Example 1.6 (Morphisms as Generalized Relations). There are interesting categories


where morphisms are not functions but more general relations. For instance, Rel is a
category where objects are sets and a morphism R : X → Y is a binary relation R ⊆
X × Y . Composition of relations R : X → Y and S : Y → Z is given by the composite
relation
S ◦ R = {(x, z) | ∃y ∈ Y, (x, y) ∈ R and (y, z) ∈ S}.
This is essentially the usual relational composition. The identity morphism on X is the
diagonal (identity) relation {(x, x) | x ∈ X}. Verifying associativity and identity laws is an
exercise. In Rel, unlike in Set, a morphism doesn’t assign a unique output to each input;
it can relate an element to multiple targets or none. Rel is an example of a category that
is not locally small if we allow arbitrary (possibly proper class-sized) sets, but restricting
to small sets it is locally small.

Another example of “non-functional” morphisms: consider a category Mat whose ob-


jects are natural numbers (or finite sets of given sizes) and a morphism m → n is an
m × n matrix with real number entries. Composition is matrix multiplication. Identity
morphisms are identity matrices. This forms a (small) category. It is closely related to
linear algebra and can be seen as the category of finite-dimensional vector spaces with a
fixed basis chosen for each (so that linear maps correspond to matrices). Morphisms in
Mat are not literally functions between the objects (since objects are just numbers), but
they can be interpreted as linear functions if we think each object n represents Rn .

The above examples should convince you that the notion of morphism is very gen-
eral. In category theory, any consistent rules of composing arrows qualify, not necessarily
arrow-as-function. Thus, category theory can capture processes (like relations, or matrices
10 CHAPTER 1. BASIC CATEGORY THEORY

as linear transformations) that are more general than single-valued functions.

We also observe that in a category, the composition law determines a directed graph
structure: objects are like vertices, and morphisms are like directed edges. In fact, if we
forget composition and identities, a category is just a directed graph. Formally:

Definition 1.7 (Underlying Graph of a Category). The underlying graph of a category


C is the directed graph whose vertices are Ob(C) and which has an edge from A to B for
every morphism f : A → B. A diagram in a category is simply a directed graph (not
necessarily the whole underlying graph, but any collection of objects and arrows closed
under the incidence relation) drawn using objects of C as nodes and morphisms as edges.
We say a diagram commutes if for any two parallel paths (paths with the same start
and end object) in the diagram, the composed morphisms are equal in C. Commutative
diagrams are a convenient way to express equations between composed morphisms.
For example, the statement that f : A → B is a monomorphism (injective arrow) can
be illustrated by a diagram:
g f
C A B,
h
commuting to f ◦ g = f ◦ h =⇒ g = h. A diagram with two different paths from C
to B (one going through g then f , the other through h then f ) indicates the equation
f ◦ g = f ◦ h. If that implies the trivial path equality g = h, the diagram expresses the
universal property of f being monic.

We often draw small diagrams to express such properties or to denote equalities of


compositions. For instance, a rectangle
f
A B
x y

C g D

is said to commute if y ◦f = g ◦x. In more complex diagrams, commutativity might impose


several equations.

Example 1.8 (Commutative Diagram Example). Consider the diagram (a portion of


which was given in the textbooks & notes consulted):
f h
A B C
j
g
D k
E
1.2. DEFINITION OF CATEGORIES AND BASIC EXAMPLES 11

This depicts objects A, B, C, D, E and arrows f : A → B, g : A → D, h : B → C,


j : B → D, k : D → E, and m : C → E (with m presumably an arrow C → E not
drawn but can be inferred if the diagram commutes fully). The diagram is said to com-
mute if j ◦ f = g and k ◦ j = m ◦ h (and hence by chasing around, k ◦ g = m ◦ h ◦ f ).
Commutativity imposes equations g = j ◦ f and m ◦ h = k ◦ j. From these one can de-
rive m◦h◦f = k◦j◦f = k◦g (this kind of derivation is sometimes called a “diagram chase”).

This shows how diagrams provide a visual and intuitive way to state algebraic con-
ditions in a category. Many definitions in category theory (especially those of universal
properties, limits, etc.) are conveniently phrased as the existence of a unique arrow making
certain diagrams commute. We will see examples soon.

Before moving on, we define some special types of morphisms which generalize familiar
concepts like injective, surjective, and bijective functions.

Definition 1.9 (Isomorphism, Monomorphism, Epimorphism). Let f : A → B be a


morphism in a category C.
• We say f is an isomorphism (or iso) if there exists a morphism f −1 : B → A (called
the inverse of f ) such that f −1 ◦ f = idA and f ◦ f −1 = idB . If such an f −1 exists,
it is unique. If A and B are connected by an isomorphism, we write A ∼ = B and say
A and B are isomorphic objects.

• f is a monomorphism (or mono) if f is left-cancellative: for all morphisms g, h :


X → A,
f ◦ g = f ◦ h =⇒ g = h.
In other words, f has a trivial equalizer. Diagrammatically, f is mono if whenever
two morphisms into A form the same composite with f , they must be the same mor-
phism. In Set, monos are precisely injective functions.

• f is an epimorphism (or epi) if f is right-cancellative: for all morphisms u, v : B →


Y,
u ◦ f = v ◦ f =⇒ u = v.
So epimorphisms are arrows that can be “cancelled” on the right. In Set, epis are
precisely surjective functions.
Proof. These definitions follow standard categorical terminology. Note that in a general
category, mono + epi does not necessarily imply iso, unlike the situation in Set. A coun-
terexample given in the source is a category with two objects and a single non-identity
12 CHAPTER 1. BASIC CATEGORY THEORY

arrow between them: that arrow is both mono and epi but not an iso.

An isomorphism is a morphism with a two-sided inverse. If f : A → B is an iso,


then f −1 : B → A is also an iso (with (f −1 )−1 = f ). Isomorphisms represent the idea of
“structure-preserving bijections” in category theory. One often regards isomorphic objects
as essentially the same for many purposes, though formally they need not be equal. (Some
categories enforce that any iso implies equality of objects, such categories are called skele-
tal, e.g., a poset viewed as a category is skeletal because the only isos are identities.)

Monomorphisms generalize injective maps. For example, in Grp (groups and homo-
morphisms), a homomorphism f : G → H is monic if and only if its kernel is trivial (since
if f (g) = e implies g = e in G, then f is injective on elements). In Top (topological
spaces), a continuous map may be monic (injective) but need not have a continuous in-
verse (hence it is not necessarily an isomorphism). Epimorphisms generalize surjections; in
Top, a continuous surjection is an epi—indeed, every epi in Top is a surjective continuous
map. (Note that while there are categories in which an epi is not given by surjectivity,
in Top epis coincide with surjections. However, even in Top the combination of mono
and epi does not guarantee an isomorphism since a continuous bijection may fail to be a
homeomorphism due to the inverse lacking continuity.)

Example 1.10. In Rel (sets and relations), what are the monomorphisms and epimor-
phisms? A relation R : X → Y is monic if whenever R ◦ S1 = R ◦ S2 as relations (with
S1 , S2 : Z → X), then S1 = S2 . It can be shown that monomorphisms in Rel are precisely
those relations R that are functional and injective as relations (i.e. each element of X is
related to at most one element of Y , and if x R y and x′ R y then x = x′ ). Epimorphisms
in Rel turn out to be those relations that are right-total and surjective in the relational
sense (each y ∈ Y has at least one x ∈ X with x R y, and if two relations out of Y agree
on R then they must agree overall). These are a bit tricky to characterize succinctly, but
it shows that mono/epi generalize injective/surjective but not always identically.

Finally, note that in a one-object category (monoid), a morphism is monic iff f · g =


f · h =⇒ g = h for all g, h in the monoid. If the monoid is like a group, every element is
invertible so monic = always true (since you can cancel f ). If the monoid is not a group,
being monic might be a nontrivial condition on the element f . Similarly for epi. This is
just a fun check of definitions in a simple setting.

We have now established the core definitions: categories, morphisms, and some spe-
cial types of morphisms. Next, we discuss how one category can map to another via a
1.3. FUNCTORS AND NATURAL TRANSFORMATIONS 13

structure-preserving translation called a functor.

1.3 Functors and Natural Transformations


Having categories as mathematical objects, the appropriate notion of a mapping between
categories is that of a functor. A functor plays the role analogous to a homomorphism
between algebraic structures: it maps objects to objects and arrows to arrows in a way
that respects all the structure (composition and identities).

Definition 1.11 (Functor). Given two categories C and D, a functor F : C → D consists


of:

• For each object A ∈ Ob(C), an object F (A) ∈ Ob(D).

• For each morphism f : A → B in C, a morphism F (f ) : F (A) → F (B) in D.

These assignments must satisfy two functoriality conditions:

• Preservation of identities: For each object A of C, F (idA ) = idF (A) .


f g
• Preservation of composition: For any composable pair A −
→ B →
− C in C, we
have
F (g ◦ f ) = F (g) ◦ F (f )
as morphisms F (A) → F (C) in D.

A functor is often denoted by its action on objects and arrows. It is common to simply
write F : C → D and F f for F (f ).

Proof. See Awodey’s notes. The conditions explicitly are F 1A = 1F A and F (g ◦ f ) =


Fg ◦ Ff.

Functors thus compose (when categories line up) and have identities, making categories
and functors into a category of categories. Indeed, one can define the category Cat whose
objects are (small) categories and whose morphisms are functors. Composition of functors
is defined by (G ◦ F )(−) := G(F (−)) on both objects and arrows, which is associative and
has an identity (the identity functor 1C that maps each object to itself and each arrow to
itself).

A quick sanity check: a functor F : C → D must send identities to identities, and


composition to composition. So F sends any commutative diagram in C to a commutative
14 CHAPTER 1. BASIC CATEGORY THEORY

diagram in D (because if some h◦g◦f equals some other composition in C, applying F yields
F (h) ◦ F (g) ◦ F (f ) equals the corresponding other composition in D). In particular, if a
certain equation holds between morphisms in C, the corresponding equation holds between
their images in D. In this sense, functors are structure-preserving maps between categories.

Example 1.12 (Examples of Functors). We list some basic examples of functors:

• The identity functor 1C : C → C maps each object to itself and each morphism to
itself. Clearly, it satisfies 1C (g ◦ f ) = (1C g) ◦ (1C f ) since it’s just g ◦ f = g ◦ f , and
identities map to identities trivially.

• For any two categories C and D, any mapping that sends objects to objects and
arrows to arrows and respects source/target can be checked if it’s a functor. For
instance, if we have C as a discrete category (only identity morphisms), then giving
a functor F : C → D is equivalent to choosing an object of D for each object of C;
there is no further condition because the only morphisms are identities which must
go to identities. So functors subsume the notion of indexing or picking out objects.

• A constant functor: Fix a category D and an object D ∈ D. For any category C,


define a functor F : C → D by F (A) = D for all objects A, and F (f ) = idD for all
morphisms f . This sends everything to D and only identity morphisms. It is indeed
a functor (composition and identities all map to 1D which works). This is called a
constant functor picking the object D. It is analogous to a constant function in set
theory.

• If C is a one-object category corresponding to a monoid M (Example 1.4), then a


functor F : C → D amounts to an object D = F (∗) in D together with a morphism
F (m) : D → D for each m ∈ M , satisfying F (1) = idD and F (m2 · m1 ) = F (m2 ) ◦
F (m1 ). So F is precisely a monoid homomorphism from M to the endomorphism
monoid EndD (D) (the set of all D → D arrows under composition). In particular,
if D = Set, F corresponds to an action of M on the set F (∗). Thus, functors from
one-object categories recover the notion of a group or monoid action on some object.

• Consider the inclusion of a subcategory as a functor: If C is a category and C ′ is a


subcategory (meaning Ob(C ′ ) ⊆ Ob(C) and for any two objects in C ′ , C ′ (A, B) ⊆
C(A, B), and composition in C ′ is the same as in C), then the inclusion map I : C ′ ,→ C
that sends each object and morphism to itself (viewed as an object or morphism in
C) is a functor (identity on each homset, preserving composition by definition). For
example, the functor I : Grp → Mon (viewing every group as a monoid by forgetting
inverses) is an inclusion functor (not full or essentially surjective, but faithful—terms
defined below).
1.3. FUNCTORS AND NATURAL TRANSFORMATIONS 15

• If C and D are poset categories (Example 1.3), then a functor F : C → D is exactly a


monotone function between posets: a ≤ b in C implies F (a) ≤ F (b) in D. The functor
conditions reduce to that single condition since the only morphisms are given by the
order. For instance, if C = (P, ≤) and D = (Q, ≤) are posets, then giving F : P → Q
such that x ≤ y =⇒ F (x) ≤ F (y) is equivalent to giving a functor between them.
We now introduce two important properties of functors: faithfulness and fullness.
These generalize the idea of an injective or surjective function, but in the context of map-
ping hom-sets.

Definition 1.13 (Full and Faithful Functors). A functor F : C → D is said to be:


• Faithful if for every pair of objects A, B in C, the function

F : C(A, B) → D(F (A), F (B))

(mapping each f : A → B to F (f ) : F (A) → F (B)) is injective. Equivalently, differ-


ent morphisms in C are never mapped to the same morphism in D.

• Full if for every A, B in C, the function

F : C(A, B) → D(F (A), F (B))

is surjective onto D(F (A), F (B)). That is, for every morphism g : F (A) → F (B) in
D, there exists at least one morphism f : A → B in C with F (f ) = g.

If F is both full and faithful, we say F is an embedding of C into D (also sometimes


called a fully faithful functor, which essentially identifies C as a subcategory of D up to
isomorphism).

Intuitively, a faithful functor doesn’t ”identify” distinct arrows from C (no information
about morphisms is lost), and a full functor doesn’t ”miss” any arrows between the images
(any potential arrow in D between images actually comes from an arrow in C). An easy
example: the inclusion functor I : Grp → Mon (from groups to monoids) is faithful (a
group homomorphism is uniquely determined by itself as a monoid homomorphism, since
I is injective on each hom-set), but not full (e.g., a monoid homomorphism between two
groups that is not a group homomorphism wouldn’t come from Grp). The inclusion of a
subcategory is always full and faithful by definition.

At this point, we have categories and functors, giving us a category-of-categories view-


point. The next level of structure is to consider transformations between functors, known
16 CHAPTER 1. BASIC CATEGORY THEORY

as natural transformations. These will be crucial for capturing the idea of equivalence
of categories (two categories being ”essentially the same”) and in many constructions like
limits, adjoints, etc.

Definition 1.14 (Natural Transformation). Let F, G : C → D be two functors between


the same categories. A natural transformation η : F ⇒ G is a family of morphisms in
D, one for each object of C, satisfying a compatibility condition:

• For each object A ∈ C, there is a morphism (called the component of η at A)


ηA : F (A) → G(A) in D.

• For every morphism f : A → B in C, the following naturality square commutes in


D:
F (f )
F (A) F (B)
ηA ηB

G(A) G(B)
G(f )

That is, G(f ) ◦ ηA = ηB ◦ F (f ).

If such an η exists, we say η : F ⇒ G is a natural transformation from F to G. If each


component ηA is an isomorphism in D, then η is called a natural isomorphism, and F
and G are said to be naturally isomorphic (written F ∼ = G).

Diagrammatically, a natural transformation is a ”vertical arrow” connecting two par-


allel functors, such that for every arrow in the source category, a certain square commutes.
The commutative square means η respects the action of each f : A → B, ensuring the
transformation is in some sense uniform or ”natural” across all morphisms of C (hence the
term natural). We can visualize η as a collection of arrows ηA : F (A) → G(A) for each A,
making all these squares commute.

In the diagram above, the equation G(f ) ◦ ηA = ηB ◦ F (f ) expresses exactly that com-
mutativity. It can be remembered as: first apply F to f then η at B, or first apply η at A
then apply G to f — both ways give the same result from F (A) to G(B).

Example 1.15 (Natural Transformations). Here are some examples to solidify the concept
of natural transformations:
1.3. FUNCTORS AND NATURAL TRANSFORMATIONS 17

• Identity transformation: For any functor F : C → D, there is an identity natural


transformation 1F : F ⇒ F , whose components are 1F (A) : F (A) → F (A) for each
object A. The naturality square trivially commutes because G = F and ηA = 1F (A)
so both sides of the equation are just F (f ). This is analogous to the identity mor-
phism but in the functor category.

• Twist transformation: Consider the functors F, G : Set × Set → Set defined by


F (X, Y ) = X × Y and G(X, Y ) = Y × X, the Cartesian product functor and the
”twisted” product. There is a natural transformation t : F ⇒ G whose component at
each pair (X, Y ) is the ”swap” isomorphism t(X,Y ) : X × Y → Y × X, (x, y) 7→ (y, x).
This t is natural because given any pair of functions f : X → X ′ , g : Y → Y ′ , the
square
f ×g
X ×Y X′ × Y ′
t(X,Y ) t(X ′ ,Y ′ )

Y ×X g×f
Y ′ × X′

commutes. Indeed t(X ′ ,Y ′ ) ◦ (f × g) = (g × f ) ◦ t(X,Y ) because both send (x, y) to


(g(y), f (x)). This shows the twist is a natural iso between the product functor and
its opposite-order version.

• Conjugation in group functors: Let G be a fixed group seen as a one-object


category G. Consider two functors F, H : G → G corresponding to two homomor-
phisms f, h : G → G (each given by what they do on the single object ∗). A natural
transformation η : F ⇒ H consists of a single component η∗ : ∗ → ∗ which is just
an element g ∈ G (since hom(∗, ∗) = G). The naturality condition for the unique
(nontrivial) a ∈ hom(∗, ∗) (an element of G) says H(a) ◦ η∗ = η∗ ◦ F (a). Writing this
in group terms: h(a) · g = g · f (a) for all a ∈ G. This is exactly the condition that
g conjugates f into h, i.e. h(a) = gf (a)g −1 . So a natural transformation between
two group homomorphisms is a group element g implementing a conjugation between
them. In particular, f and h are naturally isomorphic functors iff they are conjugate
homomorphisms.

This last example is quite illustrative: it shows that “naturally isomorphic functors”
capture the idea of equivalence up to internal symmetry. Two functors f, h : G → G being
conjugate is an example of natural isomorphism. In category theory, we often regard two
functors or even two categories as ”essentially the same” if there is a natural isomorphism
or an equivalence between them.
18 CHAPTER 1. BASIC CATEGORY THEORY

Now, with natural transformations, we can form a new category called a functor cate-
gory. Given two categories C and D, the category [C, D] (or DC ) has as objects all functors
C → D, and as morphisms all natural transformations between such functors. Composition
in [C, D] is defined by “vertical composition” of natural transformations: if η : F ⇒ G and
θ : G ⇒ H, then (θ ◦ η)A = θA ◦ ηA for each object A. One must check this is again
natural (which it is, by an exercise in diagram chasing) and associative. The identity in
this functor category is 1F for each functor F .

The functor category [C, D] is sometimes denoted DC . If C is small and D is locally


small, then DC is locally small (in fact, Hom(F, G) is the set of all natural transformations
F ⇒ G). This functor category concept is powerful: it allows us to consider “metacat-
egories” of functors and reason about functors themselves using categorical notions like
limits or adjoints. We will encounter SetC which is the category of all set-valued functors
on C, important in the Yoneda lemma.
op
One particularly important functor category is SetC , the category of all contravariant
set-valued functors on C. These are called presheaves on C. The Yoneda lemma, which
op
we will see later, relates C to a full subcategory of SetC . But before we reach Yoneda, we
need to cover the notion of universal properties like initial objects, products, etc., which
will be useful across logic and type theory.

1.4 Universal Constructions: Initial Objects, Products, and


Limits
A central idea in category theory is to characterize mathematical constructions by univer-
sal properties. These are often phrased as existence and uniqueness of certain morphisms
making a diagram commute. Universal properties lead to definitions of limits and colim-
its, generalizing concepts like products, coproducts, intersections, unions, inverse limits,
etc. In logic, these correspond to logical connectives (e.g. categorical product corresponds
to logical conjunction, as we will see) and in type theory to type constructors (product
types, sum types). Here we introduce a few basic universal constructions: initial/terminal
objects and binary products, which will be directly relevant to categorical semantics of
logic and type theory.

Definition 1.16 (Terminal and Initial Objects). In a category C:

• A terminal object is an object T such that for every object A in C, there exists
a unique morphism A → T . (In other words, a terminal object can be seen as an
empty limit.) It is sometimes denoted by 1.
1.4. UNIVERSAL CONSTRUCTIONS: INITIAL OBJECTS, PRODUCTS, AND LIMITS19

• An initial object is an object I such that for every object A, there exists a unique
morphism I → A. (Thus, an initial object may be regarded as an empty colimit.)
It is often denoted by 0.

By definition, if T is terminal, for each A there is exactly one arrow !A : A → T (some


texts use this exclamation mark notation). Terminal objects are “universal receivers” of
arrows. Dually, initial objects are “universal sources” of arrows (unique arrow out of the
initial object).

Terminal and initial objects, if they exist, are unique up to isomorphism. For example,
in Set, any singleton set is a terminal object: given any set A, there is a unique function
from A to {∗} (sending every element of A to the single element ∗). All singletons are
isomorphic (indeed equal in Set if we pick a particular one, say {0}, as the distinguished
terminal). Dually, the empty set ∅ is an initial object in Set: for any set A, there is exactly
one function ∅ → A (the empty function). In Set, ∅ is initial and any singleton is terminal.

In a poset category (viewing a poset as a category with arrows as order relations), a


terminal object is an object that every other object has exactly one arrow to: that means
an element T such that for all x, x ≤ T and the arrow is unique which implies the order
is antisymmetric so T is a top element (maximum). So “terminal” in a poset is the same
as having a greatest element. Similarly, initial is a least element (minimum). Many order
examples correspond to algebraic notions like 1 being a unit (top element) and 0 being a
zero element (bottom element) in lattices.

Initial and terminal objects are special cases of limits and colimits (specifically, an ini-
tial object is an empty limit, a terminal object is an empty colimit). These objects are
especially significant in logic: for instance, an initial object in a category of models can
represent an ”inconsistent theory” because there’s a unique arrow from it to any object
(meaning a false proposition implies anything). But let’s not get ahead of ourselves.

Next, consider binary products. The categorical product generalizes the Cartesian
product of sets, the direct product of groups, etc., by a universal property. It also will later
correspond to conjunction in logic and product types in type theory.

Definition 1.17 (Binary Product). Given two objects A and B in a category C, a product
of A and B is an object P equipped with two morphisms (projections) π1 : P → A and
π2 : P → B, such that for any object X with morphisms f : X → A and g : X → B, there
exists a unique morphism h : X → P (called the mediating morphism or pairing of f
20 CHAPTER 1. BASIC CATEGORY THEORY

and g, often denoted ⟨f, g⟩) making the following diagram commute:

X
f g
h

A π1 P π2 B.

In other words, π1 ◦ h = f and π2 ◦ h = g, and h is the unique arrow from X to P with


that property. We often denote the product as A × B (especially in Set or in a category
with a set-like flavor) and write π1 : A × B → A, π2 : A × B → B.

This is a universal property: the product (P, π1 , π2 ) is such that any “cone” of mor-
phisms X → A and X → B factors uniquely through P . The dashed arrow in the diagram
above is determined uniquely by f and g. One often says (P, π1 , π2 ) is the universal cone
from (A, B). More formally, it is the limit of the diagram consisting of A and B with
no arrows between them (just two objects) – but we’ll stick to this concrete definition for
binary products.

From this definition, one can prove that if a product exists, it is unique up to unique
isomorphism. Essentially, if (P, π1 , π2 ) and (P ′ , π1′ , π2′ ) are two products of A and B, by
universality a unique iso between P and P ′ can be constructed. So we can speak of the
product of A and B in a category (assuming it exists).

In Set, the product is the usual Cartesian product: given sets A and B, A × B with
projection maps to each coordinate is a product in the categorical sense. Indeed, given
any set X and functions f : X → A, g : X → B, the universal property is satisfied by the
function h : X → A × B defined by h(x) = (f (x), g(x)). This h is unique with the property
π1 (h(x)) = f (x), π2 (h(x)) = g(x), so A × B with projections is a product in Set.

In Grp, the product of two groups is the direct product group G × H with componen-
twise operations. The projections are the group homomorphisms sending (g, h) to g and
to h respectively. The universal property holds: given homomorphisms f : X → G and
g : X → H, the unique homomorphism h : X → G × H is h(x) = (f (x), g(x)), which is a
homomorphism if f, g are.

In any category with a terminal object 1, the product of an object A with 1 (if it ex-
ists) is isomorphic to A (since a terminal object 1 satisfies a similar universal property, the
mediating map from any X to A × 1 corresponds to giving maps to A and 1, but there’s
a unique map to 1, so it’s essentially the same as a map to A). So A × 1 ∼ = A. In Set,
A × {∗} ∼ = A obviously.
1.4. UNIVERSAL CONSTRUCTIONS: INITIAL OBJECTS, PRODUCTS, AND LIMITS21

One can also define binary coproducts dually: an object C with injections i1 : A → C,
i2 : A → C universal for any object X with arrows from A and B into X. That is a pushout
of two initial maps or simply a co-product. In Set, the coproduct is disjoint union A ⨿ B
(with inclusion maps). In Grp, coproduct is the free product of groups. In logic and type
theory, coproduct corresponds to disjunction or sum types.

Now, the power of categorical definitions is that they yield theorems like: if a certain
universal property is satisfied, then certain consequences follow automatically. For example,
one can prove:
Proposition 1.18 (Uniqueness of Products Up to Isomorphism). If (P, π1 , π2 ) is a product
of A and B and (P ′ , π1′ , π2′ ) is another product of A and B in the same category, then there
is a unique isomorphism φ : P → P ′ such that π1′ ◦ φ = π1 and π2′ ◦ φ = π2 .
Proof. By the universal property of (P, π1 , π2 ), since π1′ : P ′ → A and π2′ : P ′ → B are
maps from P ′ into A and B, there is a unique map u : P ′ → P with π1 ◦ u = π1′ and
π2 ◦ u = π2′ . Similarly, by universality of (P ′ , π1′ , π2′ ) given π1 : P → A, π2 : P → B,
there is a unique map v : P → P ′ with π1′ ◦ v = π1 and π2′ ◦ v = π2 . Now consider
v ◦ u : P ′ → P ′ . This arrow satisfies π1′ ◦ (v ◦ u) = π1′ and π2′ ◦ (v ◦ u) = π2′ (because
π1′ ◦ v = π1 , then π1′ ◦ (v ◦ u) = (π1′ ◦ v) ◦ u = π1 ◦ u = π1′ , and similarly for π2′ ). But the
identity idP ′ : P ′ → P ′ also satisfies π1′ ◦ idP ′ = π1′ , π2′ ◦ idP ′ = π2′ . By the uniqueness in
the definition of product applied to P ′ , we must have v ◦ u = idP ′ . Similarly u ◦ v = idP .
Thus u and v are inverses, giving the isomorphism. The equalities πi′ ◦ v = πi ensure
πi′ ◦ (v ◦ u) = πi′ hold as used. Therefore φ := v is the desired isomorphism (its inverse
is u) and it is unique by the same kind of reasoning (since any such φ must satisfy those
projection equalities and thus must equal v by uniqueness).

This formal argument mirrors a common approach in category theory: use universality
twice to get mutual inverses. It highlights that a product, if it exists, is essentially deter-
mined by A and B.

Given the product (P, π1 , π2 ), sometimes we write P = A × B and denote the unique
arrow from any X by ⟨f, g⟩ : X → A × B such that π1 ◦ ⟨f, g⟩ = f and π2 ◦ ⟨f, g⟩ = g. This
notation ⟨f, g⟩ is called the pairing of f and g.

One can derive a more concise definition of product from this: P is a product iff there
is a bijection
hom(X, P ) ∼
= hom(X, A) × hom(X, B)
naturally in X. This means each map X → P corresponds exactly to a pair of maps X → A
and X → B. The bijection is given by h 7→ (π1 ◦ h, π2 ◦ h), and its inverse is (f, g) 7→ ⟨f, g⟩.
Naturality in X ensures this bijection is functorial in X (like an isomorphism of functors
22 CHAPTER 1. BASIC CATEGORY THEORY

in X), which holds by uniqueness property.

Products are a special case of limits. There are other limits like equalizers, pullbacks,
etc., but products and terminal objects are enough to define what is known as a Cartesian
category (one with all finite products). If a category has a terminal object and binary
products for every pair of objects, it is a Cartesian monoidal category essentially, which
in logical terms means it can interpret conjunction and truth (the unit for conjunction).

In logic, if we think of C as a category of “domains” (like sets) and morphisms as “in-


terpretations of proofs or functions”, a terminal object corresponds to a truth value ⊤
(since from any context there’s a unique way to derive truth, reflecting the idea that truth
is always true), and a product corresponds to a logical conjunction (to give a map into
A × B is to give a proof of A and a proof of B simultaneously, echoing the meaning of
A ∧ B). We will formalize this correspondence later.

For now, let’s practice with a short exercise:

Exercise 1.19. Verify in the category Set that:

1. A terminal object exists and is a singleton set. Prove that if T and T ′ are two
singleton sets, there is a unique bijection T → T ′ (hence they are isomorphic in Set).

2. The product of two sets A and B as per Definition 1.17 is given by the Cartesian
product A × B with the usual projections. Formally show the uniqueness of the
mediating arrow h : X → A × B given f : X → A and g : X → B.

3. Dually, describe the coproduct of two sets A and B in Set (this is the disjoint union
A ⨿ B). What are the injection morphisms, and why is the mediating morphism (out
of A ⨿ B) unique?

We will not dive deeper into general limits and colimits (like equalizers, coequalizers,
pullbacks, pushouts) right now, though they are defined similarly by universal properties.
Instead, having established some categorical fundamentals, we proceed to see how these
concepts play out in categorical logic. We will start with algebraic theories and propo-
sitional logic in the next chapter, where finite products and certain special objects (like
truth values) come into play.
Chapter 2

Algebraic Theories and


Propositional Logic

In this chapter, we bridge category theory with logic by examining algebraic theories
(also known as Lawvere theories) and categorical semantics of propositional logic. Alge-
braic theories provide a categorical framework for equational reasoning about algebraic
structures (like groups, rings, etc.), while propositional logic provides the simplest case of
logical deduction, which we can analyze categorically via Boolean or Heyting algebras and
their dual spaces. We will see that both can be subsumed under the idea of categories
with certain universal properties: finite product categories for algebraic theories, and (for
propositional logic) Boolean algebras as certain categorical structures.

2.1 Algebraic Theories and Functorial Semantics


An algebraic theory in the sense of Lawvere is a presentation of an algebraic structure by
operations and equations, with the restriction that it only deals with operations of finitely
many inputs and equations that are universally quantified (no relations or quantifiers be-
yond ∀ for equations). Examples include the theory of groups, rings, lattices, etc. Each
such theory can be represented by a category whose objects are finite lists of variables
(or equivalently natural numbers representing arity) and whose morphisms are equivalence
classes of terms (operations) in those variables.

The approach we take here follows Lawvere’s insight: a theory can be identified with
a category with finite products in which certain objects (arities) and arrows (operations)
are specified, and models of the theory correspond to product-preserving functors from that
category to Set.

23
24 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC

2.1.1 Syntax and Theories as Categories


Let’s outline how to go from a conventional algebraic theory (with operations and equa-
tions) to a category:
- Start with a signature Σ: a set of operation symbols, each with a given finite arity. For
example, in the theory of groups, Σ = {e : 0-ary, m : 2-ary, i : 1-ary} containing a con-
stant e, a binary operation m (multiplication), and a unary operation i (inverse).
- Consider the term algebra built from this signature: for each natural number n (think
of n as a set of n distinct variables x1 , . . . , xn ), one can form terms in those n variables
using the operations. Equations are pairs of terms of the same arity (like m(x, e) = x).
- The Theory category TΣ has as objects the natural numbers (or equivalently, finite sets
{x1 , . . . , xn } of variables). A morphism n → m in TΣ is given by m terms in n variables:
essentially an m-tuple of Σ-terms each using n input variables. Composition of morphisms
is substitution of terms into each other.
- To enforce the equations of the theory, we take a quotient of this term category by the con-
gruence generated by those equations. That is, identify morphisms (tuples of terms) if the
corresponding equations can prove they are equal. The result is a category (indeed a Law-
vere theory) in which morphisms represent equivalence classes of terms modulo the axioms.

Crucially, TΣ is a category with finite products: the product of objects n and m is just
n + m (because a context with n variables and a context with m variables together give
n + m variables). The terminal object is 0 (no variables, the context of a closed term).
The projection maps in this category correspond to projection terms. This category can
be seen as the classifying category of the theory: models of the theory correspond to
product-preserving functors from TΣ to Set.

Let’s illustrate with a simple algebraic theory:

Example 2.1 (Theory of Monoids as a Category). Consider the theory of monoids. The
signature Σ has a constant e (unit) and a binary operation · (multiplication). The axioms
are:
x · (y · z) = (x · y) · z, x · e = x, e · x = x.

In the theory category TMon :

• Objects are the natural numbers 0, 1, 2, . . . , where n represents a context with n free
variables.

• A morphism f : n → 1 is given by a single term in n variables modulo the monoid


axioms. For example, the term
x1 · (x2 · e)
2.1. ALGEBRAIC THEORIES AND FUNCTORIAL SEMANTICS 25

represents a morphism 2 → 1 and, using the axiom x2 · e = x2 , is identified with


x1 · x2 .

• More generally, a morphism n → m is an m-tuple of terms in n variables.

To illustrate composition, consider the following concrete instance. Let

f :2→2 be given by f (x1 , x2 ) = (x21 , x2 )

(where x21 denotes x1 · x1 ), and let

g:1→2 be given by g(z) = (z · z, e).

Composing g with f means substituting in f the term z · z for x1 and e for x2 . Thus, the
composite morphism
f ◦g :1→2
is given by
f ◦ g(z) = (z · z)2 , e ,


and since (z · z)2 equals z · z · z · z (i.e. z 4 ), the result is

(z 4 , e) : 1 → 2.

This cleanly demonstrates substitution and the use of the axioms.

TMon has finite products: the product of object m and n is m + n. The projection
π1 : m + n → m is given by the tuple of terms that picks out the first m inputs and ignores
the rest (like π1 (x1 , . . . , xm+n ) = (x1 , . . . , xm ), π2 picks xm+1 , . . . , xm+n ). These satisfy
the universal property by term-wise combination.

A functor F : TMon → Set that preserves finite products will assign F (1) a set (call
it M ) and interpret the constant e as an element F (e) ∈ M = F (1), and the binary op-
eration · as a function M × M = F (1) × F (1) → F (1) (since F takes the arrow 2 → 1
corresponding to multiplication term to a function F (2) = M × M → M ). Preservation
of products ensures F (2) ∼ = F (1) × F (1) = M × M . F will automatically satisfy the ax-
ioms, because those correspond to equalities of morphisms in TMon which F will preserve,
yielding equalities of functions on M . Thus (M, F (·), F (e)) is a monoid in Set. Conversely
any monoid (M, ·, e) yields such a functor (called the forgetful functor from the theory
to Set picking out that model). Therefore, Functprod (TMon , Set) (the category of finite
product preserving functors and natural transformations between them) is equivalent to
the category of monoids and monoid homomorphisms.
26 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC

The above example demonstrates the core idea: there is a category T (sometimes called
the theory category or classifying category) whose product-preserving set-valued func-
tors correspond exactly to models of the theory T in Set. This result is often referred to
as functorial semantics or the duality between theories and categories of models:

Theorem 2.2 (Soundness and Completeness for Equational Logic (Functorial Semantics)).
Let T be an algebraic theory (presented as a category with finite products, as above). Then:

1. (Soundness) Any equation s = t derivable from the axioms of T holds in every model
of T . Equivalently, if s and t are represented by the same morphism u : n → 1 in the
theory category T (meaning s and t are proved equal), then for any product-preserving
functor (model) M : T → Set, the interpretations M (s), M (t) : M n → M 1 are the
same function.

2. (Completeness) If an equation s = t (with s, t terms in n variables) holds in every


set-based model of T , then it is derivable from the axioms of T (i.e., becomes equal as
morphisms in T ). Equivalently, if for all product-preserving functors M : T → Set
we have M (s) = M (t) as functions M n → M , then s = t can be proved from T ’s
axioms.

Thus, the category T together with the forgetful functor U : Functprod (T, Set) → Set (select-
ing the underlying set of the interpretation of one generator) forms a classifying category
for the theory, in the sense that T is initial among categories receiving a product-preserving
functor from T .

Proof. This is essentially a restatement of the fact that T captures exactly the provable
equalities. For soundness: if s = t in T , then M (s) = M (t) for any functor M because
M is a functor (so it preserves equalities of morphisms in T ). In other words, provable
equality implies semantic equality in all models. This is just saying the functor M cannot
distinguish s and t if T itself doesn’t.

For completeness: Suppose s ̸= t in T (not provably equal). Then as distinct mor-


phisms s, t : n → 1, by the nature of categories of this form, we can find a model M
(a functor) that separates them. Concretely, one standard argument is to take a model
in Set that is the term model (or free model) of T on n generators. In that free model,
the interpretations of s and t will be distinct elements (because if they were equal in the
free model, that would already impose an equation derivable in T by the principle of free
objects). This M can be constructed by taking M (1) as the set of T -terms in n variables
modulo provable equality, and interpreting each operation symbol as the induced operation
on those equivalence classes. By construction M (s) ̸= M (t) in this model, yet M is a valid
2.1. ALGEBRAIC THEORIES AND FUNCTORIAL SEMANTICS 27

product-preserving functor (since the term model obviously satisfies the axioms), contra-
dicting the assumption. So if no model distinguishes s and t, they must already be equal in
T . This establishes that semantic equality (holding in all models) implies provable equality.

In categorical terms, T is initial among all categories with finite products equipped
with a model of the theory, which is a general statement of completeness: given any model
M : T → Set, there is a unique morphism from T to the category ”generated” by M . But
perhaps the simplest explanation is the term algebra argument given above.

This theorem connects syntactic and semantic notions: it’s essentially the completeness
of equational logic (as every equation true in all models is derivable). There is a precise
contravariant equivalence between the category of algebraic theories (i.e. small categories
with finite products, known as Lawvere theories) and the category of their Set-models.
More precisely, for a Lawvere theory T , one associates the category T -Mod of product-
preserving functors T → Set. This assignment establishes a duality: informally,

Th ≃ (Mod)op ,

meaning that the syntactic category of a theory is (up to equivalence) dual to the category
of its models. This is often referred to as Lawvere duality.
In short, categories allow us to algebraically encode theories, and then use category-
theoretic constructs (like functor categories) to reason about models. This viewpoint will
extend when we add more logical constructs beyond plain equations (like adding ∨, ∃, etc.,
requiring more structure like coequalizers or left adjoints).

2.1.2 Examples of Algebraic Categories and Functors


To ground the above in more examples:
- If T is the theory of groups, then T is a category with finite products, and Functprod (T, Set) ≃
Grp, the category of groups.
- A homomorphism of models corresponds to a natural transformation between the cor-
responding functors (one can show that product-preserving functors T → Set are in fact
determined by the set X = F (1) with the structure of an algebra, and a natural trans-
formation between F and G corresponds to a function F (1) → G(1) commuting with the
interpretations of operations, i.e., an algebra homomorphism).
- There is a slight generalization: if instead of Set we consider functors T → C for some
other category C with finite products, those correspond to C-models of the theory. For
example, a product-preserving functor TGrp → Set yields a group (set-based model), while
a product-preserving functor TGrp → Cat would yield a group object in Cat, which is es-
sentially a group in the category of categories (which might be just a one-object group-like
28 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC

category), etc.

The concept of classifying category T for a theory is analogous to a classifying space


in topology or classifying topos in logic: it is an entity that encapsulates the theory fully
so that (in this case) set-based models correspond to functors from it. This notion will
reappear when we consider first-order logic, where instead of a category with finite prod-
ucts, we will need categories with additional structure (like finite limits, or a topos with
subobject classifier, etc.) to classify more complex theories.

We have focused on set-valued models. One can show a more general statement: T not
only classifies set models, but also T itself as a functor T → T is the generic model (the
identity functor considered as a model in its own category), and any model M : T → C
in a different category C factors through a unique interpretation from the generic model.
This is part of the universal property: T is an initial object in the category of categories
with finite products and a chosen model of the theory. We won’t formalize that further
here, but conceptually it’s important: the theory category yields a generic model such
that all others are its images.

Now, having established how categories capture algebraic (essentially universally quan-
tified equation) logic, we move to propositional logic, which introduces connectives that
are not just operations on one set, but truth-functional operations, and often involves a
two-valued truth notion in classical logic or multi-valued in intuitionistic logic. We will
first treat classical propositional logic via Boolean algebras and Stone duality, then intu-
itionistic logic via Heyting algebras and locales.

2.2 Boolean Algebras and Classical Propositional Logic


Classical propositional logic can be seen as an algebraic theory, but not quite an algebraic
theory in the finitary sense, because it has not just operations ∧, ∨, ¬ which are finitary,
but the laws involve also the nullary operations true (⊤) and false (⊥), and critically,
the law of double negation or excluded middle is non-algebraic if considered as a scheme.
However, propositional logic can indeed be captured by the notion of a Boolean algebra:
an algebraic structure with operations ∧, ∨, ¬, 0, 1 satisfying certain axioms (those of a
complemented distributive lattice).

Definition 2.3 (Boolean Algebra). A Boolean algebra is a set B equipped with binary
operations ∧ (meet, logical ”and”) and ∨ (join, logical ”or”), a unary operation ¬ (comple-
ment, logical ”not”), and distinguished elements 0 (bottom, false) and 1 (top, true), such
that for all a, b, c ∈ B the following axioms hold:
2.2. BOOLEAN ALGEBRAS AND CLASSICAL PROPOSITIONAL LOGIC 29

• (B, ∧, ∨) is a distributive lattice: - a ∧ (b ∧ c) = (a ∧ b) ∧ c and a ∨ (b ∨ c) = (a ∨ b) ∨ c


(associativity);
- a ∧ b = b ∧ a, a ∨ b = b ∨ a (commutativity);
- a ∧ (a ∨ b) = a, a ∨ (a ∧ b) = a (absorption laws);
- a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c), a ∨ (b ∧ c) = (a ∨ b) ∧ (a ∨ c) (distributivity of ∧ over
∨ and vice versa).

• Complement laws: for each a ∈ B, - a ∧ ¬a = 0 and a ∨ ¬a = 1.

• 0 and 1 are the identity elements for ∨ and ∧ respectively: a ∨ 0 = a, a ∧ 1 = a.

This definition is algebraic: all axioms are universally quantified equations in the lan-
guage {∧, ∨, ¬, 0, 1} (the complement law a ∨ ¬a = 1 and a ∧ ¬a = 0 are equations, not
implications). So one could indeed form a theory category for Boolean algebras and get
a similar correspondence with Boolean algebras as product-preserving functors into Set.
Boolean algebras capture exactly the equational part of propositional logic: a Boolean
algebra homomorphism is a function h : B1 → B2 preserving ∧, ∨, ¬, 0, 1. The category
Bool of Boolean algebras and homomorphisms is algebraic.

But propositional logic usually is presented as a deductive system with propositional


variables, formulas built via logical connectives, and inference rules. There is a straight-
forward connection:
- If you take the free Boolean algebra on a set of generators (propositional variables), its
elements correspond to propositional formulas modulo logical equivalence.
- In particular, the free Boolean algebra on no generators (just constants) has exactly two
elements and corresponds to classical propositional calculus with no propositional variables,
which can only produce either tautology (True) or contradiction (False). That algebra is
the two-element Boolean algebra 2 = {0, 1} with 0 and 1.
- The two-element Boolean algebra 2 plays the role of the set of truth values. In fact, any
Boolean algebra can be seen as the algebra of propositional values of some logical theory:
an element a ∈ B is like the truth value of some proposition under some maximal consistent
assignment of truth values to atoms. (This can be made precise: any Boolean algebra is iso-
morphic to a field of sets, via Stone’s representation theorem; each element corresponds to
a set of ”possible worlds” or ultrafilters where that proposition is true. More on that soon.)

The key result bridging Boolean algebras and propositional logic is that the equational
theory of Boolean algebras is equivalent to classical propositional logic in the sense that a
formula is a tautology iff it equals 1 in every Boolean algebra interpretation (soundness and
30 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC

completeness of Boolean algebra semantics for propositional logic). This can be stated as:

Theorem 2.4 (Soundness and Completeness of Propositional Calculus). Let Φ be a set of


propositional formulas (assumptions) and φ a formula. Then the following are equivalent:
1. Φ ⊢ φ (formula φ is provable from premises Φ in classical propositional calculus).
2. Every Boolean algebra valuation that makes all formulas in Φ equal 1 (true) also
makes φ = 1.

3. In every Boolean algebra B and every homomorphism v : Form → B sending each


assumption in Φ to 1, we have v(φ) = 1 in B. Here Form is the free Boolean algebra
on the set of propositional variables (so a formula is interpreted as an element of B
under v).

Consequently, a formula φ is a tautology (provable with no assumptions) if and only if φ


evaluates to 1 in all Boolean algebra valuations (which includes the usual two-valued truth
table evaluation as a special case with B = 2).
Proof. (1 ⇒ 2) is soundness: if Φ ⊢ φ, then any interpretation making Φ true must make
φ true. This is proved by induction on the length of the proof; it holds for each axiom
(which are tautologies) and is preserved by inference rules (Modus Ponens corresponds to
a certain condition on valuations preserving implication truth). Boolean algebra semantics
is equivalent to truth-table semantics for propositional logic (by Stone’s representation,
but even easier: if something holds in all Boolean algebras, in particular it holds in 2, the
standard truth values), so this is the usual soundness of propositional logic.

(2 ⇒ 1) is completeness: if Φ ̸⊢ φ, then Φ ∪ {¬φ} is consistent, extend it to a maximal


consistent set Γ. Γ corresponds to an ultrafilter of formulas (all formulas that Γ proves).
One then defines a Boolean algebra B as the set of all equivalence classes of formulas mod-
ulo Γ-provable equivalence. This B is a Boolean algebra model where each formula ψ is
mapped to its equivalence class [ψ]. In B, each element of Φ maps to 1 (since each ψ ∈ Φ
is in Γ, hence provably true in Γ). However, φ maps to 0 in B because ¬φ ∈ Γ. Thus we
have a Boolean algebra (in fact 2 can be taken by Lindenbaum–Tarski if we just do truth
assignments) that satisfies Φ but not φ. This shows if not Φ ⊢ φ, there is a counter-model,
proving completeness.

(3) is just a restatement of (2) in algebraic terms, since ”Boolean algebra valuation” can
be formalized as a homomorphism from the free Boolean algebra (the algebra of all proposi-
tions) to B that sends each assumption (which is a specific element of the free algebra) to 1.
2.2. BOOLEAN ALGEBRAS AND CLASSICAL PROPOSITIONAL LOGIC 31

Hence, Φ ⊢ φ iff in every B and every homomorphism v with v(Φ) = {1}, we have
v(φ) = 1. In particular, taking Φ empty, ⊢ φ (tautology) iff for every Boolean algebra B
and homomorphism v, v(φ) = 1. Taking specifically B = 2 recovers the usual notion: φ is
true under every truth assignment.

This is basically the algebraic completeness (Lindenbaum algebra argument) for propo-
sitional logic, which is a special case of the general equational completeness theorem we
proved for algebraic theories, instantiated to the theory of Boolean algebras. Indeed, the
above is an example of how one would approach it using the category of Boolean algebras
and its functors to Set. The free Boolean algebra on n generators is the algebra of all
formulas in those n variables modulo provable equivalence, and a homomorphism from
that free algebra to 2 corresponds to a truth assignment. Since 2 is a Boolean algebra, the
existence of a homomorphism sending formulas to 1/0 such that assumptions go to 1 and
conclusion to 0 yields an actual Boolean valuation counterexample.

Thus, Boolean algebra semantics is equivalent to the usual semantics.

Now, category theory enters through the observation: the category of Boolean algebras
Bool is not just an ordinary algebraic category, it has some additional structure (it’s a
variety of algebras). But more interestingly, Bool is dual (in the sense of a contravariant
equivalence) to the category of certain topological spaces. This is Stone duality:

Theorem 2.5 (Stone Representation and Duality). Every Boolean algebra B is isomorphic
to a field of sets (an algebra of subsets of some set, with union, intersection, complement).
Concretely, B is isomorphic to the algebra of all clopen (simultaneously closed and open)
subsets of a certain compact Hausdorff zero-dimensional topological space X (the space of
ultrafilters of B). In addition:

• The points of X correspond to ultrafilters u of B, and the clopen set corresponding to


b ∈ B is {u ∈ X | b ∈ u}.

• This assignment extends to a dual equivalence (contravariant isomorphism of cate-


gories) between Bool and the category Stone of Stone spaces (compact Hausdorff
zero-dimensional topological spaces) and continuous maps.

• In particular, the two-element Boolean algebra 2 corresponds to a one-point space. A


homomorphism of Boolean algebras h : B1 → B2 corresponds to a continuous func-
tion XB2 → XB1 between their Stone spaces (reversing arrows, hence duality).
32 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC

Proof. (Sketch) Stone’s representation theorem constructs X = Ult(B), the set of all ultra-
filters (maximal filters) of B. Each b ∈ B defines a subset b̂ = {u ∈ Ult(B) | b ∈ u}. One
checks that b̂ is both open and closed in a certain topology (the Stone topology) on X, where
basic open sets are of form b̂. The map b 7→ b̂ is a Boolean algebra homomorphism from B
to the power set Boolean algebra P(Ult(B)), and is injective (because distinct b differ on
some ultrafilter). Surjectivity onto clopen sets follows because finite Boolean combinations
of basic opens are still clopen and generate the clopen algebra. So B ∼ = Clopen(Ult(B)) as
Boolean algebras. Ult(B) is compact and zero-dimensional by construction (clopens form
a basis), and Hausdorff because ultrafilters are distinct enough to be separated by clopens
(using an element in one ultrafilter but not another yields disjoint opens containing each
ultrafilter).

This extends to a categorical duality: Given a Boolean homomorphism h : B1 → B2 ,


the inverse image of an ultrafilter along h is an ultrafilter on B1 . Thus to each ultrafilter u
of B2 we assign h−1 (u) which is an ultrafilter of B1 . This gives a map Ult(B2 ) → Ult(B1 )
that is continuous in the Stone topology. This assignment is functorial and contravariant,
and it yields an equivalence of categories Boolop ≃ Stone.

Stone duality is very significant: it shows that Boolean logic (via Boolean algebras) is
equivalent to studying certain topological spaces. The Stone space Ult(B) of ultrafilters
can be seen as the space of all “possible worlds” or models of the propositional theory rep-
resented by B. Each ultrafilter is like a consistent assignment of truth values (a maximally
consistent set of propositions), and b̂ is the set of models where proposition b is true. So
Stone duality provides a topological semantics for propositional logic: the clopen subsets
of the Stone space form the algebra of propositions. In particular:
- If B is the Boolean algebra of all formulas modulo equivalence, then Ult(B) is essentially
the space of all truth assignments or models of the propositional theory, and a formula b
corresponds to the set of assignments satisfying it (this is a Stone representation of the
Lindenbaum algebra).
- Stone’s theorem thus gives a robust formulation of the completeness theorem: the logical
content (Boolean algebra of formulas) is captured by the structure of the space of models.

From a categorical logic viewpoint, Stone duality is the first example of a logic-space
duality: algebraic logic (Boolean algebra) vs. geometric space (Stone space). This heralds
the idea of the duality between syntax and semantics: syntax (formulas, proofs) forms an
algebra or category, semantics (models) forms spaces or categories of models, and there is
a duality or equivalence bridging them.

We will see a similar pattern for intuitionistic logic: Heyting algebras vs. topological
spaces called locales, and a duality there too (Stone duality generalizes to the so-called
2.2. BOOLEAN ALGEBRAS AND CLASSICAL PROPOSITIONAL LOGIC 33

Priestley or Esakia duality for distributive lattices or Heyting algebras, but with some
conditions one gets locales).

2.2.1 Heyting Algebras and Frames: Intuitionistic Propositional Logic


Definition 2.6 (Heyting Algebra). A Heyting algebra is a bounded distributive lattice
(H, ∧, ∨, 0, 1) equipped with a binary operation ⇒ (called implication) such that for all
a, b, x ∈ H,
a ∧ x ≤ b if and only if x ≤ (a ⇒ b).
In a Heyting algebra, one defines the negation of an element a by

¬a := (a ⇒ 0).

If additionally the law of excluded middle holds (i.e. a ∨ ¬a = 1 for every a ∈ H), then H
is a Boolean algebra.
In categorical logic terms, a Heyting algebra is a lattice that is also a Cartesian closed
poset: finite meets (including top) serve as products, and ⇒ is an internal hom making it
cartesian closed. Actually, each finite meet with some a yields an adjoint a ∧ − ⊣ (a ⇒ −),
capturing quantification: a ⇒ b plays the role of a → b or logically a =⇒ b which is also
¬a ∨ b in a Boolean algebra but not necessarily in a Heyting.

A key point: Intuitionistic propositional logic is complete with respect to models in


Heyting algebras (or equivalently in Kripke models, or topological models as we mention
soon). There is a version of Stone duality for Heyting algebras, but since a Heyting alge-
bra might not have enough complements, its dual space is not a general Stone space but a
locale (a space in point-free topology). A frame is a complete Heyting algebra (one that
has arbitrary joins and finite meets), and a locale is defined as a frame considered as an
abstract “lattice of open sets” of some space. Indeed, frames and continuous maps (which
preserve finite meets and arbitrary joins in opposite direction) form a category Frame,
and locales are defined as objects of Frameop (so a locale is really an equivalence class
of frames under isomorphism, but conceptually a locale is “a space given by its lattice of
opens”).

There is a duality (in fact an equivalence of categories) between spatial locales (those
coming from actual topological spaces via their open set lattices) and sober topological
spaces, but in general locales generalize spaces (allowing “point-free” constructions). The
slogan is “Topology = Locale = Frameop .”

In particular, the category Stone we saw is replaced in intuitionistic logic by the cat-
egory Loc of locales (or perhaps specifically coherent spaces for coherent logic). Stone
34 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC

duality generalizes to Stone–Čech duality or Priestley duality or in geometric form


to Stone duality for distributive lattices and frames. The pattern remains: the
algebra of propositions (like a Heyting algebra) corresponds contravariantly to a locale (its
spectrum or space of “pseudo-characters”).

We don’t dive deeply here, but we mention:

Definition 2.7 (Frame and Locale). A frame (L, ≤) is a complete lattice (arbitrary joins
and finite meets exist, with bottom 0 and top 1) satisfying the infinite distributive law:
_ _
a∧ bi = (a ∧ bi ) for any a ∈ L, {bi }i∈I ⊆ L.
i∈I i∈I

A frame homomorphism is a function f : L → M preserving finite meets and arbitrary


joins (including 0 and 1). The category of frames is denoted Frame.

A locale is by definition an object of the category Loc := Frameop . Concretely, a


locale can be thought of as “a space” whose lattice of opens is a given frame. If X is
Sa
topological space, O(X) (the set of open sets of X) is a frame (with ∧ = ∩ and ∨ = ).
Not every frame is of that form for some X unless X is “sober”, but one treats frames as
generalized topologies.

A frame that is also a Boolean algebra (so each element has complement) is essentially
the lattice of open sets of a Stone space, and that recovers our earlier Stone duality scenario
as a special case (Boolean algebra = Stone locale).

The connection to logic: an intuitionistic propositional theory can be associated with


a Lindenbaum–Tarski algebra which is a Heyting algebra (not necessarily complete). The
space of all prime filters of that Heyting algebra can be given a topology (the Alexandroff
topology or subbasic sets of form {p : a ∈ p}), yielding a topological space whose open sets
corresponds to the theory’s propositions. This is essentially a Stone-style representation
for Heyting algebra, known as Esakia duality (if one includes an order on the space to
represent ≤). Another approach is via Kripke models, which can be seen as particular
frames (the frame of upward closed sets of a Kripke model yields a Heyting algebra seman-
tics).

One result: the category of Heyting algebras is dual to the category of certain struc-
tured spaces called Esakia spaces (which are Stone spaces with a certain order, basically
the duals of Heyting algebras that reflect the → structure). And frames are dual to sober
topological spaces.
2.2. BOOLEAN ALGEBRAS AND CLASSICAL PROPOSITIONAL LOGIC 35

So summarizing logic vs. geometry:


- Classical Prop Logic: Boolean algebra ↔ Stone space (set of models).
- Intuitionistic Prop Logic: Heyting algebra (frame of opens) ↔ Locale (space of “points”
or models possibly not all actual points).

We have now covered categories and logic for propositional fragments. Next, we move
on to first-order logic and type theory, which require more categorical machinery (like ad-
joints for quantifiers, and dependent types or objects). Before that, we provide a couple of
exercises to practice these concepts:

Exercise 2.8. 1. Show that the category of Boolean algebras Bool has all small prod-
ucts. (Hint: The Q product of a family of Boolean algebras {Bi } can be taken as the
algebra of tuples Bi with componentwise operations. One must show the resulting
algebra satisfies the Boolean axioms and is the categorical product.)

2. Prove that a homomorphism h : B → 2 from a Boolean algebra B to the 2-element


algebra corresponds exactly to an ultrafilter of B. (Hint: h−1 (1) is a filter that is
maximal because the homomorphism can’t map both b and ¬b to 1.)

3. Verify the infinite distributive law in a powerset lattice: Given a set X,Sshow that

for
S any subset A ⊆ X and any family {B i ⊆ X | i ∈ I}, we have A ∩ i∈I Bi =
i∈I (A ∩ Bi ). This shows P(X) is a frame.

4. Consider an infinite set of propositional variables {pi | i ∈ N}. Characterize the Stone
space (dual space) of the free Boolean algebra on these generators. (Hint: points are
ultrafilters = truth assignments; the space is homeomorphic to {0, 1}N with the prod-
uct topology, a Cantor space.)

With propositional logic under our belt, we move on to considering predicates and type
theory. This will involve categories that can capture not just finite products but also other
structures such as exponentials (for implication or function types), and perhaps even more
for full dependent types. That is our next chapter.
36 CHAPTER 2. ALGEBRAIC THEORIES AND PROPOSITIONAL LOGIC
Chapter 3

First-Order Logic in Categories

First-order logic extends propositional logic by adding quantifiers that allow statements
about elements of some domain of discourse. Categorical semantics of first-order logic
requires categories that can interpret: - Conjunction and disjunction (like before, via prod-
ucts or other limits/colimits).
- Existential and universal quantifiers, which in category theory correspond to the existence
of left and right adjoint functors to the pullback along projection maps (or existence of
certain limits/colimits, specifically coequalizers, etc., to handle equivalence relations for
equality).
- Equality, which is a special predicate requiring certain properties like diagonal morphisms
and their mono nature.

In algebraic terms, first-order theories are no longer simply equational (if they have
∃ or ∀ axioms, or non-algebraic axioms), but we can often break them into sequents and
consider categories called classifying categories or syntactic categories that capture
their deductive structure.

There are two main categorical approaches to first-order logic: 1. The use of syntactic
categories (or syntactic sites) as in the work of Makkai or the concept of classifying
topos for a theory. Jacobs’s approach using fibrations is one approach: interpret contexts
and predicates in a fibered category (the category of contexts and substitutions is base,
with a fiber of propositions above each context).
2. The approach using adjoint functor semantics (Lawvere’s hyperdoctrines): The
idea that ∃ and ∀ quantifiers are adjoints to pullback along projections: specifically, in a
category with finite limits (for context and equality), a functor ΠX that is right adjoint to
pullback along πX : X × Y → Y can serve as ∀x : X, and a functor ΣX left adjoint to that
pullback can serve as ∃x : X.

37
38 CHAPTER 3. FIRST-ORDER LOGIC IN CATEGORIES

The simplest categorical structure to consider is a regular category, which is a cate-


gory with finite limits and images (stable under pullback). Regular categories correspond
to first-order theories with only ∃ and ∧ (and equality) but no ∨ or ∀ beyond the ones that
can be expressed via ∃ (like a coherent theory restricts allowed formulas). A coherent
category adds finite unions (disjunctions). A Heyting category (or arithmetic category)
adds an internal ⇒ or subobject classifier.

However, rather than define each of those from scratch, let’s conceptualize: - The sim-
plest semantics of first-order logic is given by relational structures in Set, i.e. models in
the usual Tarskian sense. But category theory can treat these as functors from a syntactic
category to Set that preserve certain limits (like product and equalizer).
- Instead of Set, one can consider models in arbitrary categories with similar structure.
E.g., models in any topos, etc.

Lawvere (1963) introduced functorial semantics of algebraic theories (which we


covered) and suggested one can do similar for more general theories via categories with
certain structure.

The notion of classifying topos is the most powerful: for any first-order (even higher-
order or type-theoretic) theory T satisfying some conditions, there is a topos ET such that
for any topos E, models of T in E correspond to logical functors ET → E (functors preserv-
ing the relevant structure, i.e., finite limits and whatever else needed). For example, the
classifying topos of the theory of groups is a topos E such that giving a group in any topos
F is equivalent to giving a logical functor E → F. When the topos is Set, such a functor
picks out a group in Set, recovering ordinary models.

Although classifying toposes are conceptually elegant, constructing them directly can
be heavy. Instead, we can proceed stepwise: - Interpret first-order logic in a fixed topos
(like Set) using the internal logic of the topos. This internal logic approach says: a topos
can serve as a universe in which logical formulas can be interpreted, with ∧, ∨, ∃, ∀ having
meaning via categorical operations (subobjects, products, etc., and a subobject classifier
Ω for truth values). If the topos is boolean (like Set) this internal logic is classical; if it’s
an arbitrary topos, it’s intuitionistic.
- But we want an abstract notion of ”category that behaves like formulas and contexts.”

We introduced in Jacobs: - Fibred category semantics: e.g., a hyperdoctrine is


a functor P : C op → Poset that gives for each object A (a context) a poset of predicates
on A, with appropriate structure (like left and right adjoints for each substitution functor)
capturing ∃ and ∀.

One can show equivalently that giving such a structure is giving a first-order logical
39

calculus semantics. Jacobs defines things like regular categories and shows the subobject
functor of a regular category is a hyperdoctrine with left adjoints to pullbacks (for ∃). If
also right adjoints exist, it’s a coherent category (with ∀ for certain monos) or Heyting
category (with all ∀). This ties to Π and Σ in type theory as well.

However, due to the complexity, let’s outline a simpler vantage:

Classifying category construction: For a first-order theory T (with function and


relation symbols and axioms), one can form a category CT whose: - objects are contexts
(finite lists of variables, or possibly formulas considered as types in dependent type par-
lance).
- morphisms are interpretation of sequents or substitutions between contexts (like a mor-
phism from context Γ to ∆ could be given by a tuple of terms ∆ in context Γ that is
*provably* making ∆ imply something? Actually, simpler: a morphism from Γ to ∆ can
be taken as an equivalence class of ∆-indexed tuples of terms or formulas in Γ, capturing
how to get a ∆ instance from each Γ instance.
One can do this systematically by taking the opposite of the category of theories as in
syntactic fibration:
Jacobs had something like: Subobject fibrations: For each context Γ, consider the set
of formulas (predicates) with free variables in Γ; they form a poset of subobjects of Γ in
some classifying category.
So one defines CT (the category of contexts and provable substitutions) and a functor
p : ET → CT such that each fiber is the poset of ”provable predicates” on that context.
That is basically the syntactic fibration which is a hyperdoctrine.
Then ET might turn out to be a topos if T is geometric or something.

Given the time, let’s articulate results: - If T is a coherent theory (allowing ∧, ∨, ∃


but not full ∀ except maybe for equality), then the classifying category of T is a coherent
category (regular plus with some finite colimits).
- If T is a first-order theory (with possibly all quantifiers), and say it is essentially equational
or something, we might need to go to a topos with a subobject classifier (the classifying
topos that ensures existence of ∀ as well).
- There’s the notion of regular category for regular logic and coherent category for
coherent logic, Heyting category or logos for full first-order (with all finite limits and
power object maybe). Jacobs calls a coherent category with a certain property a logos
(which is basically a pretopos).

Anyway, to ground with an example:

Example 3.1 (Classifying category of groups (sketch)). Consider the theory of groups in
40 CHAPTER 3. FIRST-ORDER LOGIC IN CATEGORIES

first-order logic:
- Sort: one sort (the domain of group elements).
- Function symbols: m(x, y) (multiplication), e() (unit), (−)−1 (inverse).
- Axioms: ∀x, y, z. (x · y) · z = x · (y · z), ∀x. x · e = x, e · x = x, ∀x. x−1 · x = e = x · x−1 .
The classifying category CT will have one object 1 for a single variable context (or think
of objects as 1 for one generator, 2 for two generators, etc. effectively like Lawvere theory
but now with axioms). However, the difference from Lawvere theory: those axioms are ∀
statements, which means in the category they impose that certain diagrams commute or
certain subobjects are equivalences.
One can construct CT as follows:
- Objects: natural numbers n (for n distinct variables).
- Morphisms: an arrow n → m is given by an m-tuple of terms in n variables (just like
Lawvere theory morphism), but under an equivalence relation generated by the axioms not
just equational but also some involving existence of inverses, etc.
However, because the axioms are all equations with universal quantifiers, they translate
to the statement that certain parallel pairs of arrows in CT coequalize. For example, the
axiom ∀x.(e · x = x) presumably means the two morphisms from 1 to 1 given by e · x and
x (seen as terms in one variable) are equal in the category. Similarly, the inverse axiom
x m(x−1 ,x) e()
means: the composite 1 − → 1 −−−−−−→ 1 equals the morphism 1 −−→ 1.
So effectively CT is like the Lawvere theory of groups (which is a category with finite prod-
ucts) but now with the requirement that those morphisms become equal, which forces some
coequalizers. In fact, the classifying category of groups is more precisely a pretopos (finite
limits + effective equivalence relations + coequalizers) because quotienting by the normal
subgroup generated by those relations is needed.
The classifying topos of groups would be a further completion of that category into a topos
(adding a subobject classifier).
But one can already reason in CT : models of the group theory in any regular category cor-
respond to product-preserving functors CT → C that also take those coequalizer diagrams
to coequalizers in C.
This example is complex but key insight: CT has one object 1 (for one variable) and the
structure makes it a group object in the topos Cc T (the topos of presheaves on CT ). That
representability yields the classifying topos property.

To formalize the presence of quantifiers:


- ∃x.Φ(x, y) corresponds to a left adjoint to pullback along projection π : X × Y → Y :
ΣX : Sub(X × Y ) → Sub(Y ) sending a subobject U ↣ X × Y to its direct image ∃X.U
in Y . A regular category ensures existence of these left adjoints (for predicates, indeed
images of monos).
- ∀x.Φ(x, y) corresponds to a right adjoint ΠX to that pullback (this often requires a con-
dition like the subobject is “definable”), which is available in a coherent category with a
41

Heyting structure or in a topos with a subobject classifier (where Π can be constructed


using Σ and ¬ since ∀x.Ψ is ¬∃x.¬Ψ in classical logic).
- Up to issues with intuitionistic logic, one might only have ¬ as pseudo-complement.

In Jacobs (chapter on first-order logic) he introduces categories called regular, coher-


ent, and (geometric) theory categories and shows results like:
”If C is a regular category and f : X → Y a morphism, then pulling back along f has
a left adjoint ∃f (the direct image functor), and these satisfy the expected properties for
existential quantifiers.”

And:
”In a coherent category (regular + finite unions) one can also interpret ∨ and ⊤ properly.”
Similarly, ”In a Heyting category (coherent + exponentials for subobjects), one can inter-
pret ∀.” Jacobs basically builds the semantics of first-order logic in any Heyting category,
culminating in completeness results like if a sequent is valid in all models in all Heyting
categories (or all toposes), it is provable.

One remarkable fact:


Gödel’s completeness theorem (for classical first-order logic) can be seen as a special
case of the existence of a classifying topos (or category): If a sentence is true in all set-based
models, it is provable. We already saw a part of that for propositional. The first-order
version uses ultraproducts or syntactic category like constructing a term model.

We have to be careful with ∀: For completeness one uses Henkin’s trick of adding con-
stants to witness existential assumptions, effectively turning it into an equational theory
or rather a coherent theory (this ensures we can find a model when consistent).

From the category side, one often restricts to geometric logic (which allows ∃, ∧, ∨
but not ∀ except over finite sets of equations) because geometric logic is preserved under
the inverse image part of geometric morphisms between toposes, and a classifying topos
exists for geometric theories. For full first-order (with ∀), completeness is not construc-
tively valid but classically we still have it.

We have gone quite theoretical. Let’s conclude this chapter with a summary:

- Categories with finite limits can interpret conjunction and equality.


- Add stable images (regular category) to interpret existential quantifiers.
- Add finite joins (coherent category) for disjunction.
- Add a subobject classifier (topos, or at least Heyting operations) to interpret universal
quantifiers.
- The internal logic of a topos is an intuitionistic higher-order logic in which these inter-
42 CHAPTER 3. FIRST-ORDER LOGIC IN CATEGORIES

pretations make the usual logical rules sound and complete.

Thus, category theory provides a language to talk about logic where: - Objects of a
category are like types or domains.
- Morphisms are like terms or functions.
- Special objects and morphisms (like subobjects, product projections) represent predicates
and logical connectives.
- Functors between categories represent interpretations or models.

The Curry–Howard correspondence is one step up: between logic and type theory,
which we consider next.

3.1 Categorical Semantics of Type Theory


We now turn to type theory. There are various type theories; the simplest is the simply-
typed λ-calculus with function types (arrow types) and possibly product types. More
complex ones include dependent types (e.g., a type of all vectors of length n depends on a
term n of type N) and polymorphic types.

A fundamental result by Lambek (and Howard earlier informally) is:


- The category of contexts and provable function terms in simply-typed lambda calculus is
a Cartesian closed category (CCC).
- Conversely, any CCC gives rise to a simply-typed lambda calculus as its internal language.

This is often called the Curry–Howard–Lambek correspondence:

Simply-typed λ-calculus ≡ Cartesian Closed Category ≡ Propositional logic with implication.

In that correspondence: - A type A corresponds to an object in a CCC.


- A term of type B in context x : A corresponds to a morphism A → B in the category.
- The function type A ⇒ B corresponds to an exponential object B A in the category (the
internal hom).
- Application corresponds to evaluation morphism B A × A → B; abstraction (lambda)
corresponds to the curry (adjunct) of evaluation: a morphism X × A → B corresponds
bijectively to a morphism X → B A .

Thus, in this correspondence:


- A type A corresponds to an object in a CCC.
3.1. CATEGORICAL SEMANTICS OF TYPE THEORY 43

- A term of type B in context x : A corresponds to a morphism A → B in the category.


- The function type A ⇒ B corresponds to an exponential object B A in the category (the
internal hom).
- Application corresponds to evaluation morphism B A × A → B; abstraction (lambda)
corresponds to the curry (adjunct) of evaluation: a morphism X × A → B corresponds
bijectively to a morphism X → B A .

Theorem (Curry–Howard–Lambek). The simply-typed lambda calculus with prod-


uct types and a base type corresponds exactly to the theory of Cartesian closed categories
with a distinguished object. More precisely, there is an equivalence between:

• The syntactic category of the lambda calculus (with contexts as objects, terms as
morphisms).

• The free Cartesian closed category generated by the base types (and operations if
any).

And models of the lambda calculus correspond to functors from this free CCC to any CCC
(much like the algebraic theories case).

A consequence: If a formula (type) is inhabited (i.e., there is a term of that type) in the
type theory, then it is true in all CCC-models (soundness), and if it’s true in all models, it’s
inhabited (completeness). This is analogous to completeness for logic, but in type theory
it’s often called strong normalization implies consistency, etc.

Let’s break it down:


- A Cartesian Closed Category (CCC) is a category with finite products and expo-
nentials for each pair of objects. Finite products give a terminal object (type of trivially
true proposition) and binary products (pair types). Exponentials give function types.
- The internal language of a CCC is a simply-typed lambda calculus: each morphism
f : A → B can be seen as a lambda term λ(x : A).t of type B using one free variable of
type A, and composition corresponds to substitution/application.

For example, in Set (which is CCC), an exponential B A is the set of all functions
A → B. A specific function g : X → B A is equivalently a function X × A → B (by
currying). That is exactly like having a term f (x, a) with x from X and a from A yielding
a B; currying means we regard it as the function x 7→ (a 7→ f (x, a)).

So, in Set, a lambda term λxA .t(x) is interpreted as the actual function mapping each
a ∈ A to the interpretation of t(a) in B. The beta-reduction corresponds to plugging in
44 CHAPTER 3. FIRST-ORDER LOGIC IN CATEGORIES

that element.

Simply-typed lambda calculus as initial model: We can treat the syntax of


lambda calculus as a category (the term model) and any CCC as a model. Then:

Theorem 3.2. The term model (syntactic CCC) is the free CCC on the set of base types
(and constants). Thus, any equation between terms that holds in all CCC models is provable
in the lambda calculus (completeness), and if it’s provable, it holds in all models (sound-
ness). In particular, if there is no term of type ⊥ (an empty type) in the calculus, then
no CCC can give an arrow 1 → ⊥ (which means the calculus is consistent: can’t derive an
inhabitant of the empty type).

The proof is analogous to the algebraic one: construct the syntactic category and show
it is initial among CCCs. A consequence is the lambda calculus is consistent because
a term of type ⊥ in the term model would mean a morphism 1 → ⊥ in the initial CCC,
which then would exist in Set under any interpretation, implying a set of 0 elements has
an element, contradiction.

The above covers simply typed (no polymorphism, no dependent types, no higher-
order).
Polymorphism (System F) leads to models in categories with additional structure (like di-
natural transformations, not obviously just an ordinary category property, but something
like a universe object etc).
Dependent types lead to categories with families (CwF) or categories with fibra-
tions that correspond to the type theory (these generalize CCCs: - A dependent type B(x)
over x : A is like an object in a slice category C/A. A category with families provides such
a thing plus substitution operations).
The simplest such structure is a Locally Cartesian Closed Category (LCCC) which
has nice interpretations for dependent Π and Σ (the rules for these correspond to ad-
jointness of pullbacks, as mentioned for quantifiers). For example: - A locally cartesian
closed category (LCCC) is one where every slice category C/X is cartesian closed. That
corresponds to having Π types (dependent function types) and Σ types (dependent sum
types) and is the categorical model of dependent type theory without universes or higher
inductive types.
Martin-Löf type theory with universes is modeled in a category with a universe ob-
ject or a Grothendieck fibration with some additional structure. Jacobs covers
universes as well, likely showing something like: ”If a category has a universe (an object
U with a surjection El → U that classifies small objects) then one can interpret an extra
type of types.”
3.1. CATEGORICAL SEMANTICS OF TYPE THEORY 45

The interaction of logic and type theory:


- Propositions-as-Types: in type theory with a type Prop of propositions, each proposi-
tion is a type whose inhabitants are proofs. In a category, this is like having a subobject
classifier Ω (the object of propositions), and subobjects correspond to monomorphisms or
characteristic functions into Ω.
In categories:
- A Ω as subobject classifier in a topos is analogous to a type of propositions where an
element of Ω is a truth value.
- A predicate P on X is a morphism X → Ω.
So higher-order logic (where we quantify over predicates) corresponds to a type theory
with an Ω type that one can quantify over—that essentially pushes to the realm of toposes
or at least logical categories with power-objects.

Finally, summarizing Curry-Howard:


- Simply typed with →, ×, 1 corresponds to CCC.
- Add a base type 0 (empty type) or a type for false, that would correspond to an initial
object or subobject classifier phenomenon.
- Dependent types (Π, Σ) corresponds to categories that are locally cartesian closed (for
Π) and have sums (for Σ), which are basically toposes (a topos has these plus a subobject
classifier, making it a model of full higher-order logic).

So the progression:
Algebraic theories (no logic, just equations) → categories with finite products.
Propositional logic (Boolean) → Boolean algebra or Stone spaces.
First-order logic → regular, coherent categories or toposes.
Type theory → cartesian closed (for simple) → locally cartesian closed (for dependent) →
toposes with natural number object etc (for full Martin-Löf with inductive types).

And at each stage, there is a completeness: if something is true in all such categories
(models), it’s derivable in the logic.

We conclude with one more exercise:

Exercise 3.3. In a Cartesian closed category C, consider an object A and an element


(morphism from 1) a : 1 → A. Show that evaluation at a gives a natural isomorphism
C(1, B A ) ∼
= C(A, B) by mapping a morphism f : 1 → B A to eval ◦ (f × a) : 1 × A → B. Use
this to argue that a term t of type B with a free variable of type A corresponds uniquely
to a lambda term λa.t of type A ⇒ B. (This reflects the currying bijection.)
With that, we have outlined how category theory and logic/type theory inform each
other: categories provide models and structural insights into logic, while logic provides
46 CHAPTER 3. FIRST-ORDER LOGIC IN CATEGORIES

syntax and computational content for categories. The unity of these fields is one of the
beautiful aspects of categorical logic and type theory.
Appendix A

Further Reading

Due to the breadth of categorical logic and type theory, we can only scratch the surface in
one textbook. For readers seeking more:
- Samson Abramsky and Nikos Tzevelekos’s introductory chapter provides a concise start-
ing point.
- Bart Jacobs’s Categorical Logic and Type Theory covers advanced topics like fibrations
for predicate logic, internal category theory, and topos semantics in depth.
- Steve Awodey’s lecture notes offer accessible treatments of algebraic and categorical logic,
including Lawvere theories and Stone duality.
- On type theory and categories, see Categories for Types by Crole and Practical Founda-
tions of Mathematics by Johnstone for connections between type theory and topos theory.
- For Stone duality and topology related to logic, Johnstone’s Stone Spaces and Sketches
of an Elephant are comprehensive references.

We hope this textbook has equipped the reader with a foundational understanding to
approach both classical texts and research literature in categorical logic and type theory.

47
48 APPENDIX A. FURTHER READING
Bibliography

[1] Abramsky, Samson, and Nikos Tzevelekos. 2011. ”Introduction to Categories and
Categorical Logic,” arXiv:1102.1313.

[2] Awodey, Steve. 2022. Categorical Logic (Autumn School Lecture Notes).

[3] Awodey, Steve, and Andrej Bauer. 2024. ”Introduction to Categorical Logic (Draft).”

[4] Jacobs, Bart. 1999. Categorical Logic and Type Theory. Elsevier Science.

[5] Lawvere, F. William. 1963. ”Functorial Semantics of Algebraic Theories.” Proceedings


of the National Academy of Sciences 50(5): 869–872.

[6] Mac Lane, Saunders, and Ieke Moerdijk. 1992. Sheaves in Geometry and Logic: A
First Introduction to Topos Theory. Springer.

[7] Johnstone, Peter T. 1982. Stone Spaces. Cambridge Studies in Advanced Mathematics.

49

You might also like