0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \le -7.6699074942752878 \cdot 10^{-177}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{\mathsf{hypot}\left(re, im\right) - re}{im}}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(im, re\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 VAR;
if ((re <= -7.669907494275288e-177)) {
VAR = (0.5 * sqrt((2.0 * (im / ((hypot(re, im) - re) / im)))));
} else {
VAR = (0.5 * sqrt((2.0 * (hypot(im, re) + re))));
}
return VAR;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.7 |
|---|---|
| Target | 34.1 |
| Herbie | 6.3 |
if re < -7.669907494275288e-177Initial program 50.4
rmApplied flip-+50.3
Simplified38.9
Simplified32.6
rmApplied unpow232.6
Applied associate-/l*14.2
if -7.669907494275288e-177 < re Initial program 31.1
rmApplied +-commutative31.1
Applied hypot-def1.2
Final simplification6.3
herbie shell --seed 2020071 +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)))))