Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Inverses #39

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name = "InverseFunctions"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.12"

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be removed. Can you revert this?


[compat]
julia = "1"

Expand Down
2 changes: 1 addition & 1 deletion src/InverseFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 38 additions & 0 deletions src/partinverse.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# default methods for when an inverse exists
export r_inv, l_inv, retraction, coretraction

"""
r_inv(function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a more descriptive name and also be consistent with inverse. I suggest

Suggested change
r_inv(function)
right_inverse(function)

retraction(function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need an alias? I prefer a simple API and would suggest defining only right_inverse.

Suggested change
retraction(function)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, right_inverse and left_inverse would be best, I think.


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...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r_inv(args...; kwargs...) = inverse(args...; kwargs...)
right_inverse(args...; kwargs...) = inverse(args...; kwargs...)


"""
l_inv(function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same hee, I think we should use only the name

Suggested change
l_inv(function)
left_inverse(function)

coretraction(function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
l_inv(args...; kwargs...) = inverse(args...; kwargs...)
left_inverse(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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
retraction = r_inv

(BTW aliases should be defined with const)

coretraction = l_inv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
coretraction = l_inv


# Generate trig and htrig inverses
let trigfuns = ("sin", "cos", "tan", "sec", "csc", "cot")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's simpler to loop over these functions:

Suggested change
let trigfuns = ("sin", "cos", "tan", "sec", "csc", "cot")
for trigfunc in ("sin", "cos", "tan", "sec", "csc", "cot")

# regular, degrees, hyperbolic
funcs = (trigfuns..., (trigfuns .* "d")..., (trigfuns .* "h")...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for broadcasting and splatting, just loop over them:

Suggested change
funcs = (trigfuns..., (trigfuns .* "d")..., (trigfuns .* "h")...)
for func in (trigfunc, trigfunc * "d", trigfunc * "h")

invfuncs = "a" .* funcs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invfuncs = "a" .* funcs
invfunc = "a" * func

funcs, invfuncs = Symbol.(funcs), Symbol.(invfuncs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
funcs, invfuncs = Symbol.(funcs), Symbol.(invfuncs)

for (func, invfunc) in zip(funcs, invfuncs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (func, invfunc) in zip(funcs, invfuncs)

@eval l_inv(::typeof($func)) = $invfunc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@eval l_inv(::typeof($func)) = $invfunc
@eval left_inverse(::typeof($func)) = $invfunc

@eval r_inv(::typeof($invfunc)) = $func
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@eval r_inv(::typeof($invfunc)) = $func
@eval right_inverse(::typeof($invfunc)) = $func

end
end
Loading