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

Fix AbelianGroup to (better) handle empty order lists, and generators of order 1 #5432

Merged
merged 1 commit into from
Apr 5, 2023
Merged
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
2 changes: 1 addition & 1 deletion grp/basicfp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ InstallMethod( AbelianGroupCons, "fp group", true,
function( filter, ints )
local f,g,i,j,rels,gfam,fam;

if Length(ints)=0 or not ForAll( ints, x -> IsInfinity(x) or (IsInt(x) and x >= 0) ) then
if not ForAll( ints, x -> IsInfinity(x) or (IsInt(x) and x >= 0) ) then
Error( "<ints> must be a list of integers" );
Copy link
Member

Choose a reason for hiding this comment

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

Off-topic (not a change request, but perhaps we can some day address it): I guess strictly speaking this error is not accurate (as we allow infinity these days).

fi;

Expand Down
7 changes: 6 additions & 1 deletion grp/basicpcg.gi
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ local pis, f, g, r, k, pi, i, geni, j, name, ps;
fi;
if ForAll(ints,i->i=1) then
# the stupid trivial group case
return CyclicGroup( IsPcGroup, 1 );
g:= CyclicGroup( IsPcGroup, 1 );
if Length( ints ) > 0 then
g:= GroupWithGenerators(
ListWithIdenticalEntries( Length( ints ), One( g ) ) );
fi;
return g;
fi;

pis := List( ints, Factors );
Expand Down
6 changes: 5 additions & 1 deletion grp/basicprm.gi
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ InstallMethod( AbelianGroupCons,
function( filter, ints )
local grp, grps;

if IsEmpty( ints ) then
# Create a group with empty list of generators
return GroupWithGenerators( [], () );
fi;
if not ForAll( ints, IsInt ) then
Error( "<ints> must be a list of integers" );
fi;
Expand All @@ -48,7 +52,7 @@ function( filter, ints )

grps := List( ints, x -> CyclicGroupCons( IsPermGroup, x ) );
# the way a direct product is constructed guarantees the right
# generators
# generators (also generators of order 1)
grp := CallFuncList( DirectProduct, grps );
SetSize( grp, Product(ints) );
SetIsAbelian( grp, true );
Expand Down
11 changes: 11 additions & 0 deletions tst/testinstall/grp/basic.tst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ f1
gap> A.2^-1;
f2^2

#
gap> inputs:= [ [], [ 1 ], [ 2, 3, 4 ], [ 1, 2, 1, 3, 1 ] ];;
gap> for ints in inputs do
> for filt in [ IsPcGroup, IsPermGroup, IsFpGroup ] do
> G:= AbelianGroup( ints );
> if List( GeneratorsOfGroup( G ), Order ) <> ints then
> Error( "orders of the generators do not fit" );
> fi;
> od;
> od;

#
gap> AbelianGroup([2,0]);
<fp group of size infinity on the generators [ f1, f2 ]>
Expand Down