0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.0754615002920678 \cdot 10^{+66}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\sqrt{2}} \cdot \left(\left|im\right| \cdot \sqrt{\sqrt{2}}\right)}{\sqrt{re \cdot -2}}\\
\mathbf{elif}\;re \leq 6.975022293022832 \cdot 10^{-103}:\\
\;\;\;\;0.5 \cdot \left(\left|im\right| \cdot \frac{\sqrt{2}}{\sqrt{\sqrt{re \cdot re + im \cdot im} - re}}\right)\\
\mathbf{elif}\;re \leq 2.6578910116797832 \cdot 10^{-86} \lor \neg \left(re \leq 1.81655221984481 \cdot 10^{-74}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im \cdot im}{\sqrt{re \cdot re + im \cdot im} - re}}\\
\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 -2.0754615002920678e+66)
(*
0.5
(/
(* (sqrt (sqrt 2.0)) (* (fabs im) (sqrt (sqrt 2.0))))
(sqrt (* re -2.0))))
(if (<= re 6.975022293022832e-103)
(*
0.5
(*
(fabs im)
(/ (sqrt 2.0) (sqrt (- (sqrt (+ (* re re) (* im im))) re)))))
(if (or (<= re 2.6578910116797832e-86) (not (<= re 1.81655221984481e-74)))
(* 0.5 (sqrt (* 2.0 (+ re re))))
(*
0.5
(sqrt (* 2.0 (/ (* im im) (- (sqrt (+ (* re re) (* im im))) 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 <= -2.0754615002920678e+66) {
tmp = 0.5 * ((sqrt(sqrt(2.0)) * (fabs(im) * sqrt(sqrt(2.0)))) / sqrt(re * -2.0));
} else if (re <= 6.975022293022832e-103) {
tmp = 0.5 * (fabs(im) * (sqrt(2.0) / sqrt(sqrt((re * re) + (im * im)) - re)));
} else if ((re <= 2.6578910116797832e-86) || !(re <= 1.81655221984481e-74)) {
tmp = 0.5 * sqrt(2.0 * (re + re));
} else {
tmp = 0.5 * sqrt(2.0 * ((im * im) / (sqrt((re * re) + (im * im)) - re)));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.9 |
|---|---|
| Target | 33.9 |
| Herbie | 20.6 |
if re < -2.0754615002920678e66Initial program 59.5
rmApplied flip-+_binary6459.5
Applied associate-*r/_binary6459.5
Applied sqrt-div_binary6459.6
Simplified41.7
rmApplied sqrt-prod_binary6441.7
Simplified37.3
rmApplied add-sqr-sqrt_binary6437.4
Applied associate-*r*_binary6437.3
Taylor expanded around -inf 11.3
Simplified11.3
if -2.0754615002920678e66 < re < 6.97502229302283246e-103Initial program 34.0
rmApplied flip-+_binary6435.6
Applied associate-*r/_binary6435.6
Applied sqrt-div_binary6435.8
Simplified31.8
rmApplied *-un-lft-identity_binary6431.8
Applied sqrt-prod_binary6431.8
Applied sqrt-prod_binary6431.9
Applied times-frac_binary6431.9
Simplified25.4
if 6.97502229302283246e-103 < re < 2.65789101167978319e-86 or 1.8165522198448099e-74 < re Initial program 34.5
Taylor expanded around inf 18.6
if 2.65789101167978319e-86 < re < 1.8165522198448099e-74Initial program 17.7
rmApplied flip-+_binary6440.5
Simplified40.5
Final simplification20.6
herbie shell --seed 2020233
(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)))))