Average Error: 29.4 → 0.9
Time: 6.5s
Precision: 64
\[\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 10.6130564182300784:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\left(\sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)}\right) \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 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}\]
\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 10.6130564182300784:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\left(\sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)}\right) \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 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 temp;
	if ((x <= 10.613056418230078)) {
		temp = (log1p(((cbrt(expm1(fma(pow(x, 3.0), 0.6666666666666667, (fma(2.0, 2.0, (-(1.0 * 1.0) * pow(x, 4.0))) / fma(pow(x, 2.0), 1.0, 2.0))))) * cbrt(expm1(fma(pow(x, 3.0), 0.6666666666666667, (fma(2.0, 2.0, (-(1.0 * 1.0) * pow(x, 4.0))) / fma(pow(x, 2.0), 1.0, 2.0)))))) * cbrt(expm1(fma(pow(x, 3.0), 0.6666666666666667, (fma(2.0, 2.0, (-(1.0 * 1.0) * pow(x, 4.0))) / fma(pow(x, 2.0), 1.0, 2.0))))))) / 2.0);
	} else {
		temp = 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 temp;
}

Error

Bits error versus x

Bits error versus eps

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < 10.613056418230078

    1. Initial program 38.9

      \[\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}\]
    2. Taylor expanded around 0 1.2

      \[\leadsto \frac{\color{blue}{\left(0.66666666666666674 \cdot {x}^{3} + 2\right) - 1 \cdot {x}^{2}}}{2}\]
    3. Simplified1.2

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{3}, 0.66666666666666674, 2 - 1 \cdot {x}^{2}\right)}}{2}\]
    4. Using strategy rm
    5. Applied flip--1.2

      \[\leadsto \frac{\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \color{blue}{\frac{2 \cdot 2 - \left(1 \cdot {x}^{2}\right) \cdot \left(1 \cdot {x}^{2}\right)}{2 + 1 \cdot {x}^{2}}}\right)}{2}\]
    6. Simplified1.2

      \[\leadsto \frac{\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\color{blue}{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}}{2 + 1 \cdot {x}^{2}}\right)}{2}\]
    7. Simplified1.2

      \[\leadsto \frac{\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\color{blue}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}}\right)}{2}\]
    8. Using strategy rm
    9. Applied log1p-expm1-u1.2

      \[\leadsto \frac{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)\right)}}{2}\]
    10. Using strategy rm
    11. Applied add-cube-cbrt1.2

      \[\leadsto \frac{\mathsf{log1p}\left(\color{blue}{\left(\sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)}\right) \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)}}\right)}{2}\]

    if 10.613056418230078 < x

    1. Initial program 0.2

      \[\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}\]
    2. Simplified0.2

      \[\leadsto \color{blue}{\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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 10.6130564182300784:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\left(\sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)} \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 1, 2\right)}\right)\right)}\right) \cdot \sqrt[3]{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{3}, 0.66666666666666674, \frac{\mathsf{fma}\left(2, 2, \left(-1 \cdot 1\right) \cdot {x}^{4}\right)}{\mathsf{fma}\left({x}^{2}, 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}\]

Reproduce

herbie shell --seed 2020065 +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))