Skip to content

Commit

Permalink
Add docstrings for various map construction functions (#1431)
Browse files Browse the repository at this point in the history
Also include jldoctests for each, and fix a bug in the
printing of IdentityMap instances.
  • Loading branch information
fingolfin authored Sep 13, 2023
1 parent 15764fd commit 02884f3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
17 changes: 1 addition & 16 deletions docs/src/functional_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ a Julia function/closure implementing the map.

Such maps can be constructed using the following function:

```julia
```@docs
map_from_func(f::Function, R, S)
```

Construct the generic functional map with domain and codomain given by the parent objects
$R$ and $S$ corresponding to the Julia function $f$.

**Examples**

```jldoctest
julia> f = map_from_func(x -> x + 1, ZZ, ZZ)
Map defined by a Julia function
from integers
to integers
julia> f(ZZ(2))
3
```
12 changes: 6 additions & 6 deletions docs/src/map_interface.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
```@meta
CurrentModule = AbstractAlgebra
DocTestSetup = :(using AbstractAlgebra)
DocTestSetup = quote
using AbstractAlgebra
end
```

# Map Interface
Expand Down Expand Up @@ -166,7 +168,7 @@ map are identity maps on the same domain.
To construct an identity map for a given domain, specified by a parent object `R`, say,
we have the following function.

```julia
```@docs
identity_map(R::Set)
```

Expand All @@ -189,12 +191,10 @@ should be applied.

To construct a composition map from two existing maps, we have the following function:

```julia
compose(f::Map{D, U}, g::Map{U, C}) where {D, U, C}
```@docs
compose(f::Map, g::Map)
```

Compose the two maps $f$ and $g$, i.e. return the map $h$ such that $h(x) = g(f(x))$.

As a shortcut for this function we have the following operator:

```julia
Expand Down
52 changes: 52 additions & 0 deletions src/Map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ end
#
###############################################################################

@doc raw"""
compose(f::Map, g::Map)
Compose the two maps $f$ and $g$, i.e. return the map $h$ such that $h(x) = g(f(x))$.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> f = map_from_func(x -> x + 1, ZZ, ZZ);
julia> g = map_from_func(x -> QQ(x), ZZ, QQ);
julia> h = compose(f, g)
Functional composite map
first map: integers -> integers
next map: integers -> rationals
```
"""
function compose(f::Map, g::Map)
check_composable(f, g)
return Generic.CompositeMap(f, g)
Expand All @@ -40,6 +57,24 @@ end
#
################################################################################

@doc raw"""
identity_map(R::D) where D <: AbstractAlgebra.Set
Return an identity map on the domain $R$.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> R, t = ZZ[:t]
(Univariate polynomial ring in t over integers, t)
julia> f = identity_map(R)
Identity map
of univariate polynomial ring in t over integers
julia> f(t)
t
```
"""
identity_map(R::D) where D <: AbstractAlgebra.Set = Generic.IdentityMap{D}(R)

################################################################################
Expand All @@ -48,6 +83,23 @@ identity_map(R::D) where D <: AbstractAlgebra.Set = Generic.IdentityMap{D}(R)
#
################################################################################

@doc raw"""
map_from_func(image_fn::Function, domain, codomain)
Construct the generic functional map with domain and codomain given by the parent objects
$R$ and $S$ corresponding to the Julia function $f$.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> f = map_from_func(x -> x + 1, ZZ, ZZ)
Map defined by a Julia function
from integers
to integers
julia> f(ZZ(2))
3
```
"""
function map_from_func(image_fn::Function, domain, codomain)
return Generic.FunctionalMap(domain, codomain, image_fn)
end
Expand Down
2 changes: 1 addition & 1 deletion src/generic/Map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ codomain(f::IdentityMap) = f.domain

function show(io::IO, ::MIME"text/plain", M::IdentityMap)
io = pretty(io)
println("Identity map")
println(io, "Identity map")
print(io, Indent(), "of ", Lowercase())
show(io, MIME("text/plain"), domain(M))
print(io, Dedent())
Expand Down

0 comments on commit 02884f3

Please sign in to comment.