Average Error: 13.5 → 0.4
Time: 19.0s
Precision: 64
Internal Precision: 128
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le 1.8976396421588022 \cdot 10^{-08}:\\ \;\;\;\;\frac{x}{wj \cdot e^{wj} + e^{wj}} + \left({wj}^{4} - wj \cdot \left(wj \cdot wj - wj\right)\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{1}{1 + wj} \cdot \left(wj - \frac{x}{e^{wj}}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.5
Target13.0
Herbie0.4
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if wj < 1.8976396421588022e-08

    1. Initial program 13.3

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied div-sub13.3

      \[\leadsto wj - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\]
    4. Applied associate--r-6.7

      \[\leadsto \color{blue}{\left(wj - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}}\]
    5. Taylor expanded around 0 0.3

      \[\leadsto \color{blue}{\left(\left({wj}^{2} + {wj}^{4}\right) - {wj}^{3}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
    6. Simplified0.3

      \[\leadsto \color{blue}{\left({wj}^{4} - \left(wj \cdot wj - wj\right) \cdot wj\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]

    if 1.8976396421588022e-08 < wj

    1. Initial program 22.8

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied distribute-rgt1-in22.9

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity22.9

      \[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
    5. Applied times-frac22.8

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified2.4

      \[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj - \frac{x}{e^{wj}}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 1.8976396421588022 \cdot 10^{-08}:\\ \;\;\;\;\frac{x}{wj \cdot e^{wj} + e^{wj}} + \left({wj}^{4} - wj \cdot \left(wj \cdot wj - wj\right)\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{1}{1 + wj} \cdot \left(wj - \frac{x}{e^{wj}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019050 
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"

  :herbie-target
  (- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))