_divideComplex, real part

Percentage Accurate: 62.0% → 80.5%
Time: 2.6s
Alternatives: 7
Speedup: 1.8×

Specification

?
\[\begin{array}{l} \\ \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

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: 62.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

Alternative 1: 80.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{if}\;y.re \leq -1.6 \cdot 10^{+67}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq -4.5 \cdot 10^{-80}:\\ \;\;\;\;\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\ \;\;\;\;-\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(-x.im\right)}{y.im}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
   (if (<= y.re -1.6e+67)
     t_0
     (if (<= y.re -4.5e-80)
       (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))
       (if (<= y.re 1.25e+30)
         (- (/ (+ (- (/ (* y.re x.re) y.im)) (- x.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 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	double tmp;
	if (y_46_re <= -1.6e+67) {
		tmp = t_0;
	} else if (y_46_re <= -4.5e-80) {
		tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	} else if (y_46_re <= 1.25e+30) {
		tmp = -((-((y_46_re * x_46_re) / y_46_im) + -x_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(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re)
	tmp = 0.0
	if (y_46_re <= -1.6e+67)
		tmp = t_0;
	elseif (y_46_re <= -4.5e-80)
		tmp = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)));
	elseif (y_46_re <= 1.25e+30)
		tmp = Float64(-Float64(Float64(Float64(-Float64(Float64(y_46_re * x_46_re) / y_46_im)) + Float64(-x_46_im)) / y_46_im));
	else
		tmp = t_0;
	end
	return 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[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -1.6e+67], t$95$0, If[LessEqual[y$46$re, -4.5e-80], N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.25e+30], (-N[(N[((-N[(N[(y$46$re * x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision]) + (-x$46$im)), $MachinePrecision] / y$46$im), $MachinePrecision]), t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\
\;\;\;\;-\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(-x.im\right)}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -1.59999999999999991e67 or 1.25e30 < y.re

    1. Initial program 44.6%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.re + \frac{x.im \cdot y.im}{y.re}}{\color{blue}{y.re}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.im \cdot y.im}{y.re} + x.re}{y.re} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.im \cdot \frac{y.im}{y.re} + x.re}{y.re} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
      5. lower-/.f6478.9

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
    4. Applied rewrites78.9%

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

    if -1.59999999999999991e67 < y.re < -4.5000000000000003e-80

    1. Initial program 77.4%

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

    if -4.5000000000000003e-80 < y.re < 1.25e30

    1. Initial program 73.4%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im}\right) \]
      2. lower-neg.f64N/A

        \[\leadsto -\frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im} \]
      3. lower-/.f64N/A

        \[\leadsto -\frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im} \]
      4. +-commutativeN/A

        \[\leadsto -\frac{-1 \cdot \frac{x.re \cdot y.re}{y.im} + -1 \cdot x.im}{y.im} \]
      5. lower-+.f64N/A

        \[\leadsto -\frac{-1 \cdot \frac{x.re \cdot y.re}{y.im} + -1 \cdot x.im}{y.im} \]
      6. mul-1-negN/A

        \[\leadsto -\frac{\left(\mathsf{neg}\left(\frac{x.re \cdot y.re}{y.im}\right)\right) + -1 \cdot x.im}{y.im} \]
      7. lower-neg.f64N/A

        \[\leadsto -\frac{\left(-\frac{x.re \cdot y.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      8. lower-/.f64N/A

        \[\leadsto -\frac{\left(-\frac{x.re \cdot y.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      9. *-commutativeN/A

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      10. lower-*.f64N/A

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      11. mul-1-negN/A

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(\mathsf{neg}\left(x.im\right)\right)}{y.im} \]
      12. lower-neg.f6482.6

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(-x.im\right)}{y.im} \]
    4. Applied rewrites82.6%

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

Alternative 2: 78.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{if}\;y.re \leq -2.65 \cdot 10^{+59}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq -8 \cdot 10^{-80}:\\ \;\;\;\;x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\ \mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\ \;\;\;\;-\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(-x.im\right)}{y.im}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
   (if (<= y.re -2.65e+59)
     t_0
     (if (<= y.re -8e-80)
       (* x.re (/ y.re (fma y.im y.im (* y.re y.re))))
       (if (<= y.re 1.25e+30)
         (- (/ (+ (- (/ (* y.re x.re) y.im)) (- x.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 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	double tmp;
	if (y_46_re <= -2.65e+59) {
		tmp = t_0;
	} else if (y_46_re <= -8e-80) {
		tmp = x_46_re * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
	} else if (y_46_re <= 1.25e+30) {
		tmp = -((-((y_46_re * x_46_re) / y_46_im) + -x_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(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re)
	tmp = 0.0
	if (y_46_re <= -2.65e+59)
		tmp = t_0;
	elseif (y_46_re <= -8e-80)
		tmp = Float64(x_46_re * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))));
	elseif (y_46_re <= 1.25e+30)
		tmp = Float64(-Float64(Float64(Float64(-Float64(Float64(y_46_re * x_46_re) / y_46_im)) + Float64(-x_46_im)) / y_46_im));
	else
		tmp = t_0;
	end
	return 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[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -2.65e+59], t$95$0, If[LessEqual[y$46$re, -8e-80], N[(x$46$re * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.25e+30], (-N[(N[((-N[(N[(y$46$re * x$46$re), $MachinePrecision] / y$46$im), $MachinePrecision]) + (-x$46$im)), $MachinePrecision] / y$46$im), $MachinePrecision]), t$95$0]]]]
\begin{array}{l}

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

\mathbf{elif}\;y.re \leq -8 \cdot 10^{-80}:\\
\;\;\;\;x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\

\mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\
\;\;\;\;-\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(-x.im\right)}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -2.6499999999999998e59 or 1.25e30 < y.re

    1. Initial program 45.0%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.re + \frac{x.im \cdot y.im}{y.re}}{\color{blue}{y.re}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.im \cdot y.im}{y.re} + x.re}{y.re} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.im \cdot \frac{y.im}{y.re} + x.re}{y.re} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
      5. lower-/.f6478.7

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
    4. Applied rewrites78.7%

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

    if -2.6499999999999998e59 < y.re < -7.99999999999999969e-80

    1. Initial program 78.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in x.re around inf

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

        \[\leadsto x.re \cdot \color{blue}{\frac{y.re}{{y.im}^{2} + {y.re}^{2}}} \]
      2. lower-*.f64N/A

        \[\leadsto x.re \cdot \color{blue}{\frac{y.re}{{y.im}^{2} + {y.re}^{2}}} \]
      3. lower-/.f64N/A

        \[\leadsto x.re \cdot \frac{y.re}{\color{blue}{{y.im}^{2} + {y.re}^{2}}} \]
      4. pow2N/A

        \[\leadsto x.re \cdot \frac{y.re}{y.im \cdot y.im + {\color{blue}{y.re}}^{2}} \]
      5. lower-fma.f64N/A

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, \color{blue}{y.im}, {y.re}^{2}\right)} \]
      6. pow2N/A

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \]
      7. lift-*.f6454.7

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \]
    4. Applied rewrites54.7%

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

    if -7.99999999999999969e-80 < y.re < 1.25e30

    1. Initial program 73.4%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    3. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im}\right) \]
      2. lower-neg.f64N/A

        \[\leadsto -\frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im} \]
      3. lower-/.f64N/A

        \[\leadsto -\frac{-1 \cdot x.im + -1 \cdot \frac{x.re \cdot y.re}{y.im}}{y.im} \]
      4. +-commutativeN/A

        \[\leadsto -\frac{-1 \cdot \frac{x.re \cdot y.re}{y.im} + -1 \cdot x.im}{y.im} \]
      5. lower-+.f64N/A

        \[\leadsto -\frac{-1 \cdot \frac{x.re \cdot y.re}{y.im} + -1 \cdot x.im}{y.im} \]
      6. mul-1-negN/A

        \[\leadsto -\frac{\left(\mathsf{neg}\left(\frac{x.re \cdot y.re}{y.im}\right)\right) + -1 \cdot x.im}{y.im} \]
      7. lower-neg.f64N/A

        \[\leadsto -\frac{\left(-\frac{x.re \cdot y.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      8. lower-/.f64N/A

        \[\leadsto -\frac{\left(-\frac{x.re \cdot y.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      9. *-commutativeN/A

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      10. lower-*.f64N/A

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + -1 \cdot x.im}{y.im} \]
      11. mul-1-negN/A

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(\mathsf{neg}\left(x.im\right)\right)}{y.im} \]
      12. lower-neg.f6482.6

        \[\leadsto -\frac{\left(-\frac{y.re \cdot x.re}{y.im}\right) + \left(-x.im\right)}{y.im} \]
    4. Applied rewrites82.6%

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

Alternative 3: 77.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{if}\;y.re \leq -2.65 \cdot 10^{+59}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq -8 \cdot 10^{-80}:\\ \;\;\;\;x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\ \mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
   (if (<= y.re -2.65e+59)
     t_0
     (if (<= y.re -8e-80)
       (* x.re (/ y.re (fma y.im y.im (* y.re y.re))))
       (if (<= y.re 1.25e+30) (/ (fma x.re (/ y.re y.im) x.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 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	double tmp;
	if (y_46_re <= -2.65e+59) {
		tmp = t_0;
	} else if (y_46_re <= -8e-80) {
		tmp = x_46_re * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
	} else if (y_46_re <= 1.25e+30) {
		tmp = fma(x_46_re, (y_46_re / y_46_im), x_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(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re)
	tmp = 0.0
	if (y_46_re <= -2.65e+59)
		tmp = t_0;
	elseif (y_46_re <= -8e-80)
		tmp = Float64(x_46_re * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))));
	elseif (y_46_re <= 1.25e+30)
		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
	else
		tmp = t_0;
	end
	return 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[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -2.65e+59], t$95$0, If[LessEqual[y$46$re, -8e-80], N[(x$46$re * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.25e+30], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

\mathbf{elif}\;y.re \leq -8 \cdot 10^{-80}:\\
\;\;\;\;x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\

\mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -2.6499999999999998e59 or 1.25e30 < y.re

    1. Initial program 45.0%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.re + \frac{x.im \cdot y.im}{y.re}}{\color{blue}{y.re}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.im \cdot y.im}{y.re} + x.re}{y.re} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.im \cdot \frac{y.im}{y.re} + x.re}{y.re} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
      5. lower-/.f6478.7

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
    4. Applied rewrites78.7%

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

    if -2.6499999999999998e59 < y.re < -7.99999999999999969e-80

    1. Initial program 78.1%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in x.re around inf

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

        \[\leadsto x.re \cdot \color{blue}{\frac{y.re}{{y.im}^{2} + {y.re}^{2}}} \]
      2. lower-*.f64N/A

        \[\leadsto x.re \cdot \color{blue}{\frac{y.re}{{y.im}^{2} + {y.re}^{2}}} \]
      3. lower-/.f64N/A

        \[\leadsto x.re \cdot \frac{y.re}{\color{blue}{{y.im}^{2} + {y.re}^{2}}} \]
      4. pow2N/A

        \[\leadsto x.re \cdot \frac{y.re}{y.im \cdot y.im + {\color{blue}{y.re}}^{2}} \]
      5. lower-fma.f64N/A

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, \color{blue}{y.im}, {y.re}^{2}\right)} \]
      6. pow2N/A

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \]
      7. lift-*.f6454.7

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \]
    4. Applied rewrites54.7%

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

    if -7.99999999999999969e-80 < y.re < 1.25e30

    1. Initial program 73.4%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.im around inf

      \[\leadsto \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.im + \frac{x.re \cdot y.re}{y.im}}{\color{blue}{y.im}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.re \cdot y.re}{y.im} + x.im}{y.im} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.re \cdot \frac{y.re}{y.im} + x.im}{y.im} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im} \]
      5. lower-/.f6482.7

        \[\leadsto \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im} \]
    4. Applied rewrites82.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 77.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{if}\;y.re \leq -2.6 \cdot 10^{-21}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
   (if (<= y.re -2.6e-21)
     t_0
     (if (<= y.re 1.25e+30) (/ (fma x.re (/ y.re y.im) x.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 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	double tmp;
	if (y_46_re <= -2.6e-21) {
		tmp = t_0;
	} else if (y_46_re <= 1.25e+30) {
		tmp = fma(x_46_re, (y_46_re / y_46_im), x_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(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re)
	tmp = 0.0
	if (y_46_re <= -2.6e-21)
		tmp = t_0;
	elseif (y_46_re <= 1.25e+30)
		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
	else
		tmp = t_0;
	end
	return 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[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -2.6e-21], t$95$0, If[LessEqual[y$46$re, 1.25e+30], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;y.re \leq 1.25 \cdot 10^{+30}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -2.60000000000000017e-21 or 1.25e30 < y.re

    1. Initial program 49.2%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.re + \frac{x.im \cdot y.im}{y.re}}{\color{blue}{y.re}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.im \cdot y.im}{y.re} + x.re}{y.re} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.im \cdot \frac{y.im}{y.re} + x.re}{y.re} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
      5. lower-/.f6475.0

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
    4. Applied rewrites75.0%

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

    if -2.60000000000000017e-21 < y.re < 1.25e30

    1. Initial program 74.0%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.im around inf

      \[\leadsto \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.im + \frac{x.re \cdot y.re}{y.im}}{\color{blue}{y.im}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.re \cdot y.re}{y.im} + x.im}{y.im} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.re \cdot \frac{y.re}{y.im} + x.im}{y.im} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im} \]
      5. lower-/.f6480.8

        \[\leadsto \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im} \]
    4. Applied rewrites80.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 69.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{if}\;y.re \leq -4.6 \cdot 10^{-80}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 2.25 \cdot 10^{+17}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
   (if (<= y.re -4.6e-80) t_0 (if (<= y.re 2.25e+17) (/ x.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 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	double tmp;
	if (y_46_re <= -4.6e-80) {
		tmp = t_0;
	} else if (y_46_re <= 2.25e+17) {
		tmp = x_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(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re)
	tmp = 0.0
	if (y_46_re <= -4.6e-80)
		tmp = t_0;
	elseif (y_46_re <= 2.25e+17)
		tmp = Float64(x_46_im / y_46_im);
	else
		tmp = t_0;
	end
	return 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[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -4.6e-80], t$95$0, If[LessEqual[y$46$re, 2.25e+17], N[(x$46$im / y$46$im), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -4.5999999999999996e-80 or 2.25e17 < y.re

    1. Initial program 52.3%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{x.re + \frac{x.im \cdot y.im}{y.re}}{\color{blue}{y.re}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{\frac{x.im \cdot y.im}{y.re} + x.re}{y.re} \]
      3. associate-/l*N/A

        \[\leadsto \frac{x.im \cdot \frac{y.im}{y.re} + x.re}{y.re} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
      5. lower-/.f6471.9

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
    4. Applied rewrites71.9%

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

    if -4.5999999999999996e-80 < y.re < 2.25e17

    1. Initial program 73.5%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around 0

      \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
    3. Step-by-step derivation
      1. lower-/.f6466.6

        \[\leadsto \frac{x.im}{\color{blue}{y.im}} \]
    4. Applied rewrites66.6%

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

Alternative 6: 63.8% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -1.85 \cdot 10^{-30}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.re \leq 2.25 \cdot 10^{+17}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (<= y.re -1.85e-30)
   (/ x.re y.re)
   (if (<= y.re 2.25e+17) (/ x.im y.im) (/ x.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_re <= -1.85e-30) {
		tmp = x_46_re / y_46_re;
	} else if (y_46_re <= 2.25e+17) {
		tmp = x_46_im / y_46_im;
	} else {
		tmp = x_46_re / y_46_re;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
    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 <= (-1.85d-30)) then
        tmp = x_46re / y_46re
    else if (y_46re <= 2.25d+17) then
        tmp = x_46im / y_46im
    else
        tmp = x_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_re <= -1.85e-30) {
		tmp = x_46_re / y_46_re;
	} else if (y_46_re <= 2.25e+17) {
		tmp = x_46_im / y_46_im;
	} else {
		tmp = x_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_re <= -1.85e-30:
		tmp = x_46_re / y_46_re
	elif y_46_re <= 2.25e+17:
		tmp = x_46_im / y_46_im
	else:
		tmp = x_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_re <= -1.85e-30)
		tmp = Float64(x_46_re / y_46_re);
	elseif (y_46_re <= 2.25e+17)
		tmp = Float64(x_46_im / y_46_im);
	else
		tmp = Float64(x_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_re <= -1.85e-30)
		tmp = x_46_re / y_46_re;
	elseif (y_46_re <= 2.25e+17)
		tmp = x_46_im / y_46_im;
	else
		tmp = x_46_re / y_46_re;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -1.85e-30], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 2.25e+17], N[(x$46$im / y$46$im), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -1.85 \cdot 10^{-30}:\\
\;\;\;\;\frac{x.re}{y.re}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -1.8500000000000002e-30 or 2.25e17 < y.re

    1. Initial program 50.2%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around inf

      \[\leadsto \color{blue}{\frac{x.re}{y.re}} \]
    3. Step-by-step derivation
      1. lower-/.f6462.7

        \[\leadsto \frac{x.re}{\color{blue}{y.re}} \]
    4. Applied rewrites62.7%

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

    if -1.8500000000000002e-30 < y.re < 2.25e17

    1. Initial program 73.9%

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
    2. Taylor expanded in y.re around 0

      \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
    3. Step-by-step derivation
      1. lower-/.f6464.8

        \[\leadsto \frac{x.im}{\color{blue}{y.im}} \]
    4. Applied rewrites64.8%

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

Alternative 7: 43.7% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{x.im}{y.im} \end{array} \]
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ x.im y.im))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return x_46_im / y_46_im;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

    \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im} \]
  2. Taylor expanded in y.re around 0

    \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
  3. Step-by-step derivation
    1. lower-/.f6443.7

      \[\leadsto \frac{x.im}{\color{blue}{y.im}} \]
  4. Applied rewrites43.7%

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

Reproduce

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