-
-
Notifications
You must be signed in to change notification settings - Fork 599
Fix Derangements(0) to return 1 and yield the empty permutation #39766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@darijgr Do you have any thoughts on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job. D_0 should be 1; there is no controversy here.
Thanks you. I also thought so too, but I haven't really worked on derangements to know for certain. Once tests pass, I will set a positive review. |
Documentation preview for this PR (built with commit 9f22ac9; changes) is ready! 🎉 |
Thank you for your kind review. I noticed that one of the long tests timed out:
I'm not sure how to address this timeout failure. Could you please share any suggestions? Thanks! |
The failure is probably unrelated to this pull request. (We have been having sporadic issue with these) |
sagemathgh-39766: Fix Derangements(0) to return 1 and yield the empty permutation Fixes sagemath#39734 ### What this does This PR fixes the behavior of `Derangements(0)` in two ways: - `Derangements(0).cardinality()` now correctly returns `1` instead of `0`, aligning with standard combinatorics conventions and OEIS [A000166](https://oeis.org/A000166). - `Derangements(0).list()` now returns `[[]]`, representing the single (empty) derangement of the empty set, instead of an empty list. These changes ensure consistency with mathematical definitions and fix an inconsistency between `Derangements(0)` and `Permutations(0)`. ### Why this matters Returning `1` for `Derangements(0).cardinality()` is consistent with the recursive definition of derangements and is mathematically correct. Without this fix, Sage currently contradicts standard references and user expectations. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. URL: sagemath#39766 Reported by: TinaJin0228 Reviewer(s): Darij Grinberg
Fixes #39734
What this does
This PR fixes the behavior of
Derangements(0)
in two ways:Derangements(0).cardinality()
now correctly returns1
instead of0
, aligning with standard combinatorics conventions and OEIS A000166.Derangements(0).list()
now returns[[]]
, representing the single (empty) derangement of the empty set, instead of an empty list.These changes ensure consistency with mathematical definitions and fix an inconsistency between
Derangements(0)
andPermutations(0)
.Why this matters
Returning
1
forDerangements(0).cardinality()
is consistent with the recursive definition of derangements and is mathematically correct. Without this fix, Sage currently contradicts standard references and user expectations.📝 Checklist
⌛ Dependencies
None.