Average Error: 26.5 → 1.7
Time: 9.0s
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{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ t_1 := \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}, t_1 \cdot \frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right) + \mathsf{fma}\left(\frac{-y.im}{\mathsf{hypot}\left(y.re, y.im\right)}, t_0, t_1 \cdot t_0\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 (/ x.re (hypot y.re y.im))) (t_1 (/ y.im (hypot y.re y.im))))
   (+
    (fma
     (/ y.re (hypot y.re y.im))
     (/ x.im (hypot y.im y.re))
     (* t_1 (/ (- x.re) (hypot y.re y.im))))
    (fma (/ (- y.im) (hypot y.re y.im)) t_0 (* t_1 t_0)))))
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 = x_46_re / hypot(y_46_re, y_46_im);
	double t_1 = y_46_im / hypot(y_46_re, y_46_im);
	return fma((y_46_re / hypot(y_46_re, y_46_im)), (x_46_im / hypot(y_46_im, y_46_re)), (t_1 * (-x_46_re / hypot(y_46_re, y_46_im)))) + fma((-y_46_im / hypot(y_46_re, y_46_im)), t_0, (t_1 * t_0));
}
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(x_46_re / hypot(y_46_re, y_46_im))
	t_1 = Float64(y_46_im / hypot(y_46_re, y_46_im))
	return Float64(fma(Float64(y_46_re / hypot(y_46_re, y_46_im)), Float64(x_46_im / hypot(y_46_im, y_46_re)), Float64(t_1 * Float64(Float64(-x_46_re) / hypot(y_46_re, y_46_im)))) + fma(Float64(Float64(-y_46_im) / hypot(y_46_re, y_46_im)), t_0, Float64(t_1 * t_0)))
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[(x$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x$46$im / N[Sqrt[y$46$im ^ 2 + y$46$re ^ 2], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[((-x$46$re) / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[((-y$46$im) / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$0 + N[(t$95$1 * t$95$0), $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{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\
t_1 := \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\
\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.im, y.re\right)}, t_1 \cdot \frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right) + \mathsf{fma}\left(\frac{-y.im}{\mathsf{hypot}\left(y.re, y.im\right)}, t_0, t_1 \cdot t_0\right)
\end{array}

Error

Derivation

  1. Initial program 26.5

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

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y.im, -x.re, x.im \cdot y.re\right)}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}} \]
  3. Taylor expanded in x.re around 0 26.5

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

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

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

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

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

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

Reproduce

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