| 1 | /* specfunc/legendre_con.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 | #include "gsl__config.h" |
| 23 | #include "gsl_math.h" |
| 24 | #include "gsl_errno.h" |
| 25 | #include "gsl_poly.h" |
| 26 | #include "gsl_sf_exp.h" |
| 27 | #include "gsl_sf_trig.h" |
| 28 | #include "gsl_sf_gamma.h" |
| 29 | #include "gsl_sf_ellint.h" |
| 30 | #include "gsl_sf_pow_int.h" |
| 31 | #include "gsl_sf_bessel.h" |
| 32 | #include "gsl_sf_hyperg.h" |
| 33 | #include "gsl_sf_legendre.h" |
| 34 | |
| 35 | #include "gsl_specfunc__error.h" |
| 36 | #include "gsl_specfunc__legendre.h" |
| 37 | |
| 38 | #define Root_2OverPi_ 0.797884560802865355879892 |
| 39 | #define locEPS (1000.0*GSL_DBL_EPSILON) |
| 40 | |
| 41 | |
| 42 | /*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/ |
| 43 | |
| 44 | |
| 45 | #define RECURSE_LARGE (1.0e-5*GSL_DBL_MAX) |
| 46 | #define RECURSE_SMALL (1.0e+5*GSL_DBL_MIN) |
| 47 | |
| 48 | |
| 49 | /* Continued fraction for f_{ell+1}/f_ell |
| 50 | * f_ell := P^{-mu-ell}_{-1/2 + I tau}(x), x < 1.0 |
| 51 | * |
| 52 | * Uses standard CF method from Temme's book. |
| 53 | */ |
| 54 | static |
| 55 | int |
| 56 | conicalP_negmu_xlt1_CF1(const double mu, const int ell, const double tau, |
| 57 | const double x, gsl_sf_result * result) |
| 58 | { |
| 59 | const double RECUR_BIG = GSL_SQRT_DBL_MAX; |
| 60 | const int maxiter = 5000; |
| 61 | int n = 1; |
| 62 | double xi = x/(sqrt(1.0-x)*sqrt(1.0+x)); |
| 63 | double Anm2 = 1.0; |
| 64 | double Bnm2 = 0.0; |
| 65 | double Anm1 = 0.0; |
| 66 | double Bnm1 = 1.0; |
| 67 | double a1 = 1.0; |
| 68 | double b1 = 2.0*(mu + ell + 1.0) * xi; |
| 69 | double An = b1*Anm1 + a1*Anm2; |
| 70 | double Bn = b1*Bnm1 + a1*Bnm2; |
| 71 | double an, bn; |
| 72 | double fn = An/Bn; |
| 73 | |
| 74 | while(n < maxiter) { |
| 75 | double old_fn; |
| 76 | double del; |
| 77 | n++; |
| 78 | Anm2 = Anm1; |
| 79 | Bnm2 = Bnm1; |
| 80 | Anm1 = An; |
| 81 | Bnm1 = Bn; |
| 82 | an = tau*tau + (mu - 0.5 + ell + n)*(mu - 0.5 + ell + n); |
| 83 | bn = 2.0*(ell + mu + n) * xi; |
| 84 | An = bn*Anm1 + an*Anm2; |
| 85 | Bn = bn*Bnm1 + an*Bnm2; |
| 86 | |
| 87 | if(fabs(An) > RECUR_BIG || fabs(Bn) > RECUR_BIG) { |
| 88 | An /= RECUR_BIG; |
| 89 | Bn /= RECUR_BIG; |
| 90 | Anm1 /= RECUR_BIG; |
| 91 | Bnm1 /= RECUR_BIG; |
| 92 | Anm2 /= RECUR_BIG; |
| 93 | Bnm2 /= RECUR_BIG; |
| 94 | } |
| 95 | |
| 96 | old_fn = fn; |
| 97 | fn = An/Bn; |
| 98 | del = old_fn/fn; |
| 99 | |
| 100 | if(fabs(del - 1.0) < 2.0*GSL_DBL_EPSILON) break; |
| 101 | } |
| 102 | |
| 103 | result->val = fn; |
| 104 | result->err = 4.0 * GSL_DBL_EPSILON * (sqrt(n) + 1.0) * fabs(fn); |
| 105 | |
| 106 | if(n >= maxiter) |
| 107 | GSL_ERROR ("error", GSL_EMAXITER); |
| 108 | else |
| 109 | return GSL_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | /* Continued fraction for f_{ell+1}/f_ell |
| 114 | * f_ell := P^{-mu-ell}_{-1/2 + I tau}(x), x >= 1.0 |
| 115 | * |
| 116 | * Uses Gautschi (Euler) equivalent series. |
| 117 | */ |
| 118 | static |
| 119 | int |
| 120 | conicalP_negmu_xgt1_CF1(const double mu, const int ell, const double tau, |
| 121 | const double x, gsl_sf_result * result) |
| 122 | { |
| 123 | const int maxk = 20000; |
| 124 | const double gamma = 1.0-1.0/(x*x); |
| 125 | const double pre = sqrt(x-1.0)*sqrt(x+1.0) / (x*(2.0*(ell+mu+1.0))); |
| 126 | double tk = 1.0; |
| 127 | double sum = 1.0; |
| 128 | double rhok = 0.0; |
| 129 | int k; |
| 130 | |
| 131 | for(k=1; k<maxk; k++) { |
| 132 | double tlk = 2.0*(ell + mu + k); |
| 133 | double l1k = (ell + mu - 0.5 + 1.0 + k); |
| 134 | double ak = -(tau*tau + l1k*l1k)/(tlk*(tlk+2.0)) * gamma; |
| 135 | rhok = -ak*(1.0 + rhok)/(1.0 + ak*(1.0 + rhok)); |
| 136 | tk *= rhok; |
| 137 | sum += tk; |
| 138 | if(fabs(tk/sum) < GSL_DBL_EPSILON) break; |
| 139 | } |
| 140 | |
| 141 | result->val = pre * sum; |
| 142 | result->err = fabs(pre * tk); |
| 143 | result->err += 2.0 * GSL_DBL_EPSILON * (sqrt(k) + 1.0) * fabs(pre*sum); |
| 144 | |
| 145 | if(k >= maxk) |
| 146 | GSL_ERROR ("error", GSL_EMAXITER); |
| 147 | else |
| 148 | return GSL_SUCCESS; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | /* Implementation of large negative mu asymptotic |
| 153 | * [Dunster, Proc. Roy. Soc. Edinburgh 119A, 311 (1991), p. 326] |
| 154 | */ |
| 155 | |
| 156 | inline |
| 157 | static double olver_U1(double beta2, double p) |
| 158 | { |
| 159 | return (p-1.0)/(24.0*(1.0+beta2)) * (3.0 + beta2*(2.0 + 5.0*p*(1.0+p))); |
| 160 | } |
| 161 | |
| 162 | inline |
| 163 | static double olver_U2(double beta2, double p) |
| 164 | { |
| 165 | double beta4 = beta2*beta2; |
| 166 | double p2 = p*p; |
| 167 | double poly1 = 4.0*beta4 + 84.0*beta2 - 63.0; |
| 168 | double poly2 = 16.0*beta4 + 90.0*beta2 - 81.0; |
| 169 | double poly3 = beta2*p2*(97.0*beta2 - 432.0 + 77.0*p*(beta2-6.0) - 385.0*beta2*p2*(1.0 + p)); |
| 170 | return (1.0-p)/(1152.0*(1.0+beta2)) * (poly1 + poly2 + poly3); |
| 171 | } |
| 172 | |
| 173 | #if 0 |
| 174 | static double olver_U3(double beta2, double p) |
| 175 | { |
| 176 | double beta4 = beta2*beta2; |
| 177 | double beta6 = beta4*beta2; |
| 178 | double opb2s = (1.0+beta2)*(1.0+beta2); |
| 179 | double den = 39813120.0 * opb2s*opb2s; |
| 180 | double poly1 = gsl_poly_eval(U3c1, 4, p); |
| 181 | double poly2 = gsl_poly_eval(U3c2, 6, p); |
| 182 | double poly3 = gsl_poly_eval(U3c3, 8, p); |
| 183 | double poly4 = gsl_poly_eval(U3c4, 10, p); |
| 184 | double poly5 = gsl_poly_eval(U3c5, 12, p); |
| 185 | |
| 186 | return (p-1.0)*( 1215.0*poly1 + 324.0*beta2*poly2 |
| 187 | + 54.0*beta4*poly3 + 12.0*beta6*poly4 |
| 188 | + beta4*beta4*poly5 |
| 189 | ) / den; |
| 190 | } |
| 191 | #endif /* 0 */ |
| 192 | |
| 193 | |
| 194 | /* Large negative mu asymptotic |
| 195 | * P^{-mu}_{-1/2 + I tau}, mu -> Inf |
| 196 | * |x| < 1 |
| 197 | * |
| 198 | * [Dunster, Proc. Roy. Soc. Edinburgh 119A, 311 (1991), p. 326] |
| 199 | */ |
| 200 | int |
| 201 | gsl_sf_conicalP_xlt1_large_neg_mu_e(double mu, double tau, double x, |
| 202 | gsl_sf_result * result, double * ln_multiplier) |
| 203 | { |
| 204 | double beta = tau/mu; |
| 205 | double beta2 = beta*beta; |
| 206 | double S = beta * acos((1.0-beta2)/(1.0+beta2)); |
| 207 | double p = x/sqrt(beta2*(1.0-x*x) + 1.0); |
| 208 | gsl_sf_result lg_mup1; |
| 209 | int lg_stat = gsl_sf_lngamma_e(mu+1.0, &lg_mup1); |
| 210 | double ln_pre_1 = 0.5*mu*(S - log(1.0+beta2) + log((1.0-p)/(1.0+p))) - lg_mup1.val; |
| 211 | double ln_pre_2 = -0.25 * log(1.0 + beta2*(1.0-x)); |
| 212 | double ln_pre_3 = -tau * atan(p*beta); |
| 213 | double ln_pre = ln_pre_1 + ln_pre_2 + ln_pre_3; |
| 214 | double sum = 1.0 - olver_U1(beta2, p)/mu + olver_U2(beta2, p)/(mu*mu); |
| 215 | |
| 216 | if(sum == 0.0) { |
| 217 | result->val = 0.0; |
| 218 | result->err = 0.0; |
| 219 | *ln_multiplier = 0.0; |
| 220 | return GSL_SUCCESS; |
| 221 | } |
| 222 | else { |
| 223 | int stat_e = gsl_sf_exp_mult_e(ln_pre, sum, result); |
| 224 | if(stat_e != GSL_SUCCESS) { |
| 225 | result->val = sum; |
| 226 | result->err = 2.0 * GSL_DBL_EPSILON * fabs(sum); |
| 227 | *ln_multiplier = ln_pre; |
| 228 | } |
| 229 | else { |
| 230 | *ln_multiplier = 0.0; |
| 231 | } |
| 232 | return lg_stat; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | /* Implementation of large tau asymptotic |
| 238 | * |
| 239 | * A_n^{-mu}, B_n^{-mu} [Olver, p.465, 469] |
| 240 | */ |
| 241 | |
| 242 | inline |
| 243 | static double olver_B0_xi(double mu, double xi) |
| 244 | { |
| 245 | return (1.0 - 4.0*mu*mu)/(8.0*xi) * (1.0/tanh(xi) - 1.0/xi); |
| 246 | } |
| 247 | |
| 248 | static double olver_A1_xi(double mu, double xi, double x) |
| 249 | { |
| 250 | double B = olver_B0_xi(mu, xi); |
| 251 | double psi; |
| 252 | if(fabs(x - 1.0) < GSL_ROOT4_DBL_EPSILON) { |
| 253 | double y = x - 1.0; |
| 254 | double s = -1.0/3.0 + y*(2.0/15.0 - y *(61.0/945.0 - 452.0/14175.0*y)); |
| 255 | psi = (4.0*mu*mu - 1.0)/16.0 * s; |
| 256 | } |
| 257 | else { |
| 258 | psi = (4.0*mu*mu - 1.0)/16.0 * (1.0/(x*x-1.0) - 1.0/(xi*xi)); |
| 259 | } |
| 260 | return 0.5*xi*xi*B*B + (mu+0.5)*B - psi + mu/6.0*(0.25 - mu*mu); |
| 261 | } |
| 262 | |
| 263 | inline |
| 264 | static double olver_B0_th(double mu, double theta) |
| 265 | { |
| 266 | return -(1.0 - 4.0*mu*mu)/(8.0*theta) * (1.0/tan(theta) - 1.0/theta); |
| 267 | } |
| 268 | |
| 269 | static double olver_A1_th(double mu, double theta, double x) |
| 270 | { |
| 271 | double B = olver_B0_th(mu, theta); |
| 272 | double psi; |
| 273 | if(fabs(x - 1.0) < GSL_ROOT4_DBL_EPSILON) { |
| 274 | double y = 1.0 - x; |
| 275 | double s = -1.0/3.0 + y*(2.0/15.0 - y *(61.0/945.0 - 452.0/14175.0*y)); |
| 276 | psi = (4.0*mu*mu - 1.0)/16.0 * s; |
| 277 | } |
| 278 | else { |
| 279 | psi = (4.0*mu*mu - 1.0)/16.0 * (1.0/(x*x-1.0) + 1.0/(theta*theta)); |
| 280 | } |
| 281 | return -0.5*theta*theta*B*B + (mu+0.5)*B - psi + mu/6.0*(0.25 - mu*mu); |
| 282 | } |
| 283 | |
| 284 | |
| 285 | /* Large tau uniform asymptotics |
| 286 | * P^{-mu}_{-1/2 + I tau} |
| 287 | * 1 < x |
| 288 | * tau -> Inf |
| 289 | * [Olver, p. 469] |
| 290 | */ |
| 291 | int |
| 292 | gsl_sf_conicalP_xgt1_neg_mu_largetau_e(const double mu, const double tau, |
| 293 | const double x, double acosh_x, |
| 294 | gsl_sf_result * result, double * ln_multiplier) |
| 295 | { |
| 296 | double xi = acosh_x; |
| 297 | double ln_xi_pre; |
| 298 | double ln_pre; |
| 299 | double sumA, sumB, sum; |
| 300 | double arg; |
| 301 | gsl_sf_result J_mup1; |
| 302 | gsl_sf_result J_mu; |
| 303 | double J_mum1; |
| 304 | |
| 305 | if(xi < GSL_ROOT4_DBL_EPSILON) { |
| 306 | ln_xi_pre = -xi*xi/6.0; /* log(1.0 - xi*xi/6.0) */ |
| 307 | } |
| 308 | else { |
| 309 | gsl_sf_result lnshxi; |
| 310 | gsl_sf_lnsinh_e(xi, &lnshxi); |
| 311 | ln_xi_pre = log(xi) - lnshxi.val; /* log(xi/sinh(xi) */ |
| 312 | } |
| 313 | |
| 314 | ln_pre = 0.5*ln_xi_pre - mu*log(tau); |
| 315 | |
| 316 | arg = tau*xi; |
| 317 | |
| 318 | gsl_sf_bessel_Jnu_e(mu + 1.0, arg, &J_mup1); |
| 319 | gsl_sf_bessel_Jnu_e(mu, arg, &J_mu); |
| 320 | J_mum1 = -J_mup1.val + 2.0*mu/arg*J_mu.val; /* careful of mu < 1 */ |
| 321 | |
| 322 | sumA = 1.0 - olver_A1_xi(-mu, xi, x)/(tau*tau); |
| 323 | sumB = olver_B0_xi(-mu, xi); |
| 324 | sum = J_mu.val * sumA - xi/tau * J_mum1 * sumB; |
| 325 | |
| 326 | if(sum == 0.0) { |
| 327 | result->val = 0.0; |
| 328 | result->err = 0.0; |
| 329 | *ln_multiplier = 0.0; |
| 330 | return GSL_SUCCESS; |
| 331 | } |
| 332 | else { |
| 333 | int stat_e = gsl_sf_exp_mult_e(ln_pre, sum, result); |
| 334 | if(stat_e != GSL_SUCCESS) { |
| 335 | result->val = sum; |
| 336 | result->err = 2.0 * GSL_DBL_EPSILON * fabs(sum); |
| 337 | *ln_multiplier = ln_pre; |
| 338 | } |
| 339 | else { |
| 340 | *ln_multiplier = 0.0; |
| 341 | } |
| 342 | return GSL_SUCCESS; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /* Large tau uniform asymptotics |
| 348 | * P^{-mu}_{-1/2 + I tau} |
| 349 | * -1 < x < 1 |
| 350 | * tau -> Inf |
| 351 | * [Olver, p. 473] |
| 352 | */ |
| 353 | int |
| 354 | gsl_sf_conicalP_xlt1_neg_mu_largetau_e(const double mu, const double tau, |
| 355 | const double x, const double acos_x, |
| 356 | gsl_sf_result * result, double * ln_multiplier) |
| 357 | { |
| 358 | double theta = acos_x; |
| 359 | double ln_th_pre; |
| 360 | double ln_pre; |
| 361 | double sumA, sumB, sum, sumerr; |
| 362 | double arg; |
| 363 | gsl_sf_result I_mup1, I_mu; |
| 364 | double I_mum1; |
| 365 | |
| 366 | if(theta < GSL_ROOT4_DBL_EPSILON) { |
| 367 | ln_th_pre = theta*theta/6.0; /* log(1.0 + theta*theta/6.0) */ |
| 368 | } |
| 369 | else { |
| 370 | ln_th_pre = log(theta/sin(theta)); |
| 371 | } |
| 372 | |
| 373 | ln_pre = 0.5 * ln_th_pre - mu * log(tau); |
| 374 | |
| 375 | arg = tau*theta; |
| 376 | gsl_sf_bessel_Inu_e(mu + 1.0, arg, &I_mup1); |
| 377 | gsl_sf_bessel_Inu_e(mu, arg, &I_mu); |
| 378 | I_mum1 = I_mup1.val + 2.0*mu/arg * I_mu.val; /* careful of mu < 1 */ |
| 379 | |
| 380 | sumA = 1.0 - olver_A1_th(-mu, theta, x)/(tau*tau); |
| 381 | sumB = olver_B0_th(-mu, theta); |
| 382 | sum = I_mu.val * sumA - theta/tau * I_mum1 * sumB; |
| 383 | sumerr = fabs(I_mu.err * sumA); |
| 384 | sumerr += fabs(I_mup1.err * theta/tau * sumB); |
| 385 | sumerr += fabs(I_mu.err * theta/tau * sumB * 2.0 * mu/arg); |
| 386 | |
| 387 | if(sum == 0.0) { |
| 388 | result->val = 0.0; |
| 389 | result->err = 0.0; |
| 390 | *ln_multiplier = 0.0; |
| 391 | return GSL_SUCCESS; |
| 392 | } |
| 393 | else { |
| 394 | int stat_e = gsl_sf_exp_mult_e(ln_pre, sum, result); |
| 395 | if(stat_e != GSL_SUCCESS) { |
| 396 | result->val = sum; |
| 397 | result->err = sumerr; |
| 398 | result->err += GSL_DBL_EPSILON * fabs(sum); |
| 399 | *ln_multiplier = ln_pre; |
| 400 | } |
| 401 | else { |
| 402 | *ln_multiplier = 0.0; |
| 403 | } |
| 404 | return GSL_SUCCESS; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | |
| 409 | /* Hypergeometric function which appears in the |
| 410 | * large x expansion below: |
| 411 | * |
| 412 | * 2F1(1/4 - mu/2 - I tau/2, 3/4 - mu/2 - I tau/2, 1 - I tau, y) |
| 413 | * |
| 414 | * Note that for the usage below y = 1/x^2; |
| 415 | */ |
| 416 | static |
| 417 | int |
| 418 | conicalP_hyperg_large_x(const double mu, const double tau, const double y, |
| 419 | double * reF, double * imF) |
| 420 | { |
| 421 | const int kmax = 1000; |
| 422 | const double re_a = 0.25 - 0.5*mu; |
| 423 | const double re_b = 0.75 - 0.5*mu; |
| 424 | const double re_c = 1.0; |
| 425 | const double im_a = -0.5*tau; |
| 426 | const double im_b = -0.5*tau; |
| 427 | const double im_c = -tau; |
| 428 | |
| 429 | double re_sum = 1.0; |
| 430 | double im_sum = 0.0; |
| 431 | double re_term = 1.0; |
| 432 | double im_term = 0.0; |
| 433 | int k; |
| 434 | |
| 435 | for(k=1; k<=kmax; k++) { |
| 436 | double re_ak = re_a + k - 1.0; |
| 437 | double re_bk = re_b + k - 1.0; |
| 438 | double re_ck = re_c + k - 1.0; |
| 439 | double im_ak = im_a; |
| 440 | double im_bk = im_b; |
| 441 | double im_ck = im_c; |
| 442 | double den = re_ck*re_ck + im_ck*im_ck; |
| 443 | double re_multiplier = ((re_ak*re_bk - im_ak*im_bk)*re_ck + im_ck*(im_ak*re_bk + re_ak*im_bk)) / den; |
| 444 | double im_multiplier = ((im_ak*re_bk + re_ak*im_bk)*re_ck - im_ck*(re_ak*re_bk - im_ak*im_bk)) / den; |
| 445 | double re_tmp = re_multiplier*re_term - im_multiplier*im_term; |
| 446 | double im_tmp = im_multiplier*re_term + re_multiplier*im_term; |
| 447 | double asum = fabs(re_sum) + fabs(im_sum); |
| 448 | re_term = y/k * re_tmp; |
| 449 | im_term = y/k * im_tmp; |
| 450 | if(fabs(re_term/asum) < GSL_DBL_EPSILON && fabs(im_term/asum) < GSL_DBL_EPSILON) break; |
| 451 | re_sum += re_term; |
| 452 | im_sum += im_term; |
| 453 | } |
| 454 | |
| 455 | *reF = re_sum; |
| 456 | *imF = im_sum; |
| 457 | |
| 458 | if(k == kmax) |
| 459 | GSL_ERROR ("error", GSL_EMAXITER); |
| 460 | else |
| 461 | return GSL_SUCCESS; |
| 462 | } |
| 463 | |
| 464 | |
| 465 | /* P^{mu}_{-1/2 + I tau} |
| 466 | * x->Inf |
| 467 | */ |
| 468 | int |
| 469 | gsl_sf_conicalP_large_x_e(const double mu, const double tau, const double x, |
| 470 | gsl_sf_result * result, double * ln_multiplier) |
| 471 | { |
| 472 | /* 2F1 term |
| 473 | */ |
| 474 | double y = ( x < 0.5*GSL_SQRT_DBL_MAX ? 1.0/(x*x) : 0.0 ); |
| 475 | double reF, imF; |
| 476 | int stat_F = conicalP_hyperg_large_x(mu, tau, y, &reF, &imF); |
| 477 | |
| 478 | /* f = Gamma(+i tau)/Gamma(1/2 - mu + i tau) |
| 479 | * FIXME: shift so it's better for tau-> 0 |
| 480 | */ |
| 481 | gsl_sf_result lgr_num, lgth_num; |
| 482 | gsl_sf_result lgr_den, lgth_den; |
| 483 | int stat_gn = gsl_sf_lngamma_complex_e(0.0,tau,&lgr_num,&lgth_num); |
| 484 | int stat_gd = gsl_sf_lngamma_complex_e(0.5-mu,tau,&lgr_den,&lgth_den); |
| 485 | |
| 486 | double angle = lgth_num.val - lgth_den.val + atan2(imF,reF); |
| 487 | |
| 488 | double lnx = log(x); |
| 489 | double lnxp1 = log(x+1.0); |
| 490 | double lnxm1 = log(x-1.0); |
| 491 | double lnpre_const = 0.5*M_LN2 - 0.5*M_LNPI; |
| 492 | double lnpre_comm = (mu-0.5)*lnx - 0.5*mu*(lnxp1 + lnxm1); |
| 493 | double lnpre_err = GSL_DBL_EPSILON * (0.5*M_LN2 + 0.5*M_LNPI) |
| 494 | + GSL_DBL_EPSILON * fabs((mu-0.5)*lnx) |
| 495 | + GSL_DBL_EPSILON * fabs(0.5*mu)*(fabs(lnxp1)+fabs(lnxm1)); |
| 496 | |
| 497 | /* result = pre*|F|*|f| * cos(angle - tau * (log(x)+M_LN2)) |
| 498 | */ |
| 499 | gsl_sf_result cos_result; |
| 500 | int stat_cos = gsl_sf_cos_e(angle + tau*(log(x) + M_LN2), &cos_result); |
| 501 | int status = GSL_ERROR_SELECT_4(stat_cos, stat_gd, stat_gn, stat_F); |
| 502 | if(cos_result.val == 0.0) { |
| 503 | result->val = 0.0; |
| 504 | result->err = 0.0; |
| 505 | return status; |
| 506 | } |
| 507 | else { |
| 508 | double lnFf_val = 0.5*log(reF*reF+imF*imF) + lgr_num.val - lgr_den.val; |
| 509 | double lnFf_err = lgr_num.err + lgr_den.err + GSL_DBL_EPSILON * fabs(lnFf_val); |
| 510 | double lnnoc_val = lnpre_const + lnpre_comm + lnFf_val; |
| 511 | double lnnoc_err = lnpre_err + lnFf_err + GSL_DBL_EPSILON * fabs(lnnoc_val); |
| 512 | int stat_e = gsl_sf_exp_mult_err_e(lnnoc_val, lnnoc_err, |
| 513 | cos_result.val, cos_result.err, |
| 514 | result); |
| 515 | if(stat_e == GSL_SUCCESS) { |
| 516 | *ln_multiplier = 0.0; |
| 517 | } |
| 518 | else { |
| 519 | result->val = cos_result.val; |
| 520 | result->err = cos_result.err; |
| 521 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 522 | *ln_multiplier = lnnoc_val; |
| 523 | } |
| 524 | return status; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | |
| 529 | /* P^{mu}_{-1/2 + I tau} first hypergeometric representation |
| 530 | * -1 < x < 1 |
| 531 | * This is more effective for |x| small, however it will work w/o |
| 532 | * reservation for any x < 0 because everything is positive |
| 533 | * definite in that case. |
| 534 | * |
| 535 | * [Kolbig, (3)] (note typo in args of gamma functions) |
| 536 | * [Bateman, (22)] (correct form) |
| 537 | */ |
| 538 | static |
| 539 | int |
| 540 | conicalP_xlt1_hyperg_A(double mu, double tau, double x, gsl_sf_result * result) |
| 541 | { |
| 542 | double x2 = x*x; |
| 543 | double err_amp = 1.0 + 1.0/(GSL_DBL_EPSILON + fabs(1.0-fabs(x))); |
| 544 | double pre_val = M_SQRTPI / pow(0.5*sqrt(1-x2), mu); |
| 545 | double pre_err = err_amp * GSL_DBL_EPSILON * (fabs(mu)+1.0) * fabs(pre_val) ; |
| 546 | gsl_sf_result ln_g1, ln_g2, arg_g1, arg_g2; |
| 547 | gsl_sf_result F1, F2; |
| 548 | gsl_sf_result pre1, pre2; |
| 549 | double t1_val, t1_err; |
| 550 | double t2_val, t2_err; |
| 551 | |
| 552 | int stat_F1 = gsl_sf_hyperg_2F1_conj_e(0.25 - 0.5*mu, 0.5*tau, 0.5, x2, &F1); |
| 553 | int stat_F2 = gsl_sf_hyperg_2F1_conj_e(0.75 - 0.5*mu, 0.5*tau, 1.5, x2, &F2); |
| 554 | int status = GSL_ERROR_SELECT_2(stat_F1, stat_F2); |
| 555 | |
| 556 | gsl_sf_lngamma_complex_e(0.75 - 0.5*mu, -0.5*tau, &ln_g1, &arg_g1); |
| 557 | gsl_sf_lngamma_complex_e(0.25 - 0.5*mu, -0.5*tau, &ln_g2, &arg_g2); |
| 558 | |
| 559 | gsl_sf_exp_err_e(-2.0*ln_g1.val, 2.0*ln_g1.err, &pre1); |
| 560 | gsl_sf_exp_err_e(-2.0*ln_g2.val, 2.0*ln_g2.err, &pre2); |
| 561 | pre2.val *= -2.0*x; |
| 562 | pre2.err *= 2.0*fabs(x); |
| 563 | pre2.err += GSL_DBL_EPSILON * fabs(pre2.val); |
| 564 | |
| 565 | t1_val = pre1.val * F1.val; |
| 566 | t1_err = fabs(pre1.val) * F1.err + pre1.err * fabs(F1.val); |
| 567 | t2_val = pre2.val * F2.val; |
| 568 | t2_err = fabs(pre2.val) * F2.err + pre2.err * fabs(F2.val); |
| 569 | |
| 570 | result->val = pre_val * (t1_val + t2_val); |
| 571 | result->err = pre_val * (t1_err + t2_err); |
| 572 | result->err += pre_err * fabs(t1_val + t2_val); |
| 573 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 574 | |
| 575 | return status; |
| 576 | } |
| 577 | |
| 578 | |
| 579 | /* P^{mu}_{-1/2 + I tau} |
| 580 | * defining hypergeometric representation |
| 581 | * [Abramowitz+Stegun, 8.1.2] |
| 582 | * 1 < x < 3 |
| 583 | * effective for x near 1 |
| 584 | * |
| 585 | */ |
| 586 | #if 0 |
| 587 | static |
| 588 | int |
| 589 | conicalP_def_hyperg(double mu, double tau, double x, double * result) |
| 590 | { |
| 591 | double F; |
| 592 | int stat_F = gsl_sf_hyperg_2F1_conj_renorm_e(0.5, tau, 1.0-mu, 0.5*(1.0-x), &F); |
| 593 | *result = pow((x+1.0)/(x-1.0), 0.5*mu) * F; |
| 594 | return stat_F; |
| 595 | } |
| 596 | #endif /* 0 */ |
| 597 | |
| 598 | |
| 599 | /* P^{mu}_{-1/2 + I tau} second hypergeometric representation |
| 600 | * [Zhurina+Karmazina, (3.1)] |
| 601 | * -1 < x < 3 |
| 602 | * effective for x near 1 |
| 603 | * |
| 604 | */ |
| 605 | #if 0 |
| 606 | static |
| 607 | int |
| 608 | conicalP_xnear1_hyperg_C(double mu, double tau, double x, double * result) |
| 609 | { |
| 610 | double ln_pre, arg_pre; |
| 611 | double ln_g1, arg_g1; |
| 612 | double ln_g2, arg_g2; |
| 613 | double F; |
| 614 | |
| 615 | int stat_F = gsl_sf_hyperg_2F1_conj_renorm_e(0.5+mu, tau, 1.0+mu, 0.5*(1.0-x), &F); |
| 616 | |
| 617 | gsl_sf_lngamma_complex_e(0.5+mu, tau, &ln_g1, &arg_g1); |
| 618 | gsl_sf_lngamma_complex_e(0.5-mu, tau, &ln_g2, &arg_g2); |
| 619 | |
| 620 | ln_pre = mu*M_LN2 - 0.5*mu*log(fabs(x*x-1.0)) + ln_g1 - ln_g2; |
| 621 | arg_pre = arg_g1 - arg_g2; |
| 622 | |
| 623 | *result = exp(ln_pre) * F; |
| 624 | return stat_F; |
| 625 | } |
| 626 | #endif /* 0 */ |
| 627 | |
| 628 | |
| 629 | /* V0, V1 from Kolbig, m = 0 |
| 630 | */ |
| 631 | static |
| 632 | int |
| 633 | conicalP_0_V(const double t, const double f, const double tau, const double sgn, |
| 634 | double * V0, double * V1) |
| 635 | { |
| 636 | double C[8]; |
| 637 | double T[8]; |
| 638 | double H[8]; |
| 639 | double V[12]; |
| 640 | int i; |
| 641 | T[0] = 1.0; |
| 642 | H[0] = 1.0; |
| 643 | V[0] = 1.0; |
| 644 | for(i=1; i<=7; i++) { |
| 645 | T[i] = T[i-1] * t; |
| 646 | H[i] = H[i-1] * (t*f); |
| 647 | } |
| 648 | for(i=1; i<=11; i++) { |
| 649 | V[i] = V[i-1] * tau; |
| 650 | } |
| 651 | |
| 652 | C[0] = 1.0; |
| 653 | C[1] = (H[1]-1.0)/(8.0*T[1]); |
| 654 | C[2] = (9.0*H[2] + 6.0*H[1] - 15.0 - sgn*8.0*T[2])/(128.0*T[2]); |
| 655 | C[3] = 5.0*(15.0*H[3] + 27.0*H[2] + 21.0*H[1] - 63.0 - sgn*T[2]*(16.0*H[1]+24.0))/(1024.0*T[3]); |
| 656 | C[4] = 7.0*(525.0*H[4] + 1500.0*H[3] + 2430.0*H[2] + 1980.0*H[1] - 6435.0 |
| 657 | + 192.0*T[4] - sgn*T[2]*(720.0*H[2]+1600.0*H[1]+2160.0) |
| 658 | ) / (32768.0*T[4]); |
| 659 | C[5] = 21.0*(2835.0*H[5] + 11025.0*H[4] + 24750.0*H[3] + 38610.0*H[2] |
| 660 | + 32175.0*H[1] - 109395.0 + T[4]*(1984.0*H[1]+4032.0) |
| 661 | - sgn*T[2]*(4800.0*H[3]+15120.0*H[2]+26400.0*H[1]+34320.0) |
| 662 | ) / (262144.0*T[5]); |
| 663 | C[6] = 11.0*(218295.0*H[6] + 1071630.0*H[5] + 3009825.0*H[4] + 6142500.0*H[3] |
| 664 | + 9398025.0*H[2] + 7936110.0*H[1] - 27776385.0 |
| 665 | + T[4]*(254016.0*H[2]+749952.0*H[1]+1100736.0) |
| 666 | - sgn*T[2]*(441000.0*H[4] + 1814400.0*H[3] + 4127760.0*H[2] |
| 667 | + 6552000.0*H[1] + 8353800.0 + 31232.0*T[4] |
| 668 | ) |
| 669 | ) / (4194304.0*T[6]); |
| 670 | |
| 671 | *V0 = C[0] + (-4.0*C[3]/T[1]+C[4])/V[4] |
| 672 | + (-192.0*C[5]/T[3]+144.0*C[6]/T[2])/V[8] |
| 673 | + sgn * (-C[2]/V[2] |
| 674 | + (-24.0*C[4]/T[2]+12.0*C[5]/T[1]-C[6])/V[6] |
| 675 | + (-1920.0*C[6]/T[4])/V[10] |
| 676 | ); |
| 677 | *V1 = C[1]/V[1] + (8.0*(C[3]/T[2]-C[4]/T[1])+C[5])/V[5] |
| 678 | + (384.0*C[5]/T[4] - 768.0*C[6]/T[3])/V[9] |
| 679 | + sgn * ((2.0*C[2]/T[1]-C[3])/V[3] |
| 680 | + (48.0*C[4]/T[3]-72.0*C[5]/T[2] + 18.0*C[6]/T[1])/V[7] |
| 681 | + (3840.0*C[6]/T[5])/V[11] |
| 682 | ); |
| 683 | |
| 684 | return GSL_SUCCESS; |
| 685 | } |
| 686 | |
| 687 | |
| 688 | /* V0, V1 from Kolbig, m = 1 |
| 689 | */ |
| 690 | static |
| 691 | int |
| 692 | conicalP_1_V(const double t, const double f, const double tau, const double sgn, |
| 693 | double * V0, double * V1) |
| 694 | { |
| 695 | double Cm1; |
| 696 | double C[8]; |
| 697 | double T[8]; |
| 698 | double H[8]; |
| 699 | double V[12]; |
| 700 | int i; |
| 701 | T[0] = 1.0; |
| 702 | H[0] = 1.0; |
| 703 | V[0] = 1.0; |
| 704 | for(i=1; i<=7; i++) { |
| 705 | T[i] = T[i-1] * t; |
| 706 | H[i] = H[i-1] * (t*f); |
| 707 | } |
| 708 | for(i=1; i<=11; i++) { |
| 709 | V[i] = V[i-1] * tau; |
| 710 | } |
| 711 | |
| 712 | Cm1 = -1.0; |
| 713 | C[0] = 3.0*(1.0-H[1])/(8.0*T[1]); |
| 714 | C[1] = (-15.0*H[2]+6.0*H[1]+9.0+sgn*8.0*T[2])/(128.0*T[2]); |
| 715 | C[2] = 3.0*(-35.0*H[3] - 15.0*H[2] + 15.0*H[1] + 35.0 + sgn*T[2]*(32.0*H[1]+8.0))/(1024.0*T[3]); |
| 716 | C[3] = (-4725.0*H[4] - 6300.0*H[3] - 3150.0*H[2] + 3780.0*H[1] + 10395.0 |
| 717 | -1216.0*T[4] + sgn*T[2]*(6000.0*H[2]+5760.0*H[1]+1680.0)) / (32768.0*T[4]); |
| 718 | C[4] = 7.0*(-10395.0*H[5] - 23625.0*H[4] - 28350.0*H[3] - 14850.0*H[2] |
| 719 | +19305.0*H[1] + 57915.0 - T[4]*(6336.0*H[1]+6080.0) |
| 720 | + sgn*T[2]*(16800.0*H[3] + 30000.0*H[2] + 25920.0*H[1] + 7920.0) |
| 721 | ) / (262144.0*T[5]); |
| 722 | C[5] = (-2837835.0*H[6] - 9168390.0*H[5] - 16372125.0*H[4] - 18918900*H[3] |
| 723 | -10135125.0*H[2] + 13783770.0*H[1] + 43648605.0 |
| 724 | -T[4]*(3044160.0*H[2] + 5588352.0*H[1] + 4213440.0) |
| 725 | +sgn*T[2]*(5556600.0*H[4] + 14817600.0*H[3] + 20790000.0*H[2] |
| 726 | + 17297280.0*H[1] + 5405400.0 + 323072.0*T[4] |
| 727 | ) |
| 728 | ) / (4194304.0*T[6]); |
| 729 | C[6] = 0.0; |
| 730 | |
| 731 | *V0 = C[0] + (-4.0*C[3]/T[1]+C[4])/V[4] |
| 732 | + (-192.0*C[5]/T[3]+144.0*C[6]/T[2])/V[8] |
| 733 | + sgn * (-C[2]/V[2] |
| 734 | + (-24.0*C[4]/T[2]+12.0*C[5]/T[1]-C[6])/V[6] |
| 735 | ); |
| 736 | *V1 = C[1]/V[1] + (8.0*(C[3]/T[2]-C[4]/T[1])+C[5])/V[5] |
| 737 | + (384.0*C[5]/T[4] - 768.0*C[6]/T[3])/V[9] |
| 738 | + sgn * (Cm1*V[1] + (2.0*C[2]/T[1]-C[3])/V[3] |
| 739 | + (48.0*C[4]/T[3]-72.0*C[5]/T[2] + 18.0*C[6]/T[1])/V[7] |
| 740 | ); |
| 741 | |
| 742 | return GSL_SUCCESS; |
| 743 | } |
| 744 | |
| 745 | |
| 746 | |
| 747 | /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/ |
| 748 | |
| 749 | /* P^0_{-1/2 + I lambda} |
| 750 | */ |
| 751 | int |
| 752 | gsl_sf_conicalP_0_e(const double lambda, const double x, gsl_sf_result * result) |
| 753 | { |
| 754 | /* CHECK_POINTER(result) */ |
| 755 | |
| 756 | if(x <= -1.0) { |
| 757 | DOMAIN_ERROR(result); |
| 758 | } |
| 759 | else if(x == 1.0) { |
| 760 | result->val = 1.0; |
| 761 | result->err = 0.0; |
| 762 | return GSL_SUCCESS; |
| 763 | } |
| 764 | else if(lambda == 0.0) { |
| 765 | gsl_sf_result K; |
| 766 | int stat_K; |
| 767 | if(x < 1.0) { |
| 768 | const double th = acos(x); |
| 769 | const double s = sin(0.5*th); |
| 770 | stat_K = gsl_sf_ellint_Kcomp_e(s, GSL_MODE_DEFAULT, &K); |
| 771 | result->val = 2.0/M_PI * K.val; |
| 772 | result->err = 2.0/M_PI * K.err; |
| 773 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 774 | return stat_K; |
| 775 | } |
| 776 | else { |
| 777 | const double xi = acosh(x); |
| 778 | const double c = cosh(0.5*xi); |
| 779 | const double t = tanh(0.5*xi); |
| 780 | stat_K = gsl_sf_ellint_Kcomp_e(t, GSL_MODE_DEFAULT, &K); |
| 781 | result->val = 2.0/M_PI / c * K.val; |
| 782 | result->err = 2.0/M_PI / c * K.err; |
| 783 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 784 | return stat_K; |
| 785 | } |
| 786 | } |
| 787 | else if( (x <= 0.0 && lambda < 1000.0) |
| 788 | || (x < 0.1 && lambda < 17.0) |
| 789 | || (x < 0.2 && lambda < 5.0 ) |
| 790 | ) { |
| 791 | return conicalP_xlt1_hyperg_A(0.0, lambda, x, result); |
| 792 | } |
| 793 | else if( (x <= 0.2 && lambda < 17.0) |
| 794 | || (x <= 1.5 && lambda < 20.0) |
| 795 | ) { |
| 796 | return gsl_sf_hyperg_2F1_conj_e(0.5, lambda, 1.0, (1.0-x)/2, result); |
| 797 | } |
| 798 | else if(1.5 < x && lambda < GSL_MAX(x,20.0)) { |
| 799 | gsl_sf_result P; |
| 800 | double lm; |
| 801 | int stat_P = gsl_sf_conicalP_large_x_e(0.0, lambda, x, |
| 802 | &P, &lm |
| 803 | ); |
| 804 | int stat_e = gsl_sf_exp_mult_err_e(lm, 2.0*GSL_DBL_EPSILON * fabs(lm), |
| 805 | P.val, P.err, |
| 806 | result); |
| 807 | return GSL_ERROR_SELECT_2(stat_e, stat_P); |
| 808 | } |
| 809 | else { |
| 810 | double V0, V1; |
| 811 | if(x < 1.0) { |
| 812 | double th = acos(x); |
| 813 | double sth = sqrt(1.0-x*x); /* sin(th) */ |
| 814 | gsl_sf_result I0, I1; |
| 815 | int stat_I0 = gsl_sf_bessel_I0_scaled_e(th * lambda, &I0); |
| 816 | int stat_I1 = gsl_sf_bessel_I1_scaled_e(th * lambda, &I1); |
| 817 | int stat_I = GSL_ERROR_SELECT_2(stat_I0, stat_I1); |
| 818 | int stat_V = conicalP_0_V(th, x/sth, lambda, -1.0, &V0, &V1); |
| 819 | double bessterm = V0 * I0.val + V1 * I1.val; |
| 820 | double besserr = fabs(V0) * I0.err + fabs(V1) * I1.err; |
| 821 | double arg1 = th*lambda; |
| 822 | double sqts = sqrt(th/sth); |
| 823 | int stat_e = gsl_sf_exp_mult_err_e(arg1, 4.0 * GSL_DBL_EPSILON * fabs(arg1), |
| 824 | sqts * bessterm, sqts * besserr, |
| 825 | result); |
| 826 | return GSL_ERROR_SELECT_3(stat_e, stat_V, stat_I); |
| 827 | } |
| 828 | else { |
| 829 | double sh = sqrt(x-1.0)*sqrt(x+1.0); /* sinh(xi) */ |
| 830 | double xi = log(x + sh); /* xi = acosh(x) */ |
| 831 | gsl_sf_result J0, J1; |
| 832 | int stat_J0 = gsl_sf_bessel_J0_e(xi * lambda, &J0); |
| 833 | int stat_J1 = gsl_sf_bessel_J1_e(xi * lambda, &J1); |
| 834 | int stat_J = GSL_ERROR_SELECT_2(stat_J0, stat_J1); |
| 835 | int stat_V = conicalP_0_V(xi, x/sh, lambda, 1.0, &V0, &V1); |
| 836 | double bessterm = V0 * J0.val + V1 * J1.val; |
| 837 | double besserr = fabs(V0) * J0.err + fabs(V1) * J1.err; |
| 838 | double pre_val = sqrt(xi/sh); |
| 839 | double pre_err = 2.0 * fabs(pre_val); |
| 840 | result->val = pre_val * bessterm; |
| 841 | result->err = pre_val * besserr; |
| 842 | result->err += pre_err * fabs(bessterm); |
| 843 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 844 | return GSL_ERROR_SELECT_2(stat_V, stat_J); |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | |
| 850 | /* P^1_{-1/2 + I lambda} |
| 851 | */ |
| 852 | int |
| 853 | gsl_sf_conicalP_1_e(const double lambda, const double x, gsl_sf_result * result) |
| 854 | { |
| 855 | /* CHECK_POINTER(result) */ |
| 856 | |
| 857 | if(x <= -1.0) { |
| 858 | DOMAIN_ERROR(result); |
| 859 | } |
| 860 | else if(lambda == 0.0) { |
| 861 | gsl_sf_result K, E; |
| 862 | int stat_K; |
| 863 | if(x == 1.0) { |
| 864 | result->val = 0.0; |
| 865 | result->err = 0.0; |
| 866 | return GSL_SUCCESS; |
| 867 | } |
| 868 | else if(x < 1.0) { |
| 869 | if(1.0-x < GSL_SQRT_DBL_EPSILON) { |
| 870 | double err_amp = GSL_MAX_DBL(1.0, 1.0/(GSL_DBL_EPSILON + fabs(1.0-x))); |
| 871 | result->val = 0.25/M_SQRT2 * sqrt(1.0-x) * (1.0 + 5.0/16.0 * (1.0-x)); |
| 872 | result->err = err_amp * 3.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 873 | return GSL_SUCCESS; |
| 874 | } |
| 875 | else { |
| 876 | const double th = acos(x); |
| 877 | const double s = sin(0.5*th); |
| 878 | const double c2 = 1.0 - s*s; |
| 879 | const double sth = sin(th); |
| 880 | const double pre = 2.0/(M_PI*sth); |
| 881 | stat_K = gsl_sf_ellint_Kcomp_e(s, GSL_MODE_DEFAULT, &K); |
| 882 | (void) gsl_sf_ellint_Ecomp_e(s, GSL_MODE_DEFAULT, &E); |
| 883 | result->val = pre * (E.val - c2 * K.val); |
| 884 | result->err = pre * (E.err + fabs(c2) * K.err); |
| 885 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 886 | return stat_K; |
| 887 | } |
| 888 | } |
| 889 | else { |
| 890 | if(x-1.0 < GSL_SQRT_DBL_EPSILON) { |
| 891 | double err_amp = GSL_MAX_DBL(1.0, 1.0/(GSL_DBL_EPSILON + fabs(1.0-x))); |
| 892 | result->val = -0.25/M_SQRT2 * sqrt(x-1.0) * (1.0 - 5.0/16.0 * (x-1.0)); |
| 893 | result->err = err_amp * 3.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 894 | return GSL_SUCCESS; |
| 895 | } |
| 896 | else { |
| 897 | const double xi = acosh(x); |
| 898 | const double c = cosh(0.5*xi); |
| 899 | const double t = tanh(0.5*xi); |
| 900 | const double sxi = sinh(xi); |
| 901 | const double pre = 2.0/(M_PI*sxi) * c; |
| 902 | stat_K = gsl_sf_ellint_Kcomp_e(t, GSL_MODE_DEFAULT, &K); |
| 903 | (void) gsl_sf_ellint_Ecomp_e(t, GSL_MODE_DEFAULT, &E); |
| 904 | result->val = pre * (E.val - K.val); |
| 905 | result->err = pre * (E.err + K.err); |
| 906 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 907 | return stat_K; |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | else if( (x <= 0.0 && lambda < 1000.0) |
| 912 | || (x < 0.1 && lambda < 17.0) |
| 913 | || (x < 0.2 && lambda < 5.0 ) |
| 914 | ) { |
| 915 | return conicalP_xlt1_hyperg_A(1.0, lambda, x, result); |
| 916 | } |
| 917 | else if( (x <= 0.2 && lambda < 17.0) |
| 918 | || (x < 1.5 && lambda < 20.0) |
| 919 | ) { |
| 920 | const double arg = fabs(x*x - 1.0); |
| 921 | const double sgn = GSL_SIGN(1.0 - x); |
| 922 | const double pre = 0.5*(lambda*lambda + 0.25) * sgn * sqrt(arg); |
| 923 | gsl_sf_result F; |
| 924 | int stat_F = gsl_sf_hyperg_2F1_conj_e(1.5, lambda, 2.0, (1.0-x)/2, &F); |
| 925 | result->val = pre * F.val; |
| 926 | result->err = fabs(pre) * F.err; |
| 927 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 928 | return stat_F; |
| 929 | } |
| 930 | else if(1.5 <= x && lambda < GSL_MAX(x,20.0)) { |
| 931 | gsl_sf_result P; |
| 932 | double lm; |
| 933 | int stat_P = gsl_sf_conicalP_large_x_e(1.0, lambda, x, |
| 934 | &P, &lm |
| 935 | ); |
| 936 | int stat_e = gsl_sf_exp_mult_err_e(lm, 2.0 * GSL_DBL_EPSILON * fabs(lm), |
| 937 | P.val, P.err, |
| 938 | result); |
| 939 | return GSL_ERROR_SELECT_2(stat_e, stat_P); |
| 940 | } |
| 941 | else { |
| 942 | double V0, V1; |
| 943 | if(x < 1.0) { |
| 944 | const double sqrt_1mx = sqrt(1.0 - x); |
| 945 | const double sqrt_1px = sqrt(1.0 + x); |
| 946 | const double th = acos(x); |
| 947 | const double sth = sqrt_1mx * sqrt_1px; /* sin(th) */ |
| 948 | gsl_sf_result I0, I1; |
| 949 | int stat_I0 = gsl_sf_bessel_I0_scaled_e(th * lambda, &I0); |
| 950 | int stat_I1 = gsl_sf_bessel_I1_scaled_e(th * lambda, &I1); |
| 951 | int stat_I = GSL_ERROR_SELECT_2(stat_I0, stat_I1); |
| 952 | int stat_V = conicalP_1_V(th, x/sth, lambda, -1.0, &V0, &V1); |
| 953 | double bessterm = V0 * I0.val + V1 * I1.val; |
| 954 | double besserr = fabs(V0) * I0.err + fabs(V1) * I1.err |
| 955 | + 2.0 * GSL_DBL_EPSILON * fabs(V0 * I0.val) |
| 956 | + 2.0 * GSL_DBL_EPSILON * fabs(V1 * I1.val); |
| 957 | double arg1 = th * lambda; |
| 958 | double sqts = sqrt(th/sth); |
| 959 | int stat_e = gsl_sf_exp_mult_err_e(arg1, 2.0 * GSL_DBL_EPSILON * fabs(arg1), |
| 960 | sqts * bessterm, sqts * besserr, |
| 961 | result); |
| 962 | result->err *= 1.0/sqrt_1mx; |
| 963 | return GSL_ERROR_SELECT_3(stat_e, stat_V, stat_I); |
| 964 | } |
| 965 | else { |
| 966 | const double sqrt_xm1 = sqrt(x - 1.0); |
| 967 | const double sqrt_xp1 = sqrt(x + 1.0); |
| 968 | const double sh = sqrt_xm1 * sqrt_xp1; /* sinh(xi) */ |
| 969 | const double xi = log(x + sh); /* xi = acosh(x) */ |
| 970 | const double xi_lam = xi * lambda; |
| 971 | gsl_sf_result J0, J1; |
| 972 | const int stat_J0 = gsl_sf_bessel_J0_e(xi_lam, &J0); |
| 973 | const int stat_J1 = gsl_sf_bessel_J1_e(xi_lam, &J1); |
| 974 | const int stat_J = GSL_ERROR_SELECT_2(stat_J0, stat_J1); |
| 975 | const int stat_V = conicalP_1_V(xi, x/sh, lambda, 1.0, &V0, &V1); |
| 976 | const double bessterm = V0 * J0.val + V1 * J1.val; |
| 977 | const double besserr = fabs(V0) * J0.err + fabs(V1) * J1.err |
| 978 | + 512.0 * 2.0 * GSL_DBL_EPSILON * fabs(V0 * J0.val) |
| 979 | + 512.0 * 2.0 * GSL_DBL_EPSILON * fabs(V1 * J1.val) |
| 980 | + GSL_DBL_EPSILON * fabs(xi_lam * V0 * J1.val) |
| 981 | + GSL_DBL_EPSILON * fabs(xi_lam * V1 * J0.val); |
| 982 | const double pre = sqrt(xi/sh); |
| 983 | result->val = pre * bessterm; |
| 984 | result->err = pre * besserr * sqrt_xp1 / sqrt_xm1; |
| 985 | result->err += 4.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 986 | return GSL_ERROR_SELECT_2(stat_V, stat_J); |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | |
| 992 | /* P^{1/2}_{-1/2 + I lambda} (x) |
| 993 | * [Abramowitz+Stegun 8.6.8, 8.6.12] |
| 994 | * checked OK [GJ] Fri May 8 12:24:36 MDT 1998 |
| 995 | */ |
| 996 | int gsl_sf_conicalP_half_e(const double lambda, const double x, |
| 997 | gsl_sf_result * result |
| 998 | ) |
| 999 | { |
| 1000 | /* CHECK_POINTER(result) */ |
| 1001 | |
| 1002 | if(x <= -1.0) { |
| 1003 | DOMAIN_ERROR(result); |
| 1004 | } |
| 1005 | else if(x < 1.0) { |
| 1006 | double err_amp = 1.0 + 1.0/(GSL_DBL_EPSILON + fabs(1.0-fabs(x))); |
| 1007 | double ac = acos(x); |
| 1008 | double den = sqrt(sqrt(1.0-x)*sqrt(1.0+x)); |
| 1009 | result->val = Root_2OverPi_ / den * cosh(ac * lambda); |
| 1010 | result->err = err_amp * 3.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1011 | result->err *= fabs(ac * lambda) + 1.0; |
| 1012 | return GSL_SUCCESS; |
| 1013 | } |
| 1014 | else if(x == 1.0) { |
| 1015 | result->val = 0.0; |
| 1016 | result->err = 0.0; |
| 1017 | return GSL_SUCCESS; |
| 1018 | } |
| 1019 | else { |
| 1020 | /* x > 1 */ |
| 1021 | double err_amp = 1.0 + 1.0/(GSL_DBL_EPSILON + fabs(1.0-fabs(x))); |
| 1022 | double sq_term = sqrt(x-1.0)*sqrt(x+1.0); |
| 1023 | double ln_term = log(x + sq_term); |
| 1024 | double den = sqrt(sq_term); |
| 1025 | double carg_val = lambda * ln_term; |
| 1026 | double carg_err = 2.0 * GSL_DBL_EPSILON * fabs(carg_val); |
| 1027 | gsl_sf_result cos_result; |
| 1028 | int stat_cos = gsl_sf_cos_err_e(carg_val, carg_err, &cos_result); |
| 1029 | result->val = Root_2OverPi_ / den * cos_result.val; |
| 1030 | result->err = err_amp * Root_2OverPi_ / den * cos_result.err; |
| 1031 | result->err += 4.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1032 | return stat_cos; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | |
| 1037 | /* P^{-1/2}_{-1/2 + I lambda} (x) |
| 1038 | * [Abramowitz+Stegun 8.6.9, 8.6.14] |
| 1039 | * checked OK [GJ] Fri May 8 12:24:43 MDT 1998 |
| 1040 | */ |
| 1041 | int gsl_sf_conicalP_mhalf_e(const double lambda, const double x, gsl_sf_result * result) |
| 1042 | { |
| 1043 | /* CHECK_POINTER(result) */ |
| 1044 | |
| 1045 | if(x <= -1.0) { |
| 1046 | DOMAIN_ERROR(result); |
| 1047 | } |
| 1048 | else if(x < 1.0) { |
| 1049 | double ac = acos(x); |
| 1050 | double den = sqrt(sqrt(1.0-x)*sqrt(1.0+x)); |
| 1051 | double arg = ac * lambda; |
| 1052 | double err_amp = 1.0 + 1.0/(GSL_DBL_EPSILON + fabs(1.0-fabs(x))); |
| 1053 | if(fabs(arg) < GSL_SQRT_DBL_EPSILON) { |
| 1054 | result->val = Root_2OverPi_ / den * ac; |
| 1055 | result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1056 | result->err *= err_amp; |
| 1057 | } |
| 1058 | else { |
| 1059 | result->val = Root_2OverPi_ / (den*lambda) * sinh(arg); |
| 1060 | result->err = GSL_DBL_EPSILON * (fabs(arg)+1.0) * fabs(result->val); |
| 1061 | result->err *= err_amp; |
| 1062 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1063 | } |
| 1064 | return GSL_SUCCESS; |
| 1065 | } |
| 1066 | else if(x == 1.0) { |
| 1067 | result->val = 0.0; |
| 1068 | result->err = 0.0; |
| 1069 | return GSL_SUCCESS; |
| 1070 | } |
| 1071 | else { |
| 1072 | /* x > 1 */ |
| 1073 | double sq_term = sqrt(x-1.0)*sqrt(x+1.0); |
| 1074 | double ln_term = log(x + sq_term); |
| 1075 | double den = sqrt(sq_term); |
| 1076 | double arg_val = lambda * ln_term; |
| 1077 | double arg_err = 2.0 * GSL_DBL_EPSILON * fabs(arg_val); |
| 1078 | if(arg_val < GSL_SQRT_DBL_EPSILON) { |
| 1079 | result->val = Root_2OverPi_ / den * ln_term; |
| 1080 | result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1081 | return GSL_SUCCESS; |
| 1082 | } |
| 1083 | else { |
| 1084 | gsl_sf_result sin_result; |
| 1085 | int stat_sin = gsl_sf_sin_err_e(arg_val, arg_err, &sin_result); |
| 1086 | result->val = Root_2OverPi_ / (den*lambda) * sin_result.val; |
| 1087 | result->err = Root_2OverPi_ / fabs(den*lambda) * sin_result.err; |
| 1088 | result->err += 3.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1089 | return stat_sin; |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | int gsl_sf_conicalP_sph_reg_e(const int l, const double lambda, |
| 1096 | const double x, |
| 1097 | gsl_sf_result * result |
| 1098 | ) |
| 1099 | { |
| 1100 | /* CHECK_POINTER(result) */ |
| 1101 | |
| 1102 | if(x <= -1.0 || l < -1) { |
| 1103 | DOMAIN_ERROR(result); |
| 1104 | } |
| 1105 | else if(l == -1) { |
| 1106 | return gsl_sf_conicalP_half_e(lambda, x, result); |
| 1107 | } |
| 1108 | else if(l == 0) { |
| 1109 | return gsl_sf_conicalP_mhalf_e(lambda, x, result); |
| 1110 | } |
| 1111 | else if(x == 1.0) { |
| 1112 | result->val = 0.0; |
| 1113 | result->err = 0.0; |
| 1114 | return GSL_SUCCESS; |
| 1115 | } |
| 1116 | else if(x < 0.0) { |
| 1117 | double c = 1.0/sqrt(1.0-x*x); |
| 1118 | gsl_sf_result r_Pellm1; |
| 1119 | gsl_sf_result r_Pell; |
| 1120 | int stat_0 = gsl_sf_conicalP_half_e(lambda, x, &r_Pellm1); /* P^( 1/2) */ |
| 1121 | int stat_1 = gsl_sf_conicalP_mhalf_e(lambda, x, &r_Pell); /* P^(-1/2) */ |
| 1122 | int stat_P = GSL_ERROR_SELECT_2(stat_0, stat_1); |
| 1123 | double Pellm1 = r_Pellm1.val; |
| 1124 | double Pell = r_Pell.val; |
| 1125 | double Pellp1; |
| 1126 | int ell; |
| 1127 | |
| 1128 | for(ell=0; ell<l; ell++) { |
| 1129 | double d = (ell+1.0)*(ell+1.0) + lambda*lambda; |
| 1130 | Pellp1 = (Pellm1 - (2.0*ell+1.0)*c*x * Pell) / d; |
| 1131 | Pellm1 = Pell; |
| 1132 | Pell = Pellp1; |
| 1133 | } |
| 1134 | |
| 1135 | result->val = Pell; |
| 1136 | result->err = (0.5*l + 1.0) * GSL_DBL_EPSILON * fabs(Pell); |
| 1137 | result->err += GSL_DBL_EPSILON * l * fabs(result->val); |
| 1138 | return stat_P; |
| 1139 | } |
| 1140 | else if(x < 1.0) { |
| 1141 | const double xi = x/(sqrt(1.0-x)*sqrt(1.0+x)); |
| 1142 | gsl_sf_result rat; |
| 1143 | gsl_sf_result Phf; |
| 1144 | int stat_CF1 = conicalP_negmu_xlt1_CF1(0.5, l, lambda, x, &rat); |
| 1145 | int stat_Phf = gsl_sf_conicalP_half_e(lambda, x, &Phf); |
| 1146 | double Pellp1 = rat.val * GSL_SQRT_DBL_MIN; |
| 1147 | double Pell = GSL_SQRT_DBL_MIN; |
| 1148 | double Pellm1; |
| 1149 | int ell; |
| 1150 | |
| 1151 | for(ell=l; ell>=0; ell--) { |
| 1152 | double d = (ell+1.0)*(ell+1.0) + lambda*lambda; |
| 1153 | Pellm1 = (2.0*ell+1.0)*xi * Pell + d * Pellp1; |
| 1154 | Pellp1 = Pell; |
| 1155 | Pell = Pellm1; |
| 1156 | } |
| 1157 | |
| 1158 | result->val = GSL_SQRT_DBL_MIN * Phf.val / Pell; |
| 1159 | result->err = GSL_SQRT_DBL_MIN * Phf.err / fabs(Pell); |
| 1160 | result->err += fabs(rat.err/rat.val) * (l + 1.0) * fabs(result->val); |
| 1161 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1162 | |
| 1163 | return GSL_ERROR_SELECT_2(stat_Phf, stat_CF1); |
| 1164 | } |
| 1165 | else if(x == 1.0) { |
| 1166 | result->val = 0.0; |
| 1167 | result->err = 0.0; |
| 1168 | return GSL_SUCCESS; |
| 1169 | } |
| 1170 | else { |
| 1171 | /* x > 1.0 */ |
| 1172 | |
| 1173 | const double xi = x/sqrt((x-1.0)*(x+1.0)); |
| 1174 | gsl_sf_result rat; |
| 1175 | int stat_CF1 = conicalP_negmu_xgt1_CF1(0.5, l, lambda, x, &rat); |
| 1176 | int stat_P; |
| 1177 | double Pellp1 = rat.val * GSL_SQRT_DBL_MIN; |
| 1178 | double Pell = GSL_SQRT_DBL_MIN; |
| 1179 | double Pellm1; |
| 1180 | int ell; |
| 1181 | |
| 1182 | for(ell=l; ell>=0; ell--) { |
| 1183 | double d = (ell+1.0)*(ell+1.0) + lambda*lambda; |
| 1184 | Pellm1 = (2.0*ell+1.0)*xi * Pell - d * Pellp1; |
| 1185 | Pellp1 = Pell; |
| 1186 | Pell = Pellm1; |
| 1187 | } |
| 1188 | |
| 1189 | if(fabs(Pell) > fabs(Pellp1)){ |
| 1190 | gsl_sf_result Phf; |
| 1191 | stat_P = gsl_sf_conicalP_half_e(lambda, x, &Phf); |
| 1192 | result->val = GSL_SQRT_DBL_MIN * Phf.val / Pell; |
| 1193 | result->err = 2.0 * GSL_SQRT_DBL_MIN * Phf.err / fabs(Pell); |
| 1194 | result->err += 2.0 * fabs(rat.err/rat.val) * (l + 1.0) * fabs(result->val); |
| 1195 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1196 | } |
| 1197 | else { |
| 1198 | gsl_sf_result Pmhf; |
| 1199 | stat_P = gsl_sf_conicalP_mhalf_e(lambda, x, &Pmhf); |
| 1200 | result->val = GSL_SQRT_DBL_MIN * Pmhf.val / Pellp1; |
| 1201 | result->err = 2.0 * GSL_SQRT_DBL_MIN * Pmhf.err / fabs(Pellp1); |
| 1202 | result->err += 2.0 * fabs(rat.err/rat.val) * (l + 1.0) * fabs(result->val); |
| 1203 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1204 | } |
| 1205 | |
| 1206 | return GSL_ERROR_SELECT_2(stat_P, stat_CF1); |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | int gsl_sf_conicalP_cyl_reg_e(const int m, const double lambda, |
| 1212 | const double x, |
| 1213 | gsl_sf_result * result |
| 1214 | ) |
| 1215 | { |
| 1216 | /* CHECK_POINTER(result) */ |
| 1217 | |
| 1218 | if(x <= -1.0 || m < -1) { |
| 1219 | DOMAIN_ERROR(result); |
| 1220 | } |
| 1221 | else if(m == -1) { |
| 1222 | return gsl_sf_conicalP_1_e(lambda, x, result); |
| 1223 | } |
| 1224 | else if(m == 0) { |
| 1225 | return gsl_sf_conicalP_0_e(lambda, x, result); |
| 1226 | } |
| 1227 | else if(x == 1.0) { |
| 1228 | result->val = 0.0; |
| 1229 | result->err = 0.0; |
| 1230 | return GSL_SUCCESS; |
| 1231 | } |
| 1232 | else if(x < 0.0) { |
| 1233 | double c = 1.0/sqrt(1.0-x*x); |
| 1234 | gsl_sf_result r_Pkm1; |
| 1235 | gsl_sf_result r_Pk; |
| 1236 | int stat_0 = gsl_sf_conicalP_1_e(lambda, x, &r_Pkm1); /* P^1 */ |
| 1237 | int stat_1 = gsl_sf_conicalP_0_e(lambda, x, &r_Pk); /* P^0 */ |
| 1238 | int stat_P = GSL_ERROR_SELECT_2(stat_0, stat_1); |
| 1239 | double Pkm1 = r_Pkm1.val; |
| 1240 | double Pk = r_Pk.val; |
| 1241 | double Pkp1; |
| 1242 | int k; |
| 1243 | |
| 1244 | for(k=0; k<m; k++) { |
| 1245 | double d = (k+0.5)*(k+0.5) + lambda*lambda; |
| 1246 | Pkp1 = (Pkm1 - 2.0*k*c*x * Pk) / d; |
| 1247 | Pkm1 = Pk; |
| 1248 | Pk = Pkp1; |
| 1249 | } |
| 1250 | |
| 1251 | result->val = Pk; |
| 1252 | result->err = (m + 2.0) * GSL_DBL_EPSILON * fabs(Pk); |
| 1253 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1254 | |
| 1255 | return stat_P; |
| 1256 | } |
| 1257 | else if(x < 1.0) { |
| 1258 | const double xi = x/(sqrt(1.0-x)*sqrt(1.0+x)); |
| 1259 | gsl_sf_result rat; |
| 1260 | gsl_sf_result P0; |
| 1261 | int stat_CF1 = conicalP_negmu_xlt1_CF1(0.0, m, lambda, x, &rat); |
| 1262 | int stat_P0 = gsl_sf_conicalP_0_e(lambda, x, &P0); |
| 1263 | double Pkp1 = rat.val * GSL_SQRT_DBL_MIN; |
| 1264 | double Pk = GSL_SQRT_DBL_MIN; |
| 1265 | double Pkm1; |
| 1266 | int k; |
| 1267 | |
| 1268 | for(k=m; k>0; k--) { |
| 1269 | double d = (k+0.5)*(k+0.5) + lambda*lambda; |
| 1270 | Pkm1 = 2.0*k*xi * Pk + d * Pkp1; |
| 1271 | Pkp1 = Pk; |
| 1272 | Pk = Pkm1; |
| 1273 | } |
| 1274 | |
| 1275 | result->val = GSL_SQRT_DBL_MIN * P0.val / Pk; |
| 1276 | result->err = 2.0 * GSL_SQRT_DBL_MIN * P0.err / fabs(Pk); |
| 1277 | result->err += 2.0 * fabs(rat.err/rat.val) * (m + 1.0) * fabs(result->val); |
| 1278 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1279 | |
| 1280 | return GSL_ERROR_SELECT_2(stat_P0, stat_CF1); |
| 1281 | } |
| 1282 | else if(x == 1.0) { |
| 1283 | result->val = 0.0; |
| 1284 | result->err = 0.0; |
| 1285 | return GSL_SUCCESS; |
| 1286 | } |
| 1287 | else { |
| 1288 | /* x > 1.0 */ |
| 1289 | |
| 1290 | const double xi = x/sqrt((x-1.0)*(x+1.0)); |
| 1291 | gsl_sf_result rat; |
| 1292 | int stat_CF1 = conicalP_negmu_xgt1_CF1(0.0, m, lambda, x, &rat); |
| 1293 | int stat_P; |
| 1294 | double Pkp1 = rat.val * GSL_SQRT_DBL_MIN; |
| 1295 | double Pk = GSL_SQRT_DBL_MIN; |
| 1296 | double Pkm1; |
| 1297 | int k; |
| 1298 | |
| 1299 | for(k=m; k>-1; k--) { |
| 1300 | double d = (k+0.5)*(k+0.5) + lambda*lambda; |
| 1301 | Pkm1 = 2.0*k*xi * Pk - d * Pkp1; |
| 1302 | Pkp1 = Pk; |
| 1303 | Pk = Pkm1; |
| 1304 | } |
| 1305 | |
| 1306 | if(fabs(Pk) > fabs(Pkp1)){ |
| 1307 | gsl_sf_result P1; |
| 1308 | stat_P = gsl_sf_conicalP_1_e(lambda, x, &P1); |
| 1309 | result->val = GSL_SQRT_DBL_MIN * P1.val / Pk; |
| 1310 | result->err = 2.0 * GSL_SQRT_DBL_MIN * P1.err / fabs(Pk); |
| 1311 | result->err += 2.0 * fabs(rat.err/rat.val) * (m+2.0) * fabs(result->val); |
| 1312 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1313 | } |
| 1314 | else { |
| 1315 | gsl_sf_result P0; |
| 1316 | stat_P = gsl_sf_conicalP_0_e(lambda, x, &P0); |
| 1317 | result->val = GSL_SQRT_DBL_MIN * P0.val / Pkp1; |
| 1318 | result->err = 2.0 * GSL_SQRT_DBL_MIN * P0.err / fabs(Pkp1); |
| 1319 | result->err += 2.0 * fabs(rat.err/rat.val) * (m+2.0) * fabs(result->val); |
| 1320 | result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val); |
| 1321 | } |
| 1322 | |
| 1323 | return GSL_ERROR_SELECT_2(stat_P, stat_CF1); |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/ |
| 1329 | |
| 1330 | #include "gsl_specfunc__eval.h" |
| 1331 | |
| 1332 | double gsl_sf_conicalP_0(const double lambda, const double x) |
| 1333 | { |
| 1334 | EVAL_RESULT(gsl_sf_conicalP_0_e(lambda, x, &result)); |
| 1335 | } |
| 1336 | |
| 1337 | double gsl_sf_conicalP_1(const double lambda, const double x) |
| 1338 | { |
| 1339 | EVAL_RESULT(gsl_sf_conicalP_1_e(lambda, x, &result)); |
| 1340 | } |
| 1341 | |
| 1342 | double gsl_sf_conicalP_half(const double lambda, const double x) |
| 1343 | { |
| 1344 | EVAL_RESULT(gsl_sf_conicalP_half_e(lambda, x, &result)); |
| 1345 | } |
| 1346 | |
| 1347 | double gsl_sf_conicalP_mhalf(const double lambda, const double x) |
| 1348 | { |
| 1349 | EVAL_RESULT(gsl_sf_conicalP_mhalf_e(lambda, x, &result)); |
| 1350 | } |
| 1351 | |
| 1352 | double gsl_sf_conicalP_sph_reg(const int l, const double lambda, const double x) |
| 1353 | { |
| 1354 | EVAL_RESULT(gsl_sf_conicalP_sph_reg_e(l, lambda, x, &result)); |
| 1355 | } |
| 1356 | |
| 1357 | double gsl_sf_conicalP_cyl_reg(const int m, const double lambda, const double x) |
| 1358 | { |
| 1359 | EVAL_RESULT(gsl_sf_conicalP_cyl_reg_e(m, lambda, x, &result)); |
| 1360 | } |