Post Reply 
[HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
01-01-2024, 07:56 AM (This post was last modified: 01-02-2024 05:04 AM by LdBeth.)
Post: #1
[HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
There are seven functions of the type % --> % provided, they are ERF
function, Q function, and their inverse implemented using numerical
approximation methods. Internally they are all computed using extended
float.

ERF, IERF

Implementation of error function and its inverse using method from
Sergei Winitzki's paper.

ERFIV

Implementation of inverse error function using method from Mike Giles'
paper.

QNORM, IQNORM

Implementation of Q function and its inverse using `ERF` and `IERF`.
Note the `UPTN` function actually gives a more acurrate result for
Q function, but the inverse Q function is much faster than
computing the inverse of Q using numerical solver, while
the accuracy of both methods are approximately the same.

QBEST

A slightly better Q function approximation from [Dao Ngoc Phong et al].
If you ask me the result is still not as good as `UPTN`.

IQSML

This function from Pingyi Fan's paper gives decent approximation to
inverse Q function when the input is small enough, and can compute the
inverse when `IQNORM` gives infinity error.

Reference

[Sergei Winitzki] A handy approximation for the error
function and its inverse, February 6, 2008.

[Dao Ngoc Phong, Nguyen Xuan Hoai, R.I. (Bob) McKay] Evolving
the Best Known Approximation to the Q Function.

[Mike Giles] Approximating the erfinv function.

[Pingyi Fan] New inequalities of Mill's ratio and Its Application to
The Inverse Q-function Approximation


.zip  erflib.zip (Size: 64.55 KB / Downloads: 5)
Find all posts by this user
Quote this message in a reply
01-01-2024, 08:09 PM (This post was last modified: 01-01-2024 08:15 PM by Gil.)
Post: #2
RE: [HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
Where your programs can be downloaded or seen?

And do they accept complex numbers?
Find all posts by this user
Quote this message in a reply
01-02-2024, 04:36 AM
Post: #3
RE: [HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
Quote:Where your programs can be downloaded or seen?

Sorry I just figure out how to add attachment to the message. It is now added to the first message of the thread.

Quote:And do they accept complex numbers?

No since my intention was to implement fast Q function and its inverse for probability computation, the functions are not extended for complex numbers, and neither the methods I referenced are meant to be used for implement complex valued erf function.
Find all posts by this user
Quote this message in a reply
01-02-2024, 12:41 PM (This post was last modified: 01-02-2024 01:51 PM by Gil.)
Post: #4
RE: [HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
As many of these functions can be expressed in term of erf, erfc, that accept theorically a complex number as argument, it might be interesting to have an alternative way of computing them (with complex number) in the HP50G, just to compare the results with the ones calculated in my programs.

By the way, what do you find for
inverse_ERFc(1.93206244519E-475)?

The answer should be almost 33, and not infinity
as ERFc(33) =1.93206244519E-475).

Other question:
inverse_erf(1E-9) =?

The correct answer should be about
8.86226925455E-10 (by effective integral execution),
and not 8.86622703261E-10 (by UTPN).
Find all posts by this user
Quote this message in a reply
01-03-2024, 10:42 AM
Post: #5
RE: [HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
Quote:By the way, what do you find for
inverse_ERFc(1.93206244519E-475)?

The answer should be almost 33, and not infinity
as ERFc(33) =1.93206244519E-475).

I didn't implement erfc or its inverse function in the library so I have no result for comparison. But if you are interested in the correctness of your result, FriCAS gives

Code:

(3) -> digits 1000 

   (3)  5000
                                                        Type: PositiveInteger
(4) -> (1-erf 33.0)

   (4)
  0.1932062445_1698342642_6004297272_4878262694_0319954218_2378803210_3811145​90
  6_7729280350_9838344592_7210714495_4729261041_3378807649_9598674160_7827697​59
  4_1784866336_6792653022_6594598690_5177697043_1017564226_1489350712_9934497​21
  3_9594793993_5262359569_8250260525_5660501538_7635587817_8709159148_6787800​01
  8_9047375095_3646668376_0159595623_8758721064_2807064917_2318193821_5102971​00
  5_5085983115_6245282239_5693603230_4126121848_3058777289_5993452272_5154879​23
  5_0176948667_6196507796_7975788803_1141321162_8373996275_7293290870_9161149​69
  1_0433795838_7691660545_3675471594_2096004090_9235269470_0386425237_6152124​29
  1_9559601207_1199474637_4682120881_2503224600_2360167383_8202940058_4714355​92
  3_7008380850_7622281630_6532955554_5622541872_1182998216_8729690475_3754741​68
  4_8107119024_1876451777_0338712480_7685310255_1784413081_2009636745_5481002​35
  9_6163710640_0273901319_4779319675_6521022660_1014063765_6140459853_2032430​06
  7_7311393656_3570704001_7309147447_6651263962_0668950160_9685148444_5001971​24
  2_0452050499_8907437001_4649119078_6252980720_7231657066_3391430623_7802965​72
  8_5649549993_550501983 E -474

And by comparing the result computed using higher precision (5000 digits), I think you can trust the above result up to the 7_7311393656 part.

Quote:inverse_erf(1E-9) =?

The correct answer should be about
8.86226925455E-10 (by effective integral execution)

IERF gives undefined result error, ERFIV gives 8.86226869911E-10.

I don't think FriCAS can do inverse ERF so I asked Wolfram, it says

8.8622692545275801388109740820522708507986498595507634336469 × 10^-10

(Wolfram computes the result in higher precision until the result converges, so I know all except the last digit can be trusted)
Given that nothing outside extended real number computation been used, I think the ERFIV gives pretty decent approximation.
Find all posts by this user
Quote this message in a reply
01-03-2024, 02:52 PM (This post was last modified: 01-03-2024 04:07 PM by Gil.)
Post: #6
RE: [HP49/50g] ERF, ERF inverse, Q, Q inverse in SysRPL
Thanks for your reply.

I thought that your program calculated also erf, erfc and their inverse, as does my program, that calculates also the FRESNEL integrals F_C & F_S (normalized or not) for any real number (-infinity +infinity) & equally for "small" complex numbers z=a+b with b≠ 0 and abs(a) and abs(b) less or equal to 5.

I was interested in your Fresnel Integrals results F_C & /F_S — normalized as in Wolfram or not normalized as in Wikipedia graph —, when dealing with very large numbers (1000, 1 milllion, 1e12, for instance), just to see their good accuracy and compare them with my own (good) results and the ones calculated in Wolfram.

Regards,
Gil
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: