\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\mathsf{fma}\left(\frac{b}{\sqrt{\mathsf{hypot}\left(c, d\right)}}, \frac{c}{\sqrt{\mathsf{hypot}\left(c, d\right)}}, -\frac{d}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right) + \frac{d}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\left(-\frac{a}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right) + \frac{a}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}{\mathsf{hypot}\left(c, d\right) \cdot 1}double f(double a, double b, double c, double d) {
double r126238 = b;
double r126239 = c;
double r126240 = r126238 * r126239;
double r126241 = a;
double r126242 = d;
double r126243 = r126241 * r126242;
double r126244 = r126240 - r126243;
double r126245 = r126239 * r126239;
double r126246 = r126242 * r126242;
double r126247 = r126245 + r126246;
double r126248 = r126244 / r126247;
return r126248;
}
double f(double a, double b, double c, double d) {
double r126249 = b;
double r126250 = c;
double r126251 = d;
double r126252 = hypot(r126250, r126251);
double r126253 = sqrt(r126252);
double r126254 = r126249 / r126253;
double r126255 = r126250 / r126253;
double r126256 = r126251 / r126253;
double r126257 = a;
double r126258 = r126257 / r126253;
double r126259 = r126256 * r126258;
double r126260 = -r126259;
double r126261 = fma(r126254, r126255, r126260);
double r126262 = -r126258;
double r126263 = r126262 + r126258;
double r126264 = r126256 * r126263;
double r126265 = r126261 + r126264;
double r126266 = 1.0;
double r126267 = r126252 * r126266;
double r126268 = r126265 / r126267;
return r126268;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 1.0 |
Initial program 25.9
rmApplied add-sqr-sqrt25.9
Applied *-un-lft-identity25.9
Applied times-frac25.9
Simplified25.9
Simplified17.0
rmApplied associate-*l/16.9
Simplified16.9
rmApplied div-sub16.9
rmApplied add-sqr-sqrt17.0
Applied times-frac9.4
Applied add-sqr-sqrt9.5
Applied times-frac1.0
Applied prod-diff1.0
Simplified1.0
Final simplification1.0
herbie shell --seed 2020001 +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))))