ForwardDiff.jl
ForwardDiff.jl copied to clipboard
Special case `x^1`
x^0 is special-cased here (see https://github.com/JuliaDiff/ForwardDiff.jl/issues/331)
Could x^1 also be special-cased a couple of lines later?
Currently it instead calculates 1 * x^0. When x == 0 that relies on 0^0 being defined correctly.
(This led to the error in https://github.com/JuliaDiff/ForwardDiff.jl/issues/411.)
I think you need to special case it dynamically here
https://github.com/JuliaDiff/ForwardDiff.jl/blob/c374b69f47095aef60a5486065ddc6fe29c32e9f/src/dual.jl#L452-L453
by adding elseif y === one(y) branch and also here
https://github.com/JuliaDiff/ForwardDiff.jl/blob/c374b69f47095aef60a5486065ddc6fe29c32e9f/src/dual.jl#L472-L473
for the literal case (x^1).