Average Error: 25.9 → 16.7
Time: 15.2s
Precision: 64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[-\frac{\frac{\mathsf{fma}\left(y.re, x.re, \left(y.im \cdot x.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\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{\frac{\mathsf{fma}\left(y.re, x.re, \left(y.im \cdot x.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{-\mathsf{hypot}\left(y.im, y.re\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2179560 = x_re;
        double r2179561 = y_re;
        double r2179562 = r2179560 * r2179561;
        double r2179563 = x_im;
        double r2179564 = y_im;
        double r2179565 = r2179563 * r2179564;
        double r2179566 = r2179562 + r2179565;
        double r2179567 = r2179561 * r2179561;
        double r2179568 = r2179564 * r2179564;
        double r2179569 = r2179567 + r2179568;
        double r2179570 = r2179566 / r2179569;
        return r2179570;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2179571 = y_re;
        double r2179572 = x_re;
        double r2179573 = y_im;
        double r2179574 = x_im;
        double r2179575 = r2179573 * r2179574;
        double r2179576 = fma(r2179571, r2179572, r2179575);
        double r2179577 = hypot(r2179573, r2179571);
        double r2179578 = r2179576 / r2179577;
        double r2179579 = -r2179577;
        double r2179580 = r2179578 / r2179579;
        double r2179581 = -r2179580;
        return r2179581;
}

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.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
  2. Simplified25.9

    \[\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 add-sqr-sqrt25.9

    \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\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)}}}\]
  5. Applied associate-/r*25.8

    \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
  6. Using strategy rm
  7. Applied div-inv25.9

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

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

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

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

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

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

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

Reproduce

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