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

Bug in AbelianGroup.Subgroup #36974

Closed
grhkm21 opened this issue Dec 27, 2023 · 0 comments · Fixed by #36986
Closed

Bug in AbelianGroup.Subgroup #36974

grhkm21 opened this issue Dec 27, 2023 · 0 comments · Fixed by #36986
Labels

Comments

@grhkm21
Copy link
Contributor

grhkm21 commented Dec 27, 2023

Steps To Reproduce

sage: G, (g0, g1) = AbelianGroup(2, [48, 0]).objgens()
....: print(G, g0, g1)
....: assert g0.order() == 48 and g1.order() == oo
....: 
....: G0 = G.subgroup([g0])
....: print(G0, G0.gens(), G0.gens_orders())
....: print(len(G0.gens()) == len(G0.gens_orders()))
Multiplicative Abelian group isomorphic to C48 x Z f0 f1
Multiplicative Abelian subgroup isomorphic to C3 x C16 generated by {f0} (f0,) (3, 16)
False

Problem: The length of G0.gens() and G0.gens_orders() should be the same.

Additional Information

The Subgroup is computed here. The issue seems to be that the GAP functions AbelianInvariants doesn't actually return the orders of the generators in GeneratorsOfGroup, as demonstrated below:

sage: G, (g0, g1) = AbelianGroup(2, [48, 0]).objgens()
....: H = libgap(G).Subgroup(gens)
....: H_invs = H.AbelianInvariants().sage()
....: H_gens = H.GeneratorsOfGroup()
....: print(H, H_invs, H_gens)
Pcp-group with orders [ 48 ] [3, 16] [ g1 ]

The obvious fix would be to replace .AbelianInvariants on line 1710 with, well, [g.Order().sage() for g in H.GeneratorsOfGroup()] or something like that. If any GAP users have a better solution that returns the order of all (finite?) generators, please suggest it, since I haven't used GAP before.

@grhkm21 grhkm21 added the t: bug label Dec 27, 2023
vbraun pushed a commit to vbraun/sage that referenced this issue 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 issue 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 closed this as completed in 6b8deac Jan 22, 2024
vbraun pushed a commit to vbraun/sage that referenced this issue 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 issue 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
Labels
Projects
None yet
1 participant