Skip to content

Commit fb82b76

Browse files
committed
Fix the to_cycles() of signed permutations.
1 parent 6ea1fe9 commit fb82b76

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/sage/combinat/colored_permutations.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,8 @@ def has_left_descent(self, i):
11891189
return self._colors[i] == 1 or self._perm[i - 1] < self._perm[i]
11901190
return self._colors[i] == 1 and self._perm[i - 1] > self._perm[i]
11911191

1192-
def to_cycles(self, singletons=True, use_min=True, negative_singletons=True):
1193-
"""
1192+
def to_cycles(self, singletons=True, use_min=True, negative_cycles=True):
1193+
r"""
11941194
Return the signed permutation ``self`` as a list of disjoint cycles.
11951195
11961196
The cycles are returned in the order of increasing smallest
@@ -1205,18 +1205,25 @@ def to_cycles(self, singletons=True, use_min=True, negative_singletons=True):
12051205
- ``use_min`` -- (default: ``True``) if ``False``, the cycles are
12061206
returned in the order of increasing *largest* (not smallest)
12071207
elements, and each cycle starts with its largest element
1208+
- ``negative_cycles`` -- (default: ``True``) if ``False``, for any
1209+
two cycles `C^{\pm} = \{\pm c_1, \ldots, \pm c_k\}` such that
1210+
`C^+ \neq C^-`, this does not include the cycle `C^-`
12081211
12091212
EXAMPLES::
12101213
12111214
sage: pi = SignedPermutations(7)([2,-1,4,-6,-5,-3,7])
12121215
sage: pi.to_cycles()
1213-
[(1, 2, -1, -2), (3, 4, -6), (5, -5), (7,)]
1216+
[(1, 2, -1, -2), (3, 4, -6), (-3, -4, 6), (5, -5), (7,), (-7,)]
12141217
sage: pi.to_cycles(singletons=False)
1218+
[(1, 2, -1, -2), (3, 4, -6), (-3, -4, 6), (5, -5)]
1219+
sage: pi.to_cycles(negative_cycles=False)
1220+
[(1, 2, -1, -2), (3, 4, -6), (5, -5), (7,)]
1221+
sage: pi.to_cycles(singletons=False, negative_cycles=False)
12151222
[(1, 2, -1, -2), (3, 4, -6), (5, -5)]
12161223
sage: pi.to_cycles(use_min=False)
1217-
[(7,), (6, -3, -4), (5, -5), (2, -1, -2, 1)]
1224+
[(7,), (-7,), (6, -3, -4), (-6, 3, 4), (5, -5), (2, -1, -2, 1)]
12181225
sage: pi.to_cycles(singletons=False, use_min=False)
1219-
[(6, -3, -4), (5, -5), (2, -1, -2, 1)]
1226+
[(6, -3, -4), (-6, 3, 4), (5, -5), (2, -1, -2, 1)]
12201227
"""
12211228
cycles = []
12221229

@@ -1235,16 +1242,20 @@ def to_cycles(self, singletons=True, use_min=True, negative_singletons=True):
12351242
cycle = [cycle_first]
12361243
l[i], next_val = False, l[i]
12371244
s = self._colors[i]
1245+
add_neg = True
12381246
while next_val != cycle_first:
12391247
cycle.append(s * next_val)
12401248
s *= self._colors[next_val - 1]
12411249
l[next_val - 1], next_val = False, l[next_val - 1]
12421250
if s != 1:
12431251
cycle.extend([-e for e in cycle])
1252+
add_neg = False
12441253

12451254
# Add the cycle to the list of cycles
12461255
if singletons or len(cycle) > 1:
12471256
cycles.append(tuple(cycle))
1257+
if negative_cycles and add_neg:
1258+
cycles.append(tuple([-e for e in cycle]))
12481259

12491260
return cycles
12501261

@@ -1256,7 +1267,7 @@ def order(self):
12561267
12571268
sage: pi = SignedPermutations(7)([2,-1,4,-6,-5,-3,7])
12581269
sage: pi.to_cycles(singletons=False)
1259-
[(1, 2, -1, -2), (3, 4, -6), (5, -5)]
1270+
[(1, 2, -1, -2), (3, 4, -6), (-3, -4, 6), (5, -5)]
12601271
sage: pi.order()
12611272
12
12621273
"""

0 commit comments

Comments
 (0)