A **compact closed category** is a symmetric monoidal category \(\mathcal{C}\) where every object \(x\) has a **dual** \(x^\ast\) equipped with two morphisms called the **cap** or **unit**

[ \cap_x \colon I \to x \otimes x^\ast ]

and the **cup** or **counit**

[ \cup_x \colon x^\ast \otimes x \to I ]

obeying two equations called the **snake equations**.

You've seen these equations a couple times before! In Lecture 68 I was telling you about feedback in co-design diagrams: caps and cups let you describe feedback. I was secretly telling you that the category of feasibility relations was a compact closed category. In Lecture 71 I came back to this theme at a higher level of generality. Feasibility relations are just \(\mathcal{V}\)-enriched profunctors for \(\mathcal{V} = \mathbf{Bool}\), and in Lecture 71 I was secretly telling you that the category of \(\mathcal{V}\)-profunctors is always a compact closed category! But now I'm finally telling you what a compact closed category is in general.

The snake equations are easiest to remember using string diagrams. In a compact closed category we draw arrows on string in these diagrams as well as labeling them by objects. For any object \(x\) a left-pointing wire labelled \(x\) means the same as a right-pointing wire labelled \(x^\ast\). Thus, we draw the cap as

This picture has no wires coming in at left, which says that the cap is a morphism from \(I\), the unit object of our symmetric monoidal category. It has two wires doing out at right: the top wire with a right-pointing arrow, stands for \(x\), while the bottom wire with a right-pointing arrow stands for \(x^\ast\), and together these tell us that cap is a morphism to \(x \otimes x^\ast\).

Similarly, we draw the cup as

and this diagram, to the trained eye, says that the cup is a morphism from \(x^\ast \otimes x \) to \( I \).

In this language, the snake equations simply say that we can straighten out a 'zig-zag':

or a 'zag-zig':

If we don't use string diagrams, these equation look more complicated. The first says that this composite morphism is the identity:

where the unnamed isomorphisms are the inverse of the left unitor, the associator and the right unitor. The second says that this composite is the identity:

where the unnamed isomorphisms are the inverse of the right unitor, the inverse of the associator, and the left unitor. These are a lot less intuitive, I think! One advantage of string diagrams is that they hide associators and unitors, yet let us recover them if we really need them.

If you've faithfully done all the puzzles so far, you've proved the following grand result, which summarizes a lot of this chapter:

**Theorem.** Suppose \(\mathcal{V}\) is a commutative quantale. Then the category \(\mathbf{Prof}_{\mathcal{V}}\) with

- \(\mathcal{V}\)-enriched categories as objects

and

- \(\mathcal{V}\)-enriched profunctors as morphisms

is compact closed, where tensor product, associator and unitors are defined as in Lecture 70, and the dual, caps and cups are defined as in Lecture 71.

But the most famous example of a compact closed category comes from linear algebra! It's the category \(\mathbf{FinVect}_k\), with

- finite-dimensional vector spaces over the field \(k\) as objects

and

- linear maps as morphisms.

If you don't know about fields, you may still know about real vector spaces: that's the case \(k = \mathbb{R}\). There's a tensor product \(V \otimes W\) of vector spaces \(V\) and \(W\), which has dimension equal to the dimension of \(V\) times the dimension of \(W\). And there's a dual \(V^\ast\) of a vector space \(V\), which is just the space of all linear maps from \(V\) to \(k\).

Tensor products and dual vector spaces are very important in linear algebra. My main point here is that the profunctors work a lot like linear maps: both are morphisms in some compact closed category! Indeed, the introduction of profunctors into category theory was very much like the introduction of linear algebra in ordinary set-based mathematics. I've tried to hint at this several times: the ultimate reason is that composing profunctors is a lot like multiplying matrices! This is easiest to see for \(\mathcal{V}\)-enriched profunctors we've been dealing with. Composing these:

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z)]

looks just like matrix multiplication, with \(\bigvee\) replacing addition in the field \(k\) and \(\otimes\) replacing multiplication. So it's not surprising that this analogy extends, with the opposite of a \(\mathcal{V}\)-enriched category acting like a dual vector space.

If you're comfortable with tensor products and duals of vector spaces, you may want to solidify your understanding of compact closed categories by doing this puzzle:

**Puzzle 283.** Guess what the cap and cup

$$ \cap_V \colon k \to V \otimes V^\ast, \qquad \cup_V \colon V^\ast \otimes V \to k $$

are for a finite-dimensional vector space \(V\), and check your guess by proving the snake equations.

Here are some good things to know about compact closed categories:

**Puzzle 284.** Using the cap and cup, any morphism \(f \colon x \to y \) in a compact closed category gives rise to a morphism from \(y^\ast\) to \(x^\ast\). This amounts to 'turning \(f\) around' in a certain sense, and we call this morphism \(f^\ast \colon y^\ast \to x^\ast \). Write down a formula for \(f^\ast\) and also draw it as a string diagram.

**Puzzle 285.** Show that \( (fg)^\ast = g^\ast f^\ast \) for any composable morphisms \(f\) and \(g\), and show that \( (1_x)^\ast = 1_x \) for any object \(x\).

**Puzzle 286.** What is a slick way to state the result in Puzzle 285?

**Puzzle 287.** Show that if \(x\) is an object in a compact closed category, \( (x^\ast)^\ast\) is isomorphic to \(x\).

As we learned long ago, the basic idea is that adjoints give *the best possible way to approximately recover data that can't really be recovered*.

For example, you might have a map between databases that discards some data. You might like to reverse this process. Strictly speaking this is impossible: if you've truly discarded some data, you don't know what it is anymore, so you can't restore it. But you can still *do your best!*

There are actually two kinds of 'best': left adjoints and right adjoints.

Remember the idea. We have a functor \(F : \mathcal{A} \to \mathcal{B}\). We're looking for a nice functor \(G: \mathcal{B} \to \mathcal{A} \) that goes back the other way, some sort of attempt to reverse the effect of \(F\). We say that \(G\) is a **right adjoint** of \(F\) if there's a natural one-to-one correspondence between

- morphisms from \(F(a)\) to \(b\)

and

- morphisms from \(a\) to \(G(b)\)

whenever \(a\) is an object of \(\mathcal{A}\) and \(b\) is an object of \(\mathcal{B}\). In this situation we also say \(F\) is a **left adjoint** of \(G\).

The tricky part in this definition is the word 'natural'. That's why I had to explain natural transformations. But let's see how far we can get understanding adjoint functors without worrying about this.

Let's do an example. There's a category \(\mathbf{Set}\) where objects are sets and morphisms are functions. And there's much more boring category \(\mathbf{1}\), with exactly one object and one morphism. Today let's call that one object \(\star\), so the one morphism is \(1_\star\).

In Puzzle 135 we saw there is always exactly one functor from any category to \(\mathbf{1}\). So, there's exactly one functor

[ F: \mathbf{Set} \to \mathbf{1} ]

This sends every set to the object \(\star\), and every function between sets to the morphism \(1_\star\).

This is an incredibly destructive functor! It discards *all* the information about every set and every function! \(\mathbf{1}\) is like the ultimate trash can, or black hole. Drop data into it and it's *gone*.

So, it seems insane to try to 'reverse' the functor \(F\), but that's what we'll do. First let's look for a right adjoint

[ G: \mathbf{1} \to \mathbf{Set} .]

For \(G\) to be a right adjoint, we need a natural one-to-one correspondence between morphisms

[ m: F(S) \to \star ]

and morphisms

[ n: S \to G(\star) ]

where \(S\) is any set.

Think about what this means! We know \(F(S) = \star\): there's nothing else it could be, since \(\mathbf{1}\) has just one object. So, we're asking for a natural one-to-one correspondence between the set of morphisms

[ m : \star \to \star ]

and the set of functions

[ n : S \to G(\star) .]

This has got to work for every set \(S\). This should tell us a lot about \(G(\star)\).

Well, there's just *one* morphism \( m : \star \to \star\), so there had better be just one function \(n : S \to G(\star)\), *for any set* \(S\). This forces \(G(\star)\) to be a set with just one element. And that does the job! We can take \(G(\star)\) to be *any* set with just one element, and that gives us our left adjoint \(G\).

Well, okay: we have to say what \(G\) does to *morphisms*, too. But the only morphism in \(\mathbf{1}\) is \(1_\star\), and we must have \(G(1_\star) = 1_{G(\star)} \), thanks to how functors work.

(Furthermore you might wonder about the 'naturality' condition, but this example is so trivial that it's automatically true.)

So: if you throw away a set into the trash bin called \(\mathbf{1}\), and I say "wait! I want that set back!", and I have to make up something, the right adjoint procedure says "pick any one-element set". Weird but true. When you really understand adjoints, you'll have a good intuitive sense for why it works this way.

What about the left adjoint procedure? Let's use \(L\) to mean a left adjoint of our functor \(F\):

**Puzzle 149.** Again suppose \(F: \mathbf{Set} \to \mathbf{1}\) is the functor that sends every set to \(\star\) and every function to \(1_\star\). A *left* adjoint \(L : \mathbf{1} \to \mathbf{Set} \) is a functor for which there's a natural one-to-one correspondence between functions

[ m: L(\star) \to S ]

and morphisms

[ n: \star \to F(S) ]

for every set \(S\). On the basis of this, try to figure out all the left adjoints of \(F\).

Let's also try some slightly harder examples. There is a category \(\mathbf{Set}^2\) where an object is a pair of sets \( (S,T)\). In this category a morphism is a pair of functions, so a morphism

[ (f,g): (S,T) \to (S',T') ]

is just a function \(f: S \to S'\) together with function \(g: T \to T'\). We compose these morphisms componentwise:

[ (f,g) \circ (f',g') = (f\circ f', g \circ g') . ]

You can figure out what the identity morphisms are, and check all the category axioms.

There's a functor

[ F: \mathbf{Set}^2 \to \mathbf{Set} ]

that discards the second component. So, on objects it throws away the second set:

[ F(S,T) = S ]

and on morphisms it throws away the second function:

[ F(f,g) = f .]

**Puzzle 150.** Figure out all the right adjoints of \(F\).

**Puzzle 151.** Figure out all the left adjoints of \(F\).

There's also a functor

[ \times: \mathbf{Set}^2 \to \mathbf{Set} ]

that takes the Cartesian product, both for sets:

[ \times (S,T) = S \times T ]

and for functions:

[ \times (f,g) = f \times g ]

where \((f\times g)(s,t) = (f(s),g(t))\) for all \(s \in S, t \in T\).

**Puzzle 152.** Figure out all the right adjoints of \(\times\).

**Puzzle 153.** Figure out all the left adjoints of \(\times\).

Finally, there's also a functor

[ + : \mathbf{Set}^2 \to \mathbf{Set} ]

that takes the disjoint union, both for sets:

[ + (S,T) = S + T ]

and for functions:

[ +(f,g) = f + g .]

Here \(S + T\) is how category theorists write the disjoint union of sets \(S\) and \(T\). Furthermore, given functions \(f: S \to S'\) and \(g: T \to T'\) there's an obvious function \(f+g: S+T \to S'+T'\) that does \(f\) to the guys in \(S\) and \(g\) to the guys in \(T\).

**Puzzle 152.** Figure out all the right adjoints of \(+\).

**Puzzle 153.** Figure out all the left adjoints of \(+\).

I think it's possible to solve all these puzzles even if one has a rather shaky grasp on adjoint functors. At least try them! It's a good way to start confronting this new concept.

]]>**given some requirements, what resources will let us fulfill these requirements?**

and

**given some resources, what requirements will these resources let us fulfill?**

You'll notice that these questions are two sides of the same coin! There will be an enriched profunctor going from resources to requirements they fulfill, and we can 'flip' it to get an enriched profunctor from requirements to resources needed to fulfill them.

As the name suggests, an 'enriched profunctor' is a bit like a functor between enriched categories... for pros. That is, for professionals.

Indeed, most category theorists consider enriched profunctors rather sophisticated. But Fong and Spivak bring them down to earth by their clever trick of focusing on *preorders* rather than more general categories.

Remember that in Chapter 1 they introduced preorders. A **preorder** is a set \(X\) equipped with a relation \(\le\) obeying

[ x \le x]

and

[ x \le y \text{ and } y \le z \; \implies \; x \le z .]

Later we saw a preorder is secretly a category with at most one morphism from any object \(x\) to any object \(y\): if one exists we write \(x \le y\). But because there's at most *one*, we never have to worry about equations between morphisms. Everything simplifies enormously! This is the key to Fong and Spivak's expository strategy.

In Chapter 2 they introduced monoidal preorders. These are a special case of 'monoidal categories', which we haven't discussed yet - but they're much simpler! A **monoidal preorder** is a preorder \( (X,\le) \) with an operation \(\otimes : X \times X \to X\) and element \(I \in X\) obeying

$$ (x \otimes y) \otimes z = x \otimes (y \otimes z) $$

$$ I \otimes x = x = x \otimes I $$

and

$$ x \le x' \textrm{ and } y \le y' \textrm{ imply } x \otimes y \le x' \otimes y' .$$

We used preorders to study *resources*: we said \( x \le y \) if \(x \) is cheaper than \(y\), or you can get \(x\) if you have \(y\). Then we used \(\otimes\) to *combine* resources, and used \(I\) for a 'nothing' resource: \(x\) combined with nothing is just \(x\).

(Actually Fong and Spivak use the opposite convention, writing \(x \le y\) to mean you can get \(y\) if you have \(x\). This seems weird if you think of resources as being like money, but natural if you think of your preorder as a category, and remember \(x \le y\) means there's a morphism \(f : x \to y\). I should probably use this convention.)

Later in Chapter 2 they generalized preorders a bit, and introduced categories enriched in a monoidal preorder. Remember the idea: first we choose a monoidal preorder to enrich in, and call it \(\mathcal{V}\). Then a **\(\mathcal{V}\)-enriched category**, say \(\mathcal{X}\), consists of

a set of

**objects**\(\text{Ob}(\mathcal{X})\), andfor every two objects \(x,y\), an element \(\mathcal{X}(x,y)\) of \(\mathcal{V}\),

such that

a) \( I\leq\mathcal{X}(x,x) \) for every object \(x\in\text{Ob}(\mathcal{X})\), and

b) \( \mathcal{X}(x,y)\otimes\mathcal{X}(y,z)\leq\mathcal{X}(x,z) \) for all objects \(x,y,z\in\mathrm{Ob}(\mathcal{X})\).

We saw that if \(\mathcal{V} = \mathbf{Bool}\), a \(\mathcal{V}\)-enriched category is just a preorder: the truth value \(\mathcal{X}(x,y)\) tells you if you *can* get from \(x\) to \(y\). But if \(\mathcal{V} \) is something fancier, like \(\mathbf{Cost}\), \(\mathcal{X}(x,y)\) tells you more, like *how much it costs* to get from \(x\) to \(y\).

Where do enriched profunctors fit into this game?

Here: given \(\mathcal{V}\)-enriched categories \(\mathcal{X}\) and \(\mathcal{Y}\), a \(\mathcal{V}\)-enriched profunctor is a clever kind of thing going from \(\mathcal{X}\) to \(\mathcal{Y}\).

If we take objects of \(\mathcal{X}\) to be *requirements* and objects of \(\mathcal{Y}\) to be *resources*, we can use a \(\mathcal{V}\)-enriched profunctor from \(\mathcal{X}\) to \(\mathcal{Y}\) to describe, for each choice of requirements, which resources will fulfill it... or how much it will cost to make them fulfill it... or various other things like that, depending on \(\mathcal{V}\).

On the other hand, we can use a \(\mathcal{V}\)-enriched profunctor going back from \(\mathcal{Y}\) to \(\mathcal{X}\) to describe, for each choice of resources, which requirements they will fulfill.. or how much it will cost to make it fulfill them... or various other things like that, depending on \(\mathcal{V}\).

It's all very beautiful and fun. Dive in! Read Section 4.1 and 4.2.1, and maybe 4.2.2 if you're feeling energetic.

Happy Fourth of July! You don't need fireworks for excitement if you've got profunctors.

]]>We took the function \(f : \mathbb{N} \to \mathbb{N}\) that doubles any natural number

[ f(a) = 2a . ]

This function has no inverse, since you can't divide an odd number by 2 and get a natural number! But if you did the puzzles, you saw that \(f\) has a "right adjoint" \(g : \mathbb{N} \to \mathbb{N}\). This is defined by the property

[ f(a) \le b \textrm{ if and only if } a \le g(b) . ]

or in other words,

[ 2a \le b \textrm{ if and only if } a \le g(b) . ]

Using our knowledge of fractions, we have

[ 2a \le b \textrm{ if and only if } a \le b/2 ]

but since \(a\) is a natural number, this implies

[ 2a \le b \textrm{ if and only if } a \le \lfloor b/2 \rfloor ]

where we are using the floor function to pick out the largest integer \(\le b/2\). So,

[ g(b) = \lfloor b/2 \rfloor. ]

Moral: the right adjoint \(g \) is the "best approximation from below" to the nonexistent inverse of \(f\).

If you did the puzzles, you also saw that \(f\) has a left adjoint! This is the "best approximation from above" to the nonexistent inverse of \(f\): it gives you the smallest integer that's \(\ge n/2\).

So, while \(f\) has no inverse, it has two "approximate inverses". The left adjoint comes as close as possible to the (perhaps nonexistent) correct answer while making sure to never choose a number that's *too small*. The right adjoint comes as close as possible while making sure to never choose a number that's *too big*.

