Debian Codegraph @

external/gsl/gsl_specfunc__hyperg.c

raw symbols SCIP
1 /* specfunc/hyperg.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 /* Author: G. Jungman */
21
22 /* Miscellaneous implementations of use
23 * for evaluation of hypergeometric functions.
24 */
25 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
26 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
27 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
28 #include "gsl_sf_exp.h"cxx . . $ `<file>/external/gsl/gsl_sf_exp.h`/
29 #include "gsl_sf_gamma.h"cxx . . $ `<file>/external/gsl/gsl_sf_gamma.h`/
30
31 #include "gsl_specfunc__error.h"cxx . . $ `<file>/external/gsl/gsl_specfunc__error.h`/
32 #include "gsl_specfunc__hyperg.h"cxx . . $ `<file>/external/gsl/gsl_specfunc__hyperg.h`/
33
34 #define SUM_LARGEcxx . . $ `external/gsl/gsl_specfunc__hyperg.c:34:9`! (1.0e-5*GSL_DBL_MAXcxx . . $ `external/gsl/gsl_machine.h:33:9`!)
35
36
37 int
38 gsl_sf_hyperg_1F1_series_ecxx . . $ gsl_sf_hyperg_1F1_series_e(aa5d4b97d4e04b77).(const double a, const double b, const double x,
39 gsl_sf_resultcxx . . $ gsl_sf_result# * result
40 )
41 {
42 double an = a;
43 double bn = b;
44 double n = 1.0;
45 double del = 1.0;
46 double abs_del = 1.0;
47 double max_abs_del = 1.0;
48 double sum_val = 1.0;
49 double sum_err = 0.0;
50
51 while(abs_del/fabs(sum_val) > 0.25*GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`!) {
52 double u, abs_u;
53
54 if(bn == 0.0) {
55 DOMAIN_ERRORcxx . . $ `external/gsl/gsl_specfunc__error.h:9:9`!(result);
56 }
57
58 if(an == 0.0) {
59 result->valcxx . . $ gsl_sf_result_struct#val. = sum_val;
60 result->errcxx . . $ gsl_sf_result_struct#err. = sum_err;
61 result->errcxx . . $ gsl_sf_result_struct#err. += 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * n * fabs(sum_val);
62 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
63 }
64
65 if (n > 10000.0) {
66 result->valcxx . . $ gsl_sf_result_struct#val. = sum_val;
67 result->errcxx . . $ gsl_sf_result_struct#err. = sum_err;
68 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("hypergeometric series failed to converge", GSL_EFAILED);
69 }
70
71 u = x * (an/(bn*n));
72 abs_u = fabs(u);
73 if(abs_u > 1.0 && max_abs_del > GSL_DBL_MAXcxx . . $ `external/gsl/gsl_machine.h:33:9`!/abs_u) {
74 result->valcxx . . $ gsl_sf_result_struct#val. = sum_val;
75 result->errcxx . . $ gsl_sf_result_struct#err. = fabs(sum_val);
76 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("overflow", GSL_EOVRFLW);
77 }
78 del *= u;
79 sum_val += del;
80 if(fabs(sum_val) > SUM_LARGEcxx . . $ `external/gsl/gsl_specfunc__hyperg.c:34:9`!) {
81 result->valcxx . . $ gsl_sf_result_struct#val. = sum_val;
82 result->errcxx . . $ gsl_sf_result_struct#err. = fabs(sum_val);
83 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("overflow", GSL_EOVRFLW);
84 }
85
86 abs_del = fabs(del);
87 max_abs_del = GSL_MAX_DBLcxx . . $ `external/gsl/gsl_math.h:177:9`!(abs_del, max_abs_del);
88 sum_err += 2.0*GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`!*abs_del;
89
90 an += 1.0;
91 bn += 1.0;
92 n += 1.0;
93 }
94
95 result->valcxx . . $ gsl_sf_result_struct#val. = sum_val;
96 result->errcxx . . $ gsl_sf_result_struct#err. = sum_err;
97 result->errcxx . . $ gsl_sf_result_struct#err. += abs_del;
98 result->errcxx . . $ gsl_sf_result_struct#err. += 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * n * fabs(sum_val);
99
100 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
101 }
102
103
104 int
105 gsl_sf_hyperg_1F1_large_b_ecxx . . $ gsl_sf_hyperg_1F1_large_b_e(aa5d4b97d4e04b77).(const double a, const double b, const double x, gsl_sf_resultcxx . . $ gsl_sf_result# * result)
106 {
107 if(fabs(x/b) < 1.0) {
108 const double u = x/b;
109 const double v = 1.0/(1.0-u);
110 const double pre = pow(v,a);
111 const double uv = u*v;
112 const double uv2 = uv*uv;
113 const double t1 = a*(a+1.0)/(2.0*b)*uv2;
114 const double t2a = a*(a+1.0)/(24.0*b*b)*uv2;
115 const double t2b = 12.0 + 16.0*(a+2.0)*uv + 3.0*(a+2.0)*(a+3.0)*uv2;
116 const double t2 = t2a*t2b;
117 result->valcxx . . $ gsl_sf_result_struct#val. = pre * (1.0 - t1 + t2);
118 result->errcxx . . $ gsl_sf_result_struct#err. = pre * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * (1.0 + fabs(t1) + fabs(t2));
119 result->errcxx . . $ gsl_sf_result_struct#err. += 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * fabs(result->valcxx . . $ gsl_sf_result_struct#val.);
120 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
121 }
122 else {
123 DOMAIN_ERRORcxx . . $ `external/gsl/gsl_specfunc__error.h:9:9`!(result);
124 }
125 }
126
127
128 int
129 gsl_sf_hyperg_U_large_b_ecxx . . $ gsl_sf_hyperg_U_large_b_e(ca18b6552f99364f).(const double a, const double b, const double x,
130 gsl_sf_resultcxx . . $ gsl_sf_result# * result,
131 double * ln_multiplier
132 )
133 {
134 double N = floor(b); /* b = N + eps */
135 double eps = b - N;
136
137 if(fabs(eps) < GSL_SQRT_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:18:9`!) {
138 double lnpre_val;
139 double lnpre_err;
140 gsl_sf_resultcxx . . $ gsl_sf_result# M;
141 if(b > 1.0) {
142 double tmp = (1.0-b)*log(x);
143 gsl_sf_resultcxx . . $ gsl_sf_result# lg_bm1;
144 gsl_sf_resultcxx . . $ gsl_sf_result# lg_a;
145 gsl_sf_lngamma_ecxx . . $ gsl_sf_lngamma_e(feafd9287608bc44).(b-1.0, &lg_bm1);
146 gsl_sf_lngamma_ecxx . . $ gsl_sf_lngamma_e(feafd9287608bc44).(a, &lg_a);
147 lnpre_val = tmp + x + lg_bm1.valcxx . . $ gsl_sf_result_struct#val. - lg_a.valcxx . . $ gsl_sf_result_struct#val.;
148 lnpre_err = lg_bm1.errcxx . . $ gsl_sf_result_struct#err. + lg_a.errcxx . . $ gsl_sf_result_struct#err. + GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * (fabs(x) + fabs(tmp));
149 gsl_sf_hyperg_1F1_large_b_ecxx . . $ gsl_sf_hyperg_1F1_large_b_e(aa5d4b97d4e04b77).(1.0-a, 2.0-b, -x, &M);
150 }
151 else {
152 gsl_sf_resultcxx . . $ gsl_sf_result# lg_1mb;
153 gsl_sf_resultcxx . . $ gsl_sf_result# lg_1pamb;
154 gsl_sf_lngamma_ecxx . . $ gsl_sf_lngamma_e(feafd9287608bc44).(1.0-b, &lg_1mb);
155 gsl_sf_lngamma_ecxx . . $ gsl_sf_lngamma_e(feafd9287608bc44).(1.0+a-b, &lg_1pamb);
156 lnpre_val = lg_1mb.valcxx . . $ gsl_sf_result_struct#val. - lg_1pamb.valcxx . . $ gsl_sf_result_struct#val.;
157 lnpre_err = lg_1mb.errcxx . . $ gsl_sf_result_struct#err. + lg_1pamb.errcxx . . $ gsl_sf_result_struct#err.;
158 gsl_sf_hyperg_1F1_large_b_ecxx . . $ gsl_sf_hyperg_1F1_large_b_e(aa5d4b97d4e04b77).(a, b, x, &M);
159 }
160
161 if(lnpre_val > GSL_LOG_DBL_MAXcxx . . $ `external/gsl/gsl_machine.h:39:9`!-10.0) {
162 result->valcxx . . $ gsl_sf_result_struct#val. = M.valcxx . . $ gsl_sf_result_struct#val.;
163 result->errcxx . . $ gsl_sf_result_struct#err. = M.errcxx . . $ gsl_sf_result_struct#err.;
164 *ln_multiplier = lnpre_val;
165 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("overflow", GSL_EOVRFLW);
166 }
167 else {
168 gsl_sf_resultcxx . . $ gsl_sf_result# epre;
169 int stat_e = gsl_sf_exp_err_ecxx . . $ gsl_sf_exp_err_e(38fedf92a6b14b51).(lnpre_val, lnpre_err, &epre);
170 result->valcxx . . $ gsl_sf_result_struct#val. = epre.valcxx . . $ gsl_sf_result_struct#val. * M.valcxx . . $ gsl_sf_result_struct#val.;
171 result->errcxx . . $ gsl_sf_result_struct#err. = epre.valcxx . . $ gsl_sf_result_struct#val. * M.errcxx . . $ gsl_sf_result_struct#err. + epre.errcxx . . $ gsl_sf_result_struct#err. * fabs(M.valcxx . . $ gsl_sf_result_struct#val.);
172 result->errcxx . . $ gsl_sf_result_struct#err. += 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * fabs(result->valcxx . . $ gsl_sf_result_struct#val.);
173 *ln_multiplier = 0.0;
174 return stat_e;
175 }
176 }
177 else {
178 double omb_lnx = (1.0-b)*log(x);
179 gsl_sf_resultcxx . . $ gsl_sf_result# lg_1mb; double sgn_1mb;
180 gsl_sf_resultcxx . . $ gsl_sf_result# lg_1pamb; double sgn_1pamb;
181 gsl_sf_resultcxx . . $ gsl_sf_result# lg_bm1; double sgn_bm1;
182 gsl_sf_resultcxx . . $ gsl_sf_result# lg_a; double sgn_a;
183 gsl_sf_resultcxx . . $ gsl_sf_result# M1, M2;
184 double lnpre1_val, lnpre2_val;
185 double lnpre1_err, lnpre2_err;
186 double sgpre1, sgpre2;
187 gsl_sf_hyperg_1F1_large_b_ecxx . . $ gsl_sf_hyperg_1F1_large_b_e(aa5d4b97d4e04b77).( a, b, x, &M1);
188 gsl_sf_hyperg_1F1_large_b_ecxx . . $ gsl_sf_hyperg_1F1_large_b_e(aa5d4b97d4e04b77).(1.0-a, 2.0-b, x, &M2);
189
190 gsl_sf_lngamma_sgn_ecxx . . $ gsl_sf_lngamma_sgn_e(c2004ae47d1ffebf).(1.0-b, &lg_1mb, &sgn_1mb);
191 gsl_sf_lngamma_sgn_ecxx . . $ gsl_sf_lngamma_sgn_e(c2004ae47d1ffebf).(1.0+a-b, &lg_1pamb, &sgn_1pamb);
192
193 gsl_sf_lngamma_sgn_ecxx . . $ gsl_sf_lngamma_sgn_e(c2004ae47d1ffebf).(b-1.0, &lg_bm1, &sgn_bm1);
194 gsl_sf_lngamma_sgn_ecxx . . $ gsl_sf_lngamma_sgn_e(c2004ae47d1ffebf).(a, &lg_a, &sgn_a);
195
196 lnpre1_val = lg_1mb.valcxx . . $ gsl_sf_result_struct#val. - lg_1pamb.valcxx . . $ gsl_sf_result_struct#val.;
197 lnpre1_err = lg_1mb.errcxx . . $ gsl_sf_result_struct#err. + lg_1pamb.errcxx . . $ gsl_sf_result_struct#err.;
198 lnpre2_val = lg_bm1.valcxx . . $ gsl_sf_result_struct#val. - lg_a.valcxx . . $ gsl_sf_result_struct#val. - omb_lnx - x;
199 lnpre2_err = lg_bm1.errcxx . . $ gsl_sf_result_struct#err. + lg_a.errcxx . . $ gsl_sf_result_struct#err. + GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * (fabs(omb_lnx)+fabs(x));
200 sgpre1 = sgn_1mb * sgn_1pamb;
201 sgpre2 = sgn_bm1 * sgn_a;
202
203 if(lnpre1_val > GSL_LOG_DBL_MAXcxx . . $ `external/gsl/gsl_machine.h:39:9`!-10.0 || lnpre2_val > GSL_LOG_DBL_MAXcxx . . $ `external/gsl/gsl_machine.h:39:9`!-10.0) {
204 double max_lnpre_val = GSL_MAXcxx . . $ `external/gsl/gsl_math.h:122:9`!(lnpre1_val,lnpre2_val);
205 double max_lnpre_err = GSL_MAXcxx . . $ `external/gsl/gsl_math.h:122:9`!(lnpre1_err,lnpre2_err);
206 double lp1 = lnpre1_val - max_lnpre_val;
207 double lp2 = lnpre2_val - max_lnpre_val;
208 double t1 = sgpre1*exp(lp1);
209 double t2 = sgpre2*exp(lp2);
210 result->valcxx . . $ gsl_sf_result_struct#val. = t1*M1.valcxx . . $ gsl_sf_result_struct#val. + t2*M2.valcxx . . $ gsl_sf_result_struct#val.;
211 result->errcxx . . $ gsl_sf_result_struct#err. = fabs(t1)*M1.errcxx . . $ gsl_sf_result_struct#err. + fabs(t2)*M2.errcxx . . $ gsl_sf_result_struct#err.;
212 result->errcxx . . $ gsl_sf_result_struct#err. += GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * exp(max_lnpre_err) * (fabs(t1*M1.valcxx . . $ gsl_sf_result_struct#val.) + fabs(t2*M2.valcxx . . $ gsl_sf_result_struct#val.));
213 result->errcxx . . $ gsl_sf_result_struct#err. += 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * fabs(result->valcxx . . $ gsl_sf_result_struct#val.);
214 *ln_multiplier = max_lnpre_val;
215 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("overflow", GSL_EOVRFLW);
216 }
217 else {
218 double t1 = sgpre1*exp(lnpre1_val);
219 double t2 = sgpre2*exp(lnpre2_val);
220 result->valcxx . . $ gsl_sf_result_struct#val. = t1*M1.valcxx . . $ gsl_sf_result_struct#val. + t2*M2.valcxx . . $ gsl_sf_result_struct#val.;
221 result->errcxx . . $ gsl_sf_result_struct#err. = fabs(t1) * M1.errcxx . . $ gsl_sf_result_struct#err. + fabs(t2)*M2.errcxx . . $ gsl_sf_result_struct#err.;
222 result->errcxx . . $ gsl_sf_result_struct#err. += GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * (exp(lnpre1_err)*fabs(t1*M1.valcxx . . $ gsl_sf_result_struct#val.) + exp(lnpre2_err)*fabs(t2*M2.valcxx . . $ gsl_sf_result_struct#val.));
223 result->errcxx . . $ gsl_sf_result_struct#err. += 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * fabs(result->valcxx . . $ gsl_sf_result_struct#val.);
224 *ln_multiplier = 0.0;
225 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
226 }
227 }
228 }
229
230
231
232 /* [Carlson, p.109] says the error in truncating this asymptotic series
233 * is less than the absolute value of the first neglected term.
234 *
235 * A termination argument is provided, so that the series will
236 * be summed at most up to n=n_trunc. If n_trunc is set negative,
237 * then the series is summed until it appears to start diverging.
238 */
239 int
240 gsl_sf_hyperg_2F0_series_ecxx . . $ gsl_sf_hyperg_2F0_series_e(f6157083192e2c9f).(const double a, const double b, const double x,
241 int n_trunc,
242 gsl_sf_resultcxx . . $ gsl_sf_result# * result
243 )
244 {
245 const int maxiter = 2000;
246 double an = a;
247 double bn = b;
248 double n = 1.0;
249 double sum = 1.0;
250 double del = 1.0;
251 double abs_del = 1.0;
252 double max_abs_del = 1.0;
253 double last_abs_del = 1.0;
254
255 while(abs_del/fabs(sum) > GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! && n < maxiter) {
256
257 double u = an * (bn/n * x);
258 double abs_u = fabs(u);
259
260 if(abs_u > 1.0 && (max_abs_del > GSL_DBL_MAXcxx . . $ `external/gsl/gsl_machine.h:33:9`!/abs_u)) {
261 result->valcxx . . $ gsl_sf_result_struct#val. = sum;
262 result->errcxx . . $ gsl_sf_result_struct#err. = fabs(sum);
263 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("overflow", GSL_EOVRFLW);
264 }
265
266 del *= u;
267 sum += del;
268
269 abs_del = fabs(del);
270
271 if(abs_del > last_abs_del) break; /* series is probably starting to grow */
272
273 last_abs_del = abs_del;
274 max_abs_del = GSL_MAXcxx . . $ `external/gsl/gsl_math.h:122:9`!(abs_del, max_abs_del);
275
276 an += 1.0;
277 bn += 1.0;
278 n += 1.0;
279
280 if(an == 0.0 || bn == 0.0) break; /* series terminated */
281
282 if(n_trunc >= 0 && n >= n_trunc) break; /* reached requested timeout */
283 }
284
285 result->valcxx . . $ gsl_sf_result_struct#val. = sum;
286 result->errcxx . . $ gsl_sf_result_struct#err. = GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * n + abs_del;
287 if(n >= maxiter)
288 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("error", GSL_EMAXITER);
289 else
290 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
291 }