3
* Confluent hypergeometric function
9
* double a, b, x, y, hyperg();
11
* y = hyperg( a, b, x );
17
* Computes the confluent hypergeometric function
21
* F ( a,b;x ) = 1 + ---- + --------- + ...
24
* Many higher transcendental functions are special cases of
27
* As is evident from the formula, b must not be a negative
28
* integer or zero unless a is an integer with 0 >= a > b.
30
* The routine attempts both a direct summation of the series
31
* and an asymptotic expansion. In each case error due to
32
* roundoff, cancellation, and nonconvergence is estimated.
33
* The result with smaller estimated error is returned.
39
* Tested at random points (a, b, x), all three variables
40
* ranging from 0 to 30.
42
* arithmetic domain # trials peak rms
43
* DEC 0,30 2000 1.2e-15 1.3e-16
45
21800 max = 1.4200E-14 rms = 1.0841E-15 ave = -5.3640E-17
47
25500 max = 1.2759e-14 rms = 3.7155e-16 ave = 1.5384e-18
48
* IEEE 0,30 30000 1.8e-14 1.1e-15
50
* Larger errors can be observed when b is near a negative
51
* integer or zero. Certain combinations of arguments yield
52
* serious cancellation error in the power series summation
53
* and also are not in the region of near convergence of the
54
* asymptotic series. An error message is printed if the
55
* self-estimated relative error is greater than 1.0e-12.
63
Cephes Math Library Release 2.8: June, 2000
64
Copyright 1984, 1987, 1988, 2000 by Stephen L. Moshier
70
extern double exp ( double );
71
extern double log ( double );
72
extern double gamma ( double );
73
extern double lgam ( double );
74
extern double fabs ( double );
75
double hyp2f0 ( double, double, double, int, double * );
76
static double hy1f1p(double, double, double, double *);
77
static double hy1f1a(double, double, double, double *);
78
double hyperg (double, double, double);
80
double exp(), log(), gamma(), lgam(), fabs(), hyp2f0();
81
static double hy1f1p();
82
static double hy1f1a();
85
extern double MAXNUM, MACHEP;
87
double hyperg( a, b, x)
90
double asum, psum, acanc, pcanc, temp;
92
/* See if a Kummer transformation will help */
94
if( fabs(temp) < 0.001 * fabs(a) )
95
return( exp(x) * hyperg( temp, b, -x ) );
98
psum = hy1f1p( a, b, x, &pcanc );
103
/* try asymptotic series */
105
asum = hy1f1a( a, b, x, &acanc );
108
/* Pick the result with less estimated error */
117
if( pcanc > 1.0e-12 )
118
mtherr( "hyperg", PLOSS );
126
/* Power series summation for confluent hypergeometric function */
129
static double hy1f1p( a, b, x, err )
133
double n, a0, sum, t, u, temp;
138
/* set up for power series summation */
152
if( bn == 0 ) /* check bn first since if both */
154
mtherr( "hyperg", SING );
155
return( MAXNUM ); /* an and bn are zero it is */
157
if( an == 0 ) /* a singularity */
161
u = x * ( an / (bn * n) );
163
/* check for blowup */
165
if( (temp > 1.0 ) && (maxt > (MAXNUM/temp)) )
167
*err = 1.0; /* blowup: estimate 100% error */
175
c = (sumc - sum) - y;
187
/* estimate error due to roundoff and cancellation */
189
*err = fabs(c / sum);
199
/* asymptotic formula for hypergeometric function:
203
* | (b) ( -------- 2f0( a, 1+a-b, -1/x )
210
* + -------- 2f0( b-a, 1-a, 1/x ) )
215
static double hy1f1a( a, b, x, err )
219
double h1, h2, t, u, temp, acanc, asum, err1, err2;
227
temp = log( fabs(x) );
228
t = x + temp * (a-b);
238
h1 = hyp2f0( a, a-b+1, -1.0/x, 1, &err1 );
240
temp = exp(u) / gamma(b-a);
244
h2 = hyp2f0( b-a, 1.0-a, 1.0/x, 2, &err2 );
247
temp = exp(t) / gamma(a);
249
temp = exp( t - lgam(a) );
259
acanc = fabs(err1) + fabs(err2);
273
acanc *= 30.0; /* fudge factor, since error of asymptotic formula
274
* often seems this much larger than advertised */
285
double hyp2f0( a, b, x, type, err )
287
int type; /* determines what converging factor to use */
290
double a0, alast, t, tlast, maxt;
291
double n, an, bn, u, sum, temp;
310
u = an * (bn * x / n);
312
/* check for blowup */
314
if( (temp > 1.0 ) && (maxt > (MAXNUM/temp)) )
320
/* terminating condition for asymptotic series */
325
sum += alast; /* the sum is one term behind */
340
pdone: /* series converged! */
342
/* estimate error due to roundoff and cancellation */
343
*err = fabs( MACHEP * (n + maxt) );
348
ndone: /* series did not converge */
350
/* The following "Converging factors" are supposed to improve accuracy,
351
* but do not actually seem to accomplish very much. */
356
switch( type ) /* "type" given as subroutine argument */
359
alast *= ( 0.5 + (0.125 + 0.25*b - 0.5*a + 0.25*x - 0.25*n)/x );
363
alast *= 2.0/3.0 - b + 2.0*a + x - n;
370
/* estimate error due to roundoff, cancellation, and nonconvergence */
371
*err = MACHEP * (n + maxt) + fabs ( a0 );
378
/* series blew up: */
381
mtherr( "hyperg", TLOSS );