Average Error: 26.1 → 13.4
Time: 15.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 -8.305623690601149751122925407417973083209 \cdot 10^{163}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 2.805404912411875912470168548725953456027 \cdot 10^{84}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.im, x.re \cdot \left(-y.im\right)\right)}{\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 -8.305623690601149751122925407417973083209 \cdot 10^{163}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;y.re \le 2.805404912411875912470168548725953456027 \cdot 10^{84}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.im, x.re \cdot \left(-y.im\right)\right)}{\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 r3120635 = x_im;
        double r3120636 = y_re;
        double r3120637 = r3120635 * r3120636;
        double r3120638 = x_re;
        double r3120639 = y_im;
        double r3120640 = r3120638 * r3120639;
        double r3120641 = r3120637 - r3120640;
        double r3120642 = r3120636 * r3120636;
        double r3120643 = r3120639 * r3120639;
        double r3120644 = r3120642 + r3120643;
        double r3120645 = r3120641 / r3120644;
        return r3120645;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r3120646 = y_re;
        double r3120647 = -8.30562369060115e+163;
        bool r3120648 = r3120646 <= r3120647;
        double r3120649 = x_im;
        double r3120650 = y_im;
        double r3120651 = hypot(r3120650, r3120646);
        double r3120652 = r3120649 / r3120651;
        double r3120653 = -r3120652;
        double r3120654 = 2.805404912411876e+84;
        bool r3120655 = r3120646 <= r3120654;
        double r3120656 = x_re;
        double r3120657 = -r3120650;
        double r3120658 = r3120656 * r3120657;
        double r3120659 = fma(r3120646, r3120649, r3120658);
        double r3120660 = r3120659 / r3120651;
        double r3120661 = r3120660 / r3120651;
        double r3120662 = r3120655 ? r3120661 : r3120652;
        double r3120663 = r3120648 ? r3120653 : r3120662;
        return r3120663;
}

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 < -8.30562369060115e+163

    1. Initial program 45.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified45.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-sqrt45.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*45.0

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

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def45.0

      \[\leadsto \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)}}}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    9. Taylor expanded around -inf 13.0

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

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

    if -8.30562369060115e+163 < y.re < 2.805404912411876e+84

    1. Initial program 19.4

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified19.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-sqrt19.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*19.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-udef19.4

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def19.3

      \[\leadsto \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)}}}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity19.3

      \[\leadsto \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)}}}{\color{blue}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}}\]
    11. Applied associate-/r*19.3

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

      \[\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. Using strategy rm
    14. Applied fma-neg12.1

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

    if 2.805404912411876e+84 < y.re

    1. Initial program 38.3

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

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

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

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

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def38.3

      \[\leadsto \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)}}}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}\]
    9. Taylor expanded around inf 18.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -8.305623690601149751122925407417973083209 \cdot 10^{163}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 2.805404912411875912470168548725953456027 \cdot 10^{84}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(y.re, x.im, x.re \cdot \left(-y.im\right)\right)}{\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 2019179 +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))))