Average Error: 25.7 → 12.5
Time: 11.9s
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)}\\ \mathbf{elif}\;y.re \le 2.5019882417216274 \cdot 10^{136}:\\ \;\;\;\;\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}:\\ \;\;\;\;\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)}\\

\mathbf{elif}\;y.re \le 2.5019882417216274 \cdot 10^{136}:\\
\;\;\;\;\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}:\\
\;\;\;\;\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 r64972 = x_im;
        double r64973 = y_re;
        double r64974 = r64972 * r64973;
        double r64975 = x_re;
        double r64976 = y_im;
        double r64977 = r64975 * r64976;
        double r64978 = r64974 - r64977;
        double r64979 = r64973 * r64973;
        double r64980 = r64976 * r64976;
        double r64981 = r64979 + r64980;
        double r64982 = r64978 / r64981;
        return r64982;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r64983 = y_re;
        double r64984 = -5.9876509466672635e+162;
        bool r64985 = r64983 <= r64984;
        double r64986 = x_im;
        double r64987 = -r64986;
        double r64988 = y_im;
        double r64989 = hypot(r64988, r64983);
        double r64990 = r64987 / r64989;
        double r64991 = 2.5019882417216274e+136;
        bool r64992 = r64983 <= r64991;
        double r64993 = 1.0;
        double r64994 = x_re;
        double r64995 = r64988 * r64994;
        double r64996 = -r64995;
        double r64997 = fma(r64986, r64983, r64996);
        double r64998 = r64989 / r64997;
        double r64999 = r64993 / r64998;
        double r65000 = r64999 / r64989;
        double r65001 = r64986 / r64989;
        double r65002 = r64992 ? r65000 : r65001;
        double r65003 = r64985 ? r64990 : r65002;
        return r65003;
}

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 *-un-lft-identity29.5

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

      \[\leadsto \frac{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 *-un-lft-identity12.1

      \[\leadsto \frac{\color{blue}{1 \cdot 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{1}{1} \cdot \frac{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{1}{1} \cdot \left(\frac{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{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{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 *-un-lft-identity27.3

      \[\leadsto \frac{\color{blue}{1 \cdot 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{1}{1} \cdot \frac{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{1}{1} \cdot \left(\frac{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{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{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)}\\ \mathbf{elif}\;y.re \le 2.5019882417216274 \cdot 10^{136}:\\ \;\;\;\;\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}:\\ \;\;\;\;\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))))