Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 4183461[1X2 [33X[0;0YA First Session with [5XGAP[105X[101X[1X[133X[101X23[33X[0;0YThis tutorial introduces you to the [5XGAP[105X system. It is written with users in4mind who have just managed to start [5XGAP[105X for the first time on their computer5and want to learn the basic facts about [5XGAP[105X by playing around with some6instructive examples. Therefore, this tutorial contains at many places7examples consisting of several lines of input (which you should type on your8terminal) followed by the corresponding output ( which [5XGAP[105X produces as an9answer to your input).[133X1011[33X[0;0YWe encourage you to actually run through these examples on your computer.12This will support your feeling for [5XGAP[105X as a tool, which is the leading aim13of this tutorial. Do not believe any statement in it as long as you cannot14verify it for your own version of [5XGAP[105X. You will learn to distinguish between15small deviations of the behavior of your personal [5XGAP[105X from the printed16examples and serious nonsense.[133X1718[33X[0;0YSince the printing routines of [5XGAP[105X are in some sense machine dependent you19will for instance encounter a different layout of the printed objects in20different environments. But the contents should always be the same. In case21you encounter serious nonsense it is highly recommended that you send a bug22report to [7Xmailto:[email protected][107X.[133X2324[33X[0;0YThe examples in this tutorial should explain everything you have to know in25order to be able to use [5XGAP[105X. The reference manual then gives a more26systematic treatment of the various types of objects that [5XGAP[105X can27manipulate. It seems desirable neither to start this systematic course with28the most elementary (and most boring) structures, nor to confront you with29all the complex data types before you know how they are composed from30elementary structures. For this reason this tutorial wants to provide you31with a basic understanding of [5XGAP[105X objects, on which the reference manual32will then build when it explains everything in detail. So after having33mastered this tutorial, you can immediately plunge into the exciting parts34of [5XGAP[105X and only read detailed information about elementary things (in the35reference manual) when you really need them.[133X3637[33X[0;0YEach chapter of this tutorial contains a section with references to the38reference manual at the end.[133X394041[1X2.1 [33X[0;0YStarting and Leaving [5XGAP[105X[101X[1X[133X[101X4243[33X[0;0YIf the program is correctly installed then you usually start [5XGAP[105X by simply44typing [10Xgap[110X at the prompt of your operating system followed by the [12XReturn[112X45key, sometimes this is also called the [12XNewline[112X key.[133X4647[4X[32X Example [32X[104X48[4X[28X$ gap[128X[104X49[4X[32X[104X5051[33X[0;0Y[5XGAP[105X answers your request with its beautiful banner and then it shows its own52prompt [10Xgap>[110X asking you for further input. (You can avoid the banner with the53command line option [10X-b[110X; more command line options are described in54Section [14X'Reference: Command Line Options'[114X.)[133X5556[4X[32X Example [32X[104X57[4X[25Xgap>[125X [27X[127X[104X58[4X[32X[104X5960[33X[0;0YThe usual way to end a [5XGAP[105X session is to type [10Xquit;[110X at the [10Xgap>[110X prompt. Do61not omit the semicolon![133X6263[4X[32X Example [32X[104X64[4X[25Xgap>[125X [27Xquit;[127X[104X65[4X[28X$ [128X[104X66[4X[32X[104X6768[33X[0;0YOn some systems you could type [12XCtrl-D[112X to yield the same effect. In any69situation [5XGAP[105X is ended by typing [12XCtrl-C[112X twice within a second. Here as70always, a combination like [12XCtrl-D[112X means that you have to press the [12XD[112X key71while you hold down the [12XCtrl[112X key.[133X7273[33X[0;0YOn some systems (for example the Apple Macintosh) minor changes might be74necessary. This is explained in [5XGAP[105X installation instructions (see the75[11XINSTALL[111X file in the [5XGAP[105X root directory, or the [5XGAP[105X website).[133X7677[33X[0;0YIn most places [13Xwhitespace[113X characters (i.e. [12XSpace[112Xs, [12XTab[112Xs and [12XReturn[112Xs) are78insignificant for the meaning of [5XGAP[105X input. Identifiers and keywords must79however not contain any whitespace. On the other hand, sometimes there must80be whitespace around identifiers and keywords to separate them from each81other and from numbers. We will use whitespace to format more complicated82commands for better readability.[133X8384[33X[0;0YA [13Xcomment[113X in [5XGAP[105X starts with the symbol [10X#[110X and continues to the end of the85line. Comments are treated like whitespace by [5XGAP[105X. We use comments in the86printed examples in this tutorial to explain certain lines of input or87output.[133X888990[1X2.2 [33X[0;0YLoading Source Code from a File[133X[101X9192[33X[0;0YThe most convenient way of creating larger pieces of [5XGAP[105X code is to write93them to some text file. For this purpose you can simply use your favorite94text editor. You can load such a file into [5XGAP[105X using the [2XRead[102X ([14XReference:95Read[114X) function:[133X9697[4X[32X Example [32X[104X98[4X[25Xgap>[125X [27XRead("../../GAPProgs/Example.g");[127X[104X99[4X[32X[104X100101[33X[0;0YYou can either give the full absolute path name of the source file or its102relative path name from the [5XGAP[105X root directory (the directory containing103[11Xbin/[111X, [11Xdoc/[111X, [11Xlib/[111X, etc.).[133X104105106[1X2.3 [33X[0;0YThe Read Evaluate Print Loop[133X[101X107108[33X[0;0Y[5XGAP[105X is an interactive system. It continuously executes a read evaluate print109loop. Each expression you type at the keyboard is read by [5XGAP[105X, evaluated,110and then the result is shown.[133X111112[33X[0;0YThe interactive nature of [5XGAP[105X allows you to type an expression at the113keyboard and see its value immediately. You can define a function and apply114it to arguments to see how it works. You may even write whole programs115containing lots of functions and test them without leaving the program.[133X116117[33X[0;0YWhen your program is large it will be more convenient to write it on a file118and then read that file into [5XGAP[105X. Preparing your functions in a file has119several advantages. You can compose your functions more carefully in a file120(with your favorite text editor), you can correct errors without retyping121the whole function and you can keep a copy for later use. Moreover you can122write lots of comments into the program text, which are ignored by [5XGAP[105X, but123are very useful for human readers of your program text. [5XGAP[105X treats input124from a file in the same way that it treats input from the keyboard. Further125details can be found in section [2XRead[102X ([14XReference: Read[114X).[133X126127[33X[0;0YA simple calculation with [5XGAP[105X is as easy as one can imagine. You type the128problem just after the prompt, terminate it with a semicolon and then pass129the problem to the program with the [12XReturn[112X key. For example, to multiply the130difference between 9 and 7 by the sum of 5 and 6, that is to calculate [22X(9 -1317) * (5 + 6)[122X, you type exactly this last sequence of symbols followed by [10X;[110X132and [12XReturn[112X.[133X133134[4X[32X Example [32X[104X135[4X[25Xgap>[125X [27X(9 - 7) * (5 + 6);[127X[104X136[4X[28X22[128X[104X137[4X[25Xgap>[125X [27X[127X[104X138[4X[32X[104X139140[33X[0;0YThen [5XGAP[105X echoes the result 22 on the next line and shows with the prompt141that it is ready for the next problem. Henceforth, we will no longer print142this additional prompt.[133X143144[33X[0;0YIf you make a mistake while typing the line, but [13Xbefore[113X typing the final145[12XReturn[112X, you can use the [12XDelete[112X key (or sometimes [12XBackspace[112X key) to delete146the last typed character. You can also move the cursor back and forward in147the line with [12XCtrl-B[112X and [12XCtrl-F[112X and insert or delete characters anywhere in148the line. The line editing commands are fully described in149section [14X'Reference: Line Editing'[114X.[133X150151[33X[0;0YIf you did omit the semicolon at the end of the line but have already typed152[12XReturn[112X, then [5XGAP[105X has read everything you typed, but does not know that the153command is complete. The program is waiting for further input and indicates154this with a partial prompt [10X>[110X. This problem is solved by simply typing the155missing semicolon on the next line of input. Then the result is printed and156the normal prompt returns.[133X157158[4X[32X Example [32X[104X159[4X[25Xgap>[125X [27X(9 - 7) * (5 + 6)[127X[104X160[4X[25X>[125X [27X;[127X[104X161[4X[28X22[128X[104X162[4X[32X[104X163164[33X[0;0YSo the input can consist of several lines, and [5XGAP[105X prints a partial prompt [10X>[110X165in each input line except the first, until the command is completed with a166semicolon. ([5XGAP[105X may already evaluate part of the input when [12XReturn[112X is typed,167so for long calculations it might take some time until the partial prompt168appears.) Whenever you see the partial prompt and you cannot decide what [5XGAP[105X169is still waiting for, then you have to type semicolons until the normal170prompt returns. In every situation the exact meaning of the prompt [10Xgap>[110X is171that the program is waiting for a new problem.[133X172173[33X[0;0YBut even if you mistyped the command more seriously, you do not have to type174it all again. Suppose you mistyped or forgot the last closing parenthesis.175Then your command is syntactically incorrect and [5XGAP[105X will notice it,176incapable of computing the desired result.[133X177178[4X[32X Example [32X[104X179[4X[25Xgap>[125X [27X(9 - 7) * (5 + 6;[127X[104X180[4X[28XSyntax error: ) expected[128X[104X181[4X[28X(9 - 7) * (5 + 6;[128X[104X182[4X[28X ^[128X[104X183[4X[32X[104X184185[33X[0;0YInstead of the result an error message occurs indicating the place where an186unexpected symbol occurred with an arrow sign [10X^[110X under it. As a computer187program cannot know what your intentions really were, this is only a hint.188But in this case [5XGAP[105X is right by claiming that there should be a closing189parenthesis before the semicolon. Now you can type [12XCtrl-P[112X to recover the190last line of input. It will be written after the prompt with the cursor in191the first position. Type [12XCtrl-E[112X to take the cursor to the end of the line,192then [12XCtrl-B[112X to move the cursor one character back. The cursor is now on the193position of the semicolon. Enter the missing parenthesis by simply typing [10X)[110X.194Now the line is correct and may be passed to [5XGAP[105X by hitting the [12XReturn[112X key.195Note that for this action it is not necessary to move the cursor past the196last character of the input line.[133X197198[33X[0;0YEach line of commands you type is sent to [5XGAP[105X for evaluation by pressing199[12XReturn[112X regardless of the position of the cursor in that line. We will no200longer mention the [12XReturn[112X key from now on.[133X201202[33X[0;0YSometimes a syntax error will cause [5XGAP[105X to enter a [13Xbreak loop[113X. This is203indicated by the special prompt [10Xbrk>[110X. If another syntax error occurs while204[5XGAP[105X is in a break loop, the prompt will change to [10Xbrk_02>[110X, [10Xbrk_03>[110X and so205on. You can leave the current break loop and exit to the next outer one by206either typing [10Xquit;[110X or by hitting [12XCtrl-D[112X. Eventually [5XGAP[105X will return to its207normal state and show its normal prompt [10Xgap>[110X again.[133X208209210[1X2.4 [33X[0;0YConstants and Operators[133X[101X211212[33X[0;0YIn an expression like [10X(9 - 7) * (5 + 6)[110X the constants [10X5[110X, [10X6[110X, [10X7[110X, and [10X9[110X are213being composed by the operators [10X+[110X, [10X*[110X and [10X-[110X to result in a new value.[133X214215[33X[0;0YThere are three kinds of operators in [5XGAP[105X, arithmetical operators,216comparison operators, and logical operators. You have already seen that it217is possible to form the sum, the difference, and the product of two integer218values. There are some more operators applicable to integers in [5XGAP[105X. Of219course integers may be divided by each other, possibly resulting in220noninteger rational values.[133X221222[4X[32X Example [32X[104X223[4X[25Xgap>[125X [27X12345/25;[127X[104X224[4X[28X2469/5[128X[104X225[4X[32X[104X226227[33X[0;0YNote that the numerator and denominator are divided by their greatest common228divisor and that the result is uniquely represented as a division229instruction.[133X230231[33X[0;0YThe next self-explanatory example demonstrates negative numbers.[133X232233[4X[32X Example [32X[104X234[4X[25Xgap>[125X [27X-3; 17 - 23;[127X[104X235[4X[28X-3[128X[104X236[4X[28X-6[128X[104X237[4X[32X[104X238239[33X[0;0YThe exponentiation operator is written as [10X^[110X. This operation in particular240might lead to very large numbers. This is no problem for [5XGAP[105X as it can241handle numbers of (almost) any size.[133X242243[4X[32X Example [32X[104X244[4X[25Xgap>[125X [27X3^132;[127X[104X245[4X[28X955004950796825236893190701774414011919935138974343129836853841[128X[104X246[4X[32X[104X247248[33X[0;0YThe [9Xmod[109X operator allows you to compute one value modulo another.[133X249250[4X[32X Example [32X[104X251[4X[25Xgap>[125X [27X17 mod 3;[127X[104X252[4X[28X2[128X[104X253[4X[32X[104X254255[33X[0;0YNote that there must be whitespace around the keyword [9Xmod[109X in this example256since [10X17mod3[110X or [10X17mod[110X would be interpreted as identifiers. The whitespace257around operators that do not consist of letters, e.g., the operators [10X*[110X and258[10X-[110X, is not necessary.[133X259260[33X[0;0Y[5XGAP[105X knows a precedence between operators that may be overridden by261parentheses.[133X262263[4X[32X Example [32X[104X264[4X[25Xgap>[125X [27X(9 - 7) * 5 = 9 - 7 * 5;[127X[104X265[4X[28Xfalse[128X[104X266[4X[32X[104X267268[33X[0;0YBesides these arithmetical operators there are comparison operators in [5XGAP[105X.269A comparison results in a [13Xboolean value[113X which is another kind of constant.270The comparison operators [10X=[110X, [10X<>[110X, [10X<[110X, [10X<=[110X, [10X>[110X and [10X>=[110X, test for equality,271inequality, less than, less than or equal, greater than and greater than or272equal, respectively.[133X273274[4X[32X Example [32X[104X275[4X[25Xgap>[125X [27X10^5 < 10^4;[127X[104X276[4X[28Xfalse[128X[104X277[4X[32X[104X278279[33X[0;0YThe boolean values [9Xtrue[109X and [9Xfalse[109X can be manipulated via logical operators,280i. e., the unary operator [9Xnot[109X and the binary operators [9Xand[109X and [9Xor[109X. Of course281boolean values can be compared, too.[133X282283[4X[32X Example [32X[104X284[4X[25Xgap>[125X [27Xnot true; true and false; true or false;[127X[104X285[4X[28Xfalse[128X[104X286[4X[28Xfalse[128X[104X287[4X[28Xtrue[128X[104X288[4X[25Xgap>[125X [27X10 > 0 and 10 < 100;[127X[104X289[4X[28Xtrue[128X[104X290[4X[32X[104X291292[33X[0;0YAnother important type of constants in [5XGAP[105X are [13Xpermutations[113X. They are293written in cycle notation and they can be multiplied.[133X294295[4X[32X Example [32X[104X296[4X[25Xgap>[125X [27X(1,2,3);[127X[104X297[4X[28X(1,2,3)[128X[104X298[4X[25Xgap>[125X [27X(1,2,3) * (1,2);[127X[104X299[4X[28X(2,3)[128X[104X300[4X[32X[104X301302[33X[0;0YThe inverse of the permutation [10X(1,2,3)[110X is denoted by [10X(1,2,3)^-1[110X. Moreover303the caret operator [10X^[110X is used to determine the image of a point under a304permutation and to conjugate one permutation by another.[133X305306[4X[32X Example [32X[104X307[4X[25Xgap>[125X [27X(1,2,3)^-1;[127X[104X308[4X[28X(1,3,2)[128X[104X309[4X[25Xgap>[125X [27X2^(1,2,3);[127X[104X310[4X[28X3[128X[104X311[4X[25Xgap>[125X [27X(1,2,3)^(1,2);[127X[104X312[4X[28X(1,3,2)[128X[104X313[4X[32X[104X314315[33X[0;0YThe various other constants that [5XGAP[105X can deal with will be introduced when316they are used, for example there are elements of finite fields such as [10XZ(8)[110X,317and complex roots of unity such as [10XE(4)[110X.[133X318319[33X[0;0YThe last type of constants we want to mention here are the [13Xcharacters[113X, which320are simply objects in [5XGAP[105X that represent arbitrary characters from the321character set of the operating system. Character literals can be entered in322[5XGAP[105X by enclosing the character in [13Xsinglequotes[113X [10X'[110X.[133X323324[4X[32X Example [32X[104X325[4X[25Xgap>[125X [27X'a';[127X[104X326[4X[28X'a'[128X[104X327[4X[25Xgap>[125X [27X'*';[127X[104X328[4X[28X'*'[128X[104X329[4X[32X[104X330331[33X[0;0YThere are no operators defined for characters except that characters can be332compared.[133X333334[33X[0;0YIn this section you have seen that values may be preceded by unary operators335and combined by binary operators placed between the operands. There are336rules for precedence which may be overridden by parentheses. A comparison337results in a boolean value. Boolean values are combined via logical338operators. Moreover you have seen that [5XGAP[105X handles numbers of arbitrary339size. Numbers and boolean values are constants. There are other types of340constants in [5XGAP[105X like permutations. You are now in a position to use [5XGAP[105X as341a simple desktop calculator.[133X342343344[1X2.5 [33X[0;0YVariables versus Objects[133X[101X345346[33X[0;0YThe constants described in the last section are specified by certain347combinations of digits and minus signs (in the case of integers) or digits,348commas and parentheses (in the case of permutations). These sequences of349characters always have the same meaning to [5XGAP[105X. On the other hand, there are350[13Xvariables[113X, specified by a sequence of letters and digits (including at least351one letter), and their meaning depends on what has been assigned to them. An352[13Xassignment[113X is done by a [5XGAP[105X command [10X[3Xsequence_of_letters_and_digits[103X[10X :=353[3Xmeaning[103X[10X[110X, where the sequence on the left hand side is called the [13Xidentifier[113X354of the variable and it serves as its name. The meaning on the right hand355side can be a constant like an integer or a permutation, but it can also be356almost any other [5XGAP[105X object. From now on, we will use the term [13Xobject[113X to357denote something that can be assigned to a variable.[133X358359[33X[0;0YThere must be no whitespace between the [10X:[110X and the [10X=[110X in the assignment360operator. Also do not confuse the assignment operator with the single361equality sign [10X=[110X which in [5XGAP[105X is only used for the test of equality.[133X362363[4X[32X Example [32X[104X364[4X[25Xgap>[125X [27Xa:= (9 - 7) * (5 + 6);[127X[104X365[4X[28X22[128X[104X366[4X[25Xgap>[125X [27Xa;[127X[104X367[4X[28X22[128X[104X368[4X[25Xgap>[125X [27Xa * (a + 1);[127X[104X369[4X[28X506[128X[104X370[4X[25Xgap>[125X [27Xa = 10;[127X[104X371[4X[28Xfalse[128X[104X372[4X[25Xgap>[125X [27Xa:= 10;[127X[104X373[4X[28X10[128X[104X374[4X[25Xgap>[125X [27Xa * (a + 1);[127X[104X375[4X[28X110[128X[104X376[4X[32X[104X377378[33X[0;0YAfter an assignment the assigned object is echoed on the next line. The379printing of the object of a statement may be in every case prevented by380typing a double semicolon.[133X381382[4X[32X Example [32X[104X383[4X[25Xgap>[125X [27Xw:= 2;; [127X[104X384[4X[32X[104X385386[33X[0;0YAfter the assignment the variable evaluates to that object if evaluated.387Thus it is possible to refer to that object by the name of the variable in388any situation.[133X389390[33X[0;0YThis is in fact the whole secret of an assignment. An identifier is bound to391an object and from this moment points to that object. Nothing more. This392binding is changed by the next assignment to that identifier. An identifier393does not denote a block of memory as in some other programming languages. It394simply points to an object, which has been given its place in memory by the395[5XGAP[105X storage manager. This place may change during a [5XGAP[105X session, but that396doesn't bother the identifier. [13XThe identifier points to the object, not to a397place in the memory.[113X[133X398399[33X[0;0YFor the same reason it is not the identifier that has a type but the object.400This means on the other hand that the identifier [10Xa[110X which now is bound to an401integer object may in the same session point to any other object regardless402of its type.[133X403404[33X[0;0YIdentifiers may be sequences of letters and digits containing at least one405letter. For example [10Xabc[110X and [10Xa0bc1[110X are valid identifiers. But also [10X123a[110X is a406valid identifier as it cannot be confused with any number. Just [10X1234[110X407indicates the number 1234 and cannot be at the same time the name of a408variable.[133X409410[33X[0;0YSince [5XGAP[105X distinguishes upper and lower case, [10Xa1[110X and [10XA1[110X are different411identifiers. Keywords such as [9Xquit[109X must not be used as identifiers. You will412see more keywords in the following sections.[133X413414[33X[0;0YIn the remaining part of this manual we will ignore the difference between415variables, their names (identifiers), and the objects they point to. It may416be useful to think from time to time about what is really meant by terms417such as [21Xthe integer [10Xw[110X[121X.[133X418419[33X[0;0YThere are some predefined variables coming with [5XGAP[105X. Many of them you will420find in the remaining chapters of this manual, since functions are also421referred to via identifiers.[133X422423[33X[0;0YYou can get an overview of [13Xall[113X [5XGAP[105X variables by entering [10XNamesGVars()[110X. Many424of these are predefined. If you are interested in the variables you have425defined yourself in the current [5XGAP[105X session, you can enter [10XNamesUserGVars()[110X.[133X426427[4X[32X Example [32X[104X428[4X[25Xgap>[125X [27XNamesUserGVars();[127X[104X429[4X[28X[ "a", "w" ][128X[104X430[4X[32X[104X431432[33X[0;0YThis seems to be the right place to state the following rule: The name of433every global variable in the [5XGAP[105X library starts with a [13Xcapital letter[113X. Thus434if you choose only names starting with a small letter for your own variables435you will not attempt to overwrite any predefined variable. (Note that most436of the predefined variables are read-only, and trying to change their values437will result in an error message.)[133X438439[33X[0;0YThere are some further interesting variables one of which will be introduced440now.[133X441442[33X[0;0YWhenever [5XGAP[105X returns an object by printing it on the next line this object443is assigned to the variable [10Xlast[110X. So if you computed[133X444445[4X[32X Example [32X[104X446[4X[25Xgap>[125X [27X(9 - 7) * (5 + 6);[127X[104X447[4X[28X22[128X[104X448[4X[32X[104X449450[33X[0;0Yand forgot to assign the object to the variable [10Xa[110X for further use, you can451still do it by the following assignment.[133X452453[4X[32X Example [32X[104X454[4X[25Xgap>[125X [27Xa:= last;[127X[104X455[4X[28X22[128X[104X456[4X[32X[104X457458[33X[0;0YMoreover there are variables [10Xlast2[110X and [10Xlast3[110X, you can guess their values.[133X459460[33X[0;0YIn this section you have seen how to assign objects to variables. These461objects can later be accessed through the name of the variable, its462identifier. You have also encountered the useful concept of the [10Xlast[110X463variables storing the latest returned objects. And you have learned that a464double semicolon prevents the result of a statement from being printed.[133X465466467[1X2.6 [33X[0;0YObjects vs. Elements[133X[101X468469[33X[0;0YIn the last section we mentioned that every object is given a certain place470in memory by the [5XGAP[105X storage manager (although that place may change in the471course of a [5XGAP[105X session). In this sense, objects at different places in472memory are never equal, and if the object pointed to by the variable [10Xa[110X (to473be more precise, the variable with identifier [10Xa[110X) is equal to the object474pointed to by the variable [10Xb[110X, then we should better say that they are not475only equal but [13Xidentical[113X. [5XGAP[105X provides the function [2XIsIdenticalObj[102X476([14XReference: IsIdenticalObj[114X) to test whether this is the case.[133X477478[4X[32X Example [32X[104X479[4X[25Xgap>[125X [27Xa:= (1,2);; IsIdenticalObj( a, a );[127X[104X480[4X[28Xtrue[128X[104X481[4X[25Xgap>[125X [27Xb:= (1,2);; IsIdenticalObj( a, b );[127X[104X482[4X[28Xfalse[128X[104X483[4X[25Xgap>[125X [27Xb:= a;; IsIdenticalObj( a, b );[127X[104X484[4X[28Xtrue[128X[104X485[4X[32X[104X486487[33X[0;0YAs the above example indicates, [5XGAP[105X objects [3Xa[103X and [3Xb[103X can be unequal although488they are equal from a mathematical point of view, i.e., although we should489have [3Xa[103X = [3Xb[103X. It may be that the objects [3Xa[103X and [3Xb[103X are stored in different490places in memory, or it may be that we have an equivalence relation defined491on the set of objects under which [3Xa[103X and [3Xb[103X belong to the same equivalence492class. For example, if [22X[3Xa[103X = x^3[122X and [22X[3Xb[103X = x^{-5}[122X are words in the finitely493presented group [22X⟨ x ∣ x^2 = 1 ⟩[122X, we would have [3Xa[103X = [3Xb[103X in that group.[133X494495[33X[0;0Y[5XGAP[105X uses the equality operator [10X=[110X to denote such a mathematical equality, [13Xnot[113X496the identity of objects. Hence we often have [10X[3Xa[103X[10X = [3Xb[103X[10X[110X although [10XIsIdenticalObj(497[3Xa[103X[10X, [3Xb[103X[10X ) = false[110X. The operator [10X=[110X defines an equivalence relation on the set of498all [5XGAP[105X objects, and we call the corresponding equivalence classes [13Xelements[113X.499Phrasing it differently, the same element may be represented by various [5XGAP[105X500objects.[133X501502[33X[0;0YNon-trivial examples of elements that are represented by different objects503(objects that really look different, not ones that are merely stored in504different memory places) will occur only when we will be considering505composite objects such as lists or domains.[133X506507508[1X2.7 [33X[0;0YAbout Functions[133X[101X509510[33X[0;0YA program written in the [5XGAP[105X language is called a [13Xfunction[113X. Functions are511special [5XGAP[105X objects. Most of them behave like mathematical functions. They512are applied to objects and will return a new object depending on the input.513The function [2XFactorial[102X ([14XReference: Factorial[114X), for example, can be applied514to an integer and will return the factorial of this integer.[133X515516[4X[32X Example [32X[104X517[4X[25Xgap>[125X [27XFactorial(17);[127X[104X518[4X[28X355687428096000[128X[104X519[4X[32X[104X520521[33X[0;0YApplying a function to arguments means to write the arguments in parentheses522following the function. Several arguments are separated by commas, as for523the function [2XGcd[102X ([14XReference: Gcd[114X) which computes the greatest common divisor524of two integers.[133X525526[4X[32X Example [32X[104X527[4X[25Xgap>[125X [27XGcd(1234, 5678);[127X[104X528[4X[28X2[128X[104X529[4X[32X[104X530531[33X[0;0YThere are other functions that do not return an object but only produce a532side effect, for example changing one of their arguments. These functions533are sometimes called procedures. The function [2XPrint[102X ([14XReference: Print[114X) is534only called for the side effect of printing something on the screen.[133X535536[4X[32X Example [32X[104X537[4X[25Xgap>[125X [27XPrint(1234, "\n");[127X[104X538[4X[28X1234[128X[104X539[4X[32X[104X540541[33X[0;0YIn order to be able to compose arbitrary text with [2XPrint[102X ([14XReference: Print[114X),542this function itself will not produce a line break after printing. Thus we543had another newline character [10X"\n"[110X printed to start a new line.[133X544545[33X[0;0YSome functions will both change an argument and return an object such as the546function [2XSortex[102X ([14XReference: Sortex[114X) that sorts a list and returns the547permutation of the list elements that it has performed. You will not548understand right now what it means to change an object. We will return to549this subject several times in the next sections.[133X550551[33X[0;0YA comfortable way to define a function yourself is the [13Xmaps-to[113X operator [10X->[110X552consisting of a minus sign and a greater sign with no whitespace between553them. The function [10Xcubed[110X which maps a number to its cube is defined on the554following line.[133X555556[4X[32X Example [32X[104X557[4X[25Xgap>[125X [27Xcubed:= x -> x^3;[127X[104X558[4X[28Xfunction( x ) ... end[128X[104X559[4X[32X[104X560561[33X[0;0YAfter the function has been defined, it can now be applied.[133X562563[4X[32X Example [32X[104X564[4X[25Xgap>[125X [27Xcubed(5);[127X[104X565[4X[28X125[128X[104X566[4X[32X[104X567568[33X[0;0YMore complicated functions, especially functions with more than one argument569cannot be defined in this way. You will see how to write your own [5XGAP[105X570functions in Section [14X4.1[114X.[133X571572[33X[0;0YIn this section you have seen [5XGAP[105X objects of type function. You have learned573how to apply a function to arguments. This yields as result a new object or574a side effect. A side effect may change an argument of the function.575Moreover you have seen an easy way to define a function in [5XGAP[105X with the576maps-to operator.[133X577578579[1X2.8 [33X[0;0YHelp[133X[101X580581[33X[0;0YThe content of the [5XGAP[105X manuals is also available as on-line help. A [5XGAP[105X582session loads a long list of index entries. This typically contains all583chapter and section headers, all names of documented functions, operations584and so on, as well as some explicit index entries defined in the manuals.[133X585586[33X[0;0YThe format of a query is as follows.[133X587588[33X[0;0Y[10X?[[3Xbook[103X[10X:][?][3Xtopic[103X[10X[110X[133X589590[33X[0;0YA simple example would be to type [10X?help[110X at the [5XGAP[105X prompt. If there is a591single section with index entry [3Xtopic[103X then this is displayed directly.[133X592593[33X[0;0YIf there are several matches you get an overview like in the example below.[133X594595[4X[32X Example [32X[104X596[4X[25Xgap>[125X [27X?sets[127X[104X597[4X[28XHelp: several entries match this topic - type ?2 to get match [2][128X[104X598[4X[28X[128X[104X599[4X[28X[1] Tutorial: Sets[128X[104X600[4X[28X[2] Reference: Sets[128X[104X601[4X[28X[3] Reference: sets[128X[104X602[4X[28X[4] Reference: Sets of Subgroups[128X[104X603[4X[28X[5] Reference: setstabilizer[128X[104X604[4X[32X[104X605606[33X[0;0Y[5XGAP[105X's manuals consist of several [13Xbooks[113X, which are indicated before the colon607in the list above. A help query can be restricted to one book by using the608optional [3Xbook[103X: part. For example [10X?tut : sets[110X will display the first of these609help sections. More precisely, the parts of the string [3Xbook[103X which are610separated by white space are interpreted as beginnings of the first words in611the name of the book. Try [10X?books[110X to see the list of available books and612their names.[133X613614[33X[0;0YThe search for a matching [3Xtopic[103X (and optional [3Xbook[103X) is done [13Xcase615insensitively[113X. If there is another [10X?[110X before the [3Xtopic[103X, then a [13Xsubstring616search[113X for [3Xtopic[103X is performed on all index entries. Otherwise the parts of617[3Xtopic[103X which are separated by white space are considered as [13Xbeginnings of the618first words[113X in an index entry.[133X619620[33X[0;0YWhite space is normalized in the search string (and the index entries).[133X621622[33X[0;0Y[13XExamples.[113X All the following queries lead to the chapter of the reference623manual which explains the use of [5XGAP[105X's help system in more detail.[133X624625[4X[32X Example [32X[104X626[4X[25Xgap>[125X [27X?Reference: The Help System[127X[104X627[4X[25Xgap>[125X [27X? REF : t h s[127X[104X628[4X[25Xgap>[125X [27X?ref:? help system [127X[104X629[4X[32X[104X630631[33X[0;0YThe query [10X??sets[110X shows all help sections in all books whose index entries632contain the substring [10Xsets[110X.[133X633634[33X[0;0YAs mentioned in the example above a complete list of commands for the help635system is available in Section [10X?Ref: The Help System[110X of the reference636manual. In particular there are commands to browse through the help637sections, see [10X?Ref: Browsing through the Sections[110X and there is a way to638influence the way [13Xhow[113X the help sections are displayed, see [10X?Ref:639SetHelpViewer[110X. For example you can use an external pager program, a Web640browser, [10Xdvi[110X-previewer and/or [10Xpdf[110X-viewer for reading [5XGAP[105X's online help.[133X641642643[1X2.9 [33X[0;0YFurther Information introducing the System[133X[101X644645[33X[0;0YFor large amounts of input data, it might be advisable to write your input646first into a file, and then read this into [5XGAP[105X; see [2XRead[102X ([14XReference: Read[114X),647[2XEdit[102X ([14XReference: Edit[114X) for this.[133X648649[33X[0;0YThe definition of the [5XGAP[105X syntax can be looked up in Chapter [14X'Reference: The650Programming Language'[114X. A complete list of command line editing facilities is651found in Section [14X'Reference: Line Editing'[114X. The break loop is described in652Section [14X'Reference: Break Loops'[114X.[133X653654[33X[0;0YOperators are explained in more detail in Sections [14X'Reference: Expressions'[114X655and [14X'Reference: Comparisons'[114X. You will find more information about boolean656values in Chapters [14X'Reference: Booleans'[114X and [14X'Reference: Boolean Lists'[114X.657Permutations are described in Chapter [14X'Reference: Permutations'[114X and658characters in Chapter [14X'Reference: Strings and Characters'[114X.[133X659660[33X[0;0YVariables and assignments are described in more detail in [14X'Reference:661Variables'[114X and [14X'Reference: Assignments'[114X. A complete list of keywords is662contained in [14X'Reference: Keywords'[114X.[133X663664[33X[0;0YMore about functions can be found in [14X'Reference: Function Calls'[114X665and [14X'Reference: Procedure Calls'[114X.[133X666667668669