From charlesreid1

 
(16 intermediate revisions by the same user not shown)
Line 9: Line 9:
Now, if we think about how a 3x3 Rubik's Cube or 4x4 Rubik's Revenge is mechanically constructed, we see that the cube consists of:
Now, if we think about how a 3x3 Rubik's Cube or 4x4 Rubik's Revenge is mechanically constructed, we see that the cube consists of:


Rubik's Cube: 26 total (mechanical) pieces
Rubik's Cube (3x3 cube): 26 total cubies (mechanical pieces)


* 8 corner pieces
* 8 corner cubies
* 12 edge pieces
* 12 edge cubies
* 6 center pieces
* 6 center cubies (fixed)


Rubik's Revenge: 56 total (mechanical) pieces
Rubik's Revenge (4x4 cube): 56 total cubies (mechanical pieces)


* 8 corner pieces
* 8 corner cubies
* 24 double-edge pieces (12 left-hand, 12 right-hand)
* 24 double-edge (dedge) wing cubies (12 left wing, 12 right wing)
* 24 center pieces
* 24 center cubies


However, it is important to note that we are ''not'' trying to find the minimal representation of the Rubik's Cube, we are simply trying to find a ''unique'' representation of a Rubik's Cube. Representing faces requires more information than representing pieces, but it is a lot simpler and accomplishes what we need:
Professors Cube (5x5 cube): 25*2 + 16*3 = 98 total cubies (mechanical pieces)


* The 3x3 Rubik's Cube has 9 squares on each face, and 6 faces, for a total of 36 squares.  
* 8 corner cubies
* The 4x4 Rubik's Revenge has 16 squares on each face, and 6 faces, for 96 total squares.
* 24 triple-edge (tredge) wing cubies (12 left wing, 12 right wing)
* 12 triple-edge (tredge) center cubies
* 6 center (of face) cubies (fixed)
* 48 face cubies (mobile)
 
However, it is important to note that we are ''not'' trying to find the ''minimal'' representation of the cube, we are simply trying to find a ''unique'' representation of the cube. Listing the state of every single face requires more information - there are more faces than pieces, because corners have 3 faces and double edge pieces have 2 faces - but it is much simpler to accomplish, by thinking about "unfolding"the cube into a map of colored squares.
 
* The 3x3 Rubik's Cube has 9 squares on each face, and 6 faces, for a total of 54 colored squares.
* The 4x4 Rubik's Revenge has 16 squares on each face, and 6 faces, for 96 total colored squares.
* The 5x5 Professor's Cube has 25 squares on each face, and 6 faces, for 150 total colored squares.


Now, if we were looking for a ''minimal'' representation, we would utilize the fact that some of these squares are innately linked (for example, the three faces representing a corner piece are always positioned in the same way relative to one another, even though they may move relative to the rest of the pieces on the cube).
Now, if we were looking for a ''minimal'' representation, we would utilize the fact that some of these squares are innately linked (for example, the three faces representing a corner piece are always positioned in the same way relative to one another, even though they may move relative to the rest of the pieces on the cube).


However, we simply want a ''unique'' representation, so we can represent the state of any 3x3 Rubik's Cube using a 36-tuple, or the state of any 4x4 Rubik's Revenge using a 96-tuple.
However, we simply want a ''unique'' representation, so we can represent the state of any 3x3 Rubik's Cube using a 54-uple, or the state of any 4x4 Rubik's Revenge cube using a 96-uple, or the state of any 5x5 Professor's cube using a 150-uple.


==Why A Tuple Representation==
==Why A Tuple Representation==
Line 34: Line 43:
Finding a tuple representation enables us to study the properties of various move sequences and understand how the cube works.
Finding a tuple representation enables us to study the properties of various move sequences and understand how the cube works.


For example, if we repeatedly apply any sequence of moves to a Rubik's Cube, eventually it will return back to the solved state. To predict how many times a sequence must be applied to a cube to return to the solved state, we can use techniques demonstrated by Donald Knuth in Volume 3 of [[AOCP|The Art of Computer Programming]] (see [[AOCP]]) to derive a permutation algebra, factor permutations into cycles, and find the sequence length via the lcm of each cycle length.
Applying a sequence of moves, such as
 