The two adjoints represent two opposing philosophies of life: *make sure you never ask for too little* and *make sure you never ask for too much*. This is why they're philosophically profound. But the great thing is that they are defined in a completely precise, systematic way that applies to a huge number of situations!

If you need a mnemonic to remember which is which, remember left adjoints are "left-wing" or "liberal" or "generous", while right adjoints are "right-wing" or "conservative" or "cautious".

Let's think a bit more about how we can compute them in general, starting from the basic definition.

Here's the definition again. Suppose we have two preorders \((A,\le_A)\) and \((B,\le_B)\) and a monotone function \(f : A \to B\). Then we say a monotone function \(g: B \to A\) is a **right adjoint of \(f\)** if

[ f(a) \le_B b \textrm{ if and only if } a \le_A g(b) ]

for all \(a \in A\) and \(b \in B\). In this situation we also say that \(f\) is a **left adjoint of \(g\)**.

The names should be easy to remember, since \(f\) shows up on the *left* of the inequality \( f(a) \le_B b \), while \(g\) shows up on the *right* of the inequality \( a \le_A g(b) \). But let's see how they actually work!

Suppose you know \(f : A \to B\) and you're trying to figure out its right adjoint \(g: B \to A\). Say you're trying to figure out \(g(b)\). You don't know what it is, but you know

[ f(a) \le_B b \textrm{ if and only if } a \le_A g(b) ]

So, you go around looking at choices of \(a \in A\). For each one you compute \(f(a)\). If \(f(a) \le_B b\), then you know \(a \le_A g(b)\). So, you need to choose \(g(b)\) to be greater than or equal to every element of this set:

[ \{a \in A : \; f(a) \le_B b \} ]

In other words, \(g(b)\) must be an **upper bound** of this set. But you shou'ldn't choose \(g(b)\) to be any bigger that it needs to be! After all, you know \(a \le_A g(b)\) *only if* \(f(a) \le_B b\). So,
\(g(b)\) must be a **least upper bound** of the above set.

Note that I'm carefully speaking about *a* least upper bound. Our set could have two different least upper bounds, say \(a\) and \(a'\). Since they're both the least, we must have \(a \le a'\) and \(a' \le a\). This doesn't imply \(a = a'\), in general! But it does if our preorder \(A\) is a "poset". A **poset** is a preorder \((A, \le_A)\) obeying this extra axiom:

[ \textrm{ if } a \le a' \textrm{ and } a' \le a \textrm{ then } a = a' ]

for all \(a,a' \in A\).

In a poset, our desired least upper bound may still not *exist*. But if it does, it's *unique*, and Fong and Spivak write it this way:

[ \bigvee \{a \in A : \; f(a) \le_B b \} ]

The \(\bigvee\) symbol stands for "least upper bound", also known as **supremum** or **join**.

So, here's what we've shown:

If \(f : A \to B\) has a right adjoint \(g : B \to A\) and \(A\) is a poset, this right adjoint is unique and we have a formula for it:

[ g(b) = \bigvee \{a \in A : \; f(a) \le_B b \} . ]

And we can copy our whole line of reasoning and show this:

If \(g : B \to A\) has a left adjoint \(f : A \to B\) and \(B\) is a poset, this left adjoint is unique and we have a formula for it:

[ f(a) = \bigwedge \{b \in B : \; a \le_A g(b) \} . ]

Here the \(\bigwedge\) symbol stands for "greatest lower bound", also known as the **infimum** or **meet**.

We're making progress: we can now actually compute left and right adjoints! Next we'll start looking at more examples.

]]>**Definition.** A **category** \(\mathcal{C}\) consists of:

a collection of

**objects**anda set of

**morphisms**\(f : x \to y\) from any object \(x\) to any object \(y\),

such that:

a) each pair of morphisms \(f : x \to y\) and \(g: y \to z\) has a **composite** \(g \circ f : x \to z \) and

b) each object \(x\) has a morphism \(1_x : x \to x\) called its **identity**,

for which

i) the **associative law** holds: \(h \circ (g \circ f) = (h \circ g) \circ f\), and

ii) the **left and right unit laws** hold: \(1_y \circ f = f = f \circ 1_x \) for any morphism \(f: x \to y\).

A category looks like this:

**Definition.** Given categories \(\mathcal{C}\) and \(\mathcal{D}\), a **functor** \(F: \mathcal{C} \to \mathcal{D} \) maps

each object \(x\) of \(\mathcal{C}\) to an object \(F(x)\) of \(\mathcal{D}\),

each morphism \(f: x \to y\) in \(\mathcal{C}\) to a morphism \(F(f) : F(x) \to F(y) \) in \(\mathcal{D}\) ,

in such a way that:

a) it preserves composition: \(F(g \circ f) = F(g) \circ F(f) \), and

b) it preserves identities: \(F(1_x) = 1_{F(x)}\).

A functor looks sort of like this, leaving out some detail:

**Definition.** Given categories \(\mathcal{C},\mathcal{D}\) and functors \(F, G: \mathcal{C} \to \mathcal{D}\), a **natural transformation** \(\alpha : F \to G\) is a choice of morphism

[ \alpha_x : F(x) \to G(x) ]

for each object \(x \in \mathcal{C}\), such that for each morphism \(f : x \to y\) in \(\mathcal{C}\) we have

[ G(f) \alpha_x = \alpha_y F(f) ,]

or in other words, this **naturality square** commutes:

A natural transformation looks sort of like this:

You should also review the free category on a graph if you don't remember that.

Okay, now for a bunch of puzzles! If you're good at this stuff, please let beginners do the easy ones.

**Puzzle 129.** Let \(\mathbf{1}\) be the free category on the graph with one node and no edges:

Let \(\mathbf{2}\) be the free category on the graph with two nodes and one edge from the first node to the second:

How many functors are there from \(\mathbf{1}\) to \(\mathbf{2}\), and how many natural transformations are there between all these functors? It may help to draw a graph with functors \(F : \mathbf{1} \to \mathbf{2} \) as nodes and natural transformations between these as edges.

**Puzzle 130.** Let \(\mathbf{3}\) be the free category on this graph:

How many functors are there from \(\mathbf{1}\) to \(\mathbf{3}\), and how many natural transformations are there between all these functors? Again, it may help to draw a graph showing all these functors and natural transformations.

**Puzzle 131.** How many functors are there from \(\mathbf{2}\) to \(\mathbf{3}\), and how many natural transformations are there between all these functors? Again, it may help to draw a graph.

**Puzzle 132.** For any category \(\mathcal{C}\), what's another name for a functor \(F: \mathbf{1} \to \mathcal{C}\)? There's a simple answer using concepts you've already learned in this course.

**Puzzle 133.** For any category \(\mathcal{C}\), what's another name for a functor \(F: \mathbf{2} \to \mathcal{C}\)? Again, there's a simple answer using concepts you've already learned here.

**Puzzle 134.** For any category \(\mathcal{C}\), what's another name for a natural transformation \(\alpha : F \Rightarrow G\) between functors \(F,G: \mathbf{1} \to \mathcal{C}\)? Yet again there's a simple answer using concepts you've learned here.

**Puzzle 135.** For any category \(\mathcal{C}\), classify all functors \(F : \mathcal{C} \to \mathbf{1} \).

**Puzzle 136.** For any natural number \(n\), we can define a category \(\mathbf{n}\) generalizing the categories \(\mathbf{1},\mathbf{2}\) and \(\mathbf{3}\) above: it's the free category on a graph with nodes \(v_1, \dots, v_n\) and edges \(f_i : v_i \to v_{i+1}\) where \(1 \le i < n\). How many functors are there from \(\mathbf{m}\) to \(\mathbf{n}\)?

**Puzzle 137.** How many natural transformations are there between all the functors from \(\mathbf{m}\) to \(\mathbf{n}\)?

I think Puzzle 137 is the hardest; here are two easy ones to help you recover:

**Puzzle 138.** For any category \(\mathcal{C}\), classify all functors \(F : \mathbf{0} \to \mathcal{C}\).

**Puzzle 139.** For any category \(\mathcal{C}\), classify all functors \(F : \mathcal{C} \to \mathbf{0} \).

Feasibility relations work between preorders, but for simplicity suppose we have two posets \(X\) and \(Y\). We can draw them using Hasse diagrams:

Here an arrow means that one element is less than or equal to another: for example, the arrow \(S \to W\) means that \(S \le W\). But we don't bother to draw all possible inequalities as arrows, just the bare minimum. For example, obviously \(S \le S\) by reflexivity, but we don't bother to draw arrows from each element to itself. Also \(S \le N\) follows from \(S \le E\) and \(E \le N\) by transitivity, but we don't bother to draw arrows that follow from others using transitivity. This reduces clutter.

(Usually in a Hasse diagram we draw bigger elements near the top, but notice that \(e \in Y\) is not bigger than the other elements of \(Y\). In fact it's neither \(\ge\) or \(\le\) any other elements of \(Y\) - it's just floating in space all by itself. That's perfectly allowed in a poset.)

Now, we saw that a **feasibility relation** from \(X\) to \(Y\) is a special sort of relation from \(X\) to \(Y\). We can think of a relation from \(X\) to \(Y\) as a function \(\Phi\) for which \(\Phi(x,y)\) is either \(\text{true}\) or \(\text{false}\) for each pair of elements \( x \in X, y \in Y\). Then a **feasibility relation** is a relation such that:

If \(\Phi(x,y) = \text{true}\) and \(x' \le x\) then \(\Phi(x',y) = \text{true}\).

If \(\Phi(x,y) = \text{true}\) and \(y \le y'\) then \(\Phi(x,y') = \text{true}\).

Fong and Spivak have a cute trick for drawing feasibility relations: when they draw a blue dashed arrow from \(x \in X\) to \(y \in Y\) it means \(\Phi(x,y) = \text{true}\). But again, they leave out blue dashed arrows that would follow from rules 1 and 2, to reduce clutter!

Let's do an example:

So, we see \(\Phi(E,b) = \text{true}\). But we can use the two rules to draw further conclusions from this:

Since \(\Phi(E,b) = \text{true}\) and \(S \le E\) then \(\Phi(S,b) = \text{true}\), by rule 1.

Since \(\Phi(S,b) = \text{true}\) and \(b \le d\) then \(\Phi(S,d) = \text{true}\), by rule 2.

and so on.

**Puzzle 171.** Is \(\Phi(E,c) = \text{true}\) ?

**Puzzle 172.** Is \(\Phi(E,e) = \text{true}\)?

I hope you get the idea! We can think of the arrows in our Hasse diagrams as *one-way streets* going between cities in two countries, \(X\) and \(Y\). And we can think of the blue dashed arrows as *one-way plane flights* from cities in \(X\) to cities in \(Y\). Then \(\Phi(x,y) = \text{true}\) if we can get from \(x \in X\) to \(y \in Y\) *using any combination of streets and plane flights!*

That's one reason \(\Phi\) is called a feasibility relation.

What's cool is that rules 1 and 2 can also be expressed by saying

[ \Phi : X^{\text{op}} \times Y \to \mathbf{Bool} ]

is a monotone function. And it's especially cool that we need the '\(\text{op}\)' over the \(X\). Make sure you understand that: the \(\text{op}\) over the \(X\) but not the \(Y\) is why we can drive *to* an airport in \(X\), then take a plane, then drive *from* an airport in \(Y\).

Here are some ways to lots of feasibility relations. Suppose \(X\) and \(Y\) are preorders.

**Puzzle 173.** Suppose \(f : X \to Y \) is a monotone function from \(X\) to \(Y\). Prove that there is a feasibility relation \(\Phi\) from \(X\) to \(Y\) given by

[ \Phi(x,y) \text{ if and only if } f(x) \le y .]

**Puzzle 174.** Suppose \(g: Y \to X \) is a monotone function from \(Y\) to \(X\). Prove that there is a feasibility relation \(\Psi\) from \(X\) to \(Y\) given by

[ \Psi(x,y) \text{ if and only if } x \le g(y) .]

**Puzzle 175.** Suppose \(f : X \to Y\) and \(g : Y \to X\) are monotone functions, and use them to build feasibility relations \(\Phi\) and \(\Psi\) as in the previous two puzzles. When is

[ \Phi = \Psi ? ]

]]>[ ax^5 + bx^4 + cx^3 + dx^2 + ex + f = 0. ]

He used a trick for converting one view of a problem into another, and then converting the other view back into the original one. By now, we've extracted the essence of this trick and dubbed it a "Galois connection". It's far more general than Galois dreamed.

Remember, a **preorder** is a set \(A\) with a relation \(\le_A\) that's reflexive and transitive. When we're in the mood for being careful, we write a preorder as a pair \( (A,\le_A)\). When we're feeling lazy we'll just call it something like \(A\), and just write \(\le\) for the relation.

**Definition.** Given preorders \((A,\le_A)\) and \((B,\le_B)\), a **monotone function** from \(A\) to \(B\) is a function \(f : A \to B\) such that

[ x \le_A y \textrm{ implies } f(x) \le_B f(y) ]

for all elements \(x,y \in A\),

**Puzzle 10.** There are many examples of monotone maps between preorders. List a few interesting ones!

**Definition.** Given preorders \((A,\le_A)\) and \((B,\le_B)\), a **Galois connection** is a monotone function \(f : A \to B\) together with a monotone function \(g: B \to A\) such that

[ f(a) \le_B b \textrm{ if and only if } a \le_A g(b) ]

for all \(a \in A, b \in B\). In this situation we call \(f\) the **left adjoint** and \(g\) the **right adjoint**.

So, the right adjoint of \(f\) is a way of going back from \(B\) to \(A\) that's related to \(f\) in some way.

**Puzzle 11.** Show that if the monotone function \(f: A \to B\) has an inverse \(g : B \to A \) that is also a monotone function, then \(g\) is *both a right adjoint and a left adjoint* of \(f\).

So, adjoints are some sort of generalization of inverses. But as you'll eventually see, they're much more exciting!

I will spend quite a few lectures describing really interesting examples, and you'll start seeing what Galois connections are good for. It shouldn't be obvious yet, unless you already happen to know or you're some sort of superhuman genius. I just want to get the definition on the table right away.

Here's one easy example to get you started. Let \(\mathbb{N}\) be the set of natural numbers with its usual notion of \(\le\). There's a function \(f : \mathbb{N} \to \mathbb{N}\) with \(f(x) = 2x \). This function doesn't have an inverse. But:

**Puzzle 12.** Find a right adjoint for \(f\): that is, a function \(g : \mathbb{N} \to \mathbb{N}\) with

[ f(m) \le n \textrm{ if and only if } m \le g(n) ]

for all \(m,n \in \mathbb{N}\). How many right adjoints can you find?

**Puzzle 13.** Find a left adjoint for \(f\): that is, a function \(g : \mathbb{N} \to \mathbb{N}\) with

[ g(m) \le n \textrm{ if and only if } m \le f(n) ]

for all \(m,n \in \mathbb{N}\). How many left adjoints can you find?

]]>**Adjoint functors**. We've focused a lot on the simplest of categories: preorders. Pairs of adjoint functors between these are also called Galois connections, and we first met them in Lecture 4. In Lecture 6 we saw that a*left*adjoint is a 'best approximation from above' to the possibly nonexistent inverse of a monotone function between preorders, while a*right*adjoint is a 'best approximation from below'. Much later, starting in Lecture 47, we looked at adjoint functors between categories in general. We saw that the pattern persists: left adjoints are 'liberal' while right adjoints are 'conservative'.**Compact closed categories.**In Lecture 67, in our study of feasibility relations, we began looking at caps and cups. We saw these allow us to describe feedback, or, more generally, the process of 'bending back' an input to some process and turning it into an output - or vice versa. In Lecture 71 we saw that caps and cups exist - and obey the all-important snake equations - in any category of enriched profunctors. And in Lecture 74, we saw this works in any 'compact closed' category. Morphisms in a compact closed category can be drawn as string diagrams, which we can manipulate just like boxes with wires coming in and out! In particular, we can 'bend back' the wires.

These are both great ideas... but amazingly, they are *two aspects of the same idea!*

To see this, start with a pair of adjoint functors:

[ F \colon \mathcal{A} \to \mathcal{B}, \quad G \colon \mathcal{B} \to \mathcal{A} ]

By definition, there's a bijection between these sets:

[ \alpha_{a,b} \colon \mathcal{B}(F(a),b) \to \mathcal{A}(a,G(b)) ]

for any objects \(a\) in \(\mathcal{A}\) and \(b\) in \(\mathcal{B}\). Moreover this is a natural isomorphism.

What can we do with this? Not much until we know some elements of these sets! So let's take \(b = F(a)\):

[ \alpha_{a,F(a)} : \mathcal{B}(F(a),F(a)) \to \mathcal{A}(a,G(F(a))) ]

There's an obvious element of \(\mathcal{B}(F(a),F(a))\), namely the identity \(1_{F(a)}\). Our bijection maps this to some morphism from \(a\) to \(G(F(a))\), which we write as

[ \eta_a \colon a \to G(F(a)) .]

You get such a morphism for any \(a\). And using the fact that \(\alpha\) is *natural*, you can prove these morphisms define a natural transformation

[ \eta \colon 1_{\mathcal{A}} \to G F ]

