0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -9.929618555609528 \cdot 10^{-284}:\\
\;\;\;\;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 9.960539637944897 \cdot 10^{-227}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 3.3170403780581015 \cdot 10^{+89}:\\
\;\;\;\;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 -9.929618555609528e-284)
(*
0.5
(/ (sqrt (* (* im im) 2.0)) (sqrt (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re 9.960539637944897e-227)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(if (<= re 3.3170403780581015e+89)
(* 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 <= -9.929618555609528e-284) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(sqrt((im * im) + (re * re)) - re));
} else if (re <= 9.960539637944897e-227) {
tmp = 0.5 * sqrt(2.0 * (re + im));
} else if (re <= 3.3170403780581015e+89) {
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.5 |
|---|---|
| Target | 33.9 |
| Herbie | 26.4 |
if re < -9.9296185556095278e-284Initial program 46.2
rmApplied flip-+_binary64_278046.1
Applied associate-*r/_binary64_274846.1
Applied sqrt-div_binary64_282346.2
Simplified35.4
if -9.9296185556095278e-284 < re < 9.9605396379448968e-227Initial program 31.7
Taylor expanded around 0 31.3
if 9.9605396379448968e-227 < re < 3.3170403780581015e89Initial program 19.1
if 3.3170403780581015e89 < re Initial program 49.4
Taylor expanded around inf 10.8
Final simplification26.4
herbie shell --seed 2020358
(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)))))