-
Notifications
You must be signed in to change notification settings - Fork 8
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
More inverses? #12
Comments
I think this would fit in InverseFunctions, in principle. How many of these do you think there would be? |
I had a closer look at JuliaObjects/Accessors.jl#46 - I think the We should change our current definition @devmotion any objections? |
I'm not sure if this should be done. There are other possible choices such as |
Oh, you're right - sorry, I any case we could certainly define things like inverse(f::Base.Fix2{typeof(^)}) = Base.Fix2(^, inv(f.x)) right? The list of inverses proposed in JuliaObjects/Accessors.jl#46 is quite finite, I don't think they would bloat InverseFunctions too much (and can't be defined outside of it without type piracy, of course). |
|
True. Maybe best we keep |
For real numbers, I think the arguably most natural choice would be leftinverse(::typeof(sqrt)) = abs2 I am aware that it does not work in general (and I was sure someone would mention it 😄) but it would be nice to be able to use it for |
Maybe we should continue that one on #10? :-) |
I like the symmetry of inverse(f::Base.Fix1{typeof(^)}) = Base.Fix1(log, f.x))
inverse(f::Base.Fix2{typeof(^)}) = Base.Fix2(^, inv(f.x)) and so on for |
This raises the point that it might not be sufficient to know the name of the function to define the inverse. One might also need to know the domain, as defined by the type of the input. Of course, some inputs may not store their constraints in their type, so the inverse may depend on the value itself. |
Or put another way, different methods of the same function may require different inverses, and those inverses may not be different methods of the same function. |
In the context of
But this loses the nice symmetry, and requires defining separate function for these inverses to perform argument checks. |
That's a whole different level, though. :-) |
The main problem is that this is incorrect and problematic in the same sense as If one considers the maximum support on the real line in all cases, then inverse(f::Base.Fix2{typeof(^)}) = Base.Fix2(^, inv(f.x)) # incorrect e.g. if `f.x = 2` or `f.x = 1/2`
leftinverse(f::Base.Fix2{typeof(^)}) = Base.Fix2(^, inv(f.x)) # incorrect e.g. if `f.x = 2`
rightinverse(f::Base.Fix2{typeof(^)}) = Base.Fix2(^, inv(f.x)) # incorrect e.g. if `f.x = 1/2` would be correct in general. |
What definition of the right inverse do you use here? Still I agree it may be cleaner to throw an exception in f when the argument is outside of the range of the corresponding g: see my previous comment. This requires defining a few separate functions to only serve as inverses, but maybe there is nothing really wrong with it... |
Ah yes, sorry, I messed it up. In general, it is highly dependent on the choice of domain and codomain though.
Similarly, We can consider other domains and codomains as well. Eg., the inverse of |
Hmhm, we may need to do something in the direction of #8. Having |
Do you consider inverses to two-argument Julia Base functions in scope of this package? For example:
Originally, this came up in JuliaObjects/Accessors.jl#46, but can be useful elsewhere as well.
The text was updated successfully, but these errors were encountered: