~/ ~/documents ~/recommended-reading ~/software ~/pictures github (opens in new tab)

From Sets to Categories: Isomorphism and Structural Sameness

Part 2 of the “From Sets to Categories” series, exploring mathematical foundations through the lens of composition.

What do we actually mean when we say two things are “the same”?

This is something I really enjoy about Unequal by Eugenia Cheng: the way it explores that question rather than treating the answer as obvious. “The same” feels like such an ordinary phrase until you stop and ask what, exactly, you’re comparing. The way two things look? The information they carry? What you can do with them?

That way of thinking makes the abstraction feel worth learning to me. I don’t want another intimidating word to memorise. I want a better way to explain why two things can look different yet be interchangeable for a particular purpose, and when that comparison stops working.

Suppose your weather app lets you switch between Celsius and Fahrenheit. A reading of 0∘C0^\circ\text{C} becomes 32∘F32^\circ\text{F}. The weather hasn’t changed, and neither has the temperature being reported. We’ve just changed how we write it.

The useful part is that we can go back. Provided we keep the exact values rather than rounding them for the display, converting in either direction and back returns the reading we started with. Neither representation knows something the other has forgotten.

That’s the distinction I want us to keep hold of here. The numbers aren’t equal, but the two temperature scales can express the same information. The reversible conversion between them is an example of an isomorphism. The word sounds more intimidating than the idea: we can change the representation without losing anything.

graph LR
    A["Domain A (e.g., Celsius)"] -->|"f (to Fahrenheit)"| B["Domain B (e.g., Fahrenheit)"]
    B -->|"g (to Celsius)"| A
    A -.->|"g ∘ f = id_A"| A
    B -.->|"f ∘ g = id_B"| B

1. Invertible Morphisms

In Part 1, we saw that functions express many-to-one relationships. Multiple inputs can collapse onto a single output (such as is_even(x) mapping integers to booleans), and some outputs in the codomain may never be hit.

When a function is strictly one-to-one (injective) and covers the entire target (surjective), a unique property emerges: invertibility.

If we reverse the direction of every arrow, the resulting mapping is still a valid function.

Internal Definition: Two sets AA and BB are isomorphic if there exists a one-to-one and onto relationship between their individual elements.

This internal definition forces us back into element-level bookkeeping. We have to peer inside the sets, verify every element, and check that no two elements collide.

Let’s leave the letters alone for a moment and collect our coats.

Imagine handing your coat over at a cloakroom and getting a numbered ticket. You want that ticket to identify your coat, not leave the attendant choosing between yours and someone else’s. And if we’re looking at the tickets that have been handed out, each should have a coat waiting for it.

That’s what those two terms are getting at. “One-to-one” means no shared ticket; “onto” means no handed-out ticket without a coat. Get both right and you can match things up in either direction. The language is formal, but the arrangement is quite familiar.

Can we define isomorphism without ever mentioning elements?

2. The External Definition of Isomorphism

Consider what happens when you apply an invertible function f:A→Bf : A \to B, and then immediately apply its reverse function g:B→Ag : B \to A.

For every element a∈Aa \in A: (g∘f)(a)=g(f(a))=a(g \circ f)(a) = g(f(a)) = a

The composite function g∘fg \circ f maps every element of AA to itself. In other words: g∘f=idAg \circ f = \text{id}_A

Similarly, if we start at BB, apply gg, and then apply ff: f∘g=idBf \circ g = \text{id}_B

This gives us our first purely categorical, external definition:

External Definition: Two objects AA and BB are isomorphic (denoted A≅BA \cong B) if there exist morphisms f:A→Bf : A \to B and g:B→Ag : B \to A such that: g∘f=idAandf∘g=idBg \circ f = \text{id}_A \quad \text{and} \quad f \circ g = \text{id}_B

Notice what just happened. Not a single element was mentioned.

The entire concept of structural equivalence is formulated using only three primitives:

  1. Objects (A,BA, B).
  2. Morphisms (f,gf, g).
  3. The identity morphism and composition (id,∘\text{id}, \circ).
graph LR
    A((A)) -->|"f"| B((B))
    B -->|"g"| A((A))
    A -->|"id_A"| A
    B -->|"id_B"| B

In category theory, this is the foundational pattern: we define the internal character of objects purely by observing how external arrows enter, leave, and loop back through them.

Here’s how I’d check whether we’ve really kept everything.

Suppose you rewrite a diary entry from 15:00 to 3:00 PM. You can turn it back into 15:00 without asking me anything. But if I leave off the PM, you’re stuck: did I mean three in the morning or three in the afternoon?

That’s the little test I want us to keep in mind. Can we go there and back without filling in a gap or making a guess? We need that to work whichever clock format we start with. The equations above are a precise way of asking that question.

3. Isomorphisms as Equivalence Relations

In formal logic, a relationship ∼\sim is an equivalence relation if it satisfies three axioms that capture intuitive equality:

  1. Reflexivity: Every object is related to itself (A∼AA \sim A).
  2. Symmetry: If A∼BA \sim B, then B∼AB \sim A.
  3. Transitivity: If A∼BA \sim B and B∼CB \sim C, then A∼CA \sim C.

Isomorphism (≅\cong) satisfies all three laws:

Reflexivity

