From ed5c90a4f62932f307aa934ad7391980d9f3400f Mon Sep 17 00:00:00 2001 From: Alexander Hulpke Date: Tue, 24 Apr 2018 13:36:43 -0600 Subject: [PATCH] Special setter for size, made IsTrivial<->IsNonTrivial a true method and changed the corresponding immediate methods to ordinary ones. Impact on csetgrp b/c ObjectifyWithAttr for Size --- lib/coll.gd | 4 ++++ lib/coll.gi | 25 +++++++++++++++++++------ lib/csetgrp.gi | 15 +++++++-------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/coll.gd b/lib/coll.gd index e947887852..6c68678f35 100644 --- a/lib/coll.gd +++ b/lib/coll.gd @@ -1371,6 +1371,10 @@ InstallFactorMaintenance( IsTrivial, ## DeclareProperty( "IsNonTrivial", IsCollection ); +# true methods to avoid immediate methods +InstallTrueMethod(HasIsTrivial,IsNonTrivial); +InstallTrueMethod(HasIsNonTrivial,IsTrivial); + ############################################################################# ## diff --git a/lib/coll.gi b/lib/coll.gi index f7cdadee0c..46c0a6fbec 100644 --- a/lib/coll.gi +++ b/lib/coll.gi @@ -94,7 +94,7 @@ InstallMethod( PrintObj, ## InstallImmediateMethod( IsEmpty, IsCollection and HasSize, 0, - C -> Size( C ) = 0 ); + C->Size( C ) = 0); InstallMethod( IsEmpty, "for a collection", @@ -120,8 +120,8 @@ InstallMethod( IsTrivial, [ IsCollection ], C -> Size( C ) = 1 ); -InstallImmediateMethod( IsTrivial, - IsCollection and HasIsNonTrivial, 0, +InstallMethod( IsTrivial, + [IsCollection and HasIsNonTrivial], 0, C -> not IsNonTrivial( C ) ); @@ -129,8 +129,8 @@ InstallImmediateMethod( IsTrivial, ## #M IsNonTrivial( ) . . . . . . . . . test if a collection is nontrivial ## -InstallImmediateMethod( IsNonTrivial, - IsCollection and HasIsTrivial, 0, +InstallMethod( IsNonTrivial, + [IsCollection and HasIsTrivial], 0, C -> not IsTrivial( C ) ); InstallMethod( IsNonTrivial, @@ -173,7 +173,8 @@ InstallMethod( IsWholeFamily, # method, as the immediate method would get 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,true, [IsCollection and HasIsFinite], 0, +InstallMethod( Size,true, [IsCollection and HasIsFinite], + 100, # rank above object-specific methods function ( C ) if IsFinite( C ) then TryNextMethod(); @@ -3052,6 +3053,18 @@ end); InstallMethod( CanComputeIsSubset,"default: no, unless identical", [IsObject,IsObject],IsIdenticalObj); +# avoid immediate methods triggering multiple type changes once the Size of +# an object is known. +InstallOtherMethod(SetSize,true,[IsObject and IsAttributeStoringRep,IsObject], + 100, # override system setter +function(obj,sz) + SetIsEmpty(obj,sz=0); + SetIsTrivial(obj,sz=1); + SetIsNonTrivial(obj,sz<>1); + SetIsFinite(obj,sz<>infinity); + TryNextMethod(); # to enforce size setting +end); + ############################################################################# ## #E diff --git a/lib/csetgrp.gi b/lib/csetgrp.gi index 3cc43e252b..ff71d63f0e 100644 --- a/lib/csetgrp.gi +++ b/lib/csetgrp.gi @@ -573,21 +573,20 @@ end); InstallMethod(RightCoset,"use subgroup size",IsCollsElms, [IsGroup and HasSize,IsObject],0, function(U,g) -local d,fam; +local d,fam,typ; # noch tests... fam:=FamilyObj(U); - if not IsBound(fam!.rightCosetsDefaultSizeType) then - fam!.rightCosetsDefaultSizeType:=NewType(fam,IsRightCosetDefaultRep and - HasActingDomain and HasFunctionAction and HasRepresentative and - HasSize and HasCanonicalRepresentativeDeterminatorOfExternalSet); - fi; + typ:=NewType(fam,IsRightCosetDefaultRep and + HasActingDomain and HasFunctionAction and HasRepresentative + and HasCanonicalRepresentativeDeterminatorOfExternalSet); d:=rec(); - ObjectifyWithAttributes(d,fam!.rightCosetsDefaultSizeType, + ObjectifyWithAttributes(d,typ, ActingDomain,U,FunctionAction,OnLeftInverse,Representative,g, - Size,Size(U),CanonicalRepresentativeDeterminatorOfExternalSet, + CanonicalRepresentativeDeterminatorOfExternalSet, RightCosetCanonicalRepresentativeDeterminator); + SetSize(d,Size(U)); # as own setter return d; end);