Average Error: 13.3 → 0.9
Time: 4.0m
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{1}{wj} + wj\right) - (\left(\frac{1}{wj}\right) \cdot \left(\frac{1}{wj}\right) + 1)_* \le -125981247538304.98:\\
\;\;\;\;(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\
\end{array}\]
Target
| Original | 13.3 |
|---|
| Target | 12.7 |
|---|
| 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 (- (+ (/ 1 wj) wj) (fma (/ 1 wj) (/ 1 wj) 1)) < -125981247538304.98
Initial program 13.2
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify13.2
\[\leadsto \color{blue}{wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
Taylor expanded around 0 0.2
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
Applied simplify0.2
\[\leadsto \color{blue}{(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*}\]
if -125981247538304.98 < (- (+ (/ 1 wj) wj) (fma (/ 1 wj) (/ 1 wj) 1))
Initial program 16.2
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify16.2
\[\leadsto \color{blue}{wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed 2018167 +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))))))