Average Error: 26.1 → 12.8
Time: 4.7s
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.24597470578837147715123792905424957408 \cdot 10^{157}:\\ \;\;\;\;1 \cdot \frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 3.688197923953055088349924247699462614225 \cdot 10^{-142}:\\ \;\;\;\;1 \cdot \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)}\\ \mathbf{elif}\;y.re \le 2.113335576260584773435051470067988965813 \cdot 10^{129}:\\ \;\;\;\;\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.041661959657574442785069206121322868384 \cdot 10^{152}:\\ \;\;\;\;1 \cdot \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)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\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.24597470578837147715123792905424957408 \cdot 10^{157}:\\
\;\;\;\;1 \cdot \frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r108768 = x_im;
        double r108769 = y_re;
        double r108770 = r108768 * r108769;
        double r108771 = x_re;
        double r108772 = y_im;
        double r108773 = r108771 * r108772;
        double r108774 = r108770 - r108773;
        double r108775 = r108769 * r108769;
        double r108776 = r108772 * r108772;
        double r108777 = r108775 + r108776;
        double r108778 = r108774 / r108777;
        return r108778;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r108779 = y_re;
        double r108780 = -8.245974705788371e+157;
        bool r108781 = r108779 <= r108780;
        double r108782 = 1.0;
        double r108783 = -1.0;
        double r108784 = x_im;
        double r108785 = r108783 * r108784;
        double r108786 = y_im;
        double r108787 = hypot(r108779, r108786);
        double r108788 = r108785 / r108787;
        double r108789 = r108782 * r108788;
        double r108790 = 3.688197923953055e-142;
        bool r108791 = r108779 <= r108790;
        double r108792 = r108784 * r108779;
        double r108793 = x_re;
        double r108794 = r108793 * r108786;
        double r108795 = r108792 - r108794;
        double r108796 = r108795 / r108787;
        double r108797 = r108796 / r108787;
        double r108798 = r108782 * r108797;
        double r108799 = 2.1133355762605848e+129;
        bool r108800 = r108779 <= r108799;
        double r108801 = r108786 * r108786;
        double r108802 = fma(r108779, r108779, r108801);
        double r108803 = r108802 / r108779;
        double r108804 = r108784 / r108803;
        double r108805 = r108802 / r108786;
        double r108806 = r108793 / r108805;
        double r108807 = r108804 - r108806;
        double r108808 = 1.0416619596575744e+152;
        bool r108809 = r108779 <= r108808;
        double r108810 = r108784 / r108787;
        double r108811 = r108782 * r108810;
        double r108812 = r108809 ? r108798 : r108811;
        double r108813 = r108800 ? r108807 : r108812;
        double r108814 = r108791 ? r108798 : r108813;
        double r108815 = r108781 ? r108789 : r108814;
        return r108815;
}

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 < -8.245974705788371e+157

    1. Initial program 46.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-sqrt46.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-identity46.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-frac46.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. Simplified46.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.6

      \[\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 *-un-lft-identity31.6

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

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

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

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

    if -8.245974705788371e+157 < y.re < 3.688197923953055e-142 or 2.1133355762605848e+129 < y.re < 1.0416619596575744e+152

    1. Initial program 20.8

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

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

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

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

      \[\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. Simplified13.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 *-un-lft-identity13.2

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

      \[\leadsto \color{blue}{1 \cdot \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)}\]
    11. Simplified13.0

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

    if 3.688197923953055e-142 < y.re < 2.1133355762605848e+129

    1. Initial program 15.8

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

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

      \[\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.0416619596575744e+152 < y.re

    1. Initial program 44.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 add-sqr-sqrt44.2

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

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

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

      \[\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.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 *-un-lft-identity27.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -8.24597470578837147715123792905424957408 \cdot 10^{157}:\\ \;\;\;\;1 \cdot \frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 3.688197923953055088349924247699462614225 \cdot 10^{-142}:\\ \;\;\;\;1 \cdot \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)}\\ \mathbf{elif}\;y.re \le 2.113335576260584773435051470067988965813 \cdot 10^{129}:\\ \;\;\;\;\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.041661959657574442785069206121322868384 \cdot 10^{152}:\\ \;\;\;\;1 \cdot \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)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

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