The following Julia session shows the computations from the Rubik's Cube example from the GAP webpages. A Julia session with equivalent computations using just the GAP interface GAP.jl can be found inside the documentation of this package.

First we load `Oscar.jl`

.

In [1]:

```
using Oscar
```

We consider the group of transformations of Rubik's magic cube. If we number the faces of this cube as follows

```
+--------------+
| |
| 1 2 3 |
| |
| 4 top 5 |
| |
| 6 7 8 |
| |
+--------------+--------------+--------------+--------------+
| | | | |
| 9 10 11 | 17 18 19 | 25 26 27 | 33 34 35 |
| | | | |
| 12 left 13 | 20 front 21 | 28 right 29 | 36 rear 37 |
| | | | |
| 14 15 16 | 22 23 24 | 30 31 32 | 38 39 40 |
| | | | |
+--------------+--------------+--------------+--------------+
| |
| 41 42 43 |
| |
| 44 bottom 45 |
| |
| 46 47 48 |
| |
+--------------+
```

then the group is generated by the following generators, corresponding to the six faces of the cube.

In [2]:

```
g = symmetric_group(48);
l = [
[[ 1, 3, 8, 6], [ 2, 5, 7, 4], [ 9,33,25,17], [10,34,26,18], [11,35,27,19]],
[[ 9,11,16,14], [10,13,15,12], [ 1,17,41,40], [ 4,20,44,37], [ 6,22,46,35]],
[[17,19,24,22], [18,21,23,20], [ 6,25,43,16], [ 7,28,42,13], [ 8,30,41,11]],
[[25,27,32,30], [26,29,31,28], [ 3,38,43,19], [ 5,36,45,21], [ 8,33,48,24]],
[[33,35,40,38], [34,37,39,36], [ 3, 9,46,32], [ 2,12,47,29], [ 1,14,48,27]],
[[41,43,48,46], [42,45,47,44], [14,22,30,38], [15,23,31,39], [16,24,32,40]] ];
cube = sub(g, [cperm(g, x) for x in l])[1]
```

Out[2]:

First we want to know the order of this group.

In [3]:

```
cube_size = order(cube)
```

Out[3]:

Since this is a little bit unhandy, let us factorize this number.

In [4]:

```
factor(cube_size)
```

Out[4]:

(The result tells us that the order is 2^{27} 3^{14} 5^{3} 7^{2} 11.)

Next let us investigate the operation of the group on the 48 points.

In [5]:

```
orbs = orbits(cube); map(collect, orbs)
```

Out[5]:

The first orbit contains the points at the corners, the second those at the edges; clearly the group cannot move a point at a corner onto a point at an edge.

So to investigate the cube group we first investigate the operation on the corner points.
Note that the constructed group that describes this operation will operate on the set `1:24`

, not on the original set `orbs[1]`

.

In [6]:

```
cube1 = image(action_homomorphism(orbs[1]))[1]
```

Out[6]:

In [7]:

```
degree(cube1)
```

Out[7]:

In [8]:

```
order(cube1)
```

Out[8]:

Now this group obviously operates transitively, but let us test whether it is also primitive.

In [9]:

```
corners = blocks(cube1); collect(corners)
```

Out[9]:

Those eight blocks correspond to the eight corners of the cube; on the one hand the group permutes those and on the other hand it permutes the three points at each corner cyclically.

In [10]:

```
blockhom1 = action_homomorphism(corners); cube1b = image(blockhom1)[1]
```

Out[10]:

In [11]:

```
order(cube1b)
```

Out[11]:

Now a permutation group of degree 8 that has order 40320 must be the full symmetric group `Sym(8)`

on eight points.

The next thing then is to investigate the kernel of this operation on blocks, i.e., the subgroup of `cube1`

of those elements that fix the blocks setwise.

In [12]:

```
ker1 = kernel(blockhom1)[1]
```

Out[12]:

In [13]:

```
factor(order(ker1))
```

Out[13]:

In [14]:

```
is_elementary_abelian(ker1)
```

Out[14]:

We can show that the product of this elementary abelian group `3^7`

with the `Sym(8)`

is semidirect by finding a complement, i.e., a subgroup that has trivial intersection with the kernel and that generates `cube1`

together with the kernel.

In [15]:

```
cmpl1 = complement_class_reps(cube1, ker1)
```

Out[15]:

In [16]:

```
cmpl1 = cmpl1[1]; order(cmpl1)
```

Out[16]:

We verify the complement properties:

In [17]:

```
order(intersect(cmpl1, ker1)[1])
```

Out[17]:

In [18]:

```
sub(cube1, vcat(gens(cmpl1), gens(ker1)))[1] == cube1
```

Out[18]:

There is even a more elegant way to show that `cmpl1`

is a complement.

In [18]:

```
is_bijective(restrict_homomorphism(blockhom1, cmpl1))
```

Out[18]:

Of course, theoretically it is clear that `cmpl1`

must indeed be a complement.

In fact we know that `cube1`

