0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\begin{array}{l}
t_0 := \sqrt{\sqrt{2}}\\
\mathbf{if}\;re \leq 2.1698433257847657 \cdot 10^{-35}:\\
\;\;\;\;\begin{array}{l}
t_1 := \sqrt{t_0}\\
0.5 \cdot \left(t_0 \cdot \left(t_1 \cdot \left(t_1 \cdot \sqrt{\mathsf{hypot}\left(re, im\right) - re}\right)\right)\right)
\end{array}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \left(im \cdot \sqrt{0.5}\right) \cdot \sqrt{\frac{1}{re}}\\
\mathbf{if}\;re \leq 1.8652271911593446 \cdot 10^{+22}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot t_2\right)\\
\mathbf{elif}\;re \leq 6.98244041967603 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - \sqrt[3]{re} \cdot \left(\sqrt[3]{re} \cdot \sqrt[3]{re}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t_0 \cdot \left(t_0 \cdot t_2\right)\right)\\
\end{array}\\
\end{array}
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (sqrt 2.0))))
(if (<= re 2.1698433257847657e-35)
(let* ((t_1 (sqrt t_0)))
(* 0.5 (* t_0 (* t_1 (* t_1 (sqrt (- (hypot re im) re)))))))
(let* ((t_2 (* (* im (sqrt 0.5)) (sqrt (/ 1.0 re)))))
(if (<= re 1.8652271911593446e+22)
(* 0.5 (* (sqrt 2.0) t_2))
(if (<= re 6.98244041967603e+68)
(*
0.5
(sqrt
(* 2.0 (- (hypot re im) (* (cbrt re) (* (cbrt re) (cbrt re)))))))
(* 0.5 (* t_0 (* t_0 t_2)))))))))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 t_0 = sqrt(sqrt(2.0));
double tmp;
if (re <= 2.1698433257847657e-35) {
double t_1_1 = sqrt(t_0);
tmp = 0.5 * (t_0 * (t_1_1 * (t_1_1 * sqrt(hypot(re, im) - re))));
} else {
double t_2 = (im * sqrt(0.5)) * sqrt(1.0 / re);
double tmp_2;
if (re <= 1.8652271911593446e+22) {
tmp_2 = 0.5 * (sqrt(2.0) * t_2);
} else if (re <= 6.98244041967603e+68) {
tmp_2 = 0.5 * sqrt(2.0 * (hypot(re, im) - (cbrt(re) * (cbrt(re) * cbrt(re)))));
} else {
tmp_2 = 0.5 * (t_0 * (t_0 * t_2));
}
tmp = tmp_2;
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < 2.16984332578476565e-35Initial program 30.0
Simplified4.1
Applied sqrt-prod_binary644.5
Applied add-sqr-sqrt_binary644.6
Applied associate-*l*_binary644.5
Applied add-sqr-sqrt_binary644.5
Applied associate-*l*_binary644.5
if 2.16984332578476565e-35 < re < 1.86522719115934465e22Initial program 46.8
Simplified32.8
Applied sqrt-prod_binary6433.0
Taylor expanded in im around 0 27.6
if 1.86522719115934465e22 < re < 6.98244041967603038e68Initial program 46.6
Simplified30.6
Applied add-cube-cbrt_binary6433.2
Applied cancel-sign-sub-inv_binary6433.2
if 6.98244041967603038e68 < re Initial program 58.4
Simplified40.2
Applied sqrt-prod_binary6440.3
Applied add-sqr-sqrt_binary6440.3
Applied associate-*l*_binary6440.3
Taylor expanded in im around 0 11.7
Simplified11.7
Final simplification8.3
herbie shell --seed 2022067
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))