Average Error: 26.1 → 13.2
Time: 16.9s
Precision: 64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -2.2063458127550573 \cdot 10^{+100}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 4.054287420560557 \cdot 10^{+138}:\\ \;\;\;\;\frac{\frac{1}{\frac{1}{\mathsf{fma}\left(x.re, y.re, \left(y.im \cdot x.im\right)\right)} \cdot \mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
\mathbf{if}\;y.re \le -2.2063458127550573 \cdot 10^{+100}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 4.054287420560557 \cdot 10^{+138}:\\
\;\;\;\;\frac{\frac{1}{\frac{1}{\mathsf{fma}\left(x.re, y.re, \left(y.im \cdot x.im\right)\right)} \cdot \mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{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 r688433 = x_re;
        double r688434 = y_re;
        double r688435 = r688433 * r688434;
        double r688436 = x_im;
        double r688437 = y_im;
        double r688438 = r688436 * r688437;
        double r688439 = r688435 + r688438;
        double r688440 = r688434 * r688434;
        double r688441 = r688437 * r688437;
        double r688442 = r688440 + r688441;
        double r688443 = r688439 / r688442;
        return r688443;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r688444 = y_re;
        double r688445 = -2.2063458127550573e+100;
        bool r688446 = r688444 <= r688445;
        double r688447 = x_re;
        double r688448 = -r688447;
        double r688449 = y_im;
        double r688450 = hypot(r688444, r688449);
        double r688451 = r688448 / r688450;
        double r688452 = 4.054287420560557e+138;
        bool r688453 = r688444 <= r688452;
        double r688454 = 1.0;
        double r688455 = x_im;
        double r688456 = r688449 * r688455;
        double r688457 = fma(r688447, r688444, r688456);
        double r688458 = r688454 / r688457;
        double r688459 = r688458 * r688450;
        double r688460 = r688454 / r688459;
        double r688461 = r688460 / r688450;
        double r688462 = r688447 / r688450;
        double r688463 = r688453 ? r688461 : r688462;
        double r688464 = r688446 ? r688451 : r688463;
        return r688464;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Derivation

  1. Split input into 3 regimes
  2. if y.re < -2.2063458127550573e+100

    1. Initial program 38.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt38.4

      \[\leadsto \frac{x.re \cdot y.re + x.im \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*38.4

      \[\leadsto \color{blue}{\frac{\frac{x.re \cdot y.re + x.im \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-def38.4

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}{x.re \cdot y.re + x.im \cdot y.im}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    9. Simplified25.2

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

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

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

    if -2.2063458127550573e+100 < y.re < 4.054287420560557e+138

    1. Initial program 18.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt18.6

      \[\leadsto \frac{x.re \cdot y.re + x.im \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.5

      \[\leadsto \color{blue}{\frac{\frac{x.re \cdot y.re + x.im \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.5

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}{x.re \cdot y.re + x.im \cdot y.im}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    9. Simplified11.8

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    10. Using strategy rm
    11. Applied div-inv12.0

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

    if 4.054287420560557e+138 < y.re

    1. Initial program 45.0

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt45.0

      \[\leadsto \frac{x.re \cdot y.re + x.im \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.0

      \[\leadsto \color{blue}{\frac{\frac{x.re \cdot y.re + x.im \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.0

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

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}}}}{\mathsf{hypot}\left(y.re, y.im\right)}\]
    10. Taylor expanded around inf 14.5

      \[\leadsto \frac{\color{blue}{x.re}}{\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 -2.2063458127550573 \cdot 10^{+100}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 4.054287420560557 \cdot 10^{+138}:\\ \;\;\;\;\frac{\frac{1}{\frac{1}{\mathsf{fma}\left(x.re, y.re, \left(y.im \cdot x.im\right)\right)} \cdot \mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019128 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, real part"
  (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))