Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I find you lack of faith in the forth dithturbing. -- Darse ("Darth") Vader


devel / comp.lang.forth / Spherical Bessel and spherical Neumann functions in Forth

SubjectAuthor
* Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
+* Re: Spherical Bessel and spherical Neumann functions in ForthHans Bezemer
|`* Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
| `* Re: Spherical Bessel and spherical Neumann functions in ForthHans Bezemer
|  `* Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
|   `* Re: Spherical Bessel and spherical Neumann functions in ForthHans Bezemer
|    `* Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
|     +* Re: Spherical Bessel and spherical Neumann functions in Forthnone
|     |`- Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
|     `* Re: Spherical Bessel and spherical Neumann functions in ForthMarcel Hendrix
|      `* Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
|       `- Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni
`* Re: Spherical Bessel and spherical Neumann functions in Forthminf...@arcor.de
 `- Re: Spherical Bessel and spherical Neumann functions in ForthKrishna Myneni

1
Spherical Bessel and spherical Neumann functions in Forth

<t9qaag$2n5lf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18819&group=comp.lang.forth#18819

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Spherical Bessel and spherical Neumann functions in Forth
Date: Sat, 2 Jul 2022 15:37:34 -0500
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <t9qaag$2n5lf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Jul 2022 20:37:36 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="c689ee745c9d5f7775038953da54bd0a";
logging-data="2856623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VvsNOusskgsDIZA+LwkKa"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:JDQdu1Xdcy0EWto3Jkx1pISMs7g=
Content-Language: en-US
 by: Krishna Myneni - Sat, 2 Jul 2022 20:37 UTC

Forth code for calculation over a large set of spherical Bessel and
spherical Neumann functions, with standard normalization, is available
in the kForth repos. -- see, for example,

https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/extras/sph_bes_neu.4th

While the FSL provides a spherical Bessel function calculator for the
first ten functions, j_0(x) -- j_9(x), the present code extends the
calculation range to beyond j_100(x). The spherical Neumann functions,
n_l(x) (also often denoted by y_l(x)) are also computed over the same
range of l.

Test code is included, with reference values obtained from Wolfram
Alpha. The original source for this code is a paper in Computers in
Physics vol. 2, pp. 62--72 (1988), linked below, in which they provide
an accuracy analysis. The test code appears to show this version,
running under kForth, exceeds the accuracy reported in the paper for
double precision calculations. One should note that kForth's FSIN and
FCOS make use of the C math library routines for computing sin(x) and
cos(x), instead of the f.p.u. processor instruction FSINCOS -- the
latter has a well-known degradation of performance for large arguments,
x, while the C math library functions modulo the argument into a range
with full accuracy.

The original 1988 paper is available at

https://aip.scitation.org/doi/pdf/10.1063/1.168296

--
Krishna Myneni

Re: Spherical Bessel and spherical Neumann functions in Forth

<468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18845&group=comp.lang.forth#18845

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:7d05:0:b0:31d:376a:b54b with SMTP id g5-20020ac87d05000000b0031d376ab54bmr10082371qtb.42.1656847022488;
Sun, 03 Jul 2022 04:17:02 -0700 (PDT)
X-Received: by 2002:a05:622a:647:b0:31d:2a37:1adf with SMTP id
a7-20020a05622a064700b0031d2a371adfmr16472302qtb.328.1656847022344; Sun, 03
Jul 2022 04:17:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 3 Jul 2022 04:17:02 -0700 (PDT)
In-Reply-To: <t9qaag$2n5lf$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <t9qaag$2n5lf$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sun, 03 Jul 2022 11:17:02 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2238
 by: Hans Bezemer - Sun, 3 Jul 2022 11:17 UTC

On Saturday, July 2, 2022 at 10:37:38 PM UTC+2, Krishna Myneni wrote:
> The test code appears to show this version,
> running under kForth, exceeds the accuracy reported in the paper for
> double precision calculations. One should note that kForth's FSIN and
> FCOS make use of the C math library routines for computing sin(x) and
> cos(x), instead of the f.p.u. processor instruction FSINCOS -- the
> latter has a well-known degradation of performance for large arguments,
> x, while the C math library functions modulo the argument into a range
> with full accuracy.

Thanks for publishing this. It was a breeze to port to 4tH and ran straight
away. That having said, the accuracy I achieved was MUCH lower - and probably
due to the Remez algorithm of my high level FSIN + FCOS functions.

But if these ranges are that large, why not use your own "fsin near pi" function?

: fsin_near_npi ( rdelta n -- r )
2 mod if fnegate then
fdup 7 fpow 5040 s>f f/
fover 5 fpow 120 s>f f/ f-
fover 3 fpow 6 s>f f/ f+
f-
;

Hans Bezemer

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9rv70$31ajv$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18848&group=comp.lang.forth#18848

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Sun, 3 Jul 2022 06:40:15 -0500
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <t9rv70$31ajv$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me>
<468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Jul 2022 11:40:16 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="38b2810502bd89afaf006c6504d759c4";
logging-data="3189375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oPiZNLaWqGpxnEQCwD0rz"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:HpVgRIPZqIMLBq411gCLJMXw+QU=
Content-Language: en-US
In-Reply-To: <468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
 by: Krishna Myneni - Sun, 3 Jul 2022 11:40 UTC

On 7/3/22 06:17, Hans Bezemer wrote:
> On Saturday, July 2, 2022 at 10:37:38 PM UTC+2, Krishna Myneni wrote:
>> The test code appears to show this version,
>> running under kForth, exceeds the accuracy reported in the paper for
>> double precision calculations. One should note that kForth's FSIN and
>> FCOS make use of the C math library routines for computing sin(x) and
>> cos(x), instead of the f.p.u. processor instruction FSINCOS -- the
>> latter has a well-known degradation of performance for large arguments,
>> x, while the C math library functions modulo the argument into a range
>> with full accuracy.
>
> Thanks for publishing this. It was a breeze to port to 4tH and ran straight
> away. That having said, the accuracy I achieved was MUCH lower - and probably
> due to the Remez algorithm of my high level FSIN + FCOS functions.
>

I'm mistaken about the accuracy being exceeded under kForth over what is
reported in the original paper. I was comparing to the estimated
accuracies for the unnormalized version (shown in Table V) which were in
the 10^-15 range. The accuracies reported in Table III for the
normalized functions are consistent with what my test code finds against
the reference values from Wolfram Alpha.

> But if these ranges are that large, why not use your own "fsin near pi" function?
>
> : fsin_near_npi ( rdelta n -- r )
> 2 mod if fnegate then
> fdup 7 fpow 5040 s>f f/
> fover 5 fpow 120 s>f f/ f-
> fover 3 fpow 6 s>f f/ f+
> f-
> ;

The range of the argument to the different j_l(x) and n_l(x) does not
exceed 300 in the test code, which is likely too small to see a
difference between using the native FSINCOS fpu instruction vs the C
library FSIN and FCOS functions. A comparison against values for large x
should show the problem.

I'm not familiar with the algorithm above. Doesn't range reduction
require higher precision arithmetic?

--
KM

Re: Spherical Bessel and spherical Neumann functions in Forth

<0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18849&group=comp.lang.forth#18849

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ad4:5dc1:0:b0:46e:d7c:aefc with SMTP id m1-20020ad45dc1000000b0046e0d7caefcmr23175437qvh.44.1656850916731;
Sun, 03 Jul 2022 05:21:56 -0700 (PDT)
X-Received: by 2002:a05:622a:190d:b0:31d:2ac7:9dc2 with SMTP id
w13-20020a05622a190d00b0031d2ac79dc2mr16662639qtc.233.1656850916494; Sun, 03
Jul 2022 05:21:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 3 Jul 2022 05:21:56 -0700 (PDT)
In-Reply-To: <t9rv70$31ajv$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <t9qaag$2n5lf$1@dont-email.me> <468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sun, 03 Jul 2022 12:21:56 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3003
 by: Hans Bezemer - Sun, 3 Jul 2022 12:21 UTC

On Sunday, July 3, 2022 at 1:40:18 PM UTC+2, Krishna Myneni wrote:
> The range of the argument to the different j_l(x) and n_l(x) does not
> exceed 300 in the test code, which is likely too small to see a
> difference between using the native FSINCOS fpu instruction vs the C
> library FSIN and FCOS functions. A comparison against values for large x
> should show the problem.
>
> I'm not familiar with the algorithm above. Doesn't range reduction
> require higher precision arithmetic?
I dunno - YOU tell ME ;-)

HB

\ High accuracy calculation of double-precision sin(x),
\ using Taylor Series approximation when x is near
\ a multiple of pi.
\ Due to finite precision in the representation of x,
\ the calculation of sin(x) can suffer a loss of
\ significant digits when x is near pi.
\ The Intel and AMD FPUs also suffer a loss of accuracy in
\ the FSIN instruction, for an argument, x, which is
\ near a multiple of pi, n*pi, for n>1. This function uses
\ an 10th order Taylor Series approximation to compute sin(x)
\ for those cases:
\ sin(pi + delta) = -delta + delta^3/6 - delta^5/120
\ + delta^7/5040 + ...
\ Higher order terms are not used.
\ For |delta| <= 1e-5, the accuracy in double precision
\ will be 16 significant digits.
===>> \ Krishna Myneni, <krishn...@ccreweb.org> <<===

\ Compute sin(n*pi + rdelta) to high accuracy, where
\ rdelta is an offset and n = 0,1,2, ...

[UNDEFINED] fsin_near_pi [IF]
[UNDEFINED] fpow [IF] include lib/fpow.4th [THEN]
: fsin_near_npi ( rdelta n -- r )
2 mod if fnegate then
fdup 7 fpow 5040 s>f f/
fover 5 fpow 120 s>f f/ f-
fover 3 fpow 6 s>f f/ f+
f-
; [THEN]

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9s9it$32kim$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18852&group=comp.lang.forth#18852

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Sun, 3 Jul 2022 09:37:15 -0500
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <t9s9it$32kim$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me>
<468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me>
<0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Jul 2022 14:37:17 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="38b2810502bd89afaf006c6504d759c4";
logging-data="3232342"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HZYGY44M3ZZySlMRRqUCW"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:7cwRWxbazmY0OHfeGUDQpjJmrTs=
Content-Language: en-US
In-Reply-To: <0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
 by: Krishna Myneni - Sun, 3 Jul 2022 14:37 UTC

On 7/3/22 07:21, Hans Bezemer wrote:
> On Sunday, July 3, 2022 at 1:40:18 PM UTC+2, Krishna Myneni wrote:
>> The range of the argument to the different j_l(x) and n_l(x) does not
>> exceed 300 in the test code, which is likely too small to see a
>> difference between using the native FSINCOS fpu instruction vs the C
>> library FSIN and FCOS functions. A comparison against values for large x
>> should show the problem.
>>
>> I'm not familiar with the algorithm above. Doesn't range reduction
>> require higher precision arithmetic?
> I dunno - YOU tell ME ;-)
>
> HB
>
> \ High accuracy calculation of double-precision sin(x),
> \ using Taylor Series approximation when x is near
> \ a multiple of pi.
>
> \ Due to finite precision in the representation of x,
> \ the calculation of sin(x) can suffer a loss of
> \ significant digits when x is near pi.
>
> \ The Intel and AMD FPUs also suffer a loss of accuracy in
> \ the FSIN instruction, for an argument, x, which is
> \ near a multiple of pi, n*pi, for n>1. This function uses
> \ an 10th order Taylor Series approximation to compute sin(x)
> \ for those cases:
>
> \ sin(pi + delta) = -delta + delta^3/6 - delta^5/120
>
> \ + delta^7/5040 + ...
>
> \ Higher order terms are not used.
>
> \ For |delta| <= 1e-5, the accuracy in double precision
> \ will be 16 significant digits.
>
> ===>> \ Krishna Myneni, <krishn...@ccreweb.org> <<===
>
> \ Compute sin(n*pi + rdelta) to high accuracy, where
> \ rdelta is an offset and n = 0,1,2, ...
>
> [UNDEFINED] fsin_near_pi [IF]
> [UNDEFINED] fpow [IF] include lib/fpow.4th [THEN]
> : fsin_near_npi ( rdelta n -- r )
> 2 mod if fnegate then
> fdup 7 fpow 5040 s>f f/
> fover 5 fpow 120 s>f f/ f-
> fover 3 fpow 6 s>f f/ f+
> f-
> ;
> [THEN]
>
>

The above can be considered a special case of range reduction only when
the argument is very close to pi for sin(x) (delta <= 1e-5). Something
similar can be done for cos(x) when the argument is near integer
multiples of pi/2, but, in general, when x is arbitrary and greater than
pi, the accuracy of the fpu FSIN and FCOS instructions is diminished as
|x| increases. So, the algorithm above wouldn't be useful for general
arguments to the spherical Bessel function calculations when |x| is
large. Range reduction of a general argument into the interval -pi,pi
requires higher precision to avoid degrading the precision of the
original argument.

--
KM

--

Re: Spherical Bessel and spherical Neumann functions in Forth

<ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18858&group=comp.lang.forth#18858

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:1903:b0:305:a19:78b7 with SMTP id w3-20020a05622a190300b003050a1978b7mr21060989qtc.342.1656862804806;
Sun, 03 Jul 2022 08:40:04 -0700 (PDT)
X-Received: by 2002:a05:620a:2456:b0:6af:31c6:c1af with SMTP id
h22-20020a05620a245600b006af31c6c1afmr16951331qkn.25.1656862804635; Sun, 03
Jul 2022 08:40:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 3 Jul 2022 08:40:04 -0700 (PDT)
In-Reply-To: <t9s9it$32kim$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=77.174.47.232; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 77.174.47.232
References: <t9qaag$2n5lf$1@dont-email.me> <468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me> <0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
<t9s9it$32kim$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sun, 03 Jul 2022 15:40:04 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1937
 by: Hans Bezemer - Sun, 3 Jul 2022 15:40 UTC

On Sunday, July 3, 2022 at 4:37:20 PM UTC+2, Krishna Myneni wrote:
> The above can be considered a special case of range reduction only when
> the argument is very close to pi for sin(x) (delta <= 1e-5).
Oh! I didn't know that! I thought it was +/-0.5 pi ;-)

> Range reduction of a general argument into the interval -pi,pi
> requires higher precision to avoid degrading the precision of the
> original argument.
I know all about that. And it gets worse when precision is pretty low.
So, SIN(1000 PI) is always a problem (when given as an FP number).

But many thanks for your clarifications! I learned something!

Hans Bezemer

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9uli5$3ces2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18884&group=comp.lang.forth#18884

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Mon, 4 Jul 2022 07:13:55 -0500
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <t9uli5$3ces2$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me>
<468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me>
<0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
<t9s9it$32kim$1@dont-email.me>
<ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Jul 2022 12:13:57 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0d38c300d438d828a03dd0617af13c1";
logging-data="3554178"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+c9cUYXSI3SzvDQhlq2Yx"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:bAvAvl+UfzINb+nhMQkpIJRuNXE=
Content-Language: en-US
In-Reply-To: <ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
 by: Krishna Myneni - Mon, 4 Jul 2022 12:13 UTC

On 7/3/22 10:40, Hans Bezemer wrote:
> On Sunday, July 3, 2022 at 4:37:20 PM UTC+2, Krishna Myneni wrote:
>> The above can be considered a special case of range reduction only when
>> the argument is very close to pi for sin(x) (delta <= 1e-5).
> Oh! I didn't know that! I thought it was +/-0.5 pi ;-)
>
>> Range reduction of a general argument into the interval -pi,pi
>> requires higher precision to avoid degrading the precision of the
>> original argument.
> I know all about that. And it gets worse when precision is pretty low.
> So, SIN(1000 PI) is always a problem (when given as an FP number).
>
> But many thanks for your clarifications! I learned something!
>

Some examples of reduced accuracy without range reduction may be
illustrative for others who are not aware of the issue we are discussing.

In kForth FSINCOS standard floating point word uses the native fpu
instruction for computing the sin(x) and cos(x) functions -- this
provides a fast way of computing these functions when it is known in
advance that the range of x will be limited. In contrast the standard
FSIN and FCOS words call GCC's math library functions, which use proper
range reduction before calling the native fpu instructions. These words
are useful for obtaining the best accuracy over an unknown range of
arguments.

Below is a comparison of using the library version of FSIN vs the fpu
instruction for FSIN in kForth:

17 set-precision
ok

\ x = 10,000.
1.0e4 fsin fs.
-3.0561438888825215e-01 ok \ with range reduction

1.0e4 fsincos fdrop fs.
-3.0561438888825215e-01 ok \ native fpu instruction

\ x = 100,000.
1.0e5 fsin fs.
3.5748797972016508e-02 ok \ with range reduction

1.0e5 fsincos fdrop fs.
3.5748797972016383e-02 ok \ native fpu instruction

\ x = 1,000,000.
1.0e6 fsin fs.
-3.4999350217129294e-01 ok \ with range reduction

1.0e6 fsincos fdrop fs.
-3.4999350217129177e-01 ok \ native fpu instruction

The above results may be compared with high precision reference values
for sin(x), e.g. using maxima, Wolfram Alpha, etc.

It occurred to me that we should be able to implement proper range
reduction in Forth using Julian Noble's double-double arithmetic words,
for cases where it is important, without resorting to C math library
functions. I have this issue in kForth-Win32 -- the Digital Mars C++
compiler's math library does not do proper range reduction for the trig
functions.

--
Krishna

Re: Spherical Bessel and spherical Neumann functions in Forth

<nnd$5a3f24f9$3bbe5f49@2db94a243cd573ed>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18886&group=comp.lang.forth#18886

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <t9qaag$2n5lf$1@dont-email.me> <t9s9it$32kim$1@dont-email.me> <ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com> <t9uli5$3ces2$1@dont-email.me>
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$5a3f24f9$3bbe5f49@2db94a243cd573ed>
Organization: KPN B.V.
Date: Mon, 04 Jul 2022 14:25:55 +0200
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 34
Injection-Date: Mon, 04 Jul 2022 14:25:55 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2049
 by: none - Mon, 4 Jul 2022 12:25 UTC

In article <t9uli5$3ces2$1@dont-email.me>,
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
<SNIP>
>
>The above results may be compared with high precision reference values
>for sin(x), e.g. using maxima, Wolfram Alpha, etc.
>
>It occurred to me that we should be able to implement proper range
>reduction in Forth using Julian Noble's double-double arithmetic words,
>for cases where it is important, without resorting to C math library
>functions. I have this issue in kForth-Win32 -- the Digital Mars C++
>compiler's math library does not do proper range reduction for the trig
>functions.

I looked at range reduction working on tforth's floating point
packet.
For a sufficient large x the uncertainly in x is +/-pi , and the
sin and cosine may be all over the place. in the range [-1,+1].
How can range reduction help, unless by accident it is known that
x is mathematically exact (which I guess would be rare for physics
calculations) ?

>
>--
>Krishna

Groetjes Albert
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9upnr$3cs47$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18887&group=comp.lang.forth#18887

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Mon, 4 Jul 2022 08:25:15 -0500
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <t9upnr$3cs47$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me> <t9s9it$32kim$1@dont-email.me>
<ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
<t9uli5$3ces2$1@dont-email.me> <nnd$5a3f24f9$3bbe5f49@2db94a243cd573ed>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Jul 2022 13:25:15 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0d38c300d438d828a03dd0617af13c1";
logging-data="3567751"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6Tmbtu2TdI7LSTgu1E9gK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:jZAf7B/5buwCIkg+cX1rMmH7AJ8=
Content-Language: en-US
In-Reply-To: <nnd$5a3f24f9$3bbe5f49@2db94a243cd573ed>
 by: Krishna Myneni - Mon, 4 Jul 2022 13:25 UTC

On 7/4/22 07:25, albert wrote:
> In article <t9uli5$3ces2$1@dont-email.me>,
> Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
> <SNIP>
>>
>> The above results may be compared with high precision reference values
>> for sin(x), e.g. using maxima, Wolfram Alpha, etc.
>>
>> It occurred to me that we should be able to implement proper range
>> reduction in Forth using Julian Noble's double-double arithmetic words,
>> for cases where it is important, without resorting to C math library
>> functions. I have this issue in kForth-Win32 -- the Digital Mars C++
>> compiler's math library does not do proper range reduction for the trig
>> functions.
>
> I looked at range reduction working on tforth's floating point
> packet.
> For a sufficient large x the uncertainly in x is +/-pi , and the
> sin and cosine may be all over the place. in the range [-1,+1].
> How can range reduction help, unless by accident it is known that
> x is mathematically exact (which I guess would be rare for physics
> calculations) ?
>

All of the arguments used in the above examples are exactly represented
numbers in IEEE floating point. If your calculations can afford the
intermediate loss of accuracy from the native trig function
instructions, then you should use them.

--
Krishna

Re: Spherical Bessel and spherical Neumann functions in Forth

<13049107-c478-44f5-9e3c-2a1ccc55b5acn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18895&group=comp.lang.forth#18895

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:2992:b0:6ae:e8ff:b086 with SMTP id r18-20020a05620a299200b006aee8ffb086mr20825010qkp.494.1656956197844;
Mon, 04 Jul 2022 10:36:37 -0700 (PDT)
X-Received: by 2002:ac8:5991:0:b0:31d:2bfb:f089 with SMTP id
e17-20020ac85991000000b0031d2bfbf089mr20289449qte.663.1656956197625; Mon, 04
Jul 2022 10:36:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 4 Jul 2022 10:36:37 -0700 (PDT)
In-Reply-To: <t9uli5$3ces2$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c05:2f14:600:11c0:f101:174f:3962;
posting-account=-JQ2RQoAAAB6B5tcBTSdvOqrD1HpT_Rk
NNTP-Posting-Host: 2001:1c05:2f14:600:11c0:f101:174f:3962
References: <t9qaag$2n5lf$1@dont-email.me> <468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me> <0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
<t9s9it$32kim$1@dont-email.me> <ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
<t9uli5$3ces2$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <13049107-c478-44f5-9e3c-2a1ccc55b5acn@googlegroups.com>
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
From: mhx...@iae.nl (Marcel Hendrix)
Injection-Date: Mon, 04 Jul 2022 17:36:37 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 73
 by: Marcel Hendrix - Mon, 4 Jul 2022 17:36 UTC

On Monday, July 4, 2022 at 2:13:59 PM UTC+2, Krishna Myneni wrote:
> On 7/3/22 10:40, Hans Bezemer wrote:
> > On Sunday, July 3, 2022 at 4:37:20 PM UTC+2, Krishna Myneni wrote:
> >> The above can be considered a special case of range reduction only when
> >> the argument is very close to pi for sin(x) (delta <= 1e-5).
> > Oh! I didn't know that! I thought it was +/-0.5 pi ;-)
> >
> >> Range reduction of a general argument into the interval -pi,pi
> >> requires higher precision to avoid degrading the precision of the
> >> original argument.
> > I know all about that. And it gets worse when precision is pretty low.
> > So, SIN(1000 PI) is always a problem (when given as an FP number).
> >
> > But many thanks for your clarifications! I learned something!
> >
> Some examples of reduced accuracy without range reduction may be
> illustrative for others who are not aware of the issue we are discussing.
>
> In kForth FSINCOS standard floating point word uses the native fpu
> instruction for computing the sin(x) and cos(x) functions -- this
> provides a fast way of computing these functions when it is known in
> advance that the range of x will be limited. In contrast the standard
> FSIN and FCOS words call GCC's math library functions, which use proper
> range reduction before calling the native fpu instructions. These words
> are useful for obtaining the best accuracy over an unknown range of
> arguments.
>
> Below is a comparison of using the library version of FSIN vs the fpu
> instruction for FSIN in kForth:
>
> 17 set-precision
> ok
>
> \ x = 10,000.
> 1.0e4 fsin fs.
> -3.0561438888825215e-01 ok \ with range reduction
>
> 1.0e4 fsincos fdrop fs.
> -3.0561438888825215e-01 ok \ native fpu instruction
>
> \ x = 100,000.
> 1.0e5 fsin fs.
> 3.5748797972016508e-02 ok \ with range reduction
>
> 1.0e5 fsincos fdrop fs.
> 3.5748797972016383e-02 ok \ native fpu instruction
>
> \ x = 1,000,000.
> 1.0e6 fsin fs.
> -3.4999350217129294e-01 ok \ with range reduction
>
> 1.0e6 fsincos fdrop fs.
> -3.4999350217129177e-01 ok \ native fpu instruction
>
> The above results may be compared with high precision reference values
> for sin(x), e.g. using maxima, Wolfram Alpha, etc.

: TEST ( -- )
CR 1e4 fdup +e. fsin -0.3056143888882521413609100352325069742318500438618062391101551450e f- space +e.
CR 1e5 fdup +e. fsin 0.0357487979720165093164705006958088290090456925781088968546167365e f- space +e.
CR 1e6 fdup +e. fsin -0.3499935021712929521176524867807714690614066053287162738570590540e f- space +e. ;

FORTH> TEST
1.0000000000000000000e+0004 -1.2251484549086200104e-0017
1.0000000000000000000e+0005 -1.2865752842435018710e-0016
1.0000000000000000000e+0006 1.2060122865642508572e-0015 ok

For up to 1e5 we are still ok with double precision. Above that, accuracy
decreases linearly.

It might be more important that the approximation is continuous and smooth
than that it is highly accurate.

-marcel

Re: Spherical Bessel and spherical Neumann functions in Forth

<db90f127-8564-459e-8f5f-6df61f0fe3d5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18898&group=comp.lang.forth#18898

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:621:b0:432:5e0d:cb64 with SMTP id a1-20020a056214062100b004325e0dcb64mr28086615qvx.65.1656964942362;
Mon, 04 Jul 2022 13:02:22 -0700 (PDT)
X-Received: by 2002:a05:622a:1386:b0:31d:4c72:9139 with SMTP id
o6-20020a05622a138600b0031d4c729139mr5728838qtk.25.1656964941996; Mon, 04 Jul
2022 13:02:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 4 Jul 2022 13:02:21 -0700 (PDT)
In-Reply-To: <t9qaag$2n5lf$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=87.157.102.236; posting-account=AqNUYgoAAADmkK2pN-RKms8sww57W0Iw
NNTP-Posting-Host: 87.157.102.236
References: <t9qaag$2n5lf$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <db90f127-8564-459e-8f5f-6df61f0fe3d5n@googlegroups.com>
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
From: minfo...@arcor.de (minf...@arcor.de)
Injection-Date: Mon, 04 Jul 2022 20:02:22 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3179
 by: minf...@arcor.de - Mon, 4 Jul 2022 20:02 UTC

Krishna Myneni schrieb am Samstag, 2. Juli 2022 um 22:37:38 UTC+2:
> Forth code for calculation over a large set of spherical Bessel and
> spherical Neumann functions, with standard normalization, is available
> in the kForth repos. -- see, for example,
>
> https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/extras/sph_bes_neu.4th
>
> While the FSL provides a spherical Bessel function calculator for the
> first ten functions, j_0(x) -- j_9(x), the present code extends the
> calculation range to beyond j_100(x). The spherical Neumann functions,
> n_l(x) (also often denoted by y_l(x)) are also computed over the same
> range of l.
>
> Test code is included, with reference values obtained from Wolfram
> Alpha. The original source for this code is a paper in Computers in
> Physics vol. 2, pp. 62--72 (1988), linked below, in which they provide
> an accuracy analysis. The test code appears to show this version,
> running under kForth, exceeds the accuracy reported in the paper for
> double precision calculations. One should note that kForth's FSIN and
> FCOS make use of the C math library routines for computing sin(x) and
> cos(x), instead of the f.p.u. processor instruction FSINCOS -- the
> latter has a well-known degradation of performance for large arguments,
> x, while the C math library functions modulo the argument into a range
> with full accuracy.
>
> The original 1988 paper is available at
>
> https://aip.scitation.org/doi/pdf/10.1063/1.168296 >

Just being curious: I stumbled over spherical Bessel functions only once
when modelling heat propagation for thick-walled steam generator
components. FWIW there were always physically measured initial
conditions along with their naturally limited low measuring accuracies,
like pressures and temperatures at component walls. Measurement
error would always outweigh theoretical calculation precisions.

So what practical applications do really require those discussed enormous
calculation accuracies for Bessel functions??

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9vi1s$3fdrd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18900&group=comp.lang.forth#18900

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Mon, 4 Jul 2022 15:19:57 -0500
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <t9vi1s$3fdrd$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me>
<468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me>
<0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
<t9s9it$32kim$1@dont-email.me>
<ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
<t9uli5$3ces2$1@dont-email.me>
<13049107-c478-44f5-9e3c-2a1ccc55b5acn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Jul 2022 20:20:12 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0d38c300d438d828a03dd0617af13c1";
logging-data="3651437"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PHOQQ33cvmhTDQfNXkXvJ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:hhNwecRbiI7Ezj/Z7LF4JNg3Mt0=
In-Reply-To: <13049107-c478-44f5-9e3c-2a1ccc55b5acn@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Mon, 4 Jul 2022 20:19 UTC

On 7/4/22 12:36, Marcel Hendrix wrote:
> On Monday, July 4, 2022 at 2:13:59 PM UTC+2, Krishna Myneni wrote:
....
>> Below is a comparison of using the library version of FSIN vs the fpu
>> instruction for FSIN in kForth:
>>
>> 17 set-precision
>> ok
>>
>> \ x = 10,000.
>> 1.0e4 fsin fs.
>> -3.0561438888825215e-01 ok \ with range reduction
>>
>> 1.0e4 fsincos fdrop fs.
>> -3.0561438888825215e-01 ok \ native fpu instruction
>>
>> \ x = 100,000.
>> 1.0e5 fsin fs.
>> 3.5748797972016508e-02 ok \ with range reduction
>>
>> 1.0e5 fsincos fdrop fs.
>> 3.5748797972016383e-02 ok \ native fpu instruction
>>
>> \ x = 1,000,000.
>> 1.0e6 fsin fs.
>> -3.4999350217129294e-01 ok \ with range reduction
>>
>> 1.0e6 fsincos fdrop fs.
>> -3.4999350217129177e-01 ok \ native fpu instruction
>>
>> The above results may be compared with high precision reference values
>> for sin(x), e.g. using maxima, Wolfram Alpha, etc.
>
> : TEST ( -- )
> CR 1e4 fdup +e. fsin -0.3056143888882521413609100352325069742318500438618062391101551450e f- space +e.
> CR 1e5 fdup +e. fsin 0.0357487979720165093164705006958088290090456925781088968546167365e f- space +e.
> CR 1e6 fdup +e. fsin -0.3499935021712929521176524867807714690614066053287162738570590540e f- space +e. ;
>
> FORTH> TEST
> 1.0000000000000000000e+0004 -1.2251484549086200104e-0017
> 1.0000000000000000000e+0005 -1.2865752842435018710e-0016
> 1.0000000000000000000e+0006 1.2060122865642508572e-0015 ok
>
> For up to 1e5 we are still ok with double precision. Above that, accuracy
> decreases linearly.
>

See the following link. The graph showing "abs(error in ULPs)" vs
"Biased Exponent of Extended Precision input Argument" indicates that
the log-log plot of error vs magnitude is linear, not the error vs
magnitude.

> It might be more important that the approximation is continuous and smooth
> than that it is highly accurate.

I think it may be application dependent.

--
Krishna

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9vjvu$3fkqq$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18902&group=comp.lang.forth#18902

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Mon, 4 Jul 2022 15:53:16 -0500
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <t9vjvu$3fkqq$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me>
<db90f127-8564-459e-8f5f-6df61f0fe3d5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Jul 2022 20:53:18 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0d38c300d438d828a03dd0617af13c1";
logging-data="3658586"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NSoFpgJZVCyUCWwxTQItV"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:baWtbK1etY2EwKR0dJ8hBQyzE8I=
In-Reply-To: <db90f127-8564-459e-8f5f-6df61f0fe3d5n@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Mon, 4 Jul 2022 20:53 UTC

On 7/4/22 15:02, minf...@arcor.de wrote:
> Krishna Myneni schrieb am Samstag, 2. Juli 2022 um 22:37:38 UTC+2:
>> Forth code for calculation over a large set of spherical Bessel and
>> spherical Neumann functions, with standard normalization, is available
>> in the kForth repos. -- see, for example,
>>
>> https://github.com/mynenik/kForth-64/blob/master/forth-src/fsl/extras/sph_bes_neu.4th
>>
>> While the FSL provides a spherical Bessel function calculator for the
>> first ten functions, j_0(x) -- j_9(x), the present code extends the
>> calculation range to beyond j_100(x). The spherical Neumann functions,
>> n_l(x) (also often denoted by y_l(x)) are also computed over the same
>> range of l.
>>
>> Test code is included, with reference values obtained from Wolfram
>> Alpha. The original source for this code is a paper in Computers in
>> Physics vol. 2, pp. 62--72 (1988), linked below, in which they provide
>> an accuracy analysis. The test code appears to show this version,
>> running under kForth, exceeds the accuracy reported in the paper for
>> double precision calculations. One should note that kForth's FSIN and
>> FCOS make use of the C math library routines for computing sin(x) and
>> cos(x), instead of the f.p.u. processor instruction FSINCOS -- the
>> latter has a well-known degradation of performance for large arguments,
>> x, while the C math library functions modulo the argument into a range
>> with full accuracy.
>>
>> The original 1988 paper is available at
>>
>> https://aip.scitation.org/doi/pdf/10.1063/1.168296 >
>
> Just being curious: I stumbled over spherical Bessel functions only once
> when modelling heat propagation for thick-walled steam generator
> components. FWIW there were always physically measured initial
> conditions along with their naturally limited low measuring accuracies,
> like pressures and temperatures at component walls. Measurement
> error would always outweigh theoretical calculation precisions.
>
> So what practical applications do really require those discussed enormous
> calculation accuracies for Bessel functions??

One of its primary uses in physics is in theoretical quantum scattering
calculations from a finite interaction region in which the interaction
with a scattering center is spherically symmetric. I haven't used it for
such a numerical calculation, so I can't comment on practical required
accuracies, but it is likely to be highly problem-dependent, e.g. on the
energy/momentum distribution of the incident particle and on the
strength of the interaction.

A more general comment is that for a library module providing special
function values for use in calculations at some standard precision, the
ideal case is to have computed values of the function be accurate to
that level of precision (double precision f.p. in this case). Of course
it's not usually possible to have 1 ulp accuracy in the calculation of
special functions, particularly across a wide range of arguments, and
the present module is no exception.

The best accuracy within the precision format, over the widest range of
arguments, allows for the widest range of applications. But tradeoffs to
improve computational efficiency may be available if the argument range
is further restricted or the required accuracy is lower. It's important
to establish the accuracy of the calculation over an argument range to
enable further analysis of calculation errors.

--
KM

Re: Spherical Bessel and spherical Neumann functions in Forth

<t9vmn6$3ft1c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18903&group=comp.lang.forth#18903

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: Spherical Bessel and spherical Neumann functions in Forth
Date: Mon, 4 Jul 2022 16:39:50 -0500
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <t9vmn6$3ft1c$1@dont-email.me>
References: <t9qaag$2n5lf$1@dont-email.me>
<468b3e73-a6ed-4425-9ac9-878ca960ed37n@googlegroups.com>
<t9rv70$31ajv$1@dont-email.me>
<0819c63b-7920-452d-ae76-0392603a8f92n@googlegroups.com>
<t9s9it$32kim$1@dont-email.me>
<ad5cbd06-b58a-4a6a-b9c7-8d89d7d22809n@googlegroups.com>
<t9uli5$3ces2$1@dont-email.me>
<13049107-c478-44f5-9e3c-2a1ccc55b5acn@googlegroups.com>
<t9vi1s$3fdrd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 4 Jul 2022 21:39:50 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="e0d38c300d438d828a03dd0617af13c1";
logging-data="3666988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rddxVm+yWZcQ3cSuZGs+a"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:2Pu3R5hd78fVySSYMrrCdkpl2Ko=
Content-Language: en-US
In-Reply-To: <t9vi1s$3fdrd$1@dont-email.me>
 by: Krishna Myneni - Mon, 4 Jul 2022 21:39 UTC

On 7/4/22 15:19, Krishna Myneni wrote:
> On 7/4/22 12:36, Marcel Hendrix wrote:
>> On Monday, July 4, 2022 at 2:13:59 PM UTC+2, Krishna Myneni wrote:
> ...
>>> Below is a comparison of using the library version of FSIN vs the fpu
>>> instruction for FSIN in kForth:
>>>
>>> 17 set-precision
>>> ok
>>>
>>> \ x = 10,000.
>>> 1.0e4 fsin fs.
>>> -3.0561438888825215e-01 ok \ with range reduction
>>>
>>> 1.0e4 fsincos fdrop fs.
>>> -3.0561438888825215e-01 ok \ native fpu instruction
>>>
>>> \ x = 100,000.
>>> 1.0e5 fsin fs.
>>> 3.5748797972016508e-02 ok \ with range reduction
>>>
>>> 1.0e5 fsincos fdrop fs.
>>> 3.5748797972016383e-02 ok \ native fpu instruction
>>>
>>> \ x = 1,000,000.
>>> 1.0e6 fsin fs.
>>> -3.4999350217129294e-01 ok \ with range reduction
>>>
>>> 1.0e6 fsincos fdrop fs.
>>> -3.4999350217129177e-01 ok \ native fpu instruction
>>>
>>> The above results may be compared with high precision reference values
>>> for sin(x), e.g. using maxima, Wolfram Alpha, etc.
>>
>> : TEST ( -- )
>>   CR 1e4 fdup +e. fsin
>> -0.3056143888882521413609100352325069742318500438618062391101551450e
>> f- space +e.
>>   CR 1e5 fdup +e. fsin
>> 0.0357487979720165093164705006958088290090456925781088968546167365e f-
>> space +e.
>>   CR 1e6 fdup +e. fsin
>> -0.3499935021712929521176524867807714690614066053287162738570590540e
>> f- space +e. ;
>>
>> FORTH> TEST
>>   1.0000000000000000000e+0004 -1.2251484549086200104e-0017
>>   1.0000000000000000000e+0005 -1.2865752842435018710e-0016
>>   1.0000000000000000000e+0006  1.2060122865642508572e-0015 ok
>>
>> For up to 1e5 we are still ok with double precision. Above that, accuracy
>> decreases linearly.
>>
>
> See the following link. The graph showing "abs(error in ULPs)" vs
> "Biased Exponent of Extended Precision input Argument" indicates that
> the log-log plot of error vs magnitude is linear, not the error vs
> magnitude.
> ...
>

Oops. Here's the link:

http://notabs.org/fpuaccuracy/index.htm

--
KM

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor