FastMath dist4

Percentage Accurate: 87.3% → 100.0%
Time: 5.6s
Alternatives: 11
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 11 alternatives:

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

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

\\
\left(\left(\left(d4 + d2\right) + \left(-d1\right)\right) - d3\right) \cdot d1
\end{array}
Derivation
  1. Initial program 87.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. Applied rewrites100.0%

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

Alternative 2: 83.5% accurate, 1.6× speedup?

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

    1. Initial program 88.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. Applied rewrites100.0%

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

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

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

    if 4.1999999999999998e-19 < 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. Applied rewrites100.0%

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

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

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

Alternative 3: 82.9% accurate, 1.6× speedup?

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

    1. Initial program 88.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. Applied rewrites100.0%

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

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

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

    if 1.42e150 < 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. Applied rewrites100.0%

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

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

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

Alternative 4: 64.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -5.2 \cdot 10^{+17}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -6.5 \cdot 10^{-275}:\\ \;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -5.2e+17)
   (* (+ d4 d2) d1)
   (if (<= d2 -6.5e-275) (* (- (- d1) d3) d1) (* (- d4 d3) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -5.2e+17) {
		tmp = (d4 + d2) * d1;
	} else if (d2 <= -6.5e-275) {
		tmp = (-d1 - d3) * d1;
	} else {
		tmp = (d4 - d3) * d1;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-5.2d+17)) then
        tmp = (d4 + d2) * d1
    else if (d2 <= (-6.5d-275)) then
        tmp = (-d1 - d3) * d1
    else
        tmp = (d4 - d3) * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -5.2e+17) {
		tmp = (d4 + d2) * d1;
	} else if (d2 <= -6.5e-275) {
		tmp = (-d1 - d3) * d1;
	} else {
		tmp = (d4 - d3) * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -5.2e+17:
		tmp = (d4 + d2) * d1
	elif d2 <= -6.5e-275:
		tmp = (-d1 - d3) * d1
	else:
		tmp = (d4 - d3) * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -5.2e+17)
		tmp = Float64(Float64(d4 + d2) * d1);
	elseif (d2 <= -6.5e-275)
		tmp = Float64(Float64(Float64(-d1) - d3) * d1);
	else
		tmp = Float64(Float64(d4 - d3) * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -5.2e+17)
		tmp = (d4 + d2) * d1;
	elseif (d2 <= -6.5e-275)
		tmp = (-d1 - d3) * d1;
	else
		tmp = (d4 - d3) * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.2e+17], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -6.5e-275], N[(N[((-d1) - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.2 \cdot 10^{+17}:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\

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

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


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

    1. Initial program 84.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 + d4\right) - d3\right)} \]
    3. Applied rewrites89.0%

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

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

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

    if -5.2e17 < d2 < -6.500000000000001e-275

    1. Initial program 91.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 + \left(d4 + -1 \cdot d1\right)\right) - d3\right)} \]
    3. Applied rewrites100.0%

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

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

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

    if -6.500000000000001e-275 < d2

    1. Initial program 87.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 + \left(d4 + -1 \cdot d1\right)\right) - d3\right)} \]
    3. Applied rewrites100.0%

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

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

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

Alternative 5: 63.5% accurate, 2.0× speedup?

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

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

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -7500000000:\\
\;\;\;\;\left(d4 + d2\right) \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -7.5e9

    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 + d4\right) - d3\right)} \]
    3. Applied rewrites88.9%

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

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

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

    if -7.5e9 < d2

    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. Applied rewrites100.0%

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

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

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

Alternative 6: 63.2% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 4.2 \cdot 10^{-19}:\\
\;\;\;\;\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 < 4.1999999999999998e-19

    1. Initial program 88.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. Applied rewrites100.0%

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

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

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

    if 4.1999999999999998e-19 < 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. Applied rewrites100.0%

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

      \[\leadsto \left(d4 - d3\right) \cdot d1 \]
    5. Applied rewrites69.0%

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

Alternative 7: 62.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 7 \cdot 10^{+152}:\\
\;\;\;\;\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 < 6.99999999999999963e152

    1. Initial program 88.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. Applied rewrites100.0%

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

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

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

    if 6.99999999999999963e152 < 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 d4 around inf

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    3. Applied rewrites75.8%

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

