Intersection( D1, D2... )
Intersection( list )
In the first form Intersection
returns the intersection of the domains
D1, D2, etc. In the second form list must be a list of domains and
Intersection
returns the intersection of those domains. Each argument
D or element of list respectively may also be an arbitrary list, in
which case Intersection
silently applies Set
(see Set) to it first.
The result of Intersection
is the set of elements that lie in every of
the domains D1, D2, etc. Functions called by the dispatcher function
Intersection
however, are encouraged to keep as much structure as
possible. So if D1 and D2 are elements of a common category and if
this category is closed under taking intersections, then the result
should be a domain lying in this category too. So for example the
intersection of permutation groups will again be a permutation group.
gap> Intersection( CyclotomicField(9), CyclotomicField(12) ); CF(3) # 'CF' is a shorthand for 'CyclotomicField' # this is one of the rare cases where the intersection # of two infinite domains works gap> Intersection( GaussianIntegers, Rationals ); Error, sorry, cannot intersect infinite domains <D> and <E> gap> Intersection( D12, Group( (1,2), (1,2,3,4,5) ) ); Group( (1,5)(2,4) ) gap> Intersection( D12, [ (1,3)(4,6), (1,2)(3,4) ] ); [ (1,3)(4,6) ] # note that the second argument is not a set gap> Intersection( D12, [ (), (1,2)(3,4), (1,3)(4,6), (1,4)(5,6) ] ); [ (), (1,3)(4,6) ] # although the result is mathematically a # group it is returned as a proper set # because the second argument was not a group gap> Intersection( [2,4,6,8,10], [3,6,9,12,15], [5,10,15,20,25] ); [ ] # two or more domains or sets as arguments are legal gap> Intersection( [ [1,2,4], [2,3,4], [1,3,4] ] ); [ 4 ] # or a list of domains or sets gap> Intersection( [ ] ); Error, List Element: <list>[1] must have a value
The dispatcher function (see Dispatchers) Intersection
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.Intersection
checks whether both domains
are infinite. If they are it signals an error. Otherwise, if one of the
domains is infinite it loops over the elements of the other domain, and
tests for each element whether it lies in the infinite domain. If both
domains are finite it computes the proper sets of elements of both and
intersects them (see Elements and Set Functions for Sets). This
default method is overlaid by more special functions for most other
domains. Those functions usually are faster and keep the structure of
the domains if possible.
GAP 3.4.4