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
Checking if an element is in a subgroup can raise 'TypeError' #31507
Comments
comment:1
Moving to 9.4, as 9.3 has been released. |
comment:3
From #32910: Ok, I don't have a development version of sage yet. And I have trouble getting one. But here is some code I wrote that I used to monkey patch
|
Branch: public/31507 |
Author: Maarten Derickx |
Reviewer: Dave Morris |
Commit: |
comment:5
Here is a branch that implements the patch. I made a few reviewer changes: I kept some of the original code at the start of the method, I added some import statements, and I think the doctest was wrong (the correct answer is The other option would be to fix the bug in the original code. However, I think it makes sense to use this simpler code (which delegates the work to ZZ-module methods), because it is easier to understand and to maintain. The example from this ticket should probably be added as an additional doctest, but I forgot to do that. I am setting to "needs review" to start getting comments from humans and patchbots. I will do the review myself if we don't hear from anyone. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:7
Hi Dave, Thanks for turning this into a git branch and making sure that the non algorithmic part of the code like the Is there a reason to do the imports inside of the function and not at the top of the file? Was there a problem with circular imports? |
comment:8
The following suggestions are to
- sage: Zmstar.<a,b> = AbelianGroup(2, [4, 576])
+ sage: G.<a,b> = AbelianGroup(2, [4, 576])
- sage: Hgens = [a**2,a*b**2]
+ sage: Hgens = [a^2, a*b^2]
- sage: g = Zmstar.gen(1)**3
- sage: g in H
- False
- sage: a^3*b^2 in H
- True
+ sage: [g in H for g in (a^3, b^2, b^3, a^3*b^2)]
+ [False, False, False, True] - sage: f0*f1^2 in H
- False
- sage: f0 in H
- False
+ sage: [g in H for g in (f0, f0*f1^2, f0*f1^3, f0*f1^4)]
+ [False, False, True, False] Another cosmetic change I would make, but maybe my pep8 is off: - gens_basis = matrix(
- ZZ, len(self._gens), len(amb_inv), [g.list() for g in self._gens]
- )
+ gens_basis = matrix(ZZ, len(self._gens), len(amb_inv),
+ [g.list() for g in self._gens]) Feel free to ignore these minor comments. |
This comment has been minimized.
This comment has been minimized.
comment:9
I went for this simpler implementation because I had trouble understanding what the original code was trying to do. I am guessing that maybe the divisions had to be integer divisions
The following piece of code show a more subtle (i.e. not even raising an error) way that the old code can fail.
|
comment:10
Replying to @slel:
I actually let my code be formatted by black whose output is guaranteed to be pep8 compatible. And black proposed the above linebreak so at least the original is pep8 compatible. Although black does put the closing parenthesis unindented. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:13
I think this update implements all of the suggestions. I also broke two lines that were more than 80 characters, and added a check for whether "junk" is in H in the first test, because the method should not choke on stupid input. And I added the last example of comment:9 as another test. I think that example is very strong evidence that this ticket takes the right approach by getting rid of code duplication. I apologize for the python style errors -- I am not fluent. PEP8 says "Imports are always put at the top of the file..." so I moved them there. It also says "The closing brace/bracket/parenthesis on multi-line constructs may either line up under the first non-whitespace character of the last line of list ... or it may be lined up under the first character of the line that starts the multi-line construct ...". So (regarding comment:10) I left the closing parenthesis on its own line (but reduced the indent to match the author's original code that black liked). Further comments or corrections (or corrections to my implementations of the corrections) are welcome, of course. If there aren't any, and the patchbot comes back green again, then I think we are done. |
comment:14
Thanks for this! Form my part it looks good to go. |
Changed reviewer from Dave Morris to Dave Morris, Samuel Lelièvre |
comment:15
Likewise. And green light from a patchbot. |
comment:16
Thanks to both of you for the code, the comments and suggestions, and the review! |
Changed branch from public/31507 to |
In Sage 9.2, after defining:
the following correctly determines non-membership:
but the following gives a type error:
The error seems to come from the
__contains__
methodof
src/sage/groups/abelian_gps/abelian_group.py
(around line 1715), in particular the
if-else
statements of lines 1740-1743.
CC: @slel
Component: group theory
Author: Maarten Derickx
Branch/Commit:
c790824
Reviewer: Dave Morris, Samuel Lelièvre
Issue created by migration from https://trac.sagemath.org/ticket/31507
The text was updated successfully, but these errors were encountered: