wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq -5.070275397261289 \cdot 10^{-09}:\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\\
\mathbf{elif}\;wj \leq 8.586694722522736 \cdot 10^{-09}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\
\end{array}(FPCore (wj x) :precision binary64 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
:precision binary64
(if (<= wj -5.070275397261289e-09)
(+ wj (/ (- (/ x (exp wj)) wj) (+ wj 1.0)))
(if (<= wj 8.586694722522736e-09)
(+ x (* wj (+ wj (* x -2.0))))
(+ wj (/ (- (* x (exp (- wj))) wj) (+ wj 1.0))))))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 <= -5.070275397261289e-09) {
tmp = wj + (((x / exp(wj)) - wj) / (wj + 1.0));
} else if (wj <= 8.586694722522736e-09) {
tmp = x + (wj * (wj + (x * -2.0)));
} else {
tmp = wj + (((x * exp(-wj)) - wj) / (wj + 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.6 |
|---|---|
| Target | 13.1 |
| Herbie | 0.4 |
if wj < -5.07027539726128872e-9Initial program 5.2
Simplified5.0
if -5.07027539726128872e-9 < wj < 8.58669472252273645e-9Initial program 13.5
Simplified13.5
Taylor expanded around 0 0.2
Simplified0.2
if 8.58669472252273645e-9 < wj Initial program 21.7
Simplified2.9
rmApplied div-inv_binary64_31442.8
Simplified2.8
Final simplification0.4
herbie shell --seed 2020349
(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))))))