Average Error: 25.9 → 13.7
Time: 13.7s
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.im \le -7.918258552369890831509695158247559340797 \cdot 10^{212}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.im \le 6.220962021564848334609656251804715714248 \cdot 10^{84}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right) \cdot \frac{1}{\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.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.im \le -7.918258552369890831509695158247559340797 \cdot 10^{212}:\\
\;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.im \le 6.220962021564848334609656251804715714248 \cdot 10^{84}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right) \cdot \frac{1}{\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 r52976 = x_im;
        double r52977 = y_re;
        double r52978 = r52976 * r52977;
        double r52979 = x_re;
        double r52980 = y_im;
        double r52981 = r52979 * r52980;
        double r52982 = r52978 - r52981;
        double r52983 = r52977 * r52977;
        double r52984 = r52980 * r52980;
        double r52985 = r52983 + r52984;
        double r52986 = r52982 / r52985;
        return r52986;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r52987 = y_im;
        double r52988 = -7.918258552369891e+212;
        bool r52989 = r52987 <= r52988;
        double r52990 = x_re;
        double r52991 = y_re;
        double r52992 = hypot(r52991, r52987);
        double r52993 = r52990 / r52992;
        double r52994 = 6.220962021564848e+84;
        bool r52995 = r52987 <= r52994;
        double r52996 = -r52987;
        double r52997 = x_im;
        double r52998 = r52991 * r52997;
        double r52999 = fma(r52990, r52996, r52998);
        double r53000 = 1.0;
        double r53001 = r53000 / r52992;
        double r53002 = r52999 * r53001;
        double r53003 = r53002 / r52992;
        double r53004 = -r52993;
        double r53005 = r52995 ? r53003 : r53004;
        double r53006 = r52989 ? r52993 : r53005;
        return r53006;
}

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 < -7.918258552369891e+212

    1. Initial program 40.8

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt40.8

      \[\leadsto \frac{x.im \cdot y.re - x.re \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.8

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \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.8

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified40.8

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

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

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

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

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

    if -7.918258552369891e+212 < y.im < 6.220962021564848e+84

    1. Initial program 21.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt21.1

      \[\leadsto \frac{x.im \cdot y.re - x.re \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-identity21.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \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-frac21.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified21.1

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(x.re, -y.im, x.im \cdot y.re\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    11. Using strategy rm
    12. Applied div-inv13.2

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

    if 6.220962021564848e+84 < y.im

    1. Initial program 37.6

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt37.6

      \[\leadsto \frac{x.im \cdot y.re - x.re \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-identity37.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \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-frac37.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified37.6

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -7.918258552369890831509695158247559340797 \cdot 10^{212}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.im \le 6.220962021564848334609656251804715714248 \cdot 10^{84}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, -y.im, y.re \cdot x.im\right) \cdot \frac{1}{\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, imaginary part"
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))