Smiting the Demon Number: How to Solve a Rubik's Cube
- Published on
- ∘ 70 min read ∘ ––– views
Tags
Previous Article
Next Article
I talk to God as much as
I talk to Satan 'cause
I want to hear both sides1
Introduction
Lots of posts about numbers recently, eh? Well, here's another: in which, we solve a Rubik's Cube.
Two dueling, and even contentious properties of Rubik's Cubes are (1) the massive number of possible scrambles, and (2) that any of these scrambles is only 20 or so (contentious) moves away from being returned to the solved state. Due to the at-first unintuitive idea that, no matter how many twists we apply to a Rubik's cube to make it thoroughly jumbled, it can be solved in just twenty moves, that number has been dubbed God's Number.2 For the sake of motivating this post, I choose to anthropomorphize the search space of solutions to be the Demon Number.
The goal of this post is then to mathematically describe the process of moving the pieces of a valid configuration of a standard 3x3x3 Rubik's cube, and –in doing so– smite the Demon Number.
Group Theory
I have a couple other poasts that provide brief summaries of basic group theory.3 If you're starting from zero, those might be worth checking out, but this post should also be comprehensive enough (in terms of definitions, perhaps not proofs) to fill in the gaps to get the average reader up to speed. If you feel out of your depth, that's the fault of my shite writing, and not at all an indication of the readers' competency. Also worth noting that this post largely stands on the shoulders of the research and lectures of Janet Chen,4 once again I offer my meager commentary and observations about the mathematics in terms of cubing.
A Group consists of a set , and a binary operator such that:
- is closed under , that is if , then
- The operator is associate: ,
- There exists exactly one identity element satisfying
- Every element in has exactly one inverse: such that . We might also refer to the inverse as .
The order of an element of a group is the smallest such that is the identity. For example, the order of the sexy move is six, since the move is a 6-cycle, meaning that 6 repetitions of that sequence of twists returns the cube to whatever state it started in, which is equivalent to the identity: doing nothing. The largest order of a move is 1260 – one such move is which is like the least sexy move.
Taxonomy of The Cube
For this post, I focus on only the original 3x3x3 cube ("The Cube"), but the techniques described later on can be (in some cases, non-trivially) generalized to other cubes.
The standard cube is composed of 26 pieces ( external faces center core piece which we can't see or meaningfully manipulate, so we don't have to worry about solving). There are 8 corners, 12 edges, and 6 center pieces; the center pieces we can also largely ignore since they are fixed in place relative to one another.5 One of the first intuitions that novice cubers acquire is that, for standard color schemes, white is opposite yellow, green opposite blue, and red opposite orange; with the additional piece of relative positioning information that yellow is left of orange and also adjacent to blue, we can form the complete standard color scheme.
The cube obviously has 6 faces, which we've established have positions derived from their fixed centers, allowing us to completely describe the "correct" solved position of any piece in terms of the face it belongs to. For example, listing a corner's faces in clockwise order unambiguously refers to precisely one piece.6
For example, refers to the yellow, red, blue piece:
It is also conventional to refer to corner pieces by their face labels listed in clockwise order when the orientation matters. Edges only have two possible orientations, so there is less ambiguity.
Along with the pieces themselves, it's useful to uniquely denote the position they belong in: their cubicles. Cubicles form the skeleton of the cube; they do not move, but pieces move in and out of them.
A move is any 90º turn of a face.7 Thus, we have six primitive moves and their inverses (denoted with an apostrophe, or sometimes a negative superscript), from which we can completely manipulate the cube, for a total of 12 primitives:
I'll refer to this set of primitives as . Typically, (as in, in my head, I read the inverse moves as "prime").8
As mentioned above, we have four distinct categories for pieces: corners, edges, centers, and core(s) – only two of which we care about (corners and edges) since the rest cannot be meaningfully manipulated. These categories are distinct since edges can never inhabit corner cubicles and vice versa.
The Demon Number
The complexity of the cube is given by the number of permutations of each piece in each possible cubicle, confounded with the number of possible orientations each piece can have in each cubicle. Straightforwardly, we arrive at:
The Demon Number.
Here, we delineate between permutation and orientation, which are likely familiar notions to any students of intermediate speed cubing techniques such as CFOP: a method where the executor first solves the (C)ross, then completes the (F)irst two layers, then (O)rients the pieces on the last later (OLL), and finally (P)ermutes the pieces of the last layer to their final positions (PLL).9
We'll shortly convince ourselves that –though daunting– this number/search space can be drastically thinned by discounting invalid configurations. For example, one single corner twist is considered an invalid configuration due to the concept of parity. Formal definitions of what a configuration is, what makes one valid are forthcoming, and what the hell parity means in the context of a puzzle-toy. Thus, our immediate goal is to widdle away at the Demon Number.
We say that a configuration or cube-state is valid if it can be reached from the initial, pristine and solved cube-state using only the legal moves described above. We call this solved configuration . Notably absent from the list of legal moves is anything resembling "pealing the stickers off" or "just taking the pieces out." These are trash.
Though we have yet to show that the standard cube is in fact group, the general goal of "solving" is to produce a sequence of moves that can take us from any valid state to the solved state .
The Cube is a Group, Dammit!
We can construct our cube group with the set of all possible moves , which includes sequences of the primitive moves described above. Two moves are identicial if they result in the same configuration when applied to the cube. E.g.
The group operation is composition, denoted , such that for , is the move consisting of followed by . Note that, though is clearly more than just one twist, we can refer to the composition as still just a single move. So, moves can be sequences of twists.
Thus, is a group since the behavior we've described adheres to the four fundamental properties of groups defined earlier:
- is closed under since, if are moves, must also be a move.
- The identity on is the no-op , so has a right identity.
- If is a move, we can reverse all the steps of to get an inverse which is also equivalent to the no-op , therefore every move in also has a right inverse.
- Lastly, is associative. Recall that a move is also described by the spacial permutation and orientation it leaves each piece in. If we care about the orientation of a piece, we write for the oriented cubicle that the piece ends up in after application of move , with the faces of written in the same order as the faces of . That is, the first face of should end up in the first face of , and so on.
For example, the move puts the piece in the cubicle, with the face of the piece lying on the face of the cubicle and the face of the piece lying in the face of the cubicle. Thus, we would write .
For the move , moves to , and moves it to , so
To show that is associative, we need to show that
for all . That is, both the sinistral side and dextral sides of this equivalence relation must do the same thing to every piece , leaving the cube in identical configurations.
So, composition is associative, and therefore is a group!
Subgroups and Generators
The Demon Number is frightening because, in order to find our solution, we have sparse moves in an infinite10 search space. To hack away at the :ghost: spooky number, we first want to examine the subgroups of to extract any patterns or properties that might be helpful in our quest.
Any nonempty subset of is called a subgroup of .11 A group is always a subset of itself.
Let be a group. A nonempty subset of is a subgroup of iff .12
If is a subgroup of some group , we say that generates if ; that is, every element of can be written as a finite product (under group operation, whatever it is) of elements of and its inverses.
This is useful in reducing The Demon Number since we can more thoroughly state that center positions need not be considered.13
Peter uses subgroups, it's super effective.
The Symmetric Group and Cycles
Recall that there are possible positions of the set of corners in the cubicles. To better understand how these possibilities impact our solution attempts, consider the general case of configuring objects labeled into buckets, similarly labeled.
We define a bijection between pieces and labeled cubicles:
by being assigned to the object put into slot , where .
The symmetric group on letters is the set of bijections from , with the operation of composition; we write this group as .
For example, let be defined by
which implies
Notice that these subsets of the symmetric group, as well as their composition, form cycles. We can express cycles in groups as
where and so on. So we have three cycles in this arbitrary mapping .
Formally, a cycle is the element defined by
where if . The length of a cycle is and the support of the cycle is the set of elements which appear in the cycle, denoted .
Two cycles are disjoint if they have no supporting elements in common: .
If is the product of disjoint cycles of lengths (including its 1-cycles), then the integers are the cycle-type of .
Applying this ish to The Cube
We can use a modified cycle notation to describe what happens to each corner piece after applying a move to a configuration with respect to both its permutation and its face's orientations.
To illustrate this, we "unfold" part of the cube and examine the partial diagram of its faces after a move, we can see the effect the move has on all the pieces in that slice.
We can describe this effect on a single piece, e.g. since the piece goes to the cubicle. Using the above cycle notation, we can describe the effect for all the impacted pieces as:
where each piece just traverses the clockwise orbit around the centerpiece.
Configurations
Recall that a configuration is completely described by:
- The positions of the corners
- The positions of the edges
- The orientations of the corners
- The orientations of the edges
1 and 2 can be described by respectively, where are the symmetric sets of moves that take the corners or edges from their starting positions to new positions.
To tackle 3 and 4, we need some more notation to describe the orientation of a piece relative to its starting state.
Corner Configuration
Each corner has three possible orientations which we number . We then systematically label each face of every corner cubicle:
So each corner piece has 1 face lying in a labeled cubicle. We label this corner face , then continue around the cube clockwise, labeling the other corner faces and .
Now, each corner piece has each face labeled. For any integer , we can find the cubicle face with that label, and let be the number of the corner piece face which indicates its orientation on this face. This gives us an ordered 8-tuple
which contains all the corner orientation information for a configuration. We can think of each as the number of clockwise twists that that corner is away from having it's -face in the numbered face of the cubicle (the solved orientation). Observe that a corner piece that is 3 twists away from being solved is identically oriented to that of a piece which is already solved (0 twists away), so we can think of elements of each as being elements of the . Thus, is an 8-tuple of elements of , where each element .
For example, examining the slice of the cube:
The face is unaffected by an move, so we have:
Edge Configuration
We can repeat this same labeling process for edges. First, we assign cubicle labels (somewhat arbitrarily, as long as the system is internally consistent):
Each piece now has a face lying on a numbered edge cubicle. We label this edge face and the other one . We let be the number of the edge piece face in the cubicle face labeled yielding
With this orientation notation, we can completely describe any configuration of
as a 4-tuple .
Example
A common algorithm used in the beginner's method during the last step –orienting the corners of the last face– is a six-cycle .14 If we jot down the 4-tuple for this algorithm, we get:
from which, we also get their inverses:
So, the composition of the crycles listed in the complete algorithm is:
which has two 6-cycles in terms of corner orientation, and a single 3-cycle in terms of edges.15
Recall that , an element of , is a bijection from the set of 12 un-oriented edges to the 12 edge cubicles, and can be expressed in disjoint cycle notation. Here, moves , , and , so . And, similarly, can be expressed (without regard to orientation) as .
From our labeling scheme for corners, we can see that leaves unaffected, and that this algorithm puts the face of corner into the face of , so the face of is 2: , and similarly . All together:
Similarly for the edges, only affects edges of the edges. We know from the labels that only may be non-zero, but incidentally, their orientations remain unchanged after 1 iteration of the 6-cycle, so .
Group Homomorphisms
A homomorphism is a weaker condition than the structural and relational equivalence defined by an isomorphism. A homorphism exists when sets have the same algebraic structure, but they might have a different number of elements.
Formally, if we let and be two groups. A homomorphism from to is a map such that
We can define a map as any move in which rearranges the corners (that is, all moves other than the identity and equivalent moves). That is, for any , define some permutation . Let such that is the element of which describes what does to the unoriented pieces. Taking the familiar which has the disjoint cycle composition
Therefore, . That is, the corner without respect to orientation.
Similarly, we define by letting be the element of which describes what does to the twelve unoriented edges e.g. .
With these two homomorphisms, we can define the "cube" homomorphism:
which describes the permutations of the twenty unoriented edges and corners.
The Sign Homomorphism
We know from properties of generators that is generated by the 2-cycles in . That is, any permutation in can be written as a finite product of 2-cycles. However, any given permutation of can be written as a finite product of 2-cycles in infinitely many ways (actually infinite, not just like "big numbie" infinity). So this isn't super useful.
Some permutations in can be expressed as a product of even number 2-cycles; aptly referred to as even permutations. Conversely, all the other permutations of , written as a product of an odd number of 2-cycles are called odd permutations. At the moment, it might seem like there's no reason why a permutation couldn't be both odd and even, but as the name suggests: that is –in fact– impossible.
The direct proof is gross, so we'll indirectly approach this statement.
Proof of Permutation Parity
We fix and let be a polynomial in variables. That is, if is a polynomial in the variable so that has the shape:
So is a sum of terms that look like . For , is the sum of terms that look like . In general, is the sum of terms that look like
If , we say is the polynomial defined by
We simply replace with . For , , and has a cycle decomposition . Then
And note that, for any . To prove the assertion about disjoint even and odd permutations, we apply the above decomposition to the following polynomial:
E.g., for . So, for any . For :
Alternatively, for
with the idea being that we match terms of with the terms of . That is, for each , either or its negation appears in . It follows from the definition of that
The unrigouresness proof of this follows from the definition of a map by . We know that
Therefore, , so is a homomorphism called the sign homomorphism. We define that if is a 2-cycle, then .
Proof: Let , so for the sign homomorphism we have:
and expanding for separately we have
So we've proved the theorem for , which can be generalized to any 2-cycle, but there's an easier, softer way. If we let be any 2-cycle, we say that is a conjugate to , meaning
Since is a homomorphism,
and since is multiplicative, if , then must be a product of an even number of 2-cycles. Similarly, if , it must be the product of an odd number of 2-cycles. So, is even iff , and odd iff .
For example, is even, and just is odd. since
is the product of four (an even number!) 2-cycles. In general, if is a -cycle, then
The Alternating Group and Parity
Like the set of real numbers, the parity of a group is multiplicative. That is, the product of an even permutation and an odd permutation is odd, the product of two even permutations or two odd permutations as even. The inverse of an even permutation is even, the inverse of an odd is odd, so we can define a subgroup of of the symmetric group consisting of all even permutations called the Alternating Group: :
If is a face twist, then is a product of two 4-cycles. A 4-cycle:
is a product of an odd number of 2-cycles, is also odd, so two 4-cycles is even. Therefore is even. And since the face twists generate all of , is even for all . So .
Recall that , so either the edge homomorphism or corner homomorphism are both even, or both odd– but they must have the same sign. So, for any valid configuration , the sign of must be the same.
Kernels
The kernel of a homomorphism is defined to be the pre-image of the identity of in
The kernel consists of all moves of the cube which do not change the permutations of any pieces. That is, only the moves that change the orientations, which is straightforwardly useful. In particular, is the kernel of .
Group Actions
If the cube is in some configuration , the applying some move takes the cube state to a new configuration we call . If we take another move , we can compose or chain the resulting states together:
which is the same as executing on directly. This is the essence of group actions.
Formally, a right Group Action of on a non-empty set is a map . That is, given we can produce another element of , for which we write satisfying the following properties:
These are called right group actions since we associate group elements on the right. When we have a group action of on , we say that " acts on ." acts on the set of configurations of the cube (both valid and invalid).
Oftentimes, we are interested in the case where the set is the group itself. For we def to just be group multiplication. If acts on a set , the orbit of under this action is the set . We can think of orbits as the configurations that are reachable by repeating some (sequence of) move(s).
If acts on the set of configurations of the cube, the orbit of the starting configuration under this action is exactly the set of valid configurations of the cube. This is a super nifty tid bit which further eradicates the spookiness of the Demon Number.
If a group action only has one orbit, we say that the action is transitive, or that the group acts transitively. We often want to prove something about all the elements of an orbit, like oh I don't know, all valid configurations of a cube.
Suppose a finite group acts on a set , and let be a set of generators of , and be some set of conditions such that the following is true: whenever satisfies and , also satisfies . Then, if satisfies , then every element in the orbit of also satisfies ! In the case of the cube, we will apply this theorem to the action of on the set of configurations, where in order to prove other statements about the set of valid configurations.
Pragmatically speaking, acts on the set of configurations of the cube. The valid configurations, then, form a single orbit of this action, so it makes sense that the statements we make about valid configations can be generalized to other orbits.
Valid Configurations of the Cube
Six and a half thousand words in and I'm just now getting pissed that there's no Rubik's cube emoji. WTF unicode, get it together.
Using all this notation and abstraction of the innocuous toy from the seventies into dumb made up math, we can form characterizations of the cube which actually help us solve it. Only a couple more theorems, I promise.
THEOREM!! : A configuration is valid iff each of the following conditions are met:
Lemma: If are configurations in the same orbit, then
Proof of this lemma provides some further insight into the notion parity. It is sufficient to show that where is one the six primitives . Then,
and if (which it better be, let's be honest. When have we dealt with ), then are both 4-cycles with sign , so
This can be generalized to all valid configurations: which is why we know a single corner or edge twist is invalid as a direct consequence of all valid configurations being in the orbit of .
Lemma: If is in the same orbit as , then
Once more, it suffices to show that if , then .
We can illustrate this with a table and diagram:
To make sense of this table, let's examine how we arrive at for . The cubicles of the right face and are:
So , implying
Furthermore, any configuration where is a valid configuration as a direct consequence of the previous assertion that valid configurations are in the orbit of the starting configuration . Recall the ultimate goal: to show that there exists a sequence of moves from some initial, valid conifugration which takes us to . We do this by writing down the steps of solving a cube (5head moment).
Solving the Cube
- If is a configuration where
then there exists some move such that has the form with
In other words, there exists a move to put all the corner positions into their correct positions.
- If is a configuration where
then there exists some move such that has the form with
In other words, there exists a move to orient all the corners.
- If is a configuration where
then there exists a move such that has the form with . That is, we can permute all the edges (without wrecking all the corner work we've proved we can achieve).
- Finally, if is a configuration with , then there exists a move such that WHICH IS !!!!!!!!!
In proving the viability of these steps, it's worth pointing out that if some satisfies
then, for any subsequent configuration in the same orbit as , also satisfies . So we only have to prove the existence of:
- such that satisfying contains in its orbit a configuration
- such that satisfying contains in its orbit a configuration
- such that satisfying contains in its orbit a configuration
- such that satisfying contains in its orbit a configuration
But how do we find these moves?
Lemma: The homomorphism is onto.
Proof: is generated by the set of 2-cycles in the image of . It suffices to show that . We know that is a group, so . With this info, we want to show that every 2-cycle in is in the image of M_0 = (DRD'R'F)^3$ which has the disjoint cycle decomposition
Examining just the effects of the corner , we know at least this cycle exists in . If we let be any pair of corner pieces, we know we can devise a move which sends to and to . Letting , then . Since is a homomorphism:
By the above proof, we know that there exists a move usch that , so... for some
Queue EE Dee.
This... solves the cube. Completing ThE tHeOrEm. This proof also tells us that the demon number can be dodecimated from to of this number due to the elimination of invalid conigurations. That's still about four quadrillion, but it's much better.
Foonotes & References
E.g. , , etc.
Each of these extended notation moves produces the same configuration, regardless of the notation describing the moves.
In his collection of essays to American Science , Douglas Hofstadter –yes, that one– writes of "There is a young Englander from Nottingham named Nicholas Hammond who has got his average solving time down to close to 30 seconds! Such a phenomenal performance calls for several skills" (pp. 140). I disagree! With more advanced techniques, even a passive enthusiast can get their average solve time consistently below 15s.
We know that , so every satisfies the property that " leaves all the center pieces in their cubicles." If have this property, then their composition also has this property, and since generates , every element of also has this property. So, no sequence of legal moves actually displaces the centers from their cubicles.
The point of this note is to show that by studying the properties of the six basic moves and their inverses, rather than all 519 quintillion moves, we can extract a lot of information about the nature of the cube.
Footnotes
God and Satan, Biffy Clyro. ↩
More on God's number here: http://cube20.org/. ↩
Notes on Information Theory (which includes some Group Theory). ↩
"Group Theory and the Rubik’s Cube." Janet Chen. ↩
There exist other cubes with face patterns that have center pieces with orientation (example). For these cubes, we do need to consider the orientation of the center pieces relative to their surrounding edges, but their positions are still fixed. For even-dimensional cubes, those that do not have single, fixed-position center pieces some of the theorems relating to parity do not hold (as they're specified for the odd-dimensional cubes). Nonetheless, commutators discussed later can still be applied to form the centers and solve resulting parity issues introduced by the absence of fixed centers. ↩
The number of bits needed to describe a piece's location is logarithmic in the number of pieces/positions it can inhabit: For each of the three spacial axes, we have 2 options: Up/Down, Left/Right, Front/Back. ↩
The WCA also treats 180º single face twists as just one move (Article 12a1c), but for the sake of our notation, you'll quickly see that it doesn't matter whether or not we treat 180º twists as one or two moves, since the composition of individual twists also constitute a single move. ↩
A note on extended notation: many cubers may also be familiar with middle slice moves , lowercase moves , and cube rotations and their respective inverses. This expanded notation is more ergonomic to execute and semantic to read, but it's worth pointing out that each of these can be expressed in terms of primitives above as well as cube rotations which aren't really moves since they just change our view of the cube on the whole, but not the configuration of the pieces therein. ↩
With some practice, most folks who set out to learn the handful of algorithms needed to solve the standard cube with 2-Look Last Layer (link) can achieve a sub 30s average. By "some practice" I mean like two weekends, or a couple thousand solves. It's not crazy hard if you're sufficiently motivated, but the advent of this intermediate method destroys expectations set by those who witnessed the birth of Erno Rubik's puzzle. ↩
Count to 519 quintillion and then tell me it isn't basically infinity, stfu. ↩
We frequently refer to groups by just their setname once we've defined the group operation which we implicitly keep in mind. ↩
Another notational note, we also commonly express group operations as multiplication, e.g. as listed earlier, , we interpret the righthand side as . Furthermore, exponentiation can be interpreted accordingly: . ↩
I told you center pieces didn't count! ↩
It's commonly executed with the "target" corner in the