is a subgroup of index 3 in the wreath product of a cyclic 3 with `Sym(8)`

.
This missing index 3 tells us that we do not have total freedom in turning the corners.
The following tests show that whenever we turn one corner clockwise we must turn another corner counterclockwise.

In [19]:

```
cperm([1, 7, 22]) in cube1
```

Out[19]:

In [20]:

```
cperm([1, 7, 22], [2, 20, 14]) in cube1
```

Out[20]:

More or less the same things happen when we consider the operation of the cube group on the edges.

In [21]:

```
cube2 = image(action_homomorphism(cube, orbs[2]))[1]
```

Out[21]:

In [22]:

```
degree(cube2)
```

Out[22]:

In [23]:

```
order(cube2)
```

Out[23]:

In [24]:

```
edges = blocks(cube2);
```

In [25]:

```
collect(edges)
```

Out[25]:

In [26]:

```
blockhom2 = action_homomorphism(edges)
```

Out[26]:

In [27]:

```
cube2b = image(blockhom2)[1]
```

Out[27]:

In [28]:

```
order(cube2b)
```

Out[28]:

In [29]:

```
ker2 = kernel(blockhom2)[1]
```

Out[29]:

In [30]:

```
factor(order(ker2))
```

Out[30]:

In [31]:

```
is_elementary_abelian(ker2)
```

Out[31]:

In [32]:

```
cmpl2 = complement_class_reps(cube2, ker2)
```

Out[32]:

So there are even 4 classes of complements here.
This time we get a semidirect product of a `2^11`

with an `Sym(12)`

, namely a subgroup of index 2 of the wreath product of a cyclic 2 with `Sym(12)`

.
Here the missing index 2 tells us again that we do not have total freedom in turning the edges.
The following tests show that whenever we flip one edge we must also flip another edge.

In [33]:

```
cperm([1, 11]) in cube2
```

Out[33]:

In [34]:

```
cperm([1, 11], [2, 17]) in cube2
```

Out[34]:

Since `cube1`

and `cube2`

are the groups describing the actions on the two orbits of `cube`

, it is clear that `cube`

is a subdirect product of those groups, i.e., a subgroup of the direct product. Comparing the sizes of `cube1`

, `cube2`

, and `cube`

we see that `cube`

must be a subgroup of index 2 in the direct product of those two groups.

In [35]:

```
order(cube)
```

Out[35]:

In [36]:

```
order(cube1) * order(cube2)
```

Out[36]:

This final missing index 2 tells us that we cannot operate on corners and edges totally independently. The following tests show that whenever we exchange a pair of corners we must also exchange a pair of edges (and vice versa).

In [37]:

```
cflip = cperm([17, 19], [8, 11], [6, 25]); cflip in cube
```

Out[37]:

In [38]:

```
eflip = cperm([7, 28], [18, 21]); eflip in cube
```

Out[38]:

In [39]:

```
cflip * eflip in cube
```

Out[39]:

As a last part of the structure analysis of the cube group let us compute the center of the cube group, i.e., the subgroup of those operations that can be performed either before or after any other operation with the same result.

In [40]:

```
z = center(cube)[1]
```

Out[40]:

We see that the centre contains one nontrivial element, namely the operation that flips all 12 edges simultaneously.

Finally we turn to the original idea connected with the cube, namely to find a sequence of turns of the faces that will transform the cube back into its original state. This amounts to a decomposition of a given element of the cube group into a product of the generators. For this purpose we introduce a free group and a homomorphism of it onto the cube group.

(In order to make the results of the decompositions reproducible, we reset the random number generator that is involved in the computations.)

In [41]:

```
GAP.Globals.Reset(GAP.Globals.GlobalMersenneTwister);
```

In [42]:

```
f = free_group(["t", "l", "f", "r", "e", "b"])
```

Out[42]:

In [43]:

```
fhom = hom(f, cube, gens(cube))
```

Out[43]:

Using this homomorphism, we can now decompose elements into generators. The method used utilizes a stabilizer chain and does not enumerate all group elements, therefore the words obtained are not the shortest possible, though they are short enough for hand solutions.

(In order to make the results of the decompositions reproducible, we reset the random number generator that is involved in the computations.) First we decompose the nonidentity centre element:

In [44]:

```
zgen = gen(z, 1); pre1 = haspreimage(fhom, zgen)[2]
```

Out[44]:

In [45]:

```
length(pre1)
```

Out[45]:

Next we decompose some element arbitrarily chosen by us:

In [46]:

```
pre2 = haspreimage(fhom, cflip * eflip)[2]
```

Out[46]:

In [47]:

```
length(pre2)
```

Out[47]:

Last we let GAP choose a random element ...

In [48]:

```
r = rand(cube)
```

Out[48]:

In [49]:

```
pre3 = haspreimage(fhom, r)[2]
```

Out[49]:

In [50]:

```
length(pre3)
```

Out[50]:

... and we verify that the decomposition is correct:

In [51]:

```
fhom(pre3) == r
```

Out[51]:

This concludes our example.