Average Error: 26.1 → 13.1
Time: 1.9m
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 -2.2063458127550573 \cdot 10^{+100}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 4.054287420560557 \cdot 10^{+138}:\\ \;\;\;\;\frac{\frac{1}{\frac{1}{\frac{\mathsf{fma}\left(y.re, x.re, \left(y.im \cdot x.im\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\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.re \le -2.2063458127550573 \cdot 10^{+100}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{\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 r5757120 = x_re;
        double r5757121 = y_re;
        double r5757122 = r5757120 * r5757121;
        double r5757123 = x_im;
        double r5757124 = y_im;
        double r5757125 = r5757123 * r5757124;
        double r5757126 = r5757122 + r5757125;
        double r5757127 = r5757121 * r5757121;
        double r5757128 = r5757124 * r5757124;
        double r5757129 = r5757127 + r5757128;
        double r5757130 = r5757126 / r5757129;
        return r5757130;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r5757131 = y_re;
        double r5757132 = -2.2063458127550573e+100;
        bool r5757133 = r5757131 <= r5757132;
        double r5757134 = x_re;
        double r5757135 = -r5757134;
        double r5757136 = y_im;
        double r5757137 = hypot(r5757131, r5757136);
        double r5757138 = r5757135 / r5757137;
        double r5757139 = 4.054287420560557e+138;
        bool r5757140 = r5757131 <= r5757139;
        double r5757141 = 1.0;
        double r5757142 = x_im;
        double r5757143 = r5757136 * r5757142;
        double r5757144 = fma(r5757131, r5757134, r5757143);
        double r5757145 = r5757144 / r5757137;
        double r5757146 = r5757141 / r5757145;
        double r5757147 = r5757141 / r5757146;
        double r5757148 = r5757147 / r5757137;
        double r5757149 = r5757134 / r5757137;
        double r5757150 = r5757140 ? r5757148 : r5757149;
        double r5757151 = r5757133 ? r5757138 : r5757150;
        return r5757151;
}

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 < -2.2063458127550573e+100

    1. Initial program 38.4

      \[\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-sqrt38.4

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

      \[\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-def38.4

      \[\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 clear-num38.4

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

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

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

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

    if -2.2063458127550573e+100 < y.re < 4.054287420560557e+138

    1. Initial program 18.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-sqrt18.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*18.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-def18.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. Using strategy rm
    8. Applied clear-num18.6

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

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

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

    if 4.054287420560557e+138 < y.re

    1. Initial program 45.0

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

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

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

      \[\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 inf 14.5

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

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

Reproduce

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