Average Error: 4.4 → 0.1
Time: 7.6s
Precision: 64
\[\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.064503060548636040056673634498168217729 \cdot 10^{-17}:\\ \;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\sqrt[3]{{\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}^{3}}\right)}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\ \mathbf{elif}\;x \le 5.513000463537471615803120757874698005936 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \frac{x}{\sqrt{2}} + \left(\sqrt{2} + \frac{{x}^{2}}{\sqrt{2}} \cdot \left(0.25 - \frac{0.125}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\ \end{array}\]
\sqrt{\frac{e^{2 \cdot x} - 1}{e^{x} - 1}}
\begin{array}{l}
\mathbf{if}\;x \le -4.064503060548636040056673634498168217729 \cdot 10^{-17}:\\
\;\;\;\;\sqrt{\frac{\mathsf{expm1}\left(\sqrt[3]{{\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}^{3}}\right)}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\

\mathbf{elif}\;x \le 5.513000463537471615803120757874698005936 \cdot 10^{-17}:\\
\;\;\;\;0.5 \cdot \frac{x}{\sqrt{2}} + \left(\sqrt{2} + \frac{{x}^{2}}{\sqrt{2}} \cdot \left(0.25 - \frac{0.125}{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\\

\end{array}
double f(double x) {
        double r25964 = 2.0;
        double r25965 = x;
        double r25966 = r25964 * r25965;
        double r25967 = exp(r25966);
        double r25968 = 1.0;
        double r25969 = r25967 - r25968;
        double r25970 = exp(r25965);
        double r25971 = r25970 - r25968;
        double r25972 = r25969 / r25971;
        double r25973 = sqrt(r25972);
        return r25973;
}

double f(double x) {
        double r25974 = x;
        double r25975 = -4.064503060548636e-17;
        bool r25976 = r25974 <= r25975;
        double r25977 = 2.0;
        double r25978 = r25977 * r25974;
        double r25979 = exp(r25978);
        double r25980 = 1.0;
        double r25981 = r25979 - r25980;
        double r25982 = log1p(r25981);
        double r25983 = 3.0;
        double r25984 = pow(r25982, r25983);
        double r25985 = cbrt(r25984);
        double r25986 = expm1(r25985);
        double r25987 = -r25980;
        double r25988 = r25974 + r25974;
        double r25989 = exp(r25988);
        double r25990 = fma(r25987, r25980, r25989);
        double r25991 = exp(r25974);
        double r25992 = r25991 + r25980;
        double r25993 = r25990 / r25992;
        double r25994 = r25986 / r25993;
        double r25995 = sqrt(r25994);
        double r25996 = 5.5130004635374716e-17;
        bool r25997 = r25974 <= r25996;
        double r25998 = 0.5;
        double r25999 = sqrt(r25977);
        double r26000 = r25974 / r25999;
        double r26001 = r25998 * r26000;
        double r26002 = 2.0;
        double r26003 = pow(r25974, r26002);
        double r26004 = r26003 / r25999;
        double r26005 = 0.25;
        double r26006 = 0.125;
        double r26007 = r26006 / r25977;
        double r26008 = r26005 - r26007;
        double r26009 = r26004 * r26008;
        double r26010 = r25999 + r26009;
        double r26011 = r26001 + r26010;
        double r26012 = expm1(r25982);
        double r26013 = 1.0;
        double r26014 = r26013 / r25993;
        double r26015 = r26012 * r26014;
        double r26016 = sqrt(r26015);
        double r26017 = r25997 ? r26011 : r26016;
        double r26018 = r25976 ? r25995 : r26017;
        return r26018;
}

Error

Bits error versus x

Derivation

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

    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{\frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right)}}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}\]
    7. Using strategy rm
    8. Applied add-cbrt-cube0.0

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

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

    if -4.064503060548636e-17 < x < 5.5130004635374716e-17

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\left(0.25 \cdot \frac{{x}^{2}}{\sqrt{2}} + \left(\sqrt{2} + 0.5 \cdot \frac{x}{\sqrt{2}}\right)\right) - 0.125 \cdot \frac{{x}^{2}}{{\left(\sqrt{2}\right)}^{3}}}\]
    3. Simplified0

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{\sqrt{2}} + \left(\sqrt{2} + \frac{{x}^{2}}{\sqrt{2}} \cdot \left(0.25 - \frac{0.125}{2}\right)\right)}\]

    if 5.5130004635374716e-17 < x

    1. Initial program 17.7

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

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

      \[\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-u1.8

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

      \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{2 \cdot x} - 1\right)\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(-1, 1, e^{x + x}\right)}{e^{x} + 1}}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Reproduce

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