Average Error: 26.5 → 5.9
Time: 14.6s
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 -7.628418106649201380940868857866613274008 \cdot 10^{231} \lor \neg \left(y.re \le 6.466645064161413486396068949012084680784 \cdot 10^{58}\right):\\ \;\;\;\;\frac{y.re \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}}{\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 -7.628418106649201380940868857866613274008 \cdot 10^{231} \lor \neg \left(y.re \le 6.466645064161413486396068949012084680784 \cdot 10^{58}\right):\\
\;\;\;\;\frac{y.re \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{y.re \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}}{\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 r41142 = x_im;
        double r41143 = y_re;
        double r41144 = r41142 * r41143;
        double r41145 = x_re;
        double r41146 = y_im;
        double r41147 = r41145 * r41146;
        double r41148 = r41144 - r41147;
        double r41149 = r41143 * r41143;
        double r41150 = r41146 * r41146;
        double r41151 = r41149 + r41150;
        double r41152 = r41148 / r41151;
        return r41152;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r41153 = y_re;
        double r41154 = -7.628418106649201e+231;
        bool r41155 = r41153 <= r41154;
        double r41156 = 6.466645064161413e+58;
        bool r41157 = r41153 <= r41156;
        double r41158 = !r41157;
        bool r41159 = r41155 || r41158;
        double r41160 = x_im;
        double r41161 = y_im;
        double r41162 = hypot(r41153, r41161);
        double r41163 = r41160 / r41162;
        double r41164 = r41153 * r41163;
        double r41165 = r41164 / r41162;
        double r41166 = x_re;
        double r41167 = r41161 * r41166;
        double r41168 = r41167 / r41162;
        double r41169 = r41168 / r41162;
        double r41170 = r41165 - r41169;
        double r41171 = r41153 * r41160;
        double r41172 = r41171 / r41162;
        double r41173 = r41172 / r41162;
        double r41174 = r41162 / r41166;
        double r41175 = r41161 / r41174;
        double r41176 = r41175 / r41162;
        double r41177 = r41173 - r41176;
        double r41178 = r41159 ? r41170 : r41177;
        return r41178;
}

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 2 regimes
  2. if y.re < -7.628418106649201e+231 or 6.466645064161413e+58 < y.re

    1. Initial program 37.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified37.7

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity37.7

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    12. Using strategy rm
    13. Applied div-sub26.7

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

      \[\leadsto \color{blue}{\frac{\frac{y.re \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    15. Using strategy rm
    16. Applied *-un-lft-identity26.7

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

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

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

    if -7.628418106649201e+231 < y.re < 6.466645064161413e+58

    1. Initial program 22.2

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

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

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}}\]
    5. Applied *-un-lft-identity22.2

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    12. Using strategy rm
    13. Applied div-sub13.2

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

      \[\leadsto \color{blue}{\frac{\frac{y.re \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    15. Using strategy rm
    16. Applied associate-/l*5.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -7.628418106649201380940868857866613274008 \cdot 10^{231} \lor \neg \left(y.re \le 6.466645064161413486396068949012084680784 \cdot 10^{58}\right):\\ \;\;\;\;\frac{y.re \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\frac{y.im}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

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