_divideComplex, imaginary part

Percentage Accurate: 62.1% → 95.8%
Time: 11.4s
Alternatives: 9
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \frac{x.im \cdot y.re - x.re \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.im y.re) (* x.re 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_im * y_46_re) - (x_46_re * 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_46im * y_46re) - (x_46re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - Float64(x_46_re * 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_im * y_46_re) - (x_46_re * 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$im * y$46$re), $MachinePrecision] - N[(x$46$re * 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.im \cdot y.re - x.re \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.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x.im \cdot y.re - x.re \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.im y.re) (* x.re 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_im * y_46_re) - (x_46_re * 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_46im * y_46re) - (x_46re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - Float64(x_46_re * 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_im * y_46_re) - (x_46_re * 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$im * y$46$re), $MachinePrecision] - N[(x$46$re * 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.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}

Alternative 1: 95.8% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 2 \cdot 10^{+247}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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


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

    1. Initial program 76.6%

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

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

        \[\leadsto \frac{1 \cdot \left(x.im \cdot y.re - x.re \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-frac76.5%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
      4. hypot-define76.5%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, x.re \cdot \left(-y.im\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    5. Step-by-step derivation
      1. associate-*r/97.1%

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

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

    if 1.9999999999999999e247 < (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im)))

    1. Initial program 24.1%

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

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

        \[\leadsto \frac{\color{blue}{y.re \cdot x.im}}{y.re \cdot y.re + y.im \cdot y.im} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      3. add-sqr-sqrt18.1%

        \[\leadsto \frac{y.re \cdot x.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}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      4. times-frac22.3%

        \[\leadsto \color{blue}{\frac{y.re}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      5. fma-neg22.3%

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\color{blue}{x.re \cdot \frac{y.im}{y.re \cdot y.re + y.im \cdot y.im}}\right) \]
      9. add-sqr-sqrt68.8%

        \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{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}}}\right) \]
      10. pow268.8%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{y.im}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\right)} \]
    5. Step-by-step derivation
      1. *-un-lft-identity68.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}\right) \]
    7. Step-by-step derivation
      1. associate-*l/95.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 2 \cdot 10^{+247}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, x.re \cdot \frac{\frac{y.im}{-\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 97.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{-1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{x.re \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}}\right) \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (fma
  (/ y.re (hypot y.re y.im))
  (/ x.im (hypot y.re y.im))
  (/ -1.0 (/ (hypot y.im y.re) (* x.re (/ y.im (hypot y.im y.re)))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return fma((y_46_re / hypot(y_46_re, y_46_im)), (x_46_im / hypot(y_46_re, y_46_im)), (-1.0 / (hypot(y_46_im, y_46_re) / (x_46_re * (y_46_im / hypot(y_46_im, y_46_re))))));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return fma(Float64(y_46_re / hypot(y_46_re, y_46_im)), Float64(x_46_im / hypot(y_46_re, y_46_im)), Float64(-1.0 / Float64(hypot(y_46_im, y_46_re) / Float64(x_46_re * Float64(y_46_im / hypot(y_46_im, y_46_re))))))
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(N[Sqrt[y$46$im ^ 2 + y$46$re ^ 2], $MachinePrecision] / N[(x$46$re * N[(y$46$im / N[Sqrt[y$46$im ^ 2 + y$46$re ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{-1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{x.re \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}}\right)
\end{array}
Derivation
  1. Initial program 62.7%

    \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-sub59.7%

      \[\leadsto \color{blue}{\frac{x.im \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}} \]
    2. *-commutative59.7%

      \[\leadsto \frac{\color{blue}{y.re \cdot x.im}}{y.re \cdot y.re + y.im \cdot y.im} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    3. add-sqr-sqrt59.7%

      \[\leadsto \frac{y.re \cdot x.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}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    4. times-frac60.1%

      \[\leadsto \color{blue}{\frac{y.re}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    5. fma-neg60.1%

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\color{blue}{x.re \cdot \frac{y.im}{y.re \cdot y.re + y.im \cdot y.im}}\right) \]
    9. add-sqr-sqrt80.4%

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{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}}}\right) \]
    10. pow280.4%

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

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{y.im}{{\color{blue}{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}}^{2}}\right) \]
  4. Applied egg-rr80.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{y.im}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\right)} \]
  5. Step-by-step derivation
    1. *-un-lft-identity80.4%

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{y.im}{\color{blue}{\mathsf{hypot}\left(y.im, y.re\right)}}\right)\right) \]
  6. Applied egg-rr94.3%

    \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(y.im, y.re\right)} \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}\right)}\right) \]
  7. Step-by-step derivation
    1. associate-*l/94.3%

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \color{blue}{\frac{1 \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}}\right) \]
    2. *-lft-identity94.3%

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

    \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \color{blue}{\frac{\frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}}\right) \]
  9. Step-by-step derivation
    1. associate-*r/96.6%

      \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\color{blue}{\frac{x.re \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}}\right) \]
    2. clear-num95.9%

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

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

    \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{-1}{\frac{\mathsf{hypot}\left(y.im, y.re\right)}{x.re \cdot \frac{y.im}{\mathsf{hypot}\left(y.im, y.re\right)}}}\right) \]
  12. Add Preprocessing

