1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
TestZeroVector := function(filt, ring, len)
local i, vec, vec2;
vec := ZeroVector(filt, ring, len);
Assert(0, filt(vec) = true);
Assert(0, BaseDomain(vec) = ring);
Assert(0, Length(vec) = len);
for i in [1..len] do
if not IsZero(vec[i]) then Error("entry ", i," is ", vec[i], " and not zero"); fi;
od;
vec2 := ZeroVector(len, vec);
if vec <> vec2 then Error("ZeroVector(len, vec) differs"); fi;
vec2 := NewZeroVector(filt, ring, len);
if vec <> vec2 then Error("NewZeroVector(filt, ring, len) differs"); fi;
return vec;
end;
TestZeroMatrix := function(filt, ring, rows, cols)
local i, j, mat, mat2;
mat := ZeroMatrix(filt, ring, rows, cols);
Assert(0, filt(mat) = true);
Assert(0, BaseDomain(mat) = ring);
Assert(0, NrRows(mat) = rows);
Assert(0, NrCols(mat) = cols);
for i in [1..rows] do
for j in [1..cols] do
if not IsZero(mat[i,j]) then Error("entry ", i,",",j," is ", mat[i,j], " and not zero"); fi;
od;
od;
mat2 := ZeroMatrix(rows, cols, mat);
if mat <> mat2 then Error("ZeroMatrix(rows, cols, mat) differs"); fi;
mat2 := NewZeroMatrix(filt, ring, rows, cols);
if mat <> mat2 then Error("NewZeroMatrix(filt, ring, rows, cols) differs"); fi;
return mat;
end;
TestIdentityMatrix := function(filt, ring, degree)
local i, j, mat, mat2;
mat := IdentityMatrix(filt, ring, degree);
Assert(0, filt(mat) = true);
Assert(0, BaseDomain(mat) = ring);
Assert(0, NrRows(mat) = degree);
Assert(0, NrCols(mat) = degree);
for i in [1..degree] do
for j in [1..degree] do
if i<>j and not IsZero(mat[i,j]) then
Error("entry ", i,",",j," is not zero");
elif i=j and not IsOne(mat[i,j]) then
Error("diagonal entry ", i,",",j," is not one");
fi;
od;
od;
mat2 := IdentityMatrix(degree, mat);
if mat <> mat2 then Error("IdentityMatrix(degree, mat) differs"); fi;
mat2 := NewIdentityMatrix(filt, ring, degree);
if mat <> mat2 then Error("NewIdentityMatrix(filt, ring, degree) differs"); fi;
return mat;
end;
TestCompanionMatrix := function(filt, pol, ring)
local degree, mat, i, j, mat2;
degree:= Degree(pol);
mat:= CompanionMatrix(filt, pol, ring);
Assert(0, filt(mat) = true);
Assert(0, BaseDomain(mat) = ring);
Assert(0, NrRows(mat) = degree);
Assert(0, NrCols(mat) = degree);
for i in [1..degree] do
for j in [1..degree-1] do
if i <> j+1 and not IsZero(mat[i,j]) then
Error("entry ", i,",",j," is not zero");
elif i = j+1 and not IsOne(mat[i,j]) then
Error("entry ", i,",",j," is not one");
fi;
od;
od;
mat2 := CompanionMatrix(pol, mat);
if mat <> mat2 then Error("CompanionMatrix(pol, mat) differs"); fi;
mat2 := NewCompanionMatrix(filt, pol, ring);
if mat <> mat2 then Error("NewCompanionMatrix(filt, pol, ring) differs"); fi;
return mat;
end;
TestElementaryTransforms := function(mat, scalar)
local i, j, copy, eq;
Assert(0, NrRows(mat) >= 2);
Assert(0, NrCols(mat) >= 2);
# make an old-fashioned entry-wise copy of this matrix so we can compare
# all changes made there independent of any special properties of the
# matrix representation
copy := [];
for i in [1..NrRows(mat)] do
copy[i] := [];
for j in [1..NrCols(mat)] do
copy[i,j] := mat[i,j];
od;
od;
eq := function()
local i, j;
for i in [1..NrRows(mat)] do
for j in [1..NrCols(mat)] do
if copy[i,j] <> mat[i,j] then
return false;
fi;
od;
od;
return true;
end;
#
#
#
for i in [1..NrRows(mat)] do
MultMatrixRowLeft(mat,i,scalar);
MultMatrixRowLeft(copy,i,scalar);
if not eq() then Error("MultMatrixRowLeft(",i,",",scalar,") failure"); fi;
od;
for i in [1..NrRows(mat)] do
MultMatrixRowRight(mat,i,scalar);
MultMatrixRowRight(copy,i,scalar);
if not eq() then Error("MultMatrixRowRight(",i,",",scalar,") failure"); fi;
od;
for i in [1..NrCols(mat)] do
MultMatrixColumnLeft(mat,i,scalar);
MultMatrixColumnLeft(copy,i,scalar);
if not eq() then Error("MultMatrixColumnLeft(",i,",",scalar,") failure"); fi;
od;
for i in [1..NrCols(mat)] do
MultMatrixColumnRight(mat,i,scalar);
MultMatrixColumnRight(copy,i,scalar);
if not eq() then Error("MultMatrixColumnRight(",i,",",scalar,") failure"); fi;
od;
#
#
#
for i in [1..NrRows(mat)] do
for j in [1..NrRows(mat)] do
AddMatrixRowsLeft(mat,i,j,scalar);
AddMatrixRowsLeft(copy,i,j,scalar);
if not eq() then Error("AddMatrixRowsLeft(",i,",",j,",",scalar,") failure"); fi;
od;
od;
for i in [1..NrRows(mat)] do
for j in [1..NrRows(mat)] do
AddMatrixRowsRight(mat,i,j,scalar);
AddMatrixRowsRight(copy,i,j,scalar);
if not eq() then Error("AddMatrixRowsRight(",i,",",j,",",scalar,") failure"); fi;
od;
od;
for i in [1..NrCols(mat)] do
for j in [1..NrCols(mat)] do
AddMatrixColumnsLeft(mat,i,j,scalar);
AddMatrixColumnsLeft(copy,i,j,scalar);
if not eq() then Error("AddMatrixColumnsLeft(",i,",",j,",",scalar,") failure"); fi;
od;
od;
for i in [1..NrCols(mat)] do
for j in [1..NrCols(mat)] do
AddMatrixColumnsRight(mat,i,j,scalar);
AddMatrixColumnsRight(copy,i,j,scalar);
if not eq() then Error("AddMatrixColumnsRight(",i,",",j,",",scalar,") failure"); fi;
od;
od;
#
#
#
for i in [1..NrRows(mat)] do
for j in [1..NrRows(mat)] do
SwapMatrixRows(mat,i,j);
SwapMatrixRows(copy,i,j);
if not eq() then Error("SwapMatrixRows(",i,",",j,") failure"); fi;
od;
od;
for i in [1..NrCols(mat)] do
for j in [1..NrCols(mat)] do
SwapMatrixColumns(mat,i,j);
SwapMatrixColumns(copy,i,j);
if not eq() then Error("SwapMatrixColumns(",i,",",j,") failure"); fi;
od;
od;
end;
|