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

Error

Bits error versus wj

Bits error versus x

Target

Original13.6
Target13.1
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 (fma (* x 2) (- wj) (fma wj wj x)) < 8.663567874309644e-19

    1. Initial program 18.2

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

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

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

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

    if 8.663567874309644e-19 < (fma (* x 2) (- wj) (fma wj wj x))

    1. Initial program 2.2

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

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

      \[\leadsto wj - \color{blue}{\frac{1}{\frac{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}}}\]
    5. Using strategy rm
    6. Applied div-inv2.3

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

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

Runtime

Time bar (total: 29.8s)Debug logProfile

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