Average Error: 13.7 → 0.9
Time: 36.8s
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}\right) \le 6.466522119638622 \cdot 10^{-19}:\\
\;\;\;\;(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.7 |
|---|
| Target | 13.0 |
|---|
| 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 (- wj (- (/ wj (+ wj 1)) (/ x (fma (exp wj) wj (exp wj))))) < 6.466522119638622e-19
Initial program 17.9
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 18.7
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
Applied simplify1.0
\[\leadsto \color{blue}{(wj \cdot wj + x)_*}\]
if 6.466522119638622e-19 < (- wj (- (/ wj (+ wj 1)) (/ x (fma (exp wj) wj (exp wj)))))
Initial program 3.1
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub3.1
\[\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 '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)' +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))))))