Average Error: 26.4 → 10.8
Time: 7.3s
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(y.im, y.im, y.re \cdot y.re\right)\\ \mathbf{if}\;y.im \leq -7.798094340522651 \cdot 10^{+148}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.im \leq -1.1787479681689879 \cdot 10^{-125}:\\ \;\;\;\;\mathsf{fma}\left(x.im, \frac{y.im}{t_0}, \frac{x.re \cdot y.re}{t_0}\right)\\ \mathbf{elif}\;y.im \leq 3.893486015778443 \cdot 10^{-66}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{elif}\;y.im \leq 3.6928906212212155 \cdot 10^{+115}:\\ \;\;\;\;\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}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)\\ \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(y.im, y.im, y.re \cdot y.re\right)\\
\mathbf{if}\;y.im \leq -7.798094340522651 \cdot 10^{+148}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\

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

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

\mathbf{elif}\;y.im \leq 3.6928906212212155 \cdot 10^{+115}:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)\\


\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.im (* y.re y.re))))
   (if (<= y.im -7.798094340522651e+148)
     (fma (/ x.re y.im) (/ y.re y.im) (/ x.im y.im))
     (if (<= y.im -1.1787479681689879e-125)
       (fma x.im (/ y.im t_0) (/ (* x.re y.re) t_0))
       (if (<= y.im 3.893486015778443e-66)
         (fma (/ y.im y.re) (/ x.im y.re) (/ x.re y.re))
         (if (<= y.im 3.6928906212212155e+115)
           (/
            (/ (fma x.re y.re (* y.im x.im)) (hypot y.im y.re))
            (hypot y.im y.re))
           (* (/ 1.0 (hypot y.im y.re)) (fma (/ x.re y.im) y.re x.im))))))))
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_im, (y_46_re * y_46_re));
	double tmp;
	if (y_46_im <= -7.798094340522651e+148) {
		tmp = fma((x_46_re / y_46_im), (y_46_re / y_46_im), (x_46_im / y_46_im));
	} else if (y_46_im <= -1.1787479681689879e-125) {
		tmp = fma(x_46_im, (y_46_im / t_0), ((x_46_re * y_46_re) / t_0));
	} else if (y_46_im <= 3.893486015778443e-66) {
		tmp = fma((y_46_im / y_46_re), (x_46_im / y_46_re), (x_46_re / y_46_re));
	} else if (y_46_im <= 3.6928906212212155e+115) {
		tmp = (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);
	} else {
		tmp = (1.0 / hypot(y_46_im, y_46_re)) * fma((x_46_re / y_46_im), y_46_re, x_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

Derivation

  1. Split input into 5 regimes
  2. if y.im < -7.7980943405226511e148

    1. Initial program 44.5

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

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

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

    if -7.7980943405226511e148 < y.im < -1.17874796816898788e-125

    1. Initial program 17.3

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified17.3

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

      \[\leadsto \color{blue}{\frac{y.im \cdot x.im}{{y.im}^{2} + {y.re}^{2}} + \frac{x.re \cdot y.re}{{y.im}^{2} + {y.re}^{2}}} \]
    4. Simplified14.5

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

    if -1.17874796816898788e-125 < y.im < 3.89348601577844325e-66

    1. Initial program 22.1

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

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

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

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

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

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

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

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

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

    if 3.89348601577844325e-66 < y.im < 3.6928906212212155e115

    1. Initial program 16.9

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \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)} \cdot 1}{\mathsf{hypot}\left(y.im, y.re\right)}} \]

    if 3.6928906212212155e115 < y.im

    1. Initial program 41.5

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -7.798094340522651 \cdot 10^{+148}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \mathbf{elif}\;y.im \leq -1.1787479681689879 \cdot 10^{-125}:\\ \;\;\;\;\mathsf{fma}\left(x.im, \frac{y.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}, \frac{x.re \cdot y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\right)\\ \mathbf{elif}\;y.im \leq 3.893486015778443 \cdot 10^{-66}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.im}{y.re}, \frac{x.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{elif}\;y.im \leq 3.6928906212212155 \cdot 10^{+115}:\\ \;\;\;\;\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}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)\\ \end{array} \]

Reproduce

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