Why go up a dimension?
A category records objects and arrows, and asks whether two arrows are equal. Again and again, mathematics hands us arrows that are not equal but are related in a structured way:
- Two functors are compared by natural transformations — arrows between arrows. Categories, functors and natural transformations form something with three layers.
- In a monoidal category such as vector spaces under , the objects and are not equal but canonically isomorphic, and the isomorphisms satisfy laws of their own (Mac Lane's pentagon).
- Rings and -bimodules compose by tensor product, , which is associative only up to isomorphism; bimodule maps are arrows between these arrows. (This is the Morita bicategory.)
- In a space , paths compose only up to homotopy; homotopies between paths are arrows between arrows, and homotopies between homotopies go one level higher. The fundamental groupoid of the fundamental-group lesson forgets all of this higher information.
Higher category theory is the study of structures with -morphisms between -morphisms for (or for all ). Dimension 2 is completely understood and is the main subject of this lesson; dimension 3 is understood, with a surprise; beyond that the subject branches into several competing definitions, and the case has its own lesson, ∞-categories.
Cells, pasting and the two compositions
Picture a 2-category as a world of cells: 0-cells (objects) are points, 1-cells are arrows between points, and 2-cells are surfaces between parallel arrows.
Two 2-cells can be composed in two directions: vertically (along a shared 1-cell) and horizontally (along a shared 0-cell). The picture above can be evaluated "rows first" — compose and vertically, then horizontally — or "columns first". The interchange law says the answers agree:
The second idea is weakness. In , composition of functors is associative on the nose. In the Morita bicategory it is not: and are different modules, related by a canonical isomorphism. A bicategory keeps these isomorphisms as part of the data and imposes laws on them. Going up a dimension means that equations between 1-cells may be replaced by invertible 2-cells — and then those 2-cells must satisfy equations of their own.
2-categories, bicategories and pseudofunctors
Throughout, juxtaposition means ("first , then "); Lean and Mathlib write the same composite in diagrammatic order as f ≫ g.
Definition— strict 2-category
A strict 2-category consists of
- a collection of objects (0-cells) ;
- for each pair of objects a category , whose objects are the 1-cells and whose morphisms are the 2-cells; composition in is vertical composition ;
- for each triple of objects a functor , written on 1-cells and on 2-cells (horizontal composition);
- an identity 1-cell for each object,
such that horizontal composition is strictly associative and unital: , , and likewise for 2-cells. That is a functor on the product category says exactly that and that the interchange law holds.
Definition— bicategory
A bicategory (Bénabou, 1967) has the same data as a 2-category, except that horizontal composition is associative and unital only up to coherent invertible 2-cells: there are natural isomorphisms
(the associator and unitors), natural in , satisfying two axioms. For composable , , , :
- pentagon: as 2-cells ;
- triangle: as 2-cells .
A strict 2-category is a bicategory whose associators and unitors are identities.
Definition— pseudofunctor
A pseudofunctor sends objects, 1-cells and 2-cells to objects, 1-cells and 2-cells, is a functor on each hom-category, and preserves composition and identities only up to coherent invertible 2-cells and , subject to compatibility with the associators and unitors. It is a 2-functor when these 2-cells are identities. A biequivalence is a pseudofunctor that is essentially surjective on objects up to equivalence and an equivalence on every hom-category.
Definition— monoidal category
A monoidal category (see Monoidal categories) is a category with a functor , a unit object and natural isomorphisms , , satisfying the pentagon and triangle axioms.
Examples and non-examples
Example— The strict 2-category Cat
Objects are (small) categories, 1-cells are functors, 2-cells are natural transformations. Vertical composition is componentwise: . For between functors and between functors , the horizontal composite has components
the two expressions agreeing by naturality of at . Composition of functors is associative and unital on the nose, so is strict.
Example— One-object bicategories are monoidal categories
If has a single object , the hom-category carries a tensor product (horizontal composition), unit , and the associator and unitors of ; the pentagon and triangle are word for word the monoidal axioms. Conversely, a monoidal category gives a bicategory with one object, 1-cells the objects of , 2-cells the morphisms of , and composition . So a monoidal category is a bicategory with one object — "delooping" shifts everything down one dimension. Mathlib has both directions (see the formal section).
Example— Spans, bimodules and the fundamental 2-groupoid
- Spans. In a category with pullbacks, a 1-cell is a span , composition is by pullback and 2-cells are maps of spans. Pullbacks are defined only up to unique isomorphism, so composition is associative only up to isomorphism: a genuine bicategory (Bénabou's original example).
- Bimodules. Objects are rings, 1-cells are -bimodules, composition is and 2-cells are bimodule maps. Two rings are equivalent in this bicategory exactly when they are Morita equivalent.
- The fundamental 2-groupoid of a space: points, paths, and homotopy classes (rel endpoints) of homotopies between paths. Concatenation of paths is associative only up to reparametrisation homotopy, so is a bicategory in which every 2-cell is invertible and every 1-cell is invertible up to a 2-cell (a bigroupoid).
Example— A non-example, and a surprise
Take a "2-category with one object and one 1-cell ". Its 2-cells form a set with two operations, vertical and horizontal composition, both unital with unit and linked by interchange. By the Eckmann–Hilton argument below, the two operations coincide and are commutative. So you cannot model a non-commutative group as the 2-cells of a doubly degenerate 2-category: a monoid becomes forced to be commutative when it is pushed up two dimensions. This is the categorical shadow of the fact that is abelian.
Central theorems
Theorem— Theorem 1 (the interchange law in Cat)
Let , be natural transformations between functors , and , between functors . Then
Proof
Both sides are natural transformations ; compare components at an object of , using . The left side is
The right side is
Naturality of at the morphism says . Substituting this into the right side gives the left side.
∎
The same computation shows that horizontal composition is associative and unital, so is a strict 2-category.
Theorem— Theorem 2 (Eckmann–Hilton, 1962)
Let be a set with binary operations and , with two-sided units and , satisfying the interchange law
Then , the operations coincide, and the common operation is commutative (and associative).
Proof
Units. Put and : Call the common unit .
The operations agree. For all :
Commutativity. For all :
Associativity. .
∎
Theorem— Corollary 3 (2-endomorphisms of identities commute)
In any bicategory , for any object and any 2-cells , we have . In particular, natural transformations of the identity functor commute, and in a monoidal category the endomorphisms of the unit object commute.
Proof
The interchange law for the two whiskerings of and says , as 2-cells (both sides equal ). Whiskering by an identity is conjugation by a unitor: by naturality of and ,
A standard consequence of the pentagon and triangle axioms is (Kelly, 1964, for monoidal categories). Writing for this isomorphism, the interchange equation becomes , and cancelling the isomorphism gives . (Equivalently: the set of such 2-cells carries vertical composition and a second unital operation satisfying interchange; apply Theorem 2.)
∎
The same argument, in or with maps of squares , proves that — and every with — is abelian.
Theorem— Theorem 4 (coherence for bicategories; stated, not proved here)
Every bicategory is biequivalent to a strict 2-category. Moreover, in a bicategory all diagrams built from associators and unitors (formal composites, between the same two bracketings) commute.
The first statement is due to Mac Lane and Paré (1985), and can also be deduced from a bicategorical Yoneda lemma: embed into the strict 2-category of pseudofunctors (Street). A careful modern treatment, via the bicategorical Yoneda lemma, is in Johnson and Yau, 2-Dimensional Categories. For one-object bicategories this reduces to coherence for monoidal categories (Mac Lane, 1963; see also Joyal and Street): all diagrams of associators and unitors commute, and every monoidal category is monoidally equivalent to a strict one. The practical meaning is that one may calculate in a bicategory as if it were strict — provided one remembers that the strictification changes the objects.
Theorem— Theorem 5 (Gordon–Power–Street, 1995; stated, not proved here)
Every tricategory is triequivalent to a Gray-category — a semi-strict 3-category in which everything is strict except the interchange law, which holds only up to a coherent invertible 3-cell. It is not true that every tricategory is triequivalent to a strict 3-category.
The failure of full strictification is visible in homotopy theory. Simpson (1998) showed that the homotopy 3-type of the 2-sphere cannot be modelled by a strict 3-groupoid. Roughly, a strict interchange law forces the invariant linking and of a simply connected strict 3-groupoid to vanish (the braiding obtained by sliding one 2-cell around another becomes trivial), whereas for this invariant is non-zero: it is detected by the Hopf map, which generates . Strictification works in dimension 2 and fails from dimension 3 on; the "weak interchange" of Gray-categories is exactly the missing ingredient.
The landscape: what is known and what is open
Established.
- Dimension 2. Bicategories, pseudofunctors, pseudonatural transformations and modifications form a well-understood theory, with coherence (Theorem 4), a Yoneda lemma, adjunctions and monads (Johnson–Yau 2021; Lack's 2-categories companion, 2010).
- Dimension 3. Tricategories were defined by Gordon, Power and Street (1995); coherence holds in the Gray-category form (Theorem 5; see Gurski, Coherence in Three-Dimensional Category Theory, 2013).
- Degenerate cases and the periodic table. A bicategory with one object is a monoidal category; a tricategory with one object and one 1-cell is (essentially) a braided monoidal category; one more level of degeneracy gives symmetric monoidal structure, after which nothing new appears. This pattern is the periodic table of Baez and Dolan (1995). Making "is the same as" precise is subtle: Cheng and Gurski (2007) showed that the comparison works on objects but must be stated carefully once morphisms and higher morphisms are compared. A version of the Baez–Dolan stabilization hypothesis has been proved in the -categorical setting (Gepner and Haugseng, 2015).
- -categories. When all -morphisms with are invertible, there are several equivalent, fully developed models (quasi-categories, complete Segal spaces, simplicial categories) — the subject of the next lesson.
Several definitions of weak -category. For general there is no single accepted definition. Leinster's survey (2002) lists ten, including: Batanin's and Leinster's (globular operads), Trimble's, Street's (simplicial, via "orientals" and complicial sets, later developed by Verity), Tamsamani's and Simpson's (Segal-type, iterated simplicial), Baez and Dolan's (opetopic), Joyal's (-categories) and Rezk's (-spaces, for -categories).
Open or in progress. Comparing these definitions is research. Some comparisons are proved (for instance among several models of -categories, and an axiomatic characterisation of the homotopy theory of -categories by Barwick and Schommer-Pries, published 2021), but a complete comparison of all proposed definitions of weak -category is not available. Fully explicit algebraic definitions with coherence theorems exist for ; Trimble wrote down an explicit definition of tetracategories (), and explicit definitions become unmanageable by hand beyond that — one reason the field moved towards homotopical ("") models.
Higher categories in Lean and Mathlib
Mathlib has a substantial library for dimension 2: bicategories (CategoryTheory.Bicategory, with associators, unitors, the pentagon and the triangle as axioms), strict bicategories, pseudofunctors, the strict 2-category Cat, the monoidal category of endomorphisms of an object, and the one-object bicategory of a monoidal category. Note the conventions: Mathlib composes 1-cells and morphisms in diagrammatic order (f ≫ g is "first f, then g") and writes horizontal composition of natural transformations as α ◫ γ, with components (α ◫ γ).app X = γ.app (F.obj X) ≫ J.map (α.app X) — the formula of the examples section.
The interchange law, proved from naturality exactly as in Theorem 1 (after ext X and unfolding, one use of the naturality of δ finishes the proof), and Mathlib's own version:
/-- **The interchange law** in the 2-category of categories. For natural transformations
`α : F ⟶ G`, `β : G ⟶ H` (between functors `C ⥤ D`) and `γ : I ⟶ J`, `δ : J ⟶ K` (between
functors `D ⥤ E`), composing vertically first and then horizontally (`◫`) gives the same
result as composing horizontally first and then vertically:
`(α ≫ β) ◫ (γ ≫ δ) = (α ◫ γ) ≫ (β ◫ δ)`.
Mathlib's horizontal composite has components `(α ◫ γ)_X = γ_{F X} ≫ J(α_X)`. At an object `X`
the two sides differ only by the order of `δ_{F X}` and `J(α_X)`, and the naturality square
of `δ` at the morphism `α_X` swaps them. -/
theorem interchange {C D E : Type*} [Category C] [Category D] [Category E]
{F G H : C ⥤ D} {I J K : D ⥤ E}
(α : F ⟶ G) (β : G ⟶ H) (γ : I ⟶ J) (δ : J ⟶ K) :
(α ≫ β) ◫ (γ ≫ δ) = (α ◫ γ) ≫ (β ◫ δ) := by
ext X
simp only [NatTrans.hcomp_app, NatTrans.comp_app, Functor.map_comp, Category.assoc]
-- Goal: γ ≫ δ_{FX} ≫ K(α_X) ≫ K(β_X) = γ ≫ J(α_X) ≫ δ_{GX} ≫ K(β_X) (γ at F X).
-- Naturality of `δ` at `α_X : F X ⟶ G X`: `J(α_X) ≫ δ_{GX} = δ_{FX} ≫ K(α_X)`.
rw [δ.naturality_assoc]/-- The interchange law again, now by Mathlib's `CategoryTheory.NatTrans.exchange`
(proved there by the automation `cat_disch`, which finds the same naturality argument). -/
theorem interchange_library {C D E : Type*} [Category C] [Category D] [Category E]
{F G H : C ⥤ D} {I J K : D ⥤ E}
(α : F ⟶ G) (β : G ⟶ H) (γ : I ⟶ J) (δ : J ⟶ K) :
(α ≫ β) ◫ (γ ≫ δ) = (α ◫ γ) ≫ (β ◫ δ) :=
NatTrans.exchange α β γ δ/-- Categories, functors and natural transformations form a **strict** 2-category: composition
of functors is associative and unital on the nose, so Mathlib's bicategory structure on `Cat`
has associators and unitors that are identities (`eqToIso` of equalities). This is Mathlib's
instance `CategoryTheory.Cat.bicategory.strict`. -/
theorem cat_strict : Bicategory.Strict Cat.{0, 0} :=
inferInstanceThe Eckmann–Hilton argument, with a calc proof that follows Theorem 2 line by line (the units first, then agreement, then commutativity), and Mathlib's version, which it uses to prove that higher homotopy groups are abelian:
/-- If two binary operations each have a two-sided unit (`e₁` for `m₁`, `e₂` for `m₂`) and
satisfy the interchange law `m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)`, then the units are
equal. Proof: put `a = d = e₂` and `b = c = e₁` in the interchange law; the left side
collapses to `m₁ e₁ e₁ = e₁` and the right side to `m₂ e₂ e₂ = e₂`. -/
theorem units_coincide {X : Type*} (m₁ m₂ : X → X → X) (e₁ e₂ : X)
(h₁l : ∀ a, m₁ e₁ a = a) (h₁r : ∀ a, m₁ a e₁ = a)
(h₂l : ∀ a, m₂ e₂ a = a) (h₂r : ∀ a, m₂ a e₂ = a)
(interchange : ∀ a b c d, m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) :
e₁ = e₂ :=
calc e₁ = m₁ e₁ e₁ := (h₁l e₁).symm
_ = m₁ (m₂ e₂ e₁) (m₂ e₁ e₂) := by rw [h₂l, h₂r]
_ = m₂ (m₁ e₂ e₁) (m₁ e₁ e₂) := interchange e₂ e₁ e₁ e₂
_ = m₂ e₂ e₂ := by rw [h₁l, h₁r]
_ = e₂ := h₂l e₂/-- **The Eckmann–Hilton argument.** Two unital binary operations on the same set that satisfy
the interchange law are equal, and the common operation is commutative. This is the algebra
behind "π₂ is abelian" and behind `endo_id_comm` below. The proof slides `a` and `b` past each
other using the units, exactly as in the lesson's picture of 2-cells moving around each other
in the plane. -/
theorem eckmann_hilton {X : Type*} (m₁ m₂ : X → X → X) (e₁ e₂ : X)
(h₁l : ∀ a, m₁ e₁ a = a) (h₁r : ∀ a, m₁ a e₁ = a)
(h₂l : ∀ a, m₂ e₂ a = a) (h₂r : ∀ a, m₂ a e₂ = a)
(interchange : ∀ a b c d, m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) :
(∀ a b, m₁ a b = m₂ a b) ∧ (∀ a b, m₂ a b = m₂ b a) := by
have he : e₁ = e₂ := units_coincide m₁ m₂ e₁ e₂ h₁l h₁r h₂l h₂r interchange
subst he
have same : ∀ a b, m₁ a b = m₂ a b := fun a b =>
calc m₁ a b = m₁ (m₂ a e₁) (m₂ e₁ b) := by rw [h₂r, h₂l]
_ = m₂ (m₁ a e₁) (m₁ e₁ b) := interchange a e₁ e₁ b
_ = m₂ a b := by rw [h₁r, h₁l]
refine ⟨same, fun a b => ?_⟩
calc m₂ a b = m₁ a b := (same a b).symm
_ = m₁ (m₂ e₁ a) (m₂ b e₁) := by rw [h₂l, h₂r]
_ = m₂ (m₁ e₁ b) (m₁ a e₁) := interchange e₁ a b e₁
_ = m₂ b a := by rw [h₁l, h₁r]/-- Mathlib's version: `EckmannHilton.mul_comm` (in `Mathlib.GroupTheory.EckmannHilton`), stated
with Mathlib's `EckmannHilton.IsUnital`. Mathlib uses it to prove that the higher homotopy groups
`πₙ` with `n ≥ 2` are commutative. -/
theorem eckmann_hilton_library {X : Type*} {m₁ m₂ : X → X → X} {e₁ e₂ : X}
(h₁ : EckmannHilton.IsUnital m₁ e₁) (h₂ : EckmannHilton.IsUnital m₂ e₂)
(interchange : ∀ a b c d, m₁ (m₂ a b) (m₂ c d) = m₂ (m₁ a c) (m₁ b d)) :
∀ a b, m₂ a b = m₂ b a :=
(EckmannHilton.mul_comm h₁ h₂ interchange).commCorollary 3 in an arbitrary bicategory. The proof uses Mathlib's axiom whisker_exchange (the interchange law for whiskerings), the axioms id_whiskerLeft and whiskerRight_id (whiskering by an identity is conjugation by a unitor) and the lemma unitors_equal (), then cancels the unitor:
/-- **2-endomorphisms of an identity 1-morphism commute**, in any bicategory: for 2-morphisms
`η θ : 𝟙 a ⟶ 𝟙 a`, `η ≫ θ = θ ≫ η`. This is Eckmann–Hilton inside a bicategory. The two
"operations" are vertical composition and horizontal composition (whiskering), and the
interchange law is Mathlib's axiom `whisker_exchange`. The unitors enter because `𝟙 a ≫ 𝟙 a` is
only isomorphic to `𝟙 a`; the key coherence fact is `λ_(𝟙 a) = ρ_(𝟙 a)` (`unitors_equal`). -/
theorem endo_id_comm {B : Type*} [Bicategory B] {a : B} (η θ : 𝟙 a ⟶ 𝟙 a) :
η ≫ θ = θ ≫ η := by
-- Interchange for the two whiskerings of η and θ.
have ex : 𝟙 a ◁ θ ≫ η ▷ 𝟙 a = η ▷ 𝟙 a ≫ 𝟙 a ◁ θ := whisker_exchange η θ
-- Whiskering by an identity is conjugation by a unitor; for `𝟙 a` both unitors agree.
rw [id_whiskerLeft, whiskerRight_id, unitors_equal, unitors_inv_equal] at ex
-- Now ex : (ρ ≫ θ ≫ ρ⁻¹) ≫ (ρ ≫ η ≫ ρ⁻¹) = (ρ ≫ η ≫ ρ⁻¹) ≫ (ρ ≫ θ ≫ ρ⁻¹).
simp only [Category.assoc, Iso.inv_hom_id_assoc, cancel_epi] at ex
-- ex : θ ≫ η ≫ ρ⁻¹ = η ≫ θ ≫ ρ⁻¹; cancel the isomorphism ρ⁻¹ on the right.
rw [← Category.assoc, ← Category.assoc, cancel_mono] at ex
exact ex.symm/-- The special case of `endo_id_comm` in `Cat`: natural transformations from the identity
functor of a category to itself commute. (Their monoid is sometimes called the *centre* of the
category.) This applies Mathlib's `CategoryTheory.NatTrans.id_comm`. -/
theorem nat_trans_id_comm {C : Type*} [Category C] (α β : 𝟭 C ⟶ 𝟭 C) :
α ≫ β = β ≫ α :=
NatTrans.id_comm α βThe second half of Theorem 4 — every formal diagram of associators and unitors commutes — is in Mathlib in the form "the free bicategory on a quiver is locally thin", proved by normalisation:
/-- **Coherence for bicategories**, in the form Mathlib proves it: in the free bicategory on a
quiver `B` (1-morphisms are formal composites of arrows of `B` and identities; 2-morphisms are
built from associators, unitors and their inverses only), any two parallel 2-morphisms are
equal. So every "formal" diagram of associators and unitors commutes, in every bicategory. This
applies Mathlib's instance `CategoryTheory.FreeBicategory.locally_thin` (proved by normalisation,
following Beylin and Dybjer). -/
theorem free_bicategory_coherence {B : Type*} [Quiver B] {a b : FreeBicategory B}
{f g : a ⟶ b} (η θ : f ⟶ g) : η = θ :=
Subsingleton.elim η θFinally, the two halves of "a bicategory with one object is a monoidal category", as Mathlib provides them:
/-- **A bicategory with one object is a monoidal category**, one direction: the 1-morphisms
`a ⟶ a` of any object `a` form a monoidal category whose tensor product is composition, whose
unit is `𝟙 a`, and whose associator and unitors are those of the bicategory. This is Mathlib's
instance on `CategoryTheory.EndMonoidal`. -/
abbrev endMonoidal {B : Type*} [Bicategory B] (a : B) : MonoidalCategory (a ⟶ a) :=
inferInstance/-- The other direction: a monoidal category `C` becomes a bicategory `MonoidalSingleObj C` with a
single object `⋆`, objects of `C` as 1-morphisms and morphisms of `C` as 2-morphisms; and the
monoidal category of endomorphisms of `⋆` is equivalent to `C` again. This is Mathlib's
`CategoryTheory.MonoidalSingleObj.endMonoidalStarFunctorEquivalence`. -/
noncomputable def singleObjEquiv (C : Type*) [Category C] [MonoidalCategory C] :
EndMonoidal (MonoidalSingleObj.star C) ≌ C :=
MonoidalSingleObj.endMonoidalStarFunctorEquivalence CWhat is not formalised. The first half of Theorem 4 (every bicategory is biequivalent to a strict 2-category), tricategories and Gray-categories (Theorem 5), Simpson's theorem, and any definition of weak -category for are not formalised here, and as far as we know not in Mathlib. Mathlib's coherence tactics (coherence, bicategory) put the locally-thin theorem to work: they prove equations between structural 2-cells automatically.
The shape of coherence: associahedra
Bracketings of a word of letters, joined when they differ by one associator, form the 1-skeleton of Stasheff's associahedron . The experiment builds these graphs for , checks that they are connected (any two bracketings are related by associators), finds Mac Lane's pentagon as the two directed paths of lengths 2 and 3 in , and computes that the 2-dimensional faces of are 6 pentagons and 3 squares whose boundaries span every cycle (mod 2). The squares are the "naturality" relations between associators acting on disjoint parts of the word; the pentagons are instances of the pentagon axiom. This is the combinatorial content of the second half of Theorem 4.
"""Associahedra: the shapes of coherence for associativity, computed exactly.
In a bicategory (or monoidal category) composition is associative only up to
associator 2-cells. The bracketings of a word of n letters are the vertices of
a graph whose edges are single associator moves ((xy)z) <-> (x(yz)); it is the
1-skeleton of Stasheff's associahedron K_n. We enumerate it exhaustively for
small n and check: the number of bracketings is a Catalan number; the graph is
connected (any two bracketings are related by associators); the two directed
paths from the left comb to the right comb for n = 4 have lengths 2 and 3 (the
two sides of Mac Lane's pentagon); and for n = 5 the 2-dimensional faces are 6
pentagons and 3 squares, with V - E + F = 2, and their boundaries span the
cycle space mod 2 (every loop of associators is a sum of faces). This is
exact, exhaustive-finite evidence for these n only; coherence for all n is
Mac Lane's theorem.
"""
from collections import deque
from math import comb
def bracketings(letters):
"""All full bracketings of a tuple of letters, as nested pairs."""
if len(letters) == 1:
return [letters[0]]
out = []
for i in range(1, len(letters)):
for left in bracketings(letters[:i]):
for right in bracketings(letters[i:]):
out.append((left, right))
return out
def show(t):
"""Write a bracketing as a string, e.g. ((ab)c)d."""
if isinstance(t, str):
return t
a, b = (show(x) if isinstance(x, str) else "(" + show(x) + ")" for x in t)
return a + b
def moves(t, forward_only=False):
"""Bracketings one associator away from t.
The forward move is ((x y) z) -> (x (y z)); without ``forward_only`` the
inverse move (x (y z)) -> ((x y) z) is included too.
"""
if isinstance(t, str):
return []
left, right = t
out = [(m, right) for m in moves(left, forward_only)]
out += [(left, m) for m in moves(right, forward_only)]
if not isinstance(left, str):
out.append((left[0], (left[1], right)))
if not forward_only and not isinstance(right, str):
out.append(((left, right[0]), right[1]))
return out
def associator_graph(n):
"""Vertices (bracketings of n letters) and undirected edges of K_n."""
vertices = bracketings(tuple("abcdefgh"[:n]))
edges = {frozenset((v, w)) for v in vertices for w in moves(v)}
return vertices, edges
def distances(start, step):
"""Breadth-first distances from ``start`` along the neighbour map ``step``."""
dist = {start: 0}
queue = deque([start])
while queue:
v = queue.popleft()
for w in step(v):
if w not in dist:
dist[w] = dist[v] + 1
queue.append(w)
return dist
def comb_bracketing(n, left=True):
"""The left comb ((ab)c)d... or the right comb a(b(c(d...)))."""
letters = "abcdefgh"[:n]
if left:
t = letters[0]
for x in letters[1:]:
t = (t, x)
return t
t = letters[-1]
for x in reversed(letters[:-1]):
t = (x, t)
return t
def directed_path_lengths(n):
"""Lengths of all directed paths left comb -> right comb (forward moves)."""
memo = {}
def lengths(t):
if t not in memo:
nxt = moves(t, forward_only=True)
memo[t] = {0} if not nxt else {1 + k for s in nxt for k in lengths(s)}
return memo[t]
return sorted(lengths(comb_bracketing(n, left=True)))
def contains_block(t, block):
"""Does bracketing t contain a bracket around exactly the letters ``block``?"""
if isinstance(t, str):
return False
if leaves(t) == block:
return True
return contains_block(t[0], block) or contains_block(t[1], block)
def leaves(t):
"""The letters of a bracketing, in order, as a string."""
return t if isinstance(t, str) else leaves(t[0]) + leaves(t[1])
def facets(n):
"""Facets of K_n: for each proper block of >= 2 consecutive letters, the
set of bracketings that bracket that block (a list of vertex sets)."""
word = "abcdefgh"[:n]
vertices = bracketings(tuple(word))
out = []
for r in range(2, n):
for i in range(n - r + 1):
block = word[i:i + r]
out.append({v for v in vertices if contains_block(v, block)})
return out
def gf2_rank(vectors):
"""Rank over GF(2) of vectors given as Python integers (bit masks)."""
basis = {}
for v in vectors:
while v:
top = v.bit_length() - 1
if top not in basis:
basis[top] = v
break
v ^= basis[top]
return len(basis)
def face_boundary_rank(n):
"""GF(2) rank of the boundaries of the 2-faces of K_n, for n = 5.
Each face is given by its vertex set; its boundary is the set of edges of
K_n with both ends in the face, encoded as a bit mask over the edges.
"""
vertices, edges = associator_graph(n)
index = {e: i for i, e in enumerate(sorted(edges, key=sorted_key))}
masks = []
for face in facets(n):
mask = 0
for e in edges:
if e <= face:
mask |= 1 << index[e]
masks.append(mask)
return gf2_rank(masks)
def sorted_key(edge):
"""A deterministic sort key for an undirected edge."""
return sorted(show(v) for v in edge)
def main():
print(" n bracketings Catalan edges connected diameter cycle rank")
for n in range(3, 8):
vertices, edges = associator_graph(n)
nbrs = {v: set(moves(v)) for v in vertices}
reach = distances(vertices[0], nbrs.__getitem__)
diameter = max(max(distances(v, nbrs.__getitem__).values())
for v in vertices)
catalan = comb(2 * (n - 1), n - 1) // n
rank = len(edges) - len(vertices) + 1
print(f"{n:>2} {len(vertices):>12} {catalan:>8} {len(edges):>6} "
f"{str(len(reach) == len(vertices)):>10} {diameter:>9} "
f"{rank:>11}")
print()
print("Directed paths ((ab)c)d -> a(b(cd)) have lengths",
directed_path_lengths(4))
print(" (the two sides of Mac Lane's pentagon).")
print("n = 5: directed path lengths left comb -> right comb:",
directed_path_lengths(5))
sizes = [len(face) for face in facets(5)]
v5, e5 = associator_graph(5)
print(f"K_5 faces: {sizes.count(5)} pentagons, {sizes.count(4)} squares; "
f"V - E + F = {len(v5)} - {len(e5)} + {len(sizes)} = "
f"{len(v5) - len(e5) + len(sizes)}")
print(f"GF(2) rank of the face boundaries: {face_boundary_rank(5)} = cycle "
f"rank {len(e5) - len(v5) + 1}: mod 2,")
print("every loop of associators is a sum of pentagons and squares.")
print()
print("Epistemic status: exact, exhaustive enumeration for n <= 7 (faces for")
print("n = 5 only). It illustrates, but does not prove, Mac Lane's coherence")
print("theorem, which says every diagram of associators commutes for every n.")
if __name__ == "__main__":
main()Explore: the pentagon and the associahedron K₅
The pentagon axiom asserts that the two composites of associators from to are equal:
For five letters there are 14 bracketings. Below they are the vertices of the associahedron , numbered as in this table (with the fifth 1-cell); edges are single associator moves.
| # | bracketing | # | bracketing | # | bracketing |
|---|---|---|---|---|---|
| 1 | 6 | 11 | |||
| 2 | 7 | 12 | |||
| 3 | 8 | 13 | |||
| 4 | 9 | 14 | |||
| 5 | 10 |
The associahedron K₅
Vertices: bracketings of abcde. Edges: one associator.
No walk yet.
14 vertices have odd degree: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14.
So no Euler trail is possible. A trail enters and leaves each vertex in its middle in pairs, so only its two ends can have odd degree, and this graph has 14 such vertices.
Things to try:
- In degrees mode, check that every vertex has degree 3: a bracketing of five letters has three internal brackets, and each allows exactly one associator move.
- The outer pentagon and is Mac Lane's pentagon for , followed by . Find the other five pentagons and the three squares (for example the square : the associator inside the block and the associator with act on disjoint parts of the word, so they commute — a naturality square).
- In walk mode, build a closed walk. Each step is an associator or its inverse, so the walk composes to a 2-cell from a bracketing to itself. Coherence says it is always the identity — because every closed walk is filled in by faces.
Exercises
1. Higher categories
Warm-upHumanA bicategory with exactly one object is the same thing as which of the following?
2. Higher categories
Warm-upComputationalHow many ways are there to fully bracket a composite of six composable 1-cells ? (These are the vertices of the associahedron .)
3. Higher categories
CoreHumanLet (functors ) and (functors ). Which formulas give the component of the horizontal composite? (Choose all that apply.)
4. Higher categories
CoreHumanIn the proof of the interchange law in , after expanding components the two sides are and . Which fact finishes the proof?
5. Higher categories
CoreHumanThe Eckmann–Hilton argument assumes that both operations are unital. Which pair of operations on a set with at least two elements satisfies the interchange law but is not commutative, showing the unit hypothesis cannot be dropped?
6. Higher categories
CoreFormalLet B be a bicategory in Lean ([Bicategory B]) and a : B. Which statement formalises Corollary 3, 'the 2-endomorphisms of an identity 1-morphism commute'?
7. Higher categories
CoreHumanWhich of these are strict 2-categories, with composition of 1-cells associative and unital on the nose? (Choose all that apply.)
8. Higher categories
StretchHumanWhich statement about coherence in dimension 3 is correct?
9. Higher categories
StretchComputationalWrite count_bracketings(n), the number of full bracketings of a word of n letters (use the recursion over the outermost bracket), and count_moves(n), the number of edges of the associahedron : pairs of bracketings that differ by one associator. Use the fact that every bracketing of letters has exactly internal brackets, each allowing exactly one associator move.
Common misconceptions
Misconception
"Strictification works in every dimension, so weak structures are just strict ones written sloppily." It works in dimension 2 (Theorem 4) and fails in dimension 3: by Gordon–Power–Street, tricategories can be strictified only to Gray-categories, and Simpson showed that the homotopy 3-type of is not modelled by a strict 3-groupoid. Weakness carries genuine information.
Misconception
"There is one agreed definition of weak -category." There are many (Leinster's 2002 survey describes ten), they are known to agree in low dimensions and in important homotopical cases, and comparing them in general is ongoing research. Results should always say which definition they use.
Misconception
"Strictification lets you assume the bicategory you started with is strict." Theorem 4 replaces by a biequivalent strict 2-category, which usually has different objects and 1-cells. For example, composition of spans is defined only up to isomorphism, and no choice of pullbacks makes it strictly associative in general. You may reason in the strict model and transport the conclusion, but you may not pretend the associators of are identities.
Misconception
"Eckmann–Hilton says 2-cells in a 2-category commute." Only the endomorphisms of an identity 1-cell are forced to commute. For a general 1-cell the monoid of 2-cells can be any monoid: in , take to be a functor from the terminal category picking out an object ; its natural endomorphisms are the monoid , which can be non-commutative.
Misconception
"The pentagon is the only axiom." A bicategory also needs the triangle axiom relating associators and unitors, and the associator and unitors must be natural. Without the triangle, the coherence theorem fails.
Many ways of seeing
Topology— Homotopy types and the homotopy hypothesis
Every space has a fundamental -groupoid : points, paths, homotopies between paths, …, with -cells taken up to homotopy. Grothendieck's homotopy hypothesis (in Pursuing Stacks, 1983) proposes that weak -groupoids are "the same as" homotopy -types. In dimension 1 this is a theorem: the homotopy category of 1-types is equivalent to the homotopy category of groupoids. In dimension 2 it is also established, and connected pointed 2-types correspond to crossed modules (Mac Lane and Whitehead, 1950). The Eckmann–Hilton argument is the topological fact that you can move two small discs past each other in the plane; Simpson's theorem is the fact that you cannot model the Hopf map with strict interchange. For an ∞-groupoid version see ∞-categories and Homotopy theory.
Geometry— String diagrams: 2-cells live in the plane
In the Poincaré dual picture of a 2-category, 0-cells are regions of the plane, 1-cells are lines between regions and 2-cells are points (beads) on lines. Vertical composition stacks diagrams, horizontal composition places them side by side, and the interchange law is the statement that planar isotopy — sliding beads up and down past each other on different strings — does not change the value of a diagram. Joyal and Street (1991) made this precise for monoidal categories: a well-formed equation follows from the axioms exactly when the corresponding diagrams are isotopic. Braided monoidal categories need three dimensions (strings may pass over and under), which is where knots and braids enter: see Knot theory.
Algebra— Categorification and 2-groups
Higher categories turn equations into isomorphisms: this is categorification. A group becomes a 2-group, a monoidal category in which every object and every morphism is invertible; 2-groups are classified up to equivalence by a group , an abelian group with a -action, and a class in (Sinh, 1975). Categorified representation theory replaces vector spaces by linear categories and linear maps by functors; Khovanov homology categorifies the Jones polynomial and Chuang and Rouquier's -categorification proved Broué's abelian defect group conjecture for symmetric groups (2008). See Categorical representation theory.
Physics— Extended topological field theories
Atiyah's axioms (1988) describe an -dimensional topological quantum field theory as a symmetric monoidal functor from a category of -manifolds and -dimensional cobordisms to vector spaces. Physical locality suggests going further down: cutting a manifold along codimension-2 pieces, and so on to points, which requires an -category of cobordisms with corners. Baez and Dolan's cobordism hypothesis (1995) predicts that fully extended framed TQFTs are classified by their value on a point, which must be a "fully dualisable" object. Lurie (2009) gave a detailed outline of a proof in the language of -categories; supplying every detail has been the subject of substantial later work. The heuristic (locality in physics) and the theorem (about -categories) should be kept apart. See Gauge theory.
Category theory— Enrichment and the 2-category of categories
A strict 2-category is precisely a category enriched in : hom-objects are categories and composition is a functor (see Enriched categories). A bicategory is the "weak" version, and iterating — enriching in the category of -categories — gives strict -categories, which is why strict definitions are easy and weak ones hard. Much of ordinary category theory is really 2-category theory in : adjunctions, monads and Kan extensions can be defined in any 2-category, and Street's "formal theory of monads" (1972) does exactly that.
Wonder Trails
History and global context
- 1950s–1960s: higher structure appears. Mac Lane and Whitehead (1950) classified homotopy 2-types by crossed modules. Eckmann and Hilton published their argument in 1962. Stasheff (1963) introduced the associahedra to describe homotopy-associative H-spaces, and in the same year Mac Lane proved coherence for monoidal categories. Charles Ehresmann (France) introduced double categories and 2-categories in the early 1960s.
- 1967: bicategories. Jean Bénabou's Introduction to bicategories defined bicategories, with spans as the motivating example.
- 1970s–1980s: the Sydney school and Grothendieck. Ross Street and Max Kelly in Australia developed 2-category theory (the formal theory of monads, 1972; Kelly–Street's Review of the elements of 2-categories, 1974). Street's "orientals" (1987) proposed a simplicial approach to -categories. Grothendieck's long letter-manuscript Pursuing Stacks (1983) set out the homotopy hypothesis.
- 1990s: dimension 3 and beyond. Gordon, Power and Street defined tricategories (1995). Kapranov and Voevodsky (1991) claimed that strict ∞-groupoids model all homotopy types; Simpson (1998) showed that the 3-type of is not modelled by a strict 3-groupoid. Voevodsky later described this episode as one of the motivations for his work on computer-checked proofs (see Homotopy type theory). Baez and Dolan (1995) formulated the periodic table, the stabilization hypothesis and the cobordism hypothesis; Batanin (1998) gave a definition of weak -category via globular operads, and Tamsamani (1999) and Simpson developed Segal-type definitions.
- 2000s–today. Leinster's survey (2002) and book (2004) organised the definitions; Lurie's work on -categories (2009) and many others moved the subject into homotopy theory; textbooks on 2-dimensional categories (Johnson–Yau, 2021) consolidated dimension 2.
Further reading
A suggested path: start with Lack's companion and Johnson–Yau for dimension 2, read Leinster's survey for the landscape, then Cheng–Lauda for pictures and Gurski for dimension 3.
- Stephen Lack, "A 2-categories companion", in Towards Higher Categories (2010).
- Niles Johnson and Donald Yau, 2-Dimensional Categories (2021).
- Jean Bénabou, "Introduction to bicategories", Reports of the Midwest Category Seminar (1967).
- Tom Leinster, "A survey of definitions of -category", Theory and Applications of Categories 10 (2002).
- Tom Leinster, Higher Operads, Higher Categories (2004).
- Eugenia Cheng and Aaron Lauda, Higher-Dimensional Categories: an illustrated guide book (2004).
- Nick Gurski, Coherence in Three-Dimensional Category Theory (2013).
- Robert Gordon, A. John Power and Ross Street, "Coherence for tricategories", Memoirs of the AMS 558 (1995).
- John Baez and James Dolan, "Higher-dimensional algebra and topological quantum field theory", J. Math. Phys. 36 (1995).
- Saunders Mac Lane, Categories for the Working Mathematician (2nd edition, 1998), Chapters VII and XII.