-
Notifications
You must be signed in to change notification settings - Fork 160
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
Clear stored inverse when calling TrimPerm #3575
Conversation
Another option (obviously more work) would be, whenever you trim a perm |
My plan for this PR, given it might be backported, was to do the smallest (hopefully) clearly correct thing. Although I've just realised I failed at that goal, because as well as stopping |
Whoops! Okay, sure, I'll must make a note on #3576. |
f174bdc
to
db5a0cd
Compare
Now with bonus fix! |
Codecov Report
@@ Coverage Diff @@
## master #3575 +/- ##
==========================================
- Coverage 84.54% 84.51% -0.03%
==========================================
Files 696 695 -1
Lines 345127 345202 +75
==========================================
- Hits 291779 291763 -16
- Misses 53348 53439 +91
|
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.
As far as I can tell, this would also be safe if you put the CLEAR_STOREDINV_PERM(perm);
only inside the else if (m <= 65536) {
block of code, because that's the only bit that actually changes the type of perm
.
But I don't insist, and the performance gain would surely be only marginal - storing the inverse is useful when you use the inverse of a permutation many times; but I imagine a permutation doesn't get trimmed very often, meaning the recalculation of a cleared stored inverse probably doesn't happen very often.
And unfortunately Travis is failing because https://www.gap-system.org is down 🙁 |
(I can't restart the AppVeyor build; maybe you can @ChrisJefferson, otherwise I guess push again to make the tests pass.) |
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 catch! I restarted the AppVeyor builds, hopefully that'll fix them.
I think one could change to be parameterless and just compute the "largest moved point" and use that. It'll be a minor cost. Or perhaps it could take the maximum of this and the argument... That said, I'd greatly prefer if we didn't change permutations in place at all, and got rid of |
I took the liberty of updating this PR with the suggestions by Wilf and me. |
I mentioned in the original message why we have to always remove the inverse -- because if we trim |
That usage of TRIM_PERM is simply invalid. While it works by chance to call I've added a commit which does just that, including test cases. |
The whole reason (I guess) that TRIM_PERM took an argument, instead of just calculating the LargestMovedPoint, is that it was designed to be a very cheap. Actually calculating the LargestMovedPoint makes the function much more expensive. Also, while I agree TRIM_PERM(p,n) is invalid unless the permutation stabilises [1..n], I wasn't sure if someone might be using it for that purpose (where it would work fine, as long as there were no other references to the permutation). |
We can easily enumerate all uses of This suggests to me that that our best option is to modify Another variant would be to simply trim permutations as a side effect of |
OK, small correction: the call |
This is required if TrimPerm changes the TNUM of the permutation, as a permutation and its stored inverse must have the same TNUM. This is also required if TrimPerm changes the permutation (although this would break many other things if anyone did it)
Anyhow, this requires some extra work, so I've now restored the |
By the way, once a permutation has been trimmed, |
Fixes #3574 , although this is actually an old bug which was only recently discovered by an interaction between semigroups and a recent change.
This is a minimal fix, so it can be backported (if another release of 4.10 is made). I would like to investigate removing/changing TrimPerm/TRIM_PERM, because it's very easy to abuse and break things, but that's for another PR.
The problem we definitely have: If TrimPerm turns a Perm4 into a Perm2, we need to remove the stored inverse, as a permutation and it's store inverse must have the same TNUM. I think the only place this actually causes a problem is calculating x/p for an integer x and permutation p, after p has been trimmed, but there could be other places.
The reason this PR always throw away the stored inverse: If TrimPerm was used to produce a logically different permutation (say trimming (1,2)(3,4) to just (1,2)), then we also have to remove the inverse. It's unclear to me if that is supposed allowed by TrimPerm. It seems like a terrible idea as permutations are immutable, so I think should be banned.