Ask Your Question

Revision history [back]

The module was created in 2007 during the translation by Mike Hansen of 30k lines of code from Mupad-Combinat to sage. Around the same time, in 2008, the module sage/combinat/words was created and nothing has ever been done to merge the two.

Notice that the code in is based on itertools.combinations and no wiser algorithm is coded to enumerate distinct subwords.

sage: s = Subwords('aaaaa', 3)
sage: s.__iter__??
       iterator = itertools.combinations(self._w, self._k)
sage: list(s)
['aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa', 'aaa']

If you know the existence of a better algorithm, you are welcome to add it to the file which contains already 3 methods related to subwords:

sage: w = Word('abc')
sage: w.*subword*?