Average Error: 37.8 → 21.7
Time: 12.7s
Precision: 64
\[xim \ge 0\]
\[\sqrt{2.0 \cdot \left(\sqrt{xre \cdot xre + xim \cdot xim} + xre\right)}\]
\[\begin{array}{l} \mathbf{if}\;xre \le 5.350798163973607 \cdot 10^{-125}:\\ \;\;\;\;\sqrt{xim + xre} \cdot \sqrt{2.0}\\ \mathbf{elif}\;xre \le 1.003429067835426 \cdot 10^{+90}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(\sqrt{\sqrt{xim \cdot xim + xre \cdot xre}} \cdot \sqrt{\sqrt{xim \cdot xim + xre \cdot xre}} + xre\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(xre + xre\right) \cdot 2.0}\\ \end{array}\]
\sqrt{2.0 \cdot \left(\sqrt{xre \cdot xre + xim \cdot xim} + xre\right)}
\begin{array}{l}
\mathbf{if}\;xre \le 5.350798163973607 \cdot 10^{-125}:\\
\;\;\;\;\sqrt{xim + xre} \cdot \sqrt{2.0}\\

\mathbf{elif}\;xre \le 1.003429067835426 \cdot 10^{+90}:\\
\;\;\;\;\sqrt{2.0 \cdot \left(\sqrt{\sqrt{xim \cdot xim + xre \cdot xre}} \cdot \sqrt{\sqrt{xim \cdot xim + xre \cdot xre}} + xre\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\left(xre + xre\right) \cdot 2.0}\\

\end{array}
double f(double xre, double xim) {
        double r44163848 = 2.0;
        double r44163849 = xre;
        double r44163850 = r44163849 * r44163849;
        double r44163851 = xim;
        double r44163852 = r44163851 * r44163851;
        double r44163853 = r44163850 + r44163852;
        double r44163854 = sqrt(r44163853);
        double r44163855 = r44163854 + r44163849;
        double r44163856 = r44163848 * r44163855;
        double r44163857 = sqrt(r44163856);
        return r44163857;
}

double f(double xre, double xim) {
        double r44163858 = xre;
        double r44163859 = 5.350798163973607e-125;
        bool r44163860 = r44163858 <= r44163859;
        double r44163861 = xim;
        double r44163862 = r44163861 + r44163858;
        double r44163863 = sqrt(r44163862);
        double r44163864 = 2.0;
        double r44163865 = sqrt(r44163864);
        double r44163866 = r44163863 * r44163865;
        double r44163867 = 1.003429067835426e+90;
        bool r44163868 = r44163858 <= r44163867;
        double r44163869 = r44163861 * r44163861;
        double r44163870 = r44163858 * r44163858;
        double r44163871 = r44163869 + r44163870;
        double r44163872 = sqrt(r44163871);
        double r44163873 = sqrt(r44163872);
        double r44163874 = r44163873 * r44163873;
        double r44163875 = r44163874 + r44163858;
        double r44163876 = r44163864 * r44163875;
        double r44163877 = sqrt(r44163876);
        double r44163878 = r44163858 + r44163858;
        double r44163879 = r44163878 * r44163864;
        double r44163880 = sqrt(r44163879);
        double r44163881 = r44163868 ? r44163877 : r44163880;
        double r44163882 = r44163860 ? r44163866 : r44163881;
        return r44163882;
}

Error

Bits error versus xre

Bits error versus xim

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if xre < 5.350798163973607e-125

    1. Initial program 41.1

      \[\sqrt{2.0 \cdot \left(\sqrt{xre \cdot xre + xim \cdot xim} + xre\right)}\]
    2. Taylor expanded around 0 26.1

      \[\leadsto \sqrt{2.0 \cdot \color{blue}{\left(xre + xim\right)}}\]
    3. Using strategy rm
    4. Applied sqrt-prod26.3

      \[\leadsto \color{blue}{\sqrt{2.0} \cdot \sqrt{xre + xim}}\]

    if 5.350798163973607e-125 < xre < 1.003429067835426e+90

    1. Initial program 16.1

      \[\sqrt{2.0 \cdot \left(\sqrt{xre \cdot xre + xim \cdot xim} + xre\right)}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt16.1

      \[\leadsto \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{\sqrt{xre \cdot xre + xim \cdot xim} \cdot \sqrt{xre \cdot xre + xim \cdot xim}}} + xre\right)}\]
    4. Applied sqrt-prod16.2

      \[\leadsto \sqrt{2.0 \cdot \left(\color{blue}{\sqrt{\sqrt{xre \cdot xre + xim \cdot xim}} \cdot \sqrt{\sqrt{xre \cdot xre + xim \cdot xim}}} + xre\right)}\]

    if 1.003429067835426e+90 < xre

    1. Initial program 46.2

      \[\sqrt{2.0 \cdot \left(\sqrt{xre \cdot xre + xim \cdot xim} + xre\right)}\]
    2. Taylor expanded around inf 10.1

      \[\leadsto \sqrt{2.0 \cdot \left(\color{blue}{xre} + xre\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification21.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;xre \le 5.350798163973607 \cdot 10^{-125}:\\ \;\;\;\;\sqrt{xim + xre} \cdot \sqrt{2.0}\\ \mathbf{elif}\;xre \le 1.003429067835426 \cdot 10^{+90}:\\ \;\;\;\;\sqrt{2.0 \cdot \left(\sqrt{\sqrt{xim \cdot xim + xre \cdot xre}} \cdot \sqrt{\sqrt{xim \cdot xim + xre \cdot xre}} + xre\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(xre + xre\right) \cdot 2.0}\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (xre xim)
  :name "sqrt(2.0 * (sqrt(xre * xre + xim * xim) + xre))"
  :pre (>= xim 0)
  (sqrt (* 2.0 (+ (sqrt (+ (* xre xre) (* xim xim))) xre))))