Skip to content

NC versions of PreImages, PreImagesSet, PreImagesElm and PreImagesRepresentative - version 2 - #6409

Open
cdwensley wants to merge 115 commits into
masterfrom
preimrep2
Open

NC versions of PreImages, PreImagesSet, PreImagesElm and PreImagesRepresentative - version 2#6409
cdwensley wants to merge 115 commits into
masterfrom
preimrep2

Conversation

@cdwensley

@cdwensley cdwensley commented May 20, 2026

Copy link
Copy Markdown
Contributor

This aims to continue work on the process outlined in issue #4809, and started in PR #5073.
(The latter PR was so far out of sync with the master that rebasing has proved to be very difficult, hence this version.)
The operations PreImages, PreImagesSet, PreImagesElm and PreImagesRepresentative have all been renamed throughout the library by adding 'NC' to their names. New versions of the four operations have been introduced which just add a simple test and then call the NC versions.
Authors of packages which include a method for one of the four operations have been asked to adjust their packages to prepare for the change. The packages which have merged a PR, and made a release after that are: cryst, fr, orb, polycyclic, matgrp, qpa, rcwa, semigroups, utils and wedderga, while fga has merged a PR but not made a release.
The fining package has closed PR#28 without merging it - it installs another method for PreImagesSet.

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.70588% with 432 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.03%. Comparing base (4521b5b) to head (0ec5b91).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
lib/mapprep.gi 58.45% 86 Missing ⚠️
lib/mapping.gi 62.74% 38 Missing ⚠️
lib/mapphomo.gi 71.87% 27 Missing ⚠️
lib/gprdperm.gi 48.97% 25 Missing ⚠️
lib/ghomperm.gi 62.50% 21 Missing ⚠️
lib/ghom.gi 58.13% 18 Missing ⚠️
lib/mgmring.gi 63.63% 16 Missing ⚠️
lib/alghom.gi 58.33% 15 Missing ⚠️
lib/relation.gi 78.57% 15 Missing ⚠️
lib/gprdmat.gi 57.57% 14 Missing ⚠️
... and 33 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6409      +/-   ##
==========================================
- Coverage   79.08%   79.03%   -0.05%     
==========================================
  Files         685      685              
  Lines      293698   294480     +782     
  Branches     8664     8641      -23     
==========================================
+ Hits       232262   232741     +479     
- Misses      59635    59936     +301     
- Partials     1801     1803       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stertooy stertooy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very happy to see this PR revived!

One thing I'm a bit wary of, is how PreImagesSet( f, U ) always returns [ ] if U is not a subset of Range( f ), even if they have non-empty intersection. Intuitively, I would expect this function to follow the standard(?) mathematical definition of $f^{-1}(U)$, so something like

PreImagesSetNC( Intersection( Range( f ), U ) )

Comment thread lib/ghomfp.gi Outdated
@cdwensley

Copy link
Copy Markdown
Contributor Author

@stertooy It's so good to get feedback on this work - I will get on with making the changes you suggest.
The way I have done it most of the time, when the new test fails, PreImagesRepresentative returns fail, but PreImagesSet and PreImagesElm (which expect a list) return []. Is that correct, or should this be fail also for PreImagesElm? With PreImagesSet I can see that Intersection( Range(f),U) should be used.

@cdwensley

Copy link
Copy Markdown
Contributor Author

Now I am really confused. The manual states: "If elms is a subset of the range of the general mapping map then PreImagesSet returns the set of all preimages of elms under map." Sticking to that, PreImagesSet should return fail if U is not a subset of the range. Alternatively, we could ditch PreImagesSetNC, and redefine PreImagesSet to return the preimage of the intersection, which could be [].

@cdwensley

cdwensley commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Perhaps this is why I returned [] in PreImagesElm when the test failed:
Two existing methods for PreImagesElm in mapphomo.gi call PreImagesRepresentative,
and if that returns fail then [] is returned.
I'll do nothing now until advice is received.

Comment thread lib/alghom.gi Outdated
@stertooy

Copy link
Copy Markdown
Contributor

The manual states: "If elms is a subset of the range of the general mapping map then PreImagesSet returns the set of all preimages of elms under map." Sticking to that, PreImagesSet should return fail if U is not a subset of the range.

I think the question is what we want the non-NC functions to do for elements/sets not contained in the range. I see two options:

  1. We limit the scope of these functions to elements/sets contained in the range. The only difference between NC and non-NC functions, is that the latter are guaranteed to return fail if the element/set is not contained in the image.

  2. The non-NC functions behave like the usual mathematical definition of a preimage. So in this case PreImagesElm( f, x ) would return the empty set [ ] if x is not contained in the image of f, and PreImagesSet( f, U ) would return the same as PreImagesSetNC( f, Intersection( Image( f ), U ) ).

The former option keeps the NC and non-NC versions closer together, with the only difference being a extra check, which is what an NC version usually indicates in GAP. The latter option sticks closer to the standard mathematical definitions. Either option is fine with me (with a preference for option 2), but it should at least be consistent across all the affected functions.

Alternatively, we could ditch PreImagesSetNC, and redefine PreImagesSet to return the preimage of the intersection, which could be [].

I think we should still keep PreImagesNC in this case, since certain functions/methods may have prior knowledge of a set actually being contained in the image, and they can then use the NC version to avoid running a superfluous membership check or intersection calculation.

Perhaps @fingolfin @ThomasBreuer @hulpke want to weigh in, given that they were active in #4809 and #5173?

@fingolfin

Copy link
Copy Markdown
Member

Thanks for working on this again, @cdwensley. Unfortunately I don't have the bandwidth available to read all here, think about it, and come up with a good stance right now -- we'll get there, but I am afraid not in time for GAP 4.16.0 -- but I am confident it'll get merged eventually, certainly before 4.17.0.

I'll try to get back to this when I have some mental capacity for it

@hulpke

hulpke commented May 28, 2026

Copy link
Copy Markdown
Contributor

I think part of the reason of NC functions is to actually not have to worry about issues such as membership (which might require an extra test).
I.e. the result of PreImagesSetNC should undefined if the set is not in the image of the map, but if it is returns the same as PreImagesSet.

@cdwensley

cdwensley commented May 28, 2026 via email

Copy link
Copy Markdown
Contributor Author

@cdwensley

cdwensley commented May 28, 2026 via email

Copy link
Copy Markdown
Contributor Author

