\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 r85342 = a;
double r85343 = c;
double r85344 = r85342 * r85343;
double r85345 = b;
double r85346 = d;
double r85347 = r85345 * r85346;
double r85348 = r85344 + r85347;
double r85349 = r85343 * r85343;
double r85350 = r85346 * r85346;
double r85351 = r85349 + r85350;
double r85352 = r85348 / r85351;
return r85352;
}
double f(double a, double b, double c, double d) {
double r85353 = a;
double r85354 = c;
double r85355 = r85353 * r85354;
double r85356 = b;
double r85357 = d;
double r85358 = r85356 * r85357;
double r85359 = r85355 + r85358;
double r85360 = 1.0;
double r85361 = r85354 * r85354;
double r85362 = r85357 * r85357;
double r85363 = r85361 + r85362;
double r85364 = sqrt(r85363);
double r85365 = r85360 / r85364;
double r85366 = r85359 * r85365;
double r85367 = r85366 / r85364;
return r85367;
}




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))))