Skip to content

Third derivative of x^2 at x=0 is NaN #330

Closed
@tkf

Description

@tkf

If I nest ForwardDiff.derivative three times to compute the third derivative, I found that it doesn't work with some inputs. Taking derivative of x^2 at x = 0 is the minimal example I found.

julia> deriv3(f, x::Number = 0.0) =
           ForwardDiff.derivative(
               a -> ForwardDiff.derivative(
                   b -> ForwardDiff.derivative(f, b),
                   a),
               x)
deriv3 (generic function with 2 methods)

julia> deriv3(x -> x^2)
NaN

julia> deriv3(x -> x^3)  # OK
6.0

julia> deriv3(x -> x)  # OK
0.0

julia> versioninfo()
Julia Version 0.6.3
Commit d55cadc (2018-05-28 20:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM)2 Quad CPU    Q9400  @ 2.66GHz
  WORD_SIZE: 64
  BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Penryn)
  LAPACK: libopenblas
  LIBM: libm
  LLVM: libLLVM-3.9.1 (ORCJIT, penryn)

julia> Pkg.installed("ForwardDiff")
v"0.7.5"

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