FastMath dist4

Percentage Accurate: 86.9% → 98.9%
Time: 36.6s
Alternatives: 14
Speedup: 1.2×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 86.9% accurate, 1.0× speedup?

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

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

Alternative 1: 98.9% accurate, 1.2× speedup?

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

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


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

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

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

    if 2.4999999999999998e227 < d4

    1. Initial program 73.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 71.9% 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.85 \cdot 10^{-143}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 4.5 \cdot 10^{+59}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.72 \cdot 10^{+165}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \end{array} \]
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d4 2.85e-143)
   (* d1 (- d2 d3))
   (if (<= d4 4.5e+59)
     (* d1 (- d2 d1))
     (if (<= d4 1.72e+165) (* d1 (- d4 d1)) (* d1 (+ d4 d2))))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d4 <= 2.85e-143) {
		tmp = d1 * (d2 - d3);
	} else if (d4 <= 4.5e+59) {
		tmp = d1 * (d2 - d1);
	} else if (d4 <= 1.72e+165) {
		tmp = d1 * (d4 - d1);
	} else {
		tmp = d1 * (d4 + d2);
	}
	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.85d-143) then
        tmp = d1 * (d2 - d3)
    else if (d4 <= 4.5d+59) then
        tmp = d1 * (d2 - d1)
    else if (d4 <= 1.72d+165) then
        tmp = d1 * (d4 - d1)
    else
        tmp = d1 * (d4 + d2)
    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.85e-143) {
		tmp = d1 * (d2 - d3);
	} else if (d4 <= 4.5e+59) {
		tmp = d1 * (d2 - d1);
	} else if (d4 <= 1.72e+165) {
		tmp = d1 * (d4 - d1);
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4])
def code(d1, d2, d3, d4):
	tmp = 0
	if d4 <= 2.85e-143:
		tmp = d1 * (d2 - d3)
	elif d4 <= 4.5e+59:
		tmp = d1 * (d2 - d1)
	elif d4 <= 1.72e+165:
		tmp = d1 * (d4 - d1)
	else:
		tmp = d1 * (d4 + d2)
	return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4])
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d4 <= 2.85e-143)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d4 <= 4.5e+59)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d4 <= 1.72e+165)
		tmp = Float64(d1 * Float64(d4 - d1));
	else
		tmp = Float64(d1 * Float64(d4 + d2));
	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.85e-143)
		tmp = d1 * (d2 - d3);
	elseif (d4 <= 4.5e+59)
		tmp = d1 * (d2 - d1);
	elseif (d4 <= 1.72e+165)
		tmp = d1 * (d4 - d1);
	else
		tmp = d1 * (d4 + d2);
	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.85e-143], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 4.5e+59], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 1.72e+165], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 2.85 \cdot 10^{-143}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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

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

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


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

    1. Initial program 90.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
    9. Step-by-step derivation
      1. +-rgt-identityN/A

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

        \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(d2 - d3\right)\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto d1 \cdot \left(0 + \color{blue}{\left(d2 - d3\right) \cdot 1}\right) \]
      4. cancel-sign-subN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \left(d2 - d3\right)\right)} \cdot 1\right) \]
      6. *-inversesN/A

        \[\leadsto d1 \cdot \left(0 - \left(-1 \cdot \left(d2 - d3\right)\right) \cdot \color{blue}{\frac{d1}{d1}}\right) \]
      7. associate-/l*N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot d1}{d1}}\right) \]
      8. associate-*l/N/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \frac{d2 - d3}{d1}\right)} \cdot d1\right) \]
      10. *-commutativeN/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)}\right) \]
      11. neg-sub0N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)\right)} \]
      12. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(\mathsf{neg}\left(d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)\right)} \]
      13. neg-sub0N/A

        \[\leadsto d1 \cdot \color{blue}{\left(0 - d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)} \]
      14. *-commutativeN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{-1 \cdot \left(d2 - d3\right)}{d1}} \cdot d1\right) \]
      16. associate-*l/N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot d1}{d1}}\right) \]
      17. associate-/l*N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot \frac{d1}{d1}}\right) \]
      18. *-inversesN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(\mathsf{neg}\left(\left(d2 - d3\right)\right)\right)} \cdot 1\right) \]
      20. cancel-sign-subN/A

        \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(d2 - d3\right) \cdot 1\right)} \]
      21. *-rgt-identityN/A

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d2 - d3\right) + 0\right)} \]
    10. Simplified63.1%

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

    if 2.85e-143 < d4 < 4.49999999999999959e59

    1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      2. --lowering--.f6468.5

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

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

    if 4.49999999999999959e59 < d4 < 1.72e165

    1. Initial program 78.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
      2. --lowering--.f6472.3

        \[\leadsto d1 \cdot \color{blue}{\left(d4 - d1\right)} \]
    8. Simplified72.3%

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

    if 1.72e165 < d4

    1. Initial program 72.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d4 - d1\right)}\right) \]
      11. --lowering--.f6489.7

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
    8. Simplified93.1%

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

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

