Skip to content

Commit

Permalink
matrix: replace IsIntegerMatrix by MatrixObj
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfwilson authored and james-d-mitchell committed Jun 16, 2022
1 parent 5a14d0d commit ac790ca
Show file tree
Hide file tree
Showing 39 changed files with 612 additions and 461 deletions.
58 changes: 28 additions & 30 deletions doc/maxplusmat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- <Filt Name = "IsProjectiveMaxPlusMatrix" Arg = "obj" Type =
"Category"/> -->
<Filt Name = "IsNTPMatrix" Arg = "obj" Type = "Category"/>
<Filt Name = "IsIntegerMatrix" Arg = "obj" Type = "Category"/>
<Filt Name = "Integers" Arg = "obj" Type = "Category"/>
<Returns><K>true</K> or <K>false</K>.</Returns>
<Description>
Every matrix over a semiring in &SEMIGROUPS; is a member of one of these
Expand Down Expand Up @@ -89,10 +89,6 @@
"Category"/>
<Filt Name = "IsNTPMatrixCollColl" Arg = "obj" Type =
"Category"/>
<Filt Name = "IsIntegerMatrixCollection" Arg = "obj" Type =
"Category"/>
<Filt Name = "IsIntegerMatrixCollColl" Arg = "obj" Type =
"Category"/>
<Returns>
<K>true</K> or <K>false</K>.
</Returns>
Expand Down Expand Up @@ -186,18 +182,19 @@ gap> PeriodNTPMatrix(mat);
<Returns>An integer matrix.</Returns>
<Description>
If <A>mat</A> is an integer matrix (i.e. belongs to the category
<Ref Filt = "IsIntegerMatrix"/>) whose inverse (if it exists) is also an
<Ref Filt = "Integers"/>) whose inverse (if it exists) is also an
integer matrix, then <C>InverseOp</C> returns the inverse of <A>mat</A>.
<P/>

An integer matrix has an integer matrix inverse if and only if it
has determinant one.
<Example><![CDATA[
gap> mat := Matrix(IsIntegerMatrix, [[0, 0, -1],
> [0, 1, 0],
> [1, 0, 0]]);;
gap> mat := Matrix(Integers, [[0, 0, -1],
> [0, 1, 0],
> [1, 0, 0]]);
<3x3-matrix over Integers>
gap> InverseOp(mat);
Matrix(IsIntegerMatrix, [[0, 0, 1], [0, 1, 0], [-1, 0, 0]])
<3x3-matrix over Integers>
gap> mat * InverseOp(mat) = One(mat);
true
]]></Example>
Expand All @@ -211,23 +208,25 @@ true
<Returns><K>true</K> or <K>false</K></Returns>
<Description>
If <A>mat</A> is an integer matrix (i.e. belongs to the
category <Ref Filt = "IsIntegerMatrix"/>), then <C>IsTorsion</C> returns
category <Ref Filt = "Integers"/>), then <C>IsTorsion</C> returns
<K>true</K> if <A>mat</A> is torsion and <K>false</K> otherwise. <P/>

An integer matrix <A>mat</A> is torsion if and only if there exists an
integer <C>n</C> such that <A>mat</A> to the power of <C>n</C> is
equal to the identity matrix.

