Average Error: 26.0 → 26.2
Time: 11.4s
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.2109434524169916 \cdot 10^{+96}:\\ \;\;\;\;\frac{-x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \mathbf{elif}\;y.re \le 5.2422713568197025 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.im, y.re, x.re \cdot \left(-y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot 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.2109434524169916 \cdot 10^{+96}:\\
\;\;\;\;\frac{-x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2241454 = x_im;
        double r2241455 = y_re;
        double r2241456 = r2241454 * r2241455;
        double r2241457 = x_re;
        double r2241458 = y_im;
        double r2241459 = r2241457 * r2241458;
        double r2241460 = r2241456 - r2241459;
        double r2241461 = r2241455 * r2241455;
        double r2241462 = r2241458 * r2241458;
        double r2241463 = r2241461 + r2241462;
        double r2241464 = r2241460 / r2241463;
        return r2241464;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2241465 = y_re;
        double r2241466 = -1.2109434524169916e+96;
        bool r2241467 = r2241465 <= r2241466;
        double r2241468 = x_im;
        double r2241469 = -r2241468;
        double r2241470 = y_im;
        double r2241471 = r2241465 * r2241465;
        double r2241472 = fma(r2241470, r2241470, r2241471);
        double r2241473 = sqrt(r2241472);
        double r2241474 = r2241469 / r2241473;
        double r2241475 = 5.2422713568197025e+36;
        bool r2241476 = r2241465 <= r2241475;
        double r2241477 = x_re;
        double r2241478 = -r2241470;
        double r2241479 = r2241477 * r2241478;
        double r2241480 = fma(r2241468, r2241465, r2241479);
        double r2241481 = r2241480 / r2241473;
        double r2241482 = r2241481 / r2241473;
        double r2241483 = r2241468 / r2241473;
        double r2241484 = r2241476 ? r2241482 : r2241483;
        double r2241485 = r2241467 ? r2241474 : r2241484;
        return r2241485;
}

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.re < -1.2109434524169916e+96

    1. Initial program 39.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified39.0

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

      \[\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 associate-/r*38.9

      \[\leadsto \color{blue}{\frac{\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)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Taylor expanded around -inf 38.2

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

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

    if -1.2109434524169916e+96 < y.re < 5.2422713568197025e+36

    1. Initial program 18.5

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified18.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-sqrt18.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 associate-/r*18.4

      \[\leadsto \color{blue}{\frac{\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)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Using strategy rm
    7. Applied fma-neg18.4

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

    if 5.2422713568197025e+36 < y.re

    1. Initial program 34.4

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified34.4

      \[\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-sqrt34.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 associate-/r*34.4

      \[\leadsto \color{blue}{\frac{\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)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}\]
    6. Taylor expanded around inf 36.1

      \[\leadsto \frac{\color{blue}{x.im}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification26.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.2109434524169916 \cdot 10^{+96}:\\ \;\;\;\;\frac{-x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \mathbf{elif}\;y.re \le 5.2422713568197025 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.im, y.re, x.re \cdot \left(-y.im\right)\right)}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\\ \end{array}\]

Reproduce

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