]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/doc/sf/digamma.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / math / doc / sf / digamma.qbk
CommitLineData
7c673cae
FG
1[section:digamma Digamma]
2
3[h4 Synopsis]
4
5``
6#include <boost/math/special_functions/digamma.hpp>
7``
8
9 namespace boost{ namespace math{
10
11 template <class T>
12 ``__sf_result`` digamma(T z);
13
14 template <class T, class ``__Policy``>
15 ``__sf_result`` digamma(T z, const ``__Policy``&);
16
17 }} // namespaces
18
19[h4 Description]
20
21Returns the digamma or psi function of /x/. Digamma is defined as the logarithmic
22derivative of the gamma function:
23
24[equation digamma1]
25
26[graph digamma]
27
28[optional_policy]
29
30The return type of this function is computed using the __arg_promotion_rules:
31the result is of type `double` when T is an integer type, and type T otherwise.
32
33[h4 Accuracy]
34
35The following table shows the peak errors (in units of epsilon)
36found on various platforms with various floating point types.
37Unless otherwise specified any floating point type that is narrower
38than the one shown will have __zero_error.
39
40[table_digamma]
41
42As shown above, error rates for positive arguments are generally very low.
43For negative arguments there are an infinite number of irrational roots:
44relative errors very close to these can be arbitrarily large, although
45absolute error will remain very low.
46
47[h4 Testing]
48
49There are two sets of tests: spot values are computed using
50the online calculator at functions.wolfram.com, while random test values
51are generated using the high-precision reference implementation (a
52differentiated __lanczos see below).
53
54[h4 Implementation]
55
56The implementation is divided up into the following domains:
57
58For Negative arguments the reflection formula:
59
60 digamma(1-x) = digamma(x) + pi/tan(pi*x);
61
62is used to make /x/ positive.
63
64For arguments in the range [0,1] the recurrence relation:
65
66 digamma(x) = digamma(x+1) - 1/x
67
68is used to shift the evaluation to [1,2].
69
70For arguments in the range [1,2] a rational approximation [jm_rationals] is used (see below).
71
72For arguments in the range [2,BIG] the recurrence relation:
73
74 digamma(x+1) = digamma(x) + 1/x;
75
76is used to shift the evaluation to the range [1,2].
77
78For arguments > BIG the asymptotic expansion:
79
80[equation digamma2]
81
82can be used. However, this expansion is divergent after a few terms:
83exactly how many terms depends on the size of /x/. Therefore the value
84of /BIG/ must be chosen so that the series can be truncated at a term
85that is too small to have any effect on the result when evaluated at /BIG/.
86Choosing BIG=10 for up to 80-bit reals, and BIG=20 for 128-bit reals allows
87the series to truncated after a suitably small number of terms and evaluated
88as a polynomial in `1/(x*x)`.
89
90The arbitrary precision version of this function uses recurrence relations until
91x > BIG, and then evaluation via the asymptotic expansion above. As special cases
92integer and half integer arguments are handled via:
93
94[equation digamma4]
95
96[equation digamma5]
97
98The rational approximation [jm_rationals] in the range [1,2] is derived as follows.
99
100First a high precision approximation to digamma was constructed using a 60-term
101differentiated __lanczos, the form used is:
102
103[equation digamma3]
104
105Where P(x) and Q(x) are the polynomials from the rational form of the Lanczos sum,
106and P'(x) and Q'(x) are their first derivatives. The Lanzos part of this
107approximation has a theoretical precision of ~100 decimal digits. However,
108cancellation in the above sum will reduce that to around `99-(1/y)` digits
109if /y/ is the result. This approximation was used to calculate the positive root
110of digamma, and was found to agree with the value used by
111Cody to 25 digits (See Math. Comp. 27, 123-127 (1973) by Cody, Strecok and Thacher)
112and with the value used by Morris to 35 digits (See TOMS Algorithm 708).
113
114Likewise a few spot tests agreed with values calculated using
115functions.wolfram.com to >40 digits.
116That's sufficiently precise to insure that the approximation below is
117accurate to double precision. Achieving 128-bit long double precision requires that
118the location of the root is known to ~70 digits, and it's not clear whether
119the value calculated by this method meets that requirement: the difficulty
120lies in independently verifying the value obtained.
121
122The rational approximation [jm_rationals] was optimised for absolute error using the form:
123
124 digamma(x) = (x - X0)(Y + R(x - 1));
125
126Where X0 is the positive root of digamma, Y is a constant, and R(x - 1) is the
127rational approximation. Note that since X0 is irrational, we need twice as many
128digits in X0 as in x in order to avoid cancellation error during the subtraction
129(this assumes that /x/ is an exact value, if it's not then all bets are off). That
130means that even when x is the value of the root rounded to the nearest
131representable value, the result of digamma(x) ['[*will not be zero]].
132
133
134[endsect][/section:digamma The Digamma Function]
135
136[/
137 Copyright 2006 John Maddock and Paul A. Bristow.
138 Distributed under the Boost Software License, Version 1.0.
139 (See accompanying file LICENSE_1_0.txt or copy at
140 http://www.boost.org/LICENSE_1_0.txt).
141]
142