Average Error: 26.0 → 16.4
Time: 17.9s
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(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\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(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r1635757 = x_re;
        double r1635758 = y_re;
        double r1635759 = r1635757 * r1635758;
        double r1635760 = x_im;
        double r1635761 = y_im;
        double r1635762 = r1635760 * r1635761;
        double r1635763 = r1635759 + r1635762;
        double r1635764 = r1635758 * r1635758;
        double r1635765 = r1635761 * r1635761;
        double r1635766 = r1635764 + r1635765;
        double r1635767 = r1635763 / r1635766;
        return r1635767;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1635768 = 1.0;
        double r1635769 = y_im;
        double r1635770 = y_re;
        double r1635771 = hypot(r1635769, r1635770);
        double r1635772 = r1635768 / r1635771;
        double r1635773 = x_re;
        double r1635774 = x_im;
        double r1635775 = r1635774 * r1635769;
        double r1635776 = fma(r1635773, r1635770, r1635775);
        double r1635777 = r1635776 / r1635771;
        double r1635778 = r1635772 * r1635777;
        return r1635778;
}

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{1}}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
  6. Using strategy rm
  7. Applied add-sqr-sqrt26.0

    \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{1}}{\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)}}}\]
  8. Applied add-cube-cbrt26.0

    \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}}{\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)}}\]
  9. Applied *-un-lft-identity26.0

    \[\leadsto \frac{\frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\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)}}\]
  10. Applied times-frac26.0

    \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt[3]{1} \cdot \sqrt[3]{1}} \cdot \frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt[3]{1}}}}{\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)}}\]
  11. Applied times-frac26.0

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

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

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

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

Reproduce

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