0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -1.5121543370492806 \cdot 10^{+69}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}\\
\mathbf{elif}\;re \leq -1.5994446716436156 \cdot 10^{-18}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 6.424283181987542 \cdot 10^{-300}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im \cdot im}{\sqrt{im \cdot im + re \cdot re} - re}}\\
\mathbf{elif}\;re \leq 1.9018558815767983 \cdot 10^{+73}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\sqrt{im \cdot im + re \cdot re}} \cdot \sqrt{\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.5121543370492806e+69)
(*
0.5
(/ (sqrt (* (* im im) 2.0)) (sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re -1.5994446716436156e-18)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(if (<= re 6.424283181987542e-300)
(*
0.5
(sqrt (* 2.0 (/ (* im im) (- (sqrt (+ (* im im) (* re re))) re)))))
(if (<= re 1.9018558815767983e+73)
(*
0.5
(sqrt
(*
2.0
(+
re
(*
(sqrt (sqrt (+ (* im im) (* re re))))
(sqrt (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.5121543370492806e+69) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(sqrt((im * im) + (re * re)) - re));
} else if (re <= -1.5994446716436156e-18) {
tmp = 0.5 * sqrt(2.0 * (re + im));
} else if (re <= 6.424283181987542e-300) {
tmp = 0.5 * sqrt(2.0 * ((im * im) / (sqrt((im * im) + (re * re)) - re)));
} else if (re <= 1.9018558815767983e+73) {
tmp = 0.5 * sqrt(2.0 * (re + (sqrt(sqrt((im * im) + (re * re))) * sqrt(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.5 |
|---|---|
| Target | 33.7 |
| Herbie | 28.1 |
if re < -1.5121543370492806e69Initial program 59.8
rmApplied flip-+_binary6459.8
Applied associate-*r/_binary6459.8
Applied sqrt-div_binary6459.8
Simplified42.8
if -1.5121543370492806e69 < re < -1.5994446716436156e-18Initial program 45.0
Taylor expanded around 0 49.3
if -1.5994446716436156e-18 < re < 6.42428318198754199e-300Initial program 34.4
rmApplied flip-+_binary6434.1
Simplified31.0
if 6.42428318198754199e-300 < re < 1.90185588157679834e73Initial program 22.2
rmApplied add-sqr-sqrt_binary6422.3
if 1.90185588157679834e73 < re Initial program 47.4
Taylor expanded around inf 11.9
Final simplification28.1
herbie shell --seed 2020232
(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)))))