FastMath dist4

Percentage Accurate: 87.8% → 98.4%
Time: 6.8s
Alternatives: 15
Speedup: 0.6×

Specification

?
\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4):
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
end
function tmp = code(d1, d2, d3, d4)
	tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 87.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: 98.4% 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(d4 - d1\right) - d3\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))
   (* (- (- d4 d1) d3) 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 = ((d4 - d1) - d3) * 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(d4 - d1) - d3) * 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[(d4 - d1), $MachinePrecision] - d3), $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(d4 - d1\right) - d3\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 d2 around 0

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
      11. lower--.f6491.4

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

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

Alternative 2: 31.4% accurate, 0.7× 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:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) INFINITY)
   (* d2 d1)
   (* 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 = d2 * d1;
	} else {
		tmp = d1 * d1;
	}
	return tmp;
}
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= Double.POSITIVE_INFINITY) {
		tmp = d2 * d1;
	} else {
		tmp = d1 * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if ((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= math.inf:
		tmp = d2 * d1
	else:
		tmp = 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 = Float64(d2 * d1);
	else
		tmp = Float64(d1 * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= Inf)
		tmp = d2 * d1;
	else
		tmp = d1 * d1;
	end
	tmp_2 = 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[(d2 * d1), $MachinePrecision], N[(d1 * 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:\\
\;\;\;\;d2 \cdot d1\\

\mathbf{else}:\\
\;\;\;\;d1 \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)} \]
    5. Taylor expanded in d2 around inf

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

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

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

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

    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 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.f6454.4

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

      \[\leadsto \color{blue}{\left(-d1\right) \cdot d1} \]
    6. Step-by-step derivation
      1. Applied rewrites42.9%

        \[\leadsto \color{blue}{d1 \cdot d1} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification29.0%

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

    Alternative 3: 70.8% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -7.2 \cdot 10^{+29}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 7.2 \cdot 10^{-259}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+22}:\\ \;\;\;\;\left(d2 - 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 -7.2e+29)
       (* (- d2 d3) d1)
       (if (<= d3 7.2e-259)
         (* (- d4 d1) d1)
         (if (<= d3 9.2e+22) (* (- d2 d1) d1) (* (- d4 d3) d1)))))
    double code(double d1, double d2, double d3, double d4) {
    	double tmp;
    	if (d3 <= -7.2e+29) {
    		tmp = (d2 - d3) * d1;
    	} else if (d3 <= 7.2e-259) {
    		tmp = (d4 - d1) * d1;
    	} else if (d3 <= 9.2e+22) {
    		tmp = (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 <= (-7.2d+29)) then
            tmp = (d2 - d3) * d1
        else if (d3 <= 7.2d-259) then
            tmp = (d4 - d1) * d1
        else if (d3 <= 9.2d+22) then
            tmp = (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 <= -7.2e+29) {
    		tmp = (d2 - d3) * d1;
    	} else if (d3 <= 7.2e-259) {
    		tmp = (d4 - d1) * d1;
    	} else if (d3 <= 9.2e+22) {
    		tmp = (d2 - d1) * d1;
    	} else {
    		tmp = (d4 - d3) * d1;
    	}
    	return tmp;
    }
    
    def code(d1, d2, d3, d4):
    	tmp = 0
    	if d3 <= -7.2e+29:
    		tmp = (d2 - d3) * d1
    	elif d3 <= 7.2e-259:
    		tmp = (d4 - d1) * d1
    	elif d3 <= 9.2e+22:
    		tmp = (d2 - d1) * d1
    	else:
    		tmp = (d4 - d3) * d1
    	return tmp
    
    function code(d1, d2, d3, d4)
    	tmp = 0.0
    	if (d3 <= -7.2e+29)
    		tmp = Float64(Float64(d2 - d3) * d1);
    	elseif (d3 <= 7.2e-259)
    		tmp = Float64(Float64(d4 - d1) * d1);
    	elseif (d3 <= 9.2e+22)
    		tmp = Float64(Float64(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 <= -7.2e+29)
    		tmp = (d2 - d3) * d1;
    	elseif (d3 <= 7.2e-259)
    		tmp = (d4 - d1) * d1;
    	elseif (d3 <= 9.2e+22)
    		tmp = (d2 - d1) * d1;
    	else
    		tmp = (d4 - d3) * d1;
    	end
    	tmp_2 = tmp;
    end
    
    code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -7.2e+29], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 7.2e-259], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 9.2e+22], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d3 \leq -7.2 \cdot 10^{+29}:\\
    \;\;\;\;\left(d2 - d3\right) \cdot d1\\
    
    \mathbf{elif}\;d3 \leq 7.2 \cdot 10^{-259}:\\
    \;\;\;\;\left(d4 - d1\right) \cdot d1\\
    
    \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+22}:\\
    \;\;\;\;\left(d2 - d1\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(d4 - d3\right) \cdot d1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if d3 < -7.19999999999999952e29

      1. Initial program 82.8%

        \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
      2. Add Preprocessing
      3. Taylor expanded in d4 around 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--.f6484.3

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

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

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

        if -7.19999999999999952e29 < d3 < 7.1999999999999996e-259

        1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 7.1999999999999996e-259 < d3 < 9.2000000000000008e22

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

              \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
          5. Applied rewrites73.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 rewrites72.3%

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

            if 9.2000000000000008e22 < 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-+.f6494.3

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

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

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

            Alternative 4: 70.6% accurate, 1.1× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.7 \cdot 10^{+78}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq -1100000000:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+22}:\\ \;\;\;\;\left(d2 - 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.7e+78)
               (* (- d2 d3) d1)
               (if (<= d3 -1100000000.0)
                 (* (+ d2 d4) d1)
                 (if (<= d3 9.2e+22) (* (- d2 d1) d1) (* (- d4 d3) d1)))))
            double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if (d3 <= -2.7e+78) {
            		tmp = (d2 - d3) * d1;
            	} else if (d3 <= -1100000000.0) {
            		tmp = (d2 + d4) * d1;
            	} else if (d3 <= 9.2e+22) {
            		tmp = (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.7d+78)) then
                    tmp = (d2 - d3) * d1
                else if (d3 <= (-1100000000.0d0)) then
                    tmp = (d2 + d4) * d1
                else if (d3 <= 9.2d+22) then
                    tmp = (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.7e+78) {
            		tmp = (d2 - d3) * d1;
            	} else if (d3 <= -1100000000.0) {
            		tmp = (d2 + d4) * d1;
            	} else if (d3 <= 9.2e+22) {
            		tmp = (d2 - d1) * d1;
            	} else {
            		tmp = (d4 - d3) * d1;
            	}
            	return tmp;
            }
            
            def code(d1, d2, d3, d4):
            	tmp = 0
            	if d3 <= -2.7e+78:
            		tmp = (d2 - d3) * d1
            	elif d3 <= -1100000000.0:
            		tmp = (d2 + d4) * d1
            	elif d3 <= 9.2e+22:
            		tmp = (d2 - d1) * d1
            	else:
            		tmp = (d4 - d3) * d1
            	return tmp
            
            function code(d1, d2, d3, d4)
            	tmp = 0.0
            	if (d3 <= -2.7e+78)
            		tmp = Float64(Float64(d2 - d3) * d1);
            	elseif (d3 <= -1100000000.0)
            		tmp = Float64(Float64(d2 + d4) * d1);
            	elseif (d3 <= 9.2e+22)
            		tmp = Float64(Float64(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.7e+78)
            		tmp = (d2 - d3) * d1;
            	elseif (d3 <= -1100000000.0)
            		tmp = (d2 + d4) * d1;
            	elseif (d3 <= 9.2e+22)
            		tmp = (d2 - d1) * d1;
            	else
            		tmp = (d4 - d3) * d1;
            	end
            	tmp_2 = tmp;
            end
            
            code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -2.7e+78], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, -1100000000.0], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 9.2e+22], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;d3 \leq -2.7 \cdot 10^{+78}:\\
            \;\;\;\;\left(d2 - d3\right) \cdot d1\\
            
            \mathbf{elif}\;d3 \leq -1100000000:\\
            \;\;\;\;\left(d2 + d4\right) \cdot d1\\
            
            \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+22}:\\
            \;\;\;\;\left(d2 - d1\right) \cdot d1\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(d4 - d3\right) \cdot d1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 4 regimes
            2. if d3 < -2.70000000000000004e78

              1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

                if -2.70000000000000004e78 < d3 < -1.1e9

                1. Initial program 84.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-+.f6484.5

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

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

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

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

                  if -1.1e9 < d3 < 9.2000000000000008e22

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

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

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

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

                    if 9.2000000000000008e22 < 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-+.f6494.3

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

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

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

                    Alternative 5: 39.1% accurate, 1.2× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 4.4 \cdot 10^{-299}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{-224}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{+24}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                    (FPCore (d1 d2 d3 d4)
                     :precision binary64
                     (if (<= d4 4.4e-299)
                       (* d2 d1)
                       (if (<= d4 4.5e-224)
                         (* (- d3) d1)
                         (if (<= d4 7e+24) (* (- d1) d1) (* d4 d1)))))
                    double code(double d1, double d2, double d3, double d4) {
                    	double tmp;
                    	if (d4 <= 4.4e-299) {
                    		tmp = d2 * d1;
                    	} else if (d4 <= 4.5e-224) {
                    		tmp = -d3 * d1;
                    	} else if (d4 <= 7e+24) {
                    		tmp = -d1 * 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 (d4 <= 4.4d-299) then
                            tmp = d2 * d1
                        else if (d4 <= 4.5d-224) then
                            tmp = -d3 * d1
                        else if (d4 <= 7d+24) then
                            tmp = -d1 * 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 (d4 <= 4.4e-299) {
                    		tmp = d2 * d1;
                    	} else if (d4 <= 4.5e-224) {
                    		tmp = -d3 * d1;
                    	} else if (d4 <= 7e+24) {
                    		tmp = -d1 * d1;
                    	} else {
                    		tmp = d4 * d1;
                    	}
                    	return tmp;
                    }
                    
                    def code(d1, d2, d3, d4):
                    	tmp = 0
                    	if d4 <= 4.4e-299:
                    		tmp = d2 * d1
                    	elif d4 <= 4.5e-224:
                    		tmp = -d3 * d1
                    	elif d4 <= 7e+24:
                    		tmp = -d1 * d1
                    	else:
                    		tmp = d4 * d1
                    	return tmp
                    
                    function code(d1, d2, d3, d4)
                    	tmp = 0.0
                    	if (d4 <= 4.4e-299)
                    		tmp = Float64(d2 * d1);
                    	elseif (d4 <= 4.5e-224)
                    		tmp = Float64(Float64(-d3) * d1);
                    	elseif (d4 <= 7e+24)
                    		tmp = Float64(Float64(-d1) * d1);
                    	else
                    		tmp = Float64(d4 * d1);
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(d1, d2, d3, d4)
                    	tmp = 0.0;
                    	if (d4 <= 4.4e-299)
                    		tmp = d2 * d1;
                    	elseif (d4 <= 4.5e-224)
                    		tmp = -d3 * d1;
                    	elseif (d4 <= 7e+24)
                    		tmp = -d1 * d1;
                    	else
                    		tmp = d4 * d1;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 4.4e-299], N[(d2 * d1), $MachinePrecision], If[LessEqual[d4, 4.5e-224], N[((-d3) * d1), $MachinePrecision], If[LessEqual[d4, 7e+24], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;d4 \leq 4.4 \cdot 10^{-299}:\\
                    \;\;\;\;d2 \cdot d1\\
                    
                    \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{-224}:\\
                    \;\;\;\;\left(-d3\right) \cdot d1\\
                    
                    \mathbf{elif}\;d4 \leq 7 \cdot 10^{+24}:\\
                    \;\;\;\;\left(-d1\right) \cdot d1\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;d4 \cdot d1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 4 regimes
                    2. if d4 < 4.3999999999999999e-299

                      1. Initial program 86.1%

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

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

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

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

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

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

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

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

                      if 4.3999999999999999e-299 < d4 < 4.5000000000000004e-224

                      1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if 4.5000000000000004e-224 < d4 < 7.0000000000000004e24

                          1. Initial program 88.2%

                            \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                          2. Add Preprocessing
                          3. Taylor expanded in 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.f6445.3

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

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

                          if 7.0000000000000004e24 < d4

                          1. Initial program 84.3%

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

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

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

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

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

                          \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 4.4 \cdot 10^{-299}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{-224}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{+24}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                        6. Add Preprocessing

                        Alternative 6: 87.1% accurate, 1.2× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d1 \leq -4.5 \cdot 10^{+157} \lor \neg \left(d1 \leq 1.3 \cdot 10^{+29}\right):\\ \;\;\;\;\left(\left(-d3\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 (or (<= d1 -4.5e+157) (not (<= d1 1.3e+29)))
                           (* (- (- d3) d1) d1)
                           (* (- (+ d4 d2) d3) d1)))
                        double code(double d1, double d2, double d3, double d4) {
                        	double tmp;
                        	if ((d1 <= -4.5e+157) || !(d1 <= 1.3e+29)) {
                        		tmp = (-d3 - d1) * d1;
                        	} else {
                        		tmp = ((d4 + d2) - 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 ((d1 <= (-4.5d+157)) .or. (.not. (d1 <= 1.3d+29))) then
                                tmp = (-d3 - d1) * d1
                            else
                                tmp = ((d4 + d2) - d3) * d1
                            end if
                            code = tmp
                        end function
                        
                        public static double code(double d1, double d2, double d3, double d4) {
                        	double tmp;
                        	if ((d1 <= -4.5e+157) || !(d1 <= 1.3e+29)) {
                        		tmp = (-d3 - d1) * d1;
                        	} else {
                        		tmp = ((d4 + d2) - d3) * d1;
                        	}
                        	return tmp;
                        }
                        
                        def code(d1, d2, d3, d4):
                        	tmp = 0
                        	if (d1 <= -4.5e+157) or not (d1 <= 1.3e+29):
                        		tmp = (-d3 - d1) * d1
                        	else:
                        		tmp = ((d4 + d2) - d3) * d1
                        	return tmp
                        
                        function code(d1, d2, d3, d4)
                        	tmp = 0.0
                        	if ((d1 <= -4.5e+157) || !(d1 <= 1.3e+29))
                        		tmp = Float64(Float64(Float64(-d3) - d1) * d1);
                        	else
                        		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(d1, d2, d3, d4)
                        	tmp = 0.0;
                        	if ((d1 <= -4.5e+157) || ~((d1 <= 1.3e+29)))
                        		tmp = (-d3 - d1) * d1;
                        	else
                        		tmp = ((d4 + d2) - d3) * d1;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -4.5e+157], N[Not[LessEqual[d1, 1.3e+29]], $MachinePrecision]], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;d1 \leq -4.5 \cdot 10^{+157} \lor \neg \left(d1 \leq 1.3 \cdot 10^{+29}\right):\\
                        \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if d1 < -4.49999999999999985e157 or 1.3e29 < d1

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

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

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

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

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

                            if -4.49999999999999985e157 < d1 < 1.3e29

                            1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

                          Alternative 7: 63.0% accurate, 1.3× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.7 \cdot 10^{-233}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 2.15 \cdot 10^{+24}:\\ \;\;\;\;\left(\left(-d3\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 (<= d4 1.7e-233)
                             (* (- d2 d3) d1)
                             (if (<= d4 2.15e+24) (* (- (- d3) d1) d1) (* (- d4 d3) d1))))
                          double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d4 <= 1.7e-233) {
                          		tmp = (d2 - d3) * d1;
                          	} else if (d4 <= 2.15e+24) {
                          		tmp = (-d3 - 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 (d4 <= 1.7d-233) then
                                  tmp = (d2 - d3) * d1
                              else if (d4 <= 2.15d+24) then
                                  tmp = (-d3 - 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 (d4 <= 1.7e-233) {
                          		tmp = (d2 - d3) * d1;
                          	} else if (d4 <= 2.15e+24) {
                          		tmp = (-d3 - d1) * d1;
                          	} else {
                          		tmp = (d4 - d3) * d1;
                          	}
                          	return tmp;
                          }
                          
                          def code(d1, d2, d3, d4):
                          	tmp = 0
                          	if d4 <= 1.7e-233:
                          		tmp = (d2 - d3) * d1
                          	elif d4 <= 2.15e+24:
                          		tmp = (-d3 - d1) * d1
                          	else:
                          		tmp = (d4 - d3) * d1
                          	return tmp
                          
                          function code(d1, d2, d3, d4)
                          	tmp = 0.0
                          	if (d4 <= 1.7e-233)
                          		tmp = Float64(Float64(d2 - d3) * d1);
                          	elseif (d4 <= 2.15e+24)
                          		tmp = Float64(Float64(Float64(-d3) - 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 (d4 <= 1.7e-233)
                          		tmp = (d2 - d3) * d1;
                          	elseif (d4 <= 2.15e+24)
                          		tmp = (-d3 - d1) * d1;
                          	else
                          		tmp = (d4 - d3) * d1;
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 1.7e-233], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 2.15e+24], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;d4 \leq 1.7 \cdot 10^{-233}:\\
                          \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                          
                          \mathbf{elif}\;d4 \leq 2.15 \cdot 10^{+24}:\\
                          \;\;\;\;\left(\left(-d3\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 d4 < 1.7000000000000001e-233

                            1. Initial program 86.3%

                              \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                            2. Add Preprocessing
                            3. Taylor expanded in 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--.f6481.8

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

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

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

                              if 1.7000000000000001e-233 < d4 < 2.14999999999999994e24

                              1. Initial program 88.2%

                                \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                              2. Add Preprocessing
                              3. Taylor expanded in d4 around 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--.f6494.1

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

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

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

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

                                if 2.14999999999999994e24 < d4

                                1. Initial program 84.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-+.f6488.5

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

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

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

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

                                Alternative 8: 70.5% accurate, 1.4× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1950000000 \lor \neg \left(d3 \leq 9.2 \cdot 10^{+22}\right):\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \end{array} \end{array} \]
                                (FPCore (d1 d2 d3 d4)
                                 :precision binary64
                                 (if (or (<= d3 -1950000000.0) (not (<= d3 9.2e+22)))
                                   (* (- d4 d3) d1)
                                   (* (- d2 d1) d1)))
                                double code(double d1, double d2, double d3, double d4) {
                                	double tmp;
                                	if ((d3 <= -1950000000.0) || !(d3 <= 9.2e+22)) {
                                		tmp = (d4 - d3) * d1;
                                	} else {
                                		tmp = (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 <= (-1950000000.0d0)) .or. (.not. (d3 <= 9.2d+22))) then
                                        tmp = (d4 - d3) * d1
                                    else
                                        tmp = (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 <= -1950000000.0) || !(d3 <= 9.2e+22)) {
                                		tmp = (d4 - d3) * d1;
                                	} else {
                                		tmp = (d2 - d1) * d1;
                                	}
                                	return tmp;
                                }
                                
                                def code(d1, d2, d3, d4):
                                	tmp = 0
                                	if (d3 <= -1950000000.0) or not (d3 <= 9.2e+22):
                                		tmp = (d4 - d3) * d1
                                	else:
                                		tmp = (d2 - d1) * d1
                                	return tmp
                                
                                function code(d1, d2, d3, d4)
                                	tmp = 0.0
                                	if ((d3 <= -1950000000.0) || !(d3 <= 9.2e+22))
                                		tmp = Float64(Float64(d4 - d3) * d1);
                                	else
                                		tmp = Float64(Float64(d2 - d1) * d1);
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(d1, d2, d3, d4)
                                	tmp = 0.0;
                                	if ((d3 <= -1950000000.0) || ~((d3 <= 9.2e+22)))
                                		tmp = (d4 - d3) * d1;
                                	else
                                		tmp = (d2 - d1) * d1;
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1950000000.0], N[Not[LessEqual[d3, 9.2e+22]], $MachinePrecision]], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                \mathbf{if}\;d3 \leq -1950000000 \lor \neg \left(d3 \leq 9.2 \cdot 10^{+22}\right):\\
                                \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if d3 < -1.95e9 or 9.2000000000000008e22 < d3

                                  1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

                                    if -1.95e9 < d3 < 9.2000000000000008e22

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

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

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

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

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

                                    Alternative 9: 72.0% accurate, 1.4× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.8 \cdot 10^{+52} \lor \neg \left(d3 \leq 2.6 \cdot 10^{+79}\right):\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \end{array} \]
                                    (FPCore (d1 d2 d3 d4)
                                     :precision binary64
                                     (if (or (<= d3 -1.8e+52) (not (<= d3 2.6e+79)))
                                       (* (- d4 d3) d1)
                                       (* (+ d2 d4) d1)))
                                    double code(double d1, double d2, double d3, double d4) {
                                    	double tmp;
                                    	if ((d3 <= -1.8e+52) || !(d3 <= 2.6e+79)) {
                                    		tmp = (d4 - d3) * d1;
                                    	} else {
                                    		tmp = (d2 + 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 ((d3 <= (-1.8d+52)) .or. (.not. (d3 <= 2.6d+79))) then
                                            tmp = (d4 - d3) * d1
                                        else
                                            tmp = (d2 + d4) * d1
                                        end if
                                        code = tmp
                                    end function
                                    
                                    public static double code(double d1, double d2, double d3, double d4) {
                                    	double tmp;
                                    	if ((d3 <= -1.8e+52) || !(d3 <= 2.6e+79)) {
                                    		tmp = (d4 - d3) * d1;
                                    	} else {
                                    		tmp = (d2 + d4) * d1;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(d1, d2, d3, d4):
                                    	tmp = 0
                                    	if (d3 <= -1.8e+52) or not (d3 <= 2.6e+79):
                                    		tmp = (d4 - d3) * d1
                                    	else:
                                    		tmp = (d2 + d4) * d1
                                    	return tmp
                                    
                                    function code(d1, d2, d3, d4)
                                    	tmp = 0.0
                                    	if ((d3 <= -1.8e+52) || !(d3 <= 2.6e+79))
                                    		tmp = Float64(Float64(d4 - d3) * d1);
                                    	else
                                    		tmp = Float64(Float64(d2 + d4) * d1);
                                    	end
                                    	return tmp
                                    end
                                    
                                    function tmp_2 = code(d1, d2, d3, d4)
                                    	tmp = 0.0;
                                    	if ((d3 <= -1.8e+52) || ~((d3 <= 2.6e+79)))
                                    		tmp = (d4 - d3) * d1;
                                    	else
                                    		tmp = (d2 + d4) * d1;
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1.8e+52], N[Not[LessEqual[d3, 2.6e+79]], $MachinePrecision]], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;d3 \leq -1.8 \cdot 10^{+52} \lor \neg \left(d3 \leq 2.6 \cdot 10^{+79}\right):\\
                                    \;\;\;\;\left(d4 - d3\right) \cdot d1\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if d3 < -1.8e52 or 2.60000000000000015e79 < d3

                                      1. Initial program 81.5%

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

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

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

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

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

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

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

                                        \[\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 \]

                                        if -1.8e52 < d3 < 2.60000000000000015e79

                                        1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

                                        Alternative 10: 67.9% accurate, 1.4× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.7 \cdot 10^{+97} \lor \neg \left(d3 \leq 9.8 \cdot 10^{+123}\right):\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \end{array} \]
                                        (FPCore (d1 d2 d3 d4)
                                         :precision binary64
                                         (if (or (<= d3 -1.7e+97) (not (<= d3 9.8e+123)))
                                           (* (- d3) d1)
                                           (* (+ d2 d4) d1)))
                                        double code(double d1, double d2, double d3, double d4) {
                                        	double tmp;
                                        	if ((d3 <= -1.7e+97) || !(d3 <= 9.8e+123)) {
                                        		tmp = -d3 * d1;
                                        	} else {
                                        		tmp = (d2 + 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 ((d3 <= (-1.7d+97)) .or. (.not. (d3 <= 9.8d+123))) then
                                                tmp = -d3 * d1
                                            else
                                                tmp = (d2 + d4) * d1
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double d1, double d2, double d3, double d4) {
                                        	double tmp;
                                        	if ((d3 <= -1.7e+97) || !(d3 <= 9.8e+123)) {
                                        		tmp = -d3 * d1;
                                        	} else {
                                        		tmp = (d2 + d4) * d1;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(d1, d2, d3, d4):
                                        	tmp = 0
                                        	if (d3 <= -1.7e+97) or not (d3 <= 9.8e+123):
                                        		tmp = -d3 * d1
                                        	else:
                                        		tmp = (d2 + d4) * d1
                                        	return tmp
                                        
                                        function code(d1, d2, d3, d4)
                                        	tmp = 0.0
                                        	if ((d3 <= -1.7e+97) || !(d3 <= 9.8e+123))
                                        		tmp = Float64(Float64(-d3) * d1);
                                        	else
                                        		tmp = Float64(Float64(d2 + d4) * d1);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(d1, d2, d3, d4)
                                        	tmp = 0.0;
                                        	if ((d3 <= -1.7e+97) || ~((d3 <= 9.8e+123)))
                                        		tmp = -d3 * d1;
                                        	else
                                        		tmp = (d2 + d4) * d1;
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1.7e+97], N[Not[LessEqual[d3, 9.8e+123]], $MachinePrecision]], N[((-d3) * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;d3 \leq -1.7 \cdot 10^{+97} \lor \neg \left(d3 \leq 9.8 \cdot 10^{+123}\right):\\
                                        \;\;\;\;\left(-d3\right) \cdot d1\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if d3 < -1.70000000000000005e97 or 9.79999999999999952e123 < d3

                                          1. Initial program 79.5%

                                            \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in d4 around 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--.f6492.4

                                              \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                                          5. Applied rewrites92.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 rewrites87.8%

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

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

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

                                              if -1.70000000000000005e97 < d3 < 9.79999999999999952e123

                                              1. Initial program 89.6%

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

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

                                                  \[\leadsto \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-+.f6470.8

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

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

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

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

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

                                              Alternative 11: 39.1% accurate, 1.5× speedup?

                                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 4.4 \cdot 10^{-299}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{+88}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                                              (FPCore (d1 d2 d3 d4)
                                               :precision binary64
                                               (if (<= d4 4.4e-299) (* d2 d1) (if (<= d4 2.6e+88) (* (- d3) d1) (* d4 d1))))
                                              double code(double d1, double d2, double d3, double d4) {
                                              	double tmp;
                                              	if (d4 <= 4.4e-299) {
                                              		tmp = d2 * d1;
                                              	} else if (d4 <= 2.6e+88) {
                                              		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 (d4 <= 4.4d-299) then
                                                      tmp = d2 * d1
                                                  else if (d4 <= 2.6d+88) 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 (d4 <= 4.4e-299) {
                                              		tmp = d2 * d1;
                                              	} else if (d4 <= 2.6e+88) {
                                              		tmp = -d3 * d1;
                                              	} else {
                                              		tmp = d4 * d1;
                                              	}
                                              	return tmp;
                                              }
                                              
                                              def code(d1, d2, d3, d4):
                                              	tmp = 0
                                              	if d4 <= 4.4e-299:
                                              		tmp = d2 * d1
                                              	elif d4 <= 2.6e+88:
                                              		tmp = -d3 * d1
                                              	else:
                                              		tmp = d4 * d1
                                              	return tmp
                                              
                                              function code(d1, d2, d3, d4)
                                              	tmp = 0.0
                                              	if (d4 <= 4.4e-299)
                                              		tmp = Float64(d2 * d1);
                                              	elseif (d4 <= 2.6e+88)
                                              		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 (d4 <= 4.4e-299)
                                              		tmp = d2 * d1;
                                              	elseif (d4 <= 2.6e+88)
                                              		tmp = -d3 * d1;
                                              	else
                                              		tmp = d4 * d1;
                                              	end
                                              	tmp_2 = tmp;
                                              end
                                              
                                              code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 4.4e-299], N[(d2 * d1), $MachinePrecision], If[LessEqual[d4, 2.6e+88], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \begin{array}{l}
                                              \mathbf{if}\;d4 \leq 4.4 \cdot 10^{-299}:\\
                                              \;\;\;\;d2 \cdot d1\\
                                              
                                              \mathbf{elif}\;d4 \leq 2.6 \cdot 10^{+88}:\\
                                              \;\;\;\;\left(-d3\right) \cdot d1\\
                                              
                                              \mathbf{else}:\\
                                              \;\;\;\;d4 \cdot d1\\
                                              
                                              
                                              \end{array}
                                              \end{array}
                                              
                                              Derivation
                                              1. Split input into 3 regimes
                                              2. if d4 < 4.3999999999999999e-299

                                                1. Initial program 86.1%

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

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

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

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

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

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

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

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

                                                if 4.3999999999999999e-299 < d4 < 2.6000000000000001e88

                                                1. Initial program 88.3%

                                                  \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                                2. Add Preprocessing
                                                3. 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--.f6494.8

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

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

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

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

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

                                                    if 2.6000000000000001e88 < d4

                                                    1. Initial program 83.3%

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

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

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

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

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

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

                                                  Alternative 12: 83.5% accurate, 1.7× speedup?

                                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.8 \cdot 10^{-12}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
                                                  (FPCore (d1 d2 d3 d4)
                                                   :precision binary64
                                                   (if (<= d2 -1.8e-12) (* (- (- d2 d3) d1) d1) (* (- (- d4 d1) d3) d1)))
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d2 <= -1.8e-12) {
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	} else {
                                                  		tmp = ((d4 - d1) - 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 <= (-1.8d-12)) then
                                                          tmp = ((d2 - d3) - d1) * d1
                                                      else
                                                          tmp = ((d4 - d1) - d3) * d1
                                                      end if
                                                      code = tmp
                                                  end function
                                                  
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d2 <= -1.8e-12) {
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	} else {
                                                  		tmp = ((d4 - d1) - d3) * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  def code(d1, d2, d3, d4):
                                                  	tmp = 0
                                                  	if d2 <= -1.8e-12:
                                                  		tmp = ((d2 - d3) - d1) * d1
                                                  	else:
                                                  		tmp = ((d4 - d1) - d3) * d1
                                                  	return tmp
                                                  
                                                  function code(d1, d2, d3, d4)
                                                  	tmp = 0.0
                                                  	if (d2 <= -1.8e-12)
                                                  		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                                                  	else
                                                  		tmp = Float64(Float64(Float64(d4 - d1) - d3) * d1);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  function tmp_2 = code(d1, d2, d3, d4)
                                                  	tmp = 0.0;
                                                  	if (d2 <= -1.8e-12)
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	else
                                                  		tmp = ((d4 - d1) - d3) * d1;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e-12], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;d2 \leq -1.8 \cdot 10^{-12}:\\
                                                  \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if d2 < -1.8e-12

                                                    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

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

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

                                                    if -1.8e-12 < d2

                                                    1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  Alternative 13: 84.9% accurate, 1.7× speedup?

                                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 9.5 \cdot 10^{+21}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
                                                  (FPCore (d1 d2 d3 d4)
                                                   :precision binary64
                                                   (if (<= d4 9.5e+21) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d4 <= 9.5e+21) {
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	} else {
                                                  		tmp = ((d4 + d2) - 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 (d4 <= 9.5d+21) then
                                                          tmp = ((d2 - d3) - d1) * d1
                                                      else
                                                          tmp = ((d4 + d2) - d3) * d1
                                                      end if
                                                      code = tmp
                                                  end function
                                                  
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d4 <= 9.5e+21) {
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	} else {
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  def code(d1, d2, d3, d4):
                                                  	tmp = 0
                                                  	if d4 <= 9.5e+21:
                                                  		tmp = ((d2 - d3) - d1) * d1
                                                  	else:
                                                  		tmp = ((d4 + d2) - d3) * d1
                                                  	return tmp
                                                  
                                                  function code(d1, d2, d3, d4)
                                                  	tmp = 0.0
                                                  	if (d4 <= 9.5e+21)
                                                  		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                                                  	else
                                                  		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  function tmp_2 = code(d1, d2, d3, d4)
                                                  	tmp = 0.0;
                                                  	if (d4 <= 9.5e+21)
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	else
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 9.5e+21], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;d4 \leq 9.5 \cdot 10^{+21}:\\
                                                  \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if d4 < 9.500000000000001e21

                                                    1. Initial program 87.2%

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

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

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

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

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

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

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

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

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

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

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

                                                    if 9.500000000000001e21 < d4

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

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

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

                                                  Alternative 14: 38.2% accurate, 2.5× speedup?

                                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.8 \cdot 10^{-12}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                                                  (FPCore (d1 d2 d3 d4)
                                                   :precision binary64
                                                   (if (<= d2 -1.8e-12) (* d2 d1) (* d4 d1)))
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d2 <= -1.8e-12) {
                                                  		tmp = d2 * 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 <= (-1.8d-12)) then
                                                          tmp = d2 * 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 <= -1.8e-12) {
                                                  		tmp = d2 * d1;
                                                  	} else {
                                                  		tmp = d4 * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  def code(d1, d2, d3, d4):
                                                  	tmp = 0
                                                  	if d2 <= -1.8e-12:
                                                  		tmp = d2 * d1
                                                  	else:
                                                  		tmp = d4 * d1
                                                  	return tmp
                                                  
                                                  function code(d1, d2, d3, d4)
                                                  	tmp = 0.0
                                                  	if (d2 <= -1.8e-12)
                                                  		tmp = Float64(d2 * d1);
                                                  	else
                                                  		tmp = Float64(d4 * d1);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  function tmp_2 = code(d1, d2, d3, d4)
                                                  	tmp = 0.0;
                                                  	if (d2 <= -1.8e-12)
                                                  		tmp = d2 * d1;
                                                  	else
                                                  		tmp = d4 * d1;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e-12], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;d2 \leq -1.8 \cdot 10^{-12}:\\
                                                  \;\;\;\;d2 \cdot d1\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;d4 \cdot d1\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if d2 < -1.8e-12

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

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

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

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

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

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

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

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

                                                    if -1.8e-12 < d2

                                                    1. Initial program 85.9%

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

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

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

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

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

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

                                                  Alternative 15: 30.9% accurate, 5.0× speedup?

                                                  \[\begin{array}{l} \\ d2 \cdot d1 \end{array} \]
                                                  (FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	return d2 * 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 = d2 * d1
                                                  end function
                                                  
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	return d2 * d1;
                                                  }
                                                  
                                                  def code(d1, d2, d3, d4):
                                                  	return d2 * d1
                                                  
                                                  function code(d1, d2, d3, d4)
                                                  	return Float64(d2 * d1)
                                                  end
                                                  
                                                  function tmp = code(d1, d2, d3, d4)
                                                  	tmp = d2 * d1;
                                                  end
                                                  
                                                  code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
                                                  
                                                  \begin{array}{l}
                                                  
                                                  \\
                                                  d2 \cdot d1
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Initial program 86.3%

                                                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                                  2. Add Preprocessing
                                                  3. 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--.f6493.3

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

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

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

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

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

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

                                                    \[\leadsto \color{blue}{d2 \cdot d1} \]
                                                  8. Final simplification26.5%

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

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

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

                                                  Reproduce

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