Average Error: 13.3 → 1.3
Time: 4.4s
Precision: binary64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le 3.03963131152792666 \cdot 10^{-12}:\\ \;\;\;\;x + {\left(wj \cdot wj\right)}^{\frac{1}{3}} \cdot \left(\left(wj + x \cdot -2\right) \cdot \sqrt[3]{wj}\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.3
Target12.6
Herbie1.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 < 3.03963131152792666e-12

    1. Initial program 12.9

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified12.9

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}}\]
    3. Taylor expanded around 0 0.7

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

      \[\leadsto \color{blue}{x + wj \cdot \left(wj - x \cdot 2\right)}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0.9

      \[\leadsto x + \color{blue}{\left(\left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \sqrt[3]{wj}\right)} \cdot \left(wj - x \cdot 2\right)\]
    7. Applied associate-*l*0.9

      \[\leadsto x + \color{blue}{\left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - x \cdot 2\right)\right)}\]
    8. Simplified0.9

      \[\leadsto x + \left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \color{blue}{\left(\left(wj + x \cdot -2\right) \cdot \sqrt[3]{wj}\right)}\]
    9. Using strategy rm
    10. Applied pow1/332.7

      \[\leadsto x + \left(\sqrt[3]{wj} \cdot \color{blue}{{wj}^{\frac{1}{3}}}\right) \cdot \left(\left(wj + x \cdot -2\right) \cdot \sqrt[3]{wj}\right)\]
    11. Applied pow1/332.7

      \[\leadsto x + \left(\color{blue}{{wj}^{\frac{1}{3}}} \cdot {wj}^{\frac{1}{3}}\right) \cdot \left(\left(wj + x \cdot -2\right) \cdot \sqrt[3]{wj}\right)\]
    12. Applied pow-prod-down1.2

      \[\leadsto x + \color{blue}{{\left(wj \cdot wj\right)}^{\frac{1}{3}}} \cdot \left(\left(wj + x \cdot -2\right) \cdot \sqrt[3]{wj}\right)\]

    if 3.03963131152792666e-12 < wj

    1. Initial program 25.0

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified4.1

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}}\]
    3. Using strategy rm
    4. Applied div-inv4.1

      \[\leadsto wj + \frac{\color{blue}{x \cdot \frac{1}{e^{wj}}} - wj}{wj + 1}\]
    5. Simplified4.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 3.03963131152792666 \cdot 10^{-12}:\\ \;\;\;\;x + {\left(wj \cdot wj\right)}^{\frac{1}{3}} \cdot \left(\left(wj + x \cdot -2\right) \cdot \sqrt[3]{wj}\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\ \end{array}\]

Reproduce

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

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

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