Average Error: 25.9 → 12.6
Time: 18.3s
Precision: 64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -5.28633112851537097840983624634443392687 \cdot 10^{162}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.543067909128725187583327964894972109151 \cdot 10^{185}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, y.im \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.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
\mathbf{if}\;y.re \le -5.28633112851537097840983624634443392687 \cdot 10^{162}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 1.543067909128725187583327964894972109151 \cdot 10^{185}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, y.im \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 r93419 = x_re;
        double r93420 = y_re;
        double r93421 = r93419 * r93420;
        double r93422 = x_im;
        double r93423 = y_im;
        double r93424 = r93422 * r93423;
        double r93425 = r93421 + r93424;
        double r93426 = r93420 * r93420;
        double r93427 = r93423 * r93423;
        double r93428 = r93426 + r93427;
        double r93429 = r93425 / r93428;
        return r93429;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r93430 = y_re;
        double r93431 = -5.286331128515371e+162;
        bool r93432 = r93430 <= r93431;
        double r93433 = x_re;
        double r93434 = -r93433;
        double r93435 = y_im;
        double r93436 = hypot(r93430, r93435);
        double r93437 = r93434 / r93436;
        double r93438 = 1.5430679091287252e+185;
        bool r93439 = r93430 <= r93438;
        double r93440 = x_im;
        double r93441 = r93435 * r93440;
        double r93442 = fma(r93430, r93433, r93441);
        double r93443 = r93442 / r93436;
        double r93444 = r93443 / r93436;
        double r93445 = r93433 / r93436;
        double r93446 = r93439 ? r93444 : r93445;
        double r93447 = r93432 ? r93437 : r93446;
        return r93447;
}

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.re < -5.286331128515371e+162

    1. Initial program 44.6

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

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

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\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.6

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, x.im \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.6

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)} \cdot \frac{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    13. Applied associate-*l*29.7

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

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

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

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

    if -5.286331128515371e+162 < y.re < 1.5430679091287252e+185

    1. Initial program 20.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified20.4

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

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\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-identity20.4

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, x.im \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-frac20.4

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)} \cdot \frac{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    13. Applied associate-*l*12.7

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

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

    if 1.5430679091287252e+185 < y.re

    1. Initial program 44.3

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

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

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\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.3

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, x.im \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.3

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.re, y.im\right)}\right)} \cdot \frac{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    13. Applied associate-*l*30.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -5.28633112851537097840983624634443392687 \cdot 10^{162}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.543067909128725187583327964894972109151 \cdot 10^{185}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, y.im \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 2019325 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, real part"
  :precision binary64
  (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))