0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\begin{array}{l}
\mathbf{if}\;re \le -4.37964942532106859 \cdot 10^{83}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{-2 \cdot re}{im}}}\\
\mathbf{elif}\;re \le -283.23902669347274:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{im - re}{im}}}\\
\mathbf{elif}\;re \le -1.448710066223221 \cdot 10^{-194}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{e^{\log \left(\sqrt{re \cdot re + im \cdot im} - re\right)}}{im}}}\\
\mathbf{elif}\;re \le -1.984730296439969 \cdot 10^{-262}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im}{\frac{im - re}{im}}}\\
\mathbf{elif}\;re \le 1.573305619337669 \cdot 10^{-228}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\
\mathbf{elif}\;re \le 3.9315901045752092 \cdot 10^{-191}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{2 \cdot im}}{\sqrt{\frac{im - re}{im}}}\\
\mathbf{elif}\;re \le 5.32364720038125515 \cdot 10^{39}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(2 \cdot 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 <= -4.3796494253210686e+83)) {
temp = (0.5 * sqrt((2.0 * (im / ((-2.0 * re) / im)))));
} else {
double temp_1;
if ((re <= -283.23902669347274)) {
temp_1 = (0.5 * sqrt((2.0 * (im / ((im - re) / im)))));
} else {
double temp_2;
if ((re <= -1.448710066223221e-194)) {
temp_2 = (0.5 * sqrt((2.0 * (im / (exp(log((sqrt(((re * re) + (im * im))) - re))) / im)))));
} else {
double temp_3;
if ((re <= -1.984730296439969e-262)) {
temp_3 = (0.5 * sqrt((2.0 * (im / ((im - re) / im)))));
} else {
double temp_4;
if ((re <= 1.573305619337669e-228)) {
temp_4 = (0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))));
} else {
double temp_5;
if ((re <= 3.931590104575209e-191)) {
temp_5 = (0.5 * (sqrt((2.0 * im)) / sqrt(((im - re) / im))));
} else {
double temp_6;
if ((re <= 5.323647200381255e+39)) {
temp_6 = (0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))));
} else {
temp_6 = (0.5 * sqrt((2.0 * (2.0 * re))));
}
temp_5 = temp_6;
}
temp_4 = temp_5;
}
temp_3 = temp_4;
}
temp_2 = temp_3;
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.7 |
|---|---|
| Target | 33.7 |
| Herbie | 24.7 |
if re < -4.3796494253210686e+83Initial program 60.2
rmApplied flip-+60.2
Simplified44.4
rmApplied unpow244.4
Applied associate-/l*44.1
Taylor expanded around -inf 26.4
if -4.3796494253210686e+83 < re < -283.23902669347274 or -1.448710066223221e-194 < re < -1.984730296439969e-262Initial program 41.0
rmApplied flip-+40.7
Simplified31.4
rmApplied unpow231.4
Applied associate-/l*30.4
Taylor expanded around 0 39.2
if -283.23902669347274 < re < -1.448710066223221e-194Initial program 37.6
rmApplied flip-+37.5
Simplified31.3
rmApplied unpow231.3
Applied associate-/l*27.5
rmApplied add-exp-log29.4
if -1.984730296439969e-262 < re < 1.573305619337669e-228 or 3.931590104575209e-191 < re < 5.323647200381255e+39Initial program 22.3
if 1.573305619337669e-228 < re < 3.931590104575209e-191Initial program 30.3
rmApplied flip-+32.4
Simplified32.4
rmApplied unpow232.4
Applied associate-/l*32.3
Taylor expanded around 0 34.8
rmApplied associate-*r/34.8
Applied sqrt-div35.0
if 5.323647200381255e+39 < re Initial program 43.9
rmApplied flip-+61.5
Simplified60.8
Taylor expanded around 0 13.6
Final simplification24.7
herbie shell --seed 2020057
(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)))))