Average Error: 25.6 → 16.1
Time: 33.7s
Precision: 64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{\mathsf{fma}\left(y.re, x.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\]
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{\mathsf{fma}\left(y.re, x.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2072968 = x_re;
        double r2072969 = y_re;
        double r2072970 = r2072968 * r2072969;
        double r2072971 = x_im;
        double r2072972 = y_im;
        double r2072973 = r2072971 * r2072972;
        double r2072974 = r2072970 + r2072973;
        double r2072975 = r2072969 * r2072969;
        double r2072976 = r2072972 * r2072972;
        double r2072977 = r2072975 + r2072976;
        double r2072978 = r2072974 / r2072977;
        return r2072978;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2072979 = 1.0;
        double r2072980 = y_im;
        double r2072981 = y_re;
        double r2072982 = hypot(r2072980, r2072981);
        double r2072983 = r2072979 / r2072982;
        double r2072984 = x_re;
        double r2072985 = x_im;
        double r2072986 = r2072985 * r2072980;
        double r2072987 = fma(r2072981, r2072984, r2072986);
        double r2072988 = hypot(r2072981, r2072980);
        double r2072989 = r2072987 / r2072988;
        double r2072990 = r2072983 * r2072989;
        return r2072990;
}

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

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

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
  3. Using strategy rm
  4. Applied *-un-lft-identity25.6

    \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}\]
  5. Applied associate-/l*25.8

    \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}}\]
  6. Using strategy rm
  7. Applied *-un-lft-identity25.8

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}}\]
  10. Applied add-cube-cbrt25.8

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

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

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\sqrt[3]{1}}{\frac{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}\]
  13. Simplified16.1

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{\mathsf{fma}\left(y.re, x.re, \left(y.im \cdot x.im\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
  14. Final simplification16.1

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

Reproduce

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