FastMath dist4

Percentage Accurate: 87.8% → 100.0%
Time: 8.4s
Alternatives: 12
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 87.8% 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 86.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+86.7%

      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
    2. sub-neg86.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+86.7%

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

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
    5. --rgt-identity86.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-86.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-86.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. +-commutative86.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. *-commutative86.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-neg86.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--87.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--94.1%

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

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
    14. distribute-rgt-neg-out94.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: 38.5% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -d1 \cdot d3\\ \mathbf{if}\;d4 \leq -1.15 \cdot 10^{-158}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq -1.5 \cdot 10^{-227}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.6 \cdot 10^{-204}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4.05 \cdot 10^{-116}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 4.4 \cdot 10^{-101}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{+46}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (- (* d1 d3))))
   (if (<= d4 -1.15e-158)
     (* d1 d2)
     (if (<= d4 -1.5e-227)
       t_0
       (if (<= d4 1.6e-204)
         (* d1 d2)
         (if (<= d4 4.05e-116)
           t_0
           (if (<= d4 4.4e-101)
             (* d1 d2)
             (if (<= d4 4.6e+46) (* d1 (- d1)) (* d1 d4)))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = -(d1 * d3);
	double tmp;
	if (d4 <= -1.15e-158) {
		tmp = d1 * d2;
	} else if (d4 <= -1.5e-227) {
		tmp = t_0;
	} else if (d4 <= 1.6e-204) {
		tmp = d1 * d2;
	} else if (d4 <= 4.05e-116) {
		tmp = t_0;
	} else if (d4 <= 4.4e-101) {
		tmp = d1 * d2;
	} else if (d4 <= 4.6e+46) {
		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) :: t_0
    real(8) :: tmp
    t_0 = -(d1 * d3)
    if (d4 <= (-1.15d-158)) then
        tmp = d1 * d2
    else if (d4 <= (-1.5d-227)) then
        tmp = t_0
    else if (d4 <= 1.6d-204) then
        tmp = d1 * d2
    else if (d4 <= 4.05d-116) then
        tmp = t_0
    else if (d4 <= 4.4d-101) then
        tmp = d1 * d2
    else if (d4 <= 4.6d+46) 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 t_0 = -(d1 * d3);
	double tmp;
	if (d4 <= -1.15e-158) {
		tmp = d1 * d2;
	} else if (d4 <= -1.5e-227) {
		tmp = t_0;
	} else if (d4 <= 1.6e-204) {
		tmp = d1 * d2;
	} else if (d4 <= 4.05e-116) {
		tmp = t_0;
	} else if (d4 <= 4.4e-101) {
		tmp = d1 * d2;
	} else if (d4 <= 4.6e+46) {
		tmp = d1 * -d1;
	} else {
		tmp = d1 * d4;
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = -(d1 * d3)
	tmp = 0
	if d4 <= -1.15e-158:
		tmp = d1 * d2
	elif d4 <= -1.5e-227:
		tmp = t_0
	elif d4 <= 1.6e-204:
		tmp = d1 * d2
	elif d4 <= 4.05e-116:
		tmp = t_0
	elif d4 <= 4.4e-101:
		tmp = d1 * d2
	elif d4 <= 4.6e+46:
		tmp = d1 * -d1
	else:
		tmp = d1 * d4
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(-Float64(d1 * d3))
	tmp = 0.0
	if (d4 <= -1.15e-158)
		tmp = Float64(d1 * d2);
	elseif (d4 <= -1.5e-227)
		tmp = t_0;
	elseif (d4 <= 1.6e-204)
		tmp = Float64(d1 * d2);
	elseif (d4 <= 4.05e-116)
		tmp = t_0;
	elseif (d4 <= 4.4e-101)
		tmp = Float64(d1 * d2);
	elseif (d4 <= 4.6e+46)
		tmp = Float64(d1 * Float64(-d1));
	else
		tmp = Float64(d1 * d4);
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = -(d1 * d3);
	tmp = 0.0;
	if (d4 <= -1.15e-158)
		tmp = d1 * d2;
	elseif (d4 <= -1.5e-227)
		tmp = t_0;
	elseif (d4 <= 1.6e-204)
		tmp = d1 * d2;
	elseif (d4 <= 4.05e-116)
		tmp = t_0;
	elseif (d4 <= 4.4e-101)
		tmp = d1 * d2;
	elseif (d4 <= 4.6e+46)
		tmp = d1 * -d1;
	else
		tmp = d1 * d4;
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = (-N[(d1 * d3), $MachinePrecision])}, If[LessEqual[d4, -1.15e-158], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, -1.5e-227], t$95$0, If[LessEqual[d4, 1.6e-204], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 4.05e-116], t$95$0, If[LessEqual[d4, 4.4e-101], N[(d1 * d2), $MachinePrecision], If[LessEqual[d4, 4.6e+46], N[(d1 * (-d1)), $MachinePrecision], N[(d1 * d4), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -d1 \cdot d3\\
\mathbf{if}\;d4 \leq -1.15 \cdot 10^{-158}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq -1.5 \cdot 10^{-227}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 1.6 \cdot 10^{-204}:\\
\;\;\;\;d1 \cdot d2\\

\mathbf{elif}\;d4 \leq 4.05 \cdot 10^{-116}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 4.4 \cdot 10^{-101}:\\
\;\;\;\;d1 \cdot d2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < -1.1499999999999999e-158 or -1.5e-227 < d4 < 1.6e-204 or 4.05e-116 < d4 < 4.3999999999999998e-101

    1. Initial program 86.6%

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

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

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

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

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

        \[\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-86.6%

        \[\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-86.6%

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

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

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

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out95.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 d2 around inf 36.2%

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

    if -1.1499999999999999e-158 < d4 < -1.5e-227 or 1.6e-204 < d4 < 4.05e-116

    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 d3 around inf 58.2%

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-lft-neg-in58.2%

        \[\leadsto \color{blue}{\left(-d1\right) \cdot d3} \]
      3. *-commutative58.2%

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

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

    if 4.3999999999999998e-101 < d4 < 4.6000000000000001e46

    1. Initial program 86.6%

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

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

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

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

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

        \[\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-86.6%

        \[\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-86.6%

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

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

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

        \[\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--86.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--93.3%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow240.5%

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

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

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

    if 4.6000000000000001e46 < d4

    1. Initial program 81.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+81.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg81.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+81.1%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity81.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-81.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-81.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. +-commutative81.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. *-commutative81.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-neg81.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--83.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--88.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.15 \cdot 10^{-158}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq -1.5 \cdot 10^{-227}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d4 \leq 1.6 \cdot 10^{-204}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4.05 \cdot 10^{-116}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d4 \leq 4.4 \cdot 10^{-101}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{+46}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 3: 86.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{if}\;d3 \leq -7.6 \cdot 10^{+138}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 170000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 1.08 \cdot 10^{+140}:\\ \;\;\;\;\left(-d1\right) \cdot \left(d1 + d3\right)\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+167}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- (+ d4 d2) d1))))
   (if (<= d3 -7.6e+138)
     (* d1 (- d2 d3))
     (if (<= d3 170000.0)
       t_0
       (if (<= d3 1.08e+140)
         (* (- d1) (+ d1 d3))
         (if (<= d3 9.2e+167) t_0 (* d1 (- d4 d3))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * ((d4 + d2) - d1);
	double tmp;
	if (d3 <= -7.6e+138) {
		tmp = d1 * (d2 - d3);
	} else if (d3 <= 170000.0) {
		tmp = t_0;
	} else if (d3 <= 1.08e+140) {
		tmp = -d1 * (d1 + d3);
	} else if (d3 <= 9.2e+167) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = d1 * ((d4 + d2) - d1)
    if (d3 <= (-7.6d+138)) then
        tmp = d1 * (d2 - d3)
    else if (d3 <= 170000.0d0) then
        tmp = t_0
    else if (d3 <= 1.08d+140) then
        tmp = -d1 * (d1 + d3)
    else if (d3 <= 9.2d+167) then
        tmp = t_0
    else
        tmp = d1 * (d4 - d3)
    end if
    code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * ((d4 + d2) - d1);
	double tmp;
	if (d3 <= -7.6e+138) {
		tmp = d1 * (d2 - d3);
	} else if (d3 <= 170000.0) {
		tmp = t_0;
	} else if (d3 <= 1.08e+140) {
		tmp = -d1 * (d1 + d3);
	} else if (d3 <= 9.2e+167) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * ((d4 + d2) - d1)
	tmp = 0
	if d3 <= -7.6e+138:
		tmp = d1 * (d2 - d3)
	elif d3 <= 170000.0:
		tmp = t_0
	elif d3 <= 1.08e+140:
		tmp = -d1 * (d1 + d3)
	elif d3 <= 9.2e+167:
		tmp = t_0
	else:
		tmp = d1 * (d4 - d3)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(Float64(d4 + d2) - d1))
	tmp = 0.0
	if (d3 <= -7.6e+138)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d3 <= 170000.0)
		tmp = t_0;
	elseif (d3 <= 1.08e+140)
		tmp = Float64(Float64(-d1) * Float64(d1 + d3));
	elseif (d3 <= 9.2e+167)
		tmp = t_0;
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * ((d4 + d2) - d1);
	tmp = 0.0;
	if (d3 <= -7.6e+138)
		tmp = d1 * (d2 - d3);
	elseif (d3 <= 170000.0)
		tmp = t_0;
	elseif (d3 <= 1.08e+140)
		tmp = -d1 * (d1 + d3);
	elseif (d3 <= 9.2e+167)
		tmp = t_0;
	else
		tmp = d1 * (d4 - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * N[(N[(d4 + d2), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d3, -7.6e+138], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 170000.0], t$95$0, If[LessEqual[d3, 1.08e+140], N[((-d1) * N[(d1 + d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d3, 9.2e+167], t$95$0, N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq 170000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d3 \leq 1.08 \cdot 10^{+140}:\\
\;\;\;\;\left(-d1\right) \cdot \left(d1 + d3\right)\\

\mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+167}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d3 < -7.60000000000000025e138

    1. Initial program 76.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+76.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg76.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+76.4%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity76.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-76.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-76.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. +-commutative76.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. *-commutative76.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-neg76.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--79.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--91.1%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out91.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 0 97.0%

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

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

    if -7.60000000000000025e138 < d3 < 1.7e5 or 1.0799999999999999e140 < d3 < 9.19999999999999952e167

    1. Initial program 89.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+89.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg89.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+89.4%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity89.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-89.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-89.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. +-commutative89.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. *-commutative89.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-neg89.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--89.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--93.8%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out93.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 0 94.5%

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

    if 1.7e5 < d3 < 1.0799999999999999e140

    1. Initial program 80.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+80.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg80.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+80.9%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity80.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-80.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-80.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. +-commutative80.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. *-commutative80.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-neg80.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--85.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--95.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d1 \cdot \left(-\left(d3 + d1\right)\right)} \]
      5. distribute-neg-in81.9%

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

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

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

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

    if 9.19999999999999952e167 < d3

    1. Initial program 86.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+86.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg86.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+86.4%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity86.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-86.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-86.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. +-commutative86.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. *-commutative86.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-neg86.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--86.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--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--99.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -7.6 \cdot 10^{+138}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 170000:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{elif}\;d3 \leq 1.08 \cdot 10^{+140}:\\ \;\;\;\;\left(-d1\right) \cdot \left(d1 + d3\right)\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+167}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 4: 66.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -d1 \cdot d3\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -2.7 \cdot 10^{+119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 170000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 2.1 \cdot 10^{+85}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+167}:\\ \;\;\;\;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.7e+119)
     t_0
     (if (<= d3 170000.0)
       t_1
       (if (<= d3 2.1e+85) (* d1 (- d1)) (if (<= d3 9.2e+167) 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.7e+119) {
		tmp = t_0;
	} else if (d3 <= 170000.0) {
		tmp = t_1;
	} else if (d3 <= 2.1e+85) {
		tmp = d1 * -d1;
	} else if (d3 <= 9.2e+167) {
		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.7d+119)) then
        tmp = t_0
    else if (d3 <= 170000.0d0) then
        tmp = t_1
    else if (d3 <= 2.1d+85) then
        tmp = d1 * -d1
    else if (d3 <= 9.2d+167) 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.7e+119) {
		tmp = t_0;
	} else if (d3 <= 170000.0) {
		tmp = t_1;
	} else if (d3 <= 2.1e+85) {
		tmp = d1 * -d1;
	} else if (d3 <= 9.2e+167) {
		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.7e+119:
		tmp = t_0
	elif d3 <= 170000.0:
		tmp = t_1
	elif d3 <= 2.1e+85:
		tmp = d1 * -d1
	elif d3 <= 9.2e+167:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(-Float64(d1 * d3))
	t_1 = Float64(d1 * Float64(d4 + d2))
	tmp = 0.0
	if (d3 <= -2.7e+119)
		tmp = t_0;
	elseif (d3 <= 170000.0)
		tmp = t_1;
	elseif (d3 <= 2.1e+85)
		tmp = Float64(d1 * Float64(-d1));
	elseif (d3 <= 9.2e+167)
		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.7e+119)
		tmp = t_0;
	elseif (d3 <= 170000.0)
		tmp = t_1;
	elseif (d3 <= 2.1e+85)
		tmp = d1 * -d1;
	elseif (d3 <= 9.2e+167)
		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.7e+119], t$95$0, If[LessEqual[d3, 170000.0], t$95$1, If[LessEqual[d3, 2.1e+85], N[(d1 * (-d1)), $MachinePrecision], If[LessEqual[d3, 9.2e+167], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d3 \leq 170000:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+167}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -2.6999999999999998e119 or 9.19999999999999952e167 < d3

    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--80.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--93.5%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-lft-neg-in77.1%

        \[\leadsto \color{blue}{\left(-d1\right) \cdot d3} \]
      3. *-commutative77.1%

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

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

    if -2.6999999999999998e119 < d3 < 1.7e5 or 2.1000000000000001e85 < d3 < 9.19999999999999952e167

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

        \[\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.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--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 d3 around 0 93.5%

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

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

    if 1.7e5 < d3 < 2.1000000000000001e85

    1. Initial program 84.6%

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

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

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

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

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

        \[\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-84.6%

        \[\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-84.6%

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

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

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

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out92.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 d1 around inf 60.3%

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow260.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -2.7 \cdot 10^{+119}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d3 \leq 170000:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 2.1 \cdot 10^{+85}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+167}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;-d1 \cdot d3\\ \end{array} \]

Alternative 5: 69.2% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d1 \leq 1.05 \cdot 10^{-131}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d1 \leq 1.35 \cdot 10^{-120}:\\
\;\;\;\;-d1 \cdot d3\\

\mathbf{elif}\;d1 \leq 2.1 \cdot 10^{+110}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d1 < -5.2e15 or 2.10000000000000015e110 < d1

    1. Initial program 67.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+67.3%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg67.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+67.3%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity67.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-67.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-67.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. +-commutative67.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. *-commutative67.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-neg67.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--69.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--85.6%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out85.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 89.5%

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

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

    if -5.2e15 < d1 < 1.04999999999999999e-131 or 1.3499999999999999e-120 < d1 < 2.10000000000000015e110

    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--99.9%

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

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

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

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

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

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

    if 1.04999999999999999e-131 < d1 < 1.3499999999999999e-120

    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 d3 around inf 100.0%

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-lft-neg-in100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -5.2 \cdot 10^{+15}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d1 \leq 1.05 \cdot 10^{-131}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d1 \leq 1.35 \cdot 10^{-120}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d1 \leq 2.1 \cdot 10^{+110}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 6: 59.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := d1 \cdot \left(d2 - d1\right)\\
\mathbf{if}\;d4 \leq -9.8 \cdot 10^{-161}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq -9.5 \cdot 10^{-227}:\\
\;\;\;\;-d1 \cdot d3\\

\mathbf{elif}\;d4 \leq 3.2 \cdot 10^{-11}:\\
\;\;\;\;t_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d4 < -9.80000000000000071e-161 or -9.49999999999999953e-227 < d4 < 3.19999999999999994e-11

    1. Initial program 86.6%

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

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

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

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

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

        \[\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-86.6%

        \[\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-86.6%

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

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

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

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

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out94.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 77.6%

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

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

    if -9.80000000000000071e-161 < d4 < -9.49999999999999953e-227

    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 d3 around inf 52.0%

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

        \[\leadsto \color{blue}{-d1 \cdot d3} \]
      2. distribute-lft-neg-in52.0%

        \[\leadsto \color{blue}{\left(-d1\right) \cdot d3} \]
      3. *-commutative52.0%

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

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

    if 3.19999999999999994e-11 < d4 < 9.99999999999999957e110

    1. Initial program 99.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+99.8%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg99.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+99.8%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity99.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-99.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-99.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. +-commutative99.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. *-commutative99.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-neg99.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--99.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--99.9%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999957e110 < d4

    1. Initial program 77.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+77.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg77.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+77.7%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity77.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-77.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-77.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. +-commutative77.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. *-commutative77.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-neg77.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--80.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--86.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -9.8 \cdot 10^{-161}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq -9.5 \cdot 10^{-227}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d4 \leq 3.2 \cdot 10^{-11}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 10^{+111}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 7: 92.5% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d3 \leq -1.05 \cdot 10^{-15} \lor \neg \left(d3 \leq 1.45 \cdot 10^{+86}\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 -1.05e-15) (not (<= d3 1.45e+86)))
   (* d1 (- (+ d4 d2) d3))
   (* d1 (- (+ d4 d2) d1))))
double code(double d1, double d2, double d3, double d4) {
	double tmp;
	if ((d3 <= -1.05e-15) || !(d3 <= 1.45e+86)) {
		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 <= (-1.05d-15)) .or. (.not. (d3 <= 1.45d+86))) 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 <= -1.05e-15) || !(d3 <= 1.45e+86)) {
		tmp = d1 * ((d4 + d2) - d3);
	} else {
		tmp = d1 * ((d4 + d2) - d1);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	tmp = 0
	if (d3 <= -1.05e-15) or not (d3 <= 1.45e+86):
		tmp = d1 * ((d4 + d2) - d3)
	else:
		tmp = d1 * ((d4 + d2) - d1)
	return tmp
function code(d1, d2, d3, d4)
	tmp = 0.0
	if ((d3 <= -1.05e-15) || !(d3 <= 1.45e+86))
		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 <= -1.05e-15) || ~((d3 <= 1.45e+86)))
		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, -1.05e-15], N[Not[LessEqual[d3, 1.45e+86]], $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 -1.05 \cdot 10^{-15} \lor \neg \left(d3 \leq 1.45 \cdot 10^{+86}\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 < -1.0499999999999999e-15 or 1.44999999999999995e86 < d3

    1. Initial program 80.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+80.9%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg80.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+80.9%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity80.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-80.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-80.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. +-commutative80.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. *-commutative80.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-neg80.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.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--94.5%

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

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

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

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

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

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

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

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

    if -1.0499999999999999e-15 < d3 < 1.44999999999999995e86

    1. Initial program 91.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+91.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg91.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+91.1%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity91.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-91.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-91.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. +-commutative91.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. *-commutative91.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-neg91.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--91.1%

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

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out93.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 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.4%

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

Alternative 8: 91.8% accurate, 1.3× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -5.40000000000000009e-11

    1. Initial program 82.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+82.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg82.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+82.1%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity82.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-82.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-82.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. +-commutative82.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. *-commutative82.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-neg82.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--83.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--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 d1 around 0 92.0%

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

    if -5.40000000000000009e-11 < d3 < 1.7e5

    1. Initial program 91.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+91.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg91.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+91.7%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity91.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-91.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-91.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. +-commutative91.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. *-commutative91.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-neg91.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--91.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--93.9%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out93.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 99.8%

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

    if 1.7e5 < d3

    1. Initial program 80.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+80.0%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg80.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+80.0%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity80.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-80.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-80.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. +-commutative80.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. *-commutative80.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-neg80.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--82.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.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 60.8% accurate, 1.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 8.49999999999999941e-101

    1. Initial program 88.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+88.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg88.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+88.4%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity88.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-88.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-88.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. +-commutative88.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. *-commutative88.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-neg88.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--89.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--95.9%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out95.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 d1 around 0 80.9%

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

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

    if 8.49999999999999941e-101 < d4 < 1.7000000000000001e111

    1. Initial program 89.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+89.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg89.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+89.4%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity89.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-89.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-89.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. +-commutative89.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. *-commutative89.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-neg89.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--89.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--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 0 82.5%

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

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

    if 1.7000000000000001e111 < d4

    1. Initial program 77.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+77.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg77.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+77.7%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity77.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-77.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-77.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. +-commutative77.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. *-commutative77.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-neg77.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--80.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--86.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 8.5 \cdot 10^{-101}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{+111}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 10: 38.6% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 4.7 \cdot 10^{-101}:\\
\;\;\;\;d1 \cdot d2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 4.6999999999999999e-101

    1. Initial program 88.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+88.4%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg88.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+88.4%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity88.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-88.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-88.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. +-commutative88.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. *-commutative88.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-neg88.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--89.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--95.9%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out95.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 33.6%

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

    if 4.6999999999999999e-101 < d4 < 1.4500000000000001e46

    1. Initial program 86.6%

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

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

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

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

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

        \[\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-86.6%

        \[\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-86.6%

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

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

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

        \[\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--86.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--93.3%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow240.5%

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

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

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

    if 1.4500000000000001e46 < d4

    1. Initial program 81.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+81.1%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg81.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+81.1%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity81.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-81.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-81.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. +-commutative81.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. *-commutative81.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-neg81.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--83.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--88.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 4.7 \cdot 10^{-101}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.45 \cdot 10^{+46}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 11: 38.4% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 0.0027:\\
\;\;\;\;d1 \cdot d2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d4 < 0.0027000000000000001

    1. Initial program 87.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+87.7%

        \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
      2. sub-neg87.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+87.7%

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity87.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-87.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-87.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. +-commutative87.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. *-commutative87.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-neg87.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--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--95.4%

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

        \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
      14. distribute-rgt-neg-out95.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 d2 around inf 33.1%

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

    if 0.0027000000000000001 < d4

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

        \[\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--85.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--90.1%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 0.0027:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 12: 32.2% 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 86.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+86.7%

      \[\leadsto \color{blue}{\left(d1 \cdot d2 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]
    2. sub-neg86.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+86.7%

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

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
    5. --rgt-identity86.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-86.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-86.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. +-commutative86.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. *-commutative86.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-neg86.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--87.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--94.1%

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

      \[\leadsto d1 \cdot \left(\left(d4 - d3\right) - d1\right) - \color{blue}{\left(-d1 \cdot d2\right)} \]
    14. distribute-rgt-neg-out94.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 34.1%

    \[\leadsto \color{blue}{d1 \cdot d4} \]
  5. Final simplification34.1%

    \[\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 2023274 
(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)))