I'm in the process of moving MapFromFunc from Hecke into AbstractAlgebra as a replacement for Generic.FunctionalMap and I'm running into some problems with how images are computed using image_fn.
It seems like throughout AA/Nemo/Hecke, often the image of an element a under a map m is computed by calling image_fn(m)(a). But not all Map types have a defined image_fn method, this is only guaranteed for <: FunctionalMap. For example, when we compose two arbitrary maps we get a Generic.CompositeMap which has no image_fn, though we can compute images with it.
This leads to further problems when a Map type wraps another Map, for example a MapWithSection or MapWithRetraction f can wrap an arbitrary map::AbstractAlgebra.Map, and then image_fn(f) = image_fn(f.map); in some ways this is fine, we just get an error if there is not a defined image_fn, except if we want to compute f(a) it delegates to image_fn(f)(a) which will throw an error.
I see a couple of possible solutions:
- the
HeckeMap type has a fallback, if there is not an image_function stored then it just creates one
function image_function(f::Map(HeckeMap))
if isdefined(f.header, :image)
return f.header.image
else
return x -> image(f, x)
end
end
and we could just do this for arbitrary maps as well.
- maybe a better solution is just not to compute images using
image_fn by default, especially for map types that wrap other maps. For example, I am working around the issues with MapWithSection/MapWithRetraction/CompositeMap by applying the wrapped maps directly instead of using image_fn, but I find this issue also in Nemo (FinFieldMorphism and FinFieldPreimage). Actually I only find one instance in Hecke or using image_fn and none in Oscar.
TL;DR : Do we need to make sure that every Map can return an image_fn? Or should we instead be more careful to avoid using image_fn to compute images when we aren't sure this method will be defined?
I'm in the process of moving
MapFromFuncfrom Hecke into AbstractAlgebra as a replacement forGeneric.FunctionalMapand I'm running into some problems with how images are computed usingimage_fn.It seems like throughout AA/Nemo/Hecke, often the image of an element
aunder a mapmis computed by callingimage_fn(m)(a). But not allMaptypes have a definedimage_fnmethod, this is only guaranteed for<: FunctionalMap. For example, when we compose two arbitrary maps we get aGeneric.CompositeMapwhich has noimage_fn, though we can compute images with it.This leads to further problems when a
Maptype wraps anotherMap, for example aMapWithSectionorMapWithRetractionfcan wrap an arbitrarymap::AbstractAlgebra.Map, and thenimage_fn(f) = image_fn(f.map); in some ways this is fine, we just get an error if there is not a definedimage_fn, except if we want to computef(a)it delegates toimage_fn(f)(a)which will throw an error.I see a couple of possible solutions:
HeckeMaptype has a fallback, if there is not animage_functionstored then it just creates oneand we could just do this for arbitrary maps as well.
image_fnby default, especially for map types that wrap other maps. For example, I am working around the issues withMapWithSection/MapWithRetraction/CompositeMapby applying the wrapped maps directly instead of usingimage_fn, but I find this issue also in Nemo (FinFieldMorphismandFinFieldPreimage). Actually I only find one instance inHeckeor usingimage_fnand none in Oscar.TL;DR : Do we need to make sure that every
Mapcan return animage_fn? Or should we instead be more careful to avoid usingimage_fnto compute images when we aren't sure this method will be defined?