diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index 5106615ae9b..f5506152d44 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -18,7 +18,7 @@ - Arnaud Bergeron (2008) : Initial version, path on the square grid -- Sebastien Labbe (2009-01-14) : New classes and hierarchy, doc and functions. +- Sébastien Labbé (2009-01-14) : New classes and hierarchy, doc and functions. EXAMPLES: @@ -185,22 +185,22 @@ from sage.combinat.words.word import FiniteWord_class from sage.combinat.words.alphabet import build_alphabet from sage.misc.lazy_import import lazy_import -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.real_mpfr import RR from .word_datatypes import (WordDatatype_str, - WordDatatype_list, - WordDatatype_tuple) - #WordDatatype_cpp_basic_string) + WordDatatype_list, + WordDatatype_tuple) +# WordDatatype_cpp_basic_string) from .word_infinite_datatypes import ( - WordDatatype_iter_with_caching, - WordDatatype_iter, - WordDatatype_callable_with_caching, - WordDatatype_callable) + WordDatatype_iter_with_caching, + WordDatatype_iter, + WordDatatype_callable_with_caching, + WordDatatype_callable) from sage.matrix.constructor import vector_on_axis_rotation_matrix +lazy_import("sage.plot.all", ["arrow", "line", "polygon", "point", "Graphics"]) lazy_import('sage.rings.number_field.number_field', 'QuadraticField') @@ -212,13 +212,13 @@ def WordPaths(alphabet, steps=None): r""" - Returns the combinatorial class of paths of the given type of steps. + Return the combinatorial class of paths of the given type of steps. INPUT: - ``alphabet`` - ordered alphabet - - ``steps`` - (default is None). It can be one of the following: + - ``steps`` - (default is ``None``). It can be one of the following: - an iterable ordered container of as many vectors as there are letters in the alphabet. The vectors are associated to the letters @@ -248,7 +248,7 @@ def WordPaths(alphabet, steps=None): OUTPUT: - - The combinatorial class of all paths of the given type. + The combinatorial class of all paths of the given type. EXAMPLES: @@ -321,10 +321,10 @@ def WordPaths(alphabet, steps=None): ... TypeError: Unknown type of steps : square_gridd """ - #Construction of the alphabet + # Construction of the alphabet alphabet = build_alphabet(alphabet) - #If no steps are given, they are guessed from the alphabet + # If no steps are given, they are guessed from the alphabet if steps is None: if alphabet.cardinality() == 2: steps = 'north_east' @@ -335,7 +335,7 @@ def WordPaths(alphabet, steps=None): else: raise TypeError("Unable to make a class WordPaths from %s" % alphabet) - #Returns the class of WordPaths according to the given type of paths + # 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) @@ -405,25 +405,25 @@ def __init__(self, alphabet, steps): sage: WordPaths_all('ab', d) Traceback (most recent call last): ... - ValueError: Can't make vectors from steps + ValueError: cannot make vectors from steps sage: d = ((1,1), (-1,1,0)) sage: WordPaths_all('ab', d) Traceback (most recent call last): ... - ValueError: Can't make summable vectors from steps + ValueError: cannot make summable vectors from steps """ - #Construction of the words class + # Construction of the words class FiniteWords.__init__(self, alphabet) alphabet = self.alphabet() - #Checking the size of alphabet and steps + # Checking the size of alphabet and steps ls = len(steps) la = alphabet.cardinality() - if la != ls and la != 2*ls: + if la != ls and la != 2 * ls: raise TypeError("size of steps (=%s) must equal the size of alphabet (=%s) or half the size of alphabet" % (len(steps), alphabet.cardinality())) - #Construction of the steps + # Construction of the steps from sage.structure.element import Vector if all(isinstance(x, Vector) for x in steps): vsteps = steps @@ -431,13 +431,13 @@ def __init__(self, alphabet, steps): try: vsteps = [vector(s) for s in steps] except (TypeError): - raise ValueError("Can't make vectors from steps") + raise ValueError("cannot make vectors from steps") try: s = sum(vsteps) except (TypeError, AttributeError): - raise ValueError("Can't make summable vectors from steps") + raise ValueError("cannot make summable vectors from steps") - #Complete vsteps with the opposite vectors if needed + # Complete vsteps with the opposite vectors if needed if la == 2 * ls: vsteps += [-v for v in vsteps] @@ -457,9 +457,9 @@ def __eq__(self, other): False """ return self is other or (type(self) is type(other) and - self.alphabet() == other.alphabet() and - self.vector_space() == other.vector_space() and - self.letters_to_steps() == other.letters_to_steps()) + self.alphabet() == other.alphabet() and + self.vector_space() == other.vector_space() and + self.letters_to_steps() == other.letters_to_steps()) def __ne__(self, other): r""" @@ -478,7 +478,7 @@ def __ne__(self, other): @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -524,38 +524,38 @@ def _element_classes(self): dimension = self._vector_space.dimension() if dimension == 2: return { - 'list': FiniteWordPath_2d_list, - 'str': FiniteWordPath_2d_str, - 'tuple': FiniteWordPath_2d_tuple, - 'callable_with_caching': FiniteWordPath_2d_callable_with_caching, - 'callable': FiniteWordPath_2d_callable, - 'iter_with_caching': FiniteWordPath_2d_iter_with_caching, - 'iter': FiniteWordPath_2d_iter, + 'list': FiniteWordPath_2d_list, + 'str': FiniteWordPath_2d_str, + 'tuple': FiniteWordPath_2d_tuple, + 'callable_with_caching': FiniteWordPath_2d_callable_with_caching, + 'callable': FiniteWordPath_2d_callable, + 'iter_with_caching': FiniteWordPath_2d_iter_with_caching, + 'iter': FiniteWordPath_2d_iter, } elif dimension == 3: return { - 'list': FiniteWordPath_3d_list, - 'str': FiniteWordPath_3d_str, - 'tuple': FiniteWordPath_3d_tuple, - 'callable_with_caching': FiniteWordPath_3d_callable_with_caching, - 'callable': FiniteWordPath_3d_callable, - 'iter_with_caching': FiniteWordPath_3d_iter_with_caching, - 'iter': FiniteWordPath_3d_iter, + 'list': FiniteWordPath_3d_list, + 'str': FiniteWordPath_3d_str, + 'tuple': FiniteWordPath_3d_tuple, + 'callable_with_caching': FiniteWordPath_3d_callable_with_caching, + 'callable': FiniteWordPath_3d_callable, + 'iter_with_caching': FiniteWordPath_3d_iter_with_caching, + 'iter': FiniteWordPath_3d_iter, } else: return { - 'list': FiniteWordPath_all_list, - 'str': FiniteWordPath_all_str, - 'tuple': FiniteWordPath_all_tuple, - 'callable_with_caching': FiniteWordPath_all_callable_with_caching, - 'callable': FiniteWordPath_all_callable, - 'iter_with_caching': FiniteWordPath_all_iter_with_caching, - 'iter': FiniteWordPath_all_iter, + 'list': FiniteWordPath_all_list, + 'str': FiniteWordPath_all_str, + 'tuple': FiniteWordPath_all_tuple, + 'callable_with_caching': FiniteWordPath_all_callable_with_caching, + 'callable': FiniteWordPath_all_callable, + 'iter_with_caching': FiniteWordPath_all_iter_with_caching, + 'iter': FiniteWordPath_all_iter, } - def __repr__(self): + def __repr__(self) -> str: r""" - Returns a string representation of self. + Return a string representation of ``self``. EXAMPLES:: @@ -566,9 +566,9 @@ def __repr__(self): """ return "Word Paths over %s steps" % self.alphabet().cardinality() - def letters_to_steps(self): + def letters_to_steps(self) -> dict: r""" - Returns the dictionary mapping letters to vectors (steps). + Return the dictionary mapping letters to vectors (steps). EXAMPLES:: @@ -632,18 +632,17 @@ def __init__(self, alphabet): Word Paths on the square grid sage: P == loads(dumps(P)) True - """ - #Construction of the steps - d = [(1 ,0), (0,1), (-1,0), (0,-1)] + # Construction of the steps + d = [(1, 0), (0, 1), (-1, 0), (0, -1)] - #Construction of the class + # Construction of the class super().__init__(alphabet, steps=d) @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -661,16 +660,16 @@ def _element_classes(self): """ return { - 'list': FiniteWordPath_square_grid_list, - 'str': FiniteWordPath_square_grid_str, - 'tuple': FiniteWordPath_square_grid_tuple, - 'callable_with_caching': FiniteWordPath_square_grid_callable_with_caching, - 'callable': FiniteWordPath_square_grid_callable, - 'iter_with_caching': FiniteWordPath_square_grid_iter_with_caching, - 'iter': FiniteWordPath_square_grid_iter, + 'list': FiniteWordPath_square_grid_list, + 'str': FiniteWordPath_square_grid_str, + 'tuple': FiniteWordPath_square_grid_tuple, + 'callable_with_caching': FiniteWordPath_square_grid_callable_with_caching, + 'callable': FiniteWordPath_square_grid_callable, + 'iter_with_caching': FiniteWordPath_square_grid_iter_with_caching, + 'iter': FiniteWordPath_square_grid_iter, } - def __repr__(self): + def __repr__(self) -> str: r""" EXAMPLES:: @@ -701,20 +700,19 @@ def __init__(self, alphabet): Word Paths on the triangle grid sage: P == loads(dumps(P)) True - """ K = QuadraticField(3, 'sqrt3') sqrt3 = K.gen() - #Construction of the steps - d = (vector(K, (1 ,0 )), - vector(K, (ZZ(1)/ZZ(2), sqrt3/2)), - vector(K, (ZZ(-1)/ZZ(2), sqrt3/2)), - vector(K, (-1 , 0 )), - vector(K, (ZZ(-1)/ZZ(2), -sqrt3/2 )), - vector(K, (ZZ(1)/ZZ(2), -sqrt3/2 ))) + # Construction of the steps + d = (vector(K, (1, 0)), + vector(K, (ZZ(1) / ZZ(2), sqrt3 / 2)), + vector(K, (ZZ(-1) / ZZ(2), sqrt3 / 2)), + vector(K, (-1, 0)), + vector(K, (ZZ(-1) / ZZ(2), -sqrt3 / 2)), + vector(K, (ZZ(1) / ZZ(2), -sqrt3 / 2))) - #Construction of the class + # Construction of the class super().__init__(alphabet, steps=d) self._infinite_word_class = None @@ -723,7 +721,7 @@ def __init__(self, alphabet): @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -741,16 +739,16 @@ def _element_classes(self): """ return { - 'list': FiniteWordPath_triangle_grid_list, - 'str': FiniteWordPath_triangle_grid_str, - 'tuple': FiniteWordPath_triangle_grid_tuple, - 'callable_with_caching': FiniteWordPath_triangle_grid_callable_with_caching, - 'callable': FiniteWordPath_triangle_grid_callable, - 'iter_with_caching': FiniteWordPath_triangle_grid_iter_with_caching, - 'iter': FiniteWordPath_triangle_grid_iter, + 'list': FiniteWordPath_triangle_grid_list, + 'str': FiniteWordPath_triangle_grid_str, + 'tuple': FiniteWordPath_triangle_grid_tuple, + 'callable_with_caching': FiniteWordPath_triangle_grid_callable_with_caching, + 'callable': FiniteWordPath_triangle_grid_callable, + 'iter_with_caching': FiniteWordPath_triangle_grid_iter_with_caching, + 'iter': FiniteWordPath_triangle_grid_iter, } - def __repr__(self): + def __repr__(self) -> str: r""" EXAMPLES:: @@ -781,9 +779,8 @@ def __init__(self, alphabet): Word Paths on the hexagonal grid sage: P == loads(dumps(P)) True - """ - #Construction of the class + # Construction of the class super().__init__(alphabet) self._infinite_word_class = None @@ -792,7 +789,7 @@ def __init__(self, alphabet): @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -810,16 +807,16 @@ def _element_classes(self): """ return { - 'list': FiniteWordPath_hexagonal_grid_list, - 'str': FiniteWordPath_hexagonal_grid_str, - 'tuple': FiniteWordPath_hexagonal_grid_tuple, - 'callable_with_caching': FiniteWordPath_hexagonal_grid_callable_with_caching, - 'callable': FiniteWordPath_hexagonal_grid_callable, - 'iter_with_caching': FiniteWordPath_hexagonal_grid_iter_with_caching, - 'iter': FiniteWordPath_hexagonal_grid_iter, + 'list': FiniteWordPath_hexagonal_grid_list, + 'str': FiniteWordPath_hexagonal_grid_str, + 'tuple': FiniteWordPath_hexagonal_grid_tuple, + 'callable_with_caching': FiniteWordPath_hexagonal_grid_callable_with_caching, + 'callable': FiniteWordPath_hexagonal_grid_callable, + 'iter_with_caching': FiniteWordPath_hexagonal_grid_iter_with_caching, + 'iter': FiniteWordPath_hexagonal_grid_iter, } - def __repr__(self): + def __repr__(self) -> str: r""" EXAMPLES:: @@ -852,8 +849,9 @@ def __init__(self, alphabet): sage: P == loads(dumps(P)) True """ - #Construction of the class - d = [(1,0,0), (0,1,0), (0,0,1), (-1,0,0), (0,-1,0), (0,0,-1)] + # Construction of the class + d = [(1, 0, 0), (0, 1, 0), (0, 0, 1), + (-1, 0, 0), (0, -1, 0), (0, 0, -1)] super().__init__(alphabet, steps=d) self._infinite_word_class = None self._finite_word_class = FiniteWordPath_cube_grid @@ -861,7 +859,7 @@ def __init__(self, alphabet): @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -879,15 +877,15 @@ def _element_classes(self): """ return {'list': FiniteWordPath_cube_grid_list, - 'str': FiniteWordPath_cube_grid_str, - 'tuple': FiniteWordPath_cube_grid_tuple, - 'callable_with_caching': FiniteWordPath_cube_grid_callable_with_caching, - 'callable': FiniteWordPath_cube_grid_callable, - 'iter_with_caching': FiniteWordPath_cube_grid_iter_with_caching, - 'iter': FiniteWordPath_cube_grid_iter, - } - - def __repr__(self): + 'str': FiniteWordPath_cube_grid_str, + 'tuple': FiniteWordPath_cube_grid_tuple, + 'callable_with_caching': FiniteWordPath_cube_grid_callable_with_caching, + 'callable': FiniteWordPath_cube_grid_callable, + 'iter_with_caching': FiniteWordPath_cube_grid_iter_with_caching, + 'iter': FiniteWordPath_cube_grid_iter, + } + + def __repr__(self) -> str: r""" EXAMPLES:: @@ -919,8 +917,8 @@ def __init__(self, alphabet): sage: P == loads(dumps(P)) True """ - #Construction of the class - d = [(1,1), (1,-1)] + # Construction of the class + d = [(1, 1), (1, -1)] super().__init__(alphabet, steps=d) self._infinite_word_class = None @@ -929,7 +927,7 @@ def __init__(self, alphabet): @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -947,15 +945,15 @@ def _element_classes(self): """ return {'list': FiniteWordPath_dyck_list, - 'str': FiniteWordPath_dyck_str, - 'tuple': FiniteWordPath_dyck_tuple, - 'callable_with_caching': FiniteWordPath_dyck_callable_with_caching, - 'callable': FiniteWordPath_dyck_callable, - 'iter_with_caching': FiniteWordPath_dyck_iter_with_caching, - 'iter': FiniteWordPath_dyck_iter, - } - - def __repr__(self): + 'str': FiniteWordPath_dyck_str, + 'tuple': FiniteWordPath_dyck_tuple, + 'callable_with_caching': FiniteWordPath_dyck_callable_with_caching, + 'callable': FiniteWordPath_dyck_callable, + 'iter_with_caching': FiniteWordPath_dyck_iter_with_caching, + 'iter': FiniteWordPath_dyck_iter, + } + + def __repr__(self) -> str: r""" EXAMPLES:: @@ -988,8 +986,8 @@ def __init__(self, alphabet): sage: P == loads(dumps(P)) True """ - #Construction of the class - d = [(0,1), (1,0)] + # Construction of the class + d = [(0, 1), (1, 0)] super().__init__(alphabet, steps=d) self._infinite_word_class = None self._finite_word_class = FiniteWordPath_north_east @@ -997,7 +995,7 @@ def __init__(self, alphabet): @lazy_attribute def _element_classes(self): r""" - Returns a dictionary that gives the class of the elements of self. + Return a dictionary that gives the class of the elements of ``self``. The word may be finite (infinite or of unknown length is not supported yet). @@ -1015,15 +1013,15 @@ def _element_classes(self): """ return {'list': FiniteWordPath_north_east_list, - 'str': FiniteWordPath_north_east_str, - 'tuple': FiniteWordPath_north_east_tuple, - 'callable_with_caching': FiniteWordPath_north_east_callable_with_caching, - 'callable': FiniteWordPath_north_east_callable, - 'iter_with_caching': FiniteWordPath_north_east_iter_with_caching, - 'iter': FiniteWordPath_north_east_iter, - } - - def __repr__(self): + 'str': FiniteWordPath_north_east_str, + 'tuple': FiniteWordPath_north_east_tuple, + 'callable_with_caching': FiniteWordPath_north_east_callable_with_caching, + 'callable': FiniteWordPath_north_east_callable, + 'iter_with_caching': FiniteWordPath_north_east_iter_with_caching, + 'iter': FiniteWordPath_north_east_iter, + } + + def __repr__(self) -> str: r""" EXAMPLES:: @@ -1042,9 +1040,9 @@ def __repr__(self): ####################################################################### class FiniteWordPath_all(SageObject): - def _repr_(self): + def _repr_(self) -> str: r""" - Returns a string representation of this path. + Return a string representation of this path. EXAMPLES:: @@ -1058,7 +1056,7 @@ def _repr_(self): def points(self, include_last=True): r""" - Returns an iterator yielding a list of points used to draw the path + Return an iterator yielding a list of points used to draw the path represented by this word. INPUT: @@ -1093,11 +1091,11 @@ def points(self, include_last=True): def start_point(self): r""" - Return the starting point of self. + Return the starting point of ``self``. OUTPUT: - vector + vector EXAMPLES:: @@ -1114,7 +1112,7 @@ def start_point(self): @cached_method def end_point(self): r""" - Returns the end point of the path. + Return the end point of the path. EXAMPLES:: @@ -1138,10 +1136,10 @@ def end_point(self): def directive_vector(self): r""" - Returns the directive vector of self. + Return the directive vector of ``self``. The directive vector is the vector starting at the start point - and ending at the end point of the path self. + and ending at the end point of the path ``self``. EXAMPLES:: @@ -1160,9 +1158,11 @@ def directive_vector(self): """ return self.end_point() - self.start_point() - def is_closed(self): + def is_closed(self) -> bool: r""" - Returns True if the path is closed, i.e. if the origin and the end of + Return ``True`` if the path is closed. + + A path is closed if the origin and the end of the path are equal. EXAMPLES:: @@ -1179,10 +1179,12 @@ def is_closed(self): """ return self.start_point() == self.end_point() - def is_simple(self): + def is_simple(self) -> bool: r""" - Returns True if the path is simple, i.e. if all its points are - distincts. + Return ``True`` if the path is simple. + + A path is simple if all its points are + distinct. If the path is closed, the last point is not considered. @@ -1215,9 +1217,9 @@ def is_simple(self): return False return True - def tikz_trajectory(self): + def tikz_trajectory(self) -> str: r""" - Returns the trajectory of self as a tikz str. + Return the trajectory of ``self`` as a ``tikz`` string. EXAMPLES:: @@ -1228,8 +1230,7 @@ def tikz_trajectory(self): """ from sage.misc.functional import N as n - f = lambda x: n(x,digits=3) - l = [str(tuple(map(f, pt))) for pt in self.points()] + l = (str(tuple(n(x, digits=3) for x in pt)) for pt in self.points()) return ' -- '.join(l) def projected_point_iterator(self, v=None, ring=None): @@ -1292,7 +1293,7 @@ def projected_point_iterator(self, v=None, ring=None): yield R * q def plot_projection(self, v=None, letters=None, color=None, ring=None, - size=12, kind='right'): + size=12, kind='right'): r""" Return an image of the projection of the successive points of the path into the space orthogonal to the given vector. @@ -1405,7 +1406,7 @@ def plot_projection(self, v=None, letters=None, color=None, ring=None, if color is None: from sage.plot.all import hue A = self.parent().alphabet() - color = {a: hue(A.rank(a)/float(A.cardinality())) for a in A} + color = {a: hue(A.rank(a) / float(A.cardinality())) for a in A} it = self.projected_point_iterator(v, ring=ring) if kind == 'right': next(it) @@ -1464,7 +1465,7 @@ def projected_path(self, v=None, ring=None): R = vector_on_axis_rotation_matrix(v, 0, ring=ring)[1:] d = self.parent().letters_to_steps() A = self.parent().alphabet() - nvvectors = [R*d[a] for a in A] + nvvectors = [R * d[a] for a in A] projected_parent = WordPaths(A, nvvectors) return projected_parent(self) @@ -1488,13 +1489,13 @@ def is_tangent(self): class FiniteWordPath_2d(FiniteWordPath_all): - def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), - fill=True, filloptions=dict(rgbcolor='red',alpha=0.2), - startpoint=True, startoptions=dict(rgbcolor='red',pointsize=100), - endarrow=True, arrowoptions=dict(rgbcolor='red',arrowsize=20,width=3), - gridlines=False, gridoptions=dict()): + def plot(self, pathoptions=dict(rgbcolor='red', thickness=3), + fill=True, filloptions=dict(rgbcolor='red', alpha=0.2), + startpoint=True, startoptions=dict(rgbcolor='red', pointsize=100), + endarrow=True, arrowoptions=dict(rgbcolor='red', arrowsize=20, width=3), + gridlines=False, gridoptions=dict()): r""" - Returns a 2d Graphics illustrating the path. + Return a 2d Graphics illustrating the path. INPUT: @@ -1579,15 +1580,15 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), #################### pts = [[RR(i) for i in x] for x in pts] - #Inside + # Inside if fill and self.is_closed(): G += polygon(pts, **filloptions) - #Startpoint + # Startpoint if startpoint: G += point(pts[0], **startoptions) - #The path itself + # The path itself if endarrow and not self.is_empty(): G += line(pts[:-1], **pathoptions) G += arrow(pts[-2], pts[-1], **arrowoptions) @@ -1597,11 +1598,11 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), G.axes(False) G.set_aspect_ratio(1) - #gridlines - ###############BUG############## - #Gridlines doesn't work fine. - #It should be gridlines="integers" - ###############BUG############## + # gridlines + # ############## BUG ############## + # Gridlines doesn't work fine. + # It should be gridlines="integers" + # ############## BUG ############## if gridlines: G = G.show(gridlines=True, **gridoptions) @@ -1609,7 +1610,7 @@ def plot(self, pathoptions=dict(rgbcolor='red',thickness=3), def animate(self): r""" - Returns an animation object illustrating the path growing step by step. + Return an animation object illustrating the path growing step by step. EXAMPLES:: @@ -1675,17 +1676,17 @@ def animate(self): #################### #################### - #Bug: plot needs float for coordinates + # Bug: plot needs float for coordinates #################### #################### pts = [[RR(i) for i in x] for x in pts] - images = [line(pts[:i]) for i in range(1,len(pts)+1)] + images = [line(pts[:i]) for i in range(1, len(pts) + 1)] if self.is_closed(): images.append(polygon(pts)) - #Get the window of the last image + # Get the window of the last image last_image = images[-1] kwds = {} kwds['xmin'] = last_image.xmin() @@ -1699,7 +1700,7 @@ def animate(self): def plot_directive_vector(self, options=dict(rgbcolor='blue')): r""" - Returns an arrow 2d graphics that goes from the start of the path + Return an arrow 2d graphics that goes from the start of the path to the end. INPUT: @@ -1740,7 +1741,7 @@ def plot_directive_vector(self, options=dict(rgbcolor='blue')): def area(self): r""" - Returns the area of a closed path. + Return the area of a closed path. INPUT: @@ -1760,7 +1761,7 @@ def area(self): def height(self): r""" - Returns the height of self. + Return the height of ``self``. The height of a `2d`-path is merely the difference between the highest and the lowest `y`-coordinate of each @@ -1827,7 +1828,7 @@ def height_vector(self): def width(self): r""" - Returns the width of self. + Return the width of ``self``. The height of a `2d`-path is merely the difference between the rightmost and the leftmost `x`-coordinate of each @@ -1835,7 +1836,7 @@ def width(self): OUTPUT: - non negative real number + non negative real number EXAMPLES:: @@ -1894,7 +1895,7 @@ def width_vector(self): def xmin(self): r""" - Returns the minimum of the x-coordinates of the path. + Return the minimum of the x-coordinates of the path. EXAMPLES:: @@ -1917,11 +1918,11 @@ def xmin(self): sage: w.xmin() 0.000000000000000 """ - return min(x for (x,_) in self.points()) + return min(x for (x, _) in self.points()) def ymin(self): r""" - Returns the minimum of the y-coordinates of the path. + Return the minimum of the y-coordinates of the path. EXAMPLES:: @@ -1944,11 +1945,11 @@ def ymin(self): sage: w.ymin() 0.000000000000000 """ - return min(y for (_,y) in self.points()) + return min(y for (_, y) in self.points()) def xmax(self): r""" - Returns the maximum of the x-coordinates of the path. + Return the maximum of the x-coordinates of the path. EXAMPLES:: @@ -1971,11 +1972,11 @@ def xmax(self): sage: w.xmax() 4.50000000000000 """ - return max(x for (x,_) in self.points()) + return max(x for (x, _) in self.points()) def ymax(self): r""" - Returns the maximum of the y-coordinates of the path. + Return the maximum of the y-coordinates of the path. EXAMPLES:: @@ -1998,12 +1999,12 @@ def ymax(self): sage: w.ymax() 2.59807621135332 """ - return max(y for (_,y) in self.points()) + return max(y for (_, y) in self.points()) class FiniteWordPath_3d(FiniteWordPath_all): - def plot(self, pathoptions=dict(rgbcolor='red',arrow_head=True,thickness=3), - startpoint=True, startoptions=dict(rgbcolor='red',size=10)): + def plot(self, pathoptions=dict(rgbcolor='red', arrow_head=True, thickness=3), + startpoint=True, startoptions=dict(rgbcolor='red', size=10)): r""" INPUT: @@ -2031,9 +2032,9 @@ def plot(self, pathoptions=dict(rgbcolor='red',arrow_head=True,thickness=3), Graphics3d Object """ - #The following line seems not to work for 3d - #G = Graphics() - #so we draw to start a small almost invisible point instead: + # The following line seems not to work for 3d + # G = Graphics() + # so we draw to start a small almost invisible point instead: G = point([self.start_point()], size=1) pts = list(self.points()) if startpoint: @@ -2050,9 +2051,9 @@ def plot(self, pathoptions=dict(rgbcolor='red',arrow_head=True,thickness=3), ####################################################################### class FiniteWordPath_square_grid(FiniteWordPath_2d): - def is_closed(self): + def is_closed(self) -> bool: r""" - Returns True if self represents a closed path and False otherwise. + Return whether ``self`` represents a closed path. EXAMPLES:: @@ -2073,7 +2074,7 @@ def is_closed(self): def area(self): r""" - Returns the area of a closed path. + Return the area of a closed path. INPUT: @@ -2177,10 +2178,12 @@ def _area_vh(self, x=0, y=0): x -= 1 return area // 2 - def is_simple(self): + def is_simple(self) -> bool: r""" - Returns True if the path is simple, i.e. if all its points are - distincts. + Return whether the path is simple. + + A path is simple if all its points are + distinct. If the path is closed, the last point is not considered. @@ -2217,9 +2220,9 @@ def is_simple(self): """ return super().is_simple() - def tikz_trajectory(self): + def tikz_trajectory(self) -> str: r""" - Returns the trajectory of self as a tikz str. + Return the trajectory of ``self`` as a ``tikz`` string. EXAMPLES:: @@ -2246,7 +2249,7 @@ class FiniteWordPath_triangle_grid(FiniteWordPath_2d): # redefined here with conversion to RR in order to avoid this problem def xmin(self): r""" - Returns the minimum of the x-coordinates of the path. + Return the minimum of the x-coordinates of the path. EXAMPLES:: @@ -2257,11 +2260,11 @@ def xmin(self): sage: w.xmin() -3.00000000000000 """ - return min(RR(x) for (x,_) in self.points()) + return min(RR(x) for (x, _) in self.points()) def ymin(self): r""" - Returns the minimum of the y-coordinates of the path. + Return the minimum of the y-coordinates of the path. EXAMPLES:: @@ -2272,11 +2275,11 @@ def ymin(self): sage: w.ymin() -0.866025403784439 """ - return min(RR(y) for (_,y) in self.points()) + return min(RR(y) for (_, y) in self.points()) def xmax(self): r""" - Returns the maximum of the x-coordinates of the path. + Return the maximum of the x-coordinates of the path. EXAMPLES:: @@ -2287,11 +2290,11 @@ def xmax(self): sage: w.xmax() 4.00000000000000 """ - return max(RR(x) for (x,_) in self.points()) + return max(RR(x) for (x, _) in self.points()) def ymax(self): r""" - Returns the maximum of the y-coordinates of the path. + Return the maximum of the y-coordinates of the path. EXAMPLES:: @@ -2302,7 +2305,7 @@ def ymax(self): sage: w.ymax() 8.66025403784439 """ - return max(RR(y) for (_,y) in self.points()) + return max(RR(y) for (_, y) in self.points()) # TODO: faire une verification du mot pour etre sur hexagonal grid @@ -2353,7 +2356,7 @@ class FiniteWordPath_dyck(FiniteWordPath_2d): # # ####################################################################### -##### Finite paths ##### +# #### Finite paths #### class FiniteWordPath_all_list(WordDatatype_list, FiniteWordPath_all, FiniteWord_class): r""" @@ -2416,7 +2419,7 @@ class FiniteWordPath_all_callable(WordDatatype_callable, FiniteWordPath_all, Fin pass -##### Finite paths on 2d ##### +# #### Finite paths on 2d #### class FiniteWordPath_2d_list(WordDatatype_list, FiniteWordPath_2d, FiniteWord_class): r""" @@ -2479,7 +2482,7 @@ class FiniteWordPath_2d_callable(WordDatatype_callable, FiniteWordPath_2d, Finit pass -##### Finite paths on 3d ##### +# #### Finite paths on 3d #### class FiniteWordPath_3d_list(WordDatatype_list, FiniteWordPath_3d, FiniteWord_class): r""" @@ -2542,7 +2545,7 @@ class FiniteWordPath_3d_callable(WordDatatype_callable, FiniteWordPath_3d, Finit pass -##### Finite paths on square grid ##### +# #### Finite paths on square grid #### class FiniteWordPath_square_grid_list(WordDatatype_list, FiniteWordPath_square_grid, FiniteWord_class): r""" @@ -2605,12 +2608,12 @@ class FiniteWordPath_square_grid_callable(WordDatatype_callable, FiniteWordPath_ pass -##### Unknown length paths on square grid (experimental) ##### +# #### Unknown length paths on square grid (experimental) #### -#class WordPath_square_grid_iter_with_caching(WordDatatype_iter_with_caching, FiniteWordPath_square_grid, Word_class): +# class WordPath_square_grid_iter_with_caching(WordDatatype_iter_with_caching, FiniteWordPath_square_grid, Word_class): # pass -##### Finite paths on triangle grid ##### +# #### Finite paths on triangle grid #### class FiniteWordPath_triangle_grid_list(WordDatatype_list, FiniteWordPath_triangle_grid, FiniteWord_class): r""" @@ -2673,7 +2676,7 @@ class FiniteWordPath_triangle_grid_callable(WordDatatype_callable, FiniteWordPat pass -##### Finite paths on hexagonal grid ##### +# #### Finite paths on hexagonal grid #### class FiniteWordPath_hexagonal_grid_list(WordDatatype_list, FiniteWordPath_hexagonal_grid, FiniteWord_class): r""" @@ -2736,7 +2739,7 @@ class FiniteWordPath_hexagonal_grid_callable(WordDatatype_callable, FiniteWordPa pass -##### Finite paths on cube grid ##### +# #### Finite paths on cube grid #### class FiniteWordPath_cube_grid_list(WordDatatype_list, FiniteWordPath_cube_grid, FiniteWord_class): r""" @@ -2799,7 +2802,7 @@ class FiniteWordPath_cube_grid_callable(WordDatatype_callable, FiniteWordPath_cu pass -##### Finite paths on north_east ##### +# #### Finite paths on north_east #### class FiniteWordPath_north_east_list(WordDatatype_list, FiniteWordPath_north_east, FiniteWord_class): r""" @@ -2862,7 +2865,7 @@ class FiniteWordPath_north_east_callable(WordDatatype_callable, FiniteWordPath_n pass -##### Finite paths on dyck ##### +# #### Finite paths on dyck #### class FiniteWordPath_dyck_list(WordDatatype_list, FiniteWordPath_dyck, FiniteWord_class): r"""