Average Error: 26.1 → 12.2
Time: 14.8s
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 -5.555678636173395142498524095620383972223 \cdot 10^{153}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 1.283275728529221215559786646723641499797 \cdot 10^{179}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, x.re \cdot y.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 -5.555678636173395142498524095620383972223 \cdot 10^{153}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.im \le 1.283275728529221215559786646723641499797 \cdot 10^{179}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, x.re \cdot y.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 r56212 = x_re;
        double r56213 = y_re;
        double r56214 = r56212 * r56213;
        double r56215 = x_im;
        double r56216 = y_im;
        double r56217 = r56215 * r56216;
        double r56218 = r56214 + r56217;
        double r56219 = r56213 * r56213;
        double r56220 = r56216 * r56216;
        double r56221 = r56219 + r56220;
        double r56222 = r56218 / r56221;
        return r56222;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r56223 = y_im;
        double r56224 = -5.555678636173395e+153;
        bool r56225 = r56223 <= r56224;
        double r56226 = x_im;
        double r56227 = -r56226;
        double r56228 = y_re;
        double r56229 = hypot(r56223, r56228);
        double r56230 = r56227 / r56229;
        double r56231 = 1.2832757285292212e+179;
        bool r56232 = r56223 <= r56231;
        double r56233 = x_re;
        double r56234 = r56233 * r56228;
        double r56235 = fma(r56223, r56226, r56234);
        double r56236 = r56235 / r56229;
        double r56237 = r56236 / r56229;
        double r56238 = r56226 / r56229;
        double r56239 = r56232 ? r56237 : r56238;
        double r56240 = r56225 ? r56230 : r56239;
        return r56240;
}

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 < -5.555678636173395e+153

    1. Initial program 45.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-sqrt45.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 *-un-lft-identity45.4

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\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. Simplified29.4

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}^{1}} \cdot {\left(\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}^{1}\]
    11. Applied pow-prod-down29.4

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

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

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

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

    if -5.555678636173395e+153 < y.im < 1.2832757285292212e+179

    1. Initial program 19.9

      \[\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-sqrt19.9

      \[\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-identity19.9

      \[\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-frac19.9

      \[\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. Simplified19.9

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.im, y.re\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. Simplified12.4

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}^{1}} \cdot {\left(\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}^{1}\]
    11. Applied pow-prod-down12.4

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

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

    if 1.2832757285292212e+179 < y.im

    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.im, y.re\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. Simplified31.6

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}^{1}} \cdot {\left(\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}^{1}\]
    11. Applied pow-prod-down31.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -5.555678636173395142498524095620383972223 \cdot 10^{153}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \le 1.283275728529221215559786646723641499797 \cdot 10^{179}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.im, x.im, x.re \cdot y.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 2019179 +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))))