Coalgebras, Comonads, and Distributive Laws

Updated: 2016-11-19

In my current project investigating the categorical semantics of attack trees we are using distributive laws to compose comonads that model various structural rules – weakening, contraction, exchange, etc – in linear logic. During the QA section of my talk at Linear logic, mathematics and computer science – see my post on my talk and the workshop for more details – Paul-André Melliès suggested using adjunctions to compose the structural rules instead of distributive laws for the obvious reason that they really compose as opposed to monads/comonads. I told him that I did try to this initially, but was not able to get it working. He was nice enough to talk with me a bit and gave me some hints to how it works which are based on a paper of his.

Instead of just looking up the details in his paper I wanted to see if I could recreate his result with his hints. I often do this for learning purposes. So that’s what I did during my flight back from France. I figured why not make it a blog post. Keep in mind that this result is due to Paul-André, but I had a lot of fun recreating his steps.

I plan to write a follow up post describing how this result can be used to to create various adjoint models of linear logic, but here we show that when we have two comonads on a category with a distributive law, then those comonads in addition to their composition can be decomposed into a composition of adjunctions between their coalgebras.

Suppose (k,ε,δ) is a comonad on a category L. Then it is well known that it can be decomposed into the following adjunction:

where U:LkL is the forgetful functor, F:LLk is the free functor, and k=UF:LL.

Now suppose we have the following adjunctions:
Then they can be composed into the adjunction:

Keep in mind that this gives rise to a comonad HFGJ:L1L1.

We are going to use these two facts to compose comonads using adjunctions. Suppose we have the comonads (k1,ε1,δ1) and (k2,ε2,δ2) both on a category L with a distributive law – distributive laws for comonads are defined to be the opposite of the distributive laws for monadsdist:k2k1k1k2. Thus, making k2k1:LL a comonad.

Then we can decompose k1 into a an adjunction:

Here we know that k1=U1F1:LL, but we also know something about k2. We can extend it to a comonad on Lk1.

First, we define the functor k~2:Lk1Lk1 to send objects (A,hA) to (k2A,hA), where hA:=k2Ak2hAk2k1AdistAk1k2A, and to send morphisms f:(A,hA)(B,hB) to the morphism k2f:(k2A,hA)(k2B,hB). We must show that k2f:k2Ak2B is a coalgebra morphism, but the following diagram commutes:

The top diagram commutes because f is a coalgebra morphism and the bottom diagram commutes by naturality of dist. Since the morphism part of k~2 is defined using the functor k2 we know k~2 will respect composition and identities.

We now must show that k~2 is a comonad. The natural transformation ε2~:k~2Id has components ε2~(A,hA)=εA2:k~2(A,hA)(A,hA). We must show that εA2 is a coalgebra morphism between k~2(A,hA)=(k2A,k2hA;distA) and (A,hA), but this follows from the following diagram:

The top diagram commutes by naturality of ε2 and the bottom diagram commutes by the conditions of the distributive law. Naturality for ε2~ easily follows from the fact that it is defined to be ε2.

The natural transformation δ2~:k2~k2~k2~ has components δ2~(A,hA)=δA2:k2~(A,hA)k2~k2~(A,hA). Just as above we must show that δA2:k2Ak22A is a coalgebra morphism between k2~(A,hA)=(k2A,k2hA;distA) and k2~k2~(A,hA)=(k22A,k2hA;k2distA;distk2A), but this follows from the following diagram:

The top diagram commutes by naturality of δ2 and the bottom diagram commutes by the conditions of the distributive law.

It is now easy to see that ε2~ and δ2~ make k2~ a comonad on Lk1, because the conditions of a comonad will be inherited from the fact that ε2 and δ2 define a comonad on L.

At this point we have arrived at the following situation:
Since we have a comonad k2~:Lk1Lk1 we can form the following adjunction:

The functor F2(A,hA)=(k2~(A,hA),δ2~(A,hA)) is the free functor, and U2(A,hA)=A is the forgetful functor. Thus, we can think of (Lk1)k2 as the world with all the structure of L extended with all of the structure k1 brings and all the structure k2 brings. That is, (Lk1)k2 is the algebras of k2k1:LL.

We can see that the previous two adjunctions compose:
Thus, we have a comonad U1U2F2F1:LL. Chasing an object through this comonad yields the following:
U1U2F2F1A=U1U2F2(k1A,δA1)=U1U2(k2~((k1A,δA1)),δ2~(k1A,δA1))=U1U2((k2k1A,k2δA1;distk1A),δ2~(k1A,δA1))=U1(k2k1A,k2δA1;distk1A)=k2k1A

Therefore, the above adjunction gives back the composition k2k1:LL.

This result only works because we have a distributive law, but the distributive law is only used in the the definition of the structural map of the coalgebras. This result reveals a means that will allow us to abandon distributive laws in favor of adjunctions in the spirit of Benton’s LNL models, however, doing so comes with some different difficulties. Stay tuned!


Leave a comment by sending me an Email