Average Error: 26.1 → 13.2
Time: 3.8s
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 -1.24989762348172646 \cdot 10^{107}:\\ \;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 7.04631729015775065 \cdot 10^{128}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\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 -1.24989762348172646 \cdot 10^{107}:\\
\;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 7.04631729015775065 \cdot 10^{128}:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\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 r107520 = x_im;
        double r107521 = y_re;
        double r107522 = r107520 * r107521;
        double r107523 = x_re;
        double r107524 = y_im;
        double r107525 = r107523 * r107524;
        double r107526 = r107522 - r107525;
        double r107527 = r107521 * r107521;
        double r107528 = r107524 * r107524;
        double r107529 = r107527 + r107528;
        double r107530 = r107526 / r107529;
        return r107530;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r107531 = y_re;
        double r107532 = -1.2498976234817265e+107;
        bool r107533 = r107531 <= r107532;
        double r107534 = -1.0;
        double r107535 = x_im;
        double r107536 = r107534 * r107535;
        double r107537 = y_im;
        double r107538 = hypot(r107531, r107537);
        double r107539 = r107536 / r107538;
        double r107540 = 7.04631729015775e+128;
        bool r107541 = r107531 <= r107540;
        double r107542 = r107535 * r107531;
        double r107543 = x_re;
        double r107544 = r107543 * r107537;
        double r107545 = r107542 - r107544;
        double r107546 = r107545 / r107538;
        double r107547 = 1.0;
        double r107548 = r107547 / r107538;
        double r107549 = r107546 * r107548;
        double r107550 = r107535 / r107538;
        double r107551 = r107541 ? r107549 : r107550;
        double r107552 = r107533 ? r107539 : r107551;
        return r107552;
}

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 < -1.2498976234817265e+107

    1. Initial program 40.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-sqrt40.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-identity40.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-frac40.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. Simplified40.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. Simplified27.0

      \[\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/26.9

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

      \[\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. Taylor expanded around -inf 16.4

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

    if -1.2498976234817265e+107 < y.re < 7.04631729015775e+128

    1. Initial program 18.7

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

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

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

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

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

      \[\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/11.9

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

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

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

    if 7.04631729015775e+128 < y.re

    1. Initial program 42.0

      \[\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-sqrt42.0

      \[\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-identity42.0

      \[\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-frac42.0

      \[\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. Simplified42.0

      \[\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. Simplified28.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/28.1

      \[\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. Simplified28.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. Taylor expanded around inf 15.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.24989762348172646 \cdot 10^{107}:\\ \;\;\;\;\frac{-1 \cdot x.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 7.04631729015775065 \cdot 10^{128}:\\ \;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\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 2020065 +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))))