FastMath dist4

Percentage Accurate: 87.8% → 100.0%
Time: 6.0s
Alternatives: 16
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}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 16 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.8% 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: 100.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{d1}{d4}, \left(d2 - d3\right) - d1, d1\right) \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) 5e+307)
   (fma (- d2 d3) d1 (* d1 (- d4 d1)))
   (* (fma (/ d1 d4) (- (- d2 d3) d1) d1) d4)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= 5e+307) {
		tmp = fma((d2 - d3), d1, (d1 * (d4 - d1)));
	} else {
		tmp = fma((d1 / d4), ((d2 - d3) - d1), d1) * d4;
	}
	return tmp;
}
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)) <= 5e+307)
		tmp = fma(Float64(d2 - d3), d1, Float64(d1 * Float64(d4 - d1)));
	else
		tmp = Float64(fma(Float64(d1 / d4), Float64(Float64(d2 - d3) - d1), d1) * d4);
	end
	return tmp
end
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], 5e+307], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d1 / d4), $MachinePrecision] * N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] + d1), $MachinePrecision] * d4), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\

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


\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)) < 5e307

    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. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5e307 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

    1. Initial program 14.7%

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

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

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

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

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

Alternative 2: 98.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) INFINITY)
   (fma (- d2 d3) d1 (* d1 (- d4 d1)))
   (* (- (- d2 d3) d1) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= ((double) INFINITY)) {
		tmp = fma((d2 - d3), d1, (d1 * (d4 - d1)));
	} else {
		tmp = ((d2 - d3) - d1) * d1;
	}
	return tmp;
}
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)) <= Inf)
		tmp = fma(Float64(d2 - d3), d1, Float64(d1 * Float64(d4 - d1)));
	else
		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
	end
	return tmp
end
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], Infinity], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\

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


\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)) < +inf.0

    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. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

    1. Initial program 0.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}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

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

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

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

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

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

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

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

Alternative 3: 98.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) INFINITY)
   (fma d1 (- d4 d1) (* (- d2 d3) d1))
   (* (- (- d2 d3) d1) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= ((double) INFINITY)) {
		tmp = fma(d1, (d4 - d1), ((d2 - d3) * d1));
	} else {
		tmp = ((d2 - d3) - d1) * d1;
	}
	return tmp;
}
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)) <= Inf)
		tmp = fma(d1, Float64(d4 - d1), Float64(Float64(d2 - d3) * d1));
	else
		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
	end
	return tmp
end
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], Infinity], N[(d1 * N[(d4 - d1), $MachinePrecision] + N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\

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


\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)) < +inf.0

    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. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

    1. Initial program 0.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}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
    4. Step-by-step derivation
      1. associate--r+N/A

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

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

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

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

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

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

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

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

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

