FastMath dist4

Percentage Accurate: 87.5% → 98.8%
Time: 12.9s
Alternatives: 14
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 14 alternatives:

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

Initial Program: 87.5% 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.8% accurate, 1.0× speedup?

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

\mathbf{elif}\;d1 \leq 5 \cdot 10^{+189}:\\
\;\;\;\;\mathsf{fma}\left(d1, d4 - d1, \left(d2 - d3\right) \cdot d1\right)\\

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


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

    1. Initial program 40.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--.f6493.8

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

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

    if -3.9999999999999999e185 < d1 < 5.0000000000000004e189

    1. Initial program 96.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000004e189 < d1

    1. Initial program 40.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{-1 \cdot \left(d1 \cdot \left(d1 - d4\right)\right)}\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

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

        \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{d1 \cdot \left(\mathsf{neg}\left(\left(d1 - d4\right)\right)\right)}\right) \]
      3. sub-negN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(d2, d1, d1 \cdot \left(-1 \cdot d1 + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(d4\right)\right)}\right)\right)\right)\right) \]
      8. remove-double-negN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(d2, d1, \color{blue}{\left(d4 - d1\right)} \cdot d1\right) \]
      14. lower--.f6486.7

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

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

Alternative 2: 74.3% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 81.5%

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

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

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

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

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

      if -3.7999999999999998e-258 < d4 < 6.80000000000000034e-251

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

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

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

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

        if 6.80000000000000034e-251 < d4 < 1.85e37

        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. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

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

          if 1.85e37 < d4

          1. Initial program 79.2%

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

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

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

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

              \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot d4} \]
            3. Step-by-step derivation
              1. Applied rewrites69.8%

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

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

            Alternative 3: 98.7% accurate, 1.0× speedup?

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

              1. Initial program 47.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--.f6490.5

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

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

              if -1.26e154 < d1

              1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 4: 89.3% accurate, 1.2× speedup?

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

              1. Initial program 51.1%

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

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

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

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

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

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

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

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

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

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

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

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

                if -4.5000000000000001e137 < d1 < 8.49999999999999986e81

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

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

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

                if 8.49999999999999986e81 < d1

                1. Initial program 52.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 5: 99.3% accurate, 1.2× speedup?

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

                  1. Initial program 40.0%

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

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

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

                  if -1e177 < d1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 6: 98.8% accurate, 1.2× speedup?

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

                  1. Initial program 47.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--.f6490.5

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

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

                  if -1.35000000000000003e154 < d1

                  1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\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 simplification96.8%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;\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 7: 71.6% accurate, 1.4× speedup?

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

                  1. Initial program 81.5%

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

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

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

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

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

                    if -3.7999999999999998e-258 < d4 < 4.44999999999999999e36

                    1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if 4.44999999999999999e36 < d4

                      1. Initial program 79.2%

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

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

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

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

                          \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot d4} \]
                        3. Step-by-step derivation
                          1. Applied rewrites69.8%

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

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

                        Alternative 8: 70.4% accurate, 1.4× speedup?

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

                          1. Initial program 83.9%

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

                            \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 + d4\right) - d3\right)} \]
                          4. Step-by-step derivation
                            1. *-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-+.f6469.8

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

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

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

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

                            if 1.34999999999999994e-30 < d4 < 6.19999999999999973e35

                            1. Initial program 90.9%

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

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

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

                            if 6.19999999999999973e35 < d4

                            1. Initial program 79.2%

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

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

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

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

                                \[\leadsto d1 \cdot d2 + \color{blue}{d1 \cdot d4} \]
                              3. Step-by-step derivation
                                1. Applied rewrites69.8%

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

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

                              Alternative 9: 64.6% 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 -4.5 \cdot 10^{+160}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d1 \leq 6 \cdot 10^{+15}:\\ \;\;\;\;\left(d2 - d3\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 -4.5e+160) t_0 (if (<= d1 6e+15) (* (- d2 d3) 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 <= -4.5e+160) {
                              		tmp = t_0;
                              	} else if (d1 <= 6e+15) {
                              		tmp = (d2 - d3) * 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 <= (-4.5d+160)) then
                                      tmp = t_0
                                  else if (d1 <= 6d+15) then
                                      tmp = (d2 - d3) * 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 <= -4.5e+160) {
                              		tmp = t_0;
                              	} else if (d1 <= 6e+15) {
                              		tmp = (d2 - d3) * 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 <= -4.5e+160:
                              		tmp = t_0
                              	elif d1 <= 6e+15:
                              		tmp = (d2 - d3) * 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 <= -4.5e+160)
                              		tmp = t_0;
                              	elseif (d1 <= 6e+15)
                              		tmp = Float64(Float64(d2 - d3) * 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 <= -4.5e+160)
                              		tmp = t_0;
                              	elseif (d1 <= 6e+15)
                              		tmp = (d2 - d3) * 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, -4.5e+160], t$95$0, If[LessEqual[d1, 6e+15], N[(N[(d2 - d3), $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 -4.5 \cdot 10^{+160}:\\
                              \;\;\;\;t\_0\\
                              
                              \mathbf{elif}\;d1 \leq 6 \cdot 10^{+15}:\\
                              \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;t\_0\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 2 regimes
                              2. if d1 < -4.4999999999999998e160 or 6e15 < d1

                                1. Initial program 57.1%

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

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

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

                                    \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d1} \]
                                  3. 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.f6474.3

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

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

                                if -4.4999999999999998e160 < d1 < 6e15

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

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

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

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

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

                                Alternative 10: 54.0% accurate, 1.5× speedup?

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

                                  1. Initial program 81.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                      \[\leadsto \color{blue}{d1 \cdot d2} \]
                                  7. Applied rewrites31.0%

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

                                  if -2.95e-260 < d4 < 4.44999999999999999e36

                                  1. Initial program 88.1%

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

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

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

                                      \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d1} \]
                                    3. 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.f6448.4

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

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

                                  if 4.44999999999999999e36 < d4

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

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

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

                                      \[\leadsto \color{blue}{d4 \cdot d1} \]
                                  5. Applied rewrites55.7%

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

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

                                Alternative 11: 52.5% accurate, 1.5× speedup?

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

                                  1. Initial program 79.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                      \[\leadsto \color{blue}{d1 \cdot d2} \]
                                  7. Applied rewrites56.0%

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

                                  if -25 < d2 < -2.70000000000000009e-306

                                  1. Initial program 93.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  if -2.70000000000000009e-306 < d2

                                  1. Initial program 80.0%

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

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

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

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

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

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

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

                                  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. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

                                  if 4.40000000000000001e36 < d4

                                  1. Initial program 79.2%

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

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

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

                                Alternative 13: 49.2% accurate, 2.5× speedup?

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

                                  1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  if -2.39999999999999979e-7 < d2

                                  1. Initial program 84.0%

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

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

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

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

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

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

                                Alternative 14: 30.8% accurate, 5.0× speedup?

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

                                  \[\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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto \color{blue}{d1 \cdot d2} \]
                                8. Final simplification29.8%

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