Average Error: 37.5 → 18.2
Time: 14.5s
Precision: 64
\[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.948787994215982 \cdot 10^{+143}:\\ \;\;\;\;\frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{-2 \cdot re}} \cdot \frac{1}{2}\\ \mathbf{elif}\;re \le -9.361038594997412 \cdot 10^{-293}:\\ \;\;\;\;\frac{1}{2} \cdot \left(\frac{\sqrt{2}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}} \cdot \frac{\left|im\right|}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\right)\\ \mathbf{elif}\;re \le 6.586100699332152 \cdot 10^{+127}:\\ \;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} + re\right) \cdot 2} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{\left(re + re\right) \cdot 2}\\ \end{array}\]
\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
\mathbf{if}\;re \le -4.948787994215982 \cdot 10^{+143}:\\
\;\;\;\;\frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{-2 \cdot re}} \cdot \frac{1}{2}\\

\mathbf{elif}\;re \le -9.361038594997412 \cdot 10^{-293}:\\
\;\;\;\;\frac{1}{2} \cdot \left(\frac{\sqrt{2}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}} \cdot \frac{\left|im\right|}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\right)\\

\mathbf{elif}\;re \le 6.586100699332152 \cdot 10^{+127}:\\
\;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} + re\right) \cdot 2} \cdot \frac{1}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \sqrt{\left(re + re\right) \cdot 2}\\

\end{array}
double f(double re, double im) {
        double r36446368 = 0.5;
        double r36446369 = 2.0;
        double r36446370 = re;
        double r36446371 = r36446370 * r36446370;
        double r36446372 = im;
        double r36446373 = r36446372 * r36446372;
        double r36446374 = r36446371 + r36446373;
        double r36446375 = sqrt(r36446374);
        double r36446376 = r36446375 + r36446370;
        double r36446377 = r36446369 * r36446376;
        double r36446378 = sqrt(r36446377);
        double r36446379 = r36446368 * r36446378;
        return r36446379;
}

double f(double re, double im) {
        double r36446380 = re;
        double r36446381 = -4.948787994215982e+143;
        bool r36446382 = r36446380 <= r36446381;
        double r36446383 = im;
        double r36446384 = r36446383 * r36446383;
        double r36446385 = 2.0;
        double r36446386 = r36446384 * r36446385;
        double r36446387 = sqrt(r36446386);
        double r36446388 = -2.0;
        double r36446389 = r36446388 * r36446380;
        double r36446390 = sqrt(r36446389);
        double r36446391 = r36446387 / r36446390;
        double r36446392 = 0.5;
        double r36446393 = r36446391 * r36446392;
        double r36446394 = -9.361038594997412e-293;
        bool r36446395 = r36446380 <= r36446394;
        double r36446396 = sqrt(r36446385);
        double r36446397 = r36446380 * r36446380;
        double r36446398 = r36446397 + r36446384;
        double r36446399 = sqrt(r36446398);
        double r36446400 = r36446399 - r36446380;
        double r36446401 = sqrt(r36446400);
        double r36446402 = sqrt(r36446401);
        double r36446403 = r36446396 / r36446402;
        double r36446404 = fabs(r36446383);
        double r36446405 = r36446404 / r36446402;
        double r36446406 = r36446403 * r36446405;
        double r36446407 = r36446392 * r36446406;
        double r36446408 = 6.586100699332152e+127;
        bool r36446409 = r36446380 <= r36446408;
        double r36446410 = r36446399 + r36446380;
        double r36446411 = r36446410 * r36446385;
        double r36446412 = sqrt(r36446411);
        double r36446413 = r36446412 * r36446392;
        double r36446414 = r36446380 + r36446380;
        double r36446415 = r36446414 * r36446385;
        double r36446416 = sqrt(r36446415);
        double r36446417 = r36446392 * r36446416;
        double r36446418 = r36446409 ? r36446413 : r36446417;
        double r36446419 = r36446395 ? r36446407 : r36446418;
        double r36446420 = r36446382 ? r36446393 : r36446419;
        return r36446420;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if re < -4.948787994215982e+143

    1. Initial program 61.7

      \[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
    2. Using strategy rm
    3. Applied flip-+61.7

      \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\frac{\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re}{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    4. Applied associate-*r/61.7

      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{\frac{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    5. Applied sqrt-div61.7

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    6. Simplified47.4

      \[\leadsto \frac{1}{2} \cdot \frac{\color{blue}{\sqrt{\left(im \cdot im + 0\right) \cdot 2}}}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}\]
    7. Taylor expanded around -inf 20.3

      \[\leadsto \frac{1}{2} \cdot \frac{\sqrt{\left(im \cdot im + 0\right) \cdot 2}}{\sqrt{\color{blue}{-2 \cdot re}}}\]

    if -4.948787994215982e+143 < re < -9.361038594997412e-293

    1. Initial program 39.1

      \[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
    2. Using strategy rm
    3. Applied flip-+39.1

      \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \color{blue}{\frac{\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re}{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    4. Applied associate-*r/39.1

      \[\leadsto \frac{1}{2} \cdot \sqrt{\color{blue}{\frac{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    5. Applied sqrt-div39.2

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\frac{\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im} - re \cdot re\right)}}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    6. Simplified28.4

      \[\leadsto \frac{1}{2} \cdot \frac{\color{blue}{\sqrt{\left(im \cdot im + 0\right) \cdot 2}}}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt28.4

      \[\leadsto \frac{1}{2} \cdot \frac{\sqrt{\left(im \cdot im + 0\right) \cdot 2}}{\sqrt{\color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}}\]
    9. Applied sqrt-prod28.6

      \[\leadsto \frac{1}{2} \cdot \frac{\sqrt{\left(im \cdot im + 0\right) \cdot 2}}{\color{blue}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}} \cdot \sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}}\]
    10. Applied sqrt-prod28.6

      \[\leadsto \frac{1}{2} \cdot \frac{\color{blue}{\sqrt{im \cdot im + 0} \cdot \sqrt{2}}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}} \cdot \sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\]
    11. Applied times-frac28.6

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(\frac{\sqrt{im \cdot im + 0}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}} \cdot \frac{\sqrt{2}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\right)}\]
    12. Simplified19.5

      \[\leadsto \frac{1}{2} \cdot \left(\color{blue}{\frac{\left|im\right|}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}} \cdot \frac{\sqrt{2}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\right)\]

    if -9.361038594997412e-293 < re < 6.586100699332152e+127

    1. Initial program 20.2

      \[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]

    if 6.586100699332152e+127 < re

    1. Initial program 54.5

      \[\frac{1}{2} \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\]
    2. Taylor expanded around inf 8.3

      \[\leadsto \frac{1}{2} \cdot \sqrt{2 \cdot \left(\color{blue}{re} + re\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification18.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -4.948787994215982 \cdot 10^{+143}:\\ \;\;\;\;\frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{-2 \cdot re}} \cdot \frac{1}{2}\\ \mathbf{elif}\;re \le -9.361038594997412 \cdot 10^{-293}:\\ \;\;\;\;\frac{1}{2} \cdot \left(\frac{\sqrt{2}}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}} \cdot \frac{\left|im\right|}{\sqrt{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}}\right)\\ \mathbf{elif}\;re \le 6.586100699332152 \cdot 10^{+127}:\\ \;\;\;\;\sqrt{\left(\sqrt{re \cdot re + im \cdot im} + re\right) \cdot 2} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \sqrt{\left(re + re\right) \cdot 2}\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (re im)
  :name "Complex square root"
  (* 1/2 (sqrt (* 2 (+ (sqrt (+ (* re re) (* im im))) re)))))