FastMath dist4

Percentage Accurate: 88.1% → 100.0%
Time: 4.3s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 88.1% 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 88.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+88.3%

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

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

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

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

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

Alternative 2: 65.9% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d3 \leq 9.5 \cdot 10^{-105}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d3 \leq 5.4 \cdot 10^{+106}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -7.00000000000000028e122 or 5.40000000000000012e106 < d3

    1. Initial program 84.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+84.1%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity84.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-84.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-84.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. +-commutative84.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. *-commutative84.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-neg84.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--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.9%

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

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

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

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

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

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

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

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

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

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

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

    if -7.00000000000000028e122 < d3 < 9.5000000000000002e-105 or 3.39999999999999991 < d3 < 5.40000000000000012e106

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.5000000000000002e-105 < d3 < 3.39999999999999991

    1. Initial program 84.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+84.0%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity84.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-84.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-84.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. +-commutative84.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. *-commutative84.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-neg84.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--84.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow266.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -7 \cdot 10^{+122}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d3 \leq 9.5 \cdot 10^{-105}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 3.4:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \end{array} \]

Alternative 3: 68.8% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;d3 \leq 9.5 \cdot 10^{-105}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d3 \leq 8 \cdot 10^{+104}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -3.3000000000000002e-7 or 8e104 < d3

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

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

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

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

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

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

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

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

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

    if -3.3000000000000002e-7 < d3 < 9.5000000000000002e-105 or 3.39999999999999991 < d3 < 8e104

    1. Initial program 91.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.5000000000000002e-105 < d3 < 3.39999999999999991

    1. Initial program 84.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+84.0%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity84.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-84.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-84.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. +-commutative84.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. *-commutative84.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-neg84.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--84.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow266.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -3.3 \cdot 10^{-7}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 9.5 \cdot 10^{-105}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 3.4:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d3 \leq 8 \cdot 10^{+104}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]

Alternative 4: 40.0% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d2 \leq -2.9 \cdot 10^{-70} \lor \neg \left(d2 \leq -8.4 \cdot 10^{-156}\right) \land d2 \leq 8.6 \cdot 10^{-198}:\\
\;\;\;\;d1 \cdot \left(-d1\right)\\

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


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

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

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

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

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

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

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

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

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

    if -8.9999999999999994e106 < d2 < -2.89999999999999971e-70 or -8.40000000000000049e-156 < d2 < 8.6000000000000007e-198

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow247.6%

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

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

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

    if -2.89999999999999971e-70 < d2 < -8.40000000000000049e-156 or 8.6000000000000007e-198 < d2

    1. Initial program 84.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+84.0%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity84.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-84.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-84.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. +-commutative84.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. *-commutative84.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-neg84.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--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.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 d4 around inf 31.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -9 \cdot 10^{+106}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.9 \cdot 10^{-70} \lor \neg \left(d2 \leq -8.4 \cdot 10^{-156}\right) \land d2 \leq 8.6 \cdot 10^{-198}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 5: 39.6% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d2 \leq -3 \cdot 10^{-83}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d2 \leq 5.6 \cdot 10^{-195}:\\
\;\;\;\;t_0\\

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


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

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

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

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

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

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

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

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

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

    if -1.24999999999999995e110 < d2 < -3.0000000000000001e-83 or -2.7499999999999999e-151 < d2 < 5.60000000000000007e-195

    1. Initial program 89.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-{d1}^{2}} \]
      2. unpow248.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 -3.0000000000000001e-83 < d2 < -2.7499999999999999e-151

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.60000000000000007e-195 < d2

    1. Initial program 83.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+83.7%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity83.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-83.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-83.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. +-commutative83.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. *-commutative83.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-neg83.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--85.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--91.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d2 \leq -1.25 \cdot 10^{+110}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -3 \cdot 10^{-83}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq -2.75 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{elif}\;d2 \leq 5.6 \cdot 10^{-195}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]

Alternative 6: 71.2% accurate, 1.3× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d3 < -4.99999999999999977e-7 or 1.50000000000000003e88 < d3

    1. Initial program 84.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+84.9%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity84.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-84.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-84.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. +-commutative84.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. *-commutative84.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-neg84.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--86.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.99999999999999977e-7 < d3 < 1.85000000000000008e-110

    1. Initial program 92.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+92.2%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity92.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-92.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-92.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. +-commutative92.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. *-commutative92.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-neg92.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--92.2%

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

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

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

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

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

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

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

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

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

    if 1.85000000000000008e-110 < d3 < 1.50000000000000003e88

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq -5 \cdot 10^{-7}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq 1.85 \cdot 10^{-110}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{elif}\;d3 \leq 1.5 \cdot 10^{+88}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \end{array} \]

Alternative 7: 82.6% accurate, 1.7× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

    if -5.5999999999999996e108 < d2

    1. Initial program 86.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 39.7% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 94.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+94.3%

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

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

        \[\leadsto \color{blue}{\left(\left(-d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)\right) + d1 \cdot d2} \]
      5. --rgt-identity94.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-94.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-94.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. +-commutative94.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. *-commutative94.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-neg94.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--94.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--98.1%

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

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

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

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

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

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

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

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

    if -2.4000000000000002e59 < d2

    1. Initial program 86.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 32.2% 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 88.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+88.3%

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

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

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

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

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

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

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

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

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

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

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

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

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