0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -3.306189866184851 \cdot 10^{+67}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2}}{\frac{\sqrt{\left(-re\right) - re}}{\left|im\right|}}\\
\mathbf{elif}\;re \leq 6.858325427122592 \cdot 10^{-295}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{\frac{\sqrt{2}}{\sqrt{re \cdot re + im \cdot im} - re}} \cdot \left(\left|im\right| \cdot \sqrt{\sqrt{2}}\right)\right)\\
\mathbf{elif}\;re \leq 1.0440481246371513 \cdot 10^{+130}:\\
\;\;\;\;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 -3.306189866184851e+67)
(* 0.5 (/ (sqrt 2.0) (/ (sqrt (- (- re) re)) (fabs im))))
(if (<= re 6.858325427122592e-295)
(*
0.5
(*
(sqrt (/ (sqrt 2.0) (- (sqrt (+ (* re re) (* im im))) re)))
(* (fabs im) (sqrt (sqrt 2.0)))))
(if (<= re 1.0440481246371513e+130)
(* 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 <= -3.306189866184851e+67) {
tmp = 0.5 * (sqrt(2.0) / (sqrt(-re - re) / fabs(im)));
} else if (re <= 6.858325427122592e-295) {
tmp = 0.5 * (sqrt(sqrt(2.0) / (sqrt((re * re) + (im * im)) - re)) * (fabs(im) * sqrt(sqrt(2.0))));
} else if (re <= 1.0440481246371513e+130) {
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 | 39.2 |
|---|---|
| Target | 34.0 |
| Herbie | 17.7 |
if re < -3.3061898661848511e67Initial program 59.3
rmApplied flip-+_binary64_209859.3
Applied associate-*r/_binary64_206659.3
Applied sqrt-div_binary64_214159.3
Simplified41.4
rmApplied sqrt-prod_binary64_214041.4
Applied associate-/l*_binary64_206941.4
Simplified37.6
Taylor expanded around -inf 12.7
Simplified12.7
if -3.3061898661848511e67 < re < 6.8583254271225918e-295Initial program 38.3
rmApplied flip-+_binary64_209838.1
Applied associate-*r/_binary64_206638.1
Applied sqrt-div_binary64_214138.3
Simplified31.8
rmApplied sqrt-prod_binary64_214031.9
Applied associate-/l*_binary64_206931.9
Simplified22.0
rmApplied div-inv_binary64_212122.1
Applied add-sqr-sqrt_binary64_214622.1
Applied times-frac_binary64_213022.0
Simplified22.0
rmApplied sqrt-undiv_binary64_214521.9
if 6.8583254271225918e-295 < re < 1.04404812463715129e130Initial program 20.6
if 1.04404812463715129e130 < re Initial program 57.6
Taylor expanded around 0 9.6
Simplified8.5
Final simplification17.7
herbie shell --seed 2021060
(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)))))