0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
\mathbf{if}\;re \leq -5.541738335196269 \cdot 10^{+142}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot \frac{im}{re \cdot -2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{im \cdot im + re \cdot re}\\
\mathbf{if}\;re \leq -1.2662953255596096 \cdot 10^{-124}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2 \cdot \left(im \cdot im\right)}}{\sqrt{t_0 - re}}\\
\mathbf{elif}\;re \leq 3.3257616803601 \cdot 10^{-235}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot \frac{im}{\left(-re\right) - im}\right)}\\
\mathbf{elif}\;re \leq 2.856357253236775 \cdot 10^{-181}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 3.398879661315353 \cdot 10^{-149}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - \left(im + 0.5 \cdot \frac{re \cdot re}{im}\right)\right)}\\
\mathbf{elif}\;re \leq 5.110855543795228 \cdot 10^{+86}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + t_0\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}\\
\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 -5.541738335196269e+142)
(* 0.5 (sqrt (* 2.0 (* im (/ im (* re -2.0))))))
(let* ((t_0 (sqrt (+ (* im im) (* re re)))))
(if (<= re -1.2662953255596096e-124)
(* 0.5 (/ (sqrt (* 2.0 (* im im))) (sqrt (- t_0 re))))
(if (<= re 3.3257616803601e-235)
(* 0.5 (sqrt (* 2.0 (* im (/ im (- (- re) im))))))
(if (<= re 2.856357253236775e-181)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(if (<= re 3.398879661315353e-149)
(* 0.5 (sqrt (* 2.0 (- re (+ im (* 0.5 (/ (* re re) im)))))))
(if (<= re 5.110855543795228e+86)
(* 0.5 (sqrt (* 2.0 (+ re t_0))))
(* 0.5 (* 2.0 (sqrt 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 <= -5.541738335196269e+142) {
tmp = 0.5 * sqrt(2.0 * (im * (im / (re * -2.0))));
} else {
double t_0 = sqrt((im * im) + (re * re));
double tmp_1;
if (re <= -1.2662953255596096e-124) {
tmp_1 = 0.5 * (sqrt(2.0 * (im * im)) / sqrt(t_0 - re));
} else if (re <= 3.3257616803601e-235) {
tmp_1 = 0.5 * sqrt(2.0 * (im * (im / (-re - im))));
} else if (re <= 2.856357253236775e-181) {
tmp_1 = 0.5 * sqrt(2.0 * (re + im));
} else if (re <= 3.398879661315353e-149) {
tmp_1 = 0.5 * sqrt(2.0 * (re - (im + (0.5 * ((re * re) / im)))));
} else if (re <= 5.110855543795228e+86) {
tmp_1 = 0.5 * sqrt(2.0 * (re + t_0));
} else {
tmp_1 = 0.5 * (2.0 * sqrt(re));
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 39.2 |
|---|---|
| Target | 34.0 |
| Herbie | 24.2 |
if re < -5.54173833519626875e142Initial program 63.3
rmApplied flip-+_binary6463.3
Simplified48.7
rmApplied *-un-lft-identity_binary6448.7
Applied times-frac_binary6448.3
Simplified48.3
Taylor expanded around -inf 24.3
Simplified24.3
if -5.54173833519626875e142 < re < -1.2662953255596096e-124Initial program 45.4
rmApplied flip-+_binary6445.4
Simplified30.2
rmApplied associate-*r/_binary6430.3
Applied sqrt-div_binary6428.7
if -1.2662953255596096e-124 < re < 3.32576168036010002e-235Initial program 30.1
rmApplied flip-+_binary6430.0
Simplified30.0
rmApplied *-un-lft-identity_binary6430.0
Applied times-frac_binary6428.3
Simplified28.3
Taylor expanded around -inf 34.2
Simplified34.2
if 3.32576168036010002e-235 < re < 2.85635725323677504e-181Initial program 27.2
rmApplied flip-+_binary6429.0
Simplified29.0
Taylor expanded around inf 35.1
if 2.85635725323677504e-181 < re < 3.3988796613153531e-149Initial program 29.7
rmApplied flip-+_binary6435.6
Simplified35.6
Taylor expanded around -inf 38.6
Simplified38.6
if 3.3988796613153531e-149 < re < 5.1108555437952284e86Initial program 17.0
rmApplied *-un-lft-identity_binary6417.0
Applied *-un-lft-identity_binary6417.0
Applied distribute-lft-out_binary6417.0
Simplified17.0
if 5.1108555437952284e86 < re Initial program 50.4
rmApplied flip-+_binary6463.0
Simplified62.1
Taylor expanded around 0 11.6
Simplified10.6
Final simplification24.2
herbie shell --seed 2021198
(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)))))