Average Error: 25.7 → 12.6
Time: 15.2s
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.729339549361261 \cdot 10^{+115}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.512622379546738 \cdot 10^{+155}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 -7.729339549361261 \cdot 10^{+115}:\\
\;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 1.512622379546738 \cdot 10^{+155}:\\
\;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 r2616323 = x_im;
        double r2616324 = y_re;
        double r2616325 = r2616323 * r2616324;
        double r2616326 = x_re;
        double r2616327 = y_im;
        double r2616328 = r2616326 * r2616327;
        double r2616329 = r2616325 - r2616328;
        double r2616330 = r2616324 * r2616324;
        double r2616331 = r2616327 * r2616327;
        double r2616332 = r2616330 + r2616331;
        double r2616333 = r2616329 / r2616332;
        return r2616333;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2616334 = y_re;
        double r2616335 = -7.729339549361261e+115;
        bool r2616336 = r2616334 <= r2616335;
        double r2616337 = x_im;
        double r2616338 = y_im;
        double r2616339 = hypot(r2616334, r2616338);
        double r2616340 = r2616337 / r2616339;
        double r2616341 = -r2616340;
        double r2616342 = 1.512622379546738e+155;
        bool r2616343 = r2616334 <= r2616342;
        double r2616344 = r2616337 * r2616334;
        double r2616345 = x_re;
        double r2616346 = r2616338 * r2616345;
        double r2616347 = r2616344 - r2616346;
        double r2616348 = r2616347 / r2616339;
        double r2616349 = r2616348 / r2616339;
        double r2616350 = r2616343 ? r2616349 : r2616340;
        double r2616351 = r2616336 ? r2616341 : r2616350;
        return r2616351;
}

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 < -7.729339549361261e+115

    1. Initial program 40.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-sqrt40.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 associate-/r*40.9

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied hypot-def40.9

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    7. Using strategy rm
    8. Applied hypot-def26.5

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Taylor expanded around -inf 15.5

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

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

    if -7.729339549361261e+115 < y.re < 1.512622379546738e+155

    1. Initial program 18.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-sqrt18.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 associate-/r*18.4

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied hypot-def18.4

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    7. Using strategy rm
    8. Applied hypot-def11.4

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Taylor expanded around inf 11.4

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

    if 1.512622379546738e+155 < y.re

    1. Initial program 45.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-sqrt45.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 associate-/r*45.9

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied hypot-def45.9

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    7. Using strategy rm
    8. Applied hypot-def27.9

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}\]
    9. Taylor expanded around inf 15.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -7.729339549361261 \cdot 10^{+115}:\\ \;\;\;\;-\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.512622379546738 \cdot 10^{+155}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re - y.im \cdot x.re}{\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 2019162 +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))))