Average Error: 4.8 → 0.9
Time: 7.0s
Precision: 64
\[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.15812995981289169 \cdot 10^{-16}:\\ \;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{2 \cdot x} - 1}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{2}, 0.166666666666666657, \mathsf{fma}\left(0.333333333333333315, x, \log 3\right) - 0.5 \cdot \frac{{x}^{2}}{{3}^{2}}\right)\right)}\\ \end{array}\]
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\begin{array}{l}
\mathbf{if}\;x \le -7.15812995981289169 \cdot 10^{-16}:\\
\;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{2 \cdot x} - 1}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{fma}\left({x}^{2}, 0.166666666666666657, \mathsf{fma}\left(0.333333333333333315, x, \log 3\right) - 0.5 \cdot \frac{{x}^{2}}{{3}^{2}}\right)\right)}\\

\end{array}
double f(double x) {
        double r18704 = 2.0;
        double r18705 = x;
        double r18706 = r18704 * r18705;
        double r18707 = exp(r18706);
        double r18708 = 1.0;
        double r18709 = r18707 - r18708;
        double r18710 = exp(r18705);
        double r18711 = r18710 - r18708;
        double r18712 = r18709 / r18711;
        double r18713 = sqrt(r18712);
        return r18713;
}

double f(double x) {
        double r18714 = x;
        double r18715 = -7.158129959812892e-16;
        bool r18716 = r18714 <= r18715;
        double r18717 = 2.0;
        double r18718 = r18717 * r18714;
        double r18719 = exp(r18718);
        double r18720 = 1.0;
        double r18721 = r18719 - r18720;
        double r18722 = -r18720;
        double r18723 = r18714 + r18714;
        double r18724 = exp(r18723);
        double r18725 = fma(r18722, r18720, r18724);
        double r18726 = exp(r18714);
        double r18727 = r18726 + r18720;
        double r18728 = r18725 / r18727;
        double r18729 = r18721 / r18728;
        double r18730 = log1p(r18729);
        double r18731 = expm1(r18730);
        double r18732 = sqrt(r18731);
        double r18733 = 2.0;
        double r18734 = pow(r18714, r18733);
        double r18735 = 0.16666666666666666;
        double r18736 = 0.3333333333333333;
        double r18737 = 3.0;
        double r18738 = log(r18737);
        double r18739 = fma(r18736, r18714, r18738);
        double r18740 = 0.5;
        double r18741 = pow(r18737, r18733);
        double r18742 = r18734 / r18741;
        double r18743 = r18740 * r18742;
        double r18744 = r18739 - r18743;
        double r18745 = fma(r18734, r18735, r18744);
        double r18746 = expm1(r18745);
        double r18747 = sqrt(r18746);
        double r18748 = r18716 ? r18732 : r18747;
        return r18748;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -7.158129959812892e-16

    1. Initial program 0.8

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

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

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

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

    if -7.158129959812892e-16 < x

    1. Initial program 38.2

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

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

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

      \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{2 \cdot x} - 1}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}\right)\right)}}\]
    7. Taylor expanded around 0 8.4

      \[\leadsto \sqrt{\mathsf{expm1}\left(\color{blue}{\left(0.166666666666666657 \cdot {x}^{2} + \left(0.333333333333333315 \cdot x + \log 3\right)\right) - 0.5 \cdot \frac{{x}^{2}}{{3}^{2}}}\right)}\]
    8. Simplified8.4

      \[\leadsto \sqrt{\mathsf{expm1}\left(\color{blue}{\mathsf{fma}\left({x}^{2}, 0.166666666666666657, \mathsf{fma}\left(0.333333333333333315, x, \log 3\right) - 0.5 \cdot \frac{{x}^{2}}{{3}^{2}}\right)}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

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

Reproduce

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