Finite Enumerated Sets¶
-
sage.sets.finite_enumerated_set.
FiniteEnumeratedSet
¶ A class for finite enumerated set.
Returns the finite enumerated set with elements in
elements
whereelement
is any (finite) iterable object.The main purpose is to provide a variant of
list
ortuple
, which is a parent with an interface consistent withEnumeratedSets
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 facade 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