double f(double a, double b, double c, double d) {
double r5841012 = b;
double r5841013 = c;
double r5841014 = r5841012 * r5841013;
double r5841015 = a;
double r5841016 = d;
double r5841017 = r5841015 * r5841016;
double r5841018 = r5841014 - r5841017;
double r5841019 = r5841013 * r5841013;
double r5841020 = r5841016 * r5841016;
double r5841021 = r5841019 + r5841020;
double r5841022 = r5841018 / r5841021;
return r5841022;
}
double f(double a, double b, double c, double d) {
double r5841023 = b;
double r5841024 = c;
double r5841025 = r5841023 * r5841024;
double r5841026 = d;
double r5841027 = r5841024 * r5841024;
double r5841028 = fma(r5841026, r5841026, r5841027);
double r5841029 = sqrt(r5841028);
double r5841030 = r5841025 / r5841029;
double r5841031 = r5841026 / r5841029;
double r5841032 = a;
double r5841033 = r5841031 * r5841032;
double r5841034 = r5841030 - r5841033;
double r5841035 = r5841034 / r5841029;
return r5841035;
}
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\frac{b \cdot c}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} - \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}



Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.5 |
|---|---|
| Target | 0.4 |
| Herbie | 23.9 |
Initial program 25.5
Simplified25.5
rmApplied add-sqr-sqrt25.5
Applied associate-/r*25.5
Taylor expanded around inf 25.5
rmApplied div-sub25.5
rmApplied *-un-lft-identity25.5
Applied times-frac23.9
Simplified23.9
Final simplification23.9
herbie shell --seed 2019102 +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))))