wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\begin{array}{l}
\mathbf{if}\;wj \leq 8.746783178569327 \cdot 10^{-06}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{wj}^{3} + {\left(\frac{\frac{x}{e^{wj}} - wj}{wj + 1}\right)}^{3}}{wj \cdot wj + \left(\frac{x}{e^{wj}} - wj\right) \cdot \frac{\frac{\frac{x}{e^{wj}} - wj}{wj + 1} - wj}{wj + 1}}\\
\end{array}double code(double wj, double x) {
return ((double) (wj - (((double) (((double) (wj * ((double) exp(wj)))) - x)) / ((double) (((double) exp(wj)) + ((double) (wj * ((double) exp(wj)))))))));
}
double code(double wj, double x) {
double VAR;
if ((wj <= 8.746783178569327e-06)) {
VAR = ((double) (x + ((double) (wj * ((double) (wj + ((double) (x * -2.0))))))));
} else {
VAR = (((double) (((double) pow(wj, 3.0)) + ((double) pow((((double) ((x / ((double) exp(wj))) - wj)) / ((double) (wj + 1.0))), 3.0)))) / ((double) (((double) (wj * wj)) + ((double) (((double) ((x / ((double) exp(wj))) - wj)) * (((double) ((((double) ((x / ((double) exp(wj))) - wj)) / ((double) (wj + 1.0))) - wj)) / ((double) (wj + 1.0))))))));
}
return VAR;
}




Bits error versus wj




Bits error versus x
Results
| Original | 14.0 |
|---|---|
| Target | 13.5 |
| Herbie | 1.2 |
if wj < 8.7467831785693269e-6Initial program Error: 13.7 bits
SimplifiedError: 13.7 bits
Taylor expanded around 0 Error: 0.9 bits
SimplifiedError: 0.9 bits
if 8.7467831785693269e-6 < wj Initial program Error: 26.5 bits
SimplifiedError: 1.7 bits
rmApplied flip3-+Error: 14.4 bits
SimplifiedError: 14.4 bits
Final simplificationError: 1.2 bits
herbie shell --seed 2020200
(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))))))