0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -1.3575803483129278 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2 \cdot \left(im \cdot im\right)}}{\sqrt{\left(-re\right) - re}}\\
\mathbf{elif}\;re \leq 7.1702286480625436 \cdot 10^{-301}:\\
\;\;\;\;0.5 \cdot \left(\frac{\sqrt{2}}{\sqrt{\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 1.700198478212555 \cdot 10^{+134}:\\
\;\;\;\;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 -1.3575803483129278e+154)
(* 0.5 (/ (sqrt (* 2.0 (* im im))) (sqrt (- (- re) re))))
(if (<= re 7.1702286480625436e-301)
(*
0.5
(*
(/ (sqrt 2.0) (sqrt (sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(/ (fabs im) (sqrt (sqrt (- (sqrt (+ (* im im) (* re re))) re))))))
(if (<= re 1.700198478212555e+134)
(* 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 <= -1.3575803483129278e+154) {
tmp = 0.5 * (sqrt(2.0 * (im * im)) / sqrt(-re - re));
} else if (re <= 7.1702286480625436e-301) {
tmp = 0.5 * ((sqrt(2.0) / sqrt(sqrt(sqrt((im * im) + (re * re)) - re))) * (fabs(im) / sqrt(sqrt(sqrt((im * im) + (re * re)) - re))));
} else if (re <= 1.700198478212555e+134) {
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.7 |
|---|---|
| Target | 33.5 |
| Herbie | 18.7 |
if re < -1.3575803483129278e154Initial program 64.0
rmApplied flip-+_binary64_346264.0
Applied associate-*r/_binary64_343064.0
Applied sqrt-div_binary64_350564.0
Simplified51.2
Taylor expanded around -inf 20.2
if -1.3575803483129278e154 < re < 7.1702286480625436e-301Initial program 40.4
rmApplied flip-+_binary64_346240.2
Applied associate-*r/_binary64_343040.2
Applied sqrt-div_binary64_350540.3
Simplified30.3
rmApplied add-sqr-sqrt_binary64_351030.4
Applied sqrt-prod_binary64_350430.5
Applied times-frac_binary64_349430.4
Simplified20.9
if 7.1702286480625436e-301 < re < 1.70019847821255504e134Initial program 19.8
if 1.70019847821255504e134 < re Initial program 57.8
Taylor expanded around inf 8.4
Final simplification18.7
herbie shell --seed 2021024
(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)))))