Alphabets

AUTHORS:

  • Franco Saliola (2008-12-17) : merged into sage

EXAMPLES:

sage: Alphabet("ab")
Ordered Alphabet ['a', 'b']
sage: Alphabet([0,1,2])
Ordered Alphabet [0, 1, 2]
sage: Alphabet(name="PP")
Ordered Alphabet of Positive Integers
sage: Alphabet(name="NN")
Ordered Alphabet of Natural Numbers
sage.combinat.words.alphabet.Alphabet(data=None, name=None)

Returns an object representing an ordered alphabet.

EXAMPLES:

sage: Alphabet("ab")
Ordered Alphabet ['a', 'b']
sage: Alphabet([0,1,2])
Ordered Alphabet [0, 1, 2]
sage: Alphabet(name="positive integers")
Ordered Alphabet of Positive Integers
sage: Alphabet(name="PP")
Ordered Alphabet of Positive Integers
sage: Alphabet(name="natural numbers")
Ordered Alphabet of Natural Numbers
sage: Alphabet(name="NN")
Ordered Alphabet of Natural Numbers
sage.combinat.words.alphabet.OrderedAlphabet(data=None, name=None)

Returns an object representing an ordered alphabet.

EXAMPLES:

sage: Alphabet("ab")
Ordered Alphabet ['a', 'b']
sage: Alphabet([0,1,2])
Ordered Alphabet [0, 1, 2]
sage: Alphabet(name="positive integers")
Ordered Alphabet of Positive Integers
sage: Alphabet(name="PP")
Ordered Alphabet of Positive Integers
sage: Alphabet(name="natural numbers")
Ordered Alphabet of Natural Numbers
sage: Alphabet(name="NN")
Ordered Alphabet of Natural Numbers
class sage.combinat.words.alphabet.OrderedAlphabet_Finite(alphabet)

Bases: sage.combinat.words.alphabet.OrderedAlphabet_class

rank(letter)

Returns the index of letter in self.

INPUT:

  • letter - a letter contained in this alphabet

OUTPUT:

integer – the integer mapping for the letter

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_Finite
sage: OrderedAlphabet_Finite('abcd').rank('a')
0
sage: OrderedAlphabet_Finite('abcd').rank('d')
3
sage: OrderedAlphabet_Finite('abcd').rank('e')
...
IndexError: letter not in alphabet: 'e'
sage: OrderedAlphabet_Finite('abcd').rank('')
...
IndexError: letter not in alphabet: ''
unrank(n)

Returns the letter in position n of the alphabet self.

INPUT:

  • n - a nonnegative integer

OUTPUT:

letter – the (n+1)-th object output by iter(self)

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_Finite
sage: OrderedAlphabet_Finite('abcd').unrank(0)
'a'
sage: OrderedAlphabet_Finite('abcd').unrank(3)
'd'
sage: OrderedAlphabet_Finite('abcd').unrank(5)
...
IndexError: list index out of range
class sage.combinat.words.alphabet.OrderedAlphabet_Infinite(category=None, *keys, **opts)

Bases: sage.combinat.words.alphabet.OrderedAlphabet_class

cardinality()

Returns the number of elements in self.

OUTPUT:

+Infinity

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_Infinite
sage: OrderedAlphabet_Infinite().cardinality()
+Infinity
list()

Returns NotImplementedError since we cannot list all the nonnegative integers.

TESTS:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_Infinite
sage: OrderedAlphabet_Infinite().list()
...
NotImplementedError
class sage.combinat.words.alphabet.OrderedAlphabet_NaturalNumbers(category=None, *keys, **opts)

Bases: sage.combinat.words.alphabet.OrderedAlphabet_Infinite

The alphabet of nonnegative integers, ordered in the usual way.

TESTS:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_NaturalNumbers
sage: NN = OrderedAlphabet_NaturalNumbers()
sage: NN == loads(dumps(NN))
True
next(n)

Returns the letter following n in the alphabet self.

INPUT:

  • n - nonnegative integer

OUTPUT:

n+1

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_NaturalNumbers
sage: NN = OrderedAlphabet_NaturalNumbers()
sage: NN.next(0)
1
sage: NN.next(117)
118
sage: NN.next(-1)
...
ValueError: letter(=-1) not in the alphabet
rank(letter)

Returns the index of letter in self.

INPUT:

  • letter - a letter contained in this alphabet

OUTPUT:

integer – the integer mapping for the letter

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_NaturalNumbers
sage: NN = OrderedAlphabet_NaturalNumbers()
sage: NN.rank(0)
0
sage: NN.rank(17)
17

TESTS:

sage: NN.rank(-1)
...
ValueError: letter(=-1) not in the alphabet
sage: NN.rank("a")
...
ValueError: letter(=a) not in the alphabet
unrank(n)

Returns the letter in position n in self, which in this case is n.

INPUT:

  • n - nonnegative integer

OUTPUT:

  • n - nonnegative integer

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_NaturalNumbers
sage: NN = OrderedAlphabet_NaturalNumbers()
sage: NN.unrank(0)
0
sage: NN.unrank(17)
17

TESTS:

sage: NN.unrank(-1)
...
ValueError: -1 is not a nonnegative integer
sage: NN.unrank("a")
...
ValueError: a is not a nonnegative integer
class sage.combinat.words.alphabet.OrderedAlphabet_PositiveIntegers(category=None, *keys, **opts)

Bases: sage.combinat.words.alphabet.OrderedAlphabet_Infinite

The alphabet of nonnegative integers, ordered in the usual way.

TESTS:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_PositiveIntegers
sage: PP = OrderedAlphabet_PositiveIntegers()
sage: PP == loads(dumps(PP))
True
next(n)

Returns the letter following n in the alphabet self.

INPUT:

  • n - positive integer

OUTPUT:

n+1

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_PositiveIntegers
sage: PP = OrderedAlphabet_PositiveIntegers()
sage: PP.next(1)
2
sage: PP.next(117)
118
sage: PP.next(0)
...
ValueError: letter(=0) not in the alphabet
rank(letter)

Returns the index of letter in self.

INPUT:

  • letter - a positive integer

OUTPUT:

letter-1

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_PositiveIntegers
sage: OrderedAlphabet_PositiveIntegers().rank(1)
0
sage: OrderedAlphabet_PositiveIntegers().rank(8)
7

TESTS:

sage: OrderedAlphabet_PositiveIntegers().rank(-1)
...
TypeError: -1 not in alphabet
unrank(i)

Returns the i-th letter in self, where the first letter is the 0-th letter.

INPUT:

  • i - an integer

OUTPUT:

i+1

EXAMPLES:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_PositiveIntegers
sage: OrderedAlphabet_PositiveIntegers().unrank(0)
1
sage: OrderedAlphabet_PositiveIntegers().unrank(7)
8
class sage.combinat.words.alphabet.OrderedAlphabet_class(category=None, *keys, **opts)

Bases: sage.combinat.combinat.CombinatorialClass

Generic class for ordered alphabets.

string_rep()

Returns the string representation of the alphabet.

TESTS:

sage: from sage.combinat.words.alphabet import OrderedAlphabet_Finite
sage: OrderedAlphabet_Finite([1, 3, 2]).string_rep()
doctest:1: DeprecationWarning: string_rep is deprecated, use __repr__ instead!
'Ordered Alphabet [1, 3, 2]'

Previous topic

Words

Next topic

Abstract word (finite or infinite)

This Page