\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}\begin{array}{l}
\mathbf{if}\;x \le 2.5494520086503014:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{2}, 0.66666666666666674 \cdot x - 1, 2\right)\right)}\right)\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{e^{-\left(1 + \varepsilon\right) \cdot x}}{2}, 1 - \frac{1}{\varepsilon}, \frac{1 + \frac{1}{\varepsilon}}{2 \cdot e^{\left(1 - \varepsilon\right) \cdot x}}\right)\\
\end{array}double code(double x, double eps) {
return ((((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0);
}
double code(double x, double eps) {
double VAR;
if ((x <= 2.5494520086503014)) {
VAR = (log1p(log(exp(expm1(fma(pow(x, 2.0), ((0.6666666666666667 * x) - 1.0), 2.0))))) / 2.0);
} else {
VAR = fma((exp(-((1.0 + eps) * x)) / 2.0), (1.0 - (1.0 / eps)), ((1.0 + (1.0 / eps)) / (2.0 * exp(((1.0 - eps) * x)))));
}
return VAR;
}



Bits error versus x



Bits error versus eps
Results
if x < 2.5494520086503014Initial program 38.8
Taylor expanded around 0 1.3
Simplified1.3
Taylor expanded around 0 1.3
Simplified1.3
rmApplied log1p-expm1-u1.3
rmApplied add-log-exp1.3
if 2.5494520086503014 < x Initial program 0.5
Simplified0.5
Final simplification1.1
herbie shell --seed 2020092 +o rules:numerics
(FPCore (x eps)
:name "NMSE Section 6.1 mentioned, A"
:precision binary64
(/ (- (* (+ 1 (/ 1 eps)) (exp (- (* (- 1 eps) x)))) (* (- (/ 1 eps) 1) (exp (- (* (+ 1 eps) x))))) 2))