Average Error: 26.5 → 14.9
Time: 5.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.im \le -5.0306813936220228 \cdot 10^{154}:\\ \;\;\;\;{\left(\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)}\right)}^{1}\\ \mathbf{elif}\;y.im \le -7.28046239192008739 \cdot 10^{83}:\\ \;\;\;\;\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.im \le 3.8050518390474684 \cdot 10^{-78}:\\ \;\;\;\;{\left(\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)}\right)}^{1}\\ \mathbf{elif}\;y.im \le 5.27378373520958845 \cdot 10^{-64}:\\ \;\;\;\;{\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \mathbf{elif}\;y.im \le 1.9537314790331482 \cdot 10^{152}:\\ \;\;\;\;{\left(\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)}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{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.im \le -5.0306813936220228 \cdot 10^{154}:\\
\;\;\;\;{\left(\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)}\right)}^{1}\\

\mathbf{elif}\;y.im \le -7.28046239192008739 \cdot 10^{83}:\\
\;\;\;\;\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.im \le 3.8050518390474684 \cdot 10^{-78}:\\
\;\;\;\;{\left(\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)}\right)}^{1}\\

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

\mathbf{elif}\;y.im \le 1.9537314790331482 \cdot 10^{152}:\\
\;\;\;\;{\left(\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)}\right)}^{1}\\

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r56559 = x_im;
        double r56560 = y_re;
        double r56561 = r56559 * r56560;
        double r56562 = x_re;
        double r56563 = y_im;
        double r56564 = r56562 * r56563;
        double r56565 = r56561 - r56564;
        double r56566 = r56560 * r56560;
        double r56567 = r56563 * r56563;
        double r56568 = r56566 + r56567;
        double r56569 = r56565 / r56568;
        return r56569;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r56570 = y_im;
        double r56571 = -5.030681393622023e+154;
        bool r56572 = r56570 <= r56571;
        double r56573 = x_im;
        double r56574 = y_re;
        double r56575 = r56573 * r56574;
        double r56576 = x_re;
        double r56577 = r56576 * r56570;
        double r56578 = r56575 - r56577;
        double r56579 = hypot(r56574, r56570);
        double r56580 = r56578 / r56579;
        double r56581 = r56580 / r56579;
        double r56582 = 1.0;
        double r56583 = pow(r56581, r56582);
        double r56584 = -7.280462391920087e+83;
        bool r56585 = r56570 <= r56584;
        double r56586 = r56570 * r56570;
        double r56587 = fma(r56574, r56574, r56586);
        double r56588 = r56587 / r56574;
        double r56589 = r56573 / r56588;
        double r56590 = r56587 / r56570;
        double r56591 = r56576 / r56590;
        double r56592 = r56589 - r56591;
        double r56593 = 3.8050518390474684e-78;
        bool r56594 = r56570 <= r56593;
        double r56595 = 5.2737837352095884e-64;
        bool r56596 = r56570 <= r56595;
        double r56597 = r56573 / r56579;
        double r56598 = pow(r56597, r56582);
        double r56599 = 1.9537314790331482e+152;
        bool r56600 = r56570 <= r56599;
        double r56601 = -1.0;
        double r56602 = r56601 * r56576;
        double r56603 = r56602 / r56579;
        double r56604 = pow(r56603, r56582);
        double r56605 = r56600 ? r56583 : r56604;
        double r56606 = r56596 ? r56598 : r56605;
        double r56607 = r56594 ? r56583 : r56606;
        double r56608 = r56585 ? r56592 : r56607;
        double r56609 = r56572 ? r56583 : r56608;
        return r56609;
}

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.im < -5.030681393622023e+154 or -7.280462391920087e+83 < y.im < 3.8050518390474684e-78 or 5.2737837352095884e-64 < y.im < 1.9537314790331482e+152

    1. Initial program 23.7

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}\right)}^{1}} \cdot {\left(\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\]
    11. Applied pow-prod-down14.9

      \[\leadsto \color{blue}{{\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)}^{1}}\]
    12. Simplified14.8

      \[\leadsto {\color{blue}{\left(\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)}\right)}}^{1}\]

    if -5.030681393622023e+154 < y.im < -7.280462391920087e+83

    1. Initial program 23.7

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

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

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

      \[\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 3.8050518390474684e-78 < y.im < 5.2737837352095884e-64

    1. Initial program 18.6

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\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)}^{1}}\]
    12. Simplified14.1

      \[\leadsto {\color{blue}{\left(\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)}\right)}}^{1}\]
    13. Taylor expanded around inf 40.5

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

    if 1.9537314790331482e+152 < y.im

    1. Initial program 43.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-sqrt43.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-identity43.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-frac43.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. Simplified43.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. Simplified28.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 pow128.2

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

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

      \[\leadsto \color{blue}{{\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)}^{1}}\]
    12. Simplified28.2

      \[\leadsto {\color{blue}{\left(\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)}\right)}}^{1}\]
    13. Taylor expanded around 0 13.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -5.0306813936220228 \cdot 10^{154}:\\ \;\;\;\;{\left(\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)}\right)}^{1}\\ \mathbf{elif}\;y.im \le -7.28046239192008739 \cdot 10^{83}:\\ \;\;\;\;\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.im \le 3.8050518390474684 \cdot 10^{-78}:\\ \;\;\;\;{\left(\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)}\right)}^{1}\\ \mathbf{elif}\;y.im \le 5.27378373520958845 \cdot 10^{-64}:\\ \;\;\;\;{\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \mathbf{elif}\;y.im \le 1.9537314790331482 \cdot 10^{152}:\\ \;\;\;\;{\left(\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)}\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right)}^{1}\\ \end{array}\]

Reproduce

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