-
Notifications
You must be signed in to change notification settings - Fork 146
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
Complex derivative of power fails #514
Comments
It looks like Using |
Yes, I found out that that works. Now I only need to figure out if I want |
Isn't this a dup of #486? |
This appears to be "fixed" in 1.7: it doesn't give an error, but it gives wrong results (which is worse). The issue is relatively subtle: the derivative at real numbers in complex directions is wrong:
yields 1 and 6 respectively. Where should this be fixed? Here? In DiffRules? |
Pinging @devmotion because of the recent complex numbers PR (which doesn't fix this issue) |
I didn't follow this issue bit can have a look. Does ForwardDiff use DiffRules for these calculations here? If yes, then it should be possible to obtain these incorrect derivatives without ForwardDiff by just evaluating the corresponding DiffRules definition (since we don't do anything special and just use these rules here). The recent PR just fixed a bug with rules that return |
I don't think so:
By contrast the real version (without the |
To reiterate, this is a pretty nasty bug, I know several people who've been bitten by this now. The simplest way forward here is to merge JuliaDiff/DiffRules.jl#37 or something like it, then define rules for |
The behaviour of the examples listed above on ForwardDiff#master is: julia> ∂(x -> x^2, 0.1)
0.2
julia> ∂(x -> x^2, 0.1+0.0im)
0.2 + 0.0im
julia> ∂(t -> exp(-t^2), 0.1)
-0.19800996674983362
julia> ∂(t -> exp(-t^2), 0.1+0.0im)
-0.19800996674983362 + 0.0im
julia> ∂(z -> cospi(z)^2, 0.1)
-1.8465818304904567
julia> ∂(z -> cospi(z)^2, 0.1 + 0.0im)
-1.8465818304904567 + 0.0im and julia> function f(x)
imag((3+(1+im)*x)^2)
end
f (generic function with 2 methods)
julia> println(ForwardDiff.derivative(f, 0))
6.0
julia> println((f(0+1e-8) - f(0))/1e-8)
6.00000002 |
Ah I did not see this. Yes, I think we can close this now (but it's annoying that the fix is not in a release!) |
I'm trying to calculate complex derivatives of analytic functions, using a trick by @tpapp:
This works for some simple functions:
But fails for functions involving powers:
Other failing examples:
t -> exp(-t^2)
,z -> cospi(z)^2
.Unsure if related to #486
The text was updated successfully, but these errors were encountered: