FastMath dist4

Percentage Accurate: 87.9% → 97.6%
Time: 7.1s
Alternatives: 15
Speedup: 1.7×

Specification

?
\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4):
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
end
function tmp = code(d1, d2, d3, d4)
	tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\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 15 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: 87.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4):
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
end
function tmp = code(d1, d2, d3, d4)
	tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}

Alternative 1: 97.6% accurate, 1.7× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right) \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4) :precision binary64 (fma (- d2 d3) d1 (* d1 (- d4 d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	return fma((d2 - d3), d1, (d1 * (d4 - d1)));
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	return fma(Float64(d2 - d3), d1, Float64(d1 * Float64(d4 - d1)))
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)
\end{array}
Derivation
  1. Initial program 88.3%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
    2. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
    3. associate--l+N/A

      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
    4. lift--.f64N/A

      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
    5. lift-*.f64N/A

      \[\leadsto \left(\color{blue}{d1 \cdot d2} - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
    6. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
    7. distribute-lft-out--N/A

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
    8. *-commutativeN/A

      \[\leadsto \color{blue}{\left(d2 - d3\right) \cdot d1} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
    9. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - d1 \cdot d1\right)} \]
    10. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{d2 - d3}, d1, d4 \cdot d1 - d1 \cdot d1\right) \]
    11. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right) \]
    12. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right) \]
    13. distribute-rgt-out--N/A

      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
    14. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
    15. lower--.f6496.9

      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right) \]
  4. Applied rewrites96.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)} \]
  5. Add Preprocessing

Alternative 2: 74.1% accurate, 1.1× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -7.4 \cdot 10^{+43}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -6 \cdot 10^{-135} \lor \neg \left(d2 \leq 4.3 \cdot 10^{-300}\right):\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -7.4e+43)
   (* (- d2 d3) d1)
   (if (or (<= d2 -6e-135) (not (<= d2 4.3e-300)))
     (* (- d4 d3) d1)
     (* (- d4 d1) d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -7.4e+43) {
		tmp = (d2 - d3) * d1;
	} else if ((d2 <= -6e-135) || !(d2 <= 4.3e-300)) {
		tmp = (d4 - d3) * d1;
	} else {
		tmp = (d4 - d1) * d1;
	}
	return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-7.4d+43)) then
        tmp = (d2 - d3) * d1
    else if ((d2 <= (-6d-135)) .or. (.not. (d2 <= 4.3d-300))) then
        tmp = (d4 - d3) * d1
    else
        tmp = (d4 - d1) * d1
    end if
    code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -7.4e+43) {
		tmp = (d2 - d3) * d1;
	} else if ((d2 <= -6e-135) || !(d2 <= 4.3e-300)) {
		tmp = (d4 - d3) * d1;
	} else {
		tmp = (d4 - d1) * d1;
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -7.4e+43:
		tmp = (d2 - d3) * d1
	elif (d2 <= -6e-135) or not (d2 <= 4.3e-300):
		tmp = (d4 - d3) * d1
	else:
		tmp = (d4 - d1) * d1
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -7.4e+43)
		tmp = Float64(Float64(d2 - d3) * d1);
	elseif ((d2 <= -6e-135) || !(d2 <= 4.3e-300))
		tmp = Float64(Float64(d4 - d3) * d1);
	else
		tmp = Float64(Float64(d4 - d1) * d1);
	end
	return tmp
end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -7.4e+43)
		tmp = (d2 - d3) * d1;
	elseif ((d2 <= -6e-135) || ~((d2 <= 4.3e-300)))
		tmp = (d4 - d3) * d1;
	else
		tmp = (d4 - d1) * d1;
	end
	tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -7.4e+43], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[Or[LessEqual[d2, -6e-135], N[Not[LessEqual[d2, 4.3e-300]], $MachinePrecision]], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -7.4 \cdot 10^{+43}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\

\mathbf{elif}\;d2 \leq -6 \cdot 10^{-135} \lor \neg \left(d2 \leq 4.3 \cdot 10^{-300}\right):\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;\left(d4 - d1\right) \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -7.4000000000000002e43

    1. Initial program 85.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Add Preprocessing
    3. Taylor expanded in d4 around 0

      \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
      2. distribute-lft-out--N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
      3. unpow2N/A

        \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
      4. distribute-lft-out--N/A

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
      5. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
      7. lower--.f64N/A

        \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
      8. lower--.f6487.5

        \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
    5. Applied rewrites87.5%

      \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
    6. Taylor expanded in d1 around 0

      \[\leadsto \left(d2 - d3\right) \cdot d1 \]
    7. Step-by-step derivation
      1. Applied rewrites75.9%

        \[\leadsto \left(d2 - d3\right) \cdot d1 \]

      if -7.4000000000000002e43 < d2 < -6.00000000000000024e-135 or 4.3000000000000001e-300 < d2

      1. Initial program 88.5%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Add Preprocessing
      3. Taylor expanded in d4 around inf

        \[\leadsto \color{blue}{d1 \cdot d4} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{d4 \cdot d1} \]
        2. lower-*.f6428.4

          \[\leadsto \color{blue}{d4 \cdot d1} \]
      5. Applied rewrites28.4%

        \[\leadsto \color{blue}{d4 \cdot d1} \]
      6. Taylor expanded in d2 around 0

        \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto d1 \cdot d4 - \color{blue}{\left({d1}^{2} + d1 \cdot d3\right)} \]
        2. unpow2N/A

          \[\leadsto d1 \cdot d4 - \left(\color{blue}{d1 \cdot d1} + d1 \cdot d3\right) \]
        3. distribute-lft-inN/A

          \[\leadsto d1 \cdot d4 - \color{blue}{d1 \cdot \left(d1 + d3\right)} \]
        4. *-commutativeN/A

          \[\leadsto d1 \cdot d4 - \color{blue}{\left(d1 + d3\right) \cdot d1} \]
        5. fp-cancel-sub-sign-invN/A

          \[\leadsto \color{blue}{d1 \cdot d4 + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1} \]
        6. *-commutativeN/A

          \[\leadsto \color{blue}{d4 \cdot d1} + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1 \]
        7. mul-1-negN/A

          \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot \left(d1 + d3\right)\right)} \cdot d1 \]
        8. distribute-lft-inN/A

          \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot d1 + -1 \cdot d3\right)} \cdot d1 \]
        9. distribute-rgt-inN/A

          \[\leadsto \color{blue}{d1 \cdot \left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right)} \]
        10. *-commutativeN/A

          \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
        11. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
        12. associate-+r+N/A

          \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) + -1 \cdot d3\right)} \cdot d1 \]
        13. fp-cancel-sign-sub-invN/A

          \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right)} \cdot d1 \]
        14. fp-cancel-sign-sub-invN/A

          \[\leadsto \left(\color{blue}{\left(d4 - \left(\mathsf{neg}\left(-1\right)\right) \cdot d1\right)} - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
        15. metadata-evalN/A

          \[\leadsto \left(\left(d4 - \color{blue}{1} \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
        16. *-lft-identityN/A

          \[\leadsto \left(\left(d4 - \color{blue}{d1}\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
        17. metadata-evalN/A

          \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{1} \cdot d3\right) \cdot d1 \]
        18. *-lft-identityN/A

          \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{d3}\right) \cdot d1 \]
        19. lower--.f64N/A

          \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
        20. lower--.f6480.3

          \[\leadsto \left(\color{blue}{\left(d4 - d1\right)} - d3\right) \cdot d1 \]
      8. Applied rewrites80.3%

        \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right) \cdot d1} \]
      9. Taylor expanded in d1 around 0

        \[\leadsto \left(d4 - d3\right) \cdot d1 \]
      10. Step-by-step derivation
        1. Applied rewrites59.2%

          \[\leadsto \left(d4 - d3\right) \cdot d1 \]

        if -6.00000000000000024e-135 < d2 < 4.3000000000000001e-300

        1. Initial program 90.9%

          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
        2. Add Preprocessing
        3. Taylor expanded in d3 around 0

          \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
        4. Step-by-step derivation
          1. distribute-lft-outN/A

            \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
          2. unpow2N/A

            \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
          3. distribute-lft-out--N/A

            \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
          4. *-commutativeN/A

            \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
          5. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
          6. lower--.f64N/A

            \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
          7. +-commutativeN/A

            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
          8. lower-+.f6482.4

            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
        5. Applied rewrites82.4%

          \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
        6. Taylor expanded in d2 around 0

          \[\leadsto \left(d4 - d1\right) \cdot d1 \]
        7. Step-by-step derivation
          1. Applied rewrites82.4%

            \[\leadsto \left(d4 - d1\right) \cdot d1 \]
        8. Recombined 3 regimes into one program.
        9. Final simplification65.9%

          \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -7.4 \cdot 10^{+43}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -6 \cdot 10^{-135} \lor \neg \left(d2 \leq 4.3 \cdot 10^{-300}\right):\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \]
        10. Add Preprocessing

        Alternative 3: 76.1% accurate, 1.1× speedup?

        \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -8.5 \cdot 10^{+45}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -5.5 \cdot 10^{-130}:\\ \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 4.3 \cdot 10^{-300}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        (FPCore (d1 d2 d3 d4)
         :precision binary64
         (if (<= d2 -8.5e+45)
           (* (- d2 d3) d1)
           (if (<= d2 -5.5e-130)
             (* (- (- d3) d1) d1)
             (if (<= d2 4.3e-300) (* (- d4 d1) d1) (* (- d4 d3) d1)))))
        assert(d1 < d2 && d2 < d3 && d3 < d4);
        double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if (d2 <= -8.5e+45) {
        		tmp = (d2 - d3) * d1;
        	} else if (d2 <= -5.5e-130) {
        		tmp = (-d3 - d1) * d1;
        	} else if (d2 <= 4.3e-300) {
        		tmp = (d4 - d1) * d1;
        	} else {
        		tmp = (d4 - d3) * d1;
        	}
        	return tmp;
        }
        
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        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(d1, d2, d3, d4)
        use fmin_fmax_functions
            real(8), intent (in) :: d1
            real(8), intent (in) :: d2
            real(8), intent (in) :: d3
            real(8), intent (in) :: d4
            real(8) :: tmp
            if (d2 <= (-8.5d+45)) then
                tmp = (d2 - d3) * d1
            else if (d2 <= (-5.5d-130)) then
                tmp = (-d3 - d1) * d1
            else if (d2 <= 4.3d-300) then
                tmp = (d4 - d1) * d1
            else
                tmp = (d4 - d3) * d1
            end if
            code = tmp
        end function
        
        assert d1 < d2 && d2 < d3 && d3 < d4;
        public static double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if (d2 <= -8.5e+45) {
        		tmp = (d2 - d3) * d1;
        	} else if (d2 <= -5.5e-130) {
        		tmp = (-d3 - d1) * d1;
        	} else if (d2 <= 4.3e-300) {
        		tmp = (d4 - d1) * d1;
        	} else {
        		tmp = (d4 - d3) * d1;
        	}
        	return tmp;
        }
        
        [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
        def code(d1, d2, d3, d4):
        	tmp = 0
        	if d2 <= -8.5e+45:
        		tmp = (d2 - d3) * d1
        	elif d2 <= -5.5e-130:
        		tmp = (-d3 - d1) * d1
        	elif d2 <= 4.3e-300:
        		tmp = (d4 - d1) * d1
        	else:
        		tmp = (d4 - d3) * d1
        	return tmp
        
        d1, d2, d3, d4 = sort([d1, d2, d3, d4])
        function code(d1, d2, d3, d4)
        	tmp = 0.0
        	if (d2 <= -8.5e+45)
        		tmp = Float64(Float64(d2 - d3) * d1);
        	elseif (d2 <= -5.5e-130)
        		tmp = Float64(Float64(Float64(-d3) - d1) * d1);
        	elseif (d2 <= 4.3e-300)
        		tmp = Float64(Float64(d4 - d1) * d1);
        	else
        		tmp = Float64(Float64(d4 - d3) * d1);
        	end
        	return tmp
        end
        
        d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
        function tmp_2 = code(d1, d2, d3, d4)
        	tmp = 0.0;
        	if (d2 <= -8.5e+45)
        		tmp = (d2 - d3) * d1;
        	elseif (d2 <= -5.5e-130)
        		tmp = (-d3 - d1) * d1;
        	elseif (d2 <= 4.3e-300)
        		tmp = (d4 - d1) * d1;
        	else
        		tmp = (d4 - d3) * d1;
        	end
        	tmp_2 = tmp;
        end
        
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -8.5e+45], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -5.5e-130], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, 4.3e-300], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]]
        
        \begin{array}{l}
        [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;d2 \leq -8.5 \cdot 10^{+45}:\\
        \;\;\;\;\left(d2 - d3\right) \cdot d1\\
        
        \mathbf{elif}\;d2 \leq -5.5 \cdot 10^{-130}:\\
        \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\
        
        \mathbf{elif}\;d2 \leq 4.3 \cdot 10^{-300}:\\
        \;\;\;\;\left(d4 - d1\right) \cdot d1\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(d4 - d3\right) \cdot d1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if d2 < -8.4999999999999996e45

          1. Initial program 85.9%

            \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
          2. Add Preprocessing
          3. Taylor expanded in d4 around 0

            \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
          4. Step-by-step derivation
            1. associate--r+N/A

              \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
            2. distribute-lft-out--N/A

              \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
            3. unpow2N/A

              \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
            4. distribute-lft-out--N/A

              \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
            5. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
            6. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
            7. lower--.f64N/A

              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
            8. lower--.f6487.5

              \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
          5. Applied rewrites87.5%

            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
          6. Taylor expanded in d1 around 0

            \[\leadsto \left(d2 - d3\right) \cdot d1 \]
          7. Step-by-step derivation
            1. Applied rewrites75.9%

              \[\leadsto \left(d2 - d3\right) \cdot d1 \]

            if -8.4999999999999996e45 < d2 < -5.50000000000000007e-130

            1. Initial program 90.6%

              \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
            2. Add Preprocessing
            3. Taylor expanded in d4 around 0

              \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
            4. Step-by-step derivation
              1. associate--r+N/A

                \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
              2. distribute-lft-out--N/A

                \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
              3. unpow2N/A

                \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
              4. distribute-lft-out--N/A

                \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
              5. *-commutativeN/A

                \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
              6. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
              7. lower--.f64N/A

                \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
              8. lower--.f6478.6

                \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
            5. Applied rewrites78.6%

              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
            6. Taylor expanded in d2 around 0

              \[\leadsto \left(-1 \cdot d3 - d1\right) \cdot d1 \]
            7. Step-by-step derivation
              1. Applied rewrites74.2%

                \[\leadsto \left(\left(-d3\right) - d1\right) \cdot d1 \]

              if -5.50000000000000007e-130 < d2 < 4.3000000000000001e-300

              1. Initial program 90.9%

                \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
              2. Add Preprocessing
              3. Taylor expanded in d3 around 0

                \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
              4. Step-by-step derivation
                1. distribute-lft-outN/A

                  \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                2. unpow2N/A

                  \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                3. distribute-lft-out--N/A

                  \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                4. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                5. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                6. lower--.f64N/A

                  \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                7. +-commutativeN/A

                  \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                8. lower-+.f6482.4

                  \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
              5. Applied rewrites82.4%

                \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
              6. Taylor expanded in d2 around 0

                \[\leadsto \left(d4 - d1\right) \cdot d1 \]
              7. Step-by-step derivation
                1. Applied rewrites82.4%

                  \[\leadsto \left(d4 - d1\right) \cdot d1 \]

                if 4.3000000000000001e-300 < d2

                1. Initial program 87.8%

                  \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                2. Add Preprocessing
                3. Taylor expanded in d4 around inf

                  \[\leadsto \color{blue}{d1 \cdot d4} \]
                4. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \color{blue}{d4 \cdot d1} \]
                  2. lower-*.f6430.3

                    \[\leadsto \color{blue}{d4 \cdot d1} \]
                5. Applied rewrites30.3%

                  \[\leadsto \color{blue}{d4 \cdot d1} \]
                6. Taylor expanded in d2 around 0

                  \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                7. Step-by-step derivation
                  1. +-commutativeN/A

                    \[\leadsto d1 \cdot d4 - \color{blue}{\left({d1}^{2} + d1 \cdot d3\right)} \]
                  2. unpow2N/A

                    \[\leadsto d1 \cdot d4 - \left(\color{blue}{d1 \cdot d1} + d1 \cdot d3\right) \]
                  3. distribute-lft-inN/A

                    \[\leadsto d1 \cdot d4 - \color{blue}{d1 \cdot \left(d1 + d3\right)} \]
                  4. *-commutativeN/A

                    \[\leadsto d1 \cdot d4 - \color{blue}{\left(d1 + d3\right) \cdot d1} \]
                  5. fp-cancel-sub-sign-invN/A

                    \[\leadsto \color{blue}{d1 \cdot d4 + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1} \]
                  6. *-commutativeN/A

                    \[\leadsto \color{blue}{d4 \cdot d1} + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1 \]
                  7. mul-1-negN/A

                    \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot \left(d1 + d3\right)\right)} \cdot d1 \]
                  8. distribute-lft-inN/A

                    \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot d1 + -1 \cdot d3\right)} \cdot d1 \]
                  9. distribute-rgt-inN/A

                    \[\leadsto \color{blue}{d1 \cdot \left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right)} \]
                  10. *-commutativeN/A

                    \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
                  11. lower-*.f64N/A

                    \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
                  12. associate-+r+N/A

                    \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) + -1 \cdot d3\right)} \cdot d1 \]
                  13. fp-cancel-sign-sub-invN/A

                    \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right)} \cdot d1 \]
                  14. fp-cancel-sign-sub-invN/A

                    \[\leadsto \left(\color{blue}{\left(d4 - \left(\mathsf{neg}\left(-1\right)\right) \cdot d1\right)} - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                  15. metadata-evalN/A

                    \[\leadsto \left(\left(d4 - \color{blue}{1} \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                  16. *-lft-identityN/A

                    \[\leadsto \left(\left(d4 - \color{blue}{d1}\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                  17. metadata-evalN/A

                    \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{1} \cdot d3\right) \cdot d1 \]
                  18. *-lft-identityN/A

                    \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{d3}\right) \cdot d1 \]
                  19. lower--.f64N/A

                    \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                  20. lower--.f6475.2

                    \[\leadsto \left(\color{blue}{\left(d4 - d1\right)} - d3\right) \cdot d1 \]
                8. Applied rewrites75.2%

                  \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right) \cdot d1} \]
                9. Taylor expanded in d1 around 0

                  \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                10. Step-by-step derivation
                  1. Applied rewrites56.2%

                    \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                11. Recombined 4 regimes into one program.
                12. Final simplification67.0%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -8.5 \cdot 10^{+45}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -5.5 \cdot 10^{-130}:\\ \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 4.3 \cdot 10^{-300}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \]
                13. Add Preprocessing

                Alternative 4: 52.3% accurate, 1.2× speedup?

                \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+121}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -2.02 \cdot 10^{-140}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 2.5 \cdot 10^{-300}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (<= d2 -5.8e+121)
                   (* d2 d1)
                   (if (<= d2 -2.02e-140)
                     (* (- d3) d1)
                     (if (<= d2 2.5e-300) (* (- d1) d1) (* d4 d1)))))
                assert(d1 < d2 && d2 < d3 && d3 < d4);
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -5.8e+121) {
                		tmp = d2 * d1;
                	} else if (d2 <= -2.02e-140) {
                		tmp = -d3 * d1;
                	} else if (d2 <= 2.5e-300) {
                		tmp = -d1 * d1;
                	} else {
                		tmp = d4 * d1;
                	}
                	return tmp;
                }
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                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(d1, d2, d3, d4)
                use fmin_fmax_functions
                    real(8), intent (in) :: d1
                    real(8), intent (in) :: d2
                    real(8), intent (in) :: d3
                    real(8), intent (in) :: d4
                    real(8) :: tmp
                    if (d2 <= (-5.8d+121)) then
                        tmp = d2 * d1
                    else if (d2 <= (-2.02d-140)) then
                        tmp = -d3 * d1
                    else if (d2 <= 2.5d-300) then
                        tmp = -d1 * d1
                    else
                        tmp = d4 * d1
                    end if
                    code = tmp
                end function
                
                assert d1 < d2 && d2 < d3 && d3 < d4;
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -5.8e+121) {
                		tmp = d2 * d1;
                	} else if (d2 <= -2.02e-140) {
                		tmp = -d3 * d1;
                	} else if (d2 <= 2.5e-300) {
                		tmp = -d1 * d1;
                	} else {
                		tmp = d4 * d1;
                	}
                	return tmp;
                }
                
                [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if d2 <= -5.8e+121:
                		tmp = d2 * d1
                	elif d2 <= -2.02e-140:
                		tmp = -d3 * d1
                	elif d2 <= 2.5e-300:
                		tmp = -d1 * d1
                	else:
                		tmp = d4 * d1
                	return tmp
                
                d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if (d2 <= -5.8e+121)
                		tmp = Float64(d2 * d1);
                	elseif (d2 <= -2.02e-140)
                		tmp = Float64(Float64(-d3) * d1);
                	elseif (d2 <= 2.5e-300)
                		tmp = Float64(Float64(-d1) * d1);
                	else
                		tmp = Float64(d4 * d1);
                	end
                	return tmp
                end
                
                d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if (d2 <= -5.8e+121)
                		tmp = d2 * d1;
                	elseif (d2 <= -2.02e-140)
                		tmp = -d3 * d1;
                	elseif (d2 <= 2.5e-300)
                		tmp = -d1 * d1;
                	else
                		tmp = d4 * d1;
                	end
                	tmp_2 = tmp;
                end
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.8e+121], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -2.02e-140], N[((-d3) * d1), $MachinePrecision], If[LessEqual[d2, 2.5e-300], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
                
                \begin{array}{l}
                [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+121}:\\
                \;\;\;\;d2 \cdot d1\\
                
                \mathbf{elif}\;d2 \leq -2.02 \cdot 10^{-140}:\\
                \;\;\;\;\left(-d3\right) \cdot d1\\
                
                \mathbf{elif}\;d2 \leq 2.5 \cdot 10^{-300}:\\
                \;\;\;\;\left(-d1\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;d4 \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 4 regimes
                2. if d2 < -5.7999999999999998e121

                  1. Initial program 82.9%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift--.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                    2. lift-+.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                    3. associate--l+N/A

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                    4. lift--.f64N/A

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    5. lift-*.f64N/A

                      \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    6. fp-cancel-sub-sign-invN/A

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\mathsf{neg}\left(d1\right)\right) \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    7. associate-+l+N/A

                      \[\leadsto \color{blue}{d1 \cdot d2 + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                    8. lift-*.f64N/A

                      \[\leadsto \color{blue}{d1 \cdot d2} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                    9. *-commutativeN/A

                      \[\leadsto \color{blue}{d2 \cdot d1} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                    10. lower-fma.f64N/A

                      \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                    11. lower-fma.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(d1\right), d3, d4 \cdot d1 - d1 \cdot d1\right)}\right) \]
                    12. lower-neg.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(\color{blue}{-d1}, d3, d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                    13. lift-*.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right)\right) \]
                    14. lift-*.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right)\right) \]
                    15. distribute-rgt-out--N/A

                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                    16. lower-*.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                    17. lower--.f6495.1

                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right)\right) \]
                  4. Applied rewrites95.1%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \left(d4 - d1\right)\right)\right)} \]
                  5. Taylor expanded in d2 around inf

                    \[\leadsto \color{blue}{d1 \cdot d2} \]
                  6. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                    2. lower-*.f6473.0

                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                  7. Applied rewrites73.0%

                    \[\leadsto \color{blue}{d2 \cdot d1} \]

                  if -5.7999999999999998e121 < d2 < -2.02000000000000005e-140

                  1. Initial program 91.6%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift--.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                    2. lift-+.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                    3. associate--l+N/A

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                    4. lift--.f64N/A

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    5. lift-*.f64N/A

                      \[\leadsto \left(\color{blue}{d1 \cdot d2} - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    6. lift-*.f64N/A

                      \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    7. distribute-lft-out--N/A

                      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    8. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(d2 - d3\right) \cdot d1} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                    9. lower-fma.f64N/A

                      \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - d1 \cdot d1\right)} \]
                    10. lower--.f64N/A

                      \[\leadsto \mathsf{fma}\left(\color{blue}{d2 - d3}, d1, d4 \cdot d1 - d1 \cdot d1\right) \]
                    11. lift-*.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right) \]
                    12. lift-*.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right) \]
                    13. distribute-rgt-out--N/A

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
                    14. lower-*.f64N/A

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
                    15. lower--.f6496.6

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right) \]
                  4. Applied rewrites96.6%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)} \]
                  5. Taylor expanded in d1 around 0

                    \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot d4}\right) \]
                  6. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                    2. lower-*.f6472.9

                      \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                  7. Applied rewrites72.9%

                    \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                  8. Taylor expanded in d3 around inf

                    \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
                  9. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto -1 \cdot \color{blue}{\left(d3 \cdot d1\right)} \]
                    2. associate-*r*N/A

                      \[\leadsto \color{blue}{\left(-1 \cdot d3\right) \cdot d1} \]
                    3. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(-1 \cdot d3\right) \cdot d1} \]
                    4. mul-1-negN/A

                      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \cdot d1 \]
                    5. lower-neg.f6443.1

                      \[\leadsto \color{blue}{\left(-d3\right)} \cdot d1 \]
                  10. Applied rewrites43.1%

                    \[\leadsto \color{blue}{\left(-d3\right) \cdot d1} \]

                  if -2.02000000000000005e-140 < d2 < 2.49999999999999998e-300

                  1. Initial program 90.6%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Taylor expanded in d1 around inf

                    \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
                  4. Step-by-step derivation
                    1. unpow2N/A

                      \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
                    2. associate-*r*N/A

                      \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d1} \]
                    3. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d1} \]
                    4. mul-1-negN/A

                      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)} \cdot d1 \]
                    5. lower-neg.f6443.4

                      \[\leadsto \color{blue}{\left(-d1\right)} \cdot d1 \]
                  5. Applied rewrites43.4%

                    \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]

                  if 2.49999999999999998e-300 < d2

                  1. Initial program 87.8%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Taylor expanded in d4 around inf

                    \[\leadsto \color{blue}{d1 \cdot d4} \]
                  4. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                    2. lower-*.f6430.3

                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                  5. Applied rewrites30.3%

                    \[\leadsto \color{blue}{d4 \cdot d1} \]
                3. Recombined 4 regimes into one program.
                4. Final simplification41.8%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+121}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -2.02 \cdot 10^{-140}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 2.5 \cdot 10^{-300}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                5. Add Preprocessing

                Alternative 5: 92.0% accurate, 1.2× speedup?

                \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -4.4 \cdot 10^{+64} \lor \neg \left(d3 \leq 7.3 \cdot 10^{-62}\right):\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (or (<= d3 -4.4e+64) (not (<= d3 7.3e-62)))
                   (* (- (+ d4 d2) d3) d1)
                   (* (- (+ d4 d2) d1) d1)))
                assert(d1 < d2 && d2 < d3 && d3 < d4);
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if ((d3 <= -4.4e+64) || !(d3 <= 7.3e-62)) {
                		tmp = ((d4 + d2) - d3) * d1;
                	} else {
                		tmp = ((d4 + d2) - d1) * d1;
                	}
                	return tmp;
                }
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                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(d1, d2, d3, d4)
                use fmin_fmax_functions
                    real(8), intent (in) :: d1
                    real(8), intent (in) :: d2
                    real(8), intent (in) :: d3
                    real(8), intent (in) :: d4
                    real(8) :: tmp
                    if ((d3 <= (-4.4d+64)) .or. (.not. (d3 <= 7.3d-62))) then
                        tmp = ((d4 + d2) - d3) * d1
                    else
                        tmp = ((d4 + d2) - d1) * d1
                    end if
                    code = tmp
                end function
                
                assert d1 < d2 && d2 < d3 && d3 < d4;
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if ((d3 <= -4.4e+64) || !(d3 <= 7.3e-62)) {
                		tmp = ((d4 + d2) - d3) * d1;
                	} else {
                		tmp = ((d4 + d2) - d1) * d1;
                	}
                	return tmp;
                }
                
                [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if (d3 <= -4.4e+64) or not (d3 <= 7.3e-62):
                		tmp = ((d4 + d2) - d3) * d1
                	else:
                		tmp = ((d4 + d2) - d1) * d1
                	return tmp
                
                d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if ((d3 <= -4.4e+64) || !(d3 <= 7.3e-62))
                		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                	else
                		tmp = Float64(Float64(Float64(d4 + d2) - d1) * d1);
                	end
                	return tmp
                end
                
                d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if ((d3 <= -4.4e+64) || ~((d3 <= 7.3e-62)))
                		tmp = ((d4 + d2) - d3) * d1;
                	else
                		tmp = ((d4 + d2) - d1) * d1;
                	end
                	tmp_2 = tmp;
                end
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -4.4e+64], N[Not[LessEqual[d3, 7.3e-62]], $MachinePrecision]], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
                
                \begin{array}{l}
                [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;d3 \leq -4.4 \cdot 10^{+64} \lor \neg \left(d3 \leq 7.3 \cdot 10^{-62}\right):\\
                \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if d3 < -4.40000000000000004e64 or 7.2999999999999998e-62 < d3

                  1. Initial program 84.4%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Taylor expanded in d1 around 0

                    \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
                  4. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d3\right) \cdot d1} \]
                    2. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d3\right) \cdot d1} \]
                    3. lower--.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d3\right)} \cdot d1 \]
                    4. +-commutativeN/A

                      \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                    5. lower-+.f6492.1

                      \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                  5. Applied rewrites92.1%

                    \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]

                  if -4.40000000000000004e64 < d3 < 7.2999999999999998e-62

                  1. Initial program 92.2%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Taylor expanded in d3 around 0

                    \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                  4. Step-by-step derivation
                    1. distribute-lft-outN/A

                      \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                    2. unpow2N/A

                      \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                    3. distribute-lft-out--N/A

                      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                    4. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                    5. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                    6. lower--.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                    7. +-commutativeN/A

                      \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                    8. lower-+.f6497.9

                      \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                  5. Applied rewrites97.9%

                    \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
                3. Recombined 2 regimes into one program.
                4. Final simplification95.0%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4.4 \cdot 10^{+64} \lor \neg \left(d3 \leq 7.3 \cdot 10^{-62}\right):\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \end{array} \]
                5. Add Preprocessing

                Alternative 6: 88.4% accurate, 1.2× speedup?

                \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.6 \cdot 10^{+65}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 2.3 \cdot 10^{+93}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (<= d3 -2.6e+65)
                   (* (- d2 d3) d1)
                   (if (<= d3 2.3e+93) (* (- (+ d4 d2) d1) d1) (* (- d4 d3) d1))))
                assert(d1 < d2 && d2 < d3 && d3 < d4);
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d3 <= -2.6e+65) {
                		tmp = (d2 - d3) * d1;
                	} else if (d3 <= 2.3e+93) {
                		tmp = ((d4 + d2) - d1) * d1;
                	} else {
                		tmp = (d4 - d3) * d1;
                	}
                	return tmp;
                }
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                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(d1, d2, d3, d4)
                use fmin_fmax_functions
                    real(8), intent (in) :: d1
                    real(8), intent (in) :: d2
                    real(8), intent (in) :: d3
                    real(8), intent (in) :: d4
                    real(8) :: tmp
                    if (d3 <= (-2.6d+65)) then
                        tmp = (d2 - d3) * d1
                    else if (d3 <= 2.3d+93) then
                        tmp = ((d4 + d2) - d1) * d1
                    else
                        tmp = (d4 - d3) * d1
                    end if
                    code = tmp
                end function
                
                assert d1 < d2 && d2 < d3 && d3 < d4;
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d3 <= -2.6e+65) {
                		tmp = (d2 - d3) * d1;
                	} else if (d3 <= 2.3e+93) {
                		tmp = ((d4 + d2) - d1) * d1;
                	} else {
                		tmp = (d4 - d3) * d1;
                	}
                	return tmp;
                }
                
                [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if d3 <= -2.6e+65:
                		tmp = (d2 - d3) * d1
                	elif d3 <= 2.3e+93:
                		tmp = ((d4 + d2) - d1) * d1
                	else:
                		tmp = (d4 - d3) * d1
                	return tmp
                
                d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if (d3 <= -2.6e+65)
                		tmp = Float64(Float64(d2 - d3) * d1);
                	elseif (d3 <= 2.3e+93)
                		tmp = Float64(Float64(Float64(d4 + d2) - d1) * d1);
                	else
                		tmp = Float64(Float64(d4 - d3) * d1);
                	end
                	return tmp
                end
                
                d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if (d3 <= -2.6e+65)
                		tmp = (d2 - d3) * d1;
                	elseif (d3 <= 2.3e+93)
                		tmp = ((d4 + d2) - d1) * d1;
                	else
                		tmp = (d4 - d3) * d1;
                	end
                	tmp_2 = tmp;
                end
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -2.6e+65], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 2.3e+93], N[(N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
                
                \begin{array}{l}
                [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;d3 \leq -2.6 \cdot 10^{+65}:\\
                \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                
                \mathbf{elif}\;d3 \leq 2.3 \cdot 10^{+93}:\\
                \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if d3 < -2.60000000000000003e65

                  1. Initial program 86.9%

                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                  2. Add Preprocessing
                  3. Taylor expanded in d4 around 0

                    \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                  4. Step-by-step derivation
                    1. associate--r+N/A

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
                    2. distribute-lft-out--N/A

                      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                    3. unpow2N/A

                      \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
                    4. distribute-lft-out--N/A

                      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
                    5. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                    6. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                    7. lower--.f64N/A

                      \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                    8. lower--.f6487.0

                      \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                  5. Applied rewrites87.0%

                    \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                  6. Taylor expanded in d1 around 0

                    \[\leadsto \left(d2 - d3\right) \cdot d1 \]
                  7. Step-by-step derivation
                    1. Applied rewrites87.0%

                      \[\leadsto \left(d2 - d3\right) \cdot d1 \]

                    if -2.60000000000000003e65 < d3 < 2.3000000000000002e93

                    1. Initial program 91.0%

                      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                    2. Add Preprocessing
                    3. Taylor expanded in d3 around 0

                      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                    4. Step-by-step derivation
                      1. distribute-lft-outN/A

                        \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                      2. unpow2N/A

                        \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                      3. distribute-lft-out--N/A

                        \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                      4. *-commutativeN/A

                        \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                      5. lower-*.f64N/A

                        \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                      6. lower--.f64N/A

                        \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                      7. +-commutativeN/A

                        \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                      8. lower-+.f6494.5

                        \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                    5. Applied rewrites94.5%

                      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]

                    if 2.3000000000000002e93 < d3

                    1. Initial program 78.5%

                      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                    2. Add Preprocessing
                    3. Taylor expanded in d4 around inf

                      \[\leadsto \color{blue}{d1 \cdot d4} \]
                    4. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \color{blue}{d4 \cdot d1} \]
                      2. lower-*.f6414.8

                        \[\leadsto \color{blue}{d4 \cdot d1} \]
                    5. Applied rewrites14.8%

                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                    6. Taylor expanded in d2 around 0

                      \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                    7. Step-by-step derivation
                      1. +-commutativeN/A

                        \[\leadsto d1 \cdot d4 - \color{blue}{\left({d1}^{2} + d1 \cdot d3\right)} \]
                      2. unpow2N/A

                        \[\leadsto d1 \cdot d4 - \left(\color{blue}{d1 \cdot d1} + d1 \cdot d3\right) \]
                      3. distribute-lft-inN/A

                        \[\leadsto d1 \cdot d4 - \color{blue}{d1 \cdot \left(d1 + d3\right)} \]
                      4. *-commutativeN/A

                        \[\leadsto d1 \cdot d4 - \color{blue}{\left(d1 + d3\right) \cdot d1} \]
                      5. fp-cancel-sub-sign-invN/A

                        \[\leadsto \color{blue}{d1 \cdot d4 + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1} \]
                      6. *-commutativeN/A

                        \[\leadsto \color{blue}{d4 \cdot d1} + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1 \]
                      7. mul-1-negN/A

                        \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot \left(d1 + d3\right)\right)} \cdot d1 \]
                      8. distribute-lft-inN/A

                        \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot d1 + -1 \cdot d3\right)} \cdot d1 \]
                      9. distribute-rgt-inN/A

                        \[\leadsto \color{blue}{d1 \cdot \left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right)} \]
                      10. *-commutativeN/A

                        \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
                      11. lower-*.f64N/A

                        \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
                      12. associate-+r+N/A

                        \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) + -1 \cdot d3\right)} \cdot d1 \]
                      13. fp-cancel-sign-sub-invN/A

                        \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right)} \cdot d1 \]
                      14. fp-cancel-sign-sub-invN/A

                        \[\leadsto \left(\color{blue}{\left(d4 - \left(\mathsf{neg}\left(-1\right)\right) \cdot d1\right)} - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                      15. metadata-evalN/A

                        \[\leadsto \left(\left(d4 - \color{blue}{1} \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                      16. *-lft-identityN/A

                        \[\leadsto \left(\left(d4 - \color{blue}{d1}\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                      17. metadata-evalN/A

                        \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{1} \cdot d3\right) \cdot d1 \]
                      18. *-lft-identityN/A

                        \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{d3}\right) \cdot d1 \]
                      19. lower--.f64N/A

                        \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                      20. lower--.f6490.7

                        \[\leadsto \left(\color{blue}{\left(d4 - d1\right)} - d3\right) \cdot d1 \]
                    8. Applied rewrites90.7%

                      \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right) \cdot d1} \]
                    9. Taylor expanded in d1 around 0

                      \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                    10. Step-by-step derivation
                      1. Applied rewrites86.0%

                        \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                    11. Recombined 3 regimes into one program.
                    12. Final simplification91.8%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.6 \cdot 10^{+65}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 2.3 \cdot 10^{+93}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \]
                    13. Add Preprocessing

                    Alternative 7: 67.0% accurate, 1.4× speedup?

                    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+81} \lor \neg \left(d3 \leq 2.3 \cdot 10^{+102}\right):\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \end{array} \]
                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                    (FPCore (d1 d2 d3 d4)
                     :precision binary64
                     (if (or (<= d3 -2.4e+81) (not (<= d3 2.3e+102)))
                       (* (- d3) d1)
                       (* (+ d2 d4) d1)))
                    assert(d1 < d2 && d2 < d3 && d3 < d4);
                    double code(double d1, double d2, double d3, double d4) {
                    	double tmp;
                    	if ((d3 <= -2.4e+81) || !(d3 <= 2.3e+102)) {
                    		tmp = -d3 * d1;
                    	} else {
                    		tmp = (d2 + d4) * d1;
                    	}
                    	return tmp;
                    }
                    
                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                    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(d1, d2, d3, d4)
                    use fmin_fmax_functions
                        real(8), intent (in) :: d1
                        real(8), intent (in) :: d2
                        real(8), intent (in) :: d3
                        real(8), intent (in) :: d4
                        real(8) :: tmp
                        if ((d3 <= (-2.4d+81)) .or. (.not. (d3 <= 2.3d+102))) then
                            tmp = -d3 * d1
                        else
                            tmp = (d2 + d4) * d1
                        end if
                        code = tmp
                    end function
                    
                    assert d1 < d2 && d2 < d3 && d3 < d4;
                    public static double code(double d1, double d2, double d3, double d4) {
                    	double tmp;
                    	if ((d3 <= -2.4e+81) || !(d3 <= 2.3e+102)) {
                    		tmp = -d3 * d1;
                    	} else {
                    		tmp = (d2 + d4) * d1;
                    	}
                    	return tmp;
                    }
                    
                    [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                    def code(d1, d2, d3, d4):
                    	tmp = 0
                    	if (d3 <= -2.4e+81) or not (d3 <= 2.3e+102):
                    		tmp = -d3 * d1
                    	else:
                    		tmp = (d2 + d4) * d1
                    	return tmp
                    
                    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                    function code(d1, d2, d3, d4)
                    	tmp = 0.0
                    	if ((d3 <= -2.4e+81) || !(d3 <= 2.3e+102))
                    		tmp = Float64(Float64(-d3) * d1);
                    	else
                    		tmp = Float64(Float64(d2 + d4) * d1);
                    	end
                    	return tmp
                    end
                    
                    d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                    function tmp_2 = code(d1, d2, d3, d4)
                    	tmp = 0.0;
                    	if ((d3 <= -2.4e+81) || ~((d3 <= 2.3e+102)))
                    		tmp = -d3 * d1;
                    	else
                    		tmp = (d2 + d4) * d1;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                    code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -2.4e+81], N[Not[LessEqual[d3, 2.3e+102]], $MachinePrecision]], N[((-d3) * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
                    
                    \begin{array}{l}
                    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+81} \lor \neg \left(d3 \leq 2.3 \cdot 10^{+102}\right):\\
                    \;\;\;\;\left(-d3\right) \cdot d1\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if d3 < -2.3999999999999999e81 or 2.2999999999999999e102 < d3

                      1. Initial program 81.5%

                        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                      2. Add Preprocessing
                      3. Step-by-step derivation
                        1. lift--.f64N/A

                          \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                        2. lift-+.f64N/A

                          \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                        3. associate--l+N/A

                          \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                        4. lift--.f64N/A

                          \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                        5. lift-*.f64N/A

                          \[\leadsto \left(\color{blue}{d1 \cdot d2} - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                        6. lift-*.f64N/A

                          \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                        7. distribute-lft-out--N/A

                          \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                        8. *-commutativeN/A

                          \[\leadsto \color{blue}{\left(d2 - d3\right) \cdot d1} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                        9. lower-fma.f64N/A

                          \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - d1 \cdot d1\right)} \]
                        10. lower--.f64N/A

                          \[\leadsto \mathsf{fma}\left(\color{blue}{d2 - d3}, d1, d4 \cdot d1 - d1 \cdot d1\right) \]
                        11. lift-*.f64N/A

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right) \]
                        12. lift-*.f64N/A

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right) \]
                        13. distribute-rgt-out--N/A

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
                        14. lower-*.f64N/A

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
                        15. lower--.f6493.8

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right) \]
                      4. Applied rewrites93.8%

                        \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)} \]
                      5. Taylor expanded in d1 around 0

                        \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot d4}\right) \]
                      6. Step-by-step derivation
                        1. *-commutativeN/A

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                        2. lower-*.f6491.2

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                      7. Applied rewrites91.2%

                        \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                      8. Taylor expanded in d3 around inf

                        \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
                      9. Step-by-step derivation
                        1. *-commutativeN/A

                          \[\leadsto -1 \cdot \color{blue}{\left(d3 \cdot d1\right)} \]
                        2. associate-*r*N/A

                          \[\leadsto \color{blue}{\left(-1 \cdot d3\right) \cdot d1} \]
                        3. lower-*.f64N/A

                          \[\leadsto \color{blue}{\left(-1 \cdot d3\right) \cdot d1} \]
                        4. mul-1-negN/A

                          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \cdot d1 \]
                        5. lower-neg.f6475.7

                          \[\leadsto \color{blue}{\left(-d3\right)} \cdot d1 \]
                      10. Applied rewrites75.7%

                        \[\leadsto \color{blue}{\left(-d3\right) \cdot d1} \]

                      if -2.3999999999999999e81 < d3 < 2.2999999999999999e102

                      1. Initial program 91.4%

                        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                      2. Add Preprocessing
                      3. Taylor expanded in d3 around 0

                        \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                      4. Step-by-step derivation
                        1. distribute-lft-outN/A

                          \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                        2. unpow2N/A

                          \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                        3. distribute-lft-out--N/A

                          \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                        4. *-commutativeN/A

                          \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                        5. lower-*.f64N/A

                          \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                        6. lower--.f64N/A

                          \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                        7. +-commutativeN/A

                          \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                        8. lower-+.f6493.2

                          \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                      5. Applied rewrites93.2%

                        \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
                      6. Taylor expanded in d1 around 0

                        \[\leadsto \left(d2 + d4\right) \cdot d1 \]
                      7. Step-by-step derivation
                        1. Applied rewrites67.1%

                          \[\leadsto \left(d2 + d4\right) \cdot d1 \]
                      8. Recombined 2 regimes into one program.
                      9. Final simplification69.8%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+81} \lor \neg \left(d3 \leq 2.3 \cdot 10^{+102}\right):\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \]
                      10. Add Preprocessing

                      Alternative 8: 51.3% accurate, 1.5× speedup?

                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+121}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -3.8 \cdot 10^{-130}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      (FPCore (d1 d2 d3 d4)
                       :precision binary64
                       (if (<= d2 -5.8e+121)
                         (* d2 d1)
                         (if (<= d2 -3.8e-130) (* (- d3) d1) (* d4 d1))))
                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                      double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d2 <= -5.8e+121) {
                      		tmp = d2 * d1;
                      	} else if (d2 <= -3.8e-130) {
                      		tmp = -d3 * d1;
                      	} else {
                      		tmp = d4 * d1;
                      	}
                      	return tmp;
                      }
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      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(d1, d2, d3, d4)
                      use fmin_fmax_functions
                          real(8), intent (in) :: d1
                          real(8), intent (in) :: d2
                          real(8), intent (in) :: d3
                          real(8), intent (in) :: d4
                          real(8) :: tmp
                          if (d2 <= (-5.8d+121)) then
                              tmp = d2 * d1
                          else if (d2 <= (-3.8d-130)) then
                              tmp = -d3 * d1
                          else
                              tmp = d4 * d1
                          end if
                          code = tmp
                      end function
                      
                      assert d1 < d2 && d2 < d3 && d3 < d4;
                      public static double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d2 <= -5.8e+121) {
                      		tmp = d2 * d1;
                      	} else if (d2 <= -3.8e-130) {
                      		tmp = -d3 * d1;
                      	} else {
                      		tmp = d4 * d1;
                      	}
                      	return tmp;
                      }
                      
                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                      def code(d1, d2, d3, d4):
                      	tmp = 0
                      	if d2 <= -5.8e+121:
                      		tmp = d2 * d1
                      	elif d2 <= -3.8e-130:
                      		tmp = -d3 * d1
                      	else:
                      		tmp = d4 * d1
                      	return tmp
                      
                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                      function code(d1, d2, d3, d4)
                      	tmp = 0.0
                      	if (d2 <= -5.8e+121)
                      		tmp = Float64(d2 * d1);
                      	elseif (d2 <= -3.8e-130)
                      		tmp = Float64(Float64(-d3) * d1);
                      	else
                      		tmp = Float64(d4 * d1);
                      	end
                      	return tmp
                      end
                      
                      d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                      function tmp_2 = code(d1, d2, d3, d4)
                      	tmp = 0.0;
                      	if (d2 <= -5.8e+121)
                      		tmp = d2 * d1;
                      	elseif (d2 <= -3.8e-130)
                      		tmp = -d3 * d1;
                      	else
                      		tmp = d4 * d1;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.8e+121], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -3.8e-130], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
                      
                      \begin{array}{l}
                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+121}:\\
                      \;\;\;\;d2 \cdot d1\\
                      
                      \mathbf{elif}\;d2 \leq -3.8 \cdot 10^{-130}:\\
                      \;\;\;\;\left(-d3\right) \cdot d1\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;d4 \cdot d1\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 3 regimes
                      2. if d2 < -5.7999999999999998e121

                        1. Initial program 82.9%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                          2. lift-+.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                          3. associate--l+N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                          4. lift--.f64N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          5. lift-*.f64N/A

                            \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          6. fp-cancel-sub-sign-invN/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\mathsf{neg}\left(d1\right)\right) \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          7. associate-+l+N/A

                            \[\leadsto \color{blue}{d1 \cdot d2 + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                          8. lift-*.f64N/A

                            \[\leadsto \color{blue}{d1 \cdot d2} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                          9. *-commutativeN/A

                            \[\leadsto \color{blue}{d2 \cdot d1} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                          10. lower-fma.f64N/A

                            \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                          11. lower-fma.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(d1\right), d3, d4 \cdot d1 - d1 \cdot d1\right)}\right) \]
                          12. lower-neg.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(\color{blue}{-d1}, d3, d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                          13. lift-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right)\right) \]
                          14. lift-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right)\right) \]
                          15. distribute-rgt-out--N/A

                            \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                          16. lower-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                          17. lower--.f6495.1

                            \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right)\right) \]
                        4. Applied rewrites95.1%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \left(d4 - d1\right)\right)\right)} \]
                        5. Taylor expanded in d2 around inf

                          \[\leadsto \color{blue}{d1 \cdot d2} \]
                        6. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto \color{blue}{d2 \cdot d1} \]
                          2. lower-*.f6473.0

                            \[\leadsto \color{blue}{d2 \cdot d1} \]
                        7. Applied rewrites73.0%

                          \[\leadsto \color{blue}{d2 \cdot d1} \]

                        if -5.7999999999999998e121 < d2 < -3.7999999999999998e-130

                        1. Initial program 91.4%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                          2. lift-+.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                          3. associate--l+N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                          4. lift--.f64N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          5. lift-*.f64N/A

                            \[\leadsto \left(\color{blue}{d1 \cdot d2} - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          6. lift-*.f64N/A

                            \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          7. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          8. *-commutativeN/A

                            \[\leadsto \color{blue}{\left(d2 - d3\right) \cdot d1} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                          9. lower-fma.f64N/A

                            \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - d1 \cdot d1\right)} \]
                          10. lower--.f64N/A

                            \[\leadsto \mathsf{fma}\left(\color{blue}{d2 - d3}, d1, d4 \cdot d1 - d1 \cdot d1\right) \]
                          11. lift-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right) \]
                          12. lift-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right) \]
                          13. distribute-rgt-out--N/A

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
                          14. lower-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right) \]
                          15. lower--.f6496.6

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right) \]
                        4. Applied rewrites96.6%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)} \]
                        5. Taylor expanded in d1 around 0

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d1 \cdot d4}\right) \]
                        6. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                          2. lower-*.f6472.4

                            \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                        7. Applied rewrites72.4%

                          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, \color{blue}{d4 \cdot d1}\right) \]
                        8. Taylor expanded in d3 around inf

                          \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
                        9. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto -1 \cdot \color{blue}{\left(d3 \cdot d1\right)} \]
                          2. associate-*r*N/A

                            \[\leadsto \color{blue}{\left(-1 \cdot d3\right) \cdot d1} \]
                          3. lower-*.f64N/A

                            \[\leadsto \color{blue}{\left(-1 \cdot d3\right) \cdot d1} \]
                          4. mul-1-negN/A

                            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \cdot d1 \]
                          5. lower-neg.f6443.7

                            \[\leadsto \color{blue}{\left(-d3\right)} \cdot d1 \]
                        10. Applied rewrites43.7%

                          \[\leadsto \color{blue}{\left(-d3\right) \cdot d1} \]

                        if -3.7999999999999998e-130 < d2

                        1. Initial program 88.4%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Taylor expanded in d4 around inf

                          \[\leadsto \color{blue}{d1 \cdot d4} \]
                        4. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto \color{blue}{d4 \cdot d1} \]
                          2. lower-*.f6434.0

                            \[\leadsto \color{blue}{d4 \cdot d1} \]
                        5. Applied rewrites34.0%

                          \[\leadsto \color{blue}{d4 \cdot d1} \]
                      3. Recombined 3 regimes into one program.
                      4. Final simplification42.4%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.8 \cdot 10^{+121}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -3.8 \cdot 10^{-130}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                      5. Add Preprocessing

                      Alternative 9: 94.3% accurate, 1.7× speedup?

                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.3 \cdot 10^{+17}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      (FPCore (d1 d2 d3 d4)
                       :precision binary64
                       (if (<= d2 -4.3e+17) (* (- (- d2 d3) d1) d1) (* (- (- d4 d1) d3) d1)))
                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                      double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d2 <= -4.3e+17) {
                      		tmp = ((d2 - d3) - d1) * d1;
                      	} else {
                      		tmp = ((d4 - d1) - d3) * d1;
                      	}
                      	return tmp;
                      }
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      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(d1, d2, d3, d4)
                      use fmin_fmax_functions
                          real(8), intent (in) :: d1
                          real(8), intent (in) :: d2
                          real(8), intent (in) :: d3
                          real(8), intent (in) :: d4
                          real(8) :: tmp
                          if (d2 <= (-4.3d+17)) then
                              tmp = ((d2 - d3) - d1) * d1
                          else
                              tmp = ((d4 - d1) - d3) * d1
                          end if
                          code = tmp
                      end function
                      
                      assert d1 < d2 && d2 < d3 && d3 < d4;
                      public static double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d2 <= -4.3e+17) {
                      		tmp = ((d2 - d3) - d1) * d1;
                      	} else {
                      		tmp = ((d4 - d1) - d3) * d1;
                      	}
                      	return tmp;
                      }
                      
                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                      def code(d1, d2, d3, d4):
                      	tmp = 0
                      	if d2 <= -4.3e+17:
                      		tmp = ((d2 - d3) - d1) * d1
                      	else:
                      		tmp = ((d4 - d1) - d3) * d1
                      	return tmp
                      
                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                      function code(d1, d2, d3, d4)
                      	tmp = 0.0
                      	if (d2 <= -4.3e+17)
                      		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                      	else
                      		tmp = Float64(Float64(Float64(d4 - d1) - d3) * d1);
                      	end
                      	return tmp
                      end
                      
                      d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                      function tmp_2 = code(d1, d2, d3, d4)
                      	tmp = 0.0;
                      	if (d2 <= -4.3e+17)
                      		tmp = ((d2 - d3) - d1) * d1;
                      	else
                      		tmp = ((d4 - d1) - d3) * d1;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.3e+17], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                      
                      \begin{array}{l}
                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;d2 \leq -4.3 \cdot 10^{+17}:\\
                      \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if d2 < -4.3e17

                        1. Initial program 86.9%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Taylor expanded in d4 around 0

                          \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                        4. Step-by-step derivation
                          1. associate--r+N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
                          2. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                          3. unpow2N/A

                            \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
                          4. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
                          5. *-commutativeN/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                          6. lower-*.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                          7. lower--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                          8. lower--.f6486.6

                            \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                        5. Applied rewrites86.6%

                          \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]

                        if -4.3e17 < d2

                        1. Initial program 88.7%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Taylor expanded in d4 around inf

                          \[\leadsto \color{blue}{d1 \cdot d4} \]
                        4. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto \color{blue}{d4 \cdot d1} \]
                          2. lower-*.f6431.7

                            \[\leadsto \color{blue}{d4 \cdot d1} \]
                        5. Applied rewrites31.7%

                          \[\leadsto \color{blue}{d4 \cdot d1} \]
                        6. Taylor expanded in d2 around 0

                          \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                        7. Step-by-step derivation
                          1. +-commutativeN/A

                            \[\leadsto d1 \cdot d4 - \color{blue}{\left({d1}^{2} + d1 \cdot d3\right)} \]
                          2. unpow2N/A

                            \[\leadsto d1 \cdot d4 - \left(\color{blue}{d1 \cdot d1} + d1 \cdot d3\right) \]
                          3. distribute-lft-inN/A

                            \[\leadsto d1 \cdot d4 - \color{blue}{d1 \cdot \left(d1 + d3\right)} \]
                          4. *-commutativeN/A

                            \[\leadsto d1 \cdot d4 - \color{blue}{\left(d1 + d3\right) \cdot d1} \]
                          5. fp-cancel-sub-sign-invN/A

                            \[\leadsto \color{blue}{d1 \cdot d4 + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1} \]
                          6. *-commutativeN/A

                            \[\leadsto \color{blue}{d4 \cdot d1} + \left(\mathsf{neg}\left(\left(d1 + d3\right)\right)\right) \cdot d1 \]
                          7. mul-1-negN/A

                            \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot \left(d1 + d3\right)\right)} \cdot d1 \]
                          8. distribute-lft-inN/A

                            \[\leadsto d4 \cdot d1 + \color{blue}{\left(-1 \cdot d1 + -1 \cdot d3\right)} \cdot d1 \]
                          9. distribute-rgt-inN/A

                            \[\leadsto \color{blue}{d1 \cdot \left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right)} \]
                          10. *-commutativeN/A

                            \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
                          11. lower-*.f64N/A

                            \[\leadsto \color{blue}{\left(d4 + \left(-1 \cdot d1 + -1 \cdot d3\right)\right) \cdot d1} \]
                          12. associate-+r+N/A

                            \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) + -1 \cdot d3\right)} \cdot d1 \]
                          13. fp-cancel-sign-sub-invN/A

                            \[\leadsto \color{blue}{\left(\left(d4 + -1 \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right)} \cdot d1 \]
                          14. fp-cancel-sign-sub-invN/A

                            \[\leadsto \left(\color{blue}{\left(d4 - \left(\mathsf{neg}\left(-1\right)\right) \cdot d1\right)} - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                          15. metadata-evalN/A

                            \[\leadsto \left(\left(d4 - \color{blue}{1} \cdot d1\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                          16. *-lft-identityN/A

                            \[\leadsto \left(\left(d4 - \color{blue}{d1}\right) - \left(\mathsf{neg}\left(-1\right)\right) \cdot d3\right) \cdot d1 \]
                          17. metadata-evalN/A

                            \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{1} \cdot d3\right) \cdot d1 \]
                          18. *-lft-identityN/A

                            \[\leadsto \left(\left(d4 - d1\right) - \color{blue}{d3}\right) \cdot d1 \]
                          19. lower--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                          20. lower--.f6483.2

                            \[\leadsto \left(\color{blue}{\left(d4 - d1\right)} - d3\right) \cdot d1 \]
                        8. Applied rewrites83.2%

                          \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right) \cdot d1} \]
                      3. Recombined 2 regimes into one program.
                      4. Final simplification84.0%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.3 \cdot 10^{+17}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\ \end{array} \]
                      5. Add Preprocessing

                      Alternative 10: 93.2% accurate, 1.7× speedup?

                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 3.2 \cdot 10^{-21}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      (FPCore (d1 d2 d3 d4)
                       :precision binary64
                       (if (<= d4 3.2e-21) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                      double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d4 <= 3.2e-21) {
                      		tmp = ((d2 - d3) - d1) * d1;
                      	} else {
                      		tmp = ((d4 + d2) - d3) * d1;
                      	}
                      	return tmp;
                      }
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      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(d1, d2, d3, d4)
                      use fmin_fmax_functions
                          real(8), intent (in) :: d1
                          real(8), intent (in) :: d2
                          real(8), intent (in) :: d3
                          real(8), intent (in) :: d4
                          real(8) :: tmp
                          if (d4 <= 3.2d-21) then
                              tmp = ((d2 - d3) - d1) * d1
                          else
                              tmp = ((d4 + d2) - d3) * d1
                          end if
                          code = tmp
                      end function
                      
                      assert d1 < d2 && d2 < d3 && d3 < d4;
                      public static double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d4 <= 3.2e-21) {
                      		tmp = ((d2 - d3) - d1) * d1;
                      	} else {
                      		tmp = ((d4 + d2) - d3) * d1;
                      	}
                      	return tmp;
                      }
                      
                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                      def code(d1, d2, d3, d4):
                      	tmp = 0
                      	if d4 <= 3.2e-21:
                      		tmp = ((d2 - d3) - d1) * d1
                      	else:
                      		tmp = ((d4 + d2) - d3) * d1
                      	return tmp
                      
                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                      function code(d1, d2, d3, d4)
                      	tmp = 0.0
                      	if (d4 <= 3.2e-21)
                      		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                      	else
                      		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                      	end
                      	return tmp
                      end
                      
                      d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                      function tmp_2 = code(d1, d2, d3, d4)
                      	tmp = 0.0;
                      	if (d4 <= 3.2e-21)
                      		tmp = ((d2 - d3) - d1) * d1;
                      	else
                      		tmp = ((d4 + d2) - d3) * d1;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 3.2e-21], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                      
                      \begin{array}{l}
                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;d4 \leq 3.2 \cdot 10^{-21}:\\
                      \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if d4 < 3.2000000000000002e-21

                        1. Initial program 90.4%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Taylor expanded in d4 around 0

                          \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                        4. Step-by-step derivation
                          1. associate--r+N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
                          2. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                          3. unpow2N/A

                            \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
                          4. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
                          5. *-commutativeN/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                          6. lower-*.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                          7. lower--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                          8. lower--.f6482.5

                            \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                        5. Applied rewrites82.5%

                          \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]

                        if 3.2000000000000002e-21 < d4

                        1. Initial program 83.5%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Taylor expanded in d1 around 0

                          \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
                        4. Step-by-step derivation
                          1. *-commutativeN/A

                            \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d3\right) \cdot d1} \]
                          2. lower-*.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d3\right) \cdot d1} \]
                          3. lower--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d3\right)} \cdot d1 \]
                          4. +-commutativeN/A

                            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                          5. lower-+.f6488.5

                            \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                        5. Applied rewrites88.5%

                          \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
                      3. Recombined 2 regimes into one program.
                      4. Final simplification84.4%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 3.2 \cdot 10^{-21}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \]
                      5. Add Preprocessing

                      Alternative 11: 73.1% accurate, 2.0× speedup?

                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -80000000:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      (FPCore (d1 d2 d3 d4)
                       :precision binary64
                       (if (<= d2 -80000000.0) (* (- d2 d3) d1) (* (- d4 d1) d1)))
                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                      double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d2 <= -80000000.0) {
                      		tmp = (d2 - d3) * d1;
                      	} else {
                      		tmp = (d4 - d1) * d1;
                      	}
                      	return tmp;
                      }
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      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(d1, d2, d3, d4)
                      use fmin_fmax_functions
                          real(8), intent (in) :: d1
                          real(8), intent (in) :: d2
                          real(8), intent (in) :: d3
                          real(8), intent (in) :: d4
                          real(8) :: tmp
                          if (d2 <= (-80000000.0d0)) then
                              tmp = (d2 - d3) * d1
                          else
                              tmp = (d4 - d1) * d1
                          end if
                          code = tmp
                      end function
                      
                      assert d1 < d2 && d2 < d3 && d3 < d4;
                      public static double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d2 <= -80000000.0) {
                      		tmp = (d2 - d3) * d1;
                      	} else {
                      		tmp = (d4 - d1) * d1;
                      	}
                      	return tmp;
                      }
                      
                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                      def code(d1, d2, d3, d4):
                      	tmp = 0
                      	if d2 <= -80000000.0:
                      		tmp = (d2 - d3) * d1
                      	else:
                      		tmp = (d4 - d1) * d1
                      	return tmp
                      
                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                      function code(d1, d2, d3, d4)
                      	tmp = 0.0
                      	if (d2 <= -80000000.0)
                      		tmp = Float64(Float64(d2 - d3) * d1);
                      	else
                      		tmp = Float64(Float64(d4 - d1) * d1);
                      	end
                      	return tmp
                      end
                      
                      d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                      function tmp_2 = code(d1, d2, d3, d4)
                      	tmp = 0.0;
                      	if (d2 <= -80000000.0)
                      		tmp = (d2 - d3) * d1;
                      	else
                      		tmp = (d4 - d1) * d1;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -80000000.0], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]
                      
                      \begin{array}{l}
                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;d2 \leq -80000000:\\
                      \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if d2 < -8e7

                        1. Initial program 87.3%

                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                        2. Add Preprocessing
                        3. Taylor expanded in d4 around 0

                          \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                        4. Step-by-step derivation
                          1. associate--r+N/A

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
                          2. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                          3. unpow2N/A

                            \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
                          4. distribute-lft-out--N/A

                            \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
                          5. *-commutativeN/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                          6. lower-*.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                          7. lower--.f64N/A

                            \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                          8. lower--.f6485.7

                            \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                        5. Applied rewrites85.7%

                          \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                        6. Taylor expanded in d1 around 0

                          \[\leadsto \left(d2 - d3\right) \cdot d1 \]
                        7. Step-by-step derivation
                          1. Applied rewrites73.6%

                            \[\leadsto \left(d2 - d3\right) \cdot d1 \]

                          if -8e7 < d2

                          1. Initial program 88.6%

                            \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                          2. Add Preprocessing
                          3. Taylor expanded in d3 around 0

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                          4. Step-by-step derivation
                            1. distribute-lft-outN/A

                              \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                            2. unpow2N/A

                              \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                            3. distribute-lft-out--N/A

                              \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                            4. *-commutativeN/A

                              \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                            5. lower-*.f64N/A

                              \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                            6. lower--.f64N/A

                              \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                            7. +-commutativeN/A

                              \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                            8. lower-+.f6474.8

                              \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                          5. Applied rewrites74.8%

                            \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
                          6. Taylor expanded in d2 around 0

                            \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                          7. Step-by-step derivation
                            1. Applied rewrites58.0%

                              \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                          8. Recombined 2 regimes into one program.
                          9. Final simplification61.9%

                            \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -80000000:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \]
                          10. Add Preprocessing

                          Alternative 12: 71.3% accurate, 2.0× speedup?

                          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -3.6 \cdot 10^{+15}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
                          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                          (FPCore (d1 d2 d3 d4)
                           :precision binary64
                           (if (<= d2 -3.6e+15) (* (- d2 d1) d1) (* (- d4 d1) d1)))
                          assert(d1 < d2 && d2 < d3 && d3 < d4);
                          double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d2 <= -3.6e+15) {
                          		tmp = (d2 - d1) * d1;
                          	} else {
                          		tmp = (d4 - d1) * d1;
                          	}
                          	return tmp;
                          }
                          
                          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                          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(d1, d2, d3, d4)
                          use fmin_fmax_functions
                              real(8), intent (in) :: d1
                              real(8), intent (in) :: d2
                              real(8), intent (in) :: d3
                              real(8), intent (in) :: d4
                              real(8) :: tmp
                              if (d2 <= (-3.6d+15)) then
                                  tmp = (d2 - d1) * d1
                              else
                                  tmp = (d4 - d1) * d1
                              end if
                              code = tmp
                          end function
                          
                          assert d1 < d2 && d2 < d3 && d3 < d4;
                          public static double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d2 <= -3.6e+15) {
                          		tmp = (d2 - d1) * d1;
                          	} else {
                          		tmp = (d4 - d1) * d1;
                          	}
                          	return tmp;
                          }
                          
                          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                          def code(d1, d2, d3, d4):
                          	tmp = 0
                          	if d2 <= -3.6e+15:
                          		tmp = (d2 - d1) * d1
                          	else:
                          		tmp = (d4 - d1) * d1
                          	return tmp
                          
                          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                          function code(d1, d2, d3, d4)
                          	tmp = 0.0
                          	if (d2 <= -3.6e+15)
                          		tmp = Float64(Float64(d2 - d1) * d1);
                          	else
                          		tmp = Float64(Float64(d4 - d1) * d1);
                          	end
                          	return tmp
                          end
                          
                          d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                          function tmp_2 = code(d1, d2, d3, d4)
                          	tmp = 0.0;
                          	if (d2 <= -3.6e+15)
                          		tmp = (d2 - d1) * d1;
                          	else
                          		tmp = (d4 - d1) * d1;
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                          code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.6e+15], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]
                          
                          \begin{array}{l}
                          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;d2 \leq -3.6 \cdot 10^{+15}:\\
                          \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if d2 < -3.6e15

                            1. Initial program 87.1%

                              \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                            2. Add Preprocessing
                            3. Taylor expanded in d4 around 0

                              \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                            4. Step-by-step derivation
                              1. associate--r+N/A

                                \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) - {d1}^{2}} \]
                              2. distribute-lft-out--N/A

                                \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                              3. unpow2N/A

                                \[\leadsto d1 \cdot \left(d2 - d3\right) - \color{blue}{d1 \cdot d1} \]
                              4. distribute-lft-out--N/A

                                \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) - d1\right)} \]
                              5. *-commutativeN/A

                                \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                              6. lower-*.f64N/A

                                \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                              7. lower--.f64N/A

                                \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                              8. lower--.f6486.9

                                \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                            5. Applied rewrites86.9%

                              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right) \cdot d1} \]
                            6. Taylor expanded in d3 around 0

                              \[\leadsto \left(d2 - d1\right) \cdot d1 \]
                            7. Step-by-step derivation
                              1. Applied rewrites70.1%

                                \[\leadsto \left(d2 - d1\right) \cdot d1 \]

                              if -3.6e15 < d2

                              1. Initial program 88.6%

                                \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                              2. Add Preprocessing
                              3. Taylor expanded in d3 around 0

                                \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                              4. Step-by-step derivation
                                1. distribute-lft-outN/A

                                  \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                                2. unpow2N/A

                                  \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                                3. distribute-lft-out--N/A

                                  \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                                4. *-commutativeN/A

                                  \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                                5. lower-*.f64N/A

                                  \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                                6. lower--.f64N/A

                                  \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                                7. +-commutativeN/A

                                  \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                                8. lower-+.f6474.9

                                  \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                              5. Applied rewrites74.9%

                                \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
                              6. Taylor expanded in d2 around 0

                                \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                              7. Step-by-step derivation
                                1. Applied rewrites58.1%

                                  \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                              8. Recombined 2 regimes into one program.
                              9. Final simplification61.0%

                                \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.6 \cdot 10^{+15}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \]
                              10. Add Preprocessing

                              Alternative 13: 70.5% accurate, 2.0× speedup?

                              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+45}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                              (FPCore (d1 d2 d3 d4)
                               :precision binary64
                               (if (<= d2 -1.35e+45) (* (+ d2 d4) d1) (* (- d4 d1) d1)))
                              assert(d1 < d2 && d2 < d3 && d3 < d4);
                              double code(double d1, double d2, double d3, double d4) {
                              	double tmp;
                              	if (d2 <= -1.35e+45) {
                              		tmp = (d2 + d4) * d1;
                              	} else {
                              		tmp = (d4 - d1) * d1;
                              	}
                              	return tmp;
                              }
                              
                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                              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(d1, d2, d3, d4)
                              use fmin_fmax_functions
                                  real(8), intent (in) :: d1
                                  real(8), intent (in) :: d2
                                  real(8), intent (in) :: d3
                                  real(8), intent (in) :: d4
                                  real(8) :: tmp
                                  if (d2 <= (-1.35d+45)) then
                                      tmp = (d2 + d4) * d1
                                  else
                                      tmp = (d4 - d1) * d1
                                  end if
                                  code = tmp
                              end function
                              
                              assert d1 < d2 && d2 < d3 && d3 < d4;
                              public static double code(double d1, double d2, double d3, double d4) {
                              	double tmp;
                              	if (d2 <= -1.35e+45) {
                              		tmp = (d2 + d4) * d1;
                              	} else {
                              		tmp = (d4 - d1) * d1;
                              	}
                              	return tmp;
                              }
                              
                              [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                              def code(d1, d2, d3, d4):
                              	tmp = 0
                              	if d2 <= -1.35e+45:
                              		tmp = (d2 + d4) * d1
                              	else:
                              		tmp = (d4 - d1) * d1
                              	return tmp
                              
                              d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                              function code(d1, d2, d3, d4)
                              	tmp = 0.0
                              	if (d2 <= -1.35e+45)
                              		tmp = Float64(Float64(d2 + d4) * d1);
                              	else
                              		tmp = Float64(Float64(d4 - d1) * d1);
                              	end
                              	return tmp
                              end
                              
                              d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                              function tmp_2 = code(d1, d2, d3, d4)
                              	tmp = 0.0;
                              	if (d2 <= -1.35e+45)
                              		tmp = (d2 + d4) * d1;
                              	else
                              		tmp = (d4 - d1) * d1;
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                              code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.35e+45], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]
                              
                              \begin{array}{l}
                              [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+45}:\\
                              \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 2 regimes
                              2. if d2 < -1.34999999999999992e45

                                1. Initial program 85.9%

                                  \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                2. Add Preprocessing
                                3. Taylor expanded in d3 around 0

                                  \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                4. Step-by-step derivation
                                  1. distribute-lft-outN/A

                                    \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                                  2. unpow2N/A

                                    \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                                  3. distribute-lft-out--N/A

                                    \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                                  4. *-commutativeN/A

                                    \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                                  5. lower-*.f64N/A

                                    \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                                  6. lower--.f64N/A

                                    \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                                  7. +-commutativeN/A

                                    \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                                  8. lower-+.f6487.0

                                    \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                                5. Applied rewrites87.0%

                                  \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
                                6. Taylor expanded in d1 around 0

                                  \[\leadsto \left(d2 + d4\right) \cdot d1 \]
                                7. Step-by-step derivation
                                  1. Applied rewrites77.0%

                                    \[\leadsto \left(d2 + d4\right) \cdot d1 \]

                                  if -1.34999999999999992e45 < d2

                                  1. Initial program 88.9%

                                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in d3 around 0

                                    \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                  4. Step-by-step derivation
                                    1. distribute-lft-outN/A

                                      \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} - {d1}^{2} \]
                                    2. unpow2N/A

                                      \[\leadsto d1 \cdot \left(d2 + d4\right) - \color{blue}{d1 \cdot d1} \]
                                    3. distribute-lft-out--N/A

                                      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d1\right)} \]
                                    4. *-commutativeN/A

                                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                                    5. lower-*.f64N/A

                                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right) \cdot d1} \]
                                    6. lower--.f64N/A

                                      \[\leadsto \color{blue}{\left(\left(d2 + d4\right) - d1\right)} \cdot d1 \]
                                    7. +-commutativeN/A

                                      \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                                    8. lower-+.f6474.1

                                      \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                                  5. Applied rewrites74.1%

                                    \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d1\right) \cdot d1} \]
                                  6. Taylor expanded in d2 around 0

                                    \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                                  7. Step-by-step derivation
                                    1. Applied rewrites57.6%

                                      \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                                  8. Recombined 2 regimes into one program.
                                  9. Final simplification61.9%

                                    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+45}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \]
                                  10. Add Preprocessing

                                  Alternative 14: 49.8% accurate, 2.5× speedup?

                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -2.1 \cdot 10^{+43}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                  (FPCore (d1 d2 d3 d4)
                                   :precision binary64
                                   (if (<= d2 -2.1e+43) (* d2 d1) (* d4 d1)))
                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                  double code(double d1, double d2, double d3, double d4) {
                                  	double tmp;
                                  	if (d2 <= -2.1e+43) {
                                  		tmp = d2 * d1;
                                  	} else {
                                  		tmp = d4 * d1;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                  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(d1, d2, d3, d4)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: d1
                                      real(8), intent (in) :: d2
                                      real(8), intent (in) :: d3
                                      real(8), intent (in) :: d4
                                      real(8) :: tmp
                                      if (d2 <= (-2.1d+43)) then
                                          tmp = d2 * d1
                                      else
                                          tmp = d4 * d1
                                      end if
                                      code = tmp
                                  end function
                                  
                                  assert d1 < d2 && d2 < d3 && d3 < d4;
                                  public static double code(double d1, double d2, double d3, double d4) {
                                  	double tmp;
                                  	if (d2 <= -2.1e+43) {
                                  		tmp = d2 * d1;
                                  	} else {
                                  		tmp = d4 * d1;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                  def code(d1, d2, d3, d4):
                                  	tmp = 0
                                  	if d2 <= -2.1e+43:
                                  		tmp = d2 * d1
                                  	else:
                                  		tmp = d4 * d1
                                  	return tmp
                                  
                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                  function code(d1, d2, d3, d4)
                                  	tmp = 0.0
                                  	if (d2 <= -2.1e+43)
                                  		tmp = Float64(d2 * d1);
                                  	else
                                  		tmp = Float64(d4 * d1);
                                  	end
                                  	return tmp
                                  end
                                  
                                  d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                  function tmp_2 = code(d1, d2, d3, d4)
                                  	tmp = 0.0;
                                  	if (d2 <= -2.1e+43)
                                  		tmp = d2 * d1;
                                  	else
                                  		tmp = d4 * d1;
                                  	end
                                  	tmp_2 = tmp;
                                  end
                                  
                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -2.1e+43], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
                                  
                                  \begin{array}{l}
                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;d2 \leq -2.1 \cdot 10^{+43}:\\
                                  \;\;\;\;d2 \cdot d1\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;d4 \cdot d1\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 2 regimes
                                  2. if d2 < -2.10000000000000002e43

                                    1. Initial program 86.2%

                                      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                    2. Add Preprocessing
                                    3. Step-by-step derivation
                                      1. lift--.f64N/A

                                        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                                      2. lift-+.f64N/A

                                        \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                                      3. associate--l+N/A

                                        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                                      4. lift--.f64N/A

                                        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                                      5. lift-*.f64N/A

                                        \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                                      6. fp-cancel-sub-sign-invN/A

                                        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\mathsf{neg}\left(d1\right)\right) \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                                      7. associate-+l+N/A

                                        \[\leadsto \color{blue}{d1 \cdot d2 + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                                      8. lift-*.f64N/A

                                        \[\leadsto \color{blue}{d1 \cdot d2} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                                      9. *-commutativeN/A

                                        \[\leadsto \color{blue}{d2 \cdot d1} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                                      10. lower-fma.f64N/A

                                        \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                                      11. lower-fma.f64N/A

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(d1\right), d3, d4 \cdot d1 - d1 \cdot d1\right)}\right) \]
                                      12. lower-neg.f64N/A

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(\color{blue}{-d1}, d3, d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                                      13. lift-*.f64N/A

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right)\right) \]
                                      14. lift-*.f64N/A

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right)\right) \]
                                      15. distribute-rgt-out--N/A

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                                      16. lower-*.f64N/A

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                                      17. lower--.f6496.6

                                        \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right)\right) \]
                                    4. Applied rewrites96.6%

                                      \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \left(d4 - d1\right)\right)\right)} \]
                                    5. Taylor expanded in d2 around inf

                                      \[\leadsto \color{blue}{d1 \cdot d2} \]
                                    6. Step-by-step derivation
                                      1. *-commutativeN/A

                                        \[\leadsto \color{blue}{d2 \cdot d1} \]
                                      2. lower-*.f6461.9

                                        \[\leadsto \color{blue}{d2 \cdot d1} \]
                                    7. Applied rewrites61.9%

                                      \[\leadsto \color{blue}{d2 \cdot d1} \]

                                    if -2.10000000000000002e43 < d2

                                    1. Initial program 88.9%

                                      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in d4 around inf

                                      \[\leadsto \color{blue}{d1 \cdot d4} \]
                                    4. Step-by-step derivation
                                      1. *-commutativeN/A

                                        \[\leadsto \color{blue}{d4 \cdot d1} \]
                                      2. lower-*.f6431.7

                                        \[\leadsto \color{blue}{d4 \cdot d1} \]
                                    5. Applied rewrites31.7%

                                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                                  3. Recombined 2 regimes into one program.
                                  4. Final simplification38.6%

                                    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -2.1 \cdot 10^{+43}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                                  5. Add Preprocessing

                                  Alternative 15: 30.2% accurate, 5.0× speedup?

                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ d2 \cdot d1 \end{array} \]
                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                  (FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                  double code(double d1, double d2, double d3, double d4) {
                                  	return d2 * d1;
                                  }
                                  
                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                  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(d1, d2, d3, d4)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: d1
                                      real(8), intent (in) :: d2
                                      real(8), intent (in) :: d3
                                      real(8), intent (in) :: d4
                                      code = d2 * d1
                                  end function
                                  
                                  assert d1 < d2 && d2 < d3 && d3 < d4;
                                  public static double code(double d1, double d2, double d3, double d4) {
                                  	return d2 * d1;
                                  }
                                  
                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                  def code(d1, d2, d3, d4):
                                  	return d2 * d1
                                  
                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                  function code(d1, d2, d3, d4)
                                  	return Float64(d2 * d1)
                                  end
                                  
                                  d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                  function tmp = code(d1, d2, d3, d4)
                                  	tmp = d2 * d1;
                                  end
                                  
                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                  code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
                                  
                                  \begin{array}{l}
                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                  \\
                                  d2 \cdot d1
                                  \end{array}
                                  
                                  Derivation
                                  1. Initial program 88.3%

                                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                  2. Add Preprocessing
                                  3. Step-by-step derivation
                                    1. lift--.f64N/A

                                      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1} \]
                                    2. lift-+.f64N/A

                                      \[\leadsto \color{blue}{\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right)} - d1 \cdot d1 \]
                                    3. associate--l+N/A

                                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
                                    4. lift--.f64N/A

                                      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                                    5. lift-*.f64N/A

                                      \[\leadsto \left(d1 \cdot d2 - \color{blue}{d1 \cdot d3}\right) + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                                    6. fp-cancel-sub-sign-invN/A

                                      \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\mathsf{neg}\left(d1\right)\right) \cdot d3\right)} + \left(d4 \cdot d1 - d1 \cdot d1\right) \]
                                    7. associate-+l+N/A

                                      \[\leadsto \color{blue}{d1 \cdot d2 + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                                    8. lift-*.f64N/A

                                      \[\leadsto \color{blue}{d1 \cdot d2} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                                    9. *-commutativeN/A

                                      \[\leadsto \color{blue}{d2 \cdot d1} + \left(\left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                                    10. lower-fma.f64N/A

                                      \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot d3 + \left(d4 \cdot d1 - d1 \cdot d1\right)\right)} \]
                                    11. lower-fma.f64N/A

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(d1\right), d3, d4 \cdot d1 - d1 \cdot d1\right)}\right) \]
                                    12. lower-neg.f64N/A

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(\color{blue}{-d1}, d3, d4 \cdot d1 - d1 \cdot d1\right)\right) \]
                                    13. lift-*.f64N/A

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d4 \cdot d1} - d1 \cdot d1\right)\right) \]
                                    14. lift-*.f64N/A

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d4 \cdot d1 - \color{blue}{d1 \cdot d1}\right)\right) \]
                                    15. distribute-rgt-out--N/A

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                                    16. lower-*.f64N/A

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, \color{blue}{d1 \cdot \left(d4 - d1\right)}\right)\right) \]
                                    17. lower--.f6496.9

                                      \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \color{blue}{\left(d4 - d1\right)}\right)\right) \]
                                  4. Applied rewrites96.9%

                                    \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \left(d4 - d1\right)\right)\right)} \]
                                  5. Taylor expanded in d2 around inf

                                    \[\leadsto \color{blue}{d1 \cdot d2} \]
                                  6. Step-by-step derivation
                                    1. *-commutativeN/A

                                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                                    2. lower-*.f6431.6

                                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                                  7. Applied rewrites31.6%

                                    \[\leadsto \color{blue}{d2 \cdot d1} \]
                                  8. Final simplification31.6%

                                    \[\leadsto d2 \cdot d1 \]
                                  9. Add Preprocessing

                                  Developer Target 1: 100.0% accurate, 2.0× speedup?

                                  \[\begin{array}{l} \\ d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \end{array} \]
                                  (FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
                                  double code(double d1, double d2, double d3, double d4) {
                                  	return d1 * (((d2 - d3) + d4) - d1);
                                  }
                                  
                                  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(d1, d2, d3, d4)
                                  use fmin_fmax_functions
                                      real(8), intent (in) :: d1
                                      real(8), intent (in) :: d2
                                      real(8), intent (in) :: d3
                                      real(8), intent (in) :: d4
                                      code = d1 * (((d2 - d3) + d4) - d1)
                                  end function
                                  
                                  public static double code(double d1, double d2, double d3, double d4) {
                                  	return d1 * (((d2 - d3) + d4) - d1);
                                  }
                                  
                                  def code(d1, d2, d3, d4):
                                  	return d1 * (((d2 - d3) + d4) - d1)
                                  
                                  function code(d1, d2, d3, d4)
                                  	return Float64(d1 * Float64(Float64(Float64(d2 - d3) + d4) - d1))
                                  end
                                  
                                  function tmp = code(d1, d2, d3, d4)
                                  	tmp = d1 * (((d2 - d3) + d4) - d1);
                                  end
                                  
                                  code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)
                                  \end{array}
                                  

                                  Reproduce

                                  ?
                                  herbie shell --seed 2025015 
                                  (FPCore (d1 d2 d3 d4)
                                    :name "FastMath dist4"
                                    :precision binary64
                                  
                                    :alt
                                    (! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))
                                  
                                    (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))