Writing a group as a product of its generators in MAGMA Let $G \subseteq S_8$ be generated by the elements $s=\begin{pmatrix} 1 & 2 \end{pmatrix}\begin{pmatrix} 3 & 5 \end{pmatrix}\begin{pmatrix} 4 & 6 \end{pmatrix}\begin{pmatrix} 7 & 8 \end{pmatrix}$ and $t=\begin{pmatrix} 1 & 3 & 7 & 4 \end{pmatrix}\begin{pmatrix} 2 & 5 & 8 & 6 \end{pmatrix}$.
Now I would like to see how to write the element
$$u = \begin{pmatrix} 1 & 8 \end{pmatrix}\begin{pmatrix} 2 & 7 \end{pmatrix}\begin{pmatrix} 3 & 6 \end{pmatrix}\begin{pmatrix} 4 & 5 \end{pmatrix} \in S_8$$
can be written as a product of $s,s^{-1}$ and $t,t^{-1}$ in MAGMA (assuming that $u \in G$).
I wrote the following code
G<s,t> := PermutationGroup< 8 | (1, 2)(3, 5)(4, 6)(7, 8) , (1, 3, 7, 4)(2, 5, 8, 6) >;
u := G ! (1, 8)(2, 7)(3, 6)(4, 5);

Are there any commands to give me my desired result?

The code below will do what you want - in  fact the answer is rather easy! This method will work provided that the group is not too big - say maximum order about $10^7$ or maybe $10^8$. Although not really necessary for solving this problem, it computes a presentation of the group $G$.
> G<s,t> := PermutationGroup< 8 |
    (1, 2)(3, 5)(4, 6)(7, 8) , (1, 3, 7, 4)(2, 5, 8, 6) >;
> u := G ! (1, 8)(2, 7)(3, 6)(4, 5);
> F<S,T>, phi := FPGroup(G);
> u @@ phi;
  S * T^2

