FastMath dist4

Percentage Accurate: 87.7% → 98.3%
Time: 6.9s
Alternatives: 13
Speedup: 1.3×

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 13 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.7% 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: 98.3% accurate, 1.2× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 2 \cdot 10^{-194}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\ \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 2e-194)
   (* (- (- d2 d3) d1) d1)
   (fma (- d2 d3) d1 (* d1 (- d4 d1)))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 2e-194) {
		tmp = ((d2 - d3) - d1) * d1;
	} else {
		tmp = fma((d2 - d3), d1, (d1 * (d4 - d1)));
	}
	return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 2e-194)
		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
	else
		tmp = fma(Float64(d2 - d3), d1, Float64(d1 * Float64(d4 - d1)));
	end
	return 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, 2e-194], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], 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])\\
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2 \cdot 10^{-194}:\\
\;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 2.00000000000000004e-194

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

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

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

    if 2.00000000000000004e-194 < d4

    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. 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--.f6499.1

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

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

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

Alternative 2: 92.3% accurate, 1.2× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -7.5 \cdot 10^{+138} \lor \neg \left(d3 \leq 5 \cdot 10^{+110}\right):\\ \;\;\;\;\left(\left(d2 - d3\right) + d4\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 -7.5e+138) (not (<= d3 5e+110)))
   (* (+ (- d2 d3) d4) 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 <= -7.5e+138) || !(d3 <= 5e+110)) {
		tmp = ((d2 - d3) + d4) * 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 <= (-7.5d+138)) .or. (.not. (d3 <= 5d+110))) then
        tmp = ((d2 - d3) + d4) * 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 <= -7.5e+138) || !(d3 <= 5e+110)) {
		tmp = ((d2 - d3) + d4) * 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 <= -7.5e+138) or not (d3 <= 5e+110):
		tmp = ((d2 - d3) + d4) * 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 <= -7.5e+138) || !(d3 <= 5e+110))
		tmp = Float64(Float64(Float64(d2 - d3) + d4) * 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 <= -7.5e+138) || ~((d3 <= 5e+110)))
		tmp = ((d2 - d3) + d4) * 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, -7.5e+138], N[Not[LessEqual[d3, 5e+110]], $MachinePrecision]], N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $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 -7.5 \cdot 10^{+138} \lor \neg \left(d3 \leq 5 \cdot 10^{+110}\right):\\
