First time here? Check out the FAQ!

Ask Your Question
0

Is there a way to have Context Sensitive Morphisms?

asked 6 years ago

Chernoxyl gravatar image

updated 6 years ago

I be been using WordMorphism and I was wondering if there is a way to have context sensitive substitutions?

An example would be b”a”c -> ab so a is replaced iff bac appears.

WordMorphism(“bac->ab”)
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 6 years ago

vdelecroix gravatar image

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
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 264 times

Last updated: Jul 08 '18