FastMath dist4

Percentage Accurate: 88.3% → 99.1%
Time: 39.4s
Alternatives: 15
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 88.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: 99.1% accurate, 1.2× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -4.0000000000000003e272

    1. Initial program 58.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. lower-*.f64N/A

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

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

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

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

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

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

    if -4.0000000000000003e272 < d2

    1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -5.2000000000000002e138

    1. Initial program 62.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. lower-*.f64N/A

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

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

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

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

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

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

    if -5.2000000000000002e138 < d1 < 1.15000000000000005e-23

    1. Initial program 98.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. lower-*.f64N/A

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

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

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

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

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

    if 1.15000000000000005e-23 < d1

    1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.04e71 or 9e20 < d3

    1. Initial program 83.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. lower-*.f64N/A

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

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

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

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

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

    if -1.04e71 < d3 < 9e20

    1. Initial program 91.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 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. lower-*.f64N/A

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

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

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

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

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

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

Alternative 4: 89.4% accurate, 1.2× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -9 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 1.25 \cdot 10^{+83}:\\ \;\;\;\;d1 \cdot \left(d2 + \left(d4 - d1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\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 -9e+74)
   (* d1 (- d2 d3))
   (if (<= d3 1.25e+83) (* d1 (+ d2 (- d4 d1))) (* d1 (- d4 d3)))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d3 <= -9e+74) {
		tmp = d1 * (d2 - d3);
	} else if (d3 <= 1.25e+83) {
		tmp = d1 * (d2 + (d4 - d1));
	} else {
		tmp = d1 * (d4 - d3);
	}
	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 <= (-9d+74)) then
        tmp = d1 * (d2 - d3)
    else if (d3 <= 1.25d+83) then
        tmp = d1 * (d2 + (d4 - d1))
    else
        tmp = d1 * (d4 - d3)
    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 <= -9e+74) {
		tmp = d1 * (d2 - d3);
	} else if (d3 <= 1.25e+83) {
		tmp = d1 * (d2 + (d4 - d1));
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	tmp = 0
	if d3 <= -9e+74:
		tmp = d1 * (d2 - d3)
	elif d3 <= 1.25e+83:
		tmp = d1 * (d2 + (d4 - d1))
	else:
		tmp = d1 * (d4 - d3)
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d3 <= -9e+74)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d3 <= 1.25e+83)
		tmp = Float64(d1 * Float64(d2 + Float64(d4 - d1)));
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	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 <= -9e+74)
		tmp = d1 * (d2 - d3);
	elseif (d3 <= 1.25e+83)
		tmp = d1 * (d2 + (d4 - d1));
	else
		tmp = d1 * (d4 - d3);
	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, -9e+74], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 1.25e+83], N[(d1 * N[(d2 + N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -9 \cdot 10^{+74}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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

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


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

    1. Initial program 79.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -8.9999999999999999e74 < d3 < 1.25000000000000007e83

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

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

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

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

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

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

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

      if 1.25000000000000007e83 < d3

      1. Initial program 84.4%

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

        \[\leadsto \color{blue}{d1 \cdot d2} \]
      4. Step-by-step derivation
        1. lower-*.f6411.3

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 5: 99.0% accurate, 1.2× speedup?

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

        1. Initial program 56.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -1.18000000000000004e154 < d1

        1. Initial program 92.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 6: 71.9% accurate, 1.4× speedup?

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

        1. Initial program 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto d1 \cdot \left(\color{blue}{\left(d2 - d1\right)} - d3\right) \]
          12. lower--.f6475.9

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

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

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

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

          if -245 < d2 < -3.2e-295

          1. Initial program 86.6%

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

            \[\leadsto \color{blue}{d1 \cdot d2} \]
          4. Step-by-step derivation
            1. lower-*.f645.6

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -3.2e-295 < d2

            1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

            Alternative 7: 71.6% accurate, 1.4× speedup?

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

              1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -1.7499999999999999e88 < d2 < -3.2e-295

                1. Initial program 89.5%

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

                  \[\leadsto \color{blue}{d1 \cdot d2} \]
                4. Step-by-step derivation
                  1. lower-*.f6410.2

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if -3.2e-295 < d2

                  1. Initial program 92.0%

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

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

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

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

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

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

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

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

                      \[\leadsto d1 \cdot \left(d4 - \color{blue}{d1}\right) \]
                  8. Recombined 3 regimes into one program.
                  9. Final simplification62.1%

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

                  Alternative 8: 67.9% accurate, 1.4× speedup?

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

                        \[\leadsto \color{blue}{\mathsf{neg}\left(d1 \cdot d3\right)} \]
                      2. distribute-rgt-neg-inN/A

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

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

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

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

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

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

                    if -3.09999999999999986e193 < d3 < 1.19999999999999996e83

                    1. Initial program 90.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. lower-*.f64N/A

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

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

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

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

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

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

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

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

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

                    Alternative 9: 51.1% accurate, 1.5× speedup?

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

                      1. Initial program 85.1%

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      4. Step-by-step derivation
                        1. lower-*.f6422.0

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

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

                      if -3.3999999999999999e-39 < d4 < 3.34999999999999986e47

                      1. Initial program 90.7%

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

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

                          \[\leadsto \color{blue}{\mathsf{neg}\left(d1 \cdot d3\right)} \]
                        2. distribute-rgt-neg-inN/A

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

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

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

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

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

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

                      if 3.34999999999999986e47 < d4

                      1. Initial program 86.7%

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

                        \[\leadsto \color{blue}{d1 \cdot d4} \]
                      4. Step-by-step derivation
                        1. lower-*.f6471.2

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

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

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

                    Alternative 10: 54.1% accurate, 1.5× speedup?

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

                      1. Initial program 87.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. lower-*.f6428.8

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

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

                      if 5.0000000000000003e-293 < d4 < 4.39999999999999999e91

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

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

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

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

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

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

                      if 4.39999999999999999e91 < d4

                      1. Initial program 83.7%

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

                        \[\leadsto \color{blue}{d1 \cdot d4} \]
                      4. Step-by-step derivation
                        1. lower-*.f6480.6

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

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

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

                    Alternative 11: 94.1% accurate, 1.7× speedup?

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

                      1. Initial program 89.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if 5.6000000000000004e-12 < d4

                      1. Initial program 86.1%

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      4. Step-by-step derivation
                        1. lower-*.f6420.9

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

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

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

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

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

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

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

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

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

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

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

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

                      1. Initial program 89.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if 5.09999999999999962e80 < d4

                        1. Initial program 84.6%

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

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

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

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

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

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

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

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

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

                        Alternative 13: 70.9% accurate, 2.0× speedup?

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

                          1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if -1.70000000000000002e88 < d2

                            1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

                            Alternative 14: 50.9% accurate, 2.5× speedup?

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

                              1. Initial program 89.2%

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

                                \[\leadsto \color{blue}{d1 \cdot d2} \]
                              4. Step-by-step derivation
                                1. lower-*.f6433.9

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

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

                              if 2.75e75 < d4

                              1. Initial program 84.6%

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

                                \[\leadsto \color{blue}{d1 \cdot d4} \]
                              4. Step-by-step derivation
                                1. lower-*.f6478.0

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

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

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

                            Alternative 15: 32.0% 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 88.3%

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

                              \[\leadsto \color{blue}{d1 \cdot d2} \]
                            4. Step-by-step derivation
                              1. lower-*.f6430.0

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

                              \[\leadsto \color{blue}{d1 \cdot d2} \]
                            6. Final simplification30.0%

                              \[\leadsto d2 \cdot d1 \]
                            7. 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 2024219 
                            (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)))