0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.4368798138824472 \cdot 10^{+141}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq 6.71142159152561 \cdot 10^{-309}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\sqrt{im \cdot im + re \cdot re} - re}}\right)\\
\mathbf{elif}\;re \leq 2.0982341812511796 \cdot 10^{+68}:\\
\;\;\;\;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.4368798138824472e+141)
(* 0.5 (/ (sqrt (* (* im im) 2.0)) (sqrt (* re -2.0))))
(if (<= re 6.71142159152561e-309)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- (sqrt (+ (* im im) (* re re))) re)))))
(if (<= re 2.0982341812511796e+68)
(* 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.4368798138824472e+141) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(re * -2.0));
} else if (re <= 6.71142159152561e-309) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (sqrt((im * im) + (re * re)) - re)));
} else if (re <= 2.0982341812511796e+68) {
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.4 |
|---|---|
| Target | 33.5 |
| Herbie | 18.7 |
if re < -2.4368798138824472e141Initial program 63.3
rmApplied flip-+_binary64_243963.3
Applied associate-*r/_binary64_240763.3
Applied sqrt-div_binary64_248263.3
Simplified49.4
Taylor expanded around -inf 20.3
Simplified20.3
if -2.4368798138824472e141 < re < 6.711421591525609e-309Initial program 39.4
rmApplied flip-+_binary64_243939.2
Applied associate-*r/_binary64_240739.3
Applied sqrt-div_binary64_248239.4
Simplified29.9
rmApplied *-un-lft-identity_binary64_246529.9
Applied sqrt-prod_binary64_248129.9
Applied sqrt-prod_binary64_248130.0
Applied times-frac_binary64_247130.0
Simplified20.2
Simplified20.2
rmApplied sqrt-undiv_binary64_248620.1
if 6.711421591525609e-309 < re < 2.09823418125117964e68Initial program 20.5
if 2.09823418125117964e68 < re Initial program 47.5
Taylor expanded around inf 11.9
Final simplification18.7
herbie shell --seed 2020356
(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)))))