Rubiks Cube/Permutations: Difference between revisions
From charlesreid1
| Line 441: | Line 441: | ||
(95) | (95) | ||
</pre> | </pre> | ||
The least common multiple of 1, 3, and 6 is 6, meaning the order of the sequence U R U' R' is 6. If we apply the sequence U R U' R' six times to a solved cube, it will return to the solved state. | |||
=Flags= | =Flags= | ||
Revision as of 01:47, 11 January 2018
Permutation Counts
For counting the number of permutations of a Rubik's Cube, see Rubiks Cube/Numbers
Permutation Algebra
In order to create a system for talking about and dealing with permutations, we follow Volume 3 of Knuth's The Art of Computer Programming (see AOCP).
Representation of a Rubik's Cube
The mathematical. representation of a Rubik's Cube is discussed on the Rubiks Cube/Tuple page, but in short, that page concludes that we should represent the Rubik's Cube by using a particular permutation of an n-tuple, where n is the number of faces.
A 3x3 Rubik's Cube state is represented by a particular permutation of the integers 1 to 36. The solved state is (1 2 3 4 ... 35 36).
A 4x4 Rubik's Cube state is represented by a particular permutation of the integers 1 to 96. The solved state is (1 2 3 4 ... 35 36).
Writing a Permutation
Knuth introduces the top-bottom notation for permutations, in which a particular permutation of a sequence of $ n $ integers is written by first writing each element of the sequence in increasing order on the top row, then writing the occurrence of each element in the order it occurs on the bottom row:
$ a = \bigl(\begin{smallmatrix} 1 & 2 & 3 & \cdots & n-1 & n \\ 2 & 3 & 4 & \cdots & n & 1 \end{smallmatrix}\bigr) $
Intercalation Product
We now define an intercalation operation with two permutations; this is basically an operation that interleaves two permutations. We will see why this is useful in a moment.
Suppose we have two permutations, $ \alpha $ and $ \beta $, of four objects $ \{a, b, c, d\} $, each occurring multiple times:
$ \alpha = \bigl(\begin{smallmatrix} a & a & b & c & d \\ c & a & d & a & b \end{smallmatrix}\bigr) $
$ \beta = \bigl(\begin{smallmatrix} a & b & d & d & d \\ b & d & d & a & d \end{smallmatrix}\bigr) $
Then we can define the intercalation product $ \alpha \top \beta $ as the elements of these permutations combined in a way that interleaves elements of both, in a way that groups all elements by the letter on the top row, but sorts within those letters according to the original order in $ \alpha $ and $ \beta $. For our example:
$ \alpha \top \beta = \bigl(\begin{smallmatrix} a & a & b & c & d \\ c & a & d & a & b \end{smallmatrix}\bigr) \top \bigl(\begin{smallmatrix} a & b & d & d & d \\ b & d & d & a & d \end{smallmatrix}\bigr) = \bigl(\begin{smallmatrix} a & a & a & b & b & c & d & d & d & d \\ c & a & b & d & d & a & b & d & a & d \end{smallmatrix}\bigr) = $
This is basically an interleaving operation. All top-bottom pairs with $ a $ at the top are grouped together; all from $ \alpha $ come first, and all from $ \beta $ come second.
The first two $ a $ items in $ \alpha \top \beta $ come from $ \alpha $, the third $ a $ item comes from $ \beta $.
Etc.
Properties of Intercalation
Before using the intercalation product, let's define a few properties :
- If $ \alpha \top \pi = \beta \top \pi $ or $ \pi \top \alpha = \pi \top \beta $ this implies $ \alpha = \beta $
- Identity element exists such that $ \epsilon \top \alpha = \alpha \top \epsilon = \alpha $
- Commutative property only holds if $ \alpha $ independent of $ \beta $; then $ \alpha \top \beta = \beta \top \alpha $. This property does not hold in general.
Cycles and Intercalation
Cycles are elements that are swapped in some prescribed way. For example, suppose we have a sequence,
$ \bigl(\begin{smallmatrix} x_1 & x_2 & \dots & x_n \end{smallmatrix}\bigr) $
and further suppose that we shift this sequence to the left by one element, and write in the two line notation:
$ \bigl(\begin{smallmatrix} x_1 & x_2 & \dots & x_{n-1} & x_n \\ x_2 & x_3 & \dots & x_{n} & x_1 \end{smallmatrix}\bigr) $
We can observe that the product of disjoint cycles is the same as their intercalation.
Now we have a full "product" permutation.
Factoring Permutations
An Example
Suppose we have a permutation:
$ \pi = \bigl(\begin{smallmatrix} a & a & b & b & b & b & b & c & c & c & d & d & d & d & d \\ d & b & c & b & c & a & c & d & a & d & d & b & b & b & d \end{smallmatrix}\bigr) $
and suppose that we want to "factor" the permutation - that is, to write the permutation as the intercalation product of independent, disjoint cycles $ \pi = \alpha \top \beta \top \dots \top \gamma $.
Assembling Factors
We can assemble each factor one at a time using the following algorithm:
Start by supposing that the first factor $ \alpha $ contains the first symbol $ a $. If this assumption is true, then $ \alpha $ must map $ a $ to the same thing that the final permutation maps $ a $ to, namely, the first column of $ \pi $, which is the combination $ \begin{smallmatrix} a \\ d \end{smallmatrix} $. This means that the first entry in $ \alpha $ must turn $ a $ into $ d $.
Now we suppose that $ \alpha $ contains $ d $, as a consequence of the prior step. Let's find the leftmost $ d $ in the top line, and see what symbol it will map to. It maps to b. This means that the first entry in $ \alpha $ must turn $ d $ into $ d $ and should therefore contain $ \begin{smallmatrix} d \\ d \end{smallmatrix} $
Now we start with the outcome of the previous step, which is another $ d $. Since we already used the first d-d pairing, we look for the second leftmost d, which is part of the combination/mapping $ \begin{smallmatrix} d \\ b \end{smallmatrix} $. This implies the mapping d-b should be in $ \alpha $, and we use the mapping outcome b as the starting point for the next step.
If we keep doing this, eventually we will get:
$ \alpha = \bigl(\begin{smallmatrix} a & d & d & b & c & d & b & b & c \\ d & d & b & c & d & b & b & c & a \end{smallmatrix}\bigr) $
Why Does This Work
Let's pause for a moment and see what's happening. What we're doing is following a thread between the top and bottom rows of the permutation; this thread tells us how elements are being moved around to create permutations.
(A simpler but easier way to see this is by comparing two permutations of 1 2 3 4 5 6: consider the permutation 2 1 3 4 6 5, versus the permutation 2 4 5 6 1 3. The first permutation swaps positions 0 and 1, and positions 4 and 5, independently; the second permutation mixes all positions together.)
We are assembling $ \alpha $ piece by piece, by pulling out pairs from the top and bottom row of $ \pi $ and putting them into $ \alpha $. At some point we will come back to the starting point, the symbol $ a $, and we will be finished finding the first factor $ \alpha $, which is a disjoint cycle.
By starting from the top row and following where it leads in the bottom row, and continuing until we return to the original starting element in the top row, we can carve up the permutation into groups of pieces exchanged with one another and not with any other pieces, or groups of pieces that don't move.
Forming All Factors
We then continue the process of assembling factors from what is left of $ \pi $. (Note that if $ \pi $ is prime, every element of $ \pi $ will appear in $ \alpha $ and there will be no further products.) Eventually we will have a number of factors,
$ \pi = \alpha \top \beta \top \dots \top \gamma $
The result of applying this procedure, of skipping between the top and bottom rows, is a set of 1 or more permutation factors. If we continue with the example $ \pi $ above, we'll eventually get:
Original:
$ \pi = \bigl( \begin{smallmatrix} a & a & b & b & b & b & b & c & c & c & d & d & d & d & d \\ d & b & c & b & c & a & c & d & a & d & d & b & b & b & d \end{smallmatrix}\bigr) $
First factor pulled out:
$ \pi = \bigl( \begin{smallmatrix} a & d & d & b & c & d & b & b & c \\ d & d & b & c & d & b & b & c & a \end{smallmatrix} \bigr) \top \bigl( \begin{smallmatrix} a & b & b & c & d & d \\ b & a & c & d & b & d \end{smallmatrix} \bigr) $
Second factor pulled out:
$ \pi = \bigl( \begin{smallmatrix} a & d & d & b & c & d & b & b & c \\ d & d & b & c & d & b & b & c & a \end{smallmatrix} \bigr) \top \bigl( \begin{smallmatrix} a & b \\ b & a \end{smallmatrix} \bigr) \top \bigl( \begin{smallmatrix} b & c & d & d \\ c & d & b & d \end{smallmatrix} \bigr) $
and the last factor is a piece that is not moved in this permutation:
$ \pi = \bigl( \begin{smallmatrix} a & d & d & b & c & d & b & b & c \\ d & d & b & c & d & b & b & c & a \end{smallmatrix} \bigr) \top \bigl( \begin{smallmatrix} a & b \\ b & a \end{smallmatrix} \bigr) \top \bigl( \begin{smallmatrix} b & c & d \\ c & d & b \end{smallmatrix} \bigr) \top \bigl( \begin{smallmatrix} d \\ d \end{smallmatrix} \bigr) $
Thus the permutation $ \pi $ can be expressed as the intercalation of four independent cycles.
To relate this back to the Rubik's Cube, we can start with a sequence of interest, like U R D D B, and write the tuple representing the outcome of this sequence when it is applied to the cube. In this way we represent a move sequence as a tuple or as a permutation.
Next, we factor this permutation the way we factored $ \pi $, into the intercalation product of independent cycles. These are groups of pieces being swapped each time the cycle is applied.
Now if one group of pieces being swapped each time the cycle is applied is of size 4 and another group is of size 3 and yet another is of size 20, then we know that the overall sequence order (the number of times the sequence should be applied to a solved cube to return it back to the solved state) is LCM(3,4,20) = 60.
This procedure illustrates what Knuth refers to as Theorem A.
(Note: had we initially assumed $ \alpha $ contained b instead of a, we would end up starting by pulling out a different factor, but we would ultimately end up with the same set of four factors.)
Application to Rubiks Cube
Sequence R
Let's look at an example of applying this to a 4x4 Rubiks Revenge cube. We will consider the sequence "R" (turning the right face clockwise once).
Start with the solved state:
(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96)
Now, when we apply the move R, we get:
(1 2 3 36 5 6 7 40 9 10 11 44 13 14 15 48 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 84 37 38 39 88 41 42 43 92 45 46 47 96 61 57 53 49 62 58 54 50 63 59 55 51 64 60 56 52 16 66 67 68 12 70 71 72 8 74 75 76 4 78 79 80 81 82 83 77 85 86 87 73 89 90 91 69 93 94 95 65)
When we carry out the Agorithm A procedure and factor this permutation, we get many factors that are independent (meaning they do not move when we carry out the sequence). We have six groups of four faces that cycle through one another (one corner piece with three faces, two double edges with two faces, and one square piece with one face, for a total of six faces):
Factors: (1) (2) (3) (36 84 77 4) (5) (6) (7) (40 88 73 8) (9) (10) (11) (44 92 69 12) (13) (14) (15) (48 96 65 16) (17) (18) (19) (20) (21) (22) (23) (24) (25) (26) (27) (28) (29) (30) (31) (32) (33) (34) (35) (37) (38) (39) (41) (42) (43) (45) (46) (47) (61 64 52 49) (57 63 56 50) (53 62 60 51) (58 59 55 54) (66) (67) (68) (70) (71) (72) (74) (75) (76) (78) (79) (80) (81) (82) (83) (85) (86) (87) (89) (90) (91) (93) (94) (95)
This tells us what we already knew: that if we apply the sequence "R", it rotates groups of pieces in a sequence of 4 moves each, so overall the order of this permutation is 4 - if we apply the sequence R to a solved 4x4 Rubik's Revenge cube 4 times, the cube will return to the solved state.
Sequence U R U' R'
Let's look at a slightly longer sequence: U R U' R'.
We start with the n-tuple representing the solved state (top row):
(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96)
and the n-tuple representing this permutation (bottom row):
(1 2 3 77 5 6 7 73 9 10 11 69 16 12 8 20 17 18 19 36 21 22 23 24 25 26 27 28 29 30 31 32 49 50 51 33 37 38 39 40 41 42 43 44 45 46 47 48 13 56 60 64 53 54 55 34 57 58 59 35 61 62 63 4 96 66 67 68 14 70 71 72 15 74 75 76 65 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 52)
Now, if we factor out the n-tuple, we get some factors (independent cycles) of length 3 and length 6:
Factors: (1) (2) (3) (77 65 96 52 64 4) (5) (6) (7) (73 15 8) (9) (10) (11) (69 14 12) (16 20 36 33 49 13) (17) (18) (19) (21) (22) (23) (24) (25) (26) (27) (28) (29) (30) (31) (32) (50 56 34) (51 60 35) (37) (38) (39) (40) (41) (42) (43) (44) (45) (46) (47) (48) (53) (54) (55) (57) (58) (59) (61) (62) (63) (66) (67) (68) (70) (71) (72) (74) (75) (76) (78) (79) (80) (81) (82) (83) (84) (85) (86) (87) (88) (89) (90) (91) (92) (93) (94) (95)
The least common multiple of 1, 3, and 6 is 6, meaning the order of the sequence U R U' R' is 6. If we apply the sequence U R U' R' six times to a solved cube, it will return to the solved state.