Average Error: 26.2 → 13.1
Time: 30.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 -7.953097451560213 \cdot 10^{+118}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 4.980716304337378 \cdot 10^{+114}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, \left(x.re \cdot y.re\right)\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 -7.953097451560213 \cdot 10^{+118}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 4.980716304337378 \cdot 10^{+114}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, \left(x.re \cdot y.re\right)\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 r2257662 = x_re;
        double r2257663 = y_re;
        double r2257664 = r2257662 * r2257663;
        double r2257665 = x_im;
        double r2257666 = y_im;
        double r2257667 = r2257665 * r2257666;
        double r2257668 = r2257664 + r2257667;
        double r2257669 = r2257663 * r2257663;
        double r2257670 = r2257666 * r2257666;
        double r2257671 = r2257669 + r2257670;
        double r2257672 = r2257668 / r2257671;
        return r2257672;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2257673 = y_re;
        double r2257674 = -7.953097451560213e+118;
        bool r2257675 = r2257673 <= r2257674;
        double r2257676 = x_re;
        double r2257677 = -r2257676;
        double r2257678 = y_im;
        double r2257679 = hypot(r2257678, r2257673);
        double r2257680 = r2257677 / r2257679;
        double r2257681 = 4.980716304337378e+114;
        bool r2257682 = r2257673 <= r2257681;
        double r2257683 = x_im;
        double r2257684 = r2257676 * r2257673;
        double r2257685 = fma(r2257678, r2257683, r2257684);
        double r2257686 = r2257685 / r2257679;
        double r2257687 = r2257686 / r2257679;
        double r2257688 = r2257676 / r2257679;
        double r2257689 = r2257682 ? r2257687 : r2257688;
        double r2257690 = r2257675 ? r2257680 : r2257689;
        return r2257690;
}

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 < -7.953097451560213e+118

    1. Initial program 40.8

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef40.8

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

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

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

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

    if -7.953097451560213e+118 < y.re < 4.980716304337378e+114

    1. Initial program 18.9

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef18.8

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity18.8

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

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\sqrt{1} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}\]
    13. Applied *-un-lft-identity18.8

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}{\sqrt{1} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}\]
    14. Applied times-frac18.8

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1}} \cdot \frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}\]
    15. Applied times-frac18.8

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

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

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

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

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

    if 4.980716304337378e+114 < y.re

    1. Initial program 41.0

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
    6. Using strategy rm
    7. Applied fma-udef41.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -7.953097451560213 \cdot 10^{+118}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 4.980716304337378 \cdot 10^{+114}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, \left(x.re \cdot y.re\right)\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 2019121 +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))))