Average Error: 25.8 → 1.2
Time: 17.0s
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(y.re, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\]
\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(y.re, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r45552 = x_im;
        double r45553 = y_re;
        double r45554 = r45552 * r45553;
        double r45555 = x_re;
        double r45556 = y_im;
        double r45557 = r45555 * r45556;
        double r45558 = r45554 - r45557;
        double r45559 = r45553 * r45553;
        double r45560 = r45556 * r45556;
        double r45561 = r45559 + r45560;
        double r45562 = r45558 / r45561;
        return r45562;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r45563 = y_re;
        double r45564 = x_im;
        double r45565 = y_im;
        double r45566 = hypot(r45563, r45565);
        double r45567 = r45564 / r45566;
        double r45568 = x_re;
        double r45569 = r45568 / r45566;
        double r45570 = r45569 * r45565;
        double r45571 = -r45570;
        double r45572 = fma(r45563, r45567, r45571);
        double r45573 = r45572 / r45566;
        return r45573;
}

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.8

    \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
  2. Simplified25.8

    \[\leadsto \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt25.8

    \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
  5. Applied *-un-lft-identity25.8

    \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
  6. Applied times-frac25.8

    \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
  7. Simplified25.8

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

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{{\left(\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}}\]
  11. Applied pow117.2

    \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}} \cdot {\left(\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
  12. Applied pow-prod-down17.2

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

    \[\leadsto {\color{blue}{\left(\frac{\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)}\right)}}^{1}\]
  14. Using strategy rm
  15. Applied div-sub17.1

    \[\leadsto {\left(\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)}\right)}^{1}\]
  16. Simplified17.1

    \[\leadsto {\left(\frac{\color{blue}{\frac{y.re \cdot x.im}{\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)}\right)}^{1}\]
  17. Simplified9.9

    \[\leadsto {\left(\frac{\frac{y.re \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)} - \color{blue}{y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
  18. Using strategy rm
  19. Applied *-un-lft-identity9.9

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

    \[\leadsto {\left(\frac{\color{blue}{\frac{y.re}{1} \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}} - y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
  21. Applied fma-neg1.2

    \[\leadsto {\left(\frac{\color{blue}{\mathsf{fma}\left(\frac{y.re}{1}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
  22. Simplified1.2

    \[\leadsto {\left(\frac{\mathsf{fma}\left(\frac{y.re}{1}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \color{blue}{-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot y.im}\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
  23. Final simplification1.2

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

Reproduce

herbie shell --seed 2019303 +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))))