FastMath dist4

Percentage Accurate: 87.8% → 100.0%
Time: 2.4s
Alternatives: 11
Speedup: 1.7×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 87.8% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 62.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 1.9 \cdot 10^{-272}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\

\mathbf{elif}\;d4 \leq 1.4 \cdot 10^{+108}:\\
\;\;\;\;\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 < 1.89999999999999985e-272

    1. Initial program 89.0%

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

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

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

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

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

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

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

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

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

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

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

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

      if 1.89999999999999985e-272 < d4 < 1.3999999999999999e108

      1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 1.3999999999999999e108 < d4

      1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 3: 67.4% accurate, 1.4× speedup?

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

        1. Initial program 71.2%

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

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

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

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

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

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

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

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

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

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

        if -1.01999999999999991e103 < d3 < 6.5000000000000003e198

        1. Initial program 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 38.9% accurate, 1.5× speedup?

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

        1. Initial program 89.0%

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

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

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

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

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

        if 1.89999999999999985e-272 < d4 < 2.19999999999999986e118

        1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

        if 2.19999999999999986e118 < d4

        1. Initial program 55.2%

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

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

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

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

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

      Alternative 5: 82.9% accurate, 1.5× speedup?

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

        1. Initial program 89.1%

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d2\right) - d3\right) \cdot d1 \]
          2. lift-neg.f6480.6

            \[\leadsto \left(\left(\left(-d1\right) + d2\right) - d3\right) \cdot d1 \]
        8. Applied rewrites80.6%

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

        if 1.75e-59 < d4

        1. Initial program 78.1%

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(\left(-1 \cdot d1 + d4\right) - d3\right) \cdot d1 \]
          2. lift-fma.f6483.0

            \[\leadsto \left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1 \]
        8. Applied rewrites83.0%

          \[\leadsto \left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1 \]
        9. Step-by-step derivation
          1. lift-fma.f64N/A

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

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

            \[\leadsto \left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) - d3\right) \cdot d1 \]
          4. lift-neg.f6483.0

            \[\leadsto \left(\left(\left(-d1\right) + d4\right) - d3\right) \cdot d1 \]
        10. Applied rewrites83.0%

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

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

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

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

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

      Alternative 6: 84.4% accurate, 1.7× speedup?

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

        1. Initial program 85.0%

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

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

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

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

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

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

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

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

        if -5.3000000000000001e-14 < d2

        1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(\left(-1 \cdot d1 + d4\right) - d3\right) \cdot d1 \]
          2. lift-fma.f6482.5

            \[\leadsto \left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1 \]
        8. Applied rewrites82.5%

          \[\leadsto \left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1 \]
        9. Step-by-step derivation
          1. lift-fma.f64N/A

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

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

            \[\leadsto \left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) - d3\right) \cdot d1 \]
          4. lift-neg.f6482.5

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

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

          \[\leadsto \left(\left(d4 - d1\right) - d3\right) \cdot d1 \]
        12. Step-by-step derivation
          1. lower--.f6482.5

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

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

      Alternative 7: 82.6% accurate, 1.7× speedup?

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

        1. Initial program 86.0%

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

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

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

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

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

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

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

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

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

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

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

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

          if -3.44999999999999982e87 < d2

          1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \left(\left(-1 \cdot d1 + d4\right) - d3\right) \cdot d1 \]
            2. lift-fma.f6481.7

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

            \[\leadsto \left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1 \]
          9. Step-by-step derivation
            1. lift-fma.f64N/A

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

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

              \[\leadsto \left(\left(\left(\mathsf{neg}\left(d1\right)\right) + d4\right) - d3\right) \cdot d1 \]
            4. lift-neg.f6481.7

              \[\leadsto \left(\left(\left(-d1\right) + d4\right) - d3\right) \cdot d1 \]
          10. Applied rewrites81.7%

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

            \[\leadsto \left(\left(d4 - d1\right) - d3\right) \cdot d1 \]
          12. Step-by-step derivation
            1. lower--.f6481.7

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

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

        Alternative 8: 63.0% accurate, 2.0× speedup?

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

          1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

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

            if 5e-31 < d4

            1. Initial program 74.6%

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 9: 64.3% accurate, 2.0× speedup?

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

              1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

                if 2.2e18 < d4

                1. Initial program 70.6%

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

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

                    \[\leadsto \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-+.f6481.3

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

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

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

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

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

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

              Alternative 10: 37.9% accurate, 2.5× speedup?

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

                1. Initial program 89.2%

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

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

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

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

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

                if 1.09999999999999999e-57 < d4

                1. Initial program 77.4%

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

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

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

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

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

              Alternative 11: 31.5% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

              Reproduce

              ?
              herbie shell --seed 2025080 
              (FPCore (d1 d2 d3 d4)
                :name "FastMath dist4"
                :precision binary64
              
                :alt
                (! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))
              
                (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))