Opened 13 years ago

Closed 13 years ago

## #7543 closed enhancement (fixed)

Reported by: Owned by: Sébastien Labbé Sébastien Labbé major sage-4.3.1 combinatorics Vincent Delecroix, Franco Saliola sage-4.3.1.rc1 Sébastien Labbé Vincent Delecroix N/A

The definition of S-adic words is found here :

```    sage: tm = WordMorphism('a->ab,b->ba')
sage: fib = WordMorphism('a->ab,b->a')
sage: from itertools import repeat

One trivial example of infinite s-adic word::

word: abbabaabbaababbabaababbaabbabaabbaababba...

A less trivial infinite s-adic word::

sage: m = WordMorphism({0:tm,1:fib})
sage: tmword = words.ThueMorseWord()
sage: w = m(tmword)
word: abbaababbaabbaabbaababbaababbaabbaababba...

sage: from sage.misc.prandom import randint
sage: def it():
...     while True: yield randint(0,1)
word: abbaabababbaababbaabbaababbaabababbaabba...
```

See the patch for more examples.

### comment:1 Changed 13 years ago by Sébastien Labbé

Status: new → needs_review

### comment:2 Changed 13 years ago by Sébastien Labbé

Owner: changed from Mike Hansen to Sébastien Labbé

I just updated the patch (doctest improvements) :

```    sage: t = words.ThueMorseWord([tm,fib])
word: abbaababbaabbaabbaababbaababbaabbaababba...
```

I am wondering if I should add a `#random` where I use random examples. Sometimes, other computers gets different random sequence of numbers in the doctest routine...

### comment:3 Changed 13 years ago by Sébastien Labbé

I just uploaded the patch. Some more examples. Better doc. The morphisms arguments can now be a callable so that the following works:

```    sage: x = lambda h:WordMorphism({1:[2],2:[3]+[1]*(h+1),3:[3]+[1]*h})
sage: for h in [0,1,2,3]: print h, x(h)
0 WordMorphism: 1->2, 2->31, 3->3
1 WordMorphism: 1->2, 2->311, 3->31
2 WordMorphism: 1->2, 2->3111, 3->311
3 WordMorphism: 1->2, 2->31111, 3->3111
sage: w = Word(lambda n : valuation(n+1, 2) ); w
word: 0102010301020104010201030102010501020103...
sage: s = words.s_adique(w, repeat(3), x); s
word: 3232232232322322322323223223232232232232...
sage: prefixe = s[:10000]
sage: map(prefixe.number_of_factors, range(15))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
sage: [_[i+1] - _[i] for i in range(len(_)-1)]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
```

### comment:4 Changed 13 years ago by Vincent Delecroix

Status: needs_review → positive_review

Hi Sebastien,

I made the following changes in the documentation and the code seems to be OK.

Take care, Vincent

### Changed 13 years ago by Vincent Delecroix

corrections in documentation string

### comment:6 Changed 13 years ago by Sébastien Labbé

Status: positive_review → needs_work

Thanks for the review Vincent. I agree with your changes.

There are two lines that should be keep "s-adiques" : the reference html to pytheas. Will post a patch soon.

### comment:7 Changed 13 years ago by Sébastien Labbé

Status: needs_work → needs_review

Vincent, I let you change the status to positive review.

### comment:8 follow-up:  9 Changed 13 years ago by Sébastien Labbé

I just uploaded the corrections patch because I did some doc and sphinx improvements.

Vincent, can you review those small changes I did?

### Changed 13 years ago by Sébastien Labbé

Applies over the precedent 2 patches.

### comment:9 in reply to:  8 Changed 13 years ago by Vincent Delecroix

Status: needs_review → positive_review

I just uploaded the corrections patch because I did some doc and sphinx improvements.

Vincent, can you review those small changes I did?

The doc is OK. positive review.

### comment:10 Changed 13 years ago by Robert Miller

Status: positive_review → needs_work
```The following tests failed:

sage -t -long devel/sage-main/sage/combinat/words/word_generators.py # 23 doctests failed
sage -t -long devel/sage-main/sage/categories/hopf_algebras_with_basis.py # Segfault
```

### Changed 13 years ago by Sébastien Labbé

Apply only this one.

### comment:11 follow-up:  12 Changed 13 years ago by Sébastien Labbé

Authors: → Sebastien Labbe needs_work → needs_review

Sorry for that. There was something depending on patches at #7520. I commented out the offending line and now it should be fine.

Beware, I folded all patches in the same "final" one.

Needs review again!

### comment:12 in reply to:  11 ; follow-up:  13 Changed 13 years ago by Sébastien Labbé

I commented out the offending line and now it should be fine.

Vincent, to help you make the final review, here is what I changed in the patch to correct the failed doctests (the parameter check doesn't exist yet):

```- kwds['check'] = False
+ #kwds['check'] = False
```

Beware, I folded all patches in the same "final" one.

Needs review again!

### comment:13 in reply to:  12 ; follow-up:  14 Changed 13 years ago by Vincent Delecroix

Status: needs_review → needs_work

In the .identity_morphism() there a big problem with infinite alphabet ! The following will never finish

```sage: W = Words(alphabet=Alphabet(name="NN"))
sage: W.identity_morphism()
```

Anyway, it seems that WordMorphism? is not implemented for infinite alphabet. Could you just raise an Error saying "Not implemented for infinite alphabet" or something like this ?

The rest is OK (I've got no doctesting error with the patch applied on a native 4.3 release)

### Changed 13 years ago by Sébastien Labbé

This patch applies over the above 'final' patch.

### comment:14 in reply to:  13 ; follow-up:  15 Changed 13 years ago by Sébastien Labbé

Status: needs_work → needs_review

Anyway, it seems that WordMorphism? is not implemented for infinite alphabet. Could you just raise an Error saying "Not implemented for infinite alphabet" or something like this ?

Done. Thanks for finding this problem. Needs review again!

### comment:15 in reply to:  14 Changed 13 years ago by Vincent Delecroix

Status: needs_review → positive_review

Knowing that

```sage: timeit('W.size_of_alphabet() not in ZZ')
625 loops, best of 3: 24 µs per loop
sage: timeit('W.size_of_alphabet() is Infinity')
625 loops, best of 3: 3.43 µs per loop
```

We can win 21 micro seconds (at least on my computer) ! As it not important I switch to postive review...

Nice patch this sadic one !

### comment:16 Changed 13 years ago by Robert Miller

Merged in: → sage-4.3.1.rc1 → fixed positive_review → closed

### comment:17 Changed 7 years ago by Frédéric Chapoton

Authors: Sebastien Labbe → Sébastien Labbé
Note: See TracTickets for help on using tickets.