
| Current Path : /home/cgabriel/20_dev/10_dev2017/1310__algorithms/Julia/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/cgabriel/20_dev/10_dev2017/1310__algorithms/Julia/digamma.jl |
import Base: digamma, Math.@horner
function digamma(z::Complex{Float64})
# Based on eq. (12), without looking at the accompanying source code, of:
# K. S. Kölbig, "Programs for computing the logarithm of the gamma function,
# and the digamma function, for complex argument," Computer Phys. Commun.
# vol. 4, pp. 221â226 (1972).
x, y = reim(z)
if x < 0 # reflection formula
ψ = -π * cot(π*z)
x = 1 - x; y = -y
z = Complex(x, y)
else
ψ = zero(z)
end
if x < 7 # shift using recurrence formula
n = 7 - ifloor(x)
for ν = 0:n-1
ψ -= inv(z + ν)
end
z = Complex(x + n, y)
end
t = inv(z)
ψ += log(z) - 0.5*t
t *= t # 1/z^2
ψ -= t * @horner(t,0.08333333333333333,-0.008333333333333333,0.003968253968253968,-0.004166666666666667,0.007575757575757576,-0.02109279609279609,0.08333333333333334)
end
digamma{T <: Integer}(z::Complex{T}) = digamma(float(z))