From 3107864016177bfd639f03804ac8399704573e2e 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 Instead of multiple setter calls, set filters and attribute in one. To avoid deductions changing the type all the time. Includes that Empty should imply IsNonTrivial. Not really worth anything, but there are test files that check exactly this Documentation says that setter ignores second setting thus error message only if assertion level is high. Also fix reading order so assertion level is defined and make the required level >=3 so it does not occur when testing. Forgot that tests are run with assertion level 2, changed to 3. --- lib/coll.gd | 4 ++++ lib/coll.gi | 38 ++++++++++++++++++++++++++++++++------ lib/csetgrp.gi | 15 +++++++-------- lib/read1.g | 2 +- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/coll.gd b/lib/coll.gd index e9478878521..6c68678f35c 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 f7cdadee0c0..7ea55421444 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,31 @@ 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) +local filt; + if HasSize(obj) and Size(obj)<>sz then + if AssertionLevel()>2 then + # Make this an ordinary error to enter break loop so that one can + # investigate call order for debugging + Error("size of ",obj," already set to ",Size(obj), + ", cannot be changed to ",sz); + fi; + return; + fi; + if sz=0 then filt:=IsEmpty and IsNonTrivial; # IsNonTrivial hold + elif sz=1 then filt:=IsTrivial; + elif sz=infinity then filt:=IsNonTrivial and HasIsFinite; + else filt:=IsNonTrivial and IsFinite; + fi; + filt:=filt and HasSize; + obj!.Size:=sz; + SetFilterObj(obj,filt); +end); + ############################################################################# ## #E diff --git a/lib/csetgrp.gi b/lib/csetgrp.gi index 3cc43e252bb..ff71d63f0e7 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); diff --git a/lib/read1.g b/lib/read1.g index 831ca8981b2..50c115a9986 100644 --- a/lib/read1.g +++ b/lib/read1.g @@ -38,6 +38,7 @@ ReadLib( "record.gd" ); ReadLib( "random.gd" ); ReadLib( "cache.gi" ); +ReadLib( "assert.gd" ); ReadLib( "coll.gi" ); ReadLib( "flag.g" ); @@ -54,7 +55,6 @@ ReadLib( "filter.gi" ); ReadLib( "object.gi" ); ReadLib( "listcoef.gd" ); ReadLib( "info.gd" ); -ReadLib( "assert.gd" ); ReadLib( "files.gd" ); ReadLib( "streams.gd" );