\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}double f(double a, double b, double c, double d) {
double r1935523 = a;
double r1935524 = c;
double r1935525 = r1935523 * r1935524;
double r1935526 = b;
double r1935527 = d;
double r1935528 = r1935526 * r1935527;
double r1935529 = r1935525 + r1935528;
double r1935530 = r1935524 * r1935524;
double r1935531 = r1935527 * r1935527;
double r1935532 = r1935530 + r1935531;
double r1935533 = r1935529 / r1935532;
return r1935533;
}
double f(double a, double b, double c, double d) {
double r1935534 = c;
double r1935535 = a;
double r1935536 = d;
double r1935537 = b;
double r1935538 = r1935536 * r1935537;
double r1935539 = fma(r1935534, r1935535, r1935538);
double r1935540 = hypot(r1935536, r1935534);
double r1935541 = r1935539 / r1935540;
double r1935542 = r1935541 / r1935540;
return r1935542;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.6 |
|---|---|
| Target | 0.4 |
| Herbie | 16.2 |
Initial program 25.6
Simplified25.6
rmApplied add-sqr-sqrt25.6
Applied *-un-lft-identity25.6
Applied times-frac25.6
rmApplied *-un-lft-identity25.6
Applied associate-*l*25.6
Simplified16.2
Final simplification16.2
herbie shell --seed 2019154 +o rules:numerics
(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))))