Skip to content

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(D, C, f, [g])

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(QQ, F, x -> F(numerator(x)) * inv(F(denominator(x))))
Map defined by a julia-function
  from rational field
  to prime field of characteristic 2

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

julia> println(f)
Map: QQ -> GF(2)

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

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

julia> println(f)
Map: QQ -> GF(2)

source

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.