You're reading the public-facing archive of the Category Theory Zulip server.
To join the server you need an invite. Anybody can get an invite by contacting Matteo Capucci at name dot surname at gmail dot com.
For all things related to this archive refer to the same person.
I just noticed something interesting. The List monad on sets, also known as the free monoid monad, is characterized by an "algebraic" or "inductive" universal property - given a set , to explain where to send a list of elements , we can go by recursion - it suffices to explain where to send the head of the list and the tail of the list, as well as the empty list. So we have a concatenation map and a distinguished empty list , and this is initial among sets with maps and distinguished element . Initial algebra, defines a monad.
Now if we dualize everything and consider maps instead of maps , and look at the terminal object in this category, we get the set of streams in , which are finite or infinite sequences of elements of . This, again, forms a monad on the category of sets, which I find a bit surprising - the list monad is a sub-monad of a larger stream monad containing infinite streams, and the universal property of these objects is a coalgebraic one.
I think this works when you consider trees of fixed arity, too. More specifically if you fix a set representing the arity, and for each set consider the initial algebra of the endofunctor , you should get a monad on sets which are roughly trees with interior nodes in with arity and leaves in . But also if you consider the terminal coalgebra of this same endofunctor you get another monad, containing the first one as a submonad.
What is going on here? Why is this coalgebraic structure giving rise to algebraic structure?
Do you need to fix the arity? I think in general with a signature , the initial algebra is the set of well-founded (rooted) trees internally labelled in and the final coalgebra is the set of all trees internally labelled in .
Probably not, it's just that the example that led me to think about this was the set of trees of fixed arity.
Well, actually, I think we might be talking about something slightly different. I'm assuming you mean the monad which sends a set to the set of all terms in the signature with variables drawn . That's not really what I have in mind here, I think. For example, if has a binary multiplication and a unit , then the list monad is a quotient of by the usual relations asserting that is associative and is a two-sided unit. But i'm not aware of a way to express lists of elements in directly as the set of valid terms in a signature in this way.
Put more simply, in the elements of appear only at the leaves of the trees. In my version the elements of are labels for the interior nodes.
plays the role of the signature, and all symbols in have the same given arity ; then we consider all trees with variables drawn from the set .
If you let contain the symbol with arity for every and a constant ( -ary) for every , that works right? The set of terms over the empty set is the initial algebra.
For lists, the terms you get are stuff like and , which are lists (without imposing equations).
I think there's a level slip in this discussion that goes a long way to explaining the phenomenon itself. The initial algebra/terminal coalgebra semantics happens on the level of a functor on Set where you take an initial or terminal fixpoint, and the being-a-monad happens on the level of an extra parameter you have that decides which functor you take the fixpoint of.
In general if you have a bifunctor and taking the initial algebra in the second variable gives you a monad, then the unit and multiplication may extend to . The unit always extends because there's a canonical map from the initial algebra to the terminal coalgebra, which comes from the fact that each of them also carries a structure of the other type.
However, the extension of the multiplication is much trickier and List/Colist is a pathological example. The multiplication extends to a function in but there's no way to define this function in the programming languages this stuff is usually used as a model of. The problem is when there's an infinite tail of empty colists. The only thing you can really do with this is map it to , however there's no way to write a function in a programming language that can inspect the infinitely many empty colists and decide to return that.
The other example is even worse. Say you have a cotree with an infinite path, and each node along the path contains a leaf, the element of that indicates the next node on the path. Then the correct thing to do in a situation like this is to return the leaf in the upper cotree where the path stops. But the path never stops at a leaf, there is nothing to return. In the special cases where is empty (the terminal monad either way) or a singleton (List/Colist) we can avoid the problem or hack around it because there's only (at most) one possible leaf, but in general this sinks the project entirely.
(Even List/Colist doesn't actually work as a monad: take a colist with first element an infinite colist of empty colists, and second element a singleton with another singleton inside. If you apply to the outer levels first you get an empty colist, and if you apply it at the inner levels first you get a singleton; this breaks the associative law.)
Something that is probably an example is the monad of nonempty lists/monad of nonempty colists.
(Nonempty lists are the initial algebras for the family of functors .)
Finite/potentially-infinite -branching trees with an element of the carrier at internal nodes and an element of at leaves, and at least one internal node, are probably another example, but expressing them as an initial algebra/final coalgebra is tricky at best, and I'm not sure it's even possible using a single outer fixpoint and no indexing.
I guess it's possible: .
Ralph Sarkis said:
If you let contain the symbol with arity for every and a constant ( -ary) for every , that works right? The set of terms over the empty set is the initial algebra.
For lists, the terms you get are stuff like and , which are lists (without imposing equations).
This is what I had in mind in the previous message, yes. But I am interested in a monad which I call the "list monad" or "free monoid monad" whose underlying functor accepts and returns this tree constructed in terms of and . You are describing a different monad with a different underlying functor which is defined in terms of and has a different unit and different multiplication, and it happens that .
James Deikun said:
However, the extension of the multiplication is much trickier and List/Colist is a pathological example. The multiplication extends to a function in but there's no way to define this function in the programming languages this stuff is usually used as a model of. The problem is when there's an infinite tail of empty colists. The only thing you can really do with this is map it to , however there's no way to write a function in a programming language that can inspect the infinitely many empty colists and decide to return that.
This is a good observation! The language I have in mind is Turing complete and so realistically, the semantics of this would be that it diverges/loops infinitely when trying to flatten the infinite stream of empty lists.
I see, I was thinking only of the relation between initial algebra and final coalgebra, not the between the monads.