Ask Your Question

Revision history [back]

The module subword.py 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 subword.py 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 finite_word.py file which contains already 3 methods related to subwords:

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