FastMath dist4

Percentage Accurate: 87.6% → 98.3%
Time: 19.3s
Alternatives: 16
Speedup: 1.2×

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 16 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.6% accurate, 1.0× speedup?

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

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

Alternative 1: 98.3% accurate, 1.2× speedup?

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

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


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

    1. Initial program 84.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -9.9999999999999996e216 < d2

      1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 2: 52.9% accurate, 0.9× speedup?

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

      1. Initial program 90.5%

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

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

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

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

      if -3.9e8 < d2 < -3.80000000000000018e-165 or -1.4e-295 < d2 < 4e-165

      1. Initial program 93.7%

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

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

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

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

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

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

      if -3.80000000000000018e-165 < d2 < -1.4e-295

      1. Initial program 93.0%

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

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

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

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

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

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

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

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

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

      if 4e-165 < d2

      1. Initial program 81.0%

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

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

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

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

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

    Alternative 3: 74.0% accurate, 1.0× speedup?

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

      1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -2.1000000000000001e117 < d2 < -3.4e-16

        1. Initial program 89.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -3.4e-16 < d2 < -2.2999999999999999e-297

          1. Initial program 93.6%

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

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

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

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

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

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

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

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

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

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

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

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

            if -2.2999999999999999e-297 < d2

            1. Initial program 83.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

            Alternative 4: 71.7% accurate, 1.1× speedup?

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

              1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -2.1000000000000001e117 < d2 < -1.0999999999999999e-70

                1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if -1.0999999999999999e-70 < d2 < 9.49999999999999929e-276

                  1. Initial program 94.7%

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

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

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

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

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

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

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

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

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

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

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

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

                    if 9.49999999999999929e-276 < d2

                    1. Initial program 83.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. lower-*.f64N/A

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

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

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

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

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

                        \[\leadsto d1 \cdot \left(d4 - \color{blue}{d1}\right) \]
                    8. Recombined 4 regimes into one program.
                    9. Final simplification67.5%

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

                    Alternative 5: 94.4% accurate, 1.2× speedup?

                    \[\begin{array}{l} [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\ \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.12 \cdot 10^{+116}:\\ \;\;\;\;d1 \cdot \left(d2 + \left(d4 - d3\right)\right)\\ \mathbf{elif}\;d2 \leq -8 \cdot 10^{-44}:\\ \;\;\;\;d1 \cdot \left(\left(d2 - d3\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\ \end{array} \end{array} \]
                    NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
                    (FPCore (d1 d2 d3 d4)
                     :precision binary64
                     (if (<= d2 -1.12e+116)
                       (* d1 (+ d2 (- d4 d3)))
                       (if (<= d2 -8e-44) (* d1 (- (- d2 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 (d2 <= -1.12e+116) {
                    		tmp = d1 * (d2 + (d4 - d3));
                    	} else if (d2 <= -8e-44) {
                    		tmp = d1 * ((d2 - d3) - d1);
                    	} else {
                    		tmp = d1 * ((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.12d+116)) then
                            tmp = d1 * (d2 + (d4 - d3))
                        else if (d2 <= (-8d-44)) then
                            tmp = d1 * ((d2 - d3) - d1)
                        else
                            tmp = d1 * ((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.12e+116) {
                    		tmp = d1 * (d2 + (d4 - d3));
                    	} else if (d2 <= -8e-44) {
                    		tmp = d1 * ((d2 - d3) - d1);
                    	} else {
                    		tmp = d1 * ((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.12e+116:
                    		tmp = d1 * (d2 + (d4 - d3))
                    	elif d2 <= -8e-44:
                    		tmp = d1 * ((d2 - d3) - d1)
                    	else:
                    		tmp = d1 * ((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.12e+116)
                    		tmp = Float64(d1 * Float64(d2 + Float64(d4 - d3)));
                    	elseif (d2 <= -8e-44)
                    		tmp = Float64(d1 * Float64(Float64(d2 - d3) - d1));
                    	else
                    		tmp = Float64(d1 * 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.12e+116)
                    		tmp = d1 * (d2 + (d4 - d3));
                    	elseif (d2 <= -8e-44)
                    		tmp = d1 * ((d2 - d3) - d1);
                    	else
                    		tmp = d1 * ((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.12e+116], N[(d1 * N[(d2 + N[(d4 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -8e-44], N[(d1 * N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d4 - d3), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]]
                    
                    \begin{array}{l}
                    [d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;d2 \leq -1.12 \cdot 10^{+116}:\\
                    \;\;\;\;d1 \cdot \left(d2 + \left(d4 - d3\right)\right)\\
                    
                    \mathbf{elif}\;d2 \leq -8 \cdot 10^{-44}:\\
                    \;\;\;\;d1 \cdot \left(\left(d2 - d3\right) - d1\right)\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 regimes
                    2. if d2 < -1.12e116

                      1. Initial program 91.4%

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

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

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

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

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

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

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

                      if -1.12e116 < d2 < -7.99999999999999962e-44

                      1. Initial program 87.9%

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

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

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      6. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

                      if -7.99999999999999962e-44 < d2

                      1. Initial program 87.2%

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

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

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

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

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

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

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

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

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

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

                    Alternative 6: 92.3% accurate, 1.2× speedup?

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

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

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

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      6. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

                      if -4.3e17 < d3 < 2.00000000000000003e100

                      1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if 2.00000000000000003e100 < d3

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

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

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

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

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

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

                    Alternative 7: 93.0% accurate, 1.2× speedup?

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

                      1. Initial program 80.0%

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

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

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

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

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

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

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

                      if -4.2e17 < d3 < 2.00000000000000003e100

                      1. Initial program 92.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 8: 88.9% accurate, 1.2× speedup?

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

                      1. Initial program 76.7%

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

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

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

                        \[\leadsto \color{blue}{d1 \cdot d2} \]
                      6. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if -3.09999999999999991e113 < d3 < 2.84999999999999992e100

                        1. Initial program 92.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if 2.84999999999999992e100 < d3

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

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

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

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

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

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

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

                        Alternative 9: 98.8% accurate, 1.2× speedup?

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

                          1. Initial program 54.8%

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

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

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

                            \[\leadsto \color{blue}{d1 \cdot d2} \]
                          6. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

                          if -2e153 < d1

                          1. Initial program 92.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        Alternative 10: 70.9% accurate, 1.4× speedup?

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

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

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

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

                            \[\leadsto \color{blue}{d1 \cdot d2} \]
                          6. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if 1.7e-270 < d4 < 1.2e118

                            1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              if 1.2e118 < d4

                              1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              Alternative 11: 67.3% accurate, 1.4× speedup?

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

                                1. Initial program 75.8%

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

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

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

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

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

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

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

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

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

                                if -4.3000000000000002e120 < d3 < 6.99999999999999965e192

                                1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                Alternative 12: 53.1% accurate, 1.5× speedup?

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

                                  1. Initial program 90.5%

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

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

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

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

                                  if -3.9e8 < d2 < 4e-165

                                  1. Initial program 93.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 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. *-commutativeN/A

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

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

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

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

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

                                  if 4e-165 < d2

                                  1. Initial program 81.0%

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

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

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

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

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

                                Alternative 13: 73.5% accurate, 2.0× speedup?

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

                                  1. Initial program 90.0%

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

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

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

                                    \[\leadsto \color{blue}{d1 \cdot d2} \]
                                  6. Taylor expanded in d4 around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -1.95000000000000005e30 < d2

                                    1. Initial program 87.2%

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

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

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

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

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

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

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

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

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

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

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

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

                                    Alternative 14: 69.8% accurate, 2.0× speedup?

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

                                      1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        if 1.2e118 < d4

                                        1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        Alternative 15: 50.1% accurate, 2.5× speedup?

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

                                          1. Initial program 89.7%

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

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

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

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

                                          if -7.99999999999999962e-44 < d2

                                          1. Initial program 87.2%

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

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

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

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

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

                                        Alternative 16: 31.7% accurate, 5.0× speedup?

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

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

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

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

                                          \[\leadsto \color{blue}{d1 \cdot d2} \]
                                        6. Final simplification34.1%

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