(50g) Normal Distribution
12-08-2018, 09:28 PM
Post: #21
 John Keith Senior Member Posts: 621 Joined: Dec 2013
RE: (50g) Normal Distribution
(12-08-2018 08:15 PM)Albert Chan Wrote:  Hi, John Keith

Now that you have a good PDF function, here is the bad news.
The extra precision is basically useless.

Thanks, Albert. I realize that 12 digits of precision are overkill for any real-world application. After all, if you know that the chance of some outcome is 1 in 1E60 it hardly seems necessary to know it to 12 digits! Mainly, I just like the idea of a user function being as accurate as the built-in commands.

I have also learned a lot about efficient programming and numerical accuracy from your and Dieter's posts, and those of many others as well.
12-15-2018, 03:03 PM (This post was last modified: 12-15-2018 04:44 PM by Albert Chan.)
Post: #22
 Albert Chan Senior Member Posts: 1,243 Joined: Jul 2018
RE: (50g) Normal Distribution
(12-08-2018 07:13 PM)John Keith Wrote:  ... the idea of using 1-ln(sqrt(2*pi)) proved to be less accurate on the HP 50 so I stuck with dividing by sqrt(2*pi) instead.

For 12-digits calculator, this constant is better, relative error ~ 1.25e-18

k = e-0.88453 / √(2 Pi) = 0.164726 536723 000000 206 ... => 0.164726 536723

Z(x) = exp(0.88453 - B) exp(B - I²/2 - I F - F²/2) * k

Examples:

Z(20.33333 33333) = exp(0.88453 - 413/2) exp(-0.222222 221544) * 0.164726 536723 = 6.64644 887123 e-91

Z(16.4285 714286) = exp(0.88453 - 269/2) exp(-0.448979 592306) * 0.164726 536723 = 9.84720 298683 e-60

edit: 1 - ln(sqrt(2*pi)) constant had a flaw I missed. exp(-1-B) term might underflow to 0.0
12-15-2018, 08:26 PM (This post was last modified: 12-17-2018 01:52 AM by Albert Chan.)
Post: #23
 Albert Chan Senior Member Posts: 1,243 Joined: Jul 2018
RE: (50g) Normal Distribution
(12-15-2018 03:03 PM)Albert Chan Wrote:  k = e-0.88453 / √(2 Pi) = 0.164726 536723 000000 206 ... => 0.164726 536723

Combine above k with 1 Exp method, revision 2, calculate Z(z):

B = z*z/2
D = exp(0.88453 - B) * 0.164726 536723

x = z, rounded to 5 digits
h = z - x
y = B - x²/2 - x h - h²/2

Z(z) = D + y D

Examples:

Z(20.33333 33333) = 6.64644 886819 e-91 + 303 ULP = 6.64644 887122 e-91

Z(16.4285 714286) = 9.84720 298984 e-60 − 301 ULP = 9.84720 298683 e-60
01-26-2019, 10:01 PM
Post: #24
 John Keith Senior Member Posts: 621 Joined: Dec 2013
RE: (50g) Normal Distribution
Update: It turns out I was wrong, the HP 50g (48G and 49 as well) does have a command for the normal PDF. It's called NDIST and its right there in the MATH/PROBABILITY menu, 2nd page, along with the other distribution-related commands. DOH!

Still, we all learned a lot about numerical accuracy in this thread, right?
01-26-2019, 10:12 PM
Post: #25
 pier4r Senior Member Posts: 2,067 Joined: Nov 2014
RE: (50g) Normal Distribution
I think sharing alternative ways, even if solutions already exists, is always helpful.

- for discussions (see precision and so on)
- to collect info that solutions already exist (see ndist) that may not be known to others.
- to show examples how a problem can be solved, approach that is not easy to see in a compiled library (or even a library with difficult to read open source code)

In the minimal case, at least the person sharing the "redundant" solution is now part of the club "I did it too". Same as the club of "I solved it too" when there is a problem to solve of which the solution is known.

Therefore kudos.

Wikis are great, Contribute :)
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)