Average Error: 13.3 → 0.6
Time: 1.2m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;wj - \left(\frac{\sqrt[3]{e^{wj} \cdot wj - x}}{\sqrt{\left(wj + 1\right) \cdot e^{wj}}} \cdot \sqrt[3]{e^{wj} \cdot wj - x}\right) \cdot \frac{\sqrt[3]{e^{wj} \cdot wj - x}}{\sqrt{\left(wj + 1\right) \cdot e^{wj}}} \le 7.29930593245523 \cdot 10^{-15}:\\
\;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;wj - \frac{1}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}\\
\end{array}\]
Try it out
Enter valid numbers for all inputs
Target
| Original | 13.3 |
|---|
| Target | 12.7 |
|---|
| Herbie | 0.6 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (- wj (* (* (/ (cbrt (- (* (exp wj) wj) x)) (sqrt (* (+ wj 1) (exp wj)))) (cbrt (- (* (exp wj) wj) x))) (/ (cbrt (- (* (exp wj) wj) x)) (sqrt (* (+ wj 1) (exp wj)))))) < 7.29930593245523e-15
Initial program 17.7
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.6
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
if 7.29930593245523e-15 < (- wj (* (* (/ (cbrt (- (* (exp wj) wj) x)) (sqrt (* (+ wj 1) (exp wj)))) (cbrt (- (* (exp wj) wj) x))) (/ (cbrt (- (* (exp wj) wj) x)) (sqrt (* (+ wj 1) (exp wj))))))
Initial program 2.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied clear-num2.6
\[\leadsto wj - \color{blue}{\frac{1}{\frac{e^{wj} + wj \cdot e^{wj}}{wj \cdot e^{wj} - x}}}\]
Applied simplify0.6
\[\leadsto wj - \frac{1}{\color{blue}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed 2018199
(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))))))