Average Error: 25.6 → 10.8
Time: 7.3s
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 \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{if}\;t_0 \leq 1.8860901164613604 \cdot 10^{+292}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.im, y.re\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;t_0 \leq \infty:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x.re}{y.im}\\ \end{array} \]
\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 \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\
\mathbf{if}\;t_0 \leq 1.8860901164613604 \cdot 10^{+292}:\\
\;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.im, y.re\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;\frac{x.im}{y.re}\\

\mathbf{else}:\\
\;\;\;\;\frac{-x.re}{y.im}\\


\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 y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im)))))
   (if (<= t_0 1.8860901164613604e+292)
     (/
      (-
       (/ (* x.im y.re) (hypot y.im y.re))
       (/ (* x.re y.im) (hypot y.im y.re)))
      (hypot y.im y.re))
     (if (<= t_0 INFINITY) (/ x.im y.re) (/ (- x.re) y.im)))))
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 * y_46_re) - (x_46_re * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double tmp;
	if (t_0 <= 1.8860901164613604e+292) {
		tmp = (((x_46_im * y_46_re) / hypot(y_46_im, y_46_re)) - ((x_46_re * y_46_im) / hypot(y_46_im, y_46_re))) / hypot(y_46_im, y_46_re);
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = x_46_im / y_46_re;
	} else {
		tmp = -x_46_re / y_46_im;
	}
	return tmp;
}

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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))) < 1.88609011646136039e292

    1. Initial program 13.9

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

      \[\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 add-sqr-sqrt_binary6413.9

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)} \cdot \sqrt{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}}} \]
    4. Applied *-un-lft-identity_binary6413.9

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

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    8. Applied associate-*r/_binary642.8

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

      \[\leadsto \frac{\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\left(y.re \cdot x.im + \left(-x.re \cdot y.im\right)\right)}}{\mathsf{hypot}\left(y.im, y.re\right)} \]
    10. Applied distribute-rgt-in_binary642.8

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

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

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

    if 1.88609011646136039e292 < (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im))) < +inf.0

    1. Initial program 58.5

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

      \[\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. Taylor expanded in y.re around inf 37.8

      \[\leadsto \color{blue}{\frac{x.im}{y.re}} \]

    if +inf.0 < (/.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 64.0

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

      \[\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. Taylor expanded in y.re around 0 36.3

      \[\leadsto \color{blue}{-1 \cdot \frac{x.re}{y.im}} \]
    4. Simplified36.3

      \[\leadsto \color{blue}{-\frac{x.re}{y.im}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.8

    \[\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 1.8860901164613604 \cdot 10^{+292}:\\ \;\;\;\;\frac{\frac{x.im \cdot y.re}{\mathsf{hypot}\left(y.im, y.re\right)} - \frac{x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\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 \infty:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x.re}{y.im}\\ \end{array} \]

Reproduce

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