Average Error: 26.1 → 1.1
Time: 8.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.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ t_1 := x.im \cdot y.re - x.re \cdot y.im\\ t_2 := \frac{t_1}{y.re \cdot y.re + y.im \cdot y.im}\\ t_3 := \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{+290}:\\ \;\;\;\;\mathsf{fma}\left(t_0, {\left(\sqrt[3]{\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}^{3}, t_3\right)\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+275}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{t_1}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, {\left(\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re}\right)}^{-1}, t_3\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.im (hypot y.re y.im)))
        (t_1 (- (* x.im y.re) (* x.re y.im)))
        (t_2 (/ t_1 (+ (* y.re y.re) (* y.im y.im))))
        (t_3 (* (/ y.im (hypot y.re y.im)) (/ (- x.re) (hypot y.re y.im)))))
   (if (<= t_2 -5e+290)
     (fma t_0 (pow (cbrt (/ y.re (hypot y.re y.im))) 3.0) t_3)
     (if (<= t_2 5e+275)
       (* (/ 1.0 (hypot y.re y.im)) (/ t_1 (hypot y.re y.im)))
       (fma t_0 (pow (/ (hypot y.re y.im) y.re) -1.0) t_3)))))
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_im / hypot(y_46_re, y_46_im);
	double t_1 = (x_46_im * y_46_re) - (x_46_re * y_46_im);
	double t_2 = t_1 / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double t_3 = (y_46_im / hypot(y_46_re, y_46_im)) * (-x_46_re / hypot(y_46_re, y_46_im));
	double tmp;
	if (t_2 <= -5e+290) {
		tmp = fma(t_0, pow(cbrt((y_46_re / hypot(y_46_re, y_46_im))), 3.0), t_3);
	} else if (t_2 <= 5e+275) {
		tmp = (1.0 / hypot(y_46_re, y_46_im)) * (t_1 / hypot(y_46_re, y_46_im));
	} else {
		tmp = fma(t_0, pow((hypot(y_46_re, y_46_im) / y_46_re), -1.0), t_3);
	}
	return tmp;
}
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_im / hypot(y_46_re, y_46_im))
	t_1 = Float64(Float64(x_46_im * y_46_re) - Float64(x_46_re * y_46_im))
	t_2 = Float64(t_1 / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
	t_3 = Float64(Float64(y_46_im / hypot(y_46_re, y_46_im)) * Float64(Float64(-x_46_re) / hypot(y_46_re, y_46_im)))
	tmp = 0.0
	if (t_2 <= -5e+290)
		tmp = fma(t_0, (cbrt(Float64(y_46_re / hypot(y_46_re, y_46_im))) ^ 3.0), t_3);
	elseif (t_2 <= 5e+275)
		tmp = Float64(Float64(1.0 / hypot(y_46_re, y_46_im)) * Float64(t_1 / hypot(y_46_re, y_46_im)));
	else
		tmp = fma(t_0, (Float64(hypot(y_46_re, y_46_im) / y_46_re) ^ -1.0), t_3);
	end
	return tmp
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$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(x$46$re * y$46$im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[((-x$46$re) / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+290], N[(t$95$0 * N[Power[N[Power[N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision] + t$95$3), $MachinePrecision], If[LessEqual[t$95$2, 5e+275], N[(N[(1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$1 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[N[(N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision] / y$46$re), $MachinePrecision], -1.0], $MachinePrecision] + t$95$3), $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.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\
t_1 := x.im \cdot y.re - x.re \cdot y.im\\
t_2 := \frac{t_1}{y.re \cdot y.re + y.im \cdot y.im}\\
t_3 := \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+290}:\\
\;\;\;\;\mathsf{fma}\left(t_0, {\left(\sqrt[3]{\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}^{3}, t_3\right)\\

\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+275}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{t_1}{\mathsf{hypot}\left(y.re, y.im\right)}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, {\left(\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re}\right)}^{-1}, t_3\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 3 regimes
  2. if (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im))) < -4.9999999999999998e290

    1. Initial program 58.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied egg-rr39.4

      \[\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)} \]
    3. Applied egg-rr3.8

      \[\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) \]
    4. Applied egg-rr3.9

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

    if -4.9999999999999998e290 < (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im))) < 5.0000000000000003e275

    1. Initial program 12.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied egg-rr0.9

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

    if 5.0000000000000003e275 < (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im)))

    1. Initial program 61.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Applied egg-rr35.8

      \[\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)} \]
    3. Applied egg-rr1.2

      \[\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) \]
    4. Applied egg-rr1.2

      \[\leadsto \mathsf{fma}\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \color{blue}{{\left(\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re}\right)}^{-1}}, -\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq -5 \cdot 10^{+290}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, {\left(\sqrt[3]{\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}}\right)}^{3}, \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right)\\ \mathbf{elif}\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq 5 \cdot 10^{+275}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, {\left(\frac{\mathsf{hypot}\left(y.re, y.im\right)}{y.re}\right)}^{-1}, \frac{y.im}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{-x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right)\\ \end{array} \]

Reproduce

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