Average Error: 4.7 → 1.3
Time: 6.7s
Precision: 64
\[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.69778124812825276 \cdot 10^{-17}:\\ \;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\sqrt{e^{2 \cdot x}}, \sqrt{e^{2 \cdot x}}, -1\right)\right)\right)}{e^{x} - 1}}\\ \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.69778124812825276 \cdot 10^{-17}:\\
\;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(\sqrt{e^{2 \cdot x}}, \sqrt{e^{2 \cdot x}}, -1\right)\right)\right)}{e^{x} - 1}}\\

\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 r25474 = 2.0;
        double r25475 = x;
        double r25476 = r25474 * r25475;
        double r25477 = exp(r25476);
        double r25478 = 1.0;
        double r25479 = r25477 - r25478;
        double r25480 = exp(r25475);
        double r25481 = r25480 - r25478;
        double r25482 = r25479 / r25481;
        double r25483 = sqrt(r25482);
        return r25483;
}

double f(double x) {
        double r25484 = x;
        double r25485 = -5.697781248128253e-17;
        bool r25486 = r25484 <= r25485;
        double r25487 = 2.0;
        double r25488 = r25487 * r25484;
        double r25489 = exp(r25488);
        double r25490 = sqrt(r25489);
        double r25491 = 1.0;
        double r25492 = -r25491;
        double r25493 = fma(r25490, r25490, r25492);
        double r25494 = log1p(r25493);
        double r25495 = expm1(r25494);
        double r25496 = exp(r25484);
        double r25497 = r25496 - r25491;
        double r25498 = r25495 / r25497;
        double r25499 = sqrt(r25498);
        double r25500 = 0.5;
        double r25501 = 2.0;
        double r25502 = pow(r25484, r25501);
        double r25503 = fma(r25491, r25484, r25487);
        double r25504 = fma(r25500, r25502, r25503);
        double r25505 = sqrt(r25504);
        double r25506 = r25486 ? r25499 : r25505;
        return r25506;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -5.697781248128253e-17

    1. Initial program 1.0

      \[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.8

      \[\leadsto \sqrt{\frac{\color{blue}{\sqrt{e^{2 \cdot x}} \cdot \sqrt{e^{2 \cdot x}}} - 1}{e^{x} - 1}}\]
    4. Applied fma-neg0.3

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

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

    if -5.697781248128253e-17 < x

    1. Initial program 37.1

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

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

      \[\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 simplification1.3

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

Reproduce

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