Every object AA is isomorphic to itself via its identity morphism idA\text{id}_A: idA∘idA=idA⟹A≅A\text{id}_A \circ \text{id}_A = \text{id}_A \implies A \cong A

Symmetry

If f:A→Bf : A \to B has inverse g:B→Ag : B \to A, then by definition gg has inverse ff: A≅B⇔B≅AA \cong B \iff B \cong A

Transitivity

There’s a familiar idea underneath the next bit of algebra.

Take a length of two metres. That’s 200 centimetres, which is 2,000 millimetres. To get back, divide by ten to recover the centimetres, then by a hundred to recover the metres. We’re back at two.

Nothing particularly surprising has happened. If we can undo each step, we can undo the whole journey by working backwards. That’s all the calculation below is proving, without tying it to these particular units. If the letters start to blur together, keep that journey in mind.

Suppose A≅BA \cong B via (f,g)(f, g) and B≅CB \cong C via (j,k)(j, k). We can compose the forward arrows and backward arrows: Forward: j∘f:A→C\text{Forward: } j \circ f : A \to C Backward: g∘k:C→A\text{Backward: } g \circ k : C \to A

Composing them: (g∘k)∘(j∘f)=g∘(k∘j)∘f=g∘idB∘f=g∘f=idA(g \circ k) \circ (j \circ f) = g \circ (k \circ j) \circ f = g \circ \text{id}_B \circ f = g \circ f = \text{id}_A

And in reverse: (j∘f)∘(g∘k)=j∘(f∘g)∘k=j∘idB∘k=j∘k=idC(j \circ f) \circ (g \circ k) = j \circ (f \circ g) \circ k = j \circ \text{id}_B \circ k = j \circ k = \text{id}_C

Therefore, two isomorphisms compose into a new isomorphism: A≅B∧B≅C⟹A≅CA \cong B \land B \cong C \implies A \cong C

graph LR
    A((A)) -->|"f"| B((B))
    B -->|"j"| C((C))
    C -->|"k"| B
    B -->|"g"| A
    A -.->|"j ∘ f"| C
    C -.->|"g ∘ k"| A

Because isomorphism is a strict equivalence relation, we can partition our entire mathematical and computational universe into equivalence classes of isomorphic structures.

4. Treating Isomorphisms as Equality

Category theory adopts the following principle:

Category theory is what you get when you treat isomorphisms as equality.

In set theory, two singleton sets {1}\{ 1 \} and {"apple"}\{ \text{"apple"} \} are technically unequal because 1≠"apple"1 \neq \text{"apple"}. Set theory distinguishes them based on element identity.

In category theory, this distinction is irrelevant. Between any two singleton sets 11 and 1′1', there exists exactly one arrow going forward and exactly one arrow going backward:

graph LR
    One["1 = {*}"] -->|"f"| OnePrime["1' = {•}"]
    OnePrime -->|"g"| One

Their compositions must equal the respective identity arrows: g∘f=id1,f∘g=id1′g \circ f = \text{id}_1, \quad f \circ g = \text{id}_{1'}

All singleton sets are isomorphic, and furthermore, they are isomorphic in exactly one unique way.

To a category theorist or a compiler engineer, arguing whether a unit value is represented by a 0-bit memory slot or a dummy pointer is a meaningless implementation detail. They have the exact same categorical behavior: they are unique up to unique isomorphism.

Let’s make “unique up to unique isomorphism” a little less of a mouthful.

Imagine two very simple forms. One only lets you reply “Done”; the other only lets you reply with a tick. To translate between their sets of possible replies, “Done” has to become the tick, and the tick has to become “Done”. There’s nothing else to choose.

That’s why there is exactly one translation each way. Of course, you might find one form clearer than the other. We’re not dismissing that; we’re just asking a narrower question about the possible replies. For that question, these differently labelled one-element sets behave alike.

5. Type Isomorphisms in Software

In functional programming languages (Haskell, Rust, Gleam), common type isomorphisms include:

  1. Tuple Commutativity: (A,B)≅(B,A)(A, B) \cong (B, A) swap : (A, B) -> (B, A) and swap : (B, A) -> (A, B).
  2. Unit Identity: (A,())≅A(A, ()) \cong A Pairing any value with () contains no more information than the value itself.
  3. Currying: (A×B)→C≅A→(B→C)(A \times B) \to C \cong A \to (B \to C) A function taking a pair of arguments is structurally identical to a function taking one argument and returning a new function.

When two types are isomorphic, any property, function, or theorem proven for one can be mechanically transferred to the other without rewriting logic.

Here’s where I’d be a little careful with “the same”.

Suppose one form keeps your given name and family name in separate boxes. Another keeps the same two boxes in the opposite order. Moving the answers across is easy, and we can put them back exactly as they were.

Now suppose I replace both boxes with one and join the names with a space. That looks simpler, but how do I split them again? A given name or family name might itself contain spaces. Without another rule, I’ve made you guess.

That’s the distinction these type examples help us notice. Different arrangements can keep exactly the same information; a tidier-looking arrangement might not. And even when we can go back perfectly, doing the conversion may still take time or memory.

Part 3 applies this external perspective to construct products and sums using arrows and universal properties.


Previous: Part 1: Collections and Arrows

Next: Part 3: Universal Constructions and Duality