|
243 | 243 | import operator |
244 | 244 | from typing import TYPE_CHECKING |
245 | 245 |
|
246 | | -from sage.arith.misc import factorial, multinomial |
| 246 | +from sage.arith.misc import factorial, multinomial, falling_factorial |
247 | 247 | from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets |
248 | 248 | from sage.categories.finite_permutation_groups import FinitePermutationGroups |
249 | 249 | from sage.categories.finite_weyl_groups import FiniteWeylGroups |
@@ -2144,7 +2144,7 @@ def ishift(self, i): |
2144 | 2144 | Return the ``i``-shift of ``self``. If an ``i``-shift of ``self`` |
2145 | 2145 | can't be performed, then ``self`` is returned. |
2146 | 2146 |
|
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 |
2148 | 2148 | `i+1`. The `i`-shift moves `i` to the other side, and leaves the |
2149 | 2149 | relative positions of `i-1` and `i+1` in place. All other entries |
2150 | 2150 | of the permutations are also left in place. |
@@ -6243,7 +6243,7 @@ def __init__(self, n, k): |
6243 | 6243 | """ |
6244 | 6244 | TESTS:: |
6245 | 6245 |
|
6246 | | - sage: P = Permutations(3,2) |
| 6246 | + sage: P = Permutations(5, 3) |
6247 | 6247 | sage: TestSuite(P).run() |
6248 | 6248 | """ |
6249 | 6249 | self.n = ZZ(n) |
@@ -6334,7 +6334,7 @@ def cardinality(self) -> Integer: |
6334 | 6334 | 0 |
6335 | 6335 | """ |
6336 | 6336 | if 0 <= self._k <= self.n: |
6337 | | - return factorial(self.n) // factorial(self.n - self._k) |
| 6337 | + return falling_factorial(self.n, self._k) |
6338 | 6338 | return ZZ.zero() |
6339 | 6339 |
|
6340 | 6340 | def random_element(self): |
@@ -6409,7 +6409,7 @@ def __init__(self, mset): |
6409 | 6409 | """ |
6410 | 6410 | TESTS:: |
6411 | 6411 |
|
6412 | | - sage: S = Permutations(['c','a','c']) |
| 6412 | + sage: S = Permutations(['c','a','c','d']) |
6413 | 6413 | sage: TestSuite(S).run() |
6414 | 6414 | """ |
6415 | 6415 | self.mset = mset |
@@ -6898,7 +6898,7 @@ def __init__(self, mset, k): |
6898 | 6898 | """ |
6899 | 6899 | TESTS:: |
6900 | 6900 |
|
6901 | | - sage: P = Permutations([1,2,2],2) |
| 6901 | + sage: P = Permutations([1,2,2,3], 2) |
6902 | 6902 | sage: TestSuite(P).run() # needs sage.libs.gap |
6903 | 6903 | """ |
6904 | 6904 | Permutations_mset.__init__(self, mset) |
@@ -7014,12 +7014,24 @@ def __init__(self, s, k): |
7014 | 7014 | """ |
7015 | 7015 | TESTS:: |
7016 | 7016 |
|
7017 | | - sage: P = Permutations([1,2,4],2) |
| 7017 | + sage: P = Permutations([1,2,4,5], 2) |
7018 | 7018 | sage: TestSuite(P).run() |
7019 | 7019 | """ |
7020 | 7020 | Permutations_set.__init__(self, s) |
7021 | 7021 | self._k = k |
7022 | 7022 |
|
| 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 | + |
7023 | 7035 | def __contains__(self, x): |
7024 | 7036 | """ |
7025 | 7037 | EXAMPLES:: |
|
0 commit comments