This is called the **unit**. (I'm sorry; that word that is used for too many different things in mathematics.)

Amazingly, *the unit is a lot like a cap.* Why? Remember that when we have an object \(x\) in a compact closed category, the cap is a morphism

[ \cap_x \colon I \to x \otimes x^\ast.]

This resembles the unit, with \(x\) playing the role of \(G\), and \(x^\ast\) playing the role of \(F\). The surprise is that this resemblance is significant, not just superficial!

What about the cup? Well, we can take our bijection

[ \alpha_{a,b} : \mathcal{B}(F(a),b) \to \mathcal{A}(a,G(b)) ]

and let \(a = G(b)\), getting

[ \alpha_{G(b),b} : \mathcal{B}(F(G(b)),b) \to \mathcal{A}(G(b),G(b)) .]

There's an obvious element of \( \mathcal{A}(G(b),G(b))\), namely the identity \(1_{G(b)}\). It must come from some morphism from \(F(G(b))\) to \(b\), which we write as

[ \epsilon_b \colon F(G(b)) \to b, ]

and you can prove such morphisms define a natural transformation

[ \epsilon \colon F G \Rightarrow 1_{\mathcal{B}} ]

called the **counit**. This should remind you of how any object \(x\) in a compact closed category has a cup:

[ \cup_x \colon x^\ast \otimes x \to I .]

So far our evidence for an analogy between the unit and counit and the cap and cup is pretty thin. The real test is the snake equation. If we can prove the unit and counit obey that, something real must be going on!

We can do it. Of course, first we need to *state* the snake equation for the unit and counit. I don't have room to do this here, so watch these short videos by my friends Eugenia Cheng and Simon Willerton:

- The Catsters, Adjunctions 1, Adjunctions 2, Adjunctions 3, Adjunctions 4.

where they call the snake equations the 'triangle equations' - you'll see why. They *start* by defining an 'adjunction' to be a pair of functors \( F \colon \mathcal{A} \to \mathcal{B}\), \( G \colon \mathcal{B} \to \mathcal{A} \) equipped with a unit and counit \(\eta \colon 1_{\mathcal{A}} \to GF \), \( \epsilon \colon FG \to 1_{\mathcal{B}}\) obeying the triangle equations. Then they show this definition is equivalent to the definition of adjoint functors we've been using!

The success of this analogy suggests that maybe we could use string diagrams to work with categories, functors and natural transformations. It's true! To learn how, watch these:

- The Catsters, String diagrams 1, String diagrams 2, String diagrams 3, String diagrams 4.

After setting up string diagrams for category theory, Simon describes adjunctions using string diagrams in part 3. You'll see exactly why the unit is like a cap and the counit like a cup - and you'll see the snake equations pop out at the end! In parts 4 and 5 he uses string diagrams to get *monads* from adjunctions. Monads are very popular in programming languages like Haskell, but this will give a completely different outlook on them.

I should warn you: all this is a *different* idea than using string diagrams to study enriched categories and enriched profunctors, as we'd been doing in Chapter 4. So don't get them mixed up. But everything fits together in the end - as you've probably seen, category theory keeps generalizing everything in order to unify it and eventually simplify it.

There's much more to say; you can see my own take on it by reading this:

- John Baez, The tale of
*n*-categories

You'll see how adjunctions and monads and compact closed categories all fit nicely into the framework of *2-categories*. Just as you need categories to work efficiently with set-based mathematics, you need 2-categories to work efficiently with category-based mathematics. These days my students and I have been using 2-categories (and related gadgets like double categories) to study Markov processes, Petri nets and other kinds of networks.

I'm tempted to go on, but this course was meant to give you just a tiny taste of the grand meal of category theory and its many applications, so I will restrain myself and stop here. I've been getting very abstract, but next time I'll give you some suggestions to read more about applications.

]]>We started by returning to a major theme of Chapter 2: enriched categories. We saw that enriched functors between these were just a special case of something more flexible: enriched profunctors. We saw some concrete applications of these, but also their important theoretical role.

Simply put: moving from functors to profunctors is completely analogous to moving from functions to *matrices!* Thus, introducing profunctors gives category theory some of the advantages of *linear algebra*.

Recall: a function between sets

[ f \colon X \to Y ]

can be seen as a special kind of \(X \times Y\)-shaped matrix

[ \phi \colon X \times Y \to \mathbb{R} ]

namely one where the matrix entry \(\phi(x,y) \) is \(1\) if \(y = f(x)\), and \(0\) otherwise. In short:

[ \phi(x,y) = \delta_{f(x), y} ]

where \(\delta\) is the Kronecker delta. Composing functions then turns out to be a special case of multiplying matrices. Here I'm using \(\mathbb{R}\) because most of you have seen matrices of real numbers, but we could equally well use \(\mathbf{Bool} = \lbrace \texttt{true}, \texttt{false} \rbrace \), and get matrices of truth values, which are just *relations*. Matrix multiplication has the usual composition of relations as a special case!

Similarly, a \(\mathcal{V}\)-enriched functor

[ F \colon \mathcal{X} \to \mathcal{Y} ]

can be seen a special kind of \(\mathcal{V}\)-enriched profunctor

[ \Phi \colon \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} ]

namely the 'companion' of \(F\), given by

[ \Phi(x,y) = \mathcal{V}(F(x), y) .]

This is a fancier relative of the Kronecker delta! For matrices of booleans \( \delta_{f(x), y} = \texttt{true}\) iff \(f(x) = y\), but \( \mathcal{V}(F(x), y) = \texttt{true}\) iff \(f(x) \le y \).

The analogy is completed by this fact: the formula for composing enriched profunctors is really just matrix multiplication written with less familiar symbols:

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z). ]

Here \(\bigvee\) plays the role of a sum and \(\otimes\) plays the role of multiplication.

To clarify this analogy, we studied the category \(\mathbf{Prof}_\mathcal{V}\) with

- \(\mathcal{V}\)-enriched categories as objects

and

- \(\mathcal{V}\)-enriched profunctors as morphisms.

We saw that it was a compact closed category. This means that you can work with morphisms in this category using string diagrams, and you can bend the strings around using caps and cups. In short, \(\mathcal{V}\)-enriched profunctors are like circuits made of components connected by flexible pieces of wire, which we can stick together to form larger circuits.

And while you may not have learned it in your linear algebra class, this 'flexibility' is exactly one of the advantages of linear algebra! For any field \(k\) (for example the real numbers \(\mathbb{R}\)) there is a category \(\mathbf{FinVect}_k\) with

- finite-dimensional vector spaces over \(k\) as objects

and

- linear maps as morphisms.

This category is actually equivalent to the category with finite sets as objects and \(k\)-valued matrices as morphisms, where we compose matrices by matrix multiplication. And like \(\mathbf{Prof}_\mathcal{V}\), the category \(\mathbf{FinVect}_k\) is compact closed, as I mentioned last time. So, while a *function between sets* has a rigidly defined 'input' and 'output' (i.e. domain and codomain), a *linear map between finite-dimensional vector spaces* can be 'bent' or 'turned around' in various ways - as you may have first seen when you learned about the transpose of a matrix.

There's one other piece of this story whose full significance I haven't quite explained yet.

We've seen pairs of adjoint functors, and we've seen 'duals' in compact closed categories. In fact they're closely related! There is a general concept of adjunction that has both of these as special cases! And adjunctions give something all you functional programmers have probably been wishing I'd talk about all along: monads. So I'll try to explain this next time.

]]>I'll start without feedback. I seem to like examples from business and economics for these purposes:

This describes someone who buys bread and then sells it, perhaps at a higher price. This is described by the composite of two feasibility relations:

[ \mathrm{Purchase} \colon \mathbb{N} \nrightarrow \mathbb{N} ]

and

[ \mathrm{Sell} \colon \mathbb{N} \nrightarrow \mathbb{N} ]

where \(\mathbb{N}\) is the set of natural numbers given its usual ordering \(\le\).

Be careful about which way these feasibility relations go:

\( \mathrm{Purchase}(j,k) = \texttt{true}\) if you can purchase \(j\) loaves of bread for \(k\) dollars.

\( \mathrm{Sell}(i,j) = \texttt{true} \) if you can make \(i\) dollars selling \(j\) loaves of bread.

The variable at right is the 'resource', while the variable at left describes what you can obtain using this resource. For example, in purchasing bread, \( \mathrm{Purchase}(j,k) = \text{true}\) if starting with \(k\) dollars as your 'resource' you can buy \(j\) loaves of bread. This is an arbitrary convention, but it's the one in the book!

When we compose these we get a feasibility relation

[ \mathrm{Purchase} \mathrm{Sell} \colon \mathbb{N} \to \mathbb{N} ]

(and again, there's an annoying arbitrary choice of convention in the order here). We have

- \( (\mathrm{Purchase}\mathrm{Sell})(i,k) = \text{true} \) if you can make \(i\) dollars if you have \(k\) dollars to purchase bread which you then sell.

I haven't said what the feasibility relations \( \mathrm{Purchase}\) and \( \mathrm{Sell}\) actually *are*: they could be all sorts of things. But let's pick something specific, so you can do some computations with them. Let's keep it very simple: let's say you can buy a loaf of bread for \( \$ 2\) and sell it for \( \$ 3\).

**Puzzle 218.** Write down a formula for the feasibility relation \(\mathrm{Purchase}.\)

**Puzzle 219.** Write down a formula for the feasibility relation \(\mathrm{Sell}.\)

**Puzzle 220.** Compute the composite feasibility relation \( \mathrm{Purchase} \mathrm{Sell}\). (Hint: we discussed composing feasibility relations in Lecture 58.)

That was just a warmup. Now let's introduce feedback!

Now you can reinvest some of the money you make to buy more loaves of bread! That creates a 'feedback loop'. Obviously this changes things dramatically: now you can start with a little money and keep making more. But how does the mathematics work now?

First, you'll notice this feedback loop has a cap at left and a cup at right. I defined these last time.

But this feedback loop also involves two feasibility relations called \(\hat{\textstyle{\sum}}\) and \(\check{\textstyle{\sum}}\). We use the one at left,

[ \hat{\textstyle{\sum}} \colon \mathbb{N} \times \mathbb{N} \nrightarrow \mathbb{N} ,]

to say that the money we reinvest (which loops back), plus the money we take as profit (which comes out of the diagram at left), equals the money we make by selling bread.

We use the one at right,

[ \check{\textstyle{\sum}} \colon \mathbb{N} \nrightarrow \mathbb{N} \times \mathbb{N} ,]

to say that the money we have reinvested (which has looped around), plus the new money we put in (which comes into the diagram at right), equals the money we use to purchase bread.

These two feasibility relations are both built from the monotone function

[ \textstyle{\sum} \colon \mathbb{N} \times \mathbb{N} \nrightarrow \mathbb{N} ]

defined in the obvious way:

[ \textstyle{\sum}(m,n) = m + n .]

Remember, we saw in Lecture 65 that any monotone function \(F \colon \mathcal{X} \to \mathcal{Y} \) gives two feasibility relations, its 'companion' \(\hat{F} \colon \mathcal{X} \nrightarrow \mathcal{Y}\) and its 'conjoint' \(\check{F} \colon \mathcal{Y} \nrightarrow \mathcal{X}\).

**Puzzle 221.** Give a formula for the feasibility relation \( \hat{\textstyle{\sum}} \colon \mathbb{N} \times \mathbb{N} \nrightarrow \mathbb{N} \). In other words, say when \(\hat{\textstyle{\sum}}(a,b,c) = \texttt{true}\).

**Puzzle 222.** Give a formula for the feasibility relation \( \check{\textstyle{\sum}} \colon \mathbb{N} \nrightarrow \mathbb{N} \times \mathbb{N} \).

And now finally for the big puzzle that all the others were leading up to:

**Puzzle 223.** Give a formula for the feasibility relation described by this co-design diagram:

You can guess the answer, and then you can work it systematically by composing and tensoring the feasibility relations defined by the boxes, the cap and the cup! This is a good way to make sure you understand everything I've been talking about lately.

]]>We've already seen caps and cups for feasibility relations in Lecture 68. We can just generalize what we did.

As usual, let's assume \(\mathcal{V}\) is a commutative quantale, so we get a category \(\mathbf{Prof}_\mathcal{V}\) where:

- objects are \(\mathcal{V}\)-enriched categories

and

- morphisms are \(\mathcal{V}\)-enriched profunctors.

To keep my hands from getting tired, from now on in this lecture I'll simply write 'enriched' when I mean '\(\mathcal{V}\)-enriched'.

Let \(\mathcal{X}\) be an enriched category. Then there's an enriched profunctor called the **cup**

[ \cup_{\mathcal{X}} \colon \mathcal{X}^{\text{op}} \otimes \mathcal{X} \nrightarrow \textbf{1} ]

drawn as follows:

To define it, remember that enriched profunctors \(\mathcal{X}^{\text{op}} \otimes \mathcal{X} \nrightarrow \textbf{1}\) are really just enriched functors \( (\mathcal{X}^{\text{op}} \otimes \mathcal{X})^\text{op} \otimes \textbf{1} \to \mathcal{V} \). Also, remember that \(\mathcal{X}\) comes with a **hom-functor**, which is the enriched functor

[ \mathrm{hom} \colon \mathcal{X}^{\text{op}} \otimes \mathcal{X} \to \mathcal{V} ]

sending any object \( (x,x') \) to \( \mathcal{X}(x,x')\). So, we define \(\cup_\mathcal{X}\) to be the composite

[ (\mathcal{X}^{\text{op}} \otimes \mathcal{X})^\text{op} \otimes \textbf{1} \stackrel{\sim}{\to} (\mathcal{X}^{\text{op}} \otimes \mathcal{X})^\text{op} \stackrel{\sim}{\to} (\mathcal{X}^{\text{op}})^\text{op} \otimes \mathcal{X}^{\text{op}} \stackrel{\sim}{\to} \mathcal{X} \otimes \mathcal{X}^{\text{op}} \stackrel{\sim}{\to} \mathcal{X}^{\text{op}} \otimes \mathcal{X} \stackrel{\text{hom}}{\to} \mathcal{V} ]

where the arrows with squiggles over them are isomorphisms, most of which I explained last time.

There's also an enriched profunctor called the **cap**

[ \cap_\mathcal{X} \colon \textbf{1} \nrightarrow \mathcal{X} \otimes \mathcal{X}^{\text{op}} ]

drawn like this:

To define this, remember that enriched profunctors \(\textbf{1} \nrightarrow \mathcal{X} \otimes \mathcal{X}^{\text{op}} \) are enriched profunctors \(\textbf{1}^{\text{op}} \otimes (\mathcal{X} \otimes \mathcal{X}^{\text{op}}) \). But \(\textbf{1}^{\text{op}} = \textbf{1}\), so we define the cap to be the composite

[ \textbf{1}^{\text{op}} \otimes (\mathcal{X} \otimes \mathcal{X}^{\text{op}}) = \textbf{1}\otimes (\mathcal{X} \otimes \mathcal{X}^{\text{op}}) \stackrel{\sim}{\to} \mathcal{X} \otimes \mathcal{X}^{\text{op}} \stackrel{\sim}{\to} \mathcal{X}^{\text{op}} \otimes \mathcal{X} \stackrel{\text{hom}}{\to} \mathcal{V} . ]

As we've already seen for feasibility relations, the cap and cup obey the **snake equations**, also known as **zig-zag equations** or **yanking equations**. (Everyone likes making up their own poetic names for these equations.) The first snake equation says

In other words, the composite

is the identity, where the arrows with squiggles over them are obvious isomorphisms that I described last time. The second snake equation says

In other words, the composite

is the identity.

Last time I sketched how \(\mathbf{Prof}_{\mathcal{V}}\) is a monoidal category, meaning one with a tensor product obeying certain rules. It's also symmetric monoidal, meaning it has isomorphisms

[ \sigma_{\mathcal{X}, \mathcal{Y}} \colon \mathcal{X} \otimes \mathcal{Y} \nrightarrow \mathcal{Y} \otimes \mathcal{X} ]

obeying certain rules. These let us switch the order of objects in a tensor product: in terms of diagrams, it means wires can cross each other! And finally, when every object in a symmetric monoidal category has a cap and cup obeying the snake equations, we say that category is compact closed. I will define all these concepts more carefully soon. For now I just want you to know that

and also that \(\mathbf{Prof}_{\mathcal{V}}\) is an example of a compact closed category. If you're impatient to learn more, try Section 4.4 of the book.

**Puzzle 227.** Prove the snake equations in \(\mathbf{Prof}_{\mathcal{V}}\).

For this, I should state the snake equations more precisely! The first one says this composite:

is the identity, where \(\alpha\) is the associator and \(\lambda, \rho\) are the left and right unitors, defined last time. The second snake equation says this composite:

is the identity.

]]>[ f : X \to \mathbb{R} ]

assigning each resource its price. Often we have

[ f(x) + f(x') = f(x + x') ]

and this makes pricing very simple: to compute the price of a bunch of resources you just add up their prices.

On the other hand, there are sometimes sales where you can buy the first few items of some kind at a discount, but to keep you from buying too many, the price per item goes up when you buy more. In this case we have

[ f(x) + f(x') \le f(x + x') .]

The whole costs more than than sum of its parts!

More commonly are discounts on buying goods in bulk, to encourage you to buy more. For example, "the second gallon of milk is half-price". In this case we have

[ f(x) + f(x') \ge f(x + x') .]

Now the whole costs *less* than the sum of its parts! For more, see:

- Wikipedia, Economies of scale.

Now, last time I showered you with free goods you hadn't asked for: various flavors of "monoidal monotones". These are maps between monoidal preorders that behave in various ways. This was not abstraction for its own sake. Among other things, they can be used to model the three situations I just described. The first situation, where \( f(x) + f(x') = f(x + x')\), happens when \(f\) is "strict monoidal". The second, where \(f(x) + f(x') \le f(x + x')\), happens when \(f\) is "lax monoidal". And the third, where \( f(x) + f(x') \ge f(x + x')\), happens when \(f\) is "oplax monoidal".

But these different flavors also tend to show up when we have Galois connections - that is, monotone functions with adjoints. Last time we looked at the function

[ i : \mathbb{Z} \to \mathbb{R} ]

which sends each integer to itself, *regarded as a real number*. This is strict monoidal monotone with respect to addition. In particular,

[ i(x) + i(x') = i(x + x') .]

This function \(i\) has a right adjoint

[ \lfloor \cdot \rfloor : \mathbb{R} \to \mathbb{Z} , ]

the **floor function**, which is lax monoidal monotone. In particular,

[ \lfloor x \rfloor + \lfloor x' \rfloor \le \lfloor x + x' \rfloor .]

For example, \( \lfloor 0.7 \rfloor + \lfloor 0.4 \rfloor = 0 \) is less than \( \lfloor 0.7 + 0.4 \rfloor = 1 \). On the other hand, \(i\) has a left adjoint

[ \lceil \cdot \rceil : \mathbb{R} \to \mathbb{Z} , ]

the **ceiling function**, which is oplax monoidal monotone. In particular,

[ \lceil x \rceil + \lceil x' \rceil \ge \lceil x + x' \rceil .]

For example, \( \lceil 0.7 \rceil + \lceil 0.2 \rceil = 2 \) is greater than \( \lceil 0.7 + 0.2 \rceil= 1 \).

So, your prices at the grocery store would be lax monoidal if the clerk rounded your bill down to the nearest dollar... but oplax monoidal if the clerk rounded it up!

Is this a coincidence, this relation between right/left adjoints and lax/oplax monoidal monotones? No! In fact there's a very general, beautiful pattern at work here.

In everything that follows, \(X\) and \(Y\) will be monoidal preorders. I'll use the same symbols for \(\le\), \(\otimes\) and \(I\) in both \(X\) and \(Y\). This reduces clutter, and the context makes everything unambiguous. Remember that a monotone map \(f : X \to Y\) is a **strict** monoidal monotone if

[ f(x) \otimes f(x) = f(x \otimes x') \textrm{ and } I = f(I). ]

It's a **lax** monoidal monotone if

[ f(x) \otimes f(x) \le f(x \otimes x') \textrm{ and } I \le f(I), ]

and it's an **oplax** monoidal monotone if

[ f(x) \otimes f(x) \ge f(x \otimes x') \textrm{ and } I \ge f(I). ]

**Theorem.** Suppose \(f : X \to Y\) is a strict monoidal monotone and \(g: Y \to X\) is a right adjoint of \(f\). Then \(g\) is a lax monoidal monotone.

**Proof.** Since \(g\) is a right adjoint of \(f\) it is, by definition, a monotone function. Thus, to show \(g\) is a lax monoidal monotone, we only need to prove a couple of inequalities. The first of these is

[ g(y) \otimes g(y') \le g(y \otimes y') ]

for all \(y,y' \in Y\). Since \(g\) is a right adjoint of \(f\), this is equivalent to

[ f(g(y) \otimes g(y')) \le y \otimes y'. ]

So, let's show this!

Since \(f\) is strict monoidal we have

[ f(g(y) \otimes g(y')) = f(g(y)) \, \otimes \, f(g(y')) .]

Since \(g\) is a right adjoint of \(f\) we have

[ f(g(y)) \le y \textrm{ if and only if } g(y) \le g(y) ]

and the latter is true so indeed we have \(f(g(y)) \le y\), and by the same logic \(f(g(y')) \le y'\). By the monoidal preorder law this implies

[ f(g(y)) \, \otimes \, f(g(y')) \le y \otimes y'. ]

Putting all the pieces together we get

[ f(g(y) \otimes g(y')) \; = \; f(g(y)) \, \otimes\, f(g(y')) \; \le \; y \otimes y' ]

which is what we needed to show.

The second inequality we need to prove is

[ I \le g(I) .]

Since \(g\) is a right adjoint of \(f\) this is equivalent to \(f(I) \le I\), and since \(f\) is strict monoidal we actually have \(f(I) = I\). So, we're done! \( \qquad \blacksquare \)

This theorem has a partner, whose proof is very similar: just turn around a lot of inequalities!

**Theorem.** Suppose \(g: Y \to X\) is a strict monoidal monotone and \(f: X \to Y\) is a left adjoint of \(g\). Then \(f\) is an oplax monoidal monotone.

But even better, both these theorems are special cases of a beautifully symmetrical super-theorem, which is proved in basically the same way!

**Theorem.** Suppose the monotone function \(f: X \to Y\) is a left adjoint to the monotone function \(g: Y \to X\). Then \(f\) is an oplax monoidal if and only if \(g\) is a lax monoidal.

You can see that this implies the other two results, because a strict monoidal monotone is both lax and oplax. (In fact, a bit more generally, any monotone function that's both lax and oplax monoidal is called a **strong** monoidal monotone. So, in our first two theorems today, we could have replaced the word "strict" by "strong", and they'd still be true.)

**Puzzle 83.** Prove the super-theorem, preferably without "cheating" and looking at the proof of the earlier one. The trick, as so often in math, is simply to write down the facts you're given, and also the facts you want to prove, and play around with the former until you get the latter.

[ \Phi \colon a \to c \otimes d ] [ \Psi \colon d \otimes b \to e \otimes f ] [ \Theta \colon c \otimes e \to g ]

then by a combination of composing and tensoring we can cook up a morphism like this:

which goes from \(a \otimes b\) to \(g \otimes f\). This sort of picture is called a **string diagram**, and we've seen plenty of them already.

We don't *need* to use string diagrams to work with monoidal categories:

**Puzzle 281.** Describe the morphism in the above string diagram using a more traditional formula involving composition \(\circ\), tensoring \(\otimes\), the associator \(\alpha\), and the left and right unitors \(\lambda\) and \(\rho\).

However, they make it a lot easier and more intuitive!

An interesting feature of string diagrams is that they hide the the associator and the left and right unitors. You can't easily see them in these diagrams! However, when you turn a string diagram into a more traditional formula as in Puzzle 281, you'll see that you need to include associators and unitors to get a formula that makes sense.

This may seems strange: if we need the associators and unitors in our formulas, why don't we need them in our diagrams?

The ultimate answer is 'Mac Lane's strictification theorem'. This says that every monoidal category is equivalent to a one where the associator and unitors are *identity* morphisms. So, we can take any monoidal category and replace it by an equivalent one where the tensor product is 'strictly' associative, not just up to isomorphism:

[ (x \otimes y) \otimes z = x \otimes (y \otimes z) ]

and similarly, the left and right unit laws hold strictly:

[ I \otimes x = x = x \otimes I ]

This lets us stop worrying about associators and unitors. String diagrams are secretly doing this for us!

Often people use Mac Lane's strictification theorem in a loose way, simply using it as an excuse to act like monoidal categories are all strict. That's actually not so bad, if you're not too obsessed with precisoin.

To state Mac Lane's strictification theorem precisely, we first need to say exactly what it means for two monoidal categories to be 'equivalent'. For this we need to define a 'monoidal equivalence' between monoidal categories. Then, we define a **strict** monoidal category to be one where the associator and unitors are identity morphisms. Mac Lane's theorem then says that every monoidal category is monoidally equivalent to a strict one.

If you're curious about the details, try my notes:

All the necessary terms are defined, leading up to a precise statement of Mac Lane's strictification theorem at the very end. But this theorem takes quite a lot of work to prove, and I don't do that! You can see a sketch of the proof here:

- John Armstrong, The "strictification" theorem.

But there's more! If all we have is a monoidal category, the strings in our diagrams aren't allowed to cross. But last time I mentioned symmetric monoidal categories, where we have a natural isomorphism called the **symmetry**

[ \sigma_{x,y} \colon x \otimes y \to y \otimes x ]

that allows us to switch objects, obeying various rules. This lets us make sense of string diagrams where wires cross, like this:

**Puzzle 282.** Describe the morphism in the above string diagram with a formula involving composition \(\circ\), tensoring \(\otimes\), the associator \(\alpha\), the left and right unitors \(\lambda,\rho\), and the symmetry \(\sigma\).

There is a version of Mac Lane's strictification theorem for symmetric monoidal categories, too! You can find it stated in my notes. This lets us replace any symmetric monoidal category by a **strict** one, where the associator and unitors *but not the symmetry* are identity morphisms.

We really need the symmetry: it cannot in general be swept under the rug. That should be sort of obvious: for example, switching two numbers in an ordered pair really *does* something, we can't just say it's the identity.

Again, please ask questions! I'm sketching some ideas that would take considerably longer to explain in full detail.

]]>Last time we saw that for each preorder \(X\) there's a feasibility relation called the **cup**

[ \cup_X \colon X^{\text{op}} \times X \nrightarrow \textbf{1} ]

which we draw as follows:

To define the cup, we remembered that feasibility relations \(X^{\text{op}} \times X \nrightarrow \textbf{1}\) are monotone functions \( (X^{\text{op}} \times X)^\text{op} \times \textbf{1} \to \mathbf{Bool} \), and we defined \(\cup_X\) to be the composite

[ (X^{\text{op}} \times X)^\text{op} \times \textbf{1} \stackrel{\sim}{\to} (X^{\text{op}} \times X)^\text{op} \stackrel{\sim}{\to} (X^{\text{op}})^\text{op} \times X^{\text{op}} \stackrel{\sim}{\to} X \times X^{\text{op}} \stackrel{\sim}{\to} X^{\text{op}} \times X \stackrel{\text{hom}}{\to} \textbf{Bool} ]

where all the arrows with little squiggles over them are isomorphisms - most of them discussed in Puzzles 213-215. In short, the cup is the hom-functor \(\text{hom} \colon X^{\text{op}} \times X \to \mathbf{Bool}\) in disguise!

The cup's partner is called the **cap**

[ \cap_X \colon \textbf{1} \nrightarrow X \times X^{\text{op}} ]

and we draw it like this:

The cap is also the hom-functor in disguise! To define it, remember that feasibility relations \(\textbf{1} \nrightarrow X \times X^{\text{op}} \) are monotone functions \(\textbf{1}^{\text{op}} \times (X \times X^{\text{op}}) \). But \(\textbf{1}^{\text{op}} = \textbf{1}\), so we define the cap to be the compoiste

[ \textbf{1}^{\text{op}} \times (X \times X^{\text{op}}) = \textbf{1}\times (X \times X^{\text{op}}) \stackrel{\sim}{\to} X \times X^{\text{op}} \stackrel{\sim}{\to} X^{\text{op}} \times X \stackrel{\text{hom}}{\to} \textbf{Bool} . ]

One great thing about the cup and cap is that they let us treat the edges in our co-design diagrams as flexible wires. In particular, they obey the **snake equations**, also known as the **zig-zag identities**. These say that we can pull taut a zig-zag of wire.

The first snake equation says

In other words,

[ (1_X \times \cup_X) (\cap_X \times 1_X) = 1_X .]

Please study the diagram and the corresponding equation very carefully to make sure you see how each part of one corresponds to a part of the other! And please ask questions if there's anything puzzling. It takes a while to get used to these things.

The second snake equation says

In other words,

[ (\cup_X \times 1_{X^{\text{op}}}) (1_{X^{\text{op}}} \times \cap_X) = 1_{X^{\text{op}}} .]

A great exercise, to make sure you understand what's going on, is to prove the snake equations. You just need to remember all the definition, use them to compute the left-hand side of the identity, and show it equals the much simpler right-hand side.

**Puzzle 217.** Prove the snake equations.

In fact some of you have already started doing this!

]]>We've seen that these parts can be stuck together in series, by 'composition':

and in parallel, using 'tensoring':

One reason I wanted to show you this is for you to practice reasoning with diagrams in situations where you can both compose and tensor morphisms. Examples include:

functions between sets

linear maps between vector spaces

electrical circuits

PERT charts

the example we spent a lot of time on: feasibility relations

or more generally, \(\mathcal{V}\)-enriched profunctors.

The kind of structure where you can compose and tensor morphisms is called a 'monoidal category'. This is a category \(\mathcal{C}\) together with:

a functor \(\otimes \colon \mathcal{C} \times \mathcal{C} \to \mathcal{C} \) called

**tensoring**,an object \(I \in \mathcal{C}\) called the

**unit**for tensoring,a natural isomorphism called the

**associator**

[ \alpha_{X,Y,Z} \colon (X \otimes Y) \otimes Z \stackrel{\sim}{\longrightarrow} X \otimes (Y \otimes Z) ]

- a natural isomorphism called the
**left unitor**

[ \lambda_X \colon I \otimes X \stackrel{\sim}{\longrightarrow} X ]

- and a natural isomorphism called the
**right unitor**

[ \rho_x \colon X \otimes I \stackrel{\sim}{\longrightarrow} X ]

- such that the associator and unitors obey enough equations so that all diagrams built using tensoring and these isomorphisms commute.

We need the associator and unitors because in examples it's usually *not* true that \( (X \otimes Y) \otimes Z\) is *equal* to \(X \otimes (Y \otimes Z)\), etc. They're just isomorphic! But we want the associator and unitors to obey equations because they're just doing boring stuff like moving parentheses around, and if we use them in two different ways to go from, say,

[ ((W \otimes X) \otimes Y) \otimes Z) ]

to

[ W \otimes (X \otimes (Y \otimes Z)) ]

we want those two ways to agree! Otherwise life would be too confusing.

If you want to see exactly what equations the associator and unitors should obey, read this:

- John Baez, Some definitions everyone should know.

But beware: these equations, discovered by Mac Lane in 1963, are a bit scary at first! They say that certain diagrams built using tensoring, the associator and unitors commute, and the point is that Mac Lane proved a theorem saying these are enough to imply that *all* diagrams of this sort commute.

This result called 'Mac Lane's coherence theorem'. It's rather subtle; if you're curious about the details try this:

- Peter Hines, Reconsidering MacLane:the foundations of categorical coherence, October 2013.

Note: monoidal categories may not necessarily have a natural isomorphism

[ \beta_{X,Y} \colon X \otimes Y \stackrel{\sim}{\longrightarrow} Y \otimes X .]

When we have that, obeying some more equations, we have a 'braided monoidal category'. You can see the details in my notes. And when our braided monoidal category has the feature that braiding twice:

[ X\otimes Y \stackrel{\beta_{X,Y}}{\longrightarrow } Y \otimes X \stackrel{\beta_{Y,X}}{\longrightarrow } X \otimes Y ]

is the identity, we have a 'symmetric monoidal category'. In this case we call the braiding a **symmetry** and often write it as

[ \sigma_{X,Y} \colon X \otimes Y \stackrel{\sim}{\longrightarrow} Y \otimes X ]

since the letter \(\sigma\) should make you think 'symmetry'.

All the examples of monoidal categories I listed are actually symmetric monoidal - *unless* you think of circuit diagrams as having wires in 3d space that can actually get tangled up with each other, in which case they are morphisms in a braided monoidal category.

**Puzzle 278.** Use the definition of monoidal category to prove the **interchange law**

[ (f \otimes g) (f' \otimes g') = ff' \otimes gg' ]

whenever \(f,g,f',g'\) are morphsms making either side of the equation well-defined. (Hint: you only need the part of the definition I explained in my lecture, not the scary diagrams I didn't show you.)

**Puzzle 279.** Draw a picture illustrating this equation.

**Puzzle 280.** Suppose \(f : I \to I\) and \(g : I \to I\) are morphisms in a monoidal category going from the unit object to itself. Show that

[ fg = gf .]

]]>Left adjoints preserve joins, and monotone functions that preserve enough joins are left adjoints.

Right adjoints preserve meets, and monotone functions that preserve enough meets are right adjoints.

Today we'll conclude our discussion of Chapter 1 with two more bombshells:

Joins

*are*left adjoints, and meets*are*right adjoints.Left adjoints are right adjoints seen upside-down, and joins are meets seen upside-down.

This is a good example of how category theory works. You learn a bunch of concepts, but then you learn more and more facts relating them, which unify your understanding... until finally all these concepts collapse down like the core of a giant star, releasing a supernova of insight that transforms how you see the world!

Let me start by reviewing what we've already seen. To keep things simple let me state these facts just for posets, not the more general preorders. Everything can be generalized to preorders.

In Lecture 6 we saw that given a left adjoint \( f : A \to B\), we can compute its right adjoint using joins:

[ g(b) = \bigvee \{a \in A : \; f(a) \le b \} . ]

Similarly, given a right adjoint \( g : B \to A \) between posets, we can compute its left adjoint using meets:

[ f(a) = \bigwedge \{b \in B : \; a \le g(b) \} . ]

In Lecture 16 we saw that left adjoints preserve all joins, while right adjoints preserve all meets.

Then came the big surprise: if \( A \) has all joins and a monotone function \( f : A \to B \) preserves all joins, then \( f \) is a left adjoint! But if you examine the proof, you'l see we don't really need \( A \) to have *all* joins: it's enough that all the joins in this formula exist:

[ g(b) = \bigvee \{a \in A : \; f(a) \le b \} . ]

Similarly, if \(B\) has all meets and a monotone function \(g : B \to A \) preserves all meets, then \( f \) is a right adjoint! But again, we don't need \( B \) to have *all* meets: it's enough that all the meets in this formula exist:

[ f(a) = \bigwedge \{b \in B : \; a \le g(b) \} . ]

Now for the first of today's bombshells: joins are left adjoints and meets are right adjoints. I'll state this for binary joins and meets, but it generalizes.

Suppose \(A\) is a poset with all binary joins. Then we get a function

[ \vee : A \times A \to A ]

sending any pair \( (a,a') \in A\) to the join \(a \vee a'\). But we can make \(A \times A\) into a poset as follows:

[ (a,b) \le (a',b') \textrm{ if and only if } a \le a' \textrm{ and } b \le b' .]

Then \( \vee : A \times A \to A\) becomes a monotone map, since you can check that

[ a \le a' \textrm{ and } b \le b' \textrm{ implies } a \vee b \le a' \vee b'. ]

And you can show that \( \vee : A \times A \to A \) is the left adjoint of another monotone function, the **diagonal**

[ \Delta : A \to A \times A ]

sending any \(a \in A\) to the pair \( (a,a) \). This diagonal function is also called **duplication**, since it duplicates any element of \(A\).

Why is \( \vee \) the left adjoint of \( \Delta \)? If you unravel what this means using all the definitions, it amounts to this fact:

[ a \vee a' \le b \textrm{ if and only if } a \le b \textrm{ and } a' \le b . ]

Note that we're applying \( \vee \) to \( (a,a') \) in the expression at left here, and applying \( \Delta \) to \( b \) in the expression at the right. So, this fact says that \( \vee \) the left adjoint of \( \Delta \).

**Puzzle 45.** Prove that \( a \le a' \) and \( b \le b' \) imply \( a \vee b \le a' \vee b' \). Also prove that \( a \vee a' \le b \) if and only if \( a \le b \) and \( a' \le b \).

A similar argument shows that meets are really right adjoints! If \( A \) is a poset with all binary meets, we get a monotone function

[ \wedge : A \times A \to A ]

that's the *right* adjoint of \( \Delta \). This is just a clever way of saying

[ a \le b \textrm{ and } a \le b' \textrm{ if and only if } a \le b \wedge b' ]

which is also easy to check.

**Puzzle 46.** State and prove similar facts for joins and meets of any number of elements in a poset - possibly an infinite number.

All this is very beautiful, but you'll notice that all facts come in pairs: one for left adjoints and one for right adjoints. We can squeeze out this redundancy by noticing that every preorder has an "opposite", where "greater than" and "less than" trade places! It's like a mirror world where up is down, big is small, true is false, and so on.

**Definition.** Given a preorder \( (A , \le) \) there is a preorder called its **opposite**, \( (A, \ge) \). Here we define \( \ge \) by

[ a \ge a' \textrm{ if and only if } a' \le a ]

for all \( a, a' \in A \). We call the opposite preorder\( A^{\textrm{op}} \) for short.

I can't believe I've gone this far without ever mentioning \( \ge \). Now we finally have really good reason.

**Puzzle 47.** Show that the opposite of a preorder really is a preorder, and the opposite of a poset is a poset.

**Puzzle 48.** Show that the opposite of the opposite of \( A \) is \( A \) again.

**Puzzle 49.** Show that the join of any subset of \( A \), if it exists, is the meet of that subset in \( A^{\textrm{op}} \).

**Puzzle 50.** Show that any monotone function \(f : A \to B \) gives a monotone function \( f : A^{\textrm{op}} \to B^{\textrm{op}} \): the same function, but preserving \( \ge \) rather than \( \le \).

**Puzzle 51.** Show that \(f : A \to B \) is the left adjoint of \(g : B \to A \) if and only if \(f : A^{\textrm{op}} \to B^{\textrm{op}} \) is the right adjoint of \( g: B^{\textrm{op}} \to A^{\textrm{ op }}\).

So, we've taken our whole course so far and "folded it in half", reducing every fact about meets to a fact about joins, and every fact about right adjoints to a fact about left adjoints... or vice versa! This idea, so important in category theory, is called **duality**. In its simplest form, it says that things come on opposite pairs, and there's a symmetry that switches these opposite pairs. Taken to its extreme, it says that everything is built out of the interplay between opposite pairs.

Once you start looking you can find duality everywhere, from ancient Chinese philosophy:

to modern computers:

But duality has been studied very deeply in category theory: I'm just skimming the surface here. In particular, we haven't gotten into the connection between adjoints and duality!

This is the end of my lectures on Chapter 1. There's more in this chapter that we didn't cover, so now it's time for us to go through all the exercises.

]]>Last time I showed that left adjoints preserve joins and right adjoints preserve meets - but I only considered "binary" meets and joins: that is, the meets and join of a *pair* of elements. We can do much better.

Remember, given any subset \( S \) of a poset \( A \), we say the **join** of \( S \) is the least upper bound of \( S \), if it exists. We denote this join by \( \bigvee S \), but don't be fooled by the notation into thinking it always exists. Similarly, the **meet** or greatest lower bound of \( S \subseteq A \) is denoted by \( \bigwedge S \) - if it exists.

Now for two theorems. I suggest that you read the statements of both these theorems and ponder them a bit before reading the proofs. The statements are ultimately more important than the proofs, so don't be demoralized if you find the proofs tricky!

**Theorem.** If a monotone function \( f: A \to B \) is a left adjoint, it preserves joins whenever they exist. That is, whenever a set \( S \subseteq A \) has a join we have

[ f (\bigvee S ) = \bigvee \{ f(a) : \; a \in S\} . ]

Similarly, if a monotone function between posets \(g : B \to A \) is a right adjoint, it preserves meets whenever they exist. That is, whenever a set \( S \subseteq B \) has a meet we have

[ g(\bigwedge S) = \bigwedge \{ g(b) : \; b \in S \}. ]

**Proof.** We'll just prove the first half, since the second works the same way. We'll assume \( f: A \to B \) is a left adjoint, meaning that it *has* a right adjoint \( g: B \to A \), and we'll show that \(f\) preserves joins whenever they exist. This is very similar to the proof in Lecture 15, but I'll run through the argument again because it's so important. I'll go a bit faster this time!

Suppose \(S \subseteq A\) has a join \(j = \bigvee S\). This implies that \(a \le j\) for all \( a \in S \), so \(f(a) \le f(j) \), so \( f(j) \) is an upper bound of \( \{ f(a) : \; a \in S\} \). We just need to show it's the *least* upper bound of this set. So, suppose \( b \in B \) is any other upper bound of this set. This means that

[ f(a) \le b ]

for all \(a \in S \), but thanks to the magic of adjoints this gives

[ a \le g(b) ]

for all \(a \in S \) so \( g(b) \) is an upper bound of \( S\). Since \( j \) is the *least* upper bound we conclude

[ j \le g(b) , ]

but thanks to the magic of adjoints this gives

[ f(j) \le b ]

so \( f(j) \) is indeed the *least* upper bound of \( \{ f(a) : \; a \in S\} \). \( \qquad \blacksquare \)

Okay, that was fun. But now comes the really exciting part: a kind of converse is true too! It's easiest to state when we have lots of joins or meets available. We say a poset **has all joins** if every subset has a join, and similarly for meets:

**Adjoint Functor Theorem for Posets.** Suppose \(A\) is a poset that has all joins and \( B \) is any poset. Then a monotone map \(f : A \to B \) is a left adjoint if and only if it preserves all joins.

Similarly, suppose \(B\) is a poset that has all meets and \( A \) is any poset. Then a monotone map \(g : B \to A \) is a right adjoint if and only if it preserves all meets.

**Proof.** Again we'll prove only the first half. So, we'll assume \(A\) is a poset that has all joins, \( B \) is any poset, and \(f : A \to B \) is a monotone map.

The previous theorem assures us that if \( f \) is a left adjoint it preserves all joins, so we only need to prove the converse.

Suppose that \(f\) preserves all joins. To show it's a left adjoint, we construct its right adjoint \( g : B \to A \) using the formula given in Lecture 6:

[ g(b) = \bigvee \{a \in A : \; f(a) \le b \} . ]

Since \(A\) has all joins, \(g(b)\) is well-defined. To see that \(g\) is a monotone, note that if \( b \le b' \) then

[ \{a \in A : \; f(a) \le b \} \subseteq \{a \in A : \; f(a) \le b' \} ]

so

[ g(b) = \bigvee \{a \in A : \; f(a) \le b \} \le \bigvee \{a \in A : \; f(a) \le b' \} = g(b') . ]

See why?

Next we show that \(f\) is the left adjoint of \(g\):

[ f(a_0) \le b_0 \textrm{ if and only if } a_0 \le g(b_0) ]

for all \( a_0 \in A, b_0 \in B \).

To show this, first suppose \( f(a_0) \le b_0 \). Then \( a_0 \) is an element of \( \{ a \in A : f(a) \le b_0 \} \), so

[ a_0 \le \bigvee \{ a \in A : f(a) \le b_0 \} = g(b_0) ]

by the definition of \( g \). So, we have \( a_0 \le g(b_0) \) as desired.

Conversely, suppose \( a_0 \le g(b_0) \). Then \(f(a_0)) \le f(g(b_0)) \), so if we can show \(f(g(b_0)) \le b_0 \) then we'll have \( f(a_0) \le b_0 \). For this, note:

[ f(g(b_0)) = f( \bigvee \{a \in A : \; f(a) \le b_0 \}) = \bigvee \{f(a) \in B : \; f(a) \le b_0 \}) \le b_0 ]

where in the middle step we finally use the fact that \(f\) preserves joins. So, we have \( a_0 \le g(b_0) \) as desired - and we're done! \( \qquad \blacksquare \)

So the connection between joins and left adjoints, or meets and right adjoints, is very strong. Next time, in my last lecture on Chapter 1, I'll explain this a bit more.

]]>**Definition.** Suppose \( (X, \le_X) \) and \( (Y, \le_Y) \) are preorders. Then a **feasibility relation** from \(X\) to \(Y\) is a monotone function

[ \Phi : X^{\text{op}} \times Y \to \mathbf{Bool} .]

If \(\Phi\) is a feasibility relation from \(X\) to \(Y\) we write \( \Phi : X\nrightarrow Y \). If \( \Phi(x,y) = \text{true}\), we say **\(x\) can be obtained given \(y\)**.

The idea is that we use elements of \( X\) to describe 'requirements' - things you want - and elements of \(Y\) to describe 'resources' - things you have. A feasibility relation \( \Phi : X \nrightarrow Y \) says when what you want can be obtained from what you have! And the fact that it's *monotone* makes a lot of sense.

In fact:

**Theorem.** A function \(\Phi : X^{\text{op}} \times Y \to \mathbf{Bool}\) is a feasibility relation if and only if:

If \(\Phi(x,y) = \text{true}\) and \(x' \le_X x\) then \(\Phi(x',y) = \text{true}\).

If \(\Phi(x,y) = \text{true}\) and \(y \le_Y y'\) then \(\Phi(x,y') = \text{true}\).

Translating this into English, we see it makes perfect sense:

If what you want can be obtained from the resources you have, and then you change your mind and want

*less*, you can still obtain what you want.If what you want can be obtained from the resources you have, and then you acquire

*more*resources, you can still obtain what you want.

But let's prove the theorem. This is mainly a nice review of various concepts.

**Proof.** First, remember that \(\textbf{Bool}\) is the preorder with two elements \(\text{true}\) and \(\text{false}\), with

[ \text{false} \le \text{true} . ]

We can read \(\le\) here as 'implies'.

Second, remember that \(X^{\text{op}}\) is the **opposite** of the preorder \(X\), with the definition of \(\le\) turned around:

[ x \le_{X^{\text{op}}} x' \text{ if and only if } x' \le_X x ]

Third, remember that \( X^{\text{op}} \times Y \) is the **product** of the preorders \(X^{\text{op}}\) and \(Y\). So, its elements are pairs \( (x,y) \) with \(x \in X\) and \(y \in Y\), and we define a concept of \(\le\) on these pairs by

[ (x,y) \le (x',y') \text{ if and only if } x' \le_X x \text{ and } y \le_Y y' .]

Note how I said \(x' \le x\). This looks backwards, but it's not one of my usual typos! It works this way because of the \(\text{op}\) in \( X^{\text{op}} \times Y \).

Now we're ready to see exactly what a feasibility relation, that is a monotone function \(\Phi : X^{\text{op}} \times Y \to \mathbf{Bool}\), really is. It's a function that obeys

[ (x,y) \le (x',y') \text{ implies } \Phi(x,y) \le \Phi(x',y') ]

or in other words

[ \text{ if } x' \le_X x \text{ and } y \le_Y y', \text{ then } \Phi(x,y) \text{ implies } \Phi(x',y') ]

Translating this into English to see what this means, it says:

If you can get what you want from the resources you have, and then you change your mind and want

less, and also go out and getmoreresources, then you can still get what you want.

Here "less" really means "less than or equal to", and "more" really means "greater than or equal to" - English is not very good at saying these things quickly! So, the process of wanting less and getting more resources can always be broken into two steps:

wanting less but keeping the resources the same, and then

getting more resources but wanting the same thing.

So, this condition

[ \text{ if } x' \le_X x \text{ and } y \le_Y y', \text{ then } \Phi(x,y) \text{ implies } \Phi(x',y') ]

is equivalent to *the combination of both* these conditions:

If \(x' \le_X x \), then \( \Phi(x,y) \) implies \(\Phi(x',y)\).

If \(y \le y'\), then \( \Phi(x,y) \) implies \( \Phi(x,y')\).

But here's another equivalent way to say these two things:

If \(\Phi(x,y) = \text{true}\) and \(x' \le_X x\) then \(\Phi(x',y) = \text{true}\).

If \(\Phi(x,y) = \text{true}\) and \(y \le_X y'\) then \(\Phi(x,y') = \text{true}\).

Logic! Ain't it great? \( \qquad \blacksquare \)

Next time I'll show you how to draw pictures of feasibility relations, and look at some examples. We've already drawn pictures of preorders, or at least posets: they're called **Hasse diagrams**, and they look like a bunch of dots, one for each element of our poset \(X\), and a bunch of arrows, enough so that \(x \le y\) whenever there's a path of arrows leading from \(x \) to \( y \). So, to draw a feasibility
relation \(\Phi : X \nrightarrow Y\), we'll draw two Hasse diagrams and some extra arrows to say when \( \Phi(x,y) = \text{true}\).

Finally, two puzzles:

**Puzzle 169.** I gave a verbal argument for how we can break up any inequality \( (x,y) \le (x',y') \) in \(X^{\text{op}} \times Y\) into two other inequalities. Can you write this out in a purely mathematical way?

**Puzzle 170.** What if we have a morphism in a product of categories \( \mathcal{C} \times \mathcal{D}\). Can we always write it as a composite of two morphisms, copying the procedure in my verbal argument and Puzzle 169? How does this work?

Here we have three \(\mathbf{Bool}\)-enriched categories \(X,Y,\) and \(Z\), also known as preorders, and feasibility relations between these:

[ \Phi \colon X \nrightarrow Y , ] [ \Psi \colon Y \nrightarrow Z. ]

Remember, these are really monotone functions

[ \Phi: X^{\text{op}} \times Y \to \mathbf{Bool} ,] [ \Psi: Y^{\text{op}} \times Z \to \mathbf{Bool}.]

In the pictures \(\Phi(x,y) = \text{true}\) iff there's a path from \(x\in X\) to \(y \in Y\), and \(\Psi(y,z) = \text{true}\) iff there's a path from \(y \in Y\) to \(z \in Z\).

Their composite

[ \Psi\Phi \colon X \nrightarrow Z ]

is given by

[ (\Psi\Phi)(x,z) = \bigvee_{y \in Y} \Phi(x,y) \wedge \Psi(y,z). ]

Remember, the join \( \bigvee \) in \(\mathbf{Bool}\) means 'there exists', while the meet \(\wedge\) means 'and'. So, this formula says that you can get from \(x \in X\) to \(z \in Z\) iff *there exists* \(y \in Y\) such that you can get from \(x\) to \(y\) *and* from \(y\) to \(z\).

Now let's generalize this, replacing \(\mathbf{Bool}\) with any sufficiently nice poset \(\mathcal{V}\). Last time we saw that if \(\mathcal{V}\) is a closed commutative monoidal poset we can define \(\mathcal{V}\) -enriched profunctors between \(\mathcal{V}\) -enriched categories. But to compose these enriched profunctors, \(\mathcal{V}\) will need to be a bit nicer.

The reason is not hard to see. Suppose we have three \(\mathcal{V}\)-enriched categories \(\mathcal{X},\mathcal{Y}\), and \(\mathcal{Z}\). Suppose we have \(\mathcal{V}\)-enriched profunctors between these:

[ \Phi : \mathcal{X} \nrightarrow \mathcal{Y}, ] [ \Psi : \mathcal{Y} \nrightarrow \mathcal{Z}. ]

Remember, these are really \(\mathcal{V}\)-enriched functors

[ \Phi \colon \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} , ] [ \Psi \colon \mathcal{Y}^{\text{op}} \times \mathcal{Z} \to \mathcal{V} . ]

