Average Error: 25.9 → 14.0
Time: 13.9s
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.236056920632649636312988321949767458809 \cdot 10^{252}:\\ \;\;\;\;-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le -1.972049955288829430907028189059339655129 \cdot 10^{188}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}}\\ \mathbf{elif}\;y.re \le -9.931482377190183189903426181814662287963 \cdot 10^{103}:\\ \;\;\;\;-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 7.28777456571337501443708414977136635674 \cdot 10^{101}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\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 -1.236056920632649636312988321949767458809 \cdot 10^{252}:\\
\;\;\;\;-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

\mathbf{elif}\;y.re \le -9.931482377190183189903426181814662287963 \cdot 10^{103}:\\
\;\;\;\;-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 7.28777456571337501443708414977136635674 \cdot 10^{101}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\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 r53685 = x_re;
        double r53686 = y_re;
        double r53687 = r53685 * r53686;
        double r53688 = x_im;
        double r53689 = y_im;
        double r53690 = r53688 * r53689;
        double r53691 = r53687 + r53690;
        double r53692 = r53686 * r53686;
        double r53693 = r53689 * r53689;
        double r53694 = r53692 + r53693;
        double r53695 = r53691 / r53694;
        return r53695;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r53696 = y_re;
        double r53697 = -1.2360569206326496e+252;
        bool r53698 = r53696 <= r53697;
        double r53699 = x_re;
        double r53700 = y_im;
        double r53701 = hypot(r53696, r53700);
        double r53702 = r53699 / r53701;
        double r53703 = -r53702;
        double r53704 = -1.9720499552888294e+188;
        bool r53705 = r53696 <= r53704;
        double r53706 = 1.0;
        double r53707 = r53706 / r53701;
        double r53708 = x_im;
        double r53709 = r53708 * r53700;
        double r53710 = fma(r53696, r53699, r53709);
        double r53711 = r53701 / r53710;
        double r53712 = r53706 / r53711;
        double r53713 = r53707 * r53712;
        double r53714 = -9.931482377190183e+103;
        bool r53715 = r53696 <= r53714;
        double r53716 = 7.287774565713375e+101;
        bool r53717 = r53696 <= r53716;
        double r53718 = r53710 / r53701;
        double r53719 = r53718 / r53701;
        double r53720 = r53717 ? r53719 : r53702;
        double r53721 = r53715 ? r53703 : r53720;
        double r53722 = r53705 ? r53713 : r53721;
        double r53723 = r53698 ? r53703 : r53722;
        return r53723;
}

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 4 regimes
  2. if y.re < -1.2360569206326496e+252 or -1.9720499552888294e+188 < y.re < -9.931482377190183e+103

    1. Initial program 36.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-sqrt36.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 *-un-lft-identity36.0

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

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

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

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

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

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

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

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

    if -1.2360569206326496e+252 < y.re < -1.9720499552888294e+188

    1. Initial program 45.3

      \[\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.3

      \[\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-identity45.3

      \[\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-frac45.3

      \[\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. Simplified45.3

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

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

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

    if -9.931482377190183e+103 < y.re < 7.287774565713375e+101

    1. Initial program 18.5

      \[\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.5

      \[\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-identity18.5

      \[\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-frac18.5

      \[\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. Simplified18.5

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

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

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

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

    if 7.287774565713375e+101 < y.re

    1. Initial program 40.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-sqrt40.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 *-un-lft-identity40.0

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.236056920632649636312988321949767458809 \cdot 10^{252}:\\ \;\;\;\;-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le -1.972049955288829430907028189059339655129 \cdot 10^{188}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}}\\ \mathbf{elif}\;y.re \le -9.931482377190183189903426181814662287963 \cdot 10^{103}:\\ \;\;\;\;-\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 7.28777456571337501443708414977136635674 \cdot 10^{101}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\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 2019195 +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))))