Skip to content

Commit

Permalink
Make the commented-out imediate methods ordinary methods. Incorporate
Browse files Browse the repository at this point in the history
corrections suggested on github.
  • Loading branch information
hulpke committed Apr 23, 2018
1 parent f880835 commit 7aec02d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 76 deletions.
23 changes: 12 additions & 11 deletions lib/coll.gi
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@ InstallMethod( IsWholeFamily,
##
#M Size( <C> ) . . . . . . . . . . . . . . . . . . . . size of a collection
##
# This method get called for every group that knows it is finite but does
# not know its size -- e.g. permutation, pc
# the benefit OTOH is minimal beyond showing off a feature.
#InstallImmediateMethod( Size,
# IsCollection and HasIsFinite and IsAttributeStoringRep, 0,
# function ( C )
# if IsFinite( C ) then
# TryNextMethod();
# fi;
# return infinity;
# end );
# replace immediate method by ordinary, as immediate gets called for every
# group that knows it is finite but does not know its size -- e.g.
# permutation, pc. The benefit of this is minimal beyond showing off a
# feature.
InstallMethod( Size,
IsCollection and HasIsFinite, 0,
function ( C )
if IsFinite( C ) then
TryNextMethod();
fi;
return infinity;
end );

InstallImmediateMethod( Size,
IsCollection and HasAsList and IsAttributeStoringRep, 0,
Expand Down
52 changes: 24 additions & 28 deletions lib/grp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,29 @@ InstallImmediateMethod( IsFinitelyGeneratedGroup,
##
#M IsCyclic( <G> ) . . . . . . . . . . . . . . . . test if a group is cyclic
##
# this is now set when creating the groups
#InstallImmediateMethod( IsCyclic, IsGroup and HasGeneratorsOfGroup, 0,
# function( G )
# if Length( GeneratorsOfGroup( G ) ) = 1 then
# return true;
# else
# TryNextMethod();
# fi;
# end );
# this is now set when creating the groups, make ordinary instead of
# immediate
InstallMethod( IsCyclic, IsGroup and HasGeneratorsOfGroup, 0,
function( G )
if Length( GeneratorsOfGroup( G ) ) = 1 then
return true;
else
TryNextMethod();
fi;
end );

InstallMethod( IsCyclic,
"generic method for groups",
[ IsGroup ],
function ( G )
local a;

# if <G> has a generator list of length 1 then <G> is cyclic
if HasGeneratorsOfGroup( G ) and Length( GeneratorsOfGroup(G) ) = 1 then
SetMinimalGeneratingSet(G,GeneratorsOfGroup(G));
a:=GeneratorsOfGroup(G)[1];
if CanEasilyCompareElements(a) and not IsOne(a) then
SetMinimalGeneratingSet(G,GeneratorsOfGroup(G));
fi;
return true;

# if <G> is not commutative it is certainly not cyclic
Expand Down Expand Up @@ -434,12 +439,13 @@ InstallMethod( IsNilpotentGroup,
##
#M IsPerfectGroup( <G> ) . . . . . . . . . . . . test if a group is perfect
##

# This is now set when the group is created
# Replace by TrueMethod (though this will not make nontrivial solvable
# groups not perfect
#InstallImmediateMethod( IsPerfectGroup,
# IsSolvableGroup and HasIsTrivial,
# 0,
# IsTrivial );
InstallTrueMethod( IsPerfectGroup, IsGroup and IsTrivial );

InstallImmediateMethod( IsPerfectGroup,
IsGroup and HasIsAbelian and IsSimpleGroup,
Expand Down Expand Up @@ -4306,8 +4312,7 @@ local G,fam,typ,id,triv;
if IsFinite(gens) then
typ:=typ and IsFinitelyGeneratedGroup;
if Length(gens)<=1 then
typ:=typ and HasIsCyclic and IsCyclic
and HasIsCommutative and IsCommutative;
typ:=typ and IsCyclic;
fi;

if Length(gens)>0 and CanEasilyCompareElements(gens) then
Expand All @@ -4318,8 +4323,6 @@ local G,fam,typ,id,triv;
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
# basic consequence
typ:=typ and HasIsPerfectGroup and IsPerfectGroup;
fi;
fi;

Expand Down Expand Up @@ -4353,8 +4356,7 @@ local G,fam,typ,triv;
if IsFinite(gens) then
typ:=typ and IsFinitelyGeneratedGroup;
if Length(gens)<=1 then
typ:=typ and HasIsCyclic and IsCyclic
and HasIsCommutative and IsCommutative;
typ:=typ and HasIsCyclic and IsCyclic;
fi;

if Length(gens)>0 and CanEasilyCompareElements(gens) then
Expand All @@ -4364,8 +4366,6 @@ local G,fam,typ,triv;
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
# basic consequence
typ:=typ and HasIsPerfectGroup and IsPerfectGroup;
fi;
fi;

Expand Down Expand Up @@ -4393,19 +4393,15 @@ local G,fam,typ;
fam:= CollectionsFamily( FamilyObj( id ) );

typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne
and IsFinitelyGeneratedGroup and HasIsTrivial and HasIsNonTrivial
and HasIsFinite and HasIsCyclic
and HasIsPerfectGroup and HasIsEmpty;
and HasGeneratorsOfMagmaWithInverses and HasOne and IsTrivial and
HasIsEmpty and HasIsNonTrivial;
typ:=NewType(fam,typ);

G:= rec();
ObjectifyWithAttributes( G, typ,
GeneratorsOfMagmaWithInverses, empty,
One, id,IsEmpty,false,
IsTrivial,true,IsNonTrivial,false,
IsFinite,true,IsCyclic,true,
IsPerfectGroup,true);
IsEmpty,false, IsNonTrivial,false,
One, id );

return G;
end );
Expand Down
34 changes: 12 additions & 22 deletions lib/grppc.gi
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ InstallMethod( Pcgs,
##
#M GeneralizedPcgs( <G> )
##
# is now set when creating
#InstallImmediateMethod( GeneralizedPcgs, IsGroup and HasPcgs, 0, Pcgs );
# is now set when creating, no need for immediate method
InstallMethod( GeneralizedPcgs, IsGroup and HasPcgs, 0, Pcgs );

#############################################################################
##
Expand Down Expand Up @@ -353,13 +353,12 @@ local G,fam,typ,id,triv,pcgs;
# pc groups are always finite and gens is finite.
typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses
and HasIsFinite and IsFinitelyGeneratedGroup
and IsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsNonTrivial
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;

if Length(gens)<=1 then
typ:=typ and HasIsCyclic and IsCyclic
and HasIsCommutative and IsCommutative;
typ:=typ and IsCyclic;
fi;

# we can always compare to id cheaply
Expand All @@ -368,8 +367,6 @@ local G,fam,typ,id,triv,pcgs;
triv:=false;
else
triv:=true;
# basic consequence to kill an immediate method
typ:=typ and HasIsPerfectGroup and IsPerfectGroup;
fi;

typ:=NewType(fam,typ);
Expand All @@ -378,7 +375,6 @@ local G,fam,typ,id,triv,pcgs;
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
IsEmpty,false,IsTrivial,triv,
IsNonTrivial,not triv,
IsFinite,true,
FamilyPcgs,pcgs,HomePcgs,pcgs,GeneralizedPcgs,pcgs);
SetGroupOfPcgs (pcgs, G);

Expand All @@ -396,36 +392,32 @@ function( gens, id )
local G,fam,typ,triv,pcgs;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));

# pc groups are always finite and gens is finite.
typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses and HasOne
and HasIsFinite and IsFinitelyGeneratedGroup
and IsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsNonTrivial
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;

if Length(gens)<=1 then
typ:=typ and HasIsCyclic and IsCyclic
and HasIsCommutative and IsCommutative;
typ:=typ and IsCyclic;
fi;

# we can always compare to id cheaply
if ForAny(gens,x->x<>id) then
triv:=false;
else
triv:=true;
# basic consequence to kill an immediate method
typ:=typ and IsPerfectGroup;
fi;

typ:=NewType(fam,typ);
pcgs:=DefiningPcgs(ElementsFamily(fam));

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

SetGroupOfPcgs (pcgs, G);
Expand All @@ -447,20 +439,18 @@ local G,fam,typ,pcgs;
# pc groups are always finite and gens is finite.
typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne
and HasIsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsCyclic and HasIsCommutative
and IsPerfectGroup and HasIsEmpty
and IsFinite and IsFinitelyGeneratedGroup
and IsTrivial and HasIsNonTrivial
and HasIsEmpty
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typ:=NewType(fam,typ);
pcgs:=DefiningPcgs(ElementsFamily(fam));

G:= rec();
ObjectifyWithAttributes( G, typ,
GeneratorsOfMagmaWithInverses, empty,
One, id,IsEmpty,false,
IsTrivial,true,IsNonTrivial,false,
IsFinite,true,
IsCyclic,true,IsCommutative,true,IsPerfectGroup,true,
One, id,
IsEmpty,false, IsNonTrivial,false,
FamilyPcgs,pcgs,HomePcgs,pcgs,GeneralizedPcgs,pcgs);

SetGroupOfPcgs (pcgs, G);
Expand Down
30 changes: 15 additions & 15 deletions lib/magma.gi
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,18 @@ InstallImmediateMethod( IsCommutative,
fi;
end );

# this is now set when creating groups
#InstallImmediateMethod( IsCommutative,
# IsMagmaWithInverses and IsAssociative
# and HasGeneratorsOfMagmaWithInverses, 0,
# function( M )
# if Length( GeneratorsOfMagmaWithInverses( M ) ) = 1 then
# return true;
# else
# TryNextMethod();
# fi;
# end );
# this is now set for groups when creating groups, make ordinary, not
# immediate method
InstallMethod( IsCommutative,
IsMagmaWithInverses and IsAssociative
and HasGeneratorsOfMagmaWithInverses, 0,
function( M )
if Length( GeneratorsOfMagmaWithInverses( M ) ) = 1 then
return true;
else
TryNextMethod();
fi;
end );

InstallMethod( IsCommutative,
"for a magma",
Expand Down Expand Up @@ -662,10 +663,9 @@ local M,triv,typ,id;

if IsFinite(gens) then
# typ:=typ and IsFinitelyGeneratedGroup; don't know whether group
if Length(gens)<=1 then
typ:=typ and HasIsCyclic and IsCyclic
and HasIsCommutative and IsCommutative;
fi;

# not true for magmas, just for groups
#if Length(gens)<=1 then typ:=typ and IsCyclic; fi;

if Length(gens)>0 and CanEasilyCompareElements(gens) then
id:=One(gens[1]);
Expand Down

0 comments on commit 7aec02d

Please sign in to comment.