Let's try to compose them using this formula:

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z). ]

Note I've replaced the meet \(\wedge\), which is the multiplication in our monoidal poset \(\mathbf{Bool}\), by \(\otimes\), which is the name of the multiplication in a general monoidal poset \(\mathcal{V}\). But I'm keeping the join \(\bigvee\).

Why? The reason is that *composing enriched profunctors is like matrix multiplication!* First we 'multiply' the matrix entries \(\Phi(x,y)\) and \(\Psi(y,z)\), then we 'sum' over \(y\). The multiplication in \(\mathcal{V}\) is \(\otimes\), but the sum... well, in general a monoidal poset doesn't have a way to do 'sums', but if it has joins then these act like sums!

So, we'd better assume \(\mathcal{V}\) has all joins. There's a name for this:

**Definition.** A **quantale** is a closed monoidal poset \( \mathcal{V}\) that has all joins: that is, every subset of \( S\subseteq \mathcal{V}\) has a least upper bound \(\bigvee S\).

'Quantale' may sound like a strange word, but we've seen that posets are good for studying logic, and quantales first showed up in the study of quantum logic. In quantum logic we often need *noncommutative* quantales, but for our work now we need the multiplication \(\otimes\) in \(\mathcal{V}\) to be commutative.

So, putting it all together:

