0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \le -6.71816999819686615 \cdot 10^{-27}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{0 + {im}^{2}}{\mathsf{hypot}\left(re, im\right) - re}}\\
\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 <= -6.718169998196866e-27)) {
temp = (0.5 * sqrt((2.0 * ((0.0 + pow(im, 2.0)) / (hypot(re, im) - re)))));
} 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.6 |
|---|---|
| Target | 33.5 |
| Herbie | 11.5 |
if re < -6.718169998196866e-27Initial program 56.8
rmApplied flip-+56.8
Simplified40.3
Simplified30.9
if -6.718169998196866e-27 < re Initial program 31.9
rmApplied *-un-lft-identity31.9
Applied sqrt-prod31.9
Simplified4.3
Final simplification11.5
herbie shell --seed 2020058 +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)))))