Average Error: 4.6 → 0.9
Time: 12.7s
Precision: 64
\[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.31818012348102291 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}{e^{x + x} - 1 \cdot 1}} \cdot \sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{x} + 1\right)\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 -1.31818012348102291 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}{e^{x + x} - 1 \cdot 1}} \cdot \sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{x} + 1\right)\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 r20074 = 2.0;
        double r20075 = x;
        double r20076 = r20074 * r20075;
        double r20077 = exp(r20076);
        double r20078 = 1.0;
        double r20079 = r20077 - r20078;
        double r20080 = exp(r20075);
        double r20081 = r20080 - r20078;
        double r20082 = r20079 / r20081;
        double r20083 = sqrt(r20082);
        return r20083;
}

double f(double x) {
        double r20084 = x;
        double r20085 = -1.3181801234810229e-05;
        bool r20086 = r20084 <= r20085;
        double r20087 = 2.0;
        double r20088 = r20087 * r20084;
        double r20089 = exp(r20088);
        double r20090 = 1.0;
        double r20091 = r20089 - r20090;
        double r20092 = log1p(r20091);
        double r20093 = expm1(r20092);
        double r20094 = r20084 + r20084;
        double r20095 = exp(r20094);
        double r20096 = r20090 * r20090;
        double r20097 = r20095 - r20096;
        double r20098 = r20093 / r20097;
        double r20099 = sqrt(r20098);
        double r20100 = exp(r20084);
        double r20101 = r20100 + r20090;
        double r20102 = log1p(r20101);
        double r20103 = expm1(r20102);
        double r20104 = sqrt(r20103);
        double r20105 = r20099 * r20104;
        double r20106 = 0.5;
        double r20107 = 2.0;
        double r20108 = pow(r20084, r20107);
        double r20109 = fma(r20090, r20084, r20087);
        double r20110 = fma(r20106, r20108, r20109);
        double r20111 = sqrt(r20110);
        double r20112 = r20086 ? r20105 : r20111;
        return r20112;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -1.3181801234810229e-05

    1. Initial program 0.1

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

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

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

      \[\leadsto \color{blue}{\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} \cdot e^{x} - 1 \cdot 1}} \cdot \sqrt{e^{x} + 1}}\]
    6. Simplified0.0

      \[\leadsto \color{blue}{\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x + x} - 1 \cdot 1}}} \cdot \sqrt{e^{x} + 1}\]
    7. Using strategy rm
    8. Applied expm1-log1p-u0.0

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

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

    if -1.3181801234810229e-05 < x

    1. Initial program 34.5

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

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

      \[\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 -1.31818012348102291 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}{e^{x + x} - 1 \cdot 1}} \cdot \sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{x} + 1\right)\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 2020047 +o rules:numerics
(FPCore (x)
  :name "sqrtexp (problem 3.4.4)"
  :precision binary64
  (sqrt (/ (- (exp (* 2 x)) 1) (- (exp x) 1))))