Average Error: 13.6 → 1.0
Time: 1.4m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_* \le 1.0428080602965551 \cdot 10^{-26}:\\
\;\;\;\;(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{1}{wj + 1} \cdot \left(wj - \frac{x}{e^{wj}}\right)\\
\end{array}\]
Target
| Original | 13.6 |
|---|
| Target | 13.0 |
|---|
| Herbie | 1.0 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (fma (* x 2) (- wj) (fma wj wj x)) < 1.0428080602965551e-26
Initial program 18.2
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.8
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
Applied simplify0.8
\[\leadsto \color{blue}{(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*}\]
if 1.0428080602965551e-26 < (fma (* x 2) (- wj) (fma wj wj x))
Initial program 2.8
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied distribute-rgt1-in2.9
\[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
Applied *-un-lft-identity2.9
\[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
Applied times-frac2.8
\[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
Applied simplify1.5
\[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj - \frac{x}{e^{wj}}\right)}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071119240 1686926585 3481876196 78132896 2080707795 3185793749)' +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))))))