In an expression like (9 - 7) * (5 + 6)
the constants 5, 6, 7, and 9
are being composed by the operators +
, *
and -
to result in a new
value.
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.
gap> 12345/25; 2469/5
Note that the numerator and denominator are divided by their greatest common divisor and that the result is uniquely represented as a division instruction.
We haven't met negative numbers yet. So consider the following self--explanatory examples.
gap> -3; 17 - 23; -3 -6
The exponentiation operator is written as ^
. This operation in
particular might lead to very large numbers. This is no problem for
GAP as it can handle numbers of (almost) arbitrary size.
gap> 3^132; 955004950796825236893190701774414011919935138974343129836853841
The mod
operator allows you to compute one value modulo another.
gap> 17 mod 3; 2
Note that there must be whitespace around the keyword mod
in this
example since 17mod3
or 17mod
would be interpreted as identifiers.
GAP knows a precedence between operators that may be overridden by parentheses.
gap> (9 - 7) * 5 = 9 - 7 * 5; false
Besides these arithmetical operators there are comparison operators in
GAP. A comparison results in a boolean value which is another kind
of constant. Every two objects within GAP are comparable via =
,
<>
, <
, <=
, >
and >=
, that is the tests for equality,
inequality, less than, less than or equal, greater than and greater than
or equal. There is an ordering defined on the set of all GAP objects
that respects orders on subsets that one might expect. For example the
integers are ordered in the usual way.
gap> 10^5 < 10^4; false
The boolean values true
and false
can be manipulated via logical
operators, i.~e., the unary operator not
and the binary operators and
and or
. Of course boolean values can be compared, too.
gap> not true; true and false; true or false; false false true gap> 10 > 0 and 10 < 100; true
Another important type of constants in GAP are permutations. They are written in cycle notation and they can be multiplied.
gap> (1,2,3); (1,2,3) gap> (1,2,3) * (1,2); (2,3)
The inverse of the permutation (1,2,3)
is denoted by (1,2,3)^-1
.
Moreover the caret operator ^
is used to determine the image of a point
under a permutation and to conjugate one permutation by another.
gap> (1,2,3)^-1; (1,3,2) gap> 2^(1,2,3); 3 gap> (1,2,3)^(1,2); (1,3,2)
The last type of constants we want to introduce here are the
characters, 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
singlequotes '
.
gap> 'a'; 'a' gap> '*'; '*'
There are no operators defined for characters except that characters can be compared.
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. It is possible to compare any two objects. 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.
Operators are explained in more detail in Comparisons and Operations. Moreover there are sections about operators and comparisons for special types of objects in almost every chapter of this manual. You will find Boolean Lists. Permutations are described in chapter Permutations and characters are described in chapter Strings and Characters.
GAP 3.4.4