Skip to content

Commit

Permalink
Avoid the triv variable and setting properties to false.
Browse files Browse the repository at this point in the history
  • Loading branch information
hulpke committed Apr 23, 2018
1 parent 4e38dfd commit b746779
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 58 deletions.
38 changes: 9 additions & 29 deletions lib/grp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -4301,12 +4301,10 @@ InstallMethod( GroupWithGenerators,
"generic method for collection",
[ IsCollection ],
function( gens )
local G,fam,typ,id,triv,typename;
local G,fam,typ,id,typename;

fam:=FamilyObj(gens);

triv:=fail; # might not find out

typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses;
typename:="defaultGroupType";
Expand All @@ -4318,17 +4316,15 @@ local G,fam,typ,id,triv,typename;
if Length(gens)>0 and CanEasilyCompareElements(gens) then
id:=One(gens[1]);
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=false;
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupType";
fi;
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultFinitelyGeneratedTrivialGroupType";
fi;
elif Length(gens)<=1 then
Expand All @@ -4344,14 +4340,7 @@ local G,fam,typ,id,triv,typename;
fi;

G:=rec();
if triv=fail then
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false);
else
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false,IsTrivial,triv,
IsNonTrivial,not triv);
fi;
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens));

return G;
end );
Expand All @@ -4360,10 +4349,9 @@ InstallMethod( GroupWithGenerators,
"generic method for collection and identity element",
IsCollsElms, [ IsCollection, IsMultiplicativeElementWithInverse ],
function( gens, id )
local G,fam,typ,triv,typename;
local G,fam,typ,typename;

fam:=FamilyObj(gens);
triv:=fail; # might not find out

typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses and HasOne;
Expand All @@ -4375,17 +4363,15 @@ local G,fam,typ,triv,typename;

if Length(gens)>0 and CanEasilyCompareElements(gens) then
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=false;
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupWithOneType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupWithOneType";
fi;
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultFinitelyGeneratedTrivialGroupWithOneType";
fi;
elif Length(gens)<=1 then
Expand All @@ -4402,14 +4388,8 @@ local G,fam,typ,triv,typename;
fi;

G:=rec();
if triv=fail then
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false,One,id);
else
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false,One,id,
IsTrivial,triv,IsNonTrivial,not triv);
fi;
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
One,id);

return G;
end );
Expand Down
20 changes: 7 additions & 13 deletions lib/grppc.gi
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ InstallMethod( GroupWithGenerators,
# override methods for `IsList' or `IsEmpty'.
10,
function( gens )
local G,fam,typ,id,triv,pcgs,typename;
local G,fam,typ,id,pcgs,typename;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));
Expand All @@ -355,22 +355,21 @@ local G,fam,typ,id,triv,pcgs,typename;
typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses
and IsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsNonTrivial
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typename:="defaultFinitelyGeneratedGroupType";

# we can always compare to id cheaply
id:=One(gens[1]);
if ForAny(gens,x->x<>id) then
triv:=false;
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupType";
fi;
else
triv:=true;
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultFinitelyGeneratedTrivialGroupType";
fi;
if not IsBound(fam!.(typename)) then
Expand All @@ -382,8 +381,6 @@ local G,fam,typ,id,triv,pcgs,typename;

G:=rec();
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false,IsTrivial,triv,
IsNonTrivial,not triv,
FamilyPcgs,pcgs,HomePcgs,pcgs,GeneralizedPcgs,pcgs);
SetGroupOfPcgs (pcgs, G);

Expand All @@ -398,7 +395,7 @@ InstallOtherMethod( GroupWithGenerators,
IsMultiplicativeElementWithInverseByPolycyclicCollector] ,
0,
function( gens, id )
local G,fam,typ,triv,pcgs,typename;
local G,fam,typ,pcgs,typename;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));
Expand All @@ -407,21 +404,20 @@ local G,fam,typ,triv,pcgs,typename;
typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses and HasOne
and IsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsNonTrivial
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typename:="defaultFinitelyGeneratedGroupWithOneType";

# we can always compare to id cheaply
if ForAny(gens,x->x<>id) then
triv:=false;
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupWithOneType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupWithOneType";
fi;
else
triv:=true;
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultFinitelyGeneratedTrivialGroupWithOneType";
fi;
if not IsBound(fam!.(typename)) then
Expand All @@ -433,8 +429,7 @@ local G,fam,typ,triv,pcgs,typename;

G:=rec();
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false,One,id,
IsTrivial,triv,IsNonTrivial,not triv,
One,id,
FamilyPcgs,pcgs,HomePcgs,pcgs,GeneralizedPcgs,pcgs);

SetGroupOfPcgs (pcgs, G);
Expand Down Expand Up @@ -473,7 +468,6 @@ local G,fam,typ,pcgs;
ObjectifyWithAttributes( G, typ,
GeneratorsOfMagmaWithInverses, empty,
One, id,
IsEmpty,false, IsNonTrivial,false,
FamilyPcgs,pcgs,HomePcgs,pcgs,GeneralizedPcgs,pcgs);

SetGroupOfPcgs (pcgs, G);
Expand Down
23 changes: 7 additions & 16 deletions lib/magma.gi
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,9 @@ InstallOtherMethod( MagmaWithOneByGenerators,
#M MagmaWithInversesByGenerators( <gens> ) . . . . . . . . for a collection
##
MakeMagmaWithInversesByFiniteGenerators:=function(family,gens)
local M,triv,typ,id,typename,fam;
local M,typ,id,typename,fam;

fam:=FamilyObj(gens);
triv:=fail; # might not find out

typ:=IsMagmaWithInverses and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses
Expand All @@ -673,12 +672,10 @@ local M,triv,typ,id,typename,fam;
if Length(gens)>0 and CanEasilyCompareElements(gens) then
id:=One(gens[1]);
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=false;
typ:=typ and HasIsTrivial and IsNonTrivial;
typename:="defaultNontrivialMagmaWithInversesByGeneratorsType";
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultTrivialMagmaWithInversesByGeneratorsType";
fi;
fi;
Expand All @@ -691,16 +688,10 @@ local M,triv,typ,id,typename,fam;
fi;

M:=rec();
if triv=fail then
ObjectifyWithAttributes( M,typ,
GeneratorsOfMagmaWithInverses, AsList( gens ),
IsEmpty,false);
else
ObjectifyWithAttributes( M,typ,
GeneratorsOfMagmaWithInverses, AsList( gens ),
IsEmpty,false,IsTrivial,triv,
IsNonTrivial,not triv);
fi;

ObjectifyWithAttributes( M,typ,
GeneratorsOfMagmaWithInverses, AsList( gens ));

if HasIsAssociative( M ) and IsAssociative( M ) then
SetIsFinitelyGeneratedGroup( M, true );
fi;
Expand Down

0 comments on commit b746779

Please sign in to comment.