IsSubset( C1, C2 ) O
IsSubset returns true if C2, which must be a collection, is a
subset of C1, which also must be a collection, and false otherwise.
C2 is considered a subset of C1 if and only if each element of C2
is also an element of C1.
That is IsSubset behaves as if implemented as
IsSubsetSet( AsSSortedList( C1 ), AsSSortedList( C2 ) ),
except that it will also sometimes, but not always,
work for infinite collections,
and that it will usually work much faster than the above definition.
Either argument may also be a proper set (see Sorted Lists and Sets).
gap> IsSubset( Rationals, Integers ); true gap> IsSubset( Integers, [ 1, 2, 3 ] ); true gap> IsSubset( Group( (1,2,3,4) ), [ (1,2,3) ] ); false
Intersection( C1, C2... ) F
Intersection( list ) F
Intersection2( C1, C2 ) O
In the first form Intersection returns the intersection of the
collections C1, C2, etc.
In the second form list must be a nonempty list of collections
and Intersection returns the intersection of those collections.
Each argument or element of list respectively may also be a
homogeneous list that is not a proper set,
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 collections C1, C2, etc.
Methods can be installed for the operation Intersection2 that takes
only two arguments.
Intersection calls Intersection2.
Methods for Intersection2 should try to maintain as much structure as
possible, for example the intersection of two permutation groups is
again 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> D12 := Group( (2,6)(3,5), (1,2)(3,6)(4,5) );;
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 proper 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
# regarded as a group
gap> Intersection( Group( () ), [1,2,3] );
[ ]
gap> Intersection( [2,4,6,8,10], [3,6,9,12,15], [5,10,15,20,25] );
[ ] # two or more lists or collections as arguments are legal
gap> Intersection( [ [1,2,4], [2,3,4], [1,3,4] ] );
[ 4 ] # or one list of lists or collections
Union( C1, C2... ) F
Union( list ) F
Union2( C1, C2 ) O
In the first form Union returns the union of the
collections C1, C2, etc.
In the second form list must be a list of collections
and Union returns the union of those collections.
Each argument or element of list respectively may also be a
homogeneous list that is not a proper set,
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 of the
collections C1, C2, etc.
Methods can be installed for the operation Union2 that takes only two
arguments.
Union calls Union2.
gap> Union( [ (1,2,3), (1,2,3,4) ], Group( (1,2,3), (1,2) ) );
[ (), (2,3), (1,2), (1,2,3), (1,2,3,4), (1,3,2), (1,3) ]
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 lists or collections as arguments are legal
gap> Union( [ [1,2,4], [2,3,4], [1,3,4] ] );
[ 1, 2, 3, 4 ] # or one list of lists or collections
gap> Union( [ ] );
[ ]
Difference( C1, C2 ) O
Difference returns the set difference of the collections C1 and C2.
Either argument may also be a homogeneous list that is not a proper set,
in which case Difference silently applies Set (see Set) to it
first.
The result of Difference is the set of elements that lie in C1 but
not in C2.
Note that C2 need not be a subset of C1.
The elements of C2, however, that are not elements of C1 play no role
for the result.
gap> Difference( [ (1,2,3), (1,2,3,4) ], Group( (1,2,3), (1,2) ) ); [ (1,2,3,4) ]
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual