Average Error: 25.6 → 12.8
Time: 15.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.im \le -2.349525322457489826589608031591607051529 \cdot 10^{135}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.im \le 9.70450990751971859322124590202865896249 \cdot 10^{95}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{x.re}{\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.im \le -2.349525322457489826589608031591607051529 \cdot 10^{135}:\\
\;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

\mathbf{else}:\\
\;\;\;\;-\frac{x.re}{\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 r41136 = x_im;
        double r41137 = y_re;
        double r41138 = r41136 * r41137;
        double r41139 = x_re;
        double r41140 = y_im;
        double r41141 = r41139 * r41140;
        double r41142 = r41138 - r41141;
        double r41143 = r41137 * r41137;
        double r41144 = r41140 * r41140;
        double r41145 = r41143 + r41144;
        double r41146 = r41142 / r41145;
        return r41146;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r41147 = y_im;
        double r41148 = -2.3495253224574898e+135;
        bool r41149 = r41147 <= r41148;
        double r41150 = x_re;
        double r41151 = y_re;
        double r41152 = hypot(r41151, r41147);
        double r41153 = r41150 / r41152;
        double r41154 = 9.704509907519719e+95;
        bool r41155 = r41147 <= r41154;
        double r41156 = 1.0;
        double r41157 = -r41147;
        double r41158 = x_im;
        double r41159 = r41158 * r41151;
        double r41160 = fma(r41157, r41150, r41159);
        double r41161 = r41152 / r41160;
        double r41162 = r41156 / r41161;
        double r41163 = r41162 / r41152;
        double r41164 = -r41153;
        double r41165 = r41155 ? r41163 : r41164;
        double r41166 = r41149 ? r41153 : r41165;
        return r41166;
}

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 < -2.3495253224574898e+135

    1. Initial program 41.2

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

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

      \[\leadsto \frac{\mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}{\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 *-un-lft-identity41.2

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}}{\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)}}\]
    6. Applied times-frac41.2

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

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

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

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

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

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

    if -2.3495253224574898e+135 < y.im < 9.704509907519719e+95

    1. Initial program 18.7

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

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

      \[\leadsto \frac{\mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}{\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 *-un-lft-identity18.7

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}}{\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)}}\]
    6. Applied times-frac18.7

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

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

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

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

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

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

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

    if 9.704509907519719e+95 < y.im

    1. Initial program 39.2

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

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

      \[\leadsto \frac{\mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}{\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 *-un-lft-identity39.2

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(-y.im, x.re, x.im \cdot y.re\right)}}{\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)}}\]
    6. Applied times-frac39.2

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

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

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

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

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

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

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

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

Reproduce

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