Average Error: 26.8 → 4.8
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}\;x.re \le -1.362512780340662 \cdot 10^{122} \lor \neg \left(x.re \le 2.1803868185679244 \cdot 10^{83}\right):\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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 -1.362512780340662 \cdot 10^{122} \lor \neg \left(x.re \le 2.1803868185679244 \cdot 10^{83}\right):\\
\;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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 r71675 = x_im;
        double r71676 = y_re;
        double r71677 = r71675 * r71676;
        double r71678 = x_re;
        double r71679 = y_im;
        double r71680 = r71678 * r71679;
        double r71681 = r71677 - r71680;
        double r71682 = r71676 * r71676;
        double r71683 = r71679 * r71679;
        double r71684 = r71682 + r71683;
        double r71685 = r71681 / r71684;
        return r71685;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r71686 = x_re;
        double r71687 = -1.362512780340662e+122;
        bool r71688 = r71686 <= r71687;
        double r71689 = 2.1803868185679244e+83;
        bool r71690 = r71686 <= r71689;
        double r71691 = !r71690;
        bool r71692 = r71688 || r71691;
        double r71693 = x_im;
        double r71694 = y_re;
        double r71695 = r71693 * r71694;
        double r71696 = y_im;
        double r71697 = hypot(r71694, r71696);
        double r71698 = r71695 / r71697;
        double r71699 = r71698 / r71697;
        double r71700 = r71697 / r71696;
        double r71701 = r71686 / r71700;
        double r71702 = r71701 / r71697;
        double r71703 = r71699 - r71702;
        double r71704 = r71694 / r71697;
        double r71705 = r71693 * r71704;
        double r71706 = r71705 / r71697;
        double r71707 = r71686 * r71696;
        double r71708 = r71707 / r71697;
        double r71709 = r71708 / r71697;
        double r71710 = r71706 - r71709;
        double r71711 = r71692 ? r71703 : r71710;
        return r71711;
}

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 < -1.362512780340662e+122 or 2.1803868185679244e+83 < x.re

    1. Initial program 35.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-sqrt35.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 *-un-lft-identity35.9

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

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

      \[\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. Simplified31.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/31.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. Simplified30.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. Using strategy rm
    12. Applied div-sub30.9

      \[\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. Applied div-sub30.9

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

      \[\leadsto \frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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 -1.362512780340662e+122 < x.re < 2.1803868185679244e+83

    1. Initial program 22.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-sqrt22.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-identity22.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-frac22.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. Simplified22.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. Simplified11.2

      \[\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.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. Simplified11.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-sub11.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. Applied div-sub11.0

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

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

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

      \[\leadsto \frac{\color{blue}{x.im} \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \le -1.362512780340662 \cdot 10^{122} \lor \neg \left(x.re \le 2.1803868185679244 \cdot 10^{83}\right):\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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)}}{\mathsf{hypot}\left(y.re, y.im\right)} - \frac{\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 2020020 +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))))