Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Trigamma

Synopsis
#include <boost/math/special_functions/trigamma.hpp>
namespace boost{ namespace math{

template <class T>
calculated-result-type trigamma(T z);

template <class T, class Policy>
calculated-result-type trigamma(T z, const Policy&);

}} // namespaces
Description

Returns the trigamma function of x. Trigamma is defined as the derivative of the digamma function:

The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.

The return type of this function is computed using the result type calculation rules: the result is of type double when T is an integer type, and type T otherwise.

Accuracy

The following table shows the peak errors (in units of epsilon) found on various platforms with various floating point types. Unless otherwise specified any floating point type that is narrower than the one shown will have effectively zero error.

Table 6.5. Error rates for trigamma

GNU C++ version 7.1.0
linux
double

GNU C++ version 7.1.0
linux
long double

Sun compiler version 0x5150
Sun Solaris
long double

Microsoft Visual C++ version 14.1
Win32
double

Mathematica Data

Max = 0.998ε (Mean = 0.105ε)

(GSL 2.1: Max = 1.34e+04ε (Mean = 1.49e+03ε))
(Rmath 3.2.3: Max = 1.34e+04ε (Mean = 1.51e+03ε))

Max = 1.28ε (Mean = 0.449ε)

Max = 1.28ε (Mean = 0.449ε)

Max = 1ε (Mean = 0.382ε)


As shown above, error rates are generally very low for built in types. For multiprecision types, error rates are typically in the order of a few epsilon.

The following error plot are based on an exhaustive search of the functions domain, MSVC-15.5 at double precision, and GCC-7.1/Ubuntu for long double and __float128.

Testing

Testing is against Mathematica generated spot values to 35 digit precision.

Implementation

The arbitrary precision version of this function simply calls polygamma.

For built in fixed precision types, negative arguments are first made positive via:

Then arguments in the range [0, 1) are shifted to >= 1 via:

Then evaluation is via one of a number of rational approximations, for small x these are of the form:

and for large x of the form:


PrevUpHomeNext