\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{1 \cdot \frac{a \cdot c + b \cdot d}{\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 r120297 = a;
double r120298 = c;
double r120299 = r120297 * r120298;
double r120300 = b;
double r120301 = d;
double r120302 = r120300 * r120301;
double r120303 = r120299 + r120302;
double r120304 = r120298 * r120298;
double r120305 = r120301 * r120301;
double r120306 = r120304 + r120305;
double r120307 = r120303 / r120306;
return r120307;
}
double f(double a, double b, double c, double d) {
double r120308 = 1.0;
double r120309 = a;
double r120310 = c;
double r120311 = r120309 * r120310;
double r120312 = b;
double r120313 = d;
double r120314 = r120312 * r120313;
double r120315 = r120311 + r120314;
double r120316 = r120310 * r120310;
double r120317 = r120313 * r120313;
double r120318 = r120316 + r120317;
double r120319 = sqrt(r120318);
double r120320 = r120315 / r120319;
double r120321 = r120308 * r120320;
double r120322 = r120321 / r120319;
return r120322;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.5 |
|---|---|
| Target | 0.3 |
| Herbie | 26.5 |
Initial program 26.5
rmApplied add-sqr-sqrt26.5
Applied associate-/r*26.5
rmApplied *-un-lft-identity26.5
Applied sqrt-prod26.5
Applied *-un-lft-identity26.5
Applied times-frac26.5
Simplified26.5
Final simplification26.5
herbie shell --seed 2020027
(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))))