Average Error: 25.9 → 12.6
Time: 17.2s
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 -4.468015220407937198664692125642397129235 \cdot 10^{144}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 3.367831838990333489069970368031606022092 \cdot 10^{157}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\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 -4.468015220407937198664692125642397129235 \cdot 10^{144}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r61078 = x_im;
        double r61079 = y_re;
        double r61080 = r61078 * r61079;
        double r61081 = x_re;
        double r61082 = y_im;
        double r61083 = r61081 * r61082;
        double r61084 = r61080 - r61083;
        double r61085 = r61079 * r61079;
        double r61086 = r61082 * r61082;
        double r61087 = r61085 + r61086;
        double r61088 = r61084 / r61087;
        return r61088;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r61089 = y_re;
        double r61090 = -4.468015220407937e+144;
        bool r61091 = r61089 <= r61090;
        double r61092 = x_im;
        double r61093 = -r61092;
        double r61094 = y_im;
        double r61095 = hypot(r61089, r61094);
        double r61096 = r61093 / r61095;
        double r61097 = 3.3678318389903335e+157;
        bool r61098 = r61089 <= r61097;
        double r61099 = 1.0;
        double r61100 = x_re;
        double r61101 = r61094 * r61100;
        double r61102 = -r61101;
        double r61103 = fma(r61092, r61089, r61102);
        double r61104 = r61095 / r61103;
        double r61105 = r61099 / r61104;
        double r61106 = r61105 / r61095;
        double r61107 = r61092 / r61095;
        double r61108 = r61098 ? r61106 : r61107;
        double r61109 = r61091 ? r61096 : r61108;
        return r61109;
}

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.re < -4.468015220407937e+144

    1. Initial program 43.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-sqrt43.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-identity43.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-frac43.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. Simplified43.1

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}} \cdot {\left(\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
    11. Applied pow-prod-down27.5

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

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

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

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

    if -4.468015220407937e+144 < y.re < 3.3678318389903335e+157

    1. Initial program 19.2

      \[\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-sqrt19.2

      \[\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-identity19.2

      \[\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-frac19.2

      \[\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. Simplified19.2

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

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

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

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

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}}^{1}\]
    13. Using strategy rm
    14. Applied clear-num12.4

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

    if 3.3678318389903335e+157 < y.re

    1. Initial program 45.3

      \[\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-sqrt45.3

      \[\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-identity45.3

      \[\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-frac45.3

      \[\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. Simplified45.3

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}} \cdot {\left(\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
    11. Applied pow-prod-down29.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -4.468015220407937198664692125642397129235 \cdot 10^{144}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 3.367831838990333489069970368031606022092 \cdot 10^{157}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

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