ForwardDiff.jl icon indicating copy to clipboard operation
ForwardDiff.jl copied to clipboard

Special case `x^1`

Open dpsanders opened this issue 6 years ago • 1 comments

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

dpsanders avatar Oct 09 '19 16:10 dpsanders

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

tkf avatar Oct 12 '19 03:10 tkf