\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}double f(double a, double b, double c, double d) {
double r85375 = a;
double r85376 = c;
double r85377 = r85375 * r85376;
double r85378 = b;
double r85379 = d;
double r85380 = r85378 * r85379;
double r85381 = r85377 + r85380;
double r85382 = r85376 * r85376;
double r85383 = r85379 * r85379;
double r85384 = r85382 + r85383;
double r85385 = r85381 / r85384;
return r85385;
}
double f(double a, double b, double c, double d) {
double r85386 = a;
double r85387 = c;
double r85388 = r85386 * r85387;
double r85389 = b;
double r85390 = d;
double r85391 = r85389 * r85390;
double r85392 = r85388 + r85391;
double r85393 = 1.0;
double r85394 = r85387 * r85387;
double r85395 = r85390 * r85390;
double r85396 = r85394 + r85395;
double r85397 = sqrt(r85396);
double r85398 = r85393 / r85397;
double r85399 = r85392 * r85398;
double r85400 = r85399 / r85397;
return r85400;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 25.9 |
Initial program 25.9
rmApplied add-sqr-sqrt25.9
Applied associate-/r*25.8
rmApplied div-inv25.9
Final simplification25.9
herbie shell --seed 2019353
(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))))