Average Error: 13.7 → 2.1
Time: 19.5s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.3367825252779824 \cdot 10^{+145}:\\ \;\;\;\;\frac{1}{\frac{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}} + wj\\ \mathbf{else}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.7
Target13.1
Herbie2.1
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if x < -3.3367825252779824e+145

    1. Initial program 0.4

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

      \[\leadsto \frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + wj\]
    3. Using strategy rm
    4. Applied clear-num0.6

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

    if -3.3367825252779824e+145 < x

    1. Initial program 15.6

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

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

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

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

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

Runtime

Time bar (total: 19.5s)Debug logProfile

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