FastMath dist4

Percentage Accurate: 87.7% → 97.0%
Time: 10.0s
Alternatives: 13
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 87.7% accurate, 1.0× speedup?

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

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

Alternative 1: 97.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 52.8% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 94.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.1999999999999998e-241 < d4 < 2.7e34

    1. Initial program 90.1%

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

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

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

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

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

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

    if 2.7e34 < d4 < 1.15000000000000011e130

    1. Initial program 95.2%

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

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

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

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      4. 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--.f64100.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\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.f6435.2

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

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

    if 1.15000000000000011e130 < d4

    1. Initial program 77.7%

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

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

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

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

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

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

Alternative 3: 89.5% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 68.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -6.7999999999999995e86 < d1 < 1.74999999999999999e93

      1. Initial program 100.0%

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

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

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

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

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

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

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

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

      if 1.74999999999999999e93 < d1

      1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 76.8% accurate, 1.3× speedup?

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

        1. Initial program 94.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-+.f6478.7

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

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

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

          if 5.1999999999999998e-241 < d4 < 5.49999999999999967e80

          1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 5.49999999999999967e80 < d4

            1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 5: 68.2% accurate, 1.4× speedup?

            \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d3 \leq -3.9 \cdot 10^{+147} \lor \neg \left(d3 \leq 3.1 \cdot 10^{+172}\right):\\ \;\;\;\;\left(-d3\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 (or (<= d3 -3.9e+147) (not (<= d3 3.1e+172)))
               (* (- d3) d1)
               (* (+ d4 d2) d1)))
            assert(d1 < d2 && d2 < d3 && d3 < d4);
            double code(double d1, double d2, double d3, double d4) {
            	double tmp;
            	if ((d3 <= -3.9e+147) || !(d3 <= 3.1e+172)) {
            		tmp = -d3 * 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 ((d3 <= (-3.9d+147)) .or. (.not. (d3 <= 3.1d+172))) then
                    tmp = -d3 * 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 ((d3 <= -3.9e+147) || !(d3 <= 3.1e+172)) {
            		tmp = -d3 * 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 (d3 <= -3.9e+147) or not (d3 <= 3.1e+172):
            		tmp = -d3 * 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 ((d3 <= -3.9e+147) || !(d3 <= 3.1e+172))
            		tmp = Float64(Float64(-d3) * 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 ((d3 <= -3.9e+147) || ~((d3 <= 3.1e+172)))
            		tmp = -d3 * 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[Or[LessEqual[d3, -3.9e+147], N[Not[LessEqual[d3, 3.1e+172]], $MachinePrecision]], N[((-d3) * 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}\;d3 \leq -3.9 \cdot 10^{+147} \lor \neg \left(d3 \leq 3.1 \cdot 10^{+172}\right):\\
            \;\;\;\;\left(-d3\right) \cdot d1\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(d4 + d2\right) \cdot d1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if d3 < -3.90000000000000016e147 or 3.09999999999999988e172 < d3

              1. Initial program 89.7%

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

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\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.f6481.1

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

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

              if -3.90000000000000016e147 < d3 < 3.09999999999999988e172

              1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

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

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

              Alternative 6: 74.1% accurate, 1.4× speedup?

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

                1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

                  if -9.49999999999999927e28 < d2 < -8.19999999999999987e-79

                  1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if -8.19999999999999987e-79 < d2

                    1. Initial program 92.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 7: 52.9% accurate, 1.5× speedup?

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

                      1. Initial program 96.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. 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.4

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

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

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

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

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

                      if -4.2000000000000001e-293 < d4 < 1.15000000000000011e130

                      1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \color{blue}{\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)} \]
                      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.7

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

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

                      if 1.15000000000000011e130 < d4

                      1. Initial program 77.7%

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

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

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

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

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

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

                    Alternative 8: 94.1% accurate, 1.7× speedup?

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

                      1. Initial program 83.3%

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

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

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

                      if -3.9999999999999999e31 < d2

                      1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 9: 93.6% accurate, 1.7× speedup?

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

                      1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

                      if 3.29999999999999988e34 < d4

                      1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

                    Alternative 10: 72.5% accurate, 2.0× speedup?

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

                      1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

                        if -9.49999999999999927e28 < d2

                        1. Initial program 93.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        Alternative 11: 71.4% accurate, 2.0× speedup?

                        \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d4 \leq 1.2 \cdot 10^{+130}:\\ \;\;\;\;\left(d2 - d3\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.2e+130) (* (- d2 d3) 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.2e+130) {
                        		tmp = (d2 - d3) * 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.2d+130) then
                                tmp = (d2 - d3) * 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.2e+130) {
                        		tmp = (d2 - d3) * 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.2e+130:
                        		tmp = (d2 - d3) * 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.2e+130)
                        		tmp = Float64(Float64(d2 - d3) * 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.2e+130)
                        		tmp = (d2 - d3) * 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.2e+130], N[(N[(d2 - d3), $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 1.2 \cdot 10^{+130}:\\
                        \;\;\;\;\left(d2 - d3\right) \cdot d1\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\left(d4 + d2\right) \cdot d1\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if d4 < 1.20000000000000012e130

                          1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

                            if 1.20000000000000012e130 < d4

                            1. Initial program 77.7%

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 12: 50.1% accurate, 2.5× speedup?

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

                              1. Initial program 83.3%

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

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

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

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

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

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

                              if -2.99999999999999989e31 < d2

                              1. Initial program 93.3%

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

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

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

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

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

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

                            Alternative 13: 31.6% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            Reproduce

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