\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}double f(double a, double b, double c, double d) {
double r4932027 = a;
double r4932028 = c;
double r4932029 = r4932027 * r4932028;
double r4932030 = b;
double r4932031 = d;
double r4932032 = r4932030 * r4932031;
double r4932033 = r4932029 + r4932032;
double r4932034 = r4932028 * r4932028;
double r4932035 = r4932031 * r4932031;
double r4932036 = r4932034 + r4932035;
double r4932037 = r4932033 / r4932036;
return r4932037;
}
double f(double a, double b, double c, double d) {
double r4932038 = 1.0;
double r4932039 = c;
double r4932040 = r4932039 * r4932039;
double r4932041 = d;
double r4932042 = r4932041 * r4932041;
double r4932043 = r4932040 + r4932042;
double r4932044 = sqrt(r4932043);
double r4932045 = r4932038 / r4932044;
double r4932046 = b;
double r4932047 = r4932046 * r4932041;
double r4932048 = a;
double r4932049 = r4932048 * r4932039;
double r4932050 = r4932047 + r4932049;
double r4932051 = r4932045 * r4932050;
double r4932052 = r4932051 / r4932044;
return r4932052;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 25.8 |
Initial program 25.8
rmApplied add-sqr-sqrt25.8
Applied associate-/r*25.7
rmApplied div-inv25.8
Final simplification25.8
herbie shell --seed 2019163
(FPCore (a b c d)
:name "Complex division, real part"
: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))))