0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -7.802120309188862 \cdot 10^{+71}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2}}{\frac{\sqrt{re \cdot -2}}{\left|im\right|}}\\
\mathbf{elif}\;re \leq -8.72945174690765 \cdot 10^{-278}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2}}{\frac{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}{\left|im\right|}}\\
\mathbf{elif}\;re \leq 2.6083228972730953 \cdot 10^{+78}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\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 -7.802120309188862e+71)
(* 0.5 (/ (sqrt 2.0) (/ (sqrt (* re -2.0)) (fabs im))))
(if (<= re -8.72945174690765e-278)
(*
0.5
(/
(sqrt 2.0)
(/ (sqrt (- (sqrt (+ (* re re) (* im im))) re)) (fabs im))))
(if (<= re 2.6083228972730953e+78)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))))
(* 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 <= -7.802120309188862e+71) {
tmp = 0.5 * (sqrt(2.0) / (sqrt(re * -2.0) / fabs(im)));
} else if (re <= -8.72945174690765e-278) {
tmp = 0.5 * (sqrt(2.0) / (sqrt(sqrt((re * re) + (im * im)) - re) / fabs(im)));
} else if (re <= 2.6083228972730953e+78) {
tmp = 0.5 * sqrt(2.0 * (re + sqrt((re * re) + (im * im))));
} else {
tmp = 0.5 * sqrt(2.0 * (re + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.6 |
|---|---|
| Target | 33.9 |
| Herbie | 17.7 |
if re < -7.8021203091888617e71Initial program 59.6
rmApplied flip-+_binary64_243959.6
Applied associate-*r/_binary64_240759.6
Applied sqrt-div_binary64_248259.6
Simplified43.0
rmApplied sqrt-prod_binary64_248143.1
Applied associate-/l*_binary64_241043.1
Simplified39.1
Taylor expanded around -inf 12.7
Simplified12.7
if -7.8021203091888617e71 < re < -8.7294517469076501e-278Initial program 37.7
rmApplied flip-+_binary64_243937.5
Applied associate-*r/_binary64_240737.5
Applied sqrt-div_binary64_248237.6
Simplified30.4
rmApplied sqrt-prod_binary64_248130.5
Applied associate-/l*_binary64_241030.5
Simplified20.7
if -8.7294517469076501e-278 < re < 2.60832289727309527e78Initial program 22.0
if 2.60832289727309527e78 < re Initial program 48.6
Taylor expanded around inf 10.5
Final simplification17.7
herbie shell --seed 2021015
(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)))))