0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -1.3373774678016222 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2 \cdot \left(im \cdot im\right)}}{\sqrt{\left(-re\right) - re}}\\
\mathbf{elif}\;re \leq 1.3844586811812545 \cdot 10^{-253}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2} \cdot \left|im\right|}{\sqrt{\sqrt{im \cdot im + re \cdot re} - re}}\\
\mathbf{elif}\;re \leq 4.878191593403322 \cdot 10^{-211}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)\right)}\\
\mathbf{elif}\;re \leq 3.0147073164340627 \cdot 10^{+116}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{im \cdot im + re \cdot re}\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 -1.3373774678016222e+154)
(* 0.5 (/ (sqrt (* 2.0 (* im im))) (sqrt (- (- re) re))))
(if (<= re 1.3844586811812545e-253)
(*
0.5
(/
(* (sqrt 2.0) (fabs im))
(sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re 4.878191593403322e-211)
(* 0.5 (sqrt (* 2.0 (+ re (+ im (* 0.5 (/ (* re re) im)))))))
(if (<= re 3.0147073164340627e+116)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (+ (* im im) (* re re)))))))
(* 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 <= -1.3373774678016222e+154) {
tmp = 0.5 * (sqrt(2.0 * (im * im)) / sqrt(-re - re));
} else if (re <= 1.3844586811812545e-253) {
tmp = 0.5 * ((sqrt(2.0) * fabs(im)) / sqrt(sqrt((im * im) + (re * re)) - re));
} else if (re <= 4.878191593403322e-211) {
tmp = 0.5 * sqrt(2.0 * (re + (im + (0.5 * ((re * re) / im)))));
} else if (re <= 3.0147073164340627e+116) {
tmp = 0.5 * sqrt(2.0 * (re + sqrt((im * im) + (re * re))));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.6 |
|---|---|
| Target | 33.6 |
| Herbie | 19.0 |
if re < -1.33737746780162215e154Initial program 64.0
rmApplied flip-+_binary6464.0
Applied associate-*r/_binary6464.0
Applied sqrt-div_binary6464.0
Simplified50.9
Taylor expanded around -inf 20.4
if -1.33737746780162215e154 < re < 1.3844586811812545e-253Initial program 39.2
rmApplied flip-+_binary6439.2
Applied associate-*r/_binary6439.2
Applied sqrt-div_binary6439.4
Simplified30.0
rmApplied sqrt-prod_binary6430.1
Simplified21.6
if 1.3844586811812545e-253 < re < 4.878191593403322e-211Initial program 28.9
Taylor expanded around 0 33.2
Simplified33.2
if 4.878191593403322e-211 < re < 3.0147073164340627e116Initial program 18.0
if 3.0147073164340627e116 < re Initial program 54.6
Taylor expanded around 0 10.4
Simplified9.4
Final simplification19.0
herbie shell --seed 2021111
(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)))))