Skip to content
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

Fixed bugs in RestrictedPerm with second argument a range. #4178

Merged
merged 1 commit into from
Nov 18, 2020

Conversation

ChrisJefferson
Copy link
Contributor

The code in RestrictedPerm for handling ranges had a few bugs (I found issue (2) in some code I was working on, when I went to investigate I noticed issue (1))

  1. If the list contained negative numbers, () was always returned
  2. Ranges with steps which were not step = 1 were mishandled -- but (I believe) this would never return a wrong answer, just an Error about invalid input, when the input was value.

Rather than try to fix the old code, which was both buggy and confusing, I just wrote a (hopefully) much simpler loop, which I believe will be just as efficient (as the only one wasn't trying to do "clever skipping" anyway.

@ChrisJefferson ChrisJefferson added kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes backport-to-4.11 labels Nov 16, 2020
Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

src/permutat.cc Outdated Show resolved Hide resolved
@ChrisJefferson
Copy link
Contributor Author

ChrisJefferson commented Nov 16, 2020

Just to say, we could also change RestrictedPerm to just reject inputs which contain non-positive integers -- while it looked to me like the intention was to support it, I'm now investigating and it looks like it might be more sensible to reject it.

src/permutat.cc Outdated Show resolved Hide resolved
1) If the list contained negative numbers, () was always returned
2) Ranges with steps which were not = 1 were mishandled
@ChrisJefferson
Copy link
Contributor Author

Code now reformatted and simplified somewhere, I now (correctly) just reject negative inputs. Added (possibly too many) tests, to make sure all the various boundary conditions are hit properly.

Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great.

@fingolfin fingolfin merged commit f910e88 into gap-system:master Nov 18, 2020
@ChrisJefferson ChrisJefferson deleted the restricted-perm branch February 15, 2021 14:42
@ThomasBreuer ThomasBreuer self-assigned this Feb 16, 2021
@ThomasBreuer ThomasBreuer changed the title Fix bugs in RestrictedPerm Fixed bugs in RestrictedPerm with second argument a range. Feb 16, 2021
@ThomasBreuer ThomasBreuer removed their assignment Feb 16, 2021
@ThomasBreuer ThomasBreuer added release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Feb 16, 2021
@fingolfin
Copy link
Member

Backported to stable-4.11 via PR #4262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-4.11-DONE kind: bug: wrong result Issues describing bugs that result in mathematically or otherwise wrong results, and PRs fixing them release notes: added PRs introducing changes that have since been mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants