\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}double f(double a, double b, double c, double d) {
double r2427423 = a;
double r2427424 = c;
double r2427425 = r2427423 * r2427424;
double r2427426 = b;
double r2427427 = d;
double r2427428 = r2427426 * r2427427;
double r2427429 = r2427425 + r2427428;
double r2427430 = r2427424 * r2427424;
double r2427431 = r2427427 * r2427427;
double r2427432 = r2427430 + r2427431;
double r2427433 = r2427429 / r2427432;
return r2427433;
}
double f(double a, double b, double c, double d) {
double r2427434 = 1.0;
double r2427435 = c;
double r2427436 = r2427435 * r2427435;
double r2427437 = d;
double r2427438 = r2427437 * r2427437;
double r2427439 = r2427436 + r2427438;
double r2427440 = sqrt(r2427439);
double r2427441 = r2427434 / r2427440;
double r2427442 = b;
double r2427443 = r2427442 * r2427437;
double r2427444 = a;
double r2427445 = r2427444 * r2427435;
double r2427446 = r2427443 + r2427445;
double r2427447 = r2427446 / r2427440;
double r2427448 = r2427441 * r2427447;
return r2427448;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 25.7 |
Initial program 25.7
rmApplied add-sqr-sqrt25.7
Applied associate-/r*25.7
rmApplied *-un-lft-identity25.7
Applied associate-/r*25.7
Simplified25.7
rmApplied add-sqr-sqrt25.7
Applied sqrt-prod25.8
Applied add-sqr-sqrt25.8
Applied sqrt-prod25.9
Applied *-un-lft-identity25.9
Applied times-frac26.0
Applied times-frac26.0
Simplified25.9
Simplified25.7
Final simplification25.7
herbie shell --seed 2019152
(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))))