<Example><![CDATA[
gap> mat := Matrix(IsIntegerMatrix, [[0, 0, -1],
> [0, 1, 0],
> [1, 0, 0]]);;
gap> mat := Matrix(Integers, [[0, 0, -1],
> [0, 1, 0],
> [1, 0, 0]]);
<3x3-matrix over Integers>
gap> IsTorsion(mat);
true
gap> mat := Matrix(IsIntegerMatrix, [[0, 0, -1, 0],
> [0, -1, 0, 0],
> [4, 4, 2, -1],
> [1, 1, 0, 3]]);;
gap> mat := Matrix(Integers, [[0, 0, -1, 0],
> [0, -1, 0, 0],
> [4, 4, 2, -1],
> [1, 1, 0, 3]]);
<4x4-matrix over Integers>
gap> IsTorsion(mat);
false
]]></Example>
Expand All @@ -240,21 +239,20 @@ false
<Attr Name = "Order" Arg = "mat"/>
<Returns>An integer or <C>infinity</C>.</Returns>
<Description>
If <A>mat</A> is an integer matrix (i.e. belongs to the
category <Ref Filt = "IsIntegerMatrix"/>), then <C>InverseOp</C> returns
the order of <A>mat</A>. The order of <A>mat</A> is the smallest integer
power of <A>mat</A> equal to the identity. If no such integer exists,
the order is equal to <C>infinity</C>.
If <A>mat</A> is an integer matrix, then <C>InverseOp</C> returns the
order of <A>mat</A>. The order of <A>mat</A> is the smallest integer
power of <A>mat</A> equal to the identity. If no such integer exists, the
order is equal to <C>infinity</C>.
<Example><![CDATA[
gap> mat := Matrix(IsIntegerMatrix, [[0, 0, -1, 0],
> [0, -1, 0, 0],
> [4, 4, 2, -1],
> [1, 1, 0, 3]]);;
gap> mat := Matrix(Integers, [[0, 0, -1, 0],
> [0, -1, 0, 0],
> [4, 4, 2, -1],
> [1, 1, 0, 3]]);;
gap> Order(mat);
infinity
gap> mat := Matrix(IsIntegerMatrix, [[0, 0, -1],
> [0, 1, 0],
> [1, 0, 0]]);;
gap> mat := Matrix(Integers, [[0, 0, -1],
> [0, 1, 0],
> [1, 0, 0]]);;
gap> Order(mat);
4
]]></Example>
Expand Down
32 changes: 12 additions & 20 deletions doc/semiringmat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
<Ref Filt = "IsProjectiveMaxPlusMatrix"/> and a tropical max-plus
matrix or (non-tropical) max-plus matrix;
</Item> -->
<Item>
<Ref Filt = "IsIntegerMatrix"/> and an ntp matrix.
</Item>
</List>

The version of the operation with arguments <A>filt</A>, <A>mat</A>, and
Expand Down Expand Up @@ -92,8 +89,8 @@ Matrix(IsMaxPlusMatrix, [[-infinity, -infinity, 3], [0, 1, 3],
gap> mat := Matrix(IsNTPMatrix, [[1, 2, 2],
> [0, 2, 0],
> [1, 3, 0]], 4, 5);;
gap> AsMatrix(IsIntegerMatrix, mat);
Matrix(IsIntegerMatrix, [[1, 2, 2], [0, 2, 0], [1, 3, 0]])
gap> Matrix(Integers, mat);
<3x3-matrix over Integers>
gap> mat := Matrix(IsMinPlusMatrix, [[0, 1, 3], [1, 1, 6], [0, 4, 2]]);;
gap> mat := AsMatrix(IsTropicalMinPlusMatrix, mat, 2);
Matrix(IsTropicalMinPlusMatrix, [[0, 1, 2], [1, 1, 2], [0, 2, 2]], 2)
Expand All @@ -120,8 +117,8 @@ gap> mat := AsMatrix(IsNTPMatrix, mat, 2, 6);
Matrix(IsNTPMatrix, [[0, 1, 0], [1, 3, 1], [1, 0, 1]], 2, 6)
gap> mat := AsMatrix(IsNTPMatrix, mat, 2, 1);
Matrix(IsNTPMatrix, [[0, 1, 0], [1, 2, 1], [1, 0, 1]], 2, 1)
gap> mat := AsMatrix(IsIntegerMatrix, mat);
Matrix(IsIntegerMatrix, [[0, 1, 0], [1, 2, 1], [1, 0, 1]])
gap> mat := Matrix(Integers, mat);
<3x3-matrix over Integers>
gap> AsMatrix(IsNTPMatrix, mat, 1, 2);
Matrix(IsNTPMatrix, [[0, 1, 0], [1, 2, 1], [1, 0, 1]], 1, 2)]]></Example>
</Description>
Expand All @@ -144,11 +141,6 @@ Matrix(IsNTPMatrix, [[0, 1, 0], [1, 2, 1], [1, 0, 1]], 1, 2)]]></Example>
underlying list of lists of the matrix over semiring <A>mat</A>.

