Average Error: 24.9 → 9.3
Time: 5.7s
Precision: binary64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)\\ \mathbf{if}\;y.re \leq -6.262881876053762 \cdot 10^{+112}:\\ \;\;\;\;t_0 \cdot \frac{-1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{if}\;y.re \leq -7.547060237033231 \cdot 10^{-202}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.re \leq 1.4084867377569056 \cdot 10^{-189}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 2.388664514967102 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot t_0\\ \end{array}\\ \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}
t_0 := \mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)\\
\mathbf{if}\;y.re \leq -6.262881876053762 \cdot 10^{+112}:\\
\;\;\;\;t_0 \cdot \frac{-1}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\
\mathbf{if}\;y.re \leq -7.547060237033231 \cdot 10^{-202}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y.re \leq 1.4084867377569056 \cdot 10^{-189}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\

\mathbf{elif}\;y.re \leq 2.388664514967102 \cdot 10^{+71}:\\
\;\;\;\;t_1\\

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


\end{array}\\


\end{array}
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (fma (/ y.im y.re) x.im x.re)))
   (if (<= y.re -6.262881876053762e+112)
     (* t_0 (/ -1.0 (hypot y.im y.re)))
     (let* ((t_1
             (/
              (/ (fma x.re y.re (* y.im x.im)) (hypot y.im y.re))
              (hypot y.im y.re))))
       (if (<= y.re -7.547060237033231e-202)
         t_1
         (if (<= y.re 1.4084867377569056e-189)
           (fma (/ x.re y.im) (/ y.re y.im) (/ x.im y.im))
           (if (<= y.re 2.388664514967102e+71)
             t_1
             (* (/ 1.0 (hypot y.im y.re)) t_0))))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = fma((y_46_im / y_46_re), x_46_im, x_46_re);
	double tmp;
	if (y_46_re <= -6.262881876053762e+112) {
		tmp = t_0 * (-1.0 / hypot(y_46_im, y_46_re));
	} else {
		double t_1 = (fma(x_46_re, y_46_re, (y_46_im * x_46_im)) / hypot(y_46_im, y_46_re)) / hypot(y_46_im, y_46_re);
		double tmp_1;
		if (y_46_re <= -7.547060237033231e-202) {
			tmp_1 = t_1;
		} else if (y_46_re <= 1.4084867377569056e-189) {
			tmp_1 = fma((x_46_re / y_46_im), (y_46_re / y_46_im), (x_46_im / y_46_im));
		} else if (y_46_re <= 2.388664514967102e+71) {
			tmp_1 = t_1;
		} else {
			tmp_1 = (1.0 / hypot(y_46_im, y_46_re)) * t_0;
		}
		tmp = tmp_1;
	}
	return tmp;
}

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 4 regimes
  2. if y.re < -6.26288187605376184e112

    1. Initial program 39.9

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

      \[\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. Applied add-sqr-sqrt_binary6439.9

      \[\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)}}} \]
    4. Applied *-un-lft-identity_binary6439.9

      \[\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)}} \]
    5. Applied times-frac_binary6439.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)}}} \]
    6. Simplified39.9

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

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

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

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

    if -6.26288187605376184e112 < y.re < -7.547060237033231e-202 or 1.4084867377569056e-189 < y.re < 2.3886645149671019e71

    1. Initial program 16.6

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

      \[\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. Applied add-sqr-sqrt_binary6416.6

      \[\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)}}} \]
    4. Applied *-un-lft-identity_binary6416.6

      \[\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)}} \]
    5. Applied times-frac_binary6416.7

      \[\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)}}} \]
    6. Simplified16.7

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

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

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

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

    if -7.547060237033231e-202 < y.re < 1.4084867377569056e-189

    1. Initial program 21.1

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

      \[\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. Applied add-sqr-sqrt_binary6421.1

      \[\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)}}} \]
    4. Applied *-un-lft-identity_binary6421.1

      \[\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)}} \]
    5. Applied times-frac_binary6421.1

      \[\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)}}} \]
    6. Simplified21.1

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

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

      \[\leadsto \color{blue}{\frac{x.re \cdot y.re}{{y.im}^{2}} + \frac{x.im}{y.im}} \]
    9. Simplified5.9

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

    if 2.3886645149671019e71 < y.re

    1. Initial program 36.9

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

      \[\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. Applied add-sqr-sqrt_binary6436.9

      \[\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)}}} \]
    4. Applied *-un-lft-identity_binary6436.9

      \[\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)}} \]
    5. Applied times-frac_binary6436.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)}}} \]
    6. Simplified36.9

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    8. Taylor expanded in y.im around 0 14.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -6.262881876053762 \cdot 10^{+112}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot \frac{-1}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \leq -7.547060237033231 \cdot 10^{-202}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \leq 1.4084867377569056 \cdot 10^{-189}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 2.388664514967102 \cdot 10^{+71}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022067 
(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))))