User:Michiexile/MATH198/Lecture 8

From HaskellWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

IMPORTANT NOTE: THESE NOTES ARE STILL UNDER DEVELOPMENT. PLEASE WAIT UNTIL AFTER THE LECTURE WITH HANDING ANYTHING IN, OR TREATING THE NOTES AS READY TO READ.


Algebras over monads

We recall from the last lecture the definition of an Eilenberg-Moore algebra over a monad :

Definition An algebra over a monad in a category (a -algebra) is a morphism , such that the diagrams below both commute:

EilenbergMooreUnity.png EilenbergMooreAssociativity.png

While a monad corresponds to the imposition of some structure on the objects in a category, an algebra over that monad corresponds to some evaluation of that structure.

Example: monoids

Let be the Kleene star monad - the one we get from the adjunction of free and forgetful functors between Monoids and Sets. Then a -algebra on a set is equivalent to a monoid structure on .

Indeed, if we have a monoid structure on , given by and , we can construct a -algebra by

This gives us, indeed, a . Associativity and unity follows from the corresponding properties in the monoid.

On the other hand, if we have a -algebra structure on , we can construct a monoid structure by setting

It is clear that associativity of follows from the associativity of , and unitality of follows from the unitality of .

(((potential headache: shouldn't show up more? Instead of the empty list, maybe?)))

Example: Vector spaces

We have free and forgetful functors

forming an adjoint pair; where the free functor takes a set and returns the vector space with basis ; while the forgetful functor takes a vector space and returns the set of all its elements.

The composition of these yields a monad in taking a set to the set of all formal linear combinations of elements in . The monad multiplication takes formal linear combinations of formal linear combinations and multiplies them out:

A -algebra is a map that acts like a vector space in the sense that .

We can define and . The operations thus defined are associative, distributive, commutative, and everything else we could wish for in order to define a vector space - precisely because the operations inside are, and is associative.


The moral behind these examples is that using monads and monad algebras, we have significant power in defining and studying algebraic structures with categorical and algebraic tools. This paradigm ties in closely with the theory of operads - which has its origins in topology, but has come to good use within certain branches of universal algebra.

An (non-symmetric) operad is a graded set equipped with composition operations that obey certain unity and associativity conditions. As it turns out, non-symmetric operads correspond to the summands in a monad with polynomial underlying functor, and from a non-symmetric operad we can construct a corresponding monad.

The designator non-symmetric floats in this text o avoid dealing with the slightly more general theory of symmetric operads - which allow us to resort the input arguments, thus including the symmetrizer of a symmetric monoidal category in the entire definition.

To read more about these correspondences, I can recommend you start with: the blog posts Monads in Mathematics here: [1]


Algebras over endofunctors

Suppose we started out with an endofunctor that is not the underlying functor of a monad - or an endofunctor for which we don't want to settle on a monadic structure. We can still do a lot of the Eilenberg-Moore machinery on this endofunctor - but we don't get quite the power of algebraic specification that monads offer us. At the core, here, lies the lack of associativity for a generic endofunctor - and algebras over endofunctors, once defined, will correspond to non-associative correspondences to their monadic counterparts.

Definition For an endofunctor , we define a -algebra to be an arrow .

A homomorphism of -algebras is some arrow such that the diagram below commutes:

EilenbergMoorePMorphism.png

This homomorphism definition does not need much work to apply to the monadic case as well.

Example: Groups

A group is a set with operations , such that is a unit for , is associative, and is an inverse.

Ignoring for a moment the properties, the theory of groups is captured by these three maps, or by a diagram

GroupDiagram.png


Homework

  1. Find a monad whose algebras are associative algebras: vector spaces with a binary, associative, unitary operation (multiplication) defined on them. Factorize the monad into a free/forgetful adjoint pair.
  2. Find an endofunctor of whose initial object describes trees that are either binary of ternary at each point, carrying values from some in the leaves.
  3. Write an implementation of the monad of vector spaces in Haskell. If this is tricky, restrict the domain of the monad to, say, a 3-element set, and implement the specific example of a 3-dimensional vector space as a monad. Hint: [2] has written about this approach.