Average Error: 29.3 → 0.9
Time: 14.7s
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 33.941483957658718:\\ \;\;\;\;\frac{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right)\right)\right)} - 1 \cdot {x}^{2}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot {\left(e^{1 + \varepsilon}\right)}^{\left(-x\right)}}{2}\\ \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 33.941483957658718:\\
\;\;\;\;\frac{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right)\right)\right)} - 1 \cdot {x}^{2}}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot {\left(e^{1 + \varepsilon}\right)}^{\left(-x\right)}}{2}\\

\end{array}
double f(double x, double eps) {
        double r50688 = 1.0;
        double r50689 = eps;
        double r50690 = r50688 / r50689;
        double r50691 = r50688 + r50690;
        double r50692 = r50688 - r50689;
        double r50693 = x;
        double r50694 = r50692 * r50693;
        double r50695 = -r50694;
        double r50696 = exp(r50695);
        double r50697 = r50691 * r50696;
        double r50698 = r50690 - r50688;
        double r50699 = r50688 + r50689;
        double r50700 = r50699 * r50693;
        double r50701 = -r50700;
        double r50702 = exp(r50701);
        double r50703 = r50698 * r50702;
        double r50704 = r50697 - r50703;
        double r50705 = 2.0;
        double r50706 = r50704 / r50705;
        return r50706;
}

double f(double x, double eps) {
        double r50707 = x;
        double r50708 = 33.94148395765872;
        bool r50709 = r50707 <= r50708;
        double r50710 = 0.6666666666666667;
        double r50711 = 3.0;
        double r50712 = pow(r50707, r50711);
        double r50713 = 2.0;
        double r50714 = fma(r50710, r50712, r50713);
        double r50715 = sqrt(r50714);
        double r50716 = log(r50715);
        double r50717 = r50716 + r50716;
        double r50718 = log1p(r50717);
        double r50719 = expm1(r50718);
        double r50720 = exp(r50719);
        double r50721 = 1.0;
        double r50722 = 2.0;
        double r50723 = pow(r50707, r50722);
        double r50724 = r50721 * r50723;
        double r50725 = r50720 - r50724;
        double r50726 = r50725 / r50713;
        double r50727 = eps;
        double r50728 = r50721 / r50727;
        double r50729 = r50721 + r50728;
        double r50730 = r50721 - r50727;
        double r50731 = r50730 * r50707;
        double r50732 = -r50731;
        double r50733 = exp(r50732);
        double r50734 = r50729 * r50733;
        double r50735 = r50728 - r50721;
        double r50736 = r50721 + r50727;
        double r50737 = exp(r50736);
        double r50738 = -r50707;
        double r50739 = pow(r50737, r50738);
        double r50740 = r50735 * r50739;
        double r50741 = r50734 - r50740;
        double r50742 = r50741 / r50713;
        double r50743 = r50709 ? r50726 : r50742;
        return r50743;
}

Error

Bits error versus x

Bits error versus eps

Derivation

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

    1. Initial program 39.3

      \[\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.1

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

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

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

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

      \[\leadsto \frac{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \color{blue}{\left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)} \cdot \sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right)}\right)\right)} - 1 \cdot {x}^{2}}{2}\]
    10. Applied log-prod1.1

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

    if 33.94148395765872 < 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. Using strategy rm
    3. Applied distribute-rgt-neg-in0.2

      \[\leadsto \frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{\color{blue}{\left(1 + \varepsilon\right) \cdot \left(-x\right)}}}{2}\]
    4. Applied exp-prod0.2

      \[\leadsto \frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot \color{blue}{{\left(e^{1 + \varepsilon}\right)}^{\left(-x\right)}}}{2}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 33.941483957658718:\\ \;\;\;\;\frac{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(0.66666666666666674, {x}^{3}, 2\right)}\right)\right)\right)} - 1 \cdot {x}^{2}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot {\left(e^{1 + \varepsilon}\right)}^{\left(-x\right)}}{2}\\ \end{array}\]

Reproduce

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