FastMath dist4

Percentage Accurate: 88.1% → 98.4%
Time: 11.9s
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.1% accurate, 1.0× speedup?

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

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

Alternative 1: 98.4% accurate, 1.2× speedup?

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

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


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

    1. Initial program 90.7%

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

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

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

    if 2.1e-102 < d4

    1. Initial program 84.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 77.2% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 84.6%

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

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

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

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

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

      if -0.71999999999999997 < d2 < 1.65e-307

      1. Initial program 89.8%

        \[\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--.f6498.4

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

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

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

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

        if 1.65e-307 < d2 < 1.20000000000000006e-113

        1. Initial program 93.0%

          \[\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--.f64100.0

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

          \[\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 rewrites75.6%

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

          if 1.20000000000000006e-113 < d2

          1. Initial program 88.7%

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

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

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

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

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

          Alternative 3: 70.8% accurate, 1.1× speedup?

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

            1. Initial program 82.7%

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

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

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

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

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

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

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

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

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

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

              if -1.99999999999999991e111 < d3 < -9.5000000000000004e-286

              1. Initial program 87.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--.f6482.9

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

                \[\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 rewrites75.9%

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

                if -9.5000000000000004e-286 < d3 < 8.80000000000000004e32

                1. Initial program 93.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--.f6469.8

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

                  \[\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 rewrites67.4%

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

                  if 8.80000000000000004e32 < d3

                  1. Initial program 88.2%

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

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

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

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

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

                  Alternative 4: 69.9% accurate, 1.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

                      if -1.99999999999999991e111 < d3 < -9.5000000000000004e-286

                      1. Initial program 87.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--.f6482.9

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

                        \[\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 rewrites75.9%

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

                        if -9.5000000000000004e-286 < d3 < 9.99999999999999977e37

                        1. Initial program 93.7%

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

                            \[\leadsto \left(\color{blue}{\left(d4 - d3\right)} - d1\right) \cdot d1 \]
                        5. Applied rewrites68.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 rewrites66.6%

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

                        Alternative 5: 90.5% accurate, 1.2× speedup?

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

                          1. Initial program 69.2%

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

                            \[\leadsto \color{blue}{d1 \cdot d2 - \left(d1 \cdot d3 + {d1}^{2}\right)} \]
                          4. Step-by-step derivation
                            1. 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} \]
                          6. Taylor expanded in d3 around 0

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

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

                            if -7.1999999999999999e140 < d1 < 1.04999999999999991e119

                            1. Initial program 98.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-+.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 1.04999999999999991e119 < d1

                            1. Initial program 59.5%

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

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

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

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

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

                                \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} \]
                              5. *-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--.f6497.1

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

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

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

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

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

                            Alternative 6: 72.6% accurate, 1.4× speedup?

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

                              1. Initial program 89.7%

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

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

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

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

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

                                if -6.39999999999999995e-298 < d4 < 6.39999999999999989e68

                                1. Initial program 90.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--.f6495.7

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

                                  \[\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 rewrites73.5%

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

                                  if 6.39999999999999989e68 < d4

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

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

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

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

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

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

                                  Alternative 7: 66.8% accurate, 1.4× speedup?

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

                                    1. Initial program 63.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 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.f6482.0

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

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

                                    if -3.7999999999999998e127 < d1 < 1.04999999999999991e119

                                    1. Initial program 99.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-+.f6489.7

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

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

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

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

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

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

                                      1. Initial program 84.6%

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

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

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

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

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

                                      if -1.69999999999999996 < d2 < -9.5000000000000004e-286

                                      1. Initial program 92.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 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.f6437.6

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

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

                                      if -9.5000000000000004e-286 < d2

                                      1. Initial program 88.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-*.f6424.1

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

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

                                      \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.7:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -9.5 \cdot 10^{-286}:\\ \;\;\;\;\left(-d1\right) \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \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}\;d2 \leq -0.039:\\ \;\;\;\;\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 -0.039) (* (- (- 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 <= -0.039) {
                                    		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 <= (-0.039d0)) 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 <= -0.039) {
                                    		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 <= -0.039:
                                    		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 <= -0.039)
                                    		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 <= -0.039)
                                    		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, -0.039], 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 -0.039:\\
                                    \;\;\;\;\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 < -0.0389999999999999999

                                      1. Initial program 84.6%

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

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

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

                                      if -0.0389999999999999999 < d2

                                      1. Initial program 90.0%

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

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

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

                                    Alternative 10: 93.9% accurate, 1.7× speedup?

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

                                      1. Initial program 89.9%

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

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

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

                                      if 8.50000000000000038e67 < d4

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

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

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

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

                                    Alternative 11: 73.3% accurate, 2.0× speedup?

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

                                      1. Initial program 90.7%

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

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

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

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

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

                                        if 3.6999999999999999e33 < d4

                                        1. Initial program 80.7%

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

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

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

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

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

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

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

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

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

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

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

                                        Alternative 12: 50.3% accurate, 2.5× speedup?

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

                                          1. Initial program 85.5%

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

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

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

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

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

                                          if -1.49999999999999991e-31 < d2

                                          1. Initial program 89.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 inf

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

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

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

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

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

                                        Alternative 13: 30.9% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

                                        Reproduce

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