<<

Chapter 3

Databases: Categories, , and universal constructions

3.1 What is a database?

Integrating data from disparate sources is a major problem in industry today. A study in 2008 [BH08] showed that data integration accounts for 40% of IT (information technology) budgets, and that the market for data integration software was $2.5 billion in 2007 and increasing at a rate of more than 8% per year. In other words, it is a major problem; but what is it?

A database is a system of interlocking tables. Data becomes information when it is stored in a given formation. That is, the numbers and letters don’t mean anything until they are organized, often into a system of interlocking tables. An organized system of interlocking tables is called a database. Here is a favorite example:

Employee FName WorksIn Mngr Department DName Secr 1 Alan 101 2 101 Sales 1 2 Ruth 101 2 102 IT 3 3 Kris 102 3 (3.1) These two tables interlock by use of a special left-hand column, demarcated by a vertical line; it is called the ID column. The ID column of the first table is called ‘Employee,’ and the ID column of the second table is called ‘Department.’ The entries in the ID column—e.g. 1, 2, 3 or 101, 102—are like row labels; they indicate a whole row of the table they’re in. Thus each row label must be unique (no two rows in a table can have the same label), so that it can unambiguously specify its row.

77 78 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Each table’s ID column, and the set of unique identifiers found therein, is what allows for the interlocking mentioned above. Indeed, other entries in various tables can reference rows in a given table by use of its ID column. For example, each entry in the WorksIn column references a department for each employee; each entry in the Mngr (manager) column references an employee for each employee, and each entry in the Secr (secretary) column references an employee for each department. Managing all this cross-referencing is the purpose of databases. Looking back at Eq. (3.1), one might notice that every non-ID column, found in either table, is a reference to a label of some sort. Some of these, namely WorksIn, Mngr, and Secr, are internal references, often called foreign keys; they refer to rows (keys) in the ID column of some (foreign) table. Others, namely FName and DName, are external references; they refer to strings or integers, which can also be thought of as labels, whose meaning is known more broadly. Internal reference labels can be changed as long as the change is consistent—1 could be replaced by 1001 everywhere without changing the meaning—whereas external reference labels certainly cannot! Changing Ruth to Bruce everywhere would change how people understood the data. The reference structure for a given database—i.e. how tables interlock via foreign keys—tells us something about what information was intended to be stored in it. One may visualize the reference structure for Eq. (3.1) graphically as follows:

Employee WorksIn Department Mngr • Secr • easySchema B (3.2)

FName string DName ◦ This is a kind of “Hasse diagram for a database,” much like the Hasse diagrams for preorders in Remark 1.39. How should you read it? The two tables from Eq. (3.1) are represented in the (3.2) by the two black nodes, which are given the same name as the ID columns: Employee and Department. There is another node—drawn white rather than black—which represents the external reference type of strings, like “Alan,” “Alpha,” and “Sales". The arrows in the diagram represent non-ID columns of the tables; they point in the direction of reference: WorksIn refers an employee to a department.

Exercise 3.3. Count the number of non-ID columns in Eq. (3.1). Count the number of arrows (foreign keys) in Eq. (3.2). They should be the same number in this case; is this a coincidence? ♦

A Hasse-style diagram like the one in Eq. (3.2) can be called a database schema; it represents how the information is being organized, the formation in which the data is kept. One may add rules, sometimes called ‘business rules’ to the schema, in order to ensure the integrity of the data. If these rules are violated, one knows that data being 3.1. WHAT IS A DATABASE? 79 entered does not conform to the way the database designers intended. For example, the designers may enforce rules saying • every department’s secretary must work in that department; • every employee’s manager must work in the same department as the employee. Doing so changes the schema, say from ‘easySchema’ (3.2) to ‘mySchema’ below.

Employee WorksIn Department Mngr • Secr •

mySchema B (3.4) FName string DName ◦ Department.Secr.WorksIn = Department Employee.Mngr.WorksIn = Employee.WorksIn

In other words, the difference is that easySchema plus constraints equals mySchema. We will soon see that database schemas are categories C, that the data itself is given by a ‘set-valued’ C Set, and that databases can be mapped to each other via → functors C D. In other words, there is a relatively large overlap between database → theory and theory. This has been worked out in a number of papers; see Section 3.6. It has also been implemented in working software, called FQL, which stands for functorial query language. Here is example FQL code for the schema shown above:

schema mySchema = { nodes Employee, Department; attributes DName : Department -> string, FName : Employee -> string; arrows Mngr : Employee -> Employee, WorksIn : Employee -> Department, Secr : Department -> Employee; equations Department.Secr.WorksIn = Department, Employee.Mngr.WorksIn = Employee.WorksIn; }

Communication between databases. We have said that databases are designed to store information about something. But different people or organizations might view the same sort of thing in different ways. For example, one bank stores its financial records according to European standards and another does so according to Japanese standards. If these two banks merge into one, they will need to be able to share their data despite differences in the shape of their database schemas. 80 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Such problems are huge and intricate in general, because databases often comprise hundreds or thousands of interlocking tables. Moreover, these problems occur more frequently than just when companies want to merge. It is quite common that a given company moves data between databases on a daily basis. The reason is that different ways of organizing information are convenient for different purposes. Just like we pack our clothes in a suitcase when traveling but use a closet at home, there is generally not one best way to organize anything. provides a mathematical approach for translating between these different organizational forms. That is, it formalizes a sort of automated reorganizing process called data migration, which takes data that fits snugly in one schema and moves it into another. Here is a simple case. Imagine an airline company has two different databases, perhaps created at different times, that hold roughly the same data.

$ $ ◦ ◦ Price Price Price

A B Economy First Airline Seat : B • • • Position Position Position string string (3.5) ◦ ◦

Schema A has more detail than schema B—an airline seat may be in first class or economy—but they are roughly the same. We will see that they can be connected by a functor, and that data conforming to A can be migrated through this functor to schema B and vice versa. The statistics at the beginning of this section show that this sort of problem— when occurring at enterprise scale—continues to prove difficult and expensive. If one attempts to move data from a source schema to a target schema, the migrated data could fail to fit into the target schema or fail to satisfy some of its constraints. This happens surprisingly often in the world of business: a night may be spent moving data, and the next morning it is found to have arrived broken and unsuitable for further use. In fact, it is believed that over half of database migration projects fail. In this chapter, we will discuss a category-theoretic method for migrating data. Using categories and functors, one can prove up front that a given data migration will not fail, i.e. that the result is guaranteed to fit into the target schema and satisfy all its constraints. The material in this chapter gets to the heart of category theory: in particular, we discuss categories, functors, natural transformations, adjunctions, limits, and colimits. In fact, many of these ideas have been present in the discussion above: • The schema pictures, e.g. Eq. (3.4) depict categories C. 3.2. CATEGORIES 81

• The instances, e.g. Eq. (3.1) are functors from C to a certain category called Set. • The implicit mapping in Eq. (3.5), which takes economy and first class seats in A to airline seats in B, constitutes a functor A B. → • The notion of data migration for moving data between schemas is formalized by . We begin in Section 3.2 with the definition of categories and a bunch of different sorts of examples. In Section 3.3 we bring back databases, in particular their instances and the maps between them, by discussing functors and natural transformations. In Section 3.4 we discuss data migration by way of adjunctions, which generalize the Galois connections we introduced in Section 1.4. Finally in Section 3.5 we give a bonus section on limits and colimits.1

3.2 Categories

A category C consists of four pieces of data—objects, , identities, and a composition rule—satisfying two properties.

Definition 3.6. To specify a category C: (i) one specifies a collection2 Ob C , elements of which are called objects. ( ) (ii) for every two objects c, d, one specifies a set C c, d ,3 elements of which are called ( ) morphisms from c to d.

(iii) for every object c Ob C , one specifies a idc C c, c , called the ∈ ( ) ∈ ( ) identity morphism on c. (iv) for every three objects c, d, e Ob C and morphisms f C c, d and 1 C d, e , ∈ ( ) ∈ ( ) ∈ ( ) one specifies a morphism f 1 C c, e , called the composite of f and 1. # ∈ ( ) We will sometimes write an object c C, instead of c Ob C . It will also be convenient ∈ ∈ ( ) to denote elements f C c, d as f : c d. Here, c is called the domain of f , and d is ∈ ( ) → called the codomain of f . These constituents are required to satisfy two conditions: (a) unitality: for any morphism f : c d, composing with the identities at c or d → does nothing: idc f  f and f idd  f . # # (b) associativity: for any three morphisms f : c0 c1, 1 : c1 c2, and h : c2 c3, → → → the following are equal: f 1 h  f 1 h . We write this composite simply ( # ) # # ( # ) as f 1 h. # #

1By “bonus,” we mean that although not strictly essential to the understanding of this particular chapter, limits and colimits will show up throughout the book and throughout one’s interaction with category theory, and we think the reader will especially benefit from this material in the long run. 2Here, a collection can be thought of as a bunch of things, just like a set, but that may be too large to formally be a set. An example is the collection of all sets, which would run afoul of Russell’s paradox if it were itself a set. 3 This set C c, d is often denoted HomC c, d , and called the “hom-set from c to d.” The word “hom” ( ) ( ) stands for , of which the word “morphism” is a shortened version. 82 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Our next goal is to give lots of examples of categories. Our first source of examples is that of free and finitely-presented categories, which generalize the notion of Hasse diagram from Remark 1.39.

