Average Error: 13.9 → 0.4
Time: 35.5s
Precision: 64
Internal Precision: 896
\[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 \log \left(e^{\sqrt[3]{{wj}^{2} + x}}\right) - 2 \cdot \left(wj \cdot x\right) \le -126087061.82620384:\\
\;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{\frac{x}{1 + wj}}{e^{wj}}\right)\\
\mathbf{if}\;\left(\sqrt[3]{{wj}^{2} + x} \cdot \sqrt[3]{{wj}^{2} + x}\right) \cdot \log \left(e^{\sqrt[3]{{wj}^{2} + x}}\right) - 2 \cdot \left(wj \cdot x\right) \le 7.230032173577354 \cdot 10^{-16}:\\
\;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\
\end{array}\]
Target
| Original | 13.9 |
|---|
| Target | 13.2 |
|---|
| Herbie | 0.4 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 3 regimes
if (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (log (exp (cbrt (+ (pow wj 2) x))))) (* 2 (* wj x))) < -126087061.82620384
Initial program 0.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub0.5
\[\leadsto wj - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\]
Applied simplify0.0
\[\leadsto wj - \left(\color{blue}{\frac{wj}{wj + 1}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Applied simplify0.0
\[\leadsto wj - \left(\frac{wj}{wj + 1} - \color{blue}{\frac{\frac{x}{1 + wj}}{e^{wj}}}\right)\]
if -126087061.82620384 < (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (log (exp (cbrt (+ (pow wj 2) x))))) (* 2 (* wj x))) < 7.230032173577354e-16
Initial program 27.5
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.5
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
if 7.230032173577354e-16 < (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (log (exp (cbrt (+ (pow wj 2) x))))) (* 2 (* wj x)))
Initial program 2.3
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub2.3
\[\leadsto wj - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\]
Applied associate--r-2.3
\[\leadsto \color{blue}{\left(wj - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}}\]
Applied simplify0.5
\[\leadsto \color{blue}{\left(wj - \frac{wj}{1 + wj}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
- Recombined 3 regimes into one program.
Runtime
herbie shell --seed '#(1064397287 3527694221 3797617954 1138343853 2854031332 1153838279)'
(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))))))