Average Error: 25.7 → 12.8
Time: 20.8s
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 -6.24305058454472 \cdot 10^{+142}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.0408154521829639 \cdot 10^{+152}:\\ \;\;\;\;\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{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 -6.24305058454472 \cdot 10^{+142}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 1.0408154521829639 \cdot 10^{+152}:\\
\;\;\;\;\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{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 r1996068 = x_re;
        double r1996069 = y_re;
        double r1996070 = r1996068 * r1996069;
        double r1996071 = x_im;
        double r1996072 = y_im;
        double r1996073 = r1996071 * r1996072;
        double r1996074 = r1996070 + r1996073;
        double r1996075 = r1996069 * r1996069;
        double r1996076 = r1996072 * r1996072;
        double r1996077 = r1996075 + r1996076;
        double r1996078 = r1996074 / r1996077;
        return r1996078;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1996079 = y_re;
        double r1996080 = -6.24305058454472e+142;
        bool r1996081 = r1996079 <= r1996080;
        double r1996082 = x_re;
        double r1996083 = -r1996082;
        double r1996084 = y_im;
        double r1996085 = hypot(r1996084, r1996079);
        double r1996086 = r1996083 / r1996085;
        double r1996087 = 1.0408154521829639e+152;
        bool r1996088 = r1996079 <= r1996087;
        double r1996089 = x_im;
        double r1996090 = r1996084 * r1996089;
        double r1996091 = fma(r1996079, r1996082, r1996090);
        double r1996092 = r1996091 / r1996085;
        double r1996093 = r1996092 / r1996085;
        double r1996094 = r1996082 / r1996085;
        double r1996095 = r1996088 ? r1996093 : r1996094;
        double r1996096 = r1996081 ? r1996086 : r1996095;
        return r1996096;
}

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 < -6.24305058454472e+142

    1. Initial program 42.7

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

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

      \[\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 *-un-lft-identity42.7

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}} \cdot \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)}}\]
    9. Applied hypot-def42.7

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \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)}}\]
    10. Using strategy rm
    11. Applied associate-*l/42.7

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

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

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

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

    if -6.24305058454472e+142 < y.re < 1.0408154521829639e+152

    1. Initial program 18.8

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified18.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-sqrt18.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 *-un-lft-identity18.8

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}} \cdot \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)}}\]
    9. Applied hypot-def18.8

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \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)}}\]
    10. Using strategy rm
    11. Applied associate-*l/18.7

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

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

    if 1.0408154521829639e+152 < y.re

    1. Initial program 45.2

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified45.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-sqrt45.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 *-un-lft-identity45.2

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}} \cdot \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)}}\]
    9. Applied hypot-def45.2

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \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)}}\]
    10. Using strategy rm
    11. Applied associate-*l/45.2

      \[\leadsto \color{blue}{\frac{1 \cdot \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)}}}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    12. Simplified28.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -6.24305058454472 \cdot 10^{+142}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.0408154521829639 \cdot 10^{+152}:\\ \;\;\;\;\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{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]

Reproduce

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