Average Error: 26.0 → 12.9
Time: 29.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.im \le -9.070380995118472894632770750389862361245 \cdot 10^{169}:\\ \;\;\;\;x.im \cdot \frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.im \le 7.042501497551500124137433547855094410259 \cdot 10^{117}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\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 -9.070380995118472894632770750389862361245 \cdot 10^{169}:\\
\;\;\;\;x.im \cdot \frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{\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 r2802878 = x_re;
        double r2802879 = y_re;
        double r2802880 = r2802878 * r2802879;
        double r2802881 = x_im;
        double r2802882 = y_im;
        double r2802883 = r2802881 * r2802882;
        double r2802884 = r2802880 + r2802883;
        double r2802885 = r2802879 * r2802879;
        double r2802886 = r2802882 * r2802882;
        double r2802887 = r2802885 + r2802886;
        double r2802888 = r2802884 / r2802887;
        return r2802888;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2802889 = y_im;
        double r2802890 = -9.070380995118473e+169;
        bool r2802891 = r2802889 <= r2802890;
        double r2802892 = x_im;
        double r2802893 = -1.0;
        double r2802894 = y_re;
        double r2802895 = hypot(r2802894, r2802889);
        double r2802896 = r2802893 / r2802895;
        double r2802897 = r2802892 * r2802896;
        double r2802898 = 7.0425014975515e+117;
        bool r2802899 = r2802889 <= r2802898;
        double r2802900 = 1.0;
        double r2802901 = r2802900 / r2802895;
        double r2802902 = x_re;
        double r2802903 = r2802894 * r2802902;
        double r2802904 = fma(r2802889, r2802892, r2802903);
        double r2802905 = r2802904 / r2802895;
        double r2802906 = r2802901 * r2802905;
        double r2802907 = r2802892 / r2802895;
        double r2802908 = r2802899 ? r2802906 : r2802907;
        double r2802909 = r2802891 ? r2802897 : r2802908;
        return r2802909;
}

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 < -9.070380995118473e+169

    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. Using strategy rm
    3. Applied add-sqr-sqrt43.6

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied associate-/r*43.6

      \[\leadsto \color{blue}{\frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied hypot-def43.6

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

      \[\leadsto \frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}}\]
    9. Applied add-sqr-sqrt43.6

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

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

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    12. Applied times-frac43.6

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}}}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    13. Applied times-frac43.6

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    15. Simplified29.7

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

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

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

    if -9.070380995118473e+169 < y.im < 7.0425014975515e+117

    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. Using strategy rm
    3. Applied add-sqr-sqrt19.7

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied associate-/r*19.6

      \[\leadsto \color{blue}{\frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied hypot-def19.6

      \[\leadsto \frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt19.8

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    12. Applied times-frac20.0

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}}}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    13. Applied times-frac20.0

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}} \cdot \frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}}{\sqrt{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    15. Simplified12.4

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

    if 7.0425014975515e+117 < y.im

    1. Initial program 41.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt41.6

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied associate-/r*41.5

      \[\leadsto \color{blue}{\frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied hypot-def41.5

      \[\leadsto \frac{\frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    7. Taylor expanded around 0 16.0

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

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

Reproduce

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