Average Error: 26.2 → 11.2
Time: 11.5s
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{y.re \cdot x.im}{y.im}\\ \mathbf{if}\;y.im \leq -2.4390351264177468 \cdot 10^{+135}:\\ \;\;\;\;\frac{x.re - t_0}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{if}\;y.im \leq -2.263639590356727 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.im \leq 2.3930967509278203 \cdot 10^{-143}:\\ \;\;\;\;\frac{x.im}{y.re} - \frac{y.im \cdot x.re}{y.re \cdot y.re}\\ \mathbf{elif}\;y.im \leq 1.0637981004967216 \cdot 10^{+128}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 - x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array}\\ \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{y.re \cdot x.im}{y.im}\\
\mathbf{if}\;y.im \leq -2.4390351264177468 \cdot 10^{+135}:\\
\;\;\;\;\frac{x.re - t_0}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\
\mathbf{if}\;y.im \leq -2.263639590356727 \cdot 10^{-145}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y.im \leq 2.3930967509278203 \cdot 10^{-143}:\\
\;\;\;\;\frac{x.im}{y.re} - \frac{y.im \cdot x.re}{y.re \cdot y.re}\\

\mathbf{elif}\;y.im \leq 1.0637981004967216 \cdot 10^{+128}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0 - x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\


\end{array}\\


\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 (/ (* y.re x.im) y.im)))
   (if (<= y.im -2.4390351264177468e+135)
     (/ (- x.re t_0) (hypot y.im y.re))
     (let* ((t_1
             (/
              (/ (- (* y.re x.im) (* y.im x.re)) (hypot y.im y.re))
              (hypot y.im y.re))))
       (if (<= y.im -2.263639590356727e-145)
         t_1
         (if (<= y.im 2.3930967509278203e-143)
           (- (/ x.im y.re) (/ (* y.im x.re) (* y.re y.re)))
           (if (<= y.im 1.0637981004967216e+128)
             t_1
             (/ (- t_0 x.re) (hypot y.im y.re)))))))))
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 = (y_46_re * x_46_im) / y_46_im;
	double tmp;
	if (y_46_im <= -2.4390351264177468e+135) {
		tmp = (x_46_re - t_0) / hypot(y_46_im, y_46_re);
	} else {
		double t_1 = (((y_46_re * x_46_im) - (y_46_im * x_46_re)) / hypot(y_46_im, y_46_re)) / hypot(y_46_im, y_46_re);
		double tmp_1;
		if (y_46_im <= -2.263639590356727e-145) {
			tmp_1 = t_1;
		} else if (y_46_im <= 2.3930967509278203e-143) {
			tmp_1 = (x_46_im / y_46_re) - ((y_46_im * x_46_re) / (y_46_re * y_46_re));
		} else if (y_46_im <= 1.0637981004967216e+128) {
			tmp_1 = t_1;
		} else {
			tmp_1 = (t_0 - x_46_re) / hypot(y_46_im, y_46_re);
		}
		tmp = tmp_1;
	}
	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 4 regimes
  2. if y.im < -2.43903512641774683e135

    1. Initial program 43.7

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

      \[\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_binary6443.7

      \[\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_binary6443.7

      \[\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_binary6443.7

      \[\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. Simplified43.7

      \[\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. Simplified28.7

      \[\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-*l/_binary6428.7

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

      \[\leadsto \frac{\color{blue}{\frac{y.re \cdot x.im - x.re \cdot y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}}{\mathsf{hypot}\left(y.im, y.re\right)} \]
    10. Taylor expanded in y.im around -inf 12.5

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

    if -2.43903512641774683e135 < y.im < -2.26363959035672688e-145 or 2.39309675092782035e-143 < y.im < 1.06379810049672164e128

    1. Initial program 16.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified16.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 add-sqr-sqrt_binary6416.3

      \[\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_binary6416.3

      \[\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_binary6416.3

      \[\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. Simplified16.3

      \[\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. Simplified11.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-*l/_binary6411.6

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

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

    if -2.26363959035672688e-145 < y.im < 2.39309675092782035e-143

    1. Initial program 23.1

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

      \[\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 8.8

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

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

    if 1.06379810049672164e128 < y.im

    1. Initial program 43.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified43.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 add-sqr-sqrt_binary6443.3

      \[\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_binary6443.3

      \[\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_binary6443.3

      \[\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. Simplified43.3

      \[\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. Simplified28.4

      \[\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-*l/_binary6428.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -2.4390351264177468 \cdot 10^{+135}:\\ \;\;\;\;\frac{x.re - \frac{y.re \cdot x.im}{y.im}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \leq -2.263639590356727 \cdot 10^{-145}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \leq 2.3930967509278203 \cdot 10^{-143}:\\ \;\;\;\;\frac{x.im}{y.re} - \frac{y.im \cdot x.re}{y.re \cdot y.re}\\ \mathbf{elif}\;y.im \leq 1.0637981004967216 \cdot 10^{+128}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im - y.im \cdot x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im}{y.im} - x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array} \]

Reproduce

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