Average Error: 13.9 → 0.9
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}\;(\left(\frac{wj - \frac{x}{e^{wj}}}{e^{wj} - \left(wj \cdot wj\right) \cdot e^{wj}}\right) \cdot \left(\left(-1\right) + (\frac{1}{3} \cdot wj + \frac{1}{2})_* \cdot \left(wj \cdot wj\right)\right) + wj)_* \le 2.608735788713234 \cdot 10^{-17}:\\
\;\;\;\;(wj \cdot wj + x)_*\\
\mathbf{else}:\\
\;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}\right)\\
\end{array}\]
Target
| Original | 13.9 |
|---|
| Target | 13.3 |
|---|
| Herbie | 0.9 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (fma (/ (- wj (/ x (exp wj))) (- (exp wj) (* (* wj wj) (exp wj)))) (+ (- 1) (* (fma 1/3 wj 1/2) (* wj wj))) wj) < 2.608735788713234e-17
Initial program 18.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 19.3
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
Applied simplify1.0
\[\leadsto \color{blue}{(wj \cdot wj + x)_*}\]
if 2.608735788713234e-17 < (fma (/ (- wj (/ x (exp wj))) (- (exp wj) (* (* wj wj) (exp wj)))) (+ (- 1) (* (fma 1/3 wj 1/2) (* wj wj))) wj)
Initial program 2.8
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub2.8
\[\leadsto wj - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\]
Applied simplify0.6
\[\leadsto wj - \left(\color{blue}{\frac{wj}{wj + 1}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Applied simplify0.6
\[\leadsto wj - \left(\frac{wj}{wj + 1} - \color{blue}{\frac{x}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}}\right)\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' +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))))))