Post Reply 
lambertw, all branches
01-22-2024, 01:34 AM
Post: #33
RE: lambertw, all branches
Hi, Gil

If you want to implement W to HP50g, ignore lua I.W code, and use only Python code (post 16)
My guess is HP50g does not support signed zero anyway.

Python code, including blank lines, is only 34 lines long.
It is all in the code, but this is the gist of it ...

If |k| > 1, just use imaginery part as guess. There is no Newton's over-shoot issue.
If |k| = 1, and k and im(a) has same sign, again, use T as guess

A, T = abs(a), mpc(0,2*k*pi+arg(a))
x = T            # W rough guess

Now the hard part, we need good guess to avoid Newton over-shoot crossed discontinuity.

If |a+1/e| < 0.25, use lyuka's formula and y = e^W iteration formula, return a/y = x
This take cared of singularity at x = -1/e, W0(-1/e) = W-1(-1/e) = -1

If |k| = 1, guess x = LN(-a) + (0 if A<.5 else T/2)

We need customized LN() because we lost signed zero information.
If a ≈ -1, LN(-a) is very tiny, possibly 0, thus the need for adding T/2

If k = 0, guess x = log1p(a*s) / s, where s = (A+100)/(A+50) = (2 if A=0, 1 if A=∞)
We have good W0 asymptote estimate when A=0, and A=∞

repeat until loop does Newton's iteration. x = x - f/f'
f is designed to cause catastrophic cancellation, making x possibly not accurate.

Final touch with g = x*e^x - a, g' = (x+1)*e^x
--> h = g/g' = (x - a*e^-x) / (x+1)

Because of the exponential, h may not be finite.
If h is finite, we update for better x; if not, last x is the best we've got.

Quote:You write
Wk(+0) = 0 if k==0 else -∞ + (2*k-sign(k))*pi*I
OK

You write further
Wk(a → 0) = a if k==0 else lnk(a) - sign(k)*pi*I

Wk(+0) is referring Python code, which does not support signed zero.

lnk(a) = ln(a) + 2*k*pi*I = ln(|a|) + (arg(a) + 2*k*pi)*I

lnk(0) = ln(|0|) + (arg(0) + 2*k*pi)*I = -∞ + 2*k*pi*I
lnk(0) - sign(k)*pi*I = -∞ + (2*k-sign(k))*pi*I

With system that support signed zero, 0 may mean (±0 + ±0*I)
This is why lnk(a) is left unevaluated. arg(0) may have multiple values.

lua> z = 0
lua> I(z,z):arg(), I(z,-z):arg()
0                                  -0
lua> I(-z,z):arg(), I(-z,-z):arg()
3.141592653589793      -3.141592653589793
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
lambertw, all branches - Albert Chan - 04-07-2023, 01:24 PM
RE: lambertw, all branches - Albert Chan - 04-07-2023, 02:47 PM
RE: lambertw, all branches - Albert Chan - 04-19-2023, 01:30 AM
RE: lambertw, all branches - pier4r - 04-07-2023, 06:04 PM
RE: lambertw, all branches - Albert Chan - 04-07-2023, 07:54 PM
RE: lambertw, all branches - Albert Chan - 04-08-2023, 03:21 PM
RE: lambertw, all branches - Albert Chan - 04-08-2023, 05:54 PM
RE: lambertw, all branches - Albert Chan - 04-07-2023, 08:40 PM
RE: lambertw, all branches - Albert Chan - 04-09-2023, 03:59 AM
RE: lambertw, all branches - Albert Chan - 04-09-2023, 04:36 PM
RE: lambertw, all branches - Albert Chan - 04-10-2023, 04:44 PM
RE: lambertw, all branches - Albert Chan - 04-10-2023, 06:47 PM
RE: lambertw, all branches - Albert Chan - 04-13-2023, 03:03 PM
RE: lambertw, all branches - floppy - 04-13-2023, 04:14 PM
RE: lambertw, all branches - Albert Chan - 04-23-2023, 02:49 PM
RE: lambertw, all branches - Albert Chan - 04-23-2023, 04:40 PM
RE: lambertw, all branches - Albert Chan - 01-19-2024, 04:14 PM
RE: lambertw, all branches - Albert Chan - 01-20-2024, 04:48 PM
RE: lambertw, all branches - Gil - 01-20-2024, 10:52 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 01:14 AM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 01:54 AM
RE: lambertw, all branches - Gil - 01-21-2024, 01:53 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 04:19 PM
RE: lambertw, all branches - Gil - 01-21-2024, 04:35 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 06:03 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 07:01 PM
RE: lambertw, all branches - Gil - 01-21-2024, 07:30 PM
RE: lambertw, all branches - Gil - 01-21-2024, 08:39 PM
RE: lambertw, all branches - Albert Chan - 01-21-2024, 10:06 PM
RE: lambertw, all branches - Gil - 01-21-2024, 09:51 PM
RE: lambertw, all branches - Gil - 01-21-2024, 10:56 PM
RE: lambertw, all branches - Albert Chan - 01-22-2024 01:34 AM
RE: lambertw, all branches - Gil - 01-21-2024, 11:15 PM
RE: lambertw, all branches - Gil - 01-22-2024, 06:09 PM
RE: lambertw, all branches - Albert Chan - 01-22-2024, 07:29 PM
RE: lambertw, all branches - Gil - 01-22-2024, 11:33 PM
RE: lambertw, all branches - Albert Chan - 01-23-2024, 02:32 AM
RE: lambertw, all branches - Gil - 01-23-2024, 02:35 PM
RE: lambertw, all branches - Albert Chan - 01-23-2024, 03:54 PM
RE: lambertw, all branches - Gil - 01-23-2024, 04:57 PM
RE: lambertw, all branches - Albert Chan - 01-23-2024, 06:17 PM
RE: lambertw, all branches - Gil - 01-23-2024, 06:44 PM
RE: lambertw, all branches - Gil - 01-23-2024, 11:00 PM
RE: lambertw, all branches - Gil - 01-24-2024, 03:18 PM
RE: lambertw, all branches - Albert Chan - 01-24-2024, 08:53 PM
RE: lambertw, all branches - Gil - 01-25-2024, 12:37 AM
RE: lambertw, all branches - Gil - 01-25-2024, 01:10 AM
RE: lambertw, all branches - Gil - 01-25-2024, 03:04 AM
RE: lambertw, all branches - Albert Chan - 01-25-2024, 07:02 AM
RE: lambertw, all branches - Gil - 01-25-2024, 10:09 AM
RE: lambertw, all branches - Albert Chan - 01-25-2024, 04:13 PM
RE: lambertw, all branches - Gil - 01-25-2024, 05:14 PM
RE: lambertw, all branches - Albert Chan - 01-25-2024, 05:57 PM
RE: lambertw, all branches - Gil - 01-25-2024, 06:19 PM
RE: lambertw, all branches - Albert Chan - 01-28-2024, 11:18 PM
RE: lambertw, all branches - Albert Chan - 02-01-2024, 02:17 AM
RE: lambertw, all branches - Albert Chan - 02-01-2024, 04:16 PM
RE: lambertw, all branches - Albert Chan - 02-02-2024, 11:49 AM



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