Average Error: 25.8 → 12.5
Time: 31.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.re \le -1.1649944572964785 \cdot 10^{+191}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 6.443797861366497 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]
double f(double x_re, double x_im, double y_re, double y_im) {
        double r3098382 = x_re;
        double r3098383 = y_re;
        double r3098384 = r3098382 * r3098383;
        double r3098385 = x_im;
        double r3098386 = y_im;
        double r3098387 = r3098385 * r3098386;
        double r3098388 = r3098384 + r3098387;
        double r3098389 = r3098383 * r3098383;
        double r3098390 = r3098386 * r3098386;
        double r3098391 = r3098389 + r3098390;
        double r3098392 = r3098388 / r3098391;
        return r3098392;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r3098393 = y_re;
        double r3098394 = -1.1649944572964785e+191;
        bool r3098395 = r3098393 <= r3098394;
        double r3098396 = x_re;
        double r3098397 = -r3098396;
        double r3098398 = y_im;
        double r3098399 = hypot(r3098398, r3098393);
        double r3098400 = r3098397 / r3098399;
        double r3098401 = 6.443797861366497e+143;
        bool r3098402 = r3098393 <= r3098401;
        double r3098403 = x_im;
        double r3098404 = r3098398 * r3098403;
        double r3098405 = fma(r3098396, r3098393, r3098404);
        double r3098406 = r3098405 / r3098399;
        double r3098407 = r3098406 / r3098399;
        double r3098408 = r3098396 / r3098399;
        double r3098409 = r3098402 ? r3098407 : r3098408;
        double r3098410 = r3098395 ? r3098400 : r3098409;
        return r3098410;
}

\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 -1.1649944572964785 \cdot 10^{+191}:\\
\;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\

\mathbf{elif}\;y.re \le 6.443797861366497 \cdot 10^{+143}:\\
\;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^2}^*}\\

\end{array}

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 < -1.1649944572964785e+191

    1. Initial program 43.0

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

      \[\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-sqrt43.0

      \[\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*43.0

      \[\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. Using strategy rm
    7. Applied fma-udef43.0

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def43.0

      \[\leadsto \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))_*}}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied fma-udef43.0

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    11. Applied hypot-def29.7

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    12. Taylor expanded around -inf 10.9

      \[\leadsto \frac{\color{blue}{-1 \cdot x.re}}{\sqrt{y.im^2 + y.re^2}^*}\]
    13. Simplified10.9

      \[\leadsto \frac{\color{blue}{-x.re}}{\sqrt{y.im^2 + y.re^2}^*}\]

    if -1.1649944572964785e+191 < y.re < 6.443797861366497e+143

    1. Initial program 20.5

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified20.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-sqrt20.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*20.4

      \[\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. Using strategy rm
    7. Applied fma-udef20.4

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def20.4

      \[\leadsto \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))_*}}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied fma-udef20.4

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    11. Applied hypot-def12.4

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

    if 6.443797861366497e+143 < y.re

    1. Initial program 43.2

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

      \[\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-sqrt43.2

      \[\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*43.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. Using strategy rm
    7. Applied fma-udef43.2

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def43.2

      \[\leadsto \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))_*}}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied fma-udef43.2

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    11. Applied hypot-def26.9

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    12. Taylor expanded around inf 14.7

      \[\leadsto \frac{\color{blue}{x.re}}{\sqrt{y.im^2 + y.re^2}^*}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.1649944572964785 \cdot 10^{+191}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 6.443797861366497 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]

Reproduce

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