0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
\mathbf{if}\;im \leq -4.0810855285811026 \cdot 10^{-82}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{elif}\;im \leq 1.1023411135196444 \cdot 10^{-294}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \left(re + 0.5 \cdot \frac{im \cdot im}{re}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \frac{im \cdot im}{\sqrt{im \cdot im + re \cdot re} - re}}\\
\mathbf{if}\;im \leq 6.386439438427647 \cdot 10^{-106}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 9.645579323198895 \cdot 10^{-68}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(2 \cdot re\right)}\\
\mathbf{elif}\;im \leq 1.649882945586574 \cdot 10^{+32}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + 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 (<= im -4.0810855285811026e-82)
(* 0.5 (sqrt (* 2.0 (- re im))))
(if (<= im 1.1023411135196444e-294)
(* 0.5 (sqrt (* 2.0 (+ re (+ re (* 0.5 (/ (* im im) re)))))))
(let* ((t_0
(*
0.5
(sqrt
(* 2.0 (/ (* im im) (- (sqrt (+ (* im im) (* re re))) re)))))))
(if (<= im 6.386439438427647e-106)
t_0
(if (<= im 9.645579323198895e-68)
(* 0.5 (sqrt (* 2.0 (* 2.0 re))))
(if (<= im 1.649882945586574e+32)
t_0
(* 0.5 (sqrt (* 2.0 (+ 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 (im <= -4.0810855285811026e-82) {
tmp = 0.5 * sqrt(2.0 * (re - im));
} else if (im <= 1.1023411135196444e-294) {
tmp = 0.5 * sqrt(2.0 * (re + (re + (0.5 * ((im * im) / re)))));
} else {
double t_0 = 0.5 * sqrt(2.0 * ((im * im) / (sqrt((im * im) + (re * re)) - re)));
double tmp_1;
if (im <= 6.386439438427647e-106) {
tmp_1 = t_0;
} else if (im <= 9.645579323198895e-68) {
tmp_1 = 0.5 * sqrt(2.0 * (2.0 * re));
} else if (im <= 1.649882945586574e+32) {
tmp_1 = t_0;
} else {
tmp_1 = 0.5 * sqrt(2.0 * (im + re));
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 39.5 |
|---|---|
| Target | 34.2 |
| Herbie | 27.5 |
if im < -4.0810855285811026e-82Initial program 39.6
Taylor expanded around -inf 19.2
Simplified19.2
if -4.0810855285811026e-82 < im < 1.1023411135196444e-294Initial program 39.2
Taylor expanded around inf 37.8
Simplified37.8
if 1.1023411135196444e-294 < im < 6.38643943842764742e-106 or 9.6455793231988952e-68 < im < 1.649882945586574e32Initial program 35.6
rmApplied add-cube-cbrt_binary6436.4
Applied sqrt-prod_binary6436.4
Simplified36.4
rmApplied flip-+_binary6448.1
Simplified41.1
Simplified41.3
if 6.38643943842764742e-106 < im < 9.6455793231988952e-68Initial program 27.9
Taylor expanded around inf 41.7
Simplified41.7
if 1.649882945586574e32 < im Initial program 45.1
Taylor expanded around 0 13.8
Final simplification27.5
herbie shell --seed 2021206
(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)))))