0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -1.2621472493207276 \cdot 10^{+156}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2 \cdot \left(im \cdot im\right)}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq -1.7332866166362553 \cdot 10^{-302}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{\frac{2}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}} \cdot \frac{\left|im\right|}{\sqrt{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}}\right)\\
\mathbf{elif}\;re \leq 3.1850954331301157 \cdot 10^{+65}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{im \cdot im + re \cdot re}\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{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 -1.2621472493207276e+156)
(* 0.5 (/ (sqrt (* 2.0 (* im im))) (sqrt (* re -2.0))))
(if (<= re -1.7332866166362553e-302)
(*
0.5
(*
(sqrt (/ 2.0 (sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(/ (fabs im) (sqrt (sqrt (- (sqrt (+ (* im im) (* re re))) re))))))
(if (<= re 3.1850954331301157e+65)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (+ (* im im) (* re re)))))))
(* 0.5 (* 2.0 (sqrt 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 <= -1.2621472493207276e+156) {
tmp = 0.5 * (sqrt(2.0 * (im * im)) / sqrt(re * -2.0));
} else if (re <= -1.7332866166362553e-302) {
tmp = 0.5 * (sqrt(2.0 / sqrt(sqrt((im * im) + (re * re)) - re)) * (fabs(im) / sqrt(sqrt(sqrt((im * im) + (re * re)) - re))));
} else if (re <= 3.1850954331301157e+65) {
tmp = 0.5 * sqrt(2.0 * (re + sqrt((im * im) + (re * re))));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.4 |
|---|---|
| Target | 33.4 |
| Herbie | 19.1 |
if re < -1.26214724932072755e156Initial program 64.0
rmApplied flip-+_binary64_243964.0
Applied associate-*r/_binary64_240764.0
Applied sqrt-div_binary64_248264.0
Simplified50.1
Taylor expanded around -inf 19.9
Simplified19.9
if -1.26214724932072755e156 < re < -1.73328661663625528e-302Initial program 40.7
rmApplied flip-+_binary64_243940.5
Applied associate-*r/_binary64_240740.5
Applied sqrt-div_binary64_248240.6
Simplified30.5
rmApplied add-sqr-sqrt_binary64_248730.7
Applied sqrt-prod_binary64_248130.7
Applied times-frac_binary64_247130.7
Simplified21.0
rmApplied sqrt-undiv_binary64_248620.9
if -1.73328661663625528e-302 < re < 3.1850954331301157e65Initial program 21.0
if 3.1850954331301157e65 < re Initial program 46.0
Taylor expanded around 0 13.0
Simplified12.0
Final simplification19.1
herbie shell --seed 2021044
(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)))))