Average Error: 4.3 → 0.9
Time: 5.9s
Precision: 64
\[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.3888208797845926 \cdot 10^{-12}:\\ \;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \left(e^{x} + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, {x}^{2}, \mathsf{fma}\left(1, x, 2\right)\right)}\\ \end{array}\]
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\begin{array}{l}
\mathbf{if}\;x \le -5.3888208797845926 \cdot 10^{-12}:\\
\;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \left(e^{x} + 1\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, {x}^{2}, \mathsf{fma}\left(1, x, 2\right)\right)}\\

\end{array}
double f(double x) {
        double r14776 = 2.0;
        double r14777 = x;
        double r14778 = r14776 * r14777;
        double r14779 = exp(r14778);
        double r14780 = 1.0;
        double r14781 = r14779 - r14780;
        double r14782 = exp(r14777);
        double r14783 = r14782 - r14780;
        double r14784 = r14781 / r14783;
        double r14785 = sqrt(r14784);
        return r14785;
}

double f(double x) {
        double r14786 = x;
        double r14787 = -5.3888208797845926e-12;
        bool r14788 = r14786 <= r14787;
        double r14789 = 2.0;
        double r14790 = r14789 * r14786;
        double r14791 = exp(r14790);
        double r14792 = 1.0;
        double r14793 = r14791 - r14792;
        double r14794 = log1p(r14793);
        double r14795 = expm1(r14794);
        double r14796 = -r14792;
        double r14797 = r14786 + r14786;
        double r14798 = exp(r14797);
        double r14799 = fma(r14796, r14792, r14798);
        double r14800 = r14795 / r14799;
        double r14801 = exp(r14786);
        double r14802 = r14801 + r14792;
        double r14803 = r14800 * r14802;
        double r14804 = sqrt(r14803);
        double r14805 = 0.5;
        double r14806 = 2.0;
        double r14807 = pow(r14786, r14806);
        double r14808 = fma(r14792, r14786, r14789);
        double r14809 = fma(r14805, r14807, r14808);
        double r14810 = sqrt(r14809);
        double r14811 = r14788 ? r14804 : r14810;
        return r14811;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -5.3888208797845926e-12

    1. Initial program 0.5

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
    2. Using strategy rm
    3. Applied flip--0.3

      \[\leadsto \sqrt{\frac{e^{2 \cdot x} - 1}{\color{blue}{\frac{e^{x} \cdot e^{x} - 1 \cdot 1}{e^{x} + 1}}}}\]
    4. Applied associate-/r/0.3

      \[\leadsto \sqrt{\color{blue}{\frac{e^{2 \cdot x} - 1}{e^{x} \cdot e^{x} - 1 \cdot 1} \cdot \left(e^{x} + 1\right)}}\]
    5. Simplified0.0

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

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

    if -5.3888208797845926e-12 < x

    1. Initial program 35.8

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
    2. Taylor expanded around 0 7.9

      \[\leadsto \sqrt{\color{blue}{0.5 \cdot {x}^{2} + \left(1 \cdot x + 2\right)}}\]
    3. Simplified7.9

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(0.5, {x}^{2}, \mathsf{fma}\left(1, x, 2\right)\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.3888208797845926 \cdot 10^{-12}:\\ \;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \left(e^{x} + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(0.5, {x}^{2}, \mathsf{fma}\left(1, x, 2\right)\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020065 +o rules:numerics
(FPCore (x)
  :name "sqrtexp (problem 3.4.4)"
  :precision binary64
  (sqrt (/ (- (exp (* 2 x)) 1) (- (exp x) 1))))