Average Error: 25.7 → 12.2
Time: 17.6s
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.re \le -1.7011328718966327 \cdot 10^{+126}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.1342142675220587 \cdot 10^{-33}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.1159956553026526 \cdot 10^{+143}:\\ \;\;\;\;\frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot x.im - \frac{y.im}{\frac{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}{x.re}}\\ \mathbf{elif}\;y.re \le 7.096094976191454 \cdot 10^{+169}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\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.re \le -1.7011328718966327 \cdot 10^{+126}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{\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 r2430903 = x_im;
        double r2430904 = y_re;
        double r2430905 = r2430903 * r2430904;
        double r2430906 = x_re;
        double r2430907 = y_im;
        double r2430908 = r2430906 * r2430907;
        double r2430909 = r2430905 - r2430908;
        double r2430910 = r2430904 * r2430904;
        double r2430911 = r2430907 * r2430907;
        double r2430912 = r2430910 + r2430911;
        double r2430913 = r2430909 / r2430912;
        return r2430913;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2430914 = y_re;
        double r2430915 = -1.7011328718966327e+126;
        bool r2430916 = r2430914 <= r2430915;
        double r2430917 = x_im;
        double r2430918 = y_im;
        double r2430919 = hypot(r2430918, r2430914);
        double r2430920 = r2430917 / r2430919;
        double r2430921 = -r2430920;
        double r2430922 = 1.1342142675220587e-33;
        bool r2430923 = r2430914 <= r2430922;
        double r2430924 = r2430917 * r2430914;
        double r2430925 = x_re;
        double r2430926 = r2430918 * r2430925;
        double r2430927 = r2430924 - r2430926;
        double r2430928 = r2430927 / r2430919;
        double r2430929 = r2430928 / r2430919;
        double r2430930 = 1.1159956553026526e+143;
        bool r2430931 = r2430914 <= r2430930;
        double r2430932 = r2430914 * r2430914;
        double r2430933 = fma(r2430918, r2430918, r2430932);
        double r2430934 = r2430914 / r2430933;
        double r2430935 = r2430934 * r2430917;
        double r2430936 = r2430933 / r2430925;
        double r2430937 = r2430918 / r2430936;
        double r2430938 = r2430935 - r2430937;
        double r2430939 = 7.096094976191454e+169;
        bool r2430940 = r2430914 <= r2430939;
        double r2430941 = r2430940 ? r2430929 : r2430920;
        double r2430942 = r2430931 ? r2430938 : r2430941;
        double r2430943 = r2430923 ? r2430929 : r2430942;
        double r2430944 = r2430916 ? r2430921 : r2430943;
        return r2430944;
}

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 4 regimes
  2. if y.re < -1.7011328718966327e+126

    1. Initial program 41.4

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 associate-/r*41.4

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef41.4

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

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

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

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

    if -1.7011328718966327e+126 < y.re < 1.1342142675220587e-33 or 1.1159956553026526e+143 < y.re < 7.096094976191454e+169

    1. Initial program 19.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified19.7

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 associate-/r*19.7

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef19.7

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

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

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

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

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

    if 1.1342142675220587e-33 < y.re < 1.1159956553026526e+143

    1. Initial program 17.2

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 associate-/r*17.1

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef17.1

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

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

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

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

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

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

    if 7.096094976191454e+169 < y.re

    1. Initial program 43.2

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 associate-/r*43.2

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef43.2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.7011328718966327 \cdot 10^{+126}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.1342142675220587 \cdot 10^{-33}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.1159956553026526 \cdot 10^{+143}:\\ \;\;\;\;\frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot x.im - \frac{y.im}{\frac{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}{x.re}}\\ \mathbf{elif}\;y.re \le 7.096094976191454 \cdot 10^{+169}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]

Reproduce

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