Average Error: 26.5 → 17.6
Time: 41.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.304579087607779 \cdot 10^{+161}:\\ \;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le -7.011154002702933 \cdot 10^{+91}:\\ \;\;\;\;\frac{-x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\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.304579087607779 \cdot 10^{+161}:\\
\;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\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 r2615928 = x_im;
        double r2615929 = y_re;
        double r2615930 = r2615928 * r2615929;
        double r2615931 = x_re;
        double r2615932 = y_im;
        double r2615933 = r2615931 * r2615932;
        double r2615934 = r2615930 - r2615933;
        double r2615935 = r2615929 * r2615929;
        double r2615936 = r2615932 * r2615932;
        double r2615937 = r2615935 + r2615936;
        double r2615938 = r2615934 / r2615937;
        return r2615938;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2615939 = y_re;
        double r2615940 = -1.304579087607779e+161;
        bool r2615941 = r2615939 <= r2615940;
        double r2615942 = x_im;
        double r2615943 = r2615942 * r2615939;
        double r2615944 = y_im;
        double r2615945 = x_re;
        double r2615946 = r2615944 * r2615945;
        double r2615947 = r2615943 - r2615946;
        double r2615948 = hypot(r2615944, r2615939);
        double r2615949 = r2615947 / r2615948;
        double r2615950 = 1.0;
        double r2615951 = r2615950 / r2615948;
        double r2615952 = r2615949 * r2615951;
        double r2615953 = -7.011154002702933e+91;
        bool r2615954 = r2615939 <= r2615953;
        double r2615955 = -r2615942;
        double r2615956 = r2615939 * r2615939;
        double r2615957 = fma(r2615944, r2615944, r2615956);
        double r2615958 = sqrt(r2615957);
        double r2615959 = r2615955 / r2615958;
        double r2615960 = r2615954 ? r2615959 : r2615952;
        double r2615961 = r2615941 ? r2615952 : r2615960;
        return r2615961;
}

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 2 regimes
  2. if y.re < -1.304579087607779e+161 or -7.011154002702933e+91 < y.re

    1. Initial program 26.5

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

      \[\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 fma-neg26.5

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

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

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

      \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}}\]
    10. Applied add-sqr-sqrt26.6

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{x.im \cdot y.re - x.re \cdot y.im}}}\]
    12. Applied add-cube-cbrt26.6

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{x.im \cdot y.re - x.re \cdot y.im}}\]
    13. Applied times-frac26.5

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

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

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

    if -1.304579087607779e+161 < y.re < -7.011154002702933e+91

    1. Initial program 27.0

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

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

      \[\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*26.9

      \[\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. Taylor expanded around -inf 25.8

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

      \[\leadsto \frac{\color{blue}{-x.im}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification17.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.304579087607779 \cdot 10^{+161}:\\ \;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le -7.011154002702933 \cdot 10^{+91}:\\ \;\;\;\;\frac{-x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]

Reproduce

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