TITLE: Approximating the Digamma function
QUESTION [5 upvotes]: I am trying to approximate the digamma function in order to graph it in latex. I've already found an approximation of the gamma function from the Tex SE:
$$
\Gamma(z)=
    (2.506628274631\sqrt{(1/z)} + 0.20888568(1/z)^{(1.5)} + 0.00870357(1/z)^{(2.5)} - \frac{(174.2106599*(1/z)^{(3.5)})}{25920} - \frac{(715.6423511(1/z)^{(4.5)})}{1244160)}\exp((-ln(1/z)-1)z)
$$
and for the digamma, $\psi$, ive been using an approximation of the derivative:
$$
\psi(x)=\frac{\ln \Gamma(x+0.0001)-\ln \Gamma(x-0.0001)}{0.0002}
$$
But im wondering if there is a better way

REPLY [7 votes]: Since you need an implementation for graphing, a simple approximation with relative low accuracy and optimized for absolute error seems suitable. A short search with computer program shows that $$\psi(x) \approx ln (x + a) - \frac{1}{b x}, \space a = 0.4849142940227510, \space b=1.0271785180163817$$
approximates with an absolute error of less than $0.00123$ on $[\frac{1}{2}, 2^{1024})$ when evaluated in IEEE-754 double precision. For arguments $x \lt \frac{1}{2}$, the function can be computed using the reflection formula $\psi(x) = \psi(1-x) + \pi \space cot \space(\pi (1-x))$.