Average Error: 26.1 → 16.8
Time: 16.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{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\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{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}}}{\mathsf{hypot}\left(y.im, y.re\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2930241 = x_re;
        double r2930242 = y_re;
        double r2930243 = r2930241 * r2930242;
        double r2930244 = x_im;
        double r2930245 = y_im;
        double r2930246 = r2930244 * r2930245;
        double r2930247 = r2930243 + r2930246;
        double r2930248 = r2930242 * r2930242;
        double r2930249 = r2930245 * r2930245;
        double r2930250 = r2930248 + r2930249;
        double r2930251 = r2930247 / r2930250;
        return r2930251;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2930252 = 1.0;
        double r2930253 = y_im;
        double r2930254 = y_re;
        double r2930255 = hypot(r2930253, r2930254);
        double r2930256 = x_re;
        double r2930257 = x_im;
        double r2930258 = r2930257 * r2930253;
        double r2930259 = fma(r2930254, r2930256, r2930258);
        double r2930260 = r2930255 / r2930259;
        double r2930261 = r2930252 / r2930260;
        double r2930262 = r2930261 / r2930255;
        return r2930262;
}

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

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

    \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
  5. Using strategy rm
  6. Applied clear-num26.2

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)} \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
  8. Using strategy rm
  9. Applied associate-/r*16.8

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

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

Reproduce

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