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

Error

Bits error versus wj

Bits error versus x

Target

Original14.3
Target13.8
Herbie1.5
\[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 < 6.35250989482101e-09

    1. Initial program 14.1

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

      \[\leadsto \frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + wj\]
    3. Taylor expanded around 0 0.8

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

      \[\leadsto \color{blue}{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*}\]

    if 6.35250989482101e-09 < wj

    1. Initial program 23.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Initial simplification23.5

      \[\leadsto \frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + wj\]
    3. Taylor expanded around inf 23.5

      \[\leadsto \frac{\color{blue}{x - e^{wj} \cdot wj}}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + wj\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt23.7

      \[\leadsto \frac{x - e^{wj} \cdot wj}{\color{blue}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} \cdot \sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}} + wj\]
    6. Applied associate-/r*23.7

      \[\leadsto \color{blue}{\frac{\frac{x - e^{wj} \cdot wj}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}} + wj\]
    7. Using strategy rm
    8. Applied *-un-lft-identity23.7

      \[\leadsto \frac{\frac{x - e^{wj} \cdot wj}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}}{\sqrt{\color{blue}{1 \cdot (\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}} + wj\]
    9. Applied sqrt-prod23.7

      \[\leadsto \frac{\frac{x - e^{wj} \cdot wj}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}}{\color{blue}{\sqrt{1} \cdot \sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}} + wj\]
    10. Applied div-inv23.7

      \[\leadsto \frac{\color{blue}{\left(x - e^{wj} \cdot wj\right) \cdot \frac{1}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}}}{\sqrt{1} \cdot \sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}} + wj\]
    11. Applied times-frac23.7

      \[\leadsto \color{blue}{\frac{x - e^{wj} \cdot wj}{\sqrt{1}} \cdot \frac{\frac{1}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}} + wj\]
    12. Applied fma-def23.6

      \[\leadsto \color{blue}{(\left(\frac{x - e^{wj} \cdot wj}{\sqrt{1}}\right) \cdot \left(\frac{\frac{1}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}}{\sqrt{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}\right) + wj)_*}\]
    13. Simplified23.6

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

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

Runtime

Time bar (total: 1.5m)Debug logProfile

herbie shell --seed 2018273 +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))))))