<Example><![CDATA[
gap> mat := Matrix(IsIntegerMatrix, [[0, 2],
> [3, 5]]);
Matrix(IsIntegerMatrix, [[0, 2], [3, 5]])
gap> AsList(mat);
[ [ 0, 2 ], [ 3, 5 ] ]
gap> mat := Matrix(GF(7), [[Z(7) ^ 3, Z(7) ^ 2],
> [Z(7) ^ 4, Z(7)]]);
Matrix(GF(7), [[Z(7)^3, Z(7)^2], [Z(7)^4, Z(7)]])
Expand Down Expand Up @@ -356,14 +348,14 @@ gap> Matrix(IsNTPMatrix, [[0, 0, 0],
> [2, 2, 2]],
> 2, 1);
Matrix(IsNTPMatrix, [[0, 0, 0], [2, 0, 1], [2, 2, 2]], 2, 1)
gap> Matrix(IsIntegerMatrix, [[-1, -2, 0],
> [0, 3, -1],
> [1, 0, -3]]);
Matrix(IsIntegerMatrix, [[-1, -2, 0], [0, 3, -1], [1, 0, -3]])
gap> Matrix(Integers, [[-1, -2, 0],
> [0, 3, -1],
> [1, 0, -3]]);
Matrix(IsIntegerMatrix, [[-1, -2, 0], [0, 3, -1], [1, 0, -3]])
<3x3-matrix over Integers>
gap> Matrix(Integers, [[-1, -2, 0],
> [0, 3, -1],
> [1, 0, -3]]);
<3x3-matrix over Integers>
]]></Example>
<!-- Another test, for a matrix over a finite field
gap> Matrix(GF(3), [[Z(3), Z(3) ^ 0, Z(3)],
Expand Down Expand Up @@ -443,10 +435,10 @@ Matrix(IsTropicalMinPlusMatrix, [[1, -infinity, -infinity], [1, 1, 1],
[2, 2, 1]], 2)
gap> RandomMatrix(IsNTPMatrix, 3, 2, 5);
Matrix(IsNTPMatrix, [[1, 1, 1], [1, 1, 0], [3, 0, 1]], 2, 5)
gap> RandomMatrix(IsIntegerMatrix, 2);
Matrix(IsIntegerMatrix, [[1, 3], [0, 0]])
gap> RandomMatrix(Integers, 2);
Matrix(IsIntegerMatrix, [[-1, 0], [0, -1]])
Matrix(Integers, [[1, 3], [0, 0]])
gap> RandomMatrix(Integers, 2);
Matrix(Integers, [[-1, 0], [0, -1]])
gap> RandomMatrix(GF(5), 1);
Matrix(GF(5), [[Z(5)^0]])]]></Log>
</Description>
Expand Down
3 changes: 0 additions & 3 deletions gap/elements/ffmat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ DeclareAttribute("LeftInverse", IsMatrixOverFiniteField);
DeclareAttribute("RowRank", IsMatrixOverFiniteField);
DeclareAttribute("BaseDomain", IsMatrixOverFiniteField);

# TODO(later) shouldn't this be IsMultiplicativeZero??
DeclareProperty("IsZero", IsMatrixOverFiniteField);

#############################################################################
## Declarations specifically for finite field matrices collections
#############################################################################
Expand Down
10 changes: 10 additions & 0 deletions gap/elements/ffmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ function(mat, pos)
return IsBound(mat!.mat[pos]);
end);

InstallMethod(MatElm,
"for a plist matrix over finite field positional rep, and two pos ints",
[IsPlistMatrixOverFiniteFieldRep, IsPosInt, IsPosInt],
function(mat, row, col)
if Maximum(row, col) > NumberRows(mat) then
ErrorNoReturn("a position is greater than the dimension of the matrix");
fi;
return mat!.mat[row][col];
end);

# This is here to silence some GAP tests when Semigroups is loaded
# and should become rendundant once the GAP MatrixObj code works
InstallOtherMethod(TraceMat, "for a plist matrix over finite field",
Expand Down
21 changes: 4 additions & 17 deletions gap/elements/maxplusmat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
# This file contains declarations for max-plus, min-plus, tropical max-plus,
# tropical min-plus matrices, and natural number matrices.

DeclareProperty("IsTorsion", IsMatrixObj);
DeclareOperation("Matrix", [IsIntegers, IsTransformation]);
DeclareOperation("Matrix", [IsIntegers, IsTransformation, IsPosInt]);

#############################################################################
## 1. Max-plus matrices
#############################################################################
Expand Down Expand Up @@ -125,20 +129,3 @@ BindGlobal("NTPMatrixType",

DeclareAttribute("ThresholdNTPMatrix", IsNTPMatrix);
DeclareAttribute("PeriodNTPMatrix", IsNTPMatrix);

#############################################################################
## 8. Integer matrices
#############################################################################

DeclareCategory("IsIntegerMatrix",
IsMatrixOverSemiring
and IsPlistMatrixOverSemiringPositionalRep);
DeclareCategoryCollections("IsIntegerMatrix");
DeclareCategoryCollections("IsIntegerMatrixCollection");

BindGlobal("IntegerMatrixType",
NewType(NewFamily("IntegerMatrixFamily",
IsIntegerMatrix,
CanEasilySortElements,
CanEasilySortElements),
IsIntegerMatrix));
Loading

0 comments on commit ac790ca

Please sign in to comment.