AUTHORS:
Bases: sage.sets.finite_enumerated_set.FiniteEnumeratedSet
Totally ordered finite set.
This is a finite enumerated set assuming that the elements are ordered based upon their rank (i.e. their position in the set).
INPUT:
See also
EXAMPLES:
sage: S = TotallyOrderedFiniteSet([1,2,3])
sage: S
{1, 2, 3}
sage: S.cardinality()
3
By default, totally ordered finite set behaves as a facade:
sage: S(1).parent()
Integer Ring
It makes comparison fails when it is not the standard order:
sage: T1 = TotallyOrderedFiniteSet([3,2,5,1])
sage: T1(3) < T1(1)
False
sage: T2 = TotallyOrderedFiniteSet([3,var('x')])
sage: T2(3) < T2(var('x'))
3 < x
To make the above example work, you should set the argument facade to False in the constructor. In that case, the elements of the set have a dedicated class:
sage: A = TotallyOrderedFiniteSet([3,2,0,'a',7,(0,0),1], facade=False)
sage: A
{3, 2, 0, 'a', 7, (0, 0), 1}
sage: x = A.an_element()
sage: x
3
sage: x.parent()
{3, 2, 0, 'a', 7, (0, 0), 1}
sage: A(3) < A(2)
True
sage: A('a') < A(7)
True
sage: A(3) > A(2)
False
sage: A(1) < A(3)
False
sage: A(3) == A(3)
True
But then, the equality comparison is always False with elements outside of the set:
sage: A(1) == 1
False
sage: 1 == A(1)
False
sage: 'a' == A('a')
False
sage: A('a') == 'a'
False
and comparisons are comparisons of types:
sage: for e in [1,'a',(0, 0)]:
... f = A(e)
... print e == f,
... print cmp(e,f) == cmp(type(e),type(f)),
... print cmp(f,e) == cmp(type(f),type(e))
False True True
False True True
False True True
This behavior of comparison is the same as the one of Element.
When you build a totally ordered set whose elements do not inherit from sage.structure.element.Element, the following happens:
sage: S = TotallyOrderedFiniteSet(['a','b'])
sage: S('a')
Traceback (most recent call last):
...
TypeError: Cannot convert str to sage.structure.element.Element
sage: S = TotallyOrderedFiniteSet(['a','b'], facade = False)
sage: S('a')
'a'
Multiple elements are automatically deleted:
sage: TotallyOrderedFiniteSet([1,1,2,1,2,2,5,4])
{1, 2, 5, 4}
alias of TotallyOrderedFiniteSetElement
Return True if for the order of self.
EXAMPLES:
sage: T = TotallyOrderedFiniteSet([1,3,2], facade=False)
sage: T1, T3, T2 = T.list()
sage: T.le(T1,T3)
True
sage: T.le(T3,T2)
True
Bases: sage.structure.element.Element
Element of a finite totally ordered set.
EXAMPLES:
sage: S = TotallyOrderedFiniteSet([2,7], facade=False)
sage: x = S(2)
sage: print x
2
sage: x.parent()
{2, 7}