Average Error: 25.9 → 12.9
Time: 19.9s
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 -1.8277997780989823 \cdot 10^{+123}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.7195081298008246 \cdot 10^{+221}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\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 -1.8277997780989823 \cdot 10^{+123}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{\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 r1520420 = x_re;
        double r1520421 = y_re;
        double r1520422 = r1520420 * r1520421;
        double r1520423 = x_im;
        double r1520424 = y_im;
        double r1520425 = r1520423 * r1520424;
        double r1520426 = r1520422 + r1520425;
        double r1520427 = r1520421 * r1520421;
        double r1520428 = r1520424 * r1520424;
        double r1520429 = r1520427 + r1520428;
        double r1520430 = r1520426 / r1520429;
        return r1520430;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1520431 = y_re;
        double r1520432 = -1.8277997780989823e+123;
        bool r1520433 = r1520431 <= r1520432;
        double r1520434 = x_re;
        double r1520435 = -r1520434;
        double r1520436 = y_im;
        double r1520437 = hypot(r1520436, r1520431);
        double r1520438 = r1520435 / r1520437;
        double r1520439 = 1.7195081298008246e+221;
        bool r1520440 = r1520431 <= r1520439;
        double r1520441 = x_im;
        double r1520442 = r1520436 * r1520441;
        double r1520443 = fma(r1520434, r1520431, r1520442);
        double r1520444 = r1520443 / r1520437;
        double r1520445 = r1520444 / r1520437;
        double r1520446 = r1520434 / r1520437;
        double r1520447 = r1520440 ? r1520445 : r1520446;
        double r1520448 = r1520433 ? r1520438 : r1520447;
        return r1520448;
}

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 < -1.8277997780989823e+123

    1. Initial program 41.5

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

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

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

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

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

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

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

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

    if -1.8277997780989823e+123 < y.re < 1.7195081298008246e+221

    1. Initial program 21.2

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

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

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

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

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

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

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

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

    if 1.7195081298008246e+221 < y.re

    1. Initial program 39.1

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.8277997780989823 \cdot 10^{+123}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.7195081298008246 \cdot 10^{+221}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]

Reproduce

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