Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify the code for IsObjWithMemory #5875

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
2 changes: 0 additions & 2 deletions lib/memory.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ DeclareRepresentation("IsObjWithMemory",
IsComponentObjectRep and IsObjWithMemoryRankFilter and
IsMultiplicativeElementWithInverse, ["slp","n","el"]);

DeclareAttribute("TypeOfObjWithMemory",IsFamily);

DeclareGlobalFunction( "GeneratorsWithMemory" );
DeclareOperation( "StripMemory", [IsObject] );
DeclareOperation( "ForgetMemory", [IsObject] );
Expand Down
142 changes: 38 additions & 104 deletions lib/memory.gi
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,30 @@
##
#############################################################################

BindGlobal( "ObjWithMemory", function( slp, n, el )
local filt;

filt:= IsObjWithMemory;
if IsMatrixOrMatrixObj( el ) then
filt:= filt and IsMatrixOrMatrixObj;
if IsMatrix( el ) then
filt:= filt and IsMatrix;
fi;
if IsMatrixObj( el ) then
filt:= filt and IsMatrixObj;
fi;
fi;

InstallMethod(TypeOfObjWithMemory,"generic",true,[IsFamily],0,
function(fam)
return NewType(fam,IsObjWithMemory);
end);
return Objectify( NewType( FamilyObj( el ), filt ),
rec( slp:= slp, n:= n, el:= el ) );
end );

InstallGlobalFunction( GeneratorsWithMemory,
function(l)
# l is a list of objects
local i,ll,o,r,slp;
local slp;
slp := rec(prog := [],nogens := Length(l));
ll := [];
for i in [1..Length(l)] do
o := l[i];
r := rec(slp := slp, n := i, el := o);
Objectify(TypeOfObjWithMemory(FamilyObj(o)),r);
if IsMatrixOrMatrixObj(o) then
SetFilterObj(r,IsMatrixOrMatrixObj);
if IsMatrix(o) then
SetFilterObj(r,IsMatrix);
fi;
if IsMatrixObj(o) then
SetFilterObj(r,IsMatrixObj);
fi;
fi;
Add(ll,r);
od;
return ll;
return List( [ 1 .. Length( l ) ], i -> ObjWithMemory( slp, i, l[i] ) );
end);

InstallMethod( StripMemory, "for an object with memory",
Expand Down Expand Up @@ -116,9 +112,7 @@
function(gwm,h)
# h must be a homomorphic image of gwm, the memory of gwm is copied to
# h. Returns a new object with memory instead of h.
local hwm;
hwm := rec(slp := gwm!.slp, n := gwm!.n, el := h);
return Objectify(TypeOfObjWithMemory(FamilyObj(h)),hwm);
return ObjWithMemory( gwm!.slp, gwm!.n, h );

Check warning on line 115 in lib/memory.gi

View check run for this annotation

Codecov / codecov/patch

lib/memory.gi#L115

Added line #L115 was not covered by tests
end);

InstallGlobalFunction( GroupWithMemory,
Expand Down Expand Up @@ -189,101 +183,54 @@
InstallMethod( \*, "objects with memory", true,
[IsObjWithMemory,IsObjWithMemory],0,
function(a,b)
local r,slp;
local slp;
slp := a!.slp;
if not IsIdenticalObj(a!.slp, b!.slp) then
if not IsIdenticalObj( slp, b!.slp ) then
ErrorNoReturn("\\* for objects with memory: a!.slp and b!.slp must be identical");
fi;
if a!.n = 0 then # the identity!
r := rec(slp := slp, n := b!.n, el := b!.el);
return ObjWithMemory( slp, b!.n, b!.el );
elif b!.n = 0 then # the identity!
r := rec(slp := slp, n := a!.n, el := a!.el);
return ObjWithMemory( slp, a!.n, a!.el );
else
r := rec(slp := slp, n := Length(slp.prog)+slp.nogens+1,
el := a!.el*b!.el);
Add(slp.prog,[a!.n,1,b!.n,1]);
fi;
Objectify(TypeOfObjWithMemory(FamilyObj(a)),r);
if IsMatrixOrMatrixObj(a) then
SetFilterObj(r,IsMatrixOrMatrixObj);
if IsMatrix(a) then
SetFilterObj(r,IsMatrix);
fi;
if IsMatrixObj(a) then
SetFilterObj(r,IsMatrixObj);
fi;
Add( slp.prog, [ a!.n, 1, b!.n, 1 ] );
return ObjWithMemory( slp, Length( slp.prog ) + slp.nogens,
a!.el * b!.el );
fi;
return r;
end);

InstallMethod( One, "objects with memory", true,
[IsObjWithMemory],0, OneOp);

InstallMethod( OneOp, "objects with memory", true,
[IsObjWithMemory],0,
function(a)
local r;
r := rec(slp := a!.slp, n := 0, el := One(a!.el));
Objectify(TypeOfObjWithMemory(FamilyObj(a)),r);
if IsMatrixOrMatrixObj(a) then
SetFilterObj(r,IsMatrixOrMatrixObj);
if IsMatrix(a) then
SetFilterObj(r,IsMatrix);
fi;
if IsMatrixObj(a) then
SetFilterObj(r,IsMatrixObj);
fi;
fi;
return r;
end);
a -> ObjWithMemory( a!.slp, 0, One( a!.el ) ) );

