Opened 12 years ago

Closed 12 years ago

# Words_over_Alphabet should check the type of input alphabet

Reported by: Owned by: slabbe slabbe major sage-duplicate/invalid/wontfix combinatorics words alphabet sage-combinat

### Description

Do

sage: W=Words('ab')
sage: W.alphabet?

and you get the following help example :

sage: from sage.combinat.words.words import Words_over_Alphabet
sage: W = Words_over_Alphabet([1,2,3])
sage: W.alphabet()
[1, 2, 3]
sage: from sage.combinat.words.words import OrderedAlphabet
sage: W = Words_over_Alphabet(OrderedAlphabet('ab'))
sage: W.alphabet()
Ordered Alphabet ['a', 'b']

The first of the above example is misleading. In fact, it is not usable :

sage: from sage.combinat.words.words import Words_over_Alphabet
sage: W = Words_over_Alphabet([1,2,3])
sage: W.alphabet()
[1, 2, 3]
sage: W([1,1,1,2,1,3])
Traceback (most recent call last):
...
AttributeError: 'list' object has no attribute 'rank'

The problem comes from the fact that Words_over_Alphabet doesn't check the input alphabet before asigning it to self._alphabet(). It should either do alphabet=OrderedAlphabet(alphabet) before or check the type of the input alphabet with a isinstance.

### comment:1 Changed 12 years ago by slabbe

• Owner changed from mhansen to slabbe

### comment:3 Changed 12 years ago by slabbe

This problem was solved by #6519 :

sage: from sage.combinat.words.words import Words_over_Alphabet
sage: W = Words_over_Alphabet([1,2,3])
sage: W.alphabet()
[1, 2, 3]
sage: W([1,1,1,2,1,3])
word: 111213
sage: Y = Words_over_Alphabet('abcde')
sage: Y.alphabet()
'abcde'
sage: Y('abababacde')
word: abababacde

So, I propose that this ticket be closed.

### comment:4 Changed 12 years ago by mvngu

• Milestone changed from sage-4.1.1 to sage-duplicate/invalid/wontfix
• Resolution set to duplicate
• Status changed from new to closed

Closing this as a duplicate of #6519.

Note: See TracTickets for help on using tickets.