0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.5991937408382053 \cdot 10^{+162}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\left(im \cdot im\right) \cdot 2}}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq -5.2611073750173795 \cdot 10^{-303}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \frac{\sqrt{2}}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}\right)\\
\mathbf{elif}\;re \leq 5.6392861707035385 \cdot 10^{+122}:\\
\;\;\;\;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 -2.5991937408382053e+162)
(* 0.5 (/ (sqrt (* (* im im) 2.0)) (sqrt (* re -2.0))))
(if (<= re -5.2611073750173795e-303)
(*
0.5
(*
(fabs im)
(/ (sqrt 2.0) (sqrt (- (sqrt (+ (* im im) (* re re))) re)))))
(if (<= re 5.6392861707035385e+122)
(* 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 <= -2.5991937408382053e+162) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(re * -2.0));
} else if (re <= -5.2611073750173795e-303) {
tmp = 0.5 * (fabs(im) * (sqrt(2.0) / sqrt(sqrt((im * im) + (re * re)) - re)));
} else if (re <= 5.6392861707035385e+122) {
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.4 |
|---|---|
| Target | 33.5 |
| Herbie | 18.6 |
if re < -2.59919374083820533e162Initial program 64.0
rmApplied flip-+_binary64_246164.0
Applied associate-*r/_binary64_242964.0
Applied sqrt-div_binary64_250464.0
Simplified50.5
Taylor expanded around -inf 18.7
Simplified18.7
if -2.59919374083820533e162 < re < -5.26110737501737954e-303Initial program 40.1
rmApplied flip-+_binary64_246139.9
Applied associate-*r/_binary64_242939.9
Applied sqrt-div_binary64_250440.0
Simplified29.7
rmApplied *-un-lft-identity_binary64_248729.7
Applied sqrt-prod_binary64_250329.7
Applied sqrt-prod_binary64_250329.7
Applied times-frac_binary64_249329.7
Simplified20.7
if -5.26110737501737954e-303 < re < 5.63928617070353848e122Initial program 20.6
if 5.63928617070353848e122 < re Initial program 56.6
Taylor expanded around inf 8.9
Final simplification18.6
herbie shell --seed 2020289
(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)))))