Average Error: 13.8 → 0.7
Time: 1.0m
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\left(\left(\sqrt[3]{{\left(\frac{1}{wj}\right)}^{-2}} \cdot \sqrt[3]{{\left(\frac{1}{wj}\right)}^{-2}}\right) \cdot \log \left(e^{\sqrt[3]{{\left(\frac{1}{wj}\right)}^{-2}}}\right) + x\right) - 2 \cdot \left(wj \cdot x\right) \le 4.478911691085116 \cdot 10^{-11}:\\
\;\;\;\;\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.8 |
|---|
| Target | 13.1 |
|---|
| Herbie | 0.7 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (- (+ (* (* (cbrt (pow (/ 1 wj) -2)) (cbrt (pow (/ 1 wj) -2))) (log (exp (cbrt (pow (/ 1 wj) -2))))) x) (* 2 (* wj x))) < 4.478911691085116e-11
Initial program 18.1
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.9
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
if 4.478911691085116e-11 < (- (+ (* (* (cbrt (pow (/ 1 wj) -2)) (cbrt (pow (/ 1 wj) -2))) (log (exp (cbrt (pow (/ 1 wj) -2))))) x) (* 2 (* wj x)))
Initial program 2.4
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub2.4
\[\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.4
\[\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.2
\[\leadsto \color{blue}{\left(wj - \frac{wj}{1 + wj}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070578969 3140398606 632207097 462683394 1189254563 964980650)'
(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))))))