Average Error: 25.3 → 11.9
Time: 19.0s
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 -4.434994773334765 \cdot 10^{+162}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 2.2908775229370544 \cdot 10^{+141}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.im, 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 -4.434994773334765 \cdot 10^{+162}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2695665 = x_re;
        double r2695666 = y_re;
        double r2695667 = r2695665 * r2695666;
        double r2695668 = x_im;
        double r2695669 = y_im;
        double r2695670 = r2695668 * r2695669;
        double r2695671 = r2695667 + r2695670;
        double r2695672 = r2695666 * r2695666;
        double r2695673 = r2695669 * r2695669;
        double r2695674 = r2695672 + r2695673;
        double r2695675 = r2695671 / r2695674;
        return r2695675;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2695676 = y_im;
        double r2695677 = -4.434994773334765e+162;
        bool r2695678 = r2695676 <= r2695677;
        double r2695679 = x_im;
        double r2695680 = -r2695679;
        double r2695681 = y_re;
        double r2695682 = hypot(r2695676, r2695681);
        double r2695683 = r2695680 / r2695682;
        double r2695684 = 2.2908775229370544e+141;
        bool r2695685 = r2695676 <= r2695684;
        double r2695686 = x_re;
        double r2695687 = r2695681 * r2695686;
        double r2695688 = fma(r2695676, r2695679, r2695687);
        double r2695689 = r2695688 / r2695682;
        double r2695690 = r2695689 / r2695682;
        double r2695691 = r2695679 / r2695682;
        double r2695692 = r2695685 ? r2695690 : r2695691;
        double r2695693 = r2695678 ? r2695683 : r2695692;
        return r2695693;
}

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 < -4.434994773334765e+162

    1. Initial program 43.3

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt43.3

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    5. Applied associate-/r*43.3

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied clear-num43.3

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)} \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
    11. Applied associate-/r*28.3

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

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

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

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

    if -4.434994773334765e+162 < y.im < 2.2908775229370544e+141

    1. Initial program 18.8

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt18.8

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    5. Applied associate-/r*18.7

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied clear-num19.0

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)} \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
    11. Applied associate-/r*11.7

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

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

    if 2.2908775229370544e+141 < y.im

    1. Initial program 43.5

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt43.5

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    5. Applied associate-/r*43.5

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied clear-num43.6

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right) \cdot \frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)}}}\]
    9. Using strategy rm
    10. Applied *-commutative28.7

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(x.im, y.im, y.re \cdot x.re\right)} \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
    11. Applied associate-/r*28.0

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

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

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

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

Reproduce

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