Average Error: 25.4 → 12.6
Time: 23.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 -9.959880769521784 \cdot 10^{+162}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.6080482430506382 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{x.im \cdot y.re - y.im \cdot x.re}{\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 -9.959880769521784 \cdot 10^{+162}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 1.6080482430506382 \cdot 10^{+147}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{x.im \cdot y.re - y.im \cdot x.re}{\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 r1958720 = x_im;
        double r1958721 = y_re;
        double r1958722 = r1958720 * r1958721;
        double r1958723 = x_re;
        double r1958724 = y_im;
        double r1958725 = r1958723 * r1958724;
        double r1958726 = r1958722 - r1958725;
        double r1958727 = r1958721 * r1958721;
        double r1958728 = r1958724 * r1958724;
        double r1958729 = r1958727 + r1958728;
        double r1958730 = r1958726 / r1958729;
        return r1958730;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1958731 = y_re;
        double r1958732 = -9.959880769521784e+162;
        bool r1958733 = r1958731 <= r1958732;
        double r1958734 = x_im;
        double r1958735 = -r1958734;
        double r1958736 = y_im;
        double r1958737 = hypot(r1958736, r1958731);
        double r1958738 = r1958735 / r1958737;
        double r1958739 = 1.6080482430506382e+147;
        bool r1958740 = r1958731 <= r1958739;
        double r1958741 = 1.0;
        double r1958742 = r1958741 / r1958737;
        double r1958743 = r1958734 * r1958731;
        double r1958744 = x_re;
        double r1958745 = r1958736 * r1958744;
        double r1958746 = r1958743 - r1958745;
        double r1958747 = r1958746 / r1958737;
        double r1958748 = r1958742 * r1958747;
        double r1958749 = r1958734 / r1958737;
        double r1958750 = r1958740 ? r1958748 : r1958749;
        double r1958751 = r1958733 ? r1958738 : r1958750;
        return r1958751;
}

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 < -9.959880769521784e+162

    1. Initial program 43.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified43.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-sqrt43.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*43.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-udef43.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-def43.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 12.9

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

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

    if -9.959880769521784e+162 < y.re < 1.6080482430506382e+147

    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 fma-udef18.9

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

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

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

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

      \[\leadsto \frac{\frac{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{y.re \cdot x.im - y.im \cdot x.re}}}{\color{blue}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
    14. Applied associate-/r/12.4

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

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

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

    if 1.6080482430506382e+147 < y.re

    1. Initial program 43.4

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified43.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-sqrt43.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*43.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-udef43.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-def43.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 clear-num43.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -9.959880769521784 \cdot 10^{+162}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.6080482430506382 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{x.im \cdot y.re - y.im \cdot x.re}{\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 2019134 +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))))