Average Error: 37.8 → 21.7
Time: 12.1s
Precision: 64
$xim \ge 0$
$0.5 \cdot \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}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2.0} \cdot \sqrt{xre + xim}\right)\\ \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)} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(xre + xre\right) \cdot 2.0}\\ \end{array}$
0.5 \cdot \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}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2.0} \cdot \sqrt{xre + xim}\right)\\

\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)} \cdot 0.5\\

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

\end{array}
double f(double xre, double xim) {
double r44414546 = 0.5;
double r44414547 = 2.0;
double r44414548 = xre;
double r44414549 = r44414548 * r44414548;
double r44414550 = xim;
double r44414551 = r44414550 * r44414550;
double r44414552 = r44414549 + r44414551;
double r44414553 = sqrt(r44414552);
double r44414554 = r44414553 + r44414548;
double r44414555 = r44414547 * r44414554;
double r44414556 = sqrt(r44414555);
double r44414557 = r44414546 * r44414556;
return r44414557;
}


double f(double xre, double xim) {
double r44414558 = xre;
double r44414559 = 5.350798163973607e-125;
bool r44414560 = r44414558 <= r44414559;
double r44414561 = 0.5;
double r44414562 = 2.0;
double r44414563 = sqrt(r44414562);
double r44414564 = xim;
double r44414565 = r44414558 + r44414564;
double r44414566 = sqrt(r44414565);
double r44414567 = r44414563 * r44414566;
double r44414568 = r44414561 * r44414567;
double r44414569 = 1.003429067835426e+90;
bool r44414570 = r44414558 <= r44414569;
double r44414571 = r44414564 * r44414564;
double r44414572 = r44414558 * r44414558;
double r44414573 = r44414571 + r44414572;
double r44414574 = sqrt(r44414573);
double r44414575 = sqrt(r44414574);
double r44414576 = r44414575 * r44414575;
double r44414577 = r44414576 + r44414558;
double r44414578 = r44414562 * r44414577;
double r44414579 = sqrt(r44414578);
double r44414580 = r44414579 * r44414561;
double r44414581 = r44414558 + r44414558;
double r44414582 = r44414581 * r44414562;
double r44414583 = sqrt(r44414582);
double r44414584 = r44414561 * r44414583;
double r44414585 = r44414570 ? r44414580 : r44414584;
double r44414586 = r44414560 ? r44414568 : r44414585;
return r44414586;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

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

1. Initial program 41.1

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

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

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

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

1. Initial program 16.1

$0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{xre \cdot xre + xim \cdot xim} + xre\right)}$
2. Using strategy rm

$\leadsto 0.5 \cdot \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

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

$\leadsto 0.5 \cdot \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}:\\ \;\;\;\;0.5 \cdot \left(\sqrt{2.0} \cdot \sqrt{xre + xim}\right)\\ \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)} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\left(xre + xre\right) \cdot 2.0}\\ \end{array}$

# Reproduce

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