Average Error: 25.5 → 12.8
Time: 16.7s
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 -3.54617340469776 \cdot 10^{+94}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.9951833757328278 \cdot 10^{+142}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.im, y.re\right)} - \frac{x.re \cdot y.im}{\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 -3.54617340469776 \cdot 10^{+94}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 1.9951833757328278 \cdot 10^{+142}:\\
\;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.im, y.re\right)} - \frac{x.re \cdot y.im}{\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 r2070503 = x_im;
        double r2070504 = y_re;
        double r2070505 = r2070503 * r2070504;
        double r2070506 = x_re;
        double r2070507 = y_im;
        double r2070508 = r2070506 * r2070507;
        double r2070509 = r2070505 - r2070508;
        double r2070510 = r2070504 * r2070504;
        double r2070511 = r2070507 * r2070507;
        double r2070512 = r2070510 + r2070511;
        double r2070513 = r2070509 / r2070512;
        return r2070513;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2070514 = y_re;
        double r2070515 = -3.54617340469776e+94;
        bool r2070516 = r2070514 <= r2070515;
        double r2070517 = x_im;
        double r2070518 = -r2070517;
        double r2070519 = y_im;
        double r2070520 = hypot(r2070519, r2070514);
        double r2070521 = r2070518 / r2070520;
        double r2070522 = 1.9951833757328278e+142;
        bool r2070523 = r2070514 <= r2070522;
        double r2070524 = r2070517 * r2070514;
        double r2070525 = r2070524 / r2070520;
        double r2070526 = x_re;
        double r2070527 = r2070526 * r2070519;
        double r2070528 = r2070527 / r2070520;
        double r2070529 = r2070525 - r2070528;
        double r2070530 = r2070529 / r2070520;
        double r2070531 = r2070517 / r2070520;
        double r2070532 = r2070523 ? r2070530 : r2070531;
        double r2070533 = r2070516 ? r2070521 : r2070532;
        return r2070533;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if y.re < -3.54617340469776e+94

    1. Initial program 38.3

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

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

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

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

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

      \[\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 16.2

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

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

    if -3.54617340469776e+94 < y.re < 1.9951833757328278e+142

    1. Initial program 18.6

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

      \[\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-sqrt18.6

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

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

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

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

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

      \[\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.4

      \[\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. Using strategy rm
    14. Applied div-sub11.4

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

    if 1.9951833757328278e+142 < y.re

    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. Using strategy rm
    10. Applied *-un-lft-identity41.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}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
    11. Applied associate-/r*41.4

      \[\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. Simplified27.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 14.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -3.54617340469776 \cdot 10^{+94}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.9951833757328278 \cdot 10^{+142}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.im, y.re\right)} - \frac{x.re \cdot y.im}{\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 2019135 +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))))