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()
TESTS:
sage: S = FiniteEnumeratedSet([1,2,3])
sage: S.an_element()
1
TESTS:
sage: S = FiniteEnumeratedSet([1,2,3])
sage: S.cardinality()
3
TESTS:
sage: S = FiniteEnumeratedSet([1,2,3])
sage: S.list()
[1, 2, 3]