0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt[3]{\sqrt{2}}\\
0.5 \cdot \left(\left(t_0 \cdot t_0\right) \cdot \left(\left(im \cdot \sqrt{0.5}\right) \cdot \left(t_0 \cdot \sqrt{\frac{1}{re}}\right)\right)\right)
\end{array}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(FPCore (re im)
:precision binary64
(if (<= (- (sqrt (+ (* re re) (* im im))) re) 0.0)
(let* ((t_0 (cbrt (sqrt 2.0))))
(* 0.5 (* (* t_0 t_0) (* (* im (sqrt 0.5)) (* t_0 (sqrt (/ 1.0 re)))))))
(* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))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 tmp;
if ((sqrt((re * re) + (im * im)) - re) <= 0.0) {
double t_0_1 = cbrt(sqrt(2.0));
tmp = 0.5 * ((t_0_1 * t_0_1) * ((im * sqrt(0.5)) * (t_0_1 * sqrt(1.0 / re))));
} else {
tmp = 0.5 * sqrt(2.0 * (hypot(re, im) - re));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 58.5
Simplified52.3
Applied sqrt-prod_binary6452.4
Applied add-cube-cbrt_binary6452.4
Applied associate-*l*_binary6452.4
Taylor expanded in im around 0 5.9
Simplified5.9
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 34.8
Simplified6.1
Final simplification6.1
herbie shell --seed 2021215
(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)))))