JuliaDiff/HyperDualNumbers.jl — pull request #5 by timholy (2014-08-15 15:20:02+00:00)
Title: Improve performance of division

This yields an approximately 60-fold improvement in the speed of division:
```
julia> using HyperDualNumbers

julia> h = hyper(rand(),rand(),rand(),rand())
0.06982926944054846 + 0.7113057563802201ϵ1 + 0.6621427508540101ϵ2 + 0.9309141087296526ϵ1ϵ2

julia> function inv1(h, n)
c = 1/h
for i = 1:n
c += 1/h
end
c
end
inv1 (generic function with 1 method)

julia> function inv2(h, n)
c = h^(-1)
for i = 1:n
c += h^(-1)
end
c
end
inv2 (generic function with 1 method)

julia> inv1(h, 1)
28.641284894191376 - 291.7503072649095ϵ1 - 271.58553024787784ϵ2 + 5151.108248896588ϵ1ϵ2

julia> inv2(h, 1)
28.641284894191376 - 291.7503072649095ϵ1 - 271.58553024787784ϵ2 + 5151.108248896587ϵ1ϵ2

julia> @time inv1(h, 10^6)
elapsed time: 0.003128809 seconds (15800 bytes allocated)
1.4320656767741527e7 - 1.4587529950632706e8ϵ1 - 1.3579290091799736e8ϵ2 + 2.575556699956081e9ϵ1ϵ2

julia> @time inv2(h, 10^6)
elapsed time: 0.190264991 seconds (136 bytes allocated)
1.4320656767741527e7 - 1.4587529950632706e8ϵ1 - 1.3579290091799736e8ϵ2 + 2.575556699956081e9ϵ1ϵ2
```
The strategy is to avoid calling the generic `pow` function.