FastMath dist4

Percentage Accurate: 87.7% → 100.0%
Time: 7.1s
Alternatives: 15
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 87.7% 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: 100.0% accurate, 1.7× speedup?

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

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. sub-neg88.6%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
    3. *-commutative88.6%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
    8. associate--l+88.6%

      \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
    9. distribute-lft-out--89.4%

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
    10. distribute-rgt-out--91.4%

      \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    11. distribute-lft-out100.0%

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

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

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

Alternative 2: 71.2% accurate, 0.5× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 + d4\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ t_2 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d3 \leq -7 \cdot 10^{+128}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq -5 \cdot 10^{-215}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d3 \leq -5 \cdot 10^{-310}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 7.8 \cdot 10^{-125}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d3 \leq 10^{+70}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \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))) (t_1 (* d1 (- d2 d3))) (t_2 (* d1 (- d2 d1))))
   (if (<= d3 -7e+128)
     t_1
     (if (<= d3 -5e-215)
       t_2
       (if (<= d3 -5e-310)
         t_0
         (if (<= d3 7.8e-125) t_2 (if (<= d3 1e+70) t_0 t_1)))))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 + d4);
	double t_1 = d1 * (d2 - d3);
	double t_2 = d1 * (d2 - d1);
	double tmp;
	if (d3 <= -7e+128) {
		tmp = t_1;
	} else if (d3 <= -5e-215) {
		tmp = t_2;
	} else if (d3 <= -5e-310) {
		tmp = t_0;
	} else if (d3 <= 7.8e-125) {
		tmp = t_2;
	} else if (d3 <= 1e+70) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = d1 * (d2 + d4)
    t_1 = d1 * (d2 - d3)
    t_2 = d1 * (d2 - d1)
    if (d3 <= (-7d+128)) then
        tmp = t_1
    else if (d3 <= (-5d-215)) then
        tmp = t_2
    else if (d3 <= (-5d-310)) then
        tmp = t_0
    else if (d3 <= 7.8d-125) then
        tmp = t_2
    else if (d3 <= 1d+70) then
        tmp = t_0
    else
        tmp = t_1
    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);
	double t_1 = d1 * (d2 - d3);
	double t_2 = d1 * (d2 - d1);
	double tmp;
	if (d3 <= -7e+128) {
		tmp = t_1;
	} else if (d3 <= -5e-215) {
		tmp = t_2;
	} else if (d3 <= -5e-310) {
		tmp = t_0;
	} else if (d3 <= 7.8e-125) {
		tmp = t_2;
	} else if (d3 <= 1e+70) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 + d4)
	t_1 = d1 * (d2 - d3)
	t_2 = d1 * (d2 - d1)
	tmp = 0
	if d3 <= -7e+128:
		tmp = t_1
	elif d3 <= -5e-215:
		tmp = t_2
	elif d3 <= -5e-310:
		tmp = t_0
	elif d3 <= 7.8e-125:
		tmp = t_2
	elif d3 <= 1e+70:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 + d4))
	t_1 = Float64(d1 * Float64(d2 - d3))
	t_2 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d3 <= -7e+128)
		tmp = t_1;
	elseif (d3 <= -5e-215)
		tmp = t_2;
	elseif (d3 <= -5e-310)
		tmp = t_0;
	elseif (d3 <= 7.8e-125)
		tmp = t_2;
	elseif (d3 <= 1e+70)
		tmp = t_0;
	else
		tmp = t_1;
	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);
	t_1 = d1 * (d2 - d3);
	t_2 = d1 * (d2 - d1);
	tmp = 0.0;
	if (d3 <= -7e+128)
		tmp = t_1;
	elseif (d3 <= -5e-215)
		tmp = t_2;
	elseif (d3 <= -5e-310)
		tmp = t_0;
	elseif (d3 <= 7.8e-125)
		tmp = t_2;
	elseif (d3 <= 1e+70)
		tmp = t_0;
	else
		tmp = t_1;
	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 + d4), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -7e+128], t$95$1, If[LessEqual[d3, -5e-215], t$95$2, If[LessEqual[d3, -5e-310], t$95$0, If[LessEqual[d3, 7.8e-125], t$95$2, If[LessEqual[d3, 1e+70], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 + d4\right)\\
t_1 := d1 \cdot \left(d2 - d3\right)\\
t_2 := d1 \cdot \left(d2 - d1\right)\\
\mathbf{if}\;d3 \leq -7 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d3 \leq -5 \cdot 10^{-215}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d3 \leq -5 \cdot 10^{-310}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d3 \leq 7.8 \cdot 10^{-125}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d3 \leq 10^{+70}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -6.99999999999999937e128 or 1.00000000000000007e70 < d3

    1. Initial program 87.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.8%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative87.8%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+87.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.2%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 96.3%

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

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

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

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

    if -6.99999999999999937e128 < d3 < -4.99999999999999956e-215 or -4.999999999999985e-310 < d3 < 7.79999999999999965e-125

    1. Initial program 88.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg88.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative88.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg88.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+88.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--88.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--89.0%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around 0 97.5%

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

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

    if -4.99999999999999956e-215 < d3 < -4.999999999999985e-310 or 7.79999999999999965e-125 < d3 < 1.00000000000000007e70

    1. Initial program 90.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg90.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+90.5%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--95.9%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 80.0%

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

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

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

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

Alternative 3: 67.3% accurate, 0.5× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 + d4\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ t_2 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d3 \leq -8.5 \cdot 10^{+178}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d3 \leq -2.3 \cdot 10^{-212}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d3 \leq -9 \cdot 10^{-309}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d3 \leq 1.25 \cdot 10^{-124}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d3 \leq 5.8 \cdot 10^{+149}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \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))) (t_1 (* d1 (- d3))) (t_2 (* d1 (- d2 d1))))
   (if (<= d3 -8.5e+178)
     t_1
     (if (<= d3 -2.3e-212)
       t_2
       (if (<= d3 -9e-309)
         t_0
         (if (<= d3 1.25e-124) t_2 (if (<= d3 5.8e+149) t_0 t_1)))))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 + d4);
	double t_1 = d1 * -d3;
	double t_2 = d1 * (d2 - d1);
	double tmp;
	if (d3 <= -8.5e+178) {
		tmp = t_1;
	} else if (d3 <= -2.3e-212) {
		tmp = t_2;
	} else if (d3 <= -9e-309) {
		tmp = t_0;
	} else if (d3 <= 1.25e-124) {
		tmp = t_2;
	} else if (d3 <= 5.8e+149) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = d1 * (d2 + d4)
    t_1 = d1 * -d3
    t_2 = d1 * (d2 - d1)
    if (d3 <= (-8.5d+178)) then
        tmp = t_1
    else if (d3 <= (-2.3d-212)) then
        tmp = t_2
    else if (d3 <= (-9d-309)) then
        tmp = t_0
    else if (d3 <= 1.25d-124) then
        tmp = t_2
    else if (d3 <= 5.8d+149) then
        tmp = t_0
    else
        tmp = t_1
    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);
	double t_1 = d1 * -d3;
	double t_2 = d1 * (d2 - d1);
	double tmp;
	if (d3 <= -8.5e+178) {
		tmp = t_1;
	} else if (d3 <= -2.3e-212) {
		tmp = t_2;
	} else if (d3 <= -9e-309) {
		tmp = t_0;
	} else if (d3 <= 1.25e-124) {
		tmp = t_2;
	} else if (d3 <= 5.8e+149) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 + d4)
	t_1 = d1 * -d3
	t_2 = d1 * (d2 - d1)
	tmp = 0
	if d3 <= -8.5e+178:
		tmp = t_1
	elif d3 <= -2.3e-212:
		tmp = t_2
	elif d3 <= -9e-309:
		tmp = t_0
	elif d3 <= 1.25e-124:
		tmp = t_2
	elif d3 <= 5.8e+149:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 + d4))
	t_1 = Float64(d1 * Float64(-d3))
	t_2 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d3 <= -8.5e+178)
		tmp = t_1;
	elseif (d3 <= -2.3e-212)
		tmp = t_2;
	elseif (d3 <= -9e-309)
		tmp = t_0;
	elseif (d3 <= 1.25e-124)
		tmp = t_2;
	elseif (d3 <= 5.8e+149)
		tmp = t_0;
	else
		tmp = t_1;
	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);
	t_1 = d1 * -d3;
	t_2 = d1 * (d2 - d1);
	tmp = 0.0;
	if (d3 <= -8.5e+178)
		tmp = t_1;
	elseif (d3 <= -2.3e-212)
		tmp = t_2;
	elseif (d3 <= -9e-309)
		tmp = t_0;
	elseif (d3 <= 1.25e-124)
		tmp = t_2;
	elseif (d3 <= 5.8e+149)
		tmp = t_0;
	else
		tmp = t_1;
	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 + d4), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * (-d3)), $MachinePrecision]}, Block[{t$95$2 = N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -8.5e+178], t$95$1, If[LessEqual[d3, -2.3e-212], t$95$2, If[LessEqual[d3, -9e-309], t$95$0, If[LessEqual[d3, 1.25e-124], t$95$2, If[LessEqual[d3, 5.8e+149], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 + d4\right)\\
t_1 := d1 \cdot \left(-d3\right)\\
t_2 := d1 \cdot \left(d2 - d1\right)\\
\mathbf{if}\;d3 \leq -8.5 \cdot 10^{+178}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d3 \leq -2.3 \cdot 10^{-212}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d3 \leq -9 \cdot 10^{-309}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d3 \leq 1.25 \cdot 10^{-124}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d3 \leq 5.8 \cdot 10^{+149}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -8.49999999999999991e178 or 5.8000000000000004e149 < d3

    1. Initial program 87.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+87.5%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.6%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around inf 82.9%

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg82.9%

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-rgt-neg-out82.9%

        \[\leadsto \color{blue}{d1 \cdot \left(-d3\right)} \]
    7. Simplified82.9%

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

    if -8.49999999999999991e178 < d3 < -2.3000000000000001e-212 or -9.0000000000000021e-309 < d3 < 1.2500000000000001e-124

    1. Initial program 87.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.4%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative87.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+87.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--87.4%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--88.3%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around 0 96.7%

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

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

    if -2.3000000000000001e-212 < d3 < -9.0000000000000021e-309 or 1.2500000000000001e-124 < d3 < 5.8000000000000004e149

    1. Initial program 91.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg91.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative91.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg91.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+91.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--91.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--95.5%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out99.9%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 82.3%

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

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

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

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

Alternative 4: 53.2% accurate, 0.6× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ \mathbf{if}\;d2 \leq -3.4 \cdot 10^{+96}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -3.6 \cdot 10^{-6}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d2 \leq -4.6 \cdot 10^{-152}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq 1.1 \cdot 10^{-249}:\\ \;\;\;\;t\_0\\ \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
 (let* ((t_0 (* d1 (- d1))))
   (if (<= d2 -3.4e+96)
     (* d1 d2)
     (if (<= d2 -3.6e-6)
       t_0
       (if (<= d2 -4.6e-152)
         (* d1 (- d3))
         (if (<= d2 1.1e-249) t_0 (* d1 d4)))))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d1;
	double tmp;
	if (d2 <= -3.4e+96) {
		tmp = d1 * d2;
	} else if (d2 <= -3.6e-6) {
		tmp = t_0;
	} else if (d2 <= -4.6e-152) {
		tmp = d1 * -d3;
	} else if (d2 <= 1.1e-249) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = d1 * -d1
    if (d2 <= (-3.4d+96)) then
        tmp = d1 * d2
    else if (d2 <= (-3.6d-6)) then
        tmp = t_0
    else if (d2 <= (-4.6d-152)) then
        tmp = d1 * -d3
    else if (d2 <= 1.1d-249) then
        tmp = t_0
    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 t_0 = d1 * -d1;
	double tmp;
	if (d2 <= -3.4e+96) {
		tmp = d1 * d2;
	} else if (d2 <= -3.6e-6) {
		tmp = t_0;
	} else if (d2 <= -4.6e-152) {
		tmp = d1 * -d3;
	} else if (d2 <= 1.1e-249) {
		tmp = t_0;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	t_0 = d1 * -d1
	tmp = 0
	if d2 <= -3.4e+96:
		tmp = d1 * d2
	elif d2 <= -3.6e-6:
		tmp = t_0
	elif d2 <= -4.6e-152:
		tmp = d1 * -d3
	elif d2 <= 1.1e-249:
		tmp = t_0
	else:
		tmp = d1 * d4
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d1))
	tmp = 0.0
	if (d2 <= -3.4e+96)
		tmp = Float64(d1 * d2);
	elseif (d2 <= -3.6e-6)
		tmp = t_0;
	elseif (d2 <= -4.6e-152)
		tmp = Float64(d1 * Float64(-d3));
	elseif (d2 <= 1.1e-249)
		tmp = t_0;
	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)
	t_0 = d1 * -d1;
	tmp = 0.0;
	if (d2 <= -3.4e+96)
		tmp = d1 * d2;
	elseif (d2 <= -3.6e-6)
		tmp = t_0;
	elseif (d2 <= -4.6e-152)
		tmp = d1 * -d3;
	elseif (d2 <= 1.1e-249)
		tmp = t_0;
	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_] := Block[{t$95$0 = N[(d1 * (-d1)), $MachinePrecision]}, If[LessEqual[d2, -3.4e+96], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -3.6e-6], t$95$0, If[LessEqual[d2, -4.6e-152], N[(d1 * (-d3)), $MachinePrecision], If[LessEqual[d2, 1.1e-249], t$95$0, N[(d1 * d4), $MachinePrecision]]]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d1\right)\\
\mathbf{if}\;d2 \leq -3.4 \cdot 10^{+96}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -3.6 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d2 \leq 1.1 \cdot 10^{-249}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 82.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg82.2%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative82.2%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg82.2%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+82.2%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--82.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--86.7%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around inf 61.2%

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

    if -3.4000000000000001e96 < d2 < -3.59999999999999984e-6 or -4.6000000000000003e-152 < d2 < 1.1e-249

    1. Initial program 89.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.2%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.2%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg89.2%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.2%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.8%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around inf 48.0%

      \[\leadsto d1 \cdot \color{blue}{\left(-1 \cdot d1\right)} \]
    6. Step-by-step derivation
      1. neg-mul-148.0%

        \[\leadsto d1 \cdot \color{blue}{\left(-d1\right)} \]
    7. Simplified48.0%

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

    if -3.59999999999999984e-6 < d2 < -4.6000000000000003e-152

    1. Initial program 85.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg85.1%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative85.1%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg85.1%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+85.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--85.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--85.1%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out99.9%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around inf 48.0%

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg48.0%

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-rgt-neg-out48.0%

        \[\leadsto \color{blue}{d1 \cdot \left(-d3\right)} \]
    7. Simplified48.0%

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

    if 1.1e-249 < d2

    1. Initial program 91.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg91.6%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative91.6%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+91.6%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--92.4%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--94.9%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d4 around inf 28.3%

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

Alternative 5: 73.1% accurate, 0.7× speedup?

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

\mathbf{elif}\;d2 \leq -4.6 \cdot 10^{-5}:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

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

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


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

    1. Initial program 82.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg82.2%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative82.2%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg82.2%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+82.2%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--82.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--86.7%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 91.1%

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

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

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

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

    if -2.7999999999999998e95 < d2 < -4.6e-5

    1. Initial program 90.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg90.9%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative90.9%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg90.9%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+90.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.9%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around 0 91.1%

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

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

    if -4.6e-5 < d2 < -4.19999999999999998e-152

    1. Initial program 85.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg85.1%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative85.1%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg85.1%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+85.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--85.1%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--85.1%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out99.9%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 82.3%

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

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

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

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

    if -4.19999999999999998e-152 < d2

    1. Initial program 90.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg90.7%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative90.7%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg90.7%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+90.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--91.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--93.8%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around 0 81.0%

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

        \[\leadsto d1 \cdot \left(d4 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+81.0%

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

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

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

Alternative 6: 93.0% accurate, 0.9× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -6.99999999999999937e128 or 6.7e56 < d3

    1. Initial program 87.6%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg87.6%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative87.6%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+87.6%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--89.9%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out99.9%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 95.6%

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

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

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

    if -6.99999999999999937e128 < d3 < 6.7e56

    1. Initial program 89.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.2%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.2%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg89.2%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.2%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--92.2%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around 0 97.6%

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

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

Alternative 7: 92.4% accurate, 0.9× speedup?

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

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

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


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

    1. Initial program 85.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg85.7%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative85.7%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg85.7%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+85.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--89.3%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around 0 93.3%

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

        \[\leadsto d1 \cdot \left(d4 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+93.3%

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

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

    if -1.8000000000000001e122 < d3 < 1.02e49

    1. Initial program 89.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg89.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--92.1%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around 0 97.9%

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

    if 1.02e49 < d3

    1. Initial program 89.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg89.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.6%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out99.9%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 95.4%

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

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

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

Alternative 8: 89.9% accurate, 0.9× speedup?

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

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

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


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

    1. Initial program 59.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg59.3%

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

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

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg59.3%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+59.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--59.3%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--66.7%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around 0 94.3%

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

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

    if -1.56e125 < d1 < 6.5000000000000001e113

    1. Initial program 99.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg99.4%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative99.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+99.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--100.0%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 89.6%

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

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

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

    if 6.5000000000000001e113 < d1

    1. Initial program 61.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg61.3%

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

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

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg61.3%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+61.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--63.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--70.5%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around 0 91.1%

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

        \[\leadsto d1 \cdot \left(d4 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+91.1%

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

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

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

Alternative 9: 75.3% accurate, 0.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -1.4500000000000001e99

    1. Initial program 81.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg81.8%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative81.8%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+81.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--81.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--86.4%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 90.9%

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

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

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

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

    if -1.4500000000000001e99 < d2 < -1.65e-282

    1. Initial program 89.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.3%

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

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

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg89.3%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--90.6%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around 0 94.7%

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

        \[\leadsto d1 \cdot \left(d4 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+94.7%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot \left(d1 + d3\right)\right)} \]
    9. Step-by-step derivation
      1. associate-*r*64.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot \left(d1 + d3\right)} \]
      2. mul-1-neg64.9%

        \[\leadsto \color{blue}{\left(-d1\right)} \cdot \left(d1 + d3\right) \]
    10. Simplified64.9%

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

    if -1.65e-282 < d2

    1. Initial program 90.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg90.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+90.5%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--91.2%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--93.4%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around 0 77.6%

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

        \[\leadsto d1 \cdot \left(d4 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+77.6%

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

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

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

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

Alternative 10: 68.3% accurate, 1.0× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.1 \cdot 10^{+140} \lor \neg \left(d3 \leq 8.2 \cdot 10^{+149}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d3 -1.1e+140) (not (<= d3 8.2e+149)))
   (* d1 (- d3))
   (* d1 (+ d2 d4))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -1.1e+140) || !(d3 <= 8.2e+149)) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d2 + 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 ((d3 <= (-1.1d+140)) .or. (.not. (d3 <= 8.2d+149))) then
        tmp = d1 * -d3
    else
        tmp = d1 * (d2 + 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 ((d3 <= -1.1e+140) || !(d3 <= 8.2e+149)) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d2 + d4);
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -1.1e+140) or not (d3 <= 8.2e+149):
		tmp = d1 * -d3
	else:
		tmp = d1 * (d2 + d4)
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -1.1e+140) || !(d3 <= 8.2e+149))
		tmp = Float64(d1 * Float64(-d3));
	else
		tmp = Float64(d1 * Float64(d2 + 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 ((d3 <= -1.1e+140) || ~((d3 <= 8.2e+149)))
		tmp = d1 * -d3;
	else
		tmp = d1 * (d2 + 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[Or[LessEqual[d3, -1.1e+140], N[Not[LessEqual[d3, 8.2e+149]], $MachinePrecision]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d2 + d4), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -1.1 \cdot 10^{+140} \lor \neg \left(d3 \leq 8.2 \cdot 10^{+149}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -1.0999999999999999e140 or 8.1999999999999992e149 < d3

    1. Initial program 86.5%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg86.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+86.5%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.5%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--89.5%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d3 around inf 82.1%

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-rgt-neg-out82.1%

        \[\leadsto \color{blue}{d1 \cdot \left(-d3\right)} \]
    7. Simplified82.1%

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

    if -1.0999999999999999e140 < d3 < 8.1999999999999992e149

    1. Initial program 89.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.4%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.4%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--92.1%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 71.2%

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

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

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

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

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

Alternative 11: 53.2% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 2.1e-185

    1. Initial program 89.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg89.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--89.7%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--91.8%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around inf 31.2%

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

    if 2.1e-185 < d4 < 2.5e45

    1. Initial program 95.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg95.9%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative95.9%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg95.9%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+95.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--95.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--97.9%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around inf 52.2%

      \[\leadsto d1 \cdot \color{blue}{\left(-1 \cdot d1\right)} \]
    6. Step-by-step derivation
      1. neg-mul-152.2%

        \[\leadsto d1 \cdot \color{blue}{\left(-d1\right)} \]
    7. Simplified52.2%

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

    if 2.5e45 < d4

    1. Initial program 81.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg81.9%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative81.9%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg81.9%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+81.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--83.6%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--85.2%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d4 around inf 49.6%

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

Alternative 12: 72.5% accurate, 1.5× speedup?

\[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.3 \cdot 10^{+71}:\\ \;\;\;\;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 (<= d2 -4.3e+71) (* 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 (d2 <= -4.3e+71) {
		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 (d2 <= (-4.3d+71)) 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 (d2 <= -4.3e+71) {
		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 d2 <= -4.3e+71:
		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 (d2 <= -4.3e+71)
		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 (d2 <= -4.3e+71)
		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[d2, -4.3e+71], 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}\;d2 \leq -4.3 \cdot 10^{+71}:\\
\;\;\;\;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 d2 < -4.29999999999999984e71

    1. Initial program 83.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg83.9%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative83.9%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg83.9%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+83.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--83.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--87.5%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d1 around 0 87.7%

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

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

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

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

    if -4.29999999999999984e71 < d2

    1. Initial program 90.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg90.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative90.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg90.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+90.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--91.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--92.5%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around 0 83.2%

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

        \[\leadsto d1 \cdot \left(d4 - \color{blue}{\left(d3 + d1\right)}\right) \]
      2. associate--r+83.2%

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

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

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

Alternative 13: 50.3% accurate, 1.9× speedup?

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

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


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

    1. Initial program 85.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg85.0%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative85.0%

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

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

        \[\leadsto \left(d2 \cdot d1 + \left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right)\right) - d1 \cdot d1 \]
      6. sub-neg85.0%

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+85.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--85.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--88.3%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d2 around inf 53.6%

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

    if -4.5e43 < d2

    1. Initial program 89.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. sub-neg89.8%

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
      3. *-commutative89.8%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
      8. associate--l+89.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
      9. distribute-lft-out--90.8%

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
      10. distribute-rgt-out--92.3%

        \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      11. distribute-lft-out100.0%

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in d4 around inf 32.2%

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

Alternative 14: 31.3% accurate, 5.0× speedup?

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

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. sub-neg88.6%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
    3. *-commutative88.6%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
    8. associate--l+88.6%

      \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
    9. distribute-lft-out--89.4%

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
    10. distribute-rgt-out--91.4%

      \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    11. distribute-lft-out100.0%

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

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

    \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in d2 around inf 29.5%

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

Alternative 15: 7.6% accurate, 5.0× speedup?

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

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. sub-neg88.6%

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

      \[\leadsto \color{blue}{\left(d1 \cdot d2 + \left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right)\right)} - d1 \cdot d1 \]
    3. *-commutative88.6%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(d1 \cdot d4 - d1 \cdot d3\right) + d2 \cdot d1\right)} - d1 \cdot d1 \]
    8. associate--l+88.6%

      \[\leadsto \color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right) + \left(d2 \cdot d1 - d1 \cdot d1\right)} \]
    9. distribute-lft-out--89.4%

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} + \left(d2 \cdot d1 - d1 \cdot d1\right) \]
    10. distribute-rgt-out--91.4%

      \[\leadsto d1 \cdot \left(d4 - d3\right) + \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    11. distribute-lft-out100.0%

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

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

    \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d1\right) + \left(d4 - d3\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in d1 around inf 32.4%

    \[\leadsto d1 \cdot \color{blue}{\left(-1 \cdot d1\right)} \]
  6. Step-by-step derivation
    1. neg-mul-132.4%

      \[\leadsto d1 \cdot \color{blue}{\left(-d1\right)} \]
  7. Simplified32.4%

    \[\leadsto d1 \cdot \color{blue}{\left(-d1\right)} \]
  8. Step-by-step derivation
    1. neg-sub032.4%

      \[\leadsto d1 \cdot \color{blue}{\left(0 - d1\right)} \]
    2. sub-neg32.4%

      \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(-d1\right)\right)} \]
    3. add-sqr-sqrt11.9%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{\sqrt{-d1} \cdot \sqrt{-d1}}\right) \]
    4. sqrt-unprod15.8%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{\sqrt{\left(-d1\right) \cdot \left(-d1\right)}}\right) \]
    5. sqr-neg15.8%

      \[\leadsto d1 \cdot \left(0 + \sqrt{\color{blue}{d1 \cdot d1}}\right) \]
    6. sqrt-unprod3.9%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{\sqrt{d1} \cdot \sqrt{d1}}\right) \]
    7. add-sqr-sqrt7.1%

      \[\leadsto d1 \cdot \left(0 + \color{blue}{d1}\right) \]
  9. Applied egg-rr7.1%

    \[\leadsto d1 \cdot \color{blue}{\left(0 + d1\right)} \]
  10. Step-by-step derivation
    1. +-lft-identity7.1%

      \[\leadsto d1 \cdot \color{blue}{d1} \]
  11. Simplified7.1%

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

Developer Target 1: 100.0% accurate, 1.7× 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 2024181 
(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)))