Map with inverse
It is not possible to provide generic functionality to invert a map. However, sometimes one knows an inverse map explicitly and would like to keep track of this.
Recall that as map composition is not commutative, there is a notion of a left inverse and a right inverse for maps.
To keep track of such inverse maps, AbstractAlgebra provides data types Generic.MapWithRetraction and Generic.MapWithSection.
Given a map $f : X \to Y$, a retraction of $f$ is a map $g : Y \to X$ such that $g(f(x)) = x$ for all $x \in X$.
Given a map $f : X \to Y$, a section of $f$ is a map $g : Y \to X$ such that $f(g(x)) = x$ for all $y \in Y$.
In AbstractAlgebra, a map with retraction/section is an object containing a pair of maps, the second of which is a retraction/section of the first.
Maps with retraction/section can be composed, and we also define the inverse of such a pair to be the map with the pair swapped. Thus the inverse of a map with retraction is a map with section.
Map with inverse constructors
To construct a map with retraction/section from a pair of maps, we have the following functions:
AbstractAlgebra.map_with_retraction — Function
map_with_retraction(f::Map{D, C}, r::Map{C, D}) where {D, C}Return the map f together with a known retraction r of it, i.e. a map with $r(f(x)) = x$ for all $x$ in the domain of f.
AbstractAlgebra.map_with_section — Function
map_with_section(f::Map{D, C}, s::Map{C, D}) where {D, C}Return the map f together with a known section s of it, i.e. a map with $f(s(y)) = y$ for all $y$ in the codomain of f.
For convenience we allow construction of maps with retraction/section from a pair of Julia functions/closures.
AbstractAlgebra.map_with_retraction_from_func — Function
map_with_retraction_from_func(f::Function, r::Function, R, S)Return the map from R to S given by the Julia function f, together with the retraction given by the Julia function r. See map_with_retraction.
Examples
julia> f = map_with_retraction_from_func(x -> x + 1, x -> x - 1, ZZ, ZZ)
Map with retraction
from integers
to integers
julia> f(ZZ(1))
2AbstractAlgebra.map_with_section_from_func — Function
map_with_section_from_func(f::Function, s::Function, R, S)Return the map from R to S given by the Julia function f, together with the section given by the Julia function s. See map_with_section.
Functionality for maps with inverses
The following functionality is provided for maps with inverses.
inv(M::Generic.MapWithRetraction)
inv(M::Generic.MapWithSection)Return the map with the two maps contained in $M$ swapped. In the first case, a MapWithSection is returned. In the second case a MapWithRetraction is returned.
Examples
julia> f = map_with_retraction_from_func(x -> x + 1, x -> x - 1, ZZ, ZZ)
Map with retraction
from integers
to integers
julia> g = inv(f)
Map with section
from integers
to integers
julia> h = f*g
Composite map
from integers
to integers
which is the composite of
Map: integers -> integers
Map: integers -> integers
julia> h(ZZ(1))
1To access the two maps stored in a map with retraction/section, we have the following:
AbstractAlgebra.Generic.image_map — Function
image_map(f::Union{Generic.MapWithSection, Generic.MapWithRetraction})Return the underlying map of f, i.e. f stripped of its section resp. retraction.
AbstractAlgebra.Generic.retraction_map — Function
retraction_map(f::Generic.MapWithRetraction)Return the retraction stored in f. See map_with_retraction.
AbstractAlgebra.Generic.section_map — Function
section_map(f::Generic.MapWithSection)Return the section stored in f. See map_with_section.