FastMath dist4

Percentage Accurate: 88.2% → 98.4%
Time: 8.1s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 88.2% accurate, 1.0× speedup?

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

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

Alternative 1: 98.4% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 69.0% accurate, 0.9× speedup?

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

\mathbf{elif}\;d1 \leq -5.5 \cdot 10^{-246}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d1 \leq 2.3 \cdot 10^{+70}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -5.8000000000000004e112 or 2.29999999999999994e70 < d1

    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -5.8000000000000004e112 < d1 < -5.49999999999999982e-246 or 7.5999999999999995e-120 < d1 < 2.29999999999999994e70

      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-+.f6490.1

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

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

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

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

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

          if -5.49999999999999982e-246 < d1 < 7.5999999999999995e-120

          1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 3: 53.8% accurate, 1.2× speedup?

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

            1. Initial program 79.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -6e12 < d2 < -1.70000000000000008e-104

            1. Initial program 84.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -1.70000000000000008e-104 < d2 < -2.45e-300

            1. Initial program 87.8%

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

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

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

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

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

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

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

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

            if -2.45e-300 < d2

            1. Initial program 88.8%

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

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

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

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

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

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

          Alternative 4: 93.2% accurate, 1.2× speedup?

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

            1. Initial program 81.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(d4, d1, d1 \cdot \color{blue}{\left(d2 - d3\right)}\right) \]
            6. Step-by-step derivation
              1. lower--.f6490.2

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

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

            if -1.3499999999999999e-32 < d3 < 4.1e12

            1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 4.1e12 < d3

            1. Initial program 76.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-+.f6490.9

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

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

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

          Alternative 5: 93.3% accurate, 1.2× speedup?

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

            1. Initial program 79.3%

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

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

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

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

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

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

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

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

            if -1.3499999999999999e-32 < d3 < 4.1e12

            1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 6: 89.4% accurate, 1.2× speedup?

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

            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 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-+.f6493.9

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

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

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

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

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

                if -1.3999999999999999e108 < d3 < 1.64999999999999995e80

                1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 1.64999999999999995e80 < d3

                1. Initial program 75.5%

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

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

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

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

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

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

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

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

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

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

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

                Alternative 7: 74.8% accurate, 1.4× speedup?

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

                  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 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-+.f6490.1

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

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

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

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

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

                      if -5.9000000000000003e-21 < d2 < -1.84999999999999997e-294

                      1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if -1.84999999999999997e-294 < d2

                        1. Initial program 88.9%

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

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

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

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

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

                        Alternative 8: 72.8% accurate, 1.4× speedup?

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

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

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

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

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

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

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

                              if -4.39999999999999992e60 < d3 < 7.1999999999999998e73

                              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 d3 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              Alternative 9: 65.8% accurate, 1.4× speedup?

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

                                1. Initial program 48.6%

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

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

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

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

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

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

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

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

                                if -6.5999999999999998e112 < d1 < 9.49999999999999926e146

                                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-+.f6492.1

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

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

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

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

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

                                  Alternative 10: 53.5% accurate, 1.5× speedup?

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

                                    1. Initial program 79.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -6e12 < d2 < 3.89999999999999973e-290

                                    1. Initial program 87.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if 3.89999999999999973e-290 < d2

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

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

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

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

                                  Alternative 11: 50.9% accurate, 2.5× speedup?

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

                                    1. Initial program 79.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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -6e12 < d2

                                    1. Initial program 88.1%

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

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

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

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

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

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

                                  Alternative 12: 30.9% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  Reproduce

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