Alternative 3: 88.9% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+261}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.re}{-y.im}\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (<=
      (/ (- (* y.re x.im) (* y.im x.re)) (+ (* y.re y.re) (* y.im y.im)))
      1e+261)
   (*
    (/ 1.0 (hypot y.re y.im))
    (/ (fma x.im y.re (* y.im (- x.re))) (hypot y.re y.im)))
   (fma
    (/ y.re (hypot y.re y.im))
    (/ x.im (hypot y.re y.im))
    (/ x.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_re * x_46_im) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 1e+261) {
		tmp = (1.0 / hypot(y_46_re, y_46_im)) * (fma(x_46_im, y_46_re, (y_46_im * -x_46_re)) / hypot(y_46_re, y_46_im));
	} else {
		tmp = fma((y_46_re / hypot(y_46_re, y_46_im)), (x_46_im / hypot(y_46_re, y_46_im)), (x_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(y_46_re * x_46_im) - Float64(y_46_im * x_46_re)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) <= 1e+261)
		tmp = Float64(Float64(1.0 / hypot(y_46_re, y_46_im)) * Float64(fma(x_46_im, y_46_re, Float64(y_46_im * Float64(-x_46_re))) / hypot(y_46_re, y_46_im)));
	else
		tmp = fma(Float64(y_46_re / hypot(y_46_re, y_46_im)), Float64(x_46_im / hypot(y_46_re, y_46_im)), Float64(x_46_re / Float64(-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[(y$46$re * x$46$im), $MachinePrecision] - N[(y$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+261], N[(N[(1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(x$46$im * y$46$re + N[(y$46$im * (-x$46$re)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] + N[(x$46$re / (-y$46$im)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+261}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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


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

    1. Initial program 76.8%

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

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

        \[\leadsto \frac{1 \cdot \left(x.im \cdot y.re - x.re \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-frac76.8%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
      4. hypot-define76.8%

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, x.re \cdot \left(-y.im\right)\right)}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr97.0%

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

    if 9.9999999999999993e260 < (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im)))

    1. Initial program 21.8%

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub15.6%

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

        \[\leadsto \frac{\color{blue}{y.re \cdot x.im}}{y.re \cdot y.re + y.im \cdot y.im} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      3. add-sqr-sqrt15.6%

        \[\leadsto \frac{y.re \cdot x.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}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      4. times-frac19.9%

        \[\leadsto \color{blue}{\frac{y.re}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      5. fma-neg19.9%

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\color{blue}{x.re \cdot \frac{y.im}{y.re \cdot y.re + y.im \cdot y.im}}\right) \]
      9. add-sqr-sqrt67.8%

        \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{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}}}\right) \]
      10. pow267.8%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{y.im}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\right)} \]
    5. Taylor expanded in y.im around inf 72.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+261}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.re}{-y.im}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 89.0% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+261}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.re}{-y.im}\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (<=
      (/ (- (* y.re x.im) (* y.im x.re)) (+ (* y.re y.re) (* y.im y.im)))
      1e+261)
   (/
    (* (/ 1.0 (hypot y.re y.im)) (fma x.im y.re (* y.im (- x.re))))
    (hypot y.re y.im))
   (fma
    (/ y.re (hypot y.re y.im))
    (/ x.im (hypot y.re y.im))
    (/ x.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_re * x_46_im) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 1e+261) {
		tmp = ((1.0 / hypot(y_46_re, y_46_im)) * fma(x_46_im, y_46_re, (y_46_im * -x_46_re))) / hypot(y_46_re, y_46_im);
	} else {
		tmp = fma((y_46_re / hypot(y_46_re, y_46_im)), (x_46_im / hypot(y_46_re, y_46_im)), (x_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(y_46_re * x_46_im) - Float64(y_46_im * x_46_re)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) <= 1e+261)
		tmp = Float64(Float64(Float64(1.0 / hypot(y_46_re, y_46_im)) * fma(x_46_im, y_46_re, Float64(y_46_im * Float64(-x_46_re)))) / hypot(y_46_re, y_46_im));
	else
		tmp = fma(Float64(y_46_re / hypot(y_46_re, y_46_im)), Float64(x_46_im / hypot(y_46_re, y_46_im)), Float64(x_46_re / Float64(-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[(y$46$re * x$46$im), $MachinePrecision] - N[(y$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+261], N[(N[(N[(1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x$46$im * y$46$re + N[(y$46$im * (-x$46$re)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x$46$im / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] + N[(x$46$re / (-y$46$im)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+261}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\

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


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

    1. Initial program 76.8%

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

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

        \[\leadsto \frac{1 \cdot \left(x.im \cdot y.re - x.re \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-frac76.8%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} \]
      4. hypot-define76.8%

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, x.re \cdot \left(-y.im\right)\right)}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    4. Applied egg-rr97.0%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{\mathsf{fma}\left(x.im, y.re, x.re \cdot \left(-y.im\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}} \]
    5. Step-by-step derivation
      1. associate-*r/97.1%

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

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

    if 9.9999999999999993e260 < (/.f64 (-.f64 (*.f64 x.im y.re) (*.f64 x.re y.im)) (+.f64 (*.f64 y.re y.re) (*.f64 y.im y.im)))

    1. Initial program 21.8%

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub15.6%

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

        \[\leadsto \frac{\color{blue}{y.re \cdot x.im}}{y.re \cdot y.re + y.im \cdot y.im} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      3. add-sqr-sqrt15.6%

        \[\leadsto \frac{y.re \cdot x.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}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      4. times-frac19.9%

        \[\leadsto \color{blue}{\frac{y.re}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}} - \frac{x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
      5. fma-neg19.9%

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -\color{blue}{x.re \cdot \frac{y.im}{y.re \cdot y.re + y.im \cdot y.im}}\right) \]
      9. add-sqr-sqrt67.8%

        \[\leadsto \mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{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}}}\right) \]
      10. pow267.8%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, -x.re \cdot \frac{y.im}{{\left(\mathsf{hypot}\left(y.re, y.im\right)\right)}^{2}}\right)} \]
    5. Taylor expanded in y.im around inf 72.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+261}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \mathsf{fma}\left(x.im, y.re, y.im \cdot \left(-x.re\right)\right)}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.re}{-y.im}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \mathbf{if}\;y.re \leq -6.5 \cdot 10^{-24}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 2.05 \cdot 10^{-101}:\\ \;\;\;\;\frac{x.im \cdot \frac{y.re}{y.im} - x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 2.4 \cdot 10^{+115}:\\ \;\;\;\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ (- x.im (* x.re (/ y.im y.re))) y.re)))
   (if (<= y.re -6.5e-24)
     t_0
     (if (<= y.re 2.05e-101)
       (/ (- (* x.im (/ y.re y.im)) x.re) y.im)
       (if (<= y.re 2.4e+115)
         (/ (- (* y.re x.im) (* y.im x.re)) (+ (* y.re y.re) (* y.im y.im)))
         t_0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	double tmp;
	if (y_46_re <= -6.5e-24) {
		tmp = t_0;
	} else if (y_46_re <= 2.05e-101) {
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_46_re) / y_46_im;
	} else if (y_46_re <= 2.4e+115) {
		tmp = ((y_46_re * x_46_im) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} 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 = (x_46im - (x_46re * (y_46im / y_46re))) / y_46re
    if (y_46re <= (-6.5d-24)) then
        tmp = t_0
    else if (y_46re <= 2.05d-101) then
        tmp = ((x_46im * (y_46re / y_46im)) - x_46re) / y_46im
    else if (y_46re <= 2.4d+115) then
        tmp = ((y_46re * x_46im) - (y_46im * x_46re)) / ((y_46re * y_46re) + (y_46im * y_46im))
    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 = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	double tmp;
	if (y_46_re <= -6.5e-24) {
		tmp = t_0;
	} else if (y_46_re <= 2.05e-101) {
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_46_re) / y_46_im;
	} else if (y_46_re <= 2.4e+115) {
		tmp = ((y_46_re * x_46_im) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	t_0 = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re
	tmp = 0
	if y_46_re <= -6.5e-24:
		tmp = t_0
	elif y_46_re <= 2.05e-101:
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_46_re) / y_46_im
	elif y_46_re <= 2.4e+115:
		tmp = ((y_46_re * x_46_im) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
	else:
		tmp = t_0
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(x_46_im - Float64(x_46_re * Float64(y_46_im / y_46_re))) / y_46_re)
	tmp = 0.0
	if (y_46_re <= -6.5e-24)
		tmp = t_0;
	elseif (y_46_re <= 2.05e-101)
		tmp = Float64(Float64(Float64(x_46_im * Float64(y_46_re / y_46_im)) - x_46_re) / y_46_im);
	elseif (y_46_re <= 2.4e+115)
		tmp = Float64(Float64(Float64(y_46_re * x_46_im) - Float64(y_46_im * x_46_re)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)));
	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 = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	tmp = 0.0;
	if (y_46_re <= -6.5e-24)
		tmp = t_0;
	elseif (y_46_re <= 2.05e-101)
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_46_re) / y_46_im;
	elseif (y_46_re <= 2.4e+115)
		tmp = ((y_46_re * x_46_im) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	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[(x$46$im - N[(x$46$re * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -6.5e-24], t$95$0, If[LessEqual[y$46$re, 2.05e-101], N[(N[(N[(x$46$im * N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 2.4e+115], N[(N[(N[(y$46$re * x$46$im), $MachinePrecision] - N[(y$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\
\mathbf{if}\;y.re \leq -6.5 \cdot 10^{-24}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -6.5e-24 or 2.4e115 < y.re

    1. Initial program 46.7%

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

      \[\leadsto \color{blue}{\frac{x.im + -1 \cdot \frac{x.re \cdot y.im}{y.re}}{y.re}} \]
    4. Step-by-step derivation
      1. mul-1-neg80.8%

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

        \[\leadsto \frac{\color{blue}{x.im - \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      3. unsub-neg80.8%

        \[\leadsto \frac{\color{blue}{x.im + \left(-\frac{x.re \cdot y.im}{y.re}\right)}}{y.re} \]
      4. remove-double-neg80.8%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot x.im + \frac{x.re \cdot y.im}{y.re}\right)}}{y.re} \]
      9. distribute-lft-in80.8%

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot x.im\right) - \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      12. neg-mul-180.8%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot x.im\right)} - \frac{x.re \cdot y.im}{y.re}}{y.re} \]
      13. mul-1-neg80.8%

        \[\leadsto \frac{\left(-\color{blue}{\left(-x.im\right)}\right) - \frac{x.re \cdot y.im}{y.re}}{y.re} \]
      14. remove-double-neg80.8%

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

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

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

    if -6.5e-24 < y.re < 2.05000000000000013e-101

    1. Initial program 70.5%

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

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

        \[\leadsto \color{blue}{\frac{x.im \cdot y.re}{{y.im}^{2}} + -1 \cdot \frac{x.re}{y.im}} \]
      2. mul-1-neg79.4%

        \[\leadsto \frac{x.im \cdot y.re}{{y.im}^{2}} + \color{blue}{\left(-\frac{x.re}{y.im}\right)} \]
      3. unsub-neg79.4%

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

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

        \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re}{y.im}}{y.im}} - \frac{x.re}{y.im} \]
      6. div-sub89.4%

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

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

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

    if 2.05000000000000013e-101 < y.re < 2.4e115

    1. Initial program 89.8%

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification86.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -6.5 \cdot 10^{-24}:\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \mathbf{elif}\;y.re \leq 2.05 \cdot 10^{-101}:\\ \;\;\;\;\frac{x.im \cdot \frac{y.re}{y.im} - x.re}{y.im}\\ \mathbf{elif}\;y.re \leq 2.4 \cdot 10^{+115}:\\ \;\;\;\;\frac{y.re \cdot x.im - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 70.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.5 \cdot 10^{-25} \lor \neg \left(y.re \leq 2.5 \cdot 10^{-41}\right):\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{-y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -6.5e-25) (not (<= y.re 2.5e-41)))
   (/ (- x.im (* x.re (/ y.im y.re))) y.re)
   (/ x.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_re <= -6.5e-25) || !(y_46_re <= 2.5e-41)) {
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	} else {
		tmp = x_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_46re <= (-6.5d-25)) .or. (.not. (y_46re <= 2.5d-41))) then
        tmp = (x_46im - (x_46re * (y_46im / y_46re))) / y_46re
    else
        tmp = x_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_re <= -6.5e-25) || !(y_46_re <= 2.5e-41)) {
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	} else {
		tmp = x_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_re <= -6.5e-25) or not (y_46_re <= 2.5e-41):
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re
	else:
		tmp = x_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_re <= -6.5e-25) || !(y_46_re <= 2.5e-41))
		tmp = Float64(Float64(x_46_im - Float64(x_46_re * Float64(y_46_im / y_46_re))) / y_46_re);
	else
		tmp = Float64(x_46_re / Float64(-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 <= -6.5e-25) || ~((y_46_re <= 2.5e-41)))
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	else
		tmp = x_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$re, -6.5e-25], N[Not[LessEqual[y$46$re, 2.5e-41]], $MachinePrecision]], N[(N[(x$46$im - N[(x$46$re * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision], N[(x$46$re / (-y$46$im)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.5 \cdot 10^{-25} \lor \neg \left(y.re \leq 2.5 \cdot 10^{-41}\right):\\
\;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -6.5e-25 or 2.4999999999999998e-41 < y.re

    1. Initial program 55.7%

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

      \[\leadsto \color{blue}{\frac{x.im + -1 \cdot \frac{x.re \cdot y.im}{y.re}}{y.re}} \]
    4. Step-by-step derivation
      1. mul-1-neg80.2%

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

        \[\leadsto \frac{\color{blue}{x.im - \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      3. unsub-neg80.2%

        \[\leadsto \frac{\color{blue}{x.im + \left(-\frac{x.re \cdot y.im}{y.re}\right)}}{y.re} \]
      4. remove-double-neg80.2%

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

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

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

        \[\leadsto \frac{-1 \cdot \left(-1 \cdot x.im\right) + \color{blue}{-1 \cdot \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      8. distribute-lft-in80.2%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot x.im + \frac{x.re \cdot y.im}{y.re}\right)}}{y.re} \]
      9. distribute-lft-in80.2%

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot x.im\right) - \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      12. neg-mul-180.2%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot x.im\right)} - \frac{x.re \cdot y.im}{y.re}}{y.re} \]
      13. mul-1-neg80.2%

        \[\leadsto \frac{\left(-\color{blue}{\left(-x.im\right)}\right) - \frac{x.re \cdot y.im}{y.re}}{y.re} \]
      14. remove-double-neg80.2%

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

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

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

    if -6.5e-25 < y.re < 2.4999999999999998e-41

    1. Initial program 71.1%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x.re}{y.im}} \]
    4. Step-by-step derivation
      1. associate-*r/69.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot x.re}{y.im}} \]
      2. neg-mul-169.1%

        \[\leadsto \frac{\color{blue}{-x.re}}{y.im} \]
    5. Simplified69.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -6.5 \cdot 10^{-25} \lor \neg \left(y.re \leq 2.5 \cdot 10^{-41}\right):\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{-y.im}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -4.8 \cdot 10^{-25} \lor \neg \left(y.re \leq 62000000\right):\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im \cdot \frac{y.re}{y.im} - x.re}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -4.8e-25) (not (<= y.re 62000000.0)))
   (/ (- x.im (* x.re (/ y.im y.re))) y.re)
   (/ (- (* x.im (/ y.re y.im)) x.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_re <= -4.8e-25) || !(y_46_re <= 62000000.0)) {
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	} else {
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_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_46re <= (-4.8d-25)) .or. (.not. (y_46re <= 62000000.0d0))) then
        tmp = (x_46im - (x_46re * (y_46im / y_46re))) / y_46re
    else
        tmp = ((x_46im * (y_46re / y_46im)) - x_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_re <= -4.8e-25) || !(y_46_re <= 62000000.0)) {
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	} else {
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_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_re <= -4.8e-25) or not (y_46_re <= 62000000.0):
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re
	else:
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_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_re <= -4.8e-25) || !(y_46_re <= 62000000.0))
		tmp = Float64(Float64(x_46_im - Float64(x_46_re * Float64(y_46_im / y_46_re))) / y_46_re);
	else
		tmp = Float64(Float64(Float64(x_46_im * Float64(y_46_re / y_46_im)) - x_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_re <= -4.8e-25) || ~((y_46_re <= 62000000.0)))
		tmp = (x_46_im - (x_46_re * (y_46_im / y_46_re))) / y_46_re;
	else
		tmp = ((x_46_im * (y_46_re / y_46_im)) - x_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$re, -4.8e-25], N[Not[LessEqual[y$46$re, 62000000.0]], $MachinePrecision]], N[(N[(x$46$im - N[(x$46$re * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision], N[(N[(N[(x$46$im * N[(y$46$re / y$46$im), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -4.8 \cdot 10^{-25} \lor \neg \left(y.re \leq 62000000\right):\\
\;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -4.80000000000000018e-25 or 6.2e7 < y.re

    1. Initial program 53.8%

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

      \[\leadsto \color{blue}{\frac{x.im + -1 \cdot \frac{x.re \cdot y.im}{y.re}}{y.re}} \]
    4. Step-by-step derivation
      1. mul-1-neg81.5%

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

        \[\leadsto \frac{\color{blue}{x.im - \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      3. unsub-neg81.5%

        \[\leadsto \frac{\color{blue}{x.im + \left(-\frac{x.re \cdot y.im}{y.re}\right)}}{y.re} \]
      4. remove-double-neg81.5%

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

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

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

        \[\leadsto \frac{-1 \cdot \left(-1 \cdot x.im\right) + \color{blue}{-1 \cdot \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      8. distribute-lft-in81.5%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot x.im + \frac{x.re \cdot y.im}{y.re}\right)}}{y.re} \]
      9. distribute-lft-in81.5%

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

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

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot x.im\right) - \frac{x.re \cdot y.im}{y.re}}}{y.re} \]
      12. neg-mul-181.5%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot x.im\right)} - \frac{x.re \cdot y.im}{y.re}}{y.re} \]
      13. mul-1-neg81.5%

        \[\leadsto \frac{\left(-\color{blue}{\left(-x.im\right)}\right) - \frac{x.re \cdot y.im}{y.re}}{y.re} \]
      14. remove-double-neg81.5%

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

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

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

    if -4.80000000000000018e-25 < y.re < 6.2e7

    1. Initial program 72.5%

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

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

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

        \[\leadsto \frac{x.im \cdot y.re}{{y.im}^{2}} + \color{blue}{\left(-\frac{x.re}{y.im}\right)} \]
      3. unsub-neg77.7%

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

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

        \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re}{y.im}}{y.im}} - \frac{x.re}{y.im} \]
      6. div-sub86.3%

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

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

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

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

Alternative 8: 63.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-18} \lor \neg \left(y.re \leq 3.55 \cdot 10^{-43}\right):\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{-y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -6.1e-18) (not (<= y.re 3.55e-43)))
   (/ x.im y.re)
   (/ x.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_re <= -6.1e-18) || !(y_46_re <= 3.55e-43)) {
		tmp = x_46_im / y_46_re;
	} else {
		tmp = x_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_46re <= (-6.1d-18)) .or. (.not. (y_46re <= 3.55d-43))) then
        tmp = x_46im / y_46re
    else
        tmp = x_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_re <= -6.1e-18) || !(y_46_re <= 3.55e-43)) {
		tmp = x_46_im / y_46_re;
	} else {
		tmp = x_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_re <= -6.1e-18) or not (y_46_re <= 3.55e-43):
		tmp = x_46_im / y_46_re
	else:
		tmp = x_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_re <= -6.1e-18) || !(y_46_re <= 3.55e-43))
		tmp = Float64(x_46_im / y_46_re);
	else
		tmp = Float64(x_46_re / Float64(-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 <= -6.1e-18) || ~((y_46_re <= 3.55e-43)))
		tmp = x_46_im / y_46_re;
	else
		tmp = x_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$re, -6.1e-18], N[Not[LessEqual[y$46$re, 3.55e-43]], $MachinePrecision]], N[(x$46$im / y$46$re), $MachinePrecision], N[(x$46$re / (-y$46$im)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.1 \cdot 10^{-18} \lor \neg \left(y.re \leq 3.55 \cdot 10^{-43}\right):\\
\;\;\;\;\frac{x.im}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -6.0999999999999999e-18 or 3.55000000000000013e-43 < y.re

    1. Initial program 55.7%

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

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

    if -6.0999999999999999e-18 < y.re < 3.55000000000000013e-43

    1. Initial program 71.1%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x.re}{y.im}} \]
    4. Step-by-step derivation
      1. associate-*r/69.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot x.re}{y.im}} \]
      2. neg-mul-169.1%

        \[\leadsto \frac{\color{blue}{-x.re}}{y.im} \]
    5. Simplified69.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-18} \lor \neg \left(y.re \leq 3.55 \cdot 10^{-43}\right):\\ \;\;\;\;\frac{x.im}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{-y.im}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 42.1% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{x.im}{y.re} \end{array} \]
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ x.im y.re))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return x_46_im / y_46_re;
}
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_46re
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_re;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return x_46_im / y_46_re
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(x_46_im / y_46_re)
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = x_46_im / y_46_re;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im / y$46$re), $MachinePrecision]
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{\frac{x.im}{y.re}} \]
  4. Final simplification42.7%

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

Reproduce

?
herbie shell --seed 2024066 
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  :precision binary64
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))