FastMath dist4

Percentage Accurate: 88.0% → 96.6%
Time: 7.3s
Alternatives: 13
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 88.0% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -1.01999999999999993e261

    1. Initial program 30.8%

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

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

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

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

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

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

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

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

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

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

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

    if -1.01999999999999993e261 < d1

    1. Initial program 93.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 90.7% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 58.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -4.6000000000000003e144 < d1 < 2.9499999999999998e133

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

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

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

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

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

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

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

      if 2.9499999999999998e133 < d1

      1. Initial program 72.9%

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

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

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

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

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

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

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

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

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

      Alternative 3: 74.1% accurate, 1.3× speedup?

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

        1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -3.3000000000000001e114 < d2 < 7.5000000000000004e-251

          1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 7.5000000000000004e-251 < d2

            1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

            Alternative 4: 66.6% accurate, 1.4× speedup?

            \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+77} \lor \neg \left(d3 \leq 9 \cdot 10^{+86}\right):\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \mathbf{else}:\\ \;\;\;\;\left(d2 + d4\right) \cdot d1\\ \end{array} \end{array} \]
            NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
            (FPCore (d1 d2 d3 d4)
             :precision binary64
             (if (or (<= d3 -2.4e+77) (not (<= d3 9e+86))) (* (- d1) d3) (* (+ d2 d4) d1)))
            assert(d1 < d2 && d2 < d3 && d3 < d4);
            double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if ((d3 <= -2.4e+77) || !(d3 <= 9e+86)) {
            		tmp = -d1 * d3;
            	} else {
            		tmp = (d2 + d4) * d1;
            	}
            	return tmp;
            }
            
            NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
            real(8) function code(d1, d2, d3, d4)
                real(8), intent (in) :: d1
                real(8), intent (in) :: d2
                real(8), intent (in) :: d3
                real(8), intent (in) :: d4
                real(8) :: tmp
                if ((d3 <= (-2.4d+77)) .or. (.not. (d3 <= 9d+86))) then
                    tmp = -d1 * d3
                else
                    tmp = (d2 + d4) * d1
                end if
                code = tmp
            end function
            
            assert d1 < d2 && d2 < d3 && d3 < d4;
            public static double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if ((d3 <= -2.4e+77) || !(d3 <= 9e+86)) {
            		tmp = -d1 * d3;
            	} else {
            		tmp = (d2 + d4) * d1;
            	}
            	return tmp;
            }
            
            [d1, d2, d3, d4] = sort([d1, d2, d3, d4])
            def code(d1, d2, d3, d4):
            	tmp = 0
            	if (d3 <= -2.4e+77) or not (d3 <= 9e+86):
            		tmp = -d1 * d3
            	else:
            		tmp = (d2 + d4) * d1
            	return tmp
            
            d1, d2, d3, d4 = sort([d1, d2, d3, d4])
            function code(d1, d2, d3, d4)
            	tmp = 0.0
            	if ((d3 <= -2.4e+77) || !(d3 <= 9e+86))
            		tmp = Float64(Float64(-d1) * d3);
            	else
            		tmp = Float64(Float64(d2 + d4) * d1);
            	end
            	return tmp
            end
            
            d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
            function tmp_2 = code(d1, d2, d3, d4)
            	tmp = 0.0;
            	if ((d3 <= -2.4e+77) || ~((d3 <= 9e+86)))
            		tmp = -d1 * d3;
            	else
            		tmp = (d2 + d4) * d1;
            	end
            	tmp_2 = tmp;
            end
            
            NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
            code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -2.4e+77], N[Not[LessEqual[d3, 9e+86]], $MachinePrecision]], N[((-d1) * d3), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
            
            \begin{array}{l}
            [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
            \\
            \begin{array}{l}
            \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+77} \lor \neg \left(d3 \leq 9 \cdot 10^{+86}\right):\\
            \;\;\;\;\left(-d1\right) \cdot d3\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(d2 + d4\right) \cdot d1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d3 < -2.3999999999999999e77 or 8.99999999999999986e86 < d3

              1. Initial program 81.8%

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

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

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

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

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

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

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

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

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

                  \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                2. Taylor expanded in d3 around 0

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

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

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

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

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

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

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

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

                  if -2.3999999999999999e77 < d3 < 8.99999999999999986e86

                  1. Initial program 94.6%

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

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

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

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

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

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

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

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

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

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

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

                  Alternative 5: 72.2% accurate, 1.4× speedup?

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

                    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 0

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

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

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

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

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

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

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

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

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

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

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

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

                      if -7.4999999999999996e-15 < d2 < 5.4000000000000002e-251

                      1. Initial program 92.8%

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

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

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

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

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

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

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

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

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

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

                        if 5.4000000000000002e-251 < d2

                        1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

                        Alternative 6: 52.7% 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.3 \cdot 10^{+114}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq 7.6 \cdot 10^{-251}:\\ \;\;\;\;\left(-d1\right) \cdot d3\\ \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.3e+114)
                           (* d2 d1)
                           (if (<= d2 7.6e-251) (* (- d1) d3) (* d4 d1))))
                        assert(d1 < d2 && d2 < d3 && d3 < d4);
                        double code(double d1, double d2, double d3, double d4) {
                        	double tmp;
                        	if (d2 <= -3.3e+114) {
                        		tmp = d2 * d1;
                        	} else if (d2 <= 7.6e-251) {
                        		tmp = -d1 * d3;
                        	} 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.3d+114)) then
                                tmp = d2 * d1
                            else if (d2 <= 7.6d-251) then
                                tmp = -d1 * d3
                            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.3e+114) {
                        		tmp = d2 * d1;
                        	} else if (d2 <= 7.6e-251) {
                        		tmp = -d1 * d3;
                        	} 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.3e+114:
                        		tmp = d2 * d1
                        	elif d2 <= 7.6e-251:
                        		tmp = -d1 * d3
                        	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.3e+114)
                        		tmp = Float64(d2 * d1);
                        	elseif (d2 <= 7.6e-251)
                        		tmp = Float64(Float64(-d1) * d3);
                        	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.3e+114)
                        		tmp = d2 * d1;
                        	elseif (d2 <= 7.6e-251)
                        		tmp = -d1 * d3;
                        	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.3e+114], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 7.6e-251], N[((-d1) * d3), $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.3 \cdot 10^{+114}:\\
                        \;\;\;\;d2 \cdot d1\\
                        
                        \mathbf{elif}\;d2 \leq 7.6 \cdot 10^{-251}:\\
                        \;\;\;\;\left(-d1\right) \cdot d3\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;d4 \cdot d1\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 3 regimes
                        2. if d2 < -3.3000000000000001e114

                          1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \color{blue}{d2 \cdot d1} \]
                          7. Applied rewrites72.4%

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

                          if -3.3000000000000001e114 < d2 < 7.5999999999999994e-251

                          1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

                              \[\leadsto \left(d4 - d3\right) \cdot d1 \]
                            2. Taylor expanded in d3 around 0

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

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

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

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

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

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

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

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

                              if 7.5999999999999994e-251 < d2

                              1. Initial program 90.6%

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

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

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

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

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

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

                            Alternative 7: 53.0% 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.4 \cdot 10^{+129}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -4.1 \cdot 10^{-261}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \end{array} \]
                            NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                            (FPCore (d1 d2 d3 d4)
                             :precision binary64
                             (if (<= d2 -3.4e+129)
                               (* d2 d1)
                               (if (<= d2 -4.1e-261) (* (- 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.4e+129) {
                            		tmp = d2 * d1;
                            	} else if (d2 <= -4.1e-261) {
                            		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.4d+129)) then
                                    tmp = d2 * d1
                                else if (d2 <= (-4.1d-261)) 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.4e+129) {
                            		tmp = d2 * d1;
                            	} else if (d2 <= -4.1e-261) {
                            		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.4e+129:
                            		tmp = d2 * d1
                            	elif d2 <= -4.1e-261:
                            		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.4e+129)
                            		tmp = Float64(d2 * d1);
                            	elseif (d2 <= -4.1e-261)
                            		tmp = Float64(Float64(-d1) * d1);
                            	else
                            		tmp = Float64(d4 * d1);
                            	end
                            	return tmp
                            end
                            
                            d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
                            function tmp_2 = code(d1, d2, d3, d4)
                            	tmp = 0.0;
                            	if (d2 <= -3.4e+129)
                            		tmp = d2 * d1;
                            	elseif (d2 <= -4.1e-261)
                            		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.4e+129], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -4.1e-261], 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.4 \cdot 10^{+129}:\\
                            \;\;\;\;d2 \cdot d1\\
                            
                            \mathbf{elif}\;d2 \leq -4.1 \cdot 10^{-261}:\\
                            \;\;\;\;\left(-d1\right) \cdot d1\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;d4 \cdot d1\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 3 regimes
                            2. if d2 < -3.40000000000000018e129

                              1. Initial program 84.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if -3.40000000000000018e129 < d2 < -4.10000000000000015e-261

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

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

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

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

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

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

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

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

                              if -4.10000000000000015e-261 < d2

                              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 d4 around inf

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

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

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

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

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

                            Alternative 8: 94.2% accurate, 1.7× speedup?

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

                              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 0

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

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

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

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

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

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

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

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

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

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

                              if -2.8000000000000001e-14 < d2

                              1. Initial program 91.6%

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

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

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

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

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

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

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

                            Alternative 9: 94.0% accurate, 1.7× speedup?

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

                              1. Initial program 90.5%

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

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

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

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

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

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

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

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

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

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

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

                              if 9.5000000000000004e43 < d4

                              1. Initial program 89.1%

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

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

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

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

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

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

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

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

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

                            Alternative 10: 72.7% accurate, 2.0× speedup?

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

                              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 0

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

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

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

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

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

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

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

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

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

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

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

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

                                if -7.4999999999999996e-15 < d2

                                1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

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

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

                                Alternative 11: 71.6% accurate, 2.0× speedup?

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

                                  1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

                                    if -3.3000000000000001e114 < d2

                                    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

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

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

                                    Alternative 12: 50.1% accurate, 2.5× speedup?

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

                                      1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                          \[\leadsto \color{blue}{d2 \cdot d1} \]
                                      7. Applied rewrites44.9%

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

                                      if -1.62e-24 < d2

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

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

                                          \[\leadsto \color{blue}{d4 \cdot d1} \]
                                      5. Applied rewrites34.8%

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

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

                                    Alternative 13: 30.8% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \color{blue}{d2 \cdot d1} \]
                                    7. Applied rewrites30.8%

                                      \[\leadsto \color{blue}{d2 \cdot d1} \]
                                    8. 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 2024318 
                                    (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)))