FastMath dist4

Percentage Accurate: 87.9% → 98.4%
Time: 6.2s
Alternatives: 13
Speedup: 1.2×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 87.9% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 98.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\\ \mathbf{if}\;t\_0 \leq \infty:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1))))
   (if (<= t_0 INFINITY) t_0 (* (- (- d4 d1) d3) d1))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
	double tmp;
	if (t_0 <= ((double) INFINITY)) {
		tmp = t_0;
	} else {
		tmp = ((d4 - d1) - d3) * d1;
	}
	return tmp;
}
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
	double tmp;
	if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = t_0;
	} else {
		tmp = ((d4 - d1) - d3) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
	tmp = 0
	if t_0 <= math.inf:
		tmp = t_0
	else:
		tmp = ((d4 - d1) - d3) * d1
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
	tmp = 0.0
	if (t_0 <= Inf)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(d4 - d1) - d3) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
	tmp = 0.0;
	if (t_0 <= Inf)
		tmp = t_0;
	else
		tmp = ((d4 - d1) - d3) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\

\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

    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. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 98.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d3, d1, d1 \cdot \left(d4 - d1\right)\right)\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 d2 d1 (fma (- d3) d1 (* d1 (- d4 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(d2, d1, fma(-d3, d1, (d1 * (d4 - 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(d2, d1, fma(Float64(-d3), d1, Float64(d1 * Float64(d4 - 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[(d2 * d1 + N[((-d3) * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $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(d2, d1, \mathsf{fma}\left(-d3, d1, d1 \cdot \left(d4 - d1\right)\right)\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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 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(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\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 (- d2 d3) d1 (* d1 (- d4 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((d2 - d3), d1, (d1 * (d4 - 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(Float64(d2 - d3), d1, Float64(d1 * Float64(d4 - 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[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $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(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 38.6% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d2 \leq -1.2 \cdot 10^{-23}:\\
\;\;\;\;\left(-d3\right) \cdot d1\\

\mathbf{elif}\;d2 \leq 2.1 \cdot 10^{-305}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -7.99999999999999986e77

    1. Initial program 85.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.99999999999999986e77 < d2 < -1.19999999999999998e-23

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

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

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

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

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

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

        if -1.19999999999999998e-23 < d2 < 2.1e-305

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

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

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

        if 2.1e-305 < d2

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -8 \cdot 10^{+77}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -1.2 \cdot 10^{-23}:\\ \;\;\;\;\left(-d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq 2.1 \cdot 10^{-305}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
      6. Add Preprocessing

      Alternative 5: 88.9% accurate, 1.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d1 \leq -1.5 \cdot 10^{+128} \lor \neg \left(d1 \leq 3.8 \cdot 10^{+69}\right):\\ \;\;\;\;\left(d4 - 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 -1.5e+128) (not (<= d1 3.8e+69)))
         (* (- d4 d1) d1)
         (* (- (+ d4 d2) d3) d1)))
      double code(double d1, double d2, double d3, double d4) {
      	double tmp;
      	if ((d1 <= -1.5e+128) || !(d1 <= 3.8e+69)) {
      		tmp = (d4 - 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 <= (-1.5d+128)) .or. (.not. (d1 <= 3.8d+69))) then
              tmp = (d4 - 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 <= -1.5e+128) || !(d1 <= 3.8e+69)) {
      		tmp = (d4 - d1) * d1;
      	} else {
      		tmp = ((d4 + d2) - d3) * d1;
      	}
      	return tmp;
      }
      
      def code(d1, d2, d3, d4):
      	tmp = 0
      	if (d1 <= -1.5e+128) or not (d1 <= 3.8e+69):
      		tmp = (d4 - d1) * d1
      	else:
      		tmp = ((d4 + d2) - d3) * d1
      	return tmp
      
      function code(d1, d2, d3, d4)
      	tmp = 0.0
      	if ((d1 <= -1.5e+128) || !(d1 <= 3.8e+69))
      		tmp = Float64(Float64(d4 - 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 <= -1.5e+128) || ~((d1 <= 3.8e+69)))
      		tmp = (d4 - d1) * d1;
      	else
      		tmp = ((d4 + d2) - d3) * d1;
      	end
      	tmp_2 = tmp;
      end
      
      code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -1.5e+128], N[Not[LessEqual[d1, 3.8e+69]], $MachinePrecision]], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d1 \leq -1.5 \cdot 10^{+128} \lor \neg \left(d1 \leq 3.8 \cdot 10^{+69}\right):\\
      \;\;\;\;\left(d4 - 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 < -1.4999999999999999e128 or 3.80000000000000028e69 < d1

        1. Initial program 69.5%

          \[\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. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -1.4999999999999999e128 < d1 < 3.80000000000000028e69

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

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

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

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

        Alternative 6: 71.7% accurate, 1.4× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -3.4 \cdot 10^{-11} \lor \neg \left(d3 \leq 2.15 \cdot 10^{+116}\right):\\ \;\;\;\;\left(d2 - 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 -3.4e-11) (not (<= d3 2.15e+116)))
           (* (- d2 d3) d1)
           (* (+ d2 d4) d1)))
        double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if ((d3 <= -3.4e-11) || !(d3 <= 2.15e+116)) {
        		tmp = (d2 - 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 <= (-3.4d-11)) .or. (.not. (d3 <= 2.15d+116))) then
                tmp = (d2 - 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 <= -3.4e-11) || !(d3 <= 2.15e+116)) {
        		tmp = (d2 - d3) * d1;
        	} else {
        		tmp = (d2 + d4) * d1;
        	}
        	return tmp;
        }
        
        def code(d1, d2, d3, d4):
        	tmp = 0
        	if (d3 <= -3.4e-11) or not (d3 <= 2.15e+116):
        		tmp = (d2 - d3) * d1
        	else:
        		tmp = (d2 + d4) * d1
        	return tmp
        
        function code(d1, d2, d3, d4)
        	tmp = 0.0
        	if ((d3 <= -3.4e-11) || !(d3 <= 2.15e+116))
        		tmp = Float64(Float64(d2 - 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 <= -3.4e-11) || ~((d3 <= 2.15e+116)))
        		tmp = (d2 - d3) * d1;
        	else
        		tmp = (d2 + d4) * d1;
        	end
        	tmp_2 = tmp;
        end
        
        code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -3.4e-11], N[Not[LessEqual[d3, 2.15e+116]], $MachinePrecision]], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;d3 \leq -3.4 \cdot 10^{-11} \lor \neg \left(d3 \leq 2.15 \cdot 10^{+116}\right):\\
        \;\;\;\;\left(d2 - 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 < -3.3999999999999999e-11 or 2.15e116 < d3

          1. Initial program 83.5%

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

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

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

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

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

              \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
            5. lower-+.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} \]
          6. Taylor expanded in d4 around 0

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

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

            if -3.3999999999999999e-11 < d3 < 2.15e116

            1. Initial program 94.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-+.f6471.9

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

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

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

            Alternative 7: 68.7% accurate, 1.4× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.7 \cdot 10^{+113} \lor \neg \left(d3 \leq 1.26 \cdot 10^{+122}\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 -2.7e+113) (not (<= d3 1.26e+122)))
               (* (- d3) d1)
               (* (+ d2 d4) d1)))
            double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if ((d3 <= -2.7e+113) || !(d3 <= 1.26e+122)) {
            		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 <= (-2.7d+113)) .or. (.not. (d3 <= 1.26d+122))) 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 <= -2.7e+113) || !(d3 <= 1.26e+122)) {
            		tmp = -d3 * d1;
            	} else {
            		tmp = (d2 + d4) * d1;
            	}
            	return tmp;
            }
            
            def code(d1, d2, d3, d4):
            	tmp = 0
            	if (d3 <= -2.7e+113) or not (d3 <= 1.26e+122):
            		tmp = -d3 * d1
            	else:
            		tmp = (d2 + d4) * d1
            	return tmp
            
            function code(d1, d2, d3, d4)
            	tmp = 0.0
            	if ((d3 <= -2.7e+113) || !(d3 <= 1.26e+122))
            		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 <= -2.7e+113) || ~((d3 <= 1.26e+122)))
            		tmp = -d3 * d1;
            	else
            		tmp = (d2 + d4) * d1;
            	end
            	tmp_2 = tmp;
            end
            
            code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -2.7e+113], N[Not[LessEqual[d3, 1.26e+122]], $MachinePrecision]], N[((-d3) * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;d3 \leq -2.7 \cdot 10^{+113} \lor \neg \left(d3 \leq 1.26 \cdot 10^{+122}\right):\\
            \;\;\;\;\left(-d3\right) \cdot d1\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(d2 + d4\right) \cdot d1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d3 < -2.70000000000000011e113 or 1.25999999999999991e122 < d3

              1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

                  if -2.70000000000000011e113 < d3 < 1.25999999999999991e122

                  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 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-+.f6474.3

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

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

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

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

                  Alternative 8: 62.9% accurate, 1.4× speedup?

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

                    1. Initial program 84.9%

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

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

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

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

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

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

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

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

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

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

                      if -2.9000000000000002e-23 < d2 < -1.4e-241

                      1. Initial program 94.6%

                        \[\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. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if -1.4e-241 < d2

                        1. Initial program 91.1%

                          \[\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. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

                            \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                          17. lower--.f6484.0

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

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

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

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

                        Alternative 9: 39.5% accurate, 1.5× speedup?

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

                          1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                          if 1.0499999999999999e-230 < d4 < 2.99999999999999982e78

                          1. Initial program 88.7%

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

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

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

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

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

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

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

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

                            \[\leadsto \left(d2 - d3\right) \cdot d1 \]
                          7. Step-by-step derivation
                            1. Applied rewrites72.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 rewrites47.5%

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

                              if 2.99999999999999982e78 < d4

                              1. Initial program 88.9%

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

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

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

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

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

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

                            Alternative 10: 84.9% accurate, 1.7× speedup?

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

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

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

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

                              if -5.5000000000000002e99 < d2

                              1. Initial program 91.1%

                                \[\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. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

                                  \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                                17. lower--.f6486.1

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

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

                            Alternative 11: 61.8% accurate, 2.0× speedup?

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

                              1. Initial program 84.9%

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

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

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

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

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

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

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

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

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

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

                                if -2.9000000000000002e-23 < d2

                                1. Initial program 91.8%

                                  \[\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. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

                                Alternative 12: 38.5% accurate, 2.5× speedup?

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

                                  1. Initial program 84.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  if -7.49999999999999984e-17 < d2

                                  1. Initial program 91.8%

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

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

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

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

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

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

                                Alternative 13: 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 89.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto \color{blue}{d2 \cdot d1} \]
                                8. Final simplification30.9%

                                  \[\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 2024352 
                                (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)))