← back to notes

The Rubik's cube is a group

Why a puzzle toy is a clean lesson in group theory: invariants, commutators and God's number.

The Rubik’s cube looks like a puzzle about colours. It is really a puzzle about moves.

Moves form a group

Every sequence of turns is an element. Doing one sequence after another is composition. Every move can be undone, and doing nothing is the identity. That is exactly a group, and most of what makes the cube hard or easy follows from that one observation.

How many positions?

The 88 corners can be arranged in 8!8! ways and twisted in 373^7 ways (the last corner’s twist is forced by the others). The 1212 edges can be arranged in 12!12! ways and flipped in 2112^{11} ways (the last flip is forced). Finally, the permutation of the corners and the permutation of the edges must have the same parity, which halves the count. The number of positions is

N=8!⋅37⋅12!⋅2112=43,252,003,274,489,856,000≈4.3×1019\begin{gathered} N = \frac{8! \cdot 3^{7} \cdot 12! \cdot 2^{11}}{2} \\ = 43{,}252{,}003{,}274{,}489{,}856{,}000 \\ \approx 4.3 \times 10^{19} \end{gathered}

Not every arrangement of the pieces is reachable. Taking the cube apart gives 8!⋅38⋅12!⋅2128! \cdot 3^{8} \cdot 12! \cdot 2^{12} possible reassemblies, twelve times as many, so a cube put back together at random is solvable only one time in twelve.

Invariants: what never changes

Write ti∈{0,1,2}t_i \in \{0, 1, 2\} for the twist of corner ii, fj∈{0,1}f_j \in \{0, 1\} for the flip of edge jj, and σC,σE\sigma_C, \sigma_E for the permutations of corners and edges. Every face turn preserves three quantities:

∑i=18ti≡0(mod3),∑j=112fj≡0(mod2),sgn⁡(σC)=sgn⁡(σE).\begin{gathered} \sum_{i=1}^{8} t_i \equiv 0 \pmod{3}, \\ \sum_{j=1}^{12} f_j \equiv 0 \pmod{2}, \\ \operatorname{sgn}(\sigma_C) = \operatorname{sgn}(\sigma_E). \end{gathered}

These invariants explain the “impossible” positions people meet after reassembling a cube: no sequence of turns can fix a single twisted corner, because no turn can change the total twist.

Commutators do the real work

If AA and BB are two move sequences, then the commutator [A,B]=ABA−1B−1[A, B] = A B A^{-1} B^{-1} undoes almost everything, except where AA and BB interact. Choose AA and BB so that they overlap in only one or two pieces, and the result moves only those pieces. Most solving algorithms are commutators, or conjugates of the form XAX−1X A X^{-1}: move the pieces into position, act on them, move everything back. Once this clicks, the cube stops being a list of sequences to memorise and becomes something you can design.

God’s number

Every position can be solved in at most 2020 moves, counting a half turn as one move. This was proved in 2010 by Tomas Rokicki, Herbert Kociemba, Morley Davidson and John Dethridge, who split the positions into cosets and checked them with about 35 CPU-years of computing time donated by Google. Counting only quarter turns, the answer is 2626 (2014). Human methods are far from optimal: a typical speedsolve with the CFOP method takes roughly 5555–6060 moves.

Why I like it

The cube is the cleanest example I know of a pattern that keeps coming back in mathematics and computer science: describe the moves, find what they preserve, then build small tools that change exactly one thing.