Average Error: 26.0 → 13.0
Time: 18.0s
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.286184118088981486051285346181269334181 \cdot 10^{163}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.036864426879663678952022222917679113002 \cdot 10^{207}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.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 -1.286184118088981486051285346181269334181 \cdot 10^{163}:\\
\;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{elif}\;y.re \le 1.036864426879663678952022222917679113002 \cdot 10^{207}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.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 r129794 = x_re;
        double r129795 = y_re;
        double r129796 = r129794 * r129795;
        double r129797 = x_im;
        double r129798 = y_im;
        double r129799 = r129797 * r129798;
        double r129800 = r129796 + r129799;
        double r129801 = r129795 * r129795;
        double r129802 = r129798 * r129798;
        double r129803 = r129801 + r129802;
        double r129804 = r129800 / r129803;
        return r129804;
}

double f(double x_re, double x_im, double y_re, double y_im) {
        double r129805 = y_re;
        double r129806 = -1.2861841180889815e+163;
        bool r129807 = r129805 <= r129806;
        double r129808 = x_re;
        double r129809 = -r129808;
        double r129810 = y_im;
        double r129811 = hypot(r129805, r129810);
        double r129812 = r129809 / r129811;
        double r129813 = 1.0368644268796637e+207;
        bool r129814 = r129805 <= r129813;
        double r129815 = 1.0;
        double r129816 = x_im;
        double r129817 = r129810 * r129816;
        double r129818 = fma(r129805, r129808, r129817);
        double r129819 = r129811 / r129818;
        double r129820 = r129815 / r129819;
        double r129821 = r129820 / r129811;
        double r129822 = r129808 / r129811;
        double r129823 = r129814 ? r129821 : r129822;
        double r129824 = r129807 ? r129812 : r129823;
        return r129824;
}

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.2861841180889815e+163

    1. Initial program 46.8

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

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

      \[\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 *-un-lft-identity46.8

      \[\leadsto \frac{\color{blue}{1 \cdot \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)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac46.8

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

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

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

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

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

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

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

    if -1.2861841180889815e+163 < y.re < 1.0368644268796637e+207

    1. Initial program 20.8

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

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

      \[\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 *-un-lft-identity20.8

      \[\leadsto \frac{\color{blue}{1 \cdot \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)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac20.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}} \cdot \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)}}}\]
    7. Simplified20.9

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

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

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

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

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

    if 1.0368644268796637e+207 < y.re

    1. Initial program 42.2

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified42.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-sqrt42.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 *-un-lft-identity42.2

      \[\leadsto \frac{\color{blue}{1 \cdot \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)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}\]
    6. Applied times-frac42.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}} \cdot \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)}}}\]
    7. Simplified42.2

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.286184118088981486051285346181269334181 \cdot 10^{163}:\\ \;\;\;\;\frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.036864426879663678952022222917679113002 \cdot 10^{207}:\\ \;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.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 2019303 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, real part"
  :precision binary64
  (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))