MAGMA: semidirect product of finite matrix group in matrix form Apologies for the very novice question. I am trying to find conjugacy classes and representatives (in matrix form) of a finite group of matrices $G$, isomorphic to $$ (\mathbb{Z}/n\mathbb{Z})^3 \rtimes S_3. $$
The isomorphism is as follows: the $i$-th copy of $\mathbb{Z}/n\mathbb{Z}$ is generated by the diagonal matrix with entries $\omega = e^\frac{2\pi \sqrt{-1}}{n}$ in the $(i,i)$ entry, and 1 elsewhere, and $S_3$ acts by conjugation, permuting the copies of $\mathbb{Z}/n\mathbb{Z}$.
I set this problem up in Magma using SemidirectProduct (an example follows with $n=3$).
The command Classes(G); seems to be what I want, however, it returns representatives expressed in cycle notation since SemidirectProduct presents $G$ as a permutation group. Is there a way to preserve the matrix form of the elements of the group when invoking SemidirectProduct (getting elements of the semidirect product as pairs of matrices)? Or an alternative way to construct the group $G$?
//Three copies of Cyclic group
F<w> := CyclotomicField(3);
H := MatrixGroup< 3, F | [w,0,0, 0,1,0, 0,0,1], [1,0,0, 0,w,0, 0,0,1], [1,0,0, 0,1,0, 0,0,w] >;

//Permutation group
K := MatrixGroup<3, F | [0,1,0, 1,0,0, 0,0,1], [0,0,1, 1,0,0, 0,1,0]>;
k1 := elt <K | 0,1,0, 1,0,0, 0,0,1>;
k2 := elt  <K | 0,0,1, 1,0,0, 0,1,0>;

//Conjugacy action
A := AutomorphismGroup(H);
p1 := elt<A|hom<H->H | g :-> g^k1>>;
p2 := elt<A|hom<H->H | g :-> g^k2>>;
f := hom<K->A| k1 -> p1, k2-> p2>;

G := SemidirectProduct(H,K,f);

 A: The SemidirectProduct intrinsic actually produces several maps as output that you can use for this.  For example we can define
G, m1, m2, m3 := SemidirectProduct(H,K,f);

Then we have that

*

*$m_{1} : H \to G$ by $h \mapsto (h,1)$,

*$m_{2} : K \to G$ by $k \mapsto (1,k)$ (here of course the outputs of $m_{1}$ and $m_{2}$ are actually permutations in $G$ corresponding to these matrix pairs),

*$m_{3} : G \to K$ by $g \mapsto k$ where $g = m_1(h)*m_2(k)$.

This give a nice way to take a matrix pair $(h,k) : h \in H, k \in K$ as an element of $G$ by
g := m1(h)*m2(k) 

(I know you are asking about the other direction).
If you would like to turn a permutation in $G$ to a pair of matrices $(h,k)$, we can write a function
function PermutationToMatrixPair(g)
    k := m3(g);
    h := (m1^-1)(g*m2(k^-1));
    return <h,k>;
end function;

This will take $g$ as a permutation, and you want to write it as a corresponding ordered pair of matrices $h \in H$, $k \in K$;

*

*$k$ we can get directly from the projection map $m_{3}$, k := m3(g).

*Then if we multiply $g$ by (the permutation corresponding to)
$k^{-1}$, we have a new permutation $g^{\prime}$ that corresponds to
$(h,1)$; ie gprime := g*m2(k^-1);

*to recover the matrix $h$ from the permutation, we can take the
inverse image under our embedding map $m_{1}$ (since this map has as
its image the set of permutations in $G$ corresponding to matrix
pairs of the form $(h,1)$ with $h \in H$); h := (m1^-1)(gprime).

(Note: you will either need to define this function at an appropriate place in your code where m1, m2, m3 have been previously defined, or else define the function as taking m1, m2, m3 as arguments.)
As an alternate way to do this, you can define a map with specified inverse to convert back and forth between permutations and matrix pairs.
phi := map<G-> CartesianProduct(H,K) | g  :-> <(m1^-1)(g*m2(m3(g)^-1)), m3(g)>,
                                       hk :-> m1(hk)*m2(hk) >;