<pre>
U R U' R'
</pre>
 
(that is, turning the upper face clockwise, right face clockwise, upper face counter clockwise, and right face counter clockwise), to a solved cube repeatedly will eventually result in the cube returning to its original, solved state. The sequence above will return a solved 4x4 cube back to solved state after the sequence is applied 6 times.
 
Other sequences take much longer; the sequence
 
<pre>
U R
</pre>
 
will take 105 applications to return a solved 4x4 cube back to solved state.
 
It turns out that the tuple representation of a cube helps simplify and streamline the representation of these move sequences. If we write the state of a cube as a tuple, we can see which squares are exchanged after a sequence of moves. For example, after applying the sequence
 
<pre>
U R U' R'
</pre>
 
to a solved 4x4 cube, it exchanges 10 pieces total, exchanging different groups of pieces in different orders. On the other hand, after applying the sequence
 
<pre>
U R
</pre>


See also: https://github.com/charlesreid1/rubiks-cycles
to a solved 4x4 cube, it exchanges 20 pieces total, exchanging different groups of pieces.  


Tuple representation: https://github.com/charlesreid1/rubiks-cycles/blob/master/tup.py
It turns out that the placement and order in which those different groups of pieces are exchanged determines the number of times a sequence must be applied to a solved cube to reach the solved state again. This is referred to as the ''order'' of the sequence.
 
This intuitively makes sense: if you apply a sequence that cycles through 3 pieces, then every 3 applications of the sequence the pieces will return to their original positions. If you have another sequence that cycles through 4 pieces, then every 4 applications of the sequence the pieces will return to their original positions.
 
But now, if we mix these two sequences together, then the order is LCM(3,4), where LCM is the least common multiple. In this case, we need to apply the sequence 12 times to return to the original state.
 
Supposing we had a cycle of length 105, which factors into 105 = 3*5*7. Then this could be caused by two interlocking sequences with orders 7 and 15.
 
We can use techniques demonstrated by Donald Knuth in Volume 3 of [[AOCP|The Art of Computer Programming]] (see [[AOCP]]) to derive a permutation algebra, factor permutations into cycles, find the order of each permuation, and implement algorithms for everything.
 
==Code==
 
Code implementation: https://github.com/charlesreid1/rubiks-cycles
 
Specifically, the tuple representation and permutation factoring algorithms are here: https://github.com/charlesreid1/rubiks-cycles/blob/master/tup.py
 
==More on Permutations==
 
This article covers the tuple representation of the Rubik's Cube, with the ultimate goal of using it to describe permutations and sequences of moves on the cube.
 
To skip straight to the notes on permutations, see [[Rubiks Cube/Permutations]]
 
=3x3 Rubiks Cube Representation=
 
==Numbering System for 3x3 Cube==
 
==Mapping Moves to Permutations for 3x3==
 
==3x3 Permutations and Properties==
 
==3x3 Cube Code==


=4x4 Rubiks Cube Representation=
=4x4 Rubiks Cube Representation=


==Numbering System==
==Numbering System for 4x4==


Start with a numbering system for the cube. The nxnxn rubiks cube solver library I'm using (https://github.com/dwalton76/rubiks-cube-NxNxN-solver) implements the following numbering system:
Start with a numbering system for the cube. The nxnxn rubiks cube solver library I'm using (https://github.com/dwalton76/rubiks-cube-NxNxN-solver) implements the following numbering system:
Line 88: Line 153:
</pre>
</pre>


==Moves as Permutations==
==4x4 Moves Mapped to Permutations==


Each move of a face - U, D, R, L, F, B, and other two-layer or second-layer moves, as well as sequences of moves - can now be thought of as a permutation of these 96 integers.
Each move of a face - U, D, R, L, F, B, and other two-layer or second-layer moves, as well as sequences of moves - can now be thought of as a permutation of these 96 integers.
Line 135: Line 200:
Once we can write a sequence of moves as a permutation of 96 integers, we can start to dig deeper into the effect that it has on the cube state.
Once we can write a sequence of moves as a permutation of 96 integers, we can start to dig deeper into the effect that it has on the cube state.


