Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gh-36644: `sage.combinat.words`: Update `# needs`
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
- Cherry-picked from #35095
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #36644
Reported by: Matthias Köppe
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Dec 4, 2023
2 parents 5a22cce + 8153dbd commit bf801b1
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 294 deletions.
10 changes: 5 additions & 5 deletions src/sage/combinat/words/abstract_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,24 +1476,24 @@ def sum_digits(self, base=2, mod=None):
Sum of digits modulo 2 of the prime numbers written in base 2::
sage: Word(primes(1000)).sum_digits() # optional - sage.libs.pari
sage: Word(primes(1000)).sum_digits() # needs sage.libs.pari
word: 1001110100111010111011001011101110011011...
Sum of digits modulo 3 of the prime numbers written in base 3::
sage: Word(primes(1000)).sum_digits(base=3) # optional - sage.libs.pari
sage: Word(primes(1000)).sum_digits(base=3) # needs sage.libs.pari
word: 2100002020002221222121022221022122111022...
sage: Word(primes(1000)).sum_digits(base=3, mod=3) # optional - sage.libs.pari
sage: Word(primes(1000)).sum_digits(base=3, mod=3) # needs sage.libs.pari
word: 2100002020002221222121022221022122111022...
Sum of digits modulo 2 of the prime numbers written in base 3::
sage: Word(primes(1000)).sum_digits(base=3, mod=2) # optional - sage.libs.pari
sage: Word(primes(1000)).sum_digits(base=3, mod=2) # needs sage.libs.pari
word: 0111111111111111111111111111111111111111...
Sum of digits modulo 7 of the prime numbers written in base 10::
sage: Word(primes(1000)).sum_digits(base=10, mod=7) # optional - sage.libs.pari
sage: Word(primes(1000)).sum_digits(base=10, mod=7) # needs sage.libs.pari
word: 2350241354435041006132432241353546006304...
Negative entries::
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/words/alphabet.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ def build_alphabet(data=None, names=None, name=None):
Traceback (most recent call last):
...
ValueError: invalid value for names
sage: Alphabet(8, x) # optional - sage.symbolic
sage: Alphabet(8, x) # needs sage.symbolic
Traceback (most recent call last):
...
ValueError: invalid value for names
sage: Alphabet(name=x, names="punctuation") # optional - sage.symbolic
sage: Alphabet(name=x, names="punctuation") # needs sage.symbolic
Traceback (most recent call last):
...
ValueError: name cannot be specified with any other argument
sage: Alphabet(x) # optional - sage.symbolic
sage: Alphabet(x) # needs sage.symbolic
Traceback (most recent call last):
...
ValueError: unable to construct an alphabet from the given parameters
Expand Down
102 changes: 52 additions & 50 deletions src/sage/combinat/words/finite_word.py

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/sage/combinat/words/lyndon_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def LyndonWords(e=None, k=None):
word: 1112
sage: LW.last()
word: 2333
sage: LW.random_element() # random
sage: LW.random_element() # random # needs sage.libs.pari
word: 1232
sage: LW.cardinality()
sage: LW.cardinality() # needs sage.libs.pari
18
If e is a (weak) composition, then it returns the class of Lyndon
Expand Down Expand Up @@ -277,17 +277,17 @@ def cardinality(self):
sage: LyndonWords([]).cardinality()
0
sage: LyndonWords([2,2]).cardinality()
sage: LyndonWords([2,2]).cardinality() # needs sage.libs.pari
1
sage: LyndonWords([2,3,2]).cardinality()
sage: LyndonWords([2,3,2]).cardinality() # needs sage.libs.pari
30
Check to make sure that the count matches up with the number of
Lyndon words generated::
sage: comps = [[],[2,2],[3,2,7],[4,2]] + Compositions(4).list()
sage: lws = [LyndonWords(comp) for comp in comps]
sage: all(lw.cardinality() == len(lw.list()) for lw in lws)
sage: all(lw.cardinality() == len(lw.list()) for lw in lws) # needs sage.libs.pari
True
"""
evaluation = self._e
Expand Down Expand Up @@ -417,7 +417,7 @@ def __call__(self, *args, **kwds):
Make sure that the correct length is checked (:trac:`30186`)::
sage: L = LyndonWords(2, 4)
sage: _ = L(L.random_element())
sage: _ = L(L.random_element()) # needs sage.libs.pari
"""
w = self._words(*args, **kwds)
if kwds.get('check', True) and not w.is_lyndon():
Expand All @@ -443,7 +443,7 @@ def cardinality(self):
"""
TESTS::
sage: [ LyndonWords(3,i).cardinality() for i in range(1, 11) ]
sage: [ LyndonWords(3,i).cardinality() for i in range(1, 11) ] # needs sage.libs.pari
[3, 3, 8, 18, 48, 116, 312, 810, 2184, 5880]
"""
if self._k == 0:
Expand All @@ -470,7 +470,7 @@ def __iter__(self):
sage: sum(1 for lw in LyndonWords(1, 1000))
0
sage: list(LyndonWords(1, 1))
sage: list(LyndonWords(1, 1)) # needs sage.libs.pari
[word: 1]
"""
W = self._words._element_classes['list']
Expand Down
46 changes: 23 additions & 23 deletions src/sage/combinat/words/morphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
Creation of the fixed point of a morphism::
sage: m = WordMorphism('a->abc,b->baba,c->ca')
sage: w = m.fixed_point('a')
sage: w
sage: w = m.fixed_point('a'); w
word: abcbabacababaabcbabaabccaabcbabaabcbabaa...
sage: w.length()
+Infinity
Expand All @@ -24,14 +23,16 @@
abstract numeration system associated to the morphism and the starting
letter, see chapter 3 of the book [BR2010b]_::
sage: w[10000000] # optional - sage.modules
sage: w[10000000] # needs sage.modules
'b'
"""