Alternative 3: 64.5% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -4.99999999999999991e108 or 1.6200000000000001e196 < d3

    1. Initial program 82.7%

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \]
      6. neg-lowering-neg.f6478.3

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

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

    if -4.99999999999999991e108 < d3 < -2.3000000000000001e-18

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

    if -2.3000000000000001e-18 < d3 < 1.6200000000000001e196

    1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d2 + d4\right)} \]
      2. +-lowering-+.f6472.0

        \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
    8. Simplified72.0%

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

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

Alternative 4: 53.2% accurate, 1.2× speedup?

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

\mathbf{elif}\;d4 \leq 5.6 \cdot 10^{-142}:\\
\;\;\;\;-d1 \cdot d3\\

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

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


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

    1. Initial program 86.9%

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

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

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

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

    if -1.74999999999999991e-274 < d4 < 5.60000000000000009e-142

    1. Initial program 96.6%

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} \]
      6. neg-lowering-neg.f6443.0

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

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

    if 5.60000000000000009e-142 < d4 < 2.6000000000000001e88

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

    if 2.6000000000000001e88 < d4

    1. Initial program 72.0%

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

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6470.9

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

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

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

Alternative 5: 93.3% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.8000000000000001e63 < d1 < 1.9000000000000002e113

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if 1.9000000000000002e113 < d1

    1. Initial program 61.4%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 92.2% accurate, 1.2× speedup?

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

\mathbf{elif}\;d1 \leq 2.4 \cdot 10^{+148}:\\
\;\;\;\;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 < -2.00000000000000012e63

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000012e63 < d1 < 2.39999999999999995e148

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if 2.39999999999999995e148 < d1

    1. Initial program 56.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
      2. --lowering--.f6489.7

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

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

Alternative 7: 91.4% accurate, 1.2× speedup?

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

\mathbf{elif}\;d1 \leq 1.8 \cdot 10^{+150}:\\
\;\;\;\;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.15e65

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.15e65 < d1 < 1.79999999999999993e150

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if 1.79999999999999993e150 < d1

    1. Initial program 56.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d1\right)} \]
      2. --lowering--.f6489.7

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

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

Alternative 8: 86.2% accurate, 1.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -1.79999999999999991e-16

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(\color{blue}{\left(\mathsf{neg}\left(d3\right)\right)} - d1\right) \]
      2. neg-lowering-neg.f6484.7

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

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

    if -1.79999999999999991e-16 < d3 < 2.79999999999999975e129

    1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.79999999999999975e129 < d3

    1. Initial program 81.5%

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d4 - d3\right) - d1\right)} \]
      7. --lowering--.f6489.5

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

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

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

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

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

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

Alternative 9: 73.1% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 90.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
    9. Step-by-step derivation
      1. +-rgt-identityN/A

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

        \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(d2 - d3\right)\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto d1 \cdot \left(0 + \color{blue}{\left(d2 - d3\right) \cdot 1}\right) \]
      4. cancel-sign-subN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \left(d2 - d3\right)\right)} \cdot 1\right) \]
      6. *-inversesN/A

        \[\leadsto d1 \cdot \left(0 - \left(-1 \cdot \left(d2 - d3\right)\right) \cdot \color{blue}{\frac{d1}{d1}}\right) \]
      7. associate-/l*N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot d1}{d1}}\right) \]
      8. associate-*l/N/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \frac{d2 - d3}{d1}\right)} \cdot d1\right) \]
      10. *-commutativeN/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)}\right) \]
      11. neg-sub0N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)\right)} \]
      12. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(\mathsf{neg}\left(d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)\right)} \]
      13. neg-sub0N/A

        \[\leadsto d1 \cdot \color{blue}{\left(0 - d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)} \]
      14. *-commutativeN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{-1 \cdot \left(d2 - d3\right)}{d1}} \cdot d1\right) \]
      16. associate-*l/N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot d1}{d1}}\right) \]
      17. associate-/l*N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot \frac{d1}{d1}}\right) \]
      18. *-inversesN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(\mathsf{neg}\left(\left(d2 - d3\right)\right)\right)} \cdot 1\right) \]
      20. cancel-sign-subN/A

        \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(d2 - d3\right) \cdot 1\right)} \]
      21. *-rgt-identityN/A

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d2 - d3\right) + 0\right)} \]
    10. Simplified63.1%

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

    if 3.29999999999999981e-145 < d4 < 1.90000000000000005e60

    1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      2. --lowering--.f6468.5

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

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

    if 1.90000000000000005e60 < d4

    1. Initial program 74.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(d4 - d3\right)} \]
      2. --lowering--.f6476.1

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

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

Alternative 10: 70.8% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 90.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right)} \]
    9. Step-by-step derivation
      1. +-rgt-identityN/A

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

        \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(d2 - d3\right)\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto d1 \cdot \left(0 + \color{blue}{\left(d2 - d3\right) \cdot 1}\right) \]
      4. cancel-sign-subN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \left(d2 - d3\right)\right)} \cdot 1\right) \]
      6. *-inversesN/A

        \[\leadsto d1 \cdot \left(0 - \left(-1 \cdot \left(d2 - d3\right)\right) \cdot \color{blue}{\frac{d1}{d1}}\right) \]
      7. associate-/l*N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot d1}{d1}}\right) \]
      8. associate-*l/N/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \frac{d2 - d3}{d1}\right)} \cdot d1\right) \]
      10. *-commutativeN/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)}\right) \]
      11. neg-sub0N/A

        \[\leadsto d1 \cdot \color{blue}{\left(\mathsf{neg}\left(d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)\right)} \]
      12. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(\mathsf{neg}\left(d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)\right)} \]
      13. neg-sub0N/A

        \[\leadsto d1 \cdot \color{blue}{\left(0 - d1 \cdot \left(-1 \cdot \frac{d2 - d3}{d1}\right)\right)} \]
      14. *-commutativeN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{-1 \cdot \left(d2 - d3\right)}{d1}} \cdot d1\right) \]
      16. associate-*l/N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\frac{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot d1}{d1}}\right) \]
      17. associate-/l*N/A

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(-1 \cdot \left(d2 - d3\right)\right) \cdot \frac{d1}{d1}}\right) \]
      18. *-inversesN/A

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

        \[\leadsto d1 \cdot \left(0 - \color{blue}{\left(\mathsf{neg}\left(\left(d2 - d3\right)\right)\right)} \cdot 1\right) \]
      20. cancel-sign-subN/A

        \[\leadsto d1 \cdot \color{blue}{\left(0 + \left(d2 - d3\right) \cdot 1\right)} \]
      21. *-rgt-identityN/A

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

        \[\leadsto d1 \cdot \color{blue}{\left(\left(d2 - d3\right) + 0\right)} \]
    10. Simplified63.1%

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

    if 4.5e-143 < d4 < 3.99999999999999984e88

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(d2 + \color{blue}{\left(d4 - d1\right)}\right) \]
      11. --lowering--.f6481.7

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      2. --lowering--.f6465.9

        \[\leadsto d1 \cdot \color{blue}{\left(d2 - d1\right)} \]
    8. Simplified65.9%

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

    if 3.99999999999999984e88 < d4

    1. Initial program 72.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
    8. Simplified84.2%

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

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

Alternative 11: 54.2% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 86.2%

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

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

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

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

    if -3.50000000000000002e38 < d2 < 1.4999999999999999e-308

    1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

    if 1.4999999999999999e-308 < d2

    1. Initial program 86.3%

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

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6428.9

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

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

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

Alternative 12: 70.7% accurate, 2.0× speedup?

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

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


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

    1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{d1 \cdot \left(d2 - d1\right)} \]
      2. --lowering--.f6459.4

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

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

    if 1.58000000000000005e87 < d4

    1. Initial program 72.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d1 \cdot \color{blue}{\left(d2 + d4\right)} \]
    8. Simplified84.2%

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

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

Alternative 13: 49.5% accurate, 2.5× speedup?

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

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


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

    1. Initial program 90.7%

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

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

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

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

    if 1.09999999999999998e60 < d4

    1. Initial program 74.9%

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

      \[\leadsto \color{blue}{d1 \cdot d4} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6464.9

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

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

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

Alternative 14: 30.7% 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 87.5%

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

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

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

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

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

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

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

Reproduce

?
herbie shell --seed 2024205 
(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)))