Average Error: 25.7 → 15.4
Time: 5.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} \mathbf{if}\;y.re \leq -5.484152777650426 \cdot 10^{+107}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \mathsf{fma}\left(y.im, y.im, {y.re}^{2}\right)\\ t_1 := \frac{y.re \cdot x.re}{t_0}\\ \mathbf{if}\;y.re \leq -3.398154527463994 \cdot 10^{-146}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{t_0}, x.im, t_1\right)\\ \mathbf{elif}\;y.re \leq 4.956468580167358 \cdot 10^{-31}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{y.im}, x.im, t_1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{y.im \cdot x.im}{{y.re}^{2}}\\ \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}
\mathbf{if}\;y.re \leq -5.484152777650426 \cdot 10^{+107}:\\
\;\;\;\;\frac{x.re}{y.re}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re} + \frac{y.im \cdot x.im}{{y.re}^{2}}\\


\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
 (if (<= y.re -5.484152777650426e+107)
   (/ x.re y.re)
   (let* ((t_0 (fma y.im y.im (pow y.re 2.0))) (t_1 (/ (* y.re x.re) t_0)))
     (if (<= y.re -3.398154527463994e-146)
       (fma (/ y.im t_0) x.im t_1)
       (if (<= y.re 4.956468580167358e-31)
         (fma (/ 1.0 y.im) x.im t_1)
         (+ (/ x.re y.re) (/ (* y.im x.im) (pow y.re 2.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 tmp;
	if (y_46_re <= -5.484152777650426e+107) {
		tmp = x_46_re / y_46_re;
	} else {
		double t_0 = fma(y_46_im, y_46_im, pow(y_46_re, 2.0));
		double t_1 = (y_46_re * x_46_re) / t_0;
		double tmp_1;
		if (y_46_re <= -3.398154527463994e-146) {
			tmp_1 = fma((y_46_im / t_0), x_46_im, t_1);
		} else if (y_46_re <= 4.956468580167358e-31) {
			tmp_1 = fma((1.0 / y_46_im), x_46_im, t_1);
		} else {
			tmp_1 = (x_46_re / y_46_re) + ((y_46_im * x_46_im) / pow(y_46_re, 2.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 < -5.4841527776504262e107

    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. Taylor expanded around inf 16.7

      \[\leadsto \color{blue}{\frac{x.re}{y.re}} \]

    if -5.4841527776504262e107 < y.re < -3.3981545274639941e-146

    1. Initial program 15.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded around 0 15.4

      \[\leadsto \color{blue}{\frac{y.im \cdot x.im}{{y.re}^{2} + {y.im}^{2}} + \frac{x.re \cdot y.re}{{y.re}^{2} + {y.im}^{2}}} \]
    3. Simplified14.1

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

    if -3.3981545274639941e-146 < y.re < 4.95646858016735772e-31

    1. Initial program 20.7

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded around 0 20.7

      \[\leadsto \color{blue}{\frac{y.im \cdot x.im}{{y.re}^{2} + {y.im}^{2}} + \frac{x.re \cdot y.re}{{y.re}^{2} + {y.im}^{2}}} \]
    3. Simplified17.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y.im}{\mathsf{fma}\left(y.im, y.im, {y.re}^{2}\right)}, x.im, \frac{y.re \cdot x.re}{\mathsf{fma}\left(y.im, y.im, {y.re}^{2}\right)}\right)} \]
    4. Taylor expanded around inf 11.0

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

    if 4.95646858016735772e-31 < y.re

    1. Initial program 30.2

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded around inf 20.4

      \[\leadsto \color{blue}{\frac{y.im \cdot x.im}{{y.re}^{2}} + \frac{x.re}{y.re}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification15.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -5.484152777650426 \cdot 10^{+107}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.re \leq -3.398154527463994 \cdot 10^{-146}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{\mathsf{fma}\left(y.im, y.im, {y.re}^{2}\right)}, x.im, \frac{y.re \cdot x.re}{\mathsf{fma}\left(y.im, y.im, {y.re}^{2}\right)}\right)\\ \mathbf{elif}\;y.re \leq 4.956468580167358 \cdot 10^{-31}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{y.im}, x.im, \frac{y.re \cdot x.re}{\mathsf{fma}\left(y.im, y.im, {y.re}^{2}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{y.im \cdot x.im}{{y.re}^{2}}\\ \end{array} \]

Reproduce

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