_divideComplex, imaginary part

Percentage Accurate: 61.5% → 98.6%
Time: 12.9s
Alternatives: 7
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 7 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: 61.5% 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: 98.6% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\right)} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/
  (- (* x.im (/ y.re (hypot y.re y.im))) (* y.im (/ x.re (hypot y.re y.im))))
  (hypot y.re 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 / hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / hypot(y_46_re, y_46_im)))) / hypot(y_46_re, y_46_im);
}
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 / Math.hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / Math.hypot(y_46_re, y_46_im)))) / Math.hypot(y_46_re, y_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return ((x_46_im * (y_46_re / math.hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / math.hypot(y_46_re, y_46_im)))) / math.hypot(y_46_re, y_46_im)
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(Float64(x_46_im * Float64(y_46_re / hypot(y_46_re, y_46_im))) - Float64(y_46_im * Float64(x_46_re / hypot(y_46_re, y_46_im)))) / hypot(y_46_re, 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 / hypot(y_46_re, y_46_im))) - (y_46_im * (x_46_re / hypot(y_46_re, y_46_im)))) / hypot(y_46_re, y_46_im);
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$im * N[(y$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y$46$im * N[(x$46$re / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)} - y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.re, y.im\right)}}{\mathsf{hypot}\left(y.re, y.im\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-sub61.8%

      \[\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. *-un-lft-identity61.8%

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re\right)}}{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-sqrt61.8%

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re}{\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. fmm-def61.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}, \frac{x.im \cdot y.re}{\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-define61.8%

      \[\leadsto \mathsf{fma}\left(\frac{1}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{x.im \cdot y.re}{\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-define69.3%

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im \cdot y.re}{\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. fmm-undef71.1%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{x.im \cdot y.re}{\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}}} \]
    2. associate-/l*82.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \left(x.im \cdot \frac{y.re}{\mathsf{hypot}\left(y.re, y.im\right)}\right) - \color{blue}{\frac{y.im \cdot \frac{x.re}{\mathsf{hypot}\left(y.im, y.re\right)}}{\mathsf{hypot}\left(y.im, y.re\right)}} \]
  11. Step-by-step derivation
    1. *-un-lft-identity99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 84.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x.im \cdot y.re - y.im \cdot x.re\\ \mathbf{if}\;\frac{t\_0}{y.re \cdot y.re + y.im \cdot y.im} \leq 10^{+286}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(y.re, y.im\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{y.re \cdot \frac{x.im}{y.im} - x.re}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (- (* x.im y.re) (* y.im x.re))))
   (if (<= (/ t_0 (+ (* y.re y.re) (* y.im y.im))) 1e+286)
     (* (/ 1.0 (hypot y.re y.im)) (/ t_0 (hypot y.re y.im)))
     (/ (- (* y.re (/ x.im 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 t_0 = (x_46_im * y_46_re) - (y_46_im * x_46_re);
	double tmp;
	if ((t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 1e+286) {
		tmp = (1.0 / hypot(y_46_re, y_46_im)) * (t_0 / hypot(y_46_re, y_46_im));
	} else {
		tmp = ((y_46_re * (x_46_im / y_46_im)) - x_46_re) / y_46_im;
	}
	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_im * y_46_re) - (y_46_im * x_46_re);
	double tmp;
	if ((t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 1e+286) {
		tmp = (1.0 / Math.hypot(y_46_re, y_46_im)) * (t_0 / Math.hypot(y_46_re, y_46_im));
	} else {
		tmp = ((y_46_re * (x_46_im / 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):
	t_0 = (x_46_im * y_46_re) - (y_46_im * x_46_re)
	tmp = 0
	if (t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 1e+286:
		tmp = (1.0 / math.hypot(y_46_re, y_46_im)) * (t_0 / math.hypot(y_46_re, y_46_im))
	else:
		tmp = ((y_46_re * (x_46_im / 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)
	t_0 = Float64(Float64(x_46_im * y_46_re) - Float64(y_46_im * x_46_re))
	tmp = 0.0
	if (Float64(t_0 / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) <= 1e+286)
		tmp = Float64(Float64(1.0 / hypot(y_46_re, y_46_im)) * Float64(t_0 / hypot(y_46_re, y_46_im)));
	else
		tmp = Float64(Float64(Float64(y_46_re * Float64(x_46_im / 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)
	t_0 = (x_46_im * y_46_re) - (y_46_im * x_46_re);
	tmp = 0.0;
	if ((t_0 / ((y_46_re * y_46_re) + (y_46_im * y_46_im))) <= 1e+286)
		tmp = (1.0 / hypot(y_46_re, y_46_im)) * (t_0 / hypot(y_46_re, y_46_im));
	else
		tmp = ((y_46_re * (x_46_im / 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_] := Block[{t$95$0 = N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(y$46$im * x$46$re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+286], N[(N[(1.0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[y$46$re ^ 2 + y$46$im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y$46$re * N[(x$46$im / y$46$im), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision]]]
\begin{array}{l}

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

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


\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.00000000000000003e286

    1. Initial program 82.0%

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

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

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

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

        \[\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. hypot-define96.7%

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

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

    if 1.00000000000000003e286 < (/.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 9.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 42.5%

      \[\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. +-commutative42.5%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 80.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y.re \cdot \frac{x.im}{y.im} - x.re}{y.im}\\ \mathbf{if}\;y.im \leq -1.4 \cdot 10^{+106}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.im \leq -1.8 \cdot 10^{-110}:\\ \;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.im \leq 2.8 \cdot 10^{-16}:\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.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 (/ (- (* y.re (/ x.im y.im)) x.re) y.im)))
   (if (<= y.im -1.4e+106)
     t_0
     (if (<= y.im -1.8e-110)
       (/ (- (* x.im y.re) (* y.im x.re)) (+ (* y.re y.re) (* y.im y.im)))
       (if (<= y.im 2.8e-16) (/ (- x.im (* x.re (/ y.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 = ((y_46_re * (x_46_im / y_46_im)) - x_46_re) / y_46_im;
	double tmp;
	if (y_46_im <= -1.4e+106) {
		tmp = t_0;
	} else if (y_46_im <= -1.8e-110) {
		tmp = ((x_46_im * y_46_re) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} else if (y_46_im <= 2.8e-16) {
		tmp = (x_46_im - (x_46_re * (y_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 = ((y_46re * (x_46im / y_46im)) - x_46re) / y_46im
    if (y_46im <= (-1.4d+106)) then
        tmp = t_0
    else if (y_46im <= (-1.8d-110)) then
        tmp = ((x_46im * y_46re) - (y_46im * x_46re)) / ((y_46re * y_46re) + (y_46im * y_46im))
    else if (y_46im <= 2.8d-16) then
        tmp = (x_46im - (x_46re * (y_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 = ((y_46_re * (x_46_im / y_46_im)) - x_46_re) / y_46_im;
	double tmp;
	if (y_46_im <= -1.4e+106) {
		tmp = t_0;
	} else if (y_46_im <= -1.8e-110) {
		tmp = ((x_46_im * y_46_re) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} else if (y_46_im <= 2.8e-16) {
		tmp = (x_46_im - (x_46_re * (y_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 = ((y_46_re * (x_46_im / y_46_im)) - x_46_re) / y_46_im
	tmp = 0
	if y_46_im <= -1.4e+106:
		tmp = t_0
	elif y_46_im <= -1.8e-110:
		tmp = ((x_46_im * y_46_re) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
	elif y_46_im <= 2.8e-16:
		tmp = (x_46_im - (x_46_re * (y_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(Float64(y_46_re * Float64(x_46_im / y_46_im)) - x_46_re) / y_46_im)
	tmp = 0.0
	if (y_46_im <= -1.4e+106)
		tmp = t_0;
	elseif (y_46_im <= -1.8e-110)
		tmp = Float64(Float64(Float64(x_46_im * y_46_re) - Float64(y_46_im * x_46_re)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)));
	elseif (y_46_im <= 2.8e-16)
		tmp = Float64(Float64(x_46_im - Float64(x_46_re * Float64(y_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 = ((y_46_re * (x_46_im / y_46_im)) - x_46_re) / y_46_im;
	tmp = 0.0;
	if (y_46_im <= -1.4e+106)
		tmp = t_0;
	elseif (y_46_im <= -1.8e-110)
		tmp = ((x_46_im * y_46_re) - (y_46_im * x_46_re)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	elseif (y_46_im <= 2.8e-16)
		tmp = (x_46_im - (x_46_re * (y_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[(N[(y$46$re * N[(x$46$im / y$46$im), $MachinePrecision]), $MachinePrecision] - x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -1.4e+106], t$95$0, If[LessEqual[y$46$im, -1.8e-110], N[(N[(N[(x$46$im * y$46$re), $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], If[LessEqual[y$46$im, 2.8e-16], N[(N[(x$46$im - N[(x$46$re * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y.im \leq 2.8 \cdot 10^{-16}:\\
\;\;\;\;\frac{x.im - x.re \cdot \frac{y.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.39999999999999996e106 or 2.8000000000000001e-16 < y.im

    1. Initial program 50.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 74.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. +-commutative74.4%

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

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

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

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

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

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

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

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

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

    if -1.39999999999999996e106 < y.im < -1.79999999999999997e-110

    1. Initial program 75.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

    if -1.79999999999999997e-110 < y.im < 2.8000000000000001e-16

    1. Initial program 70.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. div-sub68.3%

        \[\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. *-un-lft-identity68.3%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re\right)}}{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-sqrt68.3%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re}{\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. fmm-def68.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}, \frac{x.im \cdot y.re}{\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-define68.3%

        \[\leadsto \mathsf{fma}\left(\frac{1}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{x.im \cdot y.re}{\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-define76.2%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im \cdot y.re}{\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. fmm-undef77.2%

        \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{x.im \cdot y.re}{\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}}} \]
      2. associate-/l*90.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -1.4 \cdot 10^{+106}:\\ \;\;\;\;\frac{y.re \cdot \frac{x.im}{y.im} - x.re}{y.im}\\ \mathbf{elif}\;y.im \leq -1.8 \cdot 10^{-110}:\\ \;\;\;\;\frac{x.im \cdot y.re - y.im \cdot x.re}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.im \leq 2.8 \cdot 10^{-16}:\\ \;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{y.re \cdot \frac{x.im}{y.im} - x.re}{y.im}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.4% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -1.78 \cdot 10^{+31} \lor \neg \left(y.im \leq 2.8 \cdot 10^{-16}\right):\\
\;\;\;\;\frac{y.re \cdot \frac{x.im}{y.im} - x.re}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.im < -1.7800000000000001e31 or 2.8000000000000001e-16 < y.im

    1. Initial program 54.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 72.8%

      \[\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. +-commutative72.8%

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

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

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

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

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

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

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

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

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

    if -1.7800000000000001e31 < y.im < 2.8000000000000001e-16

    1. Initial program 70.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-sub69.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. *-un-lft-identity69.1%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re\right)}}{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-sqrt69.1%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re}{\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. fmm-def69.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}, \frac{x.im \cdot y.re}{\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-define69.1%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)}, \frac{x.im \cdot y.re}{\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. fmm-undef78.6%

        \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{x.im \cdot y.re}{\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}}} \]
      2. associate-/l*93.1%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 72.1% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -9.2 \cdot 10^{+95} \lor \neg \left(y.im \leq 3.6 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{-x.re}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.im < -9.19999999999999989e95 or 3.6000000000000001e-19 < y.im

    1. Initial program 50.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 74.6%

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

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

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

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

    if -9.19999999999999989e95 < y.im < 3.6000000000000001e-19

    1. Initial program 72.0%

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

        \[\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. *-un-lft-identity70.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(x.im \cdot y.re\right)}}{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-sqrt70.5%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.im \cdot y.re}{\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. fmm-def70.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}, \frac{x.im \cdot y.re}{\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-define70.5%

        \[\leadsto \mathsf{fma}\left(\frac{1}{\color{blue}{\mathsf{hypot}\left(y.re, y.im\right)}}, \frac{x.im \cdot y.re}{\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-define79.2%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(y.re, y.im\right)} \cdot \frac{x.im \cdot y.re}{\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}}} \]
      2. associate-/l*93.7%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 62.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -1.2 \cdot 10^{+96} \lor \neg \left(y.im \leq 2.3 \cdot 10^{-39}\right):\\
\;\;\;\;\frac{-x.re}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.im < -1.19999999999999996e96 or 2.30000000000000008e-39 < y.im

    1. Initial program 51.4%

      \[\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 73.1%

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

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

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

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

    if -1.19999999999999996e96 < y.im < 2.30000000000000008e-39

    1. Initial program 72.0%

      \[\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 69.7%

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

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

Alternative 7: 43.6% 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 46.6%

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

Reproduce

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