trigamma

Computes the trigamma function at x.

The trigamma function is the second derivative of ln(Gamma(x)), or equivalently the derivative of the digamma function: psi'(x) = d/dx psi(x). It appears in the variance of sufficient statistics for exponential-family distributions and in Newton-Raphson updates for maximum-likelihood estimation.

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

Example:

trigamma(1.0)  // 1.6449... (pi^2/6)
trigamma(0.5) // 4.9348... (pi^2/2)
trigamma(2.0) // 0.6449... (pi^2/6 - 1)

Return

the value of the trigamma 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.