Average Error: 26.1 → 0.9
Time: 3.7s
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 code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return (((x_46_im * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((fma((x_46_im / sqrt(hypot(y_46_re, y_46_im))), (y_46_re / sqrt(hypot(y_46_re, y_46_im))), -((y_46_im / sqrt(hypot(y_46_re, y_46_im))) * (x_46_re / sqrt(hypot(y_46_re, y_46_im))))) + ((y_46_im / sqrt(hypot(y_46_re, y_46_im))) * (-(x_46_re / sqrt(hypot(y_46_re, y_46_im))) + (x_46_re / sqrt(hypot(y_46_re, y_46_im)))))) / hypot(y_46_re, y_46_im));
}

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

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

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

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

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

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

    \[\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 associate-*r/17.0

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

    \[\leadsto \frac{\color{blue}{\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)}\]
  11. Using strategy rm
  12. Applied div-sub17.0

    \[\leadsto \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)}\]
  13. Using strategy rm
  14. Applied add-sqr-sqrt17.1

    \[\leadsto \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)}\]
  15. Applied times-frac9.7

    \[\leadsto \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)}\]
  16. Applied add-sqr-sqrt9.8

    \[\leadsto \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)}\]
  17. Applied times-frac0.9

    \[\leadsto \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)}\]
  18. Applied prod-diff0.9

    \[\leadsto \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)}\]
  19. Simplified0.9

    \[\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) + \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)}\]
  20. Final simplification0.9

    \[\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 2020102 +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))))