Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Sep 2018 03:56:28 +0000
From:      "Montgomery-Smith, Stephen" <stephen@missouri.edu>
To:        "freebsd-numerics@freebsd.org" <freebsd-numerics@freebsd.org>, "sgk@troutmask.apl.washington.edu" <sgk@troutmask.apl.washington.edu>
Subject:   Re: j0 (and y0) in the range 2 <= x < (p/2)*log(2)
Message-ID:  <ae55265d8d544cdc8a3ebc4314e1d01c@missouri.edu>
In-Reply-To: <20180903235724.GA95333@troutmask.apl.washington.edu>
References:  <20180903235724.GA95333@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
A quick google search turned up this

https://www.cl.cam.ac.uk/~jrh13/papers/bessel.pdf

which has the functions p0 and q0.  Maybe this was the basis of this code.
________________________________
From: owner-freebsd-numerics@freebsd.org <owner-freebsd-numerics@freebsd.or=
g> on behalf of Steve Kargl <sgk@troutmask.apl.washington.edu>
Sent: Monday, September 3, 2018 6:57:24 PM
To: freebsd-numerics@freebsd.org
Subject: j0 (and y0) in the range 2 <=3D x < (p/2)*log(2)

Anyone know where the approximations for j0 (and y0) come from?

msun/src/e_j0.c states

 *         for x in (2,inf)
 *              j0(x) =3D sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
 *         where x0 =3D x-pi/4. It is better to compute sin(x0),cos(x0)
 *         as follow:
 *              cos(x0) =3D cos(x)cos(pi/4)+sin(x)sin(pi/4)
 *                      =3D 1/sqrt(2) * (cos(x) + sin(x))
 *              sin(x0) =3D sin(x)cos(pi/4)-cos(x)sin(pi/4)
 *                      =3D 1/sqrt(2) * (sin(x) - cos(x))
 *         (To avoid cancellation, use
 *              sin(x) +- cos(x) =3D -cos(2x)/(sin(x) -+ cos(x))
 *          to compute the worse one.)

p0(x) and q0(x) are divergent asymptotic series.  If I extract
pzero() and qzero() from e_j0.c and compare the results against
summing truncated versions of p0(x) and q0(x), there are no obvious
connections.

Reading the documentation for the algorithms used in MPFR suggests
that x >=3D p/2*log(2), where p is precision of x, is required for use
of the large argument approximation for j0(x).  In double precision,
p =3D 53, so we have x >=3D 18.368...

Consider x=3D18.4 and sum up to N =3D 31 in the asymptotic series:

% ./pq 30 18.4
 p =3D  9.997932830701132e-01,  q =3D -6.781826311540553e-03  <-- series
pp =3D  9.997932830701132e-01, qq =3D -6.781826311540509e-03  <-- pzero,qze=
ro
ulp(p, pp) =3D 0.000000e+00
ulp(q, qq) =3D 2.550000e+01

This is almost reasonable if 25.5 ULP is acceptable in q0(x).  Note
the series are computed in long double with 64 bits of precision.

Now, comparing x =3D 2 and summing N =3D 4 (best results).

% ./pq 4 2
 p =3D  9.894313812255859e-01,  q =3D -5.334472656250000e-02
pp =3D  9.862158212188928e-01, qq =3D -5.647769967932505e-02
ulp(p, pp) =3D 1.448159e+13
ulp(q, qq) =3D 2.257545e+14

For values of N > 4, the series start to diverge!  So, how does msun
use the large argument approximation for j0(x)?

--
Steve
_______________________________________________
freebsd-numerics@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-numerics
To unsubscribe, send any mail to "freebsd-numerics-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ae55265d8d544cdc8a3ebc4314e1d01c>