-
-
Notifications
You must be signed in to change notification settings - Fork 674
Description
Steps To Reproduce
sage: S = Permutations(range(5), 2)
sage: S.cardinality()
120
sage: len(S.list())
20
sage: S.cardinality()
20
Similar to #20317.
Expected Behavior
The correct cardinality of permutations with a given length is returned, and in an efficient manner.
Actual Behavior
It seems that the class Permutations_setk
in permutation.py does not override the cardinality()
method from its parent class. After calling .list()
, the generic _cardinality_from_list method from the category framework is used.
Replacing range(5)
with [0,1,2,3,4]
or even [99,1,2,3,4]
gives the same result. But replacing it with 5
or [1,2,3,4,5]
gives the correct behavior, since the class of S
is now Permutations_nk, whose cardinality()
method computes a quotient of factorials (maybe falling_factorial(n,k)
is better there).
Additional Information
Somewhat related, there are some naive cardinality()
methods in https://github.com/sagemath/sage/blob/develop/src/sage/combinat/permutation.py for other classes.
Environment
- OS: Linux
- Sage Version: 10.7
Checklist
- I have searched the existing issues for a bug report that matches the one I want to file, without success.
- I have read the documentation and troubleshoot guide