Skip to content
Open
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: 2 additions & 0 deletions doc/ref/matrix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ see&nbsp;<Ref Sect="Mutability and Copyability"/>.
<#Include Label="IsDiagonalMat">
<#Include Label="IsUpperTriangularMat">
<#Include Label="IsLowerTriangularMat">
<#Include Label="IsSquareMat">
<#Include Label="IsSymmetricMat">
<#Include Label="IsAntisymmetricMat">

</Section>

Expand Down
68 changes: 68 additions & 0 deletions lib/matrix.gd
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ DeclareProperty( "IsLowerTriangularMatrix", IsMatrixOrMatrixObj );
DeclareSynonym( "IsLowerTriangularMat", IsLowerTriangularMatrix );


#############################################################################
##
#P IsSquareMatrix( <mat> )
#P IsSquareMat( <mat> )
##
## <#GAPDoc Label="IsSquareMat">
## <ManSection>
## <Prop Name="IsSquareMatrix" Arg='mat'/>
## <Prop Name="IsSquareMat" Arg='mat'/>
##
## <Description>
## return <K>true</K> if the matrix <A>mat</A> has the same number of rows
## and columns, and <K>false</K> otherwise.
## <Example><![CDATA[
## gap> IsSquareMatrix( [ [ 1 ] ] );
## true
## gap> IsSquareMatrix( [ [ 1, 2 ], [ 3, 4 ] ] );
## true
## gap> IsSquareMatrix( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
## false
## ]]></Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareProperty( "IsSquareMatrix", IsMatrixOrMatrixObj );

DeclareSynonym( "IsSquareMat", IsSquareMatrix );


#############################################################################
##
#P IsSymmetricMatrix( <mat> )
Expand Down Expand Up @@ -184,6 +214,44 @@ DeclareProperty( "IsSymmetricMatrix", IsMatrixOrMatrixObj );

DeclareSynonym( "IsSymmetricMat", IsSymmetricMatrix );

InstallTrueMethod( IsSquareMatrix, IsSymmetricMatrix );


#############################################################################
##
#P IsAntisymmetricMatrix( <mat> )
#P IsAntisymmetricMat( <mat> )
##
## <#GAPDoc Label="IsAntisymmetricMat">
## <ManSection>
## <Prop Name="IsAntisymmetricMatrix" Arg='mat'/>
## <Prop Name="IsAntisymmetricMat" Arg='mat'/>
##
## <Description>
## return <K>true</K> if the matrix <A>mat</A> is a square matrix and
## satisfies <C><A>mat</A>[i,j] = -<A>mat</A>[j,i]</C> for all
## <M>i, j</M>, and <K>false</K> otherwise.
## (In particular, the diagonal entries must be zero.)
## <Example><![CDATA[
## gap> IsAntisymmetricMatrix( [ [ 0 ] ] );
## true
## gap> IsAntisymmetricMatrix( [ [ 0, 1 ], [ -1, 0 ] ] );
## true
## gap> IsAntisymmetricMatrix( [ [ 0, 1 ], [ 1, 0 ] ] );
## false
## gap> IsAntisymmetricMatrix( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
## false
## ]]></Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareProperty( "IsAntisymmetricMatrix", IsMatrixOrMatrixObj );

DeclareSynonym( "IsAntisymmetricMat", IsAntisymmetricMatrix );

InstallTrueMethod( IsSquareMatrix, IsAntisymmetricMatrix );


#############################################################################
##
Expand Down
45 changes: 44 additions & 1 deletion lib/matrix.gi
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ InstallMethod( IsLowerTriangularMatrix,
end);


#############################################################################
##
#M IsSquareMatrix(<mat>)
##
InstallMethod( IsSquareMatrix,
"for a matrix",
[ IsMatrixOrMatrixObj ],
function( mat )
return NrRows( mat ) = NrCols( mat );
end );

InstallTrueMethod( IsSquareMatrix, IsMatrixOrMatrixObj and IsEmptyMatrix );
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... is a $0\times 2$ matrix square?



#############################################################################
##
#M IsSymmetricMatrix(<mat>)
Expand All @@ -258,7 +272,7 @@ InstallMethod( IsSymmetricMatrix,
[ IsMatrixOrMatrixObj ],
function( mat )
local i, j;
if NrRows( mat ) <> NrCols( mat ) then
if not IsSquareMatrix( mat ) then
return false;
fi;
for i in [ 1 .. NrRows( mat ) ] do
Expand All @@ -274,6 +288,35 @@ InstallMethod( IsSymmetricMatrix,
InstallTrueMethod( IsSymmetricMatrix, IsMatrixOrMatrixObj and IsEmptyMatrix );


#############################################################################
##
#M IsAntisymmetricMatrix(<mat>)
##
InstallMethod( IsAntisymmetricMatrix,
"for a matrix",
[ IsMatrixOrMatrixObj ],
function( mat )
local i, j, zero;
if not IsSquareMatrix( mat ) then
return false;
fi;
zero := ZeroOfBaseDomain( mat );
for i in [ 1 .. NrRows( mat ) ] do
if mat[i,i] <> zero then
Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong condition in characteristic 0, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

In characteristic 2, you mean?

Copy link
Member

Choose a reason for hiding this comment

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

argh, yes (actually: in even positive characteristic, not just 2.

But the solution is the same: just remove this special case

return false;
fi;
for j in [ i+1 .. NrCols( mat ) ] do
if mat[i,j] <> -mat[j,i] then
return false;
fi;
od;
od;
return true;
end );

InstallTrueMethod( IsAntisymmetricMatrix, IsMatrixOrMatrixObj and IsEmptyMatrix );


#############################################################################
##
#M DiagonalOfMatrix(<mat>) . . . . . . . . . . . . . . . diagonal of matrix
Expand Down
36 changes: 36 additions & 0 deletions tst/testinstall/matrix.tst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ true
gap> IsLowerTriangularMat([[1,0],[1,1],[1,1]]);
true

#
gap> IsSquareMat(NullMat(3, 3));
true
gap> IsSquareMat(IdentityMat(3));
true
gap> IsSquareMat([[1]]);
true
gap> IsSquareMat([[1,2],[3,4]]);
true
gap> IsSquareMat(NullMat(2, 3));
false
gap> IsSquareMat(NullMat(3, 2));
false
gap> IsSquareMat([[1,2,3],[4,5,6]]);
false

#
gap> IsSymmetricMat(NullMat(3, 3));
true
Expand All @@ -112,6 +128,26 @@ false
gap> IsSymmetricMat([[1,2],[3,4],[5,6]]);
false

#
gap> IsAntisymmetricMat(NullMat(3, 3));
true
gap> IsAntisymmetricMat([[0]]);
true
gap> IsAntisymmetricMat([[0,1],[-1,0]]);
true
gap> IsAntisymmetricMat([[0,2,3],[-2,0,5],[-3,-5,0]]);
true
gap> IsAntisymmetricMat([[0,1],[1,0]]);
false
gap> IsAntisymmetricMat([[1,0],[0,1]]);
false
gap> IsAntisymmetricMat(NullMat(2, 3));
false
gap> IsAntisymmetricMat(NullMat(3, 2));
false
gap> IsAntisymmetricMat([[1,2,3],[4,5,6]]);
false

#
gap> m := Z(5)^0 * [[0, 1], [1, 0]];;
gap> m := GeneratorsWithMemory([m])[1];;
Expand Down
Loading