0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -9.54588978322931 \cdot 10^{+243}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot \frac{im}{re \cdot -2}\right)}\\
\mathbf{elif}\;re \leq -1.348090976184754 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2 \cdot \left(im \cdot im\right)}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq -7.505771444393745 \cdot 10^{-145}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2} \cdot \left|im\right|}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}\\
\mathbf{elif}\;re \leq -2.361083726192336 \cdot 10^{-294}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot \frac{im}{im - re}\right)}\\
\mathbf{elif}\;re \leq 2.503501099244196 \cdot 10^{-297}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\
\mathbf{elif}\;re \leq 3.918472623130481 \cdot 10^{-292}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{elif}\;re \leq 2.996337957612594 \cdot 10^{+104}:\\
\;\;\;\;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 -9.54588978322931e+243)
(* 0.5 (sqrt (* 2.0 (* im (/ im (* re -2.0))))))
(if (<= re -1.348090976184754e+154)
(* 0.5 (/ (sqrt (* 2.0 (* im im))) (sqrt (* re -2.0))))
(if (<= re -7.505771444393745e-145)
(*
0.5
(/
(* (sqrt 2.0) (fabs im))
(sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re -2.361083726192336e-294)
(* 0.5 (sqrt (* 2.0 (* im (/ im (- im re))))))
(if (<= re 2.503501099244196e-297)
(* 0.5 (sqrt (* im -2.0)))
(if (<= re 3.918472623130481e-292)
(* 0.5 (sqrt (* 2.0 im)))
(if (<= re 2.996337957612594e+104)
(* 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 <= -9.54588978322931e+243) {
tmp = 0.5 * sqrt(2.0 * (im * (im / (re * -2.0))));
} else if (re <= -1.348090976184754e+154) {
tmp = 0.5 * (sqrt(2.0 * (im * im)) / sqrt(re * -2.0));
} else if (re <= -7.505771444393745e-145) {
tmp = 0.5 * ((sqrt(2.0) * fabs(im)) / sqrt(sqrt((im * im) + (re * re)) - re));
} else if (re <= -2.361083726192336e-294) {
tmp = 0.5 * sqrt(2.0 * (im * (im / (im - re))));
} else if (re <= 2.503501099244196e-297) {
tmp = 0.5 * sqrt(im * -2.0);
} else if (re <= 3.918472623130481e-292) {
tmp = 0.5 * sqrt(2.0 * im);
} else if (re <= 2.996337957612594e+104) {
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 | 19.7 |
if re < -9.54588978322930981e243Initial program 64.0
rmApplied flip-+_binary6464.0
Simplified49.2
rmApplied *-un-lft-identity_binary6449.2
Applied times-frac_binary6448.8
Simplified48.8
Taylor expanded around -inf 18.4
Simplified18.4
if -9.54588978322930981e243 < re < -1.348090976184754e154Initial program 64.0
rmApplied flip-+_binary6464.0
Applied associate-*r/_binary6464.0
Applied sqrt-div_binary6464.0
Simplified52.8
Taylor expanded around -inf 23.8
if -1.348090976184754e154 < re < -7.50577144439374481e-145Initial program 45.1
rmApplied flip-+_binary6445.1
Applied associate-*r/_binary6445.1
Applied sqrt-div_binary6445.2
Simplified29.1
rmApplied sqrt-prod_binary6429.2
Simplified15.3
if -7.50577144439374481e-145 < re < -2.3610837261923362e-294Initial program 31.8
rmApplied flip-+_binary6431.2
Simplified31.1
rmApplied *-un-lft-identity_binary6431.1
Applied times-frac_binary6428.9
Simplified28.9
Taylor expanded around 0 33.0
if -2.3610837261923362e-294 < re < 2.5035010992441961e-297Initial program 37.0
Taylor expanded around -inf 29.9
if 2.5035010992441961e-297 < re < 3.9184726231304811e-292Initial program 27.4
Taylor expanded around 0 24.2
if 3.9184726231304811e-292 < re < 2.99633795761259406e104Initial program 20.9
if 2.99633795761259406e104 < re Initial program 51.7
Taylor expanded around inf 10.6
Final simplification19.7
herbie shell --seed 2021110
(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)))))