wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;\begin{array}{l}
t_0 := wj \cdot e^{wj}\\
wj - \frac{t_0 - x}{e^{wj} + t_0} \leq 1.1510916157317222 \cdot 10^{-19}
\end{array}:\\
\;\;\;\;\left(x + \left(x \cdot 2.5 + 1\right) \cdot \left(wj \cdot wj\right)\right) + \left(x \cdot \left(wj \cdot -2\right) - \left(1 + x \cdot 2.6666666666666665\right) \cdot {wj}^{3}\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 (let* ((t_0 (* wj (exp wj))))
(<= (- wj (/ (- t_0 x) (+ (exp wj) t_0))) 1.1510916157317222e-19))
(+
(+ x (* (+ (* x 2.5) 1.0) (* wj wj)))
(- (* x (* wj -2.0)) (* (+ 1.0 (* x 2.6666666666666665)) (pow wj 3.0))))
(+ 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 t_0 = wj * exp(wj);
double tmp;
if ((wj - ((t_0 - x) / (exp(wj) + t_0))) <= 1.1510916157317222e-19) {
tmp = (x + (((x * 2.5) + 1.0) * (wj * wj))) + ((x * (wj * -2.0)) - ((1.0 + (x * 2.6666666666666665)) * pow(wj, 3.0)));
} 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 | 14.0 |
|---|---|
| Target | 13.2 |
| Herbie | 0.6 |
if (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) < 1.15109162e-19Initial program 18.2
Simplified18.2
Taylor expanded around 0 0.4
Simplified0.5
if 1.15109162e-19 < (-.f64 wj (/.f64 (-.f64 (*.f64 wj (exp.f64 wj)) x) (+.f64 (exp.f64 wj) (*.f64 wj (exp.f64 wj))))) Initial program 3.3
Simplified0.7
rmApplied flip-+_binary640.7
Applied associate-/r/_binary640.7
Final simplification0.6
herbie shell --seed 2021198
(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))))))