From 02a8c740cc0ca9d0b6b255b52f4fa7dd10ff8d09 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 25 May 2023 17:51:07 -0700 Subject: [PATCH 1/9] sage.combinat: Modularization fixes for imports --- src/sage/combinat/words/suffix_trees.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index 5e4fa13ddea..59b3acb57d3 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -13,12 +13,15 @@ from itertools import chain from sage.structure.sage_object import SageObject -from sage.graphs.digraph import DiGraph from sage.sets.set import Set from sage.combinat.words.words import Words from sage.combinat.words.word import Word +from sage.misc.lazy_import import lazy_import from sage.rings.integer import Integer +lazy_import('sage.graphs.digraph', 'DiGraph') + + ################################################################################ # Suffix Tries ################################################################################ From d281815ebf8c330cd8d7b885dc5e2d8f16b8b16e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 3 Jun 2023 16:59:56 -0700 Subject: [PATCH 2/9] sage.combinat: Modularization fixes --- src/sage/combinat/words/finite_word.py | 5 +++-- src/sage/combinat/words/morphic.py | 10 +++++----- src/sage/combinat/words/morphism.py | 8 +++++--- src/sage/combinat/words/word.py | 4 +++- src/sage/combinat/words/word_generators.py | 4 +++- src/sage/combinat/words/words.py | 4 ++-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index bf355d9d10a..b5bb427373c 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -221,6 +221,7 @@ from sage.combinat.words.abstract_word import Word_class from sage.combinat.words.words import Words from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.combinat.words.word_options import word_options from sage.rings.infinity import Infinity from sage.rings.integer import Integer @@ -228,6 +229,8 @@ from sage.rings.rational_field import QQ from sage.sets.set import Set +lazy_import('sage.groups.perm_gps.permgroup_element', 'PermutationGroupElement') + class FiniteWord_class(Word_class): def __str__(self): @@ -6752,7 +6755,6 @@ def apply_permutation_to_positions(self, permutation): word: 3421 """ from sage.combinat.permutation import Permutation - from sage.groups.perm_gps.permgroup_element import PermutationGroupElement if not isinstance(permutation, Permutation): if isinstance(permutation, PermutationGroupElement): permutation = Permutation(permutation.domain()) @@ -6781,7 +6783,6 @@ def apply_permutation_to_letters(self, permutation): word: badc """ from sage.combinat.permutation import Permutation - from sage.groups.perm_gps.permgroup_element import PermutationGroupElement if not isinstance(permutation, Permutation): if isinstance(permutation, PermutationGroupElement): permutation = Permutation(permutation.domain()) diff --git a/src/sage/combinat/words/morphic.py b/src/sage/combinat/words/morphic.py index 389c37a9b65..d5c447403d0 100644 --- a/src/sage/combinat/words/morphic.py +++ b/src/sage/combinat/words/morphic.py @@ -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 @@ -30,8 +29,10 @@ """ 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', 'import vector') class WordDatatype_morphic(WordDatatype_callable): @@ -78,8 +79,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): 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 'a' diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 7e04e8646d0..e618ccbdaeb 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -93,17 +93,19 @@ from sage.misc.callable_dict import CallableDict from sage.structure.sage_object import SageObject from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.misc.lazy_list import lazy_list from sage.sets.set import Set from sage.rings.rational_field import QQ from sage.rings.infinity import Infinity from sage.rings.integer_ring import IntegerRing from sage.rings.integer import Integer -from sage.modules.free_module_element import vector -from sage.matrix.constructor import Matrix from sage.combinat.words.word import FiniteWord_class from sage.combinat.words.words import FiniteWords, FiniteOrInfiniteWords +lazy_import('sage.modules.free_module_element', 'vector') +lazy_import('sage.matrix.constructor', 'Matrix') + def get_cycles(f, domain): r""" @@ -2084,7 +2086,7 @@ def language(self, n, u=None): A growing but non-primitive example. The DOL-languages generated by 0 and 2 are different:: - sage: s = WordMorphism({0: [0,1], 1:[0], 2:[2,0,2]}) + sage: s = WordMorphism({0: [0,1], 1: [0], 2: [2,0,2]}) sage: u = s.fixed_point(0) sage: A0 = u[:200].factor_set(5) diff --git a/src/sage/combinat/words/word.py b/src/sage/combinat/words/word.py index 4555c2df762..320bc3d9f0c 100644 --- a/src/sage/combinat/words/word.py +++ b/src/sage/combinat/words/word.py @@ -23,6 +23,7 @@ # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** +from sage.misc.lazy_import import lazy_import from sage.combinat.words.word_char import WordDatatype_char from sage.combinat.words.abstract_word import Word_class from sage.combinat.words.finite_word import FiniteWord_class @@ -36,7 +37,8 @@ WordDatatype_callable_with_caching, WordDatatype_callable) from .morphic import WordDatatype_morphic -from sage.monoids.free_monoid_element import FreeMonoidElement + +lazy_import('sage.monoids.free_monoid_element', 'FreeMonoidElement') # TODO. Word needs to be replaced by Word. Consider renaming # Word_class to Word and imbedding Word as its __call__ method. diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index d7093ae997c..e21ab9a22b4 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -59,7 +59,6 @@ from random import randint from sage.misc.cachefunc import cached_method from sage.rings.integer_ring import ZZ -from sage.rings.real_mpfr import RR from sage.rings.infinity import Infinity from sage.combinat.words.abstract_word import Word_class from sage.combinat.words.word import FiniteWord_list @@ -68,6 +67,9 @@ from sage.combinat.words.morphism import WordMorphism from sage.arith.misc import gcd from sage.misc.decorators import rename_keyword +from sage.misc.lazy_import import lazy_import + +lazy_import('sage.rings.real_mpfr', 'RR') def _build_tab(sym, tab, W): diff --git a/src/sage/combinat/words/words.py b/src/sage/combinat/words/words.py index 63d6f1f0d05..8c23a452bc7 100644 --- a/src/sage/combinat/words/words.py +++ b/src/sage/combinat/words/words.py @@ -1973,7 +1973,7 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: p.length() # optional - sage.modules 100 - Creation of a word path from a FiniteWord_callable:: + Creation of a word path from a :class:`FiniteWord_callable`:: sage: g = Word(lambda n: n%2, length=100) sage: P = WordPaths([0,1,2,3]) # optional - sage.modules @@ -1984,7 +1984,7 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr Creation of a word from a pickled function:: - sage: f = lambda n : n % 10 + sage: f = lambda n: n % 10 sage: from sage.misc.fpickle import pickle_function sage: s = pickle_function(f) sage: Word(s, datatype='pickled_function') From 4696b3d27464ab5dab1d0321757a605b161a6914 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 8 Jun 2023 18:33:43 -0700 Subject: [PATCH 3/9] sage.combinat: More # optional --- src/sage/combinat/words/finite_word.py | 6 +++--- src/sage/combinat/words/lyndon_word.py | 16 ++++++++-------- src/sage/combinat/words/morphic.py | 8 ++++---- src/sage/combinat/words/morphism.py | 26 +++++++++++++------------- src/sage/combinat/words/word_char.pyx | 4 ++-- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index b5bb427373c..bdb182ac6b9 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -1676,7 +1676,7 @@ def reduced_rauzy_graph(self, n): For ultimately periodic words:: sage: sigma = WordMorphism('a->abcd,b->cd,c->cd,d->cd') - sage: w = sigma.fixed_point('a')[:100]; w + sage: w = sigma.fixed_point('a')[:100]; w # optional - sage.modules word: abcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd... sage: g = w.reduced_rauzy_graph(5) # optional - sage.graphs sage: g.vertices(sort=True) # optional - sage.graphs @@ -6749,7 +6749,7 @@ def apply_permutation_to_positions(self, permutation): word: badc sage: w.apply_permutation_to_positions(Permutation([2,1,4,3])) word: badc - sage: w.apply_permutation_to_positions(PermutationGroupElement([2,1,4,3])) + sage: w.apply_permutation_to_positions(PermutationGroupElement([2,1,4,3])) # optional - sage.groups word: badc sage: Word([1,2,3,4]).apply_permutation_to_positions([3,4,2,1]) word: 3421 @@ -6779,7 +6779,7 @@ def apply_permutation_to_letters(self, permutation): word: dcba sage: w.apply_permutation_to_letters(Permutation(p)) word: badc - sage: w.apply_permutation_to_letters(PermutationGroupElement(p)) + sage: w.apply_permutation_to_letters(PermutationGroupElement(p)) # optional - sage.groups word: badc """ from sage.combinat.permutation import Permutation diff --git a/src/sage/combinat/words/lyndon_word.py b/src/sage/combinat/words/lyndon_word.py index 6adb96421e5..575d68c58bc 100644 --- a/src/sage/combinat/words/lyndon_word.py +++ b/src/sage/combinat/words/lyndon_word.py @@ -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 # optional - sage.libs.pari word: 1232 - sage: LW.cardinality() + sage: LW.cardinality() # optional - sage.libs.pari 18 If e is a (weak) composition, then it returns the class of Lyndon @@ -277,9 +277,9 @@ def cardinality(self): sage: LyndonWords([]).cardinality() 0 - sage: LyndonWords([2,2]).cardinality() + sage: LyndonWords([2,2]).cardinality() # optional - sage.libs.pari 1 - sage: LyndonWords([2,3,2]).cardinality() + sage: LyndonWords([2,3,2]).cardinality() # optional - sage.libs.pari 30 Check to make sure that the count matches up with the number of @@ -287,7 +287,7 @@ def cardinality(self): 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) # optional - sage.libs.pari True """ evaluation = self._e @@ -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()) # optional - sage.libs.pari """ w = self._words(*args, **kwds) if kwds.get('check', True) and not w.is_lyndon(): @@ -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) ] # optional - sage.libs.pari [3, 3, 8, 18, 48, 116, 312, 810, 2184, 5880] """ if self._k == 0: @@ -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)) # optional - sage.libs.pari [word: 1] """ W = self._words._element_classes['list'] diff --git a/src/sage/combinat/words/morphic.py b/src/sage/combinat/words/morphic.py index d5c447403d0..96390756bfb 100644 --- a/src/sage/combinat/words/morphic.py +++ b/src/sage/combinat/words/morphic.py @@ -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] # optional - sage.modules 'a' - sage: w[5] + sage: w[5] # optional - sage.modules 'a' - sage: w[10000] + sage: w[10000] # optional - sage.modules 'a' TESTS: @@ -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) # optional - sage.modules 'a' """ diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index e618ccbdaeb..e46f7f9d075 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -1590,25 +1590,25 @@ def is_primitive(self): EXAMPLES:: sage: tm = WordMorphism('a->ab,b->ba') - sage: tm.is_primitive() + sage: tm.is_primitive() # optional - sage.modules True sage: fibo = WordMorphism('a->ab,b->a') - sage: fibo.is_primitive() + sage: fibo.is_primitive() # optional - sage.modules True sage: m = WordMorphism('a->bb,b->aa') - sage: m.is_primitive() + sage: m.is_primitive() # optional - sage.modules False sage: f = WordMorphism({0:[1],1:[0]}) - sage: f.is_primitive() + sage: f.is_primitive() # optional - sage.modules False :: sage: s = WordMorphism('a->b,b->c,c->ab') - sage: s.is_primitive() + sage: s.is_primitive() # optional - sage.modules True sage: s = WordMorphism('a->b,b->c,c->d,d->e,e->f,f->g,g->h,h->ab') - sage: s.is_primitive() + sage: s.is_primitive() # optional - sage.modules True TESTS:: @@ -1618,8 +1618,8 @@ def is_primitive(self): Traceback (most recent call last): ... TypeError: self (=a->bb, b->aac) is not an endomorphism - sage: m = WordMorphism('a->,b->',codomain=Words('ab')) - sage: m.is_primitive() + sage: m = WordMorphism('a->,b->', codomain=Words('ab')) + sage: m.is_primitive() # optional - sage.modules False sage: m = WordMorphism('a->,b->') sage: m.is_primitive() @@ -1683,9 +1683,9 @@ def is_prolongable(self, letter): :: - sage: n0, n1 = matrix(2,[1,1,1,0]), matrix(2,[2,1,1,0]) - sage: n = {'a':n0, 'b':n1} - sage: WordMorphism(n).is_prolongable(letter='a') #todo: not implemented + sage: n0, n1 = matrix(2,[1,1,1,0]), matrix(2,[2,1,1,0]) # optional - sage.modules + sage: n = {'a':n0, 'b':n1} # optional - sage.modules + sage: WordMorphism(n).is_prolongable(letter='a') # todo: not implemented # optional - sage.modules Traceback (most recent call last): ... TypeError: codomain of self must be an instance of Words @@ -2089,7 +2089,7 @@ def language(self, n, u=None): sage: s = WordMorphism({0: [0,1], 1: [0], 2: [2,0,2]}) sage: u = s.fixed_point(0) - sage: A0 = u[:200].factor_set(5) + sage: A0 = u[:200].factor_set(5) # optional - sage.modules sage: B0 = s.language(5, [0]) # optional - sage.modules sage: set(A0) == B0 # optional - sage.modules True @@ -2888,7 +2888,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, sage: t = WordMorphism("a->aC,b->d,C->de,d->a,e->ab") # substitution found by Julien Bernat sage: V = [vector((0,0,1,0,-1)), vector((0,0,1,-1,0))] # optional - sage.modules - sage: S = set(map(tuple, [i*V[0] + j*V[1] + sage: S = set(map(tuple, [i*V[0] + j*V[1] # optional - sage.modules ....: for i in [-1,0,1] for j in [-1,0,1]])) sage: t.rauzy_fractal_plot(n=10000, # not tested (> 1 second) ....: translate=S, exchange=true) diff --git a/src/sage/combinat/words/word_char.pyx b/src/sage/combinat/words/word_char.pyx index f2b7b47edb2..31f642ffc65 100644 --- a/src/sage/combinat/words/word_char.pyx +++ b/src/sage/combinat/words/word_char.pyx @@ -716,9 +716,9 @@ cdef class WordDatatype_char(WordDatatype): sage: W = Words([0,1]) sage: w = words.FibonacciWord() sage: w = W(list(w[:5000])) - sage: L = [[len(w[n:].longest_common_prefix(w[n+fibonacci(i):])) + sage: L = [[len(w[n:].longest_common_prefix(w[n+fibonacci(i):])) # optional - sage.libs.pari ....: for i in range(5,15)] for n in range(1,1000)] - sage: for n,l in enumerate(L): + sage: for n,l in enumerate(L): # optional - sage.libs.pari ....: if l.count(0) > 4: ....: print("{} {}".format(n+1,l)) 375 [0, 13, 0, 34, 0, 89, 0, 233, 0, 233] From 0e31af803a4f84a93703617689a348b47238c9c8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 9 Jun 2023 00:55:41 -0700 Subject: [PATCH 4/9] More # optional --- src/sage/combinat/words/morphism.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index e46f7f9d075..6e11f5db4c9 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -2095,7 +2095,7 @@ def language(self, n, u=None): True sage: v = s.fixed_point(2) - sage: A2 = v[:200].factor_set(5) + sage: A2 = v[:200].factor_set(5) # optional - sage.modules sage: B2 = s.language(5, [2]) # optional - sage.modules sage: set(A2) == B2 # optional - sage.modules True From 9aa2aa470446581cca4a1a1da25c7af6f965a858 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 10 Jun 2023 17:49:30 -0700 Subject: [PATCH 5/9] More # optional --- src/sage/combinat/words/morphism.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 6e11f5db4c9..5fc7d5e62b7 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -709,7 +709,7 @@ def __call__(self, w, order=1): sage: tm('a', 6.7) Traceback (most recent call last): ... - TypeError: order (6.70000000000000) must be a non-negative integer or plus Infinity + TypeError: order (6.7...) must be a non-negative integer or plus Infinity Only the first letter is considered for infinitely iterated image of a word under a morphism:: @@ -976,7 +976,7 @@ def __pow__(self, exp): sage: m^1.5 Traceback (most recent call last): ... - ValueError: exponent (1.50000000000000) must be an integer + ValueError: exponent (1.5...) must be an integer sage: m^-2 Traceback (most recent call last): ... @@ -2100,7 +2100,7 @@ def language(self, n, u=None): sage: set(A2) == B2 # optional - sage.modules True - sage: len(A0), len(A2) + sage: len(A0), len(A2) # optional - sage.modules (6, 20) The Chacon transformation (non-primitive):: From 91e44aa1caae5a8113f5811e5ca04a320c4d6bed Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 11 Jun 2023 23:46:00 -0700 Subject: [PATCH 6/9] sage.combinat: More # optional --- src/sage/combinat/words/finite_word.py | 2 +- src/sage/combinat/words/morphic.py | 2 +- src/sage/combinat/words/paths.py | 3 ++- src/sage/combinat/words/word_generators.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index bdb182ac6b9..9fe6dc815c0 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -5977,7 +5977,7 @@ def is_sturmian_factor(self): sage: words.LowerMechanicalWord(random(),alphabet='01')[:100].is_sturmian_factor() True - sage: words.CharacteristicSturmianWord(random())[:100].is_sturmian_factor() + sage: words.CharacteristicSturmianWord(random())[:100].is_sturmian_factor() # optional - sage.rings.real_mpfr True :: diff --git a/src/sage/combinat/words/morphic.py b/src/sage/combinat/words/morphic.py index 96390756bfb..73d4973af85 100644 --- a/src/sage/combinat/words/morphic.py +++ b/src/sage/combinat/words/morphic.py @@ -32,7 +32,7 @@ from sage.misc.lazy_import import lazy_import from sage.rings.infinity import Infinity -lazy_import('sage.modules.free_module_element', 'import vector') +lazy_import('sage.modules.free_module_element', 'vector') class WordDatatype_morphic(WordDatatype_callable): diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index cc4aecd250b..ae78cb206b9 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -188,7 +188,6 @@ lazy_import("sage.plot.all", ["arrow", "line", "polygon", "point", "Graphics"]) from sage.modules.free_module_element import vector from sage.rings.integer_ring import ZZ -from sage.rings.number_field.number_field import QuadraticField from sage.rings.real_mpfr import RR from .word_datatypes import (WordDatatype_str, WordDatatype_list, @@ -202,6 +201,8 @@ WordDatatype_callable) from sage.matrix.constructor import vector_on_axis_rotation_matrix +lazy_import('sage.rings.number_field.number_field', 'QuadraticField') + ####################################################################### # # diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index e21ab9a22b4..54d8a96f637 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -778,9 +778,9 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic word: 0100101001001010010100100101001001010010... - sage: words.CharacteristicSturmianWord(4/5) + sage: words.CharacteristicSturmianWord(4/5) # optional - sage.rings.real_mpfr word: 11110 - sage: words.CharacteristicSturmianWord(5/14) + sage: words.CharacteristicSturmianWord(5/14) # optional - sage.rings.real_mpfr word: 01001001001001 sage: words.CharacteristicSturmianWord(pi - 3) # optional - sage.symbolic word: 0000001000000100000010000001000000100000... From 2e33391db782ec01029cbe384f5690b69443fea9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 12 Jul 2023 17:59:24 -0700 Subject: [PATCH 7/9] ./sage -fixdoctests --distribution sagemath-categories --only-tags src/sage/combinat --- src/sage/combinat/words/abstract_word.py | 10 +- src/sage/combinat/words/alphabet.py | 6 +- src/sage/combinat/words/finite_word.py | 96 ++++++++-------- src/sage/combinat/words/lyndon_word.py | 16 +-- src/sage/combinat/words/morphic.py | 36 +++--- src/sage/combinat/words/morphism.py | 126 ++++++++++----------- src/sage/combinat/words/paths.py | 84 +++++++------- src/sage/combinat/words/suffix_trees.py | 26 ++--- src/sage/combinat/words/word.py | 2 +- src/sage/combinat/words/word_char.pyx | 4 +- src/sage/combinat/words/word_generators.py | 88 +++++++------- src/sage/combinat/words/words.py | 44 +++---- 12 files changed, 269 insertions(+), 269 deletions(-) diff --git a/src/sage/combinat/words/abstract_word.py b/src/sage/combinat/words/abstract_word.py index 610dba1437a..eaf5cbd4975 100644 --- a/src/sage/combinat/words/abstract_word.py +++ b/src/sage/combinat/words/abstract_word.py @@ -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:: diff --git a/src/sage/combinat/words/alphabet.py b/src/sage/combinat/words/alphabet.py index 3289ad5aa1a..1de8838df00 100644 --- a/src/sage/combinat/words/alphabet.py +++ b/src/sage/combinat/words/alphabet.py @@ -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 diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index 9fe6dc815c0..d43624c8ebe 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -136,7 +136,7 @@ sage: st = w.suffix_tree() sage: st Implicit Suffix Tree of the word: abaabbba - sage: st.show(word_labels=True) # optional - sage.plot + sage: st.show(word_labels=True) # needs sage.plot :: @@ -190,9 +190,9 @@ Rauzy graphs:: sage: f = words.FibonacciWord()[:30] - sage: f.rauzy_graph(4) # optional - sage.graphs + sage: f.rauzy_graph(4) # needs sage.graphs Looped digraph on 5 vertices - sage: f.reduced_rauzy_graph(4) # optional - sage.graphs + sage: f.reduced_rauzy_graph(4) # needs sage.graphs Looped multi-digraph on 2 vertices Left-special and bispecial factors:: @@ -1464,16 +1464,16 @@ def topological_entropy(self, n): sage: W = Words([0, 1]) sage: w = W([0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1]) - sage: t = w.topological_entropy(3); t # optional - sage.symbolic + sage: t = w.topological_entropy(3); t # needs sage.symbolic 1/3*log(7)/log(2) - sage: n(t) # optional - sage.symbolic + sage: n(t) # needs sage.symbolic 0.935784974019201 :: sage: w = words.ThueMorseWord()[:100] sage: topo = w.topological_entropy - sage: for i in range(0, 41, 5): # optional - sage.symbolic + sage: for i in range(0, 41, 5): # needs sage.symbolic ....: print("{} {}".format(i, n(topo(i), digits=5))) 0 1.0000 5 0.71699 @@ -1497,7 +1497,7 @@ def topological_entropy(self, n): sage: W = Words(range(20)) sage: w = W(range(20)) - sage: w.topological_entropy(3) # optional - sage.symbolic + sage: w.topological_entropy(3) # needs sage.symbolic 1/3*log(18)/log(20) """ d = self.parent().alphabet().cardinality() @@ -1525,12 +1525,12 @@ def rauzy_graph(self, n): sage: w = Word(range(10)); w word: 0123456789 - sage: g = w.rauzy_graph(3); g # optional - sage.graphs + sage: g = w.rauzy_graph(3); g # needs sage.graphs Looped digraph on 8 vertices sage: WordOptions(identifier='') - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs [012, 123, 234, 345, 456, 567, 678, 789] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(012, 123, 3), (123, 234, 4), (234, 345, 5), @@ -1543,20 +1543,20 @@ def rauzy_graph(self, n): :: sage: f = words.FibonacciWord()[:100] - sage: f.rauzy_graph(8) # optional - sage.graphs + sage: f.rauzy_graph(8) # needs sage.graphs Looped digraph on 9 vertices :: sage: w = Word('1111111') - sage: g = w.rauzy_graph(3) # optional - sage.graphs - sage: g.edges(sort=True) # optional - sage.graphs + sage: g = w.rauzy_graph(3) # needs sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(word: 111, word: 111, word: 1)] :: sage: w = Word('111') - sage: for i in range(5): w.rauzy_graph(i) # optional - sage.graphs + sage: for i in range(5): w.rauzy_graph(i) # needs sage.graphs Looped multi-digraph on 1 vertex Looped digraph on 1 vertex Looped digraph on 1 vertex @@ -1567,9 +1567,9 @@ def rauzy_graph(self, n): sage: W = Words('abcde') sage: w = W('abc') - sage: w.rauzy_graph(0) # optional - sage.graphs + sage: w.rauzy_graph(0) # needs sage.graphs Looped multi-digraph on 1 vertex - sage: _.edges(sort=True) # optional - sage.graphs + sage: _.edges(sort=True) # needs sage.graphs [(word: , word: , word: a), (word: , word: , word: b), (word: , word: , word: c)] @@ -1636,21 +1636,21 @@ def reduced_rauzy_graph(self, n): sage: w = Word(range(10)); w word: 0123456789 - sage: g = w.reduced_rauzy_graph(3); g # optional - sage.graphs + sage: g = w.reduced_rauzy_graph(3); g # needs sage.graphs Looped multi-digraph on 2 vertices - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs [word: 012, word: 789] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(word: 012, word: 789, word: 3456789)] For the Fibonacci word:: sage: f = words.FibonacciWord()[:100] - sage: g = f.reduced_rauzy_graph(8);g # optional - sage.graphs + sage: g = f.reduced_rauzy_graph(8);g # needs sage.graphs Looped multi-digraph on 2 vertices - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs [word: 01001010, word: 01010010] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(word: 01001010, word: 01010010, word: 010), (word: 01010010, word: 01001010, word: 01010), (word: 01010010, word: 01001010, word: 10)] @@ -1659,14 +1659,14 @@ def reduced_rauzy_graph(self, n): sage: from itertools import cycle sage: w = Word(cycle('abcd'))[:100] - sage: g = w.reduced_rauzy_graph(3) # optional - sage.graphs - sage: g.edges(sort=True) # optional - sage.graphs + sage: g = w.reduced_rauzy_graph(3) # needs sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(word: abc, word: abc, word: dabc)] :: sage: w = Word('111') - sage: for i in range(5): w.reduced_rauzy_graph(i) # optional - sage.graphs + sage: for i in range(5): w.reduced_rauzy_graph(i) # needs sage.graphs Looped digraph on 1 vertex Looped digraph on 1 vertex Looped digraph on 1 vertex @@ -1676,12 +1676,12 @@ def reduced_rauzy_graph(self, n): For ultimately periodic words:: sage: sigma = WordMorphism('a->abcd,b->cd,c->cd,d->cd') - sage: w = sigma.fixed_point('a')[:100]; w # optional - sage.modules + sage: w = sigma.fixed_point('a')[:100]; w # needs sage.modules word: abcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd... - sage: g = w.reduced_rauzy_graph(5) # optional - sage.graphs - sage: g.vertices(sort=True) # optional - sage.graphs + sage: g = w.reduced_rauzy_graph(5) # needs sage.graphs + sage: g.vertices(sort=True) # needs sage.graphs [word: abcdc, word: cdcdc] - sage: g.edges(sort=True) # optional - sage.graphs + sage: g.edges(sort=True) # needs sage.graphs [(word: abcdc, word: cdcdc, word: dc), (word: cdcdc, word: cdcdc, word: dc)] AUTHOR: @@ -3099,9 +3099,9 @@ def defect(self, f=None): sage: sa = WordMorphism('a->ab,b->b') sage: sb = WordMorphism('a->a,b->ba') sage: w = (sa*sb*sb*sa*sa*sa*sb).fixed_point('a') - sage: w[:30].defect() # optional - sage.modules + sage: w[:30].defect() # needs sage.modules 0 - sage: w[110:140].defect() # optional - sage.modules + sage: w[110:140].defect() # needs sage.modules 0 It is even conjectured that the defect of an aperiodic word which is @@ -3109,11 +3109,11 @@ def defect(self, f=None): (see [BBGL2008]_):: sage: w = words.ThueMorseWord() - sage: w[:50].defect() # optional - sage.modules + sage: w[:50].defect() # needs sage.modules 12 - sage: w[:100].defect() # optional - sage.modules + sage: w[:100].defect() # needs sage.modules 16 - sage: w[:300].defect() # optional - sage.modules + sage: w[:300].defect() # needs sage.modules 52 For generalized defect with an involution different from the identity, @@ -5977,7 +5977,7 @@ def is_sturmian_factor(self): sage: words.LowerMechanicalWord(random(),alphabet='01')[:100].is_sturmian_factor() True - sage: words.CharacteristicSturmianWord(random())[:100].is_sturmian_factor() # optional - sage.rings.real_mpfr + sage: words.CharacteristicSturmianWord(random())[:100].is_sturmian_factor() # needs sage.rings.real_mpfr True :: @@ -6749,7 +6749,7 @@ def apply_permutation_to_positions(self, permutation): word: badc sage: w.apply_permutation_to_positions(Permutation([2,1,4,3])) word: badc - sage: w.apply_permutation_to_positions(PermutationGroupElement([2,1,4,3])) # optional - sage.groups + sage: w.apply_permutation_to_positions(PermutationGroupElement([2,1,4,3])) # needs sage.groups word: badc sage: Word([1,2,3,4]).apply_permutation_to_positions([3,4,2,1]) word: 3421 @@ -6779,7 +6779,7 @@ def apply_permutation_to_letters(self, permutation): word: dcba sage: w.apply_permutation_to_letters(Permutation(p)) word: badc - sage: w.apply_permutation_to_letters(PermutationGroupElement(p)) # optional - sage.groups + sage: w.apply_permutation_to_letters(PermutationGroupElement(p)) # needs sage.groups word: badc """ from sage.combinat.permutation import Permutation @@ -6824,18 +6824,18 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn EXAMPLES:: - sage: Word(range(20)).colored_vector() # optional - sage.plot + sage: Word(range(20)).colored_vector() # needs sage.plot Graphics object consisting of 21 graphics primitives - sage: Word(range(100)).colored_vector(0,0,10,1) # optional - sage.plot + sage: Word(range(100)).colored_vector(0,0,10,1) # needs sage.plot Graphics object consisting of 101 graphics primitives - sage: Words(range(100))(range(10)).colored_vector() # optional - sage.plot + sage: Words(range(100))(range(10)).colored_vector() # needs sage.plot Graphics object consisting of 11 graphics primitives sage: w = Word('abbabaab') - sage: w.colored_vector() # optional - sage.plot + sage: w.colored_vector() # needs sage.plot Graphics object consisting of 9 graphics primitives - sage: w.colored_vector(cmap='autumn') # optional - sage.plot + sage: w.colored_vector(cmap='autumn') # needs sage.plot Graphics object consisting of 9 graphics primitives - sage: Word(range(20)).colored_vector(label='Rainbow') # optional - sage.plot + sage: Word(range(20)).colored_vector(label='Rainbow') # needs sage.plot Graphics object consisting of 23 graphics primitives When two words are defined under the same parent, same letters are @@ -6844,25 +6844,25 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn sage: W = Words(range(20)) sage: w = W(range(20)) sage: y = W(range(10,20)) - sage: y.colored_vector(y=1, x=10) + w.colored_vector() # optional - sage.plot + sage: y.colored_vector(y=1, x=10) + w.colored_vector() # needs sage.plot Graphics object consisting of 32 graphics primitives TESTS: The empty word:: - sage: Word().colored_vector() # optional - sage.plot + sage: Word().colored_vector() # needs sage.plot Graphics object consisting of 1 graphics primitive - sage: Word().colored_vector(label='empty') # optional - sage.plot + sage: Word().colored_vector(label='empty') # needs sage.plot Graphics object consisting of 3 graphics primitives Unknown cmap:: - sage: Word(range(100)).colored_vector(cmap='jolies') # optional - sage.plot + sage: Word(range(100)).colored_vector(cmap='jolies') # needs sage.plot Traceback (most recent call last): ... RuntimeError: Color map jolies not known - sage: Word(range(100)).colored_vector(cmap='__doc__') # optional - sage.plot + sage: Word(range(100)).colored_vector(cmap='__doc__') # needs sage.plot Traceback (most recent call last): ... RuntimeError: Color map __doc__ not known diff --git a/src/sage/combinat/words/lyndon_word.py b/src/sage/combinat/words/lyndon_word.py index 575d68c58bc..4c978680380 100644 --- a/src/sage/combinat/words/lyndon_word.py +++ b/src/sage/combinat/words/lyndon_word.py @@ -64,9 +64,9 @@ def LyndonWords(e=None, k=None): word: 1112 sage: LW.last() word: 2333 - sage: LW.random_element() # random # optional - sage.libs.pari + sage: LW.random_element() # random # needs sage.libs.pari word: 1232 - sage: LW.cardinality() # optional - sage.libs.pari + sage: LW.cardinality() # needs sage.libs.pari 18 If e is a (weak) composition, then it returns the class of Lyndon @@ -277,9 +277,9 @@ def cardinality(self): sage: LyndonWords([]).cardinality() 0 - sage: LyndonWords([2,2]).cardinality() # optional - sage.libs.pari + sage: LyndonWords([2,2]).cardinality() # needs sage.libs.pari 1 - sage: LyndonWords([2,3,2]).cardinality() # optional - sage.libs.pari + sage: LyndonWords([2,3,2]).cardinality() # needs sage.libs.pari 30 Check to make sure that the count matches up with the number of @@ -287,7 +287,7 @@ def cardinality(self): 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) # optional - sage.libs.pari + sage: all(lw.cardinality() == len(lw.list()) for lw in lws) # needs sage.libs.pari True """ evaluation = self._e @@ -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()) # optional - sage.libs.pari + sage: _ = L(L.random_element()) # needs sage.libs.pari """ w = self._words(*args, **kwds) if kwds.get('check', True) and not w.is_lyndon(): @@ -443,7 +443,7 @@ def cardinality(self): """ TESTS:: - sage: [ LyndonWords(3,i).cardinality() for i in range(1, 11) ] # optional - sage.libs.pari + 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: @@ -470,7 +470,7 @@ def __iter__(self): sage: sum(1 for lw in LyndonWords(1, 1000)) 0 - sage: list(LyndonWords(1, 1)) # optional - sage.libs.pari + sage: list(LyndonWords(1, 1)) # needs sage.libs.pari [word: 1] """ W = self._words._element_classes['list'] diff --git a/src/sage/combinat/words/morphic.py b/src/sage/combinat/words/morphic.py index 73d4973af85..0db7a8db6fe 100644 --- a/src/sage/combinat/words/morphic.py +++ b/src/sage/combinat/words/morphic.py @@ -23,7 +23,7 @@ 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' """ @@ -58,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 @@ -69,11 +69,11 @@ 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:: @@ -81,7 +81,7 @@ def __init__(self, parent, morphism, letter, coding=None, length=Infinity): sage: m = WordMorphism("a->ab,b->") 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 @@ -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:: @@ -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 """ @@ -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 @@ -204,7 +204,7 @@ def representation(self, n): sage: w = WordDatatype_morphic(W, m, 'a') sage: type(w) - 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)} @@ -255,11 +255,11 @@ def _func(self, key): sage: m = WordMorphism("a->ab,b->a") sage: w = m.fixed_point("a") - sage: w[0] # optional - sage.modules + sage: w[0] # needs sage.modules 'a' - sage: w[5] # optional - sage.modules + sage: w[5] # needs sage.modules 'a' - sage: w[10000] # optional - sage.modules + sage: w[10000] # needs sage.modules 'a' TESTS: @@ -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) # optional - sage.modules + sage: w._func(5) # needs sage.modules 'a' """ diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 5fc7d5e62b7..1576c5aca6c 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -66,7 +66,7 @@ Incidence matrix:: - sage: matrix(m) # optional - sage.modules + sage: matrix(m) # needs sage.modules [2 3 1] [1 3 0] [1 1 1] @@ -614,7 +614,7 @@ def __str__(self) -> str: :: sage: s = WordMorphism({1:[1,2],2:[1]}) - sage: s.dual_map() # optional - sage.modules + sage: s.dual_map() # needs sage.modules E_1^*(1->12, 2->1) TESTS:: @@ -1101,21 +1101,21 @@ def _matrix_(self, R=None): sage: fibo = WordMorphism('a->ab,b->a') sage: tm = WordMorphism('a->ab,b->ba') - sage: Mfibo = matrix(fibo); Mfibo # indirect doctest # optional - sage.modules + sage: Mfibo = matrix(fibo); Mfibo # indirect doctest # needs sage.modules [1 1] [1 0] - sage: Mtm = matrix(tm); Mtm # optional - sage.modules + sage: Mtm = matrix(tm); Mtm # needs sage.modules [1 1] [1 1] - sage: Mtm * Mfibo == matrix(tm*fibo) # indirect doctest # optional - sage.modules + sage: Mtm * Mfibo == matrix(tm*fibo) # indirect doctest # needs sage.modules True - sage: Mfibo * Mtm == matrix(fibo*tm) # indirect doctest # optional - sage.modules + sage: Mfibo * Mtm == matrix(fibo*tm) # indirect doctest # needs sage.modules True - sage: Mfibo.parent() # optional - sage.modules + sage: Mfibo.parent() # needs sage.modules Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: p = Mfibo.charpoly(); p # optional - sage.modules + sage: p = Mfibo.charpoly(); p # needs sage.modules x^2 - x - 1 - sage: p.roots(ring=RR, multiplicities=False) # optional - sage.modules + sage: p.roots(ring=RR, multiplicities=False) # needs sage.modules [-0.618033988749895, 1.61803398874989] """ if R is None: @@ -1136,12 +1136,12 @@ def incidence_matrix(self): EXAMPLES:: sage: m = WordMorphism('a->abc,b->a,c->c') - sage: m.incidence_matrix() # optional - sage.modules + sage: m.incidence_matrix() # needs sage.modules [1 1 0] [1 0 0] [1 0 1] sage: m = WordMorphism('a->abc,b->a,c->c,d->abbccccabca,e->abc') - sage: m.incidence_matrix() # optional - sage.modules + sage: m.incidence_matrix() # needs sage.modules [1 1 0 3 1] [1 0 0 3 1] [1 0 1 5 1] @@ -1204,10 +1204,10 @@ def is_endomorphism(self): We check that :trac:`8674` is fixed:: - sage: P = WordPaths('abcd') # optional - sage.modules - sage: m = WordMorphism('a->adab,b->ab,c->cbcd,d->cd', # optional - sage.modules + sage: P = WordPaths('abcd') # needs sage.modules + sage: m = WordMorphism('a->adab,b->ab,c->cbcd,d->cd', # needs sage.modules ....: domain=P, codomain=P) - sage: m.is_endomorphism() # optional - sage.modules + sage: m.is_endomorphism() # needs sage.modules True """ return self.codomain() == self.domain() @@ -1496,11 +1496,11 @@ def pisot_eigenvector_right(self): EXAMPLES:: sage: m = WordMorphism('a->aaaabbc,b->aaabbc,c->aabc') - sage: matrix(m) # optional - sage.modules + sage: matrix(m) # needs sage.modules [4 3 2] [2 2 1] [1 1 1] - sage: m.pisot_eigenvector_right() # optional - sage.modules sage.rings.number_field + sage: m.pisot_eigenvector_right() # needs sage.modules sage.rings.number_field (1, 0.5436890126920763?, 0.2955977425220848?) """ eig = self.incidence_matrix().eigenvectors_right() @@ -1526,11 +1526,11 @@ def pisot_eigenvector_left(self): EXAMPLES:: sage: m = WordMorphism('a->aaaabbc,b->aaabbc,c->aabc') - sage: matrix(m) # optional - sage.modules + sage: matrix(m) # needs sage.modules [4 3 2] [2 2 1] [1 1 1] - sage: m.pisot_eigenvector_left() # optional - sage.modules sage.rings.number_field + sage: m.pisot_eigenvector_left() # needs sage.modules sage.rings.number_field (1, 0.8392867552141611?, 0.5436890126920763?) """ eig = self.incidence_matrix().eigenvectors_left() @@ -1590,25 +1590,25 @@ def is_primitive(self): EXAMPLES:: sage: tm = WordMorphism('a->ab,b->ba') - sage: tm.is_primitive() # optional - sage.modules + sage: tm.is_primitive() # needs sage.modules True sage: fibo = WordMorphism('a->ab,b->a') - sage: fibo.is_primitive() # optional - sage.modules + sage: fibo.is_primitive() # needs sage.modules True sage: m = WordMorphism('a->bb,b->aa') - sage: m.is_primitive() # optional - sage.modules + sage: m.is_primitive() # needs sage.modules False sage: f = WordMorphism({0:[1],1:[0]}) - sage: f.is_primitive() # optional - sage.modules + sage: f.is_primitive() # needs sage.modules False :: sage: s = WordMorphism('a->b,b->c,c->ab') - sage: s.is_primitive() # optional - sage.modules + sage: s.is_primitive() # needs sage.modules True sage: s = WordMorphism('a->b,b->c,c->d,d->e,e->f,f->g,g->h,h->ab') - sage: s.is_primitive() # optional - sage.modules + sage: s.is_primitive() # needs sage.modules True TESTS:: @@ -1619,7 +1619,7 @@ def is_primitive(self): ... TypeError: self (=a->bb, b->aac) is not an endomorphism sage: m = WordMorphism('a->,b->', codomain=Words('ab')) - sage: m.is_primitive() # optional - sage.modules + sage: m.is_primitive() # needs sage.modules False sage: m = WordMorphism('a->,b->') sage: m.is_primitive() @@ -1683,9 +1683,9 @@ def is_prolongable(self, letter): :: - sage: n0, n1 = matrix(2,[1,1,1,0]), matrix(2,[2,1,1,0]) # optional - sage.modules - sage: n = {'a':n0, 'b':n1} # optional - sage.modules - sage: WordMorphism(n).is_prolongable(letter='a') # todo: not implemented # optional - sage.modules + sage: n0, n1 = matrix(2,[1,1,1,0]), matrix(2,[2,1,1,0]) # needs sage.modules + sage: n = {'a':n0, 'b':n1} # needs sage.modules + sage: WordMorphism(n).is_prolongable(letter='a') # not implemented, needs sage.modules Traceback (most recent call last): ... TypeError: codomain of self must be an instance of Words @@ -2076,11 +2076,11 @@ def language(self, n, u=None): The fibonacci morphism:: sage: s = WordMorphism({0: [0,1], 1: [0]}) - sage: sorted(s.language(3)) # optional - sage.modules + sage: sorted(s.language(3)) # needs sage.modules [word: 001, word: 010, word: 100, word: 101] - sage: len(s.language(1000)) # optional - sage.modules + sage: len(s.language(1000)) # needs sage.modules 1001 - sage: all(len(s.language(n)) == n+1 for n in range(100)) # optional - sage.modules + sage: all(len(s.language(n)) == n+1 for n in range(100)) # needs sage.modules True A growing but non-primitive example. The DOL-languages generated @@ -2089,24 +2089,24 @@ def language(self, n, u=None): sage: s = WordMorphism({0: [0,1], 1: [0], 2: [2,0,2]}) sage: u = s.fixed_point(0) - sage: A0 = u[:200].factor_set(5) # optional - sage.modules - sage: B0 = s.language(5, [0]) # optional - sage.modules - sage: set(A0) == B0 # optional - sage.modules + sage: A0 = u[:200].factor_set(5) # needs sage.modules + sage: B0 = s.language(5, [0]) # needs sage.modules + sage: set(A0) == B0 # needs sage.modules True sage: v = s.fixed_point(2) - sage: A2 = v[:200].factor_set(5) # optional - sage.modules - sage: B2 = s.language(5, [2]) # optional - sage.modules - sage: set(A2) == B2 # optional - sage.modules + sage: A2 = v[:200].factor_set(5) # needs sage.modules + sage: B2 = s.language(5, [2]) # needs sage.modules + sage: set(A2) == B2 # needs sage.modules True - sage: len(A0), len(A2) # optional - sage.modules + sage: len(A0), len(A2) # needs sage.modules (6, 20) The Chacon transformation (non-primitive):: sage: s = WordMorphism({0: [0,0,1,0], 1:[1]}) - sage: sorted(s.language(10)) # optional - sage.modules + sage: sorted(s.language(10)) # needs sage.modules [word: 0001000101, word: 0001010010, ... @@ -2461,7 +2461,7 @@ def dual_map(self, k=1): EXAMPLES:: sage: sigma = WordMorphism({1: [2], 2: [3], 3: [1,2]}) - sage: sigma.dual_map() # optional - sage.modules + sage: sigma.dual_map() # needs sage.modules E_1^*(1->2, 2->3, 3->12) :: @@ -2515,7 +2515,7 @@ def rauzy_fractal_projection(self, eig=None, prec=53): is:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: s.rauzy_fractal_projection() # optional - sage.modules + sage: s.rauzy_fractal_projection() # needs sage.modules {'1': (1.00000000000000, 0.000000000000000), '2': (-1.41964337760708, -0.606290729207199), '3': (-0.771844506346038, 1.11514250803994)} @@ -2523,9 +2523,9 @@ def rauzy_fractal_projection(self, eig=None, prec=53): TESTS:: sage: t = WordMorphism('1->12,2->3,3->45,4->5,5->6,6->7,7->8,8->1') - sage: E = t.incidence_matrix().eigenvalues() # optional - sage.modules - sage: x = [x for x in E if -0.8 < x < -0.7][0] # optional - sage.modules - sage: t.rauzy_fractal_projection(prec=10) # optional - sage.modules + sage: E = t.incidence_matrix().eigenvalues() # needs sage.modules + sage: x = [x for x in E if -0.8 < x < -0.7][0] # needs sage.modules + sage: t.rauzy_fractal_projection(prec=10) # needs sage.modules {'1': (1.0, 0.00), '2': (-1.7, -0.56), '3': (0.79, 1.3), @@ -2534,7 +2534,7 @@ def rauzy_fractal_projection(self, eig=None, prec=53): '6': (0.79, 1.3), '7': (0.21, -1.3), '8': (-0.88, 0.74)} - sage: t.rauzy_fractal_projection(eig=x, prec=10) # optional - sage.modules + sage: t.rauzy_fractal_projection(eig=x, prec=10) # needs sage.modules {'1': (1.0, 0.00), '2': (-0.12, -0.74), '3': (-0.66, -0.56), @@ -2619,20 +2619,20 @@ def rauzy_fractal_points(self, n=None, exchange=False, eig=None, translate=None, and ``'3'`` are respectively:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: D = s.rauzy_fractal_points(n=100) # optional - sage.modules - sage: len(D['1']) # optional - sage.modules + sage: D = s.rauzy_fractal_points(n=100) # needs sage.modules + sage: len(D['1']) # needs sage.modules 54 - sage: len(D['2']) # optional - sage.modules + sage: len(D['2']) # needs sage.modules 30 - sage: len(D['3']) # optional - sage.modules + sage: len(D['3']) # needs sage.modules 16 TESTS:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: D = s.rauzy_fractal_points(n=100, exchange=True, # optional - sage.modules + sage: D = s.rauzy_fractal_points(n=100, exchange=True, # needs sage.modules ....: translate=[(3,1,-2), (5,-33,8)], prec=40) - sage: len(D['1']) # optional - sage.modules + sage: len(D['1']) # needs sage.modules 108 AUTHOR: @@ -2794,7 +2794,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, #. The Rauzy fractal of the Tribonacci substitution:: sage: s = WordMorphism('1->12,2->13,3->1') - sage: s.rauzy_fractal_plot() # long time # optional - sage.plot + sage: s.rauzy_fractal_plot() # long time # needs sage.plot Graphics object consisting of 3 graphics primitives #. The "Hokkaido" fractal. We tweak the plot using the plotting options @@ -2843,8 +2843,8 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, #. Different fractals can be obtained by choosing another (non-Pisot) eigenvalue:: sage: s = WordMorphism('1->12,2->3,3->45,4->5,5->6,6->7,7->8,8->1') - sage: E = s.incidence_matrix().eigenvalues() # optional - sage.modules - sage: x = [x for x in E if -0.8 < x < -0.7][0] # optional - sage.modules + sage: E = s.incidence_matrix().eigenvalues() # needs sage.modules + sage: x = [x for x in E if -0.8 < x < -0.7][0] # needs sage.modules sage: s.rauzy_fractal_plot() # not tested (> 1 second) sage: s.rauzy_fractal_plot(eig=x) # not tested (> 1 second) @@ -2887,8 +2887,8 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, :: sage: t = WordMorphism("a->aC,b->d,C->de,d->a,e->ab") # substitution found by Julien Bernat - sage: V = [vector((0,0,1,0,-1)), vector((0,0,1,-1,0))] # optional - sage.modules - sage: S = set(map(tuple, [i*V[0] + j*V[1] # optional - sage.modules + sage: V = [vector((0,0,1,0,-1)), vector((0,0,1,-1,0))] # needs sage.modules + sage: S = set(map(tuple, [i*V[0] + j*V[1] # needs sage.modules ....: for i in [-1,0,1] for j in [-1,0,1]])) sage: t.rauzy_fractal_plot(n=10000, # not tested (> 1 second) ....: translate=S, exchange=true) @@ -2911,7 +2911,7 @@ def rauzy_fractal_plot(self, n=None, exchange=False, eig=None, TESTS:: sage: s = WordMorphism('a->ab,b->c,c->d,d->e,e->a') - sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', # optional - sage.modules sage.plot + sage: s.rauzy_fractal_plot(n=1000, colormap='Set1', # needs sage.modules sage.plot ....: opacity={'a':0.5,'b':1,'c':0.7,'d':0,'e':0.2}, ....: plot_origin=(100,"black"), plot_basis=True, ....: point_size=2.5) @@ -3331,24 +3331,24 @@ def abelian_rotation_subspace(self): EXAMPLES:: - sage: WordMorphism('0->1,1->0').abelian_rotation_subspace() # optional - sage.modules + sage: WordMorphism('0->1,1->0').abelian_rotation_subspace() # needs sage.modules Vector space of degree 2 and dimension 2 over Rational Field Basis matrix: [1 0] [0 1] - sage: WordMorphism('0->01,1->10').abelian_rotation_subspace() # optional - sage.modules + sage: WordMorphism('0->01,1->10').abelian_rotation_subspace() # needs sage.modules Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] - sage: WordMorphism('0->01,1->1').abelian_rotation_subspace() # optional - sage.modules + sage: WordMorphism('0->01,1->1').abelian_rotation_subspace() # needs sage.modules Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [0 1] - sage: WordMorphism('1->122,2->211').abelian_rotation_subspace() # optional - sage.modules + sage: WordMorphism('1->122,2->211').abelian_rotation_subspace() # needs sage.modules Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 -1] - sage: WordMorphism('0->1,1->102,2->3,3->4,4->2').abelian_rotation_subspace() # optional - sage.modules + sage: WordMorphism('0->1,1->102,2->3,3->4,4->2').abelian_rotation_subspace() # needs sage.modules Vector space of degree 5 and dimension 3 over Rational Field Basis matrix: [0 0 1 0 0] @@ -3357,7 +3357,7 @@ def abelian_rotation_subspace(self): The domain needs to be equal to the codomain:: - sage: WordMorphism('0->1,1->',codomain=Words('01')).abelian_rotation_subspace() # optional - sage.modules + sage: WordMorphism('0->1,1->',codomain=Words('01')).abelian_rotation_subspace() # needs sage.modules Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index ae78cb206b9..dcf37d8f456 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -45,7 +45,7 @@ [(0, 0), (1, 2), (-2, 6), (-1, 8), (-1, 5), (-1, 2), (-4, 6), (-3, 8)] sage: p.is_closed() False - sage: p.plot() # optional - sage.plot + sage: p.plot() # needs sage.plot Graphics object consisting of 3 graphics primitives To obtain a list of all the available word path specific functions, @@ -104,14 +104,14 @@ Finite Dyck paths sage: d = D('()()()(())'); d Path: ()()()(()) - sage: d.plot() # optional - sage.plot + sage: d.plot() # needs sage.plot Graphics object consisting of 3 graphics primitives :: sage: P = WordPaths('abcdef', steps='triangle_grid') sage: p = P('babaddefadabcadefaadfafabacdefa') - sage: p.plot() # optional - sage.plot + sage: p.plot() # needs sage.plot Graphics object consisting of 3 graphics primitives Vector steps may be in more than 2 dimensions:: @@ -120,7 +120,7 @@ sage: P = WordPaths(alphabet='abc', steps=d); P Word Paths over 3 steps sage: p = P('abcabcabcabcaabacabcababcacbabacacabcaccbcac') - sage: p.plot() # optional - sage.plot + sage: p.plot() # needs sage.plot Graphics3d Object :: @@ -137,7 +137,7 @@ sage: CubePaths = WordPaths('abcABC', steps='cube_grid'); CubePaths Word Paths on the cube grid - sage: CubePaths('abcabaabcabAAAAA').plot() # optional - sage.plot + sage: CubePaths('abcabaabcabAAAAA').plot() # needs sage.plot Graphics3d Object The input data may be a str, a list, a tuple, @@ -1366,15 +1366,15 @@ def plot_projection(self, v=None, letters=None, color=None, ring=None, To remove the axis, do like this:: - sage: r = w.plot_projection(v) # optional - sage.plot - sage: r.axes(False) # optional - sage.plot - sage: r # long time (2s) # optional - sage.plot + sage: r = w.plot_projection(v) # needs sage.plot + sage: r.axes(False) # needs sage.plot + sage: r # long time (2s) # needs sage.plot Graphics object consisting of 200 graphics primitives You can assign different colors to each letter:: sage: color = {'1': 'purple', '2': (.2,.3,.4), '3': 'magenta'} - sage: w.plot_projection(v, color=color) # long time (2s) # optional - sage.plot + sage: w.plot_projection(v, color=color) # long time (2s) # needs sage.plot Graphics object consisting of 200 graphics primitives The 3d-Rauzy fractal:: @@ -1384,14 +1384,14 @@ def plot_projection(self, v=None, letters=None, color=None, ring=None, sage: v = s.pisot_eigenvector_right() sage: P = WordPaths('1234',[(1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)]) sage: w = P(D[:200]) - sage: w.plot_projection(v) # optional - sage.plot + sage: w.plot_projection(v) # needs sage.plot Graphics3d Object The dimension of vector space of the parent must be 3 or 4:: sage: P = WordPaths('ab', [(1, 0), (0, 1)]) sage: p = P('aabbabbab') - sage: p.plot_projection() # optional - sage.plot + sage: p.plot_projection() # needs sage.plot Traceback (most recent call last): ... TypeError: The dimension of the vector space (=2) must be 3 or 4 @@ -1445,7 +1445,7 @@ def projected_path(self, v=None, ring=None): sage: p = w.projected_path(v) sage: p Path: 1213121121312121312112131213121121312121... - sage: p[:20].plot() # optional - sage.plot + sage: p[:20].plot() # needs sage.plot Graphics object consisting of 3 graphics primitives The ``ring`` argument allows to change the precision of the @@ -1531,42 +1531,42 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), A non closed path on the square grid:: sage: P = WordPaths('abAB') - sage: P('abababAABAB').plot() # optional - sage.plot + sage: P('abababAABAB').plot() # needs sage.plot Graphics object consisting of 3 graphics primitives A closed path on the square grid:: - sage: P('abababAABABB').plot() # optional - sage.plot + sage: P('abababAABABB').plot() # needs sage.plot Graphics object consisting of 4 graphics primitives A Dyck path:: sage: P = WordPaths('()', steps='dyck') - sage: P('()()()((()))').plot() # optional - sage.plot + sage: P('()()()((()))').plot() # needs sage.plot Graphics object consisting of 3 graphics primitives A path in the triangle grid:: sage: P = WordPaths('abcdef', steps='triangle_grid') - sage: P('abcdedededefab').plot() # optional - sage.plot + sage: P('abcdedededefab').plot() # needs sage.plot Graphics object consisting of 3 graphics primitives A polygon of length 220 that tiles the plane in two ways:: sage: P = WordPaths('abAB') - sage: P('aBababAbabaBaBABaBabaBaBABAbABABaBabaBaBABaBababAbabaBaBABaBabaBaBABAbABABaBABAbAbabAbABABaBABAbABABaBabaBaBABAbABABaBABAbAbabAbABAbAbabaBababAbABAbAbabAbABABaBABAbAbabAbABAbAbabaBababAbabaBaBABaBababAbabaBababAbABAbAbab').plot() # optional - sage.plot + sage: P('aBababAbabaBaBABaBabaBaBABAbABABaBabaBaBABaBababAbabaBaBABaBabaBaBABAbABABaBABAbAbabAbABABaBABAbABABaBabaBaBABAbABABaBABAbAbabAbABAbAbabaBababAbABAbAbabAbABABaBABAbAbabAbABAbAbabaBababAbabaBaBABaBababAbabaBababAbABAbAbab').plot() # needs sage.plot Graphics object consisting of 4 graphics primitives With gridlines:: - sage: P('ababababab').plot(gridlines=True) # optional - sage.plot + sage: P('ababababab').plot(gridlines=True) # needs sage.plot TESTS:: sage: P = WordPaths('abAB') - sage: P().plot() # optional - sage.plot + sage: P().plot() # needs sage.plot Graphics object consisting of 3 graphics primitives - sage: sum(map(plot,map(P,['a','A','b','B']))) # optional - sage.plot + sage: sum(map(plot,map(P,['a','A','b','B']))) # needs sage.plot Graphics object consisting of 12 graphics primitives """ G = Graphics() @@ -1615,44 +1615,44 @@ def animate(self): sage: P = WordPaths('abAB') sage: p = P('aaababbb') - sage: a = p.animate(); print(a) # optional - sage.plot + sage: a = p.animate(); print(a) # needs sage.plot Animation with 9 frames - sage: show(a) # long time # optional -- ImageMagick sage.plot - sage: show(a, delay=35, iterations=3) # long time # optional -- ImageMagick sage.plot + sage: show(a) # long time, optional - imagemagick, needs sage.plot + sage: show(a, delay=35, iterations=3) # long time, optional - imagemagick, needs sage.plot :: sage: P = WordPaths('abcdef',steps='triangle') sage: p = P('abcdef') - sage: a = p.animate(); print(a) # optional - sage.plot + sage: a = p.animate(); print(a) # needs sage.plot Animation with 8 frames - sage: show(a) # long time # optional -- ImageMagick sage.plot + sage: show(a) # long time, optional - imagemagick, needs sage.plot If the path is closed, the plain polygon is added at the end of the animation:: sage: P = WordPaths('abAB') sage: p = P('ababAbABABaB') - sage: a = p.animate(); print(a) # optional - sage.plot + sage: a = p.animate(); print(a) # needs sage.plot Animation with 14 frames - sage: show(a) # long time # optional -- ImageMagick sage.plot + sage: show(a) # long time, optional - imagemagick, needs sage.plot Another example illustrating a Fibonacci tile:: sage: w = words.fibonacci_tile(2) - sage: a = w.animate(); print(a) # optional - sage.plot + sage: a = w.animate(); print(a) # needs sage.plot Animation with 54 frames - sage: show(a) # long time # optional -- ImageMagick sage.plot + sage: show(a) # long time, optional - imagemagick, needs sage.plot The first 4 Fibonacci tiles in an animation:: - sage: a = words.fibonacci_tile(0).animate() # optional - sage.plot - sage: b = words.fibonacci_tile(1).animate() # optional - sage.plot - sage: c = words.fibonacci_tile(2).animate() # optional - sage.plot - sage: d = words.fibonacci_tile(3).animate() # optional - sage.plot - sage: print(a*b*c*d) # optional - sage.plot + sage: a = words.fibonacci_tile(0).animate() # needs sage.plot + sage: b = words.fibonacci_tile(1).animate() # needs sage.plot + sage: c = words.fibonacci_tile(2).animate() # needs sage.plot + sage: d = words.fibonacci_tile(3).animate() # needs sage.plot + sage: print(a*b*c*d) # needs sage.plot Animation with 296 frames - sage: show(a*b*c*d) # long time # optional -- ImageMagick sage.plot + sage: show(a*b*c*d) # long time, optional - imagemagick, needs sage.plot .. note:: @@ -1714,17 +1714,17 @@ def plot_directive_vector(self, options=dict(rgbcolor='blue')): Word Paths on the square grid sage: p = P('aaaccaccacacacaccccccbbdd'); p Path: aaaccaccacacacaccccccbbdd - sage: R = p.plot() + p.plot_directive_vector() # optional - sage.plot - sage: R.axes(False) # optional - sage.plot - sage: R.set_aspect_ratio(1) # optional - sage.plot - sage: R.plot() # optional - sage.plot + sage: R = p.plot() + p.plot_directive_vector() # needs sage.plot + sage: R.axes(False) # needs sage.plot + sage: R.set_aspect_ratio(1) # needs sage.plot + sage: R.plot() # needs sage.plot Graphics object consisting of 4 graphics primitives TESTS: A closed path:: - sage: P('acbd').plot_directive_vector() # optional - sage.plot + sage: P('acbd').plot_directive_vector() # needs sage.plot Graphics object consisting of 1 graphics primitive """ start = self.start_point() @@ -2021,12 +2021,12 @@ def plot(self, pathoptions=dict(rgbcolor='red',arrow_head=True,thickness=3), Word Paths over 2 steps sage: p = P('ababab'); p Path: ababab - sage: p.plot() # optional - sage.plot + sage: p.plot() # needs sage.plot Graphics3d Object sage: P = WordPaths('abcABC', steps='cube_grid') sage: p = P('abcabcAABBC') - sage: p.plot() # optional - sage.plot + sage: p.plot() # needs sage.plot Graphics3d Object """ diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index 59b3acb57d3..8375bde1a8a 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -440,9 +440,9 @@ def to_digraph(self): sage: from sage.combinat.words.suffix_trees import SuffixTrie sage: w = Words("cao")("cac") sage: t = SuffixTrie(w) - sage: d = t.to_digraph(); d # optional - sage.graphs + sage: d = t.to_digraph(); d # needs sage.graphs Digraph on 6 vertices - sage: d.adjacency_matrix() # optional - sage.graphs sage.modules + sage: d.adjacency_matrix() # needs sage.graphs sage.modules [0 1 0 1 0 0] [0 0 1 0 0 0] [0 0 0 0 1 0] @@ -464,13 +464,13 @@ def plot(self, layout='tree', tree_root=0, tree_orientation='up', EXAMPLES:: sage: from sage.combinat.words.suffix_trees import SuffixTrie - sage: SuffixTrie(Word("cacao")).plot() # optional - sage.plot + sage: SuffixTrie(Word("cacao")).plot() # needs sage.plot Graphics object consisting of 38 graphics primitives TESTS:: sage: from sage.combinat.words.suffix_trees import SuffixTrie - sage: type(SuffixTrie(Word("cacao")).plot()) # optional - sage.plot + sage: type(SuffixTrie(Word("cacao")).plot()) # needs sage.plot """ tree = self.to_digraph() @@ -494,7 +494,7 @@ def show(self, *args, **kwds): sage: from sage.combinat.words.suffix_trees import SuffixTrie sage: w = Words("cao")("cac") sage: t = SuffixTrie(w) - sage: t.show() # optional - sage.plot + sage: t.show() # needs sage.plot """ self.plot(*args, **kwds).show() return @@ -832,7 +832,7 @@ def to_digraph(self, word_labels=False): sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree sage: W = Words([0,1,2]) sage: t = ImplicitSuffixTree(W([0,1,0,1,2])) - sage: t.to_digraph() # optional - sage.graphs + sage: t.to_digraph() # needs sage.graphs Digraph on 8 vertices """ if not self._letters: @@ -868,17 +868,17 @@ def plot(self, word_labels=False, layout='tree', tree_root=0, EXAMPLES:: sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree - sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) # optional - sage.graphs sage.plot + sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=True) # needs sage.graphs sage.plot Graphics object consisting of 23 graphics primitives - sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) # optional - sage.graphs sage.plot + sage: ImplicitSuffixTree(Word('cacao')).plot(word_labels=False) # needs sage.graphs sage.plot Graphics object consisting of 23 graphics primitives TESTS:: sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree - sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=True)) # optional - sage.graphs sage.plot + sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=True)) # needs sage.graphs sage.plot - sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=False)) # optional - sage.graphs sage.plot + sage: type(ImplicitSuffixTree(Word('cacao')).plot(word_labels=False)) # needs sage.graphs sage.plot """ tree = self.to_digraph(word_labels=word_labels) @@ -907,8 +907,8 @@ def show(self, word_labels=None, *args, **kwds): sage: from sage.combinat.words.suffix_trees import ImplicitSuffixTree sage: w = Words("cao")("cacao") sage: t = ImplicitSuffixTree(w) - sage: t.show(word_labels=True) # optional - sage.plot - sage: t.show(word_labels=False) # optional - sage.plot + sage: t.show(word_labels=True) # needs sage.plot + sage: t.show(word_labels=False) # needs sage.plot """ self.plot(word_labels=word_labels, *args, **kwds).show() return @@ -1509,7 +1509,7 @@ def uncompactify(self): sage: abbab = Words("ab")("abbab") sage: s = SuffixTrie(abbab) sage: t = ImplicitSuffixTree(abbab) - sage: t.uncompactify().is_isomorphic(s.to_digraph()) # optional - sage.graphs + sage: t.uncompactify().is_isomorphic(s.to_digraph()) # needs sage.graphs True """ tree = self.to_digraph(word_labels=True) diff --git a/src/sage/combinat/words/word.py b/src/sage/combinat/words/word.py index 320bc3d9f0c..132195589e9 100644 --- a/src/sage/combinat/words/word.py +++ b/src/sage/combinat/words/word.py @@ -265,7 +265,7 @@ class FiniteWord_char(WordDatatype_char, FiniteWord_class): sage: len(w.factor_set()) 127 - sage: w.rauzy_graph(5) # optional - sage.graphs + sage: w.rauzy_graph(5) # needs sage.graphs Looped digraph on 9 vertices sage: u = W([1,2,3]) diff --git a/src/sage/combinat/words/word_char.pyx b/src/sage/combinat/words/word_char.pyx index 31f642ffc65..1b68cd293ce 100644 --- a/src/sage/combinat/words/word_char.pyx +++ b/src/sage/combinat/words/word_char.pyx @@ -716,9 +716,9 @@ cdef class WordDatatype_char(WordDatatype): sage: W = Words([0,1]) sage: w = words.FibonacciWord() sage: w = W(list(w[:5000])) - sage: L = [[len(w[n:].longest_common_prefix(w[n+fibonacci(i):])) # optional - sage.libs.pari + sage: L = [[len(w[n:].longest_common_prefix(w[n+fibonacci(i):])) # needs sage.libs.pari ....: for i in range(5,15)] for n in range(1,1000)] - sage: for n,l in enumerate(L): # optional - sage.libs.pari + sage: for n,l in enumerate(L): # needs sage.libs.pari ....: if l.count(0) > 4: ....: print("{} {}".format(n+1,l)) 375 [0, 13, 0, 34, 0, 89, 0, 233, 0, 233] diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index 54d8a96f637..681ce39e26e 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -243,10 +243,10 @@ def markoff_number(self): sage: w0 = words.LowerChristoffelWord(4,7) sage: w1, w2 = w0.standard_factorization() - sage: (m0,m1,m2) = (w.markoff_number() for w in (w0,w1,w2)) # optional - sage.modules - sage: (m0,m1,m2) # optional - sage.modules + sage: (m0,m1,m2) = (w.markoff_number() for w in (w0,w1,w2)) # needs sage.modules + sage: (m0,m1,m2) # needs sage.modules (294685, 13, 7561) - sage: m0**2 + m1**2 + m2**2 == 3*m0*m1*m2 # optional - sage.modules + sage: m0**2 + m1**2 + m2**2 == 3*m0*m1*m2 # needs sage.modules True """ from sage.matrix.constructor import matrix @@ -542,9 +542,9 @@ def FibonacciWord(self, alphabet=(0, 1), construction_method="recursive"): :: - sage: words.FibonacciWord([0,1], 'function') # optional - sage.symbolic + sage: words.FibonacciWord([0,1], 'function') # needs sage.symbolic word: 0100101001001010010100100101001001010010... - sage: words.FibonacciWord('ab', 'function') # optional - sage.symbolic + sage: words.FibonacciWord('ab', 'function') # needs sage.symbolic word: abaababaabaababaababaabaababaabaababaaba... TESTS:: @@ -642,7 +642,7 @@ def FixedPointOfMorphism(self, morphism, first_letter): sage: tm = words.FixedPointOfMorphism(mu,0); tm word: 0110100110010110100101100110100110010110... sage: TM = words.ThueMorseWord() - sage: tm[:1000] == TM[:1000] # optional - sage.modules + sage: tm[:1000] == TM[:1000] # needs sage.modules True :: @@ -652,7 +652,7 @@ def FixedPointOfMorphism(self, morphism, first_letter): word: 0100101001001010010100100101001001010010... sage: F = words.FibonacciWord(); F word: 0100101001001010010100100101001001010010... - sage: f[:1000] == F[:1000] # optional - sage.modules + sage: f[:1000] == F[:1000] # needs sage.modules True :: @@ -776,13 +776,13 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): From real slope:: - sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic + sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # needs sage.symbolic word: 0100101001001010010100100101001001010010... - sage: words.CharacteristicSturmianWord(4/5) # optional - sage.rings.real_mpfr + sage: words.CharacteristicSturmianWord(4/5) # needs sage.rings.real_mpfr word: 11110 - sage: words.CharacteristicSturmianWord(5/14) # optional - sage.rings.real_mpfr + sage: words.CharacteristicSturmianWord(5/14) # needs sage.rings.real_mpfr word: 01001001001001 - sage: words.CharacteristicSturmianWord(pi - 3) # optional - sage.symbolic + sage: words.CharacteristicSturmianWord(pi - 3) # needs sage.symbolic word: 0000001000000100000010000001000000100000... From an iterator of the continued fraction expansion of a real:: @@ -791,21 +791,21 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): ....: yield 0 ....: yield 2 ....: while True: yield 1 - sage: F = words.CharacteristicSturmianWord(cf()); F + sage: F = words.CharacteristicSturmianWord(cf()); F # needs sage.rings.real_mpfr word: 0100101001001010010100100101001001010010... sage: Fib = words.FibonacciWord(); Fib word: 0100101001001010010100100101001001010010... - sage: F[:10000] == Fib[:10000] + sage: F[:10000] == Fib[:10000] # needs sage.rings.real_mpfr True The alphabet may be specified:: - sage: words.CharacteristicSturmianWord(cf(), 'rs') + sage: words.CharacteristicSturmianWord(cf(), 'rs') # needs sage.rings.real_mpfr word: rsrrsrsrrsrrsrsrrsrsrrsrrsrsrrsrrsrsrrsr... The characteristic sturmian word of slope `(\sqrt{3}-1)/2`:: - sage: words.CharacteristicSturmianWord((sqrt(3)-1)/2) # optional - sage.symbolic + sage: words.CharacteristicSturmianWord((sqrt(3)-1)/2) # needs sage.symbolic word: 0100100101001001001010010010010100100101... The same word defined from the continued fraction expansion of @@ -848,17 +848,17 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): :: - sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic + sage: words.CharacteristicSturmianWord(1/golden_ratio^2) # needs sage.symbolic word: 0100101001001010010100100101001001010010... - sage: _.length() # optional - sage.symbolic + sage: _.length() # needs sage.symbolic +Infinity :: - sage: a = words.LowerMechanicalWord(1/pi)[1:] # optional - sage.symbolic - sage: b = words.UpperMechanicalWord(1/pi)[1:] # optional - sage.symbolic - sage: c = words.CharacteristicSturmianWord(1/pi) # optional - sage.symbolic - sage: n = 500; a[:n] == b[:n] == c[:n] # optional - sage.symbolic + sage: a = words.LowerMechanicalWord(1/pi)[1:] # needs sage.symbolic + sage: b = words.UpperMechanicalWord(1/pi)[1:] # needs sage.symbolic + sage: c = words.CharacteristicSturmianWord(1/pi) # needs sage.symbolic + sage: n = 500; a[:n] == b[:n] == c[:n] # needs sage.symbolic True :: @@ -929,19 +929,19 @@ def _CharacteristicSturmianWord_LetterIterator(self, cf, alphabet=(0,1)): EXAMPLES:: - sage: continued_fraction(1/golden_ratio^2)[:8] # optional - sage.symbolic + sage: continued_fraction(1/golden_ratio^2)[:8] # needs sage.symbolic [0; 2, 1, 1, 1, 1, 2] - sage: cf = iter(_) # optional - sage.symbolic - sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # optional - sage.symbolic + sage: cf = iter(_) # needs sage.symbolic + sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # needs sage.symbolic word: 0100101001001010010100100101001010 :: - sage: alpha = (sqrt(3)-1)/2 # optional - sage.symbolic - sage: continued_fraction(alpha)[:10] # optional - sage.symbolic + sage: alpha = (sqrt(3)-1)/2 # needs sage.symbolic + sage: continued_fraction(alpha)[:10] # needs sage.symbolic [0; 2, 1, 2, 1, 2, 1, 2, 1, 2] - sage: cf = iter(_) # optional - sage.symbolic - sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # optional - sage.symbolic + sage: cf = iter(_) # needs sage.symbolic + sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # needs sage.symbolic word: 0100100101001001001010010010010100100101... """ try: @@ -1135,23 +1135,23 @@ def LowerMechanicalWord(self, alpha, rho=0, alphabet=None): EXAMPLES:: - sage: words.LowerMechanicalWord(1/golden_ratio^2) # optional - sage.symbolic + sage: words.LowerMechanicalWord(1/golden_ratio^2) # needs sage.symbolic word: 0010010100100101001010010010100100101001... - sage: words.LowerMechanicalWord(1/5) # optional - sage.symbolic + sage: words.LowerMechanicalWord(1/5) # needs sage.symbolic word: 0000100001000010000100001000010000100001... - sage: words.LowerMechanicalWord(1/pi) # optional - sage.symbolic + sage: words.LowerMechanicalWord(1/pi) # needs sage.symbolic word: 0001001001001001001001000100100100100100... TESTS:: - sage: m = words.LowerMechanicalWord(1/golden_ratio^2)[1:] # optional - sage.symbolic - sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic - sage: m[:500] == s[:500] # optional - sage.symbolic + sage: m = words.LowerMechanicalWord(1/golden_ratio^2)[1:] # needs sage.symbolic + sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) # needs sage.symbolic + sage: m[:500] == s[:500] # needs sage.symbolic True Check that this returns a word in an alphabet (:trac:`10054`):: - sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() # optional - sage.symbolic + sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() # needs sage.symbolic Infinite words over {0, 1} """ if not 0 <= alpha <= 1: @@ -1195,23 +1195,23 @@ def UpperMechanicalWord(self, alpha, rho=0, alphabet=None): EXAMPLES:: - sage: words.UpperMechanicalWord(1/golden_ratio^2) # optional - sage.symbolic + sage: words.UpperMechanicalWord(1/golden_ratio^2) # needs sage.symbolic word: 1010010100100101001010010010100100101001... - sage: words.UpperMechanicalWord(1/5) # optional - sage.symbolic + sage: words.UpperMechanicalWord(1/5) # needs sage.symbolic word: 1000010000100001000010000100001000010000... - sage: words.UpperMechanicalWord(1/pi) # optional - sage.symbolic + sage: words.UpperMechanicalWord(1/pi) # needs sage.symbolic word: 1001001001001001001001000100100100100100... TESTS:: - sage: m = words.UpperMechanicalWord(1/golden_ratio^2)[1:] # optional - sage.symbolic - sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) # optional - sage.symbolic - sage: m[:500] == s[:500] # optional - sage.symbolic + sage: m = words.UpperMechanicalWord(1/golden_ratio^2)[1:] # needs sage.symbolic + sage: s = words.CharacteristicSturmianWord(1/golden_ratio^2) # needs sage.symbolic + sage: m[:500] == s[:500] # needs sage.symbolic True Check that this returns a word in an alphabet (:trac:`10054`):: - sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() # optional - sage.symbolic + sage: words.UpperMechanicalWord(1/golden_ratio^2).parent() # needs sage.symbolic Infinite words over {0, 1} """ if not 0 <= alpha <= 1: @@ -1522,7 +1522,7 @@ def fibonacci_tile(self, n): EXAMPLES:: - sage: for i in range(3): words.fibonacci_tile(i) # optional - sage.modules + sage: for i in range(3): words.fibonacci_tile(i) # needs sage.modules Path: 3210 Path: 323030101212 Path: 3230301030323212323032321210121232121010... @@ -1540,7 +1540,7 @@ def dual_fibonacci_tile(self, n): EXAMPLES:: - sage: for i in range(4): words.dual_fibonacci_tile(i) # optional - sage.modules + sage: for i in range(4): words.dual_fibonacci_tile(i) # needs sage.modules Path: 3210 Path: 32123032301030121012 Path: 3212303230103230321232101232123032123210... diff --git a/src/sage/combinat/words/words.py b/src/sage/combinat/words/words.py index 8c23a452bc7..0149df17598 100644 --- a/src/sage/combinat/words/words.py +++ b/src/sage/combinat/words/words.py @@ -705,9 +705,9 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr Construction of a word path from a finite word:: sage: W = FiniteWords('abcd') - sage: P = WordPaths('abcd') # optional - sage.modules + sage: P = WordPaths('abcd') # needs sage.modules sage: w = W('aaab') - sage: P(w) # optional - sage.modules + sage: P(w) # needs sage.modules Path: aaab Construction of a word path from a Christoffel word:: @@ -715,8 +715,8 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.ChristoffelWord(5,8) sage: w word: 0010010100101 - sage: P = WordPaths([0,1,2,3]) # optional - sage.modules - sage: P(w) # optional - sage.modules + sage: P = WordPaths([0,1,2,3]) # needs sage.modules + sage: P(w) # needs sage.modules Path: 0010010100101 Construction of a word represented by a list from a word @@ -744,19 +744,19 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.FibonacciWord() sage: f = w[:100] - sage: P = WordPaths([0,1,2,3]) # optional - sage.modules - sage: p = P(f); p # optional - sage.modules + sage: P = WordPaths([0,1,2,3]) # needs sage.modules + sage: p = P(f); p # needs sage.modules Path: 0100101001001010010100100101001001010010... - sage: p.length() # optional - sage.modules + sage: p.length() # needs sage.modules 100 Creation of a word path from a FiniteWord_callable:: sage: g = W(lambda n:n%2, length = 100) - sage: P = WordPaths([0,1,2,3]) # optional - sage.modules - sage: p = P(g); p # optional - sage.modules + sage: P = WordPaths([0,1,2,3]) # needs sage.modules + sage: p = P(g); p # needs sage.modules Path: 0101010101010101010101010101010101010101... - sage: p.length() # optional - sage.modules + sage: p.length() # needs sage.modules 100 Creation of a word from a pickled function:: @@ -1017,7 +1017,7 @@ def random_element(self, length=None, *args, **kwds): TESTS:: - sage: _ = FiniteWords(GF(5)).random_element() # optional - sage.rings.finite_rings + sage: _ = FiniteWords(GF(5)).random_element() # needs sage.rings.finite_rings """ if length is None: length = ZZ.random_element(0, 10) @@ -1928,9 +1928,9 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr Construction of a word path from a finite word:: sage: W = Words('abcd') - sage: P = WordPaths('abcd') # optional - sage.modules + sage: P = WordPaths('abcd') # needs sage.modules sage: w = W('aaab') - sage: P(w) # optional - sage.modules + sage: P(w) # needs sage.modules Path: aaab Construction of a word path from a Christoffel word:: @@ -1938,8 +1938,8 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.ChristoffelWord(5,8) sage: w word: 0010010100101 - sage: P = WordPaths([0,1,2,3]) # optional - sage.modules - sage: P(w) # optional - sage.modules + sage: P = WordPaths([0,1,2,3]) # needs sage.modules + sage: P(w) # needs sage.modules Path: 0010010100101 Construction of a word represented by a list from a word @@ -1967,19 +1967,19 @@ def __call__(self, data=None, length=None, datatype=None, caching=True, check=Tr sage: w = words.FibonacciWord() sage: f = w[:100] - sage: P = WordPaths([0,1,2,3]) # optional - sage.modules - sage: p = P(f); p # optional - sage.modules + sage: P = WordPaths([0,1,2,3]) # needs sage.modules + sage: p = P(f); p # needs sage.modules Path: 0100101001001010010100100101001001010010... - sage: p.length() # optional - sage.modules + sage: p.length() # needs sage.modules 100 Creation of a word path from a :class:`FiniteWord_callable`:: sage: g = Word(lambda n: n%2, length=100) - sage: P = WordPaths([0,1,2,3]) # optional - sage.modules - sage: p = P(g); p # optional - sage.modules + sage: P = WordPaths([0,1,2,3]) # needs sage.modules + sage: p = P(g); p # needs sage.modules Path: 0101010101010101010101010101010101010101... - sage: p.length() # optional - sage.modules + sage: p.length() # needs sage.modules 100 Creation of a word from a pickled function:: @@ -2216,7 +2216,7 @@ def random_element(self, *args, **kwds): TESTS:: - sage: _ = Words(GF(5),4).random_element() # optional - sage.rings.finite_rings + sage: _ = Words(GF(5),4).random_element() # needs sage.rings.finite_rings Check that :trac:`18283` is fixed:: From 6613b17ad045b129a515a0fbd92cdf082698d3db Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 13 Jul 2023 23:26:21 -0700 Subject: [PATCH 8/9] sage.combinat.words: Update # needs --- src/sage/combinat/words/morphism.py | 11 ++++++----- src/sage/combinat/words/paths.py | 13 +++++++------ src/sage/combinat/words/word_generators.py | 18 ++++++++++-------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 1576c5aca6c..de7f00902ef 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -3331,24 +3331,25 @@ def abelian_rotation_subspace(self): EXAMPLES:: - sage: WordMorphism('0->1,1->0').abelian_rotation_subspace() # needs sage.modules + sage: # needs sage.modules + sage: WordMorphism('0->1,1->0').abelian_rotation_subspace() Vector space of degree 2 and dimension 2 over Rational Field Basis matrix: [1 0] [0 1] - sage: WordMorphism('0->01,1->10').abelian_rotation_subspace() # needs sage.modules + sage: WordMorphism('0->01,1->10').abelian_rotation_subspace() Vector space of degree 2 and dimension 0 over Rational Field Basis matrix: [] - sage: WordMorphism('0->01,1->1').abelian_rotation_subspace() # needs sage.modules + sage: WordMorphism('0->01,1->1').abelian_rotation_subspace() Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [0 1] - sage: WordMorphism('1->122,2->211').abelian_rotation_subspace() # needs sage.modules + sage: WordMorphism('1->122,2->211').abelian_rotation_subspace() Vector space of degree 2 and dimension 1 over Rational Field Basis matrix: [ 1 -1] - sage: WordMorphism('0->1,1->102,2->3,3->4,4->2').abelian_rotation_subspace() # needs sage.modules + sage: WordMorphism('0->1,1->102,2->3,3->4,4->2').abelian_rotation_subspace() Vector space of degree 5 and dimension 3 over Rational Field Basis matrix: [0 0 1 0 0] diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index dcf37d8f456..5c84a784533 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -1646,13 +1646,14 @@ def animate(self): The first 4 Fibonacci tiles in an animation:: - sage: a = words.fibonacci_tile(0).animate() # needs sage.plot - sage: b = words.fibonacci_tile(1).animate() # needs sage.plot - sage: c = words.fibonacci_tile(2).animate() # needs sage.plot - sage: d = words.fibonacci_tile(3).animate() # needs sage.plot - sage: print(a*b*c*d) # needs sage.plot + sage: # needs sage.plot + sage: a = words.fibonacci_tile(0).animate() + sage: b = words.fibonacci_tile(1).animate() + sage: c = words.fibonacci_tile(2).animate() + sage: d = words.fibonacci_tile(3).animate() + sage: print(a*b*c*d) Animation with 296 frames - sage: show(a*b*c*d) # long time, optional - imagemagick, needs sage.plot + sage: show(a*b*c*d) # long time, optional - imagemagick .. note:: diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index 681ce39e26e..58886bd9108 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -855,10 +855,11 @@ def CharacteristicSturmianWord(self, slope, alphabet=(0, 1), bits=None): :: - sage: a = words.LowerMechanicalWord(1/pi)[1:] # needs sage.symbolic - sage: b = words.UpperMechanicalWord(1/pi)[1:] # needs sage.symbolic - sage: c = words.CharacteristicSturmianWord(1/pi) # needs sage.symbolic - sage: n = 500; a[:n] == b[:n] == c[:n] # needs sage.symbolic + sage: # needs sage.symbolic + sage: a = words.LowerMechanicalWord(1/pi)[1:] + sage: b = words.UpperMechanicalWord(1/pi)[1:] + sage: c = words.CharacteristicSturmianWord(1/pi) + sage: n = 500; a[:n] == b[:n] == c[:n] True :: @@ -937,11 +938,12 @@ def _CharacteristicSturmianWord_LetterIterator(self, cf, alphabet=(0,1)): :: - sage: alpha = (sqrt(3)-1)/2 # needs sage.symbolic - sage: continued_fraction(alpha)[:10] # needs sage.symbolic + sage: # needs sage.symbolic + sage: alpha = (sqrt(3)-1)/2 + sage: continued_fraction(alpha)[:10] [0; 2, 1, 2, 1, 2, 1, 2, 1, 2] - sage: cf = iter(_) # needs sage.symbolic - sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) # needs sage.symbolic + sage: cf = iter(_) + sage: Word(words._CharacteristicSturmianWord_LetterIterator(cf)) word: 0100100101001001001010010010010100100101... """ try: From 8153dbd027a4a21bcc0de7a60793b1252fff60d1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 4 Nov 2023 10:24:42 -0700 Subject: [PATCH 9/9] sage.combinat.words: More block tags --- src/sage/combinat/words/finite_word.py | 13 +++++++------ src/sage/combinat/words/morphism.py | 27 +++++++++++++------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index d43624c8ebe..35fd6e69c55 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -6824,18 +6824,19 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn EXAMPLES:: - sage: Word(range(20)).colored_vector() # needs sage.plot + sage: # needs sage.plot + sage: Word(range(20)).colored_vector() Graphics object consisting of 21 graphics primitives - sage: Word(range(100)).colored_vector(0,0,10,1) # needs sage.plot + sage: Word(range(100)).colored_vector(0,0,10,1) Graphics object consisting of 101 graphics primitives - sage: Words(range(100))(range(10)).colored_vector() # needs sage.plot + sage: Words(range(100))(range(10)).colored_vector() Graphics object consisting of 11 graphics primitives sage: w = Word('abbabaab') - sage: w.colored_vector() # needs sage.plot + sage: w.colored_vector() Graphics object consisting of 9 graphics primitives - sage: w.colored_vector(cmap='autumn') # needs sage.plot + sage: w.colored_vector(cmap='autumn') Graphics object consisting of 9 graphics primitives - sage: Word(range(20)).colored_vector(label='Rainbow') # needs sage.plot + sage: Word(range(20)).colored_vector(label='Rainbow') Graphics object consisting of 23 graphics primitives When two words are defined under the same parent, same letters are diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index de7f00902ef..279c238718e 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -346,7 +346,7 @@ def __init__(self, data, domain=None, codomain=None): The image of a letter can be a set, but the order is not preserved:: - sage: WordMorphism({2:[4,5,6],3:set([4,1,8])}) #random results + sage: WordMorphism({2:[4,5,6],3:set([4,1,8])}) # random results WordMorphism: 2->456, 3->814 If the image of a letter is not iterable, it is considered as a @@ -1099,23 +1099,24 @@ def _matrix_(self, R=None): EXAMPLES:: + sage: # needs sage.modules sage: fibo = WordMorphism('a->ab,b->a') sage: tm = WordMorphism('a->ab,b->ba') - sage: Mfibo = matrix(fibo); Mfibo # indirect doctest # needs sage.modules + sage: Mfibo = matrix(fibo); Mfibo # indirect doctest [1 1] [1 0] - sage: Mtm = matrix(tm); Mtm # needs sage.modules + sage: Mtm = matrix(tm); Mtm [1 1] [1 1] - sage: Mtm * Mfibo == matrix(tm*fibo) # indirect doctest # needs sage.modules + sage: Mtm * Mfibo == matrix(tm*fibo) # indirect doctest True - sage: Mfibo * Mtm == matrix(fibo*tm) # indirect doctest # needs sage.modules + sage: Mfibo * Mtm == matrix(fibo*tm) # indirect doctest True - sage: Mfibo.parent() # needs sage.modules + sage: Mfibo.parent() Full MatrixSpace of 2 by 2 dense matrices over Integer Ring - sage: p = Mfibo.charpoly(); p # needs sage.modules + sage: p = Mfibo.charpoly(); p x^2 - x - 1 - sage: p.roots(ring=RR, multiplicities=False) # needs sage.modules + sage: p.roots(ring=RR, multiplicities=False) [-0.618033988749895, 1.61803398874989] """ if R is None: @@ -1406,19 +1407,19 @@ def partition_of_domain_alphabet(self): EXAMPLES:: sage: m = WordMorphism('a->b,b->a') - sage: m.partition_of_domain_alphabet() #random ordering + sage: m.partition_of_domain_alphabet() # random ordering ({'a'}, {'b'}, {}) sage: m = WordMorphism('a->b,b->a,c->c') - sage: m.partition_of_domain_alphabet() #random ordering + sage: m.partition_of_domain_alphabet() # random ordering ({'a'}, {'b'}, {'c'}) sage: m = WordMorphism('a->a,b->b,c->c') - sage: m.partition_of_domain_alphabet() #random ordering + sage: m.partition_of_domain_alphabet() # random ordering ({}, {}, {'a', 'c', 'b'}) sage: m = WordMorphism('A->T,T->A,C->G,G->C') - sage: m.partition_of_domain_alphabet() #random ordering + sage: m.partition_of_domain_alphabet() # random ordering ({'A', 'C'}, {'T', 'G'}, {}) sage: I = WordMorphism({0:oo,oo:0,1:-1,-1:1,2:-2,-2:2,3:-3,-3:3}) - sage: I.partition_of_domain_alphabet() #random ordering + sage: I.partition_of_domain_alphabet() # random ordering ({0, -1, -3, -2}, {1, 2, 3, +Infinity}, {}) TESTS::