## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

s14adf returns a sequence of values of scaled derivatives of the psi function $\psi \left(x\right)$ (also known as the digamma function).

## 2Specification

Fortran Interface
 Subroutine s14adf ( x, n, m, ans,
 Integer, Intent (In) :: n, m Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x Real (Kind=nag_wp), Intent (Out) :: ans(m)
#include <nag.h>
 void s14adf_ (const double *x, const Integer *n, const Integer *m, double ans[], Integer *ifail)
The routine may be called by the names s14adf or nagf_specfun_polygamma_deriv.

## 3Description

s14adf computes $m$ values of the function
 $w(k,x)=(-1)k+1ψ (k) (x) k! ,$
for $x>0$, $k=n$, $n+1,\dots ,n+m-1$, where $\psi$ is the psi function
 $ψ(x)=ddx ln⁡Γ(x)=Γ′(x) Γ(x) ,$
and ${\psi }^{\left(k\right)}$ denotes the $k$th derivative of $\psi$.
The routine is derived from the routine PSIFN in Amos (1983). The basic method of evaluation of $w\left(k,x\right)$ is the asymptotic series
 $w(k,x)∼ε(k,x)+12xk+1 +1xk∑j=1∞B2j(2j+k-1)! (2j)!k!x2j$
for large $x$ greater than a machine-dependent value ${x}_{\mathrm{min}}$, followed by backward recurrence using
 $w(k,x)=w(k,x+1)+x-k-1$
for smaller values of $x$, where $\epsilon \left(k,x\right)=-\mathrm{ln}x$ when $k=0$, $\epsilon \left(k,x\right)=\frac{1}{k{x}^{k}}$ when $k>0$, and ${B}_{2j}$, $j=1,2,\dots$, are the Bernoulli numbers.
When $k$ is large, the above procedure may be inefficient, and the expansion
 $w(k,x)=∑j=1∞1(x+j)k+1,$
which converges rapidly for large $k$, is used instead.

## 4References

NIST Digital Library of Mathematical Functions
Amos D E (1983) Algorithm 610: A portable FORTRAN subroutine for derivatives of the psi function ACM Trans. Math. Software 9 494–502

## 5Arguments

1: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: the argument $x$ of the function.
Constraint: ${\mathbf{x}}>0.0$.
2: $\mathbf{n}$Integer Input
On entry: the index of the first member $n$ of the sequence of functions.
Constraint: ${\mathbf{n}}\ge 0$.
3: $\mathbf{m}$Integer Input
On entry: the number of members $m$ required in the sequence $w\left(\mathit{k},x\right)$, for $\mathit{k}=n,\dots ,n+m-1$.
Constraint: ${\mathbf{m}}\ge 1$.
4: $\mathbf{ans}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: the first $m$ elements of ans contain the required values $w\left(\mathit{k},x\right)$, for $\mathit{k}=n,\dots ,n+m-1$.
5: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{x}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{x}}>0.0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
${\mathbf{ifail}}=4$
Computation abandoned due to the likelihood of underflow.
${\mathbf{ifail}}=5$
Computation abandoned due to the likelihood of overflow.
${\mathbf{ifail}}=6$
There is not enough internal workspace to continue computation. m is probably too large.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

All constants in s14adf are given to approximately $18$ digits of precision. Calling the number of digits of precision in the floating-point arithmetic being used $t$, then clearly the maximum number of correct digits in the results obtained is limited by $p=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(t,18\right)$. Empirical tests of s14adf, taking values of $x$ in the range $0.0, and $n$ in the range $1\le n\le 50$, have shown that the maximum relative error is a loss of approximately two decimal places of precision. Tests with $n=0$, i.e., testing the function $-\psi \left(x\right)$, have shown somewhat better accuracy, except at points close to the zero of $\psi \left(x\right)$, $x\simeq 1.461632$, where only absolute accuracy can be obtained.

## 8Parallelism and Performance

The time taken for a call of s14adf is approximately proportional to $m$, plus a constant. In general, it is much cheaper to call s14adf with $m$ greater than $1$ to evaluate the function $w\left(\mathit{k},x\right)$, for $\mathit{k}=n,\dots ,n+m-1$, rather than to make $m$ separate calls of s14adf.

## 10Example

This example reads values of the argument $x$ from a file, evaluates the function at each value of $x$ and prints the results.