Exponent of the principal branch of the complex Lambert W Function (W0)

for HP 42S

Revised 2026-03-25
2020-08-20
Takayuki HOSODA

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):

   y_\mathrm{n+1} \leftarrow \frac{y_\mathrm{n} + x}{\ln(y_\mathrm{n}) + 1}

Initial approximation:

   y_0 = \frac{1}{\mathrm{e}} + \sqrt{\frac{2}{\mathrm{e}} \, \bigg(\frac{1}{\mathrm{e}} + x\bigg)}  + 0.3 \,\bigg(\frac{1}{\mathrm{e}} + x\bigg)

From the relation below,the Lambert W0 can be obtained from the relation:

relation between LambertW and exp(LambertW)
exponent of W0
3D plot of the eW0(x) around the branch point of -1/e.

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

  1. Lambert W function: "Lambert W-function", Wolfram MathWorld
  2. Numerical methods: "Newton's Method", Wolfram MathWorld
  3. Numerical methods: "Householder's Method", Wolfram MathWorld
  4. Background: "Why W?", Hayes, B. (2005). American Scientist. 93 (2): 104‐108.
  5. Lambert W overview: "The Lambert W function poster", ORCCA
  6. Convergence theory: "Convergence of Numerical Iteration in Solution of Equations", M. Urabe, J. Sci. Hiroshima Univ. Ser. A, 19 (3), 1956.
  7. Floating-point / numerical robustness: "Mathematics Written in Sand", W. Kahan, 1983.
  8. Complex arithmetic: "Improved Complex Division", Baudin & Smith
  9. General references: Wikipedia — Lambert W function
  10. General references: Wikipedia — Puiseux series
  11. Libraries: GNU Scientific Library
  12. Visualization: gnuplot pm3d demo

See Also

External Links