Average Error: 25.9 → 12.7
Time: 30.5s
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.58972528481860216307208015835708105017 \cdot 10^{116}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 4.790153388469599519369386020665188076147 \cdot 10^{114}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\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 -5.58972528481860216307208015835708105017 \cdot 10^{116}:\\
\;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\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 r2402029 = x_im;
        double r2402030 = y_re;
        double r2402031 = r2402029 * r2402030;
        double r2402032 = x_re;
        double r2402033 = y_im;
        double r2402034 = r2402032 * r2402033;
        double r2402035 = r2402031 - r2402034;
        double r2402036 = r2402030 * r2402030;
        double r2402037 = r2402033 * r2402033;
        double r2402038 = r2402036 + r2402037;
        double r2402039 = r2402035 / r2402038;
        return r2402039;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2402040 = y_re;
        double r2402041 = -5.589725284818602e+116;
        bool r2402042 = r2402040 <= r2402041;
        double r2402043 = x_im;
        double r2402044 = -r2402043;
        double r2402045 = y_im;
        double r2402046 = hypot(r2402040, r2402045);
        double r2402047 = r2402044 / r2402046;
        double r2402048 = 4.7901533884695995e+114;
        bool r2402049 = r2402040 <= r2402048;
        double r2402050 = r2402043 * r2402040;
        double r2402051 = r2402050 / r2402046;
        double r2402052 = x_re;
        double r2402053 = r2402052 * r2402045;
        double r2402054 = r2402053 / r2402046;
        double r2402055 = r2402051 - r2402054;
        double r2402056 = r2402055 / r2402046;
        double r2402057 = r2402043 / r2402046;
        double r2402058 = r2402049 ? r2402056 : r2402057;
        double r2402059 = r2402042 ? r2402047 : r2402058;
        return r2402059;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if y.re < -5.589725284818602e+116

    1. Initial program 41.3

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

      \[\leadsto \color{blue}{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt41.3

      \[\leadsto \frac{y.re \cdot x.im - y.im \cdot x.re}{\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*41.3

      \[\leadsto \color{blue}{\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\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 clear-num41.5

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re \cdot x.im - x.re \cdot y.im} \cdot \mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied associate-/r*28.1

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re \cdot x.im - x.re \cdot y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    11. Simplified28.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)}\]
    12. Taylor expanded around -inf 15.8

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

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

    if -5.589725284818602e+116 < y.re < 4.7901533884695995e+114

    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. Simplified18.6

      \[\leadsto \color{blue}{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt18.6

      \[\leadsto \frac{y.re \cdot x.im - y.im \cdot x.re}{\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.5

      \[\leadsto \color{blue}{\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\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 clear-num18.7

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re \cdot x.im - x.re \cdot y.im} \cdot \mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied associate-/r*11.4

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re \cdot x.im - x.re \cdot y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    11. Simplified11.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)}\]
    12. Using strategy rm
    13. Applied div-sub11.3

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

    if 4.7901533884695995e+114 < y.re

    1. Initial program 40.4

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

      \[\leadsto \color{blue}{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt40.4

      \[\leadsto \frac{y.re \cdot x.im - y.im \cdot x.re}{\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*40.4

      \[\leadsto \color{blue}{\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\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 clear-num40.4

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re \cdot x.im - x.re \cdot y.im} \cdot \mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Using strategy rm
    10. Applied associate-/r*27.2

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re \cdot x.im - x.re \cdot y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    11. Simplified27.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)}\]
    12. Taylor expanded around inf 15.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -5.58972528481860216307208015835708105017 \cdot 10^{116}:\\ \;\;\;\;\frac{-x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 4.790153388469599519369386020665188076147 \cdot 10^{114}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

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