GAP
A system and programming language for computational discrete algebra, with particular emphasis on computational group theory, developed by an open international collaboration since 1986.
Created by Joachim Neubüser and collaborators at Lehrstuhl D für Mathematik, RWTH Aachen
GAP — Groups, Algorithms, Programming — is a system for computational discrete algebra, with particular emphasis on computational group theory. It combines a domain-specific programming language, a kernel implemented in C, a very large library of mathematical algorithms written in the GAP language itself, and data libraries that encode mathematical objects (small groups, transitive permutation groups, character tables of finite simple groups, and so on). Distributed under the GNU General Public License and developed by an open international collaboration, GAP is one of the principal computer-algebra systems used in pure-mathematics research and teaching, alongside Magma, Maple, Mathematica, SageMath, and Singular.
History & Origins
Aachen beginnings (1986–1997)
GAP was started in 1986 at Lehrstuhl D für Mathematik at RWTH Aachen in Germany, under the direction of Joachim Neubüser. Neubüser’s group had a long tradition of work on computational group theory — algorithms for permutation groups, finitely presented groups, and character tables — and the GAP project was conceived as a way to make those algorithms broadly available to working mathematicians in a single, programmable environment, rather than as a constellation of standalone Fortran programs.
The first public version of GAP, in the 2.x series, was distributed in the late 1980s. GAP 3 followed in 1992 and became the de facto standard system for computational group theory in academic mathematics through the 1990s. From the outset, the design choices reflected a deliberate ethic: the system would be free, the source would be open, and the library would be readable — written in the same language that users wrote, so that anyone studying a result could inspect (and modify) the algorithm that produced it.
Move to St Andrews and GAP 4 (1997–1999)
In 1997, coordination of GAP development moved from RWTH Aachen to the University of St Andrews in Scotland, under Steve Linton, and the system gained a more distributed development model with active centers in Aachen, St Andrews, Braunschweig, and Fort Collins (Colorado State University). Two years later, in 1999, GAP 4 was released — a major rewrite that introduced a method-selection mechanism reminiscent of the Common Lisp Object System, a more uniform object model, and a substantially redesigned library. GAP 4 remains the active lineage today; all subsequent releases are point versions in the 4.x series.
Recognition and continued development
GAP received the ACM/SIGSAM Richard D. Jenks Memorial Prize in 2008 for excellence in software engineering applied to computer algebra. In the years since, GAP has continued to evolve as a community project: the core has been modernized, the package ecosystem has grown to over one hundred contributed packages, the development workflow has moved to GitHub, and GAP has been adopted as one of the four cornerstone systems of the OSCAR computer-algebra project (alongside Singular, Polymake, and Nemo/Hecke), through which GAP’s algorithms are exposed inside a Julia-based front end.
Design Philosophy
Several principles distinguish GAP from general-purpose programming languages:
- A language tailored to algebraic objects. Groups, rings, fields, modules, characters, and similar structures are first-class in the type system. The standard library is organized around mathematical categories such as
IsGroup,IsField, andIsAssociativeAlgebra, and operations dispatch on the category memberships of their arguments. - Open, readable library. The mathematical library — many tens of thousands of functions — is written in GAP itself, not in C. Users are encouraged to read the library to understand how an algorithm works; this is treated as part of the system’s documentation.
- Reproducible mathematics. Because GAP is free software with an open library, results obtained with GAP can in principle be reproduced and audited by any reader, which matters for mathematical papers that depend on computational evidence.
- Method selection over class hierarchies. GAP 4’s object system selects methods based on the filters (also called categories and properties) that an object satisfies, rather than on a single inheritance chain. This allows the same operation, e.g.
IsAbelian, to have many different efficient implementations chosen automatically based on what is known about the input. - Interactive at the top, compiled at the bottom. A GAP session is a read–eval–print loop, but performance-critical primitives — long-integer arithmetic, permutation multiplication, vector arithmetic over finite fields — live in the C kernel.
Key Language Features
Syntax
GAP’s surface syntax is mildly Pascal-like, with keywords such as if … then … fi, for … do … od, and while … do … od, and with := for assignment:
PrintFactorization := function(n)
local p;
for p in Factors(n) do
Print(p, " ");
od;
Print("\n");
end;
PrintFactorization(360);
# 2 2 2 3 3 5
Functions are first-class values; lambdas can be written with the arrow syntax n -> n^2, and higher-order patterns such as List, Filtered, ForAll, and Sum are pervasive throughout the library.
Working with groups
The features that distinguish GAP from a general-purpose language are most visible when working with algebraic objects directly:
g := SymmetricGroup(5);;
Size(g); # 120
IsSimple(g); # false
DerivedSubgroup(g) = AlternatingGroup(5); # true
Length(ConjugacyClasses(g)); # 7
CharacterTable(g);
A few lines of GAP can replace pages of by-hand computation, and the library handles the choice of representation (permutation, matrix, finitely presented, polycyclic, …) appropriate to the operation.
Method selection and filters
Operations in GAP 4 are declared once and then implemented by many methods, each guarded by a list of filter requirements. When an operation is called, GAP selects the most specific applicable method based on the actual filters its arguments satisfy. This allows, for example, Size to have one fast method for permutation groups, another for polycyclic groups, another for finitely presented groups, and so on, with the right one chosen automatically.
Records and lists
The main aggregate data structures are lists (heterogeneous, dynamically sized, 1-indexed) and records (named-field structures). Both are used pervasively in the library:
person := rec(name := "Galois", year := 1832);
Print(person.name, " (", person.year, ")\n");
squares := List([1..10], n -> n^2);
Sum(squares); # 385
Package system
GAP ships with a substantial collection of contributed packages — separately versioned extensions, written in GAP (sometimes with C kernels), that provide specialized functionality such as homological algebra (HAP), Lie algebras (GAPDoc ecosystem, quagroup), combinatorial structures (Digraphs, GRAPE), or polynomial computations. Packages are loaded with LoadPackage("name"); and are distributed both with the GAP core and from the project website.
Architecture
A running GAP system consists of three principal layers:
- The C kernel implements the interpreter, the garbage collector, long-integer arithmetic, and a handful of primitives where C performance is essential.
- The GAP library — the bulk of the mathematics — is written in the GAP language and is loaded at startup. Users can inspect any library function with
Print(NameOfFunc);(subject to legibility) and override or extend it. - Packages are loaded on demand and may add new operations, new methods on existing operations, new categories of objects, and additional C extensions.
This layered design is what makes GAP feel different from a typical interpreted language: most of what looks like a built-in capability is in fact a library function that the user can read, modify, and reimplement.
Platform Support
According to the official documentation, GAP is distributed in source form and is regularly built on Linux, macOS, and Unix-like systems. Binary and source distributions are made available from the project’s website. Running GAP on Windows is generally documented as proceeding through the Cygwin environment or the Windows Subsystem for Linux rather than as a fully first-class native port; consult the current GAP installation instructions for the supported configurations of the version you intend to use.
Community-maintained Docker images are available (see the gapsystem organization on Docker Hub), which is often the simplest way to obtain a working GAP environment without managing dependencies by hand.
Community and Ecosystem
GAP is developed as an open international collaboration coordinated from St Andrews. Its primary community resources include:
- The official website at
gap-system.org, which hosts source releases, package distributions, the manual, and the ATLAS-related data libraries. - The GAP Forum mailing list, a long-running venue where users and developers discuss bugs, algorithms, and applications.
- GitHub-hosted development for the core system and many packages, providing public issue trackers and pull-request workflows.
- The bibliography of works using GAP, maintained by the project, which records published papers and theses that cite GAP — a body of literature spanning thousands of entries across pure and applied mathematics.
GAP also has a presence in the broader open-source mathematics ecosystem through its integration with SageMath and OSCAR, both of which expose GAP’s algorithms to users who may never invoke GAP directly.
Current Relevance
In its fourth decade, GAP remains one of the standard tools for research in computational group theory and adjacent areas. It is the system most commonly cited in mathematical papers that perform large character-table computations, classification results for small groups, and explicit computations in finitely presented groups. Where other computer-algebra systems compete on commercial breadth (Magma, Maple, Mathematica), GAP competes on openness, library readability, and depth in discrete algebra.
The integration of GAP into SageMath and OSCAR means that GAP’s algorithms are reaching users who use a different surface syntax — a Python or Julia front end — and who may not think of themselves as GAP programmers at all. From the perspective of the GAP project, this is a feature: the goal has always been to make computational group theory broadly available, and embedding GAP in larger systems serves that goal regardless of which language the user types.
Why It Matters
GAP matters for several reasons that extend beyond computational group theory itself.
It is one of the earliest large-scale demonstrations that a specialized programming language plus an open mathematical library can serve as serious research infrastructure. Decades before “computational science” became a buzzword, GAP showed that a community of mathematicians could collaboratively build, document, and maintain a system that produced reproducible results, with the algorithm itself open to inspection in the same language a user would write.
It is also an early example of the science-driven open-source model that later projects such as SageMath, OSCAR, Julia, and many language-specific scientific stacks would adopt: free software, an open library written in the system’s own language, public mailing lists, contributed packages, and a peer-reviewed bibliography of applications.
Finally, for the history of programming languages, GAP is a useful reminder that domain-specific languages have a place far from the mainstream of industry. A language designed to manipulate groups and characters does not need to be popular on TIOBE rankings to be load-bearing in its domain — and GAP has been quietly load-bearing for computational group theory for forty years.
Timeline
Notable Uses & Legacy
SageMath
The open-source mathematics system SageMath embeds GAP as its primary engine for computations in group theory and several adjacent areas of discrete algebra. When a Sage user manipulates a finite group, character table, or related structure, the underlying computation is typically dispatched to GAP.
OSCAR Computer Algebra System
OSCAR, developed by the German TRR 195 collaboration, is built on four cornerstone systems — GAP, Singular, Polymake, and Nemo/Hecke — orchestrated from Julia. GAP provides the group-theory and discrete-algebra backbone of the combined system.
ATLAS of Finite Group Representations
The online ATLAS project, which catalogues representations and character tables of finite simple groups and related groups, distributes much of its data in GAP-readable form, and many of the underlying computations are reproduced and extended in GAP.
Academic research in pure mathematics
GAP is widely cited in research papers in group theory, representation theory, combinatorics, coding theory, and algebraic topology. The system maintains a public bibliography of works that use GAP, which contains thousands of entries spanning decades of mathematical literature.
Teaching abstract algebra
Universities use GAP in graduate and advanced-undergraduate courses on group theory and computational algebra. Because GAP is free, scriptable, and ships with extensive libraries (the small-groups library, the character-table library, the transitive-groups library, etc.), it has become a standard teaching tool alongside textbook proofs.
Language Influence
Influenced By
Running Today
Run examples using the official Docker image:
docker pull gapsystem/gap-dockerExample usage:
docker run --rm -it gapsystem/gap-docker gap