Software Carpentry lesson on GAP

I’ve recently developed the Software Carpentry lesson “Programming with GAP“. This lesson is intended for GAP beginners and has been beta-tested at the Software Carpentry Workshop that we run in Manchester as a part of the First CoDiMa training school in Computational Discrete Mathematics. The lesson itself is available here, and its repository is located here.

What next? I can teach my lesson myself, but is it written clearly enough to be taught by others? Is it possible for the reader to follow it for self-study? Is there any introductory material missing, or is there an interest in having more advanced lesson(s) on some (which?) aspects of the system? If you would like to contribute to its further development, issues and pull requests on GitHub are most welcome!

Why Random can not be an attribute in GAP?

What will happen if we will declare Random as an attribute? Let’s try!

First we will create new attribute MyRandom for objects in the category IsCollection:

MyRandom := NewAttribute("MyRandom", IsCollection);

Now we install a generic method (more…)

How quick are new GAP releases picked up?

I analysed 185 papers papers citing GAP, published in 2014-2015 and contained in MathSciNet as on August 18th, 2015. The diagram below (click on the picture to enlarge) shows the number of papers citing GAP releases by the year of the release. It also shows releases that were published (though not necessary cited in the analysed papers) in corresponding years.

GAP_Citations_2014-15.001

Some facts discovered:

  • 44% (81 paper) refer to GAP 4.5.4 (the 1st public release of GAP 4.5 in June 2012) or some newer version.
  • 24% (44 papers) cite GAP 4.4.12 (December 2008), which was the stable GAP release for several years until the appearance of GAP 4.5.
  • 14 papers cite some GAP package but not GAP, so this only gives some hints to the version of GAP that might be used.
  • 9 papers cite GAP without GAP version and/or release year.
  • 19% (35 papers) cite GAP 4 releases published during 2000-2007.
  • 1 paper genuinely cites GAP 3.4.4 because it uses the CHEVIE package.

It is not surprising that there is a long tail of citations of older versions. Papers that appeared in 2014 may be submitted prior to GAP 4.5 release, or, even if they were submitted after, describe experiments that were performed using GAP 4.4.12. But it is interesting what’s behind those 35 citations of the older GAP releases. Are these real usages of outdated GAP installations, re-used bibliographies from earlier papers, or something else?

Specifying the exact version of the system (as well as specific GAP packages, if their use was essential) is very important for the reproducibility of computational results. Furthermore, each GAP release contains new features and bugfixes, and comes with updated and expended set of GAP packages (see the history of GAP releases). Therefore, we suggest to always try to use the latest release, and to cite it correctly (GAP function Cite may help with that).

How to use GAP more efficiently?

  1. Use command line for object exploration and prototyping, then write the proper code.
  2. Use LogTo to save inputs and outputs to a logfile which then you can edit in a text editor.
  3. Save code in text files and use Read to load them. Find some advanced text editor to edit these files.
  4. Make your code modular and reusable by organising it into functions.
  5. Write comments in the code – this will help you when you will return to it after a while.
  6. Use command line history instead of retyping commands! It even could be made available in the next GAP session.
  7. Understand break loops: you may explore variables on the current break level and use Where to show the last commands before the error occurred.
  8. Use preferences mechanism to customise GAP.
  9. Understand the theory behind calculations: theoretical improvements could improve the performance much more than optimised code for brute-force calculations.
  10. Cite GAP if you use it! This helps for the community to grow, and this will help you.

See also my earlier posts on things you may want to do after GAP installation and first steps in GAP.

Two GAP and SageMath events in November-January

