_divideComplex, real part

Percentage Accurate: 61.4% → 82.4%
Time: 3.7s
Alternatives: 11
Speedup: 1.6×

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}

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 11 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.4% 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: 82.4% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y.re \leq -1.2 \cdot 10^{-77}:\\
\;\;\;\;\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 5.8 \cdot 10^{-80}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if y.re < -2.2000000000000001e49

    1. Initial program 37.0%

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

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

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

        \[\leadsto \frac{x.im \cdot y.im}{y.re \cdot y.re} + \frac{x.re}{y.re} \]
      3. times-fracN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \color{blue}{\frac{y.im}{y.re}}, \frac{x.re}{y.re}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      7. lower-/.f6488.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{y.re}, \frac{x.re}{y.re}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\mathsf{neg}\left(y.im\right)}{\color{blue}{\mathsf{neg}\left(y.re\right)}}, \frac{x.re}{y.re}\right) \]
      3. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{-1 \cdot y.im}{\mathsf{neg}\left(\color{blue}{y.re}\right)}, \frac{x.re}{y.re}\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im \cdot -1}{\mathsf{neg}\left(\color{blue}{y.re}\right)}, \frac{x.re}{y.re}\right) \]
      5. mul-1-negN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{-1} \cdot \color{blue}{\frac{-1}{y.re}}, \frac{x.re}{y.re}\right) \]
      7. lower-*.f64N/A

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

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

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

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

    if -2.2000000000000001e49 < y.re < -1.19999999999999995e-77

    1. Initial program 99.3%

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

    if -1.19999999999999995e-77 < y.re < 5.79999999999999996e-80

    1. Initial program 70.5%

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

      \[\leadsto \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    4. 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-/.f6485.7

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

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

    if 5.79999999999999996e-80 < y.re < 6.99999999999999996e93

    1. Initial program 81.0%

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

      \[\leadsto \frac{\color{blue}{y.re \cdot \left(x.re + \frac{x.im \cdot y.im}{y.re}\right)}}{y.re \cdot y.re + y.im \cdot y.im} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

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

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

        \[\leadsto \frac{\left(\frac{x.im \cdot y.im}{y.re} + x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      4. associate-/l*N/A

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

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      6. lower-/.f6481.1

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
    5. Applied rewrites81.1%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right) \cdot y.re}}{y.re \cdot y.re + y.im \cdot y.im} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      5. lift-/.f6481.1

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      6. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite=>}\left(lift-+.f64, \left(y.re \cdot y.re + y.im \cdot y.im\right)\right)} \]
      7. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite=>}\left(lift-*.f64, \left(y.re \cdot y.re\right)\right) + y.im \cdot y.im} \]
      8. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.re \cdot y.re + \mathsf{Rewrite=>}\left(lift-*.f64, \left(y.im \cdot y.im\right)\right)} \]
      9. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite=>}\left(pow2, \left({y.re}^{2}\right)\right) + y.im \cdot y.im} \]
      10. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{{y.re}^{2} + \mathsf{Rewrite=>}\left(pow2, \left({y.im}^{2}\right)\right)} \]
      11. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite<=}\left(+-commutative, \left({y.im}^{2} + {y.re}^{2}\right)\right)} \]
      12. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite<=}\left(pow2, \left(y.im \cdot y.im\right)\right) + {y.re}^{2}} \]
      13. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.im \cdot y.im + \mathsf{Rewrite<=}\left(pow2, \left(y.re \cdot y.re\right)\right)} \]
      14. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.im \cdot y.im + \mathsf{Rewrite<=}\left(lift-*.f64, \left(y.re \cdot y.re\right)\right)} \]
      15. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite<=}\left(lift-fma.f64, \left(\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\right)\right)} \]
    7. Applied rewrites81.1%

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

    if 6.99999999999999996e93 < y.re

    1. Initial program 44.0%

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

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

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

        \[\leadsto \frac{x.im \cdot y.im}{y.re \cdot y.re} + \frac{x.re}{y.re} \]
      3. times-fracN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \color{blue}{\frac{y.im}{y.re}}, \frac{x.re}{y.re}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      7. lower-/.f6489.0

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

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

