Thanks for the tip. Unfortunately, @evalpoly seems to be orders of 
magnitude slower for some reason, and has huge memory allocation compared 
to @horner. Here is an example:
import Base.Math.@horner
function SchroderFifthHorner(a0::Float64, a1::Float64, a2::Float64, 
a3::Float64, a4::Float64, a5::Float64, c::Complex{Float64})
x = c
M = 100
d = 10.0^-6
a = 0.1
for j in 1:M
xP = x
f = @horner(x,a0,a1,a2,a3,a4,a5)
fP = @horner(x,a1,2*a2,3*a3,4*a4,5*a5)
fPP = @horner(x,2*a2,6*a3,12*a4,20*a5)
x -= f*fP/(fP^2 - f*fPP)
if abs(x - xP) < d
return exp(-a*(j - (log(abs(x - xP)) - log(d))/log(d)) + angle(x)im)
end
end
return 0.0im
end
function SchroderFifthEvalPoly(a0::Float64, a1::Float64, a2::Float64, 
a3::Float64, a4::Float64, a5::Float64, c::Complex{Float64})
x = c
M = 100
d = 10.0^-6
a = 0.1
for j in 1:M
xP = x
f = @evalpoly(x,a0,a1,a2,a3,a4,a5)
fP = @evalpoly(x,a1,2*a2,3*a3,4*a4,5*a5)
fPP = @evalpoly(x,2*a2,6*a3,12*a4,20*a5)
x -= f*fP/(fP^2 - f*fPP)
if abs(x - xP) < d
return exp(-a*(j - (log(abs(x - xP)) - log(d))/log(d)) + angle(x)im)
end
end
return 0.0im
end

@time arr1 = [SchroderFifthHorner(1.0,0.0,0.0,0.0,0.0,6.0,x+y*im) for x in 
linspace(-1,1,200), y in linspace(-1,1,200)];
@time arr2 = [SchroderFifthEvalPoly(1.0,2.0,3.0,4.0,5.0,6.0,x+y*im) for x 
in linspace(-1,1,200), y in linspace(-1,1,200)];
Same exact code, but @horner is replaced with @evalpoly in the second 
function. On my laptop, the @horner method returns 0.040350402 seconds 
(644144 bytes allocated), whereas the @evalpoly method returns 5.265075967 
seconds (2164451728 bytes allocated). The result of the @evalpoly method 
does not appear to be type-stable, since arr2 is of type Array{Any, 2}. I'm 
not sure why the instability arises, though.

Reply via email to