Cours 6: Algebraic theories

Free monads

Pointed set:

a set $A$ equipped with an element

One should think of $\ast$ as a $0$-ary operation $1 = A^0 ⟶ A$.

$n$-ary operation:

element of $A^n ⟶ A$


  • set equipped with binary operation $A^2 ⟶ A$
  • with associativity law: $m(m(x, y), z) = m(x, m(y, z))$

Partiality monad: $1+A$ ⟺ the “free pointed set” monad

Algebraic theories

A signature $Σ$:

is a family $(Σ_n)_{n∈ℕ}$ of sets

An element $f∈Σ_n$ is called an “operation of arity $n$”

f ∈ Σ_2 \quad f(f(x, y), f(f(x, y), y))
A term of a signature $Σ$ with variables in $X$:

is a finite tree of which nodes are the operations of $Σ$ and leaves are in $X \sqcup Σ_0$

NB: notation: $Term(Σ, X)$

An algebraic theory of signature $Σ$:

is a family of pairs $(t, n)$ (also written $t = u$)

  • $X = \lbrace x_0, ⋯, x_n \rbrace$
  • $t ∈ Term(Σ, X)$
  • $u ∈ Term(Σ, X)$
Given a set $X$ of variables and algebraic theory:
T(X) = Term(Σ, X)/\sim

where $\sim$ is the equivalence relation generated by the equations of the theory

Ex: The algebraic theory of monoids

  • $Σ_2 = \lbrace m \rbrace$
  • $Σ_0 = \lbrace e \rbrace$

  • Signature:

    • $Σ_n = ∅$ for $n ≠ 0, 2$
    • $Σ = \lbrace m:2, e:0 \rbrace$
  • Equations:

    • associativity: $m(m(x, y), z)$
    • unit laws: $m(e, x) = x = m(x, e)$

In the case of the algebraic theory of monoids:

T(X) = \left\lbrace \text{trees generated by m, e with leaves in X} \right\rbrace / \text{assoc, unit laws} \\ = \lbrace \text{finite words on } X \rbrace = \bigsqcup_{n∈ℕ} A^n

Ex: Magmas


a set equipped with a binary operation $m: A^2 ⟶ A$

(no associativity, no unit)

T(X) = \lbrace \text{binary trees with leaves in } X\rbrace = Term(Σ, X)
Commutative monoids:
m(x, y) = m(y, x)
T(X) = \lbrace \text{finite multiset on the alphabet } X \rbrace

Th: algebraic theory defines a monad $T: Set ⟶ Set$ in that way

η: \begin{cases} A &⟶ TA \\ a &⟼ \text{the equivalence class of } a ∈ Term(Σ, A) \end{cases}


μ: TTA ⟶ TA

natural in $A$.

An element of $T(TA)$:

is a tree of signature $Σ$ with leaves in $TA$ (and also in $Σ_0$) modulo the equations of the algebraic theory.

For every such leaf $[t_i] ∈ TA$, one can pick an element $t_i ∈ Term(Σ, A)$ such that $[A_i]$ is the equivalence class of $t_i$

Substitute $t_1, ⋯, t_n$ in the tree $A ∈ Term(Σ, TA)$ to obtain $t[t_1, ⋯, t_n] ∈ Term(Σ, A)$

The equivalence class [\;\underbrace{t[t_1, ⋯ , t_n]}_{∈ Term(Σ,A)}\;] ∈ T(A)

does not depend on the choice of $t_1, ⋯, t_n$ but only on their equivalence classes

[t] ∈ TTA, \quad [t_i]∈ TA

Algebraic theory of the commutative rings

Σ = \lbrace 0: 0, 1: 1, -:1, ×: 2, +:2 \rbrace
  • $+, ×$ are associative and commutative
  • $0, 1$: neutral elements
  • $-$: inverse law
  • distributivity
T(X) = ℤ[X]

since we can push the $×$ under the $+$ and $-$, by distributivity.

Algebras of algebraic theories

An algebra of an algebraic theory:

is a set $A$ equipped with a function $op ≝ f: A^n ⟶ A$ for every operation $f ∈ Σ_n$ of arity $n$, and satisfies the equations of the theory.

A homomorphism $A ⟶ B$ between such algebras:

is a function $h: A ⟶ B$ such that h(op_A(a_1, ⋯, a_n)) = op_B(h(a_1), ⋯, h(a_n)) for all $op∈ Σ_n, \; a_1, ⋯, a_n ∈ A$

Th: $TA$ is the free algebra generated by the set $A$ in the sense that for every function $f: A ⟶ B$ where $B$ is an algebra, there exists a unique homomorphism h: TA ⟶ B such that

\begin{xy} \xymatrix{ TA \ar[r]^h & B \\ A \ar[u]^{η_A} \ar[ru]_f } \end{xy}


The state monad

Fact: the state monad can be defined as the monad associated to a specific algebraic theory of mnemoids.

The free mnemoid generated by $A$ = $S ⟹ (S × A)$

To make things simpler, let us take $V = S = \lbrace true, false \rbrace$

