Finite Enumerated Sets

class sage.sets.finite_enumerated_set.FiniteEnumeratedSet(elements)

Bases: sage.structure.unique_representation.UniqueRepresentation, sage.structure.parent.Parent

A class for finite enumerated set.

Returns the finite enumerated set with elements in elements where element is any (finite) iterable object.

The main purpose is to provide a variant of list or tuple, which is a parent with an interface consistent with EnumeratedSets and has unique representation. The list of the elements is expanded in memory.

EXAMPLES:

sage: S = FiniteEnumeratedSet([1, 2, 3])
sage: S
{1, 2, 3}
sage: S.list()
[1, 2, 3]
sage: S.cardinality()
3
sage: S.random_element()
1
sage: S.first()
1
sage: S.category()
Category of finite enumerated sets
sage: TestSuite(S).run()

Note that being and enumerated set, the result depends on the order:

sage: S1 = FiniteEnumeratedSet((1, 2, 3))
sage: S1
{1, 2, 3}
sage: S1.list()
[1, 2, 3]
sage: S1 == S
True
sage: S2 = FiniteEnumeratedSet((2, 1, 3))
sage: S2 == S
False

As an abuse, repeated entries in elements are allowed to model multisets:

sage: S1 = FiniteEnumeratedSet((1, 2, 1, 2, 2, 3))
sage: S1
{1, 2, 1, 2, 2, 3}

Finaly the elements are not aware of their parent:

sage: S.first().parent()
Integer Ring

TESTS:

sage: TestSuite(FiniteEnumeratedSet([])).run()
an_element()

TESTS:

sage: S = FiniteEnumeratedSet([1,2,3])
sage: S.an_element()
1
cardinality()

TESTS:

sage: S = FiniteEnumeratedSet([1,2,3])
sage: S.cardinality()
3
list()

TESTS:

sage: S = FiniteEnumeratedSet([1,2,3])
sage: S.list()
[1, 2, 3]

Previous topic

Disjoint union of enumerated sets

Next topic

Integer Range

This Page