Accurate Bernoulli numbers on the 41C, or "how close can you get"?
03-21-2014, 01:37 PM (This post was last modified: 03-21-2014 06:33 PM by Dieter.)
Post: #26
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"?
(03-21-2014 05:54 AM)Ángel Martin Wrote:  Using MCODE the advantage is obvious, as the coefficients are sort of pre-compiled. Rational approximations allow simpler operations (basically sum and multiplication), which avoids slower routines even in MCODE. It's also nice to have the same execution time for all arguments.

Yes, that's why I like these methods in Pascal and VB. Over the years I have been using custom-designed rational approximations for various applications. BTW this does not require Maple or Mathematica, it can also be done with standard software like Excel. I really like polynomial/rational approximations - but less so in a user-code program. That's why I suggested the idea of a very simple "first guess" rational approximation with subsequent refinement.

(03-21-2014 05:54 AM)Ángel Martin Wrote:  How does your method hold up in the vicinity of one? That's where the CUDA approach really surpasses any other approximation I tried in the past.

There generally is no problem near one if you use the obvious solution: In all the methods I use for the Normal quantile, only the lower half (p<0,5) is considered and the other half is simply evaluated as -QF(1-p). Easy as that. ;-)

That's why the results for p close to 1 are as accurate as those for 1-p.

QF(0,9) = -1,281551566
QF(0,99) = -2,236347874
QF(0,999) = -3,090232306
QF(0,9999) = -3,719016485
QF(0,99999) = -4,264890794
QF(0,999999) = -4,753424309
QF(0,9999999) = -5,199337582
QF(0,99999999) = -5,612001244
QF(0,999999999) = -5,997807015
QF(0,9999999999) = -6,361340902

All these are exact. Which of course does not mean that the 10-digit FOCAL routine might not have errors in the last place here and there.

In general, it simply does not matter whether QF(0,99999) or QF(0,00001) is calculated. If it was possible to enter 1 - 1E-99 the algorithm would handle this just as well. ;-)

So the idea is:

IF p < 0,5
THEN return QF(p)
ELSE return -QF(1-p)

(03-21-2014 05:54 AM)Ángel Martin Wrote:  Unfortunately I only used 10 digits to implement the double-precision expression (ran out of ROM space), but even then it returns decent results.
...
ICPF(0.9999) = 3,719016392
ICPF(0.99999) = 4,264890427
...
accurate to the 8th. and 7th decimal digits respectively

The FOCAL program I mentioned (initial guess + 1 correction step) is mostly within 1 or 2 ULP, even with just 10 digits working precision.

The only exception I noticed are results between 0,7 and 1 which may be off by 5 or 6 ULP. That's because at this point the CDF that's used in the correction step would require 11-12 digits for an exact quantile.

The FOCAL program using two rational approximations should be within 2 ULP over the whole range. But I did not do any thorough tests.

(03-21-2014 05:54 AM)Ángel Martin Wrote:  BTW, V41 is not good for benchmarking execution speed - even using default settings it's still a function of the PC's CPU. I'm using an old-reliable XP machine, 9-years old so likely slower than yours ;-)

I wouldn't bet on it. The device I'm writing this on shows a BIOS date in late 2002 when powering up. ;-) With standard settings, V41 is about twice as fast as my "real" HP41. Due to the TIME function in V41 the FOCAL program using a rational approximation runs in 2,67 seconds.

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-09-2014, 07:12 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-10-2014, 12:20 AM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-10-2014, 08:23 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-12-2014, 04:34 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-14-2014, 10:05 AM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-14-2014, 09:37 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-14-2014, 10:00 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-14-2014, 10:21 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-14-2014, 10:04 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-15-2014, 09:32 AM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-15-2014, 12:26 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-15-2014, 06:12 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Thomas Klemm - 03-15-2014, 07:17 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-15-2014, 12:56 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-15-2014, 08:47 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-18-2014, 09:24 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-19-2014, 06:47 AM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-19-2014, 01:37 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-19-2014, 07:32 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-19-2014, 08:31 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-20-2014, 06:46 AM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-20-2014, 12:44 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-20-2014, 02:21 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-20-2014, 09:07 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Ángel Martin - 03-21-2014, 05:54 AM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-21-2014 01:37 PM RE: Accurate Bernoulli numbers on the 41C, or "how close can you get"? - Dieter - 03-28-2014, 07:56 PM