Average Error: 26.1 → 13.0
Time: 16.2s
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 -1.1443562208296078 \cdot 10^{+200}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.3614475866611724 \cdot 10^{+128}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, y.re, \left(y.im \cdot x.im\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\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 -1.1443562208296078 \cdot 10^{+200}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r2929524 = x_re;
        double r2929525 = y_re;
        double r2929526 = r2929524 * r2929525;
        double r2929527 = x_im;
        double r2929528 = y_im;
        double r2929529 = r2929527 * r2929528;
        double r2929530 = r2929526 + r2929529;
        double r2929531 = r2929525 * r2929525;
        double r2929532 = r2929528 * r2929528;
        double r2929533 = r2929531 + r2929532;
        double r2929534 = r2929530 / r2929533;
        return r2929534;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r2929535 = y_re;
        double r2929536 = -1.1443562208296078e+200;
        bool r2929537 = r2929535 <= r2929536;
        double r2929538 = x_re;
        double r2929539 = -r2929538;
        double r2929540 = y_im;
        double r2929541 = hypot(r2929540, r2929535);
        double r2929542 = r2929539 / r2929541;
        double r2929543 = 1.3614475866611724e+128;
        bool r2929544 = r2929535 <= r2929543;
        double r2929545 = x_im;
        double r2929546 = r2929540 * r2929545;
        double r2929547 = fma(r2929538, r2929535, r2929546);
        double r2929548 = 1.0;
        double r2929549 = r2929548 / r2929541;
        double r2929550 = r2929547 * r2929549;
        double r2929551 = r2929550 / r2929541;
        double r2929552 = r2929538 / r2929541;
        double r2929553 = r2929544 ? r2929551 : r2929552;
        double r2929554 = r2929537 ? r2929542 : r2929553;
        return r2929554;
}

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 < -1.1443562208296078e+200

    1. Initial program 41.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified41.6

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt41.6

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
    5. Applied associate-/r*41.6

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    8. Applied hypot-def41.6

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    9. Using strategy rm
    10. Applied fma-udef41.6

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def28.5

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

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

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

    if -1.1443562208296078e+200 < y.re < 1.3614475866611724e+128

    1. Initial program 20.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified20.9

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt20.9

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
    5. Applied associate-/r*20.8

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    8. Applied hypot-def20.8

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def12.9

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

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

    if 1.3614475866611724e+128 < y.re

    1. Initial program 42.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified42.4

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt42.4

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)} \cdot \sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}}\]
    5. Applied associate-/r*42.4

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

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}}{\sqrt{\mathsf{fma}\left(y.im, y.im, \left(y.re \cdot y.re\right)\right)}}\]
    9. Using strategy rm
    10. Applied fma-udef42.4

      \[\leadsto \frac{\frac{\mathsf{fma}\left(x.re, y.re, \left(x.im \cdot y.im\right)\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def28.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.1443562208296078 \cdot 10^{+200}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \le 1.3614475866611724 \cdot 10^{+128}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, y.re, \left(y.im \cdot x.im\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\]

Reproduce

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