FastMath dist4

Percentage Accurate: 88.0% → 98.4%
Time: 10.6s
Alternatives: 14
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);
}
real(8) function code(d1, d2, d3, d4)
    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 14 alternatives:

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

Initial Program: 88.0% 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);
}
real(8) function code(d1, d2, d3, d4)
    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: 98.4% accurate, 0.6× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) INFINITY)
   (fma d1 (- d4 d1) (* (- d2 d3) d1))
   (* (- (- d2 d3) d1) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= ((double) INFINITY)) {
		tmp = fma(d1, (d4 - d1), ((d2 - d3) * d1));
	} else {
		tmp = ((d2 - d3) - d1) * d1;
	}
	return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) <= Inf)
		tmp = fma(d1, Float64(d4 - d1), Float64(Float64(d2 - d3) * d1));
	else
		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
	end
	return tmp
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := If[LessEqual[N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], Infinity], N[(d1 * N[(d4 - d1), $MachinePrecision] + N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < +inf.0

    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. 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. +-commutativeN/A

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, d1 \cdot d2 - d1 \cdot d3\right)} \]
      9. lower--.f64100.0

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

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

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

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

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

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

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

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

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

    if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

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

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

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

Alternative 2: 69.3% accurate, 1.1× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(d2 - d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+102}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq -5.2 \cdot 10^{-156}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d1 \leq 7.4 \cdot 10^{+124}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* (- d2 d1) d1)))
   (if (<= d1 -3.3e+102)
     t_0
     (if (<= d1 -5.2e-156)
       (* (- d2 d3) d1)
       (if (<= d1 7.4e+124) (* (+ d2 d4) d1) t_0)))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double t_0 = (d2 - d1) * d1;
	double tmp;
	if (d1 <= -3.3e+102) {
		tmp = t_0;
	} else if (d1 <= -5.2e-156) {
		tmp = (d2 - d3) * d1;
	} else if (d1 <= 7.4e+124) {
		tmp = (d2 + d4) * d1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
real(8) function code(d1, d2, d3, d4)
    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 - d1) * d1
    if (d1 <= (-3.3d+102)) then
        tmp = t_0
    else if (d1 <= (-5.2d-156)) then
        tmp = (d2 - d3) * d1
    else if (d1 <= 7.4d+124) then
        tmp = (d2 + d4) * d1
    else
        tmp = t_0
    end if
    code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = (d2 - d1) * d1;
	double tmp;
	if (d1 <= -3.3e+102) {
		tmp = t_0;
	} else if (d1 <= -5.2e-156) {
		tmp = (d2 - d3) * d1;
	} else if (d1 <= 7.4e+124) {
		tmp = (d2 + d4) * d1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	t_0 = (d2 - d1) * d1
	tmp = 0
	if d1 <= -3.3e+102:
		tmp = t_0
	elif d1 <= -5.2e-156:
		tmp = (d2 - d3) * d1
	elif d1 <= 7.4e+124:
		tmp = (d2 + d4) * d1
	else:
		tmp = t_0
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	t_0 = Float64(Float64(d2 - d1) * d1)
	tmp = 0.0
	if (d1 <= -3.3e+102)
		tmp = t_0;
	elseif (d1 <= -5.2e-156)
		tmp = Float64(Float64(d2 - d3) * d1);
	elseif (d1 <= 7.4e+124)
		tmp = Float64(Float64(d2 + d4) * d1);
	else
		tmp = t_0;
	end
	return tmp
end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = (d2 - d1) * d1;
	tmp = 0.0;
	if (d1 <= -3.3e+102)
		tmp = t_0;
	elseif (d1 <= -5.2e-156)
		tmp = (d2 - d3) * d1;
	elseif (d1 <= 7.4e+124)
		tmp = (d2 + d4) * d1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d1, -3.3e+102], t$95$0, If[LessEqual[d1, -5.2e-156], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 7.4e+124], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := \left(d2 - d1\right) \cdot d1\\
