Average Error: 25.7 → 25.6
Time: 12.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{\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)}}\]
\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(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)}}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r1280007 = x_re;
        double r1280008 = y_re;
        double r1280009 = r1280007 * r1280008;
        double r1280010 = x_im;
        double r1280011 = y_im;
        double r1280012 = r1280010 * r1280011;
        double r1280013 = r1280009 + r1280012;
        double r1280014 = r1280008 * r1280008;
        double r1280015 = r1280011 * r1280011;
        double r1280016 = r1280014 + r1280015;
        double r1280017 = r1280013 / r1280016;
        return r1280017;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1280018 = x_re;
        double r1280019 = y_re;
        double r1280020 = x_im;
        double r1280021 = y_im;
        double r1280022 = r1280020 * r1280021;
        double r1280023 = fma(r1280018, r1280019, r1280022);
        double r1280024 = r1280019 * r1280019;
        double r1280025 = fma(r1280021, r1280021, r1280024);
        double r1280026 = sqrt(r1280025);
        double r1280027 = r1280023 / r1280026;
        double r1280028 = r1280027 / r1280026;
        return r1280028;
}

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

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

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

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

    \[\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. Final simplification25.6

    \[\leadsto \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)}}\]

Reproduce

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