Union( D1, D2... )
Union( list )
In the first form Union
returns the union of the domains D1, D2,
etc. In the second form list must be a list of domains and Union
returns the union of those domains. Each argument D or element of
list respectively may also be an arbitrary list, in which case Union
silently applies Set
(see Set) to it first.
The result of Union
is the set of elements that lie in any the domains
D1, D2, etc. Functions called by the dispatcher function Union
however, are encouraged to keep as much structure as possible. However,
currently GAP does not support any category that is closed under
taking unions except the category of all domains. So the only case that
structure will be kept is when one argument D or element of list
respectively is a superset of all the other arguments or elements of
list.
gap> Union( GaussianIntegers, Rationals ); Error, sorry, cannot unite <E> with the infinite domain <D> gap> Union( D12, Group( (1,2), (1,2,3) ) ); [ (), (2,3), (2,6)(3,5), (1,2), (1,2)(3,6)(4,5), (1,2,3), (1,2,3,4,5,6), (1,3,2), (1,3), (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) ] gap> Union( [2,4,6,8,10], [3,6,9,12,15], [5,10,15,20,25] ); [ 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 20, 25 ] # two or more domains or sets as arguments are legal gap> Union( [ [1,2,4], [2,3,4], [1,3,4] ] ); [ 1, 2, 3, 4 ] # or a list of domains or sets gap> Union( [ ] ); [ ]
The dispatcher function (see Dispatchers) Union
is slightly different
from other dispatcher functions. It does not simply call the function in
the operations record passings its arguments. Instead it loops over its
arguments (or the list of domains or sets) and calls the function in the
operations record repeatedly, and passes each time only two domains.
This obviously makes writing the function for the operations record
simpler.
The default function DomainOps.Union
checks whether either domain is
infinite. If one is it signals an error. If both domains are finite it
computes the proper sets of elements of both and unites them (see
Elements and Set Functions for Sets). This default method is
overlaid by more special functions for some other domains. Those
functions usually are faster.
GAP 3.4.4