definition example theorem proof

A monoid consists of a Set , a function (multiplication), and an element (unit / identity element) such that, in infix notation,

for all . It is commutative if also .

Sources: 7 Sketches Example 2.6, §5.4.2 (monoid objects), Exercise 2.8; Kittenlab Lecture 5, 7; DaoFP §5.3 (“Monoids”), §10.9 (“The category of monoids”, “Free monoid”), §14.7 (“Monad as a monoid”), §18.1 (Cayley’s theorem, Tannakian reconstruction); CTfS §3.1 (Definition 3.1.1.1, Examples 3.1.1.3–3.1.1.22, §3.1.4 monoid homomorphisms: Examples 3.1.4.2–3.1.4.4, Proposition 3.1.4.5, Application 3.1.4.3, Exercises 3.1.4.6–3.1.4.7), Slogan 4.2.1.2

Examples

  • Strings over an alphabet under concatenation with unit (Kittenlab): the Free Monoid on .
  • under (unit ) or (unit ).
  • matrices under matrix multiplication, elementwise product, or elementwise sum.
  • Subsets of under (unit ) or (unit ).
  • Endomorphisms of any object of a Category under composition.
  • Any commutative monoid gives a Symmetric Monoidal Preorder on the Discrete Preorder (7S Exercise 2.8).

Monoids as agents acting (Category Theory for Scientists §3.1)

“A common way to interpret phenomena we see around us is to say that agents are acting on objects”: a monoid is a set of actions together with a formula saying how a sequence of actions is itself an action; a Group additionally lets every action be undone. The actions themselves act on a set of states — a Monoid Action, e.g. a Finite State Machine. Monoids given by generators and relations (buttons that can be pressed, a keyboard with a backspace key, a 32-character buffer, a clock) are presented monoids.

  • Smallest examples (CTfS Exercise 3.1.1.7): the trivial monoid is the smallest (the empty set has no unit); every monoid with elements is commutative, and the smallest non-commutative one has 3 elements, e.g. with for . matrices under multiplication are the linear-algebra example of non-commutativity.
  • Homomorphisms (CTfS §3.1.4): the inclusion and ; the homomorphisms are exactly , (not or ); the only homomorphism is (CTfS Proposition 3.1.4.5); is a homomorphism , while and admit only the trivial one (CTfS Exercise 3.1.4.7). Every pair of monoids has the trivial homomorphism , since the trivial monoid is both initial and terminal in .
  • Biology (CTfS Application 3.1.4.3): lists of RNA triplets map homomorphically to lists of nucleotides and, by translation, to polypeptides; but there is no homomorphism from all nucleotide lists to polypeptides — a list of two nucleotides codes for nothing — so one restricts to the submonoid of lists whose length is a multiple of three.

Monoids are one-object categories (Kittenlab Lecture 5)

Proposition. A monoid is precisely the same thing as a Category with a single object.

Proof. If has one object then is a monoid with and . Conversely a monoid gives a category with one object , , , .

Preorders and monoids are the two “extremes” of categories: lots of objects and few morphisms, versus one object and many morphisms. A Functor between monoids-as-categories is a monoid homomorphism, a function with and . A Natural Transformation between homomorphisms of groups is an with — conjugation (Kittenlab Lecture 7).

The category of monoids (DaoFP §10.9)

has monoids as objects and homomorphisms as morphisms. Functors: (view as one-object category), the forgetful , and the Free Monoid , , with (Free-Forgetful Adjunction). The List Monad is the monad of this adjunction.

Monoids in a monoidal category

A monoid is a monoid object in : maps , satisfying associativity and unit diagrams. Replacing by any Monoidal Category gives monoid objects (7 Sketches §5.4.2, DaoFP §5.3); e.g. a Monad is a monoid in the category of endofunctors (DaoFP §14.7), and a Frobenius Monoid is a monoid-comonoid pair. A monoid is also a Prop-like structure: the Free Prop on one generator with equations. Cayley’s theorem: every monoid embeds in the monoid of endofunctions of its underlying set (DaoFP §18.1, an instance of the Yoneda Lemma).

Docs: ThCategory (GATlab) · Theories & presentations — Kittenlab Lecture 5, Lecture 7

# Kittenlab Lecture 5
abstract type Monoid{T} end
# mul(m::Monoid{T}, x::T, y::T)::T
# ident(m::Monoid{T})::T
 
struct ConcatMonoid{T} <: Monoid{Vector{T}}
  alphabet::Set{T}
end
function mul(m::ConcatMonoid{T}, xs::Vector{T}, ys::Vector{T}) where {T}
  @assert all(x ∈ m.alphabet for x in xs) && all(y ∈ m.alphabet for y in ys)
  [xs; ys]
end
ident(::ConcatMonoid{T}) where {T} = T[]

Catlab version (run in a fresh Julia session — Catlab exports its own compose, id, FinFunction, …):

# Catlab: a monoid is a one-object category; the free monoid on generators a, b
using Catlab
@present M(FreeCategory) begin
  x::Ob
  (a, b)::Hom(x, x)
end
compose(M[:a], M[:b], M[:a])   # the word "aba"; id(M[:x]) is the empty word
#check Monoid            -- class Monoid (M : Type u) extends Semigroup M, MulOneClass M
#check CommMonoid
#check AddMonoid
example : Monoid (List Char) := inferInstance   -- free monoid: lists under ++
#check MonoidHom           -- M →* N
#check CategoryTheory.MonCat   -- the category of monoids
-- a monoid as a one-object category:
#check CategoryTheory.SingleObj  -- SingleObj M, with `SingleObj.star`
-- Prelude / Data.Monoid
class Semigroup a where (<>) :: a -> a -> a
class Semigroup a => Monoid a where mempty :: a
-- laws: mempty <> x = x = x <> mempty; (x <> y) <> z = x <> (y <> z)
 
-- the free monoid on a: lists
-- instance Monoid [a] where mempty = []; (<>) = (++)
 
-- a monoid homomorphism (unenforced): h mempty = mempty, h (x <> y) = h x <> h y
newtype MonHom m n = MonHom (m -> n)