Skip to content

incorrect 2nd derivative of complex exponential #653

Closed

Description

@stevengj

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.)

Activity

  1. changed the title [-]incorrect derivative of complex exponential[/-] [+]incorrect 2nd derivative of complex exponential[/+] on Jun 9, 2023
  2. mikmoore commented on Jun 9, 2023

    @mikmoore

    (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.

  3. mcabbott commented on Jun 9, 2023

    @mcabbott
    Member

    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`
    
  4. mcabbott commented on Mar 26, 2025

    @mcabbott
    Member

    Fixed on 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions