(28/48/50) Lambert W Function
03-26-2023, 06:43 PM
Post: #12
 Albert Chan Senior Member Posts: 2,697 Joined: Jul 2018
RE: (28/48/50) Lambert W Function
(03-23-2023 02:56 AM)Albert Chan Wrote:  Here is my implementation of accurate x = W(a), both branches.

x * e^x = a
ln(x) + x = ln(a)      → f = x + ln(x/a) = 0

x - f/f' = x - (x + ln(x/a)) * x/(1+x) = (1 - ln(x/a)) * x/(1+x)

I just realized this is equivalent to solving for y = e^W(a)
With "same" guess, x*y=a, Newton convergence rate are identical.

x = (1 - ln(x/a)) * x/(1+x)
a/y = (1 + ln(y)) * 1/(1+y/a)

y = (y+a) / (1 + ln(y))

lua> expW(1e99, nil, true)
2.5e+098      4
5.492824331831047e+096      182.05570387623288
4.493790313227532e+096      222.52929716290643
4.493356750520384e+096      222.55076895111614
4.493356750426822e+096      222.55076895575016
4.493356750426821e+096      222.55076895575021

lua> W(1e99, nil, true)
182.05570387623249
222.52929716290646
222.55076895111617
222.55076895575016
222.5507689557502

Note: W guess used 1 Newton step. Both code converged the same way.
Because solving for y = e^W(a) is easier, W code is not recommended.

Bonus: with y, there are 2 ways to recover W(a) = a/y or log(y)
Depends on size of y (use log if y is big), we can make W(a) estimate better.

Example, above last 2 y's differ by 1 ULP, but the log's are the same.
(Not exactly. Here, y 1 ULP error translated to 0.007 ULP error in x)

lua> log(4.493356750426822e+096)
222.5507689557502
lua> log(4.493356750426821e+096)
222.5507689557502
 « Next Oldest | Next Newest »

 Messages In This Thread (28/48/50) Lambert W Function - John Keith - 03-20-2023, 08:43 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-20-2023, 10:51 PM RE: (28/48/50) Lambert W Function - John Keith - 03-21-2023, 01:53 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-21-2023, 05:15 PM RE: (28/48/50) Lambert W Function - John Keith - 03-22-2023, 07:30 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-23-2023, 12:16 AM RE: (28/48/50) Lambert W Function - John Keith - 03-23-2023, 05:53 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-23-2023, 07:30 PM RE: (28/48/50) Lambert W Function - Gerald H - 03-21-2023, 06:15 AM RE: (28/48/50) Lambert W Function - John Keith - 03-22-2023, 08:55 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-23-2023, 02:56 AM RE: (28/48/50) Lambert W Function - Albert Chan - 03-26-2023 06:43 PM RE: (28/48/50) Lambert W Function - Albert Chan - 04-02-2023, 11:12 PM RE: (28/48/50) Lambert W Function - John Keith - 04-03-2023, 07:24 PM RE: (28/48/50) Lambert W Function - Albert Chan - 04-03-2023, 08:47 PM RE: (28/48/50) Lambert W Function - John Keith - 03-27-2023, 04:45 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-27-2023, 08:57 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-31-2023, 04:06 PM RE: (28/48/50) Lambert W Function - John Keith - 03-31-2023, 06:15 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-31-2023, 07:10 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-27-2023, 11:30 PM RE: (28/48/50) Lambert W Function - Albert Chan - 03-31-2023, 10:07 PM RE: (28/48/50) Lambert W Function - Albert Chan - 04-01-2023, 12:44 PM RE: (28/48/50) Lambert W Function - John Keith - 04-01-2023, 05:36 PM RE: (28/48/50) Lambert W Function - John Keith - 04-01-2023, 05:59 PM RE: (28/48/50) Lambert W Function - Albert Chan - 04-03-2023, 10:47 PM RE: (28/48/50) Lambert W Function - Albert Chan - 04-04-2023, 01:03 AM RE: (28/48/50) Lambert W Function - John Keith - 04-04-2023, 07:09 PM RE: (28/48/50) Lambert W Function - Gil - 01-29-2024, 11:04 AM RE: (28/48/50) Lambert W Function - Albert Chan - 01-29-2024, 03:51 PM RE: (28/48/50) Lambert W Function - Gil - 01-29-2024, 02:47 PM RE: (28/48/50) Lambert W Function - Gil - 01-29-2024, 06:46 PM RE: (28/48/50) Lambert W Function - Albert Chan - 01-29-2024, 07:30 PM RE: (28/48/50) Lambert W Function - Gil - 01-29-2024, 09:50 PM RE: (28/48/50) Lambert W Function - Albert Chan - 01-30-2024, 12:18 AM RE: (28/48/50) Lambert W Function - Gil - 01-30-2024, 12:33 AM RE: (28/48/50) Lambert W Function - Albert Chan - 01-30-2024, 01:09 AM RE: (28/48/50) Lambert W Function - Gil - 01-30-2024, 12:04 PM RE: (28/48/50) Lambert W Function - Albert Chan - 01-30-2024, 01:47 PM RE: (28/48/50) Lambert W Function - Gil - 01-30-2024, 02:52 PM RE: (28/48/50) Lambert W Function - Albert Chan - 01-30-2024, 04:04 PM RE: (28/48/50) Lambert W Function - Gil - 01-31-2024, 07:10 PM

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