0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \le -2.05529431931853659 \cdot 10^{44}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im \cdot im}{\mathsf{fma}\left(-1, re, \mathsf{hypot}\left(re, im\right)\right)}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{1} \cdot \mathsf{hypot}\left(re, im\right) + re\right)}\\
\end{array}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 temp;
if ((re <= -2.0552943193185366e+44)) {
temp = (0.5 * sqrt((2.0 * ((im * im) / fma(-1.0, re, hypot(re, im))))));
} else {
temp = (0.5 * sqrt((2.0 * ((sqrt(1.0) * hypot(re, im)) + re))));
}
return temp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.3 |
|---|---|
| Target | 33.2 |
| Herbie | 11.5 |
if re < -2.0552943193185366e+44Initial program 58.5
rmApplied flip-+58.5
Simplified42.1
Simplified30.2
if -2.0552943193185366e+44 < re Initial program 32.8
rmApplied *-un-lft-identity32.8
Applied sqrt-prod32.8
Simplified6.5
Final simplification11.5
herbie shell --seed 2020066 +o rules:numerics
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(if (< re 0.0) (* 0.5 (* (sqrt 2) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2 (+ (sqrt (+ (* re re) (* im im))) re)))))