Average Error: 25.9 → 12.5
Time: 13.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.im \le -8.854189588374422409856349074066788051196 \cdot 10^{171}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.im \le 2.946859042858365719350909171488092188425 \cdot 10^{116}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\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.im \le -8.854189588374422409856349074066788051196 \cdot 10^{171}:\\
\;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r41442 = x_im;
        double r41443 = y_re;
        double r41444 = r41442 * r41443;
        double r41445 = x_re;
        double r41446 = y_im;
        double r41447 = r41445 * r41446;
        double r41448 = r41444 - r41447;
        double r41449 = r41443 * r41443;
        double r41450 = r41446 * r41446;
        double r41451 = r41449 + r41450;
        double r41452 = r41448 / r41451;
        return r41452;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r41453 = y_im;
        double r41454 = -8.854189588374422e+171;
        bool r41455 = r41453 <= r41454;
        double r41456 = x_re;
        double r41457 = y_re;
        double r41458 = hypot(r41457, r41453);
        double r41459 = r41456 / r41458;
        double r41460 = 2.9468590428583657e+116;
        bool r41461 = r41453 <= r41460;
        double r41462 = -r41453;
        double r41463 = x_im;
        double r41464 = r41457 * r41463;
        double r41465 = fma(r41456, r41462, r41464);
        double r41466 = r41465 / r41458;
        double r41467 = r41466 / r41458;
        double r41468 = -r41456;
        double r41469 = r41468 / r41458;
        double r41470 = r41461 ? r41467 : r41469;
        double r41471 = r41455 ? r41459 : r41470;
        return r41471;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Derivation

  1. Split input into 3 regimes
  2. if y.im < -8.854189588374422e+171

    1. Initial program 44.5

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified44.5

      \[\leadsto \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt44.5

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity44.5

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

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied associate-*r/30.6

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

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

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

    if -8.854189588374422e+171 < y.im < 2.9468590428583657e+116

    1. Initial program 19.6

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

      \[\leadsto \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt19.6

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity19.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac19.6

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied associate-*r/12.5

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    12. Using strategy rm
    13. Applied clear-num12.5

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

      \[\leadsto \frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    16. Applied *-un-lft-identity12.5

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{1} \cdot \frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    18. Applied add-cube-cbrt12.5

      \[\leadsto \frac{\frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{1}{1} \cdot \frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    19. Applied times-frac12.5

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

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

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

    if 2.9468590428583657e+116 < y.im

    1. Initial program 39.9

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

      \[\leadsto \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt39.9

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity39.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac39.9

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied associate-*r/26.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -8.854189588374422409856349074066788051196 \cdot 10^{171}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.im \le 2.946859042858365719350909171488092188425 \cdot 10^{116}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019208 +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))))