FastMath dist4

Percentage Accurate: 88.0% → 100.0%
Time: 8.9s
Alternatives: 14
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 88.0% 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: 100.0% accurate, 1.7× speedup?

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

\\
d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) + d2\right)
\end{array}
Derivation
  1. Initial program 90.2%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. associate--l+90.2%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
    6. associate--r-90.2%

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
    7. associate-+r-90.2%

      \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
    8. +-commutative90.2%

      \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    9. *-commutative90.2%

      \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    10. sub-neg90.2%

      \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    11. distribute-lft-out--90.6%

      \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    12. distribute-lft-out--96.1%

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
    13. neg-sub096.1%

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
    14. distribute-rgt-neg-out96.1%

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
    15. distribute-lft-out--100.0%

      \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
    16. sub-neg100.0%

      \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
    17. remove-double-neg100.0%

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

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

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

Alternative 2: 84.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{if}\;d3 \leq -1.15 \cdot 10^{+142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -3.4 \cdot 10^{+63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -0.135:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -2.9 \cdot 10^{-26}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d3 \leq 3.4 \cdot 10^{+99}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))) (t_1 (* d1 (- (+ d4 d2) d1))))
   (if (<= d3 -1.15e+142)
     t_0
     (if (<= d3 -3.4e+63)
       t_1
       (if (<= d3 -0.135)
         t_0
         (if (<= d3 -2.9e-26)
           (* d1 (- d4 d3))
           (if (<= d3 3.4e+99) t_1 (* d1 (- (- d3) d1)))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * ((d4 + d2) - d1);
	double tmp;
	if (d3 <= -1.15e+142) {
		tmp = t_0;
	} else if (d3 <= -3.4e+63) {
		tmp = t_1;
	} else if (d3 <= -0.135) {
		tmp = t_0;
	} else if (d3 <= -2.9e-26) {
		tmp = d1 * (d4 - d3);
	} else if (d3 <= 3.4e+99) {
		tmp = t_1;
	} else {
		tmp = d1 * (-d3 - d1);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    t_1 = d1 * ((d4 + d2) - d1)
    if (d3 <= (-1.15d+142)) then
        tmp = t_0
    else if (d3 <= (-3.4d+63)) then
        tmp = t_1
    else if (d3 <= (-0.135d0)) then
        tmp = t_0
    else if (d3 <= (-2.9d-26)) then
        tmp = d1 * (d4 - d3)
    else if (d3 <= 3.4d+99) then
        tmp = t_1
    else
        tmp = d1 * (-d3 - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * ((d4 + d2) - d1);
	double tmp;
	if (d3 <= -1.15e+142) {
		tmp = t_0;
	} else if (d3 <= -3.4e+63) {
		tmp = t_1;
	} else if (d3 <= -0.135) {
		tmp = t_0;
	} else if (d3 <= -2.9e-26) {
		tmp = d1 * (d4 - d3);
	} else if (d3 <= 3.4e+99) {
		tmp = t_1;
	} else {
		tmp = d1 * (-d3 - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	t_1 = d1 * ((d4 + d2) - d1)
	tmp = 0
	if d3 <= -1.15e+142:
		tmp = t_0
	elif d3 <= -3.4e+63:
		tmp = t_1
	elif d3 <= -0.135:
		tmp = t_0
	elif d3 <= -2.9e-26:
		tmp = d1 * (d4 - d3)
	elif d3 <= 3.4e+99:
		tmp = t_1
	else:
		tmp = d1 * (-d3 - d1)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	t_1 = Float64(d1 * Float64(Float64(d4 + d2) - d1))
	tmp = 0.0
	if (d3 <= -1.15e+142)
		tmp = t_0;
	elseif (d3 <= -3.4e+63)
		tmp = t_1;
	elseif (d3 <= -0.135)
		tmp = t_0;
	elseif (d3 <= -2.9e-26)
		tmp = Float64(d1 * Float64(d4 - d3));
	elseif (d3 <= 3.4e+99)
		tmp = t_1;
	else
		tmp = Float64(d1 * Float64(Float64(-d3) - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	t_1 = d1 * ((d4 + d2) - d1);
	tmp = 0.0;
	if (d3 <= -1.15e+142)
		tmp = t_0;
	elseif (d3 <= -3.4e+63)
		tmp = t_1;
	elseif (d3 <= -0.135)
		tmp = t_0;
	elseif (d3 <= -2.9e-26)
		tmp = d1 * (d4 - d3);
	elseif (d3 <= 3.4e+99)
		tmp = t_1;
	else
		tmp = d1 * (-d3 - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -1.15e+142], t$95$0, If[LessEqual[d3, -3.4e+63], t$95$1, If[LessEqual[d3, -0.135], t$95$0, If[LessEqual[d3, -2.9e-26], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 3.4e+99], t$95$1, N[(d1 * N[((-d3) - d1), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d3\right)\\
t_1 := d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\
\mathbf{if}\;d3 \leq -1.15 \cdot 10^{+142}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq -3.4 \cdot 10^{+63}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq -0.135:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq -2.9 \cdot 10^{-26}:\\
\;\;\;\;d1 \cdot \left(d4 - d3\right)\\

\mathbf{elif}\;d3 \leq 3.4 \cdot 10^{+99}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d3 < -1.15000000000000001e142 or -3.3999999999999999e63 < d3 < -0.13500000000000001

    1. Initial program 85.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+85.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg85.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-85.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-85.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative85.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative85.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg85.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--87.7%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.5%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.5%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.5%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -1.15000000000000001e142 < d3 < -3.3999999999999999e63 or -2.8999999999999998e-26 < d3 < 3.39999999999999984e99

    1. Initial program 93.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+93.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg93.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-93.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-93.0%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative93.0%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg93.0%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--93.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.2%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -0.13500000000000001 < d3 < -2.8999999999999998e-26

    1. Initial program 100.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+100.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-100.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-100.0%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative100.0%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg100.0%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--100.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub0100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if 3.39999999999999984e99 < d3

    1. Initial program 83.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+83.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg83.3%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-83.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-83.3%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative83.3%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative83.3%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg83.3%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--83.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--94.4%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub094.4%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out94.4%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

        \[\leadsto \color{blue}{-\left(d1 + d3\right) \cdot d1} \]
      2. distribute-rgt-neg-in86.6%

        \[\leadsto \color{blue}{\left(d1 + d3\right) \cdot \left(-d1\right)} \]
    7. Simplified86.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -1.15 \cdot 10^{+142}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -3.4 \cdot 10^{+63}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{elif}\;d3 \leq -0.135:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -2.9 \cdot 10^{-26}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{elif}\;d3 \leq 3.4 \cdot 10^{+99}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\ \end{array} \]

Alternative 3: 66.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -2.5 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -7 \cdot 10^{-137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 17:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.95 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d3))) (t_1 (* d1 (+ d4 d2))))
   (if (<= d3 -2.5e+73)
     t_0
     (if (<= d3 -7e-137)
       t_1
       (if (<= d3 17.0) (* d1 (- d2 d1)) (if (<= d3 1.95e+100) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d3;
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -2.5e+73) {
		tmp = t_0;
	} else if (d3 <= -7e-137) {
		tmp = t_1;
	} else if (d3 <= 17.0) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 1.95e+100) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * -d3
    t_1 = d1 * (d4 + d2)
    if (d3 <= (-2.5d+73)) then
        tmp = t_0
    else if (d3 <= (-7d-137)) then
        tmp = t_1
    else if (d3 <= 17.0d0) then
        tmp = d1 * (d2 - d1)
    else if (d3 <= 1.95d+100) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d3;
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -2.5e+73) {
		tmp = t_0;
	} else if (d3 <= -7e-137) {
		tmp = t_1;
	} else if (d3 <= 17.0) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 1.95e+100) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d3
	t_1 = d1 * (d4 + d2)
	tmp = 0
	if d3 <= -2.5e+73:
		tmp = t_0
	elif d3 <= -7e-137:
		tmp = t_1
	elif d3 <= 17.0:
		tmp = d1 * (d2 - d1)
	elif d3 <= 1.95e+100:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d3))
	t_1 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d3 <= -2.5e+73)
		tmp = t_0;
	elseif (d3 <= -7e-137)
		tmp = t_1;
	elseif (d3 <= 17.0)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d3 <= 1.95e+100)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d3;
	t_1 = d1 * (d4 + d2);
	tmp = 0.0;
	if (d3 <= -2.5e+73)
		tmp = t_0;
	elseif (d3 <= -7e-137)
		tmp = t_1;
	elseif (d3 <= 17.0)
		tmp = d1 * (d2 - d1);
	elseif (d3 <= 1.95e+100)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d3)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -2.5e+73], t$95$0, If[LessEqual[d3, -7e-137], t$95$1, If[LessEqual[d3, 17.0], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 1.95e+100], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d1 \cdot \left(-d3\right)\\
t_1 := d1 \cdot \left(d4 + d2\right)\\
\mathbf{if}\;d3 \leq -2.5 \cdot 10^{+73}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq -7 \cdot 10^{-137}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq 17:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

\mathbf{elif}\;d3 \leq 1.95 \cdot 10^{+100}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -2.49999999999999988e73 or 1.95e100 < d3

    1. Initial program 83.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+83.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg83.1%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-83.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-83.1%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative83.1%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative83.1%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg83.1%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--84.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--94.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub094.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out94.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    5. Step-by-step derivation
      1. associate-*r*71.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d3} \]
      2. neg-mul-171.9%

        \[\leadsto \color{blue}{\left(-d1\right)} \cdot d3 \]
    6. Simplified71.9%

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

    if -2.49999999999999988e73 < d3 < -7.0000000000000002e-137 or 17 < d3 < 1.95e100

    1. Initial program 92.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+92.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg92.3%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-92.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-92.3%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative92.3%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative92.3%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg92.3%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--92.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -7.0000000000000002e-137 < d3 < 17

    1. Initial program 95.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+95.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg95.8%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-95.8%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-95.8%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative95.8%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg95.8%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--95.8%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.5 \cdot 10^{+73}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d3 \leq -7 \cdot 10^{-137}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 17:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.95 \cdot 10^{+100}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]

Alternative 4: 71.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -4.2 \cdot 10^{+72}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -1.2 \cdot 10^{-137}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 21:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 8.5 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d2 d3))) (t_1 (* d1 (+ d4 d2))))
   (if (<= d3 -4.2e+72)
     t_0
     (if (<= d3 -1.2e-137)
       t_1
       (if (<= d3 21.0) (* d1 (- d2 d1)) (if (<= d3 8.5e+96) t_1 t_0))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -4.2e+72) {
		tmp = t_0;
	} else if (d3 <= -1.2e-137) {
		tmp = t_1;
	} else if (d3 <= 21.0) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 8.5e+96) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = d1 * (d2 - d3)
    t_1 = d1 * (d4 + d2)
    if (d3 <= (-4.2d+72)) then
        tmp = t_0
    else if (d3 <= (-1.2d-137)) then
        tmp = t_1
    else if (d3 <= 21.0d0) then
        tmp = d1 * (d2 - d1)
    else if (d3 <= 8.5d+96) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d3);
	double t_1 = d1 * (d4 + d2);
	double tmp;
	if (d3 <= -4.2e+72) {
		tmp = t_0;
	} else if (d3 <= -1.2e-137) {
		tmp = t_1;
	} else if (d3 <= 21.0) {
		tmp = d1 * (d2 - d1);
	} else if (d3 <= 8.5e+96) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d3)
	t_1 = d1 * (d4 + d2)
	tmp = 0
	if d3 <= -4.2e+72:
		tmp = t_0
	elif d3 <= -1.2e-137:
		tmp = t_1
	elif d3 <= 21.0:
		tmp = d1 * (d2 - d1)
	elif d3 <= 8.5e+96:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d3))
	t_1 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d3 <= -4.2e+72)
		tmp = t_0;
	elseif (d3 <= -1.2e-137)
		tmp = t_1;
	elseif (d3 <= 21.0)
		tmp = Float64(d1 * Float64(d2 - d1));
	elseif (d3 <= 8.5e+96)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * (d2 - d3);
	t_1 = d1 * (d4 + d2);
	tmp = 0.0;
	if (d3 <= -4.2e+72)
		tmp = t_0;
	elseif (d3 <= -1.2e-137)
		tmp = t_1;
	elseif (d3 <= 21.0)
		tmp = d1 * (d2 - d1);
	elseif (d3 <= 8.5e+96)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -4.2e+72], t$95$0, If[LessEqual[d3, -1.2e-137], t$95$1, If[LessEqual[d3, 21.0], N[(d1 * N[(d2 - d1), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 8.5e+96], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d3\right)\\
t_1 := d1 \cdot \left(d4 + d2\right)\\
\mathbf{if}\;d3 \leq -4.2 \cdot 10^{+72}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq -1.2 \cdot 10^{-137}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d3 \leq 21:\\
\;\;\;\;d1 \cdot \left(d2 - d1\right)\\

\mathbf{elif}\;d3 \leq 8.5 \cdot 10^{+96}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -4.2000000000000003e72 or 8.50000000000000025e96 < d3

    1. Initial program 83.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+83.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg83.1%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-83.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-83.1%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative83.1%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative83.1%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg83.1%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--84.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--94.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub094.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out94.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -4.2000000000000003e72 < d3 < -1.2e-137 or 21 < d3 < 8.50000000000000025e96

    1. Initial program 92.3%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+92.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg92.3%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-92.3%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-92.3%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative92.3%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative92.3%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg92.3%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--92.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -1.2e-137 < d3 < 21

    1. Initial program 95.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+95.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg95.8%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-95.8%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-95.8%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative95.8%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg95.8%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--95.8%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -4.2 \cdot 10^{+72}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -1.2 \cdot 10^{-137}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 21:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 8.5 \cdot 10^{+96}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]

Alternative 5: 93.1% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -5.5 \cdot 10^{-23} \lor \neg \left(d3 \leq 3.7 \cdot 10^{+73}\right):\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d3 -5.5e-23) (not (<= d3 3.7e+73)))
   (* d1 (- (+ d4 d2) d3))
   (* d1 (- (+ d4 d2) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -5.5e-23) || !(d3 <= 3.7e+73)) {
		tmp = d1 * ((d4 + d2) - d3);
	} else {
		tmp = d1 * ((d4 + d2) - d1);
	}
	return tmp;
}
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 <= (-5.5d-23)) .or. (.not. (d3 <= 3.7d+73))) then
        tmp = d1 * ((d4 + d2) - d3)
    else
        tmp = d1 * ((d4 + d2) - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -5.5e-23) || !(d3 <= 3.7e+73)) {
		tmp = d1 * ((d4 + d2) - d3);
	} else {
		tmp = d1 * ((d4 + d2) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -5.5e-23) or not (d3 <= 3.7e+73):
		tmp = d1 * ((d4 + d2) - d3)
	else:
		tmp = d1 * ((d4 + d2) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -5.5e-23) || !(d3 <= 3.7e+73))
		tmp = Float64(d1 * Float64(Float64(d4 + d2) - d3));
	else
		tmp = Float64(d1 * Float64(Float64(d4 + d2) - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if ((d3 <= -5.5e-23) || ~((d3 <= 3.7e+73)))
		tmp = d1 * ((d4 + d2) - d3);
	else
		tmp = d1 * ((d4 + d2) - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -5.5e-23], N[Not[LessEqual[d3, 3.7e+73]], $MachinePrecision]], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -5.5 \cdot 10^{-23} \lor \neg \left(d3 \leq 3.7 \cdot 10^{+73}\right):\\
\;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -5.5000000000000001e-23 or 3.69999999999999973e73 < d3

    1. Initial program 87.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+87.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-87.4%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-87.4%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative87.4%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg87.4%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--88.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -5.5000000000000001e-23 < d3 < 3.69999999999999973e73

    1. Initial program 93.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+93.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg93.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-93.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-93.0%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative93.0%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg93.0%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--93.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.1%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -5.5 \cdot 10^{-23} \lor \neg \left(d3 \leq 3.7 \cdot 10^{+73}\right):\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \end{array} \]

