4.7 Comparisons of Domains

D = E
D < E

= evaluates to true if the two domains D and E are equal, to false otherwise. < evaluates to true if the two domains D and E are different and to false if they are equal.

Two domains are considered equal if and only if the sets of their elements as computed by Elements (see Elements) are equal. Thus, in general = behaves as if each domain operand were replaced by its set of elements. Except that = will also sometimes, but not always, work for infinite domains, for which it is of course difficult to compute the set of elements. Note that this implies that domains belonging to different categories may well be equal. As a special case of this, either operand may also be a proper set, i.e., a sorted list without holes or duplicates (see Set), and the result will be true if and only if the set of elements of the domain is, as a set, equal to the set. It is also possible to compare a domain with something else that is not a domain or a set, but the result will of course always be false in this case.

    gap> GaussianIntegers = D12;
    false    # {\GAP} knows that those domains cannot be equal because
             # 'GaussianIntegers' is infinite and 'D12' is finite
    gap> GaussianIntegers = Integers;
    false    # {\GAP} knows how to compare those two rings
    gap> GaussianIntegers = Rationals;
    Error, sorry, cannot compare the infinite domains <D> and <E>
    gap> D12 = Group( (2,6)(3,5), (1,2)(3,6)(4,5) );
    true
    gap> D12 = [(),(2,6)(3,5),(1,2)(3,6)(4,5),(1,2,3,4,5,6),(1,3)(4,6),
    >           (1,3,5)(2,4,6),(1,4)(2,3)(5,6),(1,4)(2,5)(3,6),
    >           (1,5)(2,4),(1,5,3)(2,6,4),(1,6,5,4,3,2),(1,6)(2,5)(3,4)];
    true
    gap> D12 = [(1,6,5,4,3,2),(1,6)(2,5)(3,4),(1,5,3)(2,6,4),(1,5)(2,4),
    >           (1,4)(2,5)(3,6),(1,4)(2,3)(5,6),(1,3,5)(2,4,6),(1,3)(4,6),
    >           (1,2,3,4,5,6),(1,2)(3,6)(4,5),(2,6)(3,5),()];
    false    # since the left operand behaves as a set
             # while the right operand is not a set 

The default function DomainOps.'=' checks whether both domains are infinite. If they are, an error is signalled. Otherwise, if one domain is infinite, false is returned. Otherwise the sizes (see Size) of the domains are compared. If they are different, false is returned. Finally the sets of elements of both domains are computed (see Elements) and compared. This default function is overlaid by more special functions for other domains.

D < E
D <= E
D E
D = E

<, <=, , and = evaluate to true if the domain D is less than, less than or equal to, greater than, and greater than or equal to the domain E and to false otherwise.

A domain D is considered less than a domain E if and only if the set of elements of D is less than the set of elements of the domain E. Generally you may just imagine that each domain operand is replaced by the set of its elements, and that the comparison is performed on those sets (see Comparisons of Lists). This implies that, if you compare a domain with an object that is not a list or a domain, this other object will be less than the domain, except if it is a record, in which case it is larger than the domain (see Comparisons).

Note that < does not test whether the left domain is a subset of the right operand, even though it resembles the mathematical subset notation.

    gap> GaussianIntegers < Rationals;
    Error, sorry, cannot compare <E> with the infinite domain <D>
    gap> Group( (1,2), (1,2,3,4,5,6) ) < D12;
    true     # since '(5,6)', the second element of the left operand,
             # is less than '(2,6)(3,5)', the second element of 'D12'.
    gap> D12 < [(1,6,5,4,3,2),(1,6)(2,5)(3,4),(1,5,3)(2,6,4),(1,5)(2,4),
    >           (1,4)(2,5)(3,6),(1,4)(2,3)(5,6),(1,3,5)(2,4,6),(1,3)(4,6),
    >           (1,2,3,4,5,6),(1,2)(3,6)(4,5),(2,6)(3,5),()];
    true     # since '()', the first element of 'D12', is less than
             # '(1,6,5,4,3,2)', the first element of the right operand.
    gap> 17 < D12;
    true     # objects that are not lists or records are smaller
             # than domains, which behave as if they were a set 

The default function DomainOps.'<' checks whether either domain is infinite. If one is, an error is signalled. Otherwise the sets of elements of both domains are computed (see Elements) and compared. This default function is only very seldom overlaid by more special functions for other domains. Thus the operators <, <=, , and = are quite expensive and their use should be avoided if possible.

Previous Up Top Next
Index

GAP 3.4.4
April 1997