Average Error: 26.0 → 13.9
Time: 4.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}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \le 2.846399672864898633139753001838080406359 \cdot 10^{282}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \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}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \le 2.846399672864898633139753001838080406359 \cdot 10^{282}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r50158 = x_re;
        double r50159 = y_re;
        double r50160 = r50158 * r50159;
        double r50161 = x_im;
        double r50162 = y_im;
        double r50163 = r50161 * r50162;
        double r50164 = r50160 + r50163;
        double r50165 = r50159 * r50159;
        double r50166 = r50162 * r50162;
        double r50167 = r50165 + r50166;
        double r50168 = r50164 / r50167;
        return r50168;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r50169 = x_re;
        double r50170 = y_re;
        double r50171 = r50169 * r50170;
        double r50172 = x_im;
        double r50173 = y_im;
        double r50174 = r50172 * r50173;
        double r50175 = r50171 + r50174;
        double r50176 = r50170 * r50170;
        double r50177 = r50173 * r50173;
        double r50178 = r50176 + r50177;
        double r50179 = r50175 / r50178;
        double r50180 = 2.8463996728648986e+282;
        bool r50181 = r50179 <= r50180;
        double r50182 = 1.0;
        double r50183 = hypot(r50170, r50173);
        double r50184 = fma(r50169, r50170, r50174);
        double r50185 = r50183 / r50184;
        double r50186 = r50182 / r50185;
        double r50187 = r50183 * r50182;
        double r50188 = r50186 / r50187;
        double r50189 = r50172 / r50187;
        double r50190 = r50181 ? r50188 : r50189;
        return r50190;
}

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 2 regimes
  2. if (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))) < 2.8463996728648986e+282

    1. Initial program 14.1

      \[\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-sqrt14.1

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac14.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified14.1

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}}\]
    8. Using strategy rm
    9. Applied associate-*r/2.8

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\]
    11. Using strategy rm
    12. Applied clear-num2.8

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

    if 2.8463996728648986e+282 < (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))

    1. Initial program 62.9

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac62.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified62.9

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1} \cdot \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}}\]
    8. Using strategy rm
    9. Applied associate-*r/60.3

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

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

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

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

Reproduce

herbie shell --seed 2019362 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, real part"
  :precision binary64
  (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))