Average Error: 26.6 → 13.5
Time: 16.2s
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.im \le -1.696889279647290237234578100884848526295 \cdot 10^{245}:\\ \;\;\;\;\frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot x.im\\ \mathbf{elif}\;y.im \le 7.009208612122958667307700471256846817647 \cdot 10^{165}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \frac{1}{\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.im \le -1.696889279647290237234578100884848526295 \cdot 10^{245}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot x.im\\

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

\mathbf{else}:\\
\;\;\;\;x.im \cdot \frac{1}{\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 r3137836 = x_re;
        double r3137837 = y_re;
        double r3137838 = r3137836 * r3137837;
        double r3137839 = x_im;
        double r3137840 = y_im;
        double r3137841 = r3137839 * r3137840;
        double r3137842 = r3137838 + r3137841;
        double r3137843 = r3137837 * r3137837;
        double r3137844 = r3137840 * r3137840;
        double r3137845 = r3137843 + r3137844;
        double r3137846 = r3137842 / r3137845;
        return r3137846;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r3137847 = y_im;
        double r3137848 = -1.6968892796472902e+245;
        bool r3137849 = r3137847 <= r3137848;
        double r3137850 = -1.0;
        double r3137851 = y_re;
        double r3137852 = hypot(r3137851, r3137847);
        double r3137853 = r3137850 / r3137852;
        double r3137854 = x_im;
        double r3137855 = r3137853 * r3137854;
        double r3137856 = 7.009208612122959e+165;
        bool r3137857 = r3137847 <= r3137856;
        double r3137858 = x_re;
        double r3137859 = r3137854 * r3137847;
        double r3137860 = fma(r3137851, r3137858, r3137859);
        double r3137861 = r3137860 / r3137852;
        double r3137862 = r3137861 / r3137852;
        double r3137863 = 1.0;
        double r3137864 = r3137863 / r3137852;
        double r3137865 = r3137854 * r3137864;
        double r3137866 = r3137857 ? r3137862 : r3137865;
        double r3137867 = r3137849 ? r3137855 : r3137866;
        return r3137867;
}

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 < -1.6968892796472902e+245

    1. Initial program 41.8

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

      \[\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-num41.8

      \[\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-identity41.8

      \[\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-sqrt41.8

      \[\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-frac41.8

      \[\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-cbrt41.8

      \[\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-frac41.8

      \[\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. Simplified41.8

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\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. Simplified34.2

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

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

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

    if -1.6968892796472902e+245 < y.im < 7.009208612122959e+165

    1. Initial program 23.0

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

      \[\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.1

      \[\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.1

      \[\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.1

      \[\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.1

      \[\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.1

      \[\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.0

      \[\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.0

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\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. Simplified14.0

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

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

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

    if 7.009208612122959e+165 < y.im

    1. Initial program 45.0

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

      \[\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-num45.0

      \[\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-identity45.0

      \[\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-sqrt45.0

      \[\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-frac45.0

      \[\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-cbrt45.0

      \[\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-frac45.0

      \[\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. Simplified45.0

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\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. Simplified29.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -1.696889279647290237234578100884848526295 \cdot 10^{245}:\\ \;\;\;\;\frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot x.im\\ \mathbf{elif}\;y.im \le 7.009208612122958667307700471256846817647 \cdot 10^{165}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

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