As mentioned above, GAP does not check unknown properties to test whether a method might be applicable. In some cases one wants to enforce this, however, because the gain from knowing the property outweights the cost of its determination.
In this situation one has to install a method without the additional
property (so it can be tried even if the property is not yet known) and at high
rank (so it will be used before other methods). The first thing to do in the
actual function then is to test the property and to bail out with
TryNextMethod() if it turns out to be false.
The above Exponent example thus would become:
InstallMethod(Exponent,"test abelianity", [IsGroup],
50,# enforced high rank
function(G)
if not IsAbelian(G) then
TryNextMethod();
fi;
[remaining function body omitted]
end);
The value ``50'' used in this example is quite arbitrary. A better way is to
use values that are given by the system inherently: We want this method
still to be ranked as high, as if it had the IsAbelian requirement. So
we have GAP compute the extra rank of this:
InstallMethod(Exponent,"test abelianity", [IsGroup], # enforced absolute rank of `IsGroup and IsAbelian' installation: Subtract # the rank of `IsGroup' and add the rank of `IsGroup and IsAbelian': SIZE_FLAGS(FLAGS_FILTER(IsGroup and IsAbelian)) -SIZE_FLAGS(FLAGS_FILTER(IsGroup)), function(G)the slightly complicated construction of addition and subtraction is necessary because
IsGroup and IsAbelian might imply the same
elementary filters which we otherwise would count twice.
A somehow similar situation occurs with matrix groups. Most methods for matrix groups are only applicable if the group is known to be finite.
However we should not enforce a finiteness test early (someone else later might install good methods for infinite groups while the finiteness test would be too expensive) but just before GAP would give a ``no method found'' error. This is done by redispatching, see Redispatching. For example to enforce such a final finiteness test for normalizer calculations could be done by:
RedispatchOnCondition(NormalizerOp,IsIdenticalObj, [IsMatrixGroup,IsMatrixGroup],[IsFinite,IsFinite],0);
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual