Average Error: 26.5 → 12.3
Time: 5.1s
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 := {\left(\mathsf{hypot}\left(y.im, y.re\right)\right)}^{2}\\ t_1 := \mathsf{fma}\left(\frac{y.im}{y.re}, \frac{-x.re}{y.re}, \frac{x.im}{y.re}\right)\\ \mathbf{if}\;y.re \leq -5.174874392946877 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.re \leq -1.6974732352827345 \cdot 10^{+24}:\\ \;\;\;\;\mathsf{fma}\left(y.re, \frac{x.im}{y.im \cdot y.im}, \frac{-x.re}{y.im}\right)\\ \mathbf{elif}\;y.re \leq -1.7029803518844395 \cdot 10^{-105}:\\ \;\;\;\;\left(y.im \cdot x.re - y.re \cdot x.im\right) \cdot \frac{1}{-t_0}\\ \mathbf{elif}\;y.re \leq 1.700724934216277 \cdot 10^{-110}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{x.re}{y.im}, \frac{\frac{y.re \cdot x.im}{y.im}}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 1.8454883815855177 \cdot 10^{+63}:\\ \;\;\;\;\frac{y.re \cdot x.im - y.im \cdot x.re}{t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (pow (hypot y.im y.re) 2.0))
        (t_1 (fma (/ y.im y.re) (/ (- x.re) y.re) (/ x.im y.re))))
   (if (<= y.re -5.174874392946877e+44)
     t_1
     (if (<= y.re -1.6974732352827345e+24)
       (fma y.re (/ x.im (* y.im y.im)) (/ (- x.re) y.im))
       (if (<= y.re -1.7029803518844395e-105)
         (* (- (* y.im x.re) (* y.re x.im)) (/ 1.0 (- t_0)))
         (if (<= y.re 1.700724934216277e-110)
           (fma -1.0 (/ x.re y.im) (/ (/ (* y.re x.im) y.im) y.im))
           (if (<= y.re 1.8454883815855177e+63)
             (/ (- (* y.re x.im) (* y.im x.re)) 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 = pow(hypot(y_46_im, y_46_re), 2.0);
	double t_1 = fma((y_46_im / y_46_re), (-x_46_re / y_46_re), (x_46_im / y_46_re));
	double tmp;
	if (y_46_re <= -5.174874392946877e+44) {
		tmp = t_1;
	} else if (y_46_re <= -1.6974732352827345e+24) {
		tmp = fma(y_46_re, (x_46_im / (y_46_im * y_46_im)), (-x_46_re / y_46_im));
	} else if (y_46_re <= -1.7029803518844395e-105) {
		tmp = ((y_46_im * x_46_re) - (y_46_re * x_46_im)) * (1.0 / -t_0);
	} else if (y_46_re <= 1.700724934216277e-110) {
		tmp = fma(-1.0, (x_46_re / y_46_im), (((y_46_re * x_46_im) / y_46_im) / y_46_im));
	} else if (y_46_re <= 1.8454883815855177e+63) {
		tmp = ((y_46_re * x_46_im) - (y_46_im * x_46_re)) / t_0;
	} else {
		tmp = t_1;
	}
	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 = hypot(y_46_im, y_46_re) ^ 2.0
	t_1 = fma(Float64(y_46_im / y_46_re), Float64(Float64(-x_46_re) / y_46_re), Float64(x_46_im / y_46_re))
	tmp = 0.0
	if (y_46_re <= -5.174874392946877e+44)
		tmp = t_1;
	elseif (y_46_re <= -1.6974732352827345e+24)
		tmp = fma(y_46_re, Float64(x_46_im / Float64(y_46_im * y_46_im)), Float64(Float64(-x_46_re) / y_46_im));
	elseif (y_46_re <= -1.7029803518844395e-105)
		tmp = Float64(Float64(Float64(y_46_im * x_46_re) - Float64(y_46_re * x_46_im)) * Float64(1.0 / Float64(-t_0)));
	elseif (y_46_re <= 1.700724934216277e-110)
		tmp = fma(-1.0, Float64(x_46_re / y_46_im), Float64(Float64(Float64(y_46_re * x_46_im) / y_46_im) / y_46_im));
	elseif (y_46_re <= 1.8454883815855177e+63)
		tmp = Float64(Float64(Float64(y_46_re * x_46_im) - Float64(y_46_im * x_46_re)) / t_0);
	else
		tmp = t_1;
	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[Power[N[Sqrt[y$46$im ^ 2 + y$46$re ^ 2], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(y$46$im / y$46$re), $MachinePrecision] * N[((-x$46$re) / y$46$re), $MachinePrecision] + N[(x$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -5.174874392946877e+44], t$95$1, If[LessEqual[y$46$re, -1.6974732352827345e+24], N[(y$46$re * N[(x$46$im / N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] + N[((-x$46$re) / y$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, -1.7029803518844395e-105], N[(N[(N[(y$46$im * x$46$re), $MachinePrecision] - N[(y$46$re * x$46$im), $MachinePrecision]), $MachinePrecision] * N[(1.0 / (-t$95$0)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.700724934216277e-110], N[(-1.0 * N[(x$46$re / y$46$im), $MachinePrecision] + N[(N[(N[(y$46$re * x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.8454883815855177e+63], N[(N[(N[(y$46$re * x$46$im), $MachinePrecision] - N[(y$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], t$95$1]]]]]]]
\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 := {\left(\mathsf{hypot}\left(y.im, y.re\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\frac{y.im}{y.re}, \frac{-x.re}{y.re}, \frac{x.im}{y.re}\right)\\
\mathbf{if}\;y.re \leq -5.174874392946877 \cdot 10^{+44}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y.re \leq -1.6974732352827345 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(y.re, \frac{x.im}{y.im \cdot y.im}, \frac{-x.re}{y.im}\right)\\

\mathbf{elif}\;y.re \leq -1.7029803518844395 \cdot 10^{-105}:\\
\;\;\;\;\left(y.im \cdot x.re - y.re \cdot x.im\right) \cdot \frac{1}{-t_0}\\

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

\mathbf{elif}\;y.re \leq 1.8454883815855177 \cdot 10^{+63}:\\
\;\;\;\;\frac{y.re \cdot x.im - y.im \cdot x.re}{t_0}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\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 5 regimes
  2. if y.re < -5.1748743929468772e44 or 1.8454883815855177e63 < y.re

    1. Initial program 36.6

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified36.6

      \[\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 y.im around 0 17.7

      \[\leadsto \color{blue}{\frac{x.im}{y.re} - \frac{x.re \cdot y.im}{{y.re}^{2}}} \]
    4. Simplified12.5

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

    if -5.1748743929468772e44 < y.re < -1.69747323528273453e24

    1. Initial program 18.6

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified18.6

      \[\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 y.im around inf 37.2

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

      \[\leadsto \color{blue}{x.im \cdot \frac{\frac{y.re}{y.im}}{y.im} - \frac{x.re}{y.im}} \]
    5. Applied egg-rr33.4

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

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

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

    if -1.69747323528273453e24 < y.re < -1.70298035188443947e-105

    1. Initial program 14.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified14.1

      \[\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. Applied egg-rr14.1

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

    if -1.70298035188443947e-105 < y.re < 1.70072493421627706e-110

    1. Initial program 22.2

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

      \[\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 y.im around inf 11.4

      \[\leadsto \color{blue}{\frac{y.re \cdot x.im}{{y.im}^{2}} - \frac{x.re}{y.im}} \]
    4. Simplified9.3

      \[\leadsto \color{blue}{x.im \cdot \frac{\frac{y.re}{y.im}}{y.im} - \frac{x.re}{y.im}} \]
    5. Applied egg-rr8.1

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

    if 1.70072493421627706e-110 < y.re < 1.8454883815855177e63

    1. Initial program 15.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -5.174874392946877 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{-x.re}{y.re}, \frac{x.im}{y.re}\right)\\ \mathbf{elif}\;y.re \leq -1.6974732352827345 \cdot 10^{+24}:\\ \;\;\;\;\mathsf{fma}\left(y.re, \frac{x.im}{y.im \cdot y.im}, \frac{-x.re}{y.im}\right)\\ \mathbf{elif}\;y.re \leq -1.7029803518844395 \cdot 10^{-105}:\\ \;\;\;\;\left(y.im \cdot x.re - y.re \cdot x.im\right) \cdot \frac{1}{-{\left(\mathsf{hypot}\left(y.im, y.re\right)\right)}^{2}}\\ \mathbf{elif}\;y.re \leq 1.700724934216277 \cdot 10^{-110}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{x.re}{y.im}, \frac{\frac{y.re \cdot x.im}{y.im}}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 1.8454883815855177 \cdot 10^{+63}:\\ \;\;\;\;\frac{y.re \cdot x.im - y.im \cdot x.re}{{\left(\mathsf{hypot}\left(y.im, y.re\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{-x.re}{y.re}, \frac{x.im}{y.re}\right)\\ \end{array} \]

Reproduce

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