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

Riemann Zeta Function

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

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

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

}} // namespaces

The return type of these functions is computed using the result type calculation rules: the return type is double if T is an integer type, and T otherwise.

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.

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

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

Returns the zeta function of z:

Accuracy

The following table shows the peak errors (in units of epsilon) found on various platforms with various floating point types, along with comparisons to the GSL-1.9 and Cephes libraries. Unless otherwise specified any floating point type that is narrower than the one shown will have effectively zero error.

Table 8.76. Error rates for zeta

GNU C++ version 7.1.0
linux
long double

GNU C++ version 7.1.0
linux
double

Sun compiler version 0x5150
Sun Solaris
long double

Microsoft Visual C++ version 14.1
Win32
double

Zeta: Random values greater than 1

Max = 0.846ε (Mean = 0.0833ε)

(<cmath>: Max = 5.45ε (Mean = 1ε))

Max = 0ε (Mean = 0ε)

(GSL 2.1: Max = 8.69ε (Mean = 1.03ε))

Max = 0.846ε (Mean = 0.0833ε)

Max = 0.836ε (Mean = 0.093ε)

Zeta: Random values less than 1

Max = 7.03ε (Mean = 2.93ε)

(<cmath>: Max = 538ε (Mean = 59.3ε))

Max = 0ε (Mean = 0ε)

(GSL 2.1: Max = 137ε (Mean = 13.8ε))

Max = 70.1ε (Mean = 17.1ε)

Max = 6.84ε (Mean = 3.12ε)

Zeta: Values close to and greater than 1

Max = 0.995ε (Mean = 0.5ε)

(<cmath>: Max = 1.9e+06ε (Mean = 5.11e+05ε))

Max = 0ε (Mean = 0ε)

(GSL 2.1: Max = 7.73ε (Mean = 4.07ε))

Max = 0.995ε (Mean = 0.5ε)

Max = 0.994ε (Mean = 0.421ε)

Zeta: Values close to and less than 1

Max = 0.998ε (Mean = 0.508ε)

(<cmath>: Max = 8.53e+06ε (Mean = 1.87e+06ε))

Max = 0ε (Mean = 0ε)

(GSL 2.1: Max = 0.991ε (Mean = 0.28ε))

Max = 0.998ε (Mean = 0.508ε)

Max = 0.991ε (Mean = 0.375ε)

Zeta: Integer arguments

Max = 9ε (Mean = 3.06ε)

(<cmath>: Max = 70.3ε (Mean = 17.4ε))

Max = 0ε (Mean = 0ε)

(GSL 2.1: Max = 3.75ε (Mean = 1.1ε))

Max = 28ε (Mean = 5.62ε)

Max = 9ε (Mean = 3ε)


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

The tests for these functions come in two parts: basic sanity checks use spot values calculated using Mathworld's online evaluator, while accuracy checks use high-precision test values calculated at 1000-bit precision with NTL::RR and this implementation. Note that the generic and type-specific versions of these functions use differing implementations internally, so this gives us reasonably independent test data. Using our test data to test other "known good" implementations also provides an additional sanity check.

Implementation

All versions of these functions first use the usual reflection formulas to make their arguments positive:

The generic versions of these functions are implemented using the series:

When the significand (mantissa) size is recognised (currently for 53, 64 and 113-bit reals, plus single-precision 24-bit handled via promotion to double) then a series of rational approximations devised by JM are used.

For 0 < z < 1 the approximating form is:

For a rational approximation R(1-z) and a constant C:

For 1 < z < 4 the approximating form is:

For a rational approximation R(n-z) and a constant C and integer n:

For z > 4 the approximating form is:

ζ(z) = 1 + eR(z - n)

For a rational approximation R(z-n) and integer n, note that the accuracy required for R(z-n) is not full machine-precision, but an absolute error of: /εR(0). This saves us quite a few digits when dealing with large z, especially when ε is small.

Finally, there are some special cases for integer arguments, there are closed forms for negative or even integers:

and for positive odd integers we simply cache pre-computed values as these are of great benefit to some infinite series calculations.


PrevUpHomeNext