Average Error: 26.0 → 13.0
Time: 10.4s
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 -6.603705426560988 \cdot 10^{+145}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 7.75132925369235 \cdot 10^{+139}:\\ \;\;\;\;\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 -6.603705426560988 \cdot 10^{+145}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 7.75132925369235 \cdot 10^{+139}:\\
\;\;\;\;\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 r1595590 = x_im;
        double r1595591 = y_re;
        double r1595592 = r1595590 * r1595591;
        double r1595593 = x_re;
        double r1595594 = y_im;
        double r1595595 = r1595593 * r1595594;
        double r1595596 = r1595592 - r1595595;
        double r1595597 = r1595591 * r1595591;
        double r1595598 = r1595594 * r1595594;
        double r1595599 = r1595597 + r1595598;
        double r1595600 = r1595596 / r1595599;
        return r1595600;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1595601 = y_re;
        double r1595602 = -6.603705426560988e+145;
        bool r1595603 = r1595601 <= r1595602;
        double r1595604 = x_im;
        double r1595605 = y_im;
        double r1595606 = hypot(r1595605, r1595601);
        double r1595607 = r1595604 / r1595606;
        double r1595608 = -r1595607;
        double r1595609 = 7.75132925369235e+139;
        bool r1595610 = r1595601 <= r1595609;
        double r1595611 = r1595604 * r1595601;
        double r1595612 = x_re;
        double r1595613 = r1595605 * r1595612;
        double r1595614 = r1595611 - r1595613;
        double r1595615 = r1595614 / r1595606;
        double r1595616 = r1595615 / r1595606;
        double r1595617 = r1595610 ? r1595616 : r1595607;
        double r1595618 = r1595603 ? r1595608 : r1595617;
        return r1595618;
}

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 < -6.603705426560988e+145

    1. Initial program 43.7

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

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

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

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

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

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

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

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

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

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

    if -6.603705426560988e+145 < y.re < 7.75132925369235e+139

    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*19.0

      \[\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-udef19.0

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

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

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def12.3

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

      \[\leadsto \frac{\frac{\color{blue}{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 7.75132925369235e+139 < y.re

    1. Initial program 42.9

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

      \[\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-sqrt42.9

      \[\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*42.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 fma-udef42.9

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

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

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def29.0

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

      \[\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 -6.603705426560988 \cdot 10^{+145}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 7.75132925369235 \cdot 10^{+139}:\\ \;\;\;\;\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 2019156 +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))))