Average Error: 25.4 → 16.5
Time: 15.3s
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.315223608026935 \cdot 10^{+87}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 1.263326239685677 \cdot 10^{+154}:\\ \;\;\;\;\frac{-x.re}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\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.im \le 3.315223608026935 \cdot 10^{+87}:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\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 r2374151 = x_im;
        double r2374152 = y_re;
        double r2374153 = r2374151 * r2374152;
        double r2374154 = x_re;
        double r2374155 = y_im;
        double r2374156 = r2374154 * r2374155;
        double r2374157 = r2374153 - r2374156;
        double r2374158 = r2374152 * r2374152;
        double r2374159 = r2374155 * r2374155;
        double r2374160 = r2374158 + r2374159;
        double r2374161 = r2374157 / r2374160;
        return r2374161;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2374162 = y_im;
        double r2374163 = 3.315223608026935e+87;
        bool r2374164 = r2374162 <= r2374163;
        double r2374165 = x_im;
        double r2374166 = y_re;
        double r2374167 = r2374165 * r2374166;
        double r2374168 = x_re;
        double r2374169 = r2374168 * r2374162;
        double r2374170 = r2374167 - r2374169;
        double r2374171 = hypot(r2374162, r2374166);
        double r2374172 = r2374170 / r2374171;
        double r2374173 = 1.0;
        double r2374174 = r2374173 / r2374171;
        double r2374175 = r2374172 * r2374174;
        double r2374176 = 1.263326239685677e+154;
        bool r2374177 = r2374162 <= r2374176;
        double r2374178 = -r2374168;
        double r2374179 = r2374166 * r2374166;
        double r2374180 = fma(r2374162, r2374162, r2374179);
        double r2374181 = sqrt(r2374180);
        double r2374182 = r2374178 / r2374181;
        double r2374183 = r2374177 ? r2374182 : r2374175;
        double r2374184 = r2374164 ? r2374175 : r2374183;
        return r2374184;
}

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.im < 3.315223608026935e+87 or 1.263326239685677e+154 < y.im

    1. Initial program 25.6

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}\]
    5. Applied associate-/l*25.7

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

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

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

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

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

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

      \[\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, \left(y.re \cdot y.re\right)\right)}}{x.im \cdot y.re - x.re \cdot y.im}}\]
    13. Simplified16.2

      \[\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 3.315223608026935e+87 < y.im < 1.263326239685677e+154

    1. Initial program 22.5

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le 3.315223608026935 \cdot 10^{+87}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 1.263326239685677 \cdot 10^{+154}:\\ \;\;\;\;\frac{-x.re}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\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 2019132 +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))))