FastMath dist4

Percentage Accurate: 88.3% → 100.0%
Time: 3.2s
Alternatives: 10
Speedup: 1.6×

Specification

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

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

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

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

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 10 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: 88.3% 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.6× speedup?

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

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

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

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

      \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
    8. mul-1-negN/A

      \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
    9. lower-neg.f64100.0

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

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

Alternative 2: 84.4% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 5500000000000:\\ \;\;\;\;\left(\left(d2 - d1\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 (<= d4 5500000000000.0) (* (- (- d2 d1) d3) d1) (* (- (- d4 d1) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 5500000000000.0) {
		tmp = ((d2 - d1) - 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 (d4 <= 5500000000000.0d0) then
        tmp = ((d2 - d1) - 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 (d4 <= 5500000000000.0) {
		tmp = ((d2 - d1) - d3) * d1;
	} else {
		tmp = ((d4 - d1) - d3) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d4 <= 5500000000000.0:
		tmp = ((d2 - d1) - d3) * d1
	else:
		tmp = ((d4 - d1) - d3) * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 5500000000000.0)
		tmp = Float64(Float64(Float64(d2 - d1) - 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 (d4 <= 5500000000000.0)
		tmp = ((d2 - d1) - d3) * d1;
	else
		tmp = ((d4 - d1) - d3) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 5500000000000.0], N[(N[(N[(d2 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 5500000000000:\\
\;\;\;\;\left(\left(d2 - d1\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 d4 < 5.5e12

    1. Initial program 89.6%

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

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

        \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
      8. mul-1-negN/A

        \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
      9. lower-neg.f64100.0

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

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

      \[\leadsto \left(\left(d2 - d1\right) - d3\right) \cdot d1 \]
    6. Step-by-step derivation
      1. lower--.f6484.5

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

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

    if 5.5e12 < d4

    1. Initial program 84.4%

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

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

        \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
      8. mul-1-negN/A

        \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
      9. lower-neg.f64100.0

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

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

      \[\leadsto \left(\left(d4 - d1\right) - d3\right) \cdot d1 \]
    6. Step-by-step derivation
      1. lower--.f6483.9

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

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

Alternative 3: 83.4% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 5.5 \cdot 10^{+98}:\\
\;\;\;\;\left(\left(d2 - d1\right) - 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 d4 < 5.49999999999999946e98

    1. Initial program 89.5%

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

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

        \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
      8. mul-1-negN/A

        \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
      9. lower-neg.f64100.0

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

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

      \[\leadsto \left(\left(d2 - d1\right) - d3\right) \cdot d1 \]
    6. Step-by-step derivation
      1. lower--.f6484.0

        \[\leadsto \left(\left(d2 - d1\right) - d3\right) \cdot d1 \]
    7. Applied rewrites84.0%

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

    if 5.49999999999999946e98 < d4

    1. Initial program 82.4%

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

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

        \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
      8. mul-1-negN/A

        \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
      9. lower-neg.f64100.0

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

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

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

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

    Alternative 4: 64.4% accurate, 1.0× speedup?

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

      1. Initial program 88.4%

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

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

          \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
        8. mul-1-negN/A

          \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
        9. lower-neg.f64100.0

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

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

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

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

        if -2.4000000000000001e-292 < d4 < 6e51

        1. Initial program 91.3%

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

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

            \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
          8. mul-1-negN/A

            \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
          9. lower-neg.f64100.0

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

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

          \[\leadsto \left(-1 \cdot d1 - d3\right) \cdot d1 \]
        6. 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.f6466.6

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

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

        if 6e51 < d4 < 7.19999999999999963e121

        1. Initial program 88.1%

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

          \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
        3. 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-+.f6483.6

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

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

            \[\leadsto d1 \cdot \left(\left(d2 + d4\right) - d3\right) \]
          6. associate--l+N/A

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(d2, d1, \left(d4 - d3\right) \cdot d1\right) \]
          12. lower--.f6484.1

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

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

          \[\leadsto \mathsf{fma}\left(d2, d1, d4 \cdot d1\right) \]
        8. Step-by-step derivation
          1. Applied rewrites59.5%

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

          if 7.19999999999999963e121 < d4

          1. Initial program 81.6%

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

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

              \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
            8. mul-1-negN/A

              \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
            9. lower-neg.f64100.0

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

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

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

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

          Alternative 5: 63.4% accurate, 1.4× speedup?

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

            1. Initial program 88.4%

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

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

                \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
              8. mul-1-negN/A

                \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
              9. lower-neg.f64100.0

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

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

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

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

              if -2.4000000000000001e-292 < d4 < 1.1e97

              1. Initial program 91.0%

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

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

                  \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
                8. mul-1-negN/A

                  \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
                9. lower-neg.f64100.0

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

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

                \[\leadsto \left(-1 \cdot d1 - d3\right) \cdot d1 \]
              6. 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.f6465.2

                  \[\leadsto \left(\left(-d1\right) - d3\right) \cdot d1 \]
              7. Applied rewrites65.2%

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

              if 1.1e97 < d4

              1. Initial program 82.4%

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

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

                  \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
                8. mul-1-negN/A

                  \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
                9. lower-neg.f64100.0

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

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

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

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

              Alternative 6: 63.3% accurate, 2.0× speedup?

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

                1. Initial program 89.5%

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

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

                    \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
                  8. mul-1-negN/A

                    \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
                  9. lower-neg.f64100.0

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

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

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

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

                  if 7.5999999999999995e23 < d4

                  1. Initial program 84.2%

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

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

                      \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
                    8. mul-1-negN/A

                      \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
                    9. lower-neg.f64100.0

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

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

                    \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                  6. Step-by-step derivation
                    1. Applied rewrites73.4%

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

                  Alternative 7: 61.2% accurate, 2.0× speedup?

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

                    1. Initial program 89.6%

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

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

                        \[\leadsto \left(\left(\left(-1 \cdot d1 + d4\right) + d2\right) - d3\right) \cdot d1 \]
                      8. mul-1-negN/A

                        \[\leadsto \left(\left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) + d2\right) - d3\right) \cdot d1 \]
                      9. lower-neg.f64100.0

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

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

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

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

                      if 4.79999999999999979e45 < d4

                      1. Initial program 83.5%

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

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

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

                          \[\leadsto d4 \cdot \color{blue}{d1} \]
                      4. Applied rewrites58.9%

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

                    Alternative 8: 39.5% accurate, 1.7× speedup?

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

                      1. Initial program 88.3%

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

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

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

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

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

                      if -1.76e-249 < d4 < 4.80000000000000026e44

                      1. Initial program 91.2%

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

                        \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
                      3. 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.f6438.9

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

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

                      if 4.80000000000000026e44 < d4

                      1. Initial program 83.6%

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

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

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

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

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

                    Alternative 9: 39.4% accurate, 2.7× speedup?

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

                      1. Initial program 89.6%

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

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

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

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

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

                      if 9.60000000000000058e35 < d4

                      1. Initial program 83.8%

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

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

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

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

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

                    Alternative 10: 32.1% accurate, 5.3× 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 88.3%

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

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

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

                        \[\leadsto d2 \cdot \color{blue}{d1} \]
                    4. Applied rewrites32.1%

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

                    Developer Target 1: 100.0% accurate, 1.7× 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 2025120 
                    (FPCore (d1 d2 d3 d4)
                      :name "FastMath dist4"
                      :precision binary64
                    
                      :alt
                      (! :herbie-platform c (* d1 (- (+ (- d2 d3) d4) d1)))
                    
                      (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))