_divideComplex, real part

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 62.1% accurate, 1.0× speedup?

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

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

Alternative 1: 82.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x.im \cdot y.im + y.re \cdot x.re}{y.im \cdot y.im + y.re \cdot y.re}\\ t_1 := \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \mathbf{if}\;y.im \leq -4.5 \cdot 10^{+91}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y.im \leq -2.95 \cdot 10^{-161}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.im \leq 1.1 \cdot 10^{-129}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\ \mathbf{elif}\;y.im \leq 7.2 \cdot 10^{+99}:\\ \;\;\;\;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.im y.im) (* y.re x.re)) (+ (* y.im y.im) (* y.re y.re))))
        (t_1 (/ (fma x.re (/ y.re y.im) x.im) y.im)))
   (if (<= y.im -4.5e+91)
     t_1
     (if (<= y.im -2.95e-161)
       t_0
       (if (<= y.im 1.1e-129)
         (/ (fma (/ x.im y.re) y.im x.re) y.re)
         (if (<= y.im 7.2e+99) 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_im * y_46_im) + (y_46_re * x_46_re)) / ((y_46_im * y_46_im) + (y_46_re * y_46_re));
	double t_1 = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
	double tmp;
	if (y_46_im <= -4.5e+91) {
		tmp = t_1;
	} else if (y_46_im <= -2.95e-161) {
		tmp = t_0;
	} else if (y_46_im <= 1.1e-129) {
		tmp = fma((x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re;
	} else if (y_46_im <= 7.2e+99) {
		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_im * y_46_im) + Float64(y_46_re * x_46_re)) / Float64(Float64(y_46_im * y_46_im) + Float64(y_46_re * y_46_re)))
	t_1 = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im)
	tmp = 0.0
	if (y_46_im <= -4.5e+91)
		tmp = t_1;
	elseif (y_46_im <= -2.95e-161)
		tmp = t_0;
	elseif (y_46_im <= 1.1e-129)
		tmp = Float64(fma(Float64(x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re);
	elseif (y_46_im <= 7.2e+99)
		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$im * y$46$im), $MachinePrecision] + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$im * y$46$im), $MachinePrecision] + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = 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$im, -4.5e+91], t$95$1, If[LessEqual[y$46$im, -2.95e-161], t$95$0, If[LessEqual[y$46$im, 1.1e-129], 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$im, 7.2e+99], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y.im \leq -2.95 \cdot 10^{-161}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y.im \leq 7.2 \cdot 10^{+99}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y.im < -4.5e91 or 7.2000000000000003e99 < y.im

    1. Initial program 28.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 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 \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
      2. +-commutativeN/A

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)}{y.im}} \]
    6. Step-by-step derivation
      1. Applied rewrites89.8%

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

      if -4.5e91 < y.im < -2.9500000000000001e-161 or 1.10000000000000001e-129 < y.im < 7.2000000000000003e99

      1. Initial program 81.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 -2.9500000000000001e-161 < y.im < 1.10000000000000001e-129

      1. Initial program 73.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 \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
        2. +-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}} \]
    7. Recombined 3 regimes into one program.
    8. Final simplification86.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -4.5 \cdot 10^{+91}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \mathbf{elif}\;y.im \leq -2.95 \cdot 10^{-161}:\\ \;\;\;\;\frac{x.im \cdot y.im + y.re \cdot x.re}{y.im \cdot y.im + y.re \cdot y.re}\\ \mathbf{elif}\;y.im \leq 1.1 \cdot 10^{-129}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\ \mathbf{elif}\;y.im \leq 7.2 \cdot 10^{+99}:\\ \;\;\;\;\frac{x.im \cdot y.im + y.re \cdot x.re}{y.im \cdot y.im + y.re \cdot y.re}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 2: 66.1% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -5 \cdot 10^{+144}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\ \;\;\;\;\frac{x.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot y.im\\ \mathbf{elif}\;y.im \leq 2.5 \cdot 10^{-41}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.im \leq 1.02 \cdot 10^{+123}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}{y.im \cdot y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \end{array} \]
    (FPCore (x.re x.im y.re y.im)
     :precision binary64
     (if (<= y.im -5e+144)
       (/ x.im y.im)
       (if (<= y.im -9e-18)
         (* (/ x.im (fma y.im y.im (* y.re y.re))) y.im)
         (if (<= y.im 2.5e-41)
           (/ x.re y.re)
           (if (<= y.im 1.02e+123)
             (/ (fma y.re x.re (* x.im y.im)) (* y.im 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_im <= -5e+144) {
    		tmp = x_46_im / y_46_im;
    	} else if (y_46_im <= -9e-18) {
    		tmp = (x_46_im / fma(y_46_im, y_46_im, (y_46_re * y_46_re))) * y_46_im;
    	} else if (y_46_im <= 2.5e-41) {
    		tmp = x_46_re / y_46_re;
    	} else if (y_46_im <= 1.02e+123) {
    		tmp = fma(y_46_re, x_46_re, (x_46_im * y_46_im)) / (y_46_im * y_46_im);
    	} else {
    		tmp = x_46_im / y_46_im;
    	}
    	return tmp;
    }
    
    function code(x_46_re, x_46_im, y_46_re, y_46_im)
    	tmp = 0.0
    	if (y_46_im <= -5e+144)
    		tmp = Float64(x_46_im / y_46_im);
    	elseif (y_46_im <= -9e-18)
    		tmp = Float64(Float64(x_46_im / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))) * y_46_im);
    	elseif (y_46_im <= 2.5e-41)
    		tmp = Float64(x_46_re / y_46_re);
    	elseif (y_46_im <= 1.02e+123)
    		tmp = Float64(fma(y_46_re, x_46_re, Float64(x_46_im * y_46_im)) / Float64(y_46_im * y_46_im));
    	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[LessEqual[y$46$im, -5e+144], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, -9e-18], N[(N[(x$46$im / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 2.5e-41], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 1.02e+123], N[(N[(y$46$re * x$46$re + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;y.im \leq -5 \cdot 10^{+144}:\\
    \;\;\;\;\frac{x.im}{y.im}\\
    
    \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\
    \;\;\;\;\frac{x.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot y.im\\
    
    \mathbf{elif}\;y.im \leq 2.5 \cdot 10^{-41}:\\
    \;\;\;\;\frac{x.re}{y.re}\\
    
    \mathbf{elif}\;y.im \leq 1.02 \cdot 10^{+123}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}{y.im \cdot y.im}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{x.im}{y.im}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if y.im < -4.9999999999999999e144 or 1.02e123 < y.im

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

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

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

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

      if -4.9999999999999999e144 < y.im < -8.99999999999999987e-18

      1. Initial program 69.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 x.im around inf

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

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

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

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

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

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

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

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

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

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

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

      if -8.99999999999999987e-18 < y.im < 2.4999999999999998e-41

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

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

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

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

      if 2.4999999999999998e-41 < y.im < 1.02e123

      1. Initial program 74.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.im around inf

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \leq -5 \cdot 10^{+144}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\ \;\;\;\;\frac{x.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot y.im\\ \mathbf{elif}\;y.im \leq 2.5 \cdot 10^{-41}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.im \leq 1.02 \cdot 10^{+123}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y.re, x.re, x.im \cdot y.im\right)}{y.im \cdot y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 3: 66.1% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\\ \mathbf{if}\;y.im \leq -5 \cdot 10^{+144}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\ \;\;\;\;\frac{x.im}{t\_0} \cdot y.im\\ \mathbf{elif}\;y.im \leq 6.5 \cdot 10^{-118}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.im \leq 1.18 \cdot 10^{+93}:\\ \;\;\;\;\frac{y.im}{t\_0} \cdot x.im\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \end{array} \end{array} \]
    (FPCore (x.re x.im y.re y.im)
     :precision binary64
     (let* ((t_0 (fma y.im y.im (* y.re y.re))))
       (if (<= y.im -5e+144)
         (/ x.im y.im)
         (if (<= y.im -9e-18)
           (* (/ x.im t_0) y.im)
           (if (<= y.im 6.5e-118)
             (/ x.re y.re)
             (if (<= y.im 1.18e+93) (* (/ y.im t_0) x.im) (/ x.im y.im)))))))
    double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
    	double t_0 = fma(y_46_im, y_46_im, (y_46_re * y_46_re));
    	double tmp;
    	if (y_46_im <= -5e+144) {
    		tmp = x_46_im / y_46_im;
    	} else if (y_46_im <= -9e-18) {
    		tmp = (x_46_im / t_0) * y_46_im;
    	} else if (y_46_im <= 6.5e-118) {
    		tmp = x_46_re / y_46_re;
    	} else if (y_46_im <= 1.18e+93) {
    		tmp = (y_46_im / t_0) * x_46_im;
    	} else {
    		tmp = x_46_im / y_46_im;
    	}
    	return tmp;
    }
    
    function code(x_46_re, x_46_im, y_46_re, y_46_im)
    	t_0 = fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))
    	tmp = 0.0
    	if (y_46_im <= -5e+144)
    		tmp = Float64(x_46_im / y_46_im);
    	elseif (y_46_im <= -9e-18)
    		tmp = Float64(Float64(x_46_im / t_0) * y_46_im);
    	elseif (y_46_im <= 6.5e-118)
    		tmp = Float64(x_46_re / y_46_re);
    	elseif (y_46_im <= 1.18e+93)
    		tmp = Float64(Float64(y_46_im / t_0) * x_46_im);
    	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_] := Block[{t$95$0 = N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$im, -5e+144], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, -9e-18], N[(N[(x$46$im / t$95$0), $MachinePrecision] * y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 6.5e-118], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 1.18e+93], N[(N[(y$46$im / t$95$0), $MachinePrecision] * x$46$im), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\\
    \mathbf{if}\;y.im \leq -5 \cdot 10^{+144}:\\
    \;\;\;\;\frac{x.im}{y.im}\\
    
    \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\
    \;\;\;\;\frac{x.im}{t\_0} \cdot y.im\\
    
    \mathbf{elif}\;y.im \leq 6.5 \cdot 10^{-118}:\\
    \;\;\;\;\frac{x.re}{y.re}\\
    
    \mathbf{elif}\;y.im \leq 1.18 \cdot 10^{+93}:\\
    \;\;\;\;\frac{y.im}{t\_0} \cdot x.im\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{x.im}{y.im}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if y.im < -4.9999999999999999e144 or 1.1799999999999999e93 < y.im

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

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

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

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

      if -4.9999999999999999e144 < y.im < -8.99999999999999987e-18

      1. Initial program 69.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 x.im around inf

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

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

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

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

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

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

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

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

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

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

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

      if -8.99999999999999987e-18 < y.im < 6.49999999999999958e-118

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

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

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

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

      if 6.49999999999999958e-118 < y.im < 1.1799999999999999e93

      1. Initial program 79.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.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 \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
        2. +-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)}{y.im}} \]
      6. Taylor expanded in x.im around inf

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

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

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

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

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

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

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

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

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

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

    Alternative 4: 73.3% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.re \leq -2.5 \cdot 10^{+146}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \mathbf{elif}\;y.re \leq -1.6 \cdot 10^{+14}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\ \mathbf{elif}\;y.re \leq 4 \cdot 10^{+77}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{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 -2.5e+146)
       (/ x.re y.re)
       (if (<= y.re -1.6e+14)
         (/ (fma y.im x.im (* y.re x.re)) (* y.re y.re))
         (if (<= y.re 4e+77)
           (/ (fma x.re (/ y.re y.im) 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 <= -2.5e+146) {
    		tmp = x_46_re / y_46_re;
    	} else if (y_46_re <= -1.6e+14) {
    		tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_re * y_46_re);
    	} else if (y_46_re <= 4e+77) {
    		tmp = fma(x_46_re, (y_46_re / y_46_im), 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 <= -2.5e+146)
    		tmp = Float64(x_46_re / y_46_re);
    	elseif (y_46_re <= -1.6e+14)
    		tmp = Float64(fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)) / Float64(y_46_re * y_46_re));
    	elseif (y_46_re <= 4e+77)
    		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
    	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, -2.5e+146], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -1.6e+14], N[(N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 4e+77], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;y.re \leq -2.5 \cdot 10^{+146}:\\
    \;\;\;\;\frac{x.re}{y.re}\\
    
    \mathbf{elif}\;y.re \leq -1.6 \cdot 10^{+14}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\
    
    \mathbf{elif}\;y.re \leq 4 \cdot 10^{+77}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{x.re}{y.re}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if y.re < -2.4999999999999999e146 or 3.99999999999999993e77 < y.re

      1. Initial program 43.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.im around 0

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

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

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

      if -2.4999999999999999e146 < y.re < -1.6e14

      1. Initial program 69.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.im around inf

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

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

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

        \[\leadsto \frac{\color{blue}{y.im \cdot x.im}}{y.re \cdot y.re + y.im \cdot y.im} \]
      6. Taylor expanded in y.im around 0

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

          \[\leadsto \frac{y.im \cdot x.im}{\color{blue}{y.re \cdot y.re}} \]
        2. lower-*.f6426.1

          \[\leadsto \frac{y.im \cdot x.im}{\color{blue}{y.re \cdot y.re}} \]
      8. Applied rewrites26.1%

        \[\leadsto \frac{y.im \cdot x.im}{\color{blue}{y.re \cdot y.re}} \]
      9. Taylor expanded in y.im around 0

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

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

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

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

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

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

      if -1.6e14 < y.re < 3.99999999999999993e77

      1. Initial program 68.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.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 \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
        2. +-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)}{y.im}} \]
      6. Step-by-step derivation
        1. Applied rewrites82.3%

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

      Alternative 5: 77.9% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\ \mathbf{if}\;y.re \leq -1.6 \cdot 10^{+14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y.re \leq 2.05 \cdot 10^{+77}:\\ \;\;\;\;\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.re) y.im x.re) y.re)))
         (if (<= y.re -1.6e+14)
           t_0
           (if (<= y.re 2.05e+77) (/ (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_re), y_46_im, x_46_re) / y_46_re;
      	double tmp;
      	if (y_46_re <= -1.6e+14) {
      		tmp = t_0;
      	} else if (y_46_re <= 2.05e+77) {
      		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(Float64(x_46_im / y_46_re), y_46_im, x_46_re) / y_46_re)
      	tmp = 0.0
      	if (y_46_re <= -1.6e+14)
      		tmp = t_0;
      	elseif (y_46_re <= 2.05e+77)
      		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[(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.6e+14], t$95$0, If[LessEqual[y$46$re, 2.05e+77], 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(\frac{x.im}{y.re}, y.im, x.re\right)}{y.re}\\
      \mathbf{if}\;y.re \leq -1.6 \cdot 10^{+14}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;y.re \leq 2.05 \cdot 10^{+77}:\\
      \;\;\;\;\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 < -1.6e14 or 2.05e77 < y.re

        1. Initial program 49.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 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 \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
          2. +-commutativeN/A

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

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

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

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

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

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

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

        if -1.6e14 < y.re < 2.05e77

        1. Initial program 68.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.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 \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
          2. +-commutativeN/A

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{x.re}{y.im}, y.re, x.im\right)}{y.im}} \]
        6. Step-by-step derivation
          1. Applied rewrites82.3%

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

        Alternative 6: 64.8% accurate, 0.9× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -5 \cdot 10^{+144}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\ \;\;\;\;\frac{x.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot y.im\\ \mathbf{elif}\;y.im \leq 2.9 \cdot 10^{+22}:\\ \;\;\;\;\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 (<= y.im -5e+144)
           (/ x.im y.im)
           (if (<= y.im -9e-18)
             (* (/ x.im (fma y.im y.im (* y.re y.re))) y.im)
             (if (<= y.im 2.9e+22) (/ 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_im <= -5e+144) {
        		tmp = x_46_im / y_46_im;
        	} else if (y_46_im <= -9e-18) {
        		tmp = (x_46_im / fma(y_46_im, y_46_im, (y_46_re * y_46_re))) * y_46_im;
        	} else if (y_46_im <= 2.9e+22) {
        		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_im <= -5e+144)
        		tmp = Float64(x_46_im / y_46_im);
        	elseif (y_46_im <= -9e-18)
        		tmp = Float64(Float64(x_46_im / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))) * y_46_im);
        	elseif (y_46_im <= 2.9e+22)
        		tmp = Float64(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[LessEqual[y$46$im, -5e+144], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, -9e-18], N[(N[(x$46$im / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 2.9e+22], 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.im \leq -5 \cdot 10^{+144}:\\
        \;\;\;\;\frac{x.im}{y.im}\\
        
        \mathbf{elif}\;y.im \leq -9 \cdot 10^{-18}:\\
        \;\;\;\;\frac{x.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot y.im\\
        
        \mathbf{elif}\;y.im \leq 2.9 \cdot 10^{+22}:\\
        \;\;\;\;\frac{x.re}{y.re}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{x.im}{y.im}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if y.im < -4.9999999999999999e144 or 2.9e22 < y.im

          1. Initial program 36.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}{y.im}} \]
          4. Step-by-step derivation
            1. lower-/.f6477.3

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

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

          if -4.9999999999999999e144 < y.im < -8.99999999999999987e-18

          1. Initial program 69.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 x.im around inf

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

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

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

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

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

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

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

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

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

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

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

          if -8.99999999999999987e-18 < y.im < 2.9e22

          1. Initial program 77.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.im around 0

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

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

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

        Alternative 7: 63.9% accurate, 1.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -7 \cdot 10^{-17}:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq 2.9 \cdot 10^{+22}:\\ \;\;\;\;\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 (<= y.im -7e-17)
           (/ x.im y.im)
           (if (<= y.im 2.9e+22) (/ 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_im <= -7e-17) {
        		tmp = x_46_im / y_46_im;
        	} else if (y_46_im <= 2.9e+22) {
        		tmp = x_46_re / y_46_re;
        	} else {
        		tmp = x_46_im / y_46_im;
        	}
        	return tmp;
        }
        
        real(8) function code(x_46re, x_46im, y_46re, y_46im)
            real(8), intent (in) :: x_46re
            real(8), intent (in) :: x_46im
            real(8), intent (in) :: y_46re
            real(8), intent (in) :: y_46im
            real(8) :: tmp
            if (y_46im <= (-7d-17)) then
                tmp = x_46im / y_46im
            else if (y_46im <= 2.9d+22) 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_im <= -7e-17) {
        		tmp = x_46_im / y_46_im;
        	} else if (y_46_im <= 2.9e+22) {
        		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_im <= -7e-17:
        		tmp = x_46_im / y_46_im
        	elif y_46_im <= 2.9e+22:
        		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_im <= -7e-17)
        		tmp = Float64(x_46_im / y_46_im);
        	elseif (y_46_im <= 2.9e+22)
        		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_im <= -7e-17)
        		tmp = x_46_im / y_46_im;
        	elseif (y_46_im <= 2.9e+22)
        		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[LessEqual[y$46$im, -7e-17], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 2.9e+22], 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.im \leq -7 \cdot 10^{-17}:\\
        \;\;\;\;\frac{x.im}{y.im}\\
        
        \mathbf{elif}\;y.im \leq 2.9 \cdot 10^{+22}:\\
        \;\;\;\;\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.im < -7.0000000000000003e-17 or 2.9e22 < y.im

          1. Initial program 43.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.im around inf

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

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

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

          if -7.0000000000000003e-17 < y.im < 2.9e22

          1. Initial program 77.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.im around 0

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

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

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

        Alternative 8: 42.7% 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;
        }
        
        real(8) function code(x_46re, x_46im, y_46re, y_46im)
            real(8), intent (in) :: x_46re
            real(8), intent (in) :: x_46im
            real(8), intent (in) :: y_46re
            real(8), intent (in) :: y_46im
            code = x_46im / y_46im
        end function
        
        public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
        	return x_46_im / y_46_im;
        }
        
        def code(x_46_re, x_46_im, y_46_re, y_46_im):
        	return x_46_im / y_46_im
        
        function code(x_46_re, x_46_im, y_46_re, y_46_im)
        	return Float64(x_46_im / y_46_im)
        end
        
        function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
        	tmp = x_46_im / y_46_im;
        end
        
        code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im / y$46$im), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \frac{x.im}{y.im}
        \end{array}
        
        Derivation
        1. Initial program 61.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}{y.im}} \]
        4. Step-by-step derivation
          1. lower-/.f6444.5

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

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

        Reproduce

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