\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\mathsf{fma}\left(\frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-c}{-\mathsf{hypot}\left(c, d\right)}, -\frac{a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d) :precision binary64 (fma (/ b (hypot c d)) (/ (- c) (- (hypot c d))) (- (* (/ a (hypot c d)) (/ d (hypot c d))))))
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 fma((b / hypot(c, d)), (-c / -hypot(c, d)), -((a / hypot(c, d)) * (d / hypot(c, d))));
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 1.5 |
Initial program 26.1
Simplified26.1
Applied egg-rr15.0
Applied egg-rr1.5
Applied egg-rr1.8
Applied egg-rr1.5
Final simplification1.5
herbie shell --seed 2022130
(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))))