\mathbf{if}\;d1 \leq -3.3 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d1 \leq 7.4 \cdot 10^{+124}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -3.29999999999999999e102 or 7.40000000000000016e124 < d1

    1. Initial program 66.3%

      \[\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--.f6497.6

        \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
    5. Applied rewrites97.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 rewrites91.8%

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

      if -3.29999999999999999e102 < d1 < -5.2000000000000002e-156

      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 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--.f6470.9

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

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

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

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

        if -5.2000000000000002e-156 < d1 < 7.40000000000000016e124

        1. Initial program 99.9%

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

          \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + 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.8

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

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

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

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

        Alternative 3: 65.9% accurate, 1.1× speedup?

        \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(d2 - d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -2500:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq -2.7 \cdot 10^{-118}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d1 \leq 7.4 \cdot 10^{+124}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        (FPCore (d1 d2 d3 d4)
         :precision binary64
         (let* ((t_0 (* (- d2 d1) d1)))
           (if (<= d1 -2500.0)
             t_0
             (if (<= d1 -2.7e-118)
               (* (- d1) d3)
               (if (<= d1 7.4e+124) (* (+ d2 d4) d1) t_0)))))
        assert(d1 < d2 && d2 < d3 && d3 < d4);
        double code(double d1, double d2, double d3, double d4) {
        	double t_0 = (d2 - d1) * d1;
        	double tmp;
        	if (d1 <= -2500.0) {
        		tmp = t_0;
        	} else if (d1 <= -2.7e-118) {
        		tmp = -d1 * d3;
        	} else if (d1 <= 7.4e+124) {
        		tmp = (d2 + d4) * d1;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        real(8) function code(d1, d2, d3, d4)
            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 - d1) * d1
            if (d1 <= (-2500.0d0)) then
                tmp = t_0
            else if (d1 <= (-2.7d-118)) then
                tmp = -d1 * d3
            else if (d1 <= 7.4d+124) then
                tmp = (d2 + d4) * d1
            else
                tmp = t_0
            end if
            code = tmp
        end function
        
        assert d1 < d2 && d2 < d3 && d3 < d4;
        public static double code(double d1, double d2, double d3, double d4) {
        	double t_0 = (d2 - d1) * d1;
        	double tmp;
        	if (d1 <= -2500.0) {
        		tmp = t_0;
        	} else if (d1 <= -2.7e-118) {
        		tmp = -d1 * d3;
        	} else if (d1 <= 7.4e+124) {
        		tmp = (d2 + d4) * d1;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
        def code(d1, d2, d3, d4):
        	t_0 = (d2 - d1) * d1
        	tmp = 0
        	if d1 <= -2500.0:
        		tmp = t_0
        	elif d1 <= -2.7e-118:
        		tmp = -d1 * d3
        	elif d1 <= 7.4e+124:
        		tmp = (d2 + d4) * d1
        	else:
        		tmp = t_0
        	return tmp
        
        d1, d2, d3, d4 = sort([d1, d2, d3, d4])
        function code(d1, d2, d3, d4)
        	t_0 = Float64(Float64(d2 - d1) * d1)
        	tmp = 0.0
        	if (d1 <= -2500.0)
        		tmp = t_0;
        	elseif (d1 <= -2.7e-118)
        		tmp = Float64(Float64(-d1) * d3);
        	elseif (d1 <= 7.4e+124)
        		tmp = Float64(Float64(d2 + d4) * d1);
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
        function tmp_2 = code(d1, d2, d3, d4)
        	t_0 = (d2 - d1) * d1;
        	tmp = 0.0;
        	if (d1 <= -2500.0)
        		tmp = t_0;
        	elseif (d1 <= -2.7e-118)
        		tmp = -d1 * d3;
        	elseif (d1 <= 7.4e+124)
        		tmp = (d2 + d4) * d1;
        	else
        		tmp = t_0;
        	end
        	tmp_2 = tmp;
        end
        
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d1, -2500.0], t$95$0, If[LessEqual[d1, -2.7e-118], N[((-d1) * d3), $MachinePrecision], If[LessEqual[d1, 7.4e+124], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
        
        \begin{array}{l}
        [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
        \\
        \begin{array}{l}
        t_0 := \left(d2 - d1\right) \cdot d1\\
        \mathbf{if}\;d1 \leq -2500:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;d1 \leq -2.7 \cdot 10^{-118}:\\
        \;\;\;\;\left(-d1\right) \cdot d3\\
        
        \mathbf{elif}\;d1 \leq 7.4 \cdot 10^{+124}:\\
        \;\;\;\;\left(d2 + d4\right) \cdot d1\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if d1 < -2500 or 7.40000000000000016e124 < d1

          1. Initial program 72.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 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--.f6493.5

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

            \[\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 rewrites83.8%

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

            if -2500 < d1 < -2.69999999999999994e-118

            1. Initial program 99.9%

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

              \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + 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-+.f6496.3

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

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

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

                \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d3\right)} \]
              3. Step-by-step derivation
                1. Applied rewrites61.5%

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

                if -2.69999999999999994e-118 < d1 < 7.40000000000000016e124

                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-+.f6492.7

                    \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                5. Applied rewrites92.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 rewrites67.8%

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -2500:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq -2.7 \cdot 10^{-118}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d1 \leq 7.4 \cdot 10^{+124}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \end{array} \]
                10. Add Preprocessing

                Alternative 4: 61.3% accurate, 1.1× speedup?

                \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(-d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+102}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq -2.7 \cdot 10^{-118}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d1 \leq 2.2 \cdot 10^{+126}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                (FPCore (d1 d2 d3 d4)
                 :precision binary64
                 (let* ((t_0 (* (- d1) d1)))
                   (if (<= d1 -3.3e+102)
                     t_0
                     (if (<= d1 -2.7e-118)
                       (* (- d1) d3)
                       (if (<= d1 2.2e+126) (* (+ d2 d4) d1) t_0)))))
                assert(d1 < d2 && d2 < d3 && d3 < d4);
                double code(double d1, double d2, double d3, double d4) {
                	double t_0 = -d1 * d1;
                	double tmp;
                	if (d1 <= -3.3e+102) {
                		tmp = t_0;
                	} else if (d1 <= -2.7e-118) {
                		tmp = -d1 * d3;
                	} else if (d1 <= 2.2e+126) {
                		tmp = (d2 + d4) * d1;
                	} else {
                		tmp = t_0;
                	}
                	return tmp;
                }
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                real(8) function code(d1, d2, d3, d4)
                    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 = -d1 * d1
                    if (d1 <= (-3.3d+102)) then
                        tmp = t_0
                    else if (d1 <= (-2.7d-118)) then
                        tmp = -d1 * d3
                    else if (d1 <= 2.2d+126) then
                        tmp = (d2 + d4) * d1
                    else
                        tmp = t_0
                    end if
                    code = tmp
                end function
                
                assert d1 < d2 && d2 < d3 && d3 < d4;
                public static double code(double d1, double d2, double d3, double d4) {
                	double t_0 = -d1 * d1;
                	double tmp;
                	if (d1 <= -3.3e+102) {
                		tmp = t_0;
                	} else if (d1 <= -2.7e-118) {
                		tmp = -d1 * d3;
                	} else if (d1 <= 2.2e+126) {
                		tmp = (d2 + d4) * d1;
                	} else {
                		tmp = t_0;
                	}
                	return tmp;
                }
                
                [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                def code(d1, d2, d3, d4):
                	t_0 = -d1 * d1
                	tmp = 0
                	if d1 <= -3.3e+102:
                		tmp = t_0
                	elif d1 <= -2.7e-118:
                		tmp = -d1 * d3
                	elif d1 <= 2.2e+126:
                		tmp = (d2 + d4) * d1
                	else:
                		tmp = t_0
                	return tmp
                
                d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                function code(d1, d2, d3, d4)
                	t_0 = Float64(Float64(-d1) * d1)
                	tmp = 0.0
                	if (d1 <= -3.3e+102)
                		tmp = t_0;
                	elseif (d1 <= -2.7e-118)
                		tmp = Float64(Float64(-d1) * d3);
                	elseif (d1 <= 2.2e+126)
                		tmp = Float64(Float64(d2 + d4) * d1);
                	else
                		tmp = t_0;
                	end
                	return tmp
                end
                
                d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                function tmp_2 = code(d1, d2, d3, d4)
                	t_0 = -d1 * d1;
                	tmp = 0.0;
                	if (d1 <= -3.3e+102)
                		tmp = t_0;
                	elseif (d1 <= -2.7e-118)
                		tmp = -d1 * d3;
                	elseif (d1 <= 2.2e+126)
                		tmp = (d2 + d4) * d1;
                	else
                		tmp = t_0;
                	end
                	tmp_2 = tmp;
                end
                
                NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d1, -3.3e+102], t$95$0, If[LessEqual[d1, -2.7e-118], N[((-d1) * d3), $MachinePrecision], If[LessEqual[d1, 2.2e+126], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
                
                \begin{array}{l}
                [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                \\
                \begin{array}{l}
                t_0 := \left(-d1\right) \cdot d1\\
                \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+102}:\\
                \;\;\;\;t\_0\\
                
                \mathbf{elif}\;d1 \leq -2.7 \cdot 10^{-118}:\\
                \;\;\;\;\left(-d1\right) \cdot d3\\
                
                \mathbf{elif}\;d1 \leq 2.2 \cdot 10^{+126}:\\
                \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                
                \mathbf{else}:\\
                \;\;\;\;t\_0\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if d1 < -3.29999999999999999e102 or 2.19999999999999999e126 < d1

                  1. Initial program 66.3%

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

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

                      \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
                    2. associate-*r*N/A

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

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

                      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)} \cdot d1 \]
                    5. lower-neg.f6484.6

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

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

                  if -3.29999999999999999e102 < d1 < -2.69999999999999994e-118

                  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-+.f6489.3

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

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

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

                      \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d3\right)} \]
                    3. Step-by-step derivation
                      1. Applied rewrites49.8%

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

                      if -2.69999999999999994e-118 < d1 < 2.19999999999999999e126

                      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-+.f6492.7

                          \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d3\right) \cdot d1 \]
                      5. Applied rewrites92.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 rewrites67.8%

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

                        \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+102}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq -2.7 \cdot 10^{-118}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d1 \leq 2.2 \cdot 10^{+126}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \end{array} \]
                      10. Add Preprocessing

                      Alternative 5: 53.6% accurate, 1.2× speedup?

                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq -6.2 \cdot 10^{-219}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{-105}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+119}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      (FPCore (d1 d2 d3 d4)
                       :precision binary64
                       (if (<= d4 -6.2e-219)
                         (* d2 d1)
                         (if (<= d4 4.6e-105)
                           (* (- d1) d3)
                           (if (<= d4 2.5e+119) (* (- d1) d1) (* d4 d1)))))
                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                      double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d4 <= -6.2e-219) {
                      		tmp = d2 * d1;
                      	} else if (d4 <= 4.6e-105) {
                      		tmp = -d1 * d3;
                      	} else if (d4 <= 2.5e+119) {
                      		tmp = -d1 * d1;
                      	} else {
                      		tmp = d4 * d1;
                      	}
                      	return tmp;
                      }
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      real(8) function code(d1, d2, d3, d4)
                          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 <= (-6.2d-219)) then
                              tmp = d2 * d1
                          else if (d4 <= 4.6d-105) then
                              tmp = -d1 * d3
                          else if (d4 <= 2.5d+119) then
                              tmp = -d1 * d1
                          else
                              tmp = d4 * d1
                          end if
                          code = tmp
                      end function
                      
                      assert d1 < d2 && d2 < d3 && d3 < d4;
                      public static double code(double d1, double d2, double d3, double d4) {
                      	double tmp;
                      	if (d4 <= -6.2e-219) {
                      		tmp = d2 * d1;
                      	} else if (d4 <= 4.6e-105) {
                      		tmp = -d1 * d3;
                      	} else if (d4 <= 2.5e+119) {
                      		tmp = -d1 * d1;
                      	} else {
                      		tmp = d4 * d1;
                      	}
                      	return tmp;
                      }
                      
                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                      def code(d1, d2, d3, d4):
                      	tmp = 0
                      	if d4 <= -6.2e-219:
                      		tmp = d2 * d1
                      	elif d4 <= 4.6e-105:
                      		tmp = -d1 * d3
                      	elif d4 <= 2.5e+119:
                      		tmp = -d1 * d1
                      	else:
                      		tmp = d4 * d1
                      	return tmp
                      
                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                      function code(d1, d2, d3, d4)
                      	tmp = 0.0
                      	if (d4 <= -6.2e-219)
                      		tmp = Float64(d2 * d1);
                      	elseif (d4 <= 4.6e-105)
                      		tmp = Float64(Float64(-d1) * d3);
                      	elseif (d4 <= 2.5e+119)
                      		tmp = Float64(Float64(-d1) * d1);
                      	else
                      		tmp = Float64(d4 * d1);
                      	end
                      	return tmp
                      end
                      
                      d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                      function tmp_2 = code(d1, d2, d3, d4)
                      	tmp = 0.0;
                      	if (d4 <= -6.2e-219)
                      		tmp = d2 * d1;
                      	elseif (d4 <= 4.6e-105)
                      		tmp = -d1 * d3;
                      	elseif (d4 <= 2.5e+119)
                      		tmp = -d1 * d1;
                      	else
                      		tmp = d4 * d1;
                      	end
                      	tmp_2 = tmp;
                      end
                      
                      NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                      code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, -6.2e-219], N[(d2 * d1), $MachinePrecision], If[LessEqual[d4, 4.6e-105], N[((-d1) * d3), $MachinePrecision], If[LessEqual[d4, 2.5e+119], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
                      
                      \begin{array}{l}
                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;d4 \leq -6.2 \cdot 10^{-219}:\\
                      \;\;\;\;d2 \cdot d1\\
                      
                      \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{-105}:\\
                      \;\;\;\;\left(-d1\right) \cdot d3\\
                      
                      \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+119}:\\
                      \;\;\;\;\left(-d1\right) \cdot d1\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;d4 \cdot d1\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 4 regimes
                      2. if d4 < -6.1999999999999994e-219

                        1. Initial program 93.0%

                          \[\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. +-commutativeN/A

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

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

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

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

                            \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, d1 \cdot d2 - d1 \cdot d3\right)} \]
                          9. lower--.f6499.0

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

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

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

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

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

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

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

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

                          \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\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-*.f6430.6

                            \[\leadsto \color{blue}{d2 \cdot d1} \]
                        7. Applied rewrites30.6%

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

                        if -6.1999999999999994e-219 < d4 < 4.6000000000000002e-105

                        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-+.f6466.2

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

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

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

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

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

                            if 4.6000000000000002e-105 < d4 < 2.5e119

                            1. Initial program 80.4%

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

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

                                \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
                              2. associate-*r*N/A

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

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

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

                                \[\leadsto \color{blue}{\left(-d1\right)} \cdot d1 \]
                            5. Applied rewrites47.7%

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

                            if 2.5e119 < d4

                            1. Initial program 89.7%

                              \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                            2. Add Preprocessing
                            3. Taylor expanded in 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-*.f6473.9

                                \[\leadsto \color{blue}{d4 \cdot d1} \]
                            5. Applied rewrites73.9%

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

                            \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -6.2 \cdot 10^{-219}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{-105}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{+119}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
                          6. Add Preprocessing

                          Alternative 6: 89.8% accurate, 1.2× speedup?

                          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d1 \leq -2.7 \cdot 10^{+130}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq 2.2 \cdot 10^{+126}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
                          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                          (FPCore (d1 d2 d3 d4)
                           :precision binary64
                           (if (<= d1 -2.7e+130)
                             (* (- d2 d1) d1)
                             (if (<= d1 2.2e+126) (* (- (+ d4 d2) d3) d1) (* (- (- d3) d1) d1))))
                          assert(d1 < d2 && d2 < d3 && d3 < d4);
                          double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d1 <= -2.7e+130) {
                          		tmp = (d2 - d1) * d1;
                          	} else if (d1 <= 2.2e+126) {
                          		tmp = ((d4 + d2) - d3) * d1;
                          	} else {
                          		tmp = (-d3 - d1) * d1;
                          	}
                          	return tmp;
                          }
                          
                          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                          real(8) function code(d1, d2, d3, d4)
                              real(8), intent (in) :: d1
                              real(8), intent (in) :: d2
                              real(8), intent (in) :: d3
                              real(8), intent (in) :: d4
                              real(8) :: tmp
                              if (d1 <= (-2.7d+130)) then
                                  tmp = (d2 - d1) * d1
                              else if (d1 <= 2.2d+126) then
                                  tmp = ((d4 + d2) - d3) * d1
                              else
                                  tmp = (-d3 - d1) * d1
                              end if
                              code = tmp
                          end function
                          
                          assert d1 < d2 && d2 < d3 && d3 < d4;
                          public static double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d1 <= -2.7e+130) {
                          		tmp = (d2 - d1) * d1;
                          	} else if (d1 <= 2.2e+126) {
                          		tmp = ((d4 + d2) - d3) * d1;
                          	} else {
                          		tmp = (-d3 - d1) * d1;
                          	}
                          	return tmp;
                          }
                          
                          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                          def code(d1, d2, d3, d4):
                          	tmp = 0
                          	if d1 <= -2.7e+130:
                          		tmp = (d2 - d1) * d1
                          	elif d1 <= 2.2e+126:
                          		tmp = ((d4 + d2) - d3) * d1
                          	else:
                          		tmp = (-d3 - d1) * d1
                          	return tmp
                          
                          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                          function code(d1, d2, d3, d4)
                          	tmp = 0.0
                          	if (d1 <= -2.7e+130)
                          		tmp = Float64(Float64(d2 - d1) * d1);
                          	elseif (d1 <= 2.2e+126)
                          		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                          	else
                          		tmp = Float64(Float64(Float64(-d3) - d1) * d1);
                          	end
                          	return tmp
                          end
                          
                          d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                          function tmp_2 = code(d1, d2, d3, d4)
                          	tmp = 0.0;
                          	if (d1 <= -2.7e+130)
                          		tmp = (d2 - d1) * d1;
                          	elseif (d1 <= 2.2e+126)
                          		tmp = ((d4 + d2) - d3) * d1;
                          	else
                          		tmp = (-d3 - d1) * d1;
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                          code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -2.7e+130], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 2.2e+126], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision]]]
                          
                          \begin{array}{l}
                          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;d1 \leq -2.7 \cdot 10^{+130}:\\
                          \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                          
                          \mathbf{elif}\;d1 \leq 2.2 \cdot 10^{+126}:\\
                          \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 3 regimes
                          2. if d1 < -2.6999999999999998e130

                            1. Initial program 67.4%

                              \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                            2. Add Preprocessing
                            3. Taylor expanded in d4 around 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--.f6495.3

                                \[\leadsto \left(\color{blue}{\left(d2 - d3\right)} - d1\right) \cdot d1 \]
                            5. Applied rewrites95.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 rewrites91.0%

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

                              if -2.6999999999999998e130 < d1 < 2.19999999999999999e126

                              1. Initial program 98.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-+.f6490.4

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

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

                              if 2.19999999999999999e126 < d1

                              1. Initial program 65.6%

                                \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                              2. Add Preprocessing
                              3. Taylor expanded in d2 around 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. lower--.f64N/A

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

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

                                \[\leadsto \color{blue}{\left(\left(d4 - d3\right) - d1\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 rewrites100.0%

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

                              Alternative 7: 76.0% accurate, 1.3× speedup?

                              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq -9.8 \cdot 10^{-219}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 2.25 \cdot 10^{+119}:\\ \;\;\;\;\left(\left(-d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \end{array} \]
                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                              (FPCore (d1 d2 d3 d4)
                               :precision binary64
                               (if (<= d4 -9.8e-219)
                                 (* (- d2 d3) d1)
                                 (if (<= d4 2.25e+119) (* (- (- d3) d1) d1) (* (- d4 d3) d1))))
                              assert(d1 < d2 && d2 < d3 && d3 < d4);
                              double code(double d1, double d2, double d3, double d4) {
                              	double tmp;
                              	if (d4 <= -9.8e-219) {
                              		tmp = (d2 - d3) * d1;
                              	} else if (d4 <= 2.25e+119) {
                              		tmp = (-d3 - d1) * d1;
                              	} else {
                              		tmp = (d4 - d3) * d1;
                              	}
                              	return tmp;
                              }
                              
                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                              real(8) function code(d1, d2, d3, d4)
                                  real(8), intent (in) :: d1
                                  real(8), intent (in) :: d2
                                  real(8), intent (in) :: d3
                                  real(8), intent (in) :: d4
                                  real(8) :: tmp
                                  if (d4 <= (-9.8d-219)) then
                                      tmp = (d2 - d3) * d1
                                  else if (d4 <= 2.25d+119) then
                                      tmp = (-d3 - d1) * d1
                                  else
                                      tmp = (d4 - d3) * d1
                                  end if
                                  code = tmp
                              end function
                              
                              assert d1 < d2 && d2 < d3 && d3 < d4;
                              public static double code(double d1, double d2, double d3, double d4) {
                              	double tmp;
                              	if (d4 <= -9.8e-219) {
                              		tmp = (d2 - d3) * d1;
                              	} else if (d4 <= 2.25e+119) {
                              		tmp = (-d3 - d1) * d1;
                              	} else {
                              		tmp = (d4 - d3) * d1;
                              	}
                              	return tmp;
                              }
                              
                              [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                              def code(d1, d2, d3, d4):
                              	tmp = 0
                              	if d4 <= -9.8e-219:
                              		tmp = (d2 - d3) * d1
                              	elif d4 <= 2.25e+119:
                              		tmp = (-d3 - d1) * d1
                              	else:
                              		tmp = (d4 - d3) * d1
                              	return tmp
                              
                              d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                              function code(d1, d2, d3, d4)
                              	tmp = 0.0
                              	if (d4 <= -9.8e-219)
                              		tmp = Float64(Float64(d2 - d3) * d1);
                              	elseif (d4 <= 2.25e+119)
                              		tmp = Float64(Float64(Float64(-d3) - d1) * d1);
                              	else
                              		tmp = Float64(Float64(d4 - d3) * d1);
                              	end
                              	return tmp
                              end
                              
                              d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                              function tmp_2 = code(d1, d2, d3, d4)
                              	tmp = 0.0;
                              	if (d4 <= -9.8e-219)
                              		tmp = (d2 - d3) * d1;
                              	elseif (d4 <= 2.25e+119)
                              		tmp = (-d3 - d1) * d1;
                              	else
                              		tmp = (d4 - d3) * d1;
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                              code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, -9.8e-219], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 2.25e+119], N[(N[((-d3) - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
                              
                              \begin{array}{l}
                              [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;d4 \leq -9.8 \cdot 10^{-219}:\\
                              \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                              
                              \mathbf{elif}\;d4 \leq 2.25 \cdot 10^{+119}:\\
                              \;\;\;\;\left(\left(-d3\right) - d1\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 < -9.79999999999999981e-219

                                1. Initial program 93.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 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--.f6478.4

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

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

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

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

                                  if -9.79999999999999981e-219 < d4 < 2.2500000000000001e119

                                  1. Initial program 85.0%

                                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in 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. lower--.f64N/A

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

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

                                    \[\leadsto \color{blue}{\left(\left(d4 - d3\right) - d1\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 rewrites74.3%

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

                                    if 2.2500000000000001e119 < d4

                                    1. Initial program 89.7%

                                      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in 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. lower--.f64N/A

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

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

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

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

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

                                    Alternative 8: 70.2% accurate, 1.4× speedup?

                                    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.8 \cdot 10^{+107} \lor \neg \left(d3 \leq 2.65 \cdot 10^{+128}\right):\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
                                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                    (FPCore (d1 d2 d3 d4)
                                     :precision binary64
                                     (if (or (<= d3 -1.8e+107) (not (<= d3 2.65e+128)))
                                       (* (- d2 d3) d1)
                                       (* (- d4 d1) d1)))
                                    assert(d1 < d2 && d2 < d3 && d3 < d4);
                                    double code(double d1, double d2, double d3, double d4) {
                                    	double tmp;
                                    	if ((d3 <= -1.8e+107) || !(d3 <= 2.65e+128)) {
                                    		tmp = (d2 - d3) * d1;
                                    	} else {
                                    		tmp = (d4 - d1) * d1;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                    real(8) function code(d1, d2, d3, d4)
                                        real(8), intent (in) :: d1
                                        real(8), intent (in) :: d2
                                        real(8), intent (in) :: d3
                                        real(8), intent (in) :: d4
                                        real(8) :: tmp
                                        if ((d3 <= (-1.8d+107)) .or. (.not. (d3 <= 2.65d+128))) then
                                            tmp = (d2 - d3) * d1
                                        else
                                            tmp = (d4 - d1) * d1
                                        end if
                                        code = tmp
                                    end function
                                    
                                    assert d1 < d2 && d2 < d3 && d3 < d4;
                                    public static double code(double d1, double d2, double d3, double d4) {
                                    	double tmp;
                                    	if ((d3 <= -1.8e+107) || !(d3 <= 2.65e+128)) {
                                    		tmp = (d2 - d3) * d1;
                                    	} else {
                                    		tmp = (d4 - d1) * d1;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                    def code(d1, d2, d3, d4):
                                    	tmp = 0
                                    	if (d3 <= -1.8e+107) or not (d3 <= 2.65e+128):
                                    		tmp = (d2 - d3) * d1
                                    	else:
                                    		tmp = (d4 - d1) * d1
                                    	return tmp
                                    
                                    d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                    function code(d1, d2, d3, d4)
                                    	tmp = 0.0
                                    	if ((d3 <= -1.8e+107) || !(d3 <= 2.65e+128))
                                    		tmp = Float64(Float64(d2 - d3) * d1);
                                    	else
                                    		tmp = Float64(Float64(d4 - d1) * d1);
                                    	end
                                    	return tmp
                                    end
                                    
                                    d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                    function tmp_2 = code(d1, d2, d3, d4)
                                    	tmp = 0.0;
                                    	if ((d3 <= -1.8e+107) || ~((d3 <= 2.65e+128)))
                                    		tmp = (d2 - d3) * d1;
                                    	else
                                    		tmp = (d4 - d1) * d1;
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                    code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -1.8e+107], N[Not[LessEqual[d3, 2.65e+128]], $MachinePrecision]], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;d3 \leq -1.8 \cdot 10^{+107} \lor \neg \left(d3 \leq 2.65 \cdot 10^{+128}\right):\\
                                    \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if d3 < -1.7999999999999999e107 or 2.6500000000000001e128 < d3

                                      1. Initial program 85.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--.f6487.1

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

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

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

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

                                        if -1.7999999999999999e107 < d3 < 2.6500000000000001e128

                                        1. Initial program 90.6%

                                          \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in d2 around 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. lower--.f64N/A

                                            \[\leadsto \color{blue}{\left(\left(d4 - d3\right) - d1\right)} \cdot d1 \]
                                          8. lower--.f6481.1

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

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

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

                                            \[\leadsto \left(d4 - d1\right) \cdot d1 \]
                                        8. Recombined 2 regimes into one program.
                                        9. Final simplification76.6%

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

                                        Alternative 9: 69.5% accurate, 1.4× speedup?

                                        \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d1 \leq -5.5 \cdot 10^{+44}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d1 \leq 2.05 \cdot 10^{-53}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \end{array} \end{array} \]
                                        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                        (FPCore (d1 d2 d3 d4)
                                         :precision binary64
                                         (if (<= d1 -5.5e+44)
                                           (* (- d2 d1) d1)
                                           (if (<= d1 2.05e-53) (* (- d4 d3) d1) (* (- d4 d1) d1))))
                                        assert(d1 < d2 && d2 < d3 && d3 < d4);
                                        double code(double d1, double d2, double d3, double d4) {
                                        	double tmp;
                                        	if (d1 <= -5.5e+44) {
                                        		tmp = (d2 - d1) * d1;
                                        	} else if (d1 <= 2.05e-53) {
                                        		tmp = (d4 - d3) * d1;
                                        	} else {
                                        		tmp = (d4 - d1) * d1;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                        real(8) function code(d1, d2, d3, d4)
                                            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 <= (-5.5d+44)) then
                                                tmp = (d2 - d1) * d1
                                            else if (d1 <= 2.05d-53) then
                                                tmp = (d4 - d3) * d1
                                            else
                                                tmp = (d4 - d1) * d1
                                            end if
                                            code = tmp
                                        end function
                                        
                                        assert d1 < d2 && d2 < d3 && d3 < d4;
                                        public static double code(double d1, double d2, double d3, double d4) {
                                        	double tmp;
                                        	if (d1 <= -5.5e+44) {
                                        		tmp = (d2 - d1) * d1;
                                        	} else if (d1 <= 2.05e-53) {
                                        		tmp = (d4 - d3) * d1;
                                        	} else {
                                        		tmp = (d4 - d1) * d1;
                                        	}
                                        	return tmp;
                                        }
                                        
                                        [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                        def code(d1, d2, d3, d4):
                                        	tmp = 0
                                        	if d1 <= -5.5e+44:
                                        		tmp = (d2 - d1) * d1
                                        	elif d1 <= 2.05e-53:
                                        		tmp = (d4 - d3) * d1
                                        	else:
                                        		tmp = (d4 - d1) * d1
                                        	return tmp
                                        
                                        d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                        function code(d1, d2, d3, d4)
                                        	tmp = 0.0
                                        	if (d1 <= -5.5e+44)
                                        		tmp = Float64(Float64(d2 - d1) * d1);
                                        	elseif (d1 <= 2.05e-53)
                                        		tmp = Float64(Float64(d4 - d3) * d1);
                                        	else
                                        		tmp = Float64(Float64(d4 - d1) * d1);
                                        	end
                                        	return tmp
                                        end
                                        
                                        d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                        function tmp_2 = code(d1, d2, d3, d4)
                                        	tmp = 0.0;
                                        	if (d1 <= -5.5e+44)
                                        		tmp = (d2 - d1) * d1;
                                        	elseif (d1 <= 2.05e-53)
                                        		tmp = (d4 - d3) * d1;
                                        	else
                                        		tmp = (d4 - d1) * d1;
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                        code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -5.5e+44], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 2.05e-53], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision]]]
                                        
                                        \begin{array}{l}
                                        [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;d1 \leq -5.5 \cdot 10^{+44}:\\
                                        \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                                        
                                        \mathbf{elif}\;d1 \leq 2.05 \cdot 10^{-53}:\\
                                        \;\;\;\;\left(d4 - 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 < -5.5000000000000001e44

                                          1. Initial program 72.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--.f6492.5

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

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

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

                                            if -5.5000000000000001e44 < d1 < 2.05e-53

                                            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 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. lower--.f64N/A

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

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

                                              \[\leadsto \color{blue}{\left(\left(d4 - d3\right) - d1\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.5%

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

                                              if 2.05e-53 < d1

                                              1. Initial program 81.6%

                                                \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in d2 around 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. lower--.f64N/A

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

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

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

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

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

                                              Alternative 10: 54.4% accurate, 1.5× speedup?

                                              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq -6.2 \cdot 10^{-219}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 5.5 \cdot 10^{+63}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                              (FPCore (d1 d2 d3 d4)
                                               :precision binary64
                                               (if (<= d4 -6.2e-219) (* d2 d1) (if (<= d4 5.5e+63) (* (- d1) d3) (* d4 d1))))
                                              assert(d1 < d2 && d2 < d3 && d3 < d4);
                                              double code(double d1, double d2, double d3, double d4) {
                                              	double tmp;
                                              	if (d4 <= -6.2e-219) {
                                              		tmp = d2 * d1;
                                              	} else if (d4 <= 5.5e+63) {
                                              		tmp = -d1 * d3;
                                              	} else {
                                              		tmp = d4 * d1;
                                              	}
                                              	return tmp;
                                              }
                                              
                                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                              real(8) function code(d1, d2, d3, d4)
                                                  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 <= (-6.2d-219)) then
                                                      tmp = d2 * d1
                                                  else if (d4 <= 5.5d+63) then
                                                      tmp = -d1 * d3
                                                  else
                                                      tmp = d4 * d1
                                                  end if
                                                  code = tmp
                                              end function
                                              
                                              assert d1 < d2 && d2 < d3 && d3 < d4;
                                              public static double code(double d1, double d2, double d3, double d4) {
                                              	double tmp;
                                              	if (d4 <= -6.2e-219) {
                                              		tmp = d2 * d1;
                                              	} else if (d4 <= 5.5e+63) {
                                              		tmp = -d1 * d3;
                                              	} else {
                                              		tmp = d4 * d1;
                                              	}
                                              	return tmp;
                                              }
                                              
                                              [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                              def code(d1, d2, d3, d4):
                                              	tmp = 0
                                              	if d4 <= -6.2e-219:
                                              		tmp = d2 * d1
                                              	elif d4 <= 5.5e+63:
                                              		tmp = -d1 * d3
                                              	else:
                                              		tmp = d4 * d1
                                              	return tmp
                                              
                                              d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                              function code(d1, d2, d3, d4)
                                              	tmp = 0.0
                                              	if (d4 <= -6.2e-219)
                                              		tmp = Float64(d2 * d1);
                                              	elseif (d4 <= 5.5e+63)
                                              		tmp = Float64(Float64(-d1) * d3);
                                              	else
                                              		tmp = Float64(d4 * d1);
                                              	end
                                              	return tmp
                                              end
                                              
                                              d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                              function tmp_2 = code(d1, d2, d3, d4)
                                              	tmp = 0.0;
                                              	if (d4 <= -6.2e-219)
                                              		tmp = d2 * d1;
                                              	elseif (d4 <= 5.5e+63)
                                              		tmp = -d1 * d3;
                                              	else
                                              		tmp = d4 * d1;
                                              	end
                                              	tmp_2 = tmp;
                                              end
                                              
                                              NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                              code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, -6.2e-219], N[(d2 * d1), $MachinePrecision], If[LessEqual[d4, 5.5e+63], N[((-d1) * d3), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
                                              
                                              \begin{array}{l}
                                              [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                              \\
                                              \begin{array}{l}
                                              \mathbf{if}\;d4 \leq -6.2 \cdot 10^{-219}:\\
                                              \;\;\;\;d2 \cdot d1\\
                                              
                                              \mathbf{elif}\;d4 \leq 5.5 \cdot 10^{+63}:\\
                                              \;\;\;\;\left(-d1\right) \cdot d3\\
                                              
                                              \mathbf{else}:\\
                                              \;\;\;\;d4 \cdot d1\\
                                              
                                              
                                              \end{array}
                                              \end{array}
                                              
                                              Derivation
                                              1. Split input into 3 regimes
                                              2. if d4 < -6.1999999999999994e-219

                                                1. Initial program 93.0%

                                                  \[\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. +-commutativeN/A

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

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

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

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

                                                    \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, d1 \cdot d2 - d1 \cdot d3\right)} \]
                                                  9. lower--.f6499.0

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

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

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

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

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

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

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

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

                                                  \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\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-*.f6430.6

                                                    \[\leadsto \color{blue}{d2 \cdot d1} \]
                                                7. Applied rewrites30.6%

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

                                                if -6.1999999999999994e-219 < d4 < 5.50000000000000004e63

                                                1. Initial program 86.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-+.f6469.3

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

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

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

                                                    \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d3\right)} \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites41.4%

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

                                                    if 5.50000000000000004e63 < d4

                                                    1. Initial program 86.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-*.f6464.2

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

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

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

                                                  Alternative 11: 93.7% accurate, 1.7× speedup?

                                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+69}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 - d3\right) - d1\right) \cdot d1\\ \end{array} \end{array} \]
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  (FPCore (d1 d2 d3 d4)
                                                   :precision binary64
                                                   (if (<= d2 -1.35e+69) (* (- (+ d4 d2) d3) d1) (* (- (- d4 d3) d1) d1)))
                                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d2 <= -1.35e+69) {
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	} else {
                                                  		tmp = ((d4 - d3) - d1) * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  real(8) function code(d1, d2, d3, d4)
                                                      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 <= (-1.35d+69)) then
                                                          tmp = ((d4 + d2) - d3) * d1
                                                      else
                                                          tmp = ((d4 - d3) - d1) * d1
                                                      end if
                                                      code = tmp
                                                  end function
                                                  
                                                  assert d1 < d2 && d2 < d3 && d3 < d4;
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d2 <= -1.35e+69) {
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	} else {
                                                  		tmp = ((d4 - d3) - d1) * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                                  def code(d1, d2, d3, d4):
                                                  	tmp = 0
                                                  	if d2 <= -1.35e+69:
                                                  		tmp = ((d4 + d2) - d3) * d1
                                                  	else:
                                                  		tmp = ((d4 - d3) - d1) * d1
                                                  	return tmp
                                                  
                                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                                  function code(d1, d2, d3, d4)
                                                  	tmp = 0.0
                                                  	if (d2 <= -1.35e+69)
                                                  		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                                                  	else
                                                  		tmp = Float64(Float64(Float64(d4 - d3) - d1) * d1);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                                  function tmp_2 = code(d1, d2, d3, d4)
                                                  	tmp = 0.0;
                                                  	if (d2 <= -1.35e+69)
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	else
                                                  		tmp = ((d4 - d3) - d1) * d1;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.35e+69], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;d2 \leq -1.35 \cdot 10^{+69}:\\
                                                  \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;\left(\left(d4 - d3\right) - d1\right) \cdot d1\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if d2 < -1.3499999999999999e69

                                                    1. Initial program 78.3%

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

                                                      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + 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-+.f6491.9

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

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

                                                    if -1.3499999999999999e69 < d2

                                                    1. Initial program 90.8%

                                                      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                                    2. Add Preprocessing
                                                    3. Taylor expanded in 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. lower--.f64N/A

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

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

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

                                                  Alternative 12: 92.6% accurate, 1.7× speedup?

                                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 2.25 \cdot 10^{+119}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  (FPCore (d1 d2 d3 d4)
                                                   :precision binary64
                                                   (if (<= d4 2.25e+119) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
                                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d4 <= 2.25e+119) {
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	} else {
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  real(8) function code(d1, d2, d3, d4)
                                                      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.25d+119) then
                                                          tmp = ((d2 - d3) - d1) * d1
                                                      else
                                                          tmp = ((d4 + d2) - d3) * d1
                                                      end if
                                                      code = tmp
                                                  end function
                                                  
                                                  assert d1 < d2 && d2 < d3 && d3 < d4;
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d4 <= 2.25e+119) {
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	} else {
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                                  def code(d1, d2, d3, d4):
                                                  	tmp = 0
                                                  	if d4 <= 2.25e+119:
                                                  		tmp = ((d2 - d3) - d1) * d1
                                                  	else:
                                                  		tmp = ((d4 + d2) - d3) * d1
                                                  	return tmp
                                                  
                                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                                  function code(d1, d2, d3, d4)
                                                  	tmp = 0.0
                                                  	if (d4 <= 2.25e+119)
                                                  		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                                                  	else
                                                  		tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                                  function tmp_2 = code(d1, d2, d3, d4)
                                                  	tmp = 0.0;
                                                  	if (d4 <= 2.25e+119)
                                                  		tmp = ((d2 - d3) - d1) * d1;
                                                  	else
                                                  		tmp = ((d4 + d2) - d3) * d1;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 2.25e+119], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;d4 \leq 2.25 \cdot 10^{+119}:\\
                                                  \;\;\;\;\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 < 2.2500000000000001e119

                                                    1. Initial program 88.9%

                                                      \[\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--.f6485.6

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

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

                                                    if 2.2500000000000001e119 < d4

                                                    1. Initial program 89.7%

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

                                                      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + 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-+.f6498.0

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

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

                                                  Alternative 13: 49.9% accurate, 2.5× speedup?

                                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 4 \cdot 10^{-82}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  (FPCore (d1 d2 d3 d4)
                                                   :precision binary64
                                                   (if (<= d4 4e-82) (* d2 d1) (* d4 d1)))
                                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d4 <= 4e-82) {
                                                  		tmp = d2 * d1;
                                                  	} else {
                                                  		tmp = d4 * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  real(8) function code(d1, d2, d3, d4)
                                                      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 <= 4d-82) then
                                                          tmp = d2 * d1
                                                      else
                                                          tmp = d4 * d1
                                                      end if
                                                      code = tmp
                                                  end function
                                                  
                                                  assert d1 < d2 && d2 < d3 && d3 < d4;
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	double tmp;
                                                  	if (d4 <= 4e-82) {
                                                  		tmp = d2 * d1;
                                                  	} else {
                                                  		tmp = d4 * d1;
                                                  	}
                                                  	return tmp;
                                                  }
                                                  
                                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                                  def code(d1, d2, d3, d4):
                                                  	tmp = 0
                                                  	if d4 <= 4e-82:
                                                  		tmp = d2 * d1
                                                  	else:
                                                  		tmp = d4 * d1
                                                  	return tmp
                                                  
                                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                                  function code(d1, d2, d3, d4)
                                                  	tmp = 0.0
                                                  	if (d4 <= 4e-82)
                                                  		tmp = Float64(d2 * d1);
                                                  	else
                                                  		tmp = Float64(d4 * d1);
                                                  	end
                                                  	return tmp
                                                  end
                                                  
                                                  d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                                  function tmp_2 = code(d1, d2, d3, d4)
                                                  	tmp = 0.0;
                                                  	if (d4 <= 4e-82)
                                                  		tmp = d2 * d1;
                                                  	else
                                                  		tmp = d4 * d1;
                                                  	end
                                                  	tmp_2 = tmp;
                                                  end
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 4e-82], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
                                                  
                                                  \begin{array}{l}
                                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                                  \\
                                                  \begin{array}{l}
                                                  \mathbf{if}\;d4 \leq 4 \cdot 10^{-82}:\\
                                                  \;\;\;\;d2 \cdot d1\\
                                                  
                                                  \mathbf{else}:\\
                                                  \;\;\;\;d4 \cdot d1\\
                                                  
                                                  
                                                  \end{array}
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. if d4 < 4e-82

                                                    1. Initial program 91.8%

                                                      \[\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. +-commutativeN/A

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

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

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

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

                                                        \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, d1 \cdot d2 - d1 \cdot d3\right)} \]
                                                      9. lower--.f6495.6

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

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

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

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

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

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

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

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

                                                      \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\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-*.f6431.5

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

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

                                                    if 4e-82 < d4

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

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

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

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

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

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

                                                  Alternative 14: 31.1% accurate, 5.0× speedup?

                                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ d2 \cdot d1 \end{array} \]
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  (FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
                                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                                  double code(double d1, double d2, double d3, double d4) {
                                                  	return d2 * d1;
                                                  }
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  real(8) function code(d1, d2, d3, d4)
                                                      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
                                                  
                                                  assert d1 < d2 && d2 < d3 && d3 < d4;
                                                  public static double code(double d1, double d2, double d3, double d4) {
                                                  	return d2 * d1;
                                                  }
                                                  
                                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                                  def code(d1, d2, d3, d4):
                                                  	return d2 * d1
                                                  
                                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                                  function code(d1, d2, d3, d4)
                                                  	return Float64(d2 * d1)
                                                  end
                                                  
                                                  d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                                                  function tmp = code(d1, d2, d3, d4)
                                                  	tmp = d2 * d1;
                                                  end
                                                  
                                                  NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                                                  code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
                                                  
                                                  \begin{array}{l}
                                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                                  \\
                                                  d2 \cdot d1
                                                  \end{array}
                                                  
                                                  Derivation
                                                  1. Initial program 89.0%

                                                    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
                                                  2. Add Preprocessing
                                                  3. 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. +-commutativeN/A

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

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

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

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

                                                      \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, d1 \cdot d2 - d1 \cdot d3\right)} \]
                                                    9. lower--.f6493.7

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

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

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

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

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

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

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

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

                                                    \[\leadsto \color{blue}{\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\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-*.f6426.0

                                                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                                                  7. Applied rewrites26.0%

                                                    \[\leadsto \color{blue}{d2 \cdot d1} \]
                                                  8. Final simplification26.0%

                                                    \[\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);
                                                  }
                                                  
                                                  real(8) function code(d1, d2, d3, d4)
                                                      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 2024315 
                                                  (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)))