Goal
Launch gap, evaluate an expression, read what the prompt is telling you,
recover from a mistake, and quit... all without feeling stranded.
Concept
GAP is a read-eval-print loop. You type an expression terminated by ;, it
evaluates and shows the result. The whole session is one long conversation with
a live interpreter that remembers everything you've defined until you quit.
Two things trip people up on day one: the statement terminator (; vs
;;) and the break loop (brk>), which looks like a crash but isn't.
Commands to try
Launch it from your own terminal:
gap
You'll get a banner (version, loaded packages, memory) and then the gap>
prompt. The banner is worth one glance: note the version number and which
packages auto-loaded. We'll care later when something needs LoadPackage.
Now type these one at a time. After each, look at the result before moving on.
2 + 2;
Expect 4. The ; ends the statement; GAP prints the value.
2 + 2;;
Nothing prints. The double semicolon ;; evaluates but suppresses output.
You'll want this later when a computation returns a 50,000-element list you
don't want scrolling past. Mentally file it; don't dwell.
Factorial(20);
A big integer, exact. GAP has arbitrary-precision integers natively - no overflow, no floats sneaking in. This matters: group orders and other counts get large and stay exact.
last;
last is the previous result. GAP also keeps last2 and last3. Cheap way to
reuse a value you forgot to name.
x := 7;
Assignment is :=, not =. (= is for comparison - it tests equality and returns
true/false.) This is the single most common day-one error. Try the wrong
one deliberately so you recognize the message:
x = 8;
Returns false. It compared; it did not assign. x is still 7. You can check this for yourself:
x;
The break loop - meet it on purpose
Type something genuinely broken:
1/0;
You'll drop into a brk> prompt with an error about division. This is not a
crash. GAP has paused inside an error handler so you could inspect state. You
get out with:
quit;
That leaves the break loop and returns you to the normal gap> prompt. (Inside
the break loop quit; means "leave the break loop"; at the top level it means
"leave GAP." Same word, level-dependent. So get that straight now so the next part
doesn't surprise you.)
Getting help
?Factorial
Opens the manual entry. ? followed by a topic searches the help system;
??topic does a broader full-text search. Arrow keys scroll, q quits the
pager back to the prompt.
Predict-then-check
Before you type the next line, commit to an answer out loud (or in this chat):
Order(SymmetricGroup(5));
What integer do you expect? Write it down first, then evaluate. (Hint: it's a factorial you already computed a smaller cousin of above.) Write down your prediction and what GAP returned:
Exit
quit;
At the top-level gap> prompt this ends the session and returns you to your
shell. If GAP ever asks you to confirm or seems stuck in a pager, q then
quit;.
Exercise
- Open a fresh
gap. - Without using
Factorial, get GAP to tell you the order of the symmetric group on 7 points. - Define a variable
gholding that group, then ask for itsSize. NoticeOrderandSizeboth work here. When we hit large groups we'll see why GAP distinguishes them. - Trigger the break loop on purpose with any error, then escape it cleanly.
- Quit.
Report back: the order of S₇, and one thing that behaved differently from what you expected.
Pitfalls
:=assigns,=compares. Burn this in now.;prints,;;is silent. Forgetting;entirely makes GAP wait for more input (you'll see a>continuation prompt). Just type;and Enter.quit;is context-dependent: it leaves the break loop or leaves GAP depending on which prompt you're at (brk>vsgap>).- The banner's package list is information, not noise. Glance at it.