**Definition.** If \(\mathcal{V}\) is a commutative quantale and \(\Phi \colon \mathcal{X} \nrightarrow \mathcal{Y}\), \(\Psi\colon \mathcal{Y} \nrightarrow \mathcal{Z}\) are \(\mathcal{V}\)-enriched profunctors, define their **composite** by

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z). ]

Great! But we still need to check that \(\Psi\Phi\) is an enriched profunctor! We've got a well-defined function

[ \Psi\Phi \colon \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} ]

but we need to check that it's a \(\mathcal{V}\)-enriched profunctor. I'll let you give it a try. This cool fact will help:

**Theorem.** If \(\mathcal{V}\) is a monoidal poset with all joins, \(\mathcal{V}\) is a quantale if and only if

[ a \otimes \left( \bigvee_{b\in B} b\right) = \bigvee_{b \in A} (a \otimes b) ]

for every element \(a\) and every subset \(B\) of \(\mathcal{V}\).

**Proof Sketch.** For every element \(a\) of \(\mathcal{V}\) there is a monotone function

[ a \otimes - \, \colon \mathcal{V} \to \mathcal{V} ]

sending each \(x \in \mathcal{V}\) to \(a \otimes x\) . By the Adjoint Functor Theorem for Posets, this monotone function has a right adjoint iff it preserves all joins. It a right adjoint iff \(\mathcal{V}\) is closed, since \(\mathcal{V}\) being closed says that

[ a \otimes x \le y \text{ if and only if } x \le a \multimap y ]

for all \(x, y\) in \(\mathcal{V}\), which means that

[ a \multimap - \, \colon \mathcal{V} \to \mathcal{V} ]

is a right adjoint of

[ a \otimes - \, \colon \mathcal{V} \to \mathcal{V} ]

On the other hand, \(a \otimes -\) preserves all joins iff

[ a \otimes \left( \bigvee_{b\in B} b\right) = \bigvee_{b \in B} (a \otimes b) ]

for every element \(a\) and every subset \(B\) of \(\mathcal{V}\). \( \qquad \blacksquare \)

Now try this puzzle:

**Puzzle 198.** Suppose \(\mathcal{V}\) is a commutative quantale, and suppose \( \Phi \colon \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} \) and \( \Psi \colon \mathcal{Y}^{\text{op}} \times \mathcal{Z} \to \mathcal{V} \) are \(\mathcal{V}\)-enriched functors. Show that \( \Psi\Phi \colon \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} \), defined by

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z),]

is a \(\mathcal{V}\)-enriched functor. This means checking an inequality - you can find the definition of enriched functor in Lecture 32.

Also try these:

**Puzzle 199.** Suppose that \(\mathcal{V}\) is a commutative quantale. Show that composition of \(\mathcal{V}\)-enriched profunctors is associative.

**Puzzle 200.** Suppose that \(\mathcal{V}\) is a commutative quantale and \(\mathcal{X}\) is a \(\mathcal{V}\)-enriched category. The hom-functor

[ \mathrm{hom} \colon \mathcal{X}^{\text{op}} \times \mathcal{X} \to \mathcal{V} ]

described in Puzzle 197 gives an enriched profunctor that we call \(1_{\mathcal{V}} \colon \mathcal{V} \nrightarrow \mathcal{V}\). Show that this serves as an identity for composition of \(\mathcal{V}\)-enriched profunctors: check the left and right unit laws.

You can see what's coming! If you get stuck I'll help you next time. I'll also give more examples of commutative quantales, and say more about them!

]]>**Theorem.** Suppose \(\mathcal{V}\) is a commutative quantale. Then there is a category \(\mathbf{Prof}_\mathcal{V}\) whose objects are \(\mathcal{V}\)-enriched categories and whose morphisms are \(\mathcal{V}\)-enriched profunctors, where the composite of \(\mathcal{V}\)-enriched profunctors \(\Phi \colon \mathcal{X} \nrightarrow \mathcal{Y} \) and \(\Psi \colon \mathcal{Y} \to \mathcal{Z}\) is defined by

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z).]

We'll break the proof into lots of lemmas. In all that follows, \(\mathcal{V}\) is a commutative quantale and \(\mathcal{W}, \mathcal{X}, \mathcal{Y}, \mathcal{Z}\) are \(\mathcal{V}\)-enriched categories. Letters like \(w,w',x,x',y,y',z,z'\) will always stand for objects in the enriched categories with the same letters as their names - and when I write inequalities involving these I mean they're true *for all choices* of these objects, unless I say otherwise.

First we check that the formula above really defines a \(\mathcal{V}\)-enriched profunctor!

**Lemma.** Suppose \(\Phi \colon \mathcal{X} \nrightarrow \mathcal{Y} \) and \(\Psi \colon \mathcal{Y} \to \mathcal{Z}\) are \(\mathcal{V}\)-enriched profunctors. Then the formula

[ (\Psi\Phi)(x,z) = \bigvee_{y} \Phi(x,y) \otimes \Psi(y,z) ]

specifies a \(\mathcal{V}\)-enriched profunctor \(\Psi\Phi \colon \mathcal{X} \to \mathcal{Y}\).

**Proof.** We need to show that

[ \Psi\Phi \colon \mathcal{X}^{\text{op}} \times \mathcal{Z} \to \mathcal{V} ]

is a \(\mathcal{V}\)-enriched functor, meaning

[ (\mathcal{X}^\text{op}\times \mathcal{Z})((x, z), (x', z')) \leq \mathcal{V}(\Psi\Phi)(x, z), (\Psi\Phi)(x', z')) ]

or in other words

[ \mathcal{X}(x', x) \otimes \mathcal{Z}(z, z') \leq (\Psi\Phi)(x, z)\multimap(\Psi\Phi)(x', z') .]

Using the definitions this becomes

[ \mathcal{X}(x', x) \otimes \left(\bigvee_y \Phi(x, y)\otimes\Psi(y, z)\right) \otimes\mathcal{Z}(z, z') \leq \bigvee_y \Phi(x', y)\otimes\Psi(y, z') ]

or since \(\otimes\) distributes over \(\bigvee\) in a quantale,

[ \bigvee_y \mathcal{X}(x', x) \otimes \Phi(x, y)\otimes\Psi(y, z) \otimes\mathcal{Z}(z, z') \leq \bigvee_y \Phi(x', y)\otimes\Psi(y, z'). ]

This is true because

[ \mathcal{X}(x', x) \otimes \Phi(x, y) \le \Phi(x',y) ]

and

[ \Psi(y, z) \otimes\mathcal{Z}(z, z') \le \Phi(y,z') ]

by the following theorem. \( \qquad \blacksquare \)

This is a very handy tool:

**Theorem.** The following are equivalent:

\(\Phi : \mathcal{X} \nrightarrow \mathcal{Y}\) is a \(\mathcal{V}\)-enriched profunctor.

\(\mathcal{X}(x', x) \otimes \Phi(x, y) \otimes \mathcal{Y}(y, y') \leq \Phi(x',y')\) for all \(x,x',y,y'\).

\(\mathcal{X}(x', x) \otimes \Phi(x, y) \leq \Phi(x', y)\) and \(\Phi(x, y) \otimes \mathcal{Y}(y, y') \leq \Phi(x, y')\) for all \(x,x',y,y'\).

**Proof.** Item 1 is true iff \(\Phi : \mathcal{X}^\text{op} \times \mathcal{Y} \to \mathcal{V}\) is a \(\mathcal{V}\)-functor, which by definition is true iff

[ (\mathcal{X}^\text{op} \times \mathcal{Y})((x, y), (x', y')) \leq \mathcal{V}(\Phi(x, y), \Phi(x',y')) ]

for all \(x,x',y,y'\). Using the definitions, this is equivalent to

[ \mathcal{X}(x', x) \otimes \mathcal{Y}(y, y') \leq \Phi(x, y) \multimap \Phi(x', y') .]

By the definition of\(\multimap\) this in turn is equivalent to

[ \Phi(x, y) \otimes \mathcal{X}(x', x) \otimes \mathcal{Y}(y, y') \leq \Phi(x', y') ]

Because \(\otimes\) is commutative this is the same as item 2. Thus, 1 is equivalent to 2.

