wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq 1.4176093501666414 \cdot 10^{-12}:\\
\;\;\;\;x + wj \cdot \left(wj - wj \cdot wj\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{1 + {wj}^{3}} \cdot \left(wj \cdot wj + \left(1 - wj\right)\right)\\
\end{array}(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
:precision binary64
(if (<= wj 1.4176093501666414e-12)
(+ x (* wj (- wj (* wj wj))))
(+
wj
(*
(/ (- (/ x (exp wj)) wj) (+ 1.0 (pow wj 3.0)))
(+ (* wj wj) (- 1.0 wj))))))double code(double wj, double x) {
return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
double tmp;
if (wj <= 1.4176093501666414e-12) {
tmp = x + (wj * (wj - (wj * wj)));
} else {
tmp = wj + ((((x / exp(wj)) - wj) / (1.0 + pow(wj, 3.0))) * ((wj * wj) + (1.0 - wj)));
}
return tmp;
}











Bits error versus wj











Bits error versus x
Results
| Original | 13.4 |
|---|---|
| Target | 12.6 |
| Herbie | 1.0 |
| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 7425 |
| Alternative 2 | |
|---|---|
| Error | 1.5 |
| Cost | 897 |
| Alternative 3 | |
|---|---|
| Error | 1.7 |
| Cost | 769 |
| Alternative 4 | |
|---|---|
| Error | 2.1 |
| Cost | 641 |
| Alternative 5 | |
|---|---|
| Error | 8.9 |
| Cost | 513 |
| Alternative 6 | |
|---|---|
| Error | 9.5 |
| Cost | 64 |
| Alternative 7 | |
|---|---|
| Error | 61.4 |
| Cost | 64 |

if wj < 1.4176093501666414e-12Initial program 12.9
Simplified12.9
Taylor expanded around 0 0.6
Simplified0.6
Taylor expanded around 0 0.9
Simplified0.9
rmApplied unpow3_binary64_49180.9
Applied distribute-rgt-out--_binary64_48060.9
Simplified0.9
if 1.4176093501666414e-12 < wj Initial program 25.5
Simplified4.6
rmApplied flip3-+_binary64_48554.7
Applied associate-/r/_binary64_47984.6
Simplified4.6
Simplified4.6
Final simplification1.0
herbie shell --seed 2021044
(FPCore (wj x)
:name "Jmat.Real.lambertw, newton loop step"
:precision binary64
:herbie-target
(- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))