[GAP Forum] InstallMethod
Stefan Kohl
kohl at mathematik.uni-stuttgart.de
Wed Dec 10 09:55:02 GMT 2003
Dear Forum,
Hubert Kiechle wrote:
> I want to invert 2x2 matrices over a (finite) algebra with zero
> divisors. As there does not seem to be a method available, I tried to
> provide one, but the following file
> after *Read*ing into gap leads to the ERROR message below which seems
> cryptic to me. In fact, after *return*ing from the break loop
> *Inverse* works perfectly well.
>
> How can I get rid of the ERROR message?
> Why is there no method for *Inverse* in matrix rings over rings with
> zero divisors?
>
> ----- file ----
> Inv22:=function(m)
> local u;
> if DimensionsMat(m)=[2,2] then
> u:=Determinant(m);
> if IsUnit(u) then
> return Inverse(u)*[[m[2][2],-m[1][2]],[-m[2][1],m[1][1]]];
> else
> return fail;
> fi;
> else
> return fail;
> fi;
> end;
>
> InstallMethod( Inverse,
> "Inverse of 2x2 Matrix over any Ring",
> [IsMatrix and IsRingElementCollColl],Inv22);
>
> ---------
> Error, required filters [ "IS_LIST", "IS_DENSE_LIST", "IS_HOMOG_LIST",
[ ... ]
The reason for the error message you got is that `InstallMethod' checks
whether the required filters of your method match the declaration of
the attribute `InverseImmutable', for which `Inverse' is a synonym.
You can find these declarations in lib/arith.gd:
DeclareAttribute( "InverseImmutable", IsMultiplicativeElementWithInverse );
DeclareSynonymAttr( "Inverse", InverseImmutable );
In your case, the requirement `IsMatrix and IsRingElementCollColl' does not
imply the filter `IsMultiplicativeElementWithInverse' (as there are also non-invertible
matrices), although the attribute `InverseImmutable' is only declared for such
`multiplicative elements with inverse'.
You can circumvent these strict checks by using `InstallOtherMethod' instead of
`InstallMethod'.
In any case you should issue `TryNextMethod();' instead of returning `fail'
in case your matrix is not 2x2 -- otherwise you likely break other functionality,
in particular you might run into trouble when trying to invert matrices larger
than 2x2 after your method installation. This will happen whenever the
method selection ranks your method highest.
You might also think about whether you want to get a mutable or an immutable
result (see the reference manual for a description of mutability / immutability) --
in the former case you should install your method for `InverseMutable',
and in the latter case you should return an immutable object.
Hope this helps,
Stefan Kohl
More information about the Forum
mailing list