Alternative 2: 82.4% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y.re \leq -1.2 \cdot 10^{-77}:\\
\;\;\;\;\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 5.8 \cdot 10^{-80}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y.re < -2.2000000000000001e49 or 6.99999999999999996e93 < y.re

    1. Initial program 40.0%

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

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

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

        \[\leadsto \frac{x.im \cdot y.im}{y.re \cdot y.re} + \frac{x.re}{y.re} \]
      3. times-fracN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \color{blue}{\frac{y.im}{y.re}}, \frac{x.re}{y.re}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      7. lower-/.f6488.4

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

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

    if -2.2000000000000001e49 < y.re < -1.19999999999999995e-77

    1. Initial program 99.3%

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

    if -1.19999999999999995e-77 < y.re < 5.79999999999999996e-80

    1. Initial program 70.5%

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

      \[\leadsto \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    4. 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-/.f6485.7

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

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

    if 5.79999999999999996e-80 < y.re < 6.99999999999999996e93

    1. Initial program 81.0%

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

      \[\leadsto \frac{\color{blue}{y.re \cdot \left(x.re + \frac{x.im \cdot y.im}{y.re}\right)}}{y.re \cdot y.re + y.im \cdot y.im} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

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

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

        \[\leadsto \frac{\left(\frac{x.im \cdot y.im}{y.re} + x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      4. associate-/l*N/A

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

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      6. lower-/.f6481.1

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
    5. Applied rewrites81.1%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right) \cdot y.re}}{y.re \cdot y.re + y.im \cdot y.im} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      5. lift-/.f6481.1

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.re \cdot y.re + y.im \cdot y.im} \]
      6. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite=>}\left(lift-+.f64, \left(y.re \cdot y.re + y.im \cdot y.im\right)\right)} \]
      7. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite=>}\left(lift-*.f64, \left(y.re \cdot y.re\right)\right) + y.im \cdot y.im} \]
      8. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.re \cdot y.re + \mathsf{Rewrite=>}\left(lift-*.f64, \left(y.im \cdot y.im\right)\right)} \]
      9. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite=>}\left(pow2, \left({y.re}^{2}\right)\right) + y.im \cdot y.im} \]
      10. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{{y.re}^{2} + \mathsf{Rewrite=>}\left(pow2, \left({y.im}^{2}\right)\right)} \]
      11. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite<=}\left(+-commutative, \left({y.im}^{2} + {y.re}^{2}\right)\right)} \]
      12. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite<=}\left(pow2, \left(y.im \cdot y.im\right)\right) + {y.re}^{2}} \]
      13. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.im \cdot y.im + \mathsf{Rewrite<=}\left(pow2, \left(y.re \cdot y.re\right)\right)} \]
      14. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{y.im \cdot y.im + \mathsf{Rewrite<=}\left(lift-*.f64, \left(y.re \cdot y.re\right)\right)} \]
      15. lift-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\frac{y.im}{y.re}, x.im, x.re\right) \cdot y.re}{\mathsf{Rewrite<=}\left(lift-fma.f64, \left(\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\right)\right)} \]
    7. Applied rewrites81.1%

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

