1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
|
/* specfunc/ellint.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* Author: G. Jungman */
#include <config.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_precision.h>
#include <gsl/gsl_sf_ellint.h>
#include "error.h"
/*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
inline
static double locMAX3(double x, double y, double z)
{
double xy = GSL_MAX(x, y);
return GSL_MAX(xy, z);
}
inline
static double locMAX4(double x, double y, double z, double w)
{
double xy = GSL_MAX(x, y);
double xyz = GSL_MAX(xy, z);
return GSL_MAX(xyz, w);
}
/*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
/* based on Carlson's algorithms:
[B. C. Carlson Numer. Math. 33, 1 (1979)]
see also:
[B.C. Carlson, Special Functions of Applied Mathematics (1977)]
*/
/* According to Carlson's algorithm, the errtol parameter
typically effects the relative error in the following way:
relative error < 16 errtol^6 / (1 - 2 errtol)
errtol precision
------ ----------
0.001 1.0e-17
0.003 2.0e-14
0.01 2.0e-11
0.03 2.0e-8
0.1 2.0e-5
*/
int
gsl_sf_ellint_RC_e(double x, double y, gsl_mode_t mode, gsl_sf_result * result)
{
const double lolim = 5.0 * GSL_DBL_MIN;
const double uplim = 0.2 * GSL_DBL_MAX;
const gsl_prec_t goal = GSL_MODE_PREC(mode);
const double errtol = ( goal == GSL_PREC_DOUBLE ? 0.001 : 0.03 );
const double prec = gsl_prec_eps[goal];
const int nmax = 10000;
if(x < 0.0 || y < 0.0 || x + y < lolim) {
DOMAIN_ERROR(result);
}
else if(GSL_MAX(x, y) < uplim) {
const double c1 = 1.0 / 7.0;
const double c2 = 9.0 / 22.0;
double xn = x;
double yn = y;
double mu, sn, lamda, s;
int n = 0;
while(1) {
mu = (xn + yn + yn) / 3.0;
sn = (yn + mu) / mu - 2.0;
if (fabs(sn) < errtol) break;
lamda = 2.0 * sqrt(xn) * sqrt(yn) + yn;
xn = (xn + lamda) * 0.25;
yn = (yn + lamda) * 0.25;
n++;
if(n==nmax) {
MAXITER_ERROR (result);
}
}
s = sn * sn * (0.3 + sn * (c1 + sn * (0.375 + sn * c2)));
result->val = (1.0 + s) / sqrt(mu);
result->err = prec * fabs(result->val);
return GSL_SUCCESS;
}
else {
DOMAIN_ERROR(result);
}
}
int
gsl_sf_ellint_RD_e(double x, double y, double z, gsl_mode_t mode, gsl_sf_result * result)
{
const gsl_prec_t goal = GSL_MODE_PREC(mode);
const double errtol = ( goal == GSL_PREC_DOUBLE ? 0.001 : 0.03 );
const double prec = gsl_prec_eps[goal];
const double lolim = 2.0/pow(GSL_DBL_MAX, 2.0/3.0);
const double uplim = pow(0.1*errtol/GSL_DBL_MIN, 2.0/3.0);
const int nmax = 10000;
if(GSL_MIN(x,y) < 0.0 || GSL_MIN(x+y,z) < lolim) {
DOMAIN_ERROR(result);
}
else if(locMAX3(x,y,z) < uplim) {
const double c1 = 3.0 / 14.0;
const double c2 = 1.0 / 6.0;
const double c3 = 9.0 / 22.0;
const double c4 = 3.0 / 26.0;
double xn = x;
double yn = y;
double zn = z;
double sigma = 0.0;
double power4 = 1.0;
double ea, eb, ec, ed, ef, s1, s2;
double mu, xndev, yndev, zndev;
int n = 0;
while(1) {
double xnroot, ynroot, znroot, lamda;
double epslon;
mu = (xn + yn + 3.0 * zn) * 0.2;
xndev = (mu - xn) / mu;
yndev = (mu - yn) / mu;
zndev = (mu - zn) / mu;
epslon = locMAX3(fabs(xndev), fabs(yndev), fabs(zndev));
if (epslon < errtol) break;
xnroot = sqrt(xn);
ynroot = sqrt(yn);
znroot = sqrt(zn);
lamda = xnroot * (ynroot + znroot) + ynroot * znroot;
sigma += power4 / (znroot * (zn + lamda));
power4 *= 0.25;
xn = (xn + lamda) * 0.25;
yn = (yn + lamda) * 0.25;
zn = (zn + lamda) * 0.25;
n++;
if(n==nmax) {
MAXITER_ERROR (result);
}
}
ea = xndev * yndev;
eb = zndev * zndev;
ec = ea - eb;
ed = ea - 6.0 * eb;
ef = ed + ec + ec;
s1 = ed * (- c1 + 0.25 * c3 * ed - 1.5 * c4 * zndev * ef);
s2 = zndev * (c2 * ef + zndev * (- c3 * ec + zndev * c4 * ea));
result->val = 3.0 * sigma + power4 * (1.0 + s1 + s2) / (mu * sqrt(mu));
result->err = prec * fabs(result->val);
return GSL_SUCCESS;
}
else {
DOMAIN_ERROR(result);
}
}
int
gsl_sf_ellint_RF_e(double x, double y, double z, gsl_mode_t mode, gsl_sf_result * result)
{
const double lolim = 5.0 * GSL_DBL_MIN;
const double uplim = 0.2 * GSL_DBL_MAX;
const gsl_prec_t goal = GSL_MODE_PREC(mode);
const double errtol = ( goal == GSL_PREC_DOUBLE ? 0.001 : 0.03 );
const double prec = gsl_prec_eps[goal];
const int nmax = 10000;
if(x < 0.0 || y < 0.0 || z < 0.0) {
DOMAIN_ERROR(result);
}
else if(x+y < lolim || x+z < lolim || y+z < lolim) {
DOMAIN_ERROR(result);
}
else if(locMAX3(x,y,z) < uplim) {
const double c1 = 1.0 / 24.0;
const double c2 = 3.0 / 44.0;
const double c3 = 1.0 / 14.0;
double xn = x;
double yn = y;
double zn = z;
double mu, xndev, yndev, zndev, e2, e3, s;
int n = 0;
while(1) {
double epslon, lamda;
double xnroot, ynroot, znroot;
mu = (xn + yn + zn) / 3.0;
xndev = 2.0 - (mu + xn) / mu;
yndev = 2.0 - (mu + yn) / mu;
zndev = 2.0 - (mu + zn) / mu;
epslon = locMAX3(fabs(xndev), fabs(yndev), fabs(zndev));
if (epslon < errtol) break;
xnroot = sqrt(xn);
ynroot = sqrt(yn);
znroot = sqrt(zn);
lamda = xnroot * (ynroot + znroot) + ynroot * znroot;
xn = (xn + lamda) * 0.25;
yn = (yn + lamda) * 0.25;
zn = (zn + lamda) * 0.25;
n++;
if(n==nmax) {
MAXITER_ERROR (result);
}
}
e2 = xndev * yndev - zndev * zndev;
e3 = xndev * yndev * zndev;
s = 1.0 + (c1 * e2 - 0.1 - c2 * e3) * e2 + c3 * e3;
result->val = s / sqrt(mu);
result->err = prec * fabs(result->val);
return GSL_SUCCESS;
}
else {
DOMAIN_ERROR(result);
}
}
int
gsl_sf_ellint_RJ_e(double x, double y, double z, double p, gsl_mode_t mode, gsl_sf_result * result)
{
const gsl_prec_t goal = GSL_MODE_PREC(mode);
const double errtol = ( goal == GSL_PREC_DOUBLE ? 0.001 : 0.03 );
const double prec = gsl_prec_eps[goal];
const double lolim = pow(5.0 * GSL_DBL_MIN, 1.0/3.0);
const double uplim = 0.3 * pow(0.2 * GSL_DBL_MAX, 1.0/3.0);
const int nmax = 10000;
if(x < 0.0 || y < 0.0 || z < 0.0) {
DOMAIN_ERROR(result);
}
else if(x + y < lolim || x + z < lolim || y + z < lolim || p < lolim) {
DOMAIN_ERROR(result);
}
else if(locMAX4(x,y,z,p) < uplim) {
const double c1 = 3.0 / 14.0;
const double c2 = 1.0 / 3.0;
const double c3 = 3.0 / 22.0;
const double c4 = 3.0 / 26.0;
double xn = x;
double yn = y;
double zn = z;
double pn = p;
double sigma = 0.0;
double power4 = 1.0;
double mu, xndev, yndev, zndev, pndev;
double ea, eb, ec, e2, e3, s1, s2, s3;
int n = 0;
while(1) {
double xnroot, ynroot, znroot;
double lamda, alfa, beta;
double epslon;
gsl_sf_result rcresult;
int rcstatus;
mu = (xn + yn + zn + pn + pn) * 0.2;
xndev = (mu - xn) / mu;
yndev = (mu - yn) / mu;
zndev = (mu - zn) / mu;
pndev = (mu - pn) / mu;
epslon = locMAX4(fabs(xndev), fabs(yndev), fabs(zndev), fabs(pndev));
if(epslon < errtol) break;
xnroot = sqrt(xn);
ynroot = sqrt(yn);
znroot = sqrt(zn);
lamda = xnroot * (ynroot + znroot) + ynroot * znroot;
alfa = pn * (xnroot + ynroot + znroot) + xnroot * ynroot * znroot;
alfa = alfa * alfa;
beta = pn * (pn + lamda) * (pn + lamda);
rcstatus = gsl_sf_ellint_RC_e(alfa, beta, mode, &rcresult);
if(rcstatus != GSL_SUCCESS) {
result->val = 0.0;
result->err = 0.0;
return rcstatus;
}
sigma += power4 * rcresult.val;
power4 *= 0.25;
xn = (xn + lamda) * 0.25;
yn = (yn + lamda) * 0.25;
zn = (zn + lamda) * 0.25;
pn = (pn + lamda) * 0.25;
n++;
if(n==nmax) {
MAXITER_ERROR (result);
}
}
ea = xndev * (yndev + zndev) + yndev * zndev;
eb = xndev * yndev * zndev;
ec = pndev * pndev;
e2 = ea - 3.0 * ec;
e3 = eb + 2.0 * pndev * (ea - ec);
s1 = 1.0 + e2 * (- c1 + 0.75 * c3 * e2 - 1.5 * c4 * e3);
s2 = eb * (0.5 * c2 + pndev * (- c3 - c3 + pndev * c4));
s3 = pndev * ea * (c2 - pndev * c3) - c2 * pndev * ec;
result->val = 3.0 * sigma + power4 * (s1 + s2 + s3) / (mu * sqrt(mu));
result->err = prec * fabs(result->val);
return GSL_SUCCESS;
}
else {
DOMAIN_ERROR(result);
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.1)] */
int
gsl_sf_ellint_F_e(double phi, double k, gsl_mode_t mode, gsl_sf_result * result)
{
/* Angular reduction to -pi/2 < phi < pi/2 (we should really use an
exact reduction but this will have to do for now) BJG */
double nc = floor(phi/M_PI + 0.5);
double phi_red = phi - nc * M_PI;
phi = phi_red;
{
double sin_phi = sin(phi);
double sin2_phi = sin_phi*sin_phi;
double x = 1.0 - sin2_phi;
double y = 1.0 - k*k*sin2_phi;
gsl_sf_result rf;
int status = gsl_sf_ellint_RF_e(x, y, 1.0, mode, &rf);
result->val = sin_phi * rf.val;
result->err = GSL_DBL_EPSILON * fabs(result->val) + fabs(sin_phi*rf.err);
if (nc == 0) {
return status;
} else {
gsl_sf_result rk; /* add extra terms from periodicity */
const int rkstatus = gsl_sf_ellint_Kcomp_e(k, mode, &rk);
result->val += 2*nc*rk.val;
result->err += 2*fabs(nc)*rk.err;
return GSL_ERROR_SELECT_2(status, rkstatus);
}
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.2)] */
int
gsl_sf_ellint_E_e(double phi, double k, gsl_mode_t mode, gsl_sf_result * result)
{
/* Angular reduction to -pi/2 < phi < pi/2 (we should really use an
exact reduction but this will have to do for now) BJG */
double nc = floor(phi/M_PI + 0.5);
double phi_red = phi - nc * M_PI;
phi = phi_red;
{
const double sin_phi = sin(phi);
const double sin2_phi = sin_phi * sin_phi;
const double x = 1.0 - sin2_phi;
const double y = 1.0 - k*k*sin2_phi;
if(x < GSL_DBL_EPSILON) {
gsl_sf_result re;
const int status = gsl_sf_ellint_Ecomp_e(k, mode, &re);
/* could use A&S 17.4.14 to improve the value below */
result->val = 2*nc*re.val + GSL_SIGN(sin_phi) * re.val;
result->err = 2*fabs(nc)*re.err + re.err;
return status;
}
else {
gsl_sf_result rf, rd;
const double sin3_phi = sin2_phi * sin_phi;
const int rfstatus = gsl_sf_ellint_RF_e(x, y, 1.0, mode, &rf);
const int rdstatus = gsl_sf_ellint_RD_e(x, y, 1.0, mode, &rd);
result->val = sin_phi * rf.val - k*k/3.0 * sin3_phi * rd.val;
result->err = GSL_DBL_EPSILON * fabs(sin_phi * rf.val);
result->err += fabs(sin_phi*rf.err);
result->err += k*k/3.0 * GSL_DBL_EPSILON * fabs(sin3_phi * rd.val);
result->err += k*k/3.0 * fabs(sin3_phi*rd.err);
if (nc == 0) {
return GSL_ERROR_SELECT_2(rfstatus, rdstatus);
} else {
gsl_sf_result re; /* add extra terms from periodicity */
const int restatus = gsl_sf_ellint_Ecomp_e(k, mode, &re);
result->val += 2*nc*re.val;
result->err += 2*fabs(nc)*re.err;
return GSL_ERROR_SELECT_3(rfstatus, rdstatus, restatus);
}
}
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.3)] */
int
gsl_sf_ellint_P_e(double phi, double k, double n, gsl_mode_t mode, gsl_sf_result * result)
{
/* Angular reduction to -pi/2 < phi < pi/2 (we should really use an
exact reduction but this will have to do for now) BJG */
double nc = floor(phi/M_PI + 0.5);
double phi_red = phi - nc * M_PI;
phi = phi_red;
/* FIXME: need to handle the case of small x, as for E,F */
{
const double sin_phi = sin(phi);
const double sin2_phi = sin_phi * sin_phi;
const double sin3_phi = sin2_phi * sin_phi;
const double x = 1.0 - sin2_phi;
const double y = 1.0 - k*k*sin2_phi;
gsl_sf_result rf;
gsl_sf_result rj;
const int rfstatus = gsl_sf_ellint_RF_e(x, y, 1.0, mode, &rf);
const int rjstatus = gsl_sf_ellint_RJ_e(x, y, 1.0, 1.0 + n*sin2_phi, mode, &rj);
result->val = sin_phi * rf.val - n/3.0*sin3_phi * rj.val;
result->err = GSL_DBL_EPSILON * fabs(sin_phi * rf.val);
result->err += fabs(sin_phi * rf.err);
result->err += n/3.0 * GSL_DBL_EPSILON * fabs(sin3_phi*rj.val);
result->err += n/3.0 * fabs(sin3_phi*rj.err);
if (nc == 0) {
return GSL_ERROR_SELECT_2(rfstatus, rjstatus);
} else {
gsl_sf_result rp; /* add extra terms from periodicity */
const int rpstatus = gsl_sf_ellint_Pcomp_e(k, n, mode, &rp);
result->val += 2*nc*rp.val;
result->err += 2*fabs(nc)*rp.err;
return GSL_ERROR_SELECT_3(rfstatus, rjstatus, rpstatus);
}
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.4)] */
int
gsl_sf_ellint_D_e(double phi, double k, gsl_mode_t mode, gsl_sf_result * result)
{
/* Angular reduction to -pi/2 < phi < pi/2 (we should really use an
exact reduction but this will have to do for now) BJG */
double nc = floor(phi/M_PI + 0.5);
double phi_red = phi - nc * M_PI;
phi = phi_red;
/* FIXME: need to handle the case of small x, as for E,F */
{
const double sin_phi = sin(phi);
const double sin2_phi = sin_phi * sin_phi;
const double sin3_phi = sin2_phi * sin_phi;
const double x = 1.0 - sin2_phi;
const double y = 1.0 - k*k*sin2_phi;
gsl_sf_result rd;
const int status = gsl_sf_ellint_RD_e(x, y, 1.0, mode, &rd);
result->val = sin3_phi/3.0 * rd.val;
result->err = GSL_DBL_EPSILON * fabs(result->val) + fabs(sin3_phi/3.0 * rd.err);
if (nc == 0) {
return status;
} else {
gsl_sf_result rd; /* add extra terms from periodicity */
const int rdstatus = gsl_sf_ellint_Dcomp_e(k, mode, &rd);
result->val += 2*nc*rd.val;
result->err += 2*fabs(nc)*rd.err;
return GSL_ERROR_SELECT_2(status, rdstatus);
}
}
}
int
gsl_sf_ellint_Dcomp_e(double k, gsl_mode_t mode, gsl_sf_result * result)
{
if(k*k >= 1.0) {
DOMAIN_ERROR(result);
} else {
const double y = 1.0 - k*k; /* FIXME: still need to handle k~=~1 */
gsl_sf_result rd;
const int status = gsl_sf_ellint_RD_e(0.0, y, 1.0, mode, &rd);
result->val = (1.0/3.0) * rd.val;
result->err = GSL_DBL_EPSILON * fabs(result->val) + fabs(1.0/3.0 * rd.err);
return status;
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.5)] */
int
gsl_sf_ellint_Kcomp_e(double k, gsl_mode_t mode, gsl_sf_result * result)
{
if(k*k >= 1.0) {
DOMAIN_ERROR(result);
}
else if(k*k >= 1.0 - GSL_SQRT_DBL_EPSILON) {
/* [Abramowitz+Stegun, 17.3.34] */
const double y = 1.0 - k*k;
const double a[] = { 1.38629436112, 0.09666344259, 0.03590092383 };
const double b[] = { 0.5, 0.12498593597, 0.06880248576 };
const double ta = a[0] + y*(a[1] + y*a[2]);
const double tb = -log(y) * (b[0] + y*(b[1] + y*b[2]));
result->val = ta + tb;
result->err = 2.0 * GSL_DBL_EPSILON * (fabs(result->val) + fabs(k/y));
return GSL_SUCCESS;
}
else {
/* This was previously computed as,
return gsl_sf_ellint_RF_e(0.0, 1.0 - k*k, 1.0, mode, result);
but this underestimated the total error for small k, since the
argument y=1-k^2 is not exact (there is an absolute error of
GSL_DBL_EPSILON near y=0 due to cancellation in the subtraction).
Taking the singular behavior of -log(y) above gives an error
of 0.5*epsilon/y near y=0. (BJG) */
double y = 1.0 - k*k;
int status = gsl_sf_ellint_RF_e(0.0, y, 1.0, mode, result);
result->err += 0.5 * GSL_DBL_EPSILON / y;
return status ;
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.6)] */
int
gsl_sf_ellint_Ecomp_e(double k, gsl_mode_t mode, gsl_sf_result * result)
{
if(k*k >= 1.0) {
DOMAIN_ERROR(result);
}
else if(k*k >= 1.0 - GSL_SQRT_DBL_EPSILON) {
/* [Abramowitz+Stegun, 17.3.36] */
const double y = 1.0 - k*k;
const double a[] = { 0.44325141463, 0.06260601220, 0.04757383546 };
const double b[] = { 0.24998368310, 0.09200180037, 0.04069697526 };
const double ta = 1.0 + y*(a[0] + y*(a[1] + a[2]*y));
const double tb = -y*log(y) * (b[0] + y*(b[1] + b[2]*y));
result->val = ta + tb;
result->err = 2.0 * GSL_DBL_EPSILON * result->val;
return GSL_SUCCESS;
}
else {
gsl_sf_result rf;
gsl_sf_result rd;
const double y = 1.0 - k*k;
const int rfstatus = gsl_sf_ellint_RF_e(0.0, y, 1.0, mode, &rf);
const int rdstatus = gsl_sf_ellint_RD_e(0.0, y, 1.0, mode, &rd);
result->val = rf.val - k*k/3.0 * rd.val;
result->err = rf.err + k*k/3.0 * rd.err;
return GSL_ERROR_SELECT_2(rfstatus, rdstatus);
}
}
/* [Carlson, Numer. Math. 33 (1979) 1, (4.3) phi=pi/2] */
int
gsl_sf_ellint_Pcomp_e(double k, double n, gsl_mode_t mode, gsl_sf_result * result)
{
if(k*k >= 1.0) {
DOMAIN_ERROR(result);
}
/* FIXME: need to handle k ~=~ 1 cancellations */
else {
gsl_sf_result rf;
gsl_sf_result rj;
const double y = 1.0 - k*k;
const int rfstatus = gsl_sf_ellint_RF_e(0.0, y, 1.0, mode, &rf);
const int rjstatus = gsl_sf_ellint_RJ_e(0.0, y, 1.0, 1.0 + n, mode, &rj);
result->val = rf.val - (n/3.0) * rj.val;
result->err = rf.err + fabs(n/3.0) * rj.err;
return GSL_ERROR_SELECT_2(rfstatus, rjstatus);
}
}
/*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
#include "eval.h"
double gsl_sf_ellint_Kcomp(double k, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_Kcomp_e(k, mode, &result));
}
double gsl_sf_ellint_Ecomp(double k, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_Ecomp_e(k, mode, &result));
}
double gsl_sf_ellint_Pcomp(double k, double n, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_Pcomp_e(k, n, mode, &result));
}
double gsl_sf_ellint_Dcomp(double k, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_Dcomp_e(k, mode, &result));
}
double gsl_sf_ellint_F(double phi, double k, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_F_e(phi, k, mode, &result));
}
double gsl_sf_ellint_E(double phi, double k, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_E_e(phi, k, mode, &result));
}
double gsl_sf_ellint_P(double phi, double k, double n, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_P_e(phi, k, n, mode, &result));
}
double gsl_sf_ellint_D(double phi, double k, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_D_e(phi, k, mode, &result));
}
double gsl_sf_ellint_RC(double x, double y, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_RC_e(x, y, mode, &result));
}
double gsl_sf_ellint_RD(double x, double y, double z, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_RD_e(x, y, z, mode, &result));
}
double gsl_sf_ellint_RF(double x, double y, double z, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_RF_e(x, y, z, mode, &result));
}
double gsl_sf_ellint_RJ(double x, double y, double z, double p, gsl_mode_t mode)
{
EVAL_RESULT(gsl_sf_ellint_RJ_e(x, y, z, p, mode, &result));
}
|