Complex division, real part

Percentage Accurate: 61.5% → 77.2%
Time: 3.8s
Alternatives: 7
Speedup: 1.6×

Specification

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

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

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

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

Alternative 1: 77.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3.7 \cdot 10^{+40} \lor \neg \left(c \leq 3 \cdot 10^{+22}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -3.7e+40) (not (<= c 3e+22)))
   (/ (fma d (/ b c) a) c)
   (/ (fma c (/ a d) b) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -3.7e+40) || !(c <= 3e+22)) {
		tmp = fma(d, (b / c), a) / c;
	} else {
		tmp = fma(c, (a / d), b) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -3.7e+40) || !(c <= 3e+22))
		tmp = Float64(fma(d, Float64(b / c), a) / c);
	else
		tmp = Float64(fma(c, Float64(a / d), b) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.7e+40], N[Not[LessEqual[c, 3e+22]], $MachinePrecision]], N[(N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.7 \cdot 10^{+40} \lor \neg \left(c \leq 3 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.7e40 or 3e22 < c

    1. Initial program 48.0%

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

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

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

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

        if -3.7e40 < c < 3e22

        1. Initial program 71.4%

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

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

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

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

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

          Alternative 2: 61.2% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.22 \cdot 10^{+194}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{+65}:\\ \;\;\;\;\frac{\frac{b}{c} \cdot d}{c}\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+125}:\\ \;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
          (FPCore (a b c d)
           :precision binary64
           (if (<= c -1.22e+194)
             (/ a c)
             (if (<= c -2.7e+65)
               (/ (* (/ b c) d) c)
               (if (<= c 1.75e-23)
                 (/ b d)
                 (if (<= c 4e+125) (* (/ c (fma d d (* c c))) a) (/ a c))))))
          double code(double a, double b, double c, double d) {
          	double tmp;
          	if (c <= -1.22e+194) {
          		tmp = a / c;
          	} else if (c <= -2.7e+65) {
          		tmp = ((b / c) * d) / c;
          	} else if (c <= 1.75e-23) {
          		tmp = b / d;
          	} else if (c <= 4e+125) {
          		tmp = (c / fma(d, d, (c * c))) * a;
          	} else {
          		tmp = a / c;
          	}
          	return tmp;
          }
          
          function code(a, b, c, d)
          	tmp = 0.0
          	if (c <= -1.22e+194)
          		tmp = Float64(a / c);
          	elseif (c <= -2.7e+65)
          		tmp = Float64(Float64(Float64(b / c) * d) / c);
          	elseif (c <= 1.75e-23)
          		tmp = Float64(b / d);
          	elseif (c <= 4e+125)
          		tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * a);
          	else
          		tmp = Float64(a / c);
          	end
          	return tmp
          end
          
          code[a_, b_, c_, d_] := If[LessEqual[c, -1.22e+194], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.7e+65], N[(N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.75e-23], N[(b / d), $MachinePrecision], If[LessEqual[c, 4e+125], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;c \leq -1.22 \cdot 10^{+194}:\\
          \;\;\;\;\frac{a}{c}\\
          
          \mathbf{elif}\;c \leq -2.7 \cdot 10^{+65}:\\
          \;\;\;\;\frac{\frac{b}{c} \cdot d}{c}\\
          
          \mathbf{elif}\;c \leq 1.75 \cdot 10^{-23}:\\
          \;\;\;\;\frac{b}{d}\\
          
          \mathbf{elif}\;c \leq 4 \cdot 10^{+125}:\\
          \;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{a}{c}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 4 regimes
          2. if c < -1.2200000000000001e194 or 3.9999999999999997e125 < c

            1. Initial program 33.3%

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

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

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

              if -1.2200000000000001e194 < c < -2.70000000000000019e65

              1. Initial program 49.5%

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

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

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

                    \[\leadsto \frac{\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{c} \]
                  2. Taylor expanded in a around 0

                    \[\leadsto \frac{\frac{b \cdot d}{c}}{c} \]
                  3. Step-by-step derivation
                    1. Applied rewrites51.0%

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

                    if -2.70000000000000019e65 < c < 1.74999999999999997e-23

                    1. Initial program 70.8%

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

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

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

                      if 1.74999999999999997e-23 < c < 3.9999999999999997e125

                      1. Initial program 84.2%

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

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

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

                      Alternative 3: 61.3% accurate, 0.7× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.2 \cdot 10^{+194}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{+65}:\\ \;\;\;\;\frac{\frac{b}{c}}{c} \cdot d\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+125}:\\ \;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
                      (FPCore (a b c d)
                       :precision binary64
                       (if (<= c -1.2e+194)
                         (/ a c)
                         (if (<= c -2.7e+65)
                           (* (/ (/ b c) c) d)
                           (if (<= c 1.75e-23)
                             (/ b d)
                             (if (<= c 4e+125) (* (/ c (fma d d (* c c))) a) (/ a c))))))
                      double code(double a, double b, double c, double d) {
                      	double tmp;
                      	if (c <= -1.2e+194) {
                      		tmp = a / c;
                      	} else if (c <= -2.7e+65) {
                      		tmp = ((b / c) / c) * d;
                      	} else if (c <= 1.75e-23) {
                      		tmp = b / d;
                      	} else if (c <= 4e+125) {
                      		tmp = (c / fma(d, d, (c * c))) * a;
                      	} else {
                      		tmp = a / c;
                      	}
                      	return tmp;
                      }
                      
                      function code(a, b, c, d)
                      	tmp = 0.0
                      	if (c <= -1.2e+194)
                      		tmp = Float64(a / c);
                      	elseif (c <= -2.7e+65)
                      		tmp = Float64(Float64(Float64(b / c) / c) * d);
                      	elseif (c <= 1.75e-23)
                      		tmp = Float64(b / d);
                      	elseif (c <= 4e+125)
                      		tmp = Float64(Float64(c / fma(d, d, Float64(c * c))) * a);
                      	else
                      		tmp = Float64(a / c);
                      	end
                      	return tmp
                      end
                      
                      code[a_, b_, c_, d_] := If[LessEqual[c, -1.2e+194], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.7e+65], N[(N[(N[(b / c), $MachinePrecision] / c), $MachinePrecision] * d), $MachinePrecision], If[LessEqual[c, 1.75e-23], N[(b / d), $MachinePrecision], If[LessEqual[c, 4e+125], N[(N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(a / c), $MachinePrecision]]]]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;c \leq -1.2 \cdot 10^{+194}:\\
                      \;\;\;\;\frac{a}{c}\\
                      
                      \mathbf{elif}\;c \leq -2.7 \cdot 10^{+65}:\\
                      \;\;\;\;\frac{\frac{b}{c}}{c} \cdot d\\
                      
                      \mathbf{elif}\;c \leq 1.75 \cdot 10^{-23}:\\
                      \;\;\;\;\frac{b}{d}\\
                      
                      \mathbf{elif}\;c \leq 4 \cdot 10^{+125}:\\
                      \;\;\;\;\frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\frac{a}{c}\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 4 regimes
                      2. if c < -1.2e194 or 3.9999999999999997e125 < c

                        1. Initial program 33.3%

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

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

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

                          if -1.2e194 < c < -2.70000000000000019e65

                          1. Initial program 49.5%

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

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

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

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

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

                              if -2.70000000000000019e65 < c < 1.74999999999999997e-23

                              1. Initial program 70.8%

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

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

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

                                if 1.74999999999999997e-23 < c < 3.9999999999999997e125

                                1. Initial program 84.2%

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

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

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

                                Alternative 4: 71.9% accurate, 0.8× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.2 \cdot 10^{+154}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -5.2 \cdot 10^{+42}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{c \cdot c}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+25}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
                                (FPCore (a b c d)
                                 :precision binary64
                                 (if (<= c -1.2e+154)
                                   (/ a c)
                                   (if (<= c -5.2e+42)
                                     (/ (fma d b (* c a)) (* c c))
                                     (if (<= c 1.5e+25) (/ (fma c (/ a d) b) d) (/ a c)))))
                                double code(double a, double b, double c, double d) {
                                	double tmp;
                                	if (c <= -1.2e+154) {
                                		tmp = a / c;
                                	} else if (c <= -5.2e+42) {
                                		tmp = fma(d, b, (c * a)) / (c * c);
                                	} else if (c <= 1.5e+25) {
                                		tmp = fma(c, (a / d), b) / d;
                                	} else {
                                		tmp = a / c;
                                	}
                                	return tmp;
                                }
                                
                                function code(a, b, c, d)
                                	tmp = 0.0
                                	if (c <= -1.2e+154)
                                		tmp = Float64(a / c);
                                	elseif (c <= -5.2e+42)
                                		tmp = Float64(fma(d, b, Float64(c * a)) / Float64(c * c));
                                	elseif (c <= 1.5e+25)
                                		tmp = Float64(fma(c, Float64(a / d), b) / d);
                                	else
                                		tmp = Float64(a / c);
                                	end
                                	return tmp
                                end
                                
                                code[a_, b_, c_, d_] := If[LessEqual[c, -1.2e+154], N[(a / c), $MachinePrecision], If[LessEqual[c, -5.2e+42], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.5e+25], N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                \mathbf{if}\;c \leq -1.2 \cdot 10^{+154}:\\
                                \;\;\;\;\frac{a}{c}\\
                                
                                \mathbf{elif}\;c \leq -5.2 \cdot 10^{+42}:\\
                                \;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{c \cdot c}\\
                                
                                \mathbf{elif}\;c \leq 1.5 \cdot 10^{+25}:\\
                                \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\frac{a}{c}\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 3 regimes
                                2. if c < -1.20000000000000007e154 or 1.50000000000000003e25 < c

                                  1. Initial program 41.8%

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

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

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

                                    if -1.20000000000000007e154 < c < -5.1999999999999998e42

                                    1. Initial program 72.6%

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

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

                                        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c}} \]
                                      2. Step-by-step derivation
                                        1. lift-+.f64N/A

                                          \[\leadsto \frac{\color{blue}{a \cdot c + b \cdot d}}{c \cdot c} \]
                                        2. +-commutativeN/A

                                          \[\leadsto \frac{\color{blue}{b \cdot d + a \cdot c}}{c \cdot c} \]
                                        3. lift-*.f64N/A

                                          \[\leadsto \frac{\color{blue}{b \cdot d} + a \cdot c}{c \cdot c} \]
                                        4. *-commutativeN/A

                                          \[\leadsto \frac{\color{blue}{d \cdot b} + a \cdot c}{c \cdot c} \]
                                        5. lower-fma.f6458.2

                                          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(d, b, a \cdot c\right)}}{c \cdot c} \]
                                        6. lift-*.f64N/A

                                          \[\leadsto \frac{\mathsf{fma}\left(d, b, \color{blue}{a \cdot c}\right)}{c \cdot c} \]
                                        7. *-commutativeN/A

                                          \[\leadsto \frac{\mathsf{fma}\left(d, b, \color{blue}{c \cdot a}\right)}{c \cdot c} \]
                                        8. lift-*.f6458.2

                                          \[\leadsto \frac{\mathsf{fma}\left(d, b, \color{blue}{c \cdot a}\right)}{c \cdot c} \]
                                      3. Applied rewrites58.2%

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

                                      if -5.1999999999999998e42 < c < 1.50000000000000003e25

                                      1. Initial program 71.4%

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

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

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

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

                                        Alternative 5: 59.8% accurate, 0.9× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.2 \cdot 10^{+194}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{+65}:\\ \;\;\;\;\frac{\frac{b}{c}}{c} \cdot d\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
                                        (FPCore (a b c d)
                                         :precision binary64
                                         (if (<= c -1.2e+194)
                                           (/ a c)
                                           (if (<= c -2.7e+65)
                                             (* (/ (/ b c) c) d)
                                             (if (<= c 2.15e-23) (/ b d) (/ a c)))))
                                        double code(double a, double b, double c, double d) {
                                        	double tmp;
                                        	if (c <= -1.2e+194) {
                                        		tmp = a / c;
                                        	} else if (c <= -2.7e+65) {
                                        		tmp = ((b / c) / c) * d;
                                        	} else if (c <= 2.15e-23) {
                                        		tmp = b / d;
                                        	} else {
                                        		tmp = 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 (c <= (-1.2d+194)) then
                                                tmp = a / c
                                            else if (c <= (-2.7d+65)) then
                                                tmp = ((b / c) / c) * d
                                            else if (c <= 2.15d-23) then
                                                tmp = b / d
                                            else
                                                tmp = a / c
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double a, double b, double c, double d) {
                                        	double tmp;
                                        	if (c <= -1.2e+194) {
                                        		tmp = a / c;
                                        	} else if (c <= -2.7e+65) {
                                        		tmp = ((b / c) / c) * d;
                                        	} else if (c <= 2.15e-23) {
                                        		tmp = b / d;
                                        	} else {
                                        		tmp = a / c;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(a, b, c, d):
                                        	tmp = 0
                                        	if c <= -1.2e+194:
                                        		tmp = a / c
                                        	elif c <= -2.7e+65:
                                        		tmp = ((b / c) / c) * d
                                        	elif c <= 2.15e-23:
                                        		tmp = b / d
                                        	else:
                                        		tmp = a / c
                                        	return tmp
                                        
                                        function code(a, b, c, d)
                                        	tmp = 0.0
                                        	if (c <= -1.2e+194)
                                        		tmp = Float64(a / c);
                                        	elseif (c <= -2.7e+65)
                                        		tmp = Float64(Float64(Float64(b / c) / c) * d);
                                        	elseif (c <= 2.15e-23)
                                        		tmp = Float64(b / d);
                                        	else
                                        		tmp = Float64(a / c);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(a, b, c, d)
                                        	tmp = 0.0;
                                        	if (c <= -1.2e+194)
                                        		tmp = a / c;
                                        	elseif (c <= -2.7e+65)
                                        		tmp = ((b / c) / c) * d;
                                        	elseif (c <= 2.15e-23)
                                        		tmp = b / d;
                                        	else
                                        		tmp = a / c;
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[a_, b_, c_, d_] := If[LessEqual[c, -1.2e+194], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.7e+65], N[(N[(N[(b / c), $MachinePrecision] / c), $MachinePrecision] * d), $MachinePrecision], If[LessEqual[c, 2.15e-23], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;c \leq -1.2 \cdot 10^{+194}:\\
                                        \;\;\;\;\frac{a}{c}\\
                                        
                                        \mathbf{elif}\;c \leq -2.7 \cdot 10^{+65}:\\
                                        \;\;\;\;\frac{\frac{b}{c}}{c} \cdot d\\
                                        
                                        \mathbf{elif}\;c \leq 2.15 \cdot 10^{-23}:\\
                                        \;\;\;\;\frac{b}{d}\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\frac{a}{c}\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 3 regimes
                                        2. if c < -1.2e194 or 2.15000000000000001e-23 < c

                                          1. Initial program 49.1%

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

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

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

                                            if -1.2e194 < c < -2.70000000000000019e65

                                            1. Initial program 49.5%

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

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

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

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

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

                                                if -2.70000000000000019e65 < c < 2.15000000000000001e-23

                                                1. Initial program 70.8%

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

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

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

                                                Alternative 6: 63.1% accurate, 1.6× speedup?

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

                                                  1. Initial program 50.4%

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

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

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

                                                    if -3.2999999999999998e40 < c < 2.15000000000000001e-23

                                                    1. Initial program 70.7%

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

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

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

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

                                                    Alternative 7: 41.2% accurate, 3.2× speedup?

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

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

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

                                                        \[\leadsto \color{blue}{\frac{a}{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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \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))
                                                         (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
                                                         (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
                                                      double code(double a, double b, double c, double d) {
                                                      	double tmp;
                                                      	if (fabs(d) < fabs(c)) {
                                                      		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
                                                      	} else {
                                                      		tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
                                                          else
                                                              tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
                                                      	} else {
                                                      		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
                                                      	}
                                                      	return tmp;
                                                      }
                                                      
                                                      def code(a, b, c, d):
                                                      	tmp = 0
                                                      	if math.fabs(d) < math.fabs(c):
                                                      		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
                                                      	else:
                                                      		tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
                                                      	else
                                                      		tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c)));
                                                      	else
                                                      		tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
                                                      
                                                      \mathbf{else}:\\
                                                      \;\;\;\;\frac{b + a \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, real part"
                                                        :precision binary64
                                                      
                                                        :alt
                                                        (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
                                                      
                                                        (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))