\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}double f(double a, double b, double c, double d) {
double r1722718 = b;
double r1722719 = c;
double r1722720 = r1722718 * r1722719;
double r1722721 = a;
double r1722722 = d;
double r1722723 = r1722721 * r1722722;
double r1722724 = r1722720 - r1722723;
double r1722725 = r1722719 * r1722719;
double r1722726 = r1722722 * r1722722;
double r1722727 = r1722725 + r1722726;
double r1722728 = r1722724 / r1722727;
return r1722728;
}
double f(double a, double b, double c, double d) {
double r1722729 = 1.0;
double r1722730 = d;
double r1722731 = c;
double r1722732 = r1722731 * r1722731;
double r1722733 = fma(r1722730, r1722730, r1722732);
double r1722734 = sqrt(r1722733);
double r1722735 = r1722729 / r1722734;
double r1722736 = b;
double r1722737 = a;
double r1722738 = -r1722737;
double r1722739 = r1722730 * r1722738;
double r1722740 = fma(r1722736, r1722731, r1722739);
double r1722741 = r1722735 * r1722740;
double r1722742 = r1722741 / r1722734;
return r1722742;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.4 |
|---|---|
| Target | 0.4 |
| Herbie | 25.4 |
Initial program 25.4
Simplified25.4
rmApplied add-sqr-sqrt25.4
Applied associate-/r*25.3
rmApplied fma-neg25.3
rmApplied div-inv25.4
Final simplification25.4
herbie shell --seed 2019152 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))