FastMath dist4

Percentage Accurate: 87.9% → 100.0%
Time: 3.8s
Alternatives: 11
Speedup: 1.7×

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 11 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: 100.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \left(\left(\mathsf{fma}\left(-1, d1, d4\right) + d2\right) - d3\right) \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (* (- (+ (fma -1.0 d1 d4) d2) d3) d1))
double code(double d1, double d2, double d3, double d4) {
	return ((fma(-1.0, d1, d4) + d2) - d3) * d1;
}
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(fma(-1.0, d1, d4) + d2) - d3) * d1)
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(-1.0 * d1 + d4), $MachinePrecision] + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(\mathsf{fma}\left(-1, d1, d4\right) + d2\right) - d3\right) \cdot d1
\end{array}
Derivation
  1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(\left(\mathsf{fma}\left(-1, d1, d4\right) + d2\right) - d3\right) \cdot d1} \]
  6. Add Preprocessing

Alternative 2: 89.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d1 \leq -2.9 \cdot 10^{+121} \lor \neg \left(d1 \leq 2.15 \cdot 10^{+105}\right):\\ \;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d1 -2.9e+121) (not (<= d1 2.15e+105)))
   (* (- (- d1) d3) d1)
   (fma (- d2 d3) d1 (* d4 d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d1 <= -2.9e+121) || !(d1 <= 2.15e+105)) {
		tmp = (-d1 - d3) * d1;
	} else {
		tmp = fma((d2 - d3), d1, (d4 * d1));
	}
	return tmp;
}
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d1 <= -2.9e+121) || !(d1 <= 2.15e+105))
		tmp = Float64(Float64(Float64(-d1) - d3) * d1);
	else
		tmp = fma(Float64(d2 - d3), d1, Float64(d4 * d1));
	end
	return tmp
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -2.9e+121], N[Not[LessEqual[d1, 2.15e+105]], $MachinePrecision]], N[(N[((-d1) - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d4 * d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -2.9 \cdot 10^{+121} \lor \neg \left(d1 \leq 2.15 \cdot 10^{+105}\right):\\
\;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -2.8999999999999999e121 or 2.1500000000000001e105 < d1

    1. Initial program 60.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(-1 \cdot d1 - d3\right) \cdot d1 \]
    7. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(d1\right)\right) - d3\right) \cdot d1 \]
      2. lift-neg.f6486.5

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

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

    if -2.8999999999999999e121 < d1 < 2.1500000000000001e105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 89.2% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -2.9 \cdot 10^{+121} \lor \neg \left(d1 \leq 2.7 \cdot 10^{+105}\right):\\
\;\;\;\;\left(\left(-d1\right) - d3\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 < -2.8999999999999999e121 or 2.70000000000000016e105 < d1

    1. Initial program 60.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(-1 \cdot d1 - d3\right) \cdot d1 \]
    7. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(d1\right)\right) - d3\right) \cdot d1 \]
      2. lift-neg.f6486.5

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

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

    if -2.8999999999999999e121 < d1 < 2.70000000000000016e105

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

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

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

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

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

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

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

Alternative 4: 63.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -62000:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\

\mathbf{elif}\;d2 \leq -8.8 \cdot 10^{-160}:\\
\;\;\;\;\left(\left(-d1\right) - d3\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 < -62000

    1. Initial program 78.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 + \left(d4 + -1 \cdot d1\right)\right) - d3\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

      if -62000 < d2 < -8.8e-160

      1. Initial program 93.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot d1 - d3\right) \cdot d1 \]
      7. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(d1\right)\right) - d3\right) \cdot d1 \]
        2. lift-neg.f6472.4

          \[\leadsto \left(\left(-d1\right) - d3\right) \cdot d1 \]
      8. Applied rewrites72.4%

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

      if -8.8e-160 < d2

      1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 5: 68.5% accurate, 1.4× speedup?

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

        1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

        if -3.35000000000000007e108 < d3 < 8.00000000000000041e142

        1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left(d4 + d2\right) \cdot d1 \]
      3. Recombined 2 regimes into one program.
      4. Final simplification73.4%

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

      Alternative 6: 39.5% accurate, 1.5× speedup?

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

        1. Initial program 88.4%

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

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

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

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

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

        if -4.29999999999999976e-288 < d4 < 5.2e52

        1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

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

        if 5.2e52 < d4

        1. Initial program 81.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 d4 \cdot \color{blue}{d1} \]
          2. lift-*.f6455.1

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

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

      Alternative 7: 39.8% accurate, 1.5× speedup?

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

        1. Initial program 78.3%

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

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

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

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

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

        if -235000 < d2 < -1.9499999999999999e-244

        1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

        if -1.9499999999999999e-244 < d2

        1. Initial program 89.6%

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

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

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

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

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

      Alternative 8: 63.8% accurate, 2.0× speedup?

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

        1. Initial program 78.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 + \left(d4 + -1 \cdot d1\right)\right) - d3\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

          if -9.2000000000000003e-4 < d2

          1. Initial program 90.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 + \left(d4 + -1 \cdot d1\right)\right) - d3\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

          Alternative 9: 64.1% accurate, 2.0× speedup?

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

            1. Initial program 89.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 + \left(d4 + -1 \cdot d1\right)\right) - d3\right)} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

              if 5.2e52 < d4

              1. Initial program 81.0%

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 10: 39.1% accurate, 2.5× speedup?

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

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

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

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

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

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

              if -8.1999999999999998e-4 < d2

              1. Initial program 90.2%

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

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

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

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

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

            Alternative 11: 31.2% 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 87.5%

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

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

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

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

              \[\leadsto \color{blue}{d2 \cdot d1} \]
            6. Add Preprocessing

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

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

            Reproduce

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