Ask Your Question
2

How to define WordMorphism on an infinite alphabet ?

asked 2016-11-17 03:24:55 +0100

lb gravatar image

Let imagine I want to do a substitution on the set of all words written with natural numbers.

Example 1: replace every number with its square.

Example 2: make precise rules for substitution of letter in some finite subset of the alphabet and decide that all other letters will be deleted (replaced with empty).

It's not very clear for me from the doc whether this is actually allowed with the command WordMorphism, but if it is, I would like to understand how to do it.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2016-11-17 10:20:44 +0100

tmonteil gravatar image

updated 2016-11-17 11:58:20 +0100

Your first example is unfortunately currently impossible with WordMorphism, since the map is supposed to be a dict. I quickly tried to hack self._morph with lambda functions and ad_hoc objects with __getitem__ method, but the implications with the other methods are too intricate to work easily (in particular, some of them iterate over all the items).

For your second example, you can trick with defaultdict as follows, by starting with a trivial wordmorphism and change its _morph attribute by hand:

sage: from collections import defaultdict
sage: W = Words(NN)
sage: m = WordMorphism(data={},domain=W,codomain=W)
sage: m
WordMorphism: 
sage: m._morph = defaultdict(W)
sage: m._morph[1] = W([12,34])
sage: m._morph[3] = W([42,42,42])
sage: m
WordMorphism: 1->12,34, 3->42,42,42
sage: m([1,2,3,4,5,7])
word: 12,34,42,42,42
sage: m
WordMorphism: 1->12,34, 2->, 3->42,42,42, 4->, 5->, 7->

What do you want to do more precisely with such morphisms ? Perhaps do you only need a few features that can be implemented automomously, without using wordmorphism at all.

edit flag offensive delete link more

Comments

Thank you very much for the detailed answer. I am sorry I did not replied earlier. Actually I expected an email would tell me when my question is answered.
I was using word and WordMorphism for my teaching, as an example, I am not planning to use it further for the moment, but will keep in mind the trick with default dictionary for my course next year (if I am lucky enough to have the same course again next year).

lb gravatar imagelb ( 2016-12-14 23:52:25 +0100 )edit

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: 2016-11-17 03:24:55 +0100

Seen: 295 times

Last updated: Nov 17 '16