\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{b \cdot \frac{c}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} - \frac{a}{\frac{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}{d}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}double f(double a, double b, double c, double d) {
double r4814297 = b;
double r4814298 = c;
double r4814299 = r4814297 * r4814298;
double r4814300 = a;
double r4814301 = d;
double r4814302 = r4814300 * r4814301;
double r4814303 = r4814299 - r4814302;
double r4814304 = r4814298 * r4814298;
double r4814305 = r4814301 * r4814301;
double r4814306 = r4814304 + r4814305;
double r4814307 = r4814303 / r4814306;
return r4814307;
}
double f(double a, double b, double c, double d) {
double r4814308 = b;
double r4814309 = c;
double r4814310 = d;
double r4814311 = r4814309 * r4814309;
double r4814312 = fma(r4814310, r4814310, r4814311);
double r4814313 = sqrt(r4814312);
double r4814314 = r4814309 / r4814313;
double r4814315 = r4814308 * r4814314;
double r4814316 = a;
double r4814317 = r4814313 / r4814310;
double r4814318 = r4814316 / r4814317;
double r4814319 = r4814315 - r4814318;
double r4814320 = r4814319 / r4814313;
return r4814320;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.3 |
|---|---|
| Target | 0.5 |
| Herbie | 22.1 |
Initial program 25.3
Simplified25.3
rmApplied add-sqr-sqrt25.3
Applied associate-/r*25.3
rmApplied div-sub25.3
rmApplied *-un-lft-identity25.3
Applied sqrt-prod25.3
Applied times-frac23.8
Simplified23.8
rmApplied associate-/l*22.1
Final simplification22.1
herbie shell --seed 2019144 +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))))