Average Error: 13.7 → 1.6
Time: 45.7s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;wj \le 4.520570026650869 \cdot 10^{-18}:\\
\;\;\;\;(wj \cdot wj + x)_*\\
\mathbf{if}\;wj \le 692.3975420953346:\\
\;\;\;\;wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\
\mathbf{else}:\\
\;\;\;\;wj - \left(\left(1 + \frac{x}{e^{wj} \cdot {wj}^{2}}\right) - \frac{x}{e^{wj} \cdot wj}\right)\\
\end{array}\]
Target
| Original | 13.7 |
|---|
| Target | 13.1 |
|---|
| Herbie | 1.6 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 3 regimes
if wj < 4.520570026650869e-18
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 14.1
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
Applied simplify1.0
\[\leadsto \color{blue}{(wj \cdot wj + x)_*}\]
if 4.520570026650869e-18 < wj < 692.3975420953346
Initial program 13.1
\[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))_*}}\]
if 692.3975420953346 < wj
Initial program 62.0
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify62.0
\[\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 inf 15.1
\[\leadsto wj - \color{blue}{\left(\left(1 + \frac{x}{e^{wj} \cdot {wj}^{2}}\right) - \frac{x}{e^{wj} \cdot wj}\right)}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed 2018198 +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))))))