TITLE: Computing the number of conjugacy-classes in $GL_{n}(\mathbb{F}_{p})$ of elementary abelian p-subgroups by GAP and Magma
QUESTION [5 upvotes]: I'm trying to compute the number of conjugacy-classes of elementary abelian p-subgroups of rank $2$ in $GL_{n}(\mathbb{F}_{p})$ by GAP and Magma. So I consider the following GAP function:
myfunction:= function(n,p)
local G, S, cclS, cclG;
  G := Image(IsomorphismPermGroup(GL(n,p)));
  S := SylowSubgroup(G,p); 
  cclS := Filtered(ConjugacyClassesSubgroups(S),
    cl->Size(Representative(cl))=p^2
    and not IsCyclic(Representative(cl)));
  cclG := List(EquivalenceClasses(cclS,
    function(cl1,cl2)
      return IsConjugate(G,Representative(cl1),
        Representative(cl2));
  end),Representative);
  cclG := List(cclG,cl->Representative(cl)^G);
  return Sum(List(cclG,Size));
end;

Questions:
Is there something I missed in this algorithm?
Is there a similar algorithm with  Magma which give the required computation?
Thank you in advance.

REPLY [6 votes]: This calculation should work, but you do a lot of extra work (calculating all subgroups of the Sylow subgroup) which you do not really need. This can become quite costly, in particular once the dimension $n$ becomes larger.
What will be more efficient is to find the subgroups from possible generating sets, e.g. by using:
cclG:=List(IsomorphicSubgroups(G,AbelianGroup([p,p])),Image);

(replacing the lines from S:=... down to ...Representative);
Since your function only returns the count of the total number of subgroups in these classes, this can be done even faster: Count, for each element $g\in G$ of order $p$, the number of elements of order $p$ in $C_G(g)$ outside $\langle g\rangle$, and to divide the result by the order of $GL_2(p)$ (to make up for the different generating systems for the same subgroup):
cl:=Filtered(ConjugacyClasses(G),x->Order(Representative(x))=p);
return Sum(
  List(cl,x->Size(x)*Sum(List(Filtered(ConjugacyClasses(Centralizer(x)),
    y->Order(Representative(y))=p
    and not Representative(y) in Group(Representative(x))),Size))))/Size(GL(2,p));

Presumably one could implement the same algorithm in Magma, but why would one want to do this?