\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 r2807143 = a;
double r2807144 = c;
double r2807145 = r2807143 * r2807144;
double r2807146 = b;
double r2807147 = d;
double r2807148 = r2807146 * r2807147;
double r2807149 = r2807145 + r2807148;
double r2807150 = r2807144 * r2807144;
double r2807151 = r2807147 * r2807147;
double r2807152 = r2807150 + r2807151;
double r2807153 = r2807149 / r2807152;
return r2807153;
}
double f(double a, double b, double c, double d) {
double r2807154 = 1.0;
double r2807155 = c;
double r2807156 = r2807155 * r2807155;
double r2807157 = d;
double r2807158 = r2807157 * r2807157;
double r2807159 = r2807156 + r2807158;
double r2807160 = sqrt(r2807159);
double r2807161 = r2807154 / r2807160;
double r2807162 = b;
double r2807163 = r2807162 * r2807157;
double r2807164 = a;
double r2807165 = r2807164 * r2807155;
double r2807166 = r2807163 + r2807165;
double r2807167 = r2807161 * r2807166;
double r2807168 = r2807167 / r2807160;
return r2807168;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.5 |
| Herbie | 25.8 |
Initial program 25.8
rmApplied add-sqr-sqrt25.8
Applied associate-/r*25.8
rmApplied div-inv25.8
Final simplification25.8
herbie shell --seed 2019139 +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))))