Skip to content

Commit 1f8c715

Browse files
committed
fix cardinality of Permutations_setk
1 parent 4e2319b commit 1f8c715

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/sage/combinat/permutation.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
import operator
244244
from typing import TYPE_CHECKING
245245

246-
from sage.arith.misc import factorial, multinomial
246+
from sage.arith.misc import factorial, multinomial, falling_factorial
247247
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
248248
from sage.categories.finite_permutation_groups import FinitePermutationGroups
249249
from sage.categories.finite_weyl_groups import FiniteWeylGroups
@@ -2144,7 +2144,7 @@ def ishift(self, i):
21442144
Return the ``i``-shift of ``self``. If an ``i``-shift of ``self``
21452145
can't be performed, then ``self`` is returned.
21462146
2147-
An `i`-shift can be applied when `i` is not inbetween `i-1` and
2147+
An `i`-shift can be applied when `i` is not between `i-1` and
21482148
`i+1`. The `i`-shift moves `i` to the other side, and leaves the
21492149
relative positions of `i-1` and `i+1` in place. All other entries
21502150
of the permutations are also left in place.
@@ -6243,7 +6243,7 @@ def __init__(self, n, k):
62436243
"""
62446244
TESTS::
62456245
6246-
sage: P = Permutations(3,2)
6246+
sage: P = Permutations(5, 3)
62476247
sage: TestSuite(P).run()
62486248
"""
62496249
self.n = ZZ(n)
@@ -6334,7 +6334,7 @@ def cardinality(self) -> Integer:
63346334
0
63356335
"""
63366336
if 0 <= self._k <= self.n:
6337-
return factorial(self.n) // factorial(self.n - self._k)
6337+
return falling_factorial(self.n, self._k)
63386338
return ZZ.zero()
63396339

63406340
def random_element(self):
@@ -6409,7 +6409,7 @@ def __init__(self, mset):
64096409
"""
64106410
TESTS::
64116411
6412-
sage: S = Permutations(['c','a','c'])
6412+
sage: S = Permutations(['c','a','c','d'])
64136413
sage: TestSuite(S).run()
64146414
"""
64156415
self.mset = mset
@@ -6898,7 +6898,7 @@ def __init__(self, mset, k):
68986898
"""
68996899
TESTS::
69006900
6901-
sage: P = Permutations([1,2,2],2)
6901+
sage: P = Permutations([1,2,2,3], 2)
69026902
sage: TestSuite(P).run() # needs sage.libs.gap
69036903
"""
69046904
Permutations_mset.__init__(self, mset)
@@ -7014,12 +7014,24 @@ def __init__(self, s, k):
70147014
"""
70157015
TESTS::
70167016
7017-
sage: P = Permutations([1,2,4],2)
7017+
sage: P = Permutations([1,2,4,5], 2)
70187018
sage: TestSuite(P).run()
70197019
"""
70207020
Permutations_set.__init__(self, s)
70217021
self._k = k
70227022

7023+
def cardinality(self) -> Integer:
7024+
"""
7025+
EXAMPLES::
7026+
7027+
sage: Permutations([1,2,4,5], 2).cardinality()
7028+
12
7029+
"""
7030+
n = len(self._set)
7031+
if 0 <= self._k <= n:
7032+
return falling_factorial(n, self._k)
7033+
return ZZ.zero()
7034+
70237035
def __contains__(self, x):
70247036
"""
70257037
EXAMPLES::

0 commit comments

Comments
 (0)