Average Error: 26.4 → 12.7
Time: 3.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.3927648088213951 \cdot 10^{132}:\\ \;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \mathbf{elif}\;y.re \le -1.2987370292207596 \cdot 10^{-142}:\\ \;\;\;\;\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 1.4267271815310314 \cdot 10^{169}:\\ \;\;\;\;\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{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 -5.3927648088213951 \cdot 10^{132}:\\
\;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\

\mathbf{elif}\;y.re \le -1.2987370292207596 \cdot 10^{-142}:\\
\;\;\;\;\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 1.4267271815310314 \cdot 10^{169}:\\
\;\;\;\;\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{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 r66453 = x_im;
        double r66454 = y_re;
        double r66455 = r66453 * r66454;
        double r66456 = x_re;
        double r66457 = y_im;
        double r66458 = r66456 * r66457;
        double r66459 = r66455 - r66458;
        double r66460 = r66454 * r66454;
        double r66461 = r66457 * r66457;
        double r66462 = r66460 + r66461;
        double r66463 = r66459 / r66462;
        return r66463;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r66464 = y_re;
        double r66465 = -5.392764808821395e+132;
        bool r66466 = r66464 <= r66465;
        double r66467 = -1.0;
        double r66468 = x_im;
        double r66469 = r66467 * r66468;
        double r66470 = y_im;
        double r66471 = hypot(r66464, r66470);
        double r66472 = 1.0;
        double r66473 = r66471 * r66472;
        double r66474 = r66469 / r66473;
        double r66475 = -1.2987370292207596e-142;
        bool r66476 = r66464 <= r66475;
        double r66477 = r66470 * r66470;
        double r66478 = fma(r66464, r66464, r66477);
        double r66479 = r66478 / r66464;
        double r66480 = r66468 / r66479;
        double r66481 = x_re;
        double r66482 = r66478 / r66470;
        double r66483 = r66481 / r66482;
        double r66484 = r66480 - r66483;
        double r66485 = 1.4267271815310314e+169;
        bool r66486 = r66464 <= r66485;
        double r66487 = r66468 * r66464;
        double r66488 = r66481 * r66470;
        double r66489 = r66487 - r66488;
        double r66490 = r66489 / r66471;
        double r66491 = r66490 / r66473;
        double r66492 = r66468 / r66473;
        double r66493 = r66486 ? r66491 : r66492;
        double r66494 = r66476 ? r66484 : r66493;
        double r66495 = r66466 ? r66474 : r66494;
        return r66495;
}

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 4 regimes
  2. if y.re < -5.392764808821395e+132

    1. Initial program 44.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-sqrt44.3

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

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

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

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

      \[\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/28.9

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

      \[\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 14.7

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

    if -5.392764808821395e+132 < y.re < -1.2987370292207596e-142

    1. Initial program 16.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 div-sub16.4

      \[\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. Simplified13.8

      \[\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. Simplified12.1

      \[\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 -1.2987370292207596e-142 < y.re < 1.4267271815310314e+169

    1. Initial program 21.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-sqrt21.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-identity21.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-frac21.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. Simplified21.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. Simplified12.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/12.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. Simplified12.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 1.4267271815310314e+169 < y.re

    1. Initial program 45.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-sqrt45.3

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -5.3927648088213951 \cdot 10^{132}:\\ \;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \mathbf{elif}\;y.re \le -1.2987370292207596 \cdot 10^{-142}:\\ \;\;\;\;\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 1.4267271815310314 \cdot 10^{169}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\\ \end{array}\]

Reproduce

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