lookup: \begin{cases} A^2 &⟶ A \\ (M, N) &⟼ \begin{cases} M \text{ if the register is } true \\ N \text{ else} \end{cases} \end{cases}


  • $update_{⟨true⟩}: A ⟶ A$
  • $update_{⟨false⟩}: A ⟶ A$
lookup(update_{⟨true⟩}, update_{⟨false⟩}) = x

How does one recover the algebra of a given alg. theory from the monad $T$?

For instance: can we recover the notion of monoid from the monad $TA = \bigsqcup_{n∈ℕ} A^n$?

  • unit of the monad: η_A: A ⟶ TA
  • multiplication of the monad: μ_A: TTA ⟶ TA
An algebra of a monad $T: 𝒞 ⟶ 𝒞$:

is an object $A$ of the category $𝒞$ equipped with a morphism $h: TA ⟶ A$ s.t. the following diagrams commute: \begin{xy} \xymatrix{ TA \ar[rd]^h \\ A \ar[u]^{η_A} \ar[r]_{id_A} & A } \end{xy}


\begin{xy} \xymatrix{ TTA \ar[r]^{Th} \ar[d]_{μ_A} & TA \ar[d]^h \\ TA \ar[r]_h & A } \end{xy}
A homomorphism between $T$-algebras $f: (A, h_A) ⟶ (B, h_B)$:

is a morphism $f: A ⟶ B$ s.t. the following diagram commutes: \begin{xy} \xymatrix{ TA \ar[r]^{Tf} \ar[d]_{h_A} & TB \ar[d]^{h_B} \\ A \ar[r]_f & B } \end{xy}

This defines a category $Alg$ whose objects are the $T$-algebras whose morphisms are the homomorphisms between them.

Th: for every algebraic theory, the category of algebras (and homomorphisms) of the theory is isomorphic to the category of $T$-algebras for the associated monad $T$.

Example: in the case of the “free monoid monad” $T: Set ⟶ Set$, TA ≝ \bigsqcup_{n∈ℕ} A^n

a function $h: TA ⟶ A$ is the same thing as a family of functions h_n: A^n ⟶ A

NB: $h_n(a_1, ⋯, a_n)$ can be thought of as $a_1 ⋯ a_n$

In particular:

  • neutral element: $h_0: A^0 = \lbrace \star \rbrace ⟶ A$
  • multiplication: $h_2: A^2 ⟶ A$

Claim: $h_2(h_2(a, b), c) = h_3(a, b, c)$

Because of \begin{xy} \xymatrix{ [[a, b], c] ∈ TTA \ar[r]^{\qquad Th \qquad } \ar[d]_{μ_A} & TA\ni [h_2(a,b), h_1(c)] \ar[d]^h \\ [a, b, c] ∈ TA \ar[r]_{h \qquad \qquad} & A \ni h_2(h_2(a, b), h_1(c))=h_3(a, b, c) } \end{xy}

Claim: $h_1(a) = a$

Because of \begin{xy} \xymatrix{ [a] ∈ TA \ar[rd]^h \\ a ∈ A \ar[u]^{η_A} \ar[r]_{id_A} & A \ni h_1(a)=a } \end{xy}

More generally:

h_2(h_p(a_1, ⋯, a_p), h_q(a_1', ⋯, a_q')) = h_{p+q}(a_1, ⋯, a_p, a_1', ⋯, a_q')

Hence: a $T$-algebra for the free monoid monad $T$ is entirely determined by $h_0$ and $h_1$:

h_n(a_1, ⋯, a_n) = h_2(a_1, h_2(a_2, ⋯, a_n))

Associativity comes from the equation h_2(a, h_2(b, c)) = h_3(a, b, c) = h_2(h_2(a, b), c)

We can recover the monad from the notion of $T$-algebra ⟶ the monad is an invariant of an algebraic theory.

From Monads to categories of $T$-algebras

For every monad $T: 𝒞 ⟶ 𝒞$ , there is an adjunction

\xymatrix{ 𝒞 \ar@/^1cm/[r]^{F \text{ Free}} & Alg_T \ar@/^1cm/[l]^{𝒰 \text{ forget}} }
𝒰: (A, h) ⟼ A
F: A ⟼ (TA, \; μ_A: TTA ⟶ TA)


every object $A$ of the category $𝒞$ induces a $T$-algebra $(TA, μ_A)$

μ_A: TTA ⟶ TA

The monad $T = 𝒰 \circ F$ is recovered from the adjunction.

A monoid is a topological space equipped with a contractible space of operations ⟹ operads ($A_∞$-algebras)

Operads: generalization of algebraic theories to a topological space of operations

Back to homorphisms: why are they so simple?

\begin{xy} \xymatrix{ \bigsqcup_{n∈ℕ} A^n = TA \ar[r]^{Tf} \ar[d]_{h_A} & TB = \bigsqcup_{n∈ℕ} B^n \ar[d]^{h_B} \\ A \ar[r]_f & B } \end{xy}

means that

\begin{xy} \xymatrix{ A^n \ar[r]^{f^n} \ar[d]_{(h_A)_n} & B^n \ar[d]^{(h_B)_n} \\ A \ar[r]_f & B } \end{xy}

In other words:

h_n(fa_1, ⋯, fa_n) = f(h_n(a_1, ⋯, a_n))

Leave a Comment