diff --git a/Project.toml b/Project.toml index 6d6c83e..dac2530 100644 --- a/Project.toml +++ b/Project.toml @@ -2,9 +2,6 @@ name = "InverseFunctions" uuid = "3587e190-3f89-42d0-90ee-14403ec27112" version = "0.1.12" -[deps] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - [compat] julia = "1" diff --git a/src/InverseFunctions.jl b/src/InverseFunctions.jl index 0c5438b..bf333b9 100644 --- a/src/InverseFunctions.jl +++ b/src/InverseFunctions.jl @@ -6,11 +6,11 @@ Lightweight package that defines an interface to invert functions. """ module InverseFunctions -using Test include("functions.jl") include("inverse.jl") include("setinverse.jl") +include("partinverse.jl") include("test.jl") end # module diff --git a/src/partinverse.jl b/src/partinverse.jl new file mode 100644 index 0000000..dbc79e2 --- /dev/null +++ b/src/partinverse.jl @@ -0,0 +1,38 @@ +# default methods for when an inverse exists +export r_inv, l_inv, retraction, coretraction + +""" + r_inv(function) + retraction(function) + +Return the left inverse of a function, i.e. a function that "undoes" `f`. Formally, + ``\\text{retraction}(f)(f(x)) = x`` +""" +r_inv(args...; kwargs...) = inverse(args...; kwargs...) + +""" + l_inv(function) + coretraction(function) + +Return the right inverse of a function, i.e. a function that can be "undone" by applying +`f`. Formally, +``f(\\text{coretraction}(f)(x)) = x`` +""" +l_inv(args...; kwargs...) = inverse(args...; kwargs...) + +# synonyms common in category theory +# coretractions are often called "section"s, but name is likely too generic +retraction = r_inv +coretraction = l_inv + +# Generate trig and htrig inverses +let trigfuns = ("sin", "cos", "tan", "sec", "csc", "cot") + # regular, degrees, hyperbolic + funcs = (trigfuns..., (trigfuns .* "d")..., (trigfuns .* "h")...) + invfuncs = "a" .* funcs + funcs, invfuncs = Symbol.(funcs), Symbol.(invfuncs) + for (func, invfunc) in zip(funcs, invfuncs) + @eval l_inv(::typeof($func)) = $invfunc + @eval r_inv(::typeof($invfunc)) = $func + end +end