Ask Your Question

Revision history [back]

Yes and no. You can always recode your word on a larger alphabet and apply a substitution on this larger alphabet. For your example

sage: W = Words('abc')
sage: w = W('abbabacacabcabcaacabcbac')
sage: WW = Words('abcA')
sage: ww = WW(['A' if w[i] == 'a' and i > 0 and w[i-1] == 'b' and i < len(w)-1 and w[i+1] == 'c' else w[i] for i in range(len(w))])
sage: ww
word: abbabAcacabcabcaacabcbAc
sage: f = WordMorphism('a->a,b->b,c->c,A->ab', domain=WW, codomain=W)
sage: f(ww)
word: abbababcacabcabcaacabcbabc