Average Error: 25.2 → 12.6
Time: 24.7s
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 -4.03421189658091 \cdot 10^{+207}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 5.125419024840355 \cdot 10^{+159}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\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.re \le -4.03421189658091 \cdot 10^{+207}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{\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 r2162041 = x_re;
        double r2162042 = y_re;
        double r2162043 = r2162041 * r2162042;
        double r2162044 = x_im;
        double r2162045 = y_im;
        double r2162046 = r2162044 * r2162045;
        double r2162047 = r2162043 + r2162046;
        double r2162048 = r2162042 * r2162042;
        double r2162049 = r2162045 * r2162045;
        double r2162050 = r2162048 + r2162049;
        double r2162051 = r2162047 / r2162050;
        return r2162051;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2162052 = y_re;
        double r2162053 = -4.03421189658091e+207;
        bool r2162054 = r2162052 <= r2162053;
        double r2162055 = x_re;
        double r2162056 = -r2162055;
        double r2162057 = y_im;
        double r2162058 = hypot(r2162057, r2162052);
        double r2162059 = r2162056 / r2162058;
        double r2162060 = 5.125419024840355e+159;
        bool r2162061 = r2162052 <= r2162060;
        double r2162062 = x_im;
        double r2162063 = r2162062 * r2162057;
        double r2162064 = fma(r2162052, r2162055, r2162063);
        double r2162065 = r2162064 / r2162058;
        double r2162066 = r2162065 / r2162058;
        double r2162067 = r2162055 / r2162058;
        double r2162068 = r2162061 ? r2162066 : r2162067;
        double r2162069 = r2162054 ? r2162059 : r2162068;
        return r2162069;
}

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 < -4.03421189658091e+207

    1. Initial program 41.2

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

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

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

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

      \[\leadsto \color{blue}{\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)}} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity41.2

      \[\leadsto \color{blue}{\left(1 \cdot \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)}}\right)} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    10. Applied associate-*l*41.2

      \[\leadsto \color{blue}{1 \cdot \left(\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)}} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\right)}\]
    11. Simplified30.3

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

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

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

    if -4.03421189658091e+207 < y.re < 5.125419024840355e+159

    1. Initial program 20.4

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

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

      \[\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*20.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 div-inv20.4

      \[\leadsto \color{blue}{\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)}} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity20.4

      \[\leadsto \color{blue}{\left(1 \cdot \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)}}\right)} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    10. Applied associate-*l*20.4

      \[\leadsto \color{blue}{1 \cdot \left(\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)}} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\right)}\]
    11. Simplified12.6

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

    if 5.125419024840355e+159 < y.re

    1. Initial program 44.0

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

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

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

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

      \[\leadsto \color{blue}{\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)}} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity44.0

      \[\leadsto \color{blue}{\left(1 \cdot \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)}}\right)} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    10. Applied associate-*l*44.0

      \[\leadsto \color{blue}{1 \cdot \left(\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)}} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\right)}\]
    11. Simplified28.2

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

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

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

Reproduce

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