\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot b - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}double f(double a, double b, double c, double d) {
double r120631 = b;
double r120632 = c;
double r120633 = r120631 * r120632;
double r120634 = a;
double r120635 = d;
double r120636 = r120634 * r120635;
double r120637 = r120633 - r120636;
double r120638 = r120632 * r120632;
double r120639 = r120635 * r120635;
double r120640 = r120638 + r120639;
double r120641 = r120637 / r120640;
return r120641;
}
double f(double a, double b, double c, double d) {
double r120642 = c;
double r120643 = d;
double r120644 = hypot(r120642, r120643);
double r120645 = r120642 / r120644;
double r120646 = b;
double r120647 = r120645 * r120646;
double r120648 = a;
double r120649 = r120648 / r120644;
double r120650 = r120643 * r120649;
double r120651 = r120647 - r120650;
double r120652 = r120651 / r120644;
return r120652;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 0.9 |
Initial program 26.2
Simplified26.2
rmApplied add-sqr-sqrt26.2
Applied *-un-lft-identity26.2
Applied times-frac26.2
Simplified26.2
Simplified17.0
rmApplied *-un-lft-identity17.0
Applied associate-*l*17.0
Simplified16.9
rmApplied div-sub16.9
Simplified9.9
Simplified1.3
rmApplied associate-/r/0.9
Final simplification0.9
herbie shell --seed 2019325 +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))))