Alternative 8: 39.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2 \cdot 10^{-303}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 8.2 \cdot 10^{-178}:\\
\;\;\;\;-d1 \cdot d1\\

\mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+152}:\\
\;\;\;\;-d1 \cdot d3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < 1.99999999999999986e-303

    1. Initial program 87.4%

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

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

    if 1.99999999999999986e-303 < d4 < 8.1999999999999998e-178

    1. Initial program 92.5%

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Applied rewrites38.1%

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

    if 8.1999999999999998e-178 < d4 < 5.2000000000000001e152

    1. Initial program 87.8%

      \[\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. Applied rewrites34.5%

      \[\leadsto \color{blue}{-d1 \cdot d3} \]

    if 5.2000000000000001e152 < 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 d4 around inf

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    3. Applied rewrites75.8%

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

Alternative 9: 38.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.8 \cdot 10^{-21}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 2.8 \cdot 10^{-263}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -4.8e-21) (* d1 d2) (if (<= d2 2.8e-263) (- (* d1 d1)) (* d4 d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.8e-21) {
		tmp = d1 * d2;
	} else if (d2 <= 2.8e-263) {
		tmp = -(d1 * d1);
	} else {
		tmp = d4 * d1;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-4.8d-21)) then
        tmp = d1 * d2
    else if (d2 <= 2.8d-263) then
        tmp = -(d1 * d1)
    else
        tmp = d4 * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.8e-21) {
		tmp = d1 * d2;
	} else if (d2 <= 2.8e-263) {
		tmp = -(d1 * d1);
	} else {
		tmp = d4 * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -4.8e-21:
		tmp = d1 * d2
	elif d2 <= 2.8e-263:
		tmp = -(d1 * d1)
	else:
		tmp = d4 * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -4.8e-21)
		tmp = Float64(d1 * d2);
	elseif (d2 <= 2.8e-263)
		tmp = Float64(-Float64(d1 * d1));
	else
		tmp = Float64(d4 * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -4.8e-21)
		tmp = d1 * d2;
	elseif (d2 <= 2.8e-263)
		tmp = -(d1 * d1);
	else
		tmp = d4 * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.8e-21], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, 2.8e-263], (-N[(d1 * d1), $MachinePrecision]), N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.8 \cdot 10^{-21}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq 2.8 \cdot 10^{-263}:\\
\;\;\;\;-d1 \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -4.7999999999999999e-21

    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 d2 around inf

      \[\leadsto \color{blue}{d1 \cdot d2} \]
    3. Applied rewrites53.4%

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

    if -4.7999999999999999e-21 < d2 < 2.8e-263

    1. Initial program 91.5%

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    3. Applied rewrites40.1%

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

    if 2.8e-263 < d2

    1. Initial program 86.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. Applied rewrites30.2%

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

Alternative 10: 38.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d4 \leq 13000000:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d4 13000000.0) (* d1 d2) (* d4 d1)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 13000000.0) {
		tmp = d1 * d2;
	} else {
		tmp = d4 * d1;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(d1, d2, d3, d4)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d4 <= 13000000.0d0) then
        tmp = d1 * d2
    else
        tmp = d4 * d1
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 13000000.0) {
		tmp = d1 * d2;
	} else {
		tmp = d4 * d1;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d4 <= 13000000.0:
		tmp = d1 * d2
	else:
		tmp = d4 * d1
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 13000000.0)
		tmp = Float64(d1 * d2);
	else
		tmp = Float64(d4 * d1);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d4 <= 13000000.0)
		tmp = d1 * d2;
	else
		tmp = d4 * d1;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 13000000.0], N[(d1 * d2), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 13000000:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 1.3e7

    1. Initial program 88.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. Applied rewrites33.4%

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

    if 1.3e7 < 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. Applied rewrites54.2%

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

Alternative 11: 30.8% accurate, 5.3× speedup?

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

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

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

\\
d1 \cdot d2
\end{array}
Derivation
  1. Initial program 87.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. Applied rewrites30.8%

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  4. 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 2025132 
(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)))