0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.6658846711910334 \cdot 10^{+157}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq -4.1578241603242444 \cdot 10^{-250}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \frac{\sqrt{2}}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}\right)\\
\mathbf{elif}\;re \leq 2.1575500997764812 \cdot 10^{+145}:\\
\;\;\;\;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 -2.6658846711910334e+157)
(* 0.5 (/ (sqrt (* (* im im) 2.0)) (sqrt (* re -2.0))))
(if (<= re -4.1578241603242444e-250)
(*
0.5
(*
(fabs im)
(/ (sqrt 2.0) (sqrt (- (sqrt (+ (* im im) (* re re))) re)))))
(if (<= re 2.1575500997764812e+145)
(* 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 <= -2.6658846711910334e+157) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(re * -2.0));
} else if (re <= -4.1578241603242444e-250) {
tmp = 0.5 * (fabs(im) * (sqrt(2.0) / sqrt(sqrt((im * im) + (re * re)) - re)));
} else if (re <= 2.1575500997764812e+145) {
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.9 |
|---|---|
| Target | 33.9 |
| Herbie | 18.8 |
if re < -2.6658846711910334e157Initial program 64.0
rmApplied flip-+_binary64_243964.0
Applied associate-*r/_binary64_240764.0
Applied sqrt-div_binary64_248264.0
Simplified51.3
Taylor expanded around -inf 19.0
Simplified19.0
if -2.6658846711910334e157 < re < -4.15782416032424439e-250Initial program 41.7
rmApplied flip-+_binary64_243941.6
Applied associate-*r/_binary64_240741.6
Applied sqrt-div_binary64_248241.7
Simplified29.8
rmApplied *-un-lft-identity_binary64_246529.8
Applied sqrt-prod_binary64_248129.8
Applied sqrt-prod_binary64_248129.9
Applied times-frac_binary64_247129.9
Simplified19.2
if -4.15782416032424439e-250 < re < 2.15755009977648121e145Initial program 21.9
if 2.15755009977648121e145 < re Initial program 60.9
Taylor expanded around inf 8.4
Final simplification18.8
herbie shell --seed 2020346
(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)))))