# 2.9 Comparisons

left-expr = right-expr
left-expr < right-expr

The operator = tests for equality of its two operands and evaluates to true if they are equal and to false otherwise. Likewise < tests for inequality of its two operands. Note that any two objects can be compared, i.e., = and < will never signal an error. For each type of objects the definition of equality is given in the respective chapter. Objects of different types are never equal, i.e., = evaluates in this case to false, and < evaluates to true.

left-expr < right-expr
left-expr right-expr
left-expr <= right-expr
left-expr = right-expr

< denotes less than, <= less than or equal, greater than, and = greater than or equal of its two operands. For each type of objects the definition of the ordering is given in the respective chapter. The ordering of objects of different types is as follows. Rationals are smallest, next are cyclotomics, followed by finite field elements, permutations, words, words in solvable groups, boolean values, functions, lists, and records are largest.

Comparison operators, which includes the operator in (see In) are not associative, i.e., it is not allowed to write a = b < c = d, you must use (a = b) < (c = d) instead. The comparison operators have higher precedence than the logical operators (see Operations for Booleans), but lower precedence than the arithmetic operators (see Operations). Thus, for example, a * b = c and d is interpreted, ((a * b) = c) and d).

gap> 2 * 2 + 9 = Fibonacci(7);    # a comparison where the left
true                              # operand is an expression

GAP 3.4.4
April 1997