0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -6.2492827667685015 \cdot 10^{+187}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq 5.940568352251136 \cdot 10^{-298}:\\
\;\;\;\;0.5 \cdot \frac{\left|im\right| \cdot \sqrt{2}}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}\\
\mathbf{elif}\;re \leq 4.943285085157152 \cdot 10^{+144}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{im \cdot im + re \cdot re}\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + 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 (<= re -6.2492827667685015e+187)
(* 0.5 (/ (sqrt (* (* im im) 2.0)) (sqrt (* re -2.0))))
(if (<= re 5.940568352251136e-298)
(*
0.5
(/
(* (fabs im) (sqrt 2.0))
(sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re 4.943285085157152e+144)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (+ (* im im) (* re re)))))))
(* 0.5 (sqrt (* 2.0 (+ re 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 (re <= -6.2492827667685015e+187) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(re * -2.0));
} else if (re <= 5.940568352251136e-298) {
tmp = 0.5 * ((fabs(im) * sqrt(2.0)) / sqrt(sqrt((im * im) + (re * re)) - re));
} else if (re <= 4.943285085157152e+144) {
tmp = 0.5 * sqrt(2.0 * (re + sqrt((im * im) + (re * re))));
} else {
tmp = 0.5 * sqrt(2.0 * (re + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.8 |
|---|---|
| Target | 33.6 |
| Herbie | 19.4 |
if re < -6.2492827667685015e187Initial program 64.0
rmApplied flip-+_binary64_243964.0
Applied associate-*r/_binary64_240764.0
Applied sqrt-div_binary64_248264.0
Simplified51.1
Taylor expanded around -inf 20.0
Simplified20.0
if -6.2492827667685015e187 < re < 5.9405683522511362e-298Initial program 41.3
rmApplied flip-+_binary64_243941.1
Applied associate-*r/_binary64_240741.2
Applied sqrt-div_binary64_248241.3
Simplified30.5
rmApplied sqrt-prod_binary64_248130.6
Simplified22.0
if 5.9405683522511362e-298 < re < 4.9432850851571519e144Initial program 21.1
if 4.9432850851571519e144 < re Initial program 60.9
Taylor expanded around inf 7.1
Final simplification19.4
herbie shell --seed 2020342
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))