/* WKB evaluation of F, G. Assumes 0 < x < turning point. * Overflows are trapped, GSL_EOVRFLW is signalled, * and an exponent is returned such that: * * result_F = fjwkb * exp(-exponent) * result_G = gjwkb * exp( exponent) * * See [Biedenharn et al. Phys. Rev. 97, 542-554 (1955), Section IV] * * Unfortunately, this is not very accurate in general. The * test cases typically have 3-4 digits of precision. One could * argue that this is ok for general use because, for instance, * F is exponentially small in this region and so the absolute * accuracy is still roughly acceptable. But it would be better * to have a systematic method for improving the precision. See * the Abad+Sesma method discussion below. */ static int coulomb_jwkb(const double lam, const double eta, const double x, gsl_sf_result * fjwkb, gsl_sf_result * gjwkb, double * exponent) { const double llp1 = lam*(lam+1.0) + 6.0/35.0; const double llp1_eff = GSL_MAX(llp1, 0.0); const double rho_ghalf = sqrt(x*(2.0*eta - x) + llp1_eff); const double sinh_arg = sqrt(llp1_eff/(eta*eta+llp1_eff)) * rho_ghalf / x; const double sinh_inv = log(sinh_arg + sqrt(1.0 + sinh_arg*sinh_arg)); const double phi = fabs(rho_ghalf - eta*atan2(rho_ghalf,x-eta) - sqrt(llp1_eff) * sinh_inv); const double zeta_half = pow(3.0*phi/2.0, 1.0/3.0); const double prefactor = sqrt(M_PI*phi*x/(6.0 * rho_ghalf)); double F = prefactor * 3.0/zeta_half; double G = prefactor * 3.0/zeta_half; /* Note the sqrt(3) from Bi normalization */ double F_exp; double G_exp; const double airy_scale_exp = phi; gsl_sf_result ai; gsl_sf_result bi; gsl_sf_airy_Ai_scaled_e(zeta_half*zeta_half, GSL_MODE_DEFAULT, &ai); gsl_sf_airy_Bi_scaled_e(zeta_half*zeta_half, GSL_MODE_DEFAULT, &bi); F *= ai.val; G *= bi.val; F_exp = log(F) - airy_scale_exp; G_exp = log(G) + airy_scale_exp; if(G_exp >= GSL_LOG_DBL_MAX) { fjwkb->val = F; gjwkb->val = G; fjwkb->err = 1.0e-3 * fabs(F); /* FIXME: real error here ... could be smaller */ gjwkb->err = 1.0e-3 * fabs(G); *exponent = airy_scale_exp; GSL_ERROR ("error", GSL_EOVRFLW); } else { fjwkb->val = exp(F_exp); gjwkb->val = exp(G_exp); fjwkb->err = 1.0e-3 * fabs(fjwkb->val); gjwkb->err = 1.0e-3 * fabs(gjwkb->val); *exponent = 0.0; return GSL_SUCCESS; } }
static VALUE Airy_Ai_scaled_e(VALUE self, VALUE x, VALUE mode) { int ret; gsl_sf_result r; ret = gsl_sf_airy_Ai_scaled_e(NUM2DBL(x), NUM2UINT(mode), &r); return RESULT(&r); }