FastMath dist4

Percentage Accurate: 87.5% → 96.7%
Time: 15.2s
Alternatives: 14
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 87.5% accurate, 1.0× speedup?

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

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

Alternative 1: 96.7% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.6% accurate, 0.6× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < +inf.0

    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. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 3: 73.2% accurate, 1.1× speedup?

    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.22 \cdot 10^{+110}:\\ \;\;\;\;\left(d4 + d2\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -35000000000000:\\ \;\;\;\;\left(d2 - d3\right) \cdot d1\\ \mathbf{elif}\;d2 \leq -1.12 \cdot 10^{-105}:\\ \;\;\;\;\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 -1.22e+110)
       (* (+ d4 d2) d1)
       (if (<= d2 -35000000000000.0)
         (* (- d2 d3) d1)
         (if (<= d2 -1.12e-105) (* (- 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 <= -1.22e+110) {
    		tmp = (d4 + d2) * d1;
    	} else if (d2 <= -35000000000000.0) {
    		tmp = (d2 - d3) * d1;
    	} else if (d2 <= -1.12e-105) {
    		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 <= (-1.22d+110)) then
            tmp = (d4 + d2) * d1
        else if (d2 <= (-35000000000000.0d0)) then
            tmp = (d2 - d3) * d1
        else if (d2 <= (-1.12d-105)) 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 <= -1.22e+110) {
    		tmp = (d4 + d2) * d1;
    	} else if (d2 <= -35000000000000.0) {
    		tmp = (d2 - d3) * d1;
    	} else if (d2 <= -1.12e-105) {
    		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 <= -1.22e+110:
    		tmp = (d4 + d2) * d1
    	elif d2 <= -35000000000000.0:
    		tmp = (d2 - d3) * d1
    	elif d2 <= -1.12e-105:
    		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 <= -1.22e+110)
    		tmp = Float64(Float64(d4 + d2) * d1);
    	elseif (d2 <= -35000000000000.0)
    		tmp = Float64(Float64(d2 - d3) * d1);
    	elseif (d2 <= -1.12e-105)
    		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 <= -1.22e+110)
    		tmp = (d4 + d2) * d1;
    	elseif (d2 <= -35000000000000.0)
    		tmp = (d2 - d3) * d1;
    	elseif (d2 <= -1.12e-105)
    		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, -1.22e+110], N[(N[(d4 + d2), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -35000000000000.0], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -1.12e-105], 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 -1.22 \cdot 10^{+110}:\\
    \;\;\;\;\left(d4 + d2\right) \cdot d1\\
    
    \mathbf{elif}\;d2 \leq -35000000000000:\\
    \;\;\;\;\left(d2 - d3\right) \cdot d1\\
    
    \mathbf{elif}\;d2 \leq -1.12 \cdot 10^{-105}:\\
    \;\;\;\;\left(d4 - d1\right) \cdot d1\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(d4 - d3\right) \cdot d1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if d2 < -1.22000000000000002e110

      1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

        if -1.22000000000000002e110 < d2 < -3.5e13

        1. Initial program 77.8%

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

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

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

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

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

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

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

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

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

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

          if -3.5e13 < d2 < -1.11999999999999995e-105

          1. Initial program 96.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if -1.11999999999999995e-105 < d2

            1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 4: 54.0% accurate, 1.2× speedup?

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

              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. Step-by-step derivation
                1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -2.54999999999999992e-275 < d4 < 4.89999999999999967e-145

              1. Initial program 94.2%

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

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

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

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

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

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

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

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

              if 4.89999999999999967e-145 < d4 < 1.45e31

              1. Initial program 96.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if 1.45e31 < d4

              1. Initial program 81.8%

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

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

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

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

            Alternative 5: 88.8% accurate, 1.2× speedup?

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

              1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -1.1500000000000001e132 < d1 < 7.4000000000000001e81

                1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

              Alternative 6: 77.0% accurate, 1.3× speedup?

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

                1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

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

                  if -3.4000000000000002e-204 < d4 < 2.79999999999999983e30

                  1. Initial program 94.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if 2.79999999999999983e30 < d4

                    1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 7: 68.3% accurate, 1.4× speedup?

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

                      1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if -1.2999999999999999e143 < d3 < 2.49999999999999994e101

                      1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

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

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

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

                        1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

                          if -1.22000000000000002e110 < d2 < -3.5e13

                          1. Initial program 77.8%

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

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

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

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

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

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

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

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

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

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

                            if -3.5e13 < d2

                            1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 9: 92.9% 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.5 \cdot 10^{+20}:\\ \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(d4 - d1\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 (<= d2 -5.5e+20) (fma (- d2 d3) d1 (* d4 d1)) (* (- (- d4 d1) d3) d1)))
                            assert(d1 < d2 && d2 < d3 && d3 < d4);
                            double code(double d1, double d2, double d3, double d4) {
                            	double tmp;
                            	if (d2 <= -5.5e+20) {
                            		tmp = fma((d2 - d3), d1, (d4 * d1));
                            	} else {
                            		tmp = ((d4 - d1) - d3) * d1;
                            	}
                            	return tmp;
                            }
                            
                            d1, d2, d3, d4 = sort([d1, d2, d3, d4])
                            function code(d1, d2, d3, d4)
                            	tmp = 0.0
                            	if (d2 <= -5.5e+20)
                            		tmp = fma(Float64(d2 - d3), d1, Float64(d4 * d1));
                            	else
                            		tmp = Float64(Float64(Float64(d4 - d1) - d3) * d1);
                            	end
                            	return tmp
                            end
                            
                            NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                            code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.5e+20], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d4 * d1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d4 - d1), $MachinePrecision] - 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.5 \cdot 10^{+20}:\\
                            \;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d4 \cdot d1\right)\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 2 regimes
                            2. if d2 < -5.5e20

                              1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if -5.5e20 < d2

                              1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 10: 54.0% accurate, 1.5× speedup?

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

                              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. Step-by-step derivation
                                1. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if 7.80000000000000058e-228 < d4 < 1.45e31

                              1. Initial program 98.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if 1.45e31 < d4

                              1. Initial program 81.8%

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

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

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

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

                            Alternative 11: 93.6% accurate, 1.7× speedup?

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

                              1. Initial program 83.3%

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

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

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

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

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

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

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

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

                              if -5.5e20 < d2

                              1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 12: 72.6% accurate, 2.0× speedup?

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

                              1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

                                if 1.45e31 < d4

                                1. Initial program 81.8%

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

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

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

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

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

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

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

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

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

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

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

                                Alternative 13: 50.7% accurate, 2.5× speedup?

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

                                  1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                  if 1.8499999999999999e31 < d4

                                  1. Initial program 81.8%

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

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

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

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

                                Alternative 14: 31.0% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                Reproduce

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