Average Error: 26.3 → 13.1
Time: 4.6s
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 -2.06095728035008259 \cdot 10^{150}:\\ \;\;\;\;{\left(\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \mathbf{elif}\;y.re \le 1.04482715632166882 \cdot 10^{105}:\\ \;\;\;\;{\left(\frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \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 -2.06095728035008259 \cdot 10^{150}:\\
\;\;\;\;{\left(\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\

\mathbf{elif}\;y.re \le 1.04482715632166882 \cdot 10^{105}:\\
\;\;\;\;{\left(\frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r49582 = x_im;
        double r49583 = y_re;
        double r49584 = r49582 * r49583;
        double r49585 = x_re;
        double r49586 = y_im;
        double r49587 = r49585 * r49586;
        double r49588 = r49584 - r49587;
        double r49589 = r49583 * r49583;
        double r49590 = r49586 * r49586;
        double r49591 = r49589 + r49590;
        double r49592 = r49588 / r49591;
        return r49592;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r49593 = y_re;
        double r49594 = -2.0609572803500826e+150;
        bool r49595 = r49593 <= r49594;
        double r49596 = -1.0;
        double r49597 = x_im;
        double r49598 = r49596 * r49597;
        double r49599 = y_im;
        double r49600 = hypot(r49593, r49599);
        double r49601 = r49598 / r49600;
        double r49602 = 1.0;
        double r49603 = pow(r49601, r49602);
        double r49604 = 1.0448271563216688e+105;
        bool r49605 = r49593 <= r49604;
        double r49606 = r49597 * r49593;
        double r49607 = x_re;
        double r49608 = r49607 * r49599;
        double r49609 = r49606 - r49608;
        double r49610 = r49602 / r49600;
        double r49611 = r49609 * r49610;
        double r49612 = r49611 / r49600;
        double r49613 = pow(r49612, r49602);
        double r49614 = r49597 / r49600;
        double r49615 = pow(r49614, r49602);
        double r49616 = r49605 ? r49613 : r49615;
        double r49617 = r49595 ? r49603 : r49616;
        return r49617;
}

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 < -2.0609572803500826e+150

    1. Initial program 44.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt44.3

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied *-un-lft-identity44.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac44.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified44.3

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
    11. Applied pow-prod-down27.8

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

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

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

    if -2.0609572803500826e+150 < y.re < 1.0448271563216688e+105

    1. Initial program 19.2

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt19.2

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied *-un-lft-identity19.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac19.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified19.2

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    8. Using strategy rm
    9. Applied pow112.4

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
    11. Applied pow-prod-down12.4

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}}^{1}\]
    13. Using strategy rm
    14. Applied div-inv12.3

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

    if 1.0448271563216688e+105 < y.re

    1. Initial program 39.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt39.7

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied *-un-lft-identity39.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac39.8

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified39.8

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -2.06095728035008259 \cdot 10^{150}:\\ \;\;\;\;{\left(\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \mathbf{elif}\;y.re \le 1.04482715632166882 \cdot 10^{105}:\\ \;\;\;\;{\left(\frac{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020039 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))