I will just show how to find this information in GAP - a skill that may be useful in a number of situations.
GAP has is a function PageSource
which can show the source code of a function (with comments, if present). The argument of PageSource
should be a function (not an operation - see later how to handle that case). In the case of Elements
, that is indeed a function:
gap> Elements;
function( coll ) ... end
so one could call PageSource and see the location of the source code and the code itself:
gap> PageSource(last);
Showing source in gap4r8p2/lib/list.gi (from line 3718)
#M Elements( <coll> )
##
## for gap3 compatibility. Because `InfoWarning' is not available
## immediately this is not in coll.gi, but in the later read list.gi
##
InstallGlobalFunction(Elements,function(coll)
Info(InfoPerformance,2,
"`Elements' is an outdated synonym for `AsSSortedList'");
Info(InfoPerformance,2,
"If sortedness is not required, `AsList' might be much faster!");
return AsSSortedList(coll);
end);
Besides other useful details, we see that Elements
delegates to AsSSortedList
, which is an attribute:
gap> AsSSortedList;
<Attribute "AsSSortedList">
Attribute is an operation, so PageSource
will not work for it in the same way as above:
gap> PageSource(AsSSortedList);
Cannot locate source of kernel function AsSSortedList.
This happens because AsSSortedList
is actually a bunch of methods, and you need first to find the one which will be applied to the group in question via
gap> f:=ApplicableMethod(AsSSortedList,[Group( (1,2,3,4,5,6,7,8),(1,2) )]);
function( G ) ... end
Now one could see it as follows:
gap> PageSource(last);
Showing source in gap4r8p2/lib/grpperm.gi (from line 2031)
#############################################################################
##
#M AsSSortedList( <G> ) elements of perm group
##
InstallMethod( AsSSortedList,"via stabchain",true, [ IsPermGroup ], 0,
function( G )
return ElementsStabChain( StabChainMutable(G));
end );
Both of these functions are documented, type ?ElementsStabChain
and ?StabChainMutable
in GAP to see further details.
Note that if the value of the attribute is already stored in the object, ApplicableMethod
will not be helpful, as it will return the so called "system getter" which retrieves the stored information:
gap> G:=Group( (1,2,3,4,5,6,7,8),(1,2) );
Group([ (1,2,3,4,5,6,7,8), (1,2) ])
gap> Size(G);
40320
gap> ApplicableMethod(Size,[G]);
function( object ) ... end
gap> PageSource(last);
Cannot locate source of kernel function GetterFunc(Size).
In this case, to find the actual method being used to compute the attribute, you would have to create the object from scratch:
gap> G:=Group( (1,2,3,4,5,6,7,8),(1,2) );
Group([ (1,2,3,4,5,6,7,8), (1,2) ])
gap> ApplicableMethod(Size,[G]);
function( G ) ... end
gap> PageSource(last);
Showing source in gap4r8p2/lib/grpperm.gi (from line 482)
##
InstallMethod( Size,
"for a permutation group",
true,
[ IsPermGroup ], 0,
G -> SizeStabChain( StabChainMutable( G ) ) );