  
  [1X2 [33X[0;0YA First Session with [5XGAP[105X[101X[1X[133X[101X
  
  [33X[0;0YThis  tutorial introduces you to the [5XGAP[105X system. It is written with users in
  mind who have just managed to start [5XGAP[105X for the first time on their computer
  and  want  to  learn  the  basic facts about [5XGAP[105X by playing around with some
  instructive  examples.  Therefore,  this  tutorial  contains  at many places
  examples consisting of several lines of input (which you should type on your
  terminal)  followed  by  the corresponding output ( which [5XGAP[105X produces as an
  answer to your input).[133X
  
  [33X[0;0YWe  encourage  you  to actually run through these examples on your computer.
  This  will  support your feeling for [5XGAP[105X as a tool, which is the leading aim
  of  this  tutorial. Do not believe any statement in it as long as you cannot
  verify it for your own version of [5XGAP[105X. You will learn to distinguish between
  small  deviations  of  the  behavior  of  your personal [5XGAP[105X from the printed
  examples and serious nonsense.[133X
  
  [33X[0;0YSince  the  printing routines of [5XGAP[105X are in some sense machine dependent you
  will  for  instance  encounter  a different layout of the printed objects in
  different  environments. But the contents should always be the same. In case
  you  encounter serious nonsense it is highly recommended that you send a bug
  report to [7Xmailto:support@gap-system.org[107X.[133X
  
  [33X[0;0YThe  examples in this tutorial should explain everything you have to know in
  order  to  be  able  to  use  [5XGAP[105X.  The  reference  manual then gives a more
  systematic   treatment  of  the  various  types  of  objects  that  [5XGAP[105X  can
  manipulate.  It seems desirable neither to start this systematic course with
  the  most  elementary (and most boring) structures, nor to confront you with
  all  the  complex  data  types  before  you  know how they are composed from
  elementary  structures.  For  this reason this tutorial wants to provide you
  with  a  basic  understanding  of [5XGAP[105X objects, on which the reference manual
  will  then  build  when  it  explains  everything in detail. So after having
  mastered  this  tutorial, you can immediately plunge into the exciting parts
  of  [5XGAP[105X  and  only read detailed information about elementary things (in the
  reference manual) when you really need them.[133X
  
  [33X[0;0YEach  chapter  of  this  tutorial  contains a section with references to the
  reference manual at the end.[133X
  
  
  [1X2.1 [33X[0;0YStarting and Leaving [5XGAP[105X[101X[1X[133X[101X
  
  [33X[0;0YIf  the  program is correctly installed then you usually start [5XGAP[105X by simply
  typing  [10Xgap[110X  at  the  prompt of your operating system followed by the [12XReturn[112X
  key, sometimes this is also called the [12XNewline[112X key.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28X$ gap[128X[104X
  [4X[32X[104X
  
  [33X[0;0Y[5XGAP[105X answers your request with its beautiful banner and then it shows its own
  prompt [10Xgap>[110X asking you for further input. (You can avoid the banner with the
  command  line  option  [10X-b[110X;  more  command  line  options  are  described  in
  Section [14X'Reference: Command Line Options'[114X.)[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X[127X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  usual  way to end a [5XGAP[105X session is to type [10Xquit;[110X at the [10Xgap>[110X prompt. Do
  not omit the semicolon![133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xquit;[127X[104X
    [4X[28X$[128X[104X
  [4X[32X[104X
  
  [33X[0;0YOn  some  systems  you  could  type  [12XCtrl-D[112X to yield the same effect. In any
  situation  [5XGAP[105X  is  ended  by  typing  [12XCtrl-C[112X twice within a second. Here as
  always,  a  combination  like  [12XCtrl-D[112X means that you have to press the [12XD[112X key
  while you hold down the [12XCtrl[112X key.[133X
  
  [33X[0;0YOn  some  systems minor changes might be necessary. This is explained in [5XGAP[105X
  installation  instructions  (see the [11XINSTALL[111X file in the [5XGAP[105X root directory,
  or the [5XGAP[105X website).[133X
  
  [33X[0;0YIn  most  places  [13Xwhitespace[113X  characters (i.e. [12XSpace[112Xs, [12XTab[112Xs and [12XReturn[112Xs) are
  insignificant  for  the  meaning of [5XGAP[105X input. Identifiers and keywords must
  however  not contain any whitespace. On the other hand, sometimes there must
  be  whitespace  around  identifiers  and keywords to separate them from each
  other  and  from  numbers. We will use whitespace to format more complicated
  commands for better readability.[133X
  
  [33X[0;0YA  [13Xcomment[113X  in  [5XGAP[105X starts with the symbol [10X#[110X and continues to the end of the
  line.  Comments  are  treated like whitespace by [5XGAP[105X. We use comments in the
  printed  examples  in  this  tutorial  to  explain certain lines of input or
  output.[133X
  
  
  [1X2.2 [33X[0;0YLoading Source Code from a File[133X[101X
  
  [33X[0;0YThe  most  convenient  way of creating larger pieces of [5XGAP[105X code is to write
  them  to  some  text file. For this purpose you can simply use your favorite
  text  editor.  You  can load such a file into [5XGAP[105X using the [2XRead[102X ([14XReference:
  Read[114X) function:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRead("../../GAPProgs/Example.g");[127X[104X
  [4X[32X[104X
  
  [33X[0;0YYou  can  either  give the full absolute path name of the source file or its
  relative path name from the current directory.[133X
  
  
  [1X2.3 [33X[0;0YThe Read Evaluate Print Loop[133X[101X
  
  [33X[0;0Y[5XGAP[105X is an interactive system. It continuously executes a read evaluate print
  loop.  Each  expression  you type at the keyboard is read by [5XGAP[105X, evaluated,
  and then the result is shown.[133X
  
  [33X[0;0YThe  interactive  nature  of  [5XGAP[105X  allows  you  to type an expression at the
  keyboard  and see its value immediately. You can define a function and apply
  it  to  arguments  to  see  how  it works. You may even write whole programs
  containing lots of functions and test them without leaving the program.[133X
  
  [33X[0;0YWhen  your program is large it will be more convenient to write it on a file
  and  then  read  that  file into [5XGAP[105X. Preparing your functions in a file has
  several  advantages. You can compose your functions more carefully in a file
  (with  your  favorite  text editor), you can correct errors without retyping
  the  whole  function and you can keep a copy for later use. Moreover you can
  write  lots of comments into the program text, which are ignored by [5XGAP[105X, but
  are  very  useful  for  human readers of your program text. [5XGAP[105X treats input
  from  a file in the same way that it treats input from the keyboard. Further
  details can be found in section [2XRead[102X ([14XReference: Read[114X).[133X
  
  [33X[0;0YA  simple  calculation  with [5XGAP[105X is as easy as one can imagine. You type the
  problem  just  after the prompt, terminate it with a semicolon and then pass
  the problem to the program with the [12XReturn[112X key. For example, to multiply the
  difference  between 9 and 7 by the sum of 5 and 6, that is to calculate [22X(9 -
  7)  *  (5 + 6)[122X, you type exactly this last sequence of symbols followed by [10X;[110X
  and [12XReturn[112X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(9 - 7) * (5 + 6);[127X[104X
    [4X[28X22[128X[104X
    [4X[25Xgap>[125X [27X[127X[104X
  [4X[32X[104X
  
  [33X[0;0YThen  [5XGAP[105X  echoes  the  result 22 on the next line and shows with the prompt
  that  it  is ready for the next problem. Henceforth, we will no longer print
  this additional prompt.[133X
  
  [33X[0;0YIf  you  make  a  mistake while typing the line, but [13Xbefore[113X typing the final
  [12XReturn[112X,  you  can  use the [12XDelete[112X key (or sometimes [12XBackspace[112X key) to delete
  the  last  typed character. You can also move the cursor back and forward in
  the  line with [12XCtrl-B[112X and [12XCtrl-F[112X and insert or delete characters anywhere in
  the   line.   The   line   editing   commands   are   fully   described   in
  section [14X'Reference: Line Editing'[114X.[133X
  
  [33X[0;0YIf  you did omit the semicolon at the end of the line but have already typed
  [12XReturn[112X,  then  [5XGAP[105X has read everything you typed, but does not know that the
  command  is complete. The program is waiting for further input and indicates
  this  with  a  partial prompt [10X>[110X. This problem is solved by simply typing the
  missing  semicolon on the next line of input. Then the result is printed and
  the normal prompt returns.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(9 - 7) * (5 + 6)[127X[104X
    [4X[25X>[125X [27X;[127X[104X
    [4X[28X22[128X[104X
  [4X[32X[104X
  
  [33X[0;0YSo the input can consist of several lines, and [5XGAP[105X prints a partial prompt [10X>[110X
  in  each  input line except the first, until the command is completed with a
  semicolon. ([5XGAP[105X may already evaluate part of the input when [12XReturn[112X is typed,
  so  for  long  calculations it might take some time until the partial prompt
  appears.) Whenever you see the partial prompt and you cannot decide what [5XGAP[105X
  is  still  waiting  for,  then  you have to type semicolons until the normal
  prompt  returns.  In every situation the exact meaning of the prompt [10Xgap>[110X is
  that the program is waiting for a new problem.[133X
  
  [33X[0;0YBut even if you mistyped the command more seriously, you do not have to type
  it  all  again. Suppose you mistyped or forgot the last closing parenthesis.
  Then  your  command  is  syntactically  incorrect  and  [5XGAP[105X  will notice it,
  incapable of computing the desired result.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(9 - 7) * (5 + 6;[127X[104X
    [4X[28XSyntax error: ) expected[128X[104X
    [4X[28X(9 - 7) * (5 + 6;[128X[104X
    [4X[28X                ^[128X[104X
  [4X[32X[104X
  
  [33X[0;0YInstead  of the result an error message occurs indicating the place where an
  unexpected  symbol  occurred  with  an  arrow sign [10X^[110X under it. As a computer
  program  cannot  know what your intentions really were, this is only a hint.
  But  in  this  case  [5XGAP[105X is right by claiming that there should be a closing
  parenthesis  before  the  semicolon.  Now you can type [12XCtrl-P[112X to recover the
  last  line  of input. It will be written after the prompt with the cursor in
  the  first  position. Type [12XCtrl-E[112X to take the cursor to the end of the line,
  then  [12XCtrl-B[112X to move the cursor one character back. The cursor is now on the
  position of the semicolon. Enter the missing parenthesis by simply typing [10X)[110X.
  Now  the line is correct and may be passed to [5XGAP[105X by hitting the [12XReturn[112X key.
  Note  that  for  this action it is not necessary to move the cursor past the
  last character of the input line.[133X
  
  [33X[0;0YEach  line  of  commands  you type is sent to [5XGAP[105X for evaluation by pressing
  [12XReturn[112X  regardless  of  the  position of the cursor in that line. We will no
  longer mention the [12XReturn[112X key from now on.[133X
  
  [33X[0;0YSometimes  a  syntax  error  will  cause  [5XGAP[105X to enter a [13Xbreak loop[113X. This is
  indicated  by  the special prompt [10Xbrk>[110X. If another syntax error occurs while
  [5XGAP[105X  is  in  a break loop, the prompt will change to [10Xbrk_02>[110X, [10Xbrk_03>[110X and so
  on.  You  can leave the current break loop and exit to the next outer one by
  either  typing [10Xquit;[110X or by hitting [12XCtrl-D[112X. Eventually [5XGAP[105X will return to its
  normal state and show its normal prompt [10Xgap>[110X again.[133X
  
  
  [1X2.4 [33X[0;0YConstants and Operators[133X[101X
  
  [33X[0;0YIn  an  expression  like  [10X(9 - 7) * (5 + 6)[110X the constants [10X5[110X, [10X6[110X, [10X7[110X, and [10X9[110X are
  being composed by the operators [10X+[110X, [10X*[110X and [10X-[110X to result in a new value.[133X
  
  [33X[0;0YThere   are  three  kinds  of  operators  in  [5XGAP[105X,  arithmetical  operators,
  comparison  operators,  and logical operators. You have already seen that it
  is  possible to form the sum, the difference, and the product of two integer
  values.  There  are  some  more  operators applicable to integers in [5XGAP[105X. Of
  course  integers  may  be  divided  by  each  other,  possibly  resulting in
  noninteger rational values.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X12345/25;[127X[104X
    [4X[28X2469/5[128X[104X
  [4X[32X[104X
  
  [33X[0;0YNote that the numerator and denominator are divided by their greatest common
  divisor   and  that  the  result  is  uniquely  represented  as  a  division
  instruction.[133X
  
  [33X[0;0YThe next self-explanatory example demonstrates negative numbers.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X-3; 17 - 23;[127X[104X
    [4X[28X-3[128X[104X
    [4X[28X-6[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  exponentiation  operator  is written as [10X^[110X. This operation in particular
  might  lead  to  very  large  numbers.  This is no problem for [5XGAP[105X as it can
  handle numbers of (almost) any size.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X3^132;[127X[104X
    [4X[28X955004950796825236893190701774414011919935138974343129836853841[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe [9Xmod[109X operator allows you to compute one value modulo another.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X17 mod 3;[127X[104X
    [4X[28X2[128X[104X
  [4X[32X[104X
  
  [33X[0;0YNote  that  there  must be whitespace around the keyword [9Xmod[109X in this example
  since  [10X17mod3[110X  or  [10X17mod[110X would be interpreted as identifiers. The whitespace
  around  operators  that do not consist of letters, e.g., the operators [10X*[110X and
  [10X-[110X, is not necessary.[133X
  
  [33X[0;0Y[5XGAP[105X  knows  a  precedence  between  operators  that  may  be  overridden  by
  parentheses.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(9 - 7) * 5 = 9 - 7  * 5;[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [33X[0;0YBesides  these arithmetical operators there are comparison operators in [5XGAP[105X.
  A  comparison  results in a [13Xboolean value[113X which is another kind of constant.
  The  comparison  operators  [10X=[110X,  [10X<>[110X,  [10X<[110X,  [10X<=[110X,  [10X>[110X  and  [10X>=[110X, test for equality,
  inequality,  less than, less than or equal, greater than and greater than or
  equal, respectively.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X10^5 < 10^4;[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  boolean values [9Xtrue[109X and [9Xfalse[109X can be manipulated via logical operators,
  i. e., the unary operator [9Xnot[109X and the binary operators [9Xand[109X and [9Xor[109X. Of course
  boolean values can be compared, too.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xnot true; true and false; true or false;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[28Xfalse[128X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27X10 > 0 and 10 < 100;[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [33X[0;0YAnother  important  type  of  constants  in  [5XGAP[105X  are [13Xpermutations[113X. They are
  written in cycle notation and they can be multiplied.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(1,2,3);[127X[104X
    [4X[28X(1,2,3)[128X[104X
    [4X[25Xgap>[125X [27X(1,2,3) * (1,2);[127X[104X
    [4X[28X(2,3)[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  inverse  of  the permutation [10X(1,2,3)[110X is denoted by [10X(1,2,3)^-1[110X. Moreover
  the  caret  operator  [10X^[110X  is  used  to determine the image of a point under a
  permutation and to conjugate one permutation by another.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(1,2,3)^-1;[127X[104X
    [4X[28X(1,3,2)[128X[104X
    [4X[25Xgap>[125X [27X2^(1,2,3);[127X[104X
    [4X[28X3[128X[104X
    [4X[25Xgap>[125X [27X(1,2,3)^(1,2);[127X[104X
    [4X[28X(1,3,2)[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  various  other constants that [5XGAP[105X can deal with will be introduced when
  they are used, for example there are elements of finite fields such as [10XZ(8)[110X,
  and complex roots of unity such as [10XE(4)[110X.[133X
  
  [33X[0;0YThe last type of constants we want to mention here are the [13Xcharacters[113X, which
  are  simply  objects  in  [5XGAP[105X  that  represent arbitrary characters from the
  character  set of the operating system. Character literals can be entered in
  [5XGAP[105X by enclosing the character in [13Xsinglequotes[113X [10X'[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X'a';[127X[104X
    [4X[28X'a'[128X[104X
    [4X[25Xgap>[125X [27X'*';[127X[104X
    [4X[28X'*'[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThere  are no operators defined for characters except that characters can be
  compared.[133X
  
  [33X[0;0YIn this section you have seen that values may be preceded by unary operators
  and  combined  by  binary  operators  placed between the operands. There are
  rules  for  precedence  which may be overridden by parentheses. A comparison
  results  in  a  boolean  value.  Boolean  values  are  combined  via logical
  operators.  Moreover  you  have  seen  that [5XGAP[105X handles numbers of arbitrary
  size.  Numbers  and  boolean  values are constants. There are other types of
  constants  in [5XGAP[105X like permutations. You are now in a position to use [5XGAP[105X as
  a simple desktop calculator.[133X
  
  
  [1X2.5 [33X[0;0YVariables versus Objects[133X[101X
  
  [33X[0;0YThe  constants  described  in  the  last  section  are  specified by certain
  combinations  of digits and minus signs (in the case of integers) or digits,
  commas  and  parentheses  (in  the case of permutations). These sequences of
  characters always have the same meaning to [5XGAP[105X. On the other hand, there are
  [13Xvariables[113X, specified by a sequence of letters and digits (including at least
  one letter), and their meaning depends on what has been assigned to them. An
  [13Xassignment[113X  is  done  by  a  [5XGAP[105X  command  [10X[3Xsequence_of_letters_and_digits[103X[10X :=
  [3Xmeaning[103X[10X[110X,  where  the sequence on the left hand side is called the [13Xidentifier[113X
  of  the  variable  and  it serves as its name. The meaning on the right hand
  side  can be a constant like an integer or a permutation, but it can also be
  almost  any  other  [5XGAP[105X  object. From now on, we will use the term [13Xobject[113X to
  denote something that can be assigned to a variable.[133X
  
  [33X[0;0YThere  must  be  no  whitespace  between  the  [10X:[110X and the [10X=[110X in the assignment
  operator.  Also  do  not  confuse  the  assignment  operator with the single
  equality sign [10X=[110X which in [5XGAP[105X is only used for the test of equality.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa:= (9 - 7) * (5 + 6);[127X[104X
    [4X[28X22[128X[104X
    [4X[25Xgap>[125X [27Xa;[127X[104X
    [4X[28X22[128X[104X
    [4X[25Xgap>[125X [27Xa * (a + 1);[127X[104X
    [4X[28X506[128X[104X
    [4X[25Xgap>[125X [27Xa = 10;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xa:= 10;[127X[104X
    [4X[28X10[128X[104X
    [4X[25Xgap>[125X [27Xa * (a + 1);[127X[104X
    [4X[28X110[128X[104X
  [4X[32X[104X
  
  [33X[0;0YAfter  an  assignment  the  assigned  object is echoed on the next line. The
  printing  of  the  object  of  a statement may be in every case prevented by
  typing a double semicolon.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw:= 2;;[127X[104X
  [4X[32X[104X
  
  [33X[0;0YAfter  the  assignment  the  variable evaluates to that object if evaluated.
  Thus  it  is possible to refer to that object by the name of the variable in
  any situation.[133X
  
  [33X[0;0YThis is in fact the whole secret of an assignment. An identifier is bound to
  an  object  and  from  this moment points to that object. Nothing more. This
  binding  is changed by the next assignment to that identifier. An identifier
  does not denote a block of memory as in some other programming languages. It
  simply  points to an object, which has been given its place in memory by the
  [5XGAP[105X  storage  manager.  This place may change during a [5XGAP[105X session, but that
  doesn't bother the identifier. [13XThe identifier points to the object, not to a
  place in the memory.[113X[133X
  
  [33X[0;0YFor the same reason it is not the identifier that has a type but the object.
  This  means on the other hand that the identifier [10Xa[110X which now is bound to an
  integer  object may in the same session point to any other object regardless
  of its type.[133X
  
  [33X[0;0YIdentifiers  may  be sequences of letters and digits containing at least one
  letter.  For example [10Xabc[110X and [10Xa0bc1[110X are valid identifiers. But also [10X123a[110X is a
  valid  identifier  as  it  cannot  be  confused  with  any number. Just [10X1234[110X
  indicates  the  number  1234  and  cannot  be at the same time the name of a
  variable.[133X
  
  [33X[0;0YSince  [5XGAP[105X  distinguishes  upper  and  lower  case,  [10Xa1[110X and [10XA1[110X are different
  identifiers. Keywords such as [9Xquit[109X must not be used as identifiers. You will
  see more keywords in the following sections.[133X
  
  [33X[0;0YIn  the  remaining part of this manual we will ignore the difference between
  variables,  their names (identifiers), and the objects they point to. It may
  be  useful  to  think  from time to time about what is really meant by terms
  such as [21Xthe integer [10Xw[110X[121X.[133X
  
  [33X[0;0YThere  are  some predefined variables coming with [5XGAP[105X. Many of them you will
  find  in  the  remaining  chapters  of this manual, since functions are also
  referred to via identifiers.[133X
  
  [33X[0;0YYou  can get an overview of [13Xall[113X [5XGAP[105X variables by entering [10XNamesGVars()[110X. Many
  of  these  are  predefined.  If you are interested in the variables you have
  defined yourself in the current [5XGAP[105X session, you can enter [10XNamesUserGVars()[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XNamesUserGVars();[127X[104X
    [4X[28X[ "a", "w" ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YThis  seems  to  be the right place to state the following rule: The name of
  every  global variable in the [5XGAP[105X library starts with a [13Xcapital letter[113X. Thus
  if you choose only names starting with a small letter for your own variables
  you  will  not attempt to overwrite any predefined variable. (Note that most
  of the predefined variables are read-only, and trying to change their values
  will result in an error message.)[133X
  
  [33X[0;0YThere are some further interesting variables one of which will be introduced
  now.[133X
  
  [33X[0;0YWhenever  [5XGAP[105X  returns an object by printing it on the next line this object
  is assigned to the variable [10Xlast[110X. So if you computed[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X(9 - 7) * (5 + 6);[127X[104X
    [4X[28X22[128X[104X
  [4X[32X[104X
  
  [33X[0;0Yand  forgot  to assign the object to the variable [10Xa[110X for further use, you can
  still do it by the following assignment.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa:= last;[127X[104X
    [4X[28X22[128X[104X
  [4X[32X[104X
  
  [33X[0;0YMoreover there are variables [10Xlast2[110X and [10Xlast3[110X, you can guess their values.[133X
  
  [33X[0;0YIn  this  section  you  have  seen how to assign objects to variables. These
  objects  can  later  be  accessed  through  the  name  of  the variable, its
  identifier.  You  have  also  encountered  the  useful  concept  of the [10Xlast[110X
  variables  storing  the latest returned objects. And you have learned that a
  double semicolon prevents the result of a statement from being printed.[133X
  
  
  [1X2.6 [33X[0;0YObjects vs. Elements[133X[101X
  
  [33X[0;0YIn  the last section we mentioned that every object is given a certain place
  in  memory by the [5XGAP[105X storage manager (although that place may change in the
  course  of  a  [5XGAP[105X  session).  In this sense, objects at different places in
  memory  are  never equal, and if the object pointed to by the variable [10Xa[110X (to
  be  more  precise,  the  variable  with identifier [10Xa[110X) is equal to the object
  pointed  to  by  the variable [10Xb[110X, then we should better say that they are not
  only   equal   but  [13Xidentical[113X.  [5XGAP[105X  provides  the  function  [2XIsIdenticalObj[102X
  ([14XReference: IsIdenticalObj[114X) to test whether this is the case.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa:= (1,2);; IsIdenticalObj( a, a );[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xb:= (1,2);; IsIdenticalObj( a, b );[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xb:= a;; IsIdenticalObj( a, b );[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [33X[0;0YAs  the above example indicates, [5XGAP[105X objects [3Xa[103X and [3Xb[103X can be unequal although
  they  are  equal from a mathematical point of view, i.e., although we should
  have  [3Xa[103X  =  [3Xb[103X.  It  may  be that the objects [3Xa[103X and [3Xb[103X are stored in different
  places  in memory, or it may be that we have an equivalence relation defined
  on  the  set  of  objects under which [3Xa[103X and [3Xb[103X belong to the same equivalence
  class.  For  example,  if  [22X[3Xa[103X  = x^3[122X and [22X[3Xb[103X = x^{-5}[122X are words in the finitely
  presented group [22X⟨ x ∣ x^2 = 1 ⟩[122X, we would have [3Xa[103X = [3Xb[103X in that group.[133X
  
  [33X[0;0Y[5XGAP[105X uses the equality operator [10X=[110X to denote such a mathematical equality, [13Xnot[113X
  the  identity of objects. Hence we often have [10X[3Xa[103X[10X = [3Xb[103X[10X[110X although [10XIsIdenticalObj(
  [3Xa[103X[10X, [3Xb[103X[10X ) = false[110X. The operator [10X=[110X defines an equivalence relation on the set of
  all [5XGAP[105X objects, and we call the corresponding equivalence classes [13Xelements[113X.
  Phrasing  it differently, the same element may be represented by various [5XGAP[105X
  objects.[133X
  
  [33X[0;0YNon-trivial  examples  of elements that are represented by different objects
  (objects  that  really  look  different,  not ones that are merely stored in
  different  memory  places)  will  occur  only  when  we  will be considering
  composite objects such as lists or domains.[133X
  
  
  [1X2.7 [33X[0;0YAbout Functions[133X[101X
  
  [33X[0;0YA  program  written  in the [5XGAP[105X language is called a [13Xfunction[113X. Functions are
  special  [5XGAP[105X  objects. Most of them behave like mathematical functions. They
  are  applied to objects and will return a new object depending on the input.
  The  function  [2XFactorial[102X ([14XReference: Factorial[114X), for example, can be applied
  to an integer and will return the factorial of this integer.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XFactorial(17);[127X[104X
    [4X[28X355687428096000[128X[104X
  [4X[32X[104X
  
  [33X[0;0YApplying a function to arguments means to write the arguments in parentheses
  following  the  function.  Several arguments are separated by commas, as for
  the function [2XGcd[102X ([14XReference: Gcd[114X) which computes the greatest common divisor
  of two integers.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XGcd(1234, 5678);[127X[104X
    [4X[28X2[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThere  are  other  functions that do not return an object but only produce a
  side  effect,  for  example changing one of their arguments. These functions
  are  sometimes  called  procedures. The function [2XPrint[102X ([14XReference: Print[114X) is
  only called for the side effect of printing something on the screen.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XPrint(1234, "\n");[127X[104X
    [4X[28X1234[128X[104X
  [4X[32X[104X
  
  [33X[0;0YIn order to be able to compose arbitrary text with [2XPrint[102X ([14XReference: Print[114X),
  this  function  itself will not produce a line break after printing. Thus we
  had another newline character [10X"\n"[110X printed to start a new line.[133X
  
  [33X[0;0YSome functions will both change an argument and return an object such as the
  function  [2XSortex[102X  ([14XReference:  Sortex[114X)  that  sorts  a  list and returns the
  permutation  of  the  list  elements  that  it  has  performed. You will not
  understand  right  now  what it means to change an object. We will return to
  this subject several times in the next sections.[133X
  
  [33X[0;0YA  comfortable  way to define a function yourself is the [13Xmaps-to[113X operator [10X->[110X
  consisting  of  a  minus  sign and a greater sign with no whitespace between
  them.  The  function [10Xcubed[110X which maps a number to its cube is defined on the
  following line.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xcubed:= x -> x^3;[127X[104X
    [4X[28Xfunction( x ) ... end[128X[104X
  [4X[32X[104X
  
  [33X[0;0YAfter the function has been defined, it can now be applied.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xcubed(5);[127X[104X
    [4X[28X125[128X[104X
  [4X[32X[104X
  
  [33X[0;0YMore complicated functions, especially functions with more than one argument
  cannot  be  defined  in  this  way.  You  will see how to write your own [5XGAP[105X
  functions in Section [14X4.1[114X.[133X
  
  [33X[0;0YIn this section you have seen [5XGAP[105X objects of type function. You have learned
  how  to apply a function to arguments. This yields as result a new object or
  a  side  effect.  A  side  effect  may  change  an argument of the function.
  Moreover  you  have  seen  an  easy way to define a function in [5XGAP[105X with the
  maps-to operator.[133X
  
  
  [1X2.8 [33X[0;0YHelp[133X[101X
  
  [33X[0;0YThe  content  of  the  [5XGAP[105X  manuals is also available as on-line help. A [5XGAP[105X
  session  loads  a  long  list  of index entries. This typically contains all
  chapter  and  section headers, all names of documented functions, operations
  and so on, as well as some explicit index entries defined in the manuals.[133X
  
  [33X[0;0YThe format of a query is as follows.[133X
  
  [33X[0;0Y[10X?[[3Xbook[103X[10X:][?][3Xtopic[103X[10X[110X[133X
  
  [33X[0;0YA  simple  example  would  be to type [10X?help[110X at the [5XGAP[105X prompt. If there is a
  single section with index entry [3Xtopic[103X then this is displayed directly.[133X
  
  [33X[0;0YIf there are several matches you get an overview like in the example below.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X?sets[127X[104X
    [4X[28XHelp: several entries match this topic - type ?2 to get match [2][128X[104X
    [4X[28X[128X[104X
    [4X[28X[1] Tutorial: Sets[128X[104X
    [4X[28X[2] Reference: Sets[128X[104X
    [4X[28X[3] Reference: sets[128X[104X
    [4X[28X[4] Reference: Sets of Subgroups[128X[104X
    [4X[28X[5] Reference: setstabilizer[128X[104X
  [4X[32X[104X
  
  [33X[0;0Y[5XGAP[105X's manuals consist of several [13Xbooks[113X, which are indicated before the colon
  in  the  list above. A help query can be restricted to one book by using the
  optional [3Xbook[103X: part. For example [10X?tut : sets[110X will display the first of these
  help  sections.  More  precisely,  the  parts  of  the string [3Xbook[103X which are
  separated by white space are interpreted as beginnings of the first words in
  the  name  of  the  book.  Try [10X?books[110X to see the list of available books and
  their names.[133X
  
  [33X[0;0YThe   search  for  a  matching  [3Xtopic[103X  (and  optional  [3Xbook[103X)  is  done  [13Xcase
  insensitively[113X.  If  there  is  another  [10X?[110X before the [3Xtopic[103X, then a [13Xsubstring
  search[113X  for  [3Xtopic[103X is performed on all index entries. Otherwise the parts of
  [3Xtopic[103X which are separated by white space are considered as [13Xbeginnings of the
  first words[113X in an index entry.[133X
  
  [33X[0;0YWhite space is normalized in the search string (and the index entries).[133X
  
  [33X[0;0Y[13XExamples.[113X  All  the  following  queries lead to the chapter of the reference
  manual which explains the use of [5XGAP[105X's help system in more detail.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27X?Reference: The Help System[127X[104X
    [4X[25Xgap>[125X [27X?  REF : t h s[127X[104X
    [4X[25Xgap>[125X [27X?ref:?  help   system[127X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  query  [10X??sets[110X  shows all help sections in all books whose index entries
  contain the substring [10Xsets[110X.[133X
  
  [33X[0;0YAs  mentioned  in the example above a complete list of commands for the help
  system  is  available  in  Section [10X?Ref:  The  Help  System[110X of the reference
  manual.  In  particular  there  are  commands  to  browse  through  the help
  sections,  see [10X?Ref:  Browsing  through  the  Sections[110X and there is a way to
  influence   the   way   [13Xhow[113X  the  help  sections  are  displayed,  see [10X?Ref:
  SetHelpViewer[110X.  For  example  you  can  use an external pager program, a Web
  browser, [10Xdvi[110X-previewer and/or [10Xpdf[110X-viewer for reading [5XGAP[105X's online help.[133X
  
  
  [1X2.9 [33X[0;0YFurther Information introducing the System[133X[101X
  
  [33X[0;0YFor  large  amounts of input data, it might be advisable to write your input
  first  into a file, and then read this into [5XGAP[105X; see [2XRead[102X ([14XReference: Read[114X),
  [2XEdit[102X ([14XReference: Edit[114X) for this.[133X
  
  [33X[0;0YThe definition of the [5XGAP[105X syntax can be looked up in Chapter [14X'Reference: The
  Programming Language'[114X. A complete list of command line editing facilities is
  found  in  Section [14X'Reference: Line Editing'[114X. The break loop is described in
  Section [14X'Reference: Break Loops'[114X.[133X
  
  [33X[0;0YOperators  are explained in more detail in Sections [14X'Reference: Expressions'[114X
  and  [14X'Reference:  Comparisons'[114X. You will find more information about boolean
  values  in  Chapters [14X'Reference:  Booleans'[114X  and [14X'Reference: Boolean Lists'[114X.
  Permutations   are   described   in  Chapter [14X'Reference:  Permutations'[114X  and
  characters in Chapter [14X'Reference: Strings and Characters'[114X.[133X
  
  [33X[0;0YVariables  and  assignments  are  described  in  more  detail in [14X'Reference:
  Variables'[114X  and  [14X'Reference:  Assignments'[114X.  A  complete list of keywords is
  contained in [14X'Reference: Keywords'[114X.[133X
  
  [33X[0;0YMore   about   functions   can   be  found  in [14X'Reference:  Function  Calls'[114X
  and [14X'Reference: Procedure Calls'[114X.[133X
  
