3
* Psi (digamma) function
16
* psi(x) = -- ln | (x)
19
* is the logarithmic derivative of the gamma function.
23
* psi(n) = -EUL + > 1/k.
27
* This formula is used for 0 < n <= 10. If x is negative, it
28
* is transformed to a positive argument by the reflection
29
* formula psi(1-x) = psi(x) + pi cot(pi x).
30
* For general positive x, the argument is made greater than 10
31
* using the recurrence psi(x+1) = psi(x) + 1/x.
32
* Then the following asymptotic expansion is applied:
36
* psi(x) = log(x) - 1/2x - > -------
40
* where the B2k are Bernoulli numbers.
43
* Relative error (except absolute when |psi| < 1):
44
* arithmetic domain # trials peak rms
45
* DEC 0,30 2500 1.7e-16 2.0e-17
46
* IEEE 0,30 30000 1.3e-15 1.4e-16
47
* IEEE -30,0 40000 1.5e-15 2.2e-16
50
* message condition value returned
51
* psi singularity x integer <=0 MAXNUM
55
Cephes Math Library Release 2.8: June, 2000
56
Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
63
8.33333333333333333333E-2,
64
-2.10927960927960927961E-2,
65
7.57575757575757575758E-3,
66
-4.16666666666666666667E-3,
67
3.96825396825396825397E-3,
68
-8.33333333333333333333E-3,
69
8.33333333333333333333E-2
74
static unsigned short A[] = {
75
0037252,0125252,0125252,0125253,
76
0136654,0145314,0126312,0146255,
77
0036370,0037017,0101740,0174076,
78
0136210,0104210,0104210,0104211,
79
0036202,0004040,0101010,0020202,
80
0136410,0104210,0104210,0104211,
81
0037252,0125252,0125252,0125253
86
static unsigned short A[] = {
87
0x5555,0x5555,0x5555,0x3fb5,
88
0x5996,0x9599,0x9959,0xbf95,
89
0x1f08,0xf07c,0x07c1,0x3f7f,
90
0x1111,0x1111,0x1111,0xbf71,
91
0x0410,0x1041,0x4104,0x3f70,
92
0x1111,0x1111,0x1111,0xbf81,
93
0x5555,0x5555,0x5555,0x3fb5
98
static unsigned short A[] = {
99
0x3fb5,0x5555,0x5555,0x5555,
100
0xbf95,0x9959,0x9599,0x5996,
101
0x3f7f,0x07c1,0xf07c,0x1f08,
102
0xbf71,0x1111,0x1111,0x1111,
103
0x3f70,0x4104,0x1041,0x0410,
104
0xbf81,0x1111,0x1111,0x1111,
105
0x3fb5,0x5555,0x5555,0x5555
109
#define EUL 0.57721566490153286061
112
extern double floor ( double );
113
extern double log ( double );
114
extern double tan ( double );
115
extern double polevl ( double, void *, int );
117
double floor(), log(), tan(), polevl();
119
extern double PI, MAXNUM;
125
double p, q, nz, s, w, y, z;
138
mtherr( "psi", SING );
141
/* Remove the zeros of tan(PI x)
142
* by subtracting the nearest integer from x
161
/* check for positive integer up to 10 */
162
if( (x <= 10.0) && (x == floor(x)) )
186
y = z * polevl( z, A, 6 );
191
y = log(s) - (0.5/s) - y - w;