Average Error: 26.5 → 10.8
Time: 8.2s
Precision: binary64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{if}\;y.re \leq -2.971421814725982 \cdot 10^{+64}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{if}\;y.re \leq -1.226730946338674 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y.re \leq 7.229271600501672 \cdot 10^{-220}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 6.084572634082679 \cdot 10^{+104}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \end{array} \]
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\
\mathbf{if}\;y.re \leq -2.971421814725982 \cdot 10^{+64}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;y.re \leq 6.084572634082679 \cdot 10^{+104}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}\\


\end{array}
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (fma (/ y.im y.re) (/ x.im y.re) (/ x.re y.re))))
   (if (<= y.re -2.971421814725982e+64)
     t_0
     (let* ((t_1
             (/
              (/ (fma x.re y.re (* y.im x.im)) (hypot y.im y.re))
              (hypot y.im y.re))))
       (if (<= y.re -1.226730946338674e-51)
         t_1
         (if (<= y.re 7.229271600501672e-220)
           (fma (/ x.re y.im) (/ y.re y.im) (/ x.im y.im))
           (if (<= y.re 6.084572634082679e+104) t_1 t_0)))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_re * y_46_re) + (x_46_im * 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 = fma((y_46_im / y_46_re), (x_46_im / y_46_re), (x_46_re / y_46_re));
	double tmp;
	if (y_46_re <= -2.971421814725982e+64) {
		tmp = t_0;
	} else {
		double t_1 = (fma(x_46_re, y_46_re, (y_46_im * x_46_im)) / hypot(y_46_im, y_46_re)) / hypot(y_46_im, y_46_re);
		double tmp_1;
		if (y_46_re <= -1.226730946338674e-51) {
			tmp_1 = t_1;
		} else if (y_46_re <= 7.229271600501672e-220) {
			tmp_1 = fma((x_46_re / y_46_im), (y_46_re / y_46_im), (x_46_im / y_46_im));
		} else if (y_46_re <= 6.084572634082679e+104) {
			tmp_1 = t_1;
		} else {
			tmp_1 = t_0;
		}
		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

Derivation

  1. Split input into 3 regimes
  2. if y.re < -2.9714218147259822e64 or 6.08457263408267934e104 < y.re

    1. Initial program 39.4

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified39.4

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

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\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_binary6439.4

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, x.im \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_binary6439.4

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

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

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

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

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

    if -2.9714218147259822e64 < y.re < -1.22673094633867398e-51 or 7.22927160050167182e-220 < y.re < 6.08457263408267934e104

    1. Initial program 16.5

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

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

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\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.5

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, x.im \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.5

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    8. Applied add-sqr-sqrt_binary6411.2

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{\color{blue}{1 \cdot \mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \sqrt{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    10. Applied times-frac_binary6411.2

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\left(\frac{1}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}}\right)} \]
    11. Applied *-un-lft-identity_binary6411.2

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)}} \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}}\right) \]
    12. Applied add-sqr-sqrt_binary6411.2

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{1 \cdot \mathsf{hypot}\left(y.im, y.re\right)} \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}}\right) \]
    13. Applied times-frac_binary6411.2

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1}}{\mathsf{hypot}\left(y.im, y.re\right)}\right)} \cdot \left(\frac{1}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}} \cdot \frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\sqrt{\mathsf{hypot}\left(y.im, y.re\right)}}\right) \]
    14. Applied associate-*l*_binary6411.2

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

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

    if -1.22673094633867398e-51 < y.re < 7.22927160050167182e-220

    1. Initial program 21.5

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

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

      \[\leadsto \frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\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.5

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(x.re, y.re, x.im \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.5

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \color{blue}{\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
    8. Taylor expanded in y.im around inf 11.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -2.971421814725982 \cdot 10^{+64}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{elif}\;y.re \leq -1.226730946338674 \cdot 10^{-51}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \leq 7.229271600501672 \cdot 10^{-220}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 6.084572634082679 \cdot 10^{+104}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(x.re, y.re, y.im \cdot x.im\right)}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022077 
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, real part"
  :precision binary64
  (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))