Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/alglie.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,8 @@ InstallMethod( NormalizedElementOfMagmaRingModuloRelations,
Append( tlist, todo[i] );
od;

return ObjByExtRep( Fam, [ zero, tlist ] );
tlist := ObjByExtRep( Fam, [ zero, tlist ] );
return [ zero, tlist![2] ];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see, this change is a bugfix.
(And NormalizedElementOfMagmaRingModuloRelations is a misleading name.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I had made a note what the error was / why this change is the correct fix sigh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NormalizedElementOfMagmaRingModuloRelations is called in the GAP library only in lib/mgmring.gi. In all cases, Objectify is called immediately afterwards with the result. For the old code, this means that the object had already the desired type before the Objectify call, and gets objectified again with the same type.

In this sense, I think the library code does not produce wrong results. Nevertheless, the old code contradicts the definition of NormalizedElementOfMagmaRingModuloRelations. And there may be code outside lib/mgmring.gi which wants to use NormalizedElementOfMagmaRingModuloRelations. If the package tests do not show an example where the proposed change yields a different result then we should just apply the proposed fix and add a test, perhaps even as a manual example.

gap> R:= GroupRing( Rationals, SymmetricGroup( 3 ) );;
gap> Fam:= FamilyObj( Zero( R ) );;
gap> x:= Sum( GeneratorsOfAlgebra( R ) );;
gap> descr:= [ 0, CoefficientsAndMagmaElements( x ) ];;
gap> NormalizedElementOfMagmaRingModuloRelations( Fam, descr ) = descr;
true
gap> R:= FreeLieAlgebra( Rationals, 2 );;
gap> Fam:= FamilyObj( Zero( R ) );;
gap> x:= Sum( GeneratorsOfAlgebra( R ) );;
gap> descr:= [ 0, CoefficientsAndMagmaElements( x ) ];;
gap> NormalizedElementOfMagmaRingModuloRelations( Fam, descr ) = descr;
true

(The first true comes from a correct NormalizedElementOfMagmaRingModuloRelations method, the second true will occur only after the fix.)


end );

Expand Down
29 changes: 18 additions & 11 deletions lib/type1.g
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,6 @@ BIND_GLOBAL( "FlagsObj", obj -> FlagsType( TypeObj( obj ) ) );
BIND_GLOBAL( "DataObj", obj -> DataType( TypeObj( obj ) ) );


BIND_GLOBAL( "IsNonAtomicComponentObjectRepFlags",
FLAGS_FILTER(IsNonAtomicComponentObjectRep));
BIND_GLOBAL( "IsAtomicPositionalObjectRepFlags",
FLAGS_FILTER(IsAtomicPositionalObjectRep));
BIND_GLOBAL( "IsReadOnlyPositionalObjectRepFlags",
FLAGS_FILTER(IsReadOnlyPositionalObjectRep));

#############################################################################
##
#F Objectify( <type>, <obj> )
Expand All @@ -592,26 +585,40 @@ BIND_GLOBAL( "Objectify", function ( type, obj )
if not IsType( type ) then
Error("<type> must be a type");
fi;
flags := FlagsType(type);
if IsHPCGAP then
flags := FlagsType(type);
if IS_LIST( obj ) then
if IS_SUBSET_FLAGS(flags, IsAtomicPositionalObjectRepFlags) then
if IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsAtomicPositionalObjectRep)) then
FORCE_SWITCH_OBJ( obj, FixedAtomicList(obj) );
fi;
elif IS_REC( obj ) then
if IS_ATOMIC_RECORD(obj) then
if IS_SUBSET_FLAGS(flags, IsNonAtomicComponentObjectRepFlags) then
if IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsNonAtomicComponentObjectRep)) then
FORCE_SWITCH_OBJ( obj, FromAtomicRecord(obj) );
fi;
elif not IS_SUBSET_FLAGS(flags, IsNonAtomicComponentObjectRepFlags) then
elif not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsNonAtomicComponentObjectRep)) then
FORCE_SWITCH_OBJ( obj, AtomicRecord(obj) );
fi;
fi;
fi;
if IS_LIST( obj ) then
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Comment on lines +605 to +606

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe disable this by default, but have it enabled e.g. in most test suites (as long as the use START_TEST)?

Suggested change
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
#Assert(1, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Assert(1, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));

if not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)) then
INFO_DEBUG(1, "Objectify: type does not imply IsPositionalObjectRep ",
INPUT_FILENAME(), ":", STRING_INT(INPUT_LINENUMBER()));
fi;
SET_TYPE_POSOBJ( obj, type );
elif IS_REC( obj ) then
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
Comment on lines +613 to +614

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Assert(0, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(0, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));
#Assert(1, IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)));
Assert(1, not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsPositionalObjectRep)));

if not IS_SUBSET_FLAGS(flags, FLAGS_FILTER(IsComponentObjectRep)) then
INFO_DEBUG(1, "Objectify: type does not imply IsComponentObjectRep ",
INPUT_FILENAME(), ":", STRING_INT(INPUT_LINENUMBER()));
fi;
SET_TYPE_COMOBJ( obj, type );
else
Error("<obj> must be a list or a record");
fi;
if not ( IGNORE_IMMEDIATE_METHODS
or IsNoImmediateMethodsObject(obj) ) then
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/kernel/gap.tst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gap> START_TEST("kernel/gap.tst");
# in ViewObj; afterwards everything should still work as before
gap> l := [ ~ ];; r := rec(a:=~);;
gap> cat := NewCategory("IsMockObject", IsObject);;
gap> type := NewType(NewFamily("MockFamily"), cat);;
gap> type := NewType(NewFamily("MockFamily"), cat and IsPositionalObjectRep);;
gap> InstallMethod(ViewObj, [cat], function(s) Error("oops"); end);
gap> InstallMethod(PrintObj, [cat], function(s) Error("uups"); end);
gap> x:=Objectify(type,[]); r; Print(l, "\n");
Expand Down
4 changes: 2 additions & 2 deletions tst/testinstall/kernel/opers.tst
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ gap> CLEAR_CACHE_INFO();
gap> opcheck := OPERS_CACHE_INFO();;
#@if GAPInfo.KernelInfo.KernelDebug and IsHPCGAP
gap> opcheck{[1..11]};
[ 2, 0, 0, 6, 0, 0, 6, 0, 0, 2, 0 ]
[ 2, 0, 0, 6, 0, 0, 10, 0, 0, 2, 0 ]
#@fi

# FIXME: the following code skips entry 4 (OperationHit, which is normally
Expand Down Expand Up @@ -338,7 +338,7 @@ gap> opcheck{[1..11]};
#
#@if GAPInfo.KernelInfo.KernelDebug and not IsHPCGAP
gap> opcheck{Difference([1..11], [4])};
[ 2, 0, 0, 0, 0, 4, 0, 0, 2, 0 ]
[ 2, 0, 0, 0, 0, 8, 0, 0, 2, 0 ]
#@fi
#@if not GAPInfo.KernelInfo.KernelDebug
gap> opcheck{[1..11]};
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/object.tst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
gap> START_TEST("object.tst");

# test some standard object types
gap> r := Objectify(TYPE_KERNEL_OBJECT, rec());
gap> r := [];; SET_TYPE_DATOBJ(r,TYPE_KERNEL_OBJECT);
<kernel object>
gap> KnownAttributesOfObject(r);
[ ]
Expand Down