s Chapter Contents
s Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_real_polygamma (s14aec)

## 1  Purpose

nag_real_polygamma (s14aec) returns the value of the $k$th derivative of the psi function $\psi \left(x\right)$ for real $x$ and $k=0,1,\dots ,6$.

## 2  Specification

 #include #include
 double nag_real_polygamma (double x, Integer k, NagError *fail)

## 3  Description

nag_real_polygamma (s14aec) evaluates an approximation to the $k$th derivative of the psi function $\psi \left(x\right)$ given by
 $ψ k x = d k dx k ψ x = d k dx k d dx log e ⁡Γ x ,$
where $x$ is real with $x\ne 0,-1,-2,\dots$ and $k=0,1,\dots ,6$. For negative non-integer values of $x$, the recurrence relationship
 $ψ k x+1 = ψ k x + d k dx k 1 x$
is used. The value of $\frac{{\left(-1\right)}^{k+1}{\psi }^{\left(k\right)}\left(x\right)}{k!}$ is obtained by a call to a function based on PSIFN in Amos (1983).
Note that ${\psi }^{\left(k\right)}\left(x\right)$ is also known as the polygamma function. Specifically, ${\psi }^{\left(0\right)}\left(x\right)$ is often referred to as the digamma function and ${\psi }^{\left(1\right)}\left(x\right)$ as the trigamma function in the literature. Further details can be found in Abramowitz and Stegun (1972).

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Amos D E (1983) Algorithm 610: A portable FORTRAN subroutine for derivatives of the psi function ACM Trans. Math. Software 9 494–502

## 5  Arguments

1:     xdoubleInput
On entry: the argument $x$ of the function.
Constraint: x must not be ‘too close’ (see Section 6) to a non-positive integer.
2:     kIntegerInput
On entry: the function ${\psi }^{\left(k\right)}\left(z\right)$ to be evaluated.
Constraint: $0\le {\mathbf{k}}\le 6$.
3:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{k}}\le 6$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_OVERFLOW_LIKELY
The evaluation has been abandoned due to the likelihood of overflow. The result is returned as zero.
NE_REAL
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: x must not be ‘too close’ to a non-positive integer. That is, $\left|x-\mathrm{nint}\left(x\right)\right|\ge$ machine precision $×$ nint$\left(x\right)$.
NE_UNDERFLOW_LIKELY
The evaluation has been abandoned due to the likelihood of underflow. The result is returned as zero.

## 7  Accuracy

All constants in the underlying functions are given to approximately 18 digits of precision. If $t$ denotes the number of digits of precision in the floating point arithmetic being used, then clearly the maximum number in the results obtained is limited by $p=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(t,18\right)$. Empirical tests by Amos (1983) have shown that the maximum relative error is a loss of approximately two decimal places of precision. Further tests with the function $-{\psi }^{\left(0\right)}\left(x\right)$ have shown somewhat improved accuracy, except at points near the positive zero of ${\psi }^{\left(0\right)}\left(x\right)$ at $x=1.46\dots$, where only absolute accuracy can be obtained.

None.

## 9  Example

The example program evaluates ${\psi }^{\left(2\right)}\left(x\right)$ at $x=2.5$, and prints the results.

### 9.1  Program Text

Program Text (s14aece.c)

### 9.2  Program Data

Program Data (s14aece.d)

### 9.3  Program Results

Program Results (s14aece.r)