Average Error: 13.4 → 0.5
Time: 1.0m
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 -1.4263080623703168 \cdot 10^{-15}:\\
\;\;\;\;wj - \frac{1}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}\\
\mathbf{if}\;wj \le 7.883286521787764 \cdot 10^{-12}:\\
\;\;\;\;x + wj \cdot wj\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{1}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}\\
\end{array}\]
Target
| Original | 13.4 |
|---|
| Target | 12.8 |
|---|
| 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 < -1.4263080623703168e-15 or 7.883286521787764e-12 < 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.2
\[\leadsto wj - \frac{1}{\color{blue}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}}\]
if -1.4263080623703168e-15 < wj < 7.883286521787764e-12
Initial program 13.2
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 13.2
\[\leadsto wj - \color{blue}{\left(wj - \left({wj}^{2} + x\right)\right)}\]
Applied simplify0.1
\[\leadsto \color{blue}{x + wj \cdot wj}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071821486 549052472 3784827256 1559736200 3548510075 881134285)'
(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))))))