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
38 changes: 36 additions & 2 deletions lib/matrix.gi
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ InstallMethod( IsLowerTriangularMatrix,
end);


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


#############################################################################
##
#M IsSymmetricMatrix(<mat>)
Expand All @@ -258,7 +270,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 @@ -271,7 +283,29 @@ InstallMethod( IsSymmetricMatrix,
return true;
end );

InstallTrueMethod( IsSymmetricMatrix, IsMatrixOrMatrixObj and IsEmptyMatrix );


#############################################################################
##
#M IsAntisymmetricMatrix(<mat>)
##
InstallMethod( IsAntisymmetricMatrix,
"for a matrix",
[ IsMatrixOrMatrixObj ],
function( mat )
local i, j;
if not IsSquareMatrix( mat ) then
return false;
fi;
for i in [ 1 .. NrRows( mat ) ] do
for j in [ 1 .. i ] do
if mat[i,j] <> -mat[j,i] then
return false;
fi;
od;
od;
return true;
end );


#############################################################################
Expand Down
86 changes: 86 additions & 0 deletions tst/testinstall/matrix.tst
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
gap> empty_0x2 := NewZeroMatrix(IsPlistMatrixRep, Integers, 0, 2);
<0x2-matrix over Integers>
gap> empty_2x0 := NewZeroMatrix(IsPlistMatrixRep, Integers, 2, 0);
<2x0-matrix over Integers>
gap> empty_0x0 := NewZeroMatrix(IsPlistMatrixRep, Integers, 0, 0);
<0x0-matrix over Integers>
gap> IsEmptyMatrix(empty_0x2);
true
gap> IsEmptyMatrix(empty_2x0);
true
gap> IsEmptyMatrix(empty_0x0);
true

#
gap> IsGeneralizedCartanMatrix(NullMat(3, 3));
false
Expand All @@ -21,6 +35,12 @@ gap> IsGeneralizedCartanMatrix([[2,-2],[-2,2]]);
true

#
gap> IsDiagonalMat(empty_0x2);
true
gap> IsDiagonalMat(empty_2x0);
true
gap> IsDiagonalMat(empty_0x0);
true
gap> IsDiagonalMat(NullMat(3, 3));
true
gap> IsDiagonalMat(NullMat(1, 3));
Expand All @@ -45,6 +65,12 @@ gap> IsDiagonalMat([[1,0,0],[0,1,0]]);
true

#
gap> IsUpperTriangularMat(empty_0x2);
true
gap> IsUpperTriangularMat(empty_2x0);
true
gap> IsUpperTriangularMat(empty_0x0);
true
gap> IsUpperTriangularMat(NullMat(3, 3));
true
gap> IsUpperTriangularMat(NullMat(1, 3));
Expand All @@ -67,6 +93,12 @@ gap> IsUpperTriangularMat([[1,1,1],[0,1,1]]);
true

#
gap> IsLowerTriangularMat(empty_0x2);
true
gap> IsLowerTriangularMat(empty_2x0);
true
gap> IsLowerTriangularMat(empty_0x0);
true
gap> IsLowerTriangularMat(NullMat(3, 3));
true
gap> IsLowerTriangularMat(NullMat(1, 3));
Expand All @@ -89,6 +121,34 @@ gap> IsLowerTriangularMat([[1,0],[1,1],[1,1]]);
true

#
gap> IsSquareMat(empty_0x2);
false
gap> IsSquareMat(empty_2x0);
false
gap> IsSquareMat(empty_0x0);
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(empty_0x2);
false
gap> IsSymmetricMat(empty_2x0);
false
gap> IsSymmetricMat(empty_0x0);
true
gap> IsSymmetricMat(NullMat(3, 3));
true
gap> IsSymmetricMat(IdentityMat(3));
Expand All @@ -112,6 +172,32 @@ false
gap> IsSymmetricMat([[1,2],[3,4],[5,6]]);
false

#
gap> IsAntisymmetricMat(empty_0x2);
false
gap> IsAntisymmetricMat(empty_2x0);
false
gap> IsAntisymmetricMat(empty_0x0);
true
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