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
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
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
Bases: sage.combinat.words.alphabet.OrderedAlphabet_class
Returns the index of letter in self.
INPUT:
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: ''
Returns the letter in position n of the alphabet self.
INPUT:
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
Bases: sage.combinat.words.alphabet.OrderedAlphabet_class
Returns the number of elements in self.
OUTPUT:
+Infinity
EXAMPLES:
sage: from sage.combinat.words.alphabet import OrderedAlphabet_Infinite
sage: OrderedAlphabet_Infinite().cardinality()
+Infinity
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
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
Returns the letter following n in the alphabet self.
INPUT:
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
Returns the index of letter in self.
INPUT:
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
Returns the letter in position n in self, which in this case is n.
INPUT:
OUTPUT:
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
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
Returns the letter following n in the alphabet self.
INPUT:
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
Returns the index of letter in self.
INPUT:
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
Returns the i-th letter in self, where the first letter is the 0-th letter.
INPUT:
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
Bases: sage.combinat.combinat.CombinatorialClass
Generic class for ordered alphabets.
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]'