Average Error: 26.8 → 11.2
Time: 6.9s
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 -9.10122331774869 \cdot 10^{+137}:\\ \;\;\;\;\frac{-t_0}{\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 -8.982511531385342 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{if}\;y.re \leq 4.961282432869017 \cdot 10^{-134}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y.re \leq 1.0320858618106521 \cdot 10^{-25}:\\ \;\;\;\;\begin{array}{l} t_3 := \mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\\ \mathsf{fma}\left(x.im, \frac{y.im}{t_3}, \frac{y.re \cdot x.re}{t_3}\right) \end{array}\\ \mathbf{elif}\;y.re \leq 19451542890.138916:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y.re \leq 1.8003344749034084 \cdot 10^{+144}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\\ \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 -9.10122331774869 \cdot 10^{+137}:\\
\;\;\;\;\frac{-t_0}{\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 -8.982511531385342 \cdot 10^{-94}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;y.re \leq 1.0320858618106521 \cdot 10^{-25}:\\
\;\;\;\;\begin{array}{l}
t_3 := \mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\\
\mathsf{fma}\left(x.im, \frac{y.im}{t_3}, \frac{y.re \cdot x.re}{t_3}\right)
\end{array}\\

\mathbf{elif}\;y.re \leq 19451542890.138916:\\
\;\;\;\;t_2\\

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

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


\end{array}\\


\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 -9.10122331774869e+137)
     (/ (- t_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 -8.982511531385342e-94)
         t_1
         (let* ((t_2 (fma (/ x.re y.im) (/ y.re y.im) (/ x.im y.im))))
           (if (<= y.re 4.961282432869017e-134)
             t_2
             (if (<= y.re 1.0320858618106521e-25)
               (let* ((t_3 (fma y.im y.im (* y.re y.re))))
                 (fma x.im (/ y.im t_3) (/ (* y.re x.re) t_3)))
               (if (<= y.re 19451542890.138916)
                 t_2
                 (if (<= y.re 1.8003344749034084e+144)
                   t_1
                   (/ t_0 (hypot y.im y.re))))))))))))
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 <= -9.10122331774869e+137) {
		tmp = -t_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 <= -8.982511531385342e-94) {
			tmp_1 = t_1;
		} else {
			double t_2 = fma((x_46_re / y_46_im), (y_46_re / y_46_im), (x_46_im / y_46_im));
			double tmp_2;
			if (y_46_re <= 4.961282432869017e-134) {
				tmp_2 = t_2;
			} else if (y_46_re <= 1.0320858618106521e-25) {
				double t_3 = fma(y_46_im, y_46_im, (y_46_re * y_46_re));
				tmp_2 = fma(x_46_im, (y_46_im / t_3), ((y_46_re * x_46_re) / t_3));
			} else if (y_46_re <= 19451542890.138916) {
				tmp_2 = t_2;
			} else if (y_46_re <= 1.8003344749034084e+144) {
				tmp_2 = t_1;
			} else {
				tmp_2 = t_0 / hypot(y_46_im, y_46_re);
			}
			tmp_1 = tmp_2;
		}
		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 5 regimes
  2. if y.re < -9.1012233177486906e137

    1. Initial program 44.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified44.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_binary6444.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_binary6444.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_binary6444.6

      \[\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. Simplified44.6

      \[\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. Simplified30.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. Applied associate-*l/_binary6430.0

      \[\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. Simplified30.0

      \[\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)} \]
    10. Taylor expanded in y.re around -inf 12.3

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

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

    if -9.1012233177486906e137 < y.re < -8.9825115313853416e-94 or 19451542890.13892 < y.re < 1.80033447490340839e144

    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. Simplified18.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_binary6418.7

      \[\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_binary6418.7

      \[\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_binary6418.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. Simplified18.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. Simplified14.0

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

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

      \[\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)} \]
    10. Applied pow1_binary6413.8

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

    if -8.9825115313853416e-94 < y.re < 4.9612824328690171e-134 or 1.0320858618106521e-25 < y.re < 19451542890.13892

    1. Initial program 22.0

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified22.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. Applied add-sqr-sqrt_binary6422.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)}}} \]
    4. Applied *-un-lft-identity_binary6422.0

      \[\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_binary6422.0

      \[\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. Simplified22.0

      \[\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. Simplified12.7

      \[\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 13.7

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

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

    if 4.9612824328690171e-134 < y.re < 1.0320858618106521e-25

    1. Initial program 13.5

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

      \[\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. Taylor expanded in x.re around 0 13.5

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

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

    if 1.80033447490340839e144 < y.re

    1. Initial program 44.5

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

      \[\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_binary6444.5

      \[\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_binary6444.5

      \[\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_binary6444.5

      \[\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. Simplified44.5

      \[\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. Simplified30.6

      \[\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/_binary6430.6

      \[\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. Simplified30.6

      \[\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)} \]
    10. Taylor expanded in y.re around inf 12.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -9.10122331774869 \cdot 10^{+137}:\\ \;\;\;\;\frac{-\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \leq -8.982511531385342 \cdot 10^{-94}:\\ \;\;\;\;\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 4.961282432869017 \cdot 10^{-134}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 1.0320858618106521 \cdot 10^{-25}:\\ \;\;\;\;\mathsf{fma}\left(x.im, \frac{y.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}, \frac{y.re \cdot x.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\right)\\ \mathbf{elif}\;y.re \leq 19451542890.138916:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 1.8003344749034084 \cdot 10^{+144}:\\ \;\;\;\;\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{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array} \]

Reproduce

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