Alternative 3: 82.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ t_1 := \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{y.re}, \frac{x.re}{y.re}\right)\\ \mathbf{if}\;y.re \leq -2.2 \cdot 10^{+49}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y.re \leq -1.2 \cdot 10^{-77}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 7.5 \cdot 10^{-87}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \mathbf{elif}\;y.re \leq 7 \cdot 10^{+93}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0
         (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
        (t_1 (fma (/ x.im y.re) (/ y.im y.re) (/ x.re y.re))))
   (if (<= y.re -2.2e+49)
     t_1
     (if (<= y.re -1.2e-77)
       t_0
       (if (<= y.re 7.5e-87)
         (/ (fma x.re (/ y.re y.im) x.im) y.im)
         (if (<= y.re 7e+93) t_0 t_1))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double t_1 = fma((x_46_im / y_46_re), (y_46_im / y_46_re), (x_46_re / y_46_re));
	double tmp;
	if (y_46_re <= -2.2e+49) {
		tmp = t_1;
	} else if (y_46_re <= -1.2e-77) {
		tmp = t_0;
	} else if (y_46_re <= 7.5e-87) {
		tmp = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
	} else if (y_46_re <= 7e+93) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
	t_1 = fma(Float64(x_46_im / y_46_re), Float64(y_46_im / y_46_re), Float64(x_46_re / y_46_re))
	tmp = 0.0
	if (y_46_re <= -2.2e+49)
		tmp = t_1;
	elseif (y_46_re <= -1.2e-77)
		tmp = t_0;
	elseif (y_46_re <= 7.5e-87)
		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
	elseif (y_46_re <= 7e+93)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$im / y$46$re), $MachinePrecision] * N[(y$46$im / y$46$re), $MachinePrecision] + N[(x$46$re / y$46$re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -2.2e+49], t$95$1, If[LessEqual[y$46$re, -1.2e-77], t$95$0, If[LessEqual[y$46$re, 7.5e-87], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 7e+93], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -2.2000000000000001e49 or 6.99999999999999996e93 < y.re

    1. Initial program 40.0%

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

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

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

        \[\leadsto \frac{x.im \cdot y.im}{y.re \cdot y.re} + \frac{x.re}{y.re} \]
      3. times-fracN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \color{blue}{\frac{y.im}{y.re}}, \frac{x.re}{y.re}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      7. lower-/.f6488.4

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

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

    if -2.2000000000000001e49 < y.re < -1.19999999999999995e-77 or 7.5000000000000002e-87 < y.re < 6.99999999999999996e93

    1. Initial program 86.5%

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

    if -1.19999999999999995e-77 < y.re < 7.5000000000000002e-87

    1. Initial program 70.2%

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

      \[\leadsto \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    4. 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-/.f6485.6

        \[\leadsto \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im} \]
    5. Applied rewrites85.6%

      \[\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: 82.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\ \mathbf{if}\;y.re \leq -8 \cdot 10^{+48}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\ \mathbf{elif}\;y.re \leq -1.2 \cdot 10^{-77}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 7.5 \cdot 10^{-87}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \mathbf{elif}\;y.re \leq 4.5 \cdot 10^{+95}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0
         (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))))
   (if (<= y.re -8e+48)
     (/ (fma (/ x.im y.re) y.im x.re) y.re)
     (if (<= y.re -1.2e-77)
       t_0
       (if (<= y.re 7.5e-87)
         (/ (fma x.re (/ y.re y.im) x.im) y.im)
         (if (<= y.re 4.5e+95) t_0 (/ (fma x.im (/ y.im y.re) x.re) y.re)))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
	double tmp;
	if (y_46_re <= -8e+48) {
		tmp = fma((x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re;
	} else if (y_46_re <= -1.2e-77) {
		tmp = t_0;
	} else if (y_46_re <= 7.5e-87) {
		tmp = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
	} else if (y_46_re <= 4.5e+95) {
		tmp = t_0;
	} else {
		tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im)))
	tmp = 0.0
	if (y_46_re <= -8e+48)
		tmp = Float64(fma(Float64(x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re);
	elseif (y_46_re <= -1.2e-77)
		tmp = t_0;
	elseif (y_46_re <= 7.5e-87)
		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
	elseif (y_46_re <= 4.5e+95)
		tmp = t_0;
	else
		tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re);
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -8e+48], N[(N[(N[(x$46$im / y$46$re), $MachinePrecision] * y$46$im + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -1.2e-77], t$95$0, If[LessEqual[y$46$re, 7.5e-87], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 4.5e+95], t$95$0, N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y.re < -8.00000000000000035e48

    1. Initial program 37.0%

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

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

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

        \[\leadsto \frac{x.im \cdot y.im}{y.re \cdot y.re} + \frac{x.re}{y.re} \]
      3. times-fracN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \color{blue}{\frac{y.im}{y.re}}, \frac{x.re}{y.re}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      7. lower-/.f6488.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{y.re}, \frac{x.re}{y.re}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{y.re}, \frac{x.re}{y.re}\right) \]
      4. lift-fma.f64N/A

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

        \[\leadsto \frac{\frac{x.im}{y.re} \cdot y.im}{y.re} + \frac{\color{blue}{x.re}}{y.re} \]
      6. div-add-revN/A

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

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

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

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

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

    if -8.00000000000000035e48 < y.re < -1.19999999999999995e-77 or 7.5000000000000002e-87 < y.re < 4.50000000000000017e95

    1. Initial program 86.7%

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

    if -1.19999999999999995e-77 < y.re < 7.5000000000000002e-87

    1. Initial program 70.2%

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

      \[\leadsto \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
    4. 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-/.f6485.6

        \[\leadsto \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im} \]
    5. Applied rewrites85.6%

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

    if 4.50000000000000017e95 < y.re

    1. Initial program 42.7%

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

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    4. 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-/.f6488.7

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

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

Alternative 5: 63.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-80}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.re \leq 6.3 \cdot 10^{-80}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.re \leq 1.22 \cdot 10^{+97}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.im\right)}{y.re \cdot y.re}\\ \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 -6.1e-80)
   (/ x.re y.re)
   (if (<= y.re 6.3e-80)
     (/ x.im y.im)
     (if (<= y.re 1.22e+97)
       (/ (fma y.re x.re (* y.im x.im)) (* y.re y.re))
       (/ 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 <= -6.1e-80) {
		tmp = x_46_re / y_46_re;
	} else if (y_46_re <= 6.3e-80) {
		tmp = x_46_im / y_46_im;
	} else if (y_46_re <= 1.22e+97) {
		tmp = fma(y_46_re, x_46_re, (y_46_im * x_46_im)) / (y_46_re * y_46_re);
	} 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 <= -6.1e-80)
		tmp = Float64(x_46_re / y_46_re);
	elseif (y_46_re <= 6.3e-80)
		tmp = Float64(x_46_im / y_46_im);
	elseif (y_46_re <= 1.22e+97)
		tmp = Float64(fma(y_46_re, x_46_re, Float64(y_46_im * x_46_im)) / Float64(y_46_re * y_46_re));
	else
		tmp = Float64(x_46_re / y_46_re);
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -6.1e-80], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 6.3e-80], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 1.22e+97], N[(N[(y$46$re * x$46$re + N[(y$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -6.1000000000000002e-80 or 1.21999999999999997e97 < y.re

    1. Initial program 48.7%

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

      \[\leadsto \color{blue}{\frac{x.re}{y.re}} \]
    4. Step-by-step derivation
      1. lower-/.f6472.5

        \[\leadsto \frac{x.re}{\color{blue}{y.re}} \]
    5. Applied rewrites72.5%

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

    if -6.1000000000000002e-80 < y.re < 6.29999999999999966e-80

    1. Initial program 70.2%

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

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

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

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

    if 6.29999999999999966e-80 < y.re < 1.21999999999999997e97

    1. Initial program 81.4%

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

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

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot \color{blue}{y.re}} \]
      2. lift-*.f6464.0

        \[\leadsto \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot \color{blue}{y.re}} \]
    5. Applied rewrites64.0%

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

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

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

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

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

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

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

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

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

Alternative 6: 64.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-80}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.re \leq 2.45 \cdot 10^{-86}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.re \leq 6.2 \cdot 10^{+120}:\\ \;\;\;\;x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\ \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 -6.1e-80)
   (/ x.re y.re)
   (if (<= y.re 2.45e-86)
     (/ x.im y.im)
     (if (<= y.re 6.2e+120)
       (* x.re (/ y.re (fma y.im y.im (* y.re y.re))))
       (/ 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 <= -6.1e-80) {
		tmp = x_46_re / y_46_re;
	} else if (y_46_re <= 2.45e-86) {
		tmp = x_46_im / y_46_im;
	} else if (y_46_re <= 6.2e+120) {
		tmp = x_46_re * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
	} 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 <= -6.1e-80)
		tmp = Float64(x_46_re / y_46_re);
	elseif (y_46_re <= 2.45e-86)
		tmp = Float64(x_46_im / y_46_im);
	elseif (y_46_re <= 6.2e+120)
		tmp = Float64(x_46_re * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))));
	else
		tmp = Float64(x_46_re / y_46_re);
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -6.1e-80], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 2.45e-86], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 6.2e+120], 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], N[(x$46$re / y$46$re), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.re < -6.1000000000000002e-80 or 6.19999999999999947e120 < y.re

    1. Initial program 46.4%

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

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

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

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

    if -6.1000000000000002e-80 < y.re < 2.44999999999999986e-86

    1. Initial program 69.9%

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

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

        \[\leadsto \frac{x.im}{\color{blue}{y.im}} \]
    5. Applied rewrites70.1%

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

    if 2.44999999999999986e-86 < y.re < 6.19999999999999947e120

    1. Initial program 82.4%

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

      \[\leadsto \color{blue}{\frac{x.re \cdot y.re}{{y.im}^{2} + {y.re}^{2}}} \]
    4. 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-*.f6460.2

        \[\leadsto x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \]
    5. Applied rewrites60.2%

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

Alternative 7: 77.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-77} \lor \neg \left(y.re \leq 1.8 \cdot 10^{-23}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -6.1e-77) (not (<= y.re 1.8e-23)))
   (/ (fma (/ x.im y.re) y.im x.re) y.re)
   (/ (fma x.re (/ y.re y.im) x.im) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_re <= -6.1e-77) || !(y_46_re <= 1.8e-23)) {
		tmp = fma((x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re;
	} else {
		tmp = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if ((y_46_re <= -6.1e-77) || !(y_46_re <= 1.8e-23))
		tmp = Float64(fma(Float64(x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re);
	else
		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -6.1e-77], N[Not[LessEqual[y$46$re, 1.8e-23]], $MachinePrecision]], N[(N[(N[(x$46$im / y$46$re), $MachinePrecision] * y$46$im + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.1 \cdot 10^{-77} \lor \neg \left(y.re \leq 1.8 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -6.1000000000000002e-77 or 1.7999999999999999e-23 < y.re

    1. Initial program 55.8%

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

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

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

        \[\leadsto \frac{x.im \cdot y.im}{y.re \cdot y.re} + \frac{x.re}{y.re} \]
      3. times-fracN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \color{blue}{\frac{y.im}{y.re}}, \frac{x.re}{y.re}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      6. lower-/.f64N/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{y.re}, \frac{x.re}{y.re}\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{\color{blue}{y.im}}{y.re}, \frac{x.re}{y.re}\right) \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{\color{blue}{y.re}}, \frac{x.re}{y.re}\right) \]
      3. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x.im}{y.re}, \frac{y.im}{y.re}, \frac{x.re}{y.re}\right) \]
      4. lift-fma.f64N/A

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

        \[\leadsto \frac{\frac{x.im}{y.re} \cdot y.im}{y.re} + \frac{\color{blue}{x.re}}{y.re} \]
      6. div-add-revN/A

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re} \]
      9. lift-/.f6482.3

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

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

    if -6.1000000000000002e-77 < y.re < 1.7999999999999999e-23

    1. Initial program 71.1%

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

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

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

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

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