==Permutation Algebra==
==Permutations and Their Properties==
 
In order to create a system for talking about and dealing with permutations, we follow Volume 3 of Knuth's [[AOCP|The Art of Computer Programming]] (see [[AOCP]]).
 
===Writing a Permutation===
 
Knuth introduces the top-bottom notation for permutations, in which a particular permutation of a sequence of <math>n</math> 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:
 
<math>
a = \bigl(\begin{smallmatrix}
  1 & 2 & 3 & \cdots & n-1 & n \\
  2 & 3 & 4 & \cdots &  n  & 1
\end{smallmatrix}\bigr)
</math>
 
===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, <math>\alpha</math> and <math>\beta</math>, of four objects <math>\{a, b, c, d\}</math>, each occurring multiple times:
 
<math>
\alpha = \bigl(\begin{smallmatrix}
  a & a & b & c & d \\
  c & a & d & a & b
\end{smallmatrix}\bigr)
</math>
 
<math>
\beta = \bigl(\begin{smallmatrix}
  a & b & d & d & d \\
  b & d & d & a & d
\end{smallmatrix}\bigr)
</math>
 
Then we can define the intercalation product <math>\alpha \top \beta</math> 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 <math>\alpha</math> and <math>\beta</math>. For our example:
 
<math>
\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) =
</math>
 
This is basically an interleaving operation.
 
===Properties of Intercalation===
 
Before using the intercalation product, let's define a few properties :
 
* If <math>\alpha \top \pi = \beta \top \pi</math> or <math>\pi \top \alpha = \pi \top \beta</math> this implies <math>\alpha = \beta</math>
* Identity element exists such that <math>\epsilon \top \alpha = \alpha \top \epsilon = \alpha</math>
* Commutative property only holds if <math>\alpha</math> independent of <math>\beta</math>; then <math>\alpha \top \beta = \beta \top \alpha</math>. 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,
 
<math>
\bigl(\begin{smallmatrix}
  x_1 & x_2 & \dots & x_n
\end{smallmatrix}\bigr)
</math>
 
and further suppose that we shift this sequence to the left by one element, and write in the two line notation:
 
<math>
\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)
</math>
 
We can observe that the product of disjoint cycles is the same as their intercalation.
 
Now we have a full "product" permutation.
 
===Factoring Permutations===
 
Suppose we have a permutation:
 
<math>
\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)
</math>
 
and suppose that we want to "factor" the permutation - that is, to write the permutation as the intercalation product of independent, disjoint cycles <math>\pi = \alpha \top \beta \top \dots \top \gamma</math>.
 
We can assemble each factor one at a time using the following algorithm:
 
Start by supposing that the first factor <math>\alpha</math> contains the first symbol <math>a</math>. If this assumption is true, then <math>\alpha</math> must map <math>a</math> to the same thing that the final permutation maps <math>a</math> to, namely, the first column of <math>\pi</math>, which is the combination <math>\begin{smallmatrix}
    a \\
    d
\end{smallmatrix}
</math>. This means that the first entry in <math>\alpha</math> must turn <math>a</math> into <math>d</math>.
 
Now we suppose that <math>\alpha</math> contains <math>d</math>, as a consequence of the prior step. Let's find the leftmost <math>d</math> in the top line, and see what symbol it will map to. It maps to b.  This means that the first entry in <math>\alpha</math> must turn <math>d</math> into <math>d</math> and should therefore contain <math>\begin{smallmatrix}
    d \\
    d
\end{smallmatrix}
</math>
 
Now we start with the outcome of the previous step, which is another <math>d</math>. Since we already used the first d-d pairing, we look for the second leftmost d, which is part of the combination/mapping
<math>\begin{smallmatrix}
    d \\
    b
\end{smallmatrix}
</math>. This implies the mapping d-b should be in <math>\alpha</math>, and we use the mapping outcome b as the starting point for the next step.
 
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 <math>\alpha</math> piece by piece, by pulling out pairs from the top and bottom row of <math>\pi</math> and putting them into <math>\alpha</math>. At some point we will come back to the starting point, the symbol <math>a</math>, and we will be finished finding the first factor <math>\alpha</math>, which is a disjoint cycle.


