Skip to content

Fix a mismatch between AbelianGroup class permutation_group method documentation and implementation #40267

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions src/sage/groups/abelian_gps/abelian_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,13 +1144,60 @@
Traceback (most recent call last):
...
TypeError: Abelian group must be finite
"""
# GAP does not support infinite permutation groups

Check that :issue:`39890` is fixed::

sage: G = AbelianGroup([6])
sage: H = G.permutation_group()
sage: tuple(gen.order() for gen in H.gens())
(6,)
sage: G = AbelianGroup([2, 5, 6, 4])
sage: H = G.permutation_group()
sage: tuple(gen.order() for gen in H.gens())
(2, 5, 6, 4)
sage: G = AbelianGroup([2, 5, 6, 1, 4])
sage: H = G.permutation_group()
sage: tuple(gen.order() for gen in H.gens())
(2, 5, 6, 1, 4)
sage: G = AbelianGroup([1])
sage: H = G.permutation_group()
sage: tuple(gen.order() for gen in H.gens())
(1,)
sage: G = AbelianGroup([2, 3, 2])
sage: H = G.permutation_group()
sage: tuple(gen.order() for gen in H.gens())
(2, 3, 2)
sage: G = AbelianGroup([2, 1, 1, 2])
sage: H = G.permutation_group()
sage: tuple(gen.order() for gen in H.gens())
(2, 1, 1, 2)
"""
# we do not support infinite permutation groups
if not self.is_finite():
raise TypeError('Abelian group must be finite')
from sage.groups.perm_gps.permgroup import PermutationGroup
s = 'Image(IsomorphismPermGroup(%s))' % self._gap_init_()
return PermutationGroup(gap_group=s)
gens = []
current_degree = 1
for order in self.gens_orders():
original_order = order
gen = []
p = 2
while p*p <= order:
ppow = 1
while order % p == 0:
ppow *= p
order //= p
if ppow > 1:
gen.append(tuple(range(current_degree, current_degree + ppow)))
current_degree += ppow
p += 1
if order > 1:
gen.append(tuple(range(current_degree, current_degree + order)))
current_degree += order
assert (original_order==1 and len(gen) == 0) or prod(len(cycle) for cycle in gen) == original_order

Check failure on line 1197 in src/sage/groups/abelian_gps/abelian_group.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E225)

src/sage/groups/abelian_gps/abelian_group.py:1197:35: E225 Missing whitespace around operator
gens.append(gen)

Check failure on line 1199 in src/sage/groups/abelian_gps/abelian_group.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (W293)

src/sage/groups/abelian_gps/abelian_group.py:1199:1: W293 Blank line contains whitespace
return PermutationGroup(gens=gens, domain=list(range(current_degree)), canonicalize=False)

def is_commutative(self):
"""
Expand Down
18 changes: 11 additions & 7 deletions src/sage/groups/abelian_gps/abelian_group_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
###########################################################################

from sage.groups.abelian_gps.element_base import AbelianGroupElementBase
from sage.misc.misc_c import prod


def is_AbelianGroupElement(x):
Expand Down Expand Up @@ -115,15 +116,18 @@ def as_permutation(self):
(1,2)
sage: ap in Gp # needs sage.groups sage.libs.gap
True
sage: (a * b).as_permutation() # needs sage.libs.gap
(1,2)(3,4,5)
sage: (a * b * a).as_permutation() # needs sage.libs.gap
(3,4,5)
sage: (a * b * a * b).as_permutation() # needs sage.libs.gap
(3,5,4)
sage: (a * b * c * a * b).as_permutation() # needs sage.libs.gap
(3,5,4)(6,7,8,9)
"""
from sage.libs.gap.libgap import libgap
G = self.parent()
A = libgap.AbelianGroup(G.gens_orders())
phi = libgap.IsomorphismPermGroup(A)
gens = libgap.GeneratorsOfGroup(A)
L2 = libgap.Product([geni**Li for geni, Li in zip(gens, self.list())])
pg = libgap.Image(phi, L2)
return G.permutation_group()(pg)
H = G.permutation_group()
return H(prod(gen**order for gen, order in zip(H.gens(), self.list())))

def word_problem(self, words):
"""
Expand Down
Loading