Skip to content
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

Fixed a bug in AbelianGroup.Subgroup.gens_orders(), which returns the reduced order of the subgroup #36986

Merged
merged 8 commits into from
Jan 22, 2024

Conversation

amanmoon
Copy link
Contributor

@amanmoon amanmoon commented Jan 1, 2024

The gens_orders() method will returns the correct order after these changes.

Created a new variable gens_orders:

gens_orders = [order_sage for g in H.GeneratorsOfGroup() if (order_sage := g.Order().sage()) is not infinity]

Modified the AbelianGroup_class class to include an additional argument, from which gens_orders is passed and assigned to self.gens_orders:

def __init__(self, generator_orders, names, gens_orders=None, category=None):
self._gens_orders = generator_orders if gens_orders is None else gens_orders

Also, tests have been written for the gens_orders method:

sage: G, (g0, g1) = AbelianGroup(2, [48, 0]).objgens()
sage: G0 = G.subgroup([g0])
sage: len(G0.gens()) == len(G0.gens_orders())
True

Additionally, performed code cleanup.

Fixes #36974

Changing the invs variable directly to [order_sage for g in H.GeneratorsOfGroup() if (order_sage := g.Order().sage()) is not infinity] here causes series of errors, as other variables depend on it.

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.

@amanmoon amanmoon changed the title Fixed a bug in gens_orders() that initially used to return the reduced order of the subgroup. Fixed a bug in AbelianGroup.Subgroup.gens_orders() that initially used to return the reduced order of the subgroup. Jan 2, 2024
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

I think the general idea of not passing invs as the generators of the subgroup is the correct idea. However, you are effectively creating redundant information with the additional argument. Plus there becomes an inconsistency with the variable names being created. You can see this by

sage: S.inject_variables()
Defining f0, f1
sage: f1
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[13], line 1
----> 1 f1

NameError: name 'f1' is not defined

Instead, you should simply pass the gens_orders up as the first argument to AbelianGroup_class.__init__ (after self of course).

src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
@amanmoon amanmoon requested a review from tscrim January 9, 2024 16:39
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

Thank you. Just a few more minor details.

src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
src/sage/groups/abelian_gps/abelian_group.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

Thank you. LGTM.

@tscrim tscrim changed the title Fixed a bug in AbelianGroup.Subgroup.gens_orders() that initially used to return the reduced order of the subgroup. Fixed a bug in AbelianGroup.Subgroup.gens_orders(), which returns the reduced order of the subgroup Jan 10, 2024
@vbraun
Copy link
Member

vbraun commented Jan 12, 2024

merge conflict

@amanmoon
Copy link
Contributor Author

amanmoon commented Jan 15, 2024

@vbraun, I have made the necessary changes.

@tscrim
Copy link
Collaborator

tscrim commented Jan 15, 2024

@amanmoon That's not what the automated checker is saying. Please try again by either merging or rebasing (I recommend the latter) over the most recent develop branch.

Copy link

Documentation preview for this PR (built with commit 300c530; changes) is ready! 🎉

@tscrim
Copy link
Collaborator

tscrim commented Jan 16, 2024

