FastMath dist4

Percentage Accurate: 87.8% → 98.3%
Time: 58.5s
Alternatives: 15
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 15 alternatives:

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

Initial Program: 87.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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.3% accurate, 1.2× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.2 \cdot 10^{+205}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, \left(\left(d2 - d3\right) - d1\right) \cdot d1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d2, d1, d1 \cdot d4\right)\\ \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 1.2e+205)
   (fma d4 d1 (* (- (- d2 d3) d1) d1))
   (fma d2 d1 (* d1 d4))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 1.2e+205) {
		tmp = fma(d4, d1, (((d2 - d3) - d1) * d1));
	} else {
		tmp = fma(d2, d1, (d1 * d4));
	}
	return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 1.2e+205)
		tmp = fma(d4, d1, Float64(Float64(Float64(d2 - d3) - d1) * d1));
	else
		tmp = fma(d2, d1, Float64(d1 * d4));
	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[d4, 1.2e+205], N[(d4 * d1 + N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], N[(d2 * d1 + N[(d1 * d4), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 1.2 \cdot 10^{+205}:\\
\;\;\;\;\mathsf{fma}\left(d4, d1, \left(\left(d2 - d3\right) - d1\right) \cdot d1\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(d2, d1, d1 \cdot d4\right)\\


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

    1. Initial program 85.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.19999999999999993e205 < d4

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{d1 \cdot d4}\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{d4 \cdot d1}\right) \]
    7. Applied rewrites99.9%

      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{d4 \cdot d1}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.4%

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

Alternative 2: 72.4% accurate, 1.1× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.05 \cdot 10^{+140}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -1.45 \cdot 10^{+18}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -6.5 \cdot 10^{-292}:\\ \;\;\;\;\left(d4 - 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 (<= d2 -1.05e+140)
   (* (- d2 d1) d1)
   (if (<= d2 -1.45e+18)
     (* (- d2 d3) d1)
     (if (<= d2 -6.5e-292) (* (- d4 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 (d2 <= -1.05e+140) {
		tmp = (d2 - d1) * d1;
	} else if (d2 <= -1.45e+18) {
		tmp = (d2 - d3) * d1;
	} else if (d2 <= -6.5e-292) {
		tmp = (d4 - 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 (d2 <= (-1.05d+140)) then
        tmp = (d2 - d1) * d1
    else if (d2 <= (-1.45d+18)) then
        tmp = (d2 - d3) * d1
    else if (d2 <= (-6.5d-292)) then
        tmp = (d4 - 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 (d2 <= -1.05e+140) {
		tmp = (d2 - d1) * d1;
	} else if (d2 <= -1.45e+18) {
		tmp = (d2 - d3) * d1;
	} else if (d2 <= -6.5e-292) {
		tmp = (d4 - 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 d2 <= -1.05e+140:
		tmp = (d2 - d1) * d1
	elif d2 <= -1.45e+18:
		tmp = (d2 - d3) * d1
	elif d2 <= -6.5e-292:
		tmp = (d4 - 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 (d2 <= -1.05e+140)
		tmp = Float64(Float64(d2 - d1) * d1);
	elseif (d2 <= -1.45e+18)
		tmp = Float64(Float64(d2 - d3) * d1);
	elseif (d2 <= -6.5e-292)
		tmp = Float64(Float64(d4 - 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 (d2 <= -1.05e+140)
		tmp = (d2 - d1) * d1;
	elseif (d2 <= -1.45e+18)
		tmp = (d2 - d3) * d1;
	elseif (d2 <= -6.5e-292)
		tmp = (d4 - 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[d2, -1.05e+140], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -1.45e+18], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -6.5e-292], N[(N[(d4 - 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}\;d2 \leq -1.05 \cdot 10^{+140}:\\
\;\;\;\;\left(d2 - d1\right) \cdot d1\\

\mathbf{elif}\;d2 \leq -1.45 \cdot 10^{+18}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -1.0500000000000001e140

    1. Initial program 60.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 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--.f6488.1

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

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

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

      if -1.0500000000000001e140 < d2 < -1.45e18

      1. Initial program 83.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--.f6490.7

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

        \[\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 rewrites75.4%

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

        if -1.45e18 < d2 < -6.4999999999999997e-292

        1. Initial program 88.2%

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

          \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
        4. Step-by-step derivation
          1. distribute-lft-outN/A

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

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

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

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

            \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
          6. associate-+r+N/A

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

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

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

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

            \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
          11. unsub-negN/A

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

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

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

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

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

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

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

          if -6.4999999999999997e-292 < 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 inf

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

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

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

            \[\leadsto \color{blue}{d2 \cdot d1} \]
          6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) - d3\right) \cdot d1 \]
            11. sub-negN/A

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

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

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

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

              \[\leadsto \color{blue}{\left(\left(d4 - d3\right) - d1\right)} \cdot d1 \]
            16. lower--.f6472.6

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

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

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

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

          Alternative 3: 52.5% accurate, 1.2× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -8 \cdot 10^{+120}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -9.5 \cdot 10^{+17}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d2 \leq 1.55 \cdot 10^{-306}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \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 -8e+120)
             (* d2 d1)
             (if (<= d2 -9.5e+17)
               (* (- d1) d3)
               (if (<= d2 1.55e-306) (* (- d1) d1) (* d1 d4)))))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d2 <= -8e+120) {
          		tmp = d2 * d1;
          	} else if (d2 <= -9.5e+17) {
          		tmp = -d1 * d3;
          	} else if (d2 <= 1.55e-306) {
          		tmp = -d1 * d1;
          	} else {
          		tmp = d1 * d4;
          	}
          	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 <= (-8d+120)) then
                  tmp = d2 * d1
              else if (d2 <= (-9.5d+17)) then
                  tmp = -d1 * d3
              else if (d2 <= 1.55d-306) then
                  tmp = -d1 * d1
              else
                  tmp = d1 * d4
              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 <= -8e+120) {
          		tmp = d2 * d1;
          	} else if (d2 <= -9.5e+17) {
          		tmp = -d1 * d3;
          	} else if (d2 <= 1.55e-306) {
          		tmp = -d1 * d1;
          	} else {
          		tmp = d1 * d4;
          	}
          	return tmp;
          }
          
          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if d2 <= -8e+120:
          		tmp = d2 * d1
          	elif d2 <= -9.5e+17:
          		tmp = -d1 * d3
          	elif d2 <= 1.55e-306:
          		tmp = -d1 * d1
          	else:
          		tmp = d1 * d4
          	return tmp
          
          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d2 <= -8e+120)
          		tmp = Float64(d2 * d1);
          	elseif (d2 <= -9.5e+17)
          		tmp = Float64(Float64(-d1) * d3);
          	elseif (d2 <= 1.55e-306)
          		tmp = Float64(Float64(-d1) * d1);
          	else
          		tmp = Float64(d1 * d4);
          	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 <= -8e+120)
          		tmp = d2 * d1;
          	elseif (d2 <= -9.5e+17)
          		tmp = -d1 * d3;
          	elseif (d2 <= 1.55e-306)
          		tmp = -d1 * d1;
          	else
          		tmp = d1 * d4;
          	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, -8e+120], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -9.5e+17], N[((-d1) * d3), $MachinePrecision], If[LessEqual[d2, 1.55e-306], N[((-d1) * d1), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]]
          
          \begin{array}{l}
          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;d2 \leq -8 \cdot 10^{+120}:\\
          \;\;\;\;d2 \cdot d1\\
          
          \mathbf{elif}\;d2 \leq -9.5 \cdot 10^{+17}:\\
          \;\;\;\;\left(-d1\right) \cdot d3\\
          
          \mathbf{elif}\;d2 \leq 1.55 \cdot 10^{-306}:\\
          \;\;\;\;\left(-d1\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;d1 \cdot d4\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 4 regimes
          2. if d2 < -7.9999999999999998e120

            1. Initial program 63.9%

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

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

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

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

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

            if -7.9999999999999998e120 < d2 < -9.5e17

            1. Initial program 81.0%

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

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

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

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

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

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

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

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

            if -9.5e17 < d2 < 1.54999999999999999e-306

            1. Initial program 87.6%

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

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

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

            if 1.54999999999999999e-306 < d2

            1. Initial program 91.2%

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

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

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -8 \cdot 10^{+120}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -9.5 \cdot 10^{+17}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{elif}\;d2 \leq 1.55 \cdot 10^{-306}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
          5. Add Preprocessing

          Alternative 4: 93.2% accurate, 1.2× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 450000:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 1.2 \cdot 10^{+145}:\\ \;\;\;\;\left(\left(d4 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 + d4\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 (<= d4 450000.0)
             (* (- (- d2 d3) d1) d1)
             (if (<= d4 1.2e+145) (* (- (- d4 d3) d1) d1) (* (- (+ d2 d4) d1) d1))))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	double tmp;
          	if (d4 <= 450000.0) {
          		tmp = ((d2 - d3) - d1) * d1;
          	} else if (d4 <= 1.2e+145) {
          		tmp = ((d4 - d3) - d1) * d1;
          	} else {
          		tmp = ((d2 + 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 (d4 <= 450000.0d0) then
                  tmp = ((d2 - d3) - d1) * d1
              else if (d4 <= 1.2d+145) then
                  tmp = ((d4 - d3) - d1) * d1
              else
                  tmp = ((d2 + 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 (d4 <= 450000.0) {
          		tmp = ((d2 - d3) - d1) * d1;
          	} else if (d4 <= 1.2e+145) {
          		tmp = ((d4 - d3) - d1) * d1;
          	} else {
          		tmp = ((d2 + d4) - d1) * d1;
          	}
          	return tmp;
          }
          
          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
          def code(d1, d2, d3, d4):
          	tmp = 0
          	if d4 <= 450000.0:
          		tmp = ((d2 - d3) - d1) * d1
          	elif d4 <= 1.2e+145:
          		tmp = ((d4 - d3) - d1) * d1
          	else:
          		tmp = ((d2 + d4) - d1) * d1
          	return tmp
          
          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
          function code(d1, d2, d3, d4)
          	tmp = 0.0
          	if (d4 <= 450000.0)
          		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
          	elseif (d4 <= 1.2e+145)
          		tmp = Float64(Float64(Float64(d4 - d3) - d1) * d1);
          	else
          		tmp = Float64(Float64(Float64(d2 + 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 (d4 <= 450000.0)
          		tmp = ((d2 - d3) - d1) * d1;
          	elseif (d4 <= 1.2e+145)
          		tmp = ((d4 - d3) - d1) * d1;
          	else
          		tmp = ((d2 + 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[d4, 450000.0], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 1.2e+145], N[(N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]]
          
          \begin{array}{l}
          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;d4 \leq 450000:\\
          \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
          
          \mathbf{elif}\;d4 \leq 1.2 \cdot 10^{+145}:\\
          \;\;\;\;\left(\left(d4 - d3\right) - d1\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(\left(d2 + d4\right) - d1\right) \cdot d1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if d4 < 4.5e5

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

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

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

            if 4.5e5 < d4 < 1.19999999999999996e145

            1. Initial program 96.9%

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

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

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

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

              \[\leadsto \color{blue}{d2 \cdot d1} \]
            6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) - d3\right) \cdot d1 \]
              11. sub-negN/A

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

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

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

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

                \[\leadsto \color{blue}{\left(\left(d4 - d3\right) - d1\right)} \cdot d1 \]
              16. lower--.f6477.7

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

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

            if 1.19999999999999996e145 < d4

            1. Initial program 79.4%

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

              \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
            4. Step-by-step derivation
              1. distribute-lft-outN/A

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

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

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

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

                \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
              6. associate-+r+N/A

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

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

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

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

                \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
              11. unsub-negN/A

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

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

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

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

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

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

          Alternative 5: 92.0% accurate, 1.2× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(\left(d2 + d4\right) - d1\right) \cdot d1\\ \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+114}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 3 \cdot 10^{+68}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d3\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 d4) d1) d1)))
             (if (<= d1 -3.3e+114) t_0 (if (<= d1 3e+68) (* (- (+ d2 d4) d3) d1) t_0))))
          assert(d1 < d2 && d2 < d3 && d3 < d4);
          double code(double d1, double d2, double d3, double d4) {
          	double t_0 = ((d2 + d4) - d1) * d1;
          	double tmp;
          	if (d1 <= -3.3e+114) {
          		tmp = t_0;
          	} else if (d1 <= 3e+68) {
          		tmp = ((d2 + d4) - d3) * 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 + d4) - d1) * d1
              if (d1 <= (-3.3d+114)) then
                  tmp = t_0
              else if (d1 <= 3d+68) then
                  tmp = ((d2 + d4) - d3) * 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 + d4) - d1) * d1;
          	double tmp;
          	if (d1 <= -3.3e+114) {
          		tmp = t_0;
          	} else if (d1 <= 3e+68) {
          		tmp = ((d2 + d4) - d3) * 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 + d4) - d1) * d1
          	tmp = 0
          	if d1 <= -3.3e+114:
          		tmp = t_0
          	elif d1 <= 3e+68:
          		tmp = ((d2 + d4) - d3) * 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(Float64(d2 + d4) - d1) * d1)
          	tmp = 0.0
          	if (d1 <= -3.3e+114)
          		tmp = t_0;
          	elseif (d1 <= 3e+68)
          		tmp = Float64(Float64(Float64(d2 + d4) - d3) * 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 + d4) - d1) * d1;
          	tmp = 0.0;
          	if (d1 <= -3.3e+114)
          		tmp = t_0;
          	elseif (d1 <= 3e+68)
          		tmp = ((d2 + d4) - d3) * 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[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d1, -3.3e+114], t$95$0, If[LessEqual[d1, 3e+68], N[(N[(N[(d2 + d4), $MachinePrecision] - d3), $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(\left(d2 + d4\right) - d1\right) \cdot d1\\
          \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+114}:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;d1 \leq 3 \cdot 10^{+68}:\\
          \;\;\;\;\left(\left(d2 + d4\right) - d3\right) \cdot d1\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d1 < -3.3000000000000001e114 or 3.0000000000000002e68 < d1

            1. Initial program 61.7%

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

              \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
            4. Step-by-step derivation
              1. distribute-lft-outN/A

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

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

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

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

                \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
              6. associate-+r+N/A

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

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

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

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

                \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
              11. unsub-negN/A

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

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

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

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

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

            if -3.3000000000000001e114 < d1 < 3.0000000000000002e68

            1. Initial program 99.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-+.f6494.1

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

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

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

          Alternative 6: 90.0% accurate, 1.2× speedup?

          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -9.2 \cdot 10^{+98}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 8.2 \cdot 10^{+105}:\\ \;\;\;\;\left(\left(d2 + d4\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 (<= d3 -9.2e+98)
             (* (- d2 d3) d1)
             (if (<= d3 8.2e+105) (* (- (+ d2 d4) 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 (d3 <= -9.2e+98) {
          		tmp = (d2 - d3) * d1;
          	} else if (d3 <= 8.2e+105) {
          		tmp = ((d2 + d4) - 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 (d3 <= (-9.2d+98)) then
                  tmp = (d2 - d3) * d1
              else if (d3 <= 8.2d+105) then
                  tmp = ((d2 + d4) - 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 (d3 <= -9.2e+98) {
          		tmp = (d2 - d3) * d1;
          	} else if (d3 <= 8.2e+105) {
          		tmp = ((d2 + d4) - 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 d3 <= -9.2e+98:
          		tmp = (d2 - d3) * d1
          	elif d3 <= 8.2e+105:
          		tmp = ((d2 + d4) - 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 (d3 <= -9.2e+98)
          		tmp = Float64(Float64(d2 - d3) * d1);
          	elseif (d3 <= 8.2e+105)
          		tmp = Float64(Float64(Float64(d2 + d4) - 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 (d3 <= -9.2e+98)
          		tmp = (d2 - d3) * d1;
          	elseif (d3 <= 8.2e+105)
          		tmp = ((d2 + d4) - 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[d3, -9.2e+98], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 8.2e+105], N[(N[(N[(d2 + d4), $MachinePrecision] - 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}\;d3 \leq -9.2 \cdot 10^{+98}:\\
          \;\;\;\;\left(d2 - d3\right) \cdot d1\\
          
          \mathbf{elif}\;d3 \leq 8.2 \cdot 10^{+105}:\\
          \;\;\;\;\left(\left(d2 + d4\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 d3 < -9.20000000000000053e98

            1. Initial program 66.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 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--.f6486.4

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

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

              if -9.20000000000000053e98 < d3 < 8.2000000000000005e105

              1. Initial program 90.7%

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

                \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
              4. Step-by-step derivation
                1. distribute-lft-outN/A

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

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

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

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

                  \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                6. associate-+r+N/A

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

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

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

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

                  \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                11. unsub-negN/A

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

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

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

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

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

              if 8.2000000000000005e105 < d3

              1. Initial program 76.2%

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

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

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

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

                \[\leadsto \color{blue}{d2 \cdot d1} \]
              6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) - d3\right) \cdot d1 \]
                11. sub-negN/A

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

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

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

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

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

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

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

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

                  \[\leadsto \left(d4 - d3\right) \cdot d1 \]
              11. Recombined 3 regimes into one program.
              12. Final simplification90.3%

                \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -9.2 \cdot 10^{+98}:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d3 \leq 8.2 \cdot 10^{+105}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d4 - d3\right) \cdot d1\\ \end{array} \]
              13. Add Preprocessing

              Alternative 7: 74.9% accurate, 1.3× speedup?

              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -8.2 \cdot 10^{+120}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -7 \cdot 10^{-301}:\\ \;\;\;\;\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 (<= d2 -8.2e+120)
                 (* (- d2 d1) d1)
                 (if (<= d2 -7e-301) (* (- (- 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 (d2 <= -8.2e+120) {
              		tmp = (d2 - d1) * d1;
              	} else if (d2 <= -7e-301) {
              		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 (d2 <= (-8.2d+120)) then
                      tmp = (d2 - d1) * d1
                  else if (d2 <= (-7d-301)) 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 (d2 <= -8.2e+120) {
              		tmp = (d2 - d1) * d1;
              	} else if (d2 <= -7e-301) {
              		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 d2 <= -8.2e+120:
              		tmp = (d2 - d1) * d1
              	elif d2 <= -7e-301:
              		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 (d2 <= -8.2e+120)
              		tmp = Float64(Float64(d2 - d1) * d1);
              	elseif (d2 <= -7e-301)
              		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 (d2 <= -8.2e+120)
              		tmp = (d2 - d1) * d1;
              	elseif (d2 <= -7e-301)
              		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[d2, -8.2e+120], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -7e-301], 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}\;d2 \leq -8.2 \cdot 10^{+120}:\\
              \;\;\;\;\left(d2 - d1\right) \cdot d1\\
              
              \mathbf{elif}\;d2 \leq -7 \cdot 10^{-301}:\\
              \;\;\;\;\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 d2 < -8.2e120

                1. Initial program 63.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--.f6489.1

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

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

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

                  if -8.2e120 < d2 < -6.99999999999999984e-301

                  1. Initial program 86.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--.f6474.4

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

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

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

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

                    if -6.99999999999999984e-301 < d2

                    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 inf

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

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

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

                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                    6. Taylor expanded in d2 around 0

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \left(\left(d4 + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) - d3\right) \cdot d1 \]
                      11. sub-negN/A

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

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

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

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

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

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

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

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

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

                    Alternative 8: 72.0% accurate, 1.4× speedup?

                    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.05 \cdot 10^{+140}:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -1.45 \cdot 10^{+18}:\\ \;\;\;\;\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 (<= d2 -1.05e+140)
                       (* (- d2 d1) d1)
                       (if (<= d2 -1.45e+18) (* (- 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 (d2 <= -1.05e+140) {
                    		tmp = (d2 - d1) * d1;
                    	} else if (d2 <= -1.45e+18) {
                    		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 (d2 <= (-1.05d+140)) then
                            tmp = (d2 - d1) * d1
                        else if (d2 <= (-1.45d+18)) 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 (d2 <= -1.05e+140) {
                    		tmp = (d2 - d1) * d1;
                    	} else if (d2 <= -1.45e+18) {
                    		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 d2 <= -1.05e+140:
                    		tmp = (d2 - d1) * d1
                    	elif d2 <= -1.45e+18:
                    		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 (d2 <= -1.05e+140)
                    		tmp = Float64(Float64(d2 - d1) * d1);
                    	elseif (d2 <= -1.45e+18)
                    		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 (d2 <= -1.05e+140)
                    		tmp = (d2 - d1) * d1;
                    	elseif (d2 <= -1.45e+18)
                    		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[LessEqual[d2, -1.05e+140], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -1.45e+18], 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}\;d2 \leq -1.05 \cdot 10^{+140}:\\
                    \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                    
                    \mathbf{elif}\;d2 \leq -1.45 \cdot 10^{+18}:\\
                    \;\;\;\;\left(d2 - 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 d2 < -1.0500000000000001e140

                      1. Initial program 60.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 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--.f6488.1

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

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

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

                        if -1.0500000000000001e140 < d2 < -1.45e18

                        1. Initial program 83.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--.f6490.7

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

                          \[\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 rewrites75.4%

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

                          if -1.45e18 < d2

                          1. Initial program 89.9%

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

                            \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                          4. Step-by-step derivation
                            1. distribute-lft-outN/A

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

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

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

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

                              \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                            6. associate-+r+N/A

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

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

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

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

                              \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                            11. unsub-negN/A

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

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

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

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

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

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

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

                          Alternative 9: 71.1% accurate, 1.4× speedup?

                          \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 760000:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 2 \cdot 10^{+152}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\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 760000.0)
                             (* (- d2 d1) d1)
                             (if (<= d4 2e+152) (* (- d4 d1) d1) (* (+ d2 d4) d1))))
                          assert(d1 < d2 && d2 < d3 && d3 < d4);
                          double code(double d1, double d2, double d3, double d4) {
                          	double tmp;
                          	if (d4 <= 760000.0) {
                          		tmp = (d2 - d1) * d1;
                          	} else if (d4 <= 2e+152) {
                          		tmp = (d4 - d1) * d1;
                          	} else {
                          		tmp = (d2 + 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 <= 760000.0d0) then
                                  tmp = (d2 - d1) * d1
                              else if (d4 <= 2d+152) then
                                  tmp = (d4 - d1) * d1
                              else
                                  tmp = (d2 + 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 <= 760000.0) {
                          		tmp = (d2 - d1) * d1;
                          	} else if (d4 <= 2e+152) {
                          		tmp = (d4 - d1) * d1;
                          	} else {
                          		tmp = (d2 + d4) * d1;
                          	}
                          	return tmp;
                          }
                          
                          [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                          def code(d1, d2, d3, d4):
                          	tmp = 0
                          	if d4 <= 760000.0:
                          		tmp = (d2 - d1) * d1
                          	elif d4 <= 2e+152:
                          		tmp = (d4 - d1) * d1
                          	else:
                          		tmp = (d2 + d4) * d1
                          	return tmp
                          
                          d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                          function code(d1, d2, d3, d4)
                          	tmp = 0.0
                          	if (d4 <= 760000.0)
                          		tmp = Float64(Float64(d2 - d1) * d1);
                          	elseif (d4 <= 2e+152)
                          		tmp = Float64(Float64(d4 - d1) * d1);
                          	else
                          		tmp = Float64(Float64(d2 + 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 <= 760000.0)
                          		tmp = (d2 - d1) * d1;
                          	elseif (d4 <= 2e+152)
                          		tmp = (d4 - d1) * d1;
                          	else
                          		tmp = (d2 + 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, 760000.0], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d4, 2e+152], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]]
                          
                          \begin{array}{l}
                          [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;d4 \leq 760000:\\
                          \;\;\;\;\left(d2 - d1\right) \cdot d1\\
                          
                          \mathbf{elif}\;d4 \leq 2 \cdot 10^{+152}:\\
                          \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 3 regimes
                          2. if d4 < 7.6e5

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

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

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

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

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

                              if 7.6e5 < d4 < 2.0000000000000001e152

                              1. Initial program 91.4%

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

                                \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                              4. Step-by-step derivation
                                1. distribute-lft-outN/A

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

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

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

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

                                  \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                                6. associate-+r+N/A

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

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

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

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

                                  \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                                11. unsub-negN/A

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

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

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

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

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

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

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

                                if 2.0000000000000001e152 < d4

                                1. Initial program 84.4%

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

                                  \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                4. Step-by-step derivation
                                  1. distribute-lft-outN/A

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

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

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

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

                                    \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                                  6. associate-+r+N/A

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

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

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

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

                                    \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                                  11. unsub-negN/A

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

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

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

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

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

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

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

                                  \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 760000:\\ \;\;\;\;\left(d2 - d1\right) \cdot d1\\ \mathbf{elif}\;d4 \leq 2 \cdot 10^{+152}:\\ \;\;\;\;\left(d4 - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \]
                                10. Add Preprocessing

                                Alternative 10: 66.2% accurate, 1.4× 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 -2.5 \cdot 10^{+135}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 6.2 \cdot 10^{+123}:\\ \;\;\;\;\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 -2.5e+135) t_0 (if (<= d1 6.2e+123) (* (+ 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 <= -2.5e+135) {
                                		tmp = t_0;
                                	} else if (d1 <= 6.2e+123) {
                                		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 <= (-2.5d+135)) then
                                        tmp = t_0
                                    else if (d1 <= 6.2d+123) 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 <= -2.5e+135) {
                                		tmp = t_0;
                                	} else if (d1 <= 6.2e+123) {
                                		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 <= -2.5e+135:
                                		tmp = t_0
                                	elif d1 <= 6.2e+123:
                                		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 <= -2.5e+135)
                                		tmp = t_0;
                                	elseif (d1 <= 6.2e+123)
                                		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 <= -2.5e+135)
                                		tmp = t_0;
                                	elseif (d1 <= 6.2e+123)
                                		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, -2.5e+135], t$95$0, If[LessEqual[d1, 6.2e+123], 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 -2.5 \cdot 10^{+135}:\\
                                \;\;\;\;t\_0\\
                                
                                \mathbf{elif}\;d1 \leq 6.2 \cdot 10^{+123}:\\
                                \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;t\_0\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if d1 < -2.50000000000000015e135 or 6.20000000000000013e123 < d1

                                  1. Initial program 54.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 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.f6481.4

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

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

                                  if -2.50000000000000015e135 < d1 < 6.20000000000000013e123

                                  1. Initial program 98.8%

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

                                    \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                  4. Step-by-step derivation
                                    1. distribute-lft-outN/A

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

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

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

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

                                      \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                                    6. associate-+r+N/A

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

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

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

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

                                      \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                                    11. unsub-negN/A

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

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

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

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

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

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

                                      \[\leadsto \left(d4 + d2\right) \cdot d1 \]
                                  8. Recombined 2 regimes into one program.
                                  9. Final simplification72.1%

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

                                  Alternative 11: 53.1% accurate, 1.5× speedup?

                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -2.7 \cdot 10^{+75}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq 1.55 \cdot 10^{-306}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \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 -2.7e+75)
                                     (* d2 d1)
                                     (if (<= d2 1.55e-306) (* (- d1) d1) (* d1 d4))))
                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                  double code(double d1, double d2, double d3, double d4) {
                                  	double tmp;
                                  	if (d2 <= -2.7e+75) {
                                  		tmp = d2 * d1;
                                  	} else if (d2 <= 1.55e-306) {
                                  		tmp = -d1 * d1;
                                  	} else {
                                  		tmp = d1 * d4;
                                  	}
                                  	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 <= (-2.7d+75)) then
                                          tmp = d2 * d1
                                      else if (d2 <= 1.55d-306) then
                                          tmp = -d1 * d1
                                      else
                                          tmp = d1 * d4
                                      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 <= -2.7e+75) {
                                  		tmp = d2 * d1;
                                  	} else if (d2 <= 1.55e-306) {
                                  		tmp = -d1 * d1;
                                  	} else {
                                  		tmp = d1 * d4;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                  def code(d1, d2, d3, d4):
                                  	tmp = 0
                                  	if d2 <= -2.7e+75:
                                  		tmp = d2 * d1
                                  	elif d2 <= 1.55e-306:
                                  		tmp = -d1 * d1
                                  	else:
                                  		tmp = d1 * d4
                                  	return tmp
                                  
                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                  function code(d1, d2, d3, d4)
                                  	tmp = 0.0
                                  	if (d2 <= -2.7e+75)
                                  		tmp = Float64(d2 * d1);
                                  	elseif (d2 <= 1.55e-306)
                                  		tmp = Float64(Float64(-d1) * d1);
                                  	else
                                  		tmp = Float64(d1 * d4);
                                  	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 <= -2.7e+75)
                                  		tmp = d2 * d1;
                                  	elseif (d2 <= 1.55e-306)
                                  		tmp = -d1 * d1;
                                  	else
                                  		tmp = d1 * d4;
                                  	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, -2.7e+75], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 1.55e-306], N[((-d1) * d1), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
                                  
                                  \begin{array}{l}
                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;d2 \leq -2.7 \cdot 10^{+75}:\\
                                  \;\;\;\;d2 \cdot d1\\
                                  
                                  \mathbf{elif}\;d2 \leq 1.55 \cdot 10^{-306}:\\
                                  \;\;\;\;\left(-d1\right) \cdot d1\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;d1 \cdot d4\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 3 regimes
                                  2. if d2 < -2.69999999999999998e75

                                    1. Initial program 72.9%

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

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

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

                                        \[\leadsto \color{blue}{d2 \cdot d1} \]
                                    5. Applied rewrites67.2%

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

                                    if -2.69999999999999998e75 < d2 < 1.54999999999999999e-306

                                    1. Initial program 84.1%

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

                                      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
                                    4. Step-by-step derivation
                                      1. 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.6

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

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

                                    if 1.54999999999999999e-306 < d2

                                    1. Initial program 91.2%

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

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

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

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

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

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

                                  Alternative 12: 91.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 7.6 \cdot 10^{+21}:\\ \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 + d4\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 (<= d4 7.6e+21) (* (- (- d2 d3) d1) d1) (* (- (+ d2 d4) d1) d1)))
                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                  double code(double d1, double d2, double d3, double d4) {
                                  	double tmp;
                                  	if (d4 <= 7.6e+21) {
                                  		tmp = ((d2 - d3) - d1) * d1;
                                  	} else {
                                  		tmp = ((d2 + 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 (d4 <= 7.6d+21) then
                                          tmp = ((d2 - d3) - d1) * d1
                                      else
                                          tmp = ((d2 + 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 (d4 <= 7.6e+21) {
                                  		tmp = ((d2 - d3) - d1) * d1;
                                  	} else {
                                  		tmp = ((d2 + d4) - d1) * d1;
                                  	}
                                  	return tmp;
                                  }
                                  
                                  [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                  def code(d1, d2, d3, d4):
                                  	tmp = 0
                                  	if d4 <= 7.6e+21:
                                  		tmp = ((d2 - d3) - d1) * d1
                                  	else:
                                  		tmp = ((d2 + d4) - d1) * d1
                                  	return tmp
                                  
                                  d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                  function code(d1, d2, d3, d4)
                                  	tmp = 0.0
                                  	if (d4 <= 7.6e+21)
                                  		tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1);
                                  	else
                                  		tmp = Float64(Float64(Float64(d2 + 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 (d4 <= 7.6e+21)
                                  		tmp = ((d2 - d3) - d1) * d1;
                                  	else
                                  		tmp = ((d2 + 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[d4, 7.6e+21], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision]]
                                  
                                  \begin{array}{l}
                                  [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;d4 \leq 7.6 \cdot 10^{+21}:\\
                                  \;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\left(\left(d2 + d4\right) - d1\right) \cdot d1\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 2 regimes
                                  2. if d4 < 7.6e21

                                    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 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--.f6482.2

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

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

                                    if 7.6e21 < d4

                                    1. Initial program 87.1%

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

                                      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                    4. Step-by-step derivation
                                      1. distribute-lft-outN/A

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

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

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

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

                                        \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                                      6. associate-+r+N/A

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

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

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

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

                                        \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                                      11. unsub-negN/A

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

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

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

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

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

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

                                  Alternative 13: 70.3% accurate, 2.0× speedup?

                                  \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -2.6 \cdot 10^{+75}:\\ \;\;\;\;\left(d2 + d4\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 (<= d2 -2.6e+75) (* (+ d2 d4) d1) (* (- d4 d1) d1)))
                                  assert(d1 < d2 && d2 < d3 && d3 < d4);
                                  double code(double d1, double d2, double d3, double d4) {
                                  	double tmp;
                                  	if (d2 <= -2.6e+75) {
                                  		tmp = (d2 + d4) * 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 (d2 <= (-2.6d+75)) then
                                          tmp = (d2 + d4) * 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 (d2 <= -2.6e+75) {
                                  		tmp = (d2 + d4) * 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 d2 <= -2.6e+75:
                                  		tmp = (d2 + d4) * 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 (d2 <= -2.6e+75)
                                  		tmp = Float64(Float64(d2 + d4) * 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 (d2 <= -2.6e+75)
                                  		tmp = (d2 + d4) * 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[d2, -2.6e+75], N[(N[(d2 + d4), $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}\;d2 \leq -2.6 \cdot 10^{+75}:\\
                                  \;\;\;\;\left(d2 + d4\right) \cdot d1\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\left(d4 - d1\right) \cdot d1\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 2 regimes
                                  2. if d2 < -2.59999999999999985e75

                                    1. Initial program 72.9%

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

                                      \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                    4. Step-by-step derivation
                                      1. distribute-lft-outN/A

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

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

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

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

                                        \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                                      6. associate-+r+N/A

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

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

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

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

                                        \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                                      11. unsub-negN/A

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

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

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

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

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

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

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

                                      if -2.59999999999999985e75 < d2

                                      1. Initial program 88.4%

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

                                        \[\leadsto \color{blue}{\left(d1 \cdot d2 + d1 \cdot d4\right) - {d1}^{2}} \]
                                      4. Step-by-step derivation
                                        1. distribute-lft-outN/A

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

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

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

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

                                          \[\leadsto d1 \cdot \left(\left(d2 + d4\right) + \color{blue}{-1 \cdot d1}\right) \]
                                        6. associate-+r+N/A

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

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

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

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

                                          \[\leadsto \left(\left(d2 + d4\right) + \color{blue}{\left(\mathsf{neg}\left(d1\right)\right)}\right) \cdot d1 \]
                                        11. unsub-negN/A

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

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

                                          \[\leadsto \left(\color{blue}{\left(d4 + d2\right)} - d1\right) \cdot d1 \]
                                        14. lower-+.f6477.9

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

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

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

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

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

                                      Alternative 14: 49.2% accurate, 2.5× speedup?

                                      \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+75}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \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 -3.25e+75) (* d2 d1) (* d1 d4)))
                                      assert(d1 < d2 && d2 < d3 && d3 < d4);
                                      double code(double d1, double d2, double d3, double d4) {
                                      	double tmp;
                                      	if (d2 <= -3.25e+75) {
                                      		tmp = d2 * d1;
                                      	} else {
                                      		tmp = d1 * d4;
                                      	}
                                      	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 <= (-3.25d+75)) then
                                              tmp = d2 * d1
                                          else
                                              tmp = d1 * d4
                                          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 <= -3.25e+75) {
                                      		tmp = d2 * d1;
                                      	} else {
                                      		tmp = d1 * d4;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
                                      def code(d1, d2, d3, d4):
                                      	tmp = 0
                                      	if d2 <= -3.25e+75:
                                      		tmp = d2 * d1
                                      	else:
                                      		tmp = d1 * d4
                                      	return tmp
                                      
                                      d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                                      function code(d1, d2, d3, d4)
                                      	tmp = 0.0
                                      	if (d2 <= -3.25e+75)
                                      		tmp = Float64(d2 * d1);
                                      	else
                                      		tmp = Float64(d1 * d4);
                                      	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 <= -3.25e+75)
                                      		tmp = d2 * d1;
                                      	else
                                      		tmp = d1 * d4;
                                      	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, -3.25e+75], N[(d2 * d1), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]
                                      
                                      \begin{array}{l}
                                      [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;d2 \leq -3.25 \cdot 10^{+75}:\\
                                      \;\;\;\;d2 \cdot d1\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;d1 \cdot d4\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 2 regimes
                                      2. if d2 < -3.2499999999999999e75

                                        1. Initial program 72.9%

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

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

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

                                            \[\leadsto \color{blue}{d2 \cdot d1} \]
                                        5. Applied rewrites67.2%

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

                                        if -3.2499999999999999e75 < d2

                                        1. Initial program 88.4%

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

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

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

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

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

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

                                      Alternative 15: 30.5% 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 85.5%

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

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

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

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

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

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

                                      \[\begin{array}{l} \\ d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \end{array} \]
                                      (FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
                                      double code(double d1, double d2, double d3, double d4) {
                                      	return d1 * (((d2 - d3) + d4) - d1);
                                      }
                                      
                                      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 2024235 
                                      (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)))