Coloured Permutations in GAP II
Lets introduce a third internal representation of a coloured permutation as a pair:
[sigma, colourvector] .
where sigma is a vanilla permutation, and colourvector is a list of colours.
Coloured permutation matrices are always monomial matrices
gap> A := ColouredMatrix((1,2,3,4),[E(3),1,E(3)^2,E(3)]); [ [ 0, 1, 0, 0 ], [ 0, 0, E(3)^2, 0 ], [ 0, 0, 0, E(3) ], [ E(3), 0, 0, 0 ] ] gap> IsMonomialMatrix(A); true .
We need a function that translates a permutation matrix into a permutation.
pointToVector := function( n, k ) local i, vect; vect := []; for i in [1..n] do vect[i] := 0; od; vect[k] := 1; return vect; end; vectorToPoint := function( vect ) local k; k := 1; while (vect[k] = 0) do k := k + 1; od; return k; end; matToPerm := function( mat ) local listperm; listperm := List( mat, row -> vectorToPoint( row )); return PermList(listperm); end; .
For example:
gap> sigma := PermutationMat((1,2,3),3); [ [ 0, 1, 0 ], [ 0, 0, 1 ], [ 1, 0, 0 ] ] gap> matToPerm(sigma); (1,2,3) .
Its not much harder now to write a function which translates a coloured permutation matrix into our new internal representation for coloured permutations:
vectorToColour := function( vect ) local k; k := 1; while (vect[k] = 0) do k := k + 1; od; return vect[k]; end; colMatToColPerm := function( mat ) local mat2, listperm, colours; mat2 := TransposedMat( mat ); colours := List( mat2, row -> vectorToColour( row )); listperm := List( mat, row -> vectorToPoint( row )); return [PermList(listperm), colours]; end; .
For example:
gap> colMatToColPerm( A ); [ (1,2,3,4), [ E(3), 1, E(3)^2, E(3) ] ] .
Going the other way is slightly more tricky. Starting with GAP’s representation of a coloured permutation with
colours on
points as a permutation in
which stabilizes:

we want to translate it into a pair:
[sigma, colourvect]. .
So, here goes:
extractColPerm := function( colperm, k,n ) local i, points, images, sigma, colours; points := Filtered([1..n*k], i -> (i mod k) = 1); images := List(points, p -> p^colperm); sigma := PermList(List(images, i -> Int((i-1)/k + 1))); colours := List(images, i -> E(k)^((i mod k) - 1)); return [sigma,colours]; end; .
Now lets test it:
gap> gapPerms := Elements(ColouredPerms(3,2)); [ (), (4,5,6), (4,6,5), (1,2,3), (1,2,3)(4,5,6), (1,2,3)(4,6,5), (1,3,2), (1,3,2)(4,5,6), (1,3,2)(4,6,5), (1,4)(2,5)(3,6), (1,4,2,5,3,6), (1,4,3,6,2,5), (1,5,2,6,3,4), (1,5,3,4,2,6), (1,5)(2,6)(3,4), (1,6,3,5,2,4), (1,6)(2,4)(3,5), (1,6,2,4,3,5) ] gap> test := List(gapPerms, sigma -> extractColPerm(sigma,3,2)); [ [ (), [ 1, 1 ] ], [ (), [ 1, E(3) ] ], [ (), [ 1, E(3)^2 ] ], [ (), [ E(3), 1 ] ], [ (), [ E(3), E(3) ] ], [ (), [ E(3), E(3)^2 ] ], [ (), [ E(3)^2, 1 ] ], [ (), [ E(3)^2, E(3) ] ], [ (), [ E(3)^2, E(3)^2 ] ], [ (1,2), [ 1, 1 ] ], [ (1,2), [ 1, E(3) ] ], [ (1,2), [ 1, E(3)^2 ] ], [ (1,2), [ E(3), 1 ] ], [ (1,2), [ E(3), E(3) ] ], [ (1,2), [ E(3), E(3)^2 ] ], [ (1,2), [ E(3)^2, 1 ] ], [ (1,2), [ E(3)^2, E(3) ] ], [ (1,2), [ E(3)^2, E(3)^2 ] ] ] .
Finally we need to be able to go from our internal representation of a coloured permutation, to GAP’s representation.
foo := function( rootofunity, k)
local power;
power := 0;
while not (rootofunity = E(k)^power) do
power := power + 1;
od;
return power;
end;
gapPerm := function( sigma, colourvect, k, n )
local i, images, oldcolours, newcolours;
oldcolours := List([1..n*k], i -> ((i-1) mod k));
newcolours := [];
for i in [1..n*k] do
newcolours[i] := (oldcolours[i]
+ foo(colourvect[Int( (i-1)/k ) + 1],k)) mod k;
od;
images := [];
for i in [1..n*k] do
images[i] := k*( (Int( (i-1)/k ) + 1)^sigma - 1)
+ 1 + newcolours[i];
od;
return PermList(images);
end;
.Final test:
gap> List(test, c-> gapPerm(c[1],c[2],3,2)); [ (), (4,5,6), (4,6,5), (1,2,3), (1,2,3)(4,5,6), (1,2,3)(4,6,5), (1,3,2), (1,3,2)(4,5,6), (1,3,2)(4,6,5), (1,4)(2,5)(3,6), (1,4,2,5,3,6), (1,4,3,6,2,5), (1,5,2,6,3,4), (1,5,3,4,2,6), (1,5)(2,6)(3,4), (1,6,3,5,2,4), (1,6)(2,4)(3,5), (1,6,2,4,3,5) ] .
Yes, this code is ugly.