\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} = -\infty:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 1.4420118311925315 \cdot 10^{300}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r116849 = a;
double r116850 = c;
double r116851 = r116849 * r116850;
double r116852 = b;
double r116853 = d;
double r116854 = r116852 * r116853;
double r116855 = r116851 + r116854;
double r116856 = r116850 * r116850;
double r116857 = r116853 * r116853;
double r116858 = r116856 + r116857;
double r116859 = r116855 / r116858;
return r116859;
}
double f(double a, double b, double c, double d) {
double r116860 = a;
double r116861 = c;
double r116862 = r116860 * r116861;
double r116863 = b;
double r116864 = d;
double r116865 = r116863 * r116864;
double r116866 = r116862 + r116865;
double r116867 = r116861 * r116861;
double r116868 = r116864 * r116864;
double r116869 = r116867 + r116868;
double r116870 = r116866 / r116869;
double r116871 = -inf.0;
bool r116872 = r116870 <= r116871;
double r116873 = sqrt(r116869);
double r116874 = r116860 / r116873;
double r116875 = 1.4420118311925315e+300;
bool r116876 = r116870 <= r116875;
double r116877 = r116866 / r116873;
double r116878 = r116877 / r116873;
double r116879 = -1.0;
double r116880 = r116879 * r116860;
double r116881 = r116880 / r116873;
double r116882 = r116876 ? r116878 : r116881;
double r116883 = r116872 ? r116874 : r116882;
return r116883;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 24.6 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0Initial program 64.0
rmApplied add-sqr-sqrt64.0
Applied associate-/r*64.0
Taylor expanded around inf 55.8
if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.4420118311925315e+300Initial program 11.8
rmApplied add-sqr-sqrt11.8
Applied associate-/r*11.7
if 1.4420118311925315e+300 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.5
rmApplied add-sqr-sqrt63.5
Applied associate-/r*63.5
Taylor expanded around -inf 59.5
Final simplification24.6
herbie shell --seed 2020024
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))