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}\]
Target
| Original | 14.1 |
|---|
| Target | 13.5 |
|---|
| Herbie | 1.2 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
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
Initial program 37.9
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
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))_*}}\]
Taylor expanded around 0 37.9
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
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))))))
Initial program 1.6
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
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))_*}}\]
- Using strategy
rm 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))_*}}\]
- Recombined 2 regimes into one program.
Runtime
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))))))