fingolfin and others added 10 commits June 18, 2026 15:55
Teach args helper about multi-arg variadic functions.
…s were not supported (#6401)

Add runtime argument checks to the user-facing GF2 and 8-bit
kernel entry points instead of relying on debug-only assertions or
unchecked representation assumptions.

Use shared Require helpers for compressed vectors and matrices,
and tighten plain-list validation where these entry points expect
list-backed inputs.

Harden the exported vec8bit kernel entry points that assumed a
first row existed, and fix SHIFT_VEC8BIT_RIGHT for empty
compressed vectors.

AI assistance from OpenAI Codex helped prepare these kernel
validation changes.

Co-authored-by: Codex <codex@openai.com>
Resolves #2570

Co-authored-by: Codex <codex@openai.com>
If input group is infinite or not solvable, fail is returned.
Mostly avoid putting to many things on one line, for better
readability and more accurate code coverage tracking.

Also remove obsolete restrictions for perfect group
orders 86016, 368640, 737280
This undocumented function accepted more than one argument, but
ignored any beyond the first. Apparently this was introduced in
the GAP 4.5 days for compatibility reasons? But compatibility
with what? No package known to me calls this.

For reference in GAP 4.4 it had two arguments (but also was
undocumented, and not called by any outside code).
The OrbitStabilizer entry in the reference manual only documented the
algorithm, not what the operation returns. Adds:

- A short sentence explicitly stating the return value is an immutable
  record with `orbit` (the orbit as a list) and `stabilizer` (the point
  stabilizer subgroup of G).
- A small example block using the same `g:=Group((1,3,2),(2,4,3));;`
  setup already used by the adjacent `Stabilizer` example, so the
  rendered output is identical to verified output already in this file.
@cdwensley

Copy link
Copy Markdown
Contributor Author

Many thanks @ThomasBreuer for all these corrections - sorry about the silly error.

@ThomasBreuer ThomasBreuer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks.
One more suggestion for fixing a typo.
And I am wondering whether also PreImageElm should be changed in the same spirit.

What is missing now is some text for the release notes. The following description would fit but is admittedly quite long.

  • Change the definitions of PreImagesElm, PreImagesRepresentative, PreImagesSet in the case that the given element or set is not contained in the Range of the general mapping:
    Up to now, nothing was guaranteed in this case.
    From now on, an error message is shown in this case.
  • Introduce new operations PreImagesElmNC, PreImagesRepresentativeNC, PreImagesSetNC,
    turn all GAP library methods for PreImagesElm, PreImagesRepresentative, PreImagesSet into methods for the new NC variants, and install methods for the non-NC variants that first test the given element or set for containment in the Range of the given general mapping and then delegate to the NC variants.
  • In all GAP library methods for PreImagesElm, PreImagesRepresentative, PreImagesSet, check whether the given element or set is contained in the Image of the given general mapping.
    Up to now, some of the methods had assumed this and thus gave a wrong answer if the assumption was wrong.
  • Users' code may benefit from changing calls to PreImagesElm, PreImagesRepresentative, PreImagesSet into calls of the NC variants where possible.

Comment thread lib/mapprep.gi Outdated
Co-authored-by: Thomas Breuer <sam@math.rwth-aachen.de>
@cdwensley

Copy link
Copy Markdown
Contributor Author

Regarding PreImageElm - this only applies to bijective maps, and I see no reason to change it.
Far more unsatisfactory are PreImage and PreImages. These two global functions just delegate to one of three operations, so why are they needed? Furthermore the only difference is between PreImage(map,elm) which calls PreImageElm(map,elm) and PreImages(map,elm) which calls PreImagesElm(map,elm) - the other two cases return the same sets.
Cannot remember why, but an NC version of PreImages has been added, but no PreImageNC. Surely it should be neither or both? I'm inclined to remove PreImagesNC. Advice needed!

@cdwensley

Copy link
Copy Markdown
Contributor Author

Interestingly, PreImage is called around 150 times in the main library, but PreImages not at all.

@cdwensley

Copy link
Copy Markdown
Contributor Author

How many of these should be changed? For example, in ghomperm.gi, line 308,
surely G := PreImage( hom );
should be: G := PreImagesRange( hom );
and (more complicated example with fp-groups) in grpfp.gi, line 948,
hom:=MaximalAbelianQuotient(G);
u:=PreImage(hom,TrivialSubgroup(Range(hom)));
could be:
u:=PreImagesSetNC(hom,TrivialSubgroup(Range(hom)));

@ThomasBreuer

Copy link
Copy Markdown
Contributor

Regarding PreImageElm - this only applies to bijective maps, and I see no reason to change it.

The documentation of PreImageElm( map, elm ) says: Anything may happen if elm is not an element of the range of map.
Shouldn't this be changed to a promised error message, for the sake of consistency with the PreImagesSomething operations?
(This need not be part of this pull request.)

Far more unsatisfactory are PreImage and PreImages. These two global functions just delegate to one of three operations, so why are they needed?

The idea was that PreImages( map, obj ) and PreImage( map, obj ) promise an error message if obj is not an element or subset of Range( map ). I do not remember why two functions were introduced.

ThomasBreuer and others added 11 commits July 23, 2026 13:27
* Commented variables in autsr

* PERFORMANCE: Make sure group knows it is autom.

* Set flag that triggers the standard handling of automorphism groups.
Implements a chunked caching scheme for evaluating bijective
GroupGeneralMappingByPcgs homomorphisms on PC words. Splits the source
pcgs into chunks, caching linear combinations of generator images per
exponent pattern, with the bottom elementary abelian layer handled via
a matrix over the corresponding prime field. Includes a corresponding
ImagesRepresentative method that uses this cached data for a >2.5x
speedup, per the included GAPDoc example.
… results (i.e., with some entries representing the same conjugacy classes) (#6460)

When mapping perm orbits first in DoConjugateInto, avoid duplication if
orbit images are equivalent.

Co-authored-by: Alexander Hulpke <hulpke@math.colostate.edu>
Co-authored-by: Max Horn <max@quendi.de>
Co-authored-by: Codex <codex@openai.com>
…files (#6467)

Corrects misprints and grammatical errors (misspellings, subject/verb
agreement, stray commas, non-idiomatic phrasing, etc.) in comments
across all files listing Alexander Hulpke as a (co)author. Boilerplate
headers, citation keys, GAP identifiers, GAPDoc markup, non-English
notes, and genuinely ambiguous/garbled comments were left untouched.

Co-authored-by: hulpke <hulpke@math.colostate.edu>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
... and in general make its phrasing more consistent.

Also update some several outdated sections of the
documentation about break loops and error handling.

Co-authored-by: Codex <codex@openai.com>
* Align and clarify break loop instructions further
* Adjust <Log> blocks to new late error msg
* Regenerate tst/testspecial
They are not referenced anywhere and nowadays at
most of historical interest.
@cdwensley

Copy link
Copy Markdown
Contributor Author

Thanks for your comments. Away for a few days - will address them when we return.

@fingolfin

Copy link
Copy Markdown
Member

There was a merge conflict in tst/testinstall/ggmbi.tst‎ (looked like a copy&paste accident) which I just resolved (so you should git pull)

ChrisJefferson and others added 5 commits July 27, 2026 18:17
Restyle the browser GAP page to match www.gap-system.org (Ubuntu fonts,
GAP logo, crimson accents, dark-mode support) and vendor all runtime
assets (xterm 4.17.0, xterm-pty 0.9.4, the fit addon, logo, fonts) so
the deployed site has no CDN dependency.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@cdwensley

Copy link
Copy Markdown
Contributor Author

As suggested last week I have removed the recently introduced PreImagesNC from the library, though PreImages remains. In fact there were 12 calls to PreImages in the library which were changed to PreImagesNC and are now back to PreImages (in alglie.gi, grp.gi, grpnice.gi, grpprmcs.gi, mapprep.gi and relation.gi). Entries for PreImages in mapping.gd and mapping.gi have reverted to the versions in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants