Average Error: 26.2 → 4.5
Time: 3.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}\;x.re \le -2.2571318052192643 \cdot 10^{53} \lor \neg \left(x.re \le 5.3039295420371848 \cdot 10^{69}\right):\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot \frac{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)}\\ \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}\;x.re \le -2.2571318052192643 \cdot 10^{53} \lor \neg \left(x.re \le 5.3039295420371848 \cdot 10^{69}\right):\\
\;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{x.im \cdot \frac{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)}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r56441 = x_im;
        double r56442 = y_re;
        double r56443 = r56441 * r56442;
        double r56444 = x_re;
        double r56445 = y_im;
        double r56446 = r56444 * r56445;
        double r56447 = r56443 - r56446;
        double r56448 = r56442 * r56442;
        double r56449 = r56445 * r56445;
        double r56450 = r56448 + r56449;
        double r56451 = r56447 / r56450;
        return r56451;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r56452 = x_re;
        double r56453 = -2.2571318052192643e+53;
        bool r56454 = r56452 <= r56453;
        double r56455 = 5.303929542037185e+69;
        bool r56456 = r56452 <= r56455;
        double r56457 = !r56456;
        bool r56458 = r56454 || r56457;
        double r56459 = x_im;
        double r56460 = y_re;
        double r56461 = r56459 * r56460;
        double r56462 = y_im;
        double r56463 = hypot(r56460, r56462);
        double r56464 = r56461 / r56463;
        double r56465 = r56463 / r56462;
        double r56466 = r56452 / r56465;
        double r56467 = r56464 - r56466;
        double r56468 = r56467 / r56463;
        double r56469 = r56460 / r56463;
        double r56470 = r56459 * r56469;
        double r56471 = r56452 * r56462;
        double r56472 = r56471 / r56463;
        double r56473 = r56470 - r56472;
        double r56474 = r56473 / r56463;
        double r56475 = r56458 ? r56468 : r56474;
        return r56475;
}

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 x.re < -2.2571318052192643e+53 or 5.303929542037185e+69 < x.re

    1. Initial program 33.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-sqrt33.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-identity33.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-frac33.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. Simplified33.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. 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 associate-*r/27.0

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

      \[\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)}\]
    11. Using strategy rm
    12. Applied div-sub27.0

      \[\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)}\]
    13. Using strategy rm
    14. Applied associate-/l*9.6

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

    if -2.2571318052192643e+53 < x.re < 5.303929542037185e+69

    1. Initial program 21.5

      \[\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-sqrt21.5

      \[\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-identity21.5

      \[\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-frac21.5

      \[\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. Simplified21.5

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

      \[\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 associate-*r/10.5

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

      \[\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)}\]
    11. Using strategy rm
    12. Applied div-sub10.4

      \[\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)}\]
    13. Using strategy rm
    14. Applied *-un-lft-identity10.4

      \[\leadsto \frac{\frac{x.im \cdot y.re}{\color{blue}{1 \cdot \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)}\]
    15. Applied times-frac1.4

      \[\leadsto \frac{\color{blue}{\frac{x.im}{1} \cdot \frac{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)}\]
    16. Simplified1.4

      \[\leadsto \frac{\color{blue}{x.im} \cdot \frac{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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification4.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \le -2.2571318052192643 \cdot 10^{53} \lor \neg \left(x.re \le 5.3039295420371848 \cdot 10^{69}\right):\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{x.re}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.im}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot \frac{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)}\\ \end{array}\]

Reproduce

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