Average Error: 13.6 → 0.5
Time: 1.2m
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;e^{\log \left(wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \le 3.362279932287092 \cdot 10^{-19}:\\
\;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \left(\frac{x}{\left(wj + 1\right) \cdot e^{wj}} - \frac{wj}{wj + 1}\right)\\
\end{array}\]
Target
| Original | 13.6 |
|---|
| Target | 13.0 |
|---|
| 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 (exp (log (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))) < 3.362279932287092e-19
Initial program 38.1
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.3
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
if 3.362279932287092e-19 < (exp (log (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))))
Initial program 1.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied sub-neg1.5
\[\leadsto \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)}\]
Applied simplify0.7
\[\leadsto wj + \color{blue}{\left(\frac{x}{\left(wj + 1\right) \cdot e^{wj}} - \frac{wj}{wj + 1}\right)}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)'
(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))))))