Average Error: 26.0 → 0.8
Time: 4.5s
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)}{\mathsf{hypot}\left(y.re, y.im\right)} + \left(\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)\right) \cdot \frac{1}{\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)}{\mathsf{hypot}\left(y.re, y.im\right)} + \left(\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)\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r50671 = x_im;
        double r50672 = y_re;
        double r50673 = r50671 * r50672;
        double r50674 = x_re;
        double r50675 = y_im;
        double r50676 = r50674 * r50675;
        double r50677 = r50673 - r50676;
        double r50678 = r50672 * r50672;
        double r50679 = r50675 * r50675;
        double r50680 = r50678 + r50679;
        double r50681 = r50677 / r50680;
        return r50681;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r50682 = x_im;
        double r50683 = y_re;
        double r50684 = y_im;
        double r50685 = hypot(r50683, r50684);
        double r50686 = sqrt(r50685);
        double r50687 = r50682 / r50686;
        double r50688 = r50683 / r50686;
        double r50689 = r50684 / r50686;
        double r50690 = x_re;
        double r50691 = r50690 / r50686;
        double r50692 = r50689 * r50691;
        double r50693 = -r50692;
        double r50694 = fma(r50687, r50688, r50693);
        double r50695 = r50694 / r50685;
        double r50696 = -r50691;
        double r50697 = r50696 + r50691;
        double r50698 = r50689 * r50697;
        double r50699 = 1.0;
        double r50700 = r50699 / r50685;
        double r50701 = r50698 * r50700;
        double r50702 = r50695 + r50701;
        return r50702;
}

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

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

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

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

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

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

    \[\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 div-sub16.8

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\left(\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)}\right)}\]
  10. Using strategy rm
  11. Applied add-sqr-sqrt16.8

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \left(\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)}}}\right)\]
  12. Applied times-frac9.4

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \left(\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)}}}\right)\]
  13. Applied add-sqr-sqrt9.5

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \left(\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)}}\right)\]
  14. Applied times-frac0.9

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \left(\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)}}\right)\]
  15. Applied prod-diff0.9

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\left(\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)\right)}\]
  16. Applied distribute-lft-in0.9

    \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \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{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \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)}\]
  17. Simplified0.8

    \[\leadsto \color{blue}{\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)}{\mathsf{hypot}\left(y.re, y.im\right)}} + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \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)\]
  18. Simplified0.8

    \[\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)}{\mathsf{hypot}\left(y.re, y.im\right)} + \color{blue}{\left(\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)\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
  19. Final simplification0.8

    \[\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)}{\mathsf{hypot}\left(y.re, y.im\right)} + \left(\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)\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\]

Reproduce

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