Average Error: 14.2 → 0.3
Time: 1.4m
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 5.3850977791279605 \cdot 10^{-09}:\\ \;\;\;\;\frac{x}{e^{wj} + e^{wj} \cdot wj} + (\left(wj \cdot wj\right) \cdot \left(wj \cdot wj - wj\right) + \left(wj \cdot wj\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{e^{wj} + e^{wj} \cdot wj} + \left(wj - \frac{wj}{1 + wj}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original14.2
Target13.7
Herbie0.3
\[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 < 5.3850977791279605e-09

    1. Initial program 14.0

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

      \[\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-7.2

      \[\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 \cdot wj\right) \cdot \left(wj \cdot wj - wj\right) + \left(wj \cdot wj\right))_*} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]

    if 5.3850977791279605e-09 < wj

    1. Initial program 24.6

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

      \[\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-24.6

      \[\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. Using strategy rm
    6. Applied distribute-rgt1-in24.7

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

      \[\leadsto \left(wj - \color{blue}{\frac{wj}{wj + 1} \cdot \frac{e^{wj}}{e^{wj}}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
    8. Simplified3.6

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

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

Reproduce

herbie shell --seed 2019094 +o rules:numerics
(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))))))