\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}double f(double a, double b, double c, double d) {
double r9128661 = b;
double r9128662 = c;
double r9128663 = r9128661 * r9128662;
double r9128664 = a;
double r9128665 = d;
double r9128666 = r9128664 * r9128665;
double r9128667 = r9128663 - r9128666;
double r9128668 = r9128662 * r9128662;
double r9128669 = r9128665 * r9128665;
double r9128670 = r9128668 + r9128669;
double r9128671 = r9128667 / r9128670;
return r9128671;
}
double f(double a, double b, double c, double d) {
double r9128672 = c;
double r9128673 = b;
double r9128674 = r9128672 * r9128673;
double r9128675 = d;
double r9128676 = a;
double r9128677 = r9128675 * r9128676;
double r9128678 = r9128674 - r9128677;
double r9128679 = hypot(r9128672, r9128675);
double r9128680 = r9128678 / r9128679;
double r9128681 = 1.0;
double r9128682 = hypot(r9128675, r9128672);
double r9128683 = r9128681 / r9128682;
double r9128684 = r9128680 * r9128683;
return r9128684;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 16.2 |
Initial program 25.8
Simplified25.8
rmApplied *-un-lft-identity25.8
Applied associate-/l*25.9
rmApplied *-un-lft-identity25.9
Applied add-sqr-sqrt25.9
Applied times-frac25.9
Applied add-cube-cbrt25.9
Applied times-frac25.8
Simplified25.8
Simplified16.2
Final simplification16.2
herbie shell --seed 2019121 +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))))