Average Error: 26.2 → 12.1
Time: 12.2s
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} \mathbf{if}\;y.im \leq -4.988426382296112 \cdot 10^{+108}:\\ \;\;\;\;\frac{x.re - \frac{y.re \cdot x.im}{y.im}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \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 -1.851745546982872 \cdot 10^{-226}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.im \leq 1.2315960820976547 \cdot 10^{-167}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{elif}\;y.im \leq 2.5261196808138677 \cdot 10^{+149}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-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}
\mathbf{if}\;y.im \leq -4.988426382296112 \cdot 10^{+108}:\\
\;\;\;\;\frac{x.re - \frac{y.re \cdot x.im}{y.im}}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \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 -1.851745546982872 \cdot 10^{-226}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;y.im \leq 2.5261196808138677 \cdot 10^{+149}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{-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
 (if (<= y.im -4.988426382296112e+108)
   (/ (- x.re (/ (* y.re x.im) y.im)) (hypot y.im y.re))
   (let* ((t_0
           (/
            (/ (- (* y.re x.im) (* y.im x.re)) (hypot y.im y.re))
            (hypot y.im y.re))))
     (if (<= y.im -1.851745546982872e-226)
       t_0
       (if (<= y.im 1.2315960820976547e-167)
         (/ x.im y.re)
         (if (<= y.im 2.5261196808138677e+149)
           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 tmp;
	if (y_46_im <= -4.988426382296112e+108) {
		tmp = (x_46_re - ((y_46_re * x_46_im) / y_46_im)) / hypot(y_46_im, y_46_re);
	} else {
		double t_0 = (((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 <= -1.851745546982872e-226) {
			tmp_1 = t_0;
		} else if (y_46_im <= 1.2315960820976547e-167) {
			tmp_1 = x_46_im / y_46_re;
		} else if (y_46_im <= 2.5261196808138677e+149) {
			tmp_1 = t_0;
		} else {
			tmp_1 = -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 < -4.98842638229611199e108

    1. Initial program 40.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified40.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. Applied add-sqr-sqrt_binary6440.0

      \[\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_binary6440.0

      \[\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_binary6440.0

      \[\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. Simplified40.0

      \[\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. Simplified26.5

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

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

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

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

    if -4.98842638229611199e108 < y.im < -1.8517455469828719e-226 or 1.2315960820976547e-167 < y.im < 2.5261196808138677e149

    1. Initial program 17.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified17.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. Applied add-sqr-sqrt_binary6417.1

      \[\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_binary6417.1

      \[\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_binary6417.1

      \[\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. Simplified17.1

      \[\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)} \]
    10. Applied sub-neg_binary6411.6

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

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

    if -1.8517455469828719e-226 < y.im < 1.2315960820976547e-167

    1. Initial program 24.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified24.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. Taylor expanded in y.re around inf 11.6

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

    if 2.5261196808138677e149 < y.im

    1. Initial program 45.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified45.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_binary6445.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_binary6445.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_binary6445.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. Simplified45.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. Simplified30.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/_binary6430.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -4.988426382296112 \cdot 10^{+108}:\\ \;\;\;\;\frac{x.re - \frac{y.re \cdot x.im}{y.im}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.im \leq -1.851745546982872 \cdot 10^{-226}:\\ \;\;\;\;\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 1.2315960820976547 \cdot 10^{-167}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{elif}\;y.im \leq 2.5261196808138677 \cdot 10^{+149}:\\ \;\;\;\;\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{-x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \end{array} \]

Reproduce

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