Doubles for Monoidal Categories
Posted by John Baez
guest post by Fosco Loregian and Bryce Clarke
This post belongs to the series of the Applied Category Theory Adjoint School 2019 posts. It is the result of the work of the group “Profunctor optics” led by Bartosz Milewski, and constitutes a theoretical preliminary to the real meat, i.e. the discussion of Riley’s paper Categories of Optics by Mario Roman and Emily Pillmore (hi guys! We did our best to open you the way!)
In the following post, we first introduce you to the language of co/ends. Then we deconstruct this paper by Pastro and Street:
- Craig Pastro and Ross Street, Doubles for monoidal categories, Theory and Applications of Categories 21 4 (2008), 61–75.
Our goal is to make its main result (almost) straightforward: Tambara modules can be characterized as particular profunctors, precisely those that interact well with a monoidal action on their domain. For a fixed category , these endoprofunctors form the Kleisli category of a monad on .
Coend calculus
Coend calculus rules the behaviour of certain universal objects associated to functors of two variables ; intuitively, stands to as the limit of stands to ; the major difference is that takes into account the fact that eats at the same time two “terms” of the same “type” , once covariantly in the second component, and once contravariantly in the first: on arrows the functor acts in fact as follows:
Now, a distinguising feature of the objects that depend contra-covariantly on the same variable is that they can be integrated: given a sufficiently regular function , its dependence from can be thought as “covariant” (and defined, say, on a topological vector space ), whereas the “” in the symbol is contravariant (it belongs to a certain dual space of covectors on ); altogether, the integral can be thought as exhibiting a contra-covariant dependence from .
Ends and coends are associated to functors in a similar fashion that resembles integration: they are certain objects (the end) and (the coend), canonically associated to , treating as a mute variable (meaning that and are the same object), and satisfying a “commutative rule of integrals” analogous to The end of is endowed with projections on the “symmetrized components” , one for each object ; dually, the coend is endowed with injections .
All in all, this happens also for colimits, so the two constructions are -at least intuitively- tightly related: this intuition can of course be made more precise. Every universal object built in category theory can be thought either as a subobject of a product (a limit), or as a quotient of a coproduct (a colimit), and co/ends make no exception:
- An end arises as an “object of invariants” for the action of given by the functions on arrows , and it is defined as the subobject of of those elements invariant under this action.
- Dually, a coend arises as a “quotient space” of by a suitable equivalence relation generated by the same functions , i.e. as a space of orbits for the action.
More on this will be explained later on in the discussion.
What is more important now, and quite astounding, is that such contra-covariant actions arise at every corner of category theory: using co/ends it is possible to re-state the Yoneda lemma and the theory of Kan extensions, and to find plenty of applications to algebra, topology, geometry… and functional programming. :-)
Dinaturality
As already said, a functor acts on morphisms as
given two such functors, say , we can consider the two diagrams
and
Given two functors a natural transformation can be seen as a family of maps that “fill the gap” between and in a commutative square; in a similar fashion, a dinatural transformation between the above can be seen as a way to close a certain diagram that testifies a transformation from the arrow action of to the arrow action of :
Just as co/limits are defined via suitable transformation to/from a constant, so are co/ends:
If , a wedge for with base consists of a dinatural transformation from the constant functor on , i.e. of a family of morphisms such that for each the above hexagon reduces to a commutative square:
If , a cowedge for with tip consists of a dinatural transformation to the constant functor on , i.e. of a family of morphisms such that for each the above hexagon reduces to a commutative square:
There exists a category of wedges, defined with an obvious choice of morphisms between bases; similarly, there is a category of cowedges .
The end of is now defined as a terminal object in the category of its wedges; dually, the coend of is the initial object of the category of its cowedges. Of course, we say “the” end because such an initial object is unique up to unique isomorphism when it exists.
So far, so good. In fact, we didn’t stray much far from plain old category theory, as it is possible to show the following:
Lemma (co/ends are colimits): Given there exist a category and a functor such that For those who know: the end of is the weighted colimit of with the functor , and thus the category is nothing more, nothing less than the category of elements of ; this allows for a very explicit presentation of :
- objects: the arrows of , ;
morphisms: the commutative squares
Corollary (hom commutes with all ends): As a consequence of the fact that is a limit, there is an isomorphism natural in . Dually, natural in .
(of course, a coend is just an end in the opposite category!)
But why are co/ends denoted as integrals? The notation dates back to Yoneda,
Yoneda, Nobuo. “On Ext and exact sequences.” J. Fac. Sci. Univ. Tokyo Sect. I 8.507-576 (1960): 1960.
(in particular, see §4 but beware that the notation is reversed; a coend is called an integration and denoted and an end is called a cointegration!); all the discussion and terminology is essentially motivated by the fact that an end behaves like an integral:
Theorem (Fubini rule): Let be a functor; then in the sense that if one of the three objects exists, so do the other two, and they are all canonically isomorphic (the category is of course equal to ). Similarly, there is such a rule for ends.
Thus, in category theory integration is “as commutative as it can be”; it can happen in whatever order we desire: given a permutation of the set , whenever is a functor of variables of the form , and the integral exists, then so does Proof. Sending a functor to its coend is a functor , and it is easy to see that it is a left adjoint (for those who know, is a particular kind of weighted colimit, and every such weighted colimit admits a right adjoint expressed in terms of the weight): now it’s easy to prove that these right adjoints commute, i.e. thus yielding the Fubini rule by uniqueness of adjoints.
The building blocks of co/end calculus
Here we explore how co/ends allow to rediscover category theory from scratch.
Natural transformations
Theorem (Natural transformations as an end) Let be two functors; then, there is an isomorphism Proof. There is a natural choice for a wedge , that sends a natural transformation to its -component; it remains to show that this is indeed a terminal wedge. Given another wedge , the wedge condition translates into the equation
valid for every ; but this is only a convoluted way to say that for every the family is a natural transformation.
Two important remarks:
In an additive setting, the wedge condition for can be easily translated into the fact that natural transformations appear form the kernel of a certain map; the intuition that naturality is a cocycle condition is more or less what led Yoneda to study ends and coends in homological algebra.
Even in a non-additive setting, one can easily see that a natural transformation is a map that equalizes the action of on arrows; this means that the following diagram is an equalizer; there is nothing special here, as for every functor there is a similar equalizer diagram
Here’s a discussion on what is the coend of the hom functor; I claim that the following object represents the coend of , perhaps you know where the same object appears under a different name, and where it is used for some purpose? I find this particularly intriguing in the case of a monoid regarded as single-object category:
- the end of is the center of the monoid, i.e. the subset ;
- the coend of corresponds to something like the of the monoid.
I didn’t expect these construction to be dual, and yet they are!
Claim (but also: exercise for the reader). Let be a small category. The coend is the set of connected components of the “endo-comma” category whose objects are endomorphisms of , and whose morphisms are the such that . More generally, if are functors there is an isomorphism where the endomorphism comma is defined similarly.
Compare this example with the following: let be an associative algebra, and let us consider it as a category with a single object; then the co/end of its hom functor correspond to the 0-th Hochschild co/homology of ! People in algebraic geometry, especially the Russian school of DG-categories love this kind of results!
It would be awesome to recover higher homotopy and co/homology of geometric objects as coends: any ideas?
The Yoneda lemma and Kan extensions
On the first day He created the Yoneda lemma, and He saw that it was good:
Theorem (The ninja Yoneda lemma) Let ; then for every object , Proof. The set is the set of natural transformations from to , and thus the non-ninja Yoneda lemma yields an isomorphism between this set and . Dually, call the functor Then, we have Each of these steps can be easily justified in light of what we already proved:
- the fact that the hom functor preserves ends;
- the Fubini rule for ends;
- the fact that the set of natural transformations between two functors is an end.
This natural deduction-style kind of proof is half-jokingly called “coend-fu” in my note, soon-ish a book, on coends.
Incidentally, the isomorphism is precisely the sense in which “every presheaf is a colimit of representable functors”; the colimiting diagram has domain the category of elements of , and the natural functor has colimit .
On the second day, He created Kan extensions, and category theory was complete.
Theorem (Kan extensions are co/ends) Let be a span of functors; if the coend exists, then it is the value at of the left Kan extension of along ; dually, is the end exists, then it is the value at of the right Kan extension of along .
Proof. The proof is another lengthy, but completely straightforward, kata using the coend-fu we already know:
Bimodules
The paper that we want to discuss today makes heavy use of the theory of bimodules. Let’s dig deeper into their structure. First of all, let us define a bicategory as follows:
- objects are (unitary) rings
- 1-cells are modules , left over and right over .
- 2-cells are --linear homomorphisms of modules.
The composition of 1-cells is the tensor product of modules:
- is a --bimodule for every -bimodule and every --bimodule (so in particular this is not a strict 2-category);
- 2-cells are composed horizontally and vertically, using the obvious function composition, and bifunctoriality of the operation.
So far so good! There is a 2-categorical characterization of modules.
What is it good for? Well: rings are monoids in the category of abelian groups. We could have done the very same thing taking (plain) monoids, i.e. monoids in the category of sets, and defining a category of “bimodules” as sets with a left action of some monoid, and a right action of some other monoid.
But we can also generalize the same construction, with no additional cognitive loading, and take to be multi-object monoids (i.e. categories): we define a bicategory as follows:
- objects are categories
- 1-cells are functors
- 2-cells are natural transformations between functors.
A functor is a multiobject module on which the multiobject monoids act.
So categories really are monoids, and are also eager to act on sets.
A bimodule is also called a profunctor, a distributor, a correspondence, a span,… and possibly with many other names; each name comes from a certain intuition behind their nature that leads to the definition of the same bicategory:
- they are called profunctors because they generalize functors: some profunctors are called representable, and they are the ones of the form for some functor between categories. A pro-functor thus works “on behalf of a functor”, as well as a relation generalizes a function.
- …which is why some people prefer to call them relators: just as a func-tion is a special kind of rela-tion, a func-tor is a special kind of rela-tor.
they are called distributors: as the nLab says,
Jean Bénabou, who invented the term and originally used “profunctor”, now prefers “distributor”, which is supposed to carry the intuition that a distributor generalizes a functor in a similar way to how a distribution generalizes a function.
There’s in fact a beautiful story about this: Lawvere defined a notion of distribution between toposes, such that the points of a topos behave like Dirac delta functions, and such that distributions between presheaf toposes are exactly profunctors.
they are called correspondences or spans because of the Grothendieck construction: every presheaf has a category of elements that in this case is a discrete fibration over , and composing with the projections, this is a span .
Well… until now we cheated a bit. In order to get a bicategory we need to define a composition law for 1-cells and show that it is bifunctorial, and I didn’t tell you how to do it: but it turns out it is really easy, if you know coend-fu! Indeed, the intuition of a bimodule as a “matrix indexed by its domain” and the rule to compose two relations guide us to find an expression to meaningfully compose . We can define This boils down, on discrete domains to a “matrix product of sets” like There is also a connection between the ways in which profunctors compose, and the way in which relations do. Indeed, look how the two concepts closely resemble each other: A final list of remarks, to address the many questions you might have at this point:
- Yes! The dictionary between relations and profunctors can be extended very far: try to check when a relation is a function; how does this condition translates into the one telling when a profunctor is a functor?
- Yes, you can make the dictionary a precise theorem by saying that sets are discrete categories, or even more precisely categories enriched over truth values, and that relations are precisely the -enriched version of profunctors, as they are functions !
Doubles for monoidal categories
One of the key results of the paper Doubles for Monoidal Categories is the canonical equivalence of categories:
This theorem has since been labelled by some as the “fundamental theorem of optics”, as it provides the link between the category of Tambara modules and the double of the monoidal category , now also known as the category of optics. To unpack this theorem, we first begin with the definition of a Tambara module.
Tambara modules
The category of (bi)modules forms a bicategory, however when we choose a particular category we may instead consider the monoidal category whose:
- objects are endomodules ;
- morphisms are natural transformations;
- monoidal product is module composition: One may ask the question: what if has the structure of a monoidal category?
Definition: Let be a monoidal category. A (left) Tambara module on is a pair consisting of:
- a profunctor ;
- a family of functions called the Tambara structure maps, which are natural in and dinatural in , satisfying the equations:
The idea is that the structure maps tell you how the profunctor changes under the monoidal action. For example, if we consider the hom-profunctor on the monoidal category , then the Tambara structure would tell you to take a function in to in for any set .
Tambara modules form the objects of a category , whose morphisms are natural transformations such that . There is functor to the category of endomodules on , which forgets the Tambara structure (this functor is actually strong monoidal, but that won’t be important for what follows).
An adjoint triple for Tambara modules
The forgetful functor forms part of an adjoint triple:
This adjoint triple captures almost everything you need to know about Tambara modules in order to derive the category . For the following, let be a monoidal category and be an endomodule.
The right adjoint outputs the cofree Tambara module consisting of:
- a profunctor whose action on objects is given by the end:
- Tambara structure maps which are induced by the projection functions, using the universal property of the end.
The left adjoint outputs the free Tambara module consisting of:
- has action on objects given by the coend:
Tambara structure maps which are induced, using the universal property of the coend, by the function (via functorality of the hom-functor),
composed with the coprojection into .
The adjunction yields a comonad denoted and the adjunction yields a monad denoted .
Proposition: The category of Tambara modules is isomorphic to the category of coalgebras for and the category of algebras for the monad .
The proof is a nice exercise in the universal property for (co)ends. For example, a coalgebra for the comonad consists of:
- An object of given by .
- A struture map given by a morphism in whose components are given by: However using the universal property of the end, the structure map is determined exactly by a family of morphisms dinatural in : Therefore the data for a -coalgebra corresponds to a Tambara module .
The double of a monoidal category
The adjoint triple induces an adjunction,
between the resulting monad and comonad . A basic result in category theory states that any left adjoint functor between categories of presheaves is equivalent to a profunctor. Therefore recalling that by definition, the left adjoint above is equivalent to an endomodule whose action on objects is given by the coend: This endomodule actually underlies a monad in the bicategory of modules (also known as a promonad). Furthermore it is known that the bicategory admits the Kleisli construction for promonads.
Definition: The double of a monoidal category is the Kleisli category for the promonad on .
The category has the same objects as and hom-sets given by the previous coend: While this may seem like a fairly abstract definition, it has concrete applications in describing a variety of optics used in functional programming. Taking the example again, we see that a morphism in from to is an element of the set: That is, a morphism is a pair of functions and , which is exactly the data for the optic known as a lens.
We are now ready to state the central theorem of the paper.
Theorem: There is an equivalence of categories: While the proof is outside the scope of this post, we note it essentially follows from universal property of the Kleisli category for a promonad.
Re: Doubles for Monoidal Categories
Thanks for the post. I’m just trying to match up your explicit description of the hom-sets with the one in Pastro-Street (top of Sec 6). It’s different. Is something back-to-front? and is it supposed to be what they call ?