Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
False
::
sage: p = iet.Permutation('a b c d','c a b d',reduced=True)
sage: p.has_rauzy_move(0,'right')
False
sage: p.has_rauzy_move(0,'left')
True
sage: p.has_rauzy_move(1,'right')
False
sage: p.has_rauzy_move(1,'left')
True
"""
side = side_conversion(side)
winner = interval_conversion(winner)
return self._twin[winner][side] % len(self) != side % len(self)
::
sage: p = iet.GeneralizedPermutation('a b b c','d c a e d e')
sage: p.rauzy_move_winner('top','right')
'c'
sage: p.rauzy_move_winner('bottom','right')
'e'
sage: p.rauzy_move_winner('top','left')
'a'
sage: p.rauzy_move_winner('bottom','left')
'd'
"""
if winner is None and side is None:
return None
winner = interval_conversion(winner)
side = side_conversion(side)
return self[winner][side]
integer or 2-uple of integers -- the corresponding lengths
EXAMPLES::
sage: p = iet.Permutation('a b c','c b a')
sage: p.length()
(3, 3)
sage: p = iet.GeneralizedPermutation('a a b','c d c b d')
sage: p.length()
(3, 5)
"""
if interval is None :
return len(self._twin[0]),len(self._twin[1])
else :
interval = interval_conversion(interval)
return len(self._twin[interval])
sage: p = iet.Permutation('a b','b a')
sage: print p.rauzy_move_orbit_substitution('top','right')
WordMorphism: a->ab, b->b
sage: print p.rauzy_move_orbit_substitution('bottom','right')
WordMorphism: a->a, b->ab
sage: print p.rauzy_move_orbit_substitution('top','left')
WordMorphism: a->a, b->ba
sage: print p.rauzy_move_orbit_substitution('bottom','left')
WordMorphism: a->ba, b->b
"""
d = dict([(letter,letter) for letter in self.letters()])
if winner is None and side is None:
return WordMorphism(d)
winner = interval_conversion(winner)
side = side_conversion(side)
loser_letter = self.rauzy_move_loser(winner,side)
top_letter = self.alphabet().unrank(self._intervals[0][side])
bottom_letter = self.alphabet().unrank(self._intervals[1][side])
d[loser_letter] = [bottom_letter,top_letter]
return WordMorphism(d)
sage: p = iet.GeneralizedPermutation('a a','b b c c')
sage: p.has_right_rauzy_move('top')
True
sage: p.has_right_rauzy_move('bottom')
False
::
sage: p = iet.GeneralizedPermutation('a a b b','c c')
sage: p.has_right_rauzy_move('top')
False
sage: p.has_right_rauzy_move('bottom')
True
"""
winner = interval_conversion(winner)
loser = self._intervals[1-winner][-1]
# the same letter at the right-end (False)
if self._intervals[0][-1] == self._intervals[1][-1] :
return False
# the winner (or loser) letter is repeated on the other interval (True)
if self._intervals[0][-1] in self._intervals[1]: return True
if self._intervals[1][-1] in self._intervals[0]: return True
# the loser letters is the only letter repeated in the loser
# interval (False)
for i,c in enumerate((self._intervals[1-winner])):
if c != loser and c in self._intervals[1-winner][i+1:]:
return True
sage: p = iet.Permutation('a b c','c b a',reduced=True)
sage: p.left_rauzy_move(0)
a b c
b c a
sage: p.right_rauzy_move(1)
a b c
b c a
::
sage: p = iet.GeneralizedPermutation('a a','b b c c',reduced=True)
sage: p.left_rauzy_move(0)
a a b
b c c
"""
winner = interval_conversion(winner)
result = copy(self)
result._reversed()
result = result.right_rauzy_move(winner)
result._reversed()
return result
'c'
sage: t.in_which_interval(3)
Traceback (most recent call last):
...
ValueError: your value does not lie in [0;l[
.. and for the bottom interval::
sage: t.in_which_interval(0,'bottom')
'c'
sage: t.in_which_interval(1.2,'bottom')
'b'
sage: t.in_which_interval(2.9,'bottom')
'a'
"""
interval = interval_conversion(interval)
if x < 0 or x >= self.length():
raise ValueError, "your value does not lie in [0;l["
i = 0
while x >= 0:
x -= self._lengths[self._permutation._intervals[interval][i]]
i += 1
i -= 1
x += self._lengths[self._permutation._intervals[interval][i]]
j = self._permutation._intervals[interval][i]
return self._permutation._alphabet.unrank(j)
sage: p = iet.Permutation('a b c d','b d a c')
sage: q = p.left_right_inverse()
sage: m0 = p.rauzy_move_matrix(winner='top',side='right')
sage: n0 = q.rauzy_move_matrix(winner='top',side='left')
sage: m0 == n0
True
sage: m1 = p.rauzy_move_matrix(winner='bottom',side='right')
sage: n1 = q.rauzy_move_matrix(winner='bottom',side='left')
sage: m1 == n1
True
"""
if winner is None and side is None:
return identity_matrix(len(self))
winner = interval_conversion(winner)
side = side_conversion(side)
winner_letter = self._intervals[winner][side]
loser_letter = self._intervals[1-winner][side]
m = copy(identity_matrix(len(self)))
m[winner_letter, loser_letter] = 1
return m
def right_rauzy_move(self, winner):
r"""
Performs a Rauzy move on the right.
EXAMPLE::
sage: p = iet.Permutation('a b c','c b a',reduced=True,flips='c')
sage: p.right_rauzy_move('top')
-a b -c
-a -c b
"""
winner = interval_conversion(winner)
result = copy(self)
loser_to = result._get_loser_to(winner)
result._flip_rauzy_move(winner, loser_to)
result._twin_rauzy_move(winner, loser_to)
return result
sage: p = iet.Permutation('a b','b a')
sage: print p.rauzy_move_interval_substitution('top','right')
WordMorphism: a->a, b->ba
sage: print p.rauzy_move_interval_substitution('bottom','right')
WordMorphism: a->ab, b->b
sage: print p.rauzy_move_interval_substitution('top','left')
WordMorphism: a->ba, b->b
sage: print p.rauzy_move_interval_substitution('bottom','left')
WordMorphism: a->a, b->ab
"""
d = dict([(letter,letter) for letter in self.letters()])
if winner is None and side is None:
return WordMorphism(d)
winner = interval_conversion(winner)
side = side_conversion(side)
winner_letter = self.rauzy_move_winner(winner,side)
loser_letter = self.rauzy_move_loser(winner,side)
if side == 0:
d[winner_letter] = [loser_letter,winner_letter]
else:
d[winner_letter] = [winner_letter,loser_letter]
return WordMorphism(d)