Average Error: 14.1 → 1.2
Time: 1.3m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;\sqrt{wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}} \cdot \sqrt{wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}} \le 6.200946742486267 \cdot 10^{-17}:\\ \;\;\;\;(wj \cdot wj + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - (\left(e^{wj}\right) \cdot wj + \left(-x\right))_* \cdot \frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original14.1
Target13.5
Herbie1.2
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if (* (sqrt (- wj (/ (fma (exp wj) wj (- x)) (fma wj (exp wj) (exp wj))))) (sqrt (- wj (/ (fma (exp wj) wj (- x)) (fma wj (exp wj) (exp wj)))))) < 6.200946742486267e-17

    1. Initial program 37.9

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

      \[\leadsto \color{blue}{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 37.9

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

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

    if 6.200946742486267e-17 < (* (sqrt (- wj (/ (fma (exp wj) wj (- x)) (fma wj (exp wj) (exp wj))))) (sqrt (- wj (/ (fma (exp wj) wj (- x)) (fma wj (exp wj) (exp wj))))))

    1. Initial program 1.6

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

      \[\leadsto \color{blue}{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 div-inv1.6

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

Runtime

Time bar (total: 1.3m)Debug logProfile

herbie shell --seed '#(1071725047 233389029 2036512464 3988615230 2972226563 1111574017)' +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))))))