Average Error: 26.7 → 12.9
Time: 10.9s
Precision: 64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.im \le -3.8916390277007425 \cdot 10^{179}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 9.6609644371716767 \cdot 10^{96}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
\mathbf{if}\;y.im \le -3.8916390277007425 \cdot 10^{179}:\\
\;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.im \le 9.6609644371716767 \cdot 10^{96}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r117739 = x_im;
        double r117740 = y_re;
        double r117741 = r117739 * r117740;
        double r117742 = x_re;
        double r117743 = y_im;
        double r117744 = r117742 * r117743;
        double r117745 = r117741 - r117744;
        double r117746 = r117740 * r117740;
        double r117747 = r117743 * r117743;
        double r117748 = r117746 + r117747;
        double r117749 = r117745 / r117748;
        return r117749;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r117750 = y_im;
        double r117751 = -3.8916390277007425e+179;
        bool r117752 = r117750 <= r117751;
        double r117753 = x_re;
        double r117754 = y_re;
        double r117755 = hypot(r117750, r117754);
        double r117756 = r117753 / r117755;
        double r117757 = 9.660964437171677e+96;
        bool r117758 = r117750 <= r117757;
        double r117759 = x_im;
        double r117760 = r117750 * r117753;
        double r117761 = -r117760;
        double r117762 = fma(r117759, r117754, r117761);
        double r117763 = r117762 / r117755;
        double r117764 = r117763 / r117755;
        double r117765 = -r117753;
        double r117766 = r117765 / r117755;
        double r117767 = r117758 ? r117764 : r117766;
        double r117768 = r117752 ? r117756 : r117767;
        return r117768;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Derivation

  1. Split input into 3 regimes
  2. if y.im < -3.8916390277007425e+179

    1. Initial program 44.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified44.0

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity44.0

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    12. Using strategy rm
    13. Applied clear-num30.8

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}}}}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    14. Taylor expanded around -inf 10.8

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

    if -3.8916390277007425e+179 < y.im < 9.660964437171677e+96

    1. Initial program 20.4

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity20.4

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

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

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

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

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

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

    if 9.660964437171677e+96 < y.im

    1. Initial program 40.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified40.0

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity40.0

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    12. Taylor expanded around 0 16.4

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

      \[\leadsto \frac{\color{blue}{-x.re}}{\mathsf{hypot}\left(y.im, y.re\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -3.8916390277007425 \cdot 10^{179}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 9.6609644371716767 \cdot 10^{96}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]

Reproduce

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