Average Error: 25.7 → 12.9
Time: 20.5s
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 -1.4815058757062313 \cdot 10^{+190}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 4.948399038442073 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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.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 -1.4815058757062313 \cdot 10^{+190}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 4.948399038442073 \cdot 10^{+94}:\\
\;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 r2152062 = x_im;
        double r2152063 = y_re;
        double r2152064 = r2152062 * r2152063;
        double r2152065 = x_re;
        double r2152066 = y_im;
        double r2152067 = r2152065 * r2152066;
        double r2152068 = r2152064 - r2152067;
        double r2152069 = r2152063 * r2152063;
        double r2152070 = r2152066 * r2152066;
        double r2152071 = r2152069 + r2152070;
        double r2152072 = r2152068 / r2152071;
        return r2152072;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2152073 = y_re;
        double r2152074 = -1.4815058757062313e+190;
        bool r2152075 = r2152073 <= r2152074;
        double r2152076 = x_im;
        double r2152077 = y_im;
        double r2152078 = hypot(r2152077, r2152073);
        double r2152079 = r2152076 / r2152078;
        double r2152080 = -r2152079;
        double r2152081 = 4.948399038442073e+94;
        bool r2152082 = r2152073 <= r2152081;
        double r2152083 = r2152076 * r2152073;
        double r2152084 = x_re;
        double r2152085 = r2152077 * r2152084;
        double r2152086 = r2152083 - r2152085;
        double r2152087 = r2152086 / r2152078;
        double r2152088 = r2152087 / r2152078;
        double r2152089 = r2152082 ? r2152088 : r2152079;
        double r2152090 = r2152075 ? r2152080 : r2152089;
        return r2152090;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if y.re < -1.4815058757062313e+190

    1. Initial program 41.5

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 *-un-lft-identity41.5

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\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)}}\]
    6. Applied times-frac41.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    7. Using strategy rm
    8. Applied fma-udef41.5

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

      \[\leadsto \frac{1}{\color{blue}{\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.im, y.im, y.re \cdot y.re\right)}}\]
    10. Using strategy rm
    11. Applied associate-*l/41.5

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

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

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

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

    if -1.4815058757062313e+190 < y.re < 4.948399038442073e+94

    1. Initial program 20.1

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 *-un-lft-identity20.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\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)}}\]
    6. Applied times-frac20.1

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

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

      \[\leadsto \frac{1}{\color{blue}{\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.im, y.im, y.re \cdot y.re\right)}}\]
    10. Using strategy rm
    11. Applied associate-*l/20.0

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

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

    if 4.948399038442073e+94 < y.re

    1. Initial program 38.5

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\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 *-un-lft-identity38.5

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re - x.re \cdot y.im\right)}}{\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)}}\]
    6. Applied times-frac38.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    7. Using strategy rm
    8. Applied fma-udef38.5

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

      \[\leadsto \frac{1}{\color{blue}{\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.im, y.im, y.re \cdot y.re\right)}}\]
    10. Using strategy rm
    11. Applied associate-*l/38.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.4815058757062313 \cdot 10^{+190}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 4.948399038442073 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 2019142 +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))))