next | previous | forward | backward | up | index | toc

# Set -- the class of all sets

## Description

Elements of sets may be any immutable object, such as integers, ring elements and lists of such. Ideals may also be elements of sets.
 i1 : A = set {1,2}; i2 : R = QQ[a..d]; i3 : B = set{a^2-b*c,b*d} 2 o3 = set {b*d, a - b*c} o3 : Set
Set operations, such as membership, union, intersection, difference, Cartesian product, Cartesian power, and subset are available. For example,
 i4 : toList B 2 o4 = {b*d, a - b*c} o4 : List i5 : member(1,A) o5 = true i6 : member(-b*c+a^2,B) o6 = true i7 : A ** A o7 = set {(1, 1), (1, 2), (2, 1), (2, 2)} o7 : Set i8 : A^**2 o8 = set {(1, 1), (1, 2), (2, 1), (2, 2)} o8 : Set i9 : set{1,3,2} - set{1} o9 = set {2, 3} o9 : Set i10 : set{4,5} + set{5,6} o10 = set {4, 5, 6} o10 : Set i11 : set{4,5} * set{5,6} o11 = set {5} o11 : Set i12 : set{1,3,2} === set{1,2,3} o12 = true

Ideals in Macaulay2 come equipped with a specific sequence of generators, so the following two ideals are not considered strictly equal, and thus the set containing them will appear to have two elements.
 i13 : I = ideal(a,b); J = ideal(b,a); o13 : Ideal of R o14 : Ideal of R i15 : I == J o15 = true i16 : I === J o16 = false i17 : C = set(ideal(a,b),ideal(b,a)) o17 = set {ideal (b, a), ideal (a, b)} o17 : Set
However, if you trim the ideals, then the generating sets will be the same, and so the set containing them will have one element.
 i18 : C1 = set(trim ideal(a,b),trim ideal(b,a)) o18 = set {ideal (b, a)} o18 : Set

A set is implemented as a HashTable, whose keys are the elements of the set, and whose values are all 1. In particular, this means that two objects are considered the same exactly when they are strictly equal, according to ===.

## Methods that use a set :

• # Set -- see # BasicList -- length or cardinality
• commonest(Set) -- see commonest -- the most common elements of a list or tally
• elements(Set) -- see elements -- list of elements
• isMember(Thing,Set) -- see isMember -- test membership in a list or set
• isSubset(Set,Set) -- whether one object is a subset of another
• isSubset(Set,VisibleList) -- see isSubset(Set,Set) -- whether one object is a subset of another
• isSubset(VisibleList,Set) -- see isSubset(Set,Set) -- whether one object is a subset of another
• product(Set) -- product of elements
• Set #? Thing -- test set membership
• List - Set -- see Set - Set -- set difference
• subsets(Set) -- see subsets -- produce the subsets of a set or list
• subsets(Set,ZZ) -- see subsets -- produce the subsets of a set or list
• sum(Set) -- sum of elements
• toList(Set) -- see toList -- create a list

## For the programmer

The object Set is a type, with ancestor classes Tally < VirtualTally < HashTable < Thing.