0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \le 1755103.27134319046:\\
\;\;\;\;0.5 \cdot \left(\left(\left|\sqrt[3]{\sqrt{2}}\right| \cdot \sqrt{\sqrt{2}}\right) \cdot \sqrt{\sqrt[3]{\sqrt{2}} \cdot \mathsf{hypot}\left(re, im\right) + \sqrt[3]{\sqrt{2}} \cdot \left(-re\right)}\right)\\
\mathbf{elif}\;re \le 3.9030929001675639 \cdot 10^{52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{{im}^{2} + 0}{re + \mathsf{hypot}\left(re, im\right)}}\\
\mathbf{elif}\;re \le 5.6852916263112347 \cdot 10^{140}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(1 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{{im}^{2} + 0}{re + \mathsf{hypot}\left(re, im\right)}}\\
\end{array}double code(double re, double im) {
return (0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))));
}
double code(double re, double im) {
double temp;
if ((re <= 1755103.2713431905)) {
temp = (0.5 * ((fabs(cbrt(sqrt(2.0))) * sqrt(sqrt(2.0))) * sqrt(((cbrt(sqrt(2.0)) * hypot(re, im)) + (cbrt(sqrt(2.0)) * -re)))));
} else {
double temp_1;
if ((re <= 3.903092900167564e+52)) {
temp_1 = (0.5 * sqrt((2.0 * ((pow(im, 2.0) + 0.0) / (re + hypot(re, im))))));
} else {
double temp_2;
if ((re <= 5.685291626311235e+140)) {
temp_2 = (0.5 * sqrt((2.0 * (1.0 * (hypot(re, im) - re)))));
} else {
temp_2 = (0.5 * sqrt((2.0 * ((pow(im, 2.0) + 0.0) / (re + hypot(re, im))))));
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}



Bits error versus re



Bits error versus im
Results
if re < 1755103.2713431905Initial program 32.4
rmApplied *-un-lft-identity32.4
Applied *-un-lft-identity32.4
Applied distribute-lft-out--32.4
Simplified5.2
rmApplied add-sqr-sqrt5.8
Applied associate-*l*5.6
Applied sqrt-prod5.4
rmApplied sub-neg5.4
Applied distribute-lft-in5.4
Applied distribute-lft-in5.4
Simplified5.4
Simplified5.4
rmApplied add-cube-cbrt5.4
Applied associate-*l*5.4
Applied add-cube-cbrt5.4
Applied associate-*l*5.4
Applied distribute-lft-out5.4
Applied sqrt-prod5.5
Applied associate-*r*5.4
Simplified5.4
if 1755103.2713431905 < re < 3.903092900167564e+52 or 5.685291626311235e+140 < re Initial program 59.9
rmApplied flip--59.9
Simplified44.9
Simplified31.3
if 3.903092900167564e+52 < re < 5.685291626311235e+140Initial program 51.1
rmApplied *-un-lft-identity51.1
Applied *-un-lft-identity51.1
Applied distribute-lft-out--51.1
Simplified37.1
Final simplification12.1
herbie shell --seed 2020066 +o rules:numerics
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
(* 0.5 (sqrt (* 2 (- (sqrt (+ (* re re) (* im im))) re)))))