\;\;\;\;\left(\left(d2 - d3\right) + d4\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 < -7.4999999999999999e138 or 4.99999999999999978e110 < d3

    1. Initial program 82.1%

      \[\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-+.f6493.6

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

      \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
    6. Step-by-step derivation
      1. Applied rewrites93.6%

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

      if -7.4999999999999999e138 < d3 < 4.99999999999999978e110

      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 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-+.f6496.6

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

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

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

    Alternative 3: 90.8% accurate, 1.2× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d1 \leq -2.9 \cdot 10^{+153}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq 2.05 \cdot 10^{+102}:\\ \;\;\;\;\left(\left(d2 - d3\right) + 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 (<= d1 -2.9e+153)
       (* (- d2 d1) d1)
       (if (<= d1 2.05e+102) (* (+ (- d2 d3) 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 (d1 <= -2.9e+153) {
    		tmp = (d2 - d1) * d1;
    	} else if (d1 <= 2.05e+102) {
    		tmp = ((d2 - d3) + 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 (d1 <= (-2.9d+153)) then
            tmp = (d2 - d1) * d1
        else if (d1 <= 2.05d+102) then
            tmp = ((d2 - d3) + 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 (d1 <= -2.9e+153) {
    		tmp = (d2 - d1) * d1;
    	} else if (d1 <= 2.05e+102) {
    		tmp = ((d2 - d3) + 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 d1 <= -2.9e+153:
    		tmp = (d2 - d1) * d1
    	elif d1 <= 2.05e+102:
    		tmp = ((d2 - d3) + 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 (d1 <= -2.9e+153)
    		tmp = Float64(Float64(d2 - d1) * d1);
    	elseif (d1 <= 2.05e+102)
    		tmp = Float64(Float64(Float64(d2 - d3) + 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 (d1 <= -2.9e+153)
    		tmp = (d2 - d1) * d1;
    	elseif (d1 <= 2.05e+102)
    		tmp = ((d2 - d3) + 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[d1, -2.9e+153], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 2.05e+102], N[(N[(N[(d2 - d3), $MachinePrecision] + 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}\;d1 \leq -2.9 \cdot 10^{+153}:\\
    \;\;\;\;\left(d2 - d1\right) \cdot d1\\
    
    \mathbf{elif}\;d1 \leq 2.05 \cdot 10^{+102}:\\
    \;\;\;\;\left(\left(d2 - d3\right) + d4\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(d4 - d1\right) \cdot d1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d1 < -2.90000000000000002e153

      1. Initial program 46.7%

        \[\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-+.f64100.0

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

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

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

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

        if -2.90000000000000002e153 < d1 < 2.05e102

        1. Initial program 100.0%

          \[\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-+.f6491.7

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

          \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
        6. Step-by-step derivation
          1. Applied rewrites91.7%

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

          if 2.05e102 < d1

          1. Initial program 61.7%

            \[\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-+.f6495.7

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

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

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

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

          Alternative 4: 93.9% accurate, 1.3× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 6 \cdot 10^{+24}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\ \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 6e+24) (* (- (- d2 d3) d1) d1) (fma (- d3) d1 (* d1 (- d4 d1)))))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d4 <= 6e+24) {
          		tmp = ((d2 - d3) - d1) * d1;
          	} else {
          		tmp = fma(-d3, d1, (d1 * (d4 - d1)));
          	}
          	return tmp;
          }
          
          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d4 <= 6e+24)
          		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
          	else
          		tmp = fma(Float64(-d3), d1, Float64(d1 * Float64(d4 - d1)));
          	end
          	return 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, 6e+24], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[((-d3) * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;d4 \leq 6 \cdot 10^{+24}:\\
          \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(-d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d4 < 5.9999999999999999e24

            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. 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.1

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

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

            if 5.9999999999999999e24 < d4

            1. Initial program 88.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(\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--.f64100.0

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

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

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

                \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(d3\right)}, d1, d1 \cdot \left(d4 - d1\right)\right) \]
              2. lower-neg.f6492.0

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

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

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

          Alternative 5: 70.5% accurate, 1.4× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.45 \cdot 10^{+169} \lor \neg \left(d3 \leq 5.1 \cdot 10^{+38}\right):\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 + d2\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 -1.45e+169) (not (<= d3 5.1e+38)))
             (* (- d2 d3) d1)
             (* (+ d4 d2) d1)))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if ((d3 <= -1.45e+169) || !(d3 <= 5.1e+38)) {
          		tmp = (d2 - d3) * d1;
          	} else {
          		tmp = (d4 + d2) * 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 <= (-1.45d+169)) .or. (.not. (d3 <= 5.1d+38))) then
                  tmp = (d2 - d3) * d1
              else
                  tmp = (d4 + d2) * 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 <= -1.45e+169) || !(d3 <= 5.1e+38)) {
          		tmp = (d2 - d3) * d1;
          	} else {
          		tmp = (d4 + d2) * d1;
          	}
          	return tmp;
          }
          
          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if (d3 <= -1.45e+169) or not (d3 <= 5.1e+38):
          		tmp = (d2 - d3) * d1
          	else:
          		tmp = (d4 + d2) * d1
          	return tmp
          
          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if ((d3 <= -1.45e+169) || !(d3 <= 5.1e+38))
          		tmp = Float64(Float64(d2 - d3) * d1);
          	else
          		tmp = Float64(Float64(d4 + d2) * 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 <= -1.45e+169) || ~((d3 <= 5.1e+38)))
          		tmp = (d2 - d3) * d1;
          	else
          		tmp = (d4 + d2) * 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, -1.45e+169], N[Not[LessEqual[d3, 5.1e+38]], $MachinePrecision]], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision]]
          
          \begin{array}{l}
          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;d3 \leq -1.45 \cdot 10^{+169} \lor \neg \left(d3 \leq 5.1 \cdot 10^{+38}\right):\\
          \;\;\;\;\left(d2 - d3\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(d4 + d2\right) \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d3 < -1.45e169 or 5.1000000000000001e38 < d3

            1. Initial program 81.9%

              \[\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-+.f6489.4

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

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

              \[\leadsto d1 \cdot \color{blue}{\left(d2 - d3\right)} \]
            7. Step-by-step derivation
              1. Applied rewrites76.7%

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

              if -1.45e169 < d3 < 5.1000000000000001e38

              1. Initial program 89.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-+.f6496.4

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

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

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

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

              Alternative 6: 54.2% accurate, 1.5× speedup?

              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.2 \cdot 10^{+51}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -4 \cdot 10^{-309}:\\ \;\;\;\;\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 -1.2e+51) (* d1 d2) (if (<= d2 -4e-309) (* (- 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 <= -1.2e+51) {
              		tmp = d1 * d2;
              	} else if (d2 <= -4e-309) {
              		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 <= (-1.2d+51)) then
                      tmp = d1 * d2
                  else if (d2 <= (-4d-309)) 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 <= -1.2e+51) {
              		tmp = d1 * d2;
              	} else if (d2 <= -4e-309) {
              		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 <= -1.2e+51:
              		tmp = d1 * d2
              	elif d2 <= -4e-309:
              		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 <= -1.2e+51)
              		tmp = Float64(d1 * d2);
              	elseif (d2 <= -4e-309)
              		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 <= -1.2e+51)
              		tmp = d1 * d2;
              	elseif (d2 <= -4e-309)
              		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, -1.2e+51], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -4e-309], 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 -1.2 \cdot 10^{+51}:\\
              \;\;\;\;d1 \cdot d2\\
              
              \mathbf{elif}\;d2 \leq -4 \cdot 10^{-309}:\\
              \;\;\;\;\left(-d1\right) \cdot d1\\
              
              \mathbf{else}:\\
              \;\;\;\;d4 \cdot d1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if d2 < -1.1999999999999999e51

                1. Initial program 78.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(\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--.f6492.7

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

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

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

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

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

                if -1.1999999999999999e51 < d2 < -3.9999999999999977e-309

                1. Initial program 89.3%

                  \[\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.f6439.9

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

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

                if -3.9999999999999977e-309 < 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-*.f6437.6

                    \[\leadsto \color{blue}{d4 \cdot d1} \]
                5. Applied rewrites37.6%

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

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

              Alternative 7: 54.4% accurate, 1.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^{+68}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -4.8 \cdot 10^{-250}:\\ \;\;\;\;\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 -2.1e+68)
                 (* d1 d2)
                 (if (<= d2 -4.8e-250) (* (- 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 <= -2.1e+68) {
              		tmp = d1 * d2;
              	} else if (d2 <= -4.8e-250) {
              		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 <= (-2.1d+68)) then
                      tmp = d1 * d2
                  else if (d2 <= (-4.8d-250)) 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 <= -2.1e+68) {
              		tmp = d1 * d2;
              	} else if (d2 <= -4.8e-250) {
              		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 <= -2.1e+68:
              		tmp = d1 * d2
              	elif d2 <= -4.8e-250:
              		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 <= -2.1e+68)
              		tmp = Float64(d1 * d2);
              	elseif (d2 <= -4.8e-250)
              		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 <= -2.1e+68)
              		tmp = d1 * d2;
              	elseif (d2 <= -4.8e-250)
              		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, -2.1e+68], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -4.8e-250], 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 -2.1 \cdot 10^{+68}:\\
              \;\;\;\;d1 \cdot d2\\
              
              \mathbf{elif}\;d2 \leq -4.8 \cdot 10^{-250}:\\
              \;\;\;\;\left(-d3\right) \cdot d1\\
              
              \mathbf{else}:\\
              \;\;\;\;d4 \cdot d1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 3 regimes
              2. if d2 < -2.10000000000000001e68

                1. Initial program 76.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--.f6492.1

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

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

                  \[\leadsto \color{blue}{d1 \cdot d2} \]
                6. Step-by-step derivation
                  1. lower-*.f6473.9

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

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

                if -2.10000000000000001e68 < d2 < -4.7999999999999998e-250

                1. Initial program 90.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--.f6498.6

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

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

                  \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
                6. 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.f6434.3

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

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

                if -4.7999999999999998e-250 < 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-*.f6436.8

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

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

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

              Alternative 8: 72.8% accurate, 2.0× speedup?

              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 660000:\\ \;\;\;\;\left(d2 - 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 (<= d4 660000.0) (* (- 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 (d4 <= 660000.0) {
              		tmp = (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 (d4 <= 660000.0d0) then
                      tmp = (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 (d4 <= 660000.0) {
              		tmp = (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 d4 <= 660000.0:
              		tmp = (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 (d4 <= 660000.0)
              		tmp = Float64(Float64(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 (d4 <= 660000.0)
              		tmp = (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[d4, 660000.0], N[(N[(d2 - 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}\;d4 \leq 660000:\\
              \;\;\;\;\left(d2 - d1\right) \cdot d1\\
              
              \mathbf{else}:\\
              \;\;\;\;\left(d4 - d3\right) \cdot d1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if d4 < 6.6e5

                1. Initial program 85.8%

                  \[\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-+.f6478.6

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

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

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

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

                  if 6.6e5 < d4

                  1. Initial program 89.0%

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

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

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

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

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

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

                  Alternative 9: 71.6% accurate, 2.0× speedup?

                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.3 \cdot 10^{+27}:\\ \;\;\;\;\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 (<= d4 1.3e+27) (* (- 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 (d4 <= 1.3e+27) {
                  		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 (d4 <= 1.3d+27) 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 (d4 <= 1.3e+27) {
                  		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 d4 <= 1.3e+27:
                  		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 (d4 <= 1.3e+27)
                  		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 (d4 <= 1.3e+27)
                  		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[d4, 1.3e+27], 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}\;d4 \leq 1.3 \cdot 10^{+27}:\\
                  \;\;\;\;\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 d4 < 1.30000000000000004e27

                    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. 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-+.f6479.2

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

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

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

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

                      if 1.30000000000000004e27 < d4

                      1. Initial program 88.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-+.f6486.1

                          \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                      5. Applied rewrites86.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 rewrites78.1%

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

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

                      Alternative 10: 70.7% accurate, 2.0× speedup?

                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 5 \cdot 10^{+89}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 + d2\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 5e+89) (* (- d2 d1) d1) (* (+ d4 d2) d1)))
                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                      double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d4 <= 5e+89) {
                      		tmp = (d2 - d1) * d1;
                      	} else {
                      		tmp = (d4 + d2) * 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 <= 5d+89) then
                              tmp = (d2 - d1) * d1
                          else
                              tmp = (d4 + d2) * 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 <= 5e+89) {
                      		tmp = (d2 - d1) * d1;
                      	} else {
                      		tmp = (d4 + d2) * d1;
                      	}
                      	return tmp;
                      }
                      
                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                      def code(d1, d2, d3, d4):
                      	tmp = 0
                      	if d4 <= 5e+89:
                      		tmp = (d2 - d1) * d1
                      	else:
                      		tmp = (d4 + d2) * d1
                      	return tmp
                      
                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                      function code(d1, d2, d3, d4)
                      	tmp = 0.0
                      	if (d4 <= 5e+89)
                      		tmp = Float64(Float64(d2 - d1) * d1);
                      	else
                      		tmp = Float64(Float64(d4 + d2) * 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 <= 5e+89)
                      		tmp = (d2 - d1) * d1;
                      	else
                      		tmp = (d4 + d2) * 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, 5e+89], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision]]
                      
                      \begin{array}{l}
                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;d4 \leq 5 \cdot 10^{+89}:\\
                      \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\left(d4 + d2\right) \cdot d1\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if d4 < 4.99999999999999983e89

                        1. Initial program 86.7%

                          \[\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-+.f6479.3

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

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

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

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

                          if 4.99999999999999983e89 < d4

                          1. Initial program 86.7%

                            \[\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.5

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

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

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

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

                          Alternative 11: 70.2% accurate, 2.0× speedup?

                          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.4 \cdot 10^{+119}:\\ \;\;\;\;\left(d2 - 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 (<= d4 1.4e+119) (* (- d2 d3) d1) (* d4 d1)))
                          assert(d1 < d2 && d2 < d3 && d3 < d4);
                          double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d4 <= 1.4e+119) {
                          		tmp = (d2 - 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 (d4 <= 1.4d+119) then
                                  tmp = (d2 - 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 (d4 <= 1.4e+119) {
                          		tmp = (d2 - 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 d4 <= 1.4e+119:
                          		tmp = (d2 - 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 (d4 <= 1.4e+119)
                          		tmp = Float64(Float64(d2 - 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 (d4 <= 1.4e+119)
                          		tmp = (d2 - 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[d4, 1.4e+119], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
                          
                          \begin{array}{l}
                          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;d4 \leq 1.4 \cdot 10^{+119}:\\
                          \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;d4 \cdot d1\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if d4 < 1.40000000000000007e119

                            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 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-+.f6475.8

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

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

                              \[\leadsto d1 \cdot \color{blue}{\left(d2 - d3\right)} \]
                            7. Step-by-step derivation
                              1. Applied rewrites57.1%

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

                              if 1.40000000000000007e119 < d4

                              1. Initial program 85.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-*.f6473.3

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

                                \[\leadsto \color{blue}{d4 \cdot d1} \]
                            8. Recombined 2 regimes into one program.
                            9. Final simplification60.2%

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

                            Alternative 12: 50.8% accurate, 2.5× speedup?

                            \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.3 \cdot 10^{+27}:\\ \;\;\;\;d1 \cdot d2\\ \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 (<= d4 1.3e+27) (* d1 d2) (* d4 d1)))
                            assert(d1 < d2 && d2 < d3 && d3 < d4);
                            double code(double d1, double d2, double d3, double d4) {
                            	double tmp;
                            	if (d4 <= 1.3e+27) {
                            		tmp = d1 * d2;
                            	} 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 (d4 <= 1.3d+27) then
                                    tmp = d1 * d2
                                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 (d4 <= 1.3e+27) {
                            		tmp = d1 * d2;
                            	} else {
                            		tmp = d4 * d1;
                            	}
                            	return tmp;
                            }
                            
                            [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                            def code(d1, d2, d3, d4):
                            	tmp = 0
                            	if d4 <= 1.3e+27:
                            		tmp = d1 * d2
                            	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 (d4 <= 1.3e+27)
                            		tmp = Float64(d1 * d2);
                            	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 (d4 <= 1.3e+27)
                            		tmp = d1 * d2;
                            	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[d4, 1.3e+27], N[(d1 * d2), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
                            
                            \begin{array}{l}
                            [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                            \\
                            \begin{array}{l}
                            \mathbf{if}\;d4 \leq 1.3 \cdot 10^{+27}:\\
                            \;\;\;\;d1 \cdot d2\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;d4 \cdot d1\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 2 regimes
                            2. if d4 < 1.30000000000000004e27

                              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(\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--.f6495.2

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

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

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

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

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

                              if 1.30000000000000004e27 < d4

                              1. Initial program 88.2%

                                \[\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-*.f6461.1

                                  \[\leadsto \color{blue}{d4 \cdot d1} \]
                              5. Applied rewrites61.1%

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

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

                            Alternative 13: 31.1% accurate, 5.0× speedup?

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

                              \[\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.5

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

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

                              \[\leadsto \color{blue}{d1 \cdot d2} \]
                            6. Step-by-step derivation
                              1. lower-*.f6431.4

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

                              \[\leadsto \color{blue}{d1 \cdot d2} \]
                            8. 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 2024364 
                            (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)))