Constructing matrices over finite fields silently fails if multiplicative generator not used
Bonsoir, not sure if this is related to any of the other recent `GF` matrix bugs, but there seems to be a silent failure to construct a matrix over a finite field if the multiplicative element is not used in the second argument.
To see what I mean, consider the following example:
```gap
gap> A := Matrix(GF(2), [[1, 1, 1], [0, 1, 1], [0, 0, 1]]);
[ [ 1, 1, 1 ], [ 0, 1, 1 ], [ 0, 0, 1 ] ]
gap> A^-1;
[ [ 1, -1, 0 ], [ 0, 1, -1 ], [ 0, 0, 1 ] ]
gap> A[1][1] in GF(2);
false
gap> B := Matrix(GF(2), Z(2)^0*[[1, 1, 1], [0, 1, 1], [0, 0, 1]]);
<a 3x3 matrix over GF2>
gap> B^-1;
<a 3x3 matrix over GF2>
gap> Display(B^-1);
1 1 .
. 1 1
. . 1
gap> B[1][1] in GF(2);
true
```
Despite the underlying semiring `GF(2)` being specified in the first component, since `Z(2)` is not used to define the matrix `A`, the resulting matrix is not a matrix over semiring object at all. This is a silent failure and quite an unintuitive footgun. Not sure if this is a bug or just a case of me holding it wrong, but the result is very unintuitive and can lead to hard to debug errors further down the line.
I think the fix might be to either:
1. Raise an error if the matrix in the second component of `Matrix(GF(p^d), A)` does not have all its elements in `GF(p^d)` or
2. Automatically multiply the matrix in the second component by `Z(p^d)^0`.
I think 2. might be more user friendly, but there might be some hidden cost or subtle mathematical nuance I'm missing.
Initially filed as https://github.com/semigroups/Semigroups/issues/1186
关闭于 2026-05-17 3 条评论