Next note that \(I \leq \mathcal{X}(x, x)\) and \(I \leq \mathcal{Y}(y, y)\) by the definition of a \(\mathcal{V}\)-category. Thus, given 2 we can set \(y' = y\) to get

[ \mathcal{X}(x', x) \otimes \Phi(x, y) = \mathcal{X}(x', x) \otimes \Phi(x, y) \otimes I \leq \mathcal{X}(x', x) \otimes \Phi(x, y) \otimes \mathcal{Y}(y, y) \leq \Phi(x', y) ]

or we can set \(x' = x\) to get

[ \Phi(x, y) \otimes \mathcal{Y}(y, y') = I \otimes \Phi(x, y) \otimes \mathcal{Y}(y, y') \leq \mathcal{X}(x, x) \otimes \Phi(x, y) \otimes \mathcal{Y}(y, y') \leq \Phi(x, y') ]

Thus, 2 implies 3. On the other hand, using 3 we can show 2:

[ \mathcal{X}(x', x) \otimes \Phi(x, y) \otimes \mathcal{Y}(y, y') \leq \Phi(x', y) \otimes \mathcal{Y}(y, y') \leq \Phi(a, b) ]

Thus, all three conditions are equivalent. \( \qquad \blacksquare \)

Next we check that composition is associative:

**Lemma.** Suppose \(\Theta \colon \mathcal{W} \nrightarrow \mathcal{X}, \Phi \colon \mathcal{X} \nrightarrow \mathcal{Y} \) and \(\Psi \colon \mathcal{Y} \to \mathcal{Z}\) are \(\mathcal{V}\)-enriched profunctors. Then

[ (\Psi \Phi) \Theta = \Psi (\Phi \Theta) .]

**Proof.** We need to show

[ \bigvee_{x} \Theta(x,y) \otimes \left( \bigvee_{y} \Phi(x,y) \otimes \Psi(y,z) \right) = \bigvee_{y} \left( \bigvee_{x} \Theta(x,y) \otimes \Phi(x,y) \right) \otimes \Psi(y,z) .]

Because \(\otimes\) distributes over \(\bigvee\), it's enough to show

[ \bigvee_{x} \bigvee_{y} \Theta(x,y) \otimes \left( \Phi(x,y) \otimes \Psi(y,z) \right) = \bigvee_{y} \bigvee_{x} \Theta(x,y) \otimes \Phi(x,y) \otimes \Psi(y,z) .]

Since \(\otimes\) is associative, and we always have \(\bigvee_{x} \bigvee_{y} = \bigvee_{y} \bigvee_{x} \) when the joins in question exist, this is true. \( \qquad \blacksquare \)

Next we show our would-be category \(\mathbf{Prof}_\mathcal{V}\) has identity morphisms.

**Lemma.** The \(\mathcal{V}\)-enriched functor \( \mathrm{hom} \colon \mathcal{X}^{\text{op}} \times \mathcal{X} \to \mathcal{V} \), defined by

[ \mathrm{hom}(x,x') = \mathcal{X}(x,x') ,]

corresponds to a \(\mathcal{V}\)-enriched profunctor

[ 1_{\mathcal{X}} \colon \mathcal{X} \nrightarrow \mathcal{X} ]

that serves as an identity for composition.

**Proof.** We need to check the left and right unit laws, but they are very similar so we'll only do one:

[ \Phi 1_{\mathcal{X}} = \Phi ]

for any \(\mathcal{V}\)-enriched profunctor \(\Phi \colon \mathcal{X} \to \mathcal{Y}\). This amounts to proving

[ \bigvee_{x'} \mathcal{X}(x,x') \otimes \Phi(x',y) = \Phi(x,y) ]

First we'll show

[ \Phi(x,y) \le \bigvee_{x'} \mathcal{X}(x,x') \otimes \Phi(x',y) ]

and then we'll show the reverse inequality. Since \(\mathcal{V}\) is a poset this will mean the two sides are equal.

For the inequality above it's enough to find one choice of \(x'\) that makes

[ \Phi(x,y) \le \mathcal{X}(x,x') \otimes \Phi(x',y) . ]

The obvious guess is \(x' = x\); then we need

[ \Phi(x,y) \le \mathcal{X}(x,x) \otimes \Phi(x,y) . ]

But the definition of enriched category says that \( I \le \mathcal{X}(x,x)\), so

[ \Phi(x,y) = I \otimes \mathcal{\Phi}(x,y) \le \mathcal{X}(x,x) \otimes \Phi(x,y) ]

as desired. Next we show the reverse inequality:

[ \bigvee_{x'} \mathcal{X}(x,x') \otimes \Phi(x',y) \le \Phi(x,y) .]

For this it's enough to prove that for *all* \(x'\) we have

[ \mathcal{X}(x,x') \otimes \Phi(x',y) \le \Phi(x,y) .]

We've seen this in the theorem above, so we're done. \( \qquad \blacksquare \)

Whew - that was a good workout! #:-S

]]>- Andrea Censi, A mathematical theory of co-design.

Or ask me questions!

Right now I want to talk more about enriched profunctors. We've seen how to do lots of fun stuff with feasibility relations. We can 'compose' them, which describes running two processes in series:

We can 'tensor' them, which describes running two processes in parallel:

We can also create feedback loops using cups:

and caps:

These features are the key building blocks of co-design diagrams - but they also show up in diagrams of electrical circuits, and many other diagrams used by scientists and engineers! So, we should understand them more deeply.

For starters, feasibility relations are just a special case of \(\mathcal{V}\)-enriched profunctors, namely the case where \(\mathcal{V} = \textbf{Bool}\). So, it's natural to ask if we can do all the same things with \(\mathcal{V}\)-enriched profunctors. And the answer is *yes!*

This is nice, because there's a variant of co-design diagrams where we use \(\mathcal{V} = \textbf{Cost}\) instead of \(\mathcal{V} = \textbf{Bool}\). In fact they were developed by the U.S. Navy starting in 1957 to help build nuclear submarines! They're called PERT charts, and they've been subsequently used for many other things. Of course, none of the practical people using PERT charts know they are dealing with enriched profunctors, and if you told them they probably wouldn't care. But still, this is a great example of how concepts that arise naturally in category theory can arise naturally in 'real life'.

So, let's take what we've done for feasibility relations, and do it for \(\mathcal{V}\)-enriched profunctors. It all works the same way.

We'll start by tensoring them.

In Lecture 63 and Lecture 64 we saw that if \(\mathcal{V}\) is any commutative quantale there's a category \(\mathbf{Prof}_\mathcal{V}\) with

\(\mathcal{V}\)-enriched categories as objects,

\(\mathcal{V}\)-enriched profunctors as morphisms,

and composition given by 'matrix multiplication':

[ (\Psi\Phi)(x,z) = \bigvee_{y \in \mathrm{Ob}(\mathcal{Y})} \Phi(x,y) \otimes \Psi(y,z)]

whenever \(\Phi \colon \mathcal{X} \nrightarrow \mathcal{Y} \) and \(\Psi \colon \mathcal{Y} \to \mathcal{Z}\).

But \(\mathbf{Prof}_\mathcal{V}\) is better than a mere category: you can also *tensor* objects in this category, and *tensor* morphisms!

We saw how to tensor \(\mathcal{V}\)-enriched categories way back in Lecture 62. I wrote this tensor product with a times sign, but now it's better to use the symbol \(\otimes\). Here's how it works: for any \(\mathcal{V}\)-enriched categories \(\mathcal{X}\) and \(\mathcal{Y}\), there is a \(\mathcal{V}\)-enriched category \(\mathcal{X} \otimes \mathcal{Y}\) for which:

an object is a pair \( (x,y) \) where \(x\) is an object of \(\mathcal{X}\) and \(y\) is an object of \(\mathcal{Y}\), and

we define

[ (\mathcal{X} \times \mathcal{Y})((x,y), \, (x',y')) = \mathcal{X}(x,x') \otimes \mathcal{Y}(y,y') .]

Now let's figure out how to tensor \(\mathcal{V}\)-enriched profunctors! Suppose we have two of them, say

[ \Phi \colon \mathcal{X} \nrightarrow \mathcal{Y} ]

and

[ \Psi \colon \mathcal{X'} \nrightarrow \mathcal{Y'} ]

How can we define

[ \Phi \otimes \Psi \colon X \otimes X' \nrightarrow Y \otimes Y' ?]

Well, we did this already for feasibility relations in Lecture 66, so we just copy that:

[ (\Phi \otimes \Psi)((x,x'),(y,y')) = \Phi(x,y) \otimes \Psi(x',y') .]

You should imagine \(\Phi \otimes \Psi\) as doing \(\Phi\) and \(\Psi\) in parallel:

This ability to tensor things makes \(\mathbf{Prof}_{\mathcal{V}}\) into a so-called 'monoidal category'. Instead of defining that - you can look up the definition if you care - I'll just get you to check some of the things a monoidal category should have.

First, we want tensoring to be associative. More precisely:

**Puzzle 224.** Suppose \(\mathcal{X}, \mathcal{Y}\) and \(\mathcal{Z}\) are \(\mathcal{V}\)-enriched categories. Show there is a \(\mathcal{V}\)-enriched profunctor

[ \alpha_{\mathcal{X}, \mathcal{Y},\mathcal{Z}} \colon (\mathcal{X} \otimes \mathcal{Y}) \otimes \mathcal{Z} \nrightarrow

\mathcal{X} \otimes (\mathcal{Y} \otimes \mathcal{Z}) ]

which has an inverse.

There is just one answer to this puzzle, and this choice of \( \alpha_{\mathcal{X}, \mathcal{Y},\mathcal{Z}}\) is called the **associator**.

Remember, there's a \(\mathcal{V}\)-enriched category called \(\mathbf{1}\). This has one object \(0\) and \(\mathbf{1}(0,0) = I \), where \(I\) is the multiplicative identity in \(\mathcal{V}\). Not surprisingly, this guy \(\mathbf{1}\) is the unit for tensoring! More precisely:

**Puzzle 225.** Suppose \(\mathcal{X}\) is a \(\mathcal{V}\)-enriched categories. Show there are \(\mathcal{V}\)-enriched profunctors

[ \lambda_{\mathcal{X}} \colon \mathbf{1} \otimes \mathcal{X} \nrightarrow \mathcal{X} ]

and

[ \rho_{\mathcal{X}} \colon \mathcal{X} \otimes \mathbf{1} \nrightarrow \mathcal{X} ]

both of which have inverses.

There's just one choice of each of these, unless you're a lot more sneaky than me. We call \(\lambda_{\mathcal{X}}\) the **left unitor** and \(\rho_{\mathcal{X}}\) the **right unitor**.

That's most of what we need for a monoidal category! Not everything: there are some subtleties. We want tensoring to define a functor \( \otimes \colon \mathbf{Prof}_{\mathcal{V}} \times \mathbf{Prof}_{\mathcal{V}} \to \mathbf{Prof}_{\mathcal{V}}\). And we need the associator and unitors to obey some equations.

But instead of scaring you with these details now, let me pound home the basic idea:

You already know dozens of monoidal categories, and now you know infinitely many more: all the categories \(\mathbf{Prof}_{\mathcal{V}}\).

**Puzzle 226.** List a bunch of monoidal categories. Don't be afraid to guess: if a category has a good way of combining two objects to get a new object, and it seems kind of associative, chances are you've got a monoidal category.

Remember, we're really building a feasibility relation out of other feasibility relations. Each smaller box is a feasibility relation. If we don't inquire into exactly what feasibility relations these particular boxes stand for, just how they're assembled, there's just one question left to discuss. What happens when a wire *bends back?*

Intuitively, this describes 'feedback'. For example, I may take some bread, toast it, sell it, make money, and use that to buy more bread. Here I'm stringing together a number of processes, each one producing the resources needed for the next... until finally the last one produces some resources needed for the first!

It's not obvious how to describe feedback using just **composition**, which takes two feasibility relations \(\Phi \colon X \nrightarrow Y\) and \(\Psi \colon Y \nrightarrow Z\) and puts one after the other:

and **tensoring**, which takes two feasibility relations \(\Phi \colon X \nrightarrow Y\) and \(\Psi \colon X' \nrightarrow Y'\) and puts them side by side:

Using these we can build co-design diagrams like this:

But we cannot get wires that bend back! For that we need two extra feasibility relations. The first is called the **cup**:

It looks like a wire coming in labelled \(X\), bending around and going back out to the left. In co-design diagrams, labels of wires stand for preorders. The wire coming in stands for a preorder \(X\) as usual. But what about the wire going back out? This stands for \(X^{\text{op}}\): the same set with the opposite concept of \(\le\).

This is a a rule we haven't discussed yet. A wire going from left to right, labelled by some preorder, stands for that preorder. But a wire going right to left, labelled by some preorder stands for the *opposite* of that preorder.

But how do we tell if wire are going from left to right or the other way? One way is to draw arrows on them, as I've done just now. Fong and Spivak often use a different notation: a wire going from left to right is labelled \(\le\), while one going the other way is labelled \(\ge\). This will turn out to make a lot of sense.

Anyway, it looks like our cup stands for a feasibility relation from \(X^{\text{op}} \times X \) to... *nothing!* But what's 'nothing'?

That's another rule I haven't told you. 'Nothing' - the invisible wire - is our symbol for the preorder \(\textbf{1}\). This is the set \( \{0\} \) made into a preorder in the only way possible, with \(0 \le 0\).

So, our cup stands for some particular feasibility relation

[ \cup_X \colon X^{\text{op}} \times X \nrightarrow \textbf{1} . ]

Which one? We can guess if remember that such a feasibility relation is really a monotone function

[ \cup_X \colon (X^{\text{op}} \times X)^\text{op} \times \textbf{1} \to \mathbf{Bool} .]

We can simplify this a bit:

**Puzzle 213.** Show that for any preorder \(A\), the preorder
\( A \times \textbf{1}\) is **isomorphic** to \(A\):: in other words, there is a monotone function from \( A \times \textbf{1}\) to \(A\) with a monotone inverse. For short we write \(A \times \textbf{1} \cong A\). (This is one way in which \(\textbf{1}\) acts like 'nothing'.)

**Puzzle 214.** Show that for any preorders \(A\) and \(B\) we have \( (A \times B)^{\text{op}} \cong A^{\text{op}} \times B^{\text{op}}\).

**Puzzle 215.** Show that for any preorder \(A\) we have \( (A^{\text{op}})^{\text{op}} \cong A\).

So, we get

[ (X^{\text{op}} \times X)^\text{op} \times \textbf{1} \cong (X^{\text{op}} \times X)^\text{op} \cong (X^{\text{op}})^\text{op} \times X^\text{op} \cong X \times X^\text{op} ]

Replacing the fancy expression at left by the simpler but isomorphic expression at right, we can reinterpret the cup more simply as a monotone function

[ \cup_X \colon X \times X^{\text{op}} \to \textbf{Bool} . ]

What could this be? It should remind you of our old friend the hom-functor

[ \text{hom} \colon X^{\text{op}} \times X \to \textbf{Bool} .]

And that's what it is - just twisted around a bit! In other words, we define

[ \cup_X (x,x') = \text{hom}(x',x) . ]

If you forget your old friend the hom-functor, this just means that

[ \cup_X (x,x') = \begin{cases} \texttt{true} & \mbox{if } x' \le x \\ \texttt{false} & \mbox{otherwise.} \end{cases} ]

Whew! It's simple in the end: it just says that when send a resource round a bend, what comes out must be less than or equal to what came in. The little inequality symbols on this picture are designed to make that easier to remember:

One more thing: to describe feedback we also need a feasibility relation called the **cap**, which looks like this:

This is some feasibility relation from 'nothing' to \( X \times X^{\text{op}}\), or more precisely

[ \cap_X \colon \textbf{1} \nrightarrow X \times X^{\text{op}} .]

**Puzzle 216.** Rewrite this feasibility relation as a monotone function and simplify it just as we did for the cup. Then, guess what it is!

The cap winds up being just as simple as the cup. We can discuss this and work it out... and next time I'll show you how to use the cap and cup to describe feedback.

By the way, this stuff we're doing was first invented in particle physics. Feynman invented diagrams that describe the interaction between particles... and he realized that an antiparticle could be understood as a particle going 'backwards in time', so he drew little arrows to indicate whether the edges in his diagrams were going forwards or backwards in time. The cup describes the annihilation of a particle-antiparticle pair, and the cap describes the creation of such a pair.

Only much later did people realize that the preorder \(X^{\text{op}}\) is mathematically like the 'antiparticle' of \(X\).

]]>In most branches of math you study *gadgets* and *maps between gadgets*, like:

- sets and functions between sets,
- vector spaces and linear maps between vector spaces,
- posets and monotone functions between posets,

and so on.

We do this in category theory too! We have categories and functors between categories. But category theory has an extra layer. It also has *natural transformations between functors.*

The reason is not hard to find. Some people think categories are abstract, but I don't. When you say the word 'category', a picture sort of like this pops into my head:

It's a bunch of objects, which look like dots, and a bunch of morphisms, which look like arrows between dots.

Now, you might object that this is a picture of a *graph*, not a category. And you'd be right! In a category we can *compose* morphisms, and we also have *identity* morphisms. So a more detailed mental picture of the same category would look like this:

Let's call this category \(\mathcal{C}\). Then, a functor \(F\) from this category \(\mathcal{C}\) to some other category \(\mathcal{D}\) would look a bit like this:

\(F\) maps each object of \(\mathcal{C}\) to an object in \(\mathcal{D}\), and it maps each morphism to a morphism. So, a functor from \(\mathcal{C}\) to \(\mathcal{D}\) is like *a picture of \(\,\mathcal{C}\) drawn on the blackboard of \(\,\mathcal{D}\)*.

The category \(\mathcal{D}\) may, of course, contain other objects and morphisms that aren't in our picture. To keep things simple I haven't drawn those. Also, two objects or morphisms of \(\mathcal{C}\) may get mapped to the same object in \(\mathcal{D}\), so the picture of \(\mathcal{C}\) in \(\mathcal{D}\) could be 'squashed down'. But I haven't drawn that either! You can draw these other possibilities.

Now for the fun part.

Suppose we have two functors from \(\mathcal{C}\) to \(\mathcal{D}\), say \(F\) and \(G\). Let me draw them in a stripped-down way:

Then we can define a 'natural transformation' from \(F\) to \(G\), written \(\alpha : F \Rightarrow G\). It looks like this:

For each object \(x \in \mathcal{C}\), the natural transformation gives a morphism from \(F(x)\) to \(G(x)\). In the picture above I've drawn every objects of \(\mathcal{C}\) as a mere dot, but that's a bit sloppy. So let's give all the objects and morphisms names:

Now we see more clearly that for each object \(x \in \mathcal{C}\), the natural transformation \(\alpha\) gives a morphism \(\alpha_x : F(x) \to G(x) \).

Note that this creates a lot of parallelograms in our picture... or squares, if you draw them like this:

What makes the transformation *natural* is that all these squares must 'commute': that is, going down and across gives the same morphism as going across and down.

It takes a while to see why this it's so important, but this condition is one of the first really big ideas in category theory. Ways of going between functors that feel 'natural' in an intuitive sense, meaning that they don't involve disorganized random choices, tend to be natural in this technical sense! And it turns out that one can do a lot using this idea.

Indeed, when Eilenberg and Mac Lane came out with their first paper on category theory in 1945, the main topic was natural transformations. Mac Lane later said:

I didn't invent categories to study functors; I invented them to study natural transformations.

Okay, now let me give the formal definition:

**Definition.** Given categories \(\mathcal{C},\mathcal{D}\) and functors \(F, G: \mathcal{C} \to \mathcal{D}\), a **transformation** \(\alpha : F \to G\) is a choice of morphism

[ \alpha_x : F(x) \to G(x) ]

for each object \(x \in \mathcal{C}\). We say the transformation \(\alpha\) is **natural** if for each morphism \(f : x \to y\) in \(\mathcal{C}\), this square commutes:

In other words,

[ G(f) \alpha_x = \alpha_y F(f) .]

We call a square diagram of this sort a **naturality square.**

Okay, now let's start figuring out what natural transformations are good for!

**Puzzle 126.** Let \(\mathcal{C}\) be the free category on this graph:

If we treat this as a database schema, a functor \(F: \mathcal{C} \to \mathbf{Set}\) is a database built using this schema, and you can draw it as a table, like this:

\[ \begin{array}{c|c} \text{People} & \mathrm{FriendOf} \\ \hline Alice & Bob \\ Bob & Alice \\ Stan & Alice \\ Tyler & Stan \\ \end{array} \]

Suppose \(G: \mathcal{C} \to \mathbf{Set} \) is another such database:

\[ \begin{array}{c|c} \text{People} & \mathrm{FriendOf} \\ \hline Alice & Bob \\ Bob & Alice \\ Stan & Alice \\ Tyler & Stan \\ Mei-Chu & Stan \\ \end{array} \]

Can you find a natural transformation \(\alpha : F \Rightarrow G\) in this example? What is its practical meaning: that is, what could it be used for? What is the significance of naturality in this example?

**Puzzle 127.** Suppose \(H : \mathcal{C} \to \mathbf{Set} \) is yet another database built using the same schema, namely

\[ \begin{array}{c|c} \text{People} & \mathrm{FriendOf} \\ \hline Alice & Bob \\ Bob & Alice \\ Tyler & Bob \\ \end{array} \]

Can you find a natural transformation \(\beta : F \Rightarrow H\)? What is its practical meaning? What is the significance of naturality in this example?

**Puzzle 128.** How many natural transformations \(\gamma: H \Rightarrow H\) are there? What is their practical meaning?

This describes a big complicated feasibility relation built from smaller ones - the little boxes - in various ways. Now let me start explaining those various ways!

First of all, remember that a **feasibility relation** \(\Phi \colon X \nrightarrow Y \) from a preorder \(X\) to a preorder \(Y\) is monotone function

[ \Phi \colon X^{\text{op}} \times Y \to \lbrace \text{true}, \text{false} \rbrace . ]

In collaborative design we interpret \(\Phi(x,y) = \text{true}\) to mean "we can meet the requirements \(x\) given the resources \(y\)". In a codesign diagram we can draw \(\Phi\) as a box with one wire coming in at left labelled \(X\), and one wire going out at right labelled \(Y\):

Here are a few easy examples:

**Puzzle 204.** Suppose you are trying to buy a plane ticket, and the cheapest available ticket is $500. Describe this using a feasibility relation \(\Phi : \textbf{Bool} \nrightarrow [0,\infty) \) where we make \( [0,\infty) \), the set of nonnegative real numbers, into a poset with its usual ordering \(\le\).

**Puzzle 205.** Suppose you are trying to buy either one or two loaves of bread - or perhaps none. Suppose bread costs $2 per loaf. Describe this using a feasibility relation \(\Psi : \lbrace 0,1,2\rbrace \nrightarrow [0,\infty) \). Here we make \( {0,1,2}\) into a poset with its usual ordering.

**Puzzle 206.** Suppose you are trying to feed hungry children with the loaves of bread you bought in the previous puzzle, and you can feed at most three children with each loaf of bread. Describe this using a feasibility relation \(\Phi : \mathbb{N} \nrightarrow \lbrace 0,1,2\rbrace \). Here \(\mathbb{N}\) is the set of natural numbers \( \lbrace 0,1,2,3,\dots \rbrace \) with its usual ordering.

Second, remember from Lecture 58 that we can compose feasibility relations \(\Phi \colon X \nrightarrow Y\) and \(\Psi \colon Y \nrightarrow Z\) to get a feasibility relation \(\Psi \Phi \colon X \nrightarrow Z\). We draw this as follows:

The box on the outside helps us think of \(\Psi\Phi\) as a single thing, but we could also leave it out.

The idea in codesign is that this describes two systems or processes stuck together, with the second providing the resources required for the first. Let's look at an easy example:

**Puzzle 207.** Suppose you buy loaves of bread and then use them to feed hungry children. Compose the feasibility relation \(\Psi : {0,1,2} \nrightarrow [0,\infty) \) from Puzzle 205 and the feasibility relation \(\Phi : \mathbb{N} \nrightarrow \lbrace 0,1,2\rbrace \) from Puzzle 206 to get a feasibility relation \(\Psi \Phi : \mathbb{N} \nrightarrow [0,\infty) \) describing how many children you can feed for a certain amount of money (given the fact that you plan to buy at most two loaves).

Third, if we have a bunch of preorders \(X_1, \dots, X_m \) and \(Y_1, \dots, Y_n\), their products \(X_1 \times \cdots \times X_m\) and \(Y_1 \times \cdots \times Y_n \) are also preorders, so we can talk about a feasibility relation

[ \Phi \colon X_1 \times \cdots \times X_m \nrightarrow Y_1 \times \cdots \times Y_n ]

We draw this as a box with a bunch of wires going in and a bunch going out, as follows:

The idea in codesign is that this describes a situation where a bunch of resources \(Y_1, \dots, Y_n\) are needed to meet a bunch of requirements \(X_1, \dots, X_m\).

**Puzzle 208.** Suppose you some slices of bread, some slices of cheese and some slices of ham. You are trying to make sandwiches. You can make a cheese sandwich with two slices of bread and one slice of cheese. You can make a ham sandwich with two slices of bread and one slice of ham. There is a feasibility relation \(\Theta : \mathbb{N} \times \mathbb{N} \nrightarrow \mathbb{N} \times \mathbb{N} \times \mathbb{N} \) where \(\Theta(m,n,i,j,k) = \text{true}\) if you can make \(m\) cheese sandwiches and \(n\) ham sandwiches from \(i\) slices of bread, \(j\) slices of cheese and \(k\) slices of ham.

Fourth, if we have feasibility relations \(\Phi \colon X \nrightarrow Y\) and \(\Psi \colon X' \nrightarrow Y'\), we can define a new feasibility relation

[ \Phi \otimes \Psi \colon X \times X' \nrightarrow Y \times Y' ]

given by

[ (\Phi \otimes \Psi)((x,x'),(y,y')) = \Phi(x,y) \wedge \Psi(x',y') ]

We call this way of combining feasibility relations **tensoring**, and we draw \(\Phi \otimes \Psi\) as follows:

This describes a situation where we can meet the requirements \((x,x')\) given resources \( (y,y') \) iff we can meet requirement \(x\) given \(x'\) *and* meet requirement \(y\) given \(y'\).

Here is a very simple example:

**Puzzle 209.** Suppose you are trying to fry some eggs and also toast some slices of bread. Describe each process separately as a feasibility relation from \(\mathbb{N}\) to \(\mathbb{N}\) and then tensor these relations. What is the result?

**Puzzle 210.** Show that \(\Phi \otimes \Psi\) is really a feasibility relation if \(\Phi\) and \(\Psi\) are feasibility relations.

**Puzzle 211.** What general mathematical result is Puzzle 209 an example of?

**Puzzle 212.** We can get a feasibility relation by taking either the companion or the conjoint of a monotone map, thanks to the ideas in the puzzles of Lecture 65. Which of the feasibility relations in this lecture's puzzles are companions or conjoints?

One application is to *collaborative design*. Fong and Spivak discuss it in their the book, based on this paper by a student of Spivak:

- Andrea Censi, A mathematical theory of co-design.

Censi's work is based on \(\textbf{Bool}\)-enriched profunctors, also known as feasibility relations. We introduced these in Lecture 56.

Remember, a feasibility relation \( \Phi : X\nrightarrow Y \) is a monotone function

[ \Phi : X^{\text{op}} \times Y \to \mathbf{Bool} .]

If \( \Phi(x,y) = \text{true}\), we say **\(x\) can be obtained given \(y\)**. The idea is that we use elements of \( X\) to describe 'requirements' - things you want - and elements of \(Y\) to describe 'resources' - things you have.

The idea of Andrea Censi's theory that we can compute the design requirements of a complex system from those of its parts using 'co-design diagrams'. These are really pictures of big complicated feasibility relations, like this:

This big complicated feasibility relation is built from simpler ones in various ways. Each wire in this diagram is labeled with the name of a preorder, and each little box is itself a feasibility relation between preorders. We described how to *compose* feasibility relations in Lecture 58, and that corresponds to feeding the outputs of one little box into another. But there are other things going on in this picture, like boxes sitting side by side, and wires that bend around backwards! This is what I need to explain - it may take a couple lectures to do this.

Instead of diving into the mathematical details today, let me quote the book's general explanation of the diagram above:

As an example, consider the design problem of creating a robot to carry some load at some velocity. The top-level planner breaks the problem into three design teams: team chassis, team motor, and team battery. Each of these teams could break up into multiple parts and the process repeated, but let's remain at the top level and consider the resources produced and the resources required by each of our three teams.

The chassis in some sense provides all the functionality—it carries the load at the velocity—but it requires some things in order to do so. It requires money, of course, but more to the point it requires a source of torque and speed. These are supplied by the motor, which in turn needs voltage and current from the battery. Both the motor and the battery cost money, but more importantly they need to be carried by the chassis: they become part of the load. A feedback loop is created: the chassis must carry all the weight, even that of the parts that power the chassis. A heavier battery might provide more energy to power the chassis, but is the extra power worth the heavier load?

In the picture, each part—chassis, motor, battery, and robot—is shown as a box with ports on the left and right. The functionalities, or resources produced by the part are on the left of the box, and the resources required by the part are on the right.

The boxes marked \(\Sigma\) correspond to summing inputs. These boxes are not to be designed, but we will see later that they fit easily into the same conceptual framework. Note also the \(\leq\)'s on each wire; they indicate that if box \(A\) requires a resource that box \(B\) produces, then \(A\)'s requirement must be less than or equal to \(B\)'s production.

Next time we'll get into more detail.

But to wrap up for today, here are few puzzles!

We've been talking about enriched functors and also enriched profunctors. How are they related? The first cool fact is that any enriched functor gives *two* enriched profunctors: one going each way.

**Puzzle 201.** Show that any \(\mathcal{V}\)-enriched functor \(F: \mathcal{X} \to \mathcal{Y}\) gives a \(\mathcal{V}\)-enriched profunctor

[ \hat{F} \colon \mathcal{X} \nrightarrow \mathcal{Y} ]

defined by

[ \hat{F} (x,y) = \mathcal{Y}(F(x), y ) .]

**Puzzle 202.** Show that any \(\mathcal{V}\)-enriched functor \(F: \mathcal{X} \to \mathcal{Y}\) gives a \(\mathcal{V}\)-enriched profunctor

[ \check{F} \colon \mathcal{Y} \nrightarrow \mathcal{X} ]

defined by

[ \check{F} (y,x) = \mathcal{Y}(y,F(x)) .]

These two constructions have funny names. \(\hat{F} \colon \mathcal{X} \nrightarrow \mathcal{Y}\) is called the **companion** of \(F\) and \( \check{F} \colon \mathcal{Y} \nrightarrow \mathcal{X} \), going back, is called the **conjoint** of \(F\).

If you have trouble remembering these, remember that a 'companion' is like a fellow traveler, going the same way as our original functor. The word 'conjoint' should remind you of 'adjoint', which means something going back the other way.

In fact there's a relationship between adjoints and conjoints!

**Puzzle 203.** We say a \(\mathcal{V}\)-enriched functor \(F: \mathcal{X} \to \mathcal{Y}\) is a **left adjoint** of a \(\mathcal{V}\)-enriched functor \(G: \mathcal{Y} \to \mathcal{X}\) if

[ \mathcal{Y}(F(x), y) = \mathcal{X}(x,G(y)) ]

for all objects \(x\) of \(\mathcal{X}\) and \(y\) of \(\mathcal{Y}\). In this situation we also say \(G\) is the **right adjoint** of \(F\). Show that \(F\) is the left adjoint of \(G\) if and only if

[ \hat{F} = \check{G} . ]

Pretty!

]]>There are lots of ways to build new categories from old, and most work for \(\mathcal{V}\)-enriched categories too *if* \(\,\mathcal{V}\) is nice enough. We ran into two of these constructions for categories in Lecture 52 when discussing the hom-functor

[ \mathrm{hom}: \mathcal{C}^{\text{op}} \times \mathcal{C} \to \mathbf{Set} . ]

To make sense of this we needed to show that we can take the 'product' of categories, and that every category has an 'opposite'. Now we're trying to understand \(\mathcal{V}\)-enriched profunctors \(\Phi : \mathcal{X} \nrightarrow \mathcal{Y}\), which are really just \(\mathcal{V}\)-enriched functors

[ \Phi : \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} .]

To make sense of this we need the same two constructions: the product and the opposite!

(This is no coincidence: soon we'll see that every \(\mathcal{V}\)-enriched category \(\mathcal{X}\) has a hom-functor \( \mathrm{hom} : \mathcal{X}^{\text{op}} \times \mathcal{X} \to \mathcal{V}\), which we can think of as a profunctor.)

So, first let's look at the product of enriched categories:

**Theorem.** Suppose \(\mathcal{V}\) is a commutative monoidal poset. Then for any \(\mathcal{V}\)-enriched categories \(\mathcal{X}\) and \(\mathcal{Y}\), there is a \(\mathcal{V}\)-enriched category \(\mathcal{X} \times \mathcal{Y}\) for which:

An object is a pair \( (x,y) \in \mathrm{Ob}(\mathcal{X}) \times \mathrm{Ob}(\mathcal{Y}) \).

We define

[ (\mathcal{X} \times \mathcal{Y})((x,y), \, (x',y')) = \mathcal{X}(x,x') \otimes \mathcal{Y}(y,y') .]

**Proof.** We just need to check axioms a) and b) of an enriched category (see Lecture 29):

