<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %W  introduc.tex              GAP documentation             Thomas Breuer -->
<!-- %W                                                         & Frank Celler -->
<!-- %W                                                     & Martin Schönert -->
<!-- %W                                                       & Heiko Theißen -->
<!-- %% -->
<!-- %H  @(#)<M>Id: introduc.tex,v 4.32 2005/05/05 13:22:50 gap Exp </M> -->
<!-- %% -->
<!-- %Y  Copyright 1997,  Lehrstuhl D für Mathematik,  RWTH Aachen,   Germany -->
<!-- %% -->
<!-- %%  This file contains a tutorial introduction to GAP. -->
<!-- %% -->
<P/>

<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Chapter Label="A First Session with GAP">
<Heading>A First Session with &GAP;</Heading>
<P/>
This tutorial introduces you to  the &GAP;  system.  It is written  with
users in mind who have just managed to start &GAP; for the first time on
their computer and want to learn the basic facts  about &GAP; 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 &GAP; produces as an answer to your input).
<P/>
We encourage you to actually  run through these examples on your
computer. This will support your  feeling for &GAP;  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  &GAP;. You will
learn to distinguish  between small  deviations of  the behavior of  your
personal &GAP; from the printed examples and serious nonsense.
<P/>
Since the printing routines of &GAP; 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 <Email>support@gap-system.org</Email>.
<P/>
The  examples in this  tutorial should explain  everything you have to
know in order  to be able  to use &GAP;.   The reference  manual then
gives a more systematic treatment of the various types of objects that
&GAP; 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 &GAP; 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 &GAP;
and  only read detailed  information about  elementary things (in  the
reference manual) when you really need them.
<P/>
Each chapter of this tutorial contains a section with references to the 
reference manual at the end.
<P/>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Starting and Leaving GAP">
<Heading>Starting and Leaving &GAP;</Heading>
<P/>
<Index Key="starting GAP">starting &GAP;</Index>
<Index Key="leaving GAP">leaving &GAP;</Index>
<Index Key="quit"><K>quit</K></Index>
If the  program is correctly  installed then you usually start &GAP; by
simply
typing  <C>gap</C> at  the  prompt of your   operating system followed by  the
<B>Return</B> key, sometimes this is also called the <B>Newline</B> key.
<P/>
<Log><![CDATA[
$ gap
]]></Log>
<P/>
&GAP; answers your request with its beautiful banner and then it shows
its own prompt <C>gap></C> asking you for further input.
(You can avoid the banner with the command line option <C>-b</C>;
more command line options are described in
Section&nbsp;<Ref Sect="Command Line Options" BookName="ref"/>.)
<P/>
<Example><![CDATA[
gap> 
]]></Example>
<P/>
The usual  way to end a  &GAP; session is  to type <C>quit;</C> at the <C>gap></C>
prompt. Do not omit the semicolon!
<P/>
<Log><![CDATA[
gap> quit;
$ 
]]></Log>
<P/>
On some systems you could type <B>Ctrl-D</B> to yield the same effect.
In any situation &GAP; is ended by typing <B>Ctrl-C</B> twice within a
second.  Here as always, a combination like <B>Ctrl-D</B> means that you have
to press the <B>D</B> key while you hold down the <B>Ctrl</B> key.
<P/>
On some systems minor changes might be
necessary. This is explained in &GAP; installation instructions (see the 
<F>INSTALL</F> file in the &GAP; root directory, or the &GAP; website).
<!-- TODO: put URL -->
<P/>
<Index>whitespace</Index>
In most places <E>whitespace</E> characters (i.e. <B>Space</B>s, <B>Tab</B>s
and <B>Return</B>s) are insignificant for the meaning of &GAP; 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.
<P/>
<Index>comments</Index>
A <E>comment</E> in  &GAP; starts with the  symbol <C>#</C> and continues to  the
end of the line. Comments are  treated like whitespace  by &GAP;. We use
comments in   the printed examples  in this  tutorial to  explain certain
lines of input or output.
<!-- % These comments will be printed in a normal font for better readability, -->
<!-- % they start with the symbol&nbsp;#. -->
</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Loading Source Code from a File">
<Heading>Loading Source Code from a File</Heading>

