Average Error: 13.9 → 0.3
Time: 29.7s
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;wj \le -7.065298332585179 \cdot 10^{-09}:\\
\;\;\;\;wj - e^{-wj} \cdot \frac{wj \cdot e^{wj} - x}{1 + wj}\\
\mathbf{if}\;wj \le 9.200369675987498 \cdot 10^{-09}:\\
\;\;\;\;\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.3 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 3 regimes
if wj < -7.065298332585179e-09
Initial program 5.2
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied *-un-lft-identity5.2
\[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{1 \cdot e^{wj}} + wj \cdot e^{wj}}\]
Applied distribute-rgt-out5.2
\[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{e^{wj} \cdot \left(1 + wj\right)}}\]
Applied *-un-lft-identity5.2
\[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{e^{wj} \cdot \left(1 + wj\right)}\]
Applied times-frac5.3
\[\leadsto wj - \color{blue}{\frac{1}{e^{wj}} \cdot \frac{wj \cdot e^{wj} - x}{1 + wj}}\]
Applied simplify5.2
\[\leadsto wj - \color{blue}{e^{-wj}} \cdot \frac{wj \cdot e^{wj} - x}{1 + wj}\]
if -7.065298332585179e-09 < wj < 9.200369675987498e-09
Initial program 13.7
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 0.2
\[\leadsto \color{blue}{\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)}\]
if 9.200369675987498e-09 < wj
Initial program 26.3
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub26.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-26.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 simplify2.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)' +o rules:numerics
(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))))))