Average Error: 14.0 → 0.1
Time: 1.1m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;e^{\log \left(wj - \frac{(wj \cdot \left(e^{wj}\right) + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\right)} \le 1.0539839733040413 \cdot 10^{-13}:\\
\;\;\;\;\frac{x}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + \left(wj \cdot wj - {wj}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\
\end{array}\]
Target
| Original | 14.0 |
|---|
| Target | 13.3 |
|---|
| Herbie | 0.1 |
|---|
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
Derivation
- Split input into 2 regimes
if (exp (log (- wj (/ (fma wj (exp wj) (- x)) (fma wj (exp wj) (exp wj)))))) < 1.0539839733040413e-13
Initial program 38.7
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub38.7
\[\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-20.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 simplify20.1
\[\leadsto \color{blue}{\left(wj - \frac{wj}{1 + wj}\right)} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
Taylor expanded around 0 20.1
\[\leadsto \left(wj - \color{blue}{\left(\left({wj}^{3} + wj\right) - {wj}^{2}\right)}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\]
Applied simplify0.0
\[\leadsto \color{blue}{\frac{x}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + \left(wj \cdot wj - {wj}^{3}\right)}\]
if 1.0539839733040413e-13 < (exp (log (- wj (/ (fma wj (exp wj) (- x)) (fma wj (exp wj) (exp wj))))))
Initial program 1.6
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
- Using strategy
rm Applied div-sub1.6
\[\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.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 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 2018214 +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))))))