Totally Ordered Finite Sets#

AUTHORS:

  • Stepan Starosta (2012): Initial version

class sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet(elements, facade=True)[source]#

Bases: 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:

  • elements – A list of elements in the set

  • facade – (default: True) if True, a facade is used; it should be set to False if the elements do not inherit from Element or if you want a funny order. See examples for more details.

EXAMPLES:

sage: S = TotallyOrderedFiniteSet([1,2,3])
sage: S
{1, 2, 3}
sage: S.cardinality()
3
>>> from sage.all import *
>>> S = TotallyOrderedFiniteSet([Integer(1),Integer(2),Integer(3)])
>>> S
{1, 2, 3}
>>> S.cardinality()
3

By default, totally ordered finite set behaves as a facade:

sage: S(1).parent()
Integer Ring
>>> from sage.all import *
>>> S(Integer(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, x])                                      # needs sage.symbolic
sage: T2(3) < T2(x)                                                             # needs sage.symbolic
3 < x
>>> from sage.all import *
>>> T1 = TotallyOrderedFiniteSet([Integer(3),Integer(2),Integer(5),Integer(1)])
>>> T1(Integer(3)) < T1(Integer(1))
False
>>> T2 = TotallyOrderedFiniteSet([Integer(3), x])                                      # needs sage.symbolic
>>> T2(Integer(3)) < T2(x)                                                             # needs sage.symbolic
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
>>> from sage.all import *
>>> A = TotallyOrderedFiniteSet([Integer(3),Integer(2),Integer(0),'a',Integer(7),(Integer(0),Integer(0)),Integer(1)], facade=False)
>>> A
{3, 2, 0, 'a', 7, (0, 0), 1}
>>> x = A.an_element()
>>> x
3
>>> x.parent()
{3, 2, 0, 'a', 7, (0, 0), 1}
>>> A(Integer(3)) < A(Integer(2))
True
>>> A('a') < A(Integer(7))
True
>>> A(Integer(3)) > A(Integer(2))
False
>>> A(Integer(1)) < A(Integer(3))
False
>>> A(Integer(3)) == A(Integer(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
>>> from sage.all import *
>>> A(Integer(1)) == Integer(1)
False
>>> Integer(1) == A(Integer(1))
False
>>> 'a' == A('a')
False
>>> A('a') == 'a'
False

Since Issue #16280, totally ordered sets support elements that do not inherit from sage.structure.element.Element, whether they are facade or not:

sage: S = TotallyOrderedFiniteSet(['a','b'])
sage: S('a')
'a'
sage: S = TotallyOrderedFiniteSet(['a','b'], facade = False)
sage: S('a')
'a'
>>> from sage.all import *
>>> S = TotallyOrderedFiniteSet(['a','b'])
>>> S('a')
'a'
>>> S = TotallyOrderedFiniteSet(['a','b'], facade = False)
>>> S('a')
'a'

Multiple elements are automatically deleted:

sage: TotallyOrderedFiniteSet([1,1,2,1,2,2,5,4])
{1, 2, 5, 4}
>>> from sage.all import *
>>> TotallyOrderedFiniteSet([Integer(1),Integer(1),Integer(2),Integer(1),Integer(2),Integer(2),Integer(5),Integer(4)])
{1, 2, 5, 4}
Element[source]#

alias of TotallyOrderedFiniteSetElement

le(x, y)[source]#

Return True if \(x \le y\) 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
>>> from sage.all import *
>>> T = TotallyOrderedFiniteSet([Integer(1),Integer(3),Integer(2)], facade=False)
>>> T1, T3, T2 = T.list()
>>> T.le(T1,T3)
True
>>> T.le(T3,T2)
True
class sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSetElement(parent, data)[source]#

Bases: 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}
>>> from sage.all import *
>>> S = TotallyOrderedFiniteSet([Integer(2),Integer(7)], facade=False)
>>> x = S(Integer(2))
>>> print(x)
2
>>> x.parent()
{2, 7}