FastMath dist4

Percentage Accurate: 87.7% → 96.6%
Time: 3.5s
Alternatives: 14
Speedup: 1.2×

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}

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 14 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: 96.6% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -2.4000000000000001e229

    1. Initial program 66.7%

      \[\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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. lower-+.f64100.0

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

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

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

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

      if -2.4000000000000001e229 < d2

      1. Initial program 87.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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(-1 \cdot d1\right) \cdot d3}\right) - {d1}^{2} \]
        17. mul-1-negN/A

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

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

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

          \[\leadsto \color{blue}{d1 \cdot d2 + \left(d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)\right)} \]
      4. Applied rewrites94.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(d1, d4 - d3, \left(-d1\right) \cdot d1\right)\right)} \]
    8. Recombined 2 regimes into one program.
    9. Add Preprocessing

    Alternative 2: 86.0% accurate, 0.5× speedup?

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

      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 d2 around inf

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

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

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

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

      if -1.00000000000000001e160 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

      1. Initial program 80.7%

        \[\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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6489.1

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites89.1%

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        3. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right) \]
        14. lift-*.f6488.6

          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right) \]
      7. Applied rewrites88.6%

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

    Alternative 3: 86.4% accurate, 0.6× speedup?

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

      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 d4 around 0

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

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

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

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

          \[\leadsto \left(d2 - d3\right) \cdot d1 - d1 \cdot d1 \]
      5. Applied rewrites88.3%

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

      if -4.00000000000000007e141 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

      1. Initial program 80.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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6489.4

          \[\leadsto \left(\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. Step-by-step derivation
        1. lift-*.f64N/A

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        3. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right) \]
        14. lift-*.f6488.8

          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right) \]
      7. Applied rewrites88.8%

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

    Alternative 4: 66.1% accurate, 0.9× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(-d3\right) \cdot d1\\ t_1 := \left(d4 + d2\right) \cdot d1\\ \mathbf{if}\;d3 \leq -1.9 \cdot 10^{+147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 1.15 \cdot 10^{-25}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq 4.7 \cdot 10^{+64}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+176}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
     (let* ((t_0 (* (- d3) d1)) (t_1 (* (+ d4 d2) d1)))
       (if (<= d3 -1.9e+147)
         t_0
         (if (<= d3 1.15e-25)
           t_1
           (if (<= d3 4.7e+64) (* (- d1) d1) (if (<= d3 9.2e+176) t_1 t_0))))))
    assert(d1 < d2 && d2 < d3 && d3 < d4);
    double code(double d1, double d2, double d3, double d4) {
    	double t_0 = -d3 * d1;
    	double t_1 = (d4 + d2) * d1;
    	double tmp;
    	if (d3 <= -1.9e+147) {
    		tmp = t_0;
    	} else if (d3 <= 1.15e-25) {
    		tmp = t_1;
    	} else if (d3 <= 4.7e+64) {
    		tmp = -d1 * d1;
    	} else if (d3 <= 9.2e+176) {
    		tmp = t_1;
    	} else {
    		tmp = t_0;
    	}
    	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) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = -d3 * d1
        t_1 = (d4 + d2) * d1
        if (d3 <= (-1.9d+147)) then
            tmp = t_0
        else if (d3 <= 1.15d-25) then
            tmp = t_1
        else if (d3 <= 4.7d+64) then
            tmp = -d1 * d1
        else if (d3 <= 9.2d+176) then
            tmp = t_1
        else
            tmp = t_0
        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 t_0 = -d3 * d1;
    	double t_1 = (d4 + d2) * d1;
    	double tmp;
    	if (d3 <= -1.9e+147) {
    		tmp = t_0;
    	} else if (d3 <= 1.15e-25) {
    		tmp = t_1;
    	} else if (d3 <= 4.7e+64) {
    		tmp = -d1 * d1;
    	} else if (d3 <= 9.2e+176) {
    		tmp = t_1;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
    def code(d1, d2, d3, d4):
    	t_0 = -d3 * d1
    	t_1 = (d4 + d2) * d1
    	tmp = 0
    	if d3 <= -1.9e+147:
    		tmp = t_0
    	elif d3 <= 1.15e-25:
    		tmp = t_1
    	elif d3 <= 4.7e+64:
    		tmp = -d1 * d1
    	elif d3 <= 9.2e+176:
    		tmp = t_1
    	else:
    		tmp = t_0
    	return tmp
    
    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
    function code(d1, d2, d3, d4)
    	t_0 = Float64(Float64(-d3) * d1)
    	t_1 = Float64(Float64(d4 + d2) * d1)
    	tmp = 0.0
    	if (d3 <= -1.9e+147)
    		tmp = t_0;
    	elseif (d3 <= 1.15e-25)
    		tmp = t_1;
    	elseif (d3 <= 4.7e+64)
    		tmp = Float64(Float64(-d1) * d1);
    	elseif (d3 <= 9.2e+176)
    		tmp = t_1;
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
    function tmp_2 = code(d1, d2, d3, d4)
    	t_0 = -d3 * d1;
    	t_1 = (d4 + d2) * d1;
    	tmp = 0.0;
    	if (d3 <= -1.9e+147)
    		tmp = t_0;
    	elseif (d3 <= 1.15e-25)
    		tmp = t_1;
    	elseif (d3 <= 4.7e+64)
    		tmp = -d1 * d1;
    	elseif (d3 <= 9.2e+176)
    		tmp = t_1;
    	else
    		tmp = t_0;
    	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_] := Block[{t$95$0 = N[((-d3) * d1), $MachinePrecision]}, Block[{t$95$1 = N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -1.9e+147], t$95$0, If[LessEqual[d3, 1.15e-25], t$95$1, If[LessEqual[d3, 4.7e+64], N[((-d1) * d1), $MachinePrecision], If[LessEqual[d3, 9.2e+176], t$95$1, t$95$0]]]]]]
    
    \begin{array}{l}
    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
    \\
    \begin{array}{l}
    t_0 := \left(-d3\right) \cdot d1\\
    t_1 := \left(d4 + d2\right) \cdot d1\\
    \mathbf{if}\;d3 \leq -1.9 \cdot 10^{+147}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;d3 \leq 1.15 \cdot 10^{-25}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;d3 \leq 4.7 \cdot 10^{+64}:\\
    \;\;\;\;\left(-d1\right) \cdot d1\\
    
    \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+176}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d3 < -1.89999999999999985e147 or 9.19999999999999984e176 < d3

      1. Initial program 81.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 inf

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

          \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
        2. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(d3 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d3\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d3\right)\right) \cdot d1 \]
        7. lower-neg.f6483.6

          \[\leadsto \left(-d3\right) \cdot d1 \]
      5. Applied rewrites83.6%

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

      if -1.89999999999999985e147 < d3 < 1.15e-25 or 4.70000000000000029e64 < d3 < 9.19999999999999984e176

      1. Initial program 87.8%

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

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

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

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6481.4

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites81.4%

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

        \[\leadsto \left(d2 + d4\right) \cdot d1 \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(d4 + d2\right) \cdot d1 \]
        2. lift-+.f6474.3

          \[\leadsto \left(d4 + d2\right) \cdot d1 \]
      8. Applied rewrites74.3%

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

      if 1.15e-25 < d3 < 4.70000000000000029e64

      1. Initial program 87.5%

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

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

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6470.5

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites70.5%

        \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 5: 86.6% accurate, 1.1× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+239}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d2, d1, t\_0\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
     (let* ((t_0 (* (- d1) d1)))
       (if (<= d1 -5.1e+239)
         t_0
         (if (<= d1 6.8e+115) (fma (- d2 d3) d1 (* d4 d1)) (fma d2 d1 t_0)))))
    assert(d1 < d2 && d2 < d3 && d3 < d4);
    double code(double d1, double d2, double d3, double d4) {
    	double t_0 = -d1 * d1;
    	double tmp;
    	if (d1 <= -5.1e+239) {
    		tmp = t_0;
    	} else if (d1 <= 6.8e+115) {
    		tmp = fma((d2 - d3), d1, (d4 * d1));
    	} else {
    		tmp = fma(d2, d1, t_0);
    	}
    	return tmp;
    }
    
    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
    function code(d1, d2, d3, d4)
    	t_0 = Float64(Float64(-d1) * d1)
    	tmp = 0.0
    	if (d1 <= -5.1e+239)
    		tmp = t_0;
    	elseif (d1 <= 6.8e+115)
    		tmp = fma(Float64(d2 - d3), d1, Float64(d4 * d1));
    	else
    		tmp = fma(d2, d1, t_0);
    	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_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d1, -5.1e+239], t$95$0, If[LessEqual[d1, 6.8e+115], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d4 * d1), $MachinePrecision]), $MachinePrecision], N[(d2 * d1 + t$95$0), $MachinePrecision]]]]
    
    \begin{array}{l}
    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
    \\
    \begin{array}{l}
    t_0 := \left(-d1\right) \cdot d1\\
    \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+239}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;d1 \leq 6.8 \cdot 10^{+115}:\\
    \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(d2, d1, t\_0\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d1 < -5.0999999999999998e239

      1. Initial program 47.6%

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

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

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6481.0

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites81.0%

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

      if -5.0999999999999998e239 < d1 < 6.8000000000000001e115

      1. Initial program 93.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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6491.2

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites91.2%

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        3. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right) \]
        14. lift-*.f6490.7

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

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

      if 6.8000000000000001e115 < d1

      1. Initial program 68.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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(-1 \cdot d1\right) \cdot d3}\right) - {d1}^{2} \]
        17. mul-1-negN/A

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

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

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

          \[\leadsto \color{blue}{d1 \cdot d2 + \left(d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)\right)} \]
      4. Applied rewrites86.8%

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

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

          \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{neg}\left({d1}^{2}\right)\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{neg}\left(d1 \cdot d1\right)\right) \]
        3. distribute-lft-neg-outN/A

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

          \[\leadsto \mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1}\right) \]
        5. lift-neg.f6476.7

          \[\leadsto \mathsf{fma}\left(d2, d1, \left(-d1\right) \cdot d1\right) \]
      7. Applied rewrites76.7%

        \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\left(-d1\right) \cdot d1}\right) \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 6: 53.4% accurate, 1.2× speedup?

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

      1. Initial program 85.0%

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

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

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

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

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

      if -5.5999999999999999e-266 < d4 < 4.0000000000000002e-33

      1. Initial program 92.6%

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

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

          \[\leadsto \mathsf{neg}\left(d1 \cdot d3\right) \]
        2. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(d3 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d3\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d3\right)\right) \cdot d1 \]
        7. lower-neg.f6447.1

          \[\leadsto \left(-d3\right) \cdot d1 \]
      5. Applied rewrites47.1%

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

      if 4.0000000000000002e-33 < d4 < 3.00000000000000011e45

      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 d1 around inf

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

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6458.4

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites58.4%

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

      if 3.00000000000000011e45 < d4

      1. Initial program 81.5%

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

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

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

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

        \[\leadsto \color{blue}{d4 \cdot d1} \]
    3. Recombined 4 regimes into one program.
    4. Add Preprocessing

    Alternative 7: 87.8% accurate, 1.2× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+188}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d2, d1, t\_0\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
     (let* ((t_0 (* (- d1) d1)))
       (if (<= d1 -5.1e+188)
         t_0
         (if (<= d1 6.8e+115) (* (- (+ d4 d2) d3) d1) (fma d2 d1 t_0)))))
    assert(d1 < d2 && d2 < d3 && d3 < d4);
    double code(double d1, double d2, double d3, double d4) {
    	double t_0 = -d1 * d1;
    	double tmp;
    	if (d1 <= -5.1e+188) {
    		tmp = t_0;
    	} else if (d1 <= 6.8e+115) {
    		tmp = ((d4 + d2) - d3) * d1;
    	} else {
    		tmp = fma(d2, d1, t_0);
    	}
    	return tmp;
    }
    
    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
    function code(d1, d2, d3, d4)
    	t_0 = Float64(Float64(-d1) * d1)
    	tmp = 0.0
    	if (d1 <= -5.1e+188)
    		tmp = t_0;
    	elseif (d1 <= 6.8e+115)
    		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
    	else
    		tmp = fma(d2, d1, t_0);
    	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_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d1, -5.1e+188], t$95$0, If[LessEqual[d1, 6.8e+115], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(d2 * d1 + t$95$0), $MachinePrecision]]]]
    
    \begin{array}{l}
    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
    \\
    \begin{array}{l}
    t_0 := \left(-d1\right) \cdot d1\\
    \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+188}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;d1 \leq 6.8 \cdot 10^{+115}:\\
    \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(d2, d1, t\_0\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d1 < -5.1000000000000002e188

      1. Initial program 53.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. mul-1-negN/A

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6480.0

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites80.0%

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

      if -5.1000000000000002e188 < d1 < 6.8000000000000001e115

      1. Initial program 95.2%

        \[\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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6492.3

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites92.3%

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

      if 6.8000000000000001e115 < d1

      1. Initial program 68.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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left(\left(d1 \cdot d2 + d1 \cdot d4\right) + \color{blue}{\left(-1 \cdot d1\right) \cdot d3}\right) - {d1}^{2} \]
        17. mul-1-negN/A

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

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

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

          \[\leadsto \color{blue}{d1 \cdot d2 + \left(d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)\right)} \]
      4. Applied rewrites86.8%

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

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

          \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{neg}\left({d1}^{2}\right)\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{fma}\left(d2, d1, \mathsf{neg}\left(d1 \cdot d1\right)\right) \]
        3. distribute-lft-neg-outN/A

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

          \[\leadsto \mathsf{fma}\left(d2, d1, \left(\mathsf{neg}\left(d1\right)\right) \cdot \color{blue}{d1}\right) \]
        5. lift-neg.f6476.7

          \[\leadsto \mathsf{fma}\left(d2, d1, \left(-d1\right) \cdot d1\right) \]
      7. Applied rewrites76.7%

        \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\left(-d1\right) \cdot d1}\right) \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 8: 87.4% accurate, 1.2× speedup?

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

      1. Initial program 53.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. mul-1-negN/A

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6480.0

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites80.0%

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

      if -5.1000000000000002e188 < d1 < 6.8000000000000001e115

      1. Initial program 95.2%

        \[\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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6492.3

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites92.3%

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

      if 6.8000000000000001e115 < d1

      1. Initial program 68.4%

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

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

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

          \[\leadsto d2 \cdot \color{blue}{d1} - d1 \cdot d1 \]
      5. Applied rewrites74.1%

        \[\leadsto \color{blue}{d2 \cdot d1} - d1 \cdot d1 \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 9: 87.5% accurate, 1.2× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+188} \lor \neg \left(d1 \leq 6 \cdot 10^{+166}\right):\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
    (FPCore (d1 d2 d3 d4)
     :precision binary64
     (if (or (<= d1 -5.1e+188) (not (<= d1 6e+166)))
       (* (- d1) d1)
       (* (- (+ d4 d2) d3) d1)))
    assert(d1 < d2 && d2 < d3 && d3 < d4);
    double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if ((d1 <= -5.1e+188) || !(d1 <= 6e+166)) {
    		tmp = -d1 * d1;
    	} else {
    		tmp = ((d4 + d2) - d3) * d1;
    	}
    	return tmp;
    }
    
    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(d1, d2, d3, d4)
    use fmin_fmax_functions
        real(8), intent (in) :: d1
        real(8), intent (in) :: d2
        real(8), intent (in) :: d3
        real(8), intent (in) :: d4
        real(8) :: tmp
        if ((d1 <= (-5.1d+188)) .or. (.not. (d1 <= 6d+166))) then
            tmp = -d1 * d1
        else
            tmp = ((d4 + d2) - d3) * d1
        end if
        code = tmp
    end function
    
    assert d1 < d2 && d2 < d3 && d3 < d4;
    public static double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if ((d1 <= -5.1e+188) || !(d1 <= 6e+166)) {
    		tmp = -d1 * d1;
    	} else {
    		tmp = ((d4 + d2) - d3) * d1;
    	}
    	return tmp;
    }
    
    [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
    def code(d1, d2, d3, d4):
    	tmp = 0
    	if (d1 <= -5.1e+188) or not (d1 <= 6e+166):
    		tmp = -d1 * d1
    	else:
    		tmp = ((d4 + d2) - d3) * d1
    	return tmp
    
    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
    function code(d1, d2, d3, d4)
    	tmp = 0.0
    	if ((d1 <= -5.1e+188) || !(d1 <= 6e+166))
    		tmp = Float64(Float64(-d1) * d1);
    	else
    		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
    	end
    	return tmp
    end
    
    d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
    function tmp_2 = code(d1, d2, d3, d4)
    	tmp = 0.0;
    	if ((d1 <= -5.1e+188) || ~((d1 <= 6e+166)))
    		tmp = -d1 * d1;
    	else
    		tmp = ((d4 + d2) - d3) * d1;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
    code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -5.1e+188], N[Not[LessEqual[d1, 6e+166]], $MachinePrecision]], N[((-d1) * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
    
    \begin{array}{l}
    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;d1 \leq -5.1 \cdot 10^{+188} \lor \neg \left(d1 \leq 6 \cdot 10^{+166}\right):\\
    \;\;\;\;\left(-d1\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if d1 < -5.1000000000000002e188 or 5.99999999999999997e166 < d1

      1. Initial program 57.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 inf

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

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6483.9

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites83.9%

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

      if -5.1000000000000002e188 < d1 < 5.99999999999999997e166

      1. Initial program 94.5%

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

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

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

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6490.3

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites90.3%

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

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

    Alternative 10: 53.1% accurate, 1.5× speedup?

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

      1. Initial program 82.9%

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

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

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

          \[\leadsto d2 \cdot \color{blue}{d1} \]
      5. Applied rewrites38.0%

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

      if -2.5e-188 < d4 < 3.00000000000000011e45

      1. Initial program 92.8%

        \[\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. mul-1-negN/A

          \[\leadsto \mathsf{neg}\left({d1}^{2}\right) \]
        2. pow2N/A

          \[\leadsto \mathsf{neg}\left(d1 \cdot d1\right) \]
        3. distribute-lft-neg-inN/A

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

          \[\leadsto \left(-1 \cdot d1\right) \cdot d1 \]
        5. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(d1\right)\right) \cdot d1 \]
        7. lower-neg.f6444.7

          \[\leadsto \left(-d1\right) \cdot d1 \]
      5. Applied rewrites44.7%

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

      if 3.00000000000000011e45 < d4

      1. Initial program 81.5%

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

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

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

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

        \[\leadsto \color{blue}{d4 \cdot d1} \]
    3. Recombined 3 regimes into one program.
    4. Add Preprocessing

    Alternative 11: 74.7% accurate, 2.0× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -3.8 \cdot 10^{-9}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
    (FPCore (d1 d2 d3 d4)
     :precision binary64
     (if (<= d2 -3.8e-9) (* (- d2 d3) d1) (* (- d4 d3) d1)))
    assert(d1 < d2 && d2 < d3 && d3 < d4);
    double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d2 <= -3.8e-9) {
    		tmp = (d2 - d3) * d1;
    	} else {
    		tmp = (d4 - d3) * d1;
    	}
    	return tmp;
    }
    
    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(d1, d2, d3, d4)
    use fmin_fmax_functions
        real(8), intent (in) :: d1
        real(8), intent (in) :: d2
        real(8), intent (in) :: d3
        real(8), intent (in) :: d4
        real(8) :: tmp
        if (d2 <= (-3.8d-9)) then
            tmp = (d2 - d3) * d1
        else
            tmp = (d4 - d3) * d1
        end if
        code = tmp
    end function
    
    assert d1 < d2 && d2 < d3 && d3 < d4;
    public static double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d2 <= -3.8e-9) {
    		tmp = (d2 - d3) * d1;
    	} else {
    		tmp = (d4 - d3) * d1;
    	}
    	return tmp;
    }
    
    [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
    def code(d1, d2, d3, d4):
    	tmp = 0
    	if d2 <= -3.8e-9:
    		tmp = (d2 - d3) * d1
    	else:
    		tmp = (d4 - d3) * d1
    	return tmp
    
    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
    function code(d1, d2, d3, d4)
    	tmp = 0.0
    	if (d2 <= -3.8e-9)
    		tmp = Float64(Float64(d2 - d3) * d1);
    	else
    		tmp = Float64(Float64(d4 - d3) * d1);
    	end
    	return tmp
    end
    
    d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
    function tmp_2 = code(d1, d2, d3, d4)
    	tmp = 0.0;
    	if (d2 <= -3.8e-9)
    		tmp = (d2 - d3) * d1;
    	else
    		tmp = (d4 - d3) * d1;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
    code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.8e-9], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
    
    \begin{array}{l}
    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;d2 \leq -3.8 \cdot 10^{-9}:\\
    \;\;\;\;\left(d2 - d3\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(d4 - d3\right) \cdot d1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if d2 < -3.80000000000000011e-9

      1. Initial program 79.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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. lower-+.f6485.7

          \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
      5. Applied rewrites85.7%

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

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

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

        if -3.80000000000000011e-9 < d2

        1. Initial program 88.7%

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

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

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

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

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

            \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
          5. lower-+.f6480.8

            \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
        5. Applied rewrites80.8%

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

            \[\leadsto \left(d4 - d3\right) \cdot d1 \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 12: 72.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 3.8 \cdot 10^{+39}:\\ \;\;\;\;\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 (<= d4 3.8e+39) (* (- 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 (d4 <= 3.8e+39) {
        		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 (d4 <= 3.8d+39) 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 (d4 <= 3.8e+39) {
        		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 d4 <= 3.8e+39:
        		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 (d4 <= 3.8e+39)
        		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 (d4 <= 3.8e+39)
        		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[LessEqual[d4, 3.8e+39], 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}\;d4 \leq 3.8 \cdot 10^{+39}:\\
        \;\;\;\;\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 d4 < 3.7999999999999998e39

          1. Initial program 87.6%

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

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

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

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

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

              \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
            5. lower-+.f6481.1

              \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
          5. Applied rewrites81.1%

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

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

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

            if 3.7999999999999998e39 < d4

            1. Initial program 81.8%

              \[\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 \left(\left(d2 + d4\right) - d3\right) \cdot \color{blue}{d1} \]
              2. lower-*.f64N/A

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

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

                \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
              5. lower-+.f6485.4

                \[\leadsto \left(\left(d4 + d2\right) - d3\right) \cdot d1 \]
            5. Applied rewrites85.4%

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

              \[\leadsto \left(d2 + d4\right) \cdot d1 \]
            7. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \left(d4 + d2\right) \cdot d1 \]
              2. lift-+.f6471.0

                \[\leadsto \left(d4 + d2\right) \cdot d1 \]
            8. Applied rewrites71.0%

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

          Alternative 13: 50.7% accurate, 2.5× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 5800000000:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (if (<= d4 5800000000.0) (* d2 d1) (* d4 d1)))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d4 <= 5800000000.0) {
          		tmp = d2 * d1;
          	} else {
          		tmp = d4 * d1;
          	}
          	return tmp;
          }
          
          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(d1, d2, d3, d4)
          use fmin_fmax_functions
              real(8), intent (in) :: d1
              real(8), intent (in) :: d2
              real(8), intent (in) :: d3
              real(8), intent (in) :: d4
              real(8) :: tmp
              if (d4 <= 5800000000.0d0) then
                  tmp = d2 * d1
              else
                  tmp = d4 * d1
              end if
              code = tmp
          end function
          
          assert d1 < d2 && d2 < d3 && d3 < d4;
          public static double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d4 <= 5800000000.0) {
          		tmp = d2 * d1;
          	} else {
          		tmp = d4 * d1;
          	}
          	return tmp;
          }
          
          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if d4 <= 5800000000.0:
          		tmp = d2 * d1
          	else:
          		tmp = d4 * d1
          	return tmp
          
          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d4 <= 5800000000.0)
          		tmp = Float64(d2 * d1);
          	else
          		tmp = Float64(d4 * d1);
          	end
          	return tmp
          end
          
          d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
          function tmp_2 = code(d1, d2, d3, d4)
          	tmp = 0.0;
          	if (d4 <= 5800000000.0)
          		tmp = d2 * d1;
          	else
          		tmp = d4 * d1;
          	end
          	tmp_2 = tmp;
          end
          
          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
          code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 5800000000.0], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
          
          \begin{array}{l}
          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;d4 \leq 5800000000:\\
          \;\;\;\;d2 \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;d4 \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d4 < 5.8e9

            1. Initial program 87.4%

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

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

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

                \[\leadsto d2 \cdot \color{blue}{d1} \]
            5. Applied rewrites40.7%

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

            if 5.8e9 < d4

            1. Initial program 82.8%

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

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

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

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

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

          Alternative 14: 31.0% accurate, 5.0× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ d2 \cdot d1 \end{array} \]
          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
          (FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	return d2 * d1;
          }
          
          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(d1, d2, d3, d4)
          use fmin_fmax_functions
              real(8), intent (in) :: d1
              real(8), intent (in) :: d2
              real(8), intent (in) :: d3
              real(8), intent (in) :: d4
              code = d2 * d1
          end function
          
          assert d1 < d2 && d2 < d3 && d3 < d4;
          public static double code(double d1, double d2, double d3, double d4) {
          	return d2 * d1;
          }
          
          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
          def code(d1, d2, d3, d4):
          	return d2 * d1
          
          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
          function code(d1, d2, d3, d4)
          	return Float64(d2 * d1)
          end
          
          d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
          function tmp = code(d1, d2, d3, d4)
          	tmp = d2 * d1;
          end
          
          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
          code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
          
          \begin{array}{l}
          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
          \\
          d2 \cdot d1
          \end{array}
          
          Derivation
          1. Initial program 86.3%

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

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

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

              \[\leadsto d2 \cdot \color{blue}{d1} \]
          5. Applied rewrites36.2%

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