Skip to content

Commit

Permalink
Special setter for size, made IsTrivial<->IsNonTrivial a true method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hulpke committed May 1, 2018
1 parent 425e74d commit 3107864
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions lib/coll.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,10 @@ InstallFactorMaintenance( IsTrivial,
##
DeclareProperty( "IsNonTrivial", IsCollection );

# true methods to avoid immediate methods
InstallTrueMethod(HasIsTrivial,IsNonTrivial);
InstallTrueMethod(HasIsNonTrivial,IsTrivial);


#############################################################################
##
Expand Down
38 changes: 32 additions & 6 deletions lib/coll.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -120,17 +120,17 @@ InstallMethod( IsTrivial,
[ IsCollection ],
C -> Size( C ) = 1 );

InstallImmediateMethod( IsTrivial,
IsCollection and HasIsNonTrivial, 0,
InstallMethod( IsTrivial,
[IsCollection and HasIsNonTrivial], 0,
C -> not IsNonTrivial( C ) );


#############################################################################
##
#M IsNonTrivial( <C> ) . . . . . . . . . test if a collection is nontrivial
##
InstallImmediateMethod( IsNonTrivial,
IsCollection and HasIsTrivial, 0,
InstallMethod( IsNonTrivial,
[IsCollection and HasIsTrivial], 0,
C -> not IsTrivial( C ) );

InstallMethod( IsNonTrivial,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
15 changes: 7 additions & 8 deletions lib/csetgrp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/read1.g
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ReadLib( "record.gd" );
ReadLib( "random.gd" );

ReadLib( "cache.gi" );
ReadLib( "assert.gd" );
ReadLib( "coll.gi" );

ReadLib( "flag.g" );
Expand All @@ -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" );

Expand Down

0 comments on commit 3107864

Please sign in to comment.