How to find presentation of a group using GAP?

I have a group from Small Group Library and I want to find its presentation using GAP.

I have tried to use PresentationFpGroup(G) but failed.

Please suggest me a method.


Overview.

If G is the group you want a presentation for, first use

H:=Image(IsomorphismFpGroup(G));

to transform G into a FPGroup type. GAP will output the generators. Then follow up with

RelatorsOfFpGroup(H);

to see the relations.

Remark.

Sometimes it may be helpful to call SimplifiedFpGroup like here:

H:=SimplifiedFpGroup(Image(IsomorphismFpGroup(G))); 

in order to obtain a presentation of a simpler form.


Example.

The following example demonstrates this for the dihedral group of order 256. First we will figure out its ID and extract it from the Small Groups Library:

gap> D:=DihedralGroup(256);
<pc group of size 256 with 8 generators>
gap> IdGroup(D);
[ 256, 539 ]
gap> G:=SmallGroup(256,539);
<pc group of size 256 with 8 generators>

It is given by a presentation of special kind, called polycyclic presentation. This is very efficient to process this group on a computer, but not very efficient for processing by humans:

gap> H:=Image(IsomorphismFpGroup(G));
<fp group of size 256 on the generators [ F1, F2, F3, F4, F5, F6, F7, F8 ]>
gap> RelatorsOfFpGroup(H);
[ F1^2, F2^-1*F1^-1*F2*F1*F3^-1, F3^-1*F1^-1*F3*F1*F4^-1, F4^-1*F1^-1*F4*F1*F5^-1, 
  F5^-1*F1^-1*F5*F1*F6^-1, F6^-1*F1^-1*F6*F1*F7^-1, F7^-1*F1^-1*F7*F1*F8^-1, 
  F8^-1*F1^-1*F8*F1, F2^2, F3^-1*F2^-1*F3*F2*F4^-1, F4^-1*F2^-1*F4*F2*F5^-1, 
  F5^-1*F2^-1*F5*F2*F6^-1, F6^-1*F2^-1*F6*F2*F7^-1, F7^-1*F2^-1*F7*F2*F8^-1, 
  F8^-1*F2^-1*F8*F2, F3^2*F5^-1*F4^-1, F4^-1*F3^-1*F4*F3, F5^-1*F3^-1*F5*F3, 
  F6^-1*F3^-1*F6*F3, F7^-1*F3^-1*F7*F3, F8^-1*F3^-1*F8*F3, F4^2*F6^-1*F5^-1, 
  F5^-1*F4^-1*F5*F4, F6^-1*F4^-1*F6*F4, F7^-1*F4^-1*F7*F4, F8^-1*F4^-1*F8*F4, 
  F5^2*F7^-1*F6^-1, F6^-1*F5^-1*F6*F5, F7^-1*F5^-1*F7*F5, F8^-1*F5^-1*F8*F5, 
  F6^2*F8^-1*F7^-1, F7^-1*F6^-1*F7*F6, F8^-1*F6^-1*F8*F6, F7^2*F8^-1, F8^-1*F7^-1*F8*F7, 
  F8^2 ]

Luckily, in this case SimplifiedFpGroup produces much shorter presentation:

gap> K:=SimplifiedFpGroup(H);
<fp group on the generators [ F1, F2 ]>
gap> RelatorsOfFpGroup(K);
[ F1^2, F2^2, (F1*F2)^128 ]

Just to show that all these three groups are isomorphic,

gap> List([G,H,K],StructureDescription);
[ "D256", "D256", "D256" ]

Note that if the connection to the original group is important, then the operation IsomorphismSimplifiedFpGroup should be used instead of SimplifiedFpGroup. Furthermore, if for some concrete group the resulting presentation is unsatisfying, then one could try more sophisticated interactive use of Tietze transformation commands available in GAP (see here).