Complex division, imag part

Percentage Accurate: 62.1% → 80.2%
Time: 4.1s
Alternatives: 7
Speedup: 0.9×

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 7 alternatives:

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

Initial Program: 62.1% 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.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{+90}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \mathbf{elif}\;c \leq -4.1 \cdot 10^{-126}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{+88}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.5e+90)
   (/ (- b (* (/ d c) a)) c)
   (if (<= c -4.1e-126)
     (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
     (if (<= c 2.7e+88)
       (/ (fma (/ c d) b (- a)) d)
       (/ (- b (* d (/ a c))) c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.5e+90) {
		tmp = (b - ((d / c) * a)) / c;
	} else if (c <= -4.1e-126) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (c <= 2.7e+88) {
		tmp = fma((c / d), b, -a) / d;
	} else {
		tmp = (b - (d * (a / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.5e+90)
		tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c);
	elseif (c <= -4.1e-126)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 2.7e+88)
		tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d);
	else
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.5e+90], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.1e-126], 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, 2.7e+88], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{+90}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.49999999999999989e90

    1. Initial program 36.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 rewrites86.4%

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

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

        if -1.49999999999999989e90 < c < -4.0999999999999997e-126

        1. Initial program 82.0%

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

        if -4.0999999999999997e-126 < c < 2.70000000000000016e88

        1. Initial program 66.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 rewrites82.4%

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

          if 2.70000000000000016e88 < c

          1. Initial program 35.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 rewrites82.9%

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

                \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
            3. Recombined 4 regimes into one program.
            4. Add Preprocessing

            Alternative 2: 72.1% accurate, 0.9× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{+131} \lor \neg \left(d \leq 3.7 \cdot 10^{+44}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \end{array} \end{array} \]
            (FPCore (a b c d)
             :precision binary64
             (if (or (<= d -2.3e+131) (not (<= d 3.7e+44)))
               (/ (- a) d)
               (/ (- b (* (/ d c) a)) c)))
            double code(double a, double b, double c, double d) {
            	double tmp;
            	if ((d <= -2.3e+131) || !(d <= 3.7e+44)) {
            		tmp = -a / d;
            	} else {
            		tmp = (b - ((d / c) * a)) / 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 ((d <= (-2.3d+131)) .or. (.not. (d <= 3.7d+44))) then
                    tmp = -a / d
                else
                    tmp = (b - ((d / c) * a)) / c
                end if
                code = tmp
            end function
            
            public static double code(double a, double b, double c, double d) {
            	double tmp;
            	if ((d <= -2.3e+131) || !(d <= 3.7e+44)) {
            		tmp = -a / d;
            	} else {
            		tmp = (b - ((d / c) * a)) / c;
            	}
            	return tmp;
            }
            
            def code(a, b, c, d):
            	tmp = 0
            	if (d <= -2.3e+131) or not (d <= 3.7e+44):
            		tmp = -a / d
            	else:
            		tmp = (b - ((d / c) * a)) / c
            	return tmp
            
            function code(a, b, c, d)
            	tmp = 0.0
            	if ((d <= -2.3e+131) || !(d <= 3.7e+44))
            		tmp = Float64(Float64(-a) / d);
            	else
            		tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c);
            	end
            	return tmp
            end
            
            function tmp_2 = code(a, b, c, d)
            	tmp = 0.0;
            	if ((d <= -2.3e+131) || ~((d <= 3.7e+44)))
            		tmp = -a / d;
            	else
            		tmp = (b - ((d / c) * a)) / c;
            	end
            	tmp_2 = tmp;
            end
            
            code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.3e+131], N[Not[LessEqual[d, 3.7e+44]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;d \leq -2.3 \cdot 10^{+131} \lor \neg \left(d \leq 3.7 \cdot 10^{+44}\right):\\
            \;\;\;\;\frac{-a}{d}\\
            
            \mathbf{else}:\\
            \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d < -2.29999999999999992e131 or 3.7000000000000001e44 < d

              1. Initial program 36.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 rewrites75.6%

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

                if -2.29999999999999992e131 < d < 3.7000000000000001e44

                1. Initial program 69.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.8%

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

                      \[\leadsto \frac{b - \frac{d}{c} \cdot a}{c} \]
                  3. Recombined 2 regimes into one program.
                  4. Final simplification77.7%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{+131} \lor \neg \left(d \leq 3.7 \cdot 10^{+44}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 3: 71.2% accurate, 0.9× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{+131} \lor \neg \left(d \leq 3.7 \cdot 10^{+44}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \end{array} \]
                  (FPCore (a b c d)
                   :precision binary64
                   (if (or (<= d -2.3e+131) (not (<= d 3.7e+44)))
                     (/ (- a) d)
                     (/ (- b (* d (/ a c))) c)))
                  double code(double a, double b, double c, double d) {
                  	double tmp;
                  	if ((d <= -2.3e+131) || !(d <= 3.7e+44)) {
                  		tmp = -a / d;
                  	} else {
                  		tmp = (b - (d * (a / c))) / 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 ((d <= (-2.3d+131)) .or. (.not. (d <= 3.7d+44))) then
                          tmp = -a / d
                      else
                          tmp = (b - (d * (a / c))) / c
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double a, double b, double c, double d) {
                  	double tmp;
                  	if ((d <= -2.3e+131) || !(d <= 3.7e+44)) {
                  		tmp = -a / d;
                  	} else {
                  		tmp = (b - (d * (a / c))) / c;
                  	}
                  	return tmp;
                  }
                  
                  def code(a, b, c, d):
                  	tmp = 0
                  	if (d <= -2.3e+131) or not (d <= 3.7e+44):
                  		tmp = -a / d
                  	else:
                  		tmp = (b - (d * (a / c))) / c
                  	return tmp
                  
                  function code(a, b, c, d)
                  	tmp = 0.0
                  	if ((d <= -2.3e+131) || !(d <= 3.7e+44))
                  		tmp = Float64(Float64(-a) / d);
                  	else
                  		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(a, b, c, d)
                  	tmp = 0.0;
                  	if ((d <= -2.3e+131) || ~((d <= 3.7e+44)))
                  		tmp = -a / d;
                  	else
                  		tmp = (b - (d * (a / c))) / c;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.3e+131], N[Not[LessEqual[d, 3.7e+44]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;d \leq -2.3 \cdot 10^{+131} \lor \neg \left(d \leq 3.7 \cdot 10^{+44}\right):\\
                  \;\;\;\;\frac{-a}{d}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if d < -2.29999999999999992e131 or 3.7000000000000001e44 < d

                    1. Initial program 36.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 rewrites75.6%

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

                      if -2.29999999999999992e131 < d < 3.7000000000000001e44

                      1. Initial program 69.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.8%

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

                            \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
                        3. Recombined 2 regimes into one program.
                        4. Final simplification77.4%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{+131} \lor \neg \left(d \leq 3.7 \cdot 10^{+44}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
                        5. Add Preprocessing

                        Alternative 4: 76.7% accurate, 0.9× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -4.6 \cdot 10^{+62}:\\ \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{+88}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \end{array} \]
                        (FPCore (a b c d)
                         :precision binary64
                         (if (<= c -4.6e+62)
                           (/ (- b (* (/ d c) a)) c)
                           (if (<= c 2.7e+88) (/ (fma (/ c d) b (- a)) d) (/ (- b (* d (/ a c))) c))))
                        double code(double a, double b, double c, double d) {
                        	double tmp;
                        	if (c <= -4.6e+62) {
                        		tmp = (b - ((d / c) * a)) / c;
                        	} else if (c <= 2.7e+88) {
                        		tmp = fma((c / d), b, -a) / d;
                        	} else {
                        		tmp = (b - (d * (a / c))) / c;
                        	}
                        	return tmp;
                        }
                        
                        function code(a, b, c, d)
                        	tmp = 0.0
                        	if (c <= -4.6e+62)
                        		tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c);
                        	elseif (c <= 2.7e+88)
                        		tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d);
                        	else
                        		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
                        	end
                        	return tmp
                        end
                        
                        code[a_, b_, c_, d_] := If[LessEqual[c, -4.6e+62], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.7e+88], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;c \leq -4.6 \cdot 10^{+62}:\\
                        \;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
                        
                        \mathbf{elif}\;c \leq 2.7 \cdot 10^{+88}:\\
                        \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 3 regimes
                        2. if c < -4.59999999999999968e62

                          1. Initial program 43.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 rewrites83.6%

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

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

                              if -4.59999999999999968e62 < c < 2.70000000000000016e88

                              1. Initial program 70.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} + \frac{b \cdot c}{{d}^{2}}} \]
                              4. Step-by-step derivation
                                1. Applied rewrites78.0%

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

                                if 2.70000000000000016e88 < c

                                1. Initial program 35.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 rewrites82.9%

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

                                      \[\leadsto \frac{b - d \cdot \frac{a}{c}}{c} \]
                                  3. Recombined 3 regimes into one program.
                                  4. Add Preprocessing

                                  Alternative 5: 64.2% accurate, 0.9× speedup?

                                  \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-a}{d}\\ \mathbf{if}\;d \leq -8.6 \cdot 10^{+150}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{-29}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{+43}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                                  (FPCore (a b c d)
                                   :precision binary64
                                   (let* ((t_0 (/ (- a) d)))
                                     (if (<= d -8.6e+150)
                                       t_0
                                       (if (<= d -4.8e-29)
                                         (/ (- (* b c) (* a d)) (* d d))
                                         (if (<= d 9.5e+43) (/ b c) t_0)))))
                                  double code(double a, double b, double c, double d) {
                                  	double t_0 = -a / d;
                                  	double tmp;
                                  	if (d <= -8.6e+150) {
                                  		tmp = t_0;
                                  	} else if (d <= -4.8e-29) {
                                  		tmp = ((b * c) - (a * d)) / (d * d);
                                  	} else if (d <= 9.5e+43) {
                                  		tmp = b / c;
                                  	} else {
                                  		tmp = t_0;
                                  	}
                                  	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) :: t_0
                                      real(8) :: tmp
                                      t_0 = -a / d
                                      if (d <= (-8.6d+150)) then
                                          tmp = t_0
                                      else if (d <= (-4.8d-29)) then
                                          tmp = ((b * c) - (a * d)) / (d * d)
                                      else if (d <= 9.5d+43) then
                                          tmp = b / c
                                      else
                                          tmp = t_0
                                      end if
                                      code = tmp
                                  end function
                                  
                                  public static double code(double a, double b, double c, double d) {
                                  	double t_0 = -a / d;
                                  	double tmp;
                                  	if (d <= -8.6e+150) {
                                  		tmp = t_0;
                                  	} else if (d <= -4.8e-29) {
                                  		tmp = ((b * c) - (a * d)) / (d * d);
                                  	} else if (d <= 9.5e+43) {
                                  		tmp = b / c;
                                  	} else {
                                  		tmp = t_0;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  def code(a, b, c, d):
                                  	t_0 = -a / d
                                  	tmp = 0
                                  	if d <= -8.6e+150:
                                  		tmp = t_0
                                  	elif d <= -4.8e-29:
                                  		tmp = ((b * c) - (a * d)) / (d * d)
                                  	elif d <= 9.5e+43:
                                  		tmp = b / c
                                  	else:
                                  		tmp = t_0
                                  	return tmp
                                  
                                  function code(a, b, c, d)
                                  	t_0 = Float64(Float64(-a) / d)
                                  	tmp = 0.0
                                  	if (d <= -8.6e+150)
                                  		tmp = t_0;
                                  	elseif (d <= -4.8e-29)
                                  		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(d * d));
                                  	elseif (d <= 9.5e+43)
                                  		tmp = Float64(b / c);
                                  	else
                                  		tmp = t_0;
                                  	end
                                  	return tmp
                                  end
                                  
                                  function tmp_2 = code(a, b, c, d)
                                  	t_0 = -a / d;
                                  	tmp = 0.0;
                                  	if (d <= -8.6e+150)
                                  		tmp = t_0;
                                  	elseif (d <= -4.8e-29)
                                  		tmp = ((b * c) - (a * d)) / (d * d);
                                  	elseif (d <= 9.5e+43)
                                  		tmp = b / c;
                                  	else
                                  		tmp = t_0;
                                  	end
                                  	tmp_2 = tmp;
                                  end
                                  
                                  code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -8.6e+150], t$95$0, If[LessEqual[d, -4.8e-29], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.5e+43], N[(b / c), $MachinePrecision], t$95$0]]]]
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  \begin{array}{l}
                                  t_0 := \frac{-a}{d}\\
                                  \mathbf{if}\;d \leq -8.6 \cdot 10^{+150}:\\
                                  \;\;\;\;t\_0\\
                                  
                                  \mathbf{elif}\;d \leq -4.8 \cdot 10^{-29}:\\
                                  \;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\
                                  
                                  \mathbf{elif}\;d \leq 9.5 \cdot 10^{+43}:\\
                                  \;\;\;\;\frac{b}{c}\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;t\_0\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 3 regimes
                                  2. if d < -8.59999999999999994e150 or 9.5000000000000004e43 < d

                                    1. Initial program 34.3%

                                      \[\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 rewrites77.0%

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

                                      if -8.59999999999999994e150 < d < -4.79999999999999984e-29

                                      1. Initial program 63.7%

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

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

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

                                        if -4.79999999999999984e-29 < d < 9.5000000000000004e43

                                        1. Initial program 71.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 rewrites68.4%

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

                                        Alternative 6: 61.6% accurate, 1.5× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+131} \lor \neg \left(d \leq 9.5 \cdot 10^{+43}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
                                        (FPCore (a b c d)
                                         :precision binary64
                                         (if (or (<= d -2e+131) (not (<= d 9.5e+43))) (/ (- a) d) (/ b c)))
                                        double code(double a, double b, double c, double d) {
                                        	double tmp;
                                        	if ((d <= -2e+131) || !(d <= 9.5e+43)) {
                                        		tmp = -a / d;
                                        	} 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 ((d <= (-2d+131)) .or. (.not. (d <= 9.5d+43))) then
                                                tmp = -a / d
                                            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 ((d <= -2e+131) || !(d <= 9.5e+43)) {
                                        		tmp = -a / d;
                                        	} else {
                                        		tmp = b / c;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(a, b, c, d):
                                        	tmp = 0
                                        	if (d <= -2e+131) or not (d <= 9.5e+43):
                                        		tmp = -a / d
                                        	else:
                                        		tmp = b / c
                                        	return tmp
                                        
                                        function code(a, b, c, d)
                                        	tmp = 0.0
                                        	if ((d <= -2e+131) || !(d <= 9.5e+43))
                                        		tmp = Float64(Float64(-a) / d);
                                        	else
                                        		tmp = Float64(b / c);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(a, b, c, d)
                                        	tmp = 0.0;
                                        	if ((d <= -2e+131) || ~((d <= 9.5e+43)))
                                        		tmp = -a / d;
                                        	else
                                        		tmp = b / c;
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2e+131], N[Not[LessEqual[d, 9.5e+43]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;d \leq -2 \cdot 10^{+131} \lor \neg \left(d \leq 9.5 \cdot 10^{+43}\right):\\
                                        \;\;\;\;\frac{-a}{d}\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\frac{b}{c}\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if d < -1.9999999999999998e131 or 9.5000000000000004e43 < d

                                          1. Initial program 36.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 rewrites75.6%

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

                                            if -1.9999999999999998e131 < d < 9.5000000000000004e43

                                            1. Initial program 69.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}{c}} \]
                                            4. Step-by-step derivation
                                              1. Applied rewrites63.8%

                                                \[\leadsto \color{blue}{\frac{b}{c}} \]
                                            5. Recombined 2 regimes into one program.
                                            6. Final simplification67.9%

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

                                            Alternative 7: 43.3% 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 58.2%

                                              \[\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 rewrites46.7%

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

                                              Developer Target 1: 99.4% 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 2025019 
                                              (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))))