3.2.1 Free categories

Recall from Definition 1.36 that a graph consists of two types of thing: vertices and arrows. From there one can define paths, which are just head-to-tail sequences of arrows. Every path p has a start vertex and an vertex; if p goes from v to w, we write p : v w. To every vertex v, there is a trivial path, containing no arrows, starting → and ending at v; we often denote it by idv or simply by v. We may also concatenate paths: given p : v w and q : w x, their concatenation is denoted p q, and it goes → → # v x. → In Chapter1, we used graphs to depict preorders V, : the vertices form the ( ≤) elements of the preorder, and we say that v w if there is a path from v to w in G. We ≤ will now use graphs in a very similar way to depict certain categories, known as free categories. Then we will explain a strong relationship between preorders and categories in Section 3.2.3.

Definition 3.7. For any graph G  V, A, s, t , we can define a category Free G , called ( ) ( ) the on G, whose objects are the vertices V and whose morphisms from c to d are the paths from c to d. The identity morphism on an object c is simply the trivial path at c. Composition is given by concatenation of paths.

For example, we define 2 to be the free category generated by the graph shown below:   2 B Free v1 f1 v2 (3.8) • •

It has two objects v1 and v2, and three morphisms: idv : v1 v1, f1 : v1 v2, and 1 → → idv : v2 v2. Here idv is the path of length 0 starting and ending at v1, f1 is the path 2 → 1 of length 1 consisting of just the arrow f1, and idv2 is the length 0 path at v2. As our notation suggests, idv1 is the identity morphism for the object v1, and similarly idv2 for v2. As composition is given by concatenation, we have, for example idv f1  f1, 1 # idv idv  idv , and so on. 2 # 2 2 From now on, we may elide the difference between a graph and the corresponding free category Free G , at least when the one we mean is clear enough from context. ( ) Exercise 3.9. For Free G to really be a category, we must check that this data we ( ) specified obeys the unitality and associativity properties. Check that these are obeyed for any graph G. ♦ 3.2. CATEGORIES 83

Exercise 3.10. The free category on the graph shown here:4

  3 B Free v1 f1 v2 f2 v3 (3.11) • • • has three objects and six morphisms: the three vertices and six paths in the graph. Create six names, one for each of the six morphisms in 3. Write down a six-by-six table, label the rows and columns by the six names you chose. 1. Fill out the table by writing the name of the composite in each cell, when there is a composite. 2. Where are the identities? ♦

Exercise 3.12. Let’s make some definitions, based on the pattern above: 1. What is the category 1? That is, what are its objects and morphisms? 2. What is the category 0? 3. What is the formula for the number of morphisms in n for arbitrary n N? ♦ ∈

Example 3.13 (Natural numbers as a free category). Consider the following graph:

s

(3.14) •z

