Average Error: 26.3 → 0.8
Time: 11.9s
Precision: binary64
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\\ t_1 := x.re \cdot \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathsf{fma}\left(y.re \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, t_0, \frac{t_1}{-\mathsf{hypot}\left(y.re, y.im\right)}\right) + \mathsf{fma}\left(\frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)}, t_1, t_0 \cdot t_1\right) \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ 1.0 (hypot y.re y.im)))
        (t_1 (* x.re (/ y.im (hypot y.re y.im)))))
   (+
    (fma (* y.re (/ x.im (hypot y.re y.im))) t_0 (/ t_1 (- (hypot y.re y.im))))
    (fma (/ -1.0 (hypot y.re y.im)) t_1 (* t_0 t_1)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_im * y_46_re) - (x_46_re * 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 = 1.0 / hypot(y_46_re, y_46_im);
	double t_1 = x_46_re * (y_46_im / hypot(y_46_re, y_46_im));
	return fma((y_46_re * (x_46_im / hypot(y_46_re, y_46_im))), t_0, (t_1 / -hypot(y_46_re, y_46_im))) + fma((-1.0 / hypot(y_46_re, y_46_im)), t_1, (t_0 * t_1));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_im * y_46_re) - Float64(x_46_re * 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(1.0 / hypot(y_46_re, y_46_im))
	t_1 = Float64(x_46_re * Float64(y_46_im / hypot(y_46_re, y_46_im)))
	return Float64(fma(Float64(y_46_re * Float64(x_46_im / hypot(y_46_re, y_46_im))), t_0, Float64(t_1 / Float64(-hypot(y_46_re, y_46_im)))) + fma(Float64(-1.0 / hypot(y_46_re, y_46_im)), t_1, Float64(t_0 * t_1)))
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(x$46$re * 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[(1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x$46$re * N[(y$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(y$46$re * N[(x$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0 + N[(t$95$1 / (-N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1 + N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}\\
t_1 := x.re \cdot \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\
\mathsf{fma}\left(y.re \cdot \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, t_0, \frac{t_1}{-\mathsf{hypot}\left(y.re, y.im\right)}\right) + \mathsf{fma}\left(\frac{-1}{\mathsf{hypot}\left(y.re, y.im\right)}, t_1, t_0 \cdot t_1\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. Initial program 26.3

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

    \[\leadsto \color{blue}{\frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}} \]
  3. Applied egg-rr15.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, -\frac{x.re \cdot y.im}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\right)} \]
  4. Applied egg-rr1.6

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

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

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

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

Reproduce

herbie shell --seed 2022133 
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))