\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{\mathsf{fma}\left(c, a, \left(b \cdot d\right)\right)}{\mathsf{hypot}\left(c, d\right)}double f(double a, double b, double c, double d) {
double r8345552 = a;
double r8345553 = c;
double r8345554 = r8345552 * r8345553;
double r8345555 = b;
double r8345556 = d;
double r8345557 = r8345555 * r8345556;
double r8345558 = r8345554 + r8345557;
double r8345559 = r8345553 * r8345553;
double r8345560 = r8345556 * r8345556;
double r8345561 = r8345559 + r8345560;
double r8345562 = r8345558 / r8345561;
return r8345562;
}
double f(double a, double b, double c, double d) {
double r8345563 = 1.0;
double r8345564 = d;
double r8345565 = c;
double r8345566 = hypot(r8345564, r8345565);
double r8345567 = r8345563 / r8345566;
double r8345568 = a;
double r8345569 = b;
double r8345570 = r8345569 * r8345564;
double r8345571 = fma(r8345565, r8345568, r8345570);
double r8345572 = hypot(r8345565, r8345564);
double r8345573 = r8345571 / r8345572;
double r8345574 = r8345567 * r8345573;
return r8345574;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.6 |
|---|---|
| Target | 0.5 |
| Herbie | 16.1 |
Initial program 25.6
Simplified25.6
rmApplied clear-num25.8
rmApplied *-un-lft-identity25.8
Applied add-sqr-sqrt25.8
Applied times-frac25.8
Applied add-cube-cbrt25.8
Applied times-frac25.7
Simplified25.7
Simplified16.1
Final simplification16.1
herbie shell --seed 2019124 +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))))