Average Error: 25.7 → 12.5
Time: 10.4s
Precision: 64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -5.9876509466672635 \cdot 10^{162}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \sqrt{1}\\ \mathbf{elif}\;y.re \le 2.5019882417216274 \cdot 10^{136}:\\ \;\;\;\;\sqrt{1} \cdot \frac{\frac{1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1} \cdot \frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
\mathbf{if}\;y.re \le -5.9876509466672635 \cdot 10^{162}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \sqrt{1}\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{1} \cdot \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 r79150 = x_im;
        double r79151 = y_re;
        double r79152 = r79150 * r79151;
        double r79153 = x_re;
        double r79154 = y_im;
        double r79155 = r79153 * r79154;
        double r79156 = r79152 - r79155;
        double r79157 = r79151 * r79151;
        double r79158 = r79154 * r79154;
        double r79159 = r79157 + r79158;
        double r79160 = r79156 / r79159;
        return r79160;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r79161 = y_re;
        double r79162 = -5.9876509466672635e+162;
        bool r79163 = r79161 <= r79162;
        double r79164 = x_im;
        double r79165 = -r79164;
        double r79166 = y_im;
        double r79167 = hypot(r79166, r79161);
        double r79168 = r79165 / r79167;
        double r79169 = 1.0;
        double r79170 = sqrt(r79169);
        double r79171 = r79168 * r79170;
        double r79172 = 2.5019882417216274e+136;
        bool r79173 = r79161 <= r79172;
        double r79174 = x_re;
        double r79175 = r79166 * r79174;
        double r79176 = -r79175;
        double r79177 = fma(r79164, r79161, r79176);
        double r79178 = r79167 / r79177;
        double r79179 = r79169 / r79178;
        double r79180 = r79179 / r79167;
        double r79181 = r79170 * r79180;
        double r79182 = r79164 / r79167;
        double r79183 = r79170 * r79182;
        double r79184 = r79173 ? r79181 : r79183;
        double r79185 = r79163 ? r79171 : r79184;
        return r79185;
}

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

    1. Initial program 43.8

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity43.8

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    11. Applied add-sqr-sqrt29.5

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    12. Applied times-frac29.5

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.im, y.re\right)}\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    13. Applied associate-*l*29.5

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

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

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

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

    if -5.9876509466672635e+162 < y.re < 2.5019882417216274e+136

    1. Initial program 19.2

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity19.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac19.2

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.im, y.re\right)}\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    13. Applied associate-*l*12.1

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

      \[\leadsto \frac{\sqrt{1}}{1} \cdot \color{blue}{\frac{\frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    15. Using strategy rm
    16. Applied clear-num12.1

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

    if 2.5019882417216274e+136 < y.re

    1. Initial program 42.2

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity42.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac42.2

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

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

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

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    11. Applied add-sqr-sqrt27.3

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

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.im, y.re\right)}\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, -y.im \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\]
    13. Applied associate-*l*27.3

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

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

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

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

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))