list1 = list2
list1 < list2
The equality operator =
evaluates to true
if the two lists list1
and list2 are equal and false
otherwise. The inequality operator
<
evaluates to true
if the two lists are not equal and false
otherwise. Two lists list1 and list2 are equal if and only if for
every index i, either both entries list1[i]
and list2[i]
are unbound, or both are bound and are equal, i.e., list1[i] =
list2[i]
is true
.
gap> [ 1, 2, 3 ] = [ 1, 2, 3 ]; true gap> [ , 2, 3 ] = [ 1, 2, ]; false gap> [ 1, 2, 3 ] = [ 3, 2, 1 ]; false
list1 < list2
, list1 <= list2
list1 list2
, list1 = list2
The operators <
, <=
, and
=
evaluate to true
if the list
list1 is less than, less than or equal to, greater than, or greater
than or equal to the list list2 and to false
otherwise. Lists are
ordered lexicographically, with unbound entries comparing very small.
That means the following. Let i be the smallest positive integer i,
such that neither both entries list1[i]
and list2[i]
are
unbound, nor both are bound and equal. Then list1 is less than list2
if either list1[i]
is unbound (and list2[i]
is not) or both
are bound and list1[i] < list2[i]
is true
.
gap> [ 1, 2, 3, 4 ] < [ 1, 2, 4, 8 ]; true # '<list1>[3] \<\ <list2>[3]' gap> [ 1, 2, 3 ] < [ 1, 2, 3, 4 ]; true # '<list1>[4]' is unbound and therefore very small gap> [ 1, , 3, 4 ] < [ 1, 2, 3 ]; true # '<list1>[2]' is unbound and therefore very small
You can also compare objects of other types, for example integers or permutations with lists. Of course those objects are never equal to a list. Records (see Records) are greater than lists, objects of every other type are smaller than lists.
gap> 123 < [ 1, 2, 3 ]; true gap> [ 1, 2, 3 ] < rec( a := 123 ); true
GAP 3.4.4