Alternative 6: 90.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d1 \leq -3.3 \cdot 10^{+35} \lor \neg \left(d1 \leq 1.3 \cdot 10^{-35}\right):\\ \;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d1 -3.3e+35) (not (<= d1 1.3e-35)))
   (* d1 (- d2 (+ d1 d3)))
   (* d1 (- (+ d4 d2) d3))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d1 <= -3.3e+35) || !(d1 <= 1.3e-35)) {
		tmp = d1 * (d2 - (d1 + d3));
	} else {
		tmp = d1 * ((d4 + d2) - d3);
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if ((d1 <= (-3.3d+35)) .or. (.not. (d1 <= 1.3d-35))) then
        tmp = d1 * (d2 - (d1 + d3))
    else
        tmp = d1 * ((d4 + d2) - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d1 <= -3.3e+35) || !(d1 <= 1.3e-35)) {
		tmp = d1 * (d2 - (d1 + d3));
	} else {
		tmp = d1 * ((d4 + d2) - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d1 <= -3.3e+35) or not (d1 <= 1.3e-35):
		tmp = d1 * (d2 - (d1 + d3))
	else:
		tmp = d1 * ((d4 + d2) - d3)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d1 <= -3.3e+35) || !(d1 <= 1.3e-35))
		tmp = Float64(d1 * Float64(d2 - Float64(d1 + d3)));
	else
		tmp = Float64(d1 * Float64(Float64(d4 + d2) - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if ((d1 <= -3.3e+35) || ~((d1 <= 1.3e-35)))
		tmp = d1 * (d2 - (d1 + d3));
	else
		tmp = d1 * ((d4 + d2) - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -3.3e+35], N[Not[LessEqual[d1, 1.3e-35]], $MachinePrecision]], N[(d1 * N[(d2 - N[(d1 + d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -3.3 \cdot 10^{+35} \lor \neg \left(d1 \leq 1.3 \cdot 10^{-35}\right):\\
\;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -3.3000000000000002e35 or 1.30000000000000002e-35 < d1

    1. Initial program 79.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+79.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg79.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-79.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-79.0%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative79.0%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg79.0%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--79.8%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--91.6%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub091.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -3.3000000000000002e35 < d1 < 1.30000000000000002e-35

    1. Initial program 99.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+99.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg99.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-99.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-99.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative99.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative99.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg99.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--100.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub0100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out100.0%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

Alternative 7: 61.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1 \cdot 10^{+95}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-274}:\\ \;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -1e+95)
   (* d1 (- d2 d3))
   (if (<= d2 -1.05e-274) (* d1 (- (- d3) d1)) (* d1 (- d4 d1)))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1e+95) {
		tmp = d1 * (d2 - d3);
	} else if (d2 <= -1.05e-274) {
		tmp = d1 * (-d3 - d1);
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
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 <= (-1d+95)) then
        tmp = d1 * (d2 - d3)
    else if (d2 <= (-1.05d-274)) then
        tmp = d1 * (-d3 - d1)
    else
        tmp = d1 * (d4 - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1e+95) {
		tmp = d1 * (d2 - d3);
	} else if (d2 <= -1.05e-274) {
		tmp = d1 * (-d3 - d1);
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -1e+95:
		tmp = d1 * (d2 - d3)
	elif d2 <= -1.05e-274:
		tmp = d1 * (-d3 - d1)
	else:
		tmp = d1 * (d4 - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -1e+95)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d2 <= -1.05e-274)
		tmp = Float64(d1 * Float64(Float64(-d3) - d1));
	else
		tmp = Float64(d1 * Float64(d4 - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -1e+95)
		tmp = d1 * (d2 - d3);
	elseif (d2 <= -1.05e-274)
		tmp = d1 * (-d3 - d1);
	else
		tmp = d1 * (d4 - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1e+95], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -1.05e-274], N[(d1 * N[((-d3) - d1), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1 \cdot 10^{+95}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

\mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-274}:\\
\;\;\;\;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 3 regimes
  2. if d2 < -1.00000000000000002e95

    1. Initial program 82.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+82.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg82.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-82.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-82.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative82.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative82.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg82.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--82.9%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--87.2%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub087.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out87.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -1.00000000000000002e95 < d2 < -1.04999999999999997e-274

    1. Initial program 95.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+95.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg95.1%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-95.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-95.1%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative95.1%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative95.1%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg95.1%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--95.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--98.8%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub098.8%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out98.8%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

        \[\leadsto \color{blue}{-\left(d1 + d3\right) \cdot d1} \]
      2. distribute-rgt-neg-in70.1%

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

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

    if -1.04999999999999997e-274 < d2

    1. Initial program 89.7%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+89.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg89.7%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-89.7%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-89.7%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative89.7%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative89.7%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg89.7%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--90.5%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--97.6%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub097.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out97.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1 \cdot 10^{+95}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-274}:\\ \;\;\;\;d1 \cdot \left(\left(-d3\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 8: 67.8% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -3.8 \cdot 10^{+74} \lor \neg \left(d3 \leq 7 \cdot 10^{+98}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (or (<= d3 -3.8e+74) (not (<= d3 7e+98))) (* d1 (- d3)) (* d1 (+ d4 d2))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -3.8e+74) || !(d3 <= 7e+98)) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
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.8d+74)) .or. (.not. (d3 <= 7d+98))) then
        tmp = d1 * -d3
    else
        tmp = d1 * (d4 + d2)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -3.8e+74) || !(d3 <= 7e+98)) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d4 + d2);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -3.8e+74) or not (d3 <= 7e+98):
		tmp = d1 * -d3
	else:
		tmp = d1 * (d4 + d2)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -3.8e+74) || !(d3 <= 7e+98))
		tmp = Float64(d1 * Float64(-d3));
	else
		tmp = Float64(d1 * Float64(d4 + d2));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if ((d3 <= -3.8e+74) || ~((d3 <= 7e+98)))
		tmp = d1 * -d3;
	else
		tmp = d1 * (d4 + d2);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -3.8e+74], N[Not[LessEqual[d3, 7e+98]], $MachinePrecision]], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -3.8 \cdot 10^{+74} \lor \neg \left(d3 \leq 7 \cdot 10^{+98}\right):\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -3.7999999999999998e74 or 7e98 < d3

    1. Initial program 83.1%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+83.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg83.1%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-83.1%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-83.1%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative83.1%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative83.1%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg83.1%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--84.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--94.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub094.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out94.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    5. Step-by-step derivation
      1. associate-*r*71.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d3} \]
      2. neg-mul-171.9%

        \[\leadsto \color{blue}{\left(-d1\right)} \cdot d3 \]
    6. Simplified71.9%

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

    if -3.7999999999999998e74 < d3 < 7e98

    1. Initial program 94.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+94.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-94.4%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-94.4%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative94.4%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg94.4%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--94.4%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -3.8 \cdot 10^{+74} \lor \neg \left(d3 \leq 7 \cdot 10^{+98}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 9: 58.8% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -1.4 \cdot 10^{+73}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-81}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -1.4e+73)
   (* d1 (+ d4 d2))
   (if (<= d2 -1.05e-81) (* d1 (- d3)) (* d1 (- d4 d1)))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1.4e+73) {
		tmp = d1 * (d4 + d2);
	} else if (d2 <= -1.05e-81) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
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.4d+73)) then
        tmp = d1 * (d4 + d2)
    else if (d2 <= (-1.05d-81)) then
        tmp = d1 * -d3
    else
        tmp = d1 * (d4 - d1)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -1.4e+73) {
		tmp = d1 * (d4 + d2);
	} else if (d2 <= -1.05e-81) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * (d4 - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -1.4e+73:
		tmp = d1 * (d4 + d2)
	elif d2 <= -1.05e-81:
		tmp = d1 * -d3
	else:
		tmp = d1 * (d4 - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -1.4e+73)
		tmp = Float64(d1 * Float64(d4 + d2));
	elseif (d2 <= -1.05e-81)
		tmp = Float64(d1 * Float64(-d3));
	else
		tmp = Float64(d1 * Float64(d4 - d1));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -1.4e+73)
		tmp = d1 * (d4 + d2);
	elseif (d2 <= -1.05e-81)
		tmp = d1 * -d3;
	else
		tmp = d1 * (d4 - d1);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.4e+73], N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision], If[LessEqual[d2, -1.05e-81], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.4 \cdot 10^{+73}:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right)\\

\mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-81}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -1.40000000000000004e73

    1. Initial program 81.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+81.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg81.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-81.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-81.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative81.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative81.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg81.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--81.9%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--87.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub087.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out87.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -1.40000000000000004e73 < d2 < -1.05e-81

    1. Initial program 96.8%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+96.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg96.8%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-96.8%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-96.8%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative96.8%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg96.8%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--96.8%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.8%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.8%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.8%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    5. Step-by-step derivation
      1. associate-*r*47.5%

        \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d3} \]
      2. neg-mul-147.5%

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

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

    if -1.05e-81 < d2

    1. Initial program 91.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+91.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-91.4%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-91.4%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative91.4%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg91.4%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--92.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--98.3%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub098.3%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out98.3%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.4 \cdot 10^{+73}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-81}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 10: 39.3% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -5.4 \cdot 10^{+95}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 9.5 \cdot 10^{-158}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -5.4e+95) (* d1 d2) (if (<= d2 9.5e-158) (* d1 (- d1)) (* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -5.4e+95) {
		tmp = d1 * d2;
	} else if (d2 <= 9.5e-158) {
		tmp = d1 * -d1;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    real(8) :: tmp
    if (d2 <= (-5.4d+95)) then
        tmp = d1 * d2
    else if (d2 <= 9.5d-158) then
        tmp = d1 * -d1
    else
        tmp = d1 * d4
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -5.4e+95) {
		tmp = d1 * d2;
	} else if (d2 <= 9.5e-158) {
		tmp = d1 * -d1;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -5.4e+95:
		tmp = d1 * d2
	elif d2 <= 9.5e-158:
		tmp = d1 * -d1
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -5.4e+95)
		tmp = Float64(d1 * d2);
	elseif (d2 <= 9.5e-158)
		tmp = Float64(d1 * Float64(-d1));
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -5.4e+95)
		tmp = d1 * d2;
	elseif (d2 <= 9.5e-158)
		tmp = d1 * -d1;
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -5.4e+95], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, 9.5e-158], N[(d1 * (-d1)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -5.4 \cdot 10^{+95}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq 9.5 \cdot 10^{-158}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -5.4e95

    1. Initial program 82.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+82.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg82.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-82.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-82.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative82.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative82.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg82.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--82.9%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--87.2%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub087.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out87.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -5.4e95 < d2 < 9.50000000000000051e-158

    1. Initial program 93.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+93.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg93.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-93.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-93.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative93.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative93.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg93.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--94.0%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--99.1%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub099.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out99.1%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot {d1}^{2}} \]
    5. Step-by-step derivation
      1. unpow236.9%

        \[\leadsto -1 \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
      2. mul-1-neg36.9%

        \[\leadsto \color{blue}{-d1 \cdot d1} \]
      3. distribute-rgt-neg-out36.9%

        \[\leadsto \color{blue}{d1 \cdot \left(-d1\right)} \]
    6. Simplified36.9%

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

    if 9.50000000000000051e-158 < d2

    1. Initial program 89.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+89.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-89.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-89.2%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative89.2%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative89.2%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg89.2%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--90.3%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--96.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub096.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out96.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -5.4 \cdot 10^{+95}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 9.5 \cdot 10^{-158}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 11: 39.3% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.5 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.1 \cdot 10^{-272}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -4.5e+74)
   (* d1 d2)
   (if (<= d2 -2.1e-272) (* d1 (- d3)) (* d1 d4))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.5e+74) {
		tmp = d1 * d2;
	} else if (d2 <= -2.1e-272) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
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 <= (-4.5d+74)) then
        tmp = d1 * d2
    else if (d2 <= (-2.1d-272)) then
        tmp = d1 * -d3
    else
        tmp = d1 * d4
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.5e+74) {
		tmp = d1 * d2;
	} else if (d2 <= -2.1e-272) {
		tmp = d1 * -d3;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -4.5e+74:
		tmp = d1 * d2
	elif d2 <= -2.1e-272:
		tmp = d1 * -d3
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -4.5e+74)
		tmp = Float64(d1 * d2);
	elseif (d2 <= -2.1e-272)
		tmp = Float64(d1 * Float64(-d3));
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -4.5e+74)
		tmp = d1 * d2;
	elseif (d2 <= -2.1e-272)
		tmp = d1 * -d3;
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.5e+74], N[(d1 * d2), $MachinePrecision], If[LessEqual[d2, -2.1e-272], N[(d1 * (-d3)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.5 \cdot 10^{+74}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d2 \leq -2.1 \cdot 10^{-272}:\\
\;\;\;\;d1 \cdot \left(-d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d2 < -4.5e74

    1. Initial program 81.9%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+81.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg81.9%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-81.9%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-81.9%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative81.9%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative81.9%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg81.9%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--81.9%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--87.9%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub087.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out87.9%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -4.5e74 < d2 < -2.09999999999999987e-272

    1. Initial program 97.4%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+97.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-97.4%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-97.4%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative97.4%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg97.4%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--97.4%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--98.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub098.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out98.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(d1 \cdot d3\right)} \]
    5. Step-by-step derivation
      1. associate-*r*48.5%

        \[\leadsto \color{blue}{\left(-1 \cdot d1\right) \cdot d3} \]
      2. neg-mul-148.5%

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

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

    if -2.09999999999999987e-272 < d2

    1. Initial program 89.0%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+89.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg89.0%

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-89.0%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-89.0%

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

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative89.0%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg89.0%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--89.7%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--97.6%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub097.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out97.6%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.5 \cdot 10^{+74}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.1 \cdot 10^{-272}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 12: 61.8% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -2.3 \cdot 10^{-96}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -2.3e-96) (* d1 (- d2 d3)) (* d1 (- d4 d3))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -2.3e-96) {
		tmp = d1 * (d2 - d3);
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
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.3d-96)) then
        tmp = d1 * (d2 - d3)
    else
        tmp = d1 * (d4 - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -2.3e-96) {
		tmp = d1 * (d2 - d3);
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -2.3e-96:
		tmp = d1 * (d2 - d3)
	else:
		tmp = d1 * (d4 - d3)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -2.3e-96)
		tmp = Float64(d1 * Float64(d2 - d3));
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -2.3e-96)
		tmp = d1 * (d2 - d3);
	else
		tmp = d1 * (d4 - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -2.3e-96], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -2.3 \cdot 10^{-96}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -2.3e-96

    1. Initial program 88.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+88.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-88.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-88.2%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative88.2%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative88.2%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg88.2%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--88.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--91.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub091.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    if -2.3e-96 < d2

    1. Initial program 91.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+91.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-91.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-91.2%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative91.2%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative91.2%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg91.2%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--91.8%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--98.2%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub098.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out98.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -2.3 \cdot 10^{-96}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 13: 37.0% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d2 \leq -4.9 \cdot 10^{-96}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (if (<= d2 -4.9e-96) (* d1 d2) (* d1 d4)))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.9e-96) {
		tmp = d1 * d2;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
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 <= (-4.9d-96)) then
        tmp = d1 * d2
    else
        tmp = d1 * d4
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if (d2 <= -4.9e-96) {
		tmp = d1 * d2;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if d2 <= -4.9e-96:
		tmp = d1 * d2
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if (d2 <= -4.9e-96)
		tmp = Float64(d1 * d2);
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	tmp = 0.0;
	if (d2 <= -4.9e-96)
		tmp = d1 * d2;
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.9e-96], N[(d1 * d2), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.9 \cdot 10^{-96}:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -4.90000000000000016e-96

    1. Initial program 88.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+88.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-88.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-88.2%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative88.2%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative88.2%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg88.2%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--88.2%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--91.7%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub091.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.7%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    if -4.90000000000000016e-96 < d2

    1. Initial program 91.2%

      \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
    2. Step-by-step derivation
      1. associate--l+91.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
      6. associate--r-91.2%

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
      7. associate-+r-91.2%

        \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
      8. +-commutative91.2%

        \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      9. *-commutative91.2%

        \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      10. sub-neg91.2%

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--91.8%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--98.2%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
      13. neg-sub098.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out98.2%

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
      15. distribute-lft-out--100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
      16. sub-neg100.0%

        \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
      17. remove-double-neg100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -4.9 \cdot 10^{-96}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 14: 31.1% accurate, 5.0× speedup?

\[\begin{array}{l} \\ d1 \cdot d4 \end{array} \]
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 d4))
double code(double d1, double d2, double d3, double d4) {
	return d1 * d4;
}
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 * d4
end function
public static double code(double d1, double d2, double d3, double d4) {
	return d1 * d4;
}
def code(d1, d2, d3, d4):
	return d1 * d4
