I've answered this in finding code of a function in GAP packages - please read it and also explore links that it contains.
However, this particular case seems interesting and not obvious because of the equality operation which one should input as \=, so I will show an example here too:
Get applicable method:
gap> f:=ApplicableMethod(\=,[g_1,g_2]);
function( G, H ) ... end
Now see its location in the code:
gap> FilenameFunc(f);
".../gap4r7p9/lib/grp.gi"
gap> StartlineFunc(f);
2757
or view it in the GAP session:
gap> PageSource(f);
Showing source in .../gap4r7p9/lib/grp.gi (from line 2752)
#M \=( <G>, <H> ) . . . . . . . . . . . . . . test if two groups are equal
##
InstallMethod( \=,
"generic method for two groups",
IsIdenticalObj, [ IsGroup, IsGroup ],
function ( G, H )
if IsFinite( G ) then
if IsFinite( H ) then
return GeneratorsOfGroup( G ) = GeneratorsOfGroup( H )
or IsEqualSet( GeneratorsOfGroup( G ), GeneratorsOfGroup( H ) )
or (Size( G ) = Size( H )
and ((Size(G)>1 and ForAll(GeneratorsOfGroup(G),gen->gen in H))
or (Size(G)=1 and One(G) in H)) );
else
return false;
fi;
elif IsFinite( H ) then
return false;
else
return GeneratorsOfGroup( G ) = GeneratorsOfGroup( H )
or IsEqualSet( GeneratorsOfGroup( G ), GeneratorsOfGroup( H ) )
or ( ForAll( GeneratorsOfGroup( G ), gen -> gen in H )
and ForAll( GeneratorsOfGroup( H ), gen -> gen in G ));
fi;
end );
As you may see, in the most general case it will check that each generator of one group belongs to the other group and vice versa, but before reaching that there are also certain optimisation and obvious cases requiring less or no actual computation.