from sage.combinat.words.word_infinite_datatypes import WordDatatype_callable
from sage.misc.lazy_import import lazy_import
from sage.rings.infinity import Infinity
from sage.modules.free_module_element import vector

lazy_import('sage.modules.free_module_element', 'vector')


class WordDatatype_morphic(WordDatatype_callable):
Expand All @@ -57,7 +58,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
sage: w = m.fixed_point('a')
sage: w
word: abaababaabaababaababaabaababaabaababaaba...
sage: w[555:1000] # optional - sage.modules
sage: w[555:1000] # needs sage.modules
word: abaababaabaababaababaabaababaabaababaaba...
sage: w.length()
+Infinity
Expand All @@ -68,20 +69,19 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
sage: m.fixed_point('a')
word: abcbabacababaabcbabaabccaabcbabaabcbabaa...
sage: w = m.fixed_point('a')
sage: w[7] # optional - sage.modules
sage: w[7] # needs sage.modules
'c'
sage: w[2:7] # optional - sage.modules
sage: w[2:7] # needs sage.modules
word: cbaba
sage: w[500:503] # optional - sage.modules
sage: w[500:503] # needs sage.modules
word: caa
When the morphic word is finite::
sage: m = WordMorphism("a->ab,b->")
sage: w = m.fixed_point("a")
sage: w
sage: w = m.fixed_point("a"); w
word: ab
sage: w[0] # optional - sage.modules
sage: w[0] # needs sage.modules
'a'
sage: w.length()
2
Expand All @@ -93,7 +93,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
sage: from sage.combinat.words.morphic import WordDatatype_morphic
sage: coding = {'a':'x', 'b':'y'}
sage: w = WordDatatype_morphic(W, m, 'a', coding=coding)
sage: [w[i] for i in range(10)] # optional - sage.modules
sage: [w[i] for i in range(10)] # needs sage.modules
['x', 'y', 'x', 'x', 'y', 'x', 'y', 'x', 'x', 'y']
TESTS::
Expand All @@ -104,9 +104,9 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
sage: for _ in range(10000): _ = next(it)
sage: L = [next(it) for _ in range(10)]; L
['d', 'd', 'd', 'c', 'd', 'd', 'd', 'c', 'b', 'a']
sage: w[10000:10010] # optional - sage.modules
sage: w[10000:10010] # needs sage.modules
word: dddcdddcba
sage: list(w[10000:10010]) == L # optional - sage.modules
sage: list(w[10000:10010]) == L # needs sage.modules
True
"""
Expand Down Expand Up @@ -177,18 +177,18 @@ def representation(self, n):
sage: m = WordMorphism('a->ab,b->a')
sage: w = m.fixed_point('a')
sage: w.representation(5) # optional - sage.modules
sage: w.representation(5) # needs sage.modules
[1, 0, 0, 0]
When the morphic word is finite::
sage: m = WordMorphism("a->ab,b->,c->cdab,d->dcab")
sage: w = m.fixed_point("a")
sage: w.representation(0) # optional - sage.modules
sage: w.representation(0) # needs sage.modules
[]
sage: w.representation(1) # optional - sage.modules
sage: w.representation(1) # needs sage.modules
[1]
sage: w.representation(2) # optional - sage.modules
sage: w.representation(2) # needs sage.modules
Traceback (most recent call last):
...
IndexError: index (=2) out of range, the fixed point is finite and has length 2
Expand All @@ -204,7 +204,7 @@ def representation(self, n):
sage: w = WordDatatype_morphic(W, m, 'a')
sage: type(w)
<class 'sage.combinat.words.morphic.WordDatatype_morphic'>
sage: w.representation(5) # optional - sage.modules
sage: w.representation(5) # needs sage.modules
[1, 0, 0, 0]
"""
letters_to_int = {a:i for (i,a) in enumerate(self._alphabet)}
Expand Down Expand Up @@ -255,11 +255,11 @@ def _func(self, key):
sage: m = WordMorphism("a->ab,b->a")
sage: w = m.fixed_point("a")
sage: w[0]
sage: w[0] # needs sage.modules
'a'
sage: w[5]
sage: w[5] # needs sage.modules
'a'
sage: w[10000]
sage: w[10000] # needs sage.modules
'a'
TESTS:
Expand All @@ -271,7 +271,7 @@ def _func(self, key):
sage: W = m.domain()
sage: from sage.combinat.words.morphic import WordDatatype_morphic
sage: w = WordDatatype_morphic(W, m, 'a')
sage: w._func(5)
sage: w._func(5) # needs sage.modules
'a'
"""
Expand Down
Loading

0 comments on commit bf801b1

Please sign in to comment.