Skip to content

Commit bf801b1

Browse files
author
Release Manager
committed
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
2 parents 5a22cce + 8153dbd commit bf801b1

File tree

12 files changed

+311
-294
lines changed

12 files changed

+311
-294
lines changed

src/sage/combinat/words/abstract_word.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,24 +1476,24 @@ def sum_digits(self, base=2, mod=None):
14761476
14771477
Sum of digits modulo 2 of the prime numbers written in base 2::
14781478
1479-
sage: Word(primes(1000)).sum_digits() # optional - sage.libs.pari
1479+
sage: Word(primes(1000)).sum_digits() # needs sage.libs.pari
14801480
word: 1001110100111010111011001011101110011011...
14811481
14821482
Sum of digits modulo 3 of the prime numbers written in base 3::
14831483
1484-
sage: Word(primes(1000)).sum_digits(base=3) # optional - sage.libs.pari
1484+
sage: Word(primes(1000)).sum_digits(base=3) # needs sage.libs.pari
14851485
word: 2100002020002221222121022221022122111022...
1486-
sage: Word(primes(1000)).sum_digits(base=3, mod=3) # optional - sage.libs.pari
1486+
sage: Word(primes(1000)).sum_digits(base=3, mod=3) # needs sage.libs.pari
14871487
word: 2100002020002221222121022221022122111022...
14881488
14891489
Sum of digits modulo 2 of the prime numbers written in base 3::
14901490
1491-
sage: Word(primes(1000)).sum_digits(base=3, mod=2) # optional - sage.libs.pari
1491+
sage: Word(primes(1000)).sum_digits(base=3, mod=2) # needs sage.libs.pari
14921492
word: 0111111111111111111111111111111111111111...
14931493
14941494
Sum of digits modulo 7 of the prime numbers written in base 10::
14951495
1496-
sage: Word(primes(1000)).sum_digits(base=10, mod=7) # optional - sage.libs.pari
1496+
sage: Word(primes(1000)).sum_digits(base=10, mod=7) # needs sage.libs.pari
14971497
word: 2350241354435041006132432241353546006304...
14981498
14991499
Negative entries::

src/sage/combinat/words/alphabet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ def build_alphabet(data=None, names=None, name=None):
192192
Traceback (most recent call last):
193193
...
194194
ValueError: invalid value for names
195-
sage: Alphabet(8, x) # optional - sage.symbolic
195+
sage: Alphabet(8, x) # needs sage.symbolic
196196
Traceback (most recent call last):
197197
...
198198
ValueError: invalid value for names
199-
sage: Alphabet(name=x, names="punctuation") # optional - sage.symbolic
199+
sage: Alphabet(name=x, names="punctuation") # needs sage.symbolic
200200
Traceback (most recent call last):
201201
...
202202
ValueError: name cannot be specified with any other argument
203-
sage: Alphabet(x) # optional - sage.symbolic
203+
sage: Alphabet(x) # needs sage.symbolic
204204
Traceback (most recent call last):
205205
...
206206
ValueError: unable to construct an alphabet from the given parameters

src/sage/combinat/words/finite_word.py

Lines changed: 52 additions & 50 deletions
Large diffs are not rendered by default.

