_divideComplex, real part

Percentage Accurate: 61.4% → 77.9%
Time: 3.9s
Alternatives: 6
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 6 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: 77.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -3.2 \cdot 10^{+28} \lor \neg \left(y.im \leq 9.2 \cdot 10^{-28}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\ \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
 (if (or (<= y.im -3.2e+28) (not (<= y.im 9.2e-28)))
   (fma (/ x.re y.im) (/ y.re y.im) (/ x.im y.im))
   (/ (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 tmp;
	if ((y_46_im <= -3.2e+28) || !(y_46_im <= 9.2e-28)) {
		tmp = fma((x_46_re / y_46_im), (y_46_re / y_46_im), (x_46_im / y_46_im));
	} 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)
	tmp = 0.0
	if ((y_46_im <= -3.2e+28) || !(y_46_im <= 9.2e-28))
		tmp = fma(Float64(x_46_re / y_46_im), Float64(y_46_re / y_46_im), Float64(x_46_im / y_46_im));
	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_] := If[Or[LessEqual[y$46$im, -3.2e+28], N[Not[LessEqual[y$46$im, 9.2e-28]], $MachinePrecision]], N[(N[(x$46$re / y$46$im), $MachinePrecision] * N[(y$46$re / y$46$im), $MachinePrecision] + N[(x$46$im / y$46$im), $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;y.im \leq -3.2 \cdot 10^{+28} \lor \neg \left(y.im \leq 9.2 \cdot 10^{-28}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\

\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 2 regimes
  2. if y.im < -3.2e28 or 9.19999999999999942e-28 < y.im

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

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

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

      if -3.2e28 < y.im < 9.19999999999999942e-28

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

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

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

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

      Alternative 2: 77.7% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -3.2 \cdot 10^{+28} \lor \neg \left(y.im \leq 9.2 \cdot 10^{-28}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\ \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
       (if (or (<= y.im -3.2e+28) (not (<= y.im 9.2e-28)))
         (/ (fma x.re (/ y.re y.im) x.im) y.im)
         (/ (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 tmp;
      	if ((y_46_im <= -3.2e+28) || !(y_46_im <= 9.2e-28)) {
      		tmp = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
      	} 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)
      	tmp = 0.0
      	if ((y_46_im <= -3.2e+28) || !(y_46_im <= 9.2e-28))
      		tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im);
      	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_] := If[Or[LessEqual[y$46$im, -3.2e+28], N[Not[LessEqual[y$46$im, 9.2e-28]], $MachinePrecision]], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], 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}
      \mathbf{if}\;y.im \leq -3.2 \cdot 10^{+28} \lor \neg \left(y.im \leq 9.2 \cdot 10^{-28}\right):\\
      \;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
      
      \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 2 regimes
      2. if y.im < -3.2e28 or 9.19999999999999942e-28 < y.im

        1. Initial program 41.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 \color{blue}{\frac{x.im + \frac{x.re \cdot y.re}{y.im}}{y.im}} \]
        4. Step-by-step derivation
          1. Applied rewrites80.8%

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

          if -3.2e28 < y.im < 9.19999999999999942e-28

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

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

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

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

          Alternative 3: 72.5% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -100000 \lor \neg \left(y.im \leq 5.3 \cdot 10^{-27}\right):\\ \;\;\;\;\frac{x.im}{y.im}\\ \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
           (if (or (<= y.im -100000.0) (not (<= y.im 5.3e-27)))
             (/ x.im y.im)
             (/ (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 tmp;
          	if ((y_46_im <= -100000.0) || !(y_46_im <= 5.3e-27)) {
          		tmp = x_46_im / y_46_im;
          	} 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)
          	tmp = 0.0
          	if ((y_46_im <= -100000.0) || !(y_46_im <= 5.3e-27))
          		tmp = Float64(x_46_im / y_46_im);
          	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_] := If[Or[LessEqual[y$46$im, -100000.0], N[Not[LessEqual[y$46$im, 5.3e-27]], $MachinePrecision]], N[(x$46$im / y$46$im), $MachinePrecision], 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}
          \mathbf{if}\;y.im \leq -100000 \lor \neg \left(y.im \leq 5.3 \cdot 10^{-27}\right):\\
          \;\;\;\;\frac{x.im}{y.im}\\
          
          \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 2 regimes
          2. if y.im < -1e5 or 5.30000000000000006e-27 < y.im

            1. Initial program 44.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.re around 0

              \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
            4. Step-by-step derivation
              1. Applied rewrites69.3%

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

              if -1e5 < y.im < 5.30000000000000006e-27

              1. Initial program 73.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 \color{blue}{\frac{x.re + \frac{x.im \cdot y.im}{y.re}}{y.re}} \]
              4. Step-by-step derivation
                1. Applied rewrites88.0%

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

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

              Alternative 4: 63.5% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -0.18:\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{elif}\;y.im \leq -1.5 \cdot 10^{-173}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\ \mathbf{elif}\;y.im \leq 7.6 \cdot 10^{-28}:\\ \;\;\;\;\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 -0.18)
                 (/ x.im y.im)
                 (if (<= y.im -1.5e-173)
                   (/ (fma y.im x.im (* y.re x.re)) (* y.re y.re))
                   (if (<= y.im 7.6e-28) (/ 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 <= -0.18) {
              		tmp = x_46_im / y_46_im;
              	} else if (y_46_im <= -1.5e-173) {
              		tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_re * y_46_re);
              	} else if (y_46_im <= 7.6e-28) {
              		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 <= -0.18)
              		tmp = Float64(x_46_im / y_46_im);
              	elseif (y_46_im <= -1.5e-173)
              		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_im <= 7.6e-28)
              		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, -0.18], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, -1.5e-173], 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$im, 7.6e-28], 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 -0.18:\\
              \;\;\;\;\frac{x.im}{y.im}\\
              
              \mathbf{elif}\;y.im \leq -1.5 \cdot 10^{-173}:\\
              \;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\
              
              \mathbf{elif}\;y.im \leq 7.6 \cdot 10^{-28}:\\
              \;\;\;\;\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 < -0.17999999999999999 or 7.60000000000000018e-28 < y.im

                1. Initial program 44.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.re around 0

                  \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
                4. Step-by-step derivation
                  1. Applied rewrites69.3%

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

                  if -0.17999999999999999 < y.im < -1.5000000000000001e-173

                  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.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. Applied rewrites82.8%

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

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

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

                      if -1.5000000000000001e-173 < y.im < 7.60000000000000018e-28

                      1. Initial program 72.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.re around inf

                        \[\leadsto \color{blue}{\frac{x.re}{y.re}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites74.5%

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

                      Alternative 5: 63.9% accurate, 1.6× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y.im \leq -1800 \lor \neg \left(y.im \leq 7.6 \cdot 10^{-28}\right):\\ \;\;\;\;\frac{x.im}{y.im}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{y.re}\\ \end{array} \end{array} \]
                      (FPCore (x.re x.im y.re y.im)
                       :precision binary64
                       (if (or (<= y.im -1800.0) (not (<= y.im 7.6e-28)))
                         (/ 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_im <= -1800.0) || !(y_46_im <= 7.6e-28)) {
                      		tmp = x_46_im / y_46_im;
                      	} else {
                      		tmp = x_46_re / y_46_re;
                      	}
                      	return tmp;
                      }
                      
                      module fmin_fmax_functions
                          implicit none
                          private
                          public fmax
                          public fmin
                      
                          interface fmax
                              module procedure fmax88
                              module procedure fmax44
                              module procedure fmax84
                              module procedure fmax48
                          end interface
                          interface fmin
                              module procedure fmin88
                              module procedure fmin44
                              module procedure fmin84
                              module procedure fmin48
                          end interface
                      contains
                          real(8) function fmax88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmax44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmax84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmax48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                          end function
                          real(8) function fmin88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmin44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmin84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmin48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                          end function
                      end module
                      
                      real(8) function code(x_46re, x_46im, y_46re, y_46im)
                      use fmin_fmax_functions
                          real(8), intent (in) :: x_46re
                          real(8), intent (in) :: x_46im
                          real(8), intent (in) :: y_46re
                          real(8), intent (in) :: y_46im
                          real(8) :: tmp
                          if ((y_46im <= (-1800.0d0)) .or. (.not. (y_46im <= 7.6d-28))) then
                              tmp = x_46im / y_46im
                          else
                              tmp = x_46re / y_46re
                          end if
                          code = tmp
                      end function
                      
                      public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
                      	double tmp;
                      	if ((y_46_im <= -1800.0) || !(y_46_im <= 7.6e-28)) {
                      		tmp = x_46_im / y_46_im;
                      	} else {
                      		tmp = x_46_re / y_46_re;
                      	}
                      	return tmp;
                      }
                      
                      def code(x_46_re, x_46_im, y_46_re, y_46_im):
                      	tmp = 0
                      	if (y_46_im <= -1800.0) or not (y_46_im <= 7.6e-28):
                      		tmp = x_46_im / y_46_im
                      	else:
                      		tmp = x_46_re / y_46_re
                      	return tmp
                      
                      function code(x_46_re, x_46_im, y_46_re, y_46_im)
                      	tmp = 0.0
                      	if ((y_46_im <= -1800.0) || !(y_46_im <= 7.6e-28))
                      		tmp = Float64(x_46_im / y_46_im);
                      	else
                      		tmp = Float64(x_46_re / y_46_re);
                      	end
                      	return tmp
                      end
                      
                      function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
                      	tmp = 0.0;
                      	if ((y_46_im <= -1800.0) || ~((y_46_im <= 7.6e-28)))
                      		tmp = x_46_im / y_46_im;
                      	else
                      		tmp = x_46_re / y_46_re;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$im, -1800.0], N[Not[LessEqual[y$46$im, 7.6e-28]], $MachinePrecision]], N[(x$46$im / y$46$im), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;y.im \leq -1800 \lor \neg \left(y.im \leq 7.6 \cdot 10^{-28}\right):\\
                      \;\;\;\;\frac{x.im}{y.im}\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\frac{x.re}{y.re}\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if y.im < -1800 or 7.60000000000000018e-28 < y.im

                        1. Initial program 44.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.re around 0

                          \[\leadsto \color{blue}{\frac{x.im}{y.im}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites69.3%

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

                          if -1800 < y.im < 7.60000000000000018e-28

                          1. Initial program 73.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 \color{blue}{\frac{x.re}{y.re}} \]
                          4. Step-by-step derivation
                            1. Applied rewrites66.8%

                              \[\leadsto \color{blue}{\frac{x.re}{y.re}} \]
                          5. Recombined 2 regimes into one program.
                          6. Final simplification68.2%

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

                          Alternative 6: 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;
                          }
                          
                          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 56.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. Applied rewrites47.1%

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

                            Reproduce

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