Average Error: 26.0 → 14.8
Time: 13.5s
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 7.643741764178763599768402058466858347704 \cdot 10^{138}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.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{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot x.re\\ \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 7.643741764178763599768402058466858347704 \cdot 10^{138}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.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{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot x.re\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2451474 = x_re;
        double r2451475 = y_re;
        double r2451476 = r2451474 * r2451475;
        double r2451477 = x_im;
        double r2451478 = y_im;
        double r2451479 = r2451477 * r2451478;
        double r2451480 = r2451476 + r2451479;
        double r2451481 = r2451475 * r2451475;
        double r2451482 = r2451478 * r2451478;
        double r2451483 = r2451481 + r2451482;
        double r2451484 = r2451480 / r2451483;
        return r2451484;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2451485 = y_re;
        double r2451486 = 7.643741764178764e+138;
        bool r2451487 = r2451485 <= r2451486;
        double r2451488 = x_re;
        double r2451489 = y_im;
        double r2451490 = x_im;
        double r2451491 = r2451489 * r2451490;
        double r2451492 = fma(r2451485, r2451488, r2451491);
        double r2451493 = hypot(r2451489, r2451485);
        double r2451494 = r2451492 / r2451493;
        double r2451495 = r2451494 / r2451493;
        double r2451496 = 1.0;
        double r2451497 = r2451496 / r2451493;
        double r2451498 = r2451497 * r2451488;
        double r2451499 = r2451487 ? r2451495 : r2451498;
        return r2451499;
}

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 2 regimes
  2. if y.re < 7.643741764178764e+138

    1. Initial program 23.2

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified23.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 clear-num23.4

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}}}\]
    9. Applied add-cube-cbrt23.4

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

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

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

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

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

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

    if 7.643741764178764e+138 < y.re

    1. Initial program 42.3

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

      \[\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 clear-num42.3

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{1} \cdot \frac{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}}}\]
    9. Applied add-cube-cbrt42.3

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le 7.643741764178763599768402058466858347704 \cdot 10^{138}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.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{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot x.re\\ \end{array}\]

Reproduce

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