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

Fix inefficiency when dealing with certain algebra modules #2058

Merged
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
5 changes: 5 additions & 0 deletions lib/algrep.gd
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@ DeclareCategory( "IsMonomialElement", IsVector );
DeclareCategoryCollections( "IsMonomialElement" );
DeclareCategoryFamily( "IsMonomialElement" );

#
DeclareHandlingByNiceBasis( "IsMonomialElementVectorSpace",
"for free left modules of monomial elements");


#############################################################################
##
#O ConvertToNormalFormMonomialElement( <me> )
Expand Down
129 changes: 76 additions & 53 deletions lib/algrep.gi
Original file line number Diff line number Diff line change
Expand Up @@ -927,70 +927,68 @@ end );
##
## Is the submodule of <V> generated by <gens>.
##
InstallMethod( SubAlgebraModule,
"for algebra module, and a list of submodule generators",
IsIdenticalObj, [ IsFreeLeftModule and IsAlgebraModule,
IsAlgebraModuleElementCollection and IsList ], 0,
function( V, gens )

local sub;
BindGlobal("_SubAlgebraModuleHelper", function( V, gens, args... )
local sub, isBasis;
if Length(args)>0 and args[1]<>"basis" then
Error( "Usage: SubAlgebraModule( <V>, <gens>, <str>) where the last argument is string \"basis\"" );
fi;
isBasis := Length(gens) = 0 or (Length(args)>0 and args[1]="basis");

sub:= Objectify( NewType( FamilyObj( V ),
IsLeftModule and IsAttributeStoringRep ), rec() );
SetIsAlgebraModule( sub, true );
SetLeftActingDomain( sub, LeftActingDomain( V ) );
SetGeneratorsOfAlgebraModule( sub, gens );
sub:= Objectify( NewType( FamilyObj( V ),
IsLeftModule and IsAttributeStoringRep ), rec() );
SetIsAlgebraModule( sub, true );
SetLeftActingDomain( sub, LeftActingDomain( V ) );
SetGeneratorsOfAlgebraModule( sub, gens );

if HasIsFiniteDimensional( V ) and IsFiniteDimensional( V ) then
SetIsFiniteDimensional( sub, true );
fi;
if HasIsFiniteDimensional( V ) and IsFiniteDimensional( V ) then
SetIsFiniteDimensional( sub, true );
fi;

if IsLeftAlgebraModuleElementCollection( V ) then
SetLeftActingAlgebra( sub, LeftActingAlgebra( V ) );
fi;
if IsLeftAlgebraModuleElementCollection( V ) then
SetLeftActingAlgebra( sub, LeftActingAlgebra( V ) );
fi;

if IsRightAlgebraModuleElementCollection( V ) then
SetRightActingAlgebra( sub, RightActingAlgebra( V ) );
fi;
if IsRightAlgebraModuleElementCollection( V ) then
SetRightActingAlgebra( sub, RightActingAlgebra( V ) );
fi;

return sub;
if isBasis then
SetGeneratorsOfLeftModule( sub, gens );
SetBasis( sub, BasisOfAlgebraModule( sub, gens ) );
SetDimension( sub, Length( gens ) );
fi;

return sub;
end );

InstallMethod( SubAlgebraModule,
"for algebra module, and a list of submodule generators",
IsIdenticalObj,
[ IsFreeLeftModule and IsAlgebraModule,
IsAlgebraModuleElementCollection and IsList ],
_SubAlgebraModuleHelper );

InstallOtherMethod( SubAlgebraModule,
"for algebra module, and an empty list of submodule generators",
[ IsFreeLeftModule and IsAlgebraModule,
IsEmpty and IsList ],
_SubAlgebraModuleHelper );

InstallOtherMethod( SubAlgebraModule,
"for algebra module, and a list of submodule generators, and string",
IsFamFamX,
[ IsFreeLeftModule and IsAlgebraModule,
IsAlgebraModuleElementCollection and IsList,
IsString ], 0,
function( V, gens, str )

local sub;

if str<>"basis" then
Error( "Usage: SubAlgebraModule( <V>, <gens>, <str>) where the last argument is string \"basis\"" );
fi;
IsString ],
_SubAlgebraModuleHelper );

sub:= Objectify( NewType( FamilyObj( V ),
IsLeftModule and IsAttributeStoringRep ), rec() );
SetIsAlgebraModule( sub, true );
SetLeftActingDomain( sub, LeftActingDomain( V ) );
SetGeneratorsOfAlgebraModule( sub, gens );
SetGeneratorsOfLeftModule( sub, gens );

if IsLeftAlgebraModuleElementCollection( V ) then
SetLeftActingAlgebra( sub, LeftActingAlgebra( V ) );
fi;

if IsRightAlgebraModuleElementCollection( V ) then
SetRightActingAlgebra( sub, RightActingAlgebra( V ) );
fi;

SetBasis( sub, BasisOfAlgebraModule( sub, gens ) );
SetDimension( sub, Length( gens ) );
return sub;

end );
InstallOtherMethod( SubAlgebraModule,
"for algebra module, and an empty list of submodule generators, and string",
[ IsFreeLeftModule and IsAlgebraModule,
IsEmpty and IsList,
IsString ],
_SubAlgebraModuleHelper );

##############################################################################
##
Expand Down Expand Up @@ -1196,6 +1194,15 @@ InstallMethod( NaturalHomomorphismBySubAlgebraModule,
f:= NaturalHomomorphismBySubspace( V, W );
quot:= ImagesSource( f );

if IsTrivial(quot) then
quot := SubAlgebraModule( V, [], "basis" );
nathom := ZeroMapping( V, quot );
SetIsSurjective( nathom, true );
SetImagesSource(nathom, quot);
SetKernelOfAdditiveGeneralMapping( nathom, W );
return nathom;
fi;

imgs:= List( Basis( V ), x -> Coefficients( Basis( quot ),
ImagesRepresentative(f,x)));

Expand Down Expand Up @@ -1233,7 +1240,9 @@ InstallMethod( NaturalHomomorphismBySubAlgebraModule,

# Enter the preimages info.
nathom!.basisimage:= Basis( qmod );
nathom!.preimagesbasisimage:= f!.preimagesbasisimage;
if IsBound(f!.preimagesbasisimage) then
nathom!.preimagesbasisimage:= f!.preimagesbasisimage;
fi;
SetKernelOfAdditiveGeneralMapping( nathom, W );

# Run the implications for the factor.
Expand Down Expand Up @@ -3180,8 +3189,9 @@ end );
#############################################################################
##
## Prevent nice basis handling to kick in for vector spaces over sparse
## elements, as that ends up trying to enumerate the vector space, which
## is not a good idea for non-trivial examples.
## elements (including monomial elements), as that ends up trying to
## enumerate the vector space, which is not a good idea for non-trivial
## examples.
##
InstallHandlingByNiceBasis( "IsSparseVectorSpace", rec(
detect:= function( R, gens, V, zero )
Expand All @@ -3196,6 +3206,19 @@ InstallHandlingByNiceBasis( "IsSparseVectorSpace", rec(
UglyVector := function( C, vec ) end,
) );

InstallHandlingByNiceBasis( "IsMonomialElementVectorSpace", rec(
detect:= function( R, gens, V, zero )
if IsMonomialElementCollection(V) then
return fail;
else
return false;
fi;
end,
NiceFreeLeftModuleInfo := function( C ) end,
NiceVector := function( C, c ) end,
UglyVector := function( C, vec ) end,
) );


#############################################################################
##
Expand Down
16 changes: 14 additions & 2 deletions lib/lierep.gi
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ InstallMethod( CochainSpace,
r:= Dimension( V );
F:= LeftActingDomain( L );

if r = 0 then
if s = 0 then
return VectorSpace( F, [], Cochain( V, 0, Zero(V) ), "basis" );
else
return VectorSpace( F, [], Cochain( V, s, [] ), "basis" );
fi;
fi;

if s = 0 then
bas:= List( BasisVectors( Basis( V ) ), x -> Cochain( V, s, x ) );
return VectorSpace( F, bas, "basis" );
Expand Down Expand Up @@ -623,7 +631,7 @@ InstallMethod( Coboundaries,

if s = 0 then
return VectorSpace( LeftActingDomain(V),
[ Cochain( V, 0, Zero(V) ) ] );
[ ], Cochain( V, 0, Zero(V) ), "basis" );
fi;

# The s-coboundaries are the images of the (s-1)-cochains under
Expand All @@ -632,7 +640,10 @@ InstallMethod( Coboundaries,
Csm1:= CochainSpace( V, s-1 );
gens:= List( GeneratorsOfLeftModule( Csm1 ), x ->
LieCoboundaryOperator(x) );

if Length(gens) = 0 then
return VectorSpace( LeftActingDomain(V),
[ ], Cochain( V, s, [] ), "basis" );
fi;
return VectorSpace( LeftActingDomain(V), gens );

end );
Expand All @@ -649,6 +660,7 @@ InstallMethod( Cocycles,
# when restricted to the space of s-cochains.

Cs:= CochainSpace( V, s );
if IsTrivial(Cs) then return Cs; fi;
gens:= List( GeneratorsOfLeftModule( Cs ), x ->
LieCoboundaryOperator(x) );

Expand Down
100 changes: 100 additions & 0 deletions tst/testinstall/algrep.tst
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,105 @@ true
gap> ForAll([1..10], i -> Random(A) in A);
true

#
# creating subalgebra
#
gap> L:=FullMatrixLieAlgebra(GF(3), 2);; Dimension(L);;
gap> V:=AdjointModule(L);
<left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S:=SymmetricPowerOfAlgebraModule(V, 4);
<35-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>

# span of zero vectors
gap> S0:=SubAlgebraModule(S,[]);
<0-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S0:=SubAlgebraModule(S,[],"basis");
<0-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>

# span of some vectors
gap> bas:=Basis(S){[ 1, 2, 4, 5, 6, 9, 13, 14, 15, 16, 19, 25, 32, 33, 34, 35 ]};;
gap> S1:=SubAlgebraModule(S,bas);
<left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> Dimension(S1);
16
gap> S1:=SubAlgebraModule(S,bas,"basis");
<16-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>

#
# factors
#
gap> S0/S0;
<0-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S1/S0;
<16-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S1/S1;
<0-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S/S0;
<35-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S/S1;
<19-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>
gap> S/S;
<0-dimensional left-module over <Lie algebra of dimension 4 over GF(3)>>

#
# cocycles etc.
#

# for zero module
gap> CochainSpace(S0,0);
<vector space of dimension 0 over GF(3)>
gap> CochainSpace(S0,1);
<vector space of dimension 0 over GF(3)>
gap> CochainSpace(S0,2);
<vector space of dimension 0 over GF(3)>
gap> Cocycles(S0,0);
<vector space of dimension 0 over GF(3)>
gap> Cocycles(S0,1);
<vector space of dimension 0 over GF(3)>
gap> Cocycles(S0,2);
<vector space of dimension 0 over GF(3)>
gap> Coboundaries(S0,0);
<vector space of dimension 0 over GF(3)>
gap> Coboundaries(S0,1);
<vector space of dimension 0 over GF(3)>
gap> Coboundaries(S0,2);
<vector space of dimension 0 over GF(3)>

# for proper submodule
gap> CochainSpace(S1,0);
<vector space of dimension 16 over GF(3)>
gap> CochainSpace(S1,1);
<vector space of dimension 64 over GF(3)>
gap> CochainSpace(S1,2);
<vector space of dimension 96 over GF(3)>
gap> Cocycles(S1,0);
<vector space of dimension 4 over GF(3)>
gap> Cocycles(S1,1);
<vector space of dimension 16 over GF(3)>
gap> Cocycles(S1,2);
<vector space of dimension 48 over GF(3)>
gap> tmp:=Coboundaries(S1,0);; Dimension(tmp);; tmp;
<vector space of dimension 0 over GF(3)>
gap> tmp:=Coboundaries(S1,1);; Dimension(tmp);; tmp;
<vector space of dimension 12 over GF(3)>
gap> tmp:=Coboundaries(S1,2);; Dimension(tmp);; tmp;
<vector space of dimension 48 over GF(3)>

# for full module
gap> CochainSpace(S,0);
<vector space of dimension 35 over GF(3)>
gap> CochainSpace(S,1);
<vector space of dimension 140 over GF(3)>
gap> CochainSpace(S,2);
<vector space of dimension 210 over GF(3)>
gap> Cocycles(S,0);
<vector space of dimension 6 over GF(3)>
gap> Cocycles(S,1);
<vector space of dimension 45 over GF(3)>
gap> tmp:=Coboundaries(S,0);; Dimension(tmp);; tmp;
<vector space of dimension 0 over GF(3)>
gap> tmp:=Coboundaries(S,1);; Dimension(tmp);; tmp;
<vector space of dimension 29 over GF(3)>

#
gap> STOP_TEST( "algrep.tst", 1);