We then continue the process of assembling factors from what is left of <math>\pi</math>. (Note that if <math>\pi</math> is prime, every element of <math>\pi</math> will appear in <math>\alpha</math> and there will be no further products.) Eventually we will have a number of factors,
Now that we have a tuple representation of the cube, we can start to use it to characterize sequences of moves, the permutations they lead to, and their properties.


<math>
See [[Rubiks Cube/Permutations]]
\pi = \alpha \top \beta \top \dots \top \gamma
</math>


=Flags=
=Flags=
Line 271: Line 212:
[[Category:Rubiks Revenge]]
[[Category:Rubiks Revenge]]
[[Category:Rubiks Cube]]
[[Category:Rubiks Cube]]
[[Category:Rubiks]]

Latest revision as of 22:01, 22 April 2019

Notes on Tuple Representation of Rubiks Cube

Let's first explain what we mean when we talk about a tuple representation of a cube, and why this is useful.

Tuple Representation

A tuple representation means, we are representing one possible permutation of the Rubik's Cube using a tuple, ideally a tuple of N items arranged in some particular way.

Now, if we think about how a 3x3 Rubik's Cube or 4x4 Rubik's Revenge is mechanically constructed, we see that the cube consists of:

Rubik's Cube (3x3 cube): 26 total cubies (mechanical pieces)

  • 8 corner cubies
  • 12 edge cubies
  • 6 center cubies (fixed)

Rubik's Revenge (4x4 cube): 56 total cubies (mechanical pieces)

  • 8 corner cubies
  • 24 double-edge (dedge) wing cubies (12 left wing, 12 right wing)
  • 24 center cubies

Professors Cube (5x5 cube): 25*2 + 16*3 = 98 total cubies (mechanical pieces)

  • 8 corner cubies
  • 24 triple-edge (tredge) wing cubies (12 left wing, 12 right wing)
  • 12 triple-edge (tredge) center cubies
  • 6 center (of face) cubies (fixed)
  • 48 face cubies (mobile)

However, it is important to note that we are not trying to find the minimal representation of the cube, we are simply trying to find a unique representation of the cube. Listing the state of every single face requires more information - there are more faces than pieces, because corners have 3 faces and double edge pieces have 2 faces - but it is much simpler to accomplish, by thinking about "unfolding"the cube into a map of colored squares.

  • The 3x3 Rubik's Cube has 9 squares on each face, and 6 faces, for a total of 54 colored squares.
  • The 4x4 Rubik's Revenge has 16 squares on each face, and 6 faces, for 96 total colored squares.
  • The 5x5 Professor's Cube has 25 squares on each face, and 6 faces, for 150 total colored squares.

Now, if we were looking for a minimal representation, we would utilize the fact that some of these squares are innately linked (for example, the three faces representing a corner piece are always positioned in the same way relative to one another, even though they may move relative to the rest of the pieces on the cube).

However, we simply want a unique representation, so we can represent the state of any 3x3 Rubik's Cube using a 54-uple, or the state of any 4x4 Rubik's Revenge cube using a 96-uple, or the state of any 5x5 Professor's cube using a 150-uple.

Why A Tuple Representation

Finding a tuple representation enables us to study the properties of various move sequences and understand how the cube works.

Applying a sequence of moves, such as

U R U' R'

(that is, turning the upper face clockwise, right face clockwise, upper face counter clockwise, and right face counter clockwise), to a solved cube repeatedly will eventually result in the cube returning to its original, solved state. The sequence above will return a solved 4x4 cube back to solved state after the sequence is applied 6 times.

Other sequences take much longer; the sequence

U R 

will take 105 applications to return a solved 4x4 cube back to solved state.

It turns out that the tuple representation of a cube helps simplify and streamline the representation of these move sequences. If we write the state of a cube as a tuple, we can see which squares are exchanged after a sequence of moves. For example, after applying the sequence

U R U' R'

to a solved 4x4 cube, it exchanges 10 pieces total, exchanging different groups of pieces in different orders. On the other hand, after applying the sequence

U R

to a solved 4x4 cube, it exchanges 20 pieces total, exchanging different groups of pieces.

