Average Error: 13.9 → 0.5
Time: 1.1m
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;wj \cdot wj \le 1.4952327733249957 \cdot 10^{-23}:\\
\;\;\;\;x + wj \cdot wj\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{1}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}\\
\end{array}\]
Target
| Original | 13.9 |
|---|
| Target | 13.3 |
|---|
| Herbie | 0.5 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (* wj wj) < 1.4952327733249957e-23
Initial program 13.7
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 13.7
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
Applied simplify0.1
\[\leadsto \color{blue}{x + wj \cdot wj}\]
if 1.4952327733249957e-23 < (* wj wj)
Initial program 16.6
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied clear-num16.7
\[\leadsto wj - \color{blue}{\frac{1}{\frac{e^{wj} + wj \cdot e^{wj}}{wj \cdot e^{wj} - x}}}\]
Applied simplify7.5
\[\leadsto wj - \frac{1}{\color{blue}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070609872 3456127585 2380521889 2328837196 1765472538 734540918)'
(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))))))