\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}b \cdot \frac{1}{\mathsf{fma}\left(\frac{d}{c}, d, c\right)} - \frac{a}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}double code(double a, double b, double c, double d) {
return (((b * c) - (a * d)) / ((c * c) + (d * d)));
}
double code(double a, double b, double c, double d) {
return ((b * (1.0 / fma((d / c), d, c))) - (a / fma((c / d), c, d)));
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 3.4 |
Initial program 26.0
rmApplied div-sub26.0
Simplified24.8
Simplified23.2
Taylor expanded around 0 15.7
Simplified14.0
Taylor expanded around 0 5.7
Simplified3.3
rmApplied div-inv3.4
Final simplification3.4
herbie shell --seed 2020071 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
: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))))