It has only one vertex and one arrow, but it has infinitely many paths. Indeed, it has a unique path of length n for every natural number n N. That is, Path  ∈ z, s, s s , s s s ,... , where we write z for the length 0 path on z; it represents { ( # ) ( # # ) } the morphism idz. There is a one-to-one correspondence between Path and the natural numbers, N  0, 1, 2, 3,... . { } This is an example of a category with one object. A category with one object is called a , a notion we first discussed in Example 2.6. There we said that a monoid is a tuple M, , e where : M M M is a and e M is an element, and ( ∗ ) ∗ × → ∈ m 1  m  1 m and m n p  m n p . ∗ ∗ ( ∗ ) ∗ ∗ ( ∗ ) The two notions may superficially look different, but it is easy to describe the connection. Given a category C with one object, say , let M B C , , let e  id , and • (• •) • let : C , C , C , be the composition operation  . The associativity ∗ (• •) × (• •) → (• •) ∗ # and unitality requirements for the monoid will be satisfied because C is a category.

Exercise 3.15. In Example 3.13 we identified the paths of the loop graph (3.14) with numbers n N. Paths can be concatenated. Given numbers m, n N, what number ∈ ∈ corresponds to the concatenation of their associated paths? ♦

4As mentioned above, we elide the difference between the graph and the corresponding free category. 84 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

3.2.2 Presenting categories via path equations

So for any graph G, there is a free category on G. But we don’t have to stop there: we can add equations between paths in the graph, and still get a category. We are only allowed to equate two paths p and q when they are parallel, meaning they have the same source vertex and the same target vertex. A finite graph with path equations is called a finite presentation for a category, and the category that results is known as a finitely-presented category. Here are two examples:

A f B A f B • • • • 1 h 1 h Free_square B Comm_square B •C i D• •C i D•

no equations f h  1 i # # Both of these are presentations of categories: in the left-hand one, there are no equations so it presents a free category, as discussed in Section 3.2.1. The free square category has ten morphisms, because every path is a unique morphism. Exercise 3.16. 1. Write down the ten paths in the free square category above. 2. Name two different paths that are parallel. 3. Name two different paths that are not parallel. ♦ On the other hand, the category presented on the right has only nine morphisms, because f h and 1 i are made equal. This category is called the “commutative square.” # # Its morphisms are A, B, C, D, f , 1, h, i, f h { # } One might say “the missing one is 1 i,” but that is not quite right: 1 i is there too, # # because it is equal to f h. As usual, A denotes idA, etc. # Exercise 3.17. Write down all the morphisms in the category presented by the following diagram:

A f B • • 1 j h

•C i D•

f h  j  1 i # # ♦

Example 3.18. We should also be aware that enforcing an equation between two mor- phisms often implies additional equations. Here are two more examples of presenta- 3.2. CATEGORIES 85 tions, in which this phenomenon occurs:

s s

C D B •z B •z

s s  z s s s s  s s # # # # # In C we have the equation s s  z. But this implies s s s  z s  s! And similarly # # # # we have s s s s  z z  z. The set of morphisms in C is in fact merely z, s , with # # # # { } composition described by s s  z z  z, and z s  s z  s. In theory, one # # # # would speak of a group called Z 2Z. / Exercise 3.19. Write down all the morphisms in the category D from Example 3.18. ♦ Remark 3.20. We can now see that the schemas in Section 3.1, e.g. Eqs. (3.2) and (3.4) are finite presentations of categories. We will come back to this idea in Section 3.3.

3.2.3 Preorders and free categories: two ends of a spectrum

Now that we have used graphs to depict preorders in Chapter1 and categories above, one may want to know the relationship between these two uses. The main idea we want to explain now is that

“A preorder is a category where every two parallel arrows are the same.”

Thus any preorder can be regarded as a category, and any category can be somehow “crushed down” into a preorder. Let’s discuss these ideas.

Preorders as categories. Suppose P, is a preorder. It specifies a category P as ( ≤) follows. The objects of P are precisely the elements of P; that is, Ob P  P. As for ( ) morphisms, P has exactly one morphism p q if p q and no morphisms p q if → ≤ → p  q. The fact that is reflexive ensures that every object has an identity, and the fact ≤ that is transitive ensures that morphisms can be composed. We call P the category ≤ corresponding to the preorder P, . ( ≤) In fact, a Hasse diagram for a preorder can be thought of a presentation of a category where, for all vertices p and q, every two paths from p q are declared equal. For → example, in Eq. (1.5) we saw a Hasse diagram that was like the graph on the left:

d • f d • f • e e • • • • • • • • • a b c a b c • • • no equations? a d  b e  c f # # # 86 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

The Hasse diagram (left) might look the most like the free category presentation (mid- dle) which has no equations, but that is not correct. The free category has three morphisms (paths) from bottom object to top object, whereas preorders are categories with at most one morphism between two given objects. Instead, the diagram on the right, with these paths from bottom to top made equal, is the correct presentation for the preorder on the left. Exercise 3.21. What equations would you need to add to the graphs below in order to present the associated preorders?

f f f f • • • • G1  G2  G3  1 h G4  1 ♦ • 1 • h • • i • • •

The preorder reflection of a category. Given any category C, one can obtain a preorder C, from it by destroying the distinction between any two parallel morphisms. That ( ≤) is, let C B Ob C , and put c1 c2 iff C c1, c2 , . If there is one, or two, or fifty, ( ) ≤ ( ) œ or infinitely many morphisms c1 c2 in C, the preorder reflection does not see the → difference. But it does see the difference between some morphisms and no morphisms. Exercise 3.22. What is the preorder reflection of the category N from Example 3.13? ♦ We have only discussed adjoint functors between preorders, but soon we will discuss adjoints in general. Here is a statement you might not understand exactly, but it’s true; you can ask a category theory expert about it and they should be able to explain it to you:

Considering a preorder as a category is right adjoint to turning a category into a preorder by preorder reflection.

Remark 3.23 (Ends of a spectrum). The main point of this subsection is that both preorders and free categories are specified by a graph without path equations, but they denote opposite ends of a spectrum. In both cases, the vertices of the graph become the objects of a category and the paths become morphisms. But in the case of free categories, there are no equations so each path becomes a different morphism. In the case of preorders, all parallel paths become the same morphism. Every category presentation, i.e. graph with some equations, lies somewhere in between the free category (no equations) and its preorder reflection (all possible equations).

3.2.4 Important categories in mathematics

We have been talking about category presentations, but there are categories that are best understood directly, not by way of presentations. Recall the definition of category 3.2. CATEGORIES 87 from Definition 3.6. The most important category in mathematics is the .

Definition 3.24. The category of sets, denoted Set, is defined as follows. (i) Ob Set is the collection of all sets. ( ) (ii) If S and T are sets, then Set S, T  f : S T f is a function . ( ) { → | } (iii) For each set S, the identity morphism is the function idS : S S given by → idS s B s for each s S. ( ) ∈ (iv) Given f : S T and 1 : T U, their composite is the function f 1 : S U → → # → given by f 1 s B 1 f s . ( # )( ) ( ( )) These definitions satisfy the unitality and associativity conditions, so Set is indeed a category.

Closely related is the category FinSet. This is the category whose objects are finite sets and whose morphisms are functions between them. Exercise 3.25. Let 2  1, 2 and 3  1, 2, 3 . These are objects in the category Set { } { } discussed in Definition 3.24. Write down all the elements of the set Set 2, 3 ; there ( ) should be nine. ♦ Remark 3.26. You may have wondered what categories have to do with V-categories (Definition 2.46); perhaps you think the definitions hardly look alike. Despite the term ‘’, V-categories are not categories with extra structure. While some sorts of V-categories, such as Bool-categories, i.e. preorders, can naturally be seen as categories, other sorts, such as Cost-categories, cannot. The reason for the importance of Set is that, if we generalize the definition of enriched category (Definition 2.46), we find that categories in the sense of Definition 3.6 are exactly Set-categories—so categories are V-categories for a very special choice of V. We’ll come back to this in Section 4.4.4. For now, we simply remark that just like a deep understanding of the category Cost—for example, knowing that it is a quantale—yields insight into Lawvere metric spaces, so the study of Set yields insights into categories. There are many other categories that mathematicians care about: • Top: the category of topological spaces (neighborhood) • Grph: the category of graphs (connection) • Meas: the category of measure spaces (amount) • Mon: the category of (action) • Grp: the (reversible action, symmetry) • Cat: the category of categories (action in context, structure) But in fact, this does not at all do justice to the diversity of categories mathematicians think about. They work with whatever category they find fits their purpose at the time, like ‘the category of connected Riemannian manifolds of dimension at most 4’. Here is one more source of examples: take any category you already have and reverse all its morphisms; the result is again a category. 88 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Example 3.27. Let C be a category. Its opposite, denoted Cop, is the category with the same objects, Ob Cop B Ob C , and for any two objects c, d Ob C , one has ( ) ( ) ∈ ( ) Cop c, d B C d, c . Identities and composition are as in C. ( ) ( )

3.2.5 in a category

The previous sections have all been about examples of categories: free categories, presented categories, and important categories in math. In this section, we briefly switch gears and talk about an important concept in category theory, namely the concept of . In a category, there is often the idea that two objects are interchangeable. For example, in the category Set, one can exchange the set ,  for the set 0, 1 and { } { } everything will be the same, other than the names for the elements. Similarly, if one has a preorder with elements a, b, such that a b and b a, i.e. a  b, then a and b are ≤ ≤ essentially the same. How so? Well they act the same, in that for any other object c, we know that c a iff c b, and c a iff c b. The notion of isomorphism formalizes ≤ ≤ ≥ ≥ this notion of interchangeability.

Definition 3.28. An isomorphism is a morphism f : A B such that there exists a → morphism 1 : B A satisfying f 1  idA and 1 f  idB. In this case we call f and 1 → #1 # 1 inverses, and we often write 1  f − , or equivalently f  1− . We also say that A and B are isomorphic objects.

Example 3.29. The set A B a, b, c and the set 3  1, 2, 3 are isomorphic; that is, { } { } there exists an isomorphism f : A 3 given by f a  2, f b  1, f c  3. The → ( ) ( ) ( ) isomorphisms in the category Set are the bijections.

Recall that the cardinality of a finite set is the number of elements in it. This can be understood in terms of isomorphisms in FinSet. Namely, for any finite set A FinSet, ∈ its cardinality is the number n N such that there exists an isomorphism A  n. Georg ∈ Cantor defined the cardinality of any set X to be its isomorphism class, meaning the equivalence class consisting of all sets that are isomorphic to X. Exercise 3.30. 1. What is the inverse f 1 : 3 A of the function f given in Example 3.29? − → 2. How many distinct isomorphisms are there A 3? ♦ → Exercise 3.31. Show that in any given category C, for any given object c C, the identity ∈ idc is an isomorphism. ♦ Exercise 3.32. Recall Examples 3.13 and 3.18. A monoid in which every morphism is an isomorphism is known as a group. 1. Is the monoid in Example 3.13 a group? 3.3. FUNCTORS, NATURAL TRANSFORMATIONS, AND DATABASES 89

2. What about the monoid C in Example 3.18? ♦ Exercise 3.33. Let G be a graph, and let Free G be the corresponding free category. ( ) Somebody tells you that the only isomorphisms in Free G are the identity morphisms. ( ) Is that person correct? Why or why not? ♦

Example 3.34. In this example, we will see that it is possible for 1 and f to be almost—but not quite—inverses, in a certain sense. Consider the functions f : 2 3 and 1 : 3 2 drawn below: → →

1 1 1 • • 1 • 2 2 • 2 • • 2 • 3 3 • • •

Then the reader should be able to instantly check that f 1  id2 but 1 f , id3. Thus f # # and 1 are not inverses and hence not isomorphisms. We won’t need this terminology, but category theorists would say that f and 1 form a retraction.

3.3 Functors, natural transformations, and databases

In Section 3.1 we showed some database schemas: graphs with path equations. Then in Section 3.2.2 we said that graphs with path equations correspond to finitely-presented categories. Now we want to explain what the data in a database is, as a way to introduce functors. To do so, we begin by noticing that sets and functions—the objects and morphisms in the category Set—can be captured by particularly simple databases.

3.3.1 Sets and functions as databases

The first observation is that any set can be understood as a table with only one column: the ID column.

Planet of Sol Prime number Flying pig Mercury 2 Venus 3 Earth 5 Mars 7 Jupiter 11 Saturn 13 Uranus 17 . Neptune . 90 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Rather than put the elements of the set between braces, e.g. 2, 3, 5, 7, 11,... , we write { } them down as rows in a table. In databases, single-column tables are often called controlled vocabularies, or master data. Now to be honest, we can only write out every single entry in a table when its set of rows is finite. A database practitioner might find the idea of our prime number table a bit unrealistic. But we’re mathematicians, so since the idea makes perfect sense abstractly, we will continue to think of sets as one-column tables. The above databases have schemas consisting of just one vertex:

Planet of Sol Prime number Flying pig • • • Obviously, there’s really not much difference between these schemas, other than the label of the unique vertex. So we could say “sets are databases whose schema consists of a single vertex.” Let’s move on to functions. A function f : A B can almost be depicted as a two-column table → Beatle Played George Lead guitar John Rhythm guitar Paul Bass guitar Ringo Drums except it is unclear whether the elements of the right-hand column exhaust all of B. What if there are rock-and-roll instruments out there that none of the Beatles played? So a function f : A B requires two tables, one for A and its f column, and one for B: → Beatle Played Rock-and-roll instrument George Lead guitar Bass guitar John Rhythm guitar Drums Paul Bass guitar Keyboard Ringo Drums Lead guitar Rhythm guitar

Thus the database schema for any function is just a labeled version of 2:

Rock-and-roll Beatle Played instrument • • The lesson is that an instance of a database takes a presentation of a category, and turns every vertex into a set, and every arrow into a function. As such, it describes a map from the presented category to the category Set. In Section 2.4.2 we saw that maps of V-categories are known as V-functors. Similarly, we call maps of plain old categories, functors. 3.3. FUNCTORS, NATURAL TRANSFORMATIONS, AND DATABASES 91

3.3.2 Functors

A functor is a mapping between categories. It sends objects to objects and morphisms to morphisms, all while preserving identities and composition. Here is the formal definition.

Definition 3.35. Let C and D be categories. To specify a functor from C to D, denoted F : C D, → (i) for every object c Ob C , one specifies an object F c Ob D ; ∈ ( ) ( ) ∈ ( ) (ii) for every morphism f : c1 c2 in C, one specifies a morphism F f : F c1 → ( ) ( ) → F c2 in D. ( ) The above constituents must satisfy two properties:

(a) for every object c Ob C , we have F idc  idF c . ∈ ( ) ( ) ( ) (b) for every three objects c1, c2, c3 Ob C and two morphisms f C c1, c2 , 1 ∈ ( ) ∈ ( ) ∈ C c2, c3 , the equation F f 1  F f F 1 holds in D. ( ) ( # ) ( ) # ( )

Example 3.36. For example, here we draw three functors F : 2 3: →

n0 n0 n0

m • m • m • 0 11 0 11 0 11 • n • n • n f1 1 f1 1 f1 1 • • • 12 12 12 m•1 m•1 m•1 n2 n2 n2 • • •

In each case, the dotted arrows show what the functor F does to the vertices in 2; once that information is specified, it turns out—in this special case—that what F does to the three paths in 2 is completely determined. In the left-hand diagram, F sends every path to the trivial path, i.e. the identity on n0. In the middle diagram F m0  n0, ( ) F f1  11, and F m1  n1. In the right-hand diagram, F m0  n0, F m1  n2, and ( ) ( ) ( ) ( ) F f1  11 12. ( ) #

Exercise 3.37. Above we wrote down three functors 2 3. Find and write down all → the remaining functors 2 3. ♦ →

Example 3.38. Recall the categories presented by Free_square and Comm_square in

Section 3.2.2. Here they are again, with 0 added to the labels in Free_square to help 92 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS distinguish them:

A0 f 0 B0 A f B • • • • 1 10 h0 h Free_square B Comm_square B i i C•0 0 D•0 •C D• no equations f h  1 i # # There are lots of functors from the free square category (let’s call it F) to the commutative square category (let’s call it C). However, there is exactly one functor F : F C that sends A to A, B to B, C to C, → 0 0 0 and D0 to D. That is, once we have made this decision about how F acts on objects, each of the ten paths in F is forced to go to a certain path in C: the one with the right source and target.

Exercise 3.39. Say where each of the ten morphisms in F is sent under the functor F from Example 3.38. ♦ All of our example functors so far have been completely determined by what they do on objects, but this is usually not the case. Exercise 3.40. Consider the free categories C  and D  ⇒ . Give two • → • • • functors F, G : C D that act the same on objects but differently on morphisms. ♦ →

Example 3.41. There are also lots of functors from the commutative square category C to the free square category F, but none that sends A to A0, B to B0, C to C0, and D to D0. The reason is that if F were such a functor, then since f h  1 i in C, we would have # # F f h  F 1 i , but then the rules of functors would let us reason as follows: ( # ) ( # )

f 0 h0  F f F h  F f h  F 1 i  F 1 F i  10 i0 # ( ) # ( ) ( # ) ( # ) ( ) # ( ) #

The resulting equation, f 0 h0  10 i0 does not hold in F because it is a free category # # (there are “no equations”): every two paths are considered different morphisms. Thus our proposed F is not a functor.

Example 3.42 (Functors between preorders are monotone maps). Recall from Sec- tion 3.2.3 that preorders are categories with at most one morphism between any two objects. A functor between preorders is exactly a monotone map. For example, consider the preorder N, considered as a category N with objects ( ≤) Ob N  N and a unique morphism m n iff m n. A functor F : N N sends ( ) → ≤ → each object n N to an object F n N. It must send morphisms in N to morphisms ∈ ( ) ∈ in N. This means if there is a morphism m n then there had better be a morphism → F m F n . In other words, if m n, then we had better have F m F n . But as ( ) → ( ) ≤ ( ) ≤ ( ) 3.3. FUNCTORS, NATURAL TRANSFORMATIONS, AND DATABASES 93 long as m n implies F m F n , we have a functor. ≤ ( ) ≤ ( ) Thus a functor F : N N and a monotone map N N are the same thing. → → Exercise 3.43 (The category of categories). Back in the primordial ooze, there is a category Cat in which the objects are themselves categories. Your task here is to construct this category. 1. Given any category C, show that there exists a functor idC : C C, known as the → identity functor on C, that maps each object to itself and each morphism to itself. Note that a functor C D consists of a function from Ob C to Ob D and for each → ( ) ( ) pair of objects c1, c2 C a function from C c1, c2 to D F c1 , F c2 . ∈ ( ) ( ( ) ( )) 2. Show that given F : C D and G : D E, we can define a new functor F → → ( # G : C E just by composing functions. ) → 3. Show that there is a category, call it Cat, where the objects are categories, mor- phisms are functors, and identities and composition are given as above. ♦

3.3.3 Database instances as Set-valued functors

Let C be a category, and recall the category Set from Definition 3.24. A functor F : C → Set is known as a set-valued functor on C. Much of database theory (not how to make them fast, but what they are and what you do with them) can be cast in this light. Indeed, we already saw in Remark 3.20 that any database schema can be regarded as (presenting) a category C. The next thing to notice is that the data itself—any instance of the database—is given by a set-valued functor I : C Set. The only additional string → detail is that for any white node, such as c  , we want to force I to map to the set ◦ of strings. We suppress this detail in the following definition.

Definition 3.44. Let C be a schema, i.e. a finitely-presented category. A C-instance is a functor I : C Set.5 →

Exercise 3.45. Let 1 denote the category with one object, called 1, one identity morphism id1, and no other morphisms. For any functor F : 1 Set one can extract a set F 1 . → ( ) Show that for any set S, there is a functor FS : 1 Set such that FS 1  S. ♦ → ( ) The above exercise reaffirms that the set of planets, the set of prime numbers, and the set of flying pigs are all set-valued functors—instances—on the schema 1. Similarly, set-valued functors on the category 2 are functions. All our examples so far are for the situation where the schema is a free category (no equations). Let’s try an example of a category that is not free.

5Warning: a C-instance is a state of the database “at an instant in time.” The term “instance” should not be confused with its usage in object oriented programming, which would correspond more to what we call a row r I c . ∈ ( ) 94 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Example 3.46. Consider the following category:

s

C B •z (3.47)

s s  s # What is a set-valued functor F : C Set? It will consist of a set Z B F z and a function → ( ) S B F s : Z Z, subject to the requirement that S S  S. Here are some examples ( ) → # • Z is the set of US citizens, and S sends each citizen to her or his president. The president’s president is her- or him-self. • Z  N is the set of natural numbers and S sends each number to 0. In particular, 0 goes to itself. • Z is the set of all well-formed arithmetic expressions, such as 13+ 2 4 or 5, that ( ∗ ) − one can write using integers and the symbols +, , , , . The function S evaluates − ∗ ( ) the expression to return an integer, which is itself a well-formed expression. The evaluation of an integer is itself.

• Z  N 2, and S sends n to its smallest prime factor. The smallest prime factor of ≥ a prime is itself. N 2 smallest prime factor ≥ 2 2 3 3 4 2 . . . . 49 7 50 2 51 3 . . . .

Exercise 3.48. Above, we thought of the sort of data that would make sense for the schema (3.47). Give an example of the sort of data that would make sense for the s a f b 1 c • • h • following schemas: 1. •z 2. ♦ f 1  f h s s  z # # # The main idea is this: a database schema is a category, and an instance on that schema—the data itself—is a set-valued functor. All the constraints, or business rules, are ensured by the rules of functors, namely that functors preserve composition.6

6One can put more complex constraints, called embedded dependencies, on a database; these correspond category theoretically to what are called “lifting problems” in category theory. See [Spi14b] for more on this. 3.3. FUNCTORS, NATURAL TRANSFORMATIONS, AND DATABASES 95

3.3.4 Natural transformations

If C is a schema—i.e. a finitely-presented category—then there are many database instances on it, which we can organize into a category. But this is part of a larger story, namely that of natural transformations. An abstract picture to have in mind is this:

F C α D. G

Definition 3.49. Let C and D be categories, and let F, G : C D be functors. To specify → a α : F G, ⇒ (i) for each object c C, one specifies a morphism αc : F c G c in D, called the ∈ ( ) → ( ) c-component of α. These components must satisfy the following, called the naturality condition: (a) for every morphism f : c d in C, the following equation must hold: →

F f αd  αc G f . ( ) # # ( ) A natural transformation α : F G is called a natural isomorphism if each component → αc is an isomorphism in D.

The naturality condition can also be written as a so-called .A diagram in a category is drawn as a graph whose vertices and arrows are labeled by objects and morphisms in the category. For example, here is a diagram that’s relevant to the naturality condition in Definition 3.49:

α F c c G c ( ) ( ) F f G f (3.50) ( ) ( ) F d G d ( ) αd ( )

Definition 3.51. A diagram D in C is a functor D : J C from any category J, called → the indexing category of the diagram D. We say that D commutes if D f  D f holds ( ) ( 0) for every parallel pair of morphisms f , f : a b in J.7 0 →

In terms of Eq. (3.50), the only case of two parallel morphisms is that of F c ⇒ G d , ( ) ( ) so to say that the diagram commutes is to say that F f αd  αc G f . This is exactly ( ) # # ( ) the naturality condition from Definition 3.49.

7We could package this formally by saying that D commutes iff it factors through the preorder reflection of J. 96 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Example 3.52. A representative picture is as follows:

F v w a d h f • • C B 1 2 u c 1 z : D • • • • b x e y k G • •

We have depicted, in blue and red respectively, two functors F, G : C D. A natural → transformation α : F G is given by choosing components α1 : v x and α2 : w y. ⇒ → → We have highlighted the only choice for each in green; namely, α1  c and α2  1. The key point is that the functors F and G are ways of viewing the category C as lying inside the category D. The natural transformation α, then, is a way of relating these two views using the morphisms in D. Does this help you to see and appreciate F the notation C α D? ⇓ G

Example 3.53. We said in Exercise 3.45 that a functor 1 Set can be identified with → a set. So suppose A and B are sets considered as functors A, B : 1 Set. A natural → transformation between these functors is just a function between the sets.

Definition 3.54. Let C and D be categories. We denote by DC the category whose objects are functors F : C D and whose morphisms DC F, G are the natural transformations → ( ) α : F G. This category DC is called the , or the category of functors from → C to D.

Exercise 3.55. Let’s look more deeply at how DC is a category. 1. Figure out how to compose natural transformations. (Hint: an expert tells you “for each object c C, compose the c-components.”) ∈ 2. Propose an identity natural transformation on any object F DC, and check that ∈ it is unital (i.e. that it obeys condition (a) of Definition 3.6). ♦

Example 3.56. In our new language, Example 3.53 says that Set1 is equivalent to Set.

Example 3.57. Let N denote the category associated to the preorder N, , and recall ( ≤) from Example 3.42 that we can identify a functor F : N N with a non-decreasing → sequence F0, F1, F2,... of natural numbers, i.e. F0 F1 F2 . If G is another ( ) ≤ ≤ ≤ · · · functor, considered as a non-decreasing sequence, then what is a natural transformation 3.3. FUNCTORS, NATURAL TRANSFORMATIONS, AND DATABASES 97

α : F G? → Since there is at most one morphism between two objects in a preorder, each com- ponent αn : Fn Gn has no data, it just tells us a fact: that Fn Gn. And the naturality → ≤ condition is vacuous: every square in a preorder commutes. So a natural transforma- tion between F and G exists iff Fn Gn for each n, and any two natural transformations ≤ F G are the same. In other words, the category NN is itself a preorder; namely the ⇒ preorder of monotone maps N N. → Exercise 3.58. Let C be an arbitrary category and let P be a preorder, thought of as a category. Consider the following statements: 1. For any two functors F, G : C P, there is at most one natural transformation → F G. → 2. For any two functors F, G : P C, there is at most one natural transformation → F G. → For each, if it is true, say why; if it is false, give a counterexample. ♦ Remark 3.59. Recall that in Remark 2.71 we said the category of preorders is equivalent to the category of Bool-categories. We can now state the precise meaning of this sentence. First, there exists a category PrO in which the objects are preorders and the morphisms are monotone maps. Second, there exists a category Bool-Cat in which the objects are Bool-categories and the morphisms are Bool-functors. We call these two categories equivalent because there exist functors F : PrO Bool-Cat and G : Bool-Cat PrO → → such that there exist natural isomorphisms F G  idPrO and G F  idBool-Cat in the # # sense of Definition 3.49.

3.3.5 The category of instances on a schema

Definition 3.60. Suppose that C is a database schema and I, J : C Set are database → instances. An instance homomorphism between them is a natural transformation α : I → J. Write C-Inst B SetC to denote the functor category as defined in Definition 3.54.

We saw in Example 3.53 that 1-Inst is equivalent to the category Set. In this subsection, we will show that there is a schema whose instances are graphs and whose instance are graph homomorphisms.

Extended example: the category of graphs as a functor category. You may find yourself back in the primordial ooze (first discussed in Section 2.3.2), because while previously we have been using graphs to present categories, now we obtain graphs themselves as database instances on a specific schema (which is itself a graph):

Arrow source Vertex Gr B • target • no equations 98 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Here’s an example Gr-instance, i.e. set-valued functor I : Gr Set, in table form: → Arrow source target Vertex a 1 2 1 b 1 3 2 (3.61) c 1 3 3 d 2 2 4 e 2 3

Here I Arrow  a, b, c, d, e , and I Vertex  1, 2, 3, 4 . One can draw the instance ( ) { } ( ) { } I as a graph:

1 a 2 d • • I  b e c 3 4 • • Every row in the Vertex table is drawn as a vertex, and every row in the Arrow table is drawn as an arrow, connecting its specified source and target. Every possible graph can be written as a database instance on the schema Gr, and every possible Gr-instance can be represented as a graph. Exercise 3.62. In Eq. (3.2), a graph is shown (forget the distinction between white and black nodes). Write down the corresponding Gr-instance, as in Eq. (3.61). (Do not be concerned that you are in the primordial ooze.) ♦ Thus the objects in the category Gr-Inst are graphs. The morphisms in Gr-Inst are called graph homomorphisms. Let’s unwind this. Suppose that G, H : Gr Set → are functors (i.e. Gr-instances); that is, they are objects G, H Gr-Inst. A morphism ∈ G H is a natural transformation α : G H between them; what does that entail? → → By Definition 3.49, since Gr has two objects, α consists of two components,

αVertex : G Vertex H Vertex and αArrow : G Arrow H Arrow , ( ) → ( ) ( ) → ( ) both of which are morphisms in Set. In other words, α consists of a function from vertices of G to vertices of H and a function from arrows of G to arrows of H. For these functions to constitute a , they must “respect source and target” in the precise sense that the naturality condition, Eq. (3.50) holds. That is, for every morphism in Gr, namely source and target, the following diagrams must commute:

α α G Arrow Arrow H Arrow G Arrow Arrow H Arrow ( ) ( ) ( ) ( ) G source H source G target H target ( ) ( ) ( ) ( ) G Vertex H Vertex G Vertex H Vertex ( ) αVertex ( ) ( ) αVertex ( ) These may look complicated, but they say exactly what we want. We want the functions

αVertex and αArrow to respect source and targets in G and H. The left diagram says “start 3.4. ADJUNCTIONS AND DATA MIGRATION 99 with an arrow in G. You can either apply α to the arrow and then take its source in H, or you can take its source in G and then apply α to that vertex; either way you get the same answer.” The right-hand diagram says the same thing about targets.

Example 3.63. Consider the graphs G and H shown below

4 d 5 G B 1 a 2 b 3 H B e • • • • c •

Here they are, written as database instances—i.e. set-valued functors—on Gr:

Arrow source target Vertex a 1 2 1 G B b 2 3 2 3 Arrow source target Vertex c 4 5 4 H B d 4 5 5 e 5 5

The top row is G and the bottom row is H. They are offset so you can more easily complete the following exercise.

Exercise 3.64. We claim that—with G, H as in Example 3.63—there is exactly one graph homomorphism α : G H such that αArrow a  d. → ( ) 1. What is the other value of αArrow, and what are the three values of αVertex? 2. In your own copy of the tables of Example 3.63, draw αArrow as two lines connect- ing the cells in the ID column of G Arrow to those in the ID column of H Arrow . ( ) ( ) Similarly, draw αVertex as connecting lines. 3. Check the source column and target column and make sure that the matches are natural, i.e. that “alpha-then-source equals source-then-alpha” and similarly for “target.” ♦

3.4 Adjunctions and data migration

We have talked about how set-valued functors on a schema can be understood as filling that schema with data. But there are also functors between schemas. When the two sorts of functors are composed, data is migrated. This is the simplest form of data migration; more complex ways to migrate data come from using adjoints. All of the above is the subject of this section. 100 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

3.4.1 Pulling back data along a functor

To begin, we will migrate data between the graph-indexing schema Gr and the loop schema, which we call DDS, shown below

State Arrow source Vertex • Gr B • target • DDS B next no equations no equations

We begin by writing down a sample instance I : DDS Set on this schema: → State next 1 4 2 4 3 5 (3.65) 4 5 5 5 6 7 7 6

We call the schema DDS to stand for discrete dynamical system. Indeed, we may think of the data in the DDS-instance of Eq. (3.65) as listing the states and movements of a deterministic machine: at every point in time the machine is in one of the listed states, and given the machine in one of the states, in the next instant it moves to a uniquely determined next state. Our goal is to migrate the data in Eq. (3.65) to data on Gr; this will give us the data of a graph and so allow us to visualise our machine. We will use a functor connecting these schemas in order to move data between them. The reader can create any functor she likes, but we will use a specific functor F : Gr DDS to migrate data in a way that makes sense to us, the authors. Here we → draw F, using colors to hopefully aid understanding:

Arrow • F source target State • Vertex next • Gr DDS

The functor F sends both objects of Gr to the ‘State’ object of DDS (as it must). On morphisms, it sends the ‘source’ morphism to the identity morphism on ‘State’, and the ‘target’ morphism to the morphism ‘next’. 3.4. ADJUNCTIONS AND DATA MIGRATION 101

A sample database instance on DDS was given in Eq. (3.65); recall this is a functor I : DDS Set. So now we have two functors as follows: → Gr F DDS I Set. (3.66)

Objects in Gr are sent by F to objects in DDS, which are sent by I to objects in Set, which are sets. Morphisms in Gr are sent by F to morphisms in DDS, which are sent by I to morphisms in Set, which are functions. This defines a composite functor F I : Gr Set. Both F and I respect identities and composition, so F I does too. Thus # → # we have obtained an instance on Gr, i.e. we have converted our discrete dynamical system from Eq. (3.65) into a graph! What graph is it? For an instance on Gr, we need to fill an Arrow table and a Vertex table. Both of these are sent by F to State, so let’s fill both with the rows of State in Eq. (3.65). Similarly, since F sends ‘source’ to the identity and sends ‘target’ to ‘next’, we obtain the following tables:

Arrow source target Vertex 1 1 4 1 2 2 4 2 3 3 5 3 4 4 5 4 5 5 5 5 6 6 7 6 7 7 6 7

Now that we have a graph, we can draw it.

1 2 • • 1 2 6 3 4 6 7

•3 4• • • 7 •5

5

Each arrow is labeled by its source vertex, as if to say, “What I do next is determined by what I am now.” Exercise 3.67. Consider the functor G : Gr DDS given by sending ‘source’ to ‘next’ → and sending ‘target’ to the identity on ‘State’. Migrate the same data, called I in Eq. (3.65), using the functor G. Write down the tables and draw the corresponding graph. ♦ We refer to the above procedure—basically just composing functors as in Eq. (3.66)— as “pulling back data along a functor.” We just now pulled back data I along functor F. 102 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Definition 3.68. Let C and D be categories and let F : C D be a functor. For any → set-valued functor I : D Set, we refer to the composite functor F I : C Set as the → # → pullback of I along F.

Given a natural transformation α : I J, there is a natural transformation αF : F I ⇒ # ⇒ F J, whose component F I c F J c for any c Ob C is given by αF c B αFc. # ( # )( ) → ( # )( ) ∈ ( ) ( ) I F I # F C D α Set { C αF Set J F J #

This uses the data of F to define a functor ∆F : D-Inst C-Inst. →

Note that the term pullback is also used for a certain sort of , for more details see Remark 3.100.

3.4.2 Adjunctions

In Section 1.4 we discussed Galois connections, which are adjunctions between pre- orders. Now that we’ve defined categories and functors, we can discuss adjunctions in general. The relevance to databases is that the data migration functor ∆ from Defi- nition 3.68 always has two adjoints of its own: a left adjoint which we denote Σ and a right adjoint which we denote Π. Recall that an adjunction between preorders P and Q is a pair of monotone maps f : P Q and 1 : Q P that are almost inverses: we have → → f p q if and only if p 1 q . (3.69) ( ) ≤ ≤ ( ) Recall from Section 3.2.3 that in a preorder P, a hom-set P a, b has one element when ( ) a b, and no elements otherwise. We can thus rephrase Eq. (3.69) as an isomorphism ≤ of sets Q f p , q  P p, 1 q : either both are one-element sets or both are 0-element ( ( ) ) ( ( )) sets. This suggests how to define adjunctions in the general case.

Definition 3.70. Let C and D be categories, and L : C D and R : D C be functors. → → We say that L is left adjoint to R (and that R is right adjoint to L) if, for any c C and ∈ d D, there is an isomorphism of hom-sets ∈  αc d : C c, R d D L c , d , ( ( )) −→ ( ( ) ) that is natural in c and d.8

Given a morphism f : c R d in C, its 1 B αc d f is called its mate. → ( ) , ( ) Similarly, the mate of 1 : L c d is f . ( ) → 3.4. ADJUNCTIONS AND DATA MIGRATION 103

To denote an adjunction we write L R, or in diagrams, a L C D R with the in the direction of the left adjoint. ⇒

Example 3.71. Recall that every preorder P can be regarded as a category. Galois connections between preorders and adjunctions between the corresponding categories are exactly the same thing.

Example 3.72. Let B Ob Set be any set. There is an adjunction called ‘ B,’ ∈ ( ) after the logician Haskell Curry:

B −× Set Set Set A B, C  Set A, CB B ( × ) ( ) (−) Abstractly we write it as on the left, but what this means is that for any sets A, C, there is a natural isomorphism as on the right. To explain this, we need to talk about exponential objects in Set. Suppose that B and C are sets. Then the set of functions B C is also a set; let’s denote it CB. It’s → written this way because if C has 10 elements and B has 3 elements then CB has 103 elements, and more generally for any two finite sets CB  C B . | | | || | The idea of currying is that given sets A, B, and C, there is a one-to-one correspon- dence between functions A B C and functions A CB. Intuitively, if I have a ( × ) → → function f of two variables a, b, I can “put off” entering the second variable: if you give me just a, I’ll return a function B C that’s waiting for the B input. This is the curried → version of f . As one might guess, there is a formal connection between exponential objects and what we called hom-elements b ( c in Definition 2.79.

Exercise 3.73. In Example 3.72, we discussed an adjunction between functors B − × and B. But we only said how these functors worked on objects: for an arbitrary set (−) X, they return sets X B and XB respectively. × 8This naturality is between functors Cop D Set. It says that for any morphisms f : c c in C × → 0 → and 1 : d d in D, the following diagram commutes: → 0

αc,d C c, Rd D Lc, d ( ) ( ) C f ,R1 D L f ,1 ( ) ( ) C D c0, Rd0 α Lc0, d0 ( ) c0,d0 ( ) 104 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

1. Given a morphism f : X Y, what morphism should B : X B Y B → − × × → × return? 2. Given a morphism f : X Y, what morphism should B : XB YB return? → (−) → 3. Consider the function +: N N N, which sends a, b a + b. Currying +, × → ( ) 7→ we get a certain function p : N NN. What is p 3 ? ♦ → ( )

Example 3.74. If you know some abstract algebra or , here are some other examples of adjunctions. 1. Free constructions: given any set you get a , , free , free vector , etc.; each of these is a left adjoint. The corresponding right adjoint takes a group, a monoid, a ring, a etc. and forgets the algebraic structure to return the underlying set. 2. Similarly, given a graph you get a free preorder or a free category, as we discussed in Section 3.2.3; each is a left adjoint. The corresponding right adjoint is the underlying graph of a preorder or of a category. 3. Discrete things: given any set you get a discrete preorder, discrete graph, discrete metric space, , discrete ; each of these is a left adjoint. The corresponding right adjoint is again underlying set. 4. Codiscrete things: given any set you get a codiscrete preorder, complete graph, codiscrete category, codiscrete topological space; each of these is a right adjoint. The corresponding left adjoint is the underlying set. 5. Given a group, you can quotient by its to get an ; this is a left adjoint. The right adjoint is the inclusion of abelian groups into groups.

3.4.3 Left and right functors, Σ and Π

Given F : C D, the data migration functor ∆F turns D-instances into C-instances. → This functor has both a left and a right adjoint:

ΣF

C-Inst ∆F D-Inst

ΠF 3.4. ADJUNCTIONS AND DATA MIGRATION 105

Using the names Σ and Π in this context is fairly standard in category theory. In the case of databases, they have the following helpful mnemonic:

Migration Functor Pronounced Reminiscent of Database idea ∆ Delta Duplicate Duplicate or destroy or destroy tables or columns Σ Sigma Sum Union (sum up) data

Π Pi Pair9 and query data

Just like we used ∆F to pull back any discrete dynamical system along F : Gr DDS → and get a graph, the migration functors ΣF and ΠF can be used to turn any graph into a discrete dynamical system. That is, given an instance J : Gr Set, we can get → instances ΣF J and ΠF J on DDS. This, however, is quite technical, and we leave it ( ) ( ) to the adventurous reader to compute an example, with help perhaps from [Spi14a], which explores the definitions of Σ and Π in detail. A less technical shortcut is simply to code up the computation in the open-source FQL software. To get the basic idea across without getting mired in technical details, here we shall instead discuss a very simple example. Recall the schemas from Eq. (3.5). We can set up a functor between them, the one sending black dots to black dots and white dots to white dots:

$ $

Price ◦ Price ◦ Price F A B Economy First Class Airline Seat : B • • • Position Position Position string string ◦ ◦ With this functor F in hand, we can transform any B-instance into an A-instance using

∆F. Whereas ∆ was interesting in the case of turning discrete dynamical systems into graphs in Section 3.4.1, it is not very interesting in this case. Indeed, it will just copy—∆ for duplicate—the rows in Airline seat into both Economy and First Class.

∆F has two adjoints, ΣF and ΠF, both of which transform any A-instance I into a B-instance. The functor ΣF does what one would most expect from reading the names on each object: it will put into Airline Seat the union of Economy and First Class:

ΣF I Airline Seat  I Economy I First Class . ( )( ) ( ) t ( )

The functor ΠF puts into Airline Seat the set of those pairs e, f where e is an ( ) Economy seat, f is a First Class seat, and e and f have the same price and position.

9This is more commonly called “join” by database programmers. 106 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

In this particular example, one imagines that there should be no such seats in a valid instance I, in which case ΠF I Airline Seat would be empty. But in other uses of these ( )( ) same schemas, ΠF can be a useful operation. For example, in the schema A replace the label ‘Economy’ by ‘Rewards Program’, and in B replace ‘Airline Seat’ by ‘First

Class Seats’. Then the operation ΠF finds those first class seats that are also rewards program seats. This operation is a kind of database query; querying is the operation that databases are built for. The moral is that complex data migrations can be specified by constructing functors

F between schemas and using the “induced” functors ∆F, ΣF, and ΠF. Indeed, in practice essentially all useful migrations can be built up from these. Hence the language of categories provides a framework for specifying and reasoning about data migrations.

3.4.4 Single set summaries of databases

To give a stronger idea of the flavor of Σ and Π, we consider another special case, namely where the target category D is equal to 1; see Exercise 3.12. In this case, there is exactly one functor C 1 for any C; let’s denote it → !: C 1. (3.75) → Exercise 3.76. Describe the functor !: C 1 from Eq. (3.75). Where does it send each → object? What about each morphism? ♦

We want to consider the data migration functors Σ! : C-Inst 1-Inst and Π! : C-Inst → → 1-Inst. In Example 3.53, we saw that an instance on 1 is the same thing as a set. So let’s identify 1-Inst with Set, and hence discuss

Σ! : C-Inst Set and Π! : C-Inst Set. → → Given any schema C and instance I : C Set, we will get sets Σ! I and Π! I . Thinking → ( ) ( ) of these sets as database instances, each corresponds to a single one-column table—a controlled vocabulary—summarizing an entire database instance on the schema C. Consider the following schema

Email sent_by Address G B • received_by • (3.77)

no equations Here’s a sample instance I : G Set: → Email sent_by received_by Address Em_1 Bob Grace Bob Em_2 Grace Pat Doug Em_3 Bob Emmy Emmy Em_4 Sue Doug Grace Em_5 Doug Sue Pat Em_6 Bob Bob Sue 3.5. BONUS: AN INTRODUCTION TO LIMITS AND COLIMITS 107

Exercise 3.78. Note that G from Eq. (3.77) is isomorphic to the schema Gr. In Section 3.3.5 we saw that instances on Gr are graphs. Draw the above instance I as a graph. ♦

Now we have a unique functor !: G 1, and we want to say what Σ! I and Π! I give → ( ) ( ) us as single-set summaries. First, Σ! I tells us all the emailing groups—the “connected ( ) components”—in I: 1 Bob-Grace-Pat-Emmy Sue-Doug

This form of summary, involving identifying entries into common groups, or quotients, is typical of Σ-operations.

The functor Π! I lists the emails from I which were sent from a person to her- or ( ) him-self. 1 Em_6

This is again a sort of query, selecting the entries that fit the criterion of self-to-self emails. Again, this is typical of Π-operations.

Where do these facts—that Π! and Σ! act the way we said—come from? Everything follows from the definition of adjoint functors (3.70): indeed we hope this, together with the examples given in Example 3.74, give the reader some idea of how general and useful adjunctions are, both in mathematics and in database theory. One more point: while we will not spell out the details, we note that these operations are also examples of constructions known as colimits and limits in Set. We end this chapter with bonus material, exploring these key category theoretic constructions. The reader should keep in mind that, in general and not just for functors to 1, Σ-operations are built from colimits in Set, and Π-operations are built from limits in Set.

3.5 Bonus: An introduction to limits and colimits

What do products of sets, the results of Π!-operations on database instances, and meets in a preorder all have in common? The answer, as we shall see, is that they are all examples of limits. Similarly, disjoint unions of sets, the results of Σ!-operations on database instances, and joins in a preorder are all colimits. Let’s begin with limits.

Recall that Π! takes a database instance I : C Set and turns it into a set Π! I . → ( ) More generally, a limit turns a functor F : C D into an object of D. →

3.5.1 Terminal objects and products

Terminal objects and products are each a sort of limit. Let’s discuss them in turn.

Terminal objects. The most basic limit is a terminal object. 108 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Definition 3.79. Let C be a category. Then an object Z in C is a terminal object if, for each object C of C, there exists a unique morphism !: C Z. →

Since this unique morphism exists for all objects in C, we say that terminal objects have a .

Example 3.80. In Set, any set with exactly one element is a terminal object. Why? Consider some such set . Then for any other set C we need to check that there is {•} exactly one function !: C . This unique function is the one that does the only → {•} thing that can be done: it maps each element c C to the element . ∈ • ∈ {•}

Exercise 3.81. Let P, be a preorder, let z P be an element, and let P be the ( ≤) ∈ corresponding category (see Section 3.2.3). Show that z is a terminal object in P if and only if it is a top element in P: that is, if and only if for all c P we have c z. ♦ ∈ ≤ Exercise 3.82. Name a terminal object in the category Cat. (Hint: recall Exercise 3.76.) ♦ Exercise 3.83. Not every category has a terminal object. Find one that doesn’t. ♦

Proposition 3.84. All terminal objects in a category C are isomorphic.

Proof. This is a simple, but powerful standard argument. Suppose Z and Z0 are both terminal objects in some category C. Then there exist (unique) maps a : Z Z and → 0 b : Z0 Z. Composing these, we get a map a b : Z Z. Now since Z is terminal, this → # → map Z Z must be unique. But idZ is also such a map. So we must have a b  idZ. → # Similarly, we find that b a  idZ . Thus a is an isomorphism, with inverse b.  # 0 Remark 3.85 (“The limit” vs. “a limit”). Not only are all terminal objects isomorphic, there is a unique isomorphism between any two. We hence say “terminal objects are unique up to unique isomorphism.” To a category theorist, this is very nearly the same thing as saying “all terminal objects are equal.” Thus we often abuse terminology and talk of ‘the’ terminal object, rather than “a” terminal object. We will do the same for any sort of limit or colimit, e.g. speak of “the product” of two sets, rather than “a product.” We saw a similar phenomenon in Definition 1.81.

Products. Products are slightly more complicated to formalize than terminal objects, but they are familiar in practice.

Definition 3.86. Let C be a category, and let X, Y be objects in C.A product of X and Y is an object, denoted X Y, together with morphisms pX : X Y X and pY : X Y Y × × → × → such that for all objects C together with morphisms f : C X and 1 : C Y, there → → exists a unique morphism C X Y, denoted f , 1 , for which the following diagram → × h i 3.5. BONUS: AN INTRODUCTION TO LIMITS AND COLIMITS 109 commutes: C f 1

f ,1 X h i Y pX pY X Y × We will try to bring this down to earth in Example 3.87. Before we do, note that X Y is an object equipped with morphisms to X and Y. Roughly speaking, it is like × “the best object-equipped-with-morphisms-to-X-and-Y” in all of C, in the sense that any other object-equipped-with-morphisms-to-X-and-Y maps to it uniquely. This is called a universal property. It’s customary to use a dotted line to indicate the unique morphism that exists because of some universal property.

Example 3.87. In Set, a product of two sets X and Y is their usual

X Y B x, y x X, y Y , × {( ) | ∈ ∈ } which comes with two projections pX : X Y X and pY : X Y Y, given by × → × → pX x, y B x and pY x, y B y. ( ) ( ) Given any set C with functions f : C X and 1 : C Y, the unique map from C → → to X Y such that the required diagram commutes is given by f , 1 c B f c , 1 c . × h i( ) ( ( ) ( )) Here is a picture of the product 6 4 of sets 6 and 4. × 1 ∀ C

! ∃ 4 1,4 2,4 3,4 4,4 5,4 6,4 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • • 3 1,3 2,3 3,3 4,3 5,3 6,3 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • • f 2 1,2 2,2 3,2 4,2 5,2 6,2 ∀ ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • • 1 1,1 2,1 3,1 4,1 5,1 6,1 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • •

1 2 3 4 5 6 • • • • • •

Exercise 3.88. Let P, be a preorder, let x, y P be elements, and let P be the ( ≤) ∈ corresponding category. Show that the product x y in P agrees with their meet x y × ∧ in P. ♦ 110 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Example 3.89. Given two categories C and D, their product C D may be given as × follows. The objects of this category are pairs c, d , where c is an object of C and d is an ( ) object of D. Similarly, morphisms c, d c , d are pairs f , 1 where f : c c is a ( ) → ( 0 0) ( ) → 0 morphism in C and 1 : d d is a morphism in D. Composition of morphisms is simply → 0 given by composing each entry in the pair separately, so f , 1 f 0, 10  f f 0, 1 10 . ( ) # ( ) ( # # )

Exercise 3.90. 1. What are the identity morphisms in a C D? × 2. Why is composition in a product category associative? 3. What is the product category 1 2? × 4. What is the product category P Q when P and Q are preorders and P and Q are × the corresponding categories? ♦ These two constructions, terminal objects and products, are subsumed by the notion of limit.

3.5.2 Limits

We’ll get a little abstract. Consider the definition of product. This says that given any f 1 pair of maps X C Y, there exists a unique map C X Y such that certain ←− −→ → × diagrams commute. This has the flavor of being terminal—there is a unique map to X Y—but it seems a bit more complicated. How are the two ideas related? × It turns out that products are terminal objects, but of a different category, which we’ll call X, Y , the category of cones over X and Y in C. We will see in Exercise 3.91 pX ( pY) that X X Y Y is a terminal object in Cone X, Y . ←−− × −−→ ( )f 1 An object of Cone X, Y is simply a pair of maps X C Y. A morphism from ( ) ←− −→ f 1 f 0 10 X C Y to X C Y in Cone X, Y is a morphism a : C C in C such that ←− −→ ←− 0 −→ ( ) → 0 the following diagram commutes:

C f 1

X a Y

f 0 10 C0

pX pY Exercise 3.91. Check that a product X X Y Y is exactly the same as a terminal ←−− × −−→ object in Cone X, Y . ♦ ( ) We’re now ready for the abstract definition. Don’t worry if the details are unclear; the main point is that it is possible to unify terminal objects, maximal elements, and meets, products of sets, preorders, and categories, and many other familiar friends under the scope of a single definition. In fact, they’re all just terminal objects in different categories. 3.5. BONUS: AN INTRODUCTION TO LIMITS AND COLIMITS 111

Recall from Definition 3.51 that formally speaking, a diagram in C is just a functor D : J C. Here J is called the indexing category of the diagram D. → Definition 3.92. Let D : J C be a diagram. A cone C, c over D consists of → ( ∗) (i) an object C C; ∈ (ii) for each object j J, a morphism c j : C D j . ∈ → ( ) To be a cone, these must satisfy the following property:

(a) for each f : j k in J, we have ck  c j D f . → # ( ) A morphism of cones C, c C0, c0 is a morphism a : C C0 in C such that for all ( ∗) → ( ∗) → j J we have c j  a c0. Cones over D, and their morphisms, form a category Cone D . ∈ # j ( ) The limit of D, denoted lim D , is the terminal object in the category Cone D . Say ( ) ( ) it is the cone lim D  C, c ; we refer to C as the limit object and the map c j for any ( ) ( ∗) j J as the jth projection map. ∈

For visualization purposes, if J is the free category on the graph

1 3

2 4 5 with five objects and five non-identity morphisms, then we may draw a diagram D : J C inside C as on the left below, and a cone on it as on the right: →

C c1 C

c5 c3 c2 c4

D1 D3 D1 D3

D2 D4 D5 D2 D4 D5

Here, any two parallel paths that start at C are considered the same. Note that both these diagrams depict a collection of objects and morphisms inside the category C.

Example 3.93. Terminal objects are limits where the indexing category is empty, J  . œ

Example 3.94. Products are limits where the indexing category consists of two objects v w v, w and no arrows, J  . • •

3.5.3 Finite limits in Set

Recall that this discussion was inspired by wanting to understand Π-operations, and in particular Π!. We can now see that a database instance I : C Set is a diagram in → 112 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS

Set. The functor Π! takes the limit of this diagram. In this subsection we give a formula describing the result. This captures all finite limits in Set. In database theory, we work with categories C that are presented by a finite graph plus equations. We won’t explain the details, but it’s in fact enough just to work with the graph part: as far as limits are concerned, the equations in C don’t matter. For consistency with the rest of this section, let’s denote the database schema by J instead of C.

Theorem 3.95. Let J be a category presented by the finite graph V, A, s, t together with ( ) some equations, and let D : J Set be a set-valued functor. Write V  v1,..., vn . → { } The set

 lim D B d1,..., dn di D vi for all 1 i n and J ( ) | ∈ ( ) ≤ ≤

for all a : vi v j A, we have D a di  dj . → ∈ ( )( ) together with the projection maps pi : limJ D D vi given by pi d1,..., dn B di, ( ) → ( ) ( ) is a limit of D.

Example 3.96. If J is the empty graph , then n  0: there are no vertices. There is ex- • actly one empty tuple , which vacuously satisfies the properties, so we’ve constructed () the limit as the singleton set consisting of just the empty tuple. Thus the limit of {()} the empty diagram, i.e. the terminal object in Set is the singleton set. See Remark 3.85.

Exercise 3.97. Show that the limit formula in Theorem 3.95 works for products. See Example 3.94. ♦ Exercise 3.98. If D : 1 Set is a functor, what is the limit of D? Compute it using → Theorem 3.95, and check your answer against Definition 3.92. ♦

Pullbacks. In particular, the condition that the limit of D : J Set selects tuples → d1,..., dn such that D a di  dj for each morphism a : i j in J allows us to use ( ) ( )( ) → limits to select data that satisfies certain equations or constraints. This is what allows us to express queries in terms of limits. Here is an example.

x f a 1 y Example 3.99. If J is presented by the cospan graph , then its limit is f 1 • −−→ • ←−− • known as a pullback. Given the diagram X A Y, the pullback is the cone shown −→ ←− 3.5. BONUS: AN INTRODUCTION TO LIMITS AND COLIMITS 113 on the left below:

cy cy C Y X A Y Y × ca y cx 1 cx 1 X A X A f f

The fact that the diagram commutes means that the diagonal arrow ca is in some sense superfluous, so one generally denotes pullbacks by dropping the diagonal arrow, naming the cone point X A Y, and adding the y symbol, as shown to the right above. × Here is a picture to help us unpack the definition in Set. We take X  6, Y  4, and A to be the set of colors red, blue, black . { }

4 1,4 2,4 3,4 4,4 5,4 6,4 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • • 3 1,3 2,3 3,3 4,3 5,3 6,3 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • • 2 1,2 2,2 3,2 4,2 5,2 6,2 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • • 1 1,1 2,1 3,1 4,1 5,1 6,1 ( ) ( ) ( ) ( ) ( ) ( ) • • • • • • •

1 2 3 4 5 6 • • • • • •

The functions f : 6 A and 1 : 4 A are expressed in the coloring of the dots: for → → example, 1 2  1 4  red, while f 5  black. The pullback selects pairs i, j 6 4 ( ) ( ) ( ) ( ) ∈ × such that f i and 1 j have the same color. ( ) ( ) Remark 3.100. As mentioned following Definition 3.68, this definition of pullback is not to be confused with the pullback of a set-valued functor along a functor; they are for now best thought of as different concepts which accidentally have the same name. Due to the power of the primordial ooze, however, the pullback along a functor is a special case of pullback as the limit of a cospan: it can be understood as the pullback of a certain cospan in Cat. To unpack this, however, requires the notions of and discrete opfibration; ask your friendly neighborhood category theorist.

3.5.4 A brief note on colimits

Just like upper bounds have a concept—namely that of lower bounds—so limits have a dual concept: colimits. To expose the reader to this concept, we provide a succinct definition of these using opposite categories and opposite functors. The point, however, is just exposure; we will return to explore colimits in detail in Chapter6. Exercise 3.101. Recall from Example 3.27 that every category C has an opposite Cop. Let F : C D be a functor. How should we define its opposite, Fop : Cop Dop? That → → 114 CHAPTER 3. DATABASES: CATEGORIES, FUNCTORS, AND (CO)LIMITS is, how should Fop act on objects, and how should it act on morphisms? ♦

Definition 3.102. Given a category C we say that a cocone in C is a cone in Cop. Given a diagram D : J C, we may take the limit of the functor Dop : Jop Cop. → → This is a cone in Cop, and so by definition a cocone in C. The colimit of D is this cocone.

Definition 3.102 is like a compressed file: useful for transmitting quickly, but com- pletely useless for working with, unless you can successfully unpack it. We will unpack it later in Chapter6 when we discuss electric circuits.

3.6 Summary and further reading

Congratulations on making it through one of the longest chapters in the book! We apologize for the length, but this chapter had a lot of work to do. Namely it introduced the “big three” of category theory—categories, functors, and natural transformations— as well as discussed adjunctions, limits, and very briefly colimits. That’s really quite a bit of material. For more on all these subjects, one can consult any standard book on category theory, of which there are many. The bible (old, important, seminal, and requires a priest to explain it) is [Mac98]; another thorough introduction is [Bor94]; a logical perspective is given in [Awo10]; a perspective is given in [BW90] and [Pie91] and [Wal92]; math students should probably read [Lei14] or [Rie17] or [Gra18]; a general audience might start with [Spi14a]. We presented categories from a database perspective, because data is pretty ubiq- uitous in our world. A database schema—i.e. a system of interlocking tables—can be captured by a category C, and filling it with data corresponds to a functor C Set. Here → Set is the category of sets, perhaps the most important category to mathematicians. The perspective of using category theory to model databases has been rediscovered several times. It seems to have first been discussed by various authors around the mid-90’s [IP94; CD95; PS95; TG96]. Bob Rosebrugh and collaborators took it much further in a series of papers including [FGR03; JR02; RW92]. Most of these authors tend to focus on sketches, which are more expressive categories. Spivak rediscovered the idea again quite a bit later, but focused on categories rather than sketches, so as to have all three data migration functors ∆, Σ, Π; see [Spi12; SW15b]. The version of this story presented in the chapter, including the white and black nodes in schemas, is part of a larger theory of algebraic databases, where a programming language such as Java or Haskell is attached to a database. The technical details are worked out in [Sch+17], and its use in database integration projects can be found in [SW15a; Wis+15]. Before we leave this chapter, we want to emphasize two things: coherence conditions and universal constructions.

Coherence conditions. In the definitions of category, functor, and natural transforma- tions, we have data (indexed by (i)) that is required to satisfy certain properties (indexed 3.6. SUMMARY AND FURTHER READING 115 by (a)). Indeed, for categories it was about associativity and unitality of composition, for functors it was about respecting composition and identities, and for natural trans- formations it was the naturality condition. These conditions are often called coherence conditions: we want the various structures to cohere, to work well together, rather than to flop around unattached. Understanding why these particular structures and coherence conditions are “the right ones” is more science than mathematics: we empirically observe that certain combinations result in ideas that are both widely applicable and also strongly compo- sitional. That is, we become satisfied with coherence conditions when they result in beautiful mathematics down the road.

Universal constructions. Universal constructions are one of the most important themes of category theory. Roughly speaking, one gives some specified shape in a category and says “find me the best solution!” And category theory comes back and says “do you want me to approximate from the left or the right (colimit or limit)?” You respond, and either there is a best solution or there is not. If there is, it’s called the (co)limit; if there’s not we say “the (co)limit does not exist.” Even data migration fits this form. We say “find me the closest thing in D that matches my C-instance using my functor F : C D.” In fact this approach—known → as Kan extensions—subsumes the others. One of the two founders of category theory, , has a section in his book [Mac98] called “All concepts are Kan extensions,” a big statement, no? MIT OpenCourseWare https://ocw.mit.edu/

18.S097 January IAP 2019

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.