Average Error: 13.6 → 1.1
Time: 1.2m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;e^{\log \left(wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\right)} \le 1.6447664544199101 \cdot 10^{-18}:\\
\;\;\;\;(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*\\
\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 | 13.6 |
|---|
| Target | 13.1 |
|---|
| Herbie | 1.1 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (exp (log (- wj (/ (fma (exp wj) wj (- x)) (fma wj (exp wj) (exp wj)))))) < 1.6447664544199101e-18
Initial program 38.0
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify38.0
\[\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 0.3
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
Applied simplify0.3
\[\leadsto \color{blue}{(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*}\]
if 1.6447664544199101e-18 < (exp (log (- wj (/ (fma (exp wj) wj (- x)) (fma wj (exp wj) (exp wj))))))
Initial program 1.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify1.5
\[\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.5
\[\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 '#(1071948828 1180510430 2986424009 997076509 406109801 420189285)' +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))))))