Average Error: 26.7 → 12.7
Time: 7.4s
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.re \leq -2.169176490284663 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{x.re \cdot y.im}{y.re} - x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \frac{\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)}\\ \mathbf{if}\;y.re \leq -7.250896876502094 \cdot 10^{-122}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq 1.7078829799238133 \cdot 10^{-212}:\\ \;\;\;\;\frac{y.re \cdot x.im}{y.im \cdot y.im} - \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 5.693440792837767 \cdot 10^{+122}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \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.re \leq -2.169176490284663 \cdot 10^{+36}:\\
\;\;\;\;\frac{\frac{x.re \cdot y.im}{y.re} - x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{\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)}\\
\mathbf{if}\;y.re \leq -7.250896876502094 \cdot 10^{-122}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;y.re \leq 5.693440792837767 \cdot 10^{+122}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.re}\\


\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.re -2.169176490284663e+36)
   (/ (- (/ (* x.re y.im) y.re) x.im) (hypot y.im y.re))
   (let* ((t_0
           (/
            (/ (- (* y.re x.im) (* x.re y.im)) (hypot y.im y.re))
            (hypot y.im y.re))))
     (if (<= y.re -7.250896876502094e-122)
       t_0
       (if (<= y.re 1.7078829799238133e-212)
         (- (/ (* y.re x.im) (* y.im y.im)) (/ x.re y.im))
         (if (<= y.re 5.693440792837767e+122) t_0 (/ x.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_re <= -2.169176490284663e+36) {
		tmp = (((x_46_re * y_46_im) / y_46_re) - x_46_im) / hypot(y_46_im, y_46_re);
	} else {
		double t_0 = (((y_46_re * x_46_im) - (x_46_re * y_46_im)) / hypot(y_46_im, y_46_re)) / hypot(y_46_im, y_46_re);
		double tmp_1;
		if (y_46_re <= -7.250896876502094e-122) {
			tmp_1 = t_0;
		} else if (y_46_re <= 1.7078829799238133e-212) {
			tmp_1 = ((y_46_re * x_46_im) / (y_46_im * y_46_im)) - (x_46_re / y_46_im);
		} else if (y_46_re <= 5.693440792837767e+122) {
			tmp_1 = t_0;
		} else {
			tmp_1 = x_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.re < -2.16917649028466296e36

    1. Initial program 34.5

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

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

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

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

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

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

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

      \[\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 -inf 16.1

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

    if -2.16917649028466296e36 < y.re < -7.2508968765020942e-122 or 1.70788297992381333e-212 < y.re < 5.69344079283776723e122

    1. Initial program 17.9

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

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

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

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

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

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

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

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

      \[\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 -7.2508968765020942e-122 < y.re < 1.70788297992381333e-212

    1. Initial program 22.8

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified22.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 9.2

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

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

    if 5.69344079283776723e122 < y.re

    1. Initial program 42.1

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Simplified42.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 15.0

      \[\leadsto \color{blue}{\frac{x.im}{y.re}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -2.169176490284663 \cdot 10^{+36}:\\ \;\;\;\;\frac{\frac{x.re \cdot y.im}{y.re} - x.im}{\mathsf{hypot}\left(y.im, y.re\right)}\\ \mathbf{elif}\;y.re \leq -7.250896876502094 \cdot 10^{-122}:\\ \;\;\;\;\frac{\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)}\\ \mathbf{elif}\;y.re \leq 1.7078829799238133 \cdot 10^{-212}:\\ \;\;\;\;\frac{y.re \cdot x.im}{y.im \cdot y.im} - \frac{x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 5.693440792837767 \cdot 10^{+122}:\\ \;\;\;\;\frac{\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.re}\\ \end{array} \]

Reproduce

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