In the next several years we will run a series of annual workshops and training schools in computational discrete mathematics, supported by the EPSRC-funded Collaborative Computational Project CoDiMa (http://www.codima.ac.uk)At the moment, we have finalised dates and locations for the first two of our events:

The First CoDiMa Training School in Computational Discrete Mathematics will take place at the University of Manchester on November 16th-20th, 2015. This school is intended for PhD students and researchers from UK institutions. It will start with the 2-days hands-on Software Carpentry workshop covering basic concepts and tools, including working with the command line, version control and task automation, continued with introductions to GAP and SageMath systems, and followed by the series of lectures and exercise classes on a selection of topics in computational discrete mathematics. The school will finish at Friday lunchtime, with an option to stay for the NBSAN (North British Semigroups and Applications Network) meeting on Friday afternoon.

The First Joint GAP-SageMath Days will be held at the University of St Andrews on January 18th-22nd, 2016. The focus of this event will be on improving GAP-SageMath integration and interaction between our systems. Prior to that, there will be also a GAP coding sprint on January 13th-16th. 

Please check http://www.codima.ac.uk/events/ and follow the CoDiMa project on Twitter @codima_project for further announcements.

Five hints for GAP beginners

  1. Linux and OS X users: Some GAP packages require compilation. Remember to build GAP packages after you have compiled the GAP kernel. To do this, use the InstPackages.sh script as described here.
  2. Windows users: to install GAP, use the .exe installer which you may find here. It will provide a standard installation procedure and adjust the paths in case of installing GAP in a non-default location. NEVER install GAP in path with spaces (e.g. in “My Documents”).
  3. Stay in touch! Subscribe to the GAP Forum. If you are on Twitter, follow @gap_system.
  4. If you need help: ask questions in the GAP Forum, or send them to the GAP Support, or post them at the Mathematics Q&A site. Choose among these three, dependently on the question.
  5. If you think that you’ve found a bug: please create an issue on GitHub or report it by email to GAP Support.

How to cite GAP or its package?

Is may be well-known that there is a page on the GAP website which suggests how to cite GAP.

Perhaps less known is the fact that GAP installation has a file called CITATION, situated in the GAP root directory. This file contains sample citations for this particular version of GAP in text, HTML, BibXML and LaTeX formats.

However, it may be even less known that since GAP 4.7.2 release (December 2013), GAP also provides a function Cite(), which is documented here. Called without arguments, it generates sample citations for GAP in all formats mentioned above. If it is called with the optional string pkgname which contains a name of a GAP package, it produces instructions on citing this package (only if its working version is available in this GAP installation).

It is a good practice to specify the version of the software used in the paper, so this functionality should help to keep it accurate!

 

Ten hints for GAP beginners

 

  1. Remember that GAP is case-sensitive! That means that ABC, Abc and abc are three different identifiers. A call to SymmetricGroup(3) works, but Symmetricgroup(3)will cause an error.
  2. An error message “Error, Variable: 'FuncName' must have a value” in a function call usually points to a typo in the function name (see the previous hint), or to some package that must be loaded in advance using LoadPackage.
  3. Do not hesitate to use longer and more informative variable names where appropriate. For example, x looks perfectly suitable for List([1..10], x -> x^2), while ConClassesReps may be more informative than just x for a list of representatives of conjugacy classes of a group.
  4. Use command line editing: scroll the history of commands and navigate within the command line using arrow keys.
  5. Use autocompletion instead of typing names of functions and variables in full. Type the initial part of the identifier and then press <Tab>. It will be autocompleted if its unique completion is possible. If not, you may press <Tab> again to see all possible suggestions.
  6. To view help pages, use ? and ?? commands. This will search not only in the GAP manuals, but also in the manuals of all GAP packages available in your GAP installation.
  7. Set default help format to HTML. Use SetHelpViewer function to view it with your preferred browser.
  8. Use LogTo function to save all GAP input and output into a text file. It should be called before calculations, not after!
  9. If calculation takes too long, press <Control>-C to interrupt it. Then type quit; to leave the break loop.
  10. Read A First Session with GAP from the GAP Tutorial.

Average order of group elements: a demo of test-driven development in GAP

This blog post is based on an improvised demo that I gave at the Newcastle University on May 21st, 2015 during a short visit supported by the CoDiMa project.

Let’s consider the following exercise: for a finite group G, calculate the average order of its element (that is, the sum of orders of its elements divided by the order of the group). We begin with a very straightforward approach, iterating over all elements of the group in question:


 gap> S:=SymmetricGroup(10);
 Sym( [ 1 .. 10 ] )
 gap> sum:=0;
 0
 gap> for g in S do
 >      sum := sum + Order(g);
 >    od;
 gap> sum/Size(S);
 39020911/3628800

Now assume that we would like to save this fragment of the GAP code and later repeat this calculation for some other groups. (more…)

GAP 4.7.8 release

GAP 4.7.8 release, dated 9th June 2015, is now publicly available! It fixes several bugs reported since the previous release (February 2015), and also includes 2 new and 17 updated GAP packages. Furthermore, this is the first release since we have established the official development repository for GAP on GitHub, so it also checks that everything (GAP codebase, release wrapping scripts, infrastructure for regression tests, etc.) has been migrated properly and works as expected.

Please see downloads, release announcement and changes overview for further details.