It turns out that the placement and order in which those different groups of pieces are exchanged determines the number of times a sequence must be applied to a solved cube to reach the solved state again. This is referred to as the order of the sequence.

This intuitively makes sense: if you apply a sequence that cycles through 3 pieces, then every 3 applications of the sequence the pieces will return to their original positions. If you have another sequence that cycles through 4 pieces, then every 4 applications of the sequence the pieces will return to their original positions.

But now, if we mix these two sequences together, then the order is LCM(3,4), where LCM is the least common multiple. In this case, we need to apply the sequence 12 times to return to the original state.

Supposing we had a cycle of length 105, which factors into 105 = 3*5*7. Then this could be caused by two interlocking sequences with orders 7 and 15.

We can use techniques demonstrated by Donald Knuth in Volume 3 of The Art of Computer Programming (see AOCP) to derive a permutation algebra, factor permutations into cycles, find the order of each permuation, and implement algorithms for everything.

Code

Code implementation: https://github.com/charlesreid1/rubiks-cycles

Specifically, the tuple representation and permutation factoring algorithms are here: https://github.com/charlesreid1/rubiks-cycles/blob/master/tup.py

More on Permutations

This article covers the tuple representation of the Rubik's Cube, with the ultimate goal of using it to describe permutations and sequences of moves on the cube.

To skip straight to the notes on permutations, see Rubiks Cube/Permutations

3x3 Rubiks Cube Representation

Numbering System for 3x3 Cube

Mapping Moves to Permutations for 3x3

3x3 Permutations and Properties

3x3 Cube Code

4x4 Rubiks Cube Representation

Numbering System for 4x4

Start with a numbering system for the cube. The nxnxn rubiks cube solver library I'm using (https://github.com/dwalton76/rubiks-cube-NxNxN-solver) implements the following numbering system:

             01 02 03 04
             05 06 07 08
             09 10 11 12
             13 14 15 16

17 18 19 20  33 34 35 36  49 50 51 52  65 66 67 68
21 22 23 24  37 38 39 40  53 54 55 56  69 70 71 72
25 26 27 28  41 42 43 44  57 58 59 60  73 74 75 76
29 30 31 32  45 46 47 48  61 62 63 64  77 78 79 80

             81 82 83 84
             85 86 87 88
             89 90 91 92
             93 94 95 96

corresponding to the following cube state:

         U U U U
         U U U U
         U U U U
         U U U U

L L L L  F F F F  R R R R  B B B B
L L L L  F F F F  R R R R  B B B B
L L L L  F F F F  R R R R  B B B B
L L L L  F F F F  R R R R  B B B B

         D D D D
         D D D D
         D D D D
         D D D D

Now we can write the solved cube as the following 96-tuple:

[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]

4x4 Moves Mapped to Permutations

Each move of a face - U, D, R, L, F, B, and other two-layer or second-layer moves, as well as sequences of moves - can now be thought of as a permutation of these 96 integers.

I modified the nxnxn rubiks cube library to print out the permutation corresponding to each type of move. For example, here is U:

In [7]: r.rotation_map('U')
Out[7]:
[(1, 13),
 (2, 9),
 (3, 5),
 (4, 1),
 (5, 14),
 (6, 10),
 (7, 6),
 (8, 2),
 (9, 15),
 (10, 11),
 (11, 7),
 (12, 3),
 (13, 16),
 (14, 12),
 (15, 8),
 (16, 4),
 (17, 33),
 (18, 34),
 (19, 35),
 (20, 36),
 (33, 49),
 (34, 50),
 (35, 51),
 (36, 52),
 (49, 65),
 (50, 66),
 (51, 67),
 (52, 68),
 (65, 17),
 (66, 18),
 (67, 19),
 (68, 20)]

Now the starting state of a cube can be written as the above tuple, and rotations of various faces can be written as permutations.

Once we can write a sequence of moves as a permutation of 96 integers, we can start to dig deeper into the effect that it has on the cube state.

Permutations and Their Properties

Now that we have a tuple representation of the cube, we can start to use it to characterize sequences of moves, the permutations they lead to, and their properties.

See Rubiks Cube/Permutations

Flags