Complex division, imag part

Percentage Accurate: 61.7% → 80.4%
Time: 4.9s
Alternatives: 8
Speedup: 1.5×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
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(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\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: 61.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
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(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Alternative 1: 80.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b - \frac{a}{c} \cdot d}{c}\\ \mathbf{if}\;c \leq -1.06 \cdot 10^{+74}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -5 \cdot 10^{-55}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{+23}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- b (* (/ a c) d)) c)))
   (if (<= c -1.06e+74)
     t_0
     (if (<= c -5e-55)
       (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
       (if (<= c 6.5e+23) (/ (fma (/ c d) b (- a)) d) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b - ((a / c) * d)) / c;
	double tmp;
	if (c <= -1.06e+74) {
		tmp = t_0;
	} else if (c <= -5e-55) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (c <= 6.5e+23) {
		tmp = fma((c / d), b, -a) / d;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c)
	tmp = 0.0
	if (c <= -1.06e+74)
		tmp = t_0;
	elseif (c <= -5e-55)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 6.5e+23)
		tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d);
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.06e+74], t$95$0, If[LessEqual[c, -5e-55], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.5e+23], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -1.06 \cdot 10^{+74}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq -5 \cdot 10^{-55}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;c \leq 6.5 \cdot 10^{+23}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.05999999999999999e74 or 6.4999999999999996e23 < c

    1. Initial program 41.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. Applied rewrites78.0%

        \[\leadsto \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}} \]
      2. Step-by-step derivation
        1. Applied rewrites87.5%

          \[\leadsto \color{blue}{\frac{b - \frac{a}{c} \cdot d}{c}} \]

        if -1.05999999999999999e74 < c < -5.0000000000000002e-55

        1. Initial program 87.8%

          \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
        2. Add Preprocessing

        if -5.0000000000000002e-55 < c < 6.4999999999999996e23

        1. Initial program 73.4%

          \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
        2. Add Preprocessing
        3. Taylor expanded in c around 0

          \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
        4. Step-by-step derivation
          1. Applied rewrites87.2%

            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}} \]
        5. Recombined 3 regimes into one program.
        6. Add Preprocessing

        Alternative 2: 64.1% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -55000000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.22 \cdot 10^{-58}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 8.3 \cdot 10^{+127}:\\ \;\;\;\;\frac{c \cdot b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\ \;\;\;\;d \cdot \frac{-a}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
        (FPCore (a b c d)
         :precision binary64
         (if (<= c -55000000000.0)
           (/ b c)
           (if (<= c 1.22e-58)
             (/ (- a) d)
             (if (<= c 8.3e+127)
               (/ (* c b) (fma c c (* d d)))
               (if (<= c 8.65e+148) (* d (/ (- a) (* c c))) (/ b c))))))
        double code(double a, double b, double c, double d) {
        	double tmp;
        	if (c <= -55000000000.0) {
        		tmp = b / c;
        	} else if (c <= 1.22e-58) {
        		tmp = -a / d;
        	} else if (c <= 8.3e+127) {
        		tmp = (c * b) / fma(c, c, (d * d));
        	} else if (c <= 8.65e+148) {
        		tmp = d * (-a / (c * c));
        	} else {
        		tmp = b / c;
        	}
        	return tmp;
        }
        
        function code(a, b, c, d)
        	tmp = 0.0
        	if (c <= -55000000000.0)
        		tmp = Float64(b / c);
        	elseif (c <= 1.22e-58)
        		tmp = Float64(Float64(-a) / d);
        	elseif (c <= 8.3e+127)
        		tmp = Float64(Float64(c * b) / fma(c, c, Float64(d * d)));
        	elseif (c <= 8.65e+148)
        		tmp = Float64(d * Float64(Float64(-a) / Float64(c * c)));
        	else
        		tmp = Float64(b / c);
        	end
        	return tmp
        end
        
        code[a_, b_, c_, d_] := If[LessEqual[c, -55000000000.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.22e-58], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 8.3e+127], N[(N[(c * b), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.65e+148], N[(d * N[((-a) / N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;c \leq -55000000000:\\
        \;\;\;\;\frac{b}{c}\\
        
        \mathbf{elif}\;c \leq 1.22 \cdot 10^{-58}:\\
        \;\;\;\;\frac{-a}{d}\\
        
        \mathbf{elif}\;c \leq 8.3 \cdot 10^{+127}:\\
        \;\;\;\;\frac{c \cdot b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
        
        \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\
        \;\;\;\;d \cdot \frac{-a}{c \cdot c}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{b}{c}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if c < -5.5e10 or 8.64999999999999954e148 < c

          1. Initial program 35.5%

            \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
          2. Add Preprocessing
          3. Taylor expanded in c around inf

            \[\leadsto \color{blue}{\frac{b}{c}} \]
          4. Step-by-step derivation
            1. Applied rewrites69.1%

              \[\leadsto \color{blue}{\frac{b}{c}} \]

            if -5.5e10 < c < 1.2199999999999999e-58

            1. Initial program 72.4%

              \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
            2. Add Preprocessing
            3. Taylor expanded in c around 0

              \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
            4. Step-by-step derivation
              1. Applied rewrites68.9%

                \[\leadsto \color{blue}{\frac{-a}{d}} \]

              if 1.2199999999999999e-58 < c < 8.2999999999999997e127

              1. Initial program 88.0%

                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
              2. Add Preprocessing
              3. Taylor expanded in a around 0

                \[\leadsto \color{blue}{\frac{b \cdot c}{{c}^{2} + {d}^{2}}} \]
              4. Step-by-step derivation
                1. Applied rewrites63.7%

                  \[\leadsto \color{blue}{\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b} \]
                2. Step-by-step derivation
                  1. Applied rewrites65.8%

                    \[\leadsto \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]

                  if 8.2999999999999997e127 < c < 8.64999999999999954e148

                  1. Initial program 80.1%

                    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                  2. Add Preprocessing
                  3. Taylor expanded in a around inf

                    \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2} + {d}^{2}}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites100.0%

                      \[\leadsto \color{blue}{\left(-d\right) \cdot \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
                    2. Taylor expanded in c around inf

                      \[\leadsto \left(-d\right) \cdot \frac{a}{{c}^{\color{blue}{2}}} \]
                    3. Step-by-step derivation
                      1. Applied rewrites100.0%

                        \[\leadsto \left(-d\right) \cdot \frac{a}{c \cdot \color{blue}{c}} \]
                    4. Recombined 4 regimes into one program.
                    5. Final simplification69.1%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -55000000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.22 \cdot 10^{-58}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 8.3 \cdot 10^{+127}:\\ \;\;\;\;\frac{c \cdot b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\ \;\;\;\;d \cdot \frac{-a}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
                    6. Add Preprocessing

                    Alternative 3: 64.6% accurate, 0.8× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -55000000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.22 \cdot 10^{-58}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 10^{+128}:\\ \;\;\;\;c \cdot \frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\ \;\;\;\;d \cdot \frac{-a}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
                    (FPCore (a b c d)
                     :precision binary64
                     (if (<= c -55000000000.0)
                       (/ b c)
                       (if (<= c 1.22e-58)
                         (/ (- a) d)
                         (if (<= c 1e+128)
                           (* c (/ b (fma c c (* d d))))
                           (if (<= c 8.65e+148) (* d (/ (- a) (* c c))) (/ b c))))))
                    double code(double a, double b, double c, double d) {
                    	double tmp;
                    	if (c <= -55000000000.0) {
                    		tmp = b / c;
                    	} else if (c <= 1.22e-58) {
                    		tmp = -a / d;
                    	} else if (c <= 1e+128) {
                    		tmp = c * (b / fma(c, c, (d * d)));
                    	} else if (c <= 8.65e+148) {
                    		tmp = d * (-a / (c * c));
                    	} else {
                    		tmp = b / c;
                    	}
                    	return tmp;
                    }
                    
                    function code(a, b, c, d)
                    	tmp = 0.0
                    	if (c <= -55000000000.0)
                    		tmp = Float64(b / c);
                    	elseif (c <= 1.22e-58)
                    		tmp = Float64(Float64(-a) / d);
                    	elseif (c <= 1e+128)
                    		tmp = Float64(c * Float64(b / fma(c, c, Float64(d * d))));
                    	elseif (c <= 8.65e+148)
                    		tmp = Float64(d * Float64(Float64(-a) / Float64(c * c)));
                    	else
                    		tmp = Float64(b / c);
                    	end
                    	return tmp
                    end
                    
                    code[a_, b_, c_, d_] := If[LessEqual[c, -55000000000.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 1.22e-58], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1e+128], N[(c * N[(b / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.65e+148], N[(d * N[((-a) / N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;c \leq -55000000000:\\
                    \;\;\;\;\frac{b}{c}\\
                    
                    \mathbf{elif}\;c \leq 1.22 \cdot 10^{-58}:\\
                    \;\;\;\;\frac{-a}{d}\\
                    
                    \mathbf{elif}\;c \leq 10^{+128}:\\
                    \;\;\;\;c \cdot \frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
                    
                    \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\
                    \;\;\;\;d \cdot \frac{-a}{c \cdot c}\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\frac{b}{c}\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 4 regimes
                    2. if c < -5.5e10 or 8.64999999999999954e148 < c

                      1. Initial program 35.5%

                        \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                      2. Add Preprocessing
                      3. Taylor expanded in c around inf

                        \[\leadsto \color{blue}{\frac{b}{c}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites69.1%

                          \[\leadsto \color{blue}{\frac{b}{c}} \]

                        if -5.5e10 < c < 1.2199999999999999e-58

                        1. Initial program 72.4%

                          \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                        2. Add Preprocessing
                        3. Taylor expanded in c around 0

                          \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites68.9%

                            \[\leadsto \color{blue}{\frac{-a}{d}} \]

                          if 1.2199999999999999e-58 < c < 1.0000000000000001e128

                          1. Initial program 88.0%

                            \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                          2. Add Preprocessing
                          3. Taylor expanded in a around 0

                            \[\leadsto \color{blue}{\frac{b \cdot c}{{c}^{2} + {d}^{2}}} \]
                          4. Step-by-step derivation
                            1. Applied rewrites63.7%

                              \[\leadsto \color{blue}{\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b} \]
                            2. Step-by-step derivation
                              1. Applied rewrites65.8%

                                \[\leadsto c \cdot \color{blue}{\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]

                              if 1.0000000000000001e128 < c < 8.64999999999999954e148

                              1. Initial program 80.1%

                                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                              2. Add Preprocessing
                              3. Taylor expanded in a around inf

                                \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2} + {d}^{2}}} \]
                              4. Step-by-step derivation
                                1. Applied rewrites100.0%

                                  \[\leadsto \color{blue}{\left(-d\right) \cdot \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
                                2. Taylor expanded in c around inf

                                  \[\leadsto \left(-d\right) \cdot \frac{a}{{c}^{\color{blue}{2}}} \]
                                3. Step-by-step derivation
                                  1. Applied rewrites100.0%

                                    \[\leadsto \left(-d\right) \cdot \frac{a}{c \cdot \color{blue}{c}} \]
                                4. Recombined 4 regimes into one program.
                                5. Final simplification69.0%

                                  \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -55000000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.22 \cdot 10^{-58}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 10^{+128}:\\ \;\;\;\;c \cdot \frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\ \;\;\;\;d \cdot \frac{-a}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
                                6. Add Preprocessing

                                Alternative 4: 64.7% accurate, 0.8× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -55000000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 10^{-46}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
                                (FPCore (a b c d)
                                 :precision binary64
                                 (if (<= c -55000000000.0)
                                   (/ b c)
                                   (if (<= c 1e-46)
                                     (/ (- a) d)
                                     (if (<= c 8.65e+148) (/ (- (* b c) (* a d)) (* c c)) (/ b c)))))
                                double code(double a, double b, double c, double d) {
                                	double tmp;
                                	if (c <= -55000000000.0) {
                                		tmp = b / c;
                                	} else if (c <= 1e-46) {
                                		tmp = -a / d;
                                	} else if (c <= 8.65e+148) {
                                		tmp = ((b * c) - (a * d)) / (c * c);
                                	} else {
                                		tmp = b / c;
                                	}
                                	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(a, b, c, d)
                                use fmin_fmax_functions
                                    real(8), intent (in) :: a
                                    real(8), intent (in) :: b
                                    real(8), intent (in) :: c
                                    real(8), intent (in) :: d
                                    real(8) :: tmp
                                    if (c <= (-55000000000.0d0)) then
                                        tmp = b / c
                                    else if (c <= 1d-46) then
                                        tmp = -a / d
                                    else if (c <= 8.65d+148) then
                                        tmp = ((b * c) - (a * d)) / (c * c)
                                    else
                                        tmp = b / c
                                    end if
                                    code = tmp
                                end function
                                
                                public static double code(double a, double b, double c, double d) {
                                	double tmp;
                                	if (c <= -55000000000.0) {
                                		tmp = b / c;
                                	} else if (c <= 1e-46) {
                                		tmp = -a / d;
                                	} else if (c <= 8.65e+148) {
                                		tmp = ((b * c) - (a * d)) / (c * c);
                                	} else {
                                		tmp = b / c;
                                	}
                                	return tmp;
                                }
                                
                                def code(a, b, c, d):
                                	tmp = 0
                                	if c <= -55000000000.0:
                                		tmp = b / c
                                	elif c <= 1e-46:
                                		tmp = -a / d
                                	elif c <= 8.65e+148:
                                		tmp = ((b * c) - (a * d)) / (c * c)
                                	else:
                                		tmp = b / c
                                	return tmp
                                
                                function code(a, b, c, d)
                                	tmp = 0.0
                                	if (c <= -55000000000.0)
                                		tmp = Float64(b / c);
                                	elseif (c <= 1e-46)
                                		tmp = Float64(Float64(-a) / d);
                                	elseif (c <= 8.65e+148)
                                		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c));
                                	else
                                		tmp = Float64(b / c);
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(a, b, c, d)
                                	tmp = 0.0;
                                	if (c <= -55000000000.0)
                                		tmp = b / c;
                                	elseif (c <= 1e-46)
                                		tmp = -a / d;
                                	elseif (c <= 8.65e+148)
                                		tmp = ((b * c) - (a * d)) / (c * c);
                                	else
                                		tmp = b / c;
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[a_, b_, c_, d_] := If[LessEqual[c, -55000000000.0], N[(b / c), $MachinePrecision], If[LessEqual[c, 1e-46], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 8.65e+148], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                \mathbf{if}\;c \leq -55000000000:\\
                                \;\;\;\;\frac{b}{c}\\
                                
                                \mathbf{elif}\;c \leq 10^{-46}:\\
                                \;\;\;\;\frac{-a}{d}\\
                                
                                \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\
                                \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\frac{b}{c}\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 3 regimes
                                2. if c < -5.5e10 or 8.64999999999999954e148 < c

                                  1. Initial program 35.5%

                                    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in c around inf

                                    \[\leadsto \color{blue}{\frac{b}{c}} \]
                                  4. Step-by-step derivation
                                    1. Applied rewrites69.1%

                                      \[\leadsto \color{blue}{\frac{b}{c}} \]

                                    if -5.5e10 < c < 1.00000000000000002e-46

                                    1. Initial program 72.8%

                                      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in c around 0

                                      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
                                    4. Step-by-step derivation
                                      1. Applied rewrites68.5%

                                        \[\leadsto \color{blue}{\frac{-a}{d}} \]

                                      if 1.00000000000000002e-46 < c < 8.64999999999999954e148

                                      1. Initial program 88.0%

                                        \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in c around inf

                                        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{{c}^{2}}} \]
                                      4. Step-by-step derivation
                                        1. Applied rewrites72.2%

                                          \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c}} \]
                                      5. Recombined 3 regimes into one program.
                                      6. Final simplification69.3%

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -55000000000:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 10^{-46}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 8.65 \cdot 10^{+148}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
                                      7. Add Preprocessing

                                      Alternative 5: 78.2% accurate, 0.9× speedup?

                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.12 \cdot 10^{+42} \lor \neg \left(c \leq 6.5 \cdot 10^{+23}\right):\\ \;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\ \end{array} \end{array} \]
                                      (FPCore (a b c d)
                                       :precision binary64
                                       (if (or (<= c -1.12e+42) (not (<= c 6.5e+23)))
                                         (/ (- b (* (/ a c) d)) c)
                                         (/ (fma (/ c d) b (- a)) d)))
                                      double code(double a, double b, double c, double d) {
                                      	double tmp;
                                      	if ((c <= -1.12e+42) || !(c <= 6.5e+23)) {
                                      		tmp = (b - ((a / c) * d)) / c;
                                      	} else {
                                      		tmp = fma((c / d), b, -a) / d;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      function code(a, b, c, d)
                                      	tmp = 0.0
                                      	if ((c <= -1.12e+42) || !(c <= 6.5e+23))
                                      		tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c);
                                      	else
                                      		tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d);
                                      	end
                                      	return tmp
                                      end
                                      
                                      code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.12e+42], N[Not[LessEqual[c, 6.5e+23]], $MachinePrecision]], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision]]
                                      
                                      \begin{array}{l}
                                      
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;c \leq -1.12 \cdot 10^{+42} \lor \neg \left(c \leq 6.5 \cdot 10^{+23}\right):\\
                                      \;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 2 regimes
                                      2. if c < -1.12e42 or 6.4999999999999996e23 < c

                                        1. Initial program 45.6%

                                          \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in c around inf

                                          \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
                                        4. Step-by-step derivation
                                          1. Applied rewrites77.4%

                                            \[\leadsto \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}} \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites86.2%

                                              \[\leadsto \color{blue}{\frac{b - \frac{a}{c} \cdot d}{c}} \]

                                            if -1.12e42 < c < 6.4999999999999996e23

                                            1. Initial program 75.0%

                                              \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in c around 0

                                              \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
                                            4. Step-by-step derivation
                                              1. Applied rewrites83.3%

                                                \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}} \]
                                            5. Recombined 2 regimes into one program.
                                            6. Final simplification84.7%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.12 \cdot 10^{+42} \lor \neg \left(c \leq 6.5 \cdot 10^{+23}\right):\\ \;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\ \end{array} \]
                                            7. Add Preprocessing

                                            Alternative 6: 69.5% accurate, 0.9× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -47000000000 \lor \neg \left(c \leq 1.5 \cdot 10^{-43}\right):\\ \;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \end{array} \]
                                            (FPCore (a b c d)
                                             :precision binary64
                                             (if (or (<= c -47000000000.0) (not (<= c 1.5e-43)))
                                               (/ (- b (* (/ a c) d)) c)
                                               (/ (- a) d)))
                                            double code(double a, double b, double c, double d) {
                                            	double tmp;
                                            	if ((c <= -47000000000.0) || !(c <= 1.5e-43)) {
                                            		tmp = (b - ((a / c) * d)) / c;
                                            	} else {
                                            		tmp = -a / d;
                                            	}
                                            	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(a, b, c, d)
                                            use fmin_fmax_functions
                                                real(8), intent (in) :: a
                                                real(8), intent (in) :: b
                                                real(8), intent (in) :: c
                                                real(8), intent (in) :: d
                                                real(8) :: tmp
                                                if ((c <= (-47000000000.0d0)) .or. (.not. (c <= 1.5d-43))) then
                                                    tmp = (b - ((a / c) * d)) / c
                                                else
                                                    tmp = -a / d
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double a, double b, double c, double d) {
                                            	double tmp;
                                            	if ((c <= -47000000000.0) || !(c <= 1.5e-43)) {
                                            		tmp = (b - ((a / c) * d)) / c;
                                            	} else {
                                            		tmp = -a / d;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(a, b, c, d):
                                            	tmp = 0
                                            	if (c <= -47000000000.0) or not (c <= 1.5e-43):
                                            		tmp = (b - ((a / c) * d)) / c
                                            	else:
                                            		tmp = -a / d
                                            	return tmp
                                            
                                            function code(a, b, c, d)
                                            	tmp = 0.0
                                            	if ((c <= -47000000000.0) || !(c <= 1.5e-43))
                                            		tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c);
                                            	else
                                            		tmp = Float64(Float64(-a) / d);
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(a, b, c, d)
                                            	tmp = 0.0;
                                            	if ((c <= -47000000000.0) || ~((c <= 1.5e-43)))
                                            		tmp = (b - ((a / c) * d)) / c;
                                            	else
                                            		tmp = -a / d;
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[a_, b_, c_, d_] := If[Or[LessEqual[c, -47000000000.0], N[Not[LessEqual[c, 1.5e-43]], $MachinePrecision]], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;c \leq -47000000000 \lor \neg \left(c \leq 1.5 \cdot 10^{-43}\right):\\
                                            \;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{-a}{d}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if c < -4.7e10 or 1.50000000000000002e-43 < c

                                              1. Initial program 51.1%

                                                \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in c around inf

                                                \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
                                              4. Step-by-step derivation
                                                1. Applied rewrites73.5%

                                                  \[\leadsto \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}} \]
                                                2. Step-by-step derivation
                                                  1. Applied rewrites81.2%

                                                    \[\leadsto \color{blue}{\frac{b - \frac{a}{c} \cdot d}{c}} \]

                                                  if -4.7e10 < c < 1.50000000000000002e-43

                                                  1. Initial program 72.8%

                                                    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                                  2. Add Preprocessing
                                                  3. Taylor expanded in c around 0

                                                    \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
                                                  4. Step-by-step derivation
                                                    1. Applied rewrites68.5%

                                                      \[\leadsto \color{blue}{\frac{-a}{d}} \]
                                                  5. Recombined 2 regimes into one program.
                                                  6. Final simplification75.6%

                                                    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -47000000000 \lor \neg \left(c \leq 1.5 \cdot 10^{-43}\right):\\ \;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
                                                  7. Add Preprocessing

                                                  Alternative 7: 63.9% accurate, 1.5× speedup?

                                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -55000000000 \lor \neg \left(c \leq 1.95 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \end{array} \]
                                                  (FPCore (a b c d)
                                                   :precision binary64
                                                   (if (or (<= c -55000000000.0) (not (<= c 1.95e+31))) (/ b c) (/ (- a) d)))
                                                  double code(double a, double b, double c, double d) {
                                                  	double tmp;
                                                  	if ((c <= -55000000000.0) || !(c <= 1.95e+31)) {
                                                  		tmp = b / c;
                                                  	} else {
                                                  		tmp = -a / d;
                                                  	}
                                                  	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(a, b, c, d)
                                                  use fmin_fmax_functions
                                                      real(8), intent (in) :: a
                                                      real(8), intent (in) :: b
                                                      real(8), intent (in) :: c
                                                      real(8), intent (in) :: d
                                                      real(8) :: tmp
                                                      if ((c <= (-55000000000.0d0)) .or. (.not. (c <= 1.95d+31))) then
                                                          tmp = b / c
                                                      else
                                                          tmp = -a / d
                                                      end if
                                                      code = tmp
                                                  end function
                                                  
                                                  public static double code(double a, double b, double c, double d) {
                                                  	double tmp;
                                                  	if ((c <= -55000000000.0) || !(c <= 1.95e+31)) {
                                                  		tmp = b / c;
                                                  	} else {
                                                  		tmp = -a / d;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  def code(a, b, c, d):
                                                  	tmp = 0
                                                  	if (c <= -55000000000.0) or not (c <= 1.95e+31):
                                                  		tmp = b / c
                                                  	else:
                                                  		tmp = -a / d
                                                  	return tmp
                                                  
                                                  function code(a, b, c, d)
                                                  	tmp = 0.0
                                                  	if ((c <= -55000000000.0) || !(c <= 1.95e+31))
                                                  		tmp = Float64(b / c);
                                                  	else
                                                  		tmp = Float64(Float64(-a) / d);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  function tmp_2 = code(a, b, c, d)
                                                  	tmp = 0.0;
                                                  	if ((c <= -55000000000.0) || ~((c <= 1.95e+31)))
                                                  		tmp = b / c;
                                                  	else
                                                  		tmp = -a / d;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  code[a_, b_, c_, d_] := If[Or[LessEqual[c, -55000000000.0], N[Not[LessEqual[c, 1.95e+31]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;c \leq -55000000000 \lor \neg \left(c \leq 1.95 \cdot 10^{+31}\right):\\
                                                  \;\;\;\;\frac{b}{c}\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;\frac{-a}{d}\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if c < -5.5e10 or 1.95e31 < c

                                                    1. Initial program 46.5%

                                                      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                                    2. Add Preprocessing
                                                    3. Taylor expanded in c around inf

                                                      \[\leadsto \color{blue}{\frac{b}{c}} \]
                                                    4. Step-by-step derivation
                                                      1. Applied rewrites65.6%

                                                        \[\leadsto \color{blue}{\frac{b}{c}} \]

                                                      if -5.5e10 < c < 1.95e31

                                                      1. Initial program 74.5%

                                                        \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                                      2. Add Preprocessing
                                                      3. Taylor expanded in c around 0

                                                        \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
                                                      4. Step-by-step derivation
                                                        1. Applied rewrites65.7%

                                                          \[\leadsto \color{blue}{\frac{-a}{d}} \]
                                                      5. Recombined 2 regimes into one program.
                                                      6. Final simplification65.7%

                                                        \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -55000000000 \lor \neg \left(c \leq 1.95 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
                                                      7. Add Preprocessing

                                                      Alternative 8: 42.4% accurate, 3.2× speedup?

                                                      \[\begin{array}{l} \\ \frac{b}{c} \end{array} \]
                                                      (FPCore (a b c d) :precision binary64 (/ b c))
                                                      double code(double a, double b, double c, double d) {
                                                      	return b / c;
                                                      }
                                                      
                                                      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(a, b, c, d)
                                                      use fmin_fmax_functions
                                                          real(8), intent (in) :: a
                                                          real(8), intent (in) :: b
                                                          real(8), intent (in) :: c
                                                          real(8), intent (in) :: d
                                                          code = b / c
                                                      end function
                                                      
                                                      public static double code(double a, double b, double c, double d) {
                                                      	return b / c;
                                                      }
                                                      
                                                      def code(a, b, c, d):
                                                      	return b / c
                                                      
                                                      function code(a, b, c, d)
                                                      	return Float64(b / c)
                                                      end
                                                      
                                                      function tmp = code(a, b, c, d)
                                                      	tmp = b / c;
                                                      end
                                                      
                                                      code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
                                                      
                                                      \begin{array}{l}
                                                      
                                                      \\
                                                      \frac{b}{c}
                                                      \end{array}
                                                      
                                                      Derivation
                                                      1. Initial program 60.7%

                                                        \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
                                                      2. Add Preprocessing
                                                      3. Taylor expanded in c around inf

                                                        \[\leadsto \color{blue}{\frac{b}{c}} \]
                                                      4. Step-by-step derivation
                                                        1. Applied rewrites44.6%

                                                          \[\leadsto \color{blue}{\frac{b}{c}} \]
                                                        2. Add Preprocessing

                                                        Developer Target 1: 99.3% accurate, 0.6× speedup?

                                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
                                                        (FPCore (a b c d)
                                                         :precision binary64
                                                         (if (< (fabs d) (fabs c))
                                                           (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
                                                           (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
                                                        double code(double a, double b, double c, double d) {
                                                        	double tmp;
                                                        	if (fabs(d) < fabs(c)) {
                                                        		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
                                                        	} else {
                                                        		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
                                                        	}
                                                        	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(a, b, c, d)
                                                        use fmin_fmax_functions
                                                            real(8), intent (in) :: a
                                                            real(8), intent (in) :: b
                                                            real(8), intent (in) :: c
                                                            real(8), intent (in) :: d
                                                            real(8) :: tmp
                                                            if (abs(d) < abs(c)) then
                                                                tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
                                                            else
                                                                tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
                                                            end if
                                                            code = tmp
                                                        end function
                                                        
                                                        public static double code(double a, double b, double c, double d) {
                                                        	double tmp;
                                                        	if (Math.abs(d) < Math.abs(c)) {
                                                        		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
                                                        	} else {
                                                        		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
                                                        	}
                                                        	return tmp;
                                                        }
                                                        
                                                        def code(a, b, c, d):
                                                        	tmp = 0
                                                        	if math.fabs(d) < math.fabs(c):
                                                        		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
                                                        	else:
                                                        		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
                                                        	return tmp
                                                        
                                                        function code(a, b, c, d)
                                                        	tmp = 0.0
                                                        	if (abs(d) < abs(c))
                                                        		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
                                                        	else
                                                        		tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
                                                        	end
                                                        	return tmp
                                                        end
                                                        
                                                        function tmp_2 = code(a, b, c, d)
                                                        	tmp = 0.0;
                                                        	if (abs(d) < abs(c))
                                                        		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
                                                        	else
                                                        		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
                                                        	end
                                                        	tmp_2 = tmp;
                                                        end
                                                        
                                                        code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                                                        
                                                        \begin{array}{l}
                                                        
                                                        \\
                                                        \begin{array}{l}
                                                        \mathbf{if}\;\left|d\right| < \left|c\right|:\\
                                                        \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
                                                        
                                                        \mathbf{else}:\\
                                                        \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
                                                        
                                                        
                                                        \end{array}
                                                        \end{array}
                                                        

                                                        Reproduce

                                                        ?
                                                        herbie shell --seed 2025018 
                                                        (FPCore (a b c d)
                                                          :name "Complex division, imag part"
                                                          :precision binary64
                                                        
                                                          :alt
                                                          (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
                                                        
                                                          (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))