Average Error: 25.6 → 12.7
Time: 4.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 -1.6740965059493151 \cdot 10^{204}:\\ \;\;\;\;\frac{\frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{1}\\ \mathbf{elif}\;y.re \le 3.3012917942497675 \cdot 10^{146}:\\ \;\;\;\;\frac{\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)}}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{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 -1.6740965059493151 \cdot 10^{204}:\\
\;\;\;\;\frac{\frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{1}\\

\mathbf{elif}\;y.re \le 3.3012917942497675 \cdot 10^{146}:\\
\;\;\;\;\frac{\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)}}{1}\\

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

\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.674096505949315e+204)) {
		VAR = ((double) (((double) (((double) (-1.0 * x_46_re)) / ((double) hypot(y_46_re, y_46_im)))) / 1.0));
	} else {
		double VAR_1;
		if ((y_46_re <= 3.3012917942497675e+146)) {
			VAR_1 = ((double) (((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)))) / 1.0));
		} else {
			VAR_1 = ((double) (((double) (x_46_re / ((double) hypot(y_46_re, y_46_im)))) / 1.0));
		}
		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.674096505949315e+204

    1. Initial program 41.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-sqrt41.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-identity41.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-frac41.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. Simplified41.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. 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 associate-/r*30.0

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{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)}}{1}}\]
    10. Applied div-inv30.0

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

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

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

      \[\leadsto \frac{\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)}}}{\frac{1}{1} \cdot 1}\]
    14. Simplified30.0

      \[\leadsto \frac{\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)}}{\color{blue}{1}}\]
    15. Taylor expanded around -inf 11.4

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

    if -1.674096505949315e+204 < y.re < 3.3012917942497675e+146

    1. Initial program 20.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-sqrt20.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-identity20.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-frac20.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. Simplified20.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. Simplified12.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 associate-/r*12.9

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{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)}}{1}}\]
    10. Applied div-inv12.9

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

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

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

      \[\leadsto \frac{\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)}}}{\frac{1}{1} \cdot 1}\]
    14. Simplified12.8

      \[\leadsto \frac{\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)}}{\color{blue}{1}}\]

    if 3.3012917942497675e+146 < y.re

    1. Initial program 43.4

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

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

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

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

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

      \[\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 associate-/r*28.5

      \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(y.re, y.im\right)}{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)}}{1}}\]
    10. Applied div-inv28.5

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

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}}{\frac{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)}}{1}\]
    12. Applied frac-times28.5

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

      \[\leadsto \frac{\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)}}}{\frac{1}{1} \cdot 1}\]
    14. Simplified28.4

      \[\leadsto \frac{\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)}}{\color{blue}{1}}\]
    15. Taylor expanded around inf 13.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.6740965059493151 \cdot 10^{204}:\\ \;\;\;\;\frac{\frac{-1 \cdot x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{1}\\ \mathbf{elif}\;y.re \le 3.3012917942497675 \cdot 10^{146}:\\ \;\;\;\;\frac{\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)}}{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{1}\\ \end{array}\]

Reproduce

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