Alternative 4: 38.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -8.2 \cdot 10^{+31}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.2 \cdot 10^{-71} \lor \neg \left(d2 \leq -2.2 \cdot 10^{-277}\right):\\ \;\;\;\;d4 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -8.2e+31)
   (* d1 d2)
   (if (or (<= d2 -1.2e-71) (not (<= d2 -2.2e-277))) (* d4 d1) (* (- d3) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -8.2e+31) {
		tmp = d1 * d2;
	} else if ((d2 <= -1.2e-71) || !(d2 <= -2.2e-277)) {
		tmp = d4 * d1;
	} else {
		tmp = -d3 * d1;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-8.2d+31)) then
        tmp = d1 * d2
    else if ((d2 <= (-1.2d-71)) .or. (.not. (d2 <= (-2.2d-277)))) then
        tmp = d4 * d1
    else
        tmp = -d3 * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -8.2e+31) {
		tmp = d1 * d2;
	} else if ((d2 <= -1.2e-71) || !(d2 <= -2.2e-277)) {
		tmp = d4 * d1;
	} else {
		tmp = -d3 * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -8.2e+31:
		tmp = d1 * d2
	elif (d2 <= -1.2e-71) or not (d2 <= -2.2e-277):
		tmp = d4 * d1
	else:
		tmp = -d3 * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -8.2e+31)
		tmp = Float64(d1 * d2);
	elseif ((d2 <= -1.2e-71) || !(d2 <= -2.2e-277))
		tmp = Float64(d4 * d1);
	else
		tmp = Float64(Float64(-d3) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -8.2e+31)
		tmp = d1 * d2;
	elseif ((d2 <= -1.2e-71) || ~((d2 <= -2.2e-277)))
		tmp = d4 * d1;
	else
		tmp = -d3 * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -8.2e+31], N[(d1 * d2), $MachinePrecision], If[Or[LessEqual[d2, -1.2e-71], N[Not[LessEqual[d2, -2.2e-277]], $MachinePrecision]], N[(d4 * d1), $MachinePrecision], N[((-d3) * d1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -8.2 \cdot 10^{+31}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -1.2 \cdot 10^{-71} \lor \neg \left(d2 \leq -2.2 \cdot 10^{-277}\right):\\
\;\;\;\;d4 \cdot d1\\

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


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

    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. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot d2} \]
    7. Applied rewrites54.8%

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

    if -8.2000000000000003e31 < d2 < -1.2e-71 or -2.19999999999999996e-277 < d2

    1. Initial program 87.9%

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

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

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

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

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

    if -1.2e-71 < d2 < -2.19999999999999996e-277

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(d2 - d1\right) \cdot d1 \]
      2. Taylor expanded in d3 around inf

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

          \[\leadsto \left(-d3\right) \cdot d1 \]
      4. Recombined 3 regimes into one program.
      5. Final simplification43.3%

        \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -8.2 \cdot 10^{+31}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.2 \cdot 10^{-71} \lor \neg \left(d2 \leq -2.2 \cdot 10^{-277}\right):\\ \;\;\;\;d4 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \end{array} \]
      6. Add Preprocessing

      Alternative 5: 39.0% accurate, 1.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.4 \cdot 10^{+97}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.65 \cdot 10^{-130}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -2.2 \cdot 10^{-277}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
      (FPCore (d1 d2 d3 d4)
       :precision binary64
       (if (<= d2 -4.4e+97)
         (* d1 d2)
         (if (<= d2 -1.65e-130)
           (* (- d1) d1)
           (if (<= d2 -2.2e-277) (* (- d3) d1) (* d4 d1)))))
      double code(double d1, double d2, double d3, double d4) {
      	double tmp;
      	if (d2 <= -4.4e+97) {
      		tmp = d1 * d2;
      	} else if (d2 <= -1.65e-130) {
      		tmp = -d1 * d1;
      	} else if (d2 <= -2.2e-277) {
      		tmp = -d3 * d1;
      	} else {
      		tmp = d4 * d1;
      	}
      	return tmp;
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(d1, d2, d3, d4)
      use fmin_fmax_functions
          real(8), intent (in) :: d1
          real(8), intent (in) :: d2
          real(8), intent (in) :: d3
          real(8), intent (in) :: d4
          real(8) :: tmp
          if (d2 <= (-4.4d+97)) then
              tmp = d1 * d2
          else if (d2 <= (-1.65d-130)) then
              tmp = -d1 * d1
          else if (d2 <= (-2.2d-277)) then
              tmp = -d3 * d1
          else
              tmp = d4 * d1
          end if
          code = tmp
      end function
      
      public static double code(double d1, double d2, double d3, double d4) {
      	double tmp;
      	if (d2 <= -4.4e+97) {
      		tmp = d1 * d2;
      	} else if (d2 <= -1.65e-130) {
      		tmp = -d1 * d1;
      	} else if (d2 <= -2.2e-277) {
      		tmp = -d3 * d1;
      	} else {
      		tmp = d4 * d1;
      	}
      	return tmp;
      }
      
      def code(d1, d2, d3, d4):
      	tmp = 0
      	if d2 <= -4.4e+97:
      		tmp = d1 * d2
      	elif d2 <= -1.65e-130:
      		tmp = -d1 * d1
      	elif d2 <= -2.2e-277:
      		tmp = -d3 * d1
      	else:
      		tmp = d4 * d1
      	return tmp
      
      function code(d1, d2, d3, d4)
      	tmp = 0.0
      	if (d2 <= -4.4e+97)
      		tmp = Float64(d1 * d2);
      	elseif (d2 <= -1.65e-130)
      		tmp = Float64(Float64(-d1) * d1);
      	elseif (d2 <= -2.2e-277)
      		tmp = Float64(Float64(-d3) * d1);
      	else
      		tmp = Float64(d4 * d1);
      	end
      	return tmp
      end
      
      function tmp_2 = code(d1, d2, d3, d4)
      	tmp = 0.0;
      	if (d2 <= -4.4e+97)
      		tmp = d1 * d2;
      	elseif (d2 <= -1.65e-130)
      		tmp = -d1 * d1;
      	elseif (d2 <= -2.2e-277)
      		tmp = -d3 * d1;
      	else
      		tmp = d4 * d1;
      	end
      	tmp_2 = tmp;
      end
      
      code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.4e+97], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -1.65e-130], N[((-d1) * d1), $MachinePrecision], If[LessEqual[d2, -2.2e-277], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d2 \leq -4.4 \cdot 10^{+97}:\\
      \;\;\;\;d1 \cdot d2\\
      
      \mathbf{elif}\;d2 \leq -1.65 \cdot 10^{-130}:\\
      \;\;\;\;\left(-d1\right) \cdot d1\\
      
      \mathbf{elif}\;d2 \leq -2.2 \cdot 10^{-277}:\\
      \;\;\;\;\left(-d3\right) \cdot d1\\
      
      \mathbf{else}:\\
      \;\;\;\;d4 \cdot d1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 4 regimes
      2. if d2 < -4.4000000000000002e97

        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. Step-by-step derivation
          1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{d1 \cdot d2} \]
        7. Applied rewrites66.1%

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

        if -4.4000000000000002e97 < d2 < -1.6499999999999999e-130

        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 inf

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

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

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

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

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

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

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

        if -1.6499999999999999e-130 < d2 < -2.19999999999999996e-277

        1. Initial program 88.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}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
        4. Step-by-step derivation
          1. associate--r+N/A

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(d2 - d1\right) \cdot d1 \]
          2. Taylor expanded in d3 around inf

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

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

            if -2.19999999999999996e-277 < d2

            1. Initial program 85.8%

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

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

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.4 \cdot 10^{+97}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.65 \cdot 10^{-130}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -2.2 \cdot 10^{-277}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
          6. Add Preprocessing

          Alternative 6: 92.3% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.25 \cdot 10^{-35} \lor \neg \left(d3 \leq 3.1 \cdot 10^{+50}\right):\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (if (or (<= d3 -1.25e-35) (not (<= d3 3.1e+50)))
             (* (- (+ d4 d2) d3) d1)
             (* (- (+ d4 d2) d1) d1)))
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if ((d3 <= -1.25e-35) || !(d3 <= 3.1e+50)) {
          		tmp = ((d4 + d2) - d3) * d1;
          	} else {
          		tmp = ((d4 + d2) - d1) * d1;
          	}
          	return tmp;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(d1, d2, d3, d4)
          use fmin_fmax_functions
              real(8), intent (in) :: d1
              real(8), intent (in) :: d2
              real(8), intent (in) :: d3
              real(8), intent (in) :: d4
              real(8) :: tmp
              if ((d3 <= (-1.25d-35)) .or. (.not. (d3 <= 3.1d+50))) then
                  tmp = ((d4 + d2) - d3) * d1
              else
                  tmp = ((d4 + d2) - d1) * d1
              end if
              code = tmp
          end function
          
          public static double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if ((d3 <= -1.25e-35) || !(d3 <= 3.1e+50)) {
          		tmp = ((d4 + d2) - d3) * d1;
          	} else {
          		tmp = ((d4 + d2) - d1) * d1;
          	}
          	return tmp;
          }
          
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if (d3 <= -1.25e-35) or not (d3 <= 3.1e+50):
          		tmp = ((d4 + d2) - d3) * d1
          	else:
          		tmp = ((d4 + d2) - d1) * d1
          	return tmp
          
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if ((d3 <= -1.25e-35) || !(d3 <= 3.1e+50))
          		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
          	else
          		tmp = Float64(Float64(Float64(d4 + d2) - d1) * d1);
          	end
          	return tmp
          end
          
          function tmp_2 = code(d1, d2, d3, d4)
          	tmp = 0.0;
          	if ((d3 <= -1.25e-35) || ~((d3 <= 3.1e+50)))
          		tmp = ((d4 + d2) - d3) * d1;
          	else
          		tmp = ((d4 + d2) - d1) * d1;
          	end
          	tmp_2 = tmp;
          end
          
          code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1.25e-35], N[Not[LessEqual[d3, 3.1e+50]], $MachinePrecision]], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d3 \leq -1.25 \cdot 10^{-35} \lor \neg \left(d3 \leq 3.1 \cdot 10^{+50}\right):\\
          \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d3 < -1.24999999999999991e-35 or 3.10000000000000003e50 < d3

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

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

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

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

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

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

            if -1.24999999999999991e-35 < d3 < 3.10000000000000003e50

            1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 7: 91.8% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.25 \cdot 10^{-35}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, \left(d2 - d3\right) \cdot d1\right)\\ \mathbf{elif}\;d3 \leq 3.1 \cdot 10^{+50}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
          (FPCore (d1 d2 d3 d4)
           :precision binary64
           (if (<= d3 -1.25e-35)
             (fma d4 d1 (* (- d2 d3) d1))
             (if (<= d3 3.1e+50) (* (- (+ d4 d2) d1) d1) (* (- (+ d4 d2) d3) d1))))
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d3 <= -1.25e-35) {
          		tmp = fma(d4, d1, ((d2 - d3) * d1));
          	} else if (d3 <= 3.1e+50) {
          		tmp = ((d4 + d2) - d1) * d1;
          	} else {
          		tmp = ((d4 + d2) - d3) * d1;
          	}
          	return tmp;
          }
          
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d3 <= -1.25e-35)
          		tmp = fma(d4, d1, Float64(Float64(d2 - d3) * d1));
          	elseif (d3 <= 3.1e+50)
          		tmp = Float64(Float64(Float64(d4 + d2) - d1) * d1);
          	else
          		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
          	end
          	return tmp
          end
          
          code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -1.25e-35], N[(d4 * d1 + N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 3.1e+50], N[(N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d3 \leq -1.25 \cdot 10^{-35}:\\
          \;\;\;\;\mathsf{fma}\left(d4, d1, \left(d2 - d3\right) \cdot d1\right)\\
          
          \mathbf{elif}\;d3 \leq 3.1 \cdot 10^{+50}:\\
          \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if d3 < -1.24999999999999991e-35

            1. Initial program 86.9%

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

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

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

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

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

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

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

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

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

              if -1.24999999999999991e-35 < d3 < 3.10000000000000003e50

              1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

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

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

              if 3.10000000000000003e50 < d3

              1. Initial program 83.0%

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\left(\left(d4 + d2\right) - d3\right) \cdot d1} \]
            7. Recombined 3 regimes into one program.
            8. Add Preprocessing

            Alternative 8: 88.8% accurate, 1.2× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.75 \cdot 10^{+137}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 4.5 \cdot 10^{+96}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
            (FPCore (d1 d2 d3 d4)
             :precision binary64
             (if (<= d3 -2.75e+137)
               (* (- d2 d3) d1)
               (if (<= d3 4.5e+96) (* (- (+ d4 d2) d1) d1) (* (- d4 d3) d1))))
            double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if (d3 <= -2.75e+137) {
            		tmp = (d2 - d3) * d1;
            	} else if (d3 <= 4.5e+96) {
            		tmp = ((d4 + d2) - d1) * d1;
            	} else {
            		tmp = (d4 - d3) * d1;
            	}
            	return tmp;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(d1, d2, d3, d4)
            use fmin_fmax_functions
                real(8), intent (in) :: d1
                real(8), intent (in) :: d2
                real(8), intent (in) :: d3
                real(8), intent (in) :: d4
                real(8) :: tmp
                if (d3 <= (-2.75d+137)) then
                    tmp = (d2 - d3) * d1
                else if (d3 <= 4.5d+96) then
                    tmp = ((d4 + d2) - d1) * d1
                else
                    tmp = (d4 - d3) * d1
                end if
                code = tmp
            end function
            
            public static double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if (d3 <= -2.75e+137) {
            		tmp = (d2 - d3) * d1;
            	} else if (d3 <= 4.5e+96) {
            		tmp = ((d4 + d2) - d1) * d1;
            	} else {
            		tmp = (d4 - d3) * d1;
            	}
            	return tmp;
            }
            
            def code(d1, d2, d3, d4):
            	tmp = 0
            	if d3 <= -2.75e+137:
            		tmp = (d2 - d3) * d1
            	elif d3 <= 4.5e+96:
            		tmp = ((d4 + d2) - d1) * d1
            	else:
            		tmp = (d4 - d3) * d1
            	return tmp
            
            function code(d1, d2, d3, d4)
            	tmp = 0.0
            	if (d3 <= -2.75e+137)
            		tmp = Float64(Float64(d2 - d3) * d1);
            	elseif (d3 <= 4.5e+96)
            		tmp = Float64(Float64(Float64(d4 + d2) - d1) * d1);
            	else
            		tmp = Float64(Float64(d4 - d3) * d1);
            	end
            	return tmp
            end
            
            function tmp_2 = code(d1, d2, d3, d4)
            	tmp = 0.0;
            	if (d3 <= -2.75e+137)
            		tmp = (d2 - d3) * d1;
            	elseif (d3 <= 4.5e+96)
            		tmp = ((d4 + d2) - d1) * d1;
            	else
            		tmp = (d4 - d3) * d1;
            	end
            	tmp_2 = tmp;
            end
            
            code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -2.75e+137], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 4.5e+96], N[(N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;d3 \leq -2.75 \cdot 10^{+137}:\\
            \;\;\;\;\left(d2 - d3\right) \cdot d1\\
            
            \mathbf{elif}\;d3 \leq 4.5 \cdot 10^{+96}:\\
            \;\;\;\;\left(\left(d4 + d2\right) - d1\right) \cdot d1\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(d4 - d3\right) \cdot d1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if d3 < -2.7500000000000001e137

              1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -2.7500000000000001e137 < d3 < 4.49999999999999957e96

                1. Initial program 89.0%

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

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

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

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

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

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

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

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

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

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

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

                if 4.49999999999999957e96 < d3

                1. Initial program 85.1%

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

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

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

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

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

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

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

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

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

                Alternative 9: 82.0% accurate, 1.3× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+31}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(-d3\right) \cdot d1\right)\\ \end{array} \end{array} \]
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (<= d2 -6.5e+31)
                   (* (- (- d2 d3) d1) d1)
                   (fma d1 (- d4 d1) (* (- d3) d1))))
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if (d2 <= -6.5e+31) {
                		tmp = ((d2 - d3) - d1) * d1;
                	} else {
                		tmp = fma(d1, (d4 - d1), (-d3 * d1));
                	}
                	return tmp;
                }
                
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if (d2 <= -6.5e+31)
                		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                	else
                		tmp = fma(d1, Float64(d4 - d1), Float64(Float64(-d3) * d1));
                	end
                	return tmp
                end
                
                code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6.5e+31], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision] + N[((-d3) * d1), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+31}:\\
                \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(-d3\right) \cdot d1\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if d2 < -6.5000000000000004e31

                  1. Initial program 87.8%

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

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

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

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

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

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

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

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

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

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

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

                  if -6.5000000000000004e31 < d2

                  1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 10: 65.0% accurate, 1.4× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d1 \leq -9.2 \cdot 10^{+132} \lor \neg \left(d1 \leq 3.4 \cdot 10^{+59}\right):\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \end{array} \end{array} \]
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (if (or (<= d1 -9.2e+132) (not (<= d1 3.4e+59)))
                   (* (- d1) d1)
                   (* (+ d4 d2) d1)))
                double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if ((d1 <= -9.2e+132) || !(d1 <= 3.4e+59)) {
                		tmp = -d1 * d1;
                	} else {
                		tmp = (d4 + d2) * d1;
                	}
                	return tmp;
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(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 <= (-9.2d+132)) .or. (.not. (d1 <= 3.4d+59))) then
                        tmp = -d1 * d1
                    else
                        tmp = (d4 + d2) * d1
                    end if
                    code = tmp
                end function
                
                public static double code(double d1, double d2, double d3, double d4) {
                	double tmp;
                	if ((d1 <= -9.2e+132) || !(d1 <= 3.4e+59)) {
                		tmp = -d1 * d1;
                	} else {
                		tmp = (d4 + d2) * d1;
                	}
                	return tmp;
                }
                
                def code(d1, d2, d3, d4):
                	tmp = 0
                	if (d1 <= -9.2e+132) or not (d1 <= 3.4e+59):
                		tmp = -d1 * d1
                	else:
                		tmp = (d4 + d2) * d1
                	return tmp
                
                function code(d1, d2, d3, d4)
                	tmp = 0.0
                	if ((d1 <= -9.2e+132) || !(d1 <= 3.4e+59))
                		tmp = Float64(Float64(-d1) * d1);
                	else
                		tmp = Float64(Float64(d4 + d2) * d1);
                	end
                	return tmp
                end
                
                function tmp_2 = code(d1, d2, d3, d4)
                	tmp = 0.0;
                	if ((d1 <= -9.2e+132) || ~((d1 <= 3.4e+59)))
                		tmp = -d1 * d1;
                	else
                		tmp = (d4 + d2) * d1;
                	end
                	tmp_2 = tmp;
                end
                
                code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -9.2e+132], N[Not[LessEqual[d1, 3.4e+59]], $MachinePrecision]], N[((-d1) * d1), $MachinePrecision], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;d1 \leq -9.2 \cdot 10^{+132} \lor \neg \left(d1 \leq 3.4 \cdot 10^{+59}\right):\\
                \;\;\;\;\left(-d1\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;\left(d4 + d2\right) \cdot d1\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if d1 < -9.2000000000000006e132 or 3.40000000000000006e59 < d1

                  1. Initial program 63.3%

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

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

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

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

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

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

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

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

                  if -9.2000000000000006e132 < d1 < 3.40000000000000006e59

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -9.2 \cdot 10^{+132} \lor \neg \left(d1 \leq 3.4 \cdot 10^{+59}\right):\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \end{array} \]
                  10. Add Preprocessing

                  Alternative 11: 64.0% accurate, 1.4× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+31}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -1 \cdot 10^{-80}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
                  (FPCore (d1 d2 d3 d4)
                   :precision binary64
                   (if (<= d2 -6.5e+31)
                     (* (- d2 d3) d1)
                     (if (<= d2 -1e-80) (* (- d4 d1) d1) (* (- d4 d3) d1))))
                  double code(double d1, double d2, double d3, double d4) {
                  	double tmp;
                  	if (d2 <= -6.5e+31) {
                  		tmp = (d2 - d3) * d1;
                  	} else if (d2 <= -1e-80) {
                  		tmp = (d4 - d1) * d1;
                  	} else {
                  		tmp = (d4 - d3) * d1;
                  	}
                  	return tmp;
                  }
                  
                  module fmin_fmax_functions
                      implicit none
                      private
                      public fmax
                      public fmin
                  
                      interface fmax
                          module procedure fmax88
                          module procedure fmax44
                          module procedure fmax84
                          module procedure fmax48
                      end interface
                      interface fmin
                          module procedure fmin88
                          module procedure fmin44
                          module procedure fmin84
                          module procedure fmin48
                      end interface
                  contains
                      real(8) function fmax88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmax44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmax84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmax48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                      end function
                      real(8) function fmin88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmin44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmin84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmin48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                      end function
                  end module
                  
                  real(8) function code(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 <= (-6.5d+31)) then
                          tmp = (d2 - d3) * d1
                      else if (d2 <= (-1d-80)) then
                          tmp = (d4 - d1) * d1
                      else
                          tmp = (d4 - d3) * d1
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double d1, double d2, double d3, double d4) {
                  	double tmp;
                  	if (d2 <= -6.5e+31) {
                  		tmp = (d2 - d3) * d1;
                  	} else if (d2 <= -1e-80) {
                  		tmp = (d4 - d1) * d1;
                  	} else {
                  		tmp = (d4 - d3) * d1;
                  	}
                  	return tmp;
                  }
                  
                  def code(d1, d2, d3, d4):
                  	tmp = 0
                  	if d2 <= -6.5e+31:
                  		tmp = (d2 - d3) * d1
                  	elif d2 <= -1e-80:
                  		tmp = (d4 - d1) * d1
                  	else:
                  		tmp = (d4 - d3) * d1
                  	return tmp
                  
                  function code(d1, d2, d3, d4)
                  	tmp = 0.0
                  	if (d2 <= -6.5e+31)
                  		tmp = Float64(Float64(d2 - d3) * d1);
                  	elseif (d2 <= -1e-80)
                  		tmp = Float64(Float64(d4 - d1) * d1);
                  	else
                  		tmp = Float64(Float64(d4 - d3) * d1);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(d1, d2, d3, d4)
                  	tmp = 0.0;
                  	if (d2 <= -6.5e+31)
                  		tmp = (d2 - d3) * d1;
                  	elseif (d2 <= -1e-80)
                  		tmp = (d4 - d1) * d1;
                  	else
                  		tmp = (d4 - d3) * d1;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6.5e+31], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -1e-80], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+31}:\\
                  \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                  
                  \mathbf{elif}\;d2 \leq -1 \cdot 10^{-80}:\\
                  \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if d2 < -6.5000000000000004e31

                    1. Initial program 87.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if -6.5000000000000004e31 < d2 < -9.99999999999999961e-81

                      1. Initial program 96.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if -9.99999999999999961e-81 < d2

                        1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

                        Alternative 12: 63.4% accurate, 1.4× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+31}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -1 \cdot 10^{-80}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
                        (FPCore (d1 d2 d3 d4)
                         :precision binary64
                         (if (<= d2 -6.5e+31)
                           (* (- d2 d1) d1)
                           (if (<= d2 -1e-80) (* (- d4 d1) d1) (* (- d4 d3) d1))))
                        double code(double d1, double d2, double d3, double d4) {
                        	double tmp;
                        	if (d2 <= -6.5e+31) {
                        		tmp = (d2 - d1) * d1;
                        	} else if (d2 <= -1e-80) {
                        		tmp = (d4 - d1) * d1;
                        	} else {
                        		tmp = (d4 - d3) * d1;
                        	}
                        	return tmp;
                        }
                        
                        module fmin_fmax_functions
                            implicit none
                            private
                            public fmax
                            public fmin
                        
                            interface fmax
                                module procedure fmax88
                                module procedure fmax44
                                module procedure fmax84
                                module procedure fmax48
                            end interface
                            interface fmin
                                module procedure fmin88
                                module procedure fmin44
                                module procedure fmin84
                                module procedure fmin48
                            end interface
                        contains
                            real(8) function fmax88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmax44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmax84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmax48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                            end function
                            real(8) function fmin88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmin44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmin84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmin48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                            end function
                        end module
                        
                        real(8) function code(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 <= (-6.5d+31)) then
                                tmp = (d2 - d1) * d1
                            else if (d2 <= (-1d-80)) then
                                tmp = (d4 - d1) * d1
                            else
                                tmp = (d4 - d3) * d1
                            end if
                            code = tmp
                        end function
                        
                        public static double code(double d1, double d2, double d3, double d4) {
                        	double tmp;
                        	if (d2 <= -6.5e+31) {
                        		tmp = (d2 - d1) * d1;
                        	} else if (d2 <= -1e-80) {
                        		tmp = (d4 - d1) * d1;
                        	} else {
                        		tmp = (d4 - d3) * d1;
                        	}
                        	return tmp;
                        }
                        
                        def code(d1, d2, d3, d4):
                        	tmp = 0
                        	if d2 <= -6.5e+31:
                        		tmp = (d2 - d1) * d1
                        	elif d2 <= -1e-80:
                        		tmp = (d4 - d1) * d1
                        	else:
                        		tmp = (d4 - d3) * d1
                        	return tmp
                        
                        function code(d1, d2, d3, d4)
                        	tmp = 0.0
                        	if (d2 <= -6.5e+31)
                        		tmp = Float64(Float64(d2 - d1) * d1);
                        	elseif (d2 <= -1e-80)
                        		tmp = Float64(Float64(d4 - d1) * d1);
                        	else
                        		tmp = Float64(Float64(d4 - d3) * d1);
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(d1, d2, d3, d4)
                        	tmp = 0.0;
                        	if (d2 <= -6.5e+31)
                        		tmp = (d2 - d1) * d1;
                        	elseif (d2 <= -1e-80)
                        		tmp = (d4 - d1) * d1;
                        	else
                        		tmp = (d4 - d3) * d1;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6.5e+31], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -1e-80], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;d2 \leq -6.5 \cdot 10^{+31}:\\
                        \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                        
                        \mathbf{elif}\;d2 \leq -1 \cdot 10^{-80}:\\
                        \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 3 regimes
                        2. if d2 < -6.5000000000000004e31

                          1. Initial program 87.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if -6.5000000000000004e31 < d2 < -9.99999999999999961e-81

                            1. Initial program 96.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if -9.99999999999999961e-81 < d2

                              1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

                              Alternative 13: 64.3% accurate, 1.4× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.4 \cdot 10^{+97}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -1 \cdot 10^{-80}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
                              (FPCore (d1 d2 d3 d4)
                               :precision binary64
                               (if (<= d2 -4.4e+97)
                                 (* (+ d4 d2) d1)
                                 (if (<= d2 -1e-80) (* (- d4 d1) d1) (* (- d4 d3) d1))))
                              double code(double d1, double d2, double d3, double d4) {
                              	double tmp;
                              	if (d2 <= -4.4e+97) {
                              		tmp = (d4 + d2) * d1;
                              	} else if (d2 <= -1e-80) {
                              		tmp = (d4 - d1) * d1;
                              	} else {
                              		tmp = (d4 - d3) * d1;
                              	}
                              	return tmp;
                              }
                              
                              module fmin_fmax_functions
                                  implicit none
                                  private
                                  public fmax
                                  public fmin
                              
                                  interface fmax
                                      module procedure fmax88
                                      module procedure fmax44
                                      module procedure fmax84
                                      module procedure fmax48
                                  end interface
                                  interface fmin
                                      module procedure fmin88
                                      module procedure fmin44
                                      module procedure fmin84
                                      module procedure fmin48
                                  end interface
                              contains
                                  real(8) function fmax88(x, y) result (res)
                                      real(8), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                  end function
                                  real(4) function fmax44(x, y) result (res)
                                      real(4), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                  end function
                                  real(8) function fmax84(x, y) result(res)
                                      real(8), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                  end function
                                  real(8) function fmax48(x, y) result(res)
                                      real(4), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                  end function
                                  real(8) function fmin88(x, y) result (res)
                                      real(8), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                  end function
                                  real(4) function fmin44(x, y) result (res)
                                      real(4), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                  end function
                                  real(8) function fmin84(x, y) result(res)
                                      real(8), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                  end function
                                  real(8) function fmin48(x, y) result(res)
                                      real(4), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                  end function
                              end module
                              
                              real(8) function code(d1, d2, d3, d4)
                              use fmin_fmax_functions
                                  real(8), intent (in) :: d1
                                  real(8), intent (in) :: d2
                                  real(8), intent (in) :: d3
                                  real(8), intent (in) :: d4
                                  real(8) :: tmp
                                  if (d2 <= (-4.4d+97)) then
                                      tmp = (d4 + d2) * d1
                                  else if (d2 <= (-1d-80)) then
                                      tmp = (d4 - d1) * d1
                                  else
                                      tmp = (d4 - d3) * d1
                                  end if
                                  code = tmp
                              end function
                              
                              public static double code(double d1, double d2, double d3, double d4) {
                              	double tmp;
                              	if (d2 <= -4.4e+97) {
                              		tmp = (d4 + d2) * d1;
                              	} else if (d2 <= -1e-80) {
                              		tmp = (d4 - d1) * d1;
                              	} else {
                              		tmp = (d4 - d3) * d1;
                              	}
                              	return tmp;
                              }
                              
                              def code(d1, d2, d3, d4):
                              	tmp = 0
                              	if d2 <= -4.4e+97:
                              		tmp = (d4 + d2) * d1
                              	elif d2 <= -1e-80:
                              		tmp = (d4 - d1) * d1
                              	else:
                              		tmp = (d4 - d3) * d1
                              	return tmp
                              
                              function code(d1, d2, d3, d4)
                              	tmp = 0.0
                              	if (d2 <= -4.4e+97)
                              		tmp = Float64(Float64(d4 + d2) * d1);
                              	elseif (d2 <= -1e-80)
                              		tmp = Float64(Float64(d4 - d1) * d1);
                              	else
                              		tmp = Float64(Float64(d4 - d3) * d1);
                              	end
                              	return tmp
                              end
                              
                              function tmp_2 = code(d1, d2, d3, d4)
                              	tmp = 0.0;
                              	if (d2 <= -4.4e+97)
                              		tmp = (d4 + d2) * d1;
                              	elseif (d2 <= -1e-80)
                              		tmp = (d4 - d1) * d1;
                              	else
                              		tmp = (d4 - d3) * d1;
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.4e+97], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -1e-80], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
                              
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;d2 \leq -4.4 \cdot 10^{+97}:\\
                              \;\;\;\;\left(d4 + d2\right) \cdot d1\\
                              
                              \mathbf{elif}\;d2 \leq -1 \cdot 10^{-80}:\\
                              \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 3 regimes
                              2. if d2 < -4.4000000000000002e97

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  if -4.4000000000000002e97 < d2 < -9.99999999999999961e-81

                                  1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -9.99999999999999961e-81 < d2

                                    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

                                    Alternative 14: 62.7% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        if -4.4000000000000002e97 < d2

                                        1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        Alternative 15: 39.1% accurate, 2.5× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -8.2 \cdot 10^{+31}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                                        (FPCore (d1 d2 d3 d4)
                                         :precision binary64
                                         (if (<= d2 -8.2e+31) (* d1 d2) (* d4 d1)))
                                        double code(double d1, double d2, double d3, double d4) {
                                        	double tmp;
                                        	if (d2 <= -8.2e+31) {
                                        		tmp = d1 * d2;
                                        	} else {
                                        		tmp = d4 * d1;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        module fmin_fmax_functions
                                            implicit none
                                            private
                                            public fmax
                                            public fmin
                                        
                                            interface fmax
                                                module procedure fmax88
                                                module procedure fmax44
                                                module procedure fmax84
                                                module procedure fmax48
                                            end interface
                                            interface fmin
                                                module procedure fmin88
                                                module procedure fmin44
                                                module procedure fmin84
                                                module procedure fmin48
                                            end interface
                                        contains
                                            real(8) function fmax88(x, y) result (res)
                                                real(8), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                            end function
                                            real(4) function fmax44(x, y) result (res)
                                                real(4), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                            end function
                                            real(8) function fmax84(x, y) result(res)
                                                real(8), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                            end function
                                            real(8) function fmax48(x, y) result(res)
                                                real(4), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                            end function
                                            real(8) function fmin88(x, y) result (res)
                                                real(8), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                            end function
                                            real(4) function fmin44(x, y) result (res)
                                                real(4), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                            end function
                                            real(8) function fmin84(x, y) result(res)
                                                real(8), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                            end function
                                            real(8) function fmin48(x, y) result(res)
                                                real(4), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                            end function
                                        end module
                                        
                                        real(8) function code(d1, d2, d3, d4)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: d1
                                            real(8), intent (in) :: d2
                                            real(8), intent (in) :: d3
                                            real(8), intent (in) :: d4
                                            real(8) :: tmp
                                            if (d2 <= (-8.2d+31)) then
                                                tmp = d1 * d2
                                            else
                                                tmp = d4 * d1
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double d1, double d2, double d3, double d4) {
                                        	double tmp;
                                        	if (d2 <= -8.2e+31) {
                                        		tmp = d1 * d2;
                                        	} else {
                                        		tmp = d4 * d1;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(d1, d2, d3, d4):
                                        	tmp = 0
                                        	if d2 <= -8.2e+31:
                                        		tmp = d1 * d2
                                        	else:
                                        		tmp = d4 * d1
                                        	return tmp
                                        
                                        function code(d1, d2, d3, d4)
                                        	tmp = 0.0
                                        	if (d2 <= -8.2e+31)
                                        		tmp = Float64(d1 * d2);
                                        	else
                                        		tmp = Float64(d4 * d1);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(d1, d2, d3, d4)
                                        	tmp = 0.0;
                                        	if (d2 <= -8.2e+31)
                                        		tmp = d1 * d2;
                                        	else
                                        		tmp = d4 * d1;
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -8.2e+31], N[(d1 * d2), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;d2 \leq -8.2 \cdot 10^{+31}:\\
                                        \;\;\;\;d1 \cdot d2\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;d4 \cdot d1\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if d2 < -8.2000000000000003e31

                                          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. Step-by-step derivation
                                            1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                              \[\leadsto \color{blue}{d1 \cdot d2} \]
                                          7. Applied rewrites54.8%

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

                                          if -8.2000000000000003e31 < d2

                                          1. Initial program 88.9%

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

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

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

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

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

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

                                        Alternative 16: 30.3% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \color{blue}{d1 \cdot d2} \]
                                        7. Applied rewrites27.3%

                                          \[\leadsto \color{blue}{d1 \cdot d2} \]
                                        8. Final simplification27.3%

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

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

                                        \[\begin{array}{l} \\ d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \end{array} \]
                                        (FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
                                        double code(double d1, double d2, double d3, double d4) {
                                        	return d1 * (((d2 - d3) + d4) - d1);
                                        }
                                        
                                        module fmin_fmax_functions
                                            implicit none
                                            private
                                            public fmax
                                            public fmin
                                        
                                            interface fmax
                                                module procedure fmax88
                                                module procedure fmax44
                                                module procedure fmax84
                                                module procedure fmax48
                                            end interface
                                            interface fmin
                                                module procedure fmin88
                                                module procedure fmin44
                                                module procedure fmin84
                                                module procedure fmin48
                                            end interface
                                        contains
                                            real(8) function fmax88(x, y) result (res)
                                                real(8), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                            end function
                                            real(4) function fmax44(x, y) result (res)
                                                real(4), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                            end function
                                            real(8) function fmax84(x, y) result(res)
                                                real(8), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                            end function
                                            real(8) function fmax48(x, y) result(res)
                                                real(4), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                            end function
                                            real(8) function fmin88(x, y) result (res)
                                                real(8), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                            end function
                                            real(4) function fmin44(x, y) result (res)
                                                real(4), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                            end function
                                            real(8) function fmin84(x, y) result(res)
                                                real(8), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                            end function
                                            real(8) function fmin48(x, y) result(res)
                                                real(4), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                            end function
                                        end module
                                        
                                        real(8) function code(d1, d2, d3, d4)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: d1
                                            real(8), intent (in) :: d2
                                            real(8), intent (in) :: d3
                                            real(8), intent (in) :: d4
                                            code = d1 * (((d2 - d3) + d4) - d1)
                                        end function
                                        
                                        public static double code(double d1, double d2, double d3, double d4) {
                                        	return d1 * (((d2 - d3) + d4) - d1);
                                        }
                                        
                                        def code(d1, d2, d3, d4):
                                        	return d1 * (((d2 - d3) + d4) - d1)
                                        
                                        function code(d1, d2, d3, d4)
                                        	return Float64(d1 * Float64(Float64(Float64(d2 - d3) + d4) - d1))
                                        end
                                        
                                        function tmp = code(d1, d2, d3, d4)
                                        	tmp = d1 * (((d2 - d3) + d4) - d1);
                                        end
                                        
                                        code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)
                                        \end{array}
                                        

                                        Reproduce

                                        ?
                                        herbie shell --seed 2025010 
                                        (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)))