Skip to content

Commit bc6d3bd

Browse files
author
Release Manager
committed
gh-35700: Fix corner case of ordered set partitions iteration ### 📚 Description The function `multiset_permutation_next_lex` was wrong on empty input and is fixed in this PR. Fixes #35654 ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. URL: #35700 Reported by: Vincent Delecroix Reviewer(s): Frédéric Chapoton
2 parents 752fe75 + 909f767 commit bc6d3bd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/sage/combinat/set_partition_ordered.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,13 @@ def __iter__(self):
11141114
[{1, 3}, {2}],
11151115
[{2, 3}, {1}],
11161116
[{1, 2, 3}]]
1117+
1118+
TESTS:
1119+
1120+
Test for :issue:`35654`::
1121+
1122+
sage: OrderedSetPartitions(set(),[0,0,0]).list()
1123+
[[{}, {}, {}]]
11171124
"""
11181125
for x in Compositions(len(self._set)):
11191126
for z in OrderedSetPartitions(self._set, x):
@@ -1379,11 +1386,18 @@ def multiset_permutation_next_lex(l):
13791386
[2, 1, 0, 0, 1]
13801387
[2, 1, 0, 1, 0]
13811388
[2, 1, 1, 0, 0]
1389+
1390+
TESTS:
1391+
1392+
Test for :issue:`35654`::
1393+
1394+
sage: multiset_permutation_next_lex([])
1395+
0
13821396
"""
13831397
i = len(l) - 2
13841398
while i >= 0 and l[i] >= l[i + 1]:
13851399
i -= 1
1386-
if i == -1:
1400+
if i <= -1:
13871401
return 0
13881402
j = len(l) - 1
13891403
while l[j] <= l[i]:

0 commit comments

Comments
 (0)