-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
IntegerVectorsModPermutationGroup confuses groups whose domains are different #36527
Comments
I'd like to work on this issue. Can it be assigned to me? |
According to my rudimentary tests, for the second group, the And indeed, those two permutation groups are "Sage-equal" as in
even though they have domains of different sizes, so they are supposed to act on integer vectors of different lengths. This is related to my Ask Sagemath question Equality of permutation groups. Since the SageMath behaviour of permutation group equality is not likely to change (or at least, it would be a big change), and it makes sense to keep the cached behaviour here, one simply needs a way to differentiate situations that are different but have the "Sage-same" permutation group. What if the auxiliary class is simply given an extra domain argument? |
A workaround is to always compute a strong generating system for the permutation group, and provide it as an argument. Permutation groups with different domains will have different systems, so this differentiates them.
|
Are there any thoughts on how this would be fixed? Note that this is not some funny artificial corner case, but a real issue when working with several different permutation groups. In my work with graph isomorphisms I have to use the "sgs" workaround, otherwise all my results would be incorrect. The bug is somewhat nasty because it silently causes mathematically wrong results, even unpredictably (depending on what groups have been handled in the SageMath session previously, and in what order). At the very least, if not fixed, the bug should be documented to the users. |
I can confirm it's still the same bug in Sage 10.2 |
the problem is in Maybe @tscrim can say more about it. |
I am not sure how the group theory people would react to that since the groups are "equal." Although here this means I would instead just pass the domain as part of the constructor for |
Permutation group is a pair (group, domain), not just a group. So this would be fixing a maths bug. |
Indeed. :) I don't disagree with you, but there are people who use the permutation groups and might expect them to be equal as their
This just might also end up breaking a fair bit of code in the wild. I guess we could get some sense of this by what breaks within library code. It is just such a change we might need to approach with some caution. (We can fix the bug at hand another way at least.) |
Sage's concept of equality of permutation groups is not that well-defined. It is not documented, it is not transitive, it does not conform to "equal if the permutations are equal", and it does not conform to "equal if repr are equal".
Another example showing that sometimes different domain causes the permutation groups to be different, and sometimes it does not. All of the following four groups contain the same permutations, as compared with
It is also not true that
Now what is the well-defined equality notion here? Can it be documented? |
Please don’t use corner cases as general examples (S_0 is not really well-defined as a group as you likely know). Please don’t assume that equality is broken and assume everything is built around the lists of permutations. It is documented what the behavior is in the comparison method and it is well-defined. Stop assuming that the issue is with the definition and actually look at what the code is doing before claiming where a problem is. It’s good that you are finding these inconsistencies, but I would appreciate it if you could tone done the amount of sensationalism. I am pretty sure the reason the comparison is failing is because internally the domain is set as {0, …, n-1} and basing the comparisons on that. So the permutations for I made the assumption that
This might also be an upstream issue with GAP. |
For my part I have made it very sure that I address facts, not other people or what I imagine to be their assumptions, in this discussion.
So I find strange that I am told, in a commanding voice, to "stop assuming". It was not I who was assuming. About the equality notion being documented, I guess I just have to take your word that it is, somewhere. Although in Permutation groups I am finding absolutely nothing about when would permutation groups be defined equal, or how they compare. In the source file As said, I made sure of keeping to the plain facts, and presenting evidence for what I claim. I can see that there is a different kind of discussion culture here at play. I find Travis's response unwelcoming and impolite. I apologize for bringing out these shortcomings of SageMath. I find this discussion unfitting and, for my part, will end it here. |
Good morning, I apologise for somewhat abrasive tone here. No need to apologise on your side here, you did very well by bringing up the bug(s) here. Perhaps it's also lost in translation here, but there is no commanding tone, it's more of an apology for the mess here. "Please don't assume that Sage is doing things in such and such way" is an acknowledgement that not all is good, it's not a command to stop talking about it! The background for this mess is the way GAP (https://www.gap-system.org), which is the backend called for many operations, treats permutation groups. For GAP, permutations all live in the symmetric group of a very big degree, and so their domain is always the natural numbers. |
@tscrim - what kind of a potential issue with GAP you have in mind? |
@tscrim - what's the main use of |
@tscrim - please... It's a quite bad problem, acknowledge it. |
It seems to me that the situation is somewhat similar to the vertex labels of graphs or posets. Some applications need arbitrary vertex labels, for example, I want to define a poset (or a graph) on some set of combinatorial objects, think of the flip graph of triangulations. Similarly, I (personally) want to have permutation groups on arbitrary (hashable) domains - that's what combinatorial species should be. I don't know whether standardising the labels should be the job of the permutation group class (or graph class), or not. A similar question applies to, for example |
@mantepse - I agree. What GAP does is OK for group theory itself, but for applications it's suboptimal, and Sage not doing the mathematically correct things while e.g. comparing permutation groups with explicitly given domains is a big problem. The latter is the cause of the original problem posted here. |
I am not sure. There seems to be a symmetry issue as I mentioned as we have
So I don't understand what is going on here from just looking at the code and running examples. It doesn't seem like the bug is within GAP from this. I am very confused why this is not working. |
my guess would be UniqueRepresentation somewhere, caching with data missing - just like in IntegerVectorsModPermutationGroup. |
It is not very difficult to see that
Suppose we are performing one of the comparisons Then the code always goes to branch 3, and the old-style comparison result Because both groups are subgroups of each other, it does not matter which one is left and which one is right. If This is certainly well-defined and documented, if the definition is "the result of a comparison is whatever the comparison code does" and the documentation is "read the source". |
How about adding |
I tried a slightly less intrusive change: diff --git a/src/sage/groups/perm_gps/permgroup.py b/src/sage/groups/perm_gps/permgroup.py
index b0083394cb..aa9b469506 100644
--- a/src/sage/groups/perm_gps/permgroup.py
+++ b/src/sage/groups/perm_gps/permgroup.py
@@ -2075,7 +2075,9 @@ class PermutationGroup_generic(FiniteGroup):
sage: AlternatingGroup(4)._repr_()
'Alternating group of order 4!/2 as a permutation group'
"""
- return "Permutation Group with generators %s" % list(self.gens())
+ if self._has_natural_domain():
+ return "Permutation Group with generators %s" % list(self.gens())
+ return "Permutation Group with generators %s and domain %s" % (list(self.gens()), self.domain())
def _latex_(self):
r""" This just produces 6 obvious doctests failures in In any case, this seems like a very obvious improvement. However, I think we should also insist that two permutation groups are only equal if their domains are the same - and add a |
Reminds me of something I've been wondering, and did not find documented. (Yeah, it's just me. It certainly is documented somewhere.) Are SageMath objects supposed to have repr texts that uniquely determine the value of the object? In Python it is documented that
I wonder if SageMath simply inherits the same idea from Python, or if there are house rules. |
No, only if this would be easily done and helpful. For example:
If I understand correctly, the focus is on usability for mathematicians, and - as a mathematician - I can say, that works well for me. |
Doesn't this mean that for domains other than {1,...n} we are only able to test equality up to conjugacy. I admit I'm not sure. With 'Set' I am quite sure that we cannot guarantee a fixed order, can we guarantee it with 'set'? |
no, that's certainly not desirable. Maybe @dcoudert can share some wisdom from fixing these issues in |
If we cannot even consistently test two finite S(s)ets for equality, it's pretty much end of the project... |
We can test sets for equality, but I m less sure that we can put a total order on a set consistently. |
I have not fully read this long thread, so I'm not fully sure of the question ;) In graphs, equality takes the domain (i.e., the labels of the vertices) into account. This is different from isomorphisms.
|
How are sets of vertices and (directed) edges implemented? Are these Is there an internal conversion to a canonical {0,1,...,n} domain? |
It happens all the time. I ran the script 1000 times consecutively (each time a new Sage invocation) and got 42 different results. You can see the Set behaviour more directly by just running Here are three consecutive runs, with 1's marking equality and 0 inequality between A, B, C, D, S, T. The order of the elements in the Sets determines whether the single swap
|
Very good. That is what I call defining something in Sage. The situation with the permutation group equality falls far short of this. |
This is quite complex, depends on the backend (dense, sparse, immutable, etc.) and some parts remain unclear to me. For edges, we also have different data structures for static/dynamic, sparse/dense, (im)mutable (di)graphs.
Only for static (immutable) graphs. |
I think I should clarify my statement: If we exclusively use gap to check for equality and we do not have the same total ordering of a However, it may well be that python guarantees that I think it doesn't matter that the ordering differs in different sessions. |
Surely we can test two finite S(s)ets for equality. And if they are equal, presumably it means they contain the same objects. If you have Sure, if you list But I don't see anything preventing just choosing a common mapping when performing the equality test: If you list This, of course, relies on the two domains having the same elements. If someone wants to define some kind of "consistent" mapping from two arbitrarily different sets into small integers, that is going to be a very different kind of a project. |
It does not guarantee that two sets that are equal would have equal lists in one session. This is consecutive commands on one session:
If two groups have domains that are equal ( |
@jukkakohonen, excellent, then it is clear that the mapping must be done in As the other experiment (printing the domain if it is not {1,...,n}) shows special domains are rarely used, mostly for the automorphism group of a graph. I am guessing that especially there we actually would like to take the domain into account. |
I'm not well familiar with the call interface between Sage and GAP, but something like that. Indeed it seems it must be in If each group creates their own GAP mapping (from domain elements to integers) separately, then it seems much more difficult to ensure that each group will choose the same mapping. If one of them maps "a" to 17, then how does the other know that -- if their domains are just equal ( Perhaps this code snippet explains what I'm after (or perhaps it was clear already):
We see that the GAP mapping from Then we have the two GAP objects which should have consistently the same integers for the same elements both in Not sure what is the best low-level technique of doing it. Do we need to create a new GAP object just for the purpose of the richcmp, and then throw it away? |
One point I should mention: Only one of the two "directions" of confusion is really harmful with respect to what this issue was originally about, namely IntegerVectorsModPermutationGroup thinking that two groups are the same when they aren't. If a mistake happens the other way, that two groups compare inequal while they "should" be equal (by whatever reasoning), the result is that IntegerVectorsModPermutationGroup simply does the calculations separately (creating a new strong generating system and whatever). It will work correctly, just a bit slower than if it could use the cached instance. Thus, although for many other reasons it might be nice to have a permutation group equality machinery in Sage that is consistent by all accounts, it is not necessary for fixing this particular bug. For this bug we just need something that certainly differentiates the groups that are not "really" equal. Either by fixing group equality at least in that direction, or even more easily, make a local change in IntegerVectorsModPermutationGroup. Seeing what a can of worms it is to "really" fix permutation group equality, a local change might be the best option for now. Then open a new issue for discussing the general notion. |
I don't think it is a good idea to postpone the fix for equality, if there is consensus. I don't see a can of worms, just an oversight. |
I have no informed opinion on that (when to fix equality and by what protocol). Certainly it is something that I would like to have, but I trust others will have a better hunch on just how intrusive it is going to be. Also, there could be performance issues in creating a new GAP object within In any case the equality fix deserves to be an issue with a more prominent name than "IntegerVectorsModPermutationGroup confuses group whose domains are different", no? |
at the moment (and already for a while, cf #26902) Sage has 2 interfaces to GAP
The plan is to move to libgap, largely done, but not quite. Old interface should be avoided.
|
note that |
@dimpase I don't see how constructing a gap group can be avoided if NB: |
If the consensus is to fix the equality (to respect domains, and also other bug fixes like the GAP encoding), a couple of questions:
|
Shouldn't the domain be a |
Oh I see, whatever the user is giving is always converted to the same type. That makes sense, so we don't need to worry about different types of domain objects. Now FiniteEnumeratedSet is ordered, so one needs to decide (and document) whether e.g. symmetric groups on |
IMHO the domain in permutation groups theory is a set, mathematically speaking. Also, I think I explained above that we cannot fix equality without fixing inequalities, as we want |
It seems that strict containment |
I have now added a warning of this issue in the docstring of IntegerVectorsModPermutationGroup. |
I just realized: the reason for the domain being a
|
* build/pkgs/referencing/dependencies: Add missing dep * add :wikipedia:`Cycle Index Theorem etc as explained in my comments on the PR * Fixes for reviewer comments * fix linter * Implement fallback mechanism of default latex engine * fix qepcad doctest This test started to fail on Sage 10.3.beta2 * Small edit * adding line breaks ad suggested * fix doctest warnings in src/sage/interfaces/ * some ruff fixes (UP034 and UP039 codes) and error links in categories * ruff auto-fixing several details in combinat folder * more fixes * some ruff fixes and error links in the graphs folder * removed 'arb' which popped up in deps * sage.env, sage.misc.package: Use SAGE_LOCAL_SPKG_INST to avoid clash with SAGE_SPKG_INST set by sage-spkg * fix warnings in coxeter_group.py * fix warnings in coxeter_group.py * Default engine is computed lazily * fix warnings in coxeter.pyx * fix doctest warnings in src/sage/game_theory/gambit_docs.py * fix doctest warnings in src/sage/game_theory/parser.py * ruff UP details and links to errors in doc in geometry folder * fix doctest warnings in src/sage/game_theory/normal_form_game.py * document&test corner case, empty domain without constraints * Documented that sagemath#36527 causes erroneous results & how to avoid * fix doctest warnings in src/sage/categories/finite_complex_reflection_groups.py * fix doctest warnings in src/sage/coding/ag_code_decoders.pyx * fix doctest warnings in src/sage/plot/graphics.py * oops, correct workaround * fix doctest warnings in src/sage/quadratic_forms/ternary_qf * various fixes in quadratic_forms (ruff, pep8, error links, etc) * Small language fixes; for brevity move one example to tests * png() uses the default engine * suggested details * suggested details * Changed _matrix_power_symbolic function to condier mk=0 case This fixes sagemath#36838. Here, I have added a condition to check whether mk=0 or not. Because whenever mk=0 we should give mk^(n-i) (i.e. 0^(n-i)) instead of only 0 considering (n-i) can be equal to zero and in this case 0^(n-i) will be more accurate than only 0. * Changed the _matrix_power_symbolic function to handle all the cases This change handles all the errors which were occuring in previous commit and this commit handles the case of mx=0 very effectively. * Created tests covering the changes Created tests covering the changes and checking whether the trac:`36838` is fixed or not. * Give more precise answer by using kroncker_delta function Instead of returning 0^(n-i), it would be more precise if we reutrn value of kroncker_delta function, it will be helpful when we try to evaluate the final matrix using the value of n. * Rewriting tests for the PR Changed the final answer given by test of this PR. * Correct answers of the doctest for _matrix_power_symbolic function Changed the answer of doctest according to new changes. * Corrected the doctest Corrected the doctest and improved some code styles, which were not correct according to guidelines for python coding for sage. * Modified the doctest and changed the comment Updated the old doctests which were failing before and updated the comment to make it more readable. * Corrected lint errors * use file-level tag in src/sage/libs/coxeter/coxeter.pyx * use file-level tag in src/sage/libs/coxeter/coxeter_group.py * build/pkgs/*/distros: Remove quotes, change to one package per line git grep -l \" build/pkgs/*/distros* | xargs sed -i.bak '/^"/s/"//g' git grep -l -E '^([^# ]+) +([^# ][^#]+)(#.*)' build/pkgs/*/distros/*.txt | xargs sed -E -i.bak $'s/^([^# ]+) +([^# ][^#]+)(#.*)?/\\3\\\n\\1\\\n\\2/' git grep -l -E '^([^# ]+) +([^# ][^#]+)' build/pkgs/*/distros/*.txt | xargs sed -E -i.bak $'s/^([^# ]+) +([^# ][^#]+)/\\1\\\n\\2/' git grep -l -E ' +$' build/pkgs/*/distros/*.txt | xargs sed -E -i.bak 's/[ ]+$//' * build/bin/sage-print-system-package-command: Shell-quote the packages * fix precision issue for 𝑗=0 and ℓ=3 * build/bin/sage-get-system-packages: Substitute PYTHON_MINOR here * build/bin/write-dockerfile.sh: Shell-quote system packages * src/doc/bootstrap: Use sage-get-system-packages so that ENABLE_SYSTEM_SITEPACKAGES is respected * sage-spkg-info, src/doc/bootstrap: Wrap command lines * Current engine is dependent on the user's system * Document the format of system package files * src/doc/bootstrap: Wrap more narrowly * Addressing reviewer comments. * build/bin/sage-print-system-package-command: Simplify * src/doc/bootstrap: Remove unused variable * src/doc/bootstrap: Parallelize generation of SPKG.rst files * build/bin/sage-spkg-info: Restore lost blank output line * build/bin/sage-spkg-info: Fix and improve RST markup * 36884: issue reference Co-authored-by: Travis Scrimshaw <[email protected]> * 36884: doctest formatting Co-authored-by: Travis Scrimshaw <[email protected]> * 36884: replace copy Co-authored-by: Travis Scrimshaw <[email protected]> * adding corolla-related methods to free pre-Lie algebras * 36884: new list loop_crossings * build/pkgs/_bootstrap/distros/fedora.txt: Remove outdated comment * tox.ini: Add local-macports * Add macports.txt * build/pkgs/_prereq/distros: Update file comments * build/bin/sage-print-system-package-command: Handle macports install * tox.ini (local-macports-optlocal): Use sudo * build/bin/sage-print-system-package-command (macports): Handle setup-build-env * build/bin/sage-guess-package-system: Detect macports * tox.ini: Add configuration factors macports-python{3.8,3.9} * build/bin/sage-print-system-package-command (macports): Recommend FC as configure arg, not environment variable This is so that the presence of the environment variable at 'make' time does not break the build when the compiler is not actually present. * tox.ini (macports): Pass FC as configure argument; add variants macports-gcc_{spkg,9,10,11} * tox.ini (macports): Fix up use of ALL_EXTRA_SAGE_PACKAGES * tox.ini (local-macports): Update macports base version to 2.7.2 * build/pkgs/gfortran/distros/macports.txt: Switch to gcc11 * tox.ini (macports): By default use FC=gfortran-mp-11 * build/bin/sage-print-system-package-command (macports): Also update to gcc11 here * WIP * tox.ini (macports): Remove variants that tried to use real gcc * build/pkgs/libgd/distros/macports.txt: Disable * build/pkgs/python3/distros/macports.txt: Use python310 * Disable more broken macports packages * build/bin/sage-print-system-package-command [macports]: Do not describe variants that do not work * tox.ini (macports): Set CPATH, LIBRARY_PATH * build/pkgs/pari/distros/macports.txt: Disable * tox.ini (macports): Use isysroot * build/bin/sage-print-system-package-command (macports): Update use of print_shell_command * build/pkgs/_bootstrap/distros/macports.txt: One package per line * tox.ini: Add macports-python3.12 * revert some "a -> an" changes * Updated SageMath version to 10.3.beta3 * Remove a redundant comment * build/pkgs/e_antic: Update to 2.0.0 * sage.{coding,combinat}: Update # needs * sage.combinat.root_system: Update # needs * sage.combinat: Update # needs * sage.combinat: Update # needs * sage -fixdoctests src/sage/combinat * sage.rings: Update # needs * sage.rings: Update # needs * sage.rings: Update # needs * sage -fixdoctests src/sage/rings * src/sage/rings/power_series_ring.py: Fix import * Remove empty doctest lines * sage.rings: Break an import cycle * sage.rings.continued_fraction: Make imports from sage.combinat.words lazy * sage.{categories,rings}: Modularization fixes for imports * Remove uses of sage.PACKAGE.all... * pkgs/sagemath-{flint,symbolics}: Fixups * Massive modularization fixes * Remove uses of sage.PACKAGE.all... (fixup) * pkgs/sagemath-gap: Move reflection_group, weyl_group here from sagemath-modules * suggested changes, arigato ! * refresh the doc about coercion and test the given example * reverted changes and added self.is_dead(warn_only=True) * fixing one bug in the use of valuation * suggested detail * add interface to nauty's genktreeg * 36884: treat no loops first Co-authored-by: Travis Scrimshaw <[email protected]> * src/sage/calculus/ode.pyx: constness fix for clang 16 * sage.rings: Modularization fixes for imports of power series * build/pkgs/normaliz/patches: Add https://github.com/Normaliz/Normaliz/issues/412\#issuecomment-1862036237 * src/sage/rings/finite_rings/element_ntl_gf2e.pyx: Fix test for libgap element * Fixing some details. * build/pkgs/normaliz/spkg-install.in: Override FLINT configure test * build/pkgs/_prereq/distros/conda.txt: Pin compilers until sagemath#36840 is fixed * build/pkgs/{normaliz,pynormaliz}: Add patchlevel to trigger build of pynormaliz in 'CI Linux incremental' * change build/pkgs/nauty/spkg-configure.m4 * details fixed in cfinite_sequence.py * update comment in build/pkgs/nauty/spkg-configure.m4 * src/sage/tests/gap_packages.py: Normalize package names to lower case in doctest * suggested changes * build/pkgs/furo/spkg-install.in: Remove * remove one doctest, fix the other * add some # optional - nauty tags * some details in multi_polynomial base * use # needs nauty * suggested change in src/sage/features/nauty.py * src/sage/doctest/forker.py: Use JobClient(use_cysignals=True) * src/sage/doctest/forker.py: Do not mask ImportError while calling JobClient * build/pkgs/gnumake_tokenpool: Update to 0.0.4 * build/pkgs/gnumake_tokenpool/install-requires.txt: require >= 0.0.4 * sage.plot: Update # needs * sage.plot: Update # needs * Add # needs * sage -fixdoctests src/sage/plot * src/sage/plot/arc.py: Fix # needs * sage.plot: Doctest cosmetics (copied from sagemath#35095) * src/sage/plot/plot3d/list_plot3d.py: Fix up * src/sage/misc/replace_dot_all.py: Update doctest output * src/sage/plot/plot.py: Fix Warning: Variable 'x' referenced here was set only in doctest marked '# long time, needs sage.symbolic' * src/sage/doctest/sources.py: Use file-level doctest tags for the virtual doctest; fixes Warning: Variable 'sig_on_count' referenced here was set only ... * build/pkgs/ninja_build: support samurai version scheme Samurai is a C99 ninja implementation with an almost-compatible version scheme, except that it has only two version components instead of the three that ninja has. We update the "sed" call used to parse the version number out of `ninja --version` so that it can parse a samurai version too. This should only matter on systems where (for example) /usr/bin/ninja points to samurai. That's not typical, but it recently became possible to do on Gentoo in an "official" way. * src/sage/combinat/permutation.py: Fix # needs * src/sage/combinat/root_system/non_symmetric_macdonald_polynomials.py: Fix # needs * Addressing review comments for detecting subtypes. * Updated SageMath version to 10.3.beta4 --------- Co-authored-by: Matthias Koeppe <[email protected]> Co-authored-by: Dima Pasechnik <[email protected]> Co-authored-by: Kwankyu Lee <[email protected]> Co-authored-by: Frédéric Chapoton <[email protected]> Co-authored-by: dcoudert <[email protected]> Co-authored-by: Jukka Kohonen <[email protected]> Co-authored-by: RuchitJagodara <[email protected]> Co-authored-by: Release Manager <[email protected]> Co-authored-by: Lorenz Panny <[email protected]> Co-authored-by: Travis Scrimshaw <[email protected]> Co-authored-by: Sebastian Oehms <[email protected]> Co-authored-by: Travis Scrimshaw <[email protected]> Co-authored-by: Sebastian <[email protected]> Co-authored-by: John Cremona <[email protected]> Co-authored-by: Heiko Knospe <[email protected]> Co-authored-by: adrinospy <[email protected]> Co-authored-by: Tobias Diez <[email protected]> Co-authored-by: Michael Orlitzky <[email protected]>
Steps To Reproduce
In SageMath version 9.0, running this:
Expected Behavior
In
A
, the domain has two elements, so I am expecting lists of two elements that add up to 3:In
B
, the domain has three elements, so I am expecting lists of three elements that add up to 3:Actual Behavior
From both groups we get the same listing:
Additional Information
If the order of execution is reversed, so that we do
B
first andA
second, thenB
gives the correct three-element lists, andA
gives incorrectly the three-element lists.So, the first one gets computed correctly, and the second one incorrectly. It looks like IntegerVectorsModPermutationGroup is remembering that it has already seen this group, not noticing that is in fact a different permutation group with different domain.
Environment
Checklist
The text was updated successfully, but these errors were encountered: