A duelist's last night, a schoolteacher's logic textbook, and a theologian-adjacent set theorist — three unfashionable ideas that turned out to be the operating system of modern math (and your laptop).
Paris, 30 May 1832. A 20-year-old spends what he knows might be his last night scribbling math in the margins of his own manuscript, racing the sunrise. By morning he's shot in the gut on a duelling field. He dies two days later. The notes survive — and they quietly end a 300-year manhunt.
The young man is Évariste Galois: failed his college entrance exam (twice), got expelled, got jailed for republican politics, and could not get the era's top mathematicians to read his work. The manhunt he ended was the one we watched start back in Chapter 2: the hunt for a formula. You learned the quadratic formula in school — plug in a, b, c, get the roots of any ax² + bx + c = 0. Italian Renaissance mathematicians found a (monstrous) cubic formula, then a quartic one. The degree-5 equation — the quintic — held out for centuries. Everyone assumed the formula existed and was just hard to find.
Galois's answer was not "nobody has found it yet." It was sharper and more disturbing: it cannot exist, and here is exactly why. His move was to stop staring at the equation and start staring at the symmetries of its roots — the ways you can shuffle the solutions among themselves without the algebra noticing. For a quintic, those shuffles form a structure too tangled to be unwound by the step-by-step "take a root, add, multiply" recipe that a formula is. The obstruction is the symmetry. No amount of cleverness gets around it, because the barrier isn't difficulty — it's shape.
That idea — judge a problem by the symmetries hiding inside it — is the seed of this whole chapter. To see it, we first need to nail down what "symmetry" even means when you make it precise.
Forget equations for a second. Pick up a square coaster. Rotate it 90°. Looks identical, right? Flip it over. Still identical. Symmetry is just this: the moves you can make on a thing that leave it looking unchanged. The interesting part isn't any single move — it's how the moves combine.
Three things are always true about these moves, and you already know all three from code:
Composition, inverse, identity. That package — that exact trio — is the whole definition. When a set of operations comes wrapped with those three guarantees, mathematicians call it a group. Notice we named the thing last: the package came first, the label after. That's the right order. A group isn't a mysterious abstract object; it's the bookkeeping for "what stays the same when you move a thing."
And once you have the vocabulary, you see groups everywhere: the rotations of a clock face, the shuffles of a deck of cards, the moves on a Rubik's cube (every legal twist is reversible, twists chain, and "don't touch it" is the identity), the key-schedule of a block cipher. All groups. The widget below lets you build one with your hands — the symmetries of a triangle.
Galois died before anyone understood him. It took a generation to dig the idea out. In 1854 Arthur Cayley — a London barrister who did mathematics on the side because the day job paid better — wrote down groups abstractly: never mind triangles or roots, here are the bare rules (compose, invert, identity), study anything that obeys them. That's the same abstraction leap you make when you write trait Group[A] instead of hard-coding one case. Define the interface once; every instance comes for free.
And the instances poured in. Chemists classify crystals and molecules by their symmetry groups — whether a molecule is chiral (has a non-superimposable mirror image, which decides whether a drug heals you or poisons you) is a pure group-theory question. Physicists found something even wilder: in 1915 Emmy Noether proved that every continuous symmetry of the laws of physics corresponds to a conserved quantity. Time-shift symmetry ⇒ energy is conserved. Space-shift symmetry ⇒ momentum is conserved. Conservation laws aren't separate rules of the universe; they're symmetry wearing a disguise. (We'll give Noether her own scene in Chapter 9.)
And your code uses it constantly — usually without the inverses. Whenever you have an operation that's associative (grouping doesn't matter: (a·b)·c = a·(b·c)) and has an identity element, you've got a monoid: string concatenation with "", integer addition with 0, list append with Nil, the merge step of a parallel reduce. A group is just a monoid where every element also has an undo. You ship monoids to production every week. We'll formalize that lineage in the code card — and chase it properly in Chapter 9.
Meanwhile, in a different corner of the 19th century, a self-taught English schoolteacher was quietly committing heresy. George Boole — no university degree, ran a school to support his family from age 16 — had a deceptively simple idea, published in 1854 as An Investigation of the Laws of Thought: logic isn't philosophy, it's arithmetic. Reasoning is calculation, if you pick the right number system.
The number system has exactly two values: 1 (true) and 0 (false). And the operations look almost like ordinary algebra:
&&.From those, everything in logic becomes algebra you can manipulate. And the most useful manipulation rules are De Morgan's laws — named for Boole's friend Augustus De Morgan — which you already apply in code review without naming them:
"It's not the case that both checks passed" is the same as "at least one check failed." Push a negation inside, and AND swaps with OR. Every time you rewrite !(a && b) as !a || !b to flatten a guard clause, you're invoking De Morgan. Boole turned the moves in your head into an algebra with laws. Build a circuit out of those laws below.
For 80 years Boolean algebra was a logician's curiosity — elegant, mostly useless. Then a 21-year-old MIT grad student named Claude Shannon wrote, in 1937, what's been called the most important master's thesis of the century. He noticed something nobody had: the telephone relay circuits he was wiring up — switches that route current, in series and in parallel — are Boolean algebra. A switch in series with another is AND. Two in parallel is OR. A relay that opens when energized is NOT.
Suddenly Boole's two-value arithmetic wasn't a curiosity — it was a design language for machines that compute. Want a circuit that does some logical function? Write the Boolean expression, simplify it with De Morgan and the other laws (fewer terms = fewer switches = cheaper hardware), then translate each operation into wires. Every digital chip ever built since is, at bottom, Boole's algebra compiled down to silicon. The widget you just played with is a baby version of exactly that pipeline.
We'll tell Shannon's full story — including his other 1948 paper, the one that invented information itself — in Chapter 8. For now, just hold the through-line: a schoolteacher's algebra of true-and-false became the operating principle of the device you're reading this on.
Third paper, third quiet revolutionary. Georg Cantor, 1874, asked a question that sounds childish and turns out to be a depth charge: are all infinities the same size?
First he had to define "same size" for things you can't count to the end of. His definition is beautiful and you already use it: two collections are the same size when you can pair them off perfectly — match every item on the left to exactly one on the right, with nobody left over on either side. A bijection. You don't need to count two bags of marbles to know they're equal; just pair them up. That works for infinite bags too.
Now the vertigo. Take the natural numbers 1, 2, 3, 4, … and the even numbers 2, 4, 6, 8, …. The evens are "obviously" half as many — they're a subset, you threw away all the odds. But pair n ↔ 2n: 1 pairs with 2, 2 with 4, 3 with 6, forever, nobody left over. Perfect pairing. So there are exactly as many even numbers as numbers. A part equals the whole. (This is the engine behind Hilbert's famous fully-booked hotel that can always fit one more guest — shift everyone down a room. Same trick.)
Fine, you think — infinity is just weird, and all infinities are this one weird size. That was the reasonable guess. Cantor detonated it. He proved that the real numbers — every point on the number line, every infinite decimal — cannot be paired with the naturals. No matter how clever your pairing, reals are left over. There are strictly more reals than naturals. There's infinity, and then there's a bigger infinity. And the proof is one of the most beautiful constructions in all of mathematics. Next section, with a widget.
Here's how Cantor proved the reals outrun the naturals — stripped down to its skeleton. Instead of decimals, use infinite binary sequences (each is just an endless string of 0s and 1s; there are exactly as many of those as there are reals). Suppose someone hands you a complete list of them — row 1, row 2, row 3, … one sequence per natural number, and they swear every binary sequence is somewhere on the list.
You don't argue. You build a counterexample by construction. Walk down the diagonal: take the 1st bit of row 1, the 2nd bit of row 2, the 3rd bit of row 3, and so on. Now flip every one of those bits and string the flips together into a brand-new sequence, call it d.
Where is d on the list? It can't be row 1 — it differs from row 1 at position 1 (you flipped that bit). It can't be row 2 — it differs at position 2. It can't be row k for any k, because by construction d differs from row k at position k. So d is a perfectly good binary sequence that is on nobody's row. The "complete" list was incomplete. And this works against any list you're handed — there's no patch. The reals cannot be enumerated. Step through it:
Burn this move into memory. The pattern — "assume a complete listing, then build the one thing it must have missed by disagreeing on the diagonal" — is called diagonalization, and it is the single most reused trick in this book. It detonates twice more: in Chapter 7 Gödel diagonalizes against the list of all provable statements to build a true-but-unprovable one, and Turing diagonalizes against the list of all programs to prove no program can decide whether programs halt. The same flip-the-diagonal escape, weaponized against proof and against computation. (It comes back one last time in Chapter 13, against the Busy Beaver.) One trick, three earthquakes.
Cantor paid for his heresy. His former teacher Leopold Kronecker — who held that "God made the integers, all else is the work of man" — campaigned against him, blocked his papers, blocked his jobs. Cantor spent his later years in and out of sanatoria. But the next generation saw what he'd built. David Hilbert, the most powerful mathematician alive, drew the line in the sand: "No one shall expel us from the paradise that Cantor has created." Set theory — collections, membership, pairing-off — became the bedrock everyone agreed to build on. Numbers, functions, spaces: all of it could be defined as sets of sets. Math finally had a foundation.
Except the foundation had a crack, and a 27-year-old named Bertrand Russell found it in 1901 with a single sentence. If a set can contain anything, consider the set of all sets that do not contain themselves. Call it R. Now ask the fatal question: does R contain itself?
Either answer is wrong. It's the barber who shaves exactly those who don't shave themselves — does he shave himself? — but now it's lethal, because it's aimed at the brand-new foundation of all of mathematics. Cantor's paradise had a self-referential loop coiled in its basement, and Russell's paradox proved the naïve "a set is any collection you can describe" rule is flat-out inconsistent.
So: three quiet papers handed the 20th century unimaginable power — symmetry as a master key, logic as machinery, infinity made countable in tiers — and one of them came pre-loaded with a paradox that threatened to bring the whole building down. What do you do when your foundations contradict themselves? That panic has a name — the foundational crisis — and it's the entire subject of the next chapter. It does not resolve the way anyone hoped.
The whole chapter's first big idea — compose, invert, do-nothing — is just an interface you can write down. Here it is both ways. Read combine as "do one symmetry, then the other" — exactly the r-then-f chaining the triangle widget did. The Haskell version makes the lineage explicit: a Group is a Monoid that also knows how to undo.
Three unfashionable papers, one operating system for modern math. Galois gave us groups — the algebra of symmetry, the lens that decides what's possible by looking at what stays the same. Boole gave us a logic you can compute — true and false as arithmetic, which Shannon would solder into every chip. Cantor gave us infinity in sizes, plus the diagonal argument — the most dangerous proof technique in the book. None of it was fashionable when it landed. All of it is load-bearing now.
But Cantor's paradise shipped with Russell's paradox in the basement, and that crack runs straight into the next chapter. The whole confident project of putting mathematics on an unshakeable mechanical foundation is about to meet two young men who prove it can't be done — and one of them invents the computer by accident, just to make the point.