a) We need to check that for every object \( (x,y) \) of \(\mathcal{X} \times \mathcal{Y}\) we have

[ I \le (\mathcal{X} \times \mathcal{Y})((x,y), \, (x,y)) .]

By item 2 this means we need to show

[ I \le \mathcal{X}(x,x) \otimes \mathcal{Y}(y,y) .]

But since \(\mathcal{X}\) and \(\mathcal{Y}\) are enriched categories we know

[ I \le \mathcal{X}(x,x) \text{ and } I \le \mathcal{Y}(y,y) ]

and tensoring these two inequalities gives us what we need.

b) We need to check that for all objects \( (x,y), (x',y'), (x'',y'') \) of \(\mathcal{X} \times \mathcal{Y}\) we have

[ (\mathcal{X} \times \mathcal{Y})((x,y), \, (x',y')) \otimes (\mathcal{X} \times \mathcal{Y})((x',y'), \, (x'',y'')) \le (\mathcal{X} \times \mathcal{Y})((x,y), \, (x'',y'')) .]

This looks scary, but long division did too at first! Just relax and follow the rules. To get anywhere we need to rewrite this using item 2:

[ \mathcal{X}(x,x') \otimes \mathcal{Y}(y,y') \otimes \mathcal{X}(x',x'') \otimes \mathcal{Y}(y',y'') \le \mathcal{X}(x,x'') \otimes \mathcal{Y}(y,y'') . \qquad (\star) ]

But since \(\mathcal{X}\) and \(\mathcal{Y}\) are enriched categories we know

[ \mathcal{X}(x,x') \otimes \mathcal{X}(x',x'') \le \mathcal{X}(x,x'') ]

and

[ \mathcal{Y}(y,y') \otimes \mathcal{Y}(y',y'') \le \mathcal{Y}(y,y'') . ]

Let's tensor these two inequalities and see if we get \( (\star) \). Here's what we get:

[ \mathcal{X}(x,x') \otimes \mathcal{X}(x',x'') \otimes \mathcal{Y}(y,y') \otimes \mathcal{Y}(y',y'') \le \mathcal{X}(x,x'') \otimes \mathcal{Y}(y,y'') .]

This is *almost* \( (\star) \), but not quite. To get \( (\star) \) we need to switch two things in the middle of the left-hand side! But we can do that because \(\mathcal{V}\) is a *commutative* monoidal poset. \( \qquad \blacksquare \)

Next let's look at the opposite of an enriched category:

**Theorem.** Suppose \(\mathcal{V}\) is a monoidal poset. Then for any \(\mathcal{V}\)-enriched category \(\mathcal{X}\) there is a \(\mathcal{V}\)-enriched category \(\mathcal{X}^{\text{op}}\), called the **opposite** of \(\mathcal{X}\), for which:

The objects of \(\mathcal{X}^{\text{op}}\) are the objects of \(\mathcal{X}\).

We define

[ \mathcal{X}^{\text{op}}(x,x') = \mathcal{X}(x',x) .]

**Proof.** Again we need to check axioms a) and b) of an enriched category.

a) We need to check that for every object \( x \) of \(\mathcal{X}^{\text{op}}\) we have

[ I \le \mathcal{X}^{\text{op}}(x,x) . ]

Using the definitions, this just says that for every object \( x \) of \(\mathcal{X}\) we have

[ I \le \mathcal{X}(x,x) . ]

This is true because \(\mathcal{X}\) is an enriched category.

b) We also need to check that for all objects \(x,x',x'' \) of \(\mathcal{X}^{\text{op}} \) we have

[ \mathcal{X}^{\text{op}} (x,x') \otimes \mathcal{X}^{\text{op}}(x',x'') \le \mathcal{X}^{\text{op}}(x,x'') . ]

Using the definitions, this just says that for all objects \(x,x',x'' \) of \(\mathcal{X}\) we have

[ \mathcal{X}(x',x) \otimes \mathcal{X}(x'',x') \le \mathcal{X}(x'',x) . ]

We can prove this as follows:

[ \mathcal{X}(x',x) \otimes \mathcal{X}(x'',x') = \mathcal{X}(x'',x') \otimes \mathcal{X}(x',x) \le \mathcal{X}(x'',x) .]

since \(\mathcal{V}\) is commutative and \(\mathcal{X}\) is an enriched category. \( \qquad \blacksquare \)

Now we are ready to state the definition of an enriched profunctor! I gave a tentative definition back in Lecture 60, but we didn't really know what it meant, nor under which conditions it made sense. Now we do!

**Definition.** Suppose \(\mathcal{V}\) is a closed commutative monoidal poset and \(\mathcal{X},\mathcal{Y}\) are \(\mathcal{V}\)-enriched categories. Then a \(\mathcal{V}\)-enriched profunctor

[ \Phi : \mathcal{X} \nrightarrow \mathcal{Y} ]

is a \(\mathcal{V}\)-enriched functor

[ \Phi: \mathcal{X}^{\text{op}} \times \mathcal{Y} \to \mathcal{V} .]

There are lot of adjectives here: "closed commutative monoidal poset". They're all there for a reason. Luckily we've seen our friends \(\mathbf{Bool}\) and \(\mathbf{Cost}\) have all these nice properties - and so do many other examples, like the power set \(P(X)\) of any set \(X\).

Alas, if we want to *compose* \(\mathcal{V}\)-enriched profunctors we need \(\mathcal{V}\) to be even *nicer!* From our work with feasibility relations we saw that composing profunctors is done using a kind of 'matrix multiplication'. For this to work, \(\mathcal{V}\) needs to be a 'quantale'. So, next time I'll talk about quantales. Luckily all the examples I just listed are quantales!

Here's a puzzle to keep you happy until next time. It's important:

**Puzzle 197.** Suppose \(\mathcal{V}\) is a closed commutative monoidal poset and \(\mathcal{X}\) is any \(\mathcal{V}\)-enriched category. Show that there is a \(\mathcal{V}\)-enriched functor, the **hom functor**

[ \mathrm{hom} \colon \mathcal{X}^{\text{op}} \times \mathcal{X} \to \mathcal{V} ]

defined on any object \( (x,x') \) of \(\mathcal{X}^{\text{op}} \times \mathcal{X} \) by

[ \mathrm{hom}(x,x') = \mathcal{X}(x,x') .]

If you forget the definition of enriched functor, you can find it in Lecture 32.

]]>Remember, \(\mathbf{Bool} = \lbrace \text{true}, \text{false} \rbrace \) is the preorder that we use to answer true-or-false questions like

*can we*get from here to there?

while \(\mathbf{Cost} = [0,\infty] \) is the preorder that we use to answer quantitative questions like

*how much does it cost*to get from here to there?

or

*how far is it*from here to there?

In \(\textbf{Cost}\) we use \(\infty\) to mean it's impossible to get from here to there: it plays the same role that \(\text{false}\) does in \(\textbf{Bool}\). And remember, the ordering in \(\textbf{Cost}\) is the *opposite* of the usual order of numbers! This is good, because it means we have

[ \infty \le x \text{ for all } x \in \mathbf{Cost} ]

just as we have

[ \text{false} \le x \text{ for all } x \in \mathbf{Bool} .]

Now, \(\mathbf{Bool}\) and \(\mathbf{Cost}\) are monoidal preorders, which are just what we've been using to define enriched categories! This let us define

- \(\mathbf{Bool}\)-enriched categories, which are just
**preorders**

and

- \(\mathbf{Cost}\)-enriched categories, which are
**Lawvere metric spaces**.

We can draw preorders using graphs, like these:

An edge from \(x\) to \(y\) means \(x \le y\), and we can derive other inequalities from these. Similarly, we can draw Lawvere metric spaces using \(\mathbf{Cost}\)-weighted graphs, like these:

The distance from \(x\) to \(y\) is the length of the shortest directed path from \(x\) to \(y\), or \(\infty\) if no path exists.

All this is old stuff; now we're thinking about enriched profunctors between enriched categories.

A \(\mathbf{Bool}\)-enriched profunctor between \(\mathbf{Bool}\)-enriched categories also called a feasibility relation between preorders, and we can draw one like this:

What's a \(\mathbf{Cost}\)-enriched profunctor between \(\mathbf{Cost}\)-enriched categories? It should be no surprise that we can draw one like this:

You can think of \(C\) and \(D\) as countries with toll roads between the different cities; then an enriched profunctor \(\Phi : C \nrightarrow D\) gives us the cost of getting from any city \(c \in C\) to any city \(d \in D\). This cost is \(\Phi(c,d) \in \mathbf{Cost}\).

But to specify \(\Phi\), it's enough to specify costs of flights from *some* cities in \(C\) to *some* cities in \(D\). That's why we just need to draw a *few* blue dashed edges labelled with costs. We can use this to work out the cost of going from any city \(c \in C\) to any city \(d \in D\). I hope you can guess how!

**Puzzle 182.** What's \(\Phi(E,a)\)?

**Puzzle 183.** What's \(\Phi(W,c)\)?

**Puzzle 184.** What's \(\Phi(E,c)\)?

Here's a much more challenging puzzle:

**Puzzle 185.** In general, a \(\mathbf{Cost}\)-enriched profunctor \(\Phi : C \nrightarrow D\) is defined to be a \(\mathbf{Cost}\)-enriched functor

[ \Phi : C^{\text{op}} \times D \to \mathbf{Cost} ]

This is a function that assigns to any \(c \in C\) and \(d \in D\) a cost \(\Phi(c,d)\). However, for this to be a \(\mathbf{Cost}\)-enriched functor we need to make \(\mathbf{Cost}\) into a \(\mathbf{Cost}\)-enriched category! We do this by saying that \(\mathbf{Cost}(x,y)\) equals \( y - x\) if \(y \ge x \), and \(0\) otherwise. We must also make \(C^{\text{op}} \times D\) into a \(\mathbf{Cost}\)-enriched category, which I'll let you figure out to do. Then \(\Phi\) must obey some rules to be a \(\mathbf{Cost}\)-enriched functor. What are these rules? What do they mean concretely in terms of trips between cities?

And here are some easier ones:

**Puzzle 186.** Are the graphs we used above to describe the preorders \(A\) and \(B\) Hasse diagrams? Why or why not?

**Puzzle 187.** I said that \(\infty\) plays the same role in \(\textbf{Cost}\) that \(\text{false}\) does in \(\textbf{Bool}\). What exactly is this role?

By the way, people often say **\(\mathcal{V}\)-category** to mean \(\mathcal{V}\)-enriched category, and **\(\mathcal{V}\)-functor** to mean \(\mathcal{V}\)-enriched functor, and **\(\mathcal{V}\)-profunctor** to mean \(\mathcal{V}\)-enriched profunctor. This helps you talk faster and do more math per hour.