Average Error: 25.7 → 25.6
Time: 15.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}\;y.im \le 6.646276389058437 \cdot 10^{+117}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot 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 6.646276389058437 \cdot 10^{+117}:\\
\;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r1436318 = x_re;
        double r1436319 = y_re;
        double r1436320 = r1436318 * r1436319;
        double r1436321 = x_im;
        double r1436322 = y_im;
        double r1436323 = r1436321 * r1436322;
        double r1436324 = r1436320 + r1436323;
        double r1436325 = r1436319 * r1436319;
        double r1436326 = r1436322 * r1436322;
        double r1436327 = r1436325 + r1436326;
        double r1436328 = r1436324 / r1436327;
        return r1436328;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r1436329 = y_im;
        double r1436330 = 6.646276389058437e+117;
        bool r1436331 = r1436329 <= r1436330;
        double r1436332 = x_re;
        double r1436333 = y_re;
        double r1436334 = x_im;
        double r1436335 = r1436334 * r1436329;
        double r1436336 = fma(r1436332, r1436333, r1436335);
        double r1436337 = r1436333 * r1436333;
        double r1436338 = fma(r1436329, r1436329, r1436337);
        double r1436339 = sqrt(r1436338);
        double r1436340 = r1436336 / r1436339;
        double r1436341 = r1436340 / r1436339;
        double r1436342 = r1436334 / r1436339;
        double r1436343 = r1436331 ? r1436341 : r1436342;
        return r1436343;
}

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 y.im < 6.646276389058437e+117

    1. Initial program 22.5

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified22.5

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt22.5

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied associate-/r*22.5

      \[\leadsto \color{blue}{\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]

    if 6.646276389058437e+117 < y.im

    1. Initial program 42.3

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

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt42.3

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied associate-/r*42.2

      \[\leadsto \color{blue}{\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    6. Taylor expanded around 0 41.5

      \[\leadsto \frac{\color{blue}{x.im}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification25.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le 6.646276389058437 \cdot 10^{+117}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\\ \end{array}\]

Reproduce

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