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

incorrect 2nd derivative of complex exponential #653

Open
stevengj opened this issue Jun 9, 2023 · 2 comments
Open

incorrect 2nd derivative of complex exponential #653

stevengj opened this issue Jun 9, 2023 · 2 comments

Comments

@stevengj
Copy link
Contributor

stevengj commented Jun 9, 2023

This, from discourse, looks like a bug:

julia> p(s) = exp(1im*(2π*s - π/2));

julia> p′(s) = ForwardDiff.derivative(p, s);

julia> p″(s) = ForwardDiff.derivative(p′, s);

julia> p″(0.2499999999999)
-39.47841760435743 + 2.4807694081270598e-11im

julia> p″(0.25)
0.0 + 0.0im

I don't think mere floating-point error can explain why p″(0.25) is suddenly zero — looks like a misplaced conditional or something. Note that the correct answer for p″(0.25) is exactly -(2π)² ≈ -39.47841760435743.

(The first derivative p′ looks okay.)

@stevengj stevengj changed the title incorrect derivative of complex exponential incorrect 2nd derivative of complex exponential Jun 9, 2023
@mikmoore
Copy link

mikmoore commented Jun 9, 2023

(Very slightly) reduced example:

julia> p(s) = exp(1im*s);

julia> p′(s) = ForwardDiff.derivative(p, s);

julia> p″(s) = ForwardDiff.derivative(p′, s);

julia> p″(prevfloat(0.0))
-1.0 + 5.0e-324im

julia> p″(0.0)
0.0 + 0.0im

x^(1im*s) appears to exhibit this problem for any x.
expm1(1im*s) has this problem.
exp2(1im*s) and exp10(1im*s) are mysteriously correct.

@mcabbott
Copy link
Member

mcabbott commented Jun 9, 2023

I believe this is one more case fixed by #481:

julia> p″(0.2499999999999)
-39.47841760435743 + 2.4807694081270598e-11im

julia> p″(0.25)
-39.47841760435743 + 0.0im

(jl_aRIFuW) pkg> st ForwardDiff
Status `/private/var/folders/yq/4p2zwd614y59gszh7y9ypyhh0000gn/T/jl_aRIFuW/Project.toml`
  [f6369f11] ForwardDiff v0.11.0-DEV `https://github.com/JuliaDiff/ForwardDiff.jl.git#master`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants