﻿ s14ac Method
s14ac returns a value of the function $\psi \left(x\right)-\mathrm{ln} x$, where $\psi$ is the psi function $\psi \left(x\right)=\frac{d}{dx}\mathrm{ln} \Gamma \left(x\right)=\frac{{\Gamma }^{\prime }\left(x\right)}{\Gamma \left(x\right)}$.

# Syntax

C#
```public static double s14ac(
double x,
out int ifail
)```
Visual Basic
```Public Shared Function s14ac ( _
x As Double, _
<OutAttribute> ByRef ifail As Integer _
) As Double```
Visual C++
```public:
static double s14ac(
double x,
[OutAttribute] int% ifail
)```
F#
```static member s14ac :
x : float *
ifail : int byref -> float
```

#### Parameters

x
Type: System..::..Double
On entry: the argument $x$ of the function.
Constraint: ${\mathbf{x}}>0.0$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

#### Return Value

s14ac returns a value of the function $\psi \left(x\right)-\mathrm{ln} x$, where $\psi$ is the psi function $\psi \left(x\right)=\frac{d}{dx}\mathrm{ln} \Gamma \left(x\right)=\frac{{\Gamma }^{\prime }\left(x\right)}{\Gamma \left(x\right)}$.

# Description

s14ac returns a value of the function $\psi \left(x\right)-\mathrm{ln} x$. The psi function is computed without the logarithmic term so that when $x$ is large, sums or differences of psi functions may be computed without unnecessary loss of precision, by analytically combining the logarithmic terms. For example, the difference $d=\psi \left(x+\frac{1}{2}\right)-\psi \left(x\right)$ has an asymptotic behaviour for large $x$ given by $d\sim \mathrm{ln}\left(x+\frac{1}{2}\right)-\mathrm{ln} x+\mathit{O}\left(\frac{1}{{x}^{2}}\right)\sim \mathrm{ln}\left(1+\frac{1}{2x}\right)\sim \frac{1}{2x}$.
Computing $d$ directly would amount to subtracting two large numbers which are close to $\mathrm{ln}\left(x+\frac{1}{2}\right)$ and $\mathrm{ln} x$ to produce a small number close to $\frac{1}{2x}$, resulting in a loss of significant digits. However, using this method to compute $f\left(x\right)=\psi \left(x\right)-\mathrm{ln} x$, we can compute $d=f\left(x+\frac{1}{2}\right)-f\left(x\right)+\mathrm{ln}\left(1+\frac{1}{2x}\right)$, and the dominant logarithmic term may be computed accurately from its power series when $x$ is large. Thus we avoid the unnecessary loss of precision.
The method is derived from the method PSIFN in Amos (1983).

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{x}}\le 0.0$. s14ac returns the value zero.
${\mathbf{ifail}}=2$
No result is computed because underflow is likely. The value of x is too large. s14ac returns the value zero.
${\mathbf{ifail}}=3$
No result is computed because overflow is likely. The value of x is too small. s14ac returns the value zero.
${\mathbf{ifail}}=-9000$
An error occured, see message report.

# Accuracy

All constants in s14ac 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)$.
With the above proviso, results returned by this method should be accurate almost to full precision, except at points close to the zero of $\psi \left(x\right)$, $x\simeq 1.461632$, where only absolute rather than relative accuracy can be obtained.

None.

None.

# Example

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

Example program (C#): s14ace.cs

Example program data: s14ace.d

Example program results: s14ace.r