function code(d1, d2, d3, d4)
	return Float64(d1 * d4)
end
function tmp = code(d1, d2, d3, d4)
	tmp = d1 * d4;
end
code[d1_, d2_, d3_, d4_] := N[(d1 * d4), $MachinePrecision]
\begin{array}{l}

\\
d1 \cdot d4
\end{array}
Derivation
  1. Initial program 90.2%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Step-by-step derivation
    1. associate--l+90.2%

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - 0\right)} + d1 \cdot d2 \]
    6. associate--r-90.2%

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) - \left(0 - d1 \cdot d2\right)} \]
    7. associate-+r-90.2%

      \[\leadsto \color{blue}{\left(\left(\left(-d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\right)} - \left(0 - d1 \cdot d2\right) \]
    8. +-commutative90.2%

      \[\leadsto \left(\color{blue}{\left(d4 \cdot d1 + \left(-d1 \cdot d3\right)\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    9. *-commutative90.2%

      \[\leadsto \left(\left(\color{blue}{d1 \cdot d4} + \left(-d1 \cdot d3\right)\right) - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    10. sub-neg90.2%

      \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    11. distribute-lft-out--90.6%

      \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
    12. distribute-lft-out--96.1%

      \[\leadsto \color{blue}{d1 \cdot \left(\left(d4 - d3\right) - d1\right)} - \left(0 - d1 \cdot d2\right) \]
    13. neg-sub096.1%

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
    14. distribute-rgt-neg-out96.1%

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{d1 \cdot \left(-d2\right)} \]
    15. distribute-lft-out--100.0%

      \[\leadsto \color{blue}{d1 \cdot \left(\left(\left(d4 - d3\right) - d1\right) - \left(-d2\right)\right)} \]
    16. sub-neg100.0%

      \[\leadsto d1 \cdot \color{blue}{\left(\left(\left(d4 - d3\right) - d1\right) + \left(-\left(-d2\right)\right)\right)} \]
    17. remove-double-neg100.0%

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

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

    \[\leadsto \color{blue}{d1 \cdot d4} \]
  5. Final simplification29.5%

    \[\leadsto d1 \cdot d4 \]

Developer target: 100.0% accurate, 1.7× 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 2023279 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

  :herbie-target
  (* d1 (- (+ (- d2 d3) d4) d1))

  (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))