Average Error: 26.0 → 14.1
Time: 7.9s
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{\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 -5.124136587792355 \cdot 10^{+226}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{y.im}, \frac{x.im}{y.im}, \frac{x.re \cdot \left(y.re \cdot y.re\right)}{{y.im}^{3}}\right) - \frac{x.re}{y.im}\\ \mathbf{elif}\;y.im \leq -1.9738142544677371 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.im \leq -9.658402922807776 \cdot 10^{-195}:\\ \;\;\;\;\frac{x.im}{y.re} - \frac{y.im \cdot x.re}{y.re \cdot y.re}\\ \mathbf{elif}\;y.im \leq 3.0970906241597073 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.im}{y.im} - x.re}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \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{\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 -5.124136587792355 \cdot 10^{+226}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y.re}{y.im}, \frac{x.im}{y.im}, \frac{x.re \cdot \left(y.re \cdot y.re\right)}{{y.im}^{3}}\right) - \frac{x.re}{y.im}\\

\mathbf{elif}\;y.im \leq -1.9738142544677371 \cdot 10^{-143}:\\
\;\;\;\;t_0\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{y.re \cdot x.im}{y.im} - x.re}{\mathsf{hypot}\left(y.im, y.re\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
         (/
          (/ (- (* y.re x.im) (* y.im x.re)) (hypot y.im y.re))
          (hypot y.im y.re))))
   (if (<= y.im -5.124136587792355e+226)
     (-
      (fma
       (/ y.re y.im)
       (/ x.im y.im)
       (/ (* x.re (* y.re y.re)) (pow y.im 3.0)))
      (/ x.re y.im))
     (if (<= y.im -1.9738142544677371e-143)
       t_0
       (if (<= y.im -9.658402922807776e-195)
         (- (/ x.im y.re) (/ (* y.im x.re) (* y.re y.re)))
         (if (<= y.im 3.0970906241597073e+36)
           t_0
           (/ (- (/ (* y.re x.im) y.im) 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 * x_46_re)) / hypot(y_46_im, y_46_re)) / hypot(y_46_im, y_46_re);
	double tmp;
	if (y_46_im <= -5.124136587792355e+226) {
		tmp = fma((y_46_re / y_46_im), (x_46_im / y_46_im), ((x_46_re * (y_46_re * y_46_re)) / pow(y_46_im, 3.0))) - (x_46_re / y_46_im);
	} else if (y_46_im <= -1.9738142544677371e-143) {
		tmp = t_0;
	} else if (y_46_im <= -9.658402922807776e-195) {
		tmp = (x_46_im / y_46_re) - ((y_46_im * x_46_re) / (y_46_re * y_46_re));
	} else if (y_46_im <= 3.0970906241597073e+36) {
		tmp = t_0;
	} else {
		tmp = (((y_46_re * x_46_im) / y_46_im) - x_46_re) / hypot(y_46_im, y_46_re);
	}
	return tmp;
}

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 4 regimes
  2. if y.im < -5.1241365877923551e226

    1. Initial program 41.8

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

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

      \[\leadsto \color{blue}{\left(\frac{y.re \cdot x.im}{{y.im}^{2}} + \frac{x.re \cdot {y.re}^{2}}{{y.im}^{3}}\right) - \frac{x.re}{y.im}} \]
    4. Simplified20.7

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

    if -5.1241365877923551e226 < y.im < -1.9738142544677371e-143 or -9.6584029228077763e-195 < y.im < 3.09709062415970734e36

    1. Initial program 21.3

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified21.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_binary6421.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_binary6421.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_binary6421.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. Simplified21.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. Simplified12.9

      \[\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/_binary6412.8

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

      \[\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 prod-diff_binary6412.8

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

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

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

    if -1.9738142544677371e-143 < y.im < -9.6584029228077763e-195

    1. Initial program 23.2

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

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

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

      \[\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_binary6423.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. Simplified23.2

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

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

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

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

    if 3.09709062415970734e36 < y.im

    1. Initial program 35.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified35.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_binary6435.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_binary6435.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_binary6435.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. Simplified35.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. Simplified24.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/_binary6424.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. Simplified24.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 16.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -5.124136587792355 \cdot 10^{+226}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{y.im}, \frac{x.im}{y.im}, \frac{x.re \cdot \left(y.re \cdot y.re\right)}{{y.im}^{3}}\right) - \frac{x.re}{y.im}\\ \mathbf{elif}\;y.im \leq -1.9738142544677371 \cdot 10^{-143}:\\ \;\;\;\;\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 -9.658402922807776 \cdot 10^{-195}:\\ \;\;\;\;\frac{x.im}{y.re} - \frac{y.im \cdot x.re}{y.re \cdot y.re}\\ \mathbf{elif}\;y.im \leq 3.0970906241597073 \cdot 10^{+36}:\\ \;\;\;\;\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 2022125 
(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))))