\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\frac{b}{\frac{\sqrt{c \cdot c + d \cdot d}}{c}} - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}double f(double a, double b, double c, double d) {
double r118214 = b;
double r118215 = c;
double r118216 = r118214 * r118215;
double r118217 = a;
double r118218 = d;
double r118219 = r118217 * r118218;
double r118220 = r118216 - r118219;
double r118221 = r118215 * r118215;
double r118222 = r118218 * r118218;
double r118223 = r118221 + r118222;
double r118224 = r118220 / r118223;
return r118224;
}
double f(double a, double b, double c, double d) {
double r118225 = b;
double r118226 = c;
double r118227 = r118226 * r118226;
double r118228 = d;
double r118229 = r118228 * r118228;
double r118230 = r118227 + r118229;
double r118231 = sqrt(r118230);
double r118232 = r118231 / r118226;
double r118233 = r118225 / r118232;
double r118234 = a;
double r118235 = r118231 / r118228;
double r118236 = r118234 / r118235;
double r118237 = r118233 - r118236;
double r118238 = r118237 / r118231;
return r118238;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.5 |
|---|---|
| Target | 0.4 |
| Herbie | 22.8 |
Initial program 26.5
rmApplied add-sqr-sqrt26.5
Applied associate-/r*26.4
rmApplied add-sqr-sqrt26.4
Applied sqrt-prod26.5
rmApplied div-sub26.5
Simplified24.7
Simplified22.8
Final simplification22.8
herbie shell --seed 2020064
(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))))