\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{\mathsf{fma}\left(a, c, \left(b \cdot d\right)\right)}{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}}{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}double f(double a, double b, double c, double d) {
double r21523975 = a;
double r21523976 = c;
double r21523977 = r21523975 * r21523976;
double r21523978 = b;
double r21523979 = d;
double r21523980 = r21523978 * r21523979;
double r21523981 = r21523977 + r21523980;
double r21523982 = r21523976 * r21523976;
double r21523983 = r21523979 * r21523979;
double r21523984 = r21523982 + r21523983;
double r21523985 = r21523981 / r21523984;
return r21523985;
}
double f(double a, double b, double c, double d) {
double r21523986 = a;
double r21523987 = c;
double r21523988 = b;
double r21523989 = d;
double r21523990 = r21523988 * r21523989;
double r21523991 = fma(r21523986, r21523987, r21523990);
double r21523992 = r21523987 * r21523987;
double r21523993 = fma(r21523989, r21523989, r21523992);
double r21523994 = sqrt(r21523993);
double r21523995 = r21523991 / r21523994;
double r21523996 = r21523995 / r21523994;
return r21523996;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 25.9 |
Initial program 26.0
Simplified26.0
rmApplied add-sqr-sqrt26.0
Applied associate-/r*25.9
Taylor expanded around -inf 25.9
Simplified25.9
Final simplification25.9
herbie shell --seed 2019120 +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))))