diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index fe77b50fcfd..fae124378a8 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -2092,6 +2092,15 @@ def language(self, n, u=None): ... word: 1010010001, word: 1010010100] + + Test non-extendable D0L-language (Thue-Morse with cube axiom). + This ensures factors from the axiom and early iterations are included:: + + sage: m = WordMorphism('0->01,1->10') + sage: Word('000') in m.language(3, Word('000')) + True + sage: Word('010101') in m.language(6, Word('000')) + True """ W = self.domain() if self.codomain() != W: @@ -2123,10 +2132,19 @@ def language(self, n, u=None): # of two letter words L2 = (w for w in self._language_naive(3, u) if len(w) == 2) L = set() - for u in L2: - v = im[u[0]] + im[u[1]] + for v in L2: + w = im[v[0]] + im[v[1]] + for k in range(len(w) - n + 1): + L.add(w[k:k + n]) + + # Also add factors from the axiom and early iterations + # to handle non-extendable elements in the D0L-language + v = u + for _ in range(p + 1): for k in range(len(v) - n + 1): L.add(v[k:k + n]) + v = self(v) + return L def conjugate(self, pos):