Average Error: 25.7 → 13.2
Time: 55.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.im \le -1.0287542866145704 \cdot 10^{+96}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{-x.im}}\\ \mathbf{elif}\;y.im \le 6.658964062989261 \cdot 10^{+180}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}}{\frac{1}{\frac{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}}{\frac{1}{x.im}}\\ \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.0287542866145704 \cdot 10^{+96}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{-x.im}}\\

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r1935893 = x_re;
        double r1935894 = y_re;
        double r1935895 = r1935893 * r1935894;
        double r1935896 = x_im;
        double r1935897 = y_im;
        double r1935898 = r1935896 * r1935897;
        double r1935899 = r1935895 + r1935898;
        double r1935900 = r1935894 * r1935894;
        double r1935901 = r1935897 * r1935897;
        double r1935902 = r1935900 + r1935901;
        double r1935903 = r1935899 / r1935902;
        return r1935903;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1935904 = y_im;
        double r1935905 = -1.0287542866145704e+96;
        bool r1935906 = r1935904 <= r1935905;
        double r1935907 = 1.0;
        double r1935908 = y_re;
        double r1935909 = hypot(r1935904, r1935908);
        double r1935910 = x_im;
        double r1935911 = -r1935910;
        double r1935912 = r1935909 / r1935911;
        double r1935913 = r1935907 / r1935912;
        double r1935914 = 6.658964062989261e+180;
        bool r1935915 = r1935904 <= r1935914;
        double r1935916 = r1935907 / r1935909;
        double r1935917 = x_re;
        double r1935918 = r1935908 * r1935917;
        double r1935919 = fma(r1935910, r1935904, r1935918);
        double r1935920 = r1935919 / r1935909;
        double r1935921 = r1935907 / r1935920;
        double r1935922 = r1935916 / r1935921;
        double r1935923 = r1935907 / r1935910;
        double r1935924 = r1935916 / r1935923;
        double r1935925 = r1935915 ? r1935922 : r1935924;
        double r1935926 = r1935906 ? r1935913 : r1935925;
        return r1935926;
}

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.0287542866145704e+96

    1. Initial program 38.8

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified38.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 add-sqr-sqrt38.8

      \[\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*38.8

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

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

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

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

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

    if -1.0287542866145704e+96 < y.im < 6.658964062989261e+180

    1. Initial program 19.6

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

      \[\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-sqrt19.6

      \[\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*19.6

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}}}\]
    11. Applied associate-/r*12.3

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

    if 6.658964062989261e+180 < y.im

    1. Initial program 44.1

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified44.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-sqrt44.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*44.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 clear-num44.1

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\frac{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}}}\]
    9. Using strategy rm
    10. Applied div-inv31.2

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}}}\]
    11. Applied associate-/r*30.7

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

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

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

Reproduce

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