Average Error: 13.6 → 1.6
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}\;\left(\sqrt[3]{{wj}^{2} + x} \cdot \sqrt[3]{{wj}^{2} + x}\right) \cdot \left(\sqrt[3]{\sqrt{{wj}^{2} + x}} \cdot \sqrt[3]{\sqrt{{wj}^{2} + x}}\right) - 2 \cdot \left(wj \cdot x\right) \le 6.588975398815594 \cdot 10^{-26}:\\
\;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{if}\;\left(\sqrt[3]{{wj}^{2} + x} \cdot \sqrt[3]{{wj}^{2} + x}\right) \cdot \left(\sqrt[3]{\sqrt{{wj}^{2} + x}} \cdot \sqrt[3]{\sqrt{{wj}^{2} + x}}\right) - 2 \cdot \left(wj \cdot x\right) \le 1.2942413642409161 \cdot 10^{+130}:\\
\;\;\;\;\frac{wj \cdot wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}{wj + \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}\\
\mathbf{else}:\\
\;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\
\end{array}\]
Target
| Original | 13.6 |
|---|
| Target | 13.0 |
|---|
| Herbie | 1.6 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (* (cbrt (sqrt (+ (pow wj 2) x))) (cbrt (sqrt (+ (pow wj 2) x))))) (* 2 (* wj x))) < 6.588975398815594e-26 or 1.2942413642409161e+130 < (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (* (cbrt (sqrt (+ (pow wj 2) x))) (cbrt (sqrt (+ (pow wj 2) x))))) (* 2 (* wj x)))
Initial program 15.2
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 1.1
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
if 6.588975398815594e-26 < (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (* (cbrt (sqrt (+ (pow wj 2) x))) (cbrt (sqrt (+ (pow wj 2) x))))) (* 2 (* wj x))) < 1.2942413642409161e+130
Initial program 4.7
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied flip--4.8
\[\leadsto \color{blue}{\frac{wj \cdot wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}{wj + \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071119240 1686926585 3481876196 78132896 2080707795 3185793749)'
(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))))))