src/sage/combinat/words/lyndon_word.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def LyndonWords(e=None, k=None):
6464
word: 1112
6565
sage: LW.last()
6666
word: 2333
67-
sage: LW.random_element() # random
67+
sage: LW.random_element() # random # needs sage.libs.pari
6868
word: 1232
69-
sage: LW.cardinality()
69+
sage: LW.cardinality() # needs sage.libs.pari
7070
18
7171
7272
If e is a (weak) composition, then it returns the class of Lyndon
@@ -277,17 +277,17 @@ def cardinality(self):
277277
278278
sage: LyndonWords([]).cardinality()
279279
0
280-
sage: LyndonWords([2,2]).cardinality()
280+
sage: LyndonWords([2,2]).cardinality() # needs sage.libs.pari
281281
1
282-
sage: LyndonWords([2,3,2]).cardinality()
282+
sage: LyndonWords([2,3,2]).cardinality() # needs sage.libs.pari
283283
30
284284
285285
Check to make sure that the count matches up with the number of
286286
Lyndon words generated::
287287
288288
sage: comps = [[],[2,2],[3,2,7],[4,2]] + Compositions(4).list()
289289
sage: lws = [LyndonWords(comp) for comp in comps]
290-
sage: all(lw.cardinality() == len(lw.list()) for lw in lws)
290+
sage: all(lw.cardinality() == len(lw.list()) for lw in lws) # needs sage.libs.pari
291291
True
292292
"""
293293
evaluation = self._e
@@ -417,7 +417,7 @@ def __call__(self, *args, **kwds):
417417
Make sure that the correct length is checked (:trac:`30186`)::
418418
419419
sage: L = LyndonWords(2, 4)
420-
sage: _ = L(L.random_element())
420+
sage: _ = L(L.random_element()) # needs sage.libs.pari
421421
"""
422422
w = self._words(*args, **kwds)
423423
if kwds.get('check', True) and not w.is_lyndon():
@@ -443,7 +443,7 @@ def cardinality(self):
443443
"""
444444
TESTS::
445445
446-
sage: [ LyndonWords(3,i).cardinality() for i in range(1, 11) ]
446+
sage: [ LyndonWords(3,i).cardinality() for i in range(1, 11) ] # needs sage.libs.pari
447447
[3, 3, 8, 18, 48, 116, 312, 810, 2184, 5880]
448448
"""
449449
if self._k == 0:
@@ -470,7 +470,7 @@ def __iter__(self):
470470
sage: sum(1 for lw in LyndonWords(1, 1000))
471471
0
472472
473-
sage: list(LyndonWords(1, 1))
473+
sage: list(LyndonWords(1, 1)) # needs sage.libs.pari
474474
[word: 1]
475475
"""
476476
W = self._words._element_classes['list']

src/sage/combinat/words/morphic.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
Creation of the fixed point of a morphism::
1515
1616
sage: m = WordMorphism('a->abc,b->baba,c->ca')
17-
sage: w = m.fixed_point('a')
18-
sage: w
17+
sage: w = m.fixed_point('a'); w
1918
word: abcbabacababaabcbabaabccaabcbabaabcbabaa...
2019
sage: w.length()
2120
+Infinity
@@ -24,14 +23,16 @@
2423
abstract numeration system associated to the morphism and the starting
2524
letter, see chapter 3 of the book [BR2010b]_::
2625
27-
sage: w[10000000] # optional - sage.modules
26+
sage: w[10000000] # needs sage.modules
2827
'b'
2928
3029
"""
3130

3231
from sage.combinat.words.word_infinite_datatypes import WordDatatype_callable
32+
from sage.misc.lazy_import import lazy_import
3333
from sage.rings.infinity import Infinity
34-
from sage.modules.free_module_element import vector
34+
35+
lazy_import('sage.modules.free_module_element', 'vector')
3536

3637

3738
class WordDatatype_morphic(WordDatatype_callable):
@@ -57,7 +58,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
5758
sage: w = m.fixed_point('a')
5859
sage: w
5960
word: abaababaabaababaababaabaababaabaababaaba...
60-
sage: w[555:1000] # optional - sage.modules
61+
sage: w[555:1000] # needs sage.modules
6162
word: abaababaabaababaababaabaababaabaababaaba...
6263
sage: w.length()
6364
+Infinity
@@ -68,20 +69,19 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
6869
sage: m.fixed_point('a')
6970
word: abcbabacababaabcbabaabccaabcbabaabcbabaa...
7071
sage: w = m.fixed_point('a')
71-
sage: w[7] # optional - sage.modules
72+
sage: w[7] # needs sage.modules
7273
'c'
73-
sage: w[2:7] # optional - sage.modules
74+
sage: w[2:7] # needs sage.modules
7475
word: cbaba
75-
sage: w[500:503] # optional - sage.modules
76+
sage: w[500:503] # needs sage.modules
7677
word: caa
7778
7879
When the morphic word is finite::
7980
8081
sage: m = WordMorphism("a->ab,b->")
81-
sage: w = m.fixed_point("a")
82-
sage: w
82+
sage: w = m.fixed_point("a"); w
8383
word: ab
84-
sage: w[0] # optional - sage.modules
84+
sage: w[0] # needs sage.modules
8585
'a'
8686
sage: w.length()
8787
2
@@ -93,7 +93,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
9393
sage: from sage.combinat.words.morphic import WordDatatype_morphic
9494
sage: coding = {'a':'x', 'b':'y'}
9595
sage: w = WordDatatype_morphic(W, m, 'a', coding=coding)
96-
sage: [w[i] for i in range(10)] # optional - sage.modules
96+
sage: [w[i] for i in range(10)] # needs sage.modules
9797
['x', 'y', 'x', 'x', 'y', 'x', 'y', 'x', 'x', 'y']
9898
9999
TESTS::
@@ -104,9 +104,9 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity):
104104
sage: for _ in range(10000): _ = next(it)
105105
sage: L = [next(it) for _ in range(10)]; L
106106
['d', 'd', 'd', 'c', 'd', 'd', 'd', 'c', 'b', 'a']
107-
sage: w[10000:10010] # optional - sage.modules
107+
sage: w[10000:10010] # needs sage.modules
108108
word: dddcdddcba
109-
sage: list(w[10000:10010]) == L # optional - sage.modules
109+
sage: list(w[10000:10010]) == L # needs sage.modules
110110
True
111111
112112
"""
@@ -177,18 +177,18 @@ def representation(self, n):
177177
178178
sage: m = WordMorphism('a->ab,b->a')
179179
sage: w = m.fixed_point('a')
180-
sage: w.representation(5) # optional - sage.modules
180+
sage: w.representation(5) # needs sage.modules
181181
[1, 0, 0, 0]
182182
183183
When the morphic word is finite::
184184
185185
sage: m = WordMorphism("a->ab,b->,c->cdab,d->dcab")
186186
sage: w = m.fixed_point("a")
187-
sage: w.representation(0) # optional - sage.modules
187+
sage: w.representation(0) # needs sage.modules
188188
[]
189-
sage: w.representation(1) # optional - sage.modules
189+
sage: w.representation(1) # needs sage.modules
190190
[1]
191-
sage: w.representation(2) # optional - sage.modules
191+
sage: w.representation(2) # needs sage.modules
192192
Traceback (most recent call last):
193193
...
194194
IndexError: index (=2) out of range, the fixed point is finite and has length 2
@@ -204,7 +204,7 @@ def representation(self, n):
204204
sage: w = WordDatatype_morphic(W, m, 'a')
205205
sage: type(w)
206206
<class 'sage.combinat.words.morphic.WordDatatype_morphic'>
207-
sage: w.representation(5) # optional - sage.modules
207+
sage: w.representation(5) # needs sage.modules
208208
[1, 0, 0, 0]
209209
"""
210210
letters_to_int = {a:i for (i,a) in enumerate(self._alphabet)}
@@ -255,11 +255,11 @@ def _func(self, key):
255255
256256
sage: m = WordMorphism("a->ab,b->a")
257257
sage: w = m.fixed_point("a")
258-
sage: w[0]
258+
sage: w[0] # needs sage.modules
259259
'a'
260-
sage: w[5]
260+
sage: w[5] # needs sage.modules
261261
'a'
262-
sage: w[10000]
262+
sage: w[10000] # needs sage.modules
263263
'a'
264264
265265
TESTS:
@@ -271,7 +271,7 @@ def _func(self, key):
271271
sage: W = m.domain()
272272
sage: from sage.combinat.words.morphic import WordDatatype_morphic
273273
sage: w = WordDatatype_morphic(W, m, 'a')
274-
sage: w._func(5)
274+
sage: w._func(5) # needs sage.modules
275275
'a'
276276
277277
"""

0 commit comments

Comments
 (0)