0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;im \leq -3.4810819035158894 \cdot 10^{+153}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\left(-im\right) - re}}\right)\\
\mathbf{elif}\;im \leq -4.06564811773753 \cdot 10^{-259}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\sqrt{im \cdot im + re \cdot re} - re}}\right)\\
\mathbf{elif}\;im \leq 1.1743424555098952 \cdot 10^{-197}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\
\mathbf{elif}\;im \leq 8.731569751909133 \cdot 10^{-179}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + re\right)}\\
\mathbf{elif}\;im \leq 1.8553121509605384 \cdot 10^{-162}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\
\mathbf{elif}\;im \leq 2.6357224810606306 \cdot 10^{+116}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \sqrt{\frac{2}{\sqrt{im \cdot im + re \cdot re} - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + 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 (<= im -3.4810819035158894e+153)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- (- im) re)))))
(if (<= im -4.06564811773753e-259)
(* 0.5 (* (fabs im) (sqrt (/ 2.0 (- (sqrt (+ (* im im) (* re re))) re)))))
(if (<= im 1.1743424555098952e-197)
(* 0.5 (sqrt (* 2.0 (+ re re))))
(if (<= im 8.731569751909133e-179)
(* 0.5 (sqrt (* 2.0 (+ im re))))
(if (<= im 1.8553121509605384e-162)
(* 0.5 (sqrt (* 2.0 (+ re re))))
(if (<= im 2.6357224810606306e+116)
(*
0.5
(*
(fabs im)
(sqrt (/ 2.0 (- (sqrt (+ (* im im) (* re re))) re)))))
(* 0.5 (sqrt (* 2.0 (+ im 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 (im <= -3.4810819035158894e+153) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (-im - re)));
} else if (im <= -4.06564811773753e-259) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (sqrt((im * im) + (re * re)) - re)));
} else if (im <= 1.1743424555098952e-197) {
tmp = 0.5 * sqrt(2.0 * (re + re));
} else if (im <= 8.731569751909133e-179) {
tmp = 0.5 * sqrt(2.0 * (im + re));
} else if (im <= 1.8553121509605384e-162) {
tmp = 0.5 * sqrt(2.0 * (re + re));
} else if (im <= 2.6357224810606306e+116) {
tmp = 0.5 * (fabs(im) * sqrt(2.0 / (sqrt((im * im) + (re * re)) - re)));
} else {
tmp = 0.5 * sqrt(2.0 * (im + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.0 |
|---|---|
| Target | 33.1 |
| Herbie | 23.1 |
if im < -3.48108190351588939e153Initial program 63.9
rmApplied flip-+_binary6463.9
Applied associate-*r/_binary6464.0
Applied sqrt-div_binary6464.0
Simplified64.0
rmApplied *-un-lft-identity_binary6464.0
Applied sqrt-prod_binary6464.0
Applied sqrt-prod_binary6463.9
Applied times-frac_binary6463.9
Simplified62.4
Simplified62.4
rmApplied sqrt-undiv_binary6462.4
Taylor expanded around -inf 8.4
Simplified8.4
if -3.48108190351588939e153 < im < -4.0656481177375301e-259 or 1.85531215096053838e-162 < im < 2.6357224810606306e116Initial program 26.5
rmApplied flip-+_binary6436.2
Applied associate-*r/_binary6436.2
Applied sqrt-div_binary6436.4
Simplified28.7
rmApplied *-un-lft-identity_binary6428.7
Applied sqrt-prod_binary6428.7
Applied sqrt-prod_binary6428.7
Applied times-frac_binary6428.7
Simplified26.7
Simplified26.7
rmApplied sqrt-undiv_binary6426.6
if -4.0656481177375301e-259 < im < 1.1743424555098952e-197 or 8.73156975190913269e-179 < im < 1.85531215096053838e-162Initial program 43.5
Taylor expanded around inf 34.1
if 1.1743424555098952e-197 < im < 8.73156975190913269e-179 or 2.6357224810606306e116 < im Initial program 53.5
Taylor expanded around 0 12.5
Final simplification23.1
herbie shell --seed 2020224
(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)))))