Average Error: 26.1 → 13.0
Time: 19.0s
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.431736220616081 \cdot 10^{+97}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 6.920723654382158 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 -4.431736220616081 \cdot 10^{+97}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 6.920723654382158 \cdot 10^{+133}:\\
\;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 r1772515 = x_im;
        double r1772516 = y_re;
        double r1772517 = r1772515 * r1772516;
        double r1772518 = x_re;
        double r1772519 = y_im;
        double r1772520 = r1772518 * r1772519;
        double r1772521 = r1772517 - r1772520;
        double r1772522 = r1772516 * r1772516;
        double r1772523 = r1772519 * r1772519;
        double r1772524 = r1772522 + r1772523;
        double r1772525 = r1772521 / r1772524;
        return r1772525;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1772526 = y_re;
        double r1772527 = -4.431736220616081e+97;
        bool r1772528 = r1772526 <= r1772527;
        double r1772529 = x_im;
        double r1772530 = y_im;
        double r1772531 = hypot(r1772530, r1772526);
        double r1772532 = r1772529 / r1772531;
        double r1772533 = -r1772532;
        double r1772534 = 6.920723654382158e+133;
        bool r1772535 = r1772526 <= r1772534;
        double r1772536 = r1772529 * r1772526;
        double r1772537 = x_re;
        double r1772538 = r1772530 * r1772537;
        double r1772539 = r1772536 - r1772538;
        double r1772540 = r1772539 / r1772531;
        double r1772541 = r1772540 / r1772531;
        double r1772542 = r1772535 ? r1772541 : r1772532;
        double r1772543 = r1772528 ? r1772533 : r1772542;
        return r1772543;
}

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 < -4.431736220616081e+97

    1. Initial program 39.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified39.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-sqrt39.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*39.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 div-inv39.3

      \[\leadsto \frac{\color{blue}{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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)}}\]
    8. Using strategy rm
    9. Applied fma-udef39.3

      \[\leadsto \frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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}}}\]
    10. Applied hypot-def39.3

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

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

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

    if -4.431736220616081e+97 < y.re < 6.920723654382158e+133

    1. Initial program 19.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified19.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-sqrt19.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*18.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. Using strategy rm
    7. Applied div-inv19.0

      \[\leadsto \frac{\color{blue}{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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)}}\]
    8. Using strategy rm
    9. Applied fma-udef19.0

      \[\leadsto \frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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}}}\]
    10. Applied hypot-def19.0

      \[\leadsto \frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    11. Using strategy rm
    12. Applied *-un-lft-identity19.0

      \[\leadsto \frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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)}}\]
    13. Applied associate-/r*19.0

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

      \[\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)}\]

    if 6.920723654382158e+133 < 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 div-inv41.4

      \[\leadsto \frac{\color{blue}{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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)}}\]
    8. Using strategy rm
    9. Applied fma-udef41.4

      \[\leadsto \frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\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}}}\]
    10. Applied hypot-def41.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -4.431736220616081 \cdot 10^{+97}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 6.920723654382158 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 2019146 +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))))