diff --git a/surface_dynamics/interval_exchanges/conversion.py b/surface_dynamics/interval_exchanges/conversion.py index f6e515b..33b795c 100644 --- a/surface_dynamics/interval_exchanges/conversion.py +++ b/surface_dynamics/interval_exchanges/conversion.py @@ -1,9 +1,8 @@ r""" Conversion to and from pyintervalxt """ - -from sage.all import NumberField, QQ, ZZ -from sage.rings.number_field.number_field_base import is_NumberField +from sage.all import QQ, ZZ +from sage.categories.number_fields import NumberFields from . import constructors as iet from .iet import IntervalExchangeTransformation @@ -59,7 +58,7 @@ def iet_to_pyintervalxt(T): elif K == QQ: from gmpxxyy import mpq lengths = tuple(mpq(x.numerator(), x.denominator()) for x in T._lengths) - elif is_NumberField(K): + elif K in NumberFields(): from pyeantic.real_embedded_number_field import RealEmbeddedNumberField L = RealEmbeddedNumberField(K) lengths = tuple(L(x).renf_elem for x in T._lengths) diff --git a/surface_dynamics/interval_exchanges/flip_sequence.py b/surface_dynamics/interval_exchanges/flip_sequence.py index 491feab..dcbe676 100644 --- a/surface_dynamics/interval_exchanges/flip_sequence.py +++ b/surface_dynamics/interval_exchanges/flip_sequence.py @@ -237,7 +237,7 @@ def end(self): """ return self._end.__copy__() - def __eq__(self, other): + def __eq__(self, other) -> bool: if type(self) != type(other): raise TypeError('incomparable') @@ -247,7 +247,7 @@ def __eq__(self, other): self._left_right_inverse == other._left_right_inverse and \ self._relabelling == other._relabelling - def __ne__(self, other): + def __ne__(self, other) -> bool: return not (self == other) def _check(self): @@ -357,7 +357,7 @@ def _simplified_flip_sequence(self): l.append(winner.upper()) return ''.join(l) - def _repr_(self): + def _repr_(self) -> str: args = [repr(self._start.str()), repr(self._simplified_flip_sequence())] if self._top_bottom_inverse: args.append('top_bottom_inverse=True') @@ -458,7 +458,7 @@ def close(self): self._end.relabel(p) self._relabelling = perm_compose(self._relabelling, p) - def is_closed(self): + def is_closed(self) -> bool: r""" Return whether the path is closed, that is whether its start and end coincide. @@ -521,7 +521,7 @@ def losers(self): """ return self.winners_losers()[1] - def is_complete(self): + def is_complete(self) -> bool: r""" Return whether that all winners appear. @@ -663,8 +663,6 @@ def interval_substitution(self, as_plain_list=False): for p, winner, side in reversed(self): winner_letter = p._labels[winner][side] loser_letter = p._labels[1-winner][side] - top_letter = p._labels[0][side] - bottom_letter = p._labels[1][side] if side == 0: words[winner_letter] = words[loser_letter] + words[winner_letter] else: diff --git a/surface_dynamics/interval_exchanges/iet.py b/surface_dynamics/interval_exchanges/iet.py index 7bf6c16..273d7b9 100644 --- a/surface_dynamics/interval_exchanges/iet.py +++ b/surface_dynamics/interval_exchanges/iet.py @@ -295,10 +295,9 @@ def translations(self): p = self._permutation._labels top_twin = self._permutation._twin[0] top = p[0] - bot = p[1] translations = self.vector_space()() - for i0,j in enumerate(top): + for i0, j in enumerate(top): i1 = top_twin[i0] translations[j] = im_sg[i1] - dom_sg[i0] @@ -449,7 +448,7 @@ def normalize(self, total=1, inplace=False): (1/2, 3/2) """ try: - y = float(total) + float(total) except ValueError: raise TypeError(f"unable to convert x (='{total}') into a real number") @@ -465,7 +464,7 @@ def normalize(self, total=1, inplace=False): if not inplace: return res - def __repr__(self): + def __repr__(self) -> str: r""" A representation string. @@ -479,12 +478,12 @@ def __repr__(self): a a """ - interval = "[0, %s["%self.length() - s = "Interval exchange transformation of %s "%interval - s += "with permutation\n%s"%self._permutation + interval = "[0, %s[" % self.length() + s = "Interval exchange transformation of %s " % interval + s += "with permutation\n%s" % self._permutation return s - def is_identity(self): + def is_identity(self) -> bool: r""" Returns True if self is the identity. @@ -1007,7 +1006,7 @@ def __mul__(self, other): p = LabelledPermutationIET((top_interval,bottom_interval)) return IntervalExchangeTransformation(p,l_lengths) - def __eq__(self, other): + def __eq__(self, other) -> bool: r""" Tests equality @@ -1024,7 +1023,7 @@ def __eq__(self, other): self._permutation == other._permutation and self._lengths == other._lengths) - def __ne__(self, other): + def __ne__(self, other) -> bool: r""" Tests difference @@ -1060,7 +1059,6 @@ def recoding(self, n): aba abd abc dbc ccb cba bab bdb bcc bcb cba aba abd abc dbc bcc bcb ccb bab bdb """ - length = len(self._permutation) lengths = self._lengths A = self.permutation().alphabet() unrank = A.unrank @@ -1072,14 +1070,11 @@ def recoding(self, n): sg_top = self.domain_singularities()[1:-1] # iterates of the top singularities cuts = [[[i], lengths[i]] for i in bot] # the refined bottom interval - translations = self.translations() - for step in range(n-1): i = 0 y = self.base_ring().zero() - new_sg_top = [] limits = [0] - for j,x in enumerate(sg_top): + for j, x in enumerate(sg_top): while y < x: cuts[i][0].append(top[j]) y += cuts[i][1] @@ -1591,13 +1586,11 @@ def _rauzy_move(self, side=-1, error_on_saddles=True): length_bot = self._lengths[bot] if length_top > length_bot: - winner = 0 # TODO: this value is ignored winner_interval = top loser_interval = bot abc = (bot_letter, bot_letter, top_letter) winner = 't' elif length_top < length_bot: - winner = 1 # TODO: this value is ignored winner_interval = bot loser_interval = top abc = (top_letter, bot_letter, top_letter) @@ -1612,7 +1605,7 @@ def _rauzy_move(self, side=-1, error_on_saddles=True): bot = p._labels[1][side] p._identify_intervals(side) self._lengths[top] = 0 - return None, (bot_letter,bot_letter,top_letter) + return None, (bot_letter, bot_letter, top_letter) self._permutation = self._permutation.rauzy_move(winner=winner, side=side, inplace=True) self._lengths[winner_interval] -= self._lengths[loser_interval] diff --git a/surface_dynamics/interval_exchanges/iet_family.pyx b/surface_dynamics/interval_exchanges/iet_family.pyx index 32ffea4..6bb6d6d 100644 --- a/surface_dynamics/interval_exchanges/iet_family.pyx +++ b/surface_dynamics/interval_exchanges/iet_family.pyx @@ -272,7 +272,7 @@ cdef class IETFamily: F = FreeModule(QQ, self.dim) return [F([self.ray_coefficient(i, j) for j in range(self.dim)]) for i in range(self.length)] - def __repr__(self): + def __repr__(self) -> str: r""" TESTS:: @@ -441,7 +441,7 @@ cdef class IETFamily: # this is completely useless and checks many times the same thing # we should just look at left/right Rauzy induction - def has_connection(self): + def has_connection(self) -> bool: r""" Check whether this family has a connection. diff --git a/surface_dynamics/interval_exchanges/labelled.py b/surface_dynamics/interval_exchanges/labelled.py index c18f5ea..1b4f55e 100644 --- a/surface_dynamics/interval_exchanges/labelled.py +++ b/surface_dynamics/interval_exchanges/labelled.py @@ -84,14 +84,14 @@ sage: s1.incidence_matrix() == s2.incidence_matrix().transpose() True """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2008 Vincent Delecroix <20100.delecroix@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # https://www.gnu.org/licenses/ -#***************************************************************************** +# *************************************************************************** from copy import copy from sage.structure.sage_object import SageObject @@ -740,7 +740,7 @@ class LabelledPermutationLI(LabelledPermutation, OrientablePermutationLI): sage: p in r True """ - def has_right_rauzy_move(self, winner): + def has_right_rauzy_move(self, winner) -> bool: r""" Test of Rauzy movability with a specified winner) @@ -1534,7 +1534,7 @@ def orbit_substitution(self): substitution = orbit_substitution # standard name dual_substitution = interval_substitution # standard name - def is_full(self): + def is_full(self) -> bool: r""" Tests the fullness. diff --git a/surface_dynamics/interval_exchanges/marked_partition.py b/surface_dynamics/interval_exchanges/marked_partition.py index 6e03ec8..f6dc5a1 100644 --- a/surface_dynamics/interval_exchanges/marked_partition.py +++ b/surface_dynamics/interval_exchanges/marked_partition.py @@ -87,7 +87,7 @@ def __hash__(self): """ return hash(self.t) + hash(self.data) - def _repr_(self): + def _repr_(self) -> str: r""" String representation. @@ -104,7 +104,7 @@ def _repr_(self): else: return "%do%d" % self.data - def __eq__(self, other): + def __eq__(self, other) -> bool: r""" TESTS:: @@ -118,7 +118,7 @@ def __eq__(self, other): return False return self.t == other.t and self.data == other.data - def __ne__(self, other): + def __ne__(self, other) -> bool: r""" TESTS:: @@ -273,7 +273,7 @@ def __init__(self, *args, **kwds): (self.m.data[0] == self.m.data[1] and list(self.p).count(self.m.data[0]) < 2)): raise ValueError("parts do not contains (m_l,m_r) = (%d,%d)" % (self.m.data[0], self.m.data[1])) - def _repr_(self): + def _repr_(self) -> str: r""" String representation. @@ -287,7 +287,7 @@ def _repr_(self): """ return "%s %s" % (self.m, self.p) - def __eq__(self, other): + def __eq__(self, other) -> bool: r""" Equality test. @@ -304,7 +304,7 @@ def __eq__(self, other): return self.m == other.m and self.p == other.p - def __ne__(self, other): + def __ne__(self, other) -> bool: r""" Difference test. @@ -385,7 +385,7 @@ def marking(self): """ return self.m - def is_odd(self): + def is_odd(self) -> bool: r""" Return ``True`` if all terms of p are odd. diff --git a/surface_dynamics/interval_exchanges/rauzy_class_cardinality.py b/surface_dynamics/interval_exchanges/rauzy_class_cardinality.py index e354d65..f9b374b 100644 --- a/surface_dynamics/interval_exchanges/rauzy_class_cardinality.py +++ b/surface_dynamics/interval_exchanges/rauzy_class_cardinality.py @@ -20,27 +20,26 @@ Vincent Delecroix """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2019 Vincent Delecroix <20100.delecroix@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # https://www.gnu.org/licenses/ -#***************************************************************************** +# *************************************************************************** +from sage.arith.all import factorial +from sage.combinat.partition import Partition from sage.misc.cachefunc import cached_function - from sage.rings.integer import Integer -from sage.combinat.partition import Partition -from sage.arith.all import factorial, binomial ######################### # PROFILES AND MARKINGS # ######################### -def marking_iterator(profile,left=None,standard=False): +def marking_iterator(profile, left=None, standard=False): r""" Returns the marked profile associated to a partition diff --git a/surface_dynamics/interval_exchanges/reduced.py b/surface_dynamics/interval_exchanges/reduced.py index 48a9486..e26571c 100644 --- a/surface_dynamics/interval_exchanges/reduced.py +++ b/surface_dynamics/interval_exchanges/reduced.py @@ -45,21 +45,17 @@ sage: p = ReducedPermutationIET([[1,2,3],[3,2,1]]) sage: d = ReducedRauzyDiagram(p) """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2008 Vincent Delecroix <20100.delecroix@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # https://www.gnu.org/licenses/ -#***************************************************************************** +# *************************************************************************** -from sage.structure.sage_object import SageObject - -from copy import copy - -from sage.combinat.words.alphabet import Alphabet from sage.rings.integer import Integer +from sage.structure.sage_object import SageObject from .template import OrientablePermutationIET, OrientablePermutationLI # permutations from .template import FlippedPermutationIET, FlippedPermutationLI # flipped permutations diff --git a/surface_dynamics/interval_exchanges/template.py b/surface_dynamics/interval_exchanges/template.py index 0b10b45..ad1ee51 100644 --- a/surface_dynamics/interval_exchanges/template.py +++ b/surface_dynamics/interval_exchanges/template.py @@ -478,7 +478,7 @@ def _init_flips(self,intervals,flips): if letter in flips: self._flips[interval][i] = -1 - def __eq__(self,other): + def __eq__(self, other) -> bool: r""" Tests equality @@ -925,7 +925,7 @@ def letters(self): else: return [unrank(i) for i in range(len(self))] - def _repr_(self): + def _repr_(self) -> str: r""" Representation method of self. @@ -2427,7 +2427,7 @@ def _move(self, interval, position, interval_to, position_to): position_to, self._twin[interval].pop(position)) - def has_rauzy_move(self, winner, side='right'): + def has_rauzy_move(self, winner, side='right') -> bool: r""" Test if a Rauzy move can be performed on this permutation. @@ -2464,7 +2464,7 @@ def has_rauzy_move(self, winner, side='right'): return self._twin[winner][side] % len(self) != side % len(self) - def is_irreducible(self, return_decomposition=False) : + def is_irreducible(self, return_decomposition=False) -> bool: r""" Test irreducibility. @@ -2814,7 +2814,7 @@ def twin_list(self): """ return [self._twin[0][:],self._twin[1][:]] - def is_irreducible(self, return_decomposition=False): + def is_irreducible(self, return_decomposition=False) -> bool: r""" Test of reducibility @@ -3033,7 +3033,7 @@ def to_cylindric(self): raise RuntimeError("no cylindric permutation in the extended Rauzy class") - def is_cylindric(self): + def is_cylindric(self) -> bool: r""" Test if the permutation is cylindric @@ -3270,7 +3270,7 @@ def erase_marked_points(self): else: return self - def is_hyperelliptic(self, verbose=False): + def is_hyperelliptic(self, verbose=False) -> bool: r""" Test if this permutation is in an hyperelliptic connected component. @@ -3521,7 +3521,7 @@ def stratum_component(self): return stratum.irregular_component() return stratum.regular_component() - def has_rauzy_move(self, winner, side='right'): + def has_rauzy_move(self, winner, side='right') -> bool: r""" Test of Rauzy movability (with an eventual specified choice of winner) @@ -3662,7 +3662,7 @@ class OrientablePermutationIET(PermutationIET): - Vincent Delecroix (2008-12-20): initial version """ - def is_identity(self): + def is_identity(self) -> bool: r""" Returns ``True`` if ``self`` is the identity. @@ -4575,7 +4575,7 @@ def erase_marked_points(self): return self.__class__((top,bot)) - def is_hyperelliptic(self): + def is_hyperelliptic(self) -> bool: r""" Returns True if the permutation is in the class of the symmetric permutations (with eventual marked points). @@ -4647,7 +4647,7 @@ def to_cylindric(self): return tmp - def is_cylindric(self): + def is_cylindric(self) -> bool: r""" Returns True if the permutation is cylindric @@ -4705,7 +4705,7 @@ def to_standard(self): return tmp - def is_standard(self): + def is_standard(self) -> bool: r""" Test if the permutation is standard @@ -5643,7 +5643,7 @@ def __init__(self, parent, *data): self._end = cur_vertex - def _repr_(self): + def _repr_(self) -> str: r""" Returns a representation of the path. @@ -5713,7 +5713,7 @@ def edge_types(self): """ return copy(self._edge_types) - def __eq__(self, other): + def __eq__(self, other) -> bool: r""" Tests equality @@ -5738,7 +5738,7 @@ def __eq__(self, other): self._start == other._start and self._edge_types == other._edge_types) - def __ne__(self,other): + def __ne__(self, other) -> bool: r""" Tests inequality @@ -6036,7 +6036,7 @@ def __mul__(self, n): res += self return res - def is_loop(self): + def is_loop(self) -> bool: r""" Tests whether the path is a loop (start point = end point). @@ -6332,7 +6332,7 @@ def __init__(self, p, self.complete(p) - def __eq__(self, other): + def __eq__(self, other) -> bool: r""" Tests equality. @@ -6369,7 +6369,7 @@ def __eq__(self, other): self._edge_types == other._edge_types and \ next(iter(self._succ)) in other._succ - def __ne__(self, other): + def __ne__(self, other) -> bool: r""" Tests difference. @@ -6988,7 +6988,7 @@ def __contains__(self, element): """ return any(self._vertex_to_permutation(p) == element for p in self._succ) - def _repr_(self): + def _repr_(self) -> str: r""" Returns a representation of self