2
$\begingroup$

How can I find the codes related to a function in GAP? When I use "??" in front of the name of function there is no help, so I want to find the code of function among packages.

$\endgroup$
6
  • 1
    $\begingroup$ Normally the $C$ source code is included with the GAP installation. If it is that what you want. But if you look for the script code then often the command $\mathtt{Display}$ helps. Like in $\mathtt{Display(List);}$ $\endgroup$ Sep 27, 2014 at 11:31
  • $\begingroup$ ?? is used to find the documentation, not the source. For the source, use PageSource. See this recent thread in the GAP Forum for more details. Beware of the difference between function and operation: for the latter, ApplicableMethod should be used first. $\endgroup$ Sep 27, 2014 at 13:55
  • $\begingroup$ P.S. Needless to say that if the functions belongs to a GAP package, then this package should be loaded first. $\endgroup$ Sep 27, 2014 at 13:59
  • 3
    $\begingroup$ This question has no mathematical content and is not within the scope of Math.SE - perhaps that's why it was downvoted. GAP Support might be a better place for such questions. OTOH, if you would specify which function do you have in mind and say that you're interested to understand the algorithm used, that may fit into the scope of Math.SE quite well. $\endgroup$ Sep 27, 2014 at 20:01
  • 1
    $\begingroup$ Even though this question is quite technical, let's keep an answer here: after all, this may be useful for many GAP users at Math.SE. I am happy to change the function from the example to something else, if there would be any suggestions. $\endgroup$ Oct 1, 2014 at 21:08

1 Answer 1

3
$\begingroup$

First, GAP is an open-source project, and both the core system and GAP packages are supplied in the GAP distribution with their source code. You may use various tools available at your system to search for a string in the source code, for example

grep -R --include=*.g* BoundPositions pkg/*

Secondly, you may print a function, for example:

gap> Print(BoundPositions);
function ( l )
    return Filtered( [ 1 .. Length( l ) ], function ( i )
            return IsBound( l[i] );
        end );
end
gap>

In this case, the code is formatted accordingly to GAP rules, and comments in the code are not displayed.

Thirdly, you may use PageSource to show the exact place in the file where the code is contained. In this case, you will see all comments and the author's formatting of the code. For example,

gap> PageSource(BoundPositions);
Showing source in /Users/alexk/gap4r7p5/pkg/fga/lib/util.gi (from line 6)
##
#Y  2003 - 2012
##

InstallGlobalFunction( BoundPositions,
    l -> Filtered([1..Length(l)], i -> IsBound(l[i])) );

As one could see, this is an (undocumented) function from the FGA package. Clearly, the package should be loaded before using either Print(BoundPositions) or PageSource(BoundPositions).

Note that the argument must be a function, so for operations, attributes, properties, filters etc. one should use ApplicableMethod first, otherwise you may see something like this:

gap> PageSource(Size);
Cannot locate source of kernel function Size.

gap> PageSource(IsGroup);
Cannot locate source of kernel function <<and-filter>>.

Some more details are given in this GAP Forum thread and in this question.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .