Average Error: 25.8 → 10.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} t_0 := \frac{\frac{-\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{-\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{if}\;y.re \leq -3.951719848587527 \cdot 10^{+140}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{elif}\;y.re \leq -2.1020937544048643 \cdot 10^{-195}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq 9.158472105652272 \cdot 10^{-177}:\\ \;\;\;\;\frac{y.re \cdot x.re}{{y.im}^{2}} + \frac{x.im}{y.im}\\ \mathbf{elif}\;y.re \leq 7.712883155351153 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)\\ \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 x.re y.re (* y.im x.im))) (hypot y.re y.im))
          (- (hypot y.re y.im)))))
   (if (<= y.re -3.951719848587527e+140)
     (fma (/ y.im y.re) (/ x.im y.re) (/ x.re y.re))
     (if (<= y.re -2.1020937544048643e-195)
       t_0
       (if (<= y.re 9.158472105652272e-177)
         (+ (/ (* y.re x.re) (pow y.im 2.0)) (/ x.im y.im))
         (if (<= y.re 7.712883155351153e+76)
           t_0
           (* (/ 1.0 (hypot y.re y.im)) (fma (/ y.im y.re) x.im x.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(x_46_re, y_46_re, (y_46_im * x_46_im)) / hypot(y_46_re, y_46_im)) / -hypot(y_46_re, y_46_im);
	double tmp;
	if (y_46_re <= -3.951719848587527e+140) {
		tmp = fma((y_46_im / y_46_re), (x_46_im / y_46_re), (x_46_re / y_46_re));
	} else if (y_46_re <= -2.1020937544048643e-195) {
		tmp = t_0;
	} else if (y_46_re <= 9.158472105652272e-177) {
		tmp = ((y_46_re * x_46_re) / pow(y_46_im, 2.0)) + (x_46_im / y_46_im);
	} else if (y_46_re <= 7.712883155351153e+76) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(y_46_re, y_46_im)) * fma((y_46_im / y_46_re), x_46_im, x_46_re);
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
end
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(Float64(-fma(x_46_re, y_46_re, Float64(y_46_im * x_46_im))) / hypot(y_46_re, y_46_im)) / Float64(-hypot(y_46_re, y_46_im)))
	tmp = 0.0
	if (y_46_re <= -3.951719848587527e+140)
		tmp = fma(Float64(y_46_im / y_46_re), Float64(x_46_im / y_46_re), Float64(x_46_re / y_46_re));
	elseif (y_46_re <= -2.1020937544048643e-195)
		tmp = t_0;
	elseif (y_46_re <= 9.158472105652272e-177)
		tmp = Float64(Float64(Float64(y_46_re * x_46_re) / (y_46_im ^ 2.0)) + Float64(x_46_im / y_46_im));
	elseif (y_46_re <= 7.712883155351153e+76)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(y_46_re, y_46_im)) * fma(Float64(y_46_im / y_46_re), x_46_im, x_46_re));
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[((-N[(x$46$re * y$46$re + N[(y$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]) / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[y$46$re, -3.951719848587527e+140], N[(N[(y$46$im / y$46$re), $MachinePrecision] * N[(x$46$im / y$46$re), $MachinePrecision] + N[(x$46$re / y$46$re), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, -2.1020937544048643e-195], t$95$0, If[LessEqual[y$46$re, 9.158472105652272e-177], N[(N[(N[(y$46$re * x$46$re), $MachinePrecision] / N[Power[y$46$im, 2.0], $MachinePrecision]), $MachinePrecision] + N[(x$46$im / y$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 7.712883155351153e+76], t$95$0, N[(N[(1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(y$46$im / y$46$re), $MachinePrecision] * x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]]]]]]
\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 := \frac{\frac{-\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{-\mathsf{hypot}\left(y.re, y.im\right)}\\
\mathbf{if}\;y.re \leq -3.951719848587527 \cdot 10^{+140}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\

\mathbf{elif}\;y.re \leq -2.1020937544048643 \cdot 10^{-195}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y.re \leq 9.158472105652272 \cdot 10^{-177}:\\
\;\;\;\;\frac{y.re \cdot x.re}{{y.im}^{2}} + \frac{x.im}{y.im}\\

\mathbf{elif}\;y.re \leq 7.712883155351153 \cdot 10^{+76}:\\
\;\;\;\;t_0\\

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


\end{array}

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 < -3.9517198485875273e140

    1. Initial program 44.4

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

      \[\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)}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Taylor expanded in y.re around inf 15.1

      \[\leadsto \color{blue}{\frac{y.im \cdot x.im}{{y.re}^{2}} + \frac{x.re}{y.re}} \]
    5. Simplified7.6

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

    if -3.9517198485875273e140 < y.re < -2.1020937544048643e-195 or 9.15847210565227231e-177 < y.re < 7.71288315535115255e76

    1. Initial program 16.3

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

      \[\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 egg-rr11.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)}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr11.1

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

    if -2.1020937544048643e-195 < y.re < 9.15847210565227231e-177

    1. Initial program 23.3

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

      \[\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 y.re around 0 9.7

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

    if 7.71288315535115255e76 < y.re

    1. Initial program 37.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified37.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. Applied egg-rr25.3

      \[\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)}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Taylor expanded in y.re around inf 14.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -3.951719848587527 \cdot 10^{+140}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{elif}\;y.re \leq -2.1020937544048643 \cdot 10^{-195}:\\ \;\;\;\;\frac{\frac{-\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{-\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \leq 9.158472105652272 \cdot 10^{-177}:\\ \;\;\;\;\frac{y.re \cdot x.re}{{y.im}^{2}} + \frac{x.im}{y.im}\\ \mathbf{elif}\;y.re \leq 7.712883155351153 \cdot 10^{+76}:\\ \;\;\;\;\frac{\frac{-\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{-\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right)\\ \end{array} \]

Reproduce

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