Skip to content

Commit 48c188d

Browse files
committed
fixed the IndexError in IntegerVectors_n unrank method and made the IntegerVectors_k unrank method faster
1 parent cad751d commit 48c188d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/sage/combinat/integer_vector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def unrank(self, x):
960960
[1, 9]
961961
"""
962962
rtn = [self.n]
963-
while self.rank(rtn) < x:
963+
while self.rank(rtn) <= x:
964964
rtn.append(0)
965965
rtn.pop()
966966

@@ -1075,7 +1075,7 @@ def rank(self, x):
10751075

10761076
n, k = sum(x), self.k
10771077

1078-
r = sum(binomial(k + i - 1, k - 1) for i in range(n))
1078+
r = binomial(n+k-1, k)
10791079

10801080
for i in range(k - 1):
10811081
k -= 1
@@ -1090,7 +1090,7 @@ def unrank(self, x):
10901090
10911091
INPUT:
10921092
1093-
- ``x`` -- an integer such that x < self.cardinality() ``
1093+
- ``x`` -- an integer such that x < self.cardinality()``
10941094
10951095
EXAMPLES::
10961096

0 commit comments

Comments
 (0)