Post Reply 
HP Prime: built-in inverse function of erf?
11-18-2023, 01:25 PM (This post was last modified: 11-18-2023 01:27 PM by Gil.)
Post: #1
HP Prime: built-in inverse function of erf?
I don't know if there is on the HP PRIME built-in inverse function
for error function erf.

I have a probability .8

And I want its iERF: —>.906193802438.
Find all posts by this user
Quote this message in a reply
11-18-2023, 02:09 PM
Post: #2
RE: HP Prime: built-in inverse function of erf?
> ierfc(x):=normald_icdf(x/2)/-sqrt(2)
> ierf(x):=ierfc(1-x)
> ierf(0.8)

0.906193802437
Find all posts by this user
Quote this message in a reply
12-14-2023, 10:44 PM
Post: #3
RE: HP Prime: built-in inverse function of erf?
As, in the HP PRIME, erf function admits as argument a complex number, it would be nice to have a built-in function inv_erf that would also admit as argument a complex number.
Find all posts by this user
Quote this message in a reply
12-15-2023, 12:47 PM
Post: #4
RE: HP Prime: built-in inverse function of erf?
Hi, Gil

I think erf inverse function is defined only for real x within ±1, otherwise we get infinite solutions.

> fsolve(erf(x)=2, x=i)            → 0.869417565326+1.34059481853*i
> fsolve(erf(x)=2, x=1+3i)      → 1.88472598633+2.28183639616*i
> fsolve(erf(x)=2, x=2+4i)      → 2.55833225411+2.9104037265*i
> fsolve(erf(x)=2, x=3+5i)      → 3.55858803599+3.85919595309*i

> fsolve(erf(x)=i, x=i)            → 0.731697153468*i
> fsolve(erf(x)=i, x=1+3i)      → 1.52285714842+2.04084734052*i
> fsolve(erf(x)=i, x=2+4i)      → 2.87881932565+3.2674470432*i
> fsolve(erf(x)=i, x=3+5i)      → 3.79852906513+4.13183559565*i

erf(z) = 2 --> erf(conj(z)) = conj(2) = 2-0i      → erfinv(2+0i) ≠ erfinv(2-0i)
erf(z) = i --> erf(-conj(z)) = -conj(i) = -0+i      → erfinv(0+i) ≠ erfinv(-0+i)

If we don't care about ±0, we doubled solutions for both erfinv(2) and erfinv(i)
Find all posts by this user
Quote this message in a reply
12-15-2023, 01:06 PM (This post was last modified: 12-15-2023 01:17 PM by Gil.)
Post: #5
RE: HP Prime: built-in inverse function of erf?
"I think erf inverse function is defined only for real x within ±1, otherwise we get infinite solutions."

Not quite so as I understood from Wikipedia, in article Error Function, Properties for Abs (z=a+ib) < 1 :

The inverse error function is usually defined with domain (−1,1), and it is restricted to this domain in many computer algebra systems. However, it can be extended to the disk |z| < 1 of the complex plane, using the Maclaurin series[9]

Then
InvERF
((.8,-.2))—>(.801172930851,-.341012371796)

And ERF
((.801172930851,-.341012371796))
—> (.799999999998,-.200000000002)

OrInvERF
((0.,.85)) —>
(0.,.649264402037

And ERF
((0.,.649264402037))
—> (0.,.849999999995)

It's what I developed for the HP50G in the directory program ERROR.9f for the error functions.
Find all posts by this user
Quote this message in a reply
12-15-2023, 02:33 PM
Post: #6
RE: HP Prime: built-in inverse function of erf?
(12-15-2023 01:06 PM)Gil Wrote:  Not quite so as I understood from Wikipedia, in article Error Function, Properties for Abs (z=a+ib) < 1 :

The inverse error function is usually defined with domain (−1,1), and it is restricted to this domain in many computer algebra systems. However, it can be extended to the disk |z| < 1 of the complex plane, using the Maclaurin series[9]

Then
InvERF
((.8,-.2))—>(.801172930851,-.341012371796)

Yes, we can define Maclaurin series solution as the "official" solution.
But, this is *not* properties of |z|<1. We still have infinite solutions.

> fsolve(erf(x)=0.8-0.2i, x=0.8-0.2i)  → 0.801172930852-0.341012371793*i
> fsolve(erf(x)=0.8-0.2i, x=1+3i)      → 1.53047592451+1.56695328912*i
> fsolve(erf(x)=0.8-0.2i, x=2+4i)      → 2.87803425787+3.00313505077*i
> fsolve(erf(x)=0.8-0.2i, x=3+5i)      → 3.7982932108+3.92873494629*i
> erf(Ans)                                        → 0.8-0.2i
Find all posts by this user
Quote this message in a reply
12-15-2023, 02:55 PM
Post: #7
RE: HP Prime: built-in inverse function of erf?
Yes, sorry, you are right again, Albert.

For the time being I will leave the special solution sol_z given with the Taylor's development, with apparently abs (sol_z) < 1.
Find all posts by this user
Quote this message in a reply
12-15-2023, 04:05 PM (This post was last modified: 12-15-2023 04:05 PM by Gil.)
Post: #8
RE: HP Prime: built-in inverse function of erf?
By the way, your solver seems to accept a complex unknown variable.

Is it the solver of the HP PRIME?

I use ONLY the HP50G EMU48.
Find all posts by this user
Quote this message in a reply
12-15-2023, 04:52 PM
Post: #9
RE: HP Prime: built-in inverse function of erf?
Examples were run on HP Prime emulator, 2.1.14181 (2018 10 16)
We don't really need solver for this. Plain newton's method work well.

> a := 0.8-0.2i
> Ans - (f:=erf(Ans)-a) / (2/sqrt(pi)*exp(-Ans^2))

0.817846322321-0.344502692613*i
0.800996592256-0.340824015653*i
0.801172956998-0.341012320073*i
0.801172930852-0.341012371793*i

Or, speed up with Halley's method

> a
> Ans - (f:=erf(Ans)-a) / (2/sqrt(pi)*exp(-Ans^2)+Ans*f)

0.800849610571-0.342519806279*i
0.801172932494-0.34101237069*i
0.801172930852-0.341012371793*i
Find all posts by this user
Quote this message in a reply
12-15-2023, 08:53 PM
Post: #10
RE: HP Prime: built-in inverse function of erf?
In view of the simplicity of the above regarding the error function, I will of course change my inverse subroutine for INVERSE_ERF in and use Albert Chan's suggestion with Newton's method.
Find all posts by this user
Quote this message in a reply
Post Reply 




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