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

Ratios of Gamma Functions

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

template <class T1, class T2>
calculated-result-type tgamma_ratio(T1 a, T2 b);

template <class T1, class T2, class Policy>
calculated-result-type tgamma_ratio(T1 a, T2 b, const Policy&);

template <class T1, class T2>
calculated-result-type tgamma_delta_ratio(T1 a, T2 delta);

template <class T1, class T2, class Policy>
calculated-result-type tgamma_delta_ratio(T1 a, T2 delta, const Policy&);

}} // namespaces
Description
template <class T1, class T2>
calculated-result-type tgamma_ratio(T1 a, T2 b);

template <class T1, class T2, class Policy>
calculated-result-type tgamma_ratio(T1 a, T2 b, const Policy&);

Returns the ratio of gamma functions:

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.

Internally this just calls tgamma_delta_ratio(a, b-a).

template <class T1, class T2>
calculated-result-type tgamma_delta_ratio(T1 a, T2 delta);

template <class T1, class T2, class Policy>
calculated-result-type tgamma_delta_ratio(T1 a, T2 delta, const Policy&);

Returns the ratio of gamma functions:

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.

Note that the result is calculated accurately even when delta is small compared to a: indeed even if a+delta ~ a. The function is typically used when a is large and delta is very small.

The return type of these functions is computed using the result type calculation rules when T1 and T2 are different types, otherwise the result type is simple T1.

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 8.7. Error rates for tgamma_delta_ratio

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

tgamma + small delta ratios

Max = 0ε (Mean = 0ε)

Max = 5.83ε (Mean = 1.3ε)

Max = 15.4ε (Mean = 2.09ε)

Max = 7.56ε (Mean = 1.31ε)

tgamma + small delta ratios (negative delta)

Max = 0ε (Mean = 0ε)

Max = 7.94ε (Mean = 1.4ε)

Max = 18.3ε (Mean = 2.03ε)

Max = 7.43ε (Mean = 1.42ε)

tgamma + small integer ratios

Max = 0ε (Mean = 0ε)

Max = 1.96ε (Mean = 0.677ε)

Max = 1.96ε (Mean = 0.677ε)

Max = 2.74ε (Mean = 0.736ε)

tgamma + small integer ratios (negative delta)

Max = 0ε (Mean = 0ε)

Max = 1.62ε (Mean = 0.451ε)

Max = 1.62ε (Mean = 0.451ε)

Max = 2.15ε (Mean = 0.685ε)

integer tgamma ratios

Max = 0ε (Mean = 0ε)

Max = 0.997ε (Mean = 0.4ε)

Max = 0.997ε (Mean = 0.4ε)

Max = 0.968ε (Mean = 0.386ε)

integer tgamma ratios (negative delta)

Max = 0ε (Mean = 0ε)

Max = 0.853ε (Mean = 0.176ε)

Max = 0.853ε (Mean = 0.176ε)

Max = 0.974ε (Mean = 0.175ε)


Table 8.8. Error rates for tgamma_ratio

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

tgamma ratios

Max = 0.694ε (Mean = 0.0347ε)

Max = 2.99ε (Mean = 1.15ε)

Max = 174ε (Mean = 61.2ε)

Max = 3.28ε (Mean = 1.12ε)


Testing

Accuracy tests use data generated at very high precision (with NTL RR class set at 1000-bit precision: about 300 decimal digits) and a deliberately naive calculation of Γ(x)/Γ(y).

Implementation

The implementation of these functions is very similar to that of beta, and is based on combining similar power terms to improve accuracy and avoid spurious overflow/underflow.

In addition there are optimisations for the situation where delta is a small integer: in which case this function is basically the reciprocal of a rising factorial, or where both arguments are smallish integers: in which case table lookup of factorials can be used to calculate the ratio.


PrevUpHomeNext