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

Clean up 8 bit matrix #5260

106 changes: 40 additions & 66 deletions lib/mat8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,24 @@ end);
#M Length( <mat> )
##

InstallMethod( Length, "for an 8-bit matrix rep",
true, [Is8BitMatrixRep], 0, m->m![1]);
InstallMethod(Length, "for an 8 - bit matrix rep", [Is8BitMatrixRep],
m -> m![1]);

#############################################################################
##
#M <mat> [ <pos> ]
##

InstallOtherMethod( \[\], "for an 8-bit matrix rep and pos. int.",
[Is8BitMatrixRep, IsPosInt],
ELM_MAT8BIT
);
InstallOtherMethod(\[\], "for an 8 - bit matrix rep and pos. int.",
[Is8BitMatrixRep, IsPosInt], ELM_MAT8BIT);

#############################################################################
##
#M <mat> [ <pos1>, <pos2> ]
##

InstallMethod( \[\,\], "for an 8-bit matrix rep and 2 pos. int.",
[Is8BitMatrixRep, IsPosInt, IsPosInt],
MAT_ELM_MAT8BIT
);
InstallMethod(\[\,\], "for an 8-bit matrix rep and 2 pos. int.",
[Is8BitMatrixRep, IsPosInt, IsPosInt], MAT_ELM_MAT8BIT);

#############################################################################
##
Expand All @@ -101,11 +97,10 @@ InstallMethod( \[\,\], "for an 8-bit matrix rep and 2 pos. int.",
## not lie in the appropriate field.
##

InstallOtherMethod( \[\]\:\=,
InstallOtherMethod(\[\]\:\=,
"for a mutable 8-bit matrix rep, a pos. int. and object",
[IsMutable and Is8BitMatrixRep, IsPosInt, IsObject],
ASS_MAT8BIT
);
[IsMutable and Is8BitMatrixRep, IsPosInt, IsObject],
ASS_MAT8BIT);

#############################################################################
##
Expand All @@ -128,8 +123,8 @@ InstallMethod( \[\,\]\:\=,

InstallMethod( Unbind\[\],
"for a mutable 8-bit matrix rep and pos. int.",
true, [IsMutable and Is8BitMatrixRep, IsPosInt],
0, function(m,p)
[IsMutable and Is8BitMatrixRep, IsPosInt],
function(m,p)
if p = 1 or p <> m![1] then
PLAIN_MAT8BIT(m);
Unbind(m[p]);
Expand All @@ -148,7 +143,7 @@ end);
##

InstallMethod( ViewObj, "for an 8-bit matrix rep",
true, [Is8BitMatrixRep], 0,
[Is8BitMatrixRep],
function( m )
local r,c;
r := NumberRows(m);
Expand All @@ -174,7 +169,7 @@ end);

InstallMethod( PrintObj,
"for an 8-bit matrix rep",
true, [Is8BitMatrixRep], 0,
[Is8BitMatrixRep],
function( mat )
local i,l;
Print("\>\>[ \>\>");
Expand All @@ -196,7 +191,7 @@ end);
##

InstallMethod(ShallowCopy, "for an 8-bit matrix rep",
true, [Is8BitMatrixRep], 0,
[Is8BitMatrixRep],
function(m)
local c,i,l;
l := m![1];
Expand All @@ -217,8 +212,7 @@ end );

InstallMethod( PositionCanonical,
"for 8-bit matrix rep and object",
true,
[ IsList and Is8BitMatrixRep, IsObject ], 0,
[ IsList and Is8BitMatrixRep, IsObject ],
function( list, obj )
return Position( list, obj, 0 );
end );
Expand All @@ -232,7 +226,7 @@ end );

InstallMethod( \+, "for two 8-bit matrices",
IsIdenticalObj, [Is8BitMatrixRep,
Is8BitMatrixRep], 0,
Is8BitMatrixRep], ,
Copy link
Member

Choose a reason for hiding this comment

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

Ooops, , , is a syntax error. I guess a later commit fixes this? Breaks the ability to git bisect, though :-(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Draft...

SUM_MAT8BIT_MAT8BIT
);

Expand All @@ -243,7 +237,7 @@ InstallMethod( \+, "for two 8-bit matrices",

InstallMethod( \-, "for two 8 bit matrices in same characteristic",
IsIdenticalObj, [Is8BitMatrixRep,
Is8BitMatrixRep], 0,
Is8BitMatrixRep], ,
DIFF_MAT8BIT_MAT8BIT
);

Expand Down Expand Up @@ -444,7 +438,7 @@ end);
InstallMethod( \*, "for an 8-bit vector and 8-bit matrix", IsElmsColls,
[ Is8BitVectorRep and IsRowVector and IsRingElementList,
Is8BitMatrixRep
], 0,
],
PROD_VEC8BIT_MAT8BIT);


Expand All @@ -456,7 +450,7 @@ InstallMethod( \*, "for an 8-bit vector and 8-bit matrix", IsElmsColls,
InstallMethod( \*, "for 8-bit matrix and 8-bit vector", IsCollsElms,
[ Is8BitMatrixRep,
Is8BitVectorRep and IsRowVector and IsRingElementList
], 0,
],
PROD_MAT8BIT_VEC8BIT);

#############################################################################
Expand All @@ -467,7 +461,7 @@ InstallMethod( \*, "for 8-bit matrix and 8-bit vector", IsCollsElms,
InstallMethod( \*, "for 8-bit matrices", IsIdenticalObj,
[ Is8BitMatrixRep,
Is8BitMatrixRep and IsMatrix
], 0,
],
PROD_MAT8BIT_MAT8BIT);

#############################################################################
Expand All @@ -481,7 +475,7 @@ InstallMethod( \*, "for 8-bit matrices", IsIdenticalObj,
InstallMethod( \*, "for an internal FFE and an 8 bit matrix", IsElmsCollColls,
[ IsFFE and IsInternalRep,
Is8BitMatrixRep
], 0,
],
function(s,m)
local q,i,l,r,pv;
q := Q_VEC8BIT(m![2]);
Expand Down Expand Up @@ -525,7 +519,7 @@ InstallMethod( \*, "for an 8-bit matrix and an internal FFE", IsCollCollsElms,
[
Is8BitMatrixRep,
IsFFE and IsInternalRep
], 0,
],
function(m,s)
local q,i,l,r,pv;
q := Q_VEC8BIT(m![2]);
Expand Down Expand Up @@ -562,9 +556,8 @@ end);
#M Additive Inverse
##

InstallMethod(AdditiveInverseMutable, "for an 8-bit matrix", true,
InstallMethod(AdditiveInverseMutable, "for an 8-bit matrix",
[Is8BitMatrixRep and IsAdditiveElementWithZero],
0,
function(mat)
local neg,i,negv;
neg := [mat![1]];
Expand All @@ -577,9 +570,8 @@ InstallMethod(AdditiveInverseMutable, "for an 8-bit matrix", true,
return neg;
end);

InstallMethod(AdditiveInverseImmutable, "for an 8-bit matrix", true,
InstallMethod(AdditiveInverseImmutable, "for an 8-bit matrix",
[Is8BitMatrixRep and IsAdditiveElementWithZero],
0,
function(mat)
local neg,i,negv;
neg := [mat![1]];
Expand All @@ -592,9 +584,8 @@ InstallMethod(AdditiveInverseImmutable, "for an 8-bit matrix", true,
return neg;
end);

InstallMethod(AdditiveInverseSameMutability, "for an 8-bit matrix", true,
InstallMethod(AdditiveInverseSameMutability, "for an 8-bit matrix",
[Is8BitMatrixRep and IsAdditiveElementWithZero],
0,
function(mat)
local neg,i,negv;
neg := [mat![1]];
Expand All @@ -617,9 +608,8 @@ end);
##
#M Zero

InstallMethod( ZeroMutable, "for an 8-bit matrix", true,
InstallMethod( ZeroMutable, "for an 8-bit matrix",
[Is8BitMatrixRep and IsAdditiveElementWithZero],
0,
function(mat)
local z, i,zv;
z := [mat![1]];
Expand All @@ -632,9 +622,9 @@ InstallMethod( ZeroMutable, "for an 8-bit matrix", true,
return z;
end);

InstallMethod( ZeroImmutable, "for an 8-bit matrix", true,
InstallMethod( ZeroImmutable, "for an 8-bit matrix",
[Is8BitMatrixRep and IsAdditiveElementWithZero],
0,

function(mat)
local z, i,zv;
z := [mat![1]];
Expand All @@ -648,9 +638,8 @@ InstallMethod( ZeroImmutable, "for an 8-bit matrix", true,
return z;
end);

InstallMethod( ZeroSameMutability, "for an 8-bit matrix", true,
InstallMethod( ZeroSameMutability, "for an 8-bit matrix",
[Is8BitMatrixRep and IsAdditiveElementWithZero],
0,
function(mat)
local z, i,zv;
z := [mat![1]];
Expand Down Expand Up @@ -681,7 +670,7 @@ end);
#M InverseOp(<mat>)
##

InstallMethod( InverseOp, "for an 8-bit matrix", true,
InstallMethod( InverseOp, "for an 8-bit matrix",
[Is8BitMatrixRep],
SUM_FLAGS,
INV_MAT8BIT_MUTABLE);
Expand All @@ -693,7 +682,7 @@ InstallMethod( InverseOp, "for an 8-bit matrix", true,
#M <mat>^-1
##

InstallMethod( InverseSameMutability, "for an 8-bit matrix", true,
InstallMethod( InverseSameMutability, "for an 8-bit matrix",
[Is8BitMatrixRep],
SUM_FLAGS,
INV_MAT8BIT_SAME_MUTABILITY);
Expand All @@ -703,7 +692,7 @@ InstallMethod( InverseSameMutability, "for an 8-bit matrix", true,
#M <mat>^0
##

InstallMethod( OneSameMutability, "for an 8-bit matrix", true,
InstallMethod( OneSameMutability, "for an 8-bit matrix",
[Is8BitMatrixRep],
SUM_FLAGS,
function(m)
Expand All @@ -728,7 +717,7 @@ InstallMethod( OneSameMutability, "for an 8-bit matrix", true,
return o;
end);

InstallMethod( OneMutable, "for an 8-bit matrix", true,
InstallMethod( OneMutable, "for an 8-bit matrix",
[Is8BitMatrixRep],
SUM_FLAGS,
function(m)
Expand All @@ -753,7 +742,7 @@ end);
#M One(<mat>) -- always immutable
##

InstallMethod( One, "for an 8-bit matrix", true,
InstallMethod( One, "for an 8-bit matrix",
[Is8BitMatrixRep],
SUM_FLAGS,
function(m)
Expand Down Expand Up @@ -881,8 +870,8 @@ InstallGlobalFunction( RepresentationsOfMatrix,
#M DefaultFieldOfMatrix( <ffe-mat> )
##
InstallMethod( DefaultFieldOfMatrix,
"for an 8-bit matrix", true,
[ IsMatrix and Is8BitMatrixRep ], 0,
"for an 8-bit matrix",
[ IsMatrix and Is8BitMatrixRep ],
function( mat )
return GF(Q_VEC8BIT(mat![2]));
end );
Expand All @@ -893,7 +882,7 @@ end );
##

InstallMethod( \<, "for two 8-bit matrices", IsIdenticalObj,
[ Is8BitMatrixRep, Is8BitMatrixRep ], 0,
[ Is8BitMatrixRep, Is8BitMatrixRep ],
LT_MAT8BIT_MAT8BIT);

#############################################################################
Expand All @@ -902,7 +891,7 @@ InstallMethod( \<, "for two 8-bit matrices", IsIdenticalObj,
##

InstallMethod( \=, "for two 8-bit matrices", IsIdenticalObj,
[ Is8BitMatrixRep, Is8BitMatrixRep ], 0,
[ Is8BitMatrixRep, Is8BitMatrixRep ],
EQ_MAT8BIT_MAT8BIT);

#############################################################################
Expand All @@ -912,11 +901,11 @@ InstallMethod( \=, "for two 8-bit matrices", IsIdenticalObj,
##

InstallOtherMethod( TransposedMat, "for an 8-bit matrix",
true, [Is8BitMatrixRep], 0,
[Is8BitMatrixRep],
TRANSPOSED_MAT8BIT);

InstallOtherMethod( MutableTransposedMat, "for an 8-bit matrix",
true, [Is8BitMatrixRep], 0,
[Is8BitMatrixRep],
TRANSPOSED_MAT8BIT);


Expand All @@ -931,9 +920,7 @@ InstallOtherMethod( MutableTransposedMat, "for an 8-bit matrix",
#

InstallMethod(SemiEchelonMat, "for an 8-bit matrix",
true,
[ IsMatrix and Is8BitMatrixRep ],
0,
function( mat )
local copymat, res;

Expand All @@ -944,9 +931,7 @@ InstallMethod(SemiEchelonMat, "for an 8-bit matrix",
end);

InstallMethod(SemiEchelonMatTransformation, "for an 8-bit matrix",
true,
[ IsMatrix and Is8BitMatrixRep ],
0,
function( mat )
local copymat,res,q;
copymat := List(mat, ShallowCopy);
Expand All @@ -962,19 +947,15 @@ end);
# could be done by method selection.
Copy link
Member

Choose a reason for hiding this comment

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

Example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again this was a note to myself, and not intended for review...

InstallMethod(SemiEchelonMatDestructive,
"for mutable plist-rep matrix of FFEs",
true,
[IsPlistRep and IsMatrix and IsMutable and IsFFECollColl],
0,
SEMIECHELON_LIST_VEC8BITS
);

# TODO: There's a bunch of argument checking in SEMIECHELON_LIST_VEC8BITS that
# could be done by method selection.
InstallMethod(SemiEchelonMatTransformationDestructive,
"for mutable plist-rep matrix of FFEs",
true,
[IsPlistRep and IsMatrix and IsMutable and IsFFECollColl],
0,
SEMIECHELON_LIST_VEC8BITS_TRANSFORMATIONS);


Expand All @@ -983,19 +964,14 @@ InstallMethod(SemiEchelonMatTransformationDestructive,
##
#M TriangulizeMat( <plain list of GF2 vectors> )
##
# HERE
InstallMethod(TriangulizeMat,
"for mutable plist-rep matrix of FFEs",
true,
[IsPlistRep and IsMatrix and IsMutable and IsFFECollColl],
0,
TRIANGULIZE_LIST_VEC8BITS);

InstallMethod(TriangulizeMat,
"for a mutable 8-bit matrix",
true,
[IsMutable and IsMatrix and Is8BitMatrixRep],
0,
function(m)
local q,i,imms;
imms := [];
Expand Down Expand Up @@ -1025,9 +1001,7 @@ end);

InstallMethod(DeterminantMatDestructive,
"for mutable plist-rep matrix of FFEs",
true,
[IsPlistRep and IsMatrix and IsMutable and IsFFECollColl],
0,
DETERMINANT_LIST_VEC8BITS);

#############################################################################
Expand Down