Overview
This is an implementation of the complex Lambert W function, which uses a Puiseux-based initial approximation and Newton–Raphson iteration adapted for the HP 42S environment.
Implementation of eW0(x)
For details on the algorithm and initial approximation used for
W0 and
eW0,
see Lambert W function and exponent of Lambert W function for C99.
Usage
eW - calculate eW0(x)
Rev.1.4 (Oct. 6 2020)
(c) Takayuki HOSODA, Albert Chan, Werner Huysegoms
Input X : x
Output Z : x
Y : e W 0 ( x )
X : e W 0 ( x )
Recurrence formula (Newton–Raphson method):
Initial approximation:
From the relation below,the Lambert W0 can be obtained from the relation:
Code
eW Rev.1.4 (Oct. 6 2020)00 { 53-Byte Prgm }
01▶LBL "eW"
02 0.3
03 -1
04 E↑X
05 RCL+ ST Z
06 STO× ST Y
07 STO+ ST X
08 LASTX
09 STO+ ST Z
10 ×
11 SQRT
12 +
13 X<>Y
14 +/-
15 X<>Y # Initial approximation (Puiseux-based)
16▶LBL 01
17 X=Y? # Convergence check
18 RTN
19 STO ST Y
20 LN
21 1
22 +
23 R↑
24 RCL+ ST Z
25 X<>Y
26 ÷ # Newton–Raphson method
27 -
28 STO× ST X
29 LASTX
30 STO+ ST Y
31 GTO 01
32 .END.
Download: 'eW-1.4.raw' for Free42 or DM42
Acknowledgments
Thanks to Werner of the hpmuseum forum for his advice on reducing the code by several bytes :-) Thanks to Albert Chan of the hpmuseum forum for extending the code to accept complex input :-)
References
- Lambert W function: "Lambert W-function", Wolfram MathWorld
- Numerical methods: "Newton's Method", Wolfram MathWorld
- Numerical methods: "Householder's Method", Wolfram MathWorld
- Background: "Why W?", Hayes, B. (2005). American Scientist. 93 (2): 104‐108.
- Lambert W overview: "The Lambert W function poster", ORCCA
- Convergence theory: "Convergence of Numerical Iteration in Solution of Equations", M. Urabe, J. Sci. Hiroshima Univ. Ser. A, 19 (3), 1956.
- Floating-point / numerical robustness: "Mathematics Written in Sand", W. Kahan, 1983.
- Complex arithmetic: "Improved Complex Division", Baudin & Smith
- General references: Wikipedia — Lambert W function
- General references: Wikipedia — Puiseux series
- Libraries: GNU Scientific Library
- Visualization: gnuplot pm3d demo
See Also
- Complex Lambert W (W0) — branch-stable C99 implementation
- Complex Lambert W (W0) and exp(W0) — HP Prime (CAS)
- Complex exp(W0) — HP 42S / Free42 (minimal Puiseux approximation)
- Forward voltage of a diode connected to Vin through a resistor (analysis)
- The "compdiv_robust" algorithm rewritten for C99
- Upgrading the memory of the HP 42S to 32KB
External Links
- About Convergence check and complex input → www.hpmuseum.org/forum/thread-15004-post-137100.html