InstallMethod( InverseOp, "objects with memory", true,
[IsObjWithMemory],0,
function(a)
local r,slp;
local slp;
slp := a!.slp;
if a!.n <> 0 then
r := rec(slp := slp, n := Length(slp.prog)+slp.nogens+1,
el := InverseOp(a!.el));
Add(slp.prog,[a!.n,-1]);
Add( slp.prog, [ a!.n, -1 ] );
return ObjWithMemory( slp, Length( slp.prog ) + slp.nogens,
InverseOp( a!.el ) );
else
r := rec(slp := slp, n := 0, el := a!.el);
fi;
Objectify(TypeOfObjWithMemory(FamilyObj(a)),r);
if IsMatrixOrMatrixObj(a) then
SetFilterObj(r,IsMatrixOrMatrixObj);
if IsMatrix(a) then
SetFilterObj(r,IsMatrix);
fi;
if IsMatrixObj(a) then
SetFilterObj(r,IsMatrixObj);
fi;
return ObjWithMemory( slp, 0, a!.el );

Check warning on line 219 in lib/memory.gi

View check run for this annotation

Codecov / codecov/patch

lib/memory.gi#L219

Added line #L219 was not covered by tests
fi;
return r;
end);

InstallMethod( \^, "objects with memory", true,
[IsObjWithMemory,IsInt],0,
function(a,b)
local r,slp;
local slp;
slp := a!.slp;
if a!.n = 0 then
r := rec(slp := slp, n := 0, el := a!.el);
return ObjWithMemory( slp, 0, a!.el );

Check warning on line 229 in lib/memory.gi

View check run for this annotation

Codecov / codecov/patch

lib/memory.gi#L229

Added line #L229 was not covered by tests
else
r := rec(slp := slp, n := Length(slp.prog)+slp.nogens+1,el := a!.el^b);
Add(slp.prog,[a!.n,b]);
Add( slp.prog, [ a!.n, b ] );
return ObjWithMemory( slp, Length( slp.prog ) + slp.nogens, a!.el^b );
fi;
Objectify(TypeOfObjWithMemory(FamilyObj(a)),r);
if IsMatrixOrMatrixObj(a) then
SetFilterObj(r,IsMatrixOrMatrixObj);
if IsMatrix(a) then
SetFilterObj(r,IsMatrix);
fi;
if IsMatrixObj(a) then
SetFilterObj(r,IsMatrixObj);
fi;
fi;
return r;
end);

InstallMethod(\=,"two objects with memory",IsIdenticalObj,
Expand Down Expand Up @@ -374,10 +321,7 @@
"for a permutation with memory and a list of integers",true,
[ IsPerm and IsObjWithMemory, IsList ], 0,
function(a,l)
local r;
r := rec(slp := a!.slp, n := a!.n, el := RestrictedPerm(a!.el,l));
Objectify(TypeOfObjWithMemory(FamilyObj(a)),r);
return r;
return ObjWithMemory( a!.slp, a!.n, RestrictedPerm( a!.el, l ) );

Check warning on line 324 in lib/memory.gi

View check run for this annotation

Codecov / codecov/patch

lib/memory.gi#L324

Added line #L324 was not covered by tests
end);

InstallMethod(SignPerm,
Expand Down Expand Up @@ -450,17 +394,7 @@

InstallOtherMethod( ImmutableMatrix,"object with memory",[IsField,IsMatrixOrMatrixObj and IsObjWithMemory],
function(f,a)
local r;
r := rec(slp := a!.slp, n := a!.n, el := ImmutableMatrix(f, a!.el));
Objectify(TypeOfObjWithMemory(FamilyObj(a)),r);
SetFilterObj(r,IsMatrixOrMatrixObj);
if IsMatrix(a) then
SetFilterObj(r,IsMatrix);
fi;
if IsMatrixObj(a) then
SetFilterObj(r,IsMatrixObj);
fi;
return r;
return ObjWithMemory( a!.slp, a!.n, ImmutableMatrix( f, a!.el ) );
end);

# Free group methods:
Expand Down
Loading