Average Error: 26.8 → 13.5
Time: 17.7s
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.045846669237430472528864761609559364154 \cdot 10^{123}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 8.747123436813267982750810114699097243072 \cdot 10^{191}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{x.re}}\\ \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.045846669237430472528864761609559364154 \cdot 10^{123}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

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

\end{array}
double f(double x_re, double x_im, double y_re, double y_im) {
        double r4760094 = x_re;
        double r4760095 = y_re;
        double r4760096 = r4760094 * r4760095;
        double r4760097 = x_im;
        double r4760098 = y_im;
        double r4760099 = r4760097 * r4760098;
        double r4760100 = r4760096 + r4760099;
        double r4760101 = r4760095 * r4760095;
        double r4760102 = r4760098 * r4760098;
        double r4760103 = r4760101 + r4760102;
        double r4760104 = r4760100 / r4760103;
        return r4760104;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r4760105 = y_re;
        double r4760106 = -2.0458466692374305e+123;
        bool r4760107 = r4760105 <= r4760106;
        double r4760108 = x_re;
        double r4760109 = -r4760108;
        double r4760110 = y_im;
        double r4760111 = hypot(r4760105, r4760110);
        double r4760112 = r4760109 / r4760111;
        double r4760113 = 8.747123436813268e+191;
        bool r4760114 = r4760105 <= r4760113;
        double r4760115 = 1.0;
        double r4760116 = x_im;
        double r4760117 = r4760116 * r4760110;
        double r4760118 = fma(r4760108, r4760105, r4760117);
        double r4760119 = r4760111 / r4760118;
        double r4760120 = r4760115 / r4760119;
        double r4760121 = r4760120 / r4760111;
        double r4760122 = r4760111 / r4760108;
        double r4760123 = r4760115 / r4760122;
        double r4760124 = r4760114 ? r4760121 : r4760123;
        double r4760125 = r4760107 ? r4760112 : r4760124;
        return r4760125;
}

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.0458466692374305e+123

    1. Initial program 41.2

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}}\]
    9. Using strategy rm
    10. Applied associate-/r/28.5

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

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

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

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

    if -2.0458466692374305e+123 < y.re < 8.747123436813268e+191

    1. Initial program 21.4

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}}\]
    9. Using strategy rm
    10. Applied associate-/r/13.7

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

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

    if 8.747123436813268e+191 < y.re

    1. Initial program 43.0

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified43.0

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

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

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

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

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

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

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

Reproduce

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