_divideComplex, real part

Percentage Accurate: 62.0% → 85.6%
Time: 12.6s
Alternatives: 9
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \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))))
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));
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
public static 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));
}
def code(x_46_re, x_46_im, y_46_re, 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))
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 62.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \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))))
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));
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
public static 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));
}
def code(x_46_re, x_46_im, y_46_re, 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))
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}

Alternative 1: 85.6% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq 5 \cdot 10^{+304}:\\ \;\;\;\;\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{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (<=
      (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))
      5e+304)
   (/ (/ (fma x.re y.re (* x.im y.im)) (hypot y.re y.im)) (hypot y.re y.im))
   (+ (/ x.re y.re) (/ (/ x.im y.re) (/ y.re y.im)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 5e+304) {
		tmp = (fma(x_46_re, y_46_re, (x_46_im * y_46_im)) / hypot(y_46_re, y_46_im)) / hypot(y_46_re, y_46_im);
	} else {
		tmp = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if (Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) <= 5e+304)
		tmp = Float64(Float64(fma(x_46_re, y_46_re, Float64(x_46_im * y_46_im)) / hypot(y_46_re, y_46_im)) / hypot(y_46_re, y_46_im));
	else
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(x_46_im / y_46_re) / Float64(y_46_re / y_46_im)));
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+304], N[(N[(N[(x$46$re * y$46$re + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(x$46$im / y$46$re), $MachinePrecision] / N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\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{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (*.f64 x.re y.re) (*.f64 x.im y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im))) < 4.9999999999999997e304

    1. Initial program 79.5%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity79.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{y.re \cdot y.re + y.im \cdot y.im} \]
      2. add-sqr-sqrt79.5%

        \[\leadsto \frac{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}{\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}}} \]
      3. times-frac79.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}}} \]
      4. hypot-def79.5%

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

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

        \[\leadsto \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)}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr95.4%

      \[\leadsto \color{blue}{\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)}} \]
    5. Step-by-step derivation
      1. associate-*l/95.6%

        \[\leadsto \color{blue}{\frac{1 \cdot \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)}} \]
      2. *-un-lft-identity95.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)}}}{\mathsf{hypot}\left(y.re, y.im\right)} \]
    6. Applied egg-rr95.6%

      \[\leadsto \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 4.9999999999999997e304 < (/.f64 (+.f64 (*.f64 x.re y.re) (*.f64 x.im y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im)))

    1. Initial program 8.3%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 44.5%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*52.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/52.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified52.9%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity52.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow252.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac65.0%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr65.0%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/65.0%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity65.0%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified65.0%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
    10. Step-by-step derivation
      1. associate-*l/65.1%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    11. Applied egg-rr65.1%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    12. Step-by-step derivation
      1. associate-/l*65.1%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}} \]
    13. Simplified65.1%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \leq 5 \cdot 10^{+304}:\\ \;\;\;\;\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{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x.re \cdot y.re + x.im \cdot y.im\\ t_1 := \frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \mathbf{if}\;y.re \leq -2.06 \cdot 10^{+102}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y.re \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{t\_0}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.re \leq 1.05 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - x.re \cdot \frac{y.re}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 6.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (+ (* x.re y.re) (* x.im y.im)))
        (t_1 (+ (/ x.re y.re) (/ (/ x.im y.re) (/ y.re y.im)))))
   (if (<= y.re -2.06e+102)
     t_1
     (if (<= y.re -2.3e-164)
       (/ t_0 (+ (* y.re y.re) (* y.im y.im)))
       (if (<= y.re 1.05e-105)
         (* (/ -1.0 y.im) (- (- x.im) (* x.re (/ y.re y.im))))
         (if (<= y.re 6.6e+78) (/ t_0 (pow (hypot y.re y.im) 2.0)) t_1))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = (x_46_re * y_46_re) + (x_46_im * y_46_im);
	double t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	double tmp;
	if (y_46_re <= -2.06e+102) {
		tmp = t_1;
	} else if (y_46_re <= -2.3e-164) {
		tmp = t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} else if (y_46_re <= 1.05e-105) {
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)));
	} else if (y_46_re <= 6.6e+78) {
		tmp = t_0 / pow(hypot(y_46_re, y_46_im), 2.0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = (x_46_re * y_46_re) + (x_46_im * y_46_im);
	double t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	double tmp;
	if (y_46_re <= -2.06e+102) {
		tmp = t_1;
	} else if (y_46_re <= -2.3e-164) {
		tmp = t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} else if (y_46_re <= 1.05e-105) {
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)));
	} else if (y_46_re <= 6.6e+78) {
		tmp = t_0 / Math.pow(Math.hypot(y_46_re, y_46_im), 2.0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	t_0 = (x_46_re * y_46_re) + (x_46_im * y_46_im)
	t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im))
	tmp = 0
	if y_46_re <= -2.06e+102:
		tmp = t_1
	elif y_46_re <= -2.3e-164:
		tmp = t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
	elif y_46_re <= 1.05e-105:
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)))
	elif y_46_re <= 6.6e+78:
		tmp = t_0 / math.pow(math.hypot(y_46_re, y_46_im), 2.0)
	else:
		tmp = t_1
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im))
	t_1 = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(x_46_im / y_46_re) / Float64(y_46_re / y_46_im)))
	tmp = 0.0
	if (y_46_re <= -2.06e+102)
		tmp = t_1;
	elseif (y_46_re <= -2.3e-164)
		tmp = Float64(t_0 / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)));
	elseif (y_46_re <= 1.05e-105)
		tmp = Float64(Float64(-1.0 / y_46_im) * Float64(Float64(-x_46_im) - Float64(x_46_re * Float64(y_46_re / y_46_im))));
	elseif (y_46_re <= 6.6e+78)
		tmp = Float64(t_0 / (hypot(y_46_re, y_46_im) ^ 2.0));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = (x_46_re * y_46_re) + (x_46_im * y_46_im);
	t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	tmp = 0.0;
	if (y_46_re <= -2.06e+102)
		tmp = t_1;
	elseif (y_46_re <= -2.3e-164)
		tmp = t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	elseif (y_46_re <= 1.05e-105)
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)));
	elseif (y_46_re <= 6.6e+78)
		tmp = t_0 / (hypot(y_46_re, y_46_im) ^ 2.0);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(x$46$im / y$46$re), $MachinePrecision] / N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -2.06e+102], t$95$1, If[LessEqual[y$46$re, -2.3e-164], N[(t$95$0 / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.05e-105], N[(N[(-1.0 / y$46$im), $MachinePrecision] * N[((-x$46$im) - N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 6.6e+78], N[(t$95$0 / N[Power[N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x.re \cdot y.re + x.im \cdot y.im\\
t_1 := \frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\
\mathbf{if}\;y.re \leq -2.06 \cdot 10^{+102}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y.re \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;\frac{t\_0}{y.re \cdot y.re + y.im \cdot y.im}\\

\mathbf{elif}\;y.re \leq 1.05 \cdot 10^{-105}:\\
\;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - x.re \cdot \frac{y.re}{y.im}\right)\\

\mathbf{elif}\;y.re \leq 6.6 \cdot 10^{+78}:\\
\;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y.re < -2.05999999999999999e102 or 6.6e78 < y.re

    1. Initial program 37.5%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 71.0%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*75.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/77.8%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified77.8%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity77.8%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow277.8%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac85.6%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr85.6%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/85.6%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity85.6%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified85.6%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
    10. Step-by-step derivation
      1. associate-*l/86.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    11. Applied egg-rr86.9%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    12. Step-by-step derivation
      1. associate-/l*86.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}} \]
    13. Simplified86.9%

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

    if -2.05999999999999999e102 < y.re < -2.29999999999999985e-164

    1. Initial program 83.0%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing

    if -2.29999999999999985e-164 < y.re < 1.05e-105

    1. Initial program 66.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity66.1%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{y.re \cdot y.re + y.im \cdot y.im} \]
      2. add-sqr-sqrt66.1%

        \[\leadsto \frac{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}{\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}}} \]
      3. times-frac65.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}}} \]
      4. hypot-def66.0%

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

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

        \[\leadsto \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)}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr82.6%

      \[\leadsto \color{blue}{\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)}} \]
    5. Taylor expanded in y.im around -inf 52.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-out52.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot \left(x.im + \frac{x.re \cdot y.re}{y.im}\right)\right)} \]
      2. associate-/l*52.2%

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot \left(x.im + \frac{x.re}{\frac{y.im}{y.re}}\right)\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-in52.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot x.im + -1 \cdot \frac{x.re}{\frac{y.im}{y.re}}\right)} \]
      2. distribute-lft-in50.7%

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-x.im\right) + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-1 \cdot \left(x.re \cdot \color{blue}{\frac{y.re}{y.im}}\right)\right) \]
      6. associate-*r*50.7%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-x.im\right) + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(\color{blue}{\left(-x.re\right)} \cdot \frac{y.re}{y.im}\right) \]
    9. Applied egg-rr50.7%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-x.im\right) + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(\left(-x.re\right) \cdot \frac{y.re}{y.im}\right)} \]
    10. Step-by-step derivation
      1. distribute-lft-out52.2%

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(\left(-x.im\right) + \left(-x.re\right) \cdot \frac{y.re}{y.im}\right)} \]
    12. Taylor expanded in y.im around -inf 92.1%

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

    if 1.05e-105 < y.re < 6.6e78

    1. Initial program 81.5%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u78.9%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(y.re \cdot y.re + y.im \cdot y.im\right)\right)}} \]
      2. expm1-udef50.8%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{e^{\mathsf{log1p}\left(y.re \cdot y.re + y.im \cdot y.im\right)} - 1}} \]
      3. add-sqr-sqrt50.8%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{e^{\mathsf{log1p}\left(\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}}\right)} - 1} \]
      4. pow250.8%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{e^{\mathsf{log1p}\left(\color{blue}{{\left(\sqrt{y.re \cdot y.re + y.im \cdot y.im}\right)}^{2}}\right)} - 1} \]
      5. hypot-def50.8%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{e^{\mathsf{log1p}\left({\color{blue}{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}}^{2}\right)} - 1} \]
    4. Applied egg-rr50.8%

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{e^{\mathsf{log1p}\left({\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}\right)} - 1}} \]
    5. Step-by-step derivation
      1. expm1-def78.9%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}\right)\right)}} \]
      2. expm1-log1p81.5%

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}} \]
    6. Simplified81.5%

      \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{\color{blue}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification86.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -2.06 \cdot 10^{+102}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \mathbf{elif}\;y.re \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.re \leq 1.05 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - x.re \cdot \frac{y.re}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 6.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{x.re \cdot y.re + x.im \cdot y.im}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ t_1 := \frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \mathbf{if}\;y.re \leq -2.2 \cdot 10^{+102}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y.re \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 3.9 \cdot 10^{-106}:\\ \;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - x.re \cdot \frac{y.re}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 4.2 \cdot 10^{+78}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0
         (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
        (t_1 (+ (/ x.re y.re) (/ (/ x.im y.re) (/ y.re y.im)))))
   (if (<= y.re -2.2e+102)
     t_1
     (if (<= y.re -2.3e-164)
       t_0
       (if (<= y.re 3.9e-106)
         (* (/ -1.0 y.im) (- (- x.im) (* x.re (/ y.re y.im))))
         (if (<= y.re 4.2e+78) t_0 t_1))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = ((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 t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	double tmp;
	if (y_46_re <= -2.2e+102) {
		tmp = t_1;
	} else if (y_46_re <= -2.3e-164) {
		tmp = t_0;
	} else if (y_46_re <= 3.9e-106) {
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)));
	} else if (y_46_re <= 4.2e+78) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
    t_1 = (x_46re / y_46re) + ((x_46im / y_46re) / (y_46re / y_46im))
    if (y_46re <= (-2.2d+102)) then
        tmp = t_1
    else if (y_46re <= (-2.3d-164)) then
        tmp = t_0
    else if (y_46re <= 3.9d-106) then
        tmp = ((-1.0d0) / y_46im) * (-x_46im - (x_46re * (y_46re / y_46im)))
    else if (y_46re <= 4.2d+78) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = ((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 t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	double tmp;
	if (y_46_re <= -2.2e+102) {
		tmp = t_1;
	} else if (y_46_re <= -2.3e-164) {
		tmp = t_0;
	} else if (y_46_re <= 3.9e-106) {
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)));
	} else if (y_46_re <= 4.2e+78) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
	t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im))
	tmp = 0
	if y_46_re <= -2.2e+102:
		tmp = t_1
	elif y_46_re <= -2.3e-164:
		tmp = t_0
	elif y_46_re <= 3.9e-106:
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)))
	elif y_46_re <= 4.2e+78:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
	t_1 = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(x_46_im / y_46_re) / Float64(y_46_re / y_46_im)))
	tmp = 0.0
	if (y_46_re <= -2.2e+102)
		tmp = t_1;
	elseif (y_46_re <= -2.3e-164)
		tmp = t_0;
	elseif (y_46_re <= 3.9e-106)
		tmp = Float64(Float64(-1.0 / y_46_im) * Float64(Float64(-x_46_im) - Float64(x_46_re * Float64(y_46_re / y_46_im))));
	elseif (y_46_re <= 4.2e+78)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	t_1 = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	tmp = 0.0;
	if (y_46_re <= -2.2e+102)
		tmp = t_1;
	elseif (y_46_re <= -2.3e-164)
		tmp = t_0;
	elseif (y_46_re <= 3.9e-106)
		tmp = (-1.0 / y_46_im) * (-x_46_im - (x_46_re * (y_46_re / y_46_im)));
	elseif (y_46_re <= 4.2e+78)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(x$46$im / y$46$re), $MachinePrecision] / N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -2.2e+102], t$95$1, If[LessEqual[y$46$re, -2.3e-164], t$95$0, If[LessEqual[y$46$re, 3.9e-106], N[(N[(-1.0 / y$46$im), $MachinePrecision] * N[((-x$46$im) - N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 4.2e+78], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\
t_1 := \frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\
\mathbf{if}\;y.re \leq -2.2 \cdot 10^{+102}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y.re \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y.re \leq 3.9 \cdot 10^{-106}:\\
\;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - x.re \cdot \frac{y.re}{y.im}\right)\\

\mathbf{elif}\;y.re \leq 4.2 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -2.20000000000000007e102 or 4.2000000000000002e78 < y.re

    1. Initial program 37.5%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 71.0%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*75.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/77.8%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified77.8%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity77.8%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow277.8%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac85.6%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr85.6%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/85.6%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity85.6%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified85.6%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
    10. Step-by-step derivation
      1. associate-*l/86.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    11. Applied egg-rr86.9%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    12. Step-by-step derivation
      1. associate-/l*86.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}} \]
    13. Simplified86.9%

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

    if -2.20000000000000007e102 < y.re < -2.29999999999999985e-164 or 3.9000000000000001e-106 < y.re < 4.2000000000000002e78

    1. Initial program 82.5%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing

    if -2.29999999999999985e-164 < y.re < 3.9000000000000001e-106

    1. Initial program 66.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity66.1%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{y.re \cdot y.re + y.im \cdot y.im} \]
      2. add-sqr-sqrt66.1%

        \[\leadsto \frac{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}{\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}}} \]
      3. times-frac65.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}}} \]
      4. hypot-def66.0%

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

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

        \[\leadsto \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)}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr82.6%

      \[\leadsto \color{blue}{\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)}} \]
    5. Taylor expanded in y.im around -inf 52.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-out52.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot \left(x.im + \frac{x.re \cdot y.re}{y.im}\right)\right)} \]
      2. associate-/l*52.2%

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot \left(x.im + \frac{x.re}{\frac{y.im}{y.re}}\right)\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-in52.2%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot x.im + -1 \cdot \frac{x.re}{\frac{y.im}{y.re}}\right)} \]
      2. distribute-lft-in50.7%

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-x.im\right) + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-1 \cdot \left(x.re \cdot \color{blue}{\frac{y.re}{y.im}}\right)\right) \]
      6. associate-*r*50.7%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-x.im\right) + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(\color{blue}{\left(-x.re\right)} \cdot \frac{y.re}{y.im}\right) \]
    9. Applied egg-rr50.7%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(-x.im\right) + \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(\left(-x.re\right) \cdot \frac{y.re}{y.im}\right)} \]
    10. Step-by-step derivation
      1. distribute-lft-out52.2%

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(\left(-x.im\right) + \left(-x.re\right) \cdot \frac{y.re}{y.im}\right)} \]
    12. Taylor expanded in y.im around -inf 92.1%

      \[\leadsto \color{blue}{\frac{-1}{y.im}} \cdot \left(\left(-x.im\right) + \left(-x.re\right) \cdot \frac{y.re}{y.im}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -2.2 \cdot 10^{+102}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \mathbf{elif}\;y.re \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.re \leq 3.9 \cdot 10^{-106}:\\ \;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - x.re \cdot \frac{y.re}{y.im}\right)\\ \mathbf{elif}\;y.re \leq 4.2 \cdot 10^{+78}:\\ \;\;\;\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{y.im} \cdot \left(\left(-x.im\right) - \frac{x.re}{\frac{y.im}{y.re}}\right)\\ \mathbf{if}\;y.im \leq -1.12 \cdot 10^{-35}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.im \leq 10^{-12}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im \cdot y.im}{y.re}}{y.re}\\ \mathbf{elif}\;y.im \leq 1.85 \cdot 10^{+67}:\\ \;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (* (/ -1.0 y.im) (- (- x.im) (/ x.re (/ y.im y.re))))))
   (if (<= y.im -1.12e-35)
     t_0
     (if (<= y.im 1e-12)
       (+ (/ x.re y.re) (/ (/ (* x.im y.im) y.re) y.re))
       (if (<= y.im 1.85e+67)
         (+ (/ x.re y.re) (* y.im (/ (/ x.im y.re) y.re)))
         t_0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = (-1.0 / y_46_im) * (-x_46_im - (x_46_re / (y_46_im / y_46_re)));
	double tmp;
	if (y_46_im <= -1.12e-35) {
		tmp = t_0;
	} else if (y_46_im <= 1e-12) {
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re);
	} else if (y_46_im <= 1.85e+67) {
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((-1.0d0) / y_46im) * (-x_46im - (x_46re / (y_46im / y_46re)))
    if (y_46im <= (-1.12d-35)) then
        tmp = t_0
    else if (y_46im <= 1d-12) then
        tmp = (x_46re / y_46re) + (((x_46im * y_46im) / y_46re) / y_46re)
    else if (y_46im <= 1.85d+67) then
        tmp = (x_46re / y_46re) + (y_46im * ((x_46im / y_46re) / y_46re))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = (-1.0 / y_46_im) * (-x_46_im - (x_46_re / (y_46_im / y_46_re)));
	double tmp;
	if (y_46_im <= -1.12e-35) {
		tmp = t_0;
	} else if (y_46_im <= 1e-12) {
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re);
	} else if (y_46_im <= 1.85e+67) {
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	t_0 = (-1.0 / y_46_im) * (-x_46_im - (x_46_re / (y_46_im / y_46_re)))
	tmp = 0
	if y_46_im <= -1.12e-35:
		tmp = t_0
	elif y_46_im <= 1e-12:
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re)
	elif y_46_im <= 1.85e+67:
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re))
	else:
		tmp = t_0
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(-1.0 / y_46_im) * Float64(Float64(-x_46_im) - Float64(x_46_re / Float64(y_46_im / y_46_re))))
	tmp = 0.0
	if (y_46_im <= -1.12e-35)
		tmp = t_0;
	elseif (y_46_im <= 1e-12)
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(Float64(x_46_im * y_46_im) / y_46_re) / y_46_re));
	elseif (y_46_im <= 1.85e+67)
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(y_46_im * Float64(Float64(x_46_im / y_46_re) / y_46_re)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = (-1.0 / y_46_im) * (-x_46_im - (x_46_re / (y_46_im / y_46_re)));
	tmp = 0.0;
	if (y_46_im <= -1.12e-35)
		tmp = t_0;
	elseif (y_46_im <= 1e-12)
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re);
	elseif (y_46_im <= 1.85e+67)
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(-1.0 / y$46$im), $MachinePrecision] * N[((-x$46$im) - N[(x$46$re / N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$im, -1.12e-35], t$95$0, If[LessEqual[y$46$im, 1e-12], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(N[(x$46$im * y$46$im), $MachinePrecision] / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$im, 1.85e+67], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(y$46$im * N[(N[(x$46$im / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-1}{y.im} \cdot \left(\left(-x.im\right) - \frac{x.re}{\frac{y.im}{y.re}}\right)\\
\mathbf{if}\;y.im \leq -1.12 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y.im \leq 1.85 \cdot 10^{+67}:\\
\;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.im < -1.12e-35 or 1.8499999999999999e67 < y.im

    1. Initial program 51.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity51.1%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{y.re \cdot y.re + y.im \cdot y.im} \]
      2. add-sqr-sqrt51.1%

        \[\leadsto \frac{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}{\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}}} \]
      3. times-frac51.1%

        \[\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}}} \]
      4. hypot-def51.1%

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

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

        \[\leadsto \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)}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr68.2%

      \[\leadsto \color{blue}{\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)}} \]
    5. Taylor expanded in y.im around -inf 54.3%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-out54.3%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot \left(x.im + \frac{x.re \cdot y.re}{y.im}\right)\right)} \]
      2. associate-/l*57.0%

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \color{blue}{\left(-1 \cdot \left(x.im + \frac{x.re}{\frac{y.im}{y.re}}\right)\right)} \]
    8. Taylor expanded in y.im around -inf 79.9%

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

    if -1.12e-35 < y.im < 9.9999999999999998e-13

    1. Initial program 73.3%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 78.9%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*77.4%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/76.8%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified76.8%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. pow276.8%

        \[\leadsto \frac{x.re}{y.re} + \frac{x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      2. associate-*l/78.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im \cdot y.im}{y.re \cdot y.re}} \]
      3. associate-/r*84.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    7. Applied egg-rr84.7%

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

    if 9.9999999999999998e-13 < y.im < 1.8499999999999999e67

    1. Initial program 55.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 46.3%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*56.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/56.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified56.7%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity56.7%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow256.7%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac75.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr75.9%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/75.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity75.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified75.9%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
  3. Recombined 3 regimes into one program.
  4. Final simplification81.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -1.12 \cdot 10^{-35}:\\ \;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - \frac{x.re}{\frac{y.im}{y.re}}\right)\\ \mathbf{elif}\;y.im \leq 10^{-12}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im \cdot y.im}{y.re}}{y.re}\\ \mathbf{elif}\;y.im \leq 1.85 \cdot 10^{+67}:\\ \;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{y.im} \cdot \left(\left(-x.im\right) - \frac{x.re}{\frac{y.im}{y.re}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 71.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im \cdot y.im}{y.re}}{y.re}\\ \mathbf{elif}\;y.im \leq 1.7 \cdot 10^{+70}:\\ \;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (<= y.im -2.05e-35)
   (/ x.im y.im)
   (if (<= y.im 2e-9)
     (+ (/ x.re y.re) (/ (/ (* x.im y.im) y.re) y.re))
     (if (<= y.im 1.7e+70)
       (+ (/ x.re y.re) (* y.im (/ (/ x.im y.re) y.re)))
       (/ x.im y.im)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if (y_46_im <= -2.05e-35) {
		tmp = x_46_im / y_46_im;
	} else if (y_46_im <= 2e-9) {
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re);
	} else if (y_46_im <= 1.7e+70) {
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	} else {
		tmp = x_46_im / y_46_im;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: tmp
    if (y_46im <= (-2.05d-35)) then
        tmp = x_46im / y_46im
    else if (y_46im <= 2d-9) then
        tmp = (x_46re / y_46re) + (((x_46im * y_46im) / y_46re) / y_46re)
    else if (y_46im <= 1.7d+70) then
        tmp = (x_46re / y_46re) + (y_46im * ((x_46im / y_46re) / y_46re))
    else
        tmp = x_46im / y_46im
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if (y_46_im <= -2.05e-35) {
		tmp = x_46_im / y_46_im;
	} else if (y_46_im <= 2e-9) {
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re);
	} else if (y_46_im <= 1.7e+70) {
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	} else {
		tmp = x_46_im / y_46_im;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	tmp = 0
	if y_46_im <= -2.05e-35:
		tmp = x_46_im / y_46_im
	elif y_46_im <= 2e-9:
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re)
	elif y_46_im <= 1.7e+70:
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re))
	else:
		tmp = x_46_im / y_46_im
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if (y_46_im <= -2.05e-35)
		tmp = Float64(x_46_im / y_46_im);
	elseif (y_46_im <= 2e-9)
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(Float64(x_46_im * y_46_im) / y_46_re) / y_46_re));
	elseif (y_46_im <= 1.7e+70)
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(y_46_im * Float64(Float64(x_46_im / y_46_re) / y_46_re)));
	else
		tmp = Float64(x_46_im / y_46_im);
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0;
	if (y_46_im <= -2.05e-35)
		tmp = x_46_im / y_46_im;
	elseif (y_46_im <= 2e-9)
		tmp = (x_46_re / y_46_re) + (((x_46_im * y_46_im) / y_46_re) / y_46_re);
	elseif (y_46_im <= 1.7e+70)
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	else
		tmp = x_46_im / y_46_im;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$im, -2.05e-35], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 2e-9], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(N[(x$46$im * y$46$im), $MachinePrecision] / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$im, 1.7e+70], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(y$46$im * N[(N[(x$46$im / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35}:\\
\;\;\;\;\frac{x.im}{y.im}\\

\mathbf{elif}\;y.im \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im \cdot y.im}{y.re}}{y.re}\\

\mathbf{elif}\;y.im \leq 1.7 \cdot 10^{+70}:\\
\;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.im < -2.05000000000000013e-35 or 1.7e70 < y.im

    1. Initial program 51.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around 0 67.2%

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

    if -2.05000000000000013e-35 < y.im < 2.00000000000000012e-9

    1. Initial program 73.3%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 78.9%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*77.4%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/76.8%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified76.8%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. pow276.8%

        \[\leadsto \frac{x.re}{y.re} + \frac{x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      2. associate-*l/78.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im \cdot y.im}{y.re \cdot y.re}} \]
      3. associate-/r*84.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    7. Applied egg-rr84.7%

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

    if 2.00000000000000012e-9 < y.im < 1.7e70

    1. Initial program 55.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 46.3%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*56.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/56.7%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified56.7%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity56.7%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow256.7%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac75.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr75.9%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/75.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity75.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified75.9%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
  3. Recombined 3 regimes into one program.
  4. Final simplification76.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im \cdot y.im}{y.re}}{y.re}\\ \mathbf{elif}\;y.im \leq 1.7 \cdot 10^{+70}:\\ \;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 68.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35} \lor \neg \left(y.im \leq 1.75 \cdot 10^{+70}\right):\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.im -2.05e-35) (not (<= y.im 1.75e+70)))
   (/ x.im y.im)
   (+ (/ x.re y.re) (* y.im (/ (/ x.im y.re) y.re)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_im <= -2.05e-35) || !(y_46_im <= 1.75e+70)) {
		tmp = x_46_im / y_46_im;
	} else {
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: tmp
    if ((y_46im <= (-2.05d-35)) .or. (.not. (y_46im <= 1.75d+70))) then
        tmp = x_46im / y_46im
    else
        tmp = (x_46re / y_46re) + (y_46im * ((x_46im / y_46re) / y_46re))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_im <= -2.05e-35) || !(y_46_im <= 1.75e+70)) {
		tmp = x_46_im / y_46_im;
	} else {
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	tmp = 0
	if (y_46_im <= -2.05e-35) or not (y_46_im <= 1.75e+70):
		tmp = x_46_im / y_46_im
	else:
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re))
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if ((y_46_im <= -2.05e-35) || !(y_46_im <= 1.75e+70))
		tmp = Float64(x_46_im / y_46_im);
	else
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(y_46_im * Float64(Float64(x_46_im / y_46_re) / y_46_re)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0;
	if ((y_46_im <= -2.05e-35) || ~((y_46_im <= 1.75e+70)))
		tmp = x_46_im / y_46_im;
	else
		tmp = (x_46_re / y_46_re) + (y_46_im * ((x_46_im / y_46_re) / y_46_re));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$im, -2.05e-35], N[Not[LessEqual[y$46$im, 1.75e+70]], $MachinePrecision]], N[(x$46$im / y$46$im), $MachinePrecision], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(y$46$im * N[(N[(x$46$im / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35} \lor \neg \left(y.im \leq 1.75 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{x.im}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.im < -2.05000000000000013e-35 or 1.75000000000000001e70 < y.im

    1. Initial program 51.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around 0 67.2%

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

    if -2.05000000000000013e-35 < y.im < 1.75000000000000001e70

    1. Initial program 70.7%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 74.2%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*74.4%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/73.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified73.9%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity73.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow273.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac79.5%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr79.5%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/79.5%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity79.5%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified79.5%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35} \lor \neg \left(y.im \leq 1.75 \cdot 10^{+70}\right):\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + y.im \cdot \frac{\frac{x.im}{y.re}}{y.re}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 70.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35} \lor \neg \left(y.im \leq 1.12 \cdot 10^{+70}\right):\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.im -2.05e-35) (not (<= y.im 1.12e+70)))
   (/ x.im y.im)
   (+ (/ x.re y.re) (/ (/ x.im y.re) (/ y.re y.im)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_im <= -2.05e-35) || !(y_46_im <= 1.12e+70)) {
		tmp = x_46_im / y_46_im;
	} else {
		tmp = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: tmp
    if ((y_46im <= (-2.05d-35)) .or. (.not. (y_46im <= 1.12d+70))) then
        tmp = x_46im / y_46im
    else
        tmp = (x_46re / y_46re) + ((x_46im / y_46re) / (y_46re / y_46im))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_im <= -2.05e-35) || !(y_46_im <= 1.12e+70)) {
		tmp = x_46_im / y_46_im;
	} else {
		tmp = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	tmp = 0
	if (y_46_im <= -2.05e-35) or not (y_46_im <= 1.12e+70):
		tmp = x_46_im / y_46_im
	else:
		tmp = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im))
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if ((y_46_im <= -2.05e-35) || !(y_46_im <= 1.12e+70))
		tmp = Float64(x_46_im / y_46_im);
	else
		tmp = Float64(Float64(x_46_re / y_46_re) + Float64(Float64(x_46_im / y_46_re) / Float64(y_46_re / y_46_im)));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0;
	if ((y_46_im <= -2.05e-35) || ~((y_46_im <= 1.12e+70)))
		tmp = x_46_im / y_46_im;
	else
		tmp = (x_46_re / y_46_re) + ((x_46_im / y_46_re) / (y_46_re / y_46_im));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$im, -2.05e-35], N[Not[LessEqual[y$46$im, 1.12e+70]], $MachinePrecision]], N[(x$46$im / y$46$im), $MachinePrecision], N[(N[(x$46$re / y$46$re), $MachinePrecision] + N[(N[(x$46$im / y$46$re), $MachinePrecision] / N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35} \lor \neg \left(y.im \leq 1.12 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{x.im}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.im < -2.05000000000000013e-35 or 1.11999999999999993e70 < y.im

    1. Initial program 51.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around 0 67.2%

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

    if -2.05000000000000013e-35 < y.im < 1.11999999999999993e70

    1. Initial program 70.7%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 74.2%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im \cdot y.im}{{y.re}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*74.4%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{\frac{{y.re}^{2}}{y.im}}} \]
      2. associate-/r/73.9%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    5. Simplified73.9%

      \[\leadsto \color{blue}{\frac{x.re}{y.re} + \frac{x.im}{{y.re}^{2}} \cdot y.im} \]
    6. Step-by-step derivation
      1. *-un-lft-identity73.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{1 \cdot x.im}}{{y.re}^{2}} \cdot y.im \]
      2. pow273.9%

        \[\leadsto \frac{x.re}{y.re} + \frac{1 \cdot x.im}{\color{blue}{y.re \cdot y.re}} \cdot y.im \]
      3. times-frac79.5%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    7. Applied egg-rr79.5%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\left(\frac{1}{y.re} \cdot \frac{x.im}{y.re}\right)} \cdot y.im \]
    8. Step-by-step derivation
      1. associate-*l/79.5%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{1 \cdot \frac{x.im}{y.re}}{y.re}} \cdot y.im \]
      2. *-lft-identity79.5%

        \[\leadsto \frac{x.re}{y.re} + \frac{\color{blue}{\frac{x.im}{y.re}}}{y.re} \cdot y.im \]
    9. Simplified79.5%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{y.re}} \cdot y.im \]
    10. Step-by-step derivation
      1. associate-*l/80.8%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    11. Applied egg-rr80.8%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}} \]
    12. Step-by-step derivation
      1. associate-/l*80.1%

        \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}} \]
    13. Simplified80.1%

      \[\leadsto \frac{x.re}{y.re} + \color{blue}{\frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -2.05 \cdot 10^{-35} \lor \neg \left(y.im \leq 1.12 \cdot 10^{+70}\right):\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re} + \frac{\frac{x.im}{y.re}}{\frac{y.re}{y.im}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 62.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -5.5 \cdot 10^{-32} \lor \neg \left(y.re \leq 2.05 \cdot 10^{+77}\right):\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -5.5e-32) (not (<= y.re 2.05e+77)))
   (/ x.re y.re)
   (/ x.im y.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 <= -5.5e-32) || !(y_46_re <= 2.05e+77)) {
		tmp = x_46_re / y_46_re;
	} else {
		tmp = x_46_im / y_46_im;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: tmp
    if ((y_46re <= (-5.5d-32)) .or. (.not. (y_46re <= 2.05d+77))) then
        tmp = x_46re / y_46re
    else
        tmp = x_46im / y_46im
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_re <= -5.5e-32) || !(y_46_re <= 2.05e+77)) {
		tmp = x_46_re / y_46_re;
	} else {
		tmp = x_46_im / y_46_im;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	tmp = 0
	if (y_46_re <= -5.5e-32) or not (y_46_re <= 2.05e+77):
		tmp = x_46_re / y_46_re
	else:
		tmp = x_46_im / y_46_im
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if ((y_46_re <= -5.5e-32) || !(y_46_re <= 2.05e+77))
		tmp = Float64(x_46_re / y_46_re);
	else
		tmp = Float64(x_46_im / y_46_im);
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0;
	if ((y_46_re <= -5.5e-32) || ~((y_46_re <= 2.05e+77)))
		tmp = x_46_re / y_46_re;
	else
		tmp = x_46_im / y_46_im;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -5.5e-32], N[Not[LessEqual[y$46$re, 2.05e+77]], $MachinePrecision]], N[(x$46$re / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -5.5 \cdot 10^{-32} \lor \neg \left(y.re \leq 2.05 \cdot 10^{+77}\right):\\
\;\;\;\;\frac{x.re}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -5.50000000000000024e-32 or 2.05e77 < y.re

    1. Initial program 47.8%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around inf 68.8%

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

    if -5.50000000000000024e-32 < y.re < 2.05e77

    1. Initial program 74.4%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Taylor expanded in y.re around 0 61.8%

      \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -5.5 \cdot 10^{-32} \lor \neg \left(y.re \leq 2.05 \cdot 10^{+77}\right):\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 42.8% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{x.im}{y.im} \end{array} \]
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ x.im y.im))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return x_46_im / y_46_im;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = x_46im / y_46im
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return x_46_im / y_46_im;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return x_46_im / y_46_im
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(x_46_im / y_46_im)
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = x_46_im / y_46_im;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im / y$46$im), $MachinePrecision]
\begin{array}{l}

\\
\frac{x.im}{y.im}
\end{array}
Derivation
  1. Initial program 61.7%

    \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
  2. Add Preprocessing
  3. Taylor expanded in y.re around 0 40.0%

    \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
  4. Final simplification40.0%

    \[\leadsto \frac{x.im}{y.im} \]
  5. Add Preprocessing

Reproduce

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