wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq 2.941308039666007 \cdot 10^{-06}:\\
\;\;\;\;\left({wj}^{2} + \left(x + 2.5 \cdot \left({wj}^{2} \cdot x\right)\right)\right) - \left({wj}^{3} + \left(2.6666666666666665 \cdot \left(x \cdot {wj}^{3}\right) + 2 \cdot \left(wj \cdot x\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;wj + \frac{\frac{x}{e^{wj}} - wj}{wj \cdot wj - 1} \cdot \left(wj - 1\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 2.941308039666007e-06)
(-
(+ (pow wj 2.0) (+ x (* 2.5 (* (pow wj 2.0) x))))
(+
(pow wj 3.0)
(+ (* 2.6666666666666665 (* x (pow wj 3.0))) (* 2.0 (* wj x)))))
(+ wj (* (/ (- (/ x (exp wj)) wj) (- (* wj wj) 1.0)) (- 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 <= 2.941308039666007e-06) {
tmp = (pow(wj, 2.0) + (x + (2.5 * (pow(wj, 2.0) * x)))) - (pow(wj, 3.0) + ((2.6666666666666665 * (x * pow(wj, 3.0))) + (2.0 * (wj * x))));
} else {
tmp = wj + ((((x / exp(wj)) - wj) / ((wj * wj) - 1.0)) * (wj - 1.0));
}
return tmp;
}




Bits error versus wj




Bits error versus x
Results
| Original | 13.7 |
|---|---|
| Target | 13.0 |
| Herbie | 0.6 |
if wj < 2.9413080396660069e-6Initial program 13.3
Simplified13.3
Taylor expanded around 0 0.6
if 2.9413080396660069e-6 < wj Initial program 29.6
Simplified1.5
rmApplied flip-+_binary641.5
Applied associate-/r/_binary641.5
Final simplification0.6
herbie shell --seed 2021173
(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))))))