Average Error: 14.1 → 0.2
Time: 59.4s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;wj - \frac{{\left(wj \cdot e^{wj}\right)}^{3} - {x}^{3}}{\left(e^{wj} + wj \cdot e^{wj}\right) \cdot \left(\left(wj \cdot e^{wj}\right) \cdot \left(wj \cdot e^{wj}\right) + \left(x \cdot x + \left(wj \cdot e^{wj}\right) \cdot x\right)\right)} \le 1.121841522316379 \cdot 10^{-13}:\\
\;\;\;\;\frac{\frac{x}{e^{wj}}}{1 + wj} + \left({wj}^{4} + \left(1 - wj\right) \cdot \left(wj \cdot wj\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\
\end{array}\]
Target
| Original | 14.1 |
|---|
| Target | 13.5 |
|---|
| Herbie | 0.2 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (- wj (/ (- (pow (* wj (exp wj)) 3) (pow x 3)) (* (+ (exp wj) (* wj (exp wj))) (+ (* (* wj (exp wj)) (* wj (exp wj))) (+ (* x x) (* (* wj (exp wj)) x)))))) < 1.121841522316379e-13
Initial program 20.9
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub20.9
\[\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-14.2
\[\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 simplify14.2
\[\leadsto \color{blue}{\left(wj - \frac{wj}{1 + wj}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.3
\[\leadsto \color{blue}{\left(\left({wj}^{4} + {wj}^{2}\right) - {wj}^{3}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify0.3
\[\leadsto \color{blue}{\frac{\frac{x}{e^{wj}}}{1 + wj} + \left({wj}^{4} + \left(1 - wj\right) \cdot \left(wj \cdot wj\right)\right)}\]
if 1.121841522316379e-13 < (- wj (/ (- (pow (* wj (exp wj)) 3) (pow x 3)) (* (+ (exp wj) (* wj (exp wj))) (+ (* (* wj (exp wj)) (* wj (exp wj))) (+ (* x x) (* (* wj (exp wj)) x))))))
Initial program 7.3
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub7.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-1.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.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 '#(1071725047 233389029 2036512464 3988615230 2972226563 1111574017)'
(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))))))