Skip to content

Commit

Permalink
Removed type caching again.
Browse files Browse the repository at this point in the history
  • Loading branch information
hulpke committed Apr 28, 2018
1 parent 0f114a4 commit 4ef8805
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 84 deletions.
45 changes: 8 additions & 37 deletions lib/grp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -4293,43 +4293,31 @@ InstallMethod( GroupWithGenerators,
"generic method for collection",
[ IsCollection ],
function( gens )
local G,fam,typ,id,typename;
local G,fam,typ,id;

fam:=FamilyObj(gens);

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

if IsFinite(gens) then
typ:=typ and IsFinitelyGeneratedGroup;
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 IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultNontrivialCyclicGroupType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupType";
fi;
else
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultTrivialGroupType";
fi;
elif Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultCyclicGroupType";
fi;
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 @@ -4341,43 +4329,31 @@ InstallMethod( GroupWithGenerators,
"generic method for collection and identity element",
IsCollsElms, [ IsCollection, IsMultiplicativeElementWithInverse ],
function( gens, id )
local G,fam,typ,typename;
local G,fam,typ;

fam:=FamilyObj(gens);

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

if IsFinite(gens) then
typ:=typ and IsFinitelyGeneratedGroup;
typename:="defaultFinitelyGeneratedGroupWithOneType";

if Length(gens)>0 and CanEasilyCompareElements(gens) then
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultNontrivialCyclicGroupWithOneType";
else
typename:="defaultNontrivialGroupWithOneType";
fi;
else
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultTrivialGroupWithOneType";
fi;
elif Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultCyclicGroupWithOneType";
fi;

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 @@ -4393,15 +4369,10 @@ local G,fam,typ;

fam:= CollectionsFamily( FamilyObj( id ) );

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!.defaultTrivialGroupWithOneType:=typ;
else
typ:=fam!.defaultTrivialGroupWithOneType;
fi;
typ:=IsGroup and IsAttributeStoringRep
and HasGeneratorsOfMagmaWithInverses and HasOne and IsTrivial and
HasIsEmpty and HasIsNonTrivial;
typ:=NewType(fam,typ);

G:= rec();
ObjectifyWithAttributes( G, typ,
Expand Down
49 changes: 12 additions & 37 deletions lib/grppc.gi
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ InstallMethod( GroupWithGenerators,
# override methods for `IsList' or `IsEmpty'.
10,
function( gens )
local G,fam,typ,id,pcgs,typename;
local G,fam,typ,id,pcgs;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));
Expand All @@ -357,28 +357,18 @@ local G,fam,typ,id,pcgs,typename;
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses
and IsFinite and IsFinitelyGeneratedGroup
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
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultNontrivialCyclicGroupType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupType";
fi;
else
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultTrivialGroupType";
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 @@ -396,7 +386,7 @@ InstallOtherMethod( GroupWithGenerators,
IsMultiplicativeElementWithInverseByPolycyclicCollector] ,
0,
function( gens, id )
local G,fam,typ,pcgs,typename;
local G,fam,typ,pcgs;

fam:=FamilyObj(gens);
pcgs:=DefiningPcgs(ElementsFamily(fam));
Expand All @@ -406,27 +396,17 @@ local G,fam,typ,pcgs,typename;
and HasIsEmpty and HasGeneratorsOfMagmaWithInverses and HasOne
and IsFinite and IsFinitelyGeneratedGroup
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typename:="defaultFinitelyGeneratedGroupWithOneType";

# we can always compare to id cheaply
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and IsNonTrivial;
if Length(gens)<=1 then
typ:=typ and IsCyclic;
typename:="defaultNontrivialCyclicGroupWithOneType";
else
typename:="defaultFinitelyGeneratedNontrivialGroupWithOneType";
fi;
else
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultTrivialGroupWithOneType";
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 @@ -449,19 +429,14 @@ local G,fam,typ,pcgs;

fam:= CollectionsFamily( FamilyObj( id ) );

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 IsSolvableGroup
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typ:=NewType(fam,typ);
fam!.defaultTrivialGroupWithOneType:=typ;
else
typ:=fam!.defaultTrivialGroupWithOneType;
fi;
# 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 IsSolvableGroup
and HasFamilyPcgs and HasHomePcgs and HasGeneralizedPcgs;
typ:=NewType(fam,typ);

pcgs:=DefiningPcgs(ElementsFamily(fam));

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

fam:=FamilyObj(gens);

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 @@ -673,19 +672,12 @@ local M,typ,id,typename,fam;
id:=One(gens[1]);
if ForAny(gens,x->x<>id) then
typ:=typ and HasIsTrivial and IsNonTrivial;
typename:="defaultNontrivialMagmaWithInversesByGeneratorsType";
else
typ:=typ and IsTrivial and HasIsNonTrivial;
typename:="defaultTrivialMagmaWithInversesByGeneratorsType";
fi;
fi;
fi;
if not IsBound(fam!.(typename)) then
typ:=NewType(fam,typ);
fam!.(typename):=typ;
else
typ:=fam!.(typename);
fi;
typ:=NewType(fam,typ);

M:=rec();

Expand Down

0 comments on commit 4ef8805

Please sign in to comment.