Average Error: 26.4 → 1.1
Time: 13.8s
Precision: 64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\frac{\frac{x.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re}} - \frac{y.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}}{\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{\frac{x.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re}} - \frac{y.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}}{\mathsf{hypot}\left(y.re, y.im\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r87845 = x_im;
        double r87846 = y_re;
        double r87847 = r87845 * r87846;
        double r87848 = x_re;
        double r87849 = y_im;
        double r87850 = r87848 * r87849;
        double r87851 = r87847 - r87850;
        double r87852 = r87846 * r87846;
        double r87853 = r87849 * r87849;
        double r87854 = r87852 + r87853;
        double r87855 = r87851 / r87854;
        return r87855;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r87856 = x_im;
        double r87857 = y_re;
        double r87858 = y_im;
        double r87859 = hypot(r87857, r87858);
        double r87860 = r87859 / r87857;
        double r87861 = r87856 / r87860;
        double r87862 = x_re;
        double r87863 = r87859 / r87862;
        double r87864 = r87858 / r87863;
        double r87865 = r87861 - r87864;
        double r87866 = r87865 / r87859;
        return r87866;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 26.4

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

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

    \[\leadsto \frac{\mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\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. Applied *-un-lft-identity26.4

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\sqrt{1}}{1} \cdot \frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \color{blue}{\frac{y.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
  18. Using strategy rm
  19. Applied associate-/l*1.1

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

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

Reproduce

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