\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}double f(double a, double b, double c, double d) {
double r3994249 = a;
double r3994250 = c;
double r3994251 = r3994249 * r3994250;
double r3994252 = b;
double r3994253 = d;
double r3994254 = r3994252 * r3994253;
double r3994255 = r3994251 + r3994254;
double r3994256 = r3994250 * r3994250;
double r3994257 = r3994253 * r3994253;
double r3994258 = r3994256 + r3994257;
double r3994259 = r3994255 / r3994258;
return r3994259;
}
double f(double a, double b, double c, double d) {
double r3994260 = 1.0;
double r3994261 = c;
double r3994262 = r3994261 * r3994261;
double r3994263 = d;
double r3994264 = r3994263 * r3994263;
double r3994265 = r3994262 + r3994264;
double r3994266 = sqrt(r3994265);
double r3994267 = r3994260 / r3994266;
double r3994268 = b;
double r3994269 = r3994268 * r3994263;
double r3994270 = a;
double r3994271 = r3994270 * r3994261;
double r3994272 = r3994269 + r3994271;
double r3994273 = r3994267 * r3994272;
double r3994274 = r3994273 / r3994266;
return r3994274;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.6 |
|---|---|
| Target | 0.6 |
| Herbie | 25.6 |
Initial program 25.6
rmApplied add-sqr-sqrt25.6
Applied associate-/r*25.5
rmApplied div-inv25.6
Final simplification25.6
herbie shell --seed 2019135
(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))))