FastMath dist4

Percentage Accurate: 87.3% → 96.9%
Time: 12.3s
Alternatives: 14
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 87.3% accurate, 1.0× speedup?

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

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -4 \cdot 10^{-267}:\\ \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d2, d1, \left(\left(d4 - d1\right) - d3\right) \cdot d1\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 (<= d3 -4e-267)
   (fma d1 (- d4 d1) (* (- d2 d3) d1))
   (fma d2 d1 (* (- (- d4 d1) d3) d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d3 <= -4e-267) {
		tmp = fma(d1, (d4 - d1), ((d2 - d3) * d1));
	} else {
		tmp = fma(d2, d1, (((d4 - d1) - d3) * d1));
	}
	return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d3 <= -4e-267)
		tmp = fma(d1, Float64(d4 - d1), Float64(Float64(d2 - d3) * d1));
	else
		tmp = fma(d2, d1, Float64(Float64(Float64(d4 - d1) - d3) * d1));
	end
	return tmp
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -4e-267], N[(d1 * N[(d4 - d1), $MachinePrecision] + N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], N[(d2 * d1 + N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -4 \cdot 10^{-267}:\\
\;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -3.9999999999999999e-267

    1. Initial program 89.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.9999999999999999e-267 < d3

    1. Initial program 91.6%

      \[\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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

\mathbf{elif}\;d4 \leq 2.6 \cdot 10^{-124}:\\
\;\;\;\;\left(-d3\right) \cdot d1\\

\mathbf{elif}\;d4 \leq 1.36 \cdot 10^{+47}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\

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


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

    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 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-*.f6428.5

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

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

    if -1.64999999999999996e-217 < d4 < 2.6e-124

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

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

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

    if 2.6e-124 < d4 < 1.3599999999999999e47

    1. Initial program 94.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.f6454.7

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

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

    if 1.3599999999999999e47 < d4

    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. 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-*.f6467.0

        \[\leadsto \color{blue}{d4 \cdot d1} \]
    5. Applied rewrites67.0%

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

Alternative 3: 93.7% accurate, 1.2× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.9 \cdot 10^{+78}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, \left(d2 - d3\right) \cdot d1\right)\\ \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+34}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d3\right) \cdot d1\\ \end{array} \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d3 -1.9e+78)
   (fma d4 d1 (* (- d2 d3) d1))
   (if (<= d3 4.2e+34) (* (- (+ d2 d4) d1) d1) (* (- (+ d2 d4) d3) d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d3 <= -1.9e+78) {
		tmp = fma(d4, d1, ((d2 - d3) * d1));
	} else if (d3 <= 4.2e+34) {
		tmp = ((d2 + d4) - d1) * d1;
	} else {
		tmp = ((d2 + 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 <= -1.9e+78)
		tmp = fma(d4, d1, Float64(Float64(d2 - d3) * d1));
	elseif (d3 <= 4.2e+34)
		tmp = Float64(Float64(Float64(d2 + d4) - d1) * d1);
	else
		tmp = Float64(Float64(Float64(d2 + d4) - d3) * d1);
	end
	return tmp
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := If[LessEqual[d3, -1.9e+78], N[(d4 * d1 + N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 4.2e+34], N[(N[(N[(d2 + d4), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d2 + d4), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.9 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(d4, d1, \left(d2 - d3\right) \cdot d1\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.9e78

    1. Initial program 80.0%

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

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

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

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

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

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

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

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

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

      if -1.9e78 < d3 < 4.20000000000000035e34

      1. Initial program 93.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-+.f6495.6

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

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

      if 4.20000000000000035e34 < d3

      1. Initial program 89.6%

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.9 \cdot 10^{+78}:\\ \;\;\;\;\mathsf{fma}\left(d4, d1, \left(d2 - d3\right) \cdot d1\right)\\ \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+34}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d3\right) \cdot d1\\ \end{array} \]
    9. Add Preprocessing

    Alternative 4: 93.7% 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) - d3\right) \cdot d1\\ \mathbf{if}\;d3 \leq -1.9 \cdot 10^{+78}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+34}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d1\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) d3) d1)))
       (if (<= d3 -1.9e+78) t_0 (if (<= d3 4.2e+34) (* (- (+ d2 d4) d1) 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) - d3) * d1;
    	double tmp;
    	if (d3 <= -1.9e+78) {
    		tmp = t_0;
    	} else if (d3 <= 4.2e+34) {
    		tmp = ((d2 + d4) - d1) * 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) - d3) * d1
        if (d3 <= (-1.9d+78)) then
            tmp = t_0
        else if (d3 <= 4.2d+34) then
            tmp = ((d2 + d4) - d1) * 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) - d3) * d1;
    	double tmp;
    	if (d3 <= -1.9e+78) {
    		tmp = t_0;
    	} else if (d3 <= 4.2e+34) {
    		tmp = ((d2 + d4) - d1) * 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) - d3) * d1
    	tmp = 0
    	if d3 <= -1.9e+78:
    		tmp = t_0
    	elif d3 <= 4.2e+34:
    		tmp = ((d2 + d4) - d1) * 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) - d3) * d1)
    	tmp = 0.0
    	if (d3 <= -1.9e+78)
    		tmp = t_0;
    	elseif (d3 <= 4.2e+34)
    		tmp = Float64(Float64(Float64(d2 + d4) - d1) * 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) - d3) * d1;
    	tmp = 0.0;
    	if (d3 <= -1.9e+78)
    		tmp = t_0;
    	elseif (d3 <= 4.2e+34)
    		tmp = ((d2 + d4) - d1) * 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] - d3), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -1.9e+78], t$95$0, If[LessEqual[d3, 4.2e+34], N[(N[(N[(d2 + d4), $MachinePrecision] - d1), $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) - d3\right) \cdot d1\\
    \mathbf{if}\;d3 \leq -1.9 \cdot 10^{+78}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+34}:\\
    \;\;\;\;\left(\left(d2 + d4\right) - d1\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if d3 < -1.9e78 or 4.20000000000000035e34 < d3

      1. Initial program 86.0%

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

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

      if -1.9e78 < d3 < 4.20000000000000035e34

      1. Initial program 93.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-+.f6495.6

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

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

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

    Alternative 5: 88.1% accurate, 1.2× speedup?

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

      1. Initial program 80.0%

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

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

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

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

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

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

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

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

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

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

        if -1.22000000000000002e79 < d3 < 7.49999999999999973e81

        1. Initial program 94.5%

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

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

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

        if 7.49999999999999973e81 < d3

        1. Initial program 86.5%

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(d2 - d3\right) \cdot d1 \]
        8. Recombined 3 regimes into one program.
        9. Final simplification90.9%

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

        Alternative 6: 96.7% accurate, 1.2× speedup?

        \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d1 \leq -2.1 \cdot 10^{+252}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\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 (<= d1 -2.1e+252) (* (- d1) d1) (fma d1 (- d4 d1) (* (- d2 d3) d1))))
        assert(d1 < d2 && d2 < d3 && d3 < d4);
        double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if (d1 <= -2.1e+252) {
        		tmp = -d1 * d1;
        	} else {
        		tmp = fma(d1, (d4 - d1), ((d2 - d3) * d1));
        	}
        	return tmp;
        }
        
        d1, d2, d3, d4 = sort([d1, d2, d3, d4])
        function code(d1, d2, d3, d4)
        	tmp = 0.0
        	if (d1 <= -2.1e+252)
        		tmp = Float64(Float64(-d1) * d1);
        	else
        		tmp = fma(d1, Float64(d4 - d1), Float64(Float64(d2 - d3) * d1));
        	end
        	return tmp
        end
        
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -2.1e+252], N[((-d1) * d1), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision] + N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;d1 \leq -2.1 \cdot 10^{+252}:\\
        \;\;\;\;\left(-d1\right) \cdot d1\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if d1 < -2.1000000000000001e252

          1. Initial program 33.3%

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

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

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

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

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

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

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

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

          if -2.1000000000000001e252 < d1

          1. Initial program 92.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Alternative 7: 91.3% accurate, 1.3× speedup?

        \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -3.7 \cdot 10^{+55}:\\ \;\;\;\;\left(\left(d2 + d4\right) - d3\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(-d3\right) \cdot d1\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 (<= d2 -3.7e+55)
           (* (- (+ d2 d4) d3) d1)
           (fma d1 (- d4 d1) (* (- d3) d1))))
        assert(d1 < d2 && d2 < d3 && d3 < d4);
        double code(double d1, double d2, double d3, double d4) {
        	double tmp;
        	if (d2 <= -3.7e+55) {
        		tmp = ((d2 + d4) - d3) * d1;
        	} else {
        		tmp = fma(d1, (d4 - d1), (-d3 * d1));
        	}
        	return tmp;
        }
        
        d1, d2, d3, d4 = sort([d1, d2, d3, d4])
        function code(d1, d2, d3, d4)
        	tmp = 0.0
        	if (d2 <= -3.7e+55)
        		tmp = Float64(Float64(Float64(d2 + d4) - d3) * d1);
        	else
        		tmp = fma(d1, Float64(d4 - d1), Float64(Float64(-d3) * d1));
        	end
        	return tmp
        end
        
        NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
        code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -3.7e+55], N[(N[(N[(d2 + d4), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision] + N[((-d3) * d1), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;d2 \leq -3.7 \cdot 10^{+55}:\\
        \;\;\;\;\left(\left(d2 + d4\right) - d3\right) \cdot d1\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(-d3\right) \cdot d1\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if d2 < -3.7000000000000002e55

          1. Initial program 84.9%

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

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

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

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

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

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

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

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

          if -3.7000000000000002e55 < d2

          1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(d1, d4 - d1, \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \cdot d1\right) \]
            2. lower-neg.f6487.3

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

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

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

        Alternative 8: 74.4% accurate, 1.4× speedup?

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

          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. Taylor expanded in d1 around 0

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

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

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

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

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

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

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

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

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

            if -6.7999999999999996e46 < d2 < -2.7e25

            1. Initial program 100.0%

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

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

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

              if -2.7e25 < d2

              1. Initial program 91.8%

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

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

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

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

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

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

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

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

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

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

              Alternative 9: 66.8% accurate, 1.4× speedup?

              \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := \left(-d3\right) \cdot d1\\ \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+55}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 5.2 \cdot 10^{+136}:\\ \;\;\;\;\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 (* (- d3) d1)))
                 (if (<= d3 -2.4e+55) t_0 (if (<= d3 5.2e+136) (* (+ 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 = -d3 * d1;
              	double tmp;
              	if (d3 <= -2.4e+55) {
              		tmp = t_0;
              	} else if (d3 <= 5.2e+136) {
              		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 = -d3 * d1
                  if (d3 <= (-2.4d+55)) then
                      tmp = t_0
                  else if (d3 <= 5.2d+136) 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 = -d3 * d1;
              	double tmp;
              	if (d3 <= -2.4e+55) {
              		tmp = t_0;
              	} else if (d3 <= 5.2e+136) {
              		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 = -d3 * d1
              	tmp = 0
              	if d3 <= -2.4e+55:
              		tmp = t_0
              	elif d3 <= 5.2e+136:
              		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(-d3) * d1)
              	tmp = 0.0
              	if (d3 <= -2.4e+55)
              		tmp = t_0;
              	elseif (d3 <= 5.2e+136)
              		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 = -d3 * d1;
              	tmp = 0.0;
              	if (d3 <= -2.4e+55)
              		tmp = t_0;
              	elseif (d3 <= 5.2e+136)
              		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[((-d3) * d1), $MachinePrecision]}, If[LessEqual[d3, -2.4e+55], t$95$0, If[LessEqual[d3, 5.2e+136], 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(-d3\right) \cdot d1\\
              \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+55}:\\
              \;\;\;\;t\_0\\
              
              \mathbf{elif}\;d3 \leq 5.2 \cdot 10^{+136}:\\
              \;\;\;\;\left(d2 + d4\right) \cdot d1\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_0\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if d3 < -2.3999999999999999e55 or 5.2000000000000003e136 < d3

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

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

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

                if -2.3999999999999999e55 < d3 < 5.2000000000000003e136

                1. Initial program 94.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-+.f6492.3

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

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

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

                Alternative 10: 54.6% accurate, 1.5× speedup?

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

                  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. 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 -1.25000000000000005e47 < d2 < 5.8000000000000002e-284

                  1. Initial program 95.7%

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

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

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

                  if 5.8000000000000002e-284 < d2

                  1. Initial program 89.0%

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

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

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

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

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

                Alternative 11: 72.0% accurate, 2.0× speedup?

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

                  1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

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

                    if 5.00000000000000022e47 < d4

                    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. 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-+.f6488.0

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

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

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

                    Alternative 12: 70.9% accurate, 2.0× speedup?

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

                      1. Initial program 92.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-+.f6473.7

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

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

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

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

                        if 3.45000000000000009e46 < d4

                        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. 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-+.f6488.0

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

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

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

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

                          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. 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.3999999999999998e47 < d2

                          1. Initial program 92.1%

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

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

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

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

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

                        Alternative 14: 31.7% 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 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-*.f6429.1

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

                          \[\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 2024244 
                        (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)))