243243import operator
244244from typing import TYPE_CHECKING
245245
246- from sage .arith .misc import factorial , multinomial
246+ from sage .arith .misc import factorial , multinomial , falling_factorial
247247from sage .categories .finite_enumerated_sets import FiniteEnumeratedSets
248248from sage .categories .finite_permutation_groups import FinitePermutationGroups
249249from 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 )
@@ -6320,6 +6320,8 @@ def __iter__(self) -> Iterator[Permutation]:
63206320
63216321 def cardinality (self ) -> Integer :
63226322 """
6323+ Return the cardinality of the set.
6324+
63236325 EXAMPLES::
63246326
63256327 sage: Permutations(3,0).cardinality()
@@ -6334,7 +6336,7 @@ def cardinality(self) -> Integer:
63346336 0
63356337 """
63366338 if 0 <= self ._k <= self .n :
6337- return factorial (self .n ) // factorial ( self . n - self ._k )
6339+ return falling_factorial (self .n , self ._k )
63386340 return ZZ .zero ()
63396341
63406342 def random_element (self ):
@@ -6409,7 +6411,7 @@ def __init__(self, mset):
64096411 """
64106412 TESTS::
64116413
6412- sage: S = Permutations(['c','a','c'])
6414+ sage: S = Permutations(['c','a','c','d' ])
64136415 sage: TestSuite(S).run()
64146416 """
64156417 self .mset = mset
@@ -6898,7 +6900,7 @@ def __init__(self, mset, k):
68986900 """
68996901 TESTS::
69006902
6901- sage: P = Permutations([1,2,2], 2)
6903+ sage: P = Permutations([1,2,2,3], 2)
69026904 sage: TestSuite(P).run() # needs sage.libs.gap
69036905 """
69046906 Permutations_mset .__init__ (self , mset )
@@ -7014,12 +7016,26 @@ def __init__(self, s, k):
70147016 """
70157017 TESTS::
70167018
7017- sage: P = Permutations([1,2,4], 2)
7019+ sage: P = Permutations([1,2,4,5], 2)
70187020 sage: TestSuite(P).run()
70197021 """
70207022 Permutations_set .__init__ (self , s )
70217023 self ._k = k
70227024
7025+ def cardinality (self ) -> Integer :
7026+ """
7027+ Return the cardinality of the set.
7028+
7029+ EXAMPLES::
7030+
7031+ sage: Permutations([1,2,4,5], 2).cardinality()
7032+ 12
7033+ """
7034+ n = len (self ._set )
7035+ if 0 <= self ._k <= n :
7036+ return falling_factorial (n , self ._k )
7037+ return ZZ .zero ()
7038+
70237039 def __contains__ (self , x ):
70247040 """
70257041 EXAMPLES::
@@ -9841,6 +9857,8 @@ def __init__(self, n):
98419857
98429858 def cardinality (self ):
98439859 """
9860+ Return the cardinality of the set.
9861+
98449862 EXAMPLES::
98459863
98469864 sage: Permutations(5, avoiding=[1, 3, 2]).cardinality()
@@ -9918,6 +9936,8 @@ def __init__(self, n):
99189936
99199937 def cardinality (self ) -> Integer :
99209938 """
9939+ Return the cardinality of the set.
9940+
99219941 EXAMPLES::
99229942
99239943 sage: Permutations(5, avoiding=[1, 2, 3]).cardinality()
@@ -9990,6 +10010,8 @@ def __init__(self, n):
999010010
999110011 def cardinality (self ):
999210012 """
10013+ Return the cardinality of the set.
10014+
999310015 EXAMPLES::
999410016
999510017 sage: Permutations(5, avoiding=[3, 2, 1]).cardinality()
@@ -10022,6 +10044,8 @@ def __init__(self, n):
1002210044
1002310045 def cardinality (self ):
1002410046 """
10047+ Return the cardinality of the set.
10048+
1002510049 EXAMPLES::
1002610050
1002710051 sage: Permutations(5, avoiding=[2, 3, 1]).cardinality()
@@ -10054,6 +10078,8 @@ def __init__(self, n):
1005410078
1005510079 def cardinality (self ):
1005610080 """
10081+ Return the cardinality of the set.
10082+
1005710083 EXAMPLES::
1005810084
1005910085 sage: Permutations(5, avoiding=[3, 1, 2]).cardinality()
@@ -10086,6 +10112,8 @@ def __init__(self, n):
1008610112
1008710113 def cardinality (self ):
1008810114 """
10115+ Return the cardinality of the set.
10116+
1008910117 EXAMPLES::
1009010118
1009110119 sage: Permutations(5, avoiding=[2, 1, 3]).cardinality()
0 commit comments