gap> A := Matrix(Integers, [
> [1, 2, 3],
> [4, 3, -1],
> [1, 0, -3]]);
<3x3-matrix over Integers>
gap> B := Matrix(Integers, [
> [1, -1, 0],
> [0, 0, 1],
> [1, 0, 1]]);
<3x3-matrix over Integers>
gap> C := Matrix(Integers, [
> [0, 0, 0],
> [0, 1, -1],
> [1, 0, 1]]);
<3x3-matrix over Integers>
gap> A^-1;
Error, the elements in <list> must lie in <basedomain>
*[1] Error( "the elements in <list> must lie in <basedomain>" );
@ /Users/rcirpons/Desktop/Source/gap/lib/matobjplist.gi:90
[2] MakeIsPlistVectorRep( v![1], list, true )
@ /Users/rcirpons/Desktop/Source/gap/lib/matobjplist.gi:319
[3] Vector( list[i], t )
@ /Users/rcirpons/Desktop/Source/gap/lib/matobjplist.gi:687
[4] Matrix( n, Length( n ), M )
@ /Users/rcirpons/Desktop/Source/gap/lib/matobjplist.gi:1215
<function "InverseSameMutability [ IsPlistMatrixRep ]">( <arguments> )
called from read-eval loop at *stdin*:160
you can 'quit;' to quit to outer loop, or
you can 'return;' to continue
brk> quit;
gap> Display(B ^ -1);
<3x3-matrix over Integers:
[[ 0, -1, 1 ]
[ -1, -1, 1 ]
[ 0, 1, 0 ]
]>
gap> C^-1;
fail
I think the correct behavior would be to simply fail if the inverse is not an integer matrix. This can be checked rather easily, since
an integer matrix is invertible with an inverse lying in the integers precisely when the determinant is +1 or -1. So probably adding
this check prior to trying to invert, and returning fail if it is not +1 or -1 is the simplest fix. At the very least we should document this behavior if this is intended.
Consider the following 3 examples:
Inverting
Athrows, however invertingBsucceeds and invertingCfails but does not throw.The error for
Aseems to be thrown sinceAis invertible over the rationals but not the integers, and themethod seems to be trying to cast the rational inverse to an integer matrix, which understandably fails.
I think the correct behavior would be to simply fail if the inverse is not an integer matrix. This can be checked rather easily, since
an integer matrix is invertible with an inverse lying in the integers precisely when the determinant is +1 or -1. So probably adding
this check prior to trying to invert, and returning fail if it is not +1 or -1 is the simplest fix. At the very least we should document this behavior if this is intended.