FastMath dist4

Percentage Accurate: 87.8% → 96.9%
Time: 7.8s
Alternatives: 12
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 12 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: 96.9% accurate, 1.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 71.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(d2 - d3\right) \cdot d1\\ \mathbf{if}\;d3 \leq -3900000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq -1.55 \cdot 10^{-256}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 7.6 \cdot 10^{+99}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* (- d2 d3) d1)))
   (if (<= d3 -3900000000.0)
     t_0
     (if (<= d3 -1.55e-256)
       (* (- d2 d1) d1)
       (if (<= d3 7.6e+99) (* (+ d2 d4) d1) t_0)))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = (d2 - d3) * d1;
	double tmp;
	if (d3 <= -3900000000.0) {
		tmp = t_0;
	} else if (d3 <= -1.55e-256) {
		tmp = (d2 - d1) * d1;
	} else if (d3 <= 7.6e+99) {
		tmp = (d2 + d4) * d1;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (d2 - d3) * d1
    if (d3 <= (-3900000000.0d0)) then
        tmp = t_0
    else if (d3 <= (-1.55d-256)) then
        tmp = (d2 - d1) * d1
    else if (d3 <= 7.6d+99) then
        tmp = (d2 + d4) * d1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = (d2 - d3) * d1;
	double tmp;
	if (d3 <= -3900000000.0) {
		tmp = t_0;
	} else if (d3 <= -1.55e-256) {
		tmp = (d2 - d1) * d1;
	} else if (d3 <= 7.6e+99) {
		tmp = (d2 + d4) * d1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = (d2 - d3) * d1
	tmp = 0
	if d3 <= -3900000000.0:
		tmp = t_0
	elif d3 <= -1.55e-256:
		tmp = (d2 - d1) * d1
	elif d3 <= 7.6e+99:
		tmp = (d2 + d4) * d1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(Float64(d2 - d3) * d1)
	tmp = 0.0
	if (d3 <= -3900000000.0)
		tmp = t_0;
	elseif (d3 <= -1.55e-256)
		tmp = Float64(Float64(d2 - d1) * d1);
	elseif (d3 <= 7.6e+99)
		tmp = Float64(Float64(d2 + d4) * d1);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = (d2 - d3) * d1;
	tmp = 0.0;
	if (d3 <= -3900000000.0)
		tmp = t_0;
	elseif (d3 <= -1.55e-256)
		tmp = (d2 - d1) * d1;
	elseif (d3 <= 7.6e+99)
		tmp = (d2 + d4) * d1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -3900000000.0], t$95$0, If[LessEqual[d3, -1.55e-256], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 7.6e+99], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d3 \leq 7.6 \cdot 10^{+99}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -3.9e9 or 7.6e99 < d3

    1. Initial program 87.7%

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

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

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

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

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

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

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

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

      \[\leadsto d1 \cdot \color{blue}{\left(d2 - d3\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites78.2%

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

      if -3.9e9 < d3 < -1.54999999999999993e-256

      1. Initial program 77.8%

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

        \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
      4. Step-by-step derivation
        1. associate--r+N/A

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

          \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
        3. unpow2N/A

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

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

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

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

          \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
        8. lower--.f6463.6

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

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

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

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

        if -1.54999999999999993e-256 < d3 < 7.6e99

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

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

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

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

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

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

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

          \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
        7. Step-by-step derivation
          1. Applied rewrites79.6%

            \[\leadsto \left(d2 + d4\right) \cdot \color{blue}{d1} \]
        8. Recombined 3 regimes into one program.
        9. Add Preprocessing

        Alternative 3: 88.7% accurate, 1.2× speedup?

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

          1. Initial program 57.1%

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

            \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
          4. Step-by-step derivation
            1. associate--r+N/A

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

              \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
            3. unpow2N/A

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

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

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

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

              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
            8. lower--.f6494.3

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

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

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

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

            if -4.6000000000000003e144 < d1 < 1.0999999999999999e95

            1. Initial program 100.0%

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

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

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

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

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

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

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

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

            if 1.0999999999999999e95 < d1

            1. Initial program 65.3%

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

              \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
            4. Step-by-step derivation
              1. associate--r+N/A

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

                \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} - {d1}^{2} \]
              3. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 4: 63.7% accurate, 1.3× speedup?

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

              1. Initial program 79.6%

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

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

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

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

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

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

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

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

                \[\leadsto d1 \cdot \color{blue}{\left(d2 - d3\right)} \]
              7. Step-by-step derivation
                1. Applied rewrites74.6%

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

                if -5.59999999999999977e88 < d2 < -2.2000000000000001e-139

                1. Initial program 87.8%

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

                  \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                4. Step-by-step derivation
                  1. associate--r+N/A

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

                    \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} - {d1}^{2} \]
                  3. unpow2N/A

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

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

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

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

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

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

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

                    \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                  11. lower--.f6483.9

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

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

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

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

                  if -2.2000000000000001e-139 < d2

                  1. Initial program 90.1%

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

                    \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                  4. Step-by-step derivation
                    1. associate--r+N/A

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

                      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} - {d1}^{2} \]
                    3. unpow2N/A

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

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

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

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

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

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

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

                      \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                    11. lower--.f6482.2

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

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

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

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

                  Alternative 5: 68.3% accurate, 1.4× speedup?

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

                    1. Initial program 84.7%

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

                      \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                    4. Step-by-step derivation
                      1. associate--r+N/A

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

                        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} - {d1}^{2} \]
                      3. unpow2N/A

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

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

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

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

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

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

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

                        \[\leadsto \color{blue}{\left(\left(d4 - d1\right) - d3\right)} \cdot d1 \]
                      11. lower--.f6492.2

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

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

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

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

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

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

                        if -6.0000000000000002e137 < d3 < 2.99999999999999997e140

                        1. Initial program 88.6%

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

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

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

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

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

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

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

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

                          \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
                        7. Step-by-step derivation
                          1. Applied rewrites68.6%

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

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

                        Alternative 6: 62.1% accurate, 1.4× speedup?

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

                          1. Initial program 87.5%

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

                            \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                          4. Step-by-step derivation
                            1. associate--r+N/A

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

                              \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                            3. unpow2N/A

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

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

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

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

                              \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                            8. lower--.f6479.2

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

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

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

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

                            if 1.05000000000000003e-293 < d4 < 1.8e6

                            1. Initial program 96.2%

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

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

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

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

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

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

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

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

                              \[\leadsto d1 \cdot \color{blue}{\left(d2 - d3\right)} \]
                            7. Step-by-step derivation
                              1. Applied rewrites76.6%

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

                              if 1.8e6 < d4

                              1. Initial program 80.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 0

                                \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                              4. Step-by-step derivation
                                1. associate--r+N/A

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

                                  \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} - {d1}^{2} \]
                                3. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

                              Alternative 7: 39.8% accurate, 1.5× speedup?

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

                                1. Initial program 80.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                if -7.9999999999999996e61 < d2 < 1.75e-205

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

                                  \[\leadsto \color{blue}{d1 \cdot d4 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                                4. Step-by-step derivation
                                  1. associate--r+N/A

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

                                    \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} - {d1}^{2} \]
                                  3. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if 1.75e-205 < d2

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

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

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

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

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

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

                                  Alternative 8: 84.5% accurate, 1.7× speedup?

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

                                    1. Initial program 89.5%

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

                                      \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                                    4. Step-by-step derivation
                                      1. associate--r+N/A

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

                                        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} - {d1}^{2} \]
                                      3. unpow2N/A

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

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

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

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

                                        \[\leadsto \color{blue}{\left(\left(d2 - d3\right) - d1\right)} \cdot d1 \]
                                      8. lower--.f6484.3

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

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

                                    if 3.69999999999999988e26 < d4

                                    1. Initial program 81.5%

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

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

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

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

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

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

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

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

                                  Alternative 9: 97.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  Alternative 10: 63.6% accurate, 2.0× speedup?

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

                                    1. Initial program 89.3%

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

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

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

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

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

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

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

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

                                      \[\leadsto d1 \cdot \color{blue}{\left(d2 - d3\right)} \]
                                    7. Step-by-step derivation
                                      1. Applied rewrites62.2%

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

                                      if 2.20000000000000021e93 < d4

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

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

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

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

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

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

                                        \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
                                      7. Step-by-step derivation
                                        1. Applied rewrites77.5%

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

                                      Alternative 11: 40.3% accurate, 2.5× speedup?

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

                                        1. Initial program 80.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        if -9.19999999999999936e62 < d2

                                        1. Initial program 89.6%

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

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

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

                                            \[\leadsto \color{blue}{d4 \cdot d1} \]
                                        5. Applied rewrites33.6%

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

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

                                      Alternative 12: 30.8% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \color{blue}{d2 \cdot d1} \]
                                      8. Final simplification32.5%

                                        \[\leadsto d2 \cdot d1 \]
                                      9. Add Preprocessing

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

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

                                      Reproduce

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