0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -5.951936524466467 \cdot 10^{+118}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \frac{\left|im\right|}{\sqrt{re \cdot -2}}\right)\\
\mathbf{elif}\;re \leq -4.919411827174503 \cdot 10^{-303}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{\sqrt{2}} \cdot \left(\sqrt{\sqrt{2}} \cdot \frac{\left|im\right|}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}\right)\right)\\
\mathbf{elif}\;re \leq 1.7095004368937527 \cdot 10^{-227}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-im\right)}\\
\mathbf{elif}\;re \leq 5.843883136633396 \cdot 10^{+151}:\\
\;\;\;\;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 -5.951936524466467e+118)
(* 0.5 (* (sqrt 2.0) (/ (fabs im) (sqrt (* re -2.0)))))
(if (<= re -4.919411827174503e-303)
(*
0.5
(*
(sqrt (sqrt 2.0))
(*
(sqrt (sqrt 2.0))
(/ (fabs im) (sqrt (- (sqrt (+ (* re re) (* im im))) re))))))
(if (<= re 1.7095004368937527e-227)
(* 0.5 (sqrt (* 2.0 (- im))))
(if (<= re 5.843883136633396e+151)
(* 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 <= -5.951936524466467e+118) {
tmp = 0.5 * (sqrt(2.0) * (fabs(im) / sqrt(re * -2.0)));
} else if (re <= -4.919411827174503e-303) {
tmp = 0.5 * (sqrt(sqrt(2.0)) * (sqrt(sqrt(2.0)) * (fabs(im) / sqrt(sqrt((re * re) + (im * im)) - re))));
} else if (re <= 1.7095004368937527e-227) {
tmp = 0.5 * sqrt(2.0 * -im);
} else if (re <= 5.843883136633396e+151) {
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 | 38.3 |
|---|---|
| Target | 33.2 |
| Herbie | 17.1 |
if re < -5.95193652446646687e118Initial program 62.3
rmApplied flip-+_binary64_243962.3
Applied associate-*r/_binary64_240762.3
Applied sqrt-div_binary64_248262.3
Simplified45.9
rmApplied *-un-lft-identity_binary64_246545.9
Applied sqrt-prod_binary64_248145.9
Applied sqrt-prod_binary64_248145.9
Applied times-frac_binary64_247146.0
Simplified46.0
Simplified43.7
Taylor expanded around -inf 9.3
Simplified9.3
if -5.95193652446646687e118 < re < -4.9194118271745028e-303Initial program 39.0
rmApplied flip-+_binary64_243938.8
Applied associate-*r/_binary64_240738.8
Applied sqrt-div_binary64_248238.9
Simplified30.1
rmApplied *-un-lft-identity_binary64_246530.1
Applied sqrt-prod_binary64_248130.1
Applied sqrt-prod_binary64_248130.2
Applied times-frac_binary64_247130.2
Simplified30.2
Simplified20.3
rmApplied add-sqr-sqrt_binary64_248720.3
Applied associate-*l*_binary64_240620.3
Simplified20.3
if -4.9194118271745028e-303 < re < 1.7095004368937527e-227Initial program 28.3
Taylor expanded around -inf 34.0
Simplified34.0
if 1.7095004368937527e-227 < re < 5.84388313663339647e151Initial program 17.6
if 5.84388313663339647e151 < re Initial program 62.9
Taylor expanded around 0 8.8
Simplified7.7
Final simplification17.1
herbie shell --seed 2021027
(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)))))