Thanks. This is back to a positive review.

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 16, 2024
…`, which returns the reduced order of the subgroup

    
The `gens_orders()` method will returns the correct order after these
changes.
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
Created a new variable `gens_orders`:
```python
gens_orders = [order_sage for g in H.GeneratorsOfGroup() if (order_sage
:= g.Order().sage()) is not infinity]
```
Modified the `AbelianGroup_class` class to include an additional
argument, from which gens_orders is passed and assigned to
`self.gens_orders`:
```python
def __init__(self, generator_orders, names, gens_orders=None,
category=None):
self._gens_orders = generator_orders if gens_orders is None else
gens_orders
```
Also, tests have been written for the `gens_orders` method:
```sage
sage: G, (g0, g1) = AbelianGroup(2, [48, 0]).objgens()
sage: G0 = G.subgroup([g0])
sage: len(G0.gens()) == len(G0.gens_orders())
True
```
Additionally, performed code cleanup.
<!-- Why is this change required? What problem does it solve? -->
Fixes sagemath#36974

Changing the `invs` variable directly to `[order_sage for g in
H.GeneratorsOfGroup() if (order_sage := g.Order().sage()) is not
infinity]` [here](https://github.com/sagemath/sage/blob/e249befd47ad8610
f74372533a2943ff7b2dde94/src/sage/groups/abelian_gps/abelian_group.py#L1
710) causes series of errors, as other variables depend on it.
### 📝 Checklist


<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36986
Reported by: Aman Moon
Reviewer(s): Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 16, 2024
…`, which returns the reduced order of the subgroup

    
The `gens_orders()` method will returns the correct order after these
changes.
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
Created a new variable `gens_orders`:
```python
gens_orders = [order_sage for g in H.GeneratorsOfGroup() if (order_sage
:= g.Order().sage()) is not infinity]
```
Modified the `AbelianGroup_class` class to include an additional
argument, from which gens_orders is passed and assigned to
`self.gens_orders`:
```python
def __init__(self, generator_orders, names, gens_orders=None,
category=None):
self._gens_orders = generator_orders if gens_orders is None else
gens_orders
```
Also, tests have been written for the `gens_orders` method:
```sage
sage: G, (g0, g1) = AbelianGroup(2, [48, 0]).objgens()
sage: G0 = G.subgroup([g0])
sage: len(G0.gens()) == len(G0.gens_orders())
True
```
Additionally, performed code cleanup.
<!-- Why is this change required? What problem does it solve? -->
Fixes sagemath#36974

Changing the `invs` variable directly to `[order_sage for g in
H.GeneratorsOfGroup() if (order_sage := g.Order().sage()) is not
infinity]` [here](https://github.com/sagemath/sage/blob/e249befd47ad8610
f74372533a2943ff7b2dde94/src/sage/groups/abelian_gps/abelian_group.py#L1
710) causes series of errors, as other variables depend on it.
### 📝 Checklist


<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36986
Reported by: Aman Moon
Reviewer(s): Travis Scrimshaw
@vbraun vbraun merged commit 6b8deac into sagemath:develop Jan 22, 2024
14 of 18 checks passed
@amanmoon amanmoon deleted the bug/AbelianGroup.Subgroup branch January 23, 2024 18:52
@mkoeppe mkoeppe added this to the sage-10.3 milestone Mar 7, 2024
@dimpase
Copy link
Member

dimpase commented Apr 4, 2024

This has broken .subgroup(...) rather badly, see sage-devel
e.g. with this one gets

sage: g=AbelianGroup([2,2])
sage: g.cardinality().factor()
2^2
sage: gg=g.subgroup(g.list())
sage: gg.cardinality().factor()
2^3

@amanmoon amanmoon restored the bug/AbelianGroup.Subgroup branch April 22, 2024 14:35
amanmoon added a commit to amanmoon/sage that referenced this pull request Apr 22, 2024
@amanmoon amanmoon mentioned this pull request Apr 22, 2024
4 tasks
vbraun pushed a commit to vbraun/sage that referenced this pull request Jun 5, 2024
    
Reverted changes made in sagemath#36986

The bug in sagemath#36974 remains unsolved. Efforts are being made in sagemath#37744 to
resolve the bug.

Fixes  sagemath#37744
### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies
    
URL: sagemath#37850
Reported by: Aman Moon
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this pull request Jun 8, 2024
    
Reverted changes made in sagemath#36986

The bug in sagemath#36974 remains unsolved. Efforts are being made in sagemath#37744 to
resolve the bug.

Fixes  sagemath#37744
### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies
    
URL: sagemath#37850
Reported by: Aman Moon
Reviewer(s):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in AbelianGroup.Subgroup
5 participants