<Index>loading source code from a file</Index>
<Index>reading source code from a file</Index>
<Index Key="Read"><C>Read</C></Index>
The most convenient way of creating larger pieces of &GAP; 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 &GAP; using the
<Ref Func="Read" BookName="ref"/> function:
<P/>
<Log><![CDATA[
gap> Read("../../GAPProgs/Example.g");
]]></Log>
<P/>
You can either give the full absolute path name of the source file or
its relative path name from the current directory.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="The Read Evaluate Print Loop">
<Heading>The Read Evaluate Print Loop</Heading>

<Index>read evaluate print loop</Index>
&GAP;  is  an   interactive   system.    It  continuously   executes   a
read evaluate print loop.  Each  expression you type  at the  keyboard is
read by &GAP;, evaluated, and then the result is shown.
<P/>
The interactive nature of &GAP; 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.
<P/>
When  your program is large it  will be more  convenient to write it on a
file and then read that file  into &GAP;. 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 &GAP;, but are   very useful for  human readers of
your program text. &GAP; treats  input from a  file in the same way that
it treats input from the keyboard. Further details can be found in
section <Ref Func="Read" BookName="ref"/>.
<P/>
A simple calculation with &GAP; 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 <B>Return</B> key.  For  example, to
multiply the difference between 9 and 7 by the sum of 5 and 6, that is to
calculate  <M>(9 - 7) * (5 + 6)</M>, you type exactly this  last sequence  of
symbols followed by <C>;</C> and <B>Return</B>.
<P/>
<Example><![CDATA[
gap> (9 - 7) * (5 + 6);
22
gap> 
]]></Example>
<P/>
Then &GAP; 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.
<P/>
<Index>line editing</Index>
If you make a mistake while typing the line,
but <E>before</E> typing the final <B>Return</B>,
you can use the <B>Delete</B> key (or sometimes <B>Backspace</B> key)
to delete the last typed character.
You can also move the cursor back and forward in the line with <B>Ctrl-B</B>
and <B>Ctrl-F</B> and insert or delete characters anywhere in the line.
The line editing commands are fully described
in section&nbsp;<Ref Sect="Line Editing" BookName="ref"/>.
<P/>
If you did omit the semicolon at the end of  the line but have already
typed <B>Return</B>, then &GAP; 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 <C>></C>.   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.
<P/>
<Example><![CDATA[
gap> (9 - 7) * (5 + 6)
> ;
22
]]></Example>
<P/>
So the input can consist of several lines, and &GAP; prints a partial
prompt <C>></C> in each input line except the first, until the command is
completed with a semicolon.
(&GAP; may already evaluate part of the input when <B>Return</B> 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 &GAP; is
still  waiting for, then  you have  to type  semicolons  until the normal
prompt returns.
In  every situation the exact meaning of the prompt <C>gap></C> is that the
program is waiting for a new problem.
<P/>
But 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 &GAP; will
notice it, incapable of computing the desired result.
<P/>
<Log><![CDATA[
gap> (9 - 7) * (5 + 6;
Syntax error: ) expected
(9 - 7) * (5 + 6;
                ^
]]></Log>
<P/>
<Index>line editing</Index>
Instead of the result an error message  occurs indicating the place where
an unexpected  symbol occurred with   an arrow sign  <C>^</C>  under it.  As a
computer program  cannot know what your  intentions really were,  this is
only  a hint. But in this  case &GAP;  is  right by  claiming that there
should be a closing  parenthesis before the  semicolon. Now you  can type
<B>Ctrl-P</B> to recover the last line of input. It will be written after the
prompt with the cursor in the first  position. Type <B>Ctrl-E</B> to take the
cursor to the end of the line, then <B>Ctrl-B</B> to move the cursor one
character back. The cursor is now on the position of the semicolon. Enter
the missing parenthesis by simply typing <C>)</C>. Now the line is correct and
may be passed to &GAP;  by hitting the <B>Return</B>  key. Note that for this
action it is not necessary to move the cursor  past the last character of
the input line.
<P/>
Each line  of commands  you  type is sent to    &GAP; for evaluation  by
pressing <B>Return</B> regardless of the position of  the cursor in that line.
We will no longer mention the <B>Return</B> key from now on.
<P/>
<Index>break loops</Index>
Sometimes a syntax error will cause &GAP; to enter a <E>break loop</E>.  This
is indicated by the special prompt <C>brk></C>. If another syntax error occurs
while  &GAP; is in  a break loop, the prompt  will  change to <C>brk_02></C>,
<C>brk_03></C> and so on. You can leave the current break loop and exit to the
next outer one by either typing <C>quit;</C> or by hitting <B>Ctrl-D</B>.
Eventually &GAP; will return to its normal state and show its normal
prompt <C>gap></C> again.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Constants and Operators">
<Heading>Constants and Operators</Heading>

<Index>constants</Index><Index>operators</Index>
In an  expression like <C>(9  - 7) * (5 +  6)</C> the constants <C>5</C>, <C>6</C>, <C>7</C>,
and <C>9</C> are being composed by the operators <C>+</C>, <C>*</C> and <C>-</C> to result in
a new value.
<P/>
There are  three kinds  of operators in  &GAP;, 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
&GAP;.   Of  course integers  may  be divided  by  each other,  possibly
resulting in noninteger rational values.
<P/>
<Example><![CDATA[
gap> 12345/25;
2469/5
]]></Example>
<P/>
Note  that  the numerator and denominator  are divided by their  greatest
common divisor  and that the result is uniquely represented as a division
instruction.
<P/>
The next self-explanatory example demonstrates negative numbers.
<P/>
<Example><![CDATA[
gap> -3; 17 - 23;
-3
-6
]]></Example>
<P/>
The exponentiation   operator  is  written  as  <C>^</C>. This   operation  in
particular might lead  to  very large numbers.  This  is  no problem  for
&GAP; as it can handle numbers of (almost) any size.
<P/>
<Example><![CDATA[
gap> 3^132;
955004950796825236893190701774414011919935138974343129836853841
]]></Example>
<P/>
The <K>mod</K> operator allows you to compute one value modulo another.
<P/>
<Example><![CDATA[
gap> 17 mod 3;
2
]]></Example>
<P/>
Note  that  there must be   whitespace around the  keyword  <K>mod</K> in this
example since <C>17mod3</C> or <C>17mod</C> would be interpreted as identifiers.
The whitespace around operators that do not consist of letters, e.g.,
the operators <C>*</C> and <C>-</C>, is not necessary.
<P/>
&GAP;  knows a  precedence  between operators that may be overridden  by
parentheses.
<P/>
<Example><![CDATA[
gap> (9 - 7) * 5 = 9 - 7  * 5;
false
]]></Example>
<P/>
Besides these arithmetical operators there are comparison operators in &GAP;.
A comparison results in a <E>boolean value</E> which is another kind
of constant.
The comparison  operators <C>=</C>, <C>&lt;></C>, <C>&lt;</C>, <C>&lt;=</C>,
<C>></C> and <C>>=</C>, test for equality, inequality, less than,
less than or equal, greater than and greater than or equal, respectively.
<P/>
<Example><![CDATA[
gap> 10^5 < 10^4;
false
]]></Example>
<P/>
The boolean values <K>true</K> and <K>false</K> can be manipulated via
logical operators, i.&nbsp;e., the unary operator <K>not</K> and the
binary operators <K>and</K> and <K>or</K>.
Of course boolean values can be compared, too.
<P/>
<Example><![CDATA[
gap> not true; true and false; true or false;
false
false
true
gap> 10 > 0 and 10 < 100;
true
]]></Example>
<P/>
Another important  type of constants in   &GAP; are <E>permutations</E>. They
are written in cycle notation and they can be multiplied.
<P/>
<Example><![CDATA[
gap> (1,2,3);
(1,2,3)
gap> (1,2,3) * (1,2);
(2,3)
]]></Example>
<P/>
The inverse of the   permutation  <C>(1,2,3)</C> is denoted   by <C>(1,2,3)^-1</C>.
Moreover the caret operator <C>^</C> is used to determine the image of a point
under a permutation and to conjugate one permutation by another.
<P/>
<Example><![CDATA[
gap> (1,2,3)^-1;
(1,3,2)
gap> 2^(1,2,3);
3
gap> (1,2,3)^(1,2);
(1,3,2)
]]></Example>
<P/>
The various other constants that &GAP; can deal with will be introduced
when they are used, for example there are elements of finite fields
such as <C>Z(8)</C>, and complex roots of unity such as <C>E(4)</C>.
<P/>
The    last  type  of   constants  we  want  to mention    here are the
<E>characters</E>, which are simply objects in &GAP; that represent arbitrary
characters  from  the character set   of the  operating system. Character
literals can  be  entered   in  &GAP; by  enclosing  the   character  in
<E>singlequotes</E> <C>'</C>.
<P/>
<Example><![CDATA[
gap> 'a';
'a'
gap> '*';
'*'
]]></Example>
<P/>
There are no  operators defined for characters except that characters can
be compared.
<P/>
<!-- %%  Summary  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
In 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 &GAP; handles numbers of
arbitrary size.   Numbers and boolean   values are constants.   There are
other types of  constants in &GAP; like permutations.   You are now in a
position to use &GAP; as a simple desktop calculator.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Variables versus Objects">
<Heading>Variables versus Objects</Heading>

<Index>variables</Index><Index>assignment</Index><Index>identifier</Index><Index>objects</Index>
<Index Subkey="vs. variables">objects</Index>
The  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 &GAP;.  On the
other hand, there are <E>variables</E>, 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 <E>assignment</E> is  done by a &GAP; command
<C><A>sequence_of_letters_and_digits</A> := <A>meaning</A></C>,  where the  sequence  on
the left hand side is called the <E>identifier</E>  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 &GAP;
object. From now on,  we will use the  term <E>object</E> to denote  something
that can be assigned to a variable.
<P/>
There must be no whitespace between the <C>:</C> and the <C>=</C> in the assignment
operator.  Also do not confuse  the  assignment operator with the  single
equality sign <C>=</C> which in &GAP; is only used for the test of equality.
<P/>
<Example><![CDATA[
gap> a:= (9 - 7) * (5 + 6);
22
gap> a;
22
gap> a * (a + 1);
506
gap> a = 10;
false
gap> a:= 10;
10
gap> a * (a + 1);
110
]]></Example>
<P/>
After 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.
<P/>
<Example><![CDATA[
gap> w:= 2;; 
]]></Example>
<P/>
After 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.
<P/>
This 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 &GAP; storage manager.   This place may change during a
&GAP; session, but that doesn't  bother the identifier.  <E>The identifier
points to the object, not to a place in the memory.</E>
<P/>
For the  same reason it is  not the  identifier that has   a type but the
object.  This means  on the other hand that  the identifier <C>a</C> which now
is bound to an integer object may in the  same session point to any other
object regardless of its type.
<P/>
Identifiers  may be sequences  of letters and digits containing at  least
one letter.   For example  <C>abc</C> and <C>a0bc1</C>  are valid identifiers.  But
also <C>123a</C>  is  a valid identifier as  it cannot be  confused  with  any
number.  Just <C>1234</C> indicates the  number 1234 and cannot be at the same
time the name of a variable.
<P/>
Since  &GAP; distinguishes  upper and  lower  case, <C>a1</C>  and  <C>A1</C>  are
different  identifiers.   Keywords  such as <K>quit</K>  must not  be used  as
identifiers.  You will see more keywords in the following sections.
<P/>
In  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 <Q>the integer <C>w</C></Q>.
<P/>
There are some predefined variables coming with &GAP;.  Many of them you
will find in the remaining  chapters of  this manual, since functions are
also referred to via identifiers.
<P/>
You    can get   an  overview   of  <E>all</E>  &GAP;   variables by entering
<C>NamesGVars()</C>.  Many of these are predefined.  If  you are interested in
the variables you  have defined yourself  in the current &GAP;  session,
you can enter <C>NamesUserGVars()</C>.
<P/>
<Log><![CDATA[
gap> NamesUserGVars();
[ "a", "w" ]
]]></Log>
<P/>
This seems to be the  right place to state the  following rule:
The name of every global variable in the &GAP; library starts with a
<E>capital letter</E>.
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.)
<P/>
There are some further interesting variables one of which will be
introduced now.
<P/>
<Index Key="last"><C>last</C></Index>
<Index Key="last2"><C>last2</C></Index>
<Index Key="last3"><C>last3</C></Index>
Whenever &GAP; returns an object by printing it  on  the next  line this
object is assigned to the variable <C>last</C>.  So if you computed
<P/>
<Example><![CDATA[
gap> (9 - 7) * (5 + 6);
22
]]></Example>
<P/>
and forgot to assign the object to the  variable <C>a</C> for further use, you
can still do it by the following assignment.
<P/>
<Example><![CDATA[
gap> a:= last;
22
]]></Example>
<P/>
Moreover there are variables <C>last2</C> and <C>last3</C>, you can guess their values.
<P/>
<!-- %%  Summary  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
In 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 <C>last</C>
variables storing the latest returned  objects. And you have learned that
a double semicolon prevents the result of a statement from being printed.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Objects vs. Elements">
<Heading>Objects vs. Elements</Heading>

<Index Subkey="vs. elements">objects</Index>
<Index>elements</Index>
In the last section  we mentioned that every object   is given a  certain
place  in memory by the  &GAP; storage manager  (although that place may
change in the course  of  a &GAP;  session). In  this sense, objects  at
different places in memory are never equal, and if  the object pointed to
by the  variable  <C>a</C> (to be more  precise,  the variable with identifier
<C>a</C>)  is  equal to the   object pointed to by  the  variable <C>b</C>, then we
should better  say that they  are not only  equal but <E>identical</E>. &GAP;
provides the function <Ref Func="IsIdenticalObj" BookName="ref"/>
to test whether this is the case.
<P/>
<Example><![CDATA[
gap> a:= (1,2);; IsIdenticalObj( a, a );
true
gap> b:= (1,2);; IsIdenticalObj( a, b );
false
gap> b:= a;; IsIdenticalObj( a, b );
true
]]></Example>
<P/>
<Index Key="IsIdenticalObj"><C>IsIdenticalObj</C></Index>
<P/>
As the above example indicates, &GAP;
objects  <A>a</A>  and  <A>b</A> can  be  unequal  although they are   equal from a
mathematical point of view, i.e., although we should have <A>a</A> = <A>b</A>. It
may  be that the objects <A>a</A>  and <A>b</A> 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 <A>a</A>  and <A>b</A> belong   to the same equivalence
class.  For example, if <M><A>a</A> = x^3</M> and <M><A>b</A> = x^{{-5}}</M> are words in
the finitely presented group <M>\langle x \mid x^2 = 1 \rangle</M>,
we would have <A>a</A> = <A>b</A> in that group.
<P/>
&GAP;   uses  the equality operator  <C>=</C>  to  denote such a mathematical
equality, <E>not</E> the identity of objects. Hence we often  have <C><A>a</A> = <A>b</A></C>
although <C>IsIdenticalObj( <A>a</A>, <A>b</A> ) =  false</C>.  The operator <C>=</C> defines
an equivalence relation on the set of all &GAP; objects, and we call the
corresponding  equivalence classes <E>elements</E>.   Phrasing it differently,
the same element may be represented by various &GAP; objects.
<P/>
Non-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.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="About Functions">
<Heading>About Functions</Heading>

A  program  written  in  the  &GAP; language  is  called  a  <E>function</E>.
Functions  are   special  &GAP;  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 <Ref Func="Factorial" BookName="ref"/>,  for
example,  can be applied to an  integer and will  return the factorial of
this integer.
<P/>
<Example><![CDATA[
gap> Factorial(17);
355687428096000
]]></Example>
<P/>
Applying  a  function  to arguments  means  to  write  the  arguments  in
parentheses following the function.   Several arguments are  separated by
commas, as for the  function
<Ref Func="Gcd" BookName="ref"/> which  computes  the greatest  common
divisor of two integers.
<P/>
<Example><![CDATA[
gap> Gcd(1234, 5678);
2
]]></Example>
<P/>
There   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 <Ref Func="Print" BookName="ref"/>
is only called for the side effect of printing something on the screen.
<P/>
<Example><![CDATA[
gap> Print(1234, "\n");
1234
]]></Example>
<P/>
In order to be able to compose arbitrary text with
<Ref Func="Print" BookName="ref"/>, this function
itself will not produce a line break  after printing. Thus we had another
newline character <C>"\n"</C> printed to start a new line.
<P/>
Some functions will both change an argument  and return an object such as
the function <Ref Func="Sortex" BookName="ref"/>  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.
<P/>
<Index>maps-to operator</Index>
A comfortable way to define a function yourself is the <E>maps-to</E> operator
<C>-></C> consisting of  a minus sign and a   greater sign with  no whitespace
between them. The function  <C>cubed</C> which maps a  number  to its  cube is
defined on the following line.
<P/>
<Example><![CDATA[
gap> cubed:= x -> x^3;
function( x ) ... end
]]></Example>
<P/>
After the function has been defined, it can now be applied.
<P/>
<Example><![CDATA[
gap> cubed(5);
125
]]></Example>
<P/>
More complicated  functions,  especially  functions with   more  than one
argument cannot be defined in this way.
You will see how to write your own &GAP; functions in
Section&nbsp;<Ref Sect="Writing Functions"/>.
<P/>
<!-- %%  Summary  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
In  this section you have seen &GAP; 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
&GAP; with the maps-to operator.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Help">
<Heading>Help</Heading>

The  content of  the &GAP;  manuals is  also available  as on-line  help. A
&GAP; 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.
<P/>
The format of a query is as follows.
<P/>
<C>?[<A>book</A>:][?]<A>topic</A></C>
<P/>
A simple example would be to type  <C>?help</C> at the &GAP; prompt. If there is
a single section with index entry <A>topic</A> then this is displayed directly.
<P/>
If there are several matches you get an overview like in the example below.
<P/>
<Log><![CDATA[
gap> ?sets
Help: several entries match this topic - type ?2 to get match [2]

[1] Tutorial: Sets
[2] Reference: Sets
[3] Reference: sets
[4] Reference: Sets of Subgroups
[5] Reference: setstabilizer
]]></Log>
<P/>
&GAP;'s manuals consist of several  <E>books</E>, which are indicated before the
colon in the list above. A help query can be restricted to one book by using
the optional <A>book</A>: part. For example  <C>?tut : sets</C> will display the first
of these help sections. More precisely, the parts of the string <A>book</A> which
are separated  by white  space are  interpreted as  beginnings of  the first
words in  the name of the  book. Try <C>?books</C>  to see the list  of available
books and their names.
<P/>
The  search for  a  matching <A>topic</A>  (and optional  <A>book</A>)  is done  <E>case
insensitively</E>.  If  there  is  another  <C>?</C>  before  the  <A>topic</A>,  then  a
<E>substring search</E> for <A>topic</A> is  performed on all index entries. Otherwise
the parts  of <A>topic</A> which are  separated by white space  are considered as
<E>beginnings of the first words</E> in an index entry.
<P/>
White space is normalized in the search string (and the index entries). 
<P/>
<E>Examples.</E> All the  following queries lead to the chapter  of the reference
manual which explains the use of &GAP;'s help system in more detail.
<P/>
<Log><![CDATA[
gap> ?Reference: The Help System
gap> ?  REF : t h s
gap> ?ref:?  help   system 
]]></Log>
<P/>
The query <C>??sets</C> shows all help  sections in all books whose index entries
contain the substring <C>sets</C>.
<P/>
As mentioned in the  example above a complete list of  commands for the help
system  is available  in Section&nbsp;<C>?Ref: The Help System</C> of  the reference
manual.  In  particular  there  are  commands to  browse  through  the  help
sections, see&nbsp;<C>?Ref:  Browsing through the Sections</C>  and there is a  way to
influence  the  way  <E>how</E>  the  help  sections  are  displayed,  see&nbsp;<C>?Ref:
SetHelpViewer</C>. For  example you can  use an  external pager program,  a Web
browser,  <C>dvi</C>-previewer and/or  <C>pdf</C>-viewer for  reading &GAP;'s  online
help.

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Further Information introducing the System">
<Heading>Further Information introducing the System</Heading>

For large amounts of input data, it might be advisable to write your
input first into a file, and then read this into &GAP;;
see&nbsp;<Ref Func="Read" BookName="ref"/>, <Ref Func="Edit" BookName="ref"/> for this.
<P/>
The definition of the &GAP; syntax can be looked up in
Chapter&nbsp;<Ref Chap="The Programming Language" BookName="ref"/>.
A complete list of command line editing facilities is found
in Section&nbsp;<Ref Sect="Line Editing" BookName="ref"/>.
The break loop is described in Section&nbsp;<Ref Sect="Break Loops" BookName="ref"/>.
<P/>
Operators are explained in more detail in Sections&nbsp;<Ref Sect="Expressions" BookName="ref"/> and
<Ref Sect="Comparisons" BookName="ref"/>.
You will find more information about boolean values in
Chapters&nbsp;<Ref Chap="Booleans" BookName="ref"/> and <Ref Chap="Boolean Lists" BookName="ref"/>.
Permutations are described in Chapter&nbsp;<Ref Chap="Permutations" BookName="ref"/> and characters
in Chapter&nbsp;<Ref Chap="Strings and Characters" BookName="ref"/>.
<P/>
Variables and assignments are described in more detail in&nbsp;<Ref Sect="Variables" BookName="ref"/>
and <Ref Sect="Assignments" BookName="ref"/>.
A complete list of keywords is contained in&nbsp;<Ref Sect="Keywords" BookName="ref"/>.
<P/>
More about functions can be found in&nbsp;<Ref Sect="Function Calls" BookName="ref"/>
and&nbsp;<Ref Sect="Procedure Calls" BookName="ref"/>.

</Section>
</Chapter>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %E -->

