Intuition behind $T$-algebras

642 Views Asked by At

The definition of a $T$-algebra on a monad seems random to me. Can anyone shed some light on it? This is the inuition I have behind monads.

2

There are 2 best solutions below

0
On BEST ANSWER

Let $(T,\mu,\eta)$ be a monad on the category of sets and let $(X, f: T(X) \to X)$ be a pair where $X$ is a set and $f$ is a map of sets. I think of $T(X)$ as the set of free/formal expressions of "type $T$" that we can build using elements of $X$. Stated otherwise, $T(X)$ is the synax we can build using elements of $X$ as variables. The map $f$ then is a procedure that builds an element of $X$ from a free expression of "type $T$". Stated otherwise, $f$ interprets syntactic expressions as elements of $X$.

We can think of it as an evaluation of the expressions, e.g. $2 + 3$ is an expression built from natural numbers and $f(2+3) = 5$ is the element it evaluates to, 5 is what $2 + 3$ means inside of natural numbers.

Saying that $(X, f: T(X) \to X)$ is a $T$-algebra is asking for $f$ to be compatible with $\mu$ and $\eta$ :

  • First $\eta_X : X \to T(X)$ builds a free/formal expression from an element of $X$. For $x \in X$, think of $\eta_X(x)$ as the "atomic" expression "$x$". Then the axiom asking $f(\eta_X(x)) = x$ for all $x\in X$ is saying that an atomic expression evaluates to the element it is built from. $\eta_X(x)$ is the symbol "$x$", and $f$ interprets it as the element $x$.
  • $\mu_X : T(T(X)) \to T(X)$ is a procedure that forms a free expression from free expressions on free expressions. Then the axiom $f \circ T(f) = f \circ \mu_X$ corresponds to the fact that when you have a free expression of free expressions, if you build a free expression using $\mu_X$ and then evaluate it (right hand side of the equation), it gives the same result that building the free expression from the evaluation of the free expressions, and then evaluating it.

My favourite example, and the one that made me understand it is using the monad of vector spaces :

Suppose $(T,\mu,\eta)$ is the monad of $K$-vector spaces on sets. If $X$ is a set, then $T(X)$ is the set of formal finite linear combinations of elements of $X$, say $a_1 \cdot x_1 + \cdots + a_n \cdot x_n$ where the $a_i$'s are in $K$ and $n \in \mathbb{N}$. If I have a map $f : T(X) \to X$, I have a way to interpret $a_1 \cdot x_1 + \cdots + a_n \cdot x_n$ as an element of $X$, so $f$ gives a way to interpret "$+$" and "$\cdot$" inside of $X$ !

If further more $f$ verifies the axioms of a $T$-algebra I have the following :

  • $\eta_X : X \to T(X)$ is the map that builds atomic expressions : $\eta_X(x)$ is the expression $x$ or $1 \cdot x$ if you prefer. Then the expression $x$ evaluates to the element $x$, all is good !
  • Say I have an element in $T(T(X))$, for example something like $$ b_1\cdot(a_{1,1} \cdot x_{1,1} + \cdots + a_{1,n_1} \cdot x_{1,n_1} ) + \cdots + b_m \cdot(a_{m,1} \cdot x_{m,1} + \cdots + a_{m,n_m} \cdot x_{m,n_m} ) $$ Then the second axiom gives that interpreting first the bits $a_{k,1} \cdot x_{k,1} + \cdots + a_{k,n_k} \cdot x_{k,n_k}$ as $y_k$ and then interpreting $b_1 \cdot y_1 + \cdots + b_m \cdot y_m$ is the same thing as building the expression $$(b_1a_{1,1}) \cdot x_{1,1} + \cdots + (b_1a_{1,n_1}) \cdot x_{1,n_1} + \cdots + (b_m a_{m,1}) \cdot x_{m,1} + \cdots + (b_m a_{m,n_m}) \cdot x_{m,n_m} $$ and then interpreting it again ! This is associativity and distributivity of "$+$" and "$\cdot$".

So to sum things up, $f:T(X) \to X$ is a way to interpret pure syntactic objects (the elements of $T(X)$) inside of $X$. And then a $K$-vector space (or $T$-algebra) is a set $X$ where finite $K$-linear combinations have an internal meaning that is compatible with the syntactic rules of linear combinations (given by $\mu$ and $\eta$).

0
On

I'll try to offer the intuitions I use to understand Eilenberg-Moore algebras; hopefully it is not too idiosyncratic to be helpful. There are two, in my mind, archetypal examples of algebras on monads, both coming from monoids (for the Cartesian monoidal structure on $\mathsf{Set}$).

The first example is monoid actions $f:M\times X\to X$. If we take $\eta_X:X\to M\times X$ as $x\mapsto\langle e,x\rangle$ and $\mu_X:M\times M\times X\to M\times X$ to be $\langle m,n,x\rangle\mapsto\langle mn,x\rangle$, then the usual way of saying that $f:M\times X\to X$ is an $M$-action is precisely the same as saying that it's an algebra for $\langle M\times-,\eta,\mu\rangle$. So we can think of $T$-algebras as some kind of "generalized monoid action," where the "monoid" may be something more abstract than an ordinary monoid.

The other is the algebras of the monad $\langle (-)^*,\eta,\mu\rangle$ on $\mathsf{Set}$, where $X^*$ is the set of finite sequences of elements of $X$, $f^*:X^*\to Y^*$ takes a sequence $\langle x_1,\ldots,x_n\rangle$ to the sequence $\langle f(x_1),\ldots,f(x_n)\rangle$, $\eta_X$ is the inclusion of $X$ as the subset of length 1 sequences, and $\mu_X$ is concatenation of sequences. Here, the algebras are essentially a different presentation of monoids. An algebra $f:X^*\to X$ is the monoid operation extended to finite sequences instead of just ordered pairs; $f\circ\mu_X=f\circ (f)^*$ says that the operation is associative (in a way that extends to the arbitrary arity of $f$); and $f\circ\eta_X=id_X$ says that $f(\langle x\rangle)=x$, implying, in the context of the other condition, that there's a unit element.

Generalizing from this second example, we can think of $f:TX\to X$ as giving us an operation of "abstract arbitrary arity" on $X$, that has to obey certain niceness conditions (the operation on a "unary" input just gives you back that input, and it's "associative" in a generalized sense). The monad is the thing that tells us just what being "unital and associative" means for this "abstract arity".

These are, of course, imperfect ways of conceptualizing $T$-algebras, since there are a lot of monads whose algebras do not, concretely, look much like monoids or monoid actions; but they are motivating examples where the $T$-algebra structure is a reasonably natural way to describe fairly ordinary mathematical objects, and where "associative" and "unital" can be taken fairly literally.