Average Error: 25.8 → 12.6
Time: 4.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 -2.23527954643198682 \cdot 10^{180}:\\ \;\;\;\;1 \cdot \frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 3.26314722618803973 \cdot 10^{197}:\\ \;\;\;\;1 \cdot \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{x.im}{\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.re \le -2.23527954643198682 \cdot 10^{180}:\\
\;\;\;\;1 \cdot \frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

\mathbf{else}:\\
\;\;\;\;1 \cdot \frac{x.im}{\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 r108075 = x_im;
        double r108076 = y_re;
        double r108077 = r108075 * r108076;
        double r108078 = x_re;
        double r108079 = y_im;
        double r108080 = r108078 * r108079;
        double r108081 = r108077 - r108080;
        double r108082 = r108076 * r108076;
        double r108083 = r108079 * r108079;
        double r108084 = r108082 + r108083;
        double r108085 = r108081 / r108084;
        return r108085;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r108086 = y_re;
        double r108087 = -2.235279546431987e+180;
        bool r108088 = r108086 <= r108087;
        double r108089 = 1.0;
        double r108090 = -1.0;
        double r108091 = x_im;
        double r108092 = r108090 * r108091;
        double r108093 = y_im;
        double r108094 = hypot(r108086, r108093);
        double r108095 = r108092 / r108094;
        double r108096 = r108089 * r108095;
        double r108097 = 3.26314722618804e+197;
        bool r108098 = r108086 <= r108097;
        double r108099 = r108091 * r108086;
        double r108100 = x_re;
        double r108101 = r108100 * r108093;
        double r108102 = r108099 - r108101;
        double r108103 = r108102 / r108094;
        double r108104 = r108103 / r108094;
        double r108105 = r108089 * r108104;
        double r108106 = r108091 / r108094;
        double r108107 = r108089 * r108106;
        double r108108 = r108098 ? r108105 : r108107;
        double r108109 = r108088 ? r108096 : r108108;
        return r108109;
}

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 < -2.235279546431987e+180

    1. Initial program 42.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-sqrt42.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-identity42.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-frac42.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. Simplified42.1

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

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

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

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

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

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

    if -2.235279546431987e+180 < y.re < 3.26314722618804e+197

    1. Initial program 21.2

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

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

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

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

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

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

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

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

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

    if 3.26314722618804e+197 < y.re

    1. Initial program 44.4

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -2.23527954643198682 \cdot 10^{180}:\\ \;\;\;\;1 \cdot \frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 3.26314722618803973 \cdot 10^{197}:\\ \;\;\;\;1 \cdot \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

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