Alphabet

AUTHORS:

  • Franco Saliola (2008-12-17) : merged into sage
  • Vincent Delecroix and Stepan Starosta (2012): remove classes for alphabet and use other Sage classes otherwise (TotallyOrderFiniteSet, FiniteEnumeratedSet, ...). More shortcut to standard alphabets.

EXAMPLES:

sage: build_alphabet("ab")
{'a', 'b'}
sage: build_alphabet([0,1,2])
{0, 1, 2}
sage: build_alphabet(name="PP")
Positive integers
sage: build_alphabet(name="NN")
Non negative integers
sage: build_alphabet(name="lower")
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
sage.combinat.words.alphabet.Alphabet(data=None, names=None, name=None)

Returns an object representing an ordered alphabet.

EXAMPLES:

If the argument is a Set, it just returns it:

sage: build_alphabet(ZZ) is ZZ
True
sage: F = FiniteEnumeratedSet('abc')
sage: build_alphabet(F) is F
True

If a list, tuple or string is provided, then it builds a proper Sage class (TotallyOrderedFiniteSet):

sage: build_alphabet([0,1,2])
{0, 1, 2}
sage: F = build_alphabet('abc'); F
{'a', 'b', 'c'}
sage: print type(F).__name__
TotallyOrderedFiniteSet_with_category

If no data is provided, name may be a string which describe an alphabet. The available names decompose into two families. The first one are ‘positive integers’, ‘PP’, ‘natural numbers’ or ‘NN’ which refer to standard set of numbers:

sage: build_alphabet(name="positive integers")
Positive integers
sage: build_alphabet(name="PP")
Positive integers
sage: build_alphabet(name="natural numbers")
Non negative integers
sage: build_alphabet(name="NN")
Non negative integers

The other families for the option name are among ‘lower’, ‘upper’, ‘space’, ‘underscore’, ‘punctuation’, ‘printable’, ‘binary’, ‘octal’, ‘decimal’, ‘hexadecimal’, ‘radix64’ which refer to standard set of charaters. Theses names may be combined by separating them by a space:

sage: build_alphabet(name="lower")
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
sage: build_alphabet(name="hexadecimal")
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
sage: build_alphabet(name="decimal punctuation")
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', ',', '.', ';', ':', '!', '?'}

In the case the alphabet is built from a list or a tuple, the order on the alphabet is given by the elements themselves:

sage: A = build_alphabet([0,2,1])
sage: A(0) < A(2)
True
sage: A(2) < A(1)
False

If a different order is needed, you may use TotallyOrderedFiniteSet and set the option facade to False. That way, the comparison fits the order of the input:

sage: A = TotallyOrderedFiniteSet([4,2,6,1], facade=False)
sage: A(4) < A(2)
True
sage: A(1) < A(6)
False

Be careful, the element of the set in the last example are no more integers and do not compare equal with integers:

sage: type(A.an_element())
<class 'sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet_with_category.element_class'>
sage: A(1) == 1
False
sage: 1 == A(1)
False
class sage.combinat.words.alphabet.OrderedAlphabet

Bases: object

Warning

Not to be used! (backward compatibility)

Returns a finite or infinite ordered alphabet.

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet
sage: A = OrderedAlphabet('ab'); A
doctest:1: DeprecationWarning: OrderedAlphabet is deprecated; use Alphabet instead.
See http://trac.sagemath.org/8920 for details.
{'a', 'b'}
sage: type(A)
<class 'sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet_with_category'>
sage.combinat.words.alphabet.OrderedAlphabet_Finite

alias of OrderedAlphabet

class sage.combinat.words.alphabet.OrderedAlphabet_backward_compatibility(elements, facade=True)

Bases: sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet

Warning

Not to be used! (backward compatibility)

Version prior to trac ticket #8920 uses classes Alphabet with an argument ._alphabet instead of ._elements used in TotallyOrderedFiniteSet. This class is dedicated to handle this problem which occurs when unpickling OrderedAlphabet.

sage.combinat.words.alphabet.build_alphabet(data=None, names=None, name=None)

Returns an object representing an ordered alphabet.

EXAMPLES:

If the argument is a Set, it just returns it:

sage: build_alphabet(ZZ) is ZZ
True
sage: F = FiniteEnumeratedSet('abc')
sage: build_alphabet(F) is F
True

If a list, tuple or string is provided, then it builds a proper Sage class (TotallyOrderedFiniteSet):

sage: build_alphabet([0,1,2])
{0, 1, 2}
sage: F = build_alphabet('abc'); F
{'a', 'b', 'c'}
sage: print type(F).__name__
TotallyOrderedFiniteSet_with_category

If no data is provided, name may be a string which describe an alphabet. The available names decompose into two families. The first one are ‘positive integers’, ‘PP’, ‘natural numbers’ or ‘NN’ which refer to standard set of numbers:

sage: build_alphabet(name="positive integers")
Positive integers
sage: build_alphabet(name="PP")
Positive integers
sage: build_alphabet(name="natural numbers")
Non negative integers
sage: build_alphabet(name="NN")
Non negative integers

The other families for the option name are among ‘lower’, ‘upper’, ‘space’, ‘underscore’, ‘punctuation’, ‘printable’, ‘binary’, ‘octal’, ‘decimal’, ‘hexadecimal’, ‘radix64’ which refer to standard set of charaters. Theses names may be combined by separating them by a space:

sage: build_alphabet(name="lower")
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
sage: build_alphabet(name="hexadecimal")
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
sage: build_alphabet(name="decimal punctuation")
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', ',', '.', ';', ':', '!', '?'}

In the case the alphabet is built from a list or a tuple, the order on the alphabet is given by the elements themselves:

sage: A = build_alphabet([0,2,1])
sage: A(0) < A(2)
True
sage: A(2) < A(1)
False

If a different order is needed, you may use TotallyOrderedFiniteSet and set the option facade to False. That way, the comparison fits the order of the input:

sage: A = TotallyOrderedFiniteSet([4,2,6,1], facade=False)
sage: A(4) < A(2)
True
sage: A(1) < A(6)
False

Be careful, the element of the set in the last example are no more integers and do not compare equal with integers:

sage: type(A.an_element())
<class 'sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet_with_category.element_class'>
sage: A(1) == 1
False
sage: 1 == A(1)
False

Previous topic

Words

Next topic

Abstract word (finite or infinite)

This Page