0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.3838929425074713 \cdot 10^{+136}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq -6.527935055640734 \cdot 10^{-301}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\sqrt{im \cdot im + re \cdot re} - re}}\right)\\
\mathbf{elif}\;re \leq 1.1339651548786607 \cdot 10^{-217}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 2.3897943661054227 \cdot 10^{-18}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\left(-im\right) - 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.3838929425074713e+136)
(* 0.5 (/ (sqrt (* (* im im) 2.0)) (sqrt (* re -2.0))))
(if (<= re -6.527935055640734e-301)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- (sqrt (+ (* im im) (* re re))) re)))))
(if (<= re 1.1339651548786607e-217)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(if (<= re 2.3897943661054227e-18)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- (- im) 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.3838929425074713e+136) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(re * -2.0));
} else if (re <= -6.527935055640734e-301) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (sqrt((im * im) + (re * re)) - re)));
} else if (re <= 1.1339651548786607e-217) {
tmp = 0.5 * sqrt(2.0 * (re + im));
} else if (re <= 2.3897943661054227e-18) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (-im - re)));
} else {
tmp = 0.5 * sqrt(2.0 * (re + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.8 |
|---|---|
| Target | 33.6 |
| Herbie | 23.4 |
if re < -2.3838929425074713e136Initial program 63.0
rmApplied flip-+_binary64_142963.0
Applied associate-*r/_binary64_139763.0
Applied sqrt-div_binary64_147263.0
Simplified46.7
Taylor expanded around -inf 18.6
Simplified18.6
if -2.3838929425074713e136 < re < -6.527935055640734e-301Initial program 39.5
rmApplied flip-+_binary64_142939.3
Applied associate-*r/_binary64_139739.3
Applied sqrt-div_binary64_147239.4
Simplified30.1
rmApplied *-un-lft-identity_binary64_145530.1
Applied sqrt-prod_binary64_147130.1
Applied sqrt-prod_binary64_147130.2
Applied times-frac_binary64_146130.2
Simplified20.5
Simplified20.5
rmApplied sqrt-undiv_binary64_147620.3
if -6.527935055640734e-301 < re < 1.1339651548786607e-217Initial program 28.0
Taylor expanded around 0 31.9
if 1.1339651548786607e-217 < re < 2.3897943661054227e-18Initial program 21.4
rmApplied flip-+_binary64_142937.4
Applied associate-*r/_binary64_139737.5
Applied sqrt-div_binary64_147237.7
Simplified37.8
rmApplied *-un-lft-identity_binary64_145537.8
Applied sqrt-prod_binary64_147137.8
Applied sqrt-prod_binary64_147137.8
Applied times-frac_binary64_146137.8
Simplified37.3
Simplified37.3
rmApplied sqrt-undiv_binary64_147637.3
Taylor expanded around -inf 43.2
Simplified43.2
if 2.3897943661054227e-18 < re Initial program 38.5
Taylor expanded around inf 15.4
Final simplification23.4
herbie shell --seed 2020292
(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)))))