Average Error: 25.9 → 12.9
Time: 28.1s
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 -3.146721494979391 \cdot 10^{+170}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 1.3523719097356063 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\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.im \le -3.146721494979391 \cdot 10^{+170}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{\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 r2084256 = x_re;
        double r2084257 = y_re;
        double r2084258 = r2084256 * r2084257;
        double r2084259 = x_im;
        double r2084260 = y_im;
        double r2084261 = r2084259 * r2084260;
        double r2084262 = r2084258 + r2084261;
        double r2084263 = r2084257 * r2084257;
        double r2084264 = r2084260 * r2084260;
        double r2084265 = r2084263 + r2084264;
        double r2084266 = r2084262 / r2084265;
        return r2084266;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2084267 = y_im;
        double r2084268 = -3.146721494979391e+170;
        bool r2084269 = r2084267 <= r2084268;
        double r2084270 = x_im;
        double r2084271 = y_re;
        double r2084272 = hypot(r2084267, r2084271);
        double r2084273 = r2084270 / r2084272;
        double r2084274 = -r2084273;
        double r2084275 = 1.3523719097356063e+94;
        bool r2084276 = r2084267 <= r2084275;
        double r2084277 = x_re;
        double r2084278 = r2084271 * r2084277;
        double r2084279 = fma(r2084270, r2084267, r2084278);
        double r2084280 = r2084279 / r2084272;
        double r2084281 = r2084280 / r2084272;
        double r2084282 = r2084276 ? r2084281 : r2084273;
        double r2084283 = r2084269 ? r2084274 : r2084282;
        return r2084283;
}

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 < -3.146721494979391e+170

    1. Initial program 43.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified43.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-sqrt43.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*43.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-num43.6

      \[\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. Simplified29.9

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

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \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)}}}}\]
    11. Applied add-sqr-sqrt29.9

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot \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)}}}\]
    12. Applied times-frac29.9

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\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)}}}}\]
    13. Simplified29.9

      \[\leadsto \color{blue}{1} \cdot \frac{\sqrt{1}}{\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)}}}\]
    14. Simplified29.2

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

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

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

    if -3.146721494979391e+170 < y.im < 1.3523719097356063e+94

    1. Initial program 19.7

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified19.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-sqrt19.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 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 *-un-lft-identity12.5

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \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)}}}}\]
    11. Applied add-sqr-sqrt12.5

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot \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)}}}\]
    12. Applied times-frac12.5

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\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)}}}}\]
    13. Simplified12.5

      \[\leadsto \color{blue}{1} \cdot \frac{\sqrt{1}}{\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)}}}\]
    14. Simplified12.0

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

    if 1.3523719097356063e+94 < y.im

    1. Initial program 38.3

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \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)}}}}\]
    11. Applied add-sqr-sqrt26.6

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot \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)}}}\]
    12. Applied times-frac26.6

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\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)}}}}\]
    13. Simplified26.6

      \[\leadsto \color{blue}{1} \cdot \frac{\sqrt{1}}{\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)}}}\]
    14. Simplified26.0

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

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

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

Reproduce

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