Skip to content

Commit

Permalink
Re-added caching types.
Browse files Browse the repository at this point in the history
  • Loading branch information
hulpke committed Apr 23, 2018
1 parent 27327a4 commit 093d077
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 39 deletions.
64 changes: 49 additions & 15 deletions lib/grp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -4301,33 +4301,47 @@ InstallMethod( GroupWithGenerators,
"generic method for collection",
[ IsCollection ],
function( gens )
local G,fam,typ,id,triv;
local G,fam,typ,id,triv,typename;

fam:=FamilyObj(gens);

triv:=fail; # might not find out

typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses;
typename:="defaultGroupType";

if IsFinite(gens) then
typ:=typ and IsFinitelyGeneratedGroup;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
fi;
typename:="defaultFinitelyGeneratedGroupType";

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;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupType";
fi;
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
typename:="defaultFinitelyGeneratedTrivialGroupType";
fi;
elif Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedCyclicGroupType";
fi;

fi;
typ:=NewType(fam,typ);
if not IsBound(fam!.(typename)) then
typ:=NewType(fam,typ);
fam!.(typename):=typ;
else
typ:=fam!.(typename);
fi;

G:=rec();
if triv=fail then
Expand All @@ -4346,31 +4360,46 @@ InstallMethod( GroupWithGenerators,
"generic method for collection and identity element",
IsCollsElms, [ IsCollection, IsMultiplicativeElementWithInverse ],
function( gens, id )
local G,fam,typ,triv;
local G,fam,typ,triv,typename;

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

typ:=IsGroup and IsAttributeStoringRep
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses and HasOne;
typename:="defaultGroupWithOneType";

if IsFinite(gens) then
typ:=typ and IsFinitelyGeneratedGroup;
if Length(gens)<=1 then
typ:=typ and HasIsCyclic and IsCyclic;
fi;
typename:="defaultFinitelyGeneratedGroupWithOneType";

if Length(gens)>0 and CanEasilyCompareElements(gens) then
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=false;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupWithOneType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupWithOneType";
fi;
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
typename:="defaultFinitelyGeneratedTrivialGroupWithOneType";
fi;
elif Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedCyclicGroupWithOneType";
fi;

fi;
typ:=NewType(fam,typ);
if not IsBound(fam!.(typename)) then
typ:=NewType(fam,typ);
fam!.(typename):=typ;
else
typ:=fam!.(typename);
fi;

G:=rec();
if triv=fail then
Expand All @@ -4392,10 +4421,15 @@ local G,fam,typ;

fam:= CollectionsFamily( FamilyObj( id ) );

typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne and IsTrivial and
HasIsEmpty and HasIsNonTrivial;
typ:=NewType(fam,typ);
if not IsBound(fam!.defaultFinitelyGeneratedTrivialGroupWithOneType) then
typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne and IsTrivial and
HasIsEmpty and HasIsNonTrivial;
typ:=NewType(fam,typ);
fam!.defaultFinitelyGeneratedTrivialGroupWithOneType:=typ;
else
typ:=fam!.defaultFinitelyGeneratedTrivialGroupWithOneType;
fi;

G:= rec();
ObjectifyWithAttributes( G, typ,
Expand Down
67 changes: 45 additions & 22 deletions lib/grppc.gi
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ InstallMethod( Pcgs,
# is now set when creating, no need for immediate method
InstallMethod( GeneralizedPcgs,true,[ IsGroup and HasPcgs], 0, Pcgs );


#############################################################################
##
#M HomePcgs( <G> )
Expand Down Expand Up @@ -345,7 +346,7 @@ InstallMethod( GroupWithGenerators,
# override methods for `IsList' or `IsEmpty'.
10,
function( gens )
local G,fam,typ,id,triv,pcgs;
local G,fam,typ,id,triv,pcgs,typename;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));
Expand All @@ -356,20 +357,28 @@ local G,fam,typ,id,triv,pcgs;
and IsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsNonTrivial
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;

if Length(gens)<=1 then
typ:=typ and IsCyclic;
fi;
typename:="defaultFinitelyGeneratedGroupType";

# we can always compare to id cheaply
id:=One(gens[1]);
if ForAny(gens,x->x<>id) then
triv:=false;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupType";
fi;
else
triv:=true;
typename:="defaultFinitelyGeneratedTrivialGroupType";
fi;
if not IsBound(fam!.(typename)) then
typ:=NewType(fam,typ);
fam!.(typename):=typ;
else
typ:=fam!.(typename);
fi;

typ:=NewType(fam,typ);

G:=rec();
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
Expand All @@ -389,7 +398,7 @@ InstallOtherMethod( GroupWithGenerators,
IsMultiplicativeElementWithInverseByPolycyclicCollector] ,
0,
function( gens, id )
local G,fam,typ,triv,pcgs;
local G,fam,typ,triv,pcgs,typename;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));
Expand All @@ -400,19 +409,27 @@ local G,fam,typ,triv,pcgs;
and IsFinite and IsFinitelyGeneratedGroup
and HasIsTrivial and HasIsNonTrivial
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;

if Length(gens)<=1 then
typ:=typ and IsCyclic;
fi;
typename:="defaultFinitelyGeneratedGroupWithOneType";

# we can always compare to id cheaply
if ForAny(gens,x->x<>id) then
triv:=false;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultFinitelyGeneratedNontrivialCyclicGroupWithOneType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupWithOneType";
fi;
else
triv:=true;
typename:="defaultFinitelyGeneratedTrivialGroupWithOneType";
fi;
if not IsBound(fam!.(typename)) then
typ:=NewType(fam,typ);
fam!.(typename):=typ;
else
typ:=fam!.(typename);
fi;

typ:=NewType(fam,typ);

G:=rec();
ObjectifyWithAttributes(G,typ,GeneratorsOfMagmaWithInverses,AsList(gens),
Expand All @@ -436,14 +453,20 @@ local G,fam,typ,pcgs;

fam:= CollectionsFamily( FamilyObj( id ) );

# pc groups are always finite and gens is finite.
typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne
and IsFinite and IsFinitelyGeneratedGroup
and IsTrivial and HasIsNonTrivial
and HasIsEmpty
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typ:=NewType(fam,typ);
if not IsBound(fam!.defaultFinitelyGeneratedTrivialGroupWithOneType) then
# pc groups are always finite and gens is finite.
typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne
and IsFinite and IsFinitelyGeneratedGroup
and IsTrivial and HasIsNonTrivial
and HasIsEmpty
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typ:=NewType(fam,typ);
fam!.defaultFinitelyGeneratedTrivialGroupWithOneType:=typ;
else
typ:=fam!.defaultFinitelyGeneratedTrivialGroupWithOneType;
fi;

pcgs:=DefiningPcgs(ElementsFamily(fam));

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

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

typ:=IsMagmaWithInverses and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses
and HasIsEmpty;
typename:="defaultMagmaWithInversesByGeneratorsType";

if IsFinite(gens) then
# typ:=typ and IsFinitelyGeneratedGroup; don't know whether group
Expand All @@ -672,13 +675,20 @@ local M,triv,typ,id;
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=false;
typename:="defaultNontrivialMagmaWithInversesByGeneratorsType";
else
typ:=typ and HasIsTrivial and HasIsNonTrivial;
triv:=true;
typename:="defaultTrivialMagmaWithInversesByGeneratorsType";
fi;
fi;
fi;
typ:=NewType( FamilyObj( gens ),typ);
if not IsBound(fam!.(typename)) then
typ:=NewType(fam,typ);
fam!.(typename):=typ;
else
typ:=fam!.(typename);
fi;

M:=rec();
if triv=fail then
Expand Down

0 comments on commit 093d077

Please sign in to comment.