0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.45305725845355 \cdot 10^{+153}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2} \cdot \left|im\right|}{\sqrt{\left(\left(-re\right) - \frac{0.5 \cdot im}{\frac{re}{im}}\right) - re}}\\
\mathbf{elif}\;re \leq 1.2893888095222202 \cdot 10^{-306}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2} \cdot \left|im\right|}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}\\
\mathbf{elif}\;re \leq 3.1200050919961303 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\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.45305725845355e+153)
(*
0.5
(/
(* (sqrt 2.0) (fabs im))
(sqrt (- (- (- re) (/ (* 0.5 im) (/ re im))) re))))
(if (<= re 1.2893888095222202e-306)
(*
0.5
(/
(* (sqrt 2.0) (fabs im))
(sqrt (- (sqrt (+ (* re re) (* im im))) re))))
(if (<= re 3.1200050919961303e+102)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))))
(* 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.45305725845355e+153) {
tmp = 0.5 * ((sqrt(2.0) * fabs(im)) / sqrt((-re - ((0.5 * im) / (re / im))) - re));
} else if (re <= 1.2893888095222202e-306) {
tmp = 0.5 * ((sqrt(2.0) * fabs(im)) / sqrt(sqrt((re * re) + (im * im)) - re));
} else if (re <= 3.1200050919961303e+102) {
tmp = 0.5 * sqrt(2.0 * (re + sqrt((re * re) + (im * im))));
} else {
tmp = 0.5 * sqrt(2.0 * (re + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.9 |
|---|---|
| Target | 34.0 |
| Herbie | 17.4 |
if re < -2.45305725845354985e153Initial program 64.0
rmApplied flip-+_binary64_346264.0
Applied associate-*r/_binary64_343064.0
Applied sqrt-div_binary64_350564.0
Simplified51.9
rmApplied sqrt-prod_binary64_350451.9
Simplified51.4
Taylor expanded around -inf 16.7
Simplified8.2
if -2.45305725845354985e153 < re < 1.28938880952222021e-306Initial program 40.7
rmApplied flip-+_binary64_346240.5
Applied associate-*r/_binary64_343040.5
Applied sqrt-div_binary64_350540.6
Simplified30.5
rmApplied sqrt-prod_binary64_350430.6
Simplified21.3
if 1.28938880952222021e-306 < re < 3.12000509199613031e102Initial program 20.5
if 3.12000509199613031e102 < re Initial program 52.0
Taylor expanded around inf 9.8
Final simplification17.4
herbie shell --seed 2021176
(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)))))