Skip to content

Some issues around image_fn #2453

Description

@mjrodgers

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions