Average Error: 26.2 → 12.8
Time: 9.9s
Precision: 64
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -7.8635706565981409 \cdot 10^{93}:\\ \;\;\;\;\frac{-1 \cdot x.re}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\\ \mathbf{elif}\;y.re \le 3.99749813133416796 \cdot 10^{155}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\sqrt{1}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\\ \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}
\mathbf{if}\;y.re \le -7.8635706565981409 \cdot 10^{93}:\\
\;\;\;\;\frac{-1 \cdot x.re}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\\

\mathbf{elif}\;y.re \le 3.99749813133416796 \cdot 10^{155}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\sqrt{1}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x.re}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\\

\end{array}
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 temp;
	if ((y_46_re <= -7.863570656598141e+93)) {
		temp = ((-1.0 * x_46_re) / ((hypot(y_46_re, y_46_im) / 1.0) / sqrt(1.0)));
	} else {
		double temp_1;
		if ((y_46_re <= 3.997498131334168e+155)) {
			temp_1 = ((fma(x_46_re, y_46_re, (x_46_im * y_46_im)) / hypot(y_46_re, y_46_im)) * (1.0 / (hypot(y_46_re, y_46_im) / sqrt(1.0))));
		} else {
			temp_1 = (x_46_re / ((hypot(y_46_re, y_46_im) / 1.0) / sqrt(1.0)));
		}
		temp = temp_1;
	}
	return temp;
}

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 3 regimes
  2. if y.re < -7.863570656598141e+93

    1. Initial program 39.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt39.6

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied *-un-lft-identity39.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac39.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified39.6

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

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

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

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

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

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

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

    if -7.863570656598141e+93 < y.re < 3.997498131334168e+155

    1. Initial program 18.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt18.9

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied *-un-lft-identity18.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac18.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified18.9

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\]
    13. Using strategy rm
    14. Applied div-inv11.8

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

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

    if 3.997498131334168e+155 < y.re

    1. Initial program 45.6

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt45.6

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied *-un-lft-identity45.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac45.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Simplified45.6

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

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}} \cdot \color{blue}{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right) \cdot 1}}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt30.0

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -7.8635706565981409 \cdot 10^{93}:\\ \;\;\;\;\frac{-1 \cdot x.re}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\\ \mathbf{elif}\;y.re \le 3.99749813133416796 \cdot 10^{155}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\sqrt{1}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\frac{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}{\sqrt{1}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(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))))