0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -1.3365884841721249 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{im - re}}\right)\\
\mathbf{elif}\;re \leq 2.5976900549837345 \cdot 10^{-305}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\sqrt{re \cdot re + im \cdot im} - re}}\right)\\
\mathbf{elif}\;re \leq 6.503475815263617 \cdot 10^{+54}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\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.3365884841721249e+154)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- im re)))))
(if (<= re 2.5976900549837345e-305)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(if (<= re 6.503475815263617e+54)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))))
(* 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.3365884841721249e+154) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (im - re)));
} else if (re <= 2.5976900549837345e-305) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (sqrt((re * re) + (im * im)) - re)));
} else if (re <= 6.503475815263617e+54) {
tmp = 0.5 * sqrt(2.0 * (re + sqrt((re * re) + (im * im))));
} 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 | 20.9 |
if re < -1.3365884841721249e154Initial program 64.0
rmApplied flip-+_binary64_209864.0
Applied associate-*r/_binary64_206664.0
Applied sqrt-div_binary64_214164.0
Simplified50.5
rmApplied *-un-lft-identity_binary64_212450.5
Applied sqrt-prod_binary64_214050.5
Applied sqrt-prod_binary64_214050.5
Applied times-frac_binary64_213050.5
Simplified50.1
rmApplied sqrt-undiv_binary64_214550.1
Taylor expanded around 0 39.6
if -1.3365884841721249e154 < re < 2.59769005498373445e-305Initial program 40.3
rmApplied flip-+_binary64_209840.1
Applied associate-*r/_binary64_206640.1
Applied sqrt-div_binary64_214140.2
Simplified30.3
rmApplied *-un-lft-identity_binary64_212430.3
Applied sqrt-prod_binary64_214030.3
Applied sqrt-prod_binary64_214030.3
Applied times-frac_binary64_213030.3
Simplified20.4
rmApplied sqrt-undiv_binary64_214520.2
if 2.59769005498373445e-305 < re < 6.5034758152636166e54Initial program 20.9
if 6.5034758152636166e54 < re Initial program 44.8
Taylor expanded around 0 12.4
Simplified11.4
Final simplification20.9
herbie shell --seed 2020344
(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)))))