Average Error: 26.6 → 13.3
Time: 12.1s
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 -1.999293010764536 \cdot 10^{152}:\\ \;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{elif}\;y.re \le 1.23638593134364678 \cdot 10^{107}:\\ \;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{\frac{\mathsf{fma}\left(x.re, y.re, x.im \cdot y.im\right)}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{x.re}{\mathsf{hypot}\left(y.re, y.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}
\mathbf{if}\;y.re \le -1.999293010764536 \cdot 10^{152}:\\
\;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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

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

\end{array}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((double) (((double) (((double) (x_46_re * y_46_re)) + ((double) (x_46_im * y_46_im)))) / ((double) (((double) (y_46_re * y_46_re)) + ((double) (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 VAR;
	if ((y_46_re <= -1.999293010764536e+152)) {
		VAR = ((double) (((double) (((double) sqrt(1.0)) / 1.0)) * ((double) (((double) (-1.0 * x_46_re)) / ((double) hypot(y_46_re, y_46_im))))));
	} else {
		double VAR_1;
		if ((y_46_re <= 1.2363859313436468e+107)) {
			VAR_1 = ((double) (((double) (((double) sqrt(1.0)) / 1.0)) * ((double) (((double) (((double) fma(x_46_re, y_46_re, ((double) (x_46_im * y_46_im)))) / ((double) hypot(y_46_re, y_46_im)))) / ((double) hypot(y_46_re, y_46_im))))));
		} else {
			VAR_1 = ((double) (((double) (((double) sqrt(1.0)) / 1.0)) * ((double) (x_46_re / ((double) hypot(y_46_re, y_46_im))))));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -1.999293010764536e+152

    1. Initial program 45.7

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

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

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

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

      \[\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. Simplified29.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 *-un-lft-identity29.0

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\color{blue}{1 \cdot 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 *-un-lft-identity29.0

      \[\leadsto \frac{1}{\frac{\color{blue}{1 \cdot \mathsf{hypot}\left(y.re, y.im\right)}}{1 \cdot 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 times-frac29.0

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{1} \cdot \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}\]
    12. Applied add-sqr-sqrt29.0

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\frac{1}{1} \cdot \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}\]
    13. Applied times-frac29.0

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{\frac{1}{1}} \cdot \frac{\sqrt{1}}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}\right)} \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}\]
    14. Applied associate-*l*29.0

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\frac{1}{1}} \cdot \left(\frac{\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}\right)}\]
    15. Simplified28.9

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

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

    if -1.999293010764536e+152 < y.re < 1.2363859313436468e+107

    1. Initial program 19.5

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

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

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

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

      \[\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. Simplified12.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 *-un-lft-identity12.8

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\color{blue}{1 \cdot 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 *-un-lft-identity12.8

      \[\leadsto \frac{1}{\frac{\color{blue}{1 \cdot \mathsf{hypot}\left(y.re, y.im\right)}}{1 \cdot 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 times-frac12.8

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{1} \cdot \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}\]
    12. Applied add-sqr-sqrt12.8

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\frac{1}{1} \cdot \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}\]
    13. Applied times-frac12.8

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{\frac{1}{1}} \cdot \frac{\sqrt{1}}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}\right)} \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}\]
    14. Applied associate-*l*12.8

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\frac{1}{1}} \cdot \left(\frac{\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}\right)}\]
    15. Simplified12.6

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

    if 1.2363859313436468e+107 < y.re

    1. Initial program 40.0

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

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

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

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

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

      \[\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 *-un-lft-identity26.9

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{\color{blue}{1 \cdot 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 *-un-lft-identity26.9

      \[\leadsto \frac{1}{\frac{\color{blue}{1 \cdot \mathsf{hypot}\left(y.re, y.im\right)}}{1 \cdot 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 times-frac26.9

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{1} \cdot \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}\]
    12. Applied add-sqr-sqrt26.9

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\frac{1}{1} \cdot \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}\]
    13. Applied times-frac26.9

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{\frac{1}{1}} \cdot \frac{\sqrt{1}}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{1}}\right)} \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}\]
    14. Applied associate-*l*26.9

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\frac{1}{1}} \cdot \left(\frac{\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}\right)}\]
    15. Simplified26.8

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

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

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

Reproduce

herbie shell --seed 2020114 +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))))