digamma

Computes the digamma (psi) function at x.

The digamma function is the logarithmic derivative of the gamma function: psi(x) = d/dx ln(Gamma(x)) = Gamma'(x) / Gamma(x). It appears in the entropy of gamma, beta, and related distributions, and in maximum-likelihood parameter estimation for exponential-family distributions.

Uses the asymptotic expansion for x >= 6, with recurrence relation to shift smaller arguments upward, and a reflection formula for negative non-integer arguments.

Example:

digamma(1.0)  // -0.5772... (negative Euler-Mascheroni constant)
digamma(2.0) // 0.4227... (1 - gamma)
digamma(0.5) // -1.9635... (-gamma - 2*ln(2))

Return

the value of the digamma function at x.

Parameters

x

the point at which to evaluate. Must not be zero or a negative integer (poles of the gamma function).

Throws

if x is zero or a negative integer.