Average Error: 26.1 → 1.2
Time: 15.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(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 r47805 = x_im;
        double r47806 = y_re;
        double r47807 = r47805 * r47806;
        double r47808 = x_re;
        double r47809 = y_im;
        double r47810 = r47808 * r47809;
        double r47811 = r47807 - r47810;
        double r47812 = r47806 * r47806;
        double r47813 = r47809 * r47809;
        double r47814 = r47812 + r47813;
        double r47815 = r47811 / r47814;
        return r47815;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r47816 = y_re;
        double r47817 = x_im;
        double r47818 = y_im;
        double r47819 = hypot(r47816, r47818);
        double r47820 = r47817 / r47819;
        double r47821 = x_re;
        double r47822 = r47821 / r47819;
        double r47823 = r47822 * r47818;
        double r47824 = -r47823;
        double r47825 = fma(r47816, r47820, r47824);
        double r47826 = r47825 / r47819;
        return r47826;
}

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 26.1

    \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
  2. Simplified26.1

    \[\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-sqrt26.1

    \[\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-identity26.1

    \[\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-frac26.1

    \[\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. Simplified26.1

    \[\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.1

    \[\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 *-un-lft-identity17.1

    \[\leadsto \frac{1}{\color{blue}{1 \cdot \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)}\]
  11. Applied add-sqr-sqrt17.1

    \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot \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)}\]
  12. Applied times-frac17.1

    \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  13. Applied associate-*l*17.1

    \[\leadsto \color{blue}{\frac{\sqrt{1}}{1} \cdot \left(\frac{\sqrt{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)}\]
  14. Simplified17.0

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \color{blue}{\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)}}\]
  15. Using strategy rm
  16. Applied div-sub17.0

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  17. Simplified17.0

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  18. Simplified9.7

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  19. Using strategy rm
  20. Applied *-un-lft-identity9.7

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  21. Applied times-frac1.2

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  22. Applied fma-neg1.2

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  23. Simplified1.2

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \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)}\]
  24. 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 2019304 +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))))