FastMath dist4

Percentage Accurate: 87.5% → 100.0%
Time: 6.3s
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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 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 87.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+87.1%

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

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

      \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
    5. --rgt-identity87.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-87.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-87.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. +-commutative87.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. *-commutative87.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-neg87.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--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--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--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: 62.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 1.32 \cdot 10^{-205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 6.7 \cdot 10^{-189}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.15 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 11600000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 9 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \end{array} \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (let* ((t_0 (* d1 (- d1))) (t_1 (* d1 (- d2 d3))))
   (if (<= d4 1.32e-205)
     t_1
     (if (<= d4 6.7e-189)
       t_0
       (if (<= d4 1.15e-62)
         t_1
         (if (<= d4 11600000.0)
           t_0
           (if (<= d4 9e+30) t_1 (* d1 (- d4 d3)))))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * -d1;
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= 1.32e-205) {
		tmp = t_1;
	} else if (d4 <= 6.7e-189) {
		tmp = t_0;
	} else if (d4 <= 1.15e-62) {
		tmp = t_1;
	} else if (d4 <= 11600000.0) {
		tmp = t_0;
	} else if (d4 <= 9e+30) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = d1 * -d1
    t_1 = d1 * (d2 - d3)
    if (d4 <= 1.32d-205) then
        tmp = t_1
    else if (d4 <= 6.7d-189) then
        tmp = t_0
    else if (d4 <= 1.15d-62) then
        tmp = t_1
    else if (d4 <= 11600000.0d0) then
        tmp = t_0
    else if (d4 <= 9d+30) then
        tmp = t_1
    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 * -d1;
	double t_1 = d1 * (d2 - d3);
	double tmp;
	if (d4 <= 1.32e-205) {
		tmp = t_1;
	} else if (d4 <= 6.7e-189) {
		tmp = t_0;
	} else if (d4 <= 1.15e-62) {
		tmp = t_1;
	} else if (d4 <= 11600000.0) {
		tmp = t_0;
	} else if (d4 <= 9e+30) {
		tmp = t_1;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * -d1
	t_1 = d1 * (d2 - d3)
	tmp = 0
	if d4 <= 1.32e-205:
		tmp = t_1
	elif d4 <= 6.7e-189:
		tmp = t_0
	elif d4 <= 1.15e-62:
		tmp = t_1
	elif d4 <= 11600000.0:
		tmp = t_0
	elif d4 <= 9e+30:
		tmp = t_1
	else:
		tmp = d1 * (d4 - d3)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(-d1))
	t_1 = Float64(d1 * Float64(d2 - d3))
	tmp = 0.0
	if (d4 <= 1.32e-205)
		tmp = t_1;
	elseif (d4 <= 6.7e-189)
		tmp = t_0;
	elseif (d4 <= 1.15e-62)
		tmp = t_1;
	elseif (d4 <= 11600000.0)
		tmp = t_0;
	elseif (d4 <= 9e+30)
		tmp = t_1;
	else
		tmp = Float64(d1 * Float64(d4 - d3));
	end
	return tmp
end
function tmp_2 = code(d1, d2, d3, d4)
	t_0 = d1 * -d1;
	t_1 = d1 * (d2 - d3);
	tmp = 0.0;
	if (d4 <= 1.32e-205)
		tmp = t_1;
	elseif (d4 <= 6.7e-189)
		tmp = t_0;
	elseif (d4 <= 1.15e-62)
		tmp = t_1;
	elseif (d4 <= 11600000.0)
		tmp = t_0;
	elseif (d4 <= 9e+30)
		tmp = t_1;
	else
		tmp = d1 * (d4 - d3);
	end
	tmp_2 = tmp;
end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(d1 * (-d1)), $MachinePrecision]}, Block[{t$95$1 = N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 1.32e-205], t$95$1, If[LessEqual[d4, 6.7e-189], t$95$0, If[LessEqual[d4, 1.15e-62], t$95$1, If[LessEqual[d4, 11600000.0], t$95$0, If[LessEqual[d4, 9e+30], t$95$1, N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d4 \leq 6.7 \cdot 10^{-189}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 1.15 \cdot 10^{-62}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d4 \leq 11600000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d4 \leq 9 \cdot 10^{+30}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 1.31999999999999992e-205 or 6.7000000000000002e-189 < d4 < 1.15e-62 or 1.16e7 < d4 < 8.9999999999999999e30

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

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

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

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

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

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

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

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

    if 1.31999999999999992e-205 < d4 < 6.7000000000000002e-189 or 1.15e-62 < d4 < 1.16e7

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

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

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

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

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

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

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

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

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

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

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

    if 8.9999999999999999e30 < d4

    1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--87.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--92.2%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 1.32 \cdot 10^{-205}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 6.7 \cdot 10^{-189}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 1.15 \cdot 10^{-62}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 11600000:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 9 \cdot 10^{+30}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 3: 38.8% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d2 \leq -2.45 \cdot 10^{+31}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d2 \leq -3.9 \cdot 10^{-293}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d2 < -3.70000000000000013e134

    1. Initial program 75.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+75.0%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity75.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-75.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-75.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. +-commutative75.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. *-commutative75.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-neg75.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--75.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--79.5%

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

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

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

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

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

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

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

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

    if -3.70000000000000013e134 < d2 < -2.44999999999999998e31 or -6.9999999999999994e-89 < d2 < -3.9e-293

    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.4%

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

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

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

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

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

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

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

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

    if -2.44999999999999998e31 < d2 < -6.9999999999999994e-89

    1. Initial program 96.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+96.6%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity96.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-96.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-96.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. +-commutative96.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. *-commutative96.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-neg96.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--96.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--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 inf 28.0%

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

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

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

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

    if -3.9e-293 < d2

    1. Initial program 90.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+90.6%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity90.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-90.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-90.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. +-commutative90.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. *-commutative90.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-neg90.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--90.6%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--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 d4 around inf 34.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.7 \cdot 10^{+134}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.45 \cdot 10^{+31}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq -7 \cdot 10^{-89}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq -3.9 \cdot 10^{-293}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 4: 61.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -3.5 \cdot 10^{+132} \lor \neg \left(d2 \leq -3.9 \cdot 10^{+84}\right) \land d2 \leq -2.4 \cdot 10^{-15}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d2 < -3.5000000000000002e132 or -3.90000000000000016e84 < d2 < -2.39999999999999995e-15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.5000000000000002e132 < d2 < -3.90000000000000016e84 or -2.39999999999999995e-15 < d2

    1. Initial program 89.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--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 0 82.4%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.5 \cdot 10^{+132} \lor \neg \left(d2 \leq -3.9 \cdot 10^{+84}\right) \land d2 \leq -2.4 \cdot 10^{-15}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]

Alternative 5: 62.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d4 \leq -1.15 \cdot 10^{-270}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 5.6 \cdot 10^{-208}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.95 \cdot 10^{+29}:\\ \;\;\;\;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 (- d2 d1))))
   (if (<= d4 -1.15e-270)
     t_0
     (if (<= d4 5.6e-208)
       (* d1 (- d2 d3))
       (if (<= d4 2.95e+29) t_0 (* d1 (- d4 d3)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double tmp;
	if (d4 <= -1.15e-270) {
		tmp = t_0;
	} else if (d4 <= 5.6e-208) {
		tmp = d1 * (d2 - d3);
	} else if (d4 <= 2.95e+29) {
		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 * (d2 - d1)
    if (d4 <= (-1.15d-270)) then
        tmp = t_0
    else if (d4 <= 5.6d-208) then
        tmp = d1 * (d2 - d3)
    else if (d4 <= 2.95d+29) 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 * (d2 - d1);
	double tmp;
	if (d4 <= -1.15e-270) {
		tmp = t_0;
	} else if (d4 <= 5.6e-208) {
		tmp = d1 * (d2 - d3);
	} else if (d4 <= 2.95e+29) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	tmp = 0
	if d4 <= -1.15e-270:
		tmp = t_0
	elif d4 <= 5.6e-208:
		tmp = d1 * (d2 - d3)
	elif d4 <= 2.95e+29:
		tmp = t_0
	else:
		tmp = d1 * (d4 - d3)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d4 <= -1.15e-270)
		tmp = t_0;
	elseif (d4 <= 5.6e-208)
		tmp = Float64(d1 * Float64(d2 - d3));
	elseif (d4 <= 2.95e+29)
		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 * (d2 - d1);
	tmp = 0.0;
	if (d4 <= -1.15e-270)
		tmp = t_0;
	elseif (d4 <= 5.6e-208)
		tmp = d1 * (d2 - d3);
	elseif (d4 <= 2.95e+29)
		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[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, -1.15e-270], t$95$0, If[LessEqual[d4, 5.6e-208], N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 2.95e+29], t$95$0, N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d4 \leq 5.6 \cdot 10^{-208}:\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

\mathbf{elif}\;d4 \leq 2.95 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < -1.1500000000000001e-270 or 5.60000000000000003e-208 < d4 < 2.9499999999999999e29

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.1500000000000001e-270 < d4 < 5.60000000000000003e-208

    1. Initial program 93.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+93.1%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity93.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-93.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-93.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. +-commutative93.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. *-commutative93.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-neg93.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--93.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--96.6%

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

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

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

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

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

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

    if 2.9499999999999999e29 < d4

    1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--87.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--92.2%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq -1.15 \cdot 10^{-270}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 5.6 \cdot 10^{-208}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 2.95 \cdot 10^{+29}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 6: 62.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ \mathbf{if}\;d4 \leq 2.15 \cdot 10^{-302}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 6.2 \cdot 10^{-145}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d4 \leq 1.32 \cdot 10^{+32}:\\ \;\;\;\;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 (- d2 d1))))
   (if (<= d4 2.15e-302)
     t_0
     (if (<= d4 6.2e-145)
       (* d1 (- (- d1) d3))
       (if (<= d4 1.32e+32) t_0 (* d1 (- d4 d3)))))))
double code(double d1, double d2, double d3, double d4) {
	double t_0 = d1 * (d2 - d1);
	double tmp;
	if (d4 <= 2.15e-302) {
		tmp = t_0;
	} else if (d4 <= 6.2e-145) {
		tmp = d1 * (-d1 - d3);
	} else if (d4 <= 1.32e+32) {
		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 * (d2 - d1)
    if (d4 <= 2.15d-302) then
        tmp = t_0
    else if (d4 <= 6.2d-145) then
        tmp = d1 * (-d1 - d3)
    else if (d4 <= 1.32d+32) 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 * (d2 - d1);
	double tmp;
	if (d4 <= 2.15e-302) {
		tmp = t_0;
	} else if (d4 <= 6.2e-145) {
		tmp = d1 * (-d1 - d3);
	} else if (d4 <= 1.32e+32) {
		tmp = t_0;
	} else {
		tmp = d1 * (d4 - d3);
	}
	return tmp;
}
def code(d1, d2, d3, d4):
	t_0 = d1 * (d2 - d1)
	tmp = 0
	if d4 <= 2.15e-302:
		tmp = t_0
	elif d4 <= 6.2e-145:
		tmp = d1 * (-d1 - d3)
	elif d4 <= 1.32e+32:
		tmp = t_0
	else:
		tmp = d1 * (d4 - d3)
	return tmp
function code(d1, d2, d3, d4)
	t_0 = Float64(d1 * Float64(d2 - d1))
	tmp = 0.0
	if (d4 <= 2.15e-302)
		tmp = t_0;
	elseif (d4 <= 6.2e-145)
		tmp = Float64(d1 * Float64(Float64(-d1) - d3));
	elseif (d4 <= 1.32e+32)
		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 * (d2 - d1);
	tmp = 0.0;
	if (d4 <= 2.15e-302)
		tmp = t_0;
	elseif (d4 <= 6.2e-145)
		tmp = d1 * (-d1 - d3);
	elseif (d4 <= 1.32e+32)
		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[(d2 - d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d4, 2.15e-302], t$95$0, If[LessEqual[d4, 6.2e-145], N[(d1 * N[((-d1) - d3), $MachinePrecision]), $MachinePrecision], If[LessEqual[d4, 1.32e+32], t$95$0, N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d4 \leq 1.32 \cdot 10^{+32}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d4 < 2.1500000000000001e-302 or 6.20000000000000001e-145 < d4 < 1.31999999999999997e32

    1. Initial program 85.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+85.5%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity85.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-85.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-85.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. +-commutative85.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. *-commutative85.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-neg85.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--85.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--92.4%

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

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

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

        \[\leadsto d1 \cdot \left(\color{blue}{\left(-d1\right)} + d2\right) \]
    6. Simplified63.1%

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

    if 2.1500000000000001e-302 < d4 < 6.20000000000000001e-145

    1. Initial program 97.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+97.0%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity97.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-97.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-97.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. +-commutative97.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. *-commutative97.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-neg97.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--97.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 d2 around 0 71.5%

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

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

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

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

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

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

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

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

    if 1.31999999999999997e32 < d4

    1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--87.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--92.2%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 2.15 \cdot 10^{-302}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 6.2 \cdot 10^{-145}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d4 \leq 1.32 \cdot 10^{+32}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]

Alternative 7: 65.4% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -2.35 \cdot 10^{+76} \lor \neg \left(d1 \leq 1.35 \cdot 10^{+123}\right):\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d1 < -2.3500000000000002e76 or 1.35000000000000007e123 < d1

    1. Initial program 62.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+62.5%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity62.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-62.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-62.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. +-commutative62.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. *-commutative62.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-neg62.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--63.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--80.7%

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

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

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

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

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

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

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

    if -2.3500000000000002e76 < d1 < 1.35000000000000007e123

    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 d4 around inf 66.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d1 \leq -2.35 \cdot 10^{+76} \lor \neg \left(d1 \leq 1.35 \cdot 10^{+123}\right):\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]

Alternative 8: 72.1% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -2.4 \cdot 10^{+109} \lor \neg \left(d3 \leq 1.85 \cdot 10^{+62}\right):\\
\;\;\;\;d1 \cdot \left(d2 - d3\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d3 < -2.39999999999999987e109 or 1.85000000000000007e62 < d3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.39999999999999987e109 < d3 < 1.85000000000000007e62

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--90.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--93.6%

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

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

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

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

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

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

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

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

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

Alternative 9: 81.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 73.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+73.1%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity73.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-73.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-73.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. +-commutative73.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. *-commutative73.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-neg73.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--73.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--76.9%

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

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

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

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

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

    if -1.45e175 < d2

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

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

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

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

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

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

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

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

Alternative 10: 38.6% accurate, 1.8× speedup?

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

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

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

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


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

    1. Initial program 75.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+75.0%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity75.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-75.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-75.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. +-commutative75.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. *-commutative75.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-neg75.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--75.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--79.5%

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

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

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

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

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

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

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

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

    if -3.70000000000000013e134 < d2 < -7.4999999999999997e-295

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.4999999999999997e-295 < d2

    1. Initial program 90.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+90.6%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity90.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-90.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-90.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. +-commutative90.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. *-commutative90.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-neg90.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--90.6%

        \[\leadsto \left(\color{blue}{d1 \cdot \left(d4 - d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      12. distribute-lft-out--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 d4 around inf 34.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -3.7 \cdot 10^{+134}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -7.5 \cdot 10^{-295}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 11: 39.4% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 9.2 \cdot 10^{+30}:\\
\;\;\;\;d1 \cdot d2\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.2e30 < d4

    1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left(d1 \cdot d4 - d1 \cdot d3\right)} - d1 \cdot d1\right) - \left(0 - d1 \cdot d2\right) \]
      11. distribute-lft-out--87.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--92.2%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d4 \leq 9.2 \cdot 10^{+30}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 12: 31.3% accurate, 5.0× speedup?

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

\\
d1 \cdot d2
\end{array}
Derivation
  1. Initial program 87.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+87.1%

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

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

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

    \[\leadsto \color{blue}{d1 \cdot d2} \]
  5. Final simplification32.5%

    \[\leadsto d1 \cdot d2 \]

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 2023271 
(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)))