Alternative 8: 76.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-77} \lor \neg \left(y.re \leq 1.65 \cdot 10^{-23}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -6.1e-77) (not (<= y.re 1.65e-23)))
   (/ (fma x.im (/ y.im y.re) x.re) y.re)
   (/ (fma x.re (/ y.re y.im) x.im) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_re <= -6.1e-77) || !(y_46_re <= 1.65e-23)) {
		tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	} else {
		tmp = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if ((y_46_re <= -6.1e-77) || !(y_46_re <= 1.65e-23))
		tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re);
	else
		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -6.1e-77], N[Not[LessEqual[y$46$re, 1.65e-23]], $MachinePrecision]], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.1 \cdot 10^{-77} \lor \neg \left(y.re \leq 1.65 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -6.1000000000000002e-77 or 1.6500000000000001e-23 < y.re

    1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    4. 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-/.f6481.6

        \[\leadsto \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re} \]
    5. Applied rewrites81.6%

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

    if -6.1000000000000002e-77 < y.re < 1.6500000000000001e-23

    1. Initial program 71.1%

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

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

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

      \[\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. Final simplification82.2%

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

Alternative 9: 69.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -6.1 \cdot 10^{-80} \lor \neg \left(y.re \leq 6.3 \cdot 10^{-80}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (or (<= y.re -6.1e-80) (not (<= y.re 6.3e-80)))
   (/ (fma x.im (/ y.im y.re) x.re) y.re)
   (/ x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((y_46_re <= -6.1e-80) || !(y_46_re <= 6.3e-80)) {
		tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
	} else {
		tmp = x_46_im / y_46_im;
	}
	return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if ((y_46_re <= -6.1e-80) || !(y_46_re <= 6.3e-80))
		tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re);
	else
		tmp = Float64(x_46_im / y_46_im);
	end
	return tmp
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -6.1e-80], N[Not[LessEqual[y$46$re, 6.3e-80]], $MachinePrecision]], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.1 \cdot 10^{-80} \lor \neg \left(y.re \leq 6.3 \cdot 10^{-80}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\

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


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

    1. Initial program 57.6%

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

      \[\leadsto \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
    4. 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-/.f6479.5

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

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

    if -6.1000000000000002e-80 < y.re < 6.29999999999999966e-80

    1. Initial program 70.2%

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

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

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

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

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

Alternative 10: 62.0% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.1 \cdot 10^{-80} \lor \neg \left(y.re \leq 1.28 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{x.re}{y.re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y.re < -6.1000000000000002e-80 or 1.28e-79 < y.re

    1. Initial program 57.6%

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

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

        \[\leadsto \frac{x.re}{\color{blue}{y.re}} \]
    5. Applied rewrites63.1%

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

    if -6.1000000000000002e-80 < y.re < 1.28e-79

    1. Initial program 70.2%

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

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

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

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

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

Alternative 11: 42.0% accurate, 3.2× 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.3%

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

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

      \[\leadsto \frac{x.im}{\color{blue}{y.im}} \]
  5. Applied rewrites37.3%

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

Reproduce

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