-
Notifications
You must be signed in to change notification settings - Fork 161
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
Speed up AsList
, AsSet
and ElementsStabChain
for permutation groups, by not sorting the list returned by ElementsStabChain
(in accordance with its documentation which never promised this)
#5216
Conversation
ElementsStabChain
and AsList
for permutation groupsAsList
, AsSet
and ElementsStabChain
for permutation groups
b8089f0
to
4c04460
Compare
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.
Changing the behaviour of a function w.r.t. sortedness of its result usually has the effect that some examples will have different outputs, thus tests have to be adjusted.
(I expect this effect in some package manuals or in files that document GAP computations.)
Nevertheless, the proposed change is a nice performance improvement.
Perhaps the fact that ElementsStabChain
does no longer return a sorted result should be mentioned in the release notes.
I approve this, but I agree this should be in the release notes |
Another option would be to rename the modified Since no package calls |
(The function looks like a utility that had been introduced only in order to use it in methods for |
The documentation for `ElementsStabChain` never claimed that the result it returns is sorted. So we change it to not do that, by using `Append` instead of `UniteSet`. Then we use that to provide a faster version of `AsList`. As a side effect, this actually even speeds up `AsSet`, as sorting only at the end is cheaper then sorting repeatedly during creation of the list. Some timings: Before: gap> AsList(SymmetricGroup(10));; time; 1507 gap> AsSet(SymmetricGroup(10));; time; 1492 After: gap> AsList(SymmetricGroup(10)); time; 611 gap> AsSet(SymmetricGroup(10)); time; 1120 As another side effect, the output of `AsList(G)` and `List(Iterator(G))` now seem to coincide if `G` is a permutation group.
4c04460
to
f01b270
Compare
AsList
, AsSet
and ElementsStabChain
for permutation groupsAsList
, AsSet
and ElementsStabChain
for permutation groups, by not sorting the list returned by ElementsStabChain
(in accordance with its documentation which never promised this)
@ThomasBreuer I've adjusted the docstring to mention that the result may be unsorted, and adjusted the title of this PR (which will be used for the release notes). Better now? |
@fingolfin Yes, thanks. |
The documentation for
ElementsStabChain
never claimed that the result it returns is sorted. So we change it to not do that, by usingAppend
instead ofUniteSet
. Then we use that to provide a faster version ofAsList
. As a side effect, this actually even speeds upAsSet
, as sorting only at the end is cheaper then sorting repeatedly during creation of the list.Some timings:
Before:
After:
As another side effect, the output of
AsList(G)
andList(Iterator(G))
now seem to coincide ifG
is a permutation group.Of course in practice it's usually a bad idea to enumerate all group elements to start with... but for some applications this is still needed.