Average Error: 26.3 → 13.1
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 -1.92809702332723783 \cdot 10^{94}:\\ \;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \mathbf{elif}\;y.re \le 3.85849841677322835 \cdot 10^{39}:\\ \;\;\;\;\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) \cdot 1}\\ \mathbf{elif}\;y.re \le 4.0740961827290516 \cdot 10^{154}:\\ \;\;\;\;\frac{x.im}{\frac{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}{y.re}} - \frac{x.re}{\frac{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}{y.im}}\\ \mathbf{elif}\;y.re \le 5.21434504503365728 \cdot 10^{171}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \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.92809702332723783 \cdot 10^{94}:\\
\;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\

\mathbf{elif}\;y.re \le 3.85849841677322835 \cdot 10^{39}:\\
\;\;\;\;\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) \cdot 1}\\

\mathbf{elif}\;y.re \le 4.0740961827290516 \cdot 10^{154}:\\
\;\;\;\;\frac{x.im}{\frac{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}{y.re}} - \frac{x.re}{\frac{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}{y.im}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r68369 = x_im;
        double r68370 = y_re;
        double r68371 = r68369 * r68370;
        double r68372 = x_re;
        double r68373 = y_im;
        double r68374 = r68372 * r68373;
        double r68375 = r68371 - r68374;
        double r68376 = r68370 * r68370;
        double r68377 = r68373 * r68373;
        double r68378 = r68376 + r68377;
        double r68379 = r68375 / r68378;
        return r68379;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r68380 = y_re;
        double r68381 = -1.928097023327238e+94;
        bool r68382 = r68380 <= r68381;
        double r68383 = -1.0;
        double r68384 = x_im;
        double r68385 = r68383 * r68384;
        double r68386 = y_im;
        double r68387 = hypot(r68380, r68386);
        double r68388 = 1.0;
        double r68389 = r68387 * r68388;
        double r68390 = r68385 / r68389;
        double r68391 = 3.8584984167732284e+39;
        bool r68392 = r68380 <= r68391;
        double r68393 = r68384 * r68380;
        double r68394 = x_re;
        double r68395 = r68394 * r68386;
        double r68396 = r68393 - r68395;
        double r68397 = r68396 / r68387;
        double r68398 = r68397 / r68389;
        double r68399 = 4.0740961827290516e+154;
        bool r68400 = r68380 <= r68399;
        double r68401 = r68386 * r68386;
        double r68402 = fma(r68380, r68380, r68401);
        double r68403 = r68402 / r68380;
        double r68404 = r68384 / r68403;
        double r68405 = r68402 / r68386;
        double r68406 = r68394 / r68405;
        double r68407 = r68404 - r68406;
        double r68408 = 5.214345045033657e+171;
        bool r68409 = r68380 <= r68408;
        double r68410 = r68387 / r68397;
        double r68411 = r68388 / r68410;
        double r68412 = r68384 / r68389;
        double r68413 = r68409 ? r68411 : r68412;
        double r68414 = r68400 ? r68407 : r68413;
        double r68415 = r68392 ? r68398 : r68414;
        double r68416 = r68382 ? r68390 : r68415;
        return r68416;
}

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 5 regimes
  2. if y.re < -1.928097023327238e+94

    1. Initial program 38.9

      \[\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-sqrt38.9

      \[\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-identity38.9

      \[\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-frac38.9

      \[\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. Simplified38.9

      \[\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. Simplified27.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 associate-*l/27.2

      \[\leadsto \color{blue}{\frac{1 \cdot \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) \cdot 1}}\]
    10. Simplified27.2

      \[\leadsto \frac{\color{blue}{\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) \cdot 1}\]
    11. Taylor expanded around -inf 17.1

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

    if -1.928097023327238e+94 < y.re < 3.8584984167732284e+39

    1. Initial program 18.3

      \[\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-sqrt18.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-identity18.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-frac18.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. Simplified18.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. Simplified11.4

      \[\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 associate-*l/11.3

      \[\leadsto \color{blue}{\frac{1 \cdot \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) \cdot 1}}\]
    10. Simplified11.3

      \[\leadsto \frac{\color{blue}{\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) \cdot 1}\]

    if 3.8584984167732284e+39 < y.re < 4.0740961827290516e+154

    1. Initial program 22.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 div-sub22.2

      \[\leadsto \color{blue}{\frac{x.im \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}}\]
    4. Simplified14.3

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

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

    if 4.0740961827290516e+154 < y.re < 5.214345045033657e+171

    1. Initial program 54.0

      \[\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-sqrt54.0

      \[\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-identity54.0

      \[\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-frac54.0

      \[\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. Simplified54.0

      \[\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. Simplified21.9

      \[\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 associate-*l/21.8

      \[\leadsto \color{blue}{\frac{1 \cdot \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) \cdot 1}}\]
    10. Simplified21.8

      \[\leadsto \frac{\color{blue}{\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) \cdot 1}\]
    11. Using strategy rm
    12. Applied clear-num22.4

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

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

    if 5.214345045033657e+171 < y.re

    1. Initial program 45.5

      \[\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-sqrt45.5

      \[\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-identity45.5

      \[\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-frac45.5

      \[\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. Simplified45.5

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

      \[\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 associate-*l/31.4

      \[\leadsto \color{blue}{\frac{1 \cdot \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) \cdot 1}}\]
    10. Simplified31.4

      \[\leadsto \frac{\color{blue}{\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) \cdot 1}\]
    11. Taylor expanded around inf 13.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.92809702332723783 \cdot 10^{94}:\\ \;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \mathbf{elif}\;y.re \le 3.85849841677322835 \cdot 10^{39}:\\ \;\;\;\;\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) \cdot 1}\\ \mathbf{elif}\;y.re \le 4.0740961827290516 \cdot 10^{154}:\\ \;\;\;\;\frac{x.im}{\frac{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}{y.re}} - \frac{x.re}{\frac{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}{y.im}}\\ \mathbf{elif}\;y.re \le 5.21434504503365728 \cdot 10^{171}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \end{array}\]

Reproduce

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