Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sage/combinat/words/abstract_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,9 +1617,9 @@ def factor_occurrences_iterator(self, fact):
[0, 2, 8]
"""
if fact.is_empty():
raise NotImplementedError("The factor must be non empty")
raise NotImplementedError("the factor must be non empty")
if not fact.is_finite():
raise ValueError("The factor must be finite")
raise ValueError("the factor must be finite")
p = self.first_occurrence(fact, start=0)
while p is not None:
yield p
Expand Down
26 changes: 13 additions & 13 deletions src/sage/combinat/words/finite_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ def number_of_factors(self, n=None, algorithm='suffix tree'):
elif algorithm == 'naive':
return ZZ(len(self.factor_set(n, algorithm='naive')))
else:
raise ValueError(f'Unknown algorithm (={algorithm})')
raise ValueError(f'unknown algorithm (={algorithm})')

def factor_iterator(self, n=None):
r"""
Expand Down Expand Up @@ -1423,7 +1423,7 @@ def factor_set(self, n=None, algorithm='suffix tree'):
S.add(self[i:i+n])
return Set(S)
else:
raise ValueError(f'Unknown algorithm (={algorithm})')
raise ValueError(f'unknown algorithm (={algorithm})')

def topological_entropy(self, n):
r"""
Expand Down Expand Up @@ -1474,7 +1474,7 @@ def topological_entropy(self, n):
sage: w.topological_entropy(3)
Traceback (most recent call last):
...
TypeError: The word must be defined over a finite alphabet
TypeError: the word must be defined over a finite alphabet

The following is ok::

Expand All @@ -1485,7 +1485,7 @@ def topological_entropy(self, n):
"""
d = self.parent().alphabet().cardinality()
if d is Infinity:
raise TypeError("The word must be defined over a finite alphabet")
raise TypeError("the word must be defined over a finite alphabet")
if n == 0:
return 1
pn = self.number_of_factors(n)
Expand Down Expand Up @@ -4370,7 +4370,7 @@ def number_of_factor_occurrences(self, other):
sage: Word('123').number_of_factor_occurrences(Word())
Traceback (most recent call last):
...
NotImplementedError: The factor must be non empty
NotImplementedError: the factor must be non empty
"""
return sum(1 for _ in self.factor_occurrences_iterator(other))

Expand Down Expand Up @@ -4899,14 +4899,14 @@ def overlap_partition(self, other, delay=0, p=None, involution=None):
{{-4, -2, 0, 2, 4}, {-5, -3, -1, 1, 3, 5}}
"""
if not isinstance(delay, (int, Integer)):
raise TypeError("delay (=%s) must be an integer" % delay)
raise TypeError(f"delay (={delay}) must be an integer")
elif delay < 0:
return other.overlap_partition(self, -delay, p)

from sage.sets.disjoint_set import DisjointSet_class
if p is None:
if self.parent().alphabet().cardinality() is Infinity:
raise ValueError("The alphabet of the parent must be finite")
raise ValueError("the alphabet of the parent must be finite")
from sage.sets.disjoint_set import DisjointSet
p = DisjointSet(self.parent().alphabet())
elif not isinstance(p, DisjointSet_class):
Expand Down Expand Up @@ -6398,18 +6398,18 @@ def standard_factorization(self):
sage: w.standard_factorization()
Traceback (most recent call last):
...
ValueError: Standard factorization not defined on words of
ValueError: standard factorization not defined on words of
length less than 2
sage: w = Word('a')
sage: w.standard_factorization()
Traceback (most recent call last):
...
ValueError: Standard factorization not defined on words of
ValueError: standard factorization not defined on words of
length less than 2
"""
selflen = self.length()
if selflen < 2:
raise ValueError("Standard factorization not defined on"
raise ValueError("standard factorization not defined on"
" words of length less than 2")
for l in range(1, selflen):
suff = self[l:]
Expand Down Expand Up @@ -6542,11 +6542,11 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn
sage: Word(range(100)).colored_vector(cmap='jolies') # needs sage.plot
Traceback (most recent call last):
...
RuntimeError: Color map jolies not known
RuntimeError: color map jolies not known
sage: Word(range(100)).colored_vector(cmap='__doc__') # needs sage.plot
Traceback (most recent call last):
...
RuntimeError: Color map __doc__ not known
RuntimeError: color map __doc__ not known
"""
# Recognize the color map
import matplotlib.cm as cm
Expand All @@ -6562,7 +6562,7 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn
if isinstance(val, C))
import sage.misc.verbose
sage.misc.verbose.verbose("The possible color maps include: %s" % possibilities, level=0)
raise RuntimeError("Color map %s not known" % cmap)
raise RuntimeError(f"color map {cmap} not known")

# Drawing the colored vector...
from sage.plot.line import line
Expand Down
23 changes: 11 additions & 12 deletions src/sage/combinat/words/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ def WordPaths(alphabet, steps=None):
sage: WordPaths(range(5))
Traceback (most recent call last):
...
TypeError: Unable to make a class WordPaths from {0, 1, 2, 3, 4}
TypeError: unable to make a class WordPaths from {0, 1, 2, 3, 4}
sage: WordPaths('abAB', steps='square_gridd')
Traceback (most recent call last):
...
TypeError: Unknown type of steps : square_gridd
TypeError: unknown type of steps : square_gridd
"""
# Construction of the alphabet
alphabet = build_alphabet(alphabet)
Expand All @@ -330,26 +330,25 @@ def WordPaths(alphabet, steps=None):
elif alphabet.cardinality() == 6:
steps = 'hexagonal_grid'
else:
raise TypeError("Unable to make a class WordPaths from %s" % alphabet)
raise TypeError("unable to make a class WordPaths from %s" % alphabet)

# Return the class of WordPaths according to the given type of paths
if isinstance(steps, str):
if steps in ('square_grid', 'square'):
return WordPaths_square_grid(alphabet=alphabet)
elif steps in ('triangle_grid', 'triangle'):
if steps in ('triangle_grid', 'triangle'):
return WordPaths_triangle_grid(alphabet=alphabet)
elif steps in ('hexagonal_grid', 'hexagon'):
if steps in ('hexagonal_grid', 'hexagon'):
return WordPaths_hexagonal_grid(alphabet=alphabet)
elif steps in ('cube_grid', 'cube'):
if steps in ('cube_grid', 'cube'):
return WordPaths_cube_grid(alphabet=alphabet)
elif steps in ('north_east', 'ne', 'NE'):
if steps in ('north_east', 'ne', 'NE'):
return WordPaths_north_east(alphabet=alphabet)
elif steps == 'dyck':
if steps == 'dyck':
return WordPaths_dyck(alphabet=alphabet)
else:
raise TypeError("Unknown type of steps : %s" % steps)
else:
return WordPaths_all(alphabet=alphabet, steps=steps)
raise TypeError(f"unknown type of steps : {steps}")

return WordPaths_all(alphabet=alphabet, steps=steps)


#######################################################################
Expand Down
26 changes: 13 additions & 13 deletions src/sage/combinat/words/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Sébastien Labbé
- Franco Saliola
"""
#*****************************************************************************
# ***************************************************************************
# Copyright (C) 2008 Arnaud Bergeron <abergeron@gmail.com>,
# Amy Glen <amy.glen@gmail.com>,
# Sébastien Labbé <slabqc@gmail.com>,
Expand All @@ -19,15 +19,15 @@
# the Free Software Foundation, either version 2 of the License, or
# (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
from sage.combinat.words.infinite_word import InfiniteWord_class
from .word_datatypes import (WordDatatype_str,
WordDatatype_list,
WordDatatype_tuple)
WordDatatype_list,
WordDatatype_tuple)
from .word_infinite_datatypes import (
WordDatatype_iter_with_caching,
WordDatatype_iter,
Expand Down Expand Up @@ -191,18 +191,18 @@ def Word(data=None, alphabet=None, length=None, datatype=None, caching=True, RSK
return data.to_word(alphabet)

if RSK_data is not None:
#if a list of a semistandard and a standard tableau or a pair of lists
# if a list of a semistandard and a standard tableau or a pair of lists
from sage.combinat.tableau import Tableau
if isinstance(RSK_data, (tuple, list)) and len(RSK_data) == 2 and \
all(isinstance(x, Tableau) for x in RSK_data):
all(isinstance(x, Tableau) for x in RSK_data):
from sage.combinat.rsk import RSK_inverse
return RSK_inverse(*RSK_data, output='word')
elif isinstance(RSK_data, (tuple, list)) and len(RSK_data) == 2 and \
all(isinstance(x, (list, tuple)) for x in RSK_data):
all(isinstance(x, (list, tuple)) for x in RSK_data):
from sage.combinat.rsk import RSK_inverse
P,Q = map(Tableau, RSK_data)
P, Q = map(Tableau, RSK_data)
return RSK_inverse(P, Q, 'word')
raise ValueError("Invalid input. Must be a pair of tableaux")
raise ValueError("input must be a pair of tableaux")

# Create the parent object
from .words import Words
Expand All @@ -216,7 +216,7 @@ def Word(data=None, alphabet=None, length=None, datatype=None, caching=True, RSK
# #
#######################################################################

##### Finite Words #####
# #### Finite Words ####


class FiniteWord_char(WordDatatype_char, FiniteWord_class):
Expand Down Expand Up @@ -485,7 +485,7 @@ class FiniteWord_callable(WordDatatype_callable, FiniteWord_class):
pass


##### Infinite Words #####
# #### Infinite Words ####

class InfiniteWord_iter_with_caching(WordDatatype_iter_with_caching, InfiniteWord_class):
r"""
Expand Down Expand Up @@ -628,7 +628,7 @@ class InfiniteWord_callable(WordDatatype_callable, InfiniteWord_class):
pass


##### Words of unknown length #####
# #### Words of unknown length ####

class Word_iter_with_caching(WordDatatype_iter_with_caching, Word_class):
r"""
Expand Down Expand Up @@ -704,7 +704,7 @@ class Word_iter(WordDatatype_iter, Word_class):
pass


##### Morphic Words #####
# #### Morphic Words ####

class FiniteWord_morphic(WordDatatype_morphic, FiniteWord_class):
r"""
Expand Down
Loading
Loading