Map from julia functions

For the situation where it is desirable to create a Map given arbitrary callable julia objects (like anonymous functions), the type MapFromFunc is provided.

MapFromFuncType
MapFromFunc(f, [g], D, C)

Creates the map D -> C, x -> f(x) given the callable object f. If g is provided, it is assumed to satisfy f(g(x)) = x and will be used as the preimage function.

Example

julia> F = GF(2);

julia> f = MapFromFunc(x -> F(numerator(x)) * inv(F(denominator(x))), QQ, F)
Map from
Rational field to Finite field of characteristic 2 defined by a julia-function

julia> f(QQ(1//3))
1

julia> f = MapFromFunc(x -> F(numerator(x)) * inv(F(denominator(x))), y -> QQ(lift(y)),  QQ, F)
Map from
Rational field to Finite field of characteristic 2 defined by a julia-function with inverse

julia> preimage(f, F(1))
1
Note

When applying an object f of type MapFromFunc to an element x, it will be checked whether the parent of x coincides with the domain and whether the parent of f(x) coincides with the codomain of f. Similar for the optional preimage function.