Average Error: 25.9 → 1.0
Time: 4.4s
Precision: 64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, 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 r54979 = x_im;
        double r54980 = y_re;
        double r54981 = r54979 * r54980;
        double r54982 = x_re;
        double r54983 = y_im;
        double r54984 = r54982 * r54983;
        double r54985 = r54981 - r54984;
        double r54986 = r54980 * r54980;
        double r54987 = r54983 * r54983;
        double r54988 = r54986 + r54987;
        double r54989 = r54985 / r54988;
        return r54989;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r54990 = x_im;
        double r54991 = y_re;
        double r54992 = y_im;
        double r54993 = hypot(r54991, r54992);
        double r54994 = sqrt(r54993);
        double r54995 = r54990 / r54994;
        double r54996 = r54991 / r54994;
        double r54997 = r54992 / r54994;
        double r54998 = x_re;
        double r54999 = r54998 / r54994;
        double r55000 = r54997 * r54999;
        double r55001 = -r55000;
        double r55002 = fma(r54995, r54996, r55001);
        double r55003 = -r54999;
        double r55004 = r55003 + r54999;
        double r55005 = r54997 * r55004;
        double r55006 = r55002 + r55005;
        double r55007 = r55006 / r54993;
        return r55007;
}

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.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt25.9

    \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
  4. Applied *-un-lft-identity25.9

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
  6. Simplified25.9

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
  8. Using strategy rm
  9. Applied *-un-lft-identity17.0

    \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\right)} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  10. Applied associate-*l*17.0

    \[\leadsto \color{blue}{1 \cdot \left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}\]
  11. Simplified16.9

    \[\leadsto 1 \cdot \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
  12. Using strategy rm
  13. Applied div-sub16.9

    \[\leadsto 1 \cdot \frac{\color{blue}{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  14. Using strategy rm
  15. Applied add-sqr-sqrt17.0

    \[\leadsto 1 \cdot \frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  16. Applied times-frac9.4

    \[\leadsto 1 \cdot \frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \color{blue}{\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  17. Applied add-sqr-sqrt9.5

    \[\leadsto 1 \cdot \frac{\frac{x.im \cdot y.re}{\color{blue}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}} - \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  18. Applied times-frac1.0

    \[\leadsto 1 \cdot \frac{\color{blue}{\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}} - \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  19. Applied prod-diff1.0

    \[\leadsto 1 \cdot \frac{\color{blue}{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \mathsf{fma}\left(-\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  20. Simplified1.0

    \[\leadsto 1 \cdot \frac{\mathsf{fma}\left(\frac{x.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{y.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}, -\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \color{blue}{\frac{y.im}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \left(\left(-\frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right) + \frac{x.re}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  21. Final simplification1.0

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

Reproduce

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