Average Error: 25.9 → 1.0
Time: 4.5s
Precision: 64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r71447 = x_im;
        double r71448 = y_re;
        double r71449 = r71447 * r71448;
        double r71450 = x_re;
        double r71451 = y_im;
        double r71452 = r71450 * r71451;
        double r71453 = r71449 - r71452;
        double r71454 = r71448 * r71448;
        double r71455 = r71451 * r71451;
        double r71456 = r71454 + r71455;
        double r71457 = r71453 / r71456;
        return r71457;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r71458 = x_im;
        double r71459 = y_re;
        double r71460 = y_im;
        double r71461 = hypot(r71459, r71460);
        double r71462 = sqrt(r71461);
        double r71463 = r71458 / r71462;
        double r71464 = r71459 / r71462;
        double r71465 = r71460 / r71462;
        double r71466 = x_re;
        double r71467 = r71466 / r71462;
        double r71468 = r71465 * r71467;
        double r71469 = -r71468;
        double r71470 = fma(r71463, r71464, r71469);
        double r71471 = -r71467;
        double r71472 = r71471 + r71467;
        double r71473 = r71465 * r71472;
        double r71474 = r71470 + r71473;
        double r71475 = 1.0;
        double r71476 = r71461 * r71475;
        double r71477 = r71474 / r71476;
        return r71477;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Derivation

  1. Initial program 25.9

    \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt25.9

    \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
  4. Applied *-un-lft-identity25.9

    \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
  5. Applied times-frac25.9

    \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
  6. Simplified25.9

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
  7. Simplified17.0

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
  8. Using strategy rm
  9. Applied associate-*l/16.9

    \[\leadsto \color{blue}{\frac{1 \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}}\]
  10. Simplified16.9

    \[\leadsto \frac{\color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  11. Using strategy rm
  12. Applied div-sub16.9

    \[\leadsto \frac{\color{blue}{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  13. Using strategy rm
  14. Applied add-sqr-sqrt17.0

    \[\leadsto \frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  15. Applied times-frac9.4

    \[\leadsto \frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \color{blue}{\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  16. Applied add-sqr-sqrt9.5

    \[\leadsto \frac{\frac{x.im \cdot y.re}{\color{blue}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}} - \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  17. Applied times-frac1.0

    \[\leadsto \frac{\color{blue}{\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}} - \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  18. Applied prod-diff1.0

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \mathsf{fma}\left(-\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  19. Simplified1.0

    \[\leadsto \frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \color{blue}{\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
  20. Final simplification1.0

    \[\leadsto \frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]

Reproduce

herbie shell --seed 2020001 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))