Skip to content
Merged
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
7 changes: 3 additions & 4 deletions surface_dynamics/interval_exchanges/conversion.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions surface_dynamics/interval_exchanges/flip_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down
29 changes: 11 additions & 18 deletions surface_dynamics/interval_exchanges/iet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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")

Expand All @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions surface_dynamics/interval_exchanges/iet_family.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down Expand Up @@ -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.

Expand Down
8 changes: 4 additions & 4 deletions surface_dynamics/interval_exchanges/labelled.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.

Expand Down
14 changes: 7 additions & 7 deletions surface_dynamics/interval_exchanges/marked_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __hash__(self):
"""
return hash(self.t) + hash(self.data)

def _repr_(self):
def _repr_(self) -> str:
r"""
String representation.

Expand All @@ -104,7 +104,7 @@ def _repr_(self):
else:
return "%do%d" % self.data

def __eq__(self, other):
def __eq__(self, other) -> bool:
r"""
TESTS::

Expand All @@ -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::

Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
11 changes: 5 additions & 6 deletions surface_dynamics/interval_exchanges/rauzy_class_cardinality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 3